Organize the engine/ directory

This is an informed attempt at reorganizing the engine/ directory by
creating categorized subdirectories, in order to make it easier to
navigate and find things.

The directories created are as follows:
* engine/game: Contains all "minigames", things like the unown puzzle
and slot machine.
* engine/gfx: Contains all handling of graphics. From loading palettes
to playing animations.
* engine/link: Contains all multiplayer functionality.
* engine/menu: Contains all generic/misc. menus and menu code.
Other, more specialized menus are in their own subdirectories (pokedex,
pokegear, party menu, etc).
* engine/overworld: Contains all handling of the overworld. From loading
and connecting maps to wild encounters and the scripting engine.
* engine/pokegear: In the same vein as engine/pokedex, except it could
use some more splitting up.
* engine/pokemon: Contains everything related to manipulating pokemon
data. From the pokemon storage system to evolution and mail.
* engine/printer: Contains everything related to printing things as well
as the printer communication.
* engine/title: Contains intro sequences, title screens and credits.
This commit is contained in:
mid-kid
2018-03-13 13:07:16 +01:00
parent 12070ca500
commit baa0dc5a96
106 changed files with 104 additions and 104 deletions

1303
engine/overworld/decorations.asm Executable file

File diff suppressed because it is too large Load Diff

1111
engine/overworld/events.asm Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,103 @@
ReanchorBGMap_NoOAMUpdate:: ; 6454
call DelayFrame
ld a, [hOAMUpdate]
push af
ld a, $1
ld [hOAMUpdate], a
ld a, [hBGMapMode]
push af
xor a
ld [hBGMapMode], a
call .ReanchorBGMap
pop af
ld [hBGMapMode], a
pop af
ld [hOAMUpdate], a
ld hl, wVramState
set 6, [hl]
ret
.ReanchorBGMap:
xor a
ld [hLCDCPointer], a
ld [hBGMapMode], a
ld a, $90
ld [hWY], a
call OverworldTextModeSwitch
ld a, HIGH(vBGMap1)
call .LoadBGMapAddrIntoHRAM
call _OpenAndCloseMenu_HDMATransferTileMapAndAttrMap
farcall LoadOW_BGPal7
farcall ApplyPals
ld a, $1
ld [hCGBPalUpdate], a
xor a
ld [hBGMapMode], a
ld [hWY], a
farcall HDMATransfer_FillBGMap0WithBlack ; no need to farcall
ld a, HIGH(vBGMap0)
call .LoadBGMapAddrIntoHRAM
xor a ; LOW(vBGMap0)
ld [wBGMapAnchor], a
ld a, HIGH(vBGMap0)
ld [wBGMapAnchor + 1], a
xor a
ld [hSCX], a
ld [hSCY], a
call ApplyBGMapAnchorToObjects
ret
.LoadBGMapAddrIntoHRAM: ; 64b9
ld [hBGMapAddress + 1], a
xor a
ld [hBGMapAddress], a
ret
LoadFonts_NoOAMUpdate:: ; 64bf
ld a, [hOAMUpdate]
push af
ld a, $1
ld [hOAMUpdate], a
call .LoadGFX
pop af
ld [hOAMUpdate], a
ret
.LoadGFX:
call LoadFontsExtra
ld a, $90
ld [hWY], a
call SafeUpdateSprites
call LoadStandardFont
ret
HDMATransfer_FillBGMap0WithBlack: ; 64db
ld a, [rSVBK]
push af
ld a, BANK(wDecompressScratch)
ld [rSVBK], a
ld a, "■"
ld hl, wDecompressScratch
ld bc, wScratchAttrMap - wDecompressScratch
call ByteFill
ld a, HIGH(wDecompressScratch)
ld [rHDMA1], a
ld a, LOW(wDecompressScratch)
ld [rHDMA2], a
ld a, HIGH(vBGMap0 % $8000)
ld [rHDMA3], a
ld a, LOW(vBGMap0 % $8000)
ld [rHDMA4], a
ld a, $3f
ld [hDMATransfer], a
call DelayFrame
pop af
ld [rSVBK], a
ret

View File

@@ -0,0 +1,87 @@
GetLandmarkCoords: ; 0x1ca896
; Return coordinates (d, e) of landmark e.
push hl
ld l, e
ld h, 0
add hl, hl
add hl, hl
ld de, Landmarks
add hl, de
ld a, [hli]
ld e, a
ld d, [hl]
pop hl
ret
; 0x1ca8a5
GetLandmarkName:: ; 0x1ca8a5
; Copy the name of landmark e to wStringBuffer1.
push hl
push de
push bc
ld l, e
ld h, 0
add hl, hl
add hl, hl
ld de, Landmarks + 2
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
ld de, wStringBuffer1
ld c, 18
.copy
ld a, [hli]
ld [de], a
inc de
dec c
jr nz, .copy
pop bc
pop de
pop hl
ret
; 0x1ca8c3
INCLUDE "data/maps/landmarks.asm"
RegionCheck: ; 0x1caea1
; Checks if the player is in Kanto or Johto.
; If in Johto, returns 0 in e.
; If in Kanto, returns 1 in e.
ld a, [wMapGroup]
ld b, a
ld a, [wMapNumber]
ld c, a
call GetWorldMapLocation
cp FAST_SHIP ; S.S. Aqua
jr z, .johto
cp SPECIAL_MAP
jr nz, .checkagain
; In a special map, get the backup map group / map id
ld a, [wBackupMapGroup]
ld b, a
ld a, [wBackupMapNumber]
ld c, a
call GetWorldMapLocation
.checkagain
cp KANTO_LANDMARK
jr c, .johto
; Victory Road area is considered to be Johto.
cp VICTORY_ROAD
jr c, .kanto
.johto
ld e, JOHTO_REGION
ret
.kanto
ld e, KANTO_REGION
ret

View File

@@ -0,0 +1,313 @@
ObjectActionPairPointers: ; 445f
; entries correspond to OBJECT_ACTION_* constants
dw SetFacingStanding, SetFacingStanding
dw SetFacingStandAction, SetFacingCurrent
dw SetFacingStepAction, SetFacingCurrent
dw SetFacingBumpAction, SetFacingCurrent
dw SetFacingCounterclockwiseSpin, SetFacingCurrent
dw SetFacingCounterclockwiseSpin2, SetFacingStanding
dw SetFacingFish, SetFacingFish
dw SetFacingShadow, SetFacingStanding
dw SetFacingEmote, SetFacingEmote
dw SetFacingBigDollSym, SetFacingBigDollSym
dw SetFacingBounce, SetFacingFreezeBounce
dw SetFacingWeirdTree, SetFacingCurrent
dw SetFacingBigDollAsym, SetFacingBigDollAsym
dw SetFacingBigDoll, SetFacingBigDoll
dw SetFacingBoulderDust, SetFacingStanding
dw SetFacingGrassShake, SetFacingStanding
dw SetFacingSkyfall, SetFacingCurrent
; 44a3
SetFacingStanding: ; 44a3
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], STANDING
ret
; 44aa
SetFacingCurrent: ; 44aa
call GetSpriteDirection
or FACING_STEP_DOWN_0 ; useless
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], a
ret
; 44b5
SetFacingStandAction: ; 44b5
ld hl, OBJECT_FACING_STEP
add hl, bc
ld a, [hl]
and 1
jr nz, SetFacingStepAction
jp SetFacingCurrent
; 44c1
SetFacingStepAction: ; 44c1
ld hl, OBJECT_FLAGS1
add hl, bc
bit SLIDING, [hl]
jp nz, SetFacingCurrent
ld hl, OBJECT_STEP_FRAME
add hl, bc
ld a, [hl]
inc a
and %00001111
ld [hl], a
rrca
rrca
and %00000011
ld d, a
call GetSpriteDirection
or FACING_STEP_DOWN_0 ; useless
or d
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], a
ret
; 44e4
SetFacingSkyfall: ; 44e4
ld hl, OBJECT_FLAGS1
add hl, bc
bit SLIDING, [hl]
jp nz, SetFacingCurrent
ld hl, OBJECT_STEP_FRAME
add hl, bc
ld a, [hl]
add 2
and %00001111
ld [hl], a
rrca
rrca
and %00000011
ld d, a
call GetSpriteDirection
or FACING_STEP_DOWN_0 ; useless
or d
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], a
ret
; 4508
SetFacingBumpAction: ; 4508
ld hl, OBJECT_FLAGS1
add hl, bc
bit SLIDING, [hl]
jp nz, SetFacingCurrent
ld hl, OBJECT_STEP_FRAME
add hl, bc
inc [hl]
ld a, [hl]
rrca
rrca
rrca
and %00000011
ld d, a
call GetSpriteDirection
or FACING_STEP_DOWN_0 ; useless
or d
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], a
ret
; 4529
SetFacingCounterclockwiseSpin: ; 4529
call CounterclockwiseSpinAction
ld hl, OBJECT_FACING
add hl, bc
ld a, [hl]
or FACING_STEP_DOWN_0 ; useless
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], a
ret
; 4539
SetFacingCounterclockwiseSpin2: ; 4539
call CounterclockwiseSpinAction
jp SetFacingStanding
; 453f
CounterclockwiseSpinAction: ; 453f
; Here, OBJECT_STEP_FRAME consists of two 2-bit components,
; using only bits 0,1 and 4,5.
; bits 0,1 is a timer (4 overworld frames)
; bits 4,5 determines the facing - the direction is counterclockwise.
ld hl, OBJECT_STEP_FRAME
add hl, bc
ld a, [hl]
and %11110000
ld e, a
ld a, [hl]
inc a
and %00001111
ld d, a
cp 4
jr c, .ok
ld d, 0
ld a, e
add $10
and %00110000
ld e, a
.ok
ld a, d
or e
ld [hl], a
swap e
ld d, 0
ld hl, .Directions
add hl, de
ld a, [hl]
ld hl, OBJECT_FACING
add hl, bc
ld [hl], a
ret
; 456a
.Directions: ; 456a
db OW_DOWN, OW_RIGHT, OW_UP, OW_LEFT
; 456e
SetFacingFish: ; 456e
call GetSpriteDirection
rrca
rrca
add FACING_FISH_DOWN
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], a
ret
; 457b
SetFacingShadow: ; 457b
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], FACING_SHADOW
ret
; 4582
SetFacingEmote: ; 4582 emote
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], FACING_EMOTE
ret
; 4589
SetFacingBigDollSym: ; 4589
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], FACING_BIG_DOLL_SYM
ret
; 4590
SetFacingBounce: ; 4590
ld hl, OBJECT_STEP_FRAME
add hl, bc
ld a, [hl]
inc a
and %00001111
ld [hl], a
and %00001000
jr z, SetFacingFreezeBounce
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], FACING_STEP_UP_0
ret
; 45a4
SetFacingFreezeBounce: ; 45a4
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], FACING_STEP_DOWN_0
ret
; 45ab
SetFacingWeirdTree: ; 45ab
ld hl, OBJECT_STEP_FRAME
add hl, bc
ld a, [hl]
inc a
ld [hl], a
and %00001100
rrca
rrca
add FACING_WEIRD_TREE_0
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], a
ret
; 45be
SetFacingBigDollAsym: ; 45be
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], FACING_BIG_DOLL_ASYM
ret
; 45c5
SetFacingBigDoll: ; 45c5
ld a, [wVariableSprites + SPRITE_BIG_DOLL - SPRITE_VARS]
ld d, FACING_BIG_DOLL_SYM ; symmetric
cp SPRITE_BIG_SNORLAX
jr z, .ok
cp SPRITE_BIG_LAPRAS
jr z, .ok
ld d, FACING_BIG_DOLL_ASYM ; asymmetric
.ok
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], d
ret
; 45da
SetFacingBoulderDust: ; 45da
ld hl, OBJECT_STEP_FRAME
add hl, bc
inc [hl]
ld a, [hl]
ld hl, OBJECT_FACING_STEP
add hl, bc
and 2
ld a, FACING_BOULDER_DUST_1
jr z, .ok
inc a ; FACING_BOULDER_DUST_2
.ok
ld [hl], a
ret
; 45ed
SetFacingGrassShake: ; 45ed
ld hl, OBJECT_STEP_FRAME
add hl, bc
inc [hl]
ld a, [hl]
ld hl, OBJECT_FACING_STEP
add hl, bc
and 4
ld a, FACING_GRASS_1
jr z, .ok
inc a ; FACING_GRASS_2
.ok
ld [hl], a
ret
; 4600

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,70 @@
LoadObjectMasks: ; 2454f
ld hl, wObjectMasks
xor a
ld bc, NUM_OBJECTS
call ByteFill
nop
ld bc, wMapObjects
ld de, wObjectMasks
xor a
.loop
push af
push bc
push de
call GetObjectTimeMask
jr c, .next
call CheckObjectFlag
.next
pop de
ld [de], a
inc de
pop bc
ld hl, OBJECT_LENGTH
add hl, bc
ld b, h
ld c, l
pop af
inc a
cp NUM_OBJECTS
jr nz, .loop
ret
CheckObjectFlag: ; 2457d (9:457d)
ld hl, MAPOBJECT_SPRITE
add hl, bc
ld a, [hl]
and a
jr z, .masked
ld hl, MAPOBJECT_EVENT_FLAG
add hl, bc
ld a, [hli]
ld e, a
ld a, [hl]
ld d, a
cp -1
jr nz, .check
ld a, e
cp -1
jr z, .unmasked
jr .masked
.check
ld b, CHECK_FLAG
call EventFlagAction
ld a, c
and a
jr nz, .masked
.unmasked
xor a
ret
.masked
ld a, -1
scf
ret
GetObjectTimeMask: ; 245a7 (9:45a7)
call CheckObjectTime
ld a, -1
ret c
xor a
ret

View File

@@ -0,0 +1,260 @@
RunMapSetupScript:: ; 15363
ld a, [hMapEntryMethod]
and $f
dec a
ld c, a
ld b, 0
ld hl, MapSetupScripts
add hl, bc
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
call ReadMapSetupScript
ret
; 15377
INCLUDE "data/maps/setup_scripts.asm"
ReadMapSetupScript: ; 1541d
.loop
ld a, [hli]
cp -1
ret z
push hl
ld c, a
ld b, 0
ld hl, MapSetupCommands
add hl, bc
add hl, bc
add hl, bc
; bank
ld b, [hl]
inc hl
; address
ld a, [hli]
ld h, [hl]
ld l, a
; Bit 7 of the bank indicates a parameter.
; This is left unused.
bit 7, b
jr z, .go
pop de
ld a, [de]
ld c, a
inc de
push de
.go
ld a, b
and $7f
rst FarCall
pop hl
jr .loop
; 15440
MapSetupCommands: ; 15440
; entries correspond to command indexes in constants/map_setup_constants.asm
dba EnableLCD ; 00
dba DisableLCD ; 01
dba MapSetup_Sound_Off ; 02
dba PlayMapMusic ; 03
dba RestartMapMusic ; 04
dba FadeToMapMusic ; 05
dba RotatePalettesRightMapAndMusic ; 06
dba EnterMapMusic ; 07
dba ForceMapMusic ; 08
dba FadeInMusic ; 09
dba LoadBlockData ; 0a (callback 1)
dba LoadNeighboringBlockData ; 0b
dba SaveScreen ; 0c
dba BufferScreen ; 0d
dba LoadGraphics ; 0e
dba LoadTileset ; 0f
dba LoadMapTimeOfDay ; 10
dba LoadMapPalettes ; 11
dba LoadWildMonData ; 12
dba RefreshMapSprites ; 13
dba HandleNewMap ; 14
dba InitCommandQueue ; 15
dba LoadObjectsRunCallback_02 ; 16
dba LoadSpawnPoint ; 17
dba EnterMapConnection ; 18
dba LoadWarpData ; 19
dba LoadMapAttributes ; 1a
dba LoadMapAttributes_SkipPeople ; 1b
dba ClearBGPalettes ; 1c
dba FadeOutPalettes ; 1d
dba FadeInPalettes ; 1e
dba GetCoordOfUpperLeftCorner ; 1f
dba RestoreFacingAfterWarp ; 20
dba SpawnInFacingDown ; 21
dba SpawnPlayer ; 22
dba RefreshPlayerCoords ; 23
dba DelayClearingOldSprites ; 24
dba DelayLoadingNewSprites ; 25
dba UpdateRoamMons ; 26
dba JumpRoamMons ; 27
dba FadeOldMapMusic ; 28
dba ActivateMapAnims ; 29
dba SuspendMapAnims ; 2a
dba RetainOldPalettes ; 2b
dba DontScrollText ; 2c
dba ReturnFromMapSetupScript ; 2d
; 154ca
DontScrollText: ; 154ca
xor a
ld [wDisableTextAcceleration], a
ret
; 154cf
ActivateMapAnims: ; 154cf
ld a, $1
ld [hMapAnims], a
ret
; 154d3
SuspendMapAnims: ; 154d3
xor a
ld [hMapAnims], a
ret
; 154d7
LoadObjectsRunCallback_02: ; 154d7
ld a, MAPCALLBACK_OBJECTS
call RunMapCallback
farcall LoadObjectMasks
farcall InitializeVisibleSprites
ret
; 154ea (5:54ea)
; unused
ret
; 154eb
DelayClearingOldSprites: ; 154eb
ld hl, wPlayerSpriteSetupFlags
set PLAYERSPRITESETUP_RESET_ACTION_F, [hl]
ret
; 154f1
DelayLoadingNewSprites: ; 154f1
ld hl, wPlayerSpriteSetupFlags
set PLAYERSPRITESETUP_SKIP_RELOAD_GFX_F, [hl]
ret
CheckReplaceKrisSprite: ; 154f7
nop
call .CheckBiking
jr c, .ok
call .CheckSurfing
jr c, .ok
call .CheckSurfing2
jr c, .ok
ret
.ok
call ReplaceKrisSprite
ret
.CheckBiking: ; 1550c (5:550c)
and a
ld hl, wBikeFlags
bit BIKEFLAGS_ALWAYS_ON_BIKE_F, [hl]
ret z
ld a, PLAYER_BIKE
ld [wPlayerState], a
scf
ret
.CheckSurfing2: ; 1551a (5:551a)
ld a, [wPlayerState]
cp PLAYER_NORMAL
jr z, .nope
cp PLAYER_SKATE
jr z, .nope
cp PLAYER_SURF
jr z, .surfing
cp PLAYER_SURF_PIKA
jr z, .surfing
call GetMapEnvironment
cp INDOOR
jr z, .checkbiking
cp ENVIRONMENT_5
jr z, .checkbiking
cp DUNGEON
jr z, .checkbiking
jr .nope
.checkbiking
ld a, [wPlayerState]
cp PLAYER_BIKE
jr nz, .nope
.surfing
ld a, PLAYER_NORMAL
ld [wPlayerState], a
scf
ret
.nope
and a
ret
.CheckSurfing: ; 1554e (5:554e)
call CheckOnWater
jr nz, .ret_nc
ld a, [wPlayerState]
cp PLAYER_SURF
jr z, ._surfing
cp PLAYER_SURF_PIKA
jr z, ._surfing
ld a, PLAYER_SURF
ld [wPlayerState], a
._surfing
scf
ret
.ret_nc
and a
ret
; 15567
FadeOldMapMusic: ; 15567
ld a, 6
call SkipMusic
ret
; 1556d
RetainOldPalettes: ; 1556d
farcall _UpdateTimePals
ret
RotatePalettesRightMapAndMusic: ; 15574
ld e, 0
ld a, [wMusicFadeID]
ld d, 0
ld a, [wMusicFadeID + 1]
ld a, $4
ld [wMusicFade], a
call RotateThreePalettesRight
ret
; 15587
ForceMapMusic: ; 15587
ld a, [wPlayerState]
cp PLAYER_BIKE
jr nz, .notbiking
call VolumeOff
ld a, $88
ld [wMusicFade], a
.notbiking
call TryRestartMapMusic
ret
; 1559a

File diff suppressed because it is too large Load Diff

573
engine/overworld/npc_movement.asm Executable file

File diff suppressed because it is too large Load Diff

715
engine/overworld/overworld.asm Executable file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

270
engine/overworld/player_step.asm Executable file
View File

@@ -0,0 +1,270 @@
_HandlePlayerStep:: ; d497 (3:5497)
ld a, [wPlayerStepFlags]
and a
ret z
bit 7, a ; starting step
jr nz, .update_overworld_map
bit 6, a ; finishing step
jr nz, .update_player_coords
bit 5, a ; ongoing step
jr nz, .finish
ret
.update_overworld_map
ld a, 4
ld [wHandlePlayerStep], a
call UpdateOverworldMap
jr .finish
.update_player_coords
call UpdatePlayerCoords
jr .finish
.finish
call HandlePlayerStep
ld a, [wPlayerStepVectorX]
ld d, a
ld a, [wPlayerStepVectorY]
ld e, a
ld a, [wPlayerBGMapOffsetX]
sub d
ld [wPlayerBGMapOffsetX], a
ld a, [wPlayerBGMapOffsetY]
sub e
ld [wPlayerBGMapOffsetY], a
ret
ScrollScreen:: ; d4d2 (3:54d2)
ld a, [wPlayerStepVectorX]
ld d, a
ld a, [wPlayerStepVectorY]
ld e, a
ld a, [hSCX]
add d
ld [hSCX], a
ld a, [hSCY]
add e
ld [hSCY], a
ret
HandlePlayerStep: ; d4e5 (3:54e5)
ld hl, wHandlePlayerStep
ld a, [hl]
and a
ret z
dec [hl]
ld a, [hl]
ld hl, .Jumptable
rst JumpTable
ret
.Jumptable: ; d4f2 (3:54f2)
dw GetMovementPermissions
dw BufferScreen
dw .mobile
dw .fail2
; The rest are never used. Ever.
dw .fail1
dw .fail1
dw .fail1
dw .fail1
dw .fail1
dw .fail1
dw .fail1
.fail1 ; d508 (3:5508)
ret
.mobile ; d509 (3:5509)
farcall StubbedTrainerRankings_StepCount
ret
.fail2 ; d510 (3:5510)
ret
UpdatePlayerCoords: ; d511 (3:5511)
ld a, [wPlayerStepDirection]
and a
jr nz, .check_step_down
ld hl, wYCoord
inc [hl]
ret
.check_step_down
cp UP
jr nz, .check_step_left
ld hl, wYCoord
dec [hl]
ret
.check_step_left
cp LEFT
jr nz, .check_step_right
ld hl, wXCoord
dec [hl]
ret
.check_step_right
cp RIGHT
ret nz
ld hl, wXCoord
inc [hl]
ret
UpdateOverworldMap: ; d536 (3:5536)
ld a, [wPlayerStepDirection]
and a
jr z, .step_down
cp UP
jr z, .step_up
cp LEFT
jr z, .step_left
cp RIGHT
jr z, .step_right
ret
.step_down
call .ScrollOverworldMapDown
call LoadMapPart
call ScrollMapUp
ret
.step_up
call .ScrollOverworldMapUp
call LoadMapPart
call ScrollMapDown
ret
.step_left
call .ScrollOverworldMapLeft
call LoadMapPart
call ScrollMapRight
ret
.step_right
call .ScrollOverworldMapRight
call LoadMapPart
call ScrollMapLeft
ret
.ScrollOverworldMapDown: ; d571 (3:5571)
ld a, [wBGMapAnchor]
add 2 * BG_MAP_WIDTH
ld [wBGMapAnchor], a
jr nc, .not_overflowed
ld a, [wBGMapAnchor + 1]
inc a
and %11
or HIGH(vBGMap0)
ld [wBGMapAnchor + 1], a
.not_overflowed
ld hl, wMetatileStandingY
inc [hl]
ld a, [hl]
cp 2 ; was 1
jr nz, .done_down
ld [hl], 0
call .Add6ToOverworldMapAnchor
.done_down
ret
.Add6ToOverworldMapAnchor: ; d595 (3:5595)
ld hl, wOverworldMapAnchor
ld a, [wMapWidth]
add 6
add [hl]
ld [hli], a
ret nc
inc [hl]
ret
.ScrollOverworldMapUp: ; d5a2 (3:55a2)
ld a, [wBGMapAnchor]
sub 2 * BG_MAP_WIDTH
ld [wBGMapAnchor], a
jr nc, .not_underflowed
ld a, [wBGMapAnchor + 1]
dec a
and %11
or HIGH(vBGMap0)
ld [wBGMapAnchor + 1], a
.not_underflowed
ld hl, wMetatileStandingY
dec [hl]
ld a, [hl]
cp -1 ; was 0
jr nz, .done_up
ld [hl], $1
call .Sub6FromOverworldMapAnchor
.done_up
ret
.Sub6FromOverworldMapAnchor: ; d5c6 (3:55c6)
ld hl, wOverworldMapAnchor
ld a, [wMapWidth]
add 6
ld b, a
ld a, [hl]
sub b
ld [hli], a
ret nc
dec [hl]
ret
.ScrollOverworldMapLeft: ; d5d5 (3:55d5)
ld a, [wBGMapAnchor]
ld e, a
and $e0
ld d, a
ld a, e
sub $2
and $1f
or d
ld [wBGMapAnchor], a
ld hl, wMetatileStandingX
dec [hl]
ld a, [hl]
cp -1
jr nz, .done_left
ld [hl], 1
call .DecrementwOverworldMapAnchor
.done_left
ret
.DecrementwOverworldMapAnchor: ; d5f4 (3:55f4)
ld hl, wOverworldMapAnchor
ld a, [hl]
sub 1
ld [hli], a
ret nc
dec [hl]
ret
.ScrollOverworldMapRight: ; d5fe (3:55fe)
ld a, [wBGMapAnchor]
ld e, a
and $e0
ld d, a
ld a, e
add $2
and $1f
or d
ld [wBGMapAnchor], a
ld hl, wMetatileStandingX
inc [hl]
ld a, [hl]
cp 2
jr nz, .done_right
ld [hl], 0
call .IncrementwOverworldMapAnchor
.done_right
ret
.IncrementwOverworldMapAnchor: ; d61d (3:561d)
ld hl, wOverworldMapAnchor
ld a, [hl]
add 1
ld [hli], a
ret nc
inc [hl]
ret

File diff suppressed because it is too large Load Diff

191
engine/overworld/select_menu.asm Executable file
View File

@@ -0,0 +1,191 @@
SelectMenu:: ; 13327
call CheckRegisteredItem
jr c, .NotRegistered
jp UseRegisteredItem
.NotRegistered:
call OpenText
ld b, BANK(ItemMayBeRegisteredText)
ld hl, ItemMayBeRegisteredText
call MapTextbox
call WaitButton
jp CloseText
; 13340
ItemMayBeRegisteredText: ; 13340
text_jump UnknownText_0x1c1cf3
db "@"
; 13345
CheckRegisteredItem: ; 13345
ld a, [wWhichRegisteredItem]
and a
jr z, .NoRegisteredItem
and REGISTERED_POCKET
rlca
rlca
ld hl, .Pockets
rst JumpTable
ret
.Pockets:
; entries correspond to *_POCKET constants
dw .CheckItem
dw .CheckBall
dw .CheckKeyItem
dw .CheckTMHM
.CheckItem:
ld hl, wNumItems
call .CheckRegisteredNo
jr c, .NoRegisteredItem
inc hl
ld e, a
ld d, 0
add hl, de
add hl, de
call .IsSameItem
jr c, .NoRegisteredItem
and a
ret
.CheckKeyItem:
ld a, [wRegisteredItem]
ld hl, wKeyItems
ld de, 1
call IsInArray
jr nc, .NoRegisteredItem
ld a, [wRegisteredItem]
ld [wCurItem], a
and a
ret
.CheckBall:
ld hl, wNumBalls
call .CheckRegisteredNo
jr nc, .NoRegisteredItem
inc hl
ld e, a
ld d, 0
add hl, de
add hl, de
call .IsSameItem
jr c, .NoRegisteredItem
ret
.CheckTMHM:
jr .NoRegisteredItem
.NoRegisteredItem:
xor a
ld [wWhichRegisteredItem], a
ld [wRegisteredItem], a
scf
ret
; 133a6
.CheckRegisteredNo: ; 133a6
ld a, [wWhichRegisteredItem]
and REGISTERED_NUMBER
dec a
cp [hl]
jr nc, .NotEnoughItems
ld [wCurItemQuantity], a
and a
ret
.NotEnoughItems:
scf
ret
; 133b6
.IsSameItem: ; 133b6
ld a, [wRegisteredItem]
cp [hl]
jr nz, .NotSameItem
ld [wCurItem], a
and a
ret
.NotSameItem:
scf
ret
; 133c3
UseRegisteredItem: ; 133c3
farcall CheckItemMenu
ld a, [wItemAttributeParamBuffer]
ld hl, .SwitchTo
rst JumpTable
ret
.SwitchTo:
; entries correspond to ITEMMENU_* constants
dw .CantUse
dw .NoFunction
dw .NoFunction
dw .NoFunction
dw .Current
dw .Party
dw .Overworld
; 133df
.NoFunction: ; 133df
call OpenText
call CantUseItem
call CloseText
and a
ret
; 133ea
.Current: ; 133ea
call OpenText
call DoItemEffect
call CloseText
and a
ret
; 133f5
.Party: ; 133f5
call RefreshScreen
call FadeToMenu
call DoItemEffect
call CloseSubmenu
call CloseText
and a
ret
; 13406
.Overworld: ; 13406
call RefreshScreen
ld a, 1
ld [wUsingItemWithSelect], a
call DoItemEffect
xor a
ld [wUsingItemWithSelect], a
ld a, [wItemEffectSucceeded]
cp 1
jr nz, ._cantuse
scf
ld a, HMENURETURN_SCRIPT
ld [hMenuReturn], a
ret
; 13422
.CantUse: ; 13422
call RefreshScreen
._cantuse
call CantUseItem
call CloseText
and a
ret
; 1342d

View File

@@ -0,0 +1,62 @@
INCLUDE "data/maps/spawn_points.asm"
LoadSpawnPoint: ; 1531f
; loads the spawn point in wDefaultSpawnpoint
push hl
push de
ld a, [wDefaultSpawnpoint]
cp SPAWN_N_A
jr z, .spawn_n_a
ld l, a
ld h, 0
add hl, hl
add hl, hl
ld de, SpawnPoints
add hl, de
ld a, [hli]
ld [wMapGroup], a
ld a, [hli]
ld [wMapNumber], a
ld a, [hli]
ld [wXCoord], a
ld a, [hli]
ld [wYCoord], a
.spawn_n_a
pop de
pop hl
ret
; 15344
IsSpawnPoint: ; 15344
; Checks if the map loaded in de is a spawn point. Returns carry if it's a spawn point.
ld hl, SpawnPoints
ld c, 0
.loop
ld a, [hl]
cp SPAWN_N_A
jr z, .nope
cp d
jr nz, .next
inc hl
ld a, [hld]
cp e
jr z, .yes
.next
push bc
ld bc, 4 ; length of a spawn table entry
add hl, bc
pop bc
inc c
jr .loop
.nope
and a
ret
.yes
scf
ret
; 15363

110
engine/overworld/tile_events.asm Executable file
View File

@@ -0,0 +1,110 @@
CheckWarpCollision:: ; 1499a
; Is this tile a warp?
ld a, [wPlayerStandingTile]
cp COLL_PIT
jr z, .warp
cp COLL_PIT_68
jr z, .warp
and $f0
cp HI_NYBBLE_WARPS
jr z, .warp
and a
ret
.warp
scf
ret
; 149af
CheckDirectionalWarp:: ; 149af
; If this is a directional warp, clear carry (press the designated button to warp).
; Else, set carry (immediate warp).
ld a, [wPlayerStandingTile]
cp COLL_WARP_CARPET_DOWN
jr z, .directional
cp COLL_WARP_CARPET_LEFT
jr z, .directional
cp COLL_WARP_CARPET_UP
jr z, .directional
cp COLL_WARP_CARPET_RIGHT
jr z, .directional
scf
ret
.directional
xor a
ret
; 149c6
CheckWarpFacingDown: ; 149c6
ld de, 1
ld hl, .blocks
ld a, [wPlayerStandingTile]
call IsInArray
ret
; 149d3
.blocks ; 149d3
db COLL_DOOR
db COLL_DOOR_79
db COLL_STAIRCASE
db COLL_STAIRCASE_73
db COLL_CAVE
db COLL_CAVE_74
db COLL_WARP_PANEL
db COLL_DOOR_75
db COLL_DOOR_7D
db -1
; 149dd
CheckGrassCollision:: ; 149dd
ld a, [wPlayerStandingTile]
ld hl, .blocks
ld de, 1
call IsInArray
ret
; 149ea
.blocks ; 149ea
db COLL_CUT_08
db COLL_TALL_GRASS
db COLL_LONG_GRASS
db COLL_CUT_28
db COLL_WATER
db COLL_GRASS_48
db COLL_GRASS_49
db COLL_GRASS_4A
db COLL_GRASS_4B
db COLL_GRASS_4C
db -1
; 149f5
CheckCutCollision: ; 149f5
ld a, c
ld hl, .blocks
ld de, 1
call IsInArray
ret
; 14a00
.blocks ; 14a00
db COLL_CUT_TREE
db COLL_CUT_TREE_1A
db COLL_TALL_GRASS_10
db COLL_TALL_GRASS
db COLL_LONG_GRASS
db COLL_LONG_GRASS_1C
db -1
; 14a07
GetWarpSFX:: ; 14a07
ld a, [wPlayerStandingTile]
ld de, SFX_ENTER_DOOR
cp COLL_DOOR
ret z
ld de, SFX_WARP_TO
cp COLL_WARP_PANEL
ret z
ld de, SFX_EXIT_BUILDING
ret
; 14a1a

465
engine/overworld/time.asm Executable file
View File

@@ -0,0 +1,465 @@
_InitializeStartDay: ; 113d6
call InitializeStartDay
ret
; 113da
ClearDailyTimers: ; 113da
xor a
ld [wLuckyNumberDayBuffer], a
ld [wUnusedTwoDayTimer], a
ld [wDailyResetTimer], a
ret
; 113e5
InitCallReceiveDelay:: ; 113e5
xor a
ld [wTimeCyclesSinceLastCall], a
NextCallReceiveDelay: ; 113e9
ld a, [wTimeCyclesSinceLastCall]
cp 3
jr c, .okay
ld a, 3
.okay
ld e, a
ld d, 0
ld hl, .ReceiveCallDelays
add hl, de
ld a, [hl]
jp RestartReceiveCallDelay
; 113fd
.ReceiveCallDelays:
db 20, 10, 5, 3
; 11401
CheckReceiveCallTimer: ; 11401
call CheckReceiveCallDelay ; check timer
ret nc
ld hl, wTimeCyclesSinceLastCall
ld a, [hl]
cp 3
jr nc, .ok
inc [hl]
.ok
call NextCallReceiveDelay ; restart timer
scf
ret
; 11413
InitOneDayCountdown: ; 11413
ld a, 1
InitNDaysCountdown: ; 11415
ld [hl], a
push hl
call UpdateTime
pop hl
inc hl
call CopyDayToHL
ret
; 11420
CheckDayDependentEventHL: ; 11420
inc hl
push hl
call CalcDaysSince
call GetDaysSince
pop hl
dec hl
call UpdateTimeRemaining
ret
; 1142e
RestartReceiveCallDelay: ; 1142e
ld hl, wReceiveCallDelay_MinsRemaining
ld [hl], a
call UpdateTime
ld hl, wReceiveCallDelay_StartTime
call CopyDayHourMinToHL
ret
; 1143c
CheckReceiveCallDelay: ; 1143c
ld hl, wReceiveCallDelay_StartTime
call CalcMinsHoursDaysSince
call GetMinutesSinceIfLessThan60
ld hl, wReceiveCallDelay_MinsRemaining
call UpdateTimeRemaining
ret
; 1144c
RestartDailyResetTimer: ; 1144c
ld hl, wDailyResetTimer
jp InitOneDayCountdown
; 11452
CheckDailyResetTimer:: ; 11452
ld hl, wDailyResetTimer
call CheckDayDependentEventHL
ret nc
xor a
ld hl, wDailyFlags
ld [hli], a ; wDailyFlags
ld [hli], a ; wWeeklyFlags
ld [hli], a ; wSwarmFlags
ld [hl], a ; wSwarmFlags + 1
ld hl, wDailyRematchFlags
rept 4
ld [hli], a
endr
ld hl, wDailyPhoneItemFlags
rept 4
ld [hli], a
endr
ld hl, wDailyPhoneTimeOfDayFlags
rept 4
ld [hli], a
endr
ld hl, wKenjiBreakTimer
ld a, [hl]
and a
jr z, .RestartKenjiBreakCountdown
dec [hl]
jr nz, .DontRestartKenjiBreakCountdown
.RestartKenjiBreakCountdown:
call SampleKenjiBreakCountdown
.DontRestartKenjiBreakCountdown:
jr RestartDailyResetTimer
; 11485
SampleKenjiBreakCountdown: ; 11485
; Generate a random number between 3 and 6
call Random
and %11
add 3
ld [wKenjiBreakTimer], a
ret
; 11490
StartBugContestTimer: ; 11490
ld a, BUG_CONTEST_MINUTES
ld [wBugContestMinsRemaining], a
ld a, BUG_CONTEST_SECONDS
ld [wBugContestSecsRemaining], a
call UpdateTime
ld hl, wBugContestStartTime
call CopyDayHourMinSecToHL
ret
; 114a4
CheckBugContestTimer:: ; 114a4 (4:54a4)
ld hl, wBugContestStartTime
call CalcSecsMinsHoursDaysSince
ld a, [wDaysSince]
and a
jr nz, .timed_out
ld a, [wHoursSince]
and a
jr nz, .timed_out
ld a, [wSecondsSince]
ld b, a
ld a, [wBugContestSecsRemaining]
sub b
jr nc, .okay
add 60
.okay
ld [wBugContestSecsRemaining], a
ld a, [wMinutesSince]
ld b, a
ld a, [wBugContestMinsRemaining]
sbc b
ld [wBugContestMinsRemaining], a
jr c, .timed_out
and a
ret
.timed_out
xor a
ld [wBugContestMinsRemaining], a
ld [wBugContestSecsRemaining], a
scf
ret
InitializeStartDay: ; 114dd
call UpdateTime
ld hl, wTimerEventStartDay
call CopyDayToHL
ret
; 114e7
CheckPokerusTick:: ; 114e7
ld hl, wTimerEventStartDay
call CalcDaysSince
call GetDaysSince
and a
jr z, .done ; not even a day has passed since game start
ld b, a
farcall ApplyPokerusTick
.done
xor a
ret
; 114fc
SetUnusedTwoDayTimer: ; 114fc
ld a, 2
ld hl, wUnusedTwoDayTimer
ld [hl], a
call UpdateTime
ld hl, wUnusedTwoDayTimerStartDate
call CopyDayToHL
ret
; 1150c
CheckUnusedTwoDayTimer: ; 1150c
ld hl, wUnusedTwoDayTimerStartDate
call CalcDaysSince
call GetDaysSince
ld hl, wUnusedTwoDayTimer
call UpdateTimeRemaining
ret
; 1151c
; unused
ld hl, wDailyFlags
set DAILYFLAGS_FISH_SWARM_F, [hl]
ret
; 11522
; unused
and a
ld hl, wDailyFlags
bit DAILYFLAGS_FISH_SWARM_F, [hl]
ret nz
scf
ret
; 1152b
RestartLuckyNumberCountdown: ; 1152b
call .GetDaysUntilNextFriday
ld hl, wLuckyNumberDayBuffer
jp InitNDaysCountdown
; 11534
.GetDaysUntilNextFriday: ; 11534
call GetWeekday
ld c, a
ld a, FRIDAY
sub c
jr z, .friday_saturday
jr nc, .earlier ; could have done "ret nc"
.friday_saturday
add 7
.earlier
ret
; 11542
_CheckLuckyNumberShowFlag: ; 11542
ld hl, wLuckyNumberDayBuffer
jp CheckDayDependentEventHL
; 11548
DoMysteryGiftIfDayHasPassed: ; 11548
ld a, BANK(sMysteryGiftTimer)
call GetSRAMBank
ld hl, sMysteryGiftTimer
ld a, [hli]
ld [wBuffer1], a
ld a, [hl]
ld [wBuffer2], a
call CloseSRAM
ld hl, wBuffer1
call CheckDayDependentEventHL
jr nc, .not_timed_out
ld hl, wBuffer1
call InitOneDayCountdown
call CloseSRAM
farcall Function1050c8
.not_timed_out
ld a, BANK(sMysteryGiftTimer)
call GetSRAMBank
ld hl, wBuffer1
ld a, [hli]
ld [sMysteryGiftTimer], a
ld a, [hl]
ld [sMysteryGiftTimer + 1], a
call CloseSRAM
ret
; 11586
UpdateTimeRemaining: ; 11586
; If the amount of time elapsed exceeds the capacity of its
; unit, skip this part.
cp -1
jr z, .set_carry
ld c, a
ld a, [hl] ; time remaining
sub c
jr nc, .ok
xor a
.ok
ld [hl], a
jr z, .set_carry
xor a
ret
.set_carry
xor a
ld [hl], a
scf
ret
; 11599
GetSecondsSinceIfLessThan60: ; 11599
ld a, [wDaysSince]
and a
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wHoursSince]
and a
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wMinutesSince]
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wSecondsSince]
ret
; 115ae
GetMinutesSinceIfLessThan60: ; 115ae
ld a, [wDaysSince]
and a
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wHoursSince]
and a
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wMinutesSince]
ret
; 115be
GetHoursSinceIfLessThan24: ; 115be
ld a, [wDaysSince]
and a
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wHoursSince]
ret
; 115c8
GetDaysSince: ; 115c8
ld a, [wDaysSince]
ret
; 115cc
GetTimeElapsed_ExceedsUnitLimit: ; 115cc
ld a, -1
ret
; 115cf
CalcDaysSince: ; 115cf
xor a
jr _CalcDaysSince
; 115d2
CalcHoursDaysSince: ; 115d2
inc hl
xor a
jr _CalcHoursDaysSince
; 115d6
CalcMinsHoursDaysSince: ; 115d6
inc hl
inc hl
xor a
jr _CalcMinsHoursDaysSince
; 115db
CalcSecsMinsHoursDaysSince: ; 115db
inc hl
inc hl
inc hl
ld a, [hSeconds]
ld c, a
sub [hl]
jr nc, .skip
add 60
.skip
ld [hl], c ; current seconds
dec hl
ld [wSecondsSince], a ; seconds since
_CalcMinsHoursDaysSince: ; 115eb
ld a, [hMinutes]
ld c, a
sbc [hl]
jr nc, .skip
add 60
.skip
ld [hl], c ; current minutes
dec hl
ld [wMinutesSince], a ; minutes since
_CalcHoursDaysSince: ; 115f8
ld a, [hHours]
ld c, a
sbc [hl]
jr nc, .skip
add 24
.skip
ld [hl], c ; current hours
dec hl
ld [wHoursSince], a ; hours since
_CalcDaysSince:
ld a, [wCurDay]
ld c, a
sbc [hl]
jr nc, .skip
add 20 * 7
.skip
ld [hl], c ; current days
ld [wDaysSince], a ; days since
ret
; 11613
CopyDayHourMinSecToHL: ; 11613
ld a, [wCurDay]
ld [hli], a
ld a, [hHours]
ld [hli], a
ld a, [hMinutes]
ld [hli], a
ld a, [hSeconds]
ld [hli], a
ret
; 11621
CopyDayToHL: ; 11621
ld a, [wCurDay]
ld [hl], a
ret
; 11626
CopyDayHourToHL: ; 11626
ld a, [wCurDay]
ld [hli], a
ld a, [hHours]
ld [hli], a
ret
; 1162e
CopyDayHourMinToHL: ; 1162e
ld a, [wCurDay]
ld [hli], a
ld a, [hHours]
ld [hli], a
ld a, [hMinutes]
ld [hli], a
ret
; 11639

Some files were not shown because too many files have changed in this diff Show More