summaryrefslogtreecommitdiff
path: root/src/engine
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/bank01.asm6
-rw-r--r--src/engine/bank03.asm76
-rw-r--r--src/engine/bank04.asm1255
-rw-r--r--src/engine/bank05.asm4
-rw-r--r--src/engine/bank06.asm8
-rw-r--r--src/engine/bank07.asm1511
-rw-r--r--src/engine/bank20.asm5
-rw-r--r--src/engine/home.asm42
-rw-r--r--src/engine/sequences/credits_sequence_commands.asm484
-rw-r--r--src/engine/sequences/opening_sequence_commands.asm350
10 files changed, 3345 insertions, 396 deletions
diff --git a/src/engine/bank01.asm b/src/engine/bank01.asm
index 449cd75..358aabf 100644
--- a/src/engine/bank01.asm
+++ b/src/engine/bank01.asm
@@ -1643,7 +1643,7 @@ DrawDuelistPortraitsAndNames: ; 4a97 (1:4a97)
call ProcessText
; player's portrait
lb bc, 0, 5
- call Func_3e10
+ call DrawPlayerPortrait
; opponent's name (aligned to the right)
ld de, wDefaultText
push de
@@ -6159,9 +6159,9 @@ Func_66e9: ; 66e9 (1:66e9)
ret c
ld de, sCurrentDuel
call LoadSavedDuelData
- call Func_3a45
+ call ValidateGeneralSaveData
ret nc
- call Func_3a40
+ call LoadGeneralSaveData
or a
ret
diff --git a/src/engine/bank03.asm b/src/engine/bank03.asm
index 75e3081..3468a54 100644
--- a/src/engine/bank03.asm
+++ b/src/engine/bank03.asm
@@ -28,7 +28,7 @@ LoadMap: ; c000 (3:4000)
call Func_3ca0
ld a, PLAYER_TURN
ldh [hWhoseTurn], a
- farcall Func_1c440
+ farcall ClearNPCs
ld a, [wTempMap]
ld [wCurMap], a
ld a, [wTempPlayerXCoord]
@@ -184,7 +184,7 @@ Func_c158: ; c158 (3:4158)
call GetItemInLoadedNPCIndex
ld a, [wd0c5]
ld [hl], a
- farcall Func_1c58e
+ farcall UpdateNPCAnimation
.asm_c179
ret
@@ -238,10 +238,10 @@ Func_c1b1: ; c1b1 (3:41b1)
ld [wTempPlayerYCoord], a
ld a, SOUTH
ld [wTempPlayerDirection], a
- call Func_c9cb
- call Func_c9dd
+ call ClearEvents
+ call DetermineImakuniAndChallengeHall
farcall Func_80b7a
- farcall Func_1c82e
+ farcall ClearMasterBeatenList
farcall Func_131b3
xor a
ld [wPlayTimeCounter + 0], a
@@ -252,9 +252,9 @@ Func_c1b1: ; c1b1 (3:41b1)
ret
Func_c1ed: ; c1ed (3:41ed)
- call Func_c9cb
- farcall Func_11416
- call Func_c9dd
+ call ClearEvents
+ farcall LoadBackupSaveData
+ call DetermineImakuniAndChallengeHall
ret
Func_c1f8: ; c1f8 (3:41f8)
@@ -266,7 +266,7 @@ Func_c1f8: ; c1f8 (3:41f8)
ld [wd0c2], a
ld [wDefaultSong], a
ld [wd112], a
- ld [wd3b8], a
+ ld [wRonaldIsInMap], a
call EnableSRAM
ld a, [sAnimationsDisabled]
ld [wAnimationsDisabled], a
@@ -409,7 +409,7 @@ Func_c2db: ; c2db (3:42db)
res 0, [hl]
call Func_c34e
farcall Func_12c5e
- farcall Func_1c6f8
+ farcall SetAllNPCTilePermissions
ld hl, wd0c1
res 7, [hl]
ld hl, wd10f
@@ -698,7 +698,7 @@ Func_c4b9: ; c4b9 (3:44b9)
xor a
ld [wVRAMTileOffset], a
ld [wd4cb], a
- ld a, $1d
+ ld a, PALETTE_29
farcall LoadPaletteData
ld b, $0
ld a, [wConsole]
@@ -759,7 +759,7 @@ HandlePlayerMoveMode: ; c510 (3:4510)
.not_moving
ldh a, [hKeysPressed]
and START
- call nz, OpenStartMenu
+ call nz, OpenPauseMenu
ret
Func_c53d: ; c53d (3:453d)
@@ -1104,18 +1104,18 @@ FindNPCOrObject: ; c71e (3:471e)
scf
ret
-OpenStartMenu: ; c74d (3:474d)
+OpenPauseMenu: ; c74d (3:474d)
push hl
push bc
push de
- call StartMenu
+ call PauseMenu
call CloseAdvancedDialogueBox
pop de
pop bc
pop hl
ret
-StartMenu: ; c75a (3:475a)
+PauseMenu: ; c75a (3:475a)
call PauseSong
ld a, MUSIC_PAUSE_MENU
call PlaySong
@@ -1148,7 +1148,7 @@ StartMenu: ; c75a (3:475a)
Func_c797: ; c797 (3:4797)
ld a, [wd0b8]
ld hl, Unknown_10d98
- farcall Func_111e9
+ farcall InitAndPrintPauseMenu
ret
PointerTable_c7a2: ; c7a2 (3:47a2)
@@ -1245,7 +1245,7 @@ PointerTable_c846: ; c846 (3:4846)
Func_c84e: ; c84e (3:484e)
ld a, [wd0b9]
ld hl, Unknown_10da9
- farcall Func_111e9
+ farcall InitAndPrintPauseMenu
ret
Func_c859: ; c859 (3:4859)
@@ -1430,7 +1430,7 @@ Func_c943: ; c943 (3:4943)
ld a, [wTempNPC]
farcall LoadNPCSpriteData
call Func_c998
- farcall Func_1c485
+ farcall LoadNPC
.next_npc
pop hl
ld bc, NPC_MAP_SIZE
@@ -1458,9 +1458,9 @@ Func_c998: ; c998 (3:4998)
ld b, $e
.not_cgb
ld a, b
- ld [wd3b1], a
+ ld [wNPCAnim], a
ld a, $0
- ld [wd3b2], a
+ ld [wNPCAnimFlags], a
ret
Func_c9b8: ; c9b8 (3:49b8)
@@ -1483,7 +1483,7 @@ Func_c9c7: ; c9c7 (3:49c7)
ld l, MAP_SCRIPT_CLOSE_TEXTBOX
jr CallMapScriptPointerIfExists
-Func_c9cb: ; c9cb (3:49cb)
+ClearEvents: ; c9cb (3:49cb)
push hl
push bc
ld hl, wEventVars
@@ -1500,11 +1500,11 @@ Func_c9cb: ; c9cb (3:49cb)
ret
; Clears temporary event vars before determining Imakuni Room
-Func_c9dd: ; c9dd (3:49dd)
+DetermineImakuniAndChallengeHall: ; c9dd (3:49dd)
xor a
ld [wEventVars + EVENT_VAR_BYTES - 1], a
call DetermineImakuniRoom
- call Func_ca0e
+ call DetermineChallengeHallEvent
ret
; Determines what room Imakuni is in when you reset
@@ -1535,7 +1535,7 @@ ImakuniPossibleRooms: ; ca0a (3:4a04)
db LIGHTNING_CLUB_LOBBY
db WATER_CLUB_LOBBY
-Func_ca0e: ; ca0e (3:4a0e)
+DetermineChallengeHallEvent: ; ca0e (3:4a0e)
ld a, [wOverworldMapSelection]
cp OWMAP_CHALLENGE_HALL
jr z, .done
@@ -2195,7 +2195,7 @@ ScriptCommand_UnloadActiveNPC: ; cdcb (3:4dcb)
ld a, [wScriptNPC]
ld [wLoadedNPCTempIndex], a
Func_cdd1: ; cdd1 (3:4dd1)
- farcall Func_1c50a
+ farcall UnloadNPC
jp IncreaseScriptPointerBy1
ScriptCommand_UnloadChallengeHallNPC: ; cdd8 (3:4dd8)
@@ -2228,7 +2228,7 @@ ScriptCommand_SetChallengeHallNPCCoords: ; cdf5 (3:4df5)
ld [wLoadNPCDirection], a
ld a, [wTempNPC]
farcall LoadNPCSpriteData
- farcall Func_1c485
+ farcall LoadNPC
pop af
ld [wTempNPC], a
pop af
@@ -2255,10 +2255,10 @@ ScriptCommand_MoveActiveNPCByDirection: ; ce26 (3:4e26)
; Moves an NPC given the list of directions pointed to by bc
; set bit 7 to only rotate the NPC
ExecuteNPCMovement: ; ce3a (3:4e3a)
- farcall Func_1c78d
+ farcall StartNPCMovement
.loop
call DoFrameIfLCDEnabled
- farcall Func_1c7de
+ farcall CheckIsAnNPCMoving
jr nz, .loop
jp IncreaseScriptPointerBy3
@@ -2376,7 +2376,7 @@ ScriptCommand_ShowCardReceivedScreen: ; cee2 (3:4ee2)
.show_card
push af
farcall Func_10000
- farcall Func_10031
+ farcall FlashWhiteScreen
pop af
bank1call Func_7594
call WhiteOutDMGPals
@@ -2656,9 +2656,9 @@ ScriptCommand_SetSpriteAttributes: ; d095 (3:5095)
push bc
call GetScriptArgs3AfterPointer
ld a, [wScriptNPC]
- ld l, LOADED_NPC_FIELD_05
+ ld l, LOADED_NPC_FLAGS
call GetItemInLoadedNPCIndex
- res 4, [hl]
+ res NPC_FLAG_DIRECTIONLESS_F, [hl]
ld a, [hl]
or c
ld [hl], a
@@ -2670,7 +2670,7 @@ ScriptCommand_SetSpriteAttributes: ; d095 (3:5095)
ld e, b
.not_cgb
ld a, e
- farcall Func_1c57b
+ farcall SetNPCAnimation
jp IncreaseScriptPointerBy4
ScriptCommand_SetActiveNPCCoords: ; d0be (3:50be)
@@ -2679,7 +2679,7 @@ ScriptCommand_SetActiveNPCCoords: ; d0be (3:50be)
ld a, c
ld c, b
ld b, a
- farcall Func_1c461
+ farcall SetNPCPosition
jp IncreaseScriptPointerBy3
ScriptCommand_DoFrames: ; d0ce (3:50ce)
@@ -2695,7 +2695,7 @@ ScriptCommand_JumpIfActiveNPCCoordsMatch: ; d0d9 (3:50d9)
ld [wLoadedNPCTempIndex], a
ld d, c
ld e, b
- farcall Func_1c477
+ farcall GetNPCPosition
ld a, e
cp c
jp nz, ScriptCommand_JumpIfEventEqual.fail
@@ -2817,7 +2817,7 @@ ScriptCommand_PickChallengeHallOpponent: ; d195 (3:5195)
jp IncreaseScriptPointerBy1
ScriptCommand_OpenMenu: ; d1ad (3:51ad)
- call StartMenu
+ call PauseMenu
jp IncreaseScriptPointerBy1
ScriptCommand_PickChallengeCupPrizeCard: ; d1b3 (3:51b3)
@@ -3025,7 +3025,7 @@ ShowMultichoiceTextbox: ; d28c (3:528c)
ld h, [hl]
ld l, a
ld a, [wd416]
- farcall Func_111e9
+ farcall InitAndPrintPauseMenu
pop hl
inc hl
ld a, [hli]
@@ -3181,7 +3181,7 @@ ScriptCommand_GiftCenter: ; d39d (3:539d)
jp IncreaseScriptPointerBy2
ScriptCommand_PlayCredits: ; d3b9 (3:53b9)
- call Func_3917
+ call GetReceivedLegendaryCards
ld a, GAME_EVENT_CREDITS
ld [wGameEvent], a
ld hl, wd0b4
@@ -3256,7 +3256,7 @@ ScriptCommand_WaitForSongToFinish: ; d42f (3:542f)
ScriptCommand_RecordMasterWin: ; d435 (3:5435)
ld a, c
- farcall Func_1c83d
+ farcall AddMasterBeatenToList
jp IncreaseScriptPointerBy2
ScriptCommand_ChallengeMachine: ; d43d (3:543d)
diff --git a/src/engine/bank04.asm b/src/engine/bank04.asm
index 38b1271..d1d6bfa 100644
--- a/src/engine/bank04.asm
+++ b/src/engine/bank04.asm
@@ -23,20 +23,24 @@ Func_10000: ; 10000 (4:4000)
ld [wVBlankOAMCopyToggle], a
ret
-Func_10031: ; 10031 (4:4031)
+; saves all pals to SRAM, then fills them with white.
+; after flushing, it loads back the saved pals from SRAM.
+FlashWhiteScreen: ; 10031 (4:4031)
ldh a, [hBankSRAM]
+
push af
- ld a, $1
+ ld a, BANK("SRAM1")
call BankswitchSRAM
- call Func_10cbb
+ call CopyPalsToSRAMBuffer
call DisableSRAM
call Func_10b28
call FlushAllPalettes
call EnableLCD
call DoFrameIfLCDEnabled
- call Func_10cea
+ call LoadPalsFromSRAMBuffer
call FlushAllPalettes
pop af
+
call BankswitchSRAM
call DisableSRAM
ret
@@ -51,7 +55,13 @@ Func_1010c: ; 1010c (4:410c)
INCROM $1010c, $10197
Func_10197: ; 10197 (4:4197)
- INCROM $10197, $1029e
+ INCROM $10197, $101df
+
+Func_101df: ; 101df (4:41df)
+ INCROM $101df, $1024f
+
+Func_1024f: ; 1024f (4:424f)
+ INCROM $1024f, $1029e
Medal_1029e: ; 1029e (4:429e)
sub $8
@@ -80,7 +90,7 @@ Medal_1029e: ; 1029e (4:429e)
ld [wTxRam2], a
ld a, [hl]
ld [wTxRam2 + 1], a
- call Func_10031
+ call FlashWhiteScreen
ld a, MUSIC_MEDAL
call PlaySong
ld a, $ff
@@ -148,7 +158,7 @@ GiveBoosterPack: ; 1031b (4:431b)
ld [wTxRam2], a
ld a, [hl]
ld [wTxRam2 + 1], a
- call Func_10031
+ call FlashWhiteScreen
call PauseSong
ld a, MUSIC_BOOSTER_PACK
call PlaySong
@@ -272,7 +282,7 @@ Duel_Init: ; 103d3 (4:43d3)
call Func_3e2a ; LoadDuelistPortrait
ld a, [wMatchStartTheme]
call PlaySong
- call Func_10031
+ call FlashWhiteScreen
call DoFrameIfLCDEnabled
lb bc, $2f, $1d ; cursor tile, tile behind cursor
lb de, 18, 17 ; x, y
@@ -285,10 +295,14 @@ Duel_Init: ; 103d3 (4:43d3)
ret
Unknown_10451: ; 10451 (4:4451)
- INCROM $10451, $10456
+ db 1, 14
+ tx Text0395
+ db $ff
Unknown_10456: ; 10456 (4:4456)
- INCROM $10456, $1045b
+ db 1, 16
+ tx Text0396
+ db $ff
Unknown_1045b: ; 1045b (4:445b)
INCROM $1045b, $1052f
@@ -311,7 +325,7 @@ TryGivePCPack: ; 10a70 (4:4a70)
push bc
push de
ld b, a
- ld c, $f ; number of packs possible
+ ld c, NUM_PC_PACKS
ld hl, wPCPacks
.searchLoop1
ld a, [hli]
@@ -320,7 +334,7 @@ TryGivePCPack: ; 10a70 (4:4a70)
jr z, .quit
dec c
jr nz, .searchLoop1
- ld c, $f
+ ld c, NUM_PC_PACKS
ld hl, wPCPacks
.findFreeSlotLoop
ld a, [hl]
@@ -334,7 +348,7 @@ TryGivePCPack: ; 10a70 (4:4a70)
.foundFreeSlot
ld a, b
- or $80 ; mark pack as unopened
+ or PACK_OPENED ; mark pack as unopened
ld [hl], a
.quit
@@ -343,17 +357,400 @@ TryGivePCPack: ; 10a70 (4:4a70)
pop hl
ret
+; writes wd293 with byte depending on console
+; every entry in the list is $00
Func_10a9b: ; 10a9b (4:4a9b)
- INCROM $10a9b, $10ab4
+ push hl
+ ld a, [wConsole]
+ add LOW(.data_10ab1)
+ ld l, a
+ ld a, HIGH(.data_10ab1)
+ adc $00
+ ld h, a
+ ld a, [hl]
+ ld [wd293], a
+ xor a
+ ld [wd317], a
+ pop hl
+ ret
+
+.data_10ab1
+ db $00 ; CONSOLE_DMG
+ db $00 ; CONSOLE_SGB
+ db $00 ; CONSOLE_CGB
+; 0x10ab4
Func_10ab4: ; 10ab4 (4:4ab4)
- INCROM $10ab4, $10af9
+ ld a, [wLCDC]
+ bit 7, a
+ jr z, .lcd_off
+ ld a, [wd293]
+ ld [wd294], a
+ ld [wd295], a
+ ld [wd296], a
+ ld de, PALRGB_WHITE
+ ld hl, wTempBackgroundPalettesCGB
+ ld bc, NUM_BACKGROUND_PALETTES palettes
+ call FillMemoryWithDE
+ call RestoreFirstColorInOBPals
+ call FadeScreenToTempPals
+ call DisableLCD
+ ret
+
+.lcd_off
+ ld a, [wd293]
+ ld [wBGP], a
+ ld [wOBP0], a
+ ld [wOBP1], a
+ ld de, PALRGB_WHITE
+ ld hl, wBackgroundPalettesCGB
+ ld bc, NUM_BACKGROUND_PALETTES palettes
+ call FillMemoryWithDE
+ call FlushAllPalettes
+ ret
+; 0x10af9
Func_10af9: ; 10af9 (4:4af9)
- INCROM $10af9, $10b28
+ call BackupPalsAndSetWhite
+ call RestoreFirstColorInOBPals
+ call FlushAllPalettes
+ call EnableLCD
+ jp FadeScreenToTempPals
+; 0x10b08
+
+BackupPalsAndSetWhite: ; 10b08 (4:4b08)
+ ld a, [wBGP]
+ ld [wd294], a
+ ld a, [wOBP0]
+ ld [wd295], a
+ ld a, [wOBP1]
+ ld [wd296], a
+ ld hl, wBackgroundPalettesCGB
+ ld de, wTempBackgroundPalettesCGB
+ ld bc, NUM_BACKGROUND_PALETTES palettes + NUM_OBJECT_PALETTES palettes
+ call CopyDataHLtoDE_SaveRegisters
+ jr Func_10b28 ; can be fallthrough
+; fills wBackgroundPalettesCGB with white pal
Func_10b28: ; 10b28 (4:4b28)
- INCROM $10b28, $10c96
+ ld a, [wd293]
+ ld [wBGP], a
+ ld [wOBP0], a
+ ld [wOBP1], a
+ ld de, PALRGB_WHITE
+ ld hl, wBackgroundPalettesCGB
+ ld bc, NUM_BACKGROUND_PALETTES palettes
+ call FillMemoryWithDE
+ ret
+; 0x10b41
+
+; gets from backup OB pals the first color
+; of each pal and writes them in wObjectPalettesCGB
+RestoreFirstColorInOBPals: ; 10b41 (4:4b41)
+ ld hl, wTempObjectPalettesCGB
+ ld de, wObjectPalettesCGB
+ ld c, NUM_OBJECT_PALETTES
+.loop_pals
+ push bc
+ ld a, [hli]
+ ld [de], a
+ inc de
+ ld a, [hl]
+ ld [de], a
+ ld bc, CGB_PAL_SIZE - 1
+ add hl, bc
+ ld a, c
+ add e
+ ld e, a
+ ld a, b
+ adc d
+ ld d, a
+ pop bc
+ dec c
+ jr nz, .loop_pals
+ ret
+; 0x10b5e
+
+FadeScreenToTempPals: ; 10b5e (4:4b5e)
+ ld a, [wVBlankCounter]
+ push af
+ ld c, $10
+.loop
+ push bc
+ ld a, c
+ and %11
+ cp 0
+ call z, Func_10b85
+ call FadeBGPalIntoTemp3
+ call FadeOBPalIntoTemp
+ call FlushAllPalettes
+ call DoFrameIfLCDEnabled
+ pop bc
+ dec c
+ dec c
+ jr nz, .loop
+ pop af
+ ld b, a
+ ld a, [wVBlankCounter]
+ sub b
+ ret
+; 0x10b85
+
+; does something with wBGP given wd294
+; mixes them into a single value?
+Func_10b85: ; 10b85 (4:4b85)
+ push bc
+ ld c, $03
+ ld hl, wBGP
+ ld de, wd294
+.asm_10b8e
+ push bc
+ ld b, [hl]
+ ld a, [de]
+ ld c, a
+ call .Func_10b9e
+ ld [hl], a
+ pop bc
+ inc de
+ inc hl
+ dec c
+ jr nz, .asm_10b8e
+ pop bc
+ ret
+
+.Func_10b9e
+ push bc
+ push de
+ ld e, 4
+ ld d, $00
+.loop
+ call .Func_10bba
+ or d
+ rlca
+ rlca
+ ld d, a
+ rlc b
+ rlc b
+ rlc c
+ rlc c
+ dec e
+ jr nz, .loop
+ ld a, d
+ pop de
+ pop bc
+ ret
+
+; calculates ((b & %11) << 2) | (c & %11)
+; that is, %0000xxyy, where x and y are
+; the 2 lower bits of b and c respectively
+; and outputs the entry from a table given that value
+.Func_10bba
+ push hl
+ push bc
+ ld a, %11
+ and b
+ add a
+ add a
+ ld b, a
+ ld a, %11
+ and c
+ or b
+ ld c, a
+ ld b, $00
+ ld hl, .data_10bd1
+ add hl, bc
+ ld a, [hl]
+ pop bc
+ pop hl
+ ret
+
+.data_10bd1
+ db %00 ; b = %00 | c = %00
+ db %01 ; b = %00 | c = %01
+ db %01 ; b = %00 | c = %10
+ db %01 ; b = %00 | c = %11
+ db %00 ; b = %01 | c = %00
+ db %01 ; b = %01 | c = %01
+ db %10 ; b = %01 | c = %10
+ db %10 ; b = %01 | c = %11
+ db %01 ; b = %10 | c = %00
+ db %01 ; b = %10 | c = %01
+ db %10 ; b = %10 | c = %10
+ db %11 ; b = %10 | c = %11
+ db %10 ; b = %11 | c = %00
+ db %10 ; b = %11 | c = %01
+ db %10 ; b = %11 | c = %10
+ db %11 ; b = %11 | c = %11
+; 0x10be1
+
+FadeOBPalIntoTemp: ; 10be1 (4:4be1)
+ push bc
+ ld c, 4 palettes
+ ld hl, wObjectPalettesCGB
+ ld de, wTempObjectPalettesCGB
+ jr FadePalIntoAnother
+; 0x10bec
+
+FadeBGPalIntoTemp1: ; 10bec (4:4bec)
+ push bc
+ ld c, 2 palettes
+ ld hl, wBackgroundPalettesCGB
+ ld de, wTempBackgroundPalettesCGB
+ jr FadePalIntoAnother
+
+FadeBGPalIntoTemp2: ; 10bf7 (4:4bf7)
+ push bc
+ ld c, 2 palettes
+ ld hl, wBackgroundPalettesCGB + 4 palettes
+ ld de, wTempBackgroundPalettesCGB + 4 palettes
+ jr FadePalIntoAnother
+
+FadeBGPalIntoTemp3: ; 10c02 (4:4c02)
+ push bc
+ ld c, 4 palettes
+ ld hl, wBackgroundPalettesCGB
+ ld de, wTempBackgroundPalettesCGB
+; fallthrough
+
+; hl = input pal to modify
+; de = pal to fade into
+; c = number of colors to fade
+FadePalIntoAnother: ; 10c0b (4:4c0b)
+ push bc
+ ld a, [de]
+ inc de
+ ld c, a
+ ld a, [de]
+ inc de
+ ld b, a
+ push de
+ push bc
+ ld c, [hl]
+ inc hl
+ ld b, [hl]
+ pop de
+ call .GetFadedColor
+ ; overwrite with new color
+ ld [hld], a
+ ld [hl], c
+ inc hl
+ inc hl
+ pop de
+ pop bc
+ dec c
+ jr nz, FadePalIntoAnother
+ pop bc
+ ret
+
+; fade pal bc to de
+; output resulting pal in a and c
+.GetFadedColor
+ push hl
+ ld a, c
+ cp e
+ jr nz, .unequal
+ ld a, b
+ cp d
+ jr z, .skip
+
+.unequal
+ ; red
+ ld a, e
+ and %11111
+ ld l, a
+ ld a, c
+ and %11111
+ call .FadeColor
+ ldh [hffb6], a
+
+ ; green
+ ld a, e
+ and %11100000
+ ld l, a
+ ld a, d
+ and %11
+ or l
+ swap a
+ rrca
+ ld l, a
+ ld a, c
+ and %11100000
+ ld h, a
+ ld a, b
+ and %11
+ or h
+ swap a
+ rrca
+ call .FadeColor
+ rlca
+ swap a
+ ld h, a
+ and %11
+ ldh [hffb7], a
+ ld a, %11100000
+ and h
+ ld h, a
+ ldh a, [hffb6]
+ or h
+ ld h, a
+
+ ; blue
+ ld a, d
+ and %1111100
+ rrca
+ rrca
+ ld l, a
+ ld a, b
+ and %1111100
+ rrca
+ rrca
+ call .FadeColor
+ rlca
+ rlca
+ ld b, a
+ ldh a, [hffb7]
+ or b
+ ld c, h
+.skip
+ pop hl
+ ret
+
+; compares color in a and in l
+; if a is smaller/greater than l, then
+; increase/decrease its value up to l
+; up to a maximum of 4
+; a = pal color (red, green or blue)
+; l = pal color (red, green or blue)
+.FadeColor
+ cp l
+ ret z ; same value
+ jr c, .incr_a
+; decr a
+ dec a
+ cp l
+ ret z
+ dec a
+ cp l
+ ret z
+ dec a
+ cp l
+ ret z
+ dec a
+ ret
+
+.incr_a
+ inc a
+ cp l
+ ret z
+ inc a
+ cp l
+ ret z
+ inc a
+ cp l
+ ret z
+ inc a
+ ret
+; 0x10c96
Func_10c96: ; 10c96 (4:4c96)
ldh a, [hBankSRAM]
@@ -361,13 +758,13 @@ Func_10c96: ; 10c96 (4:4c96)
push bc
ld a, $1
call BankswitchSRAM
- call Func_10cbb
+ call CopyPalsToSRAMBuffer
call Func_10ab4
pop bc
ld a, c
or a
jr nz, .asm_10cb0
- call Func_10cea
+ call LoadPalsFromSRAMBuffer
call Func_10af9
.asm_10cb0
@@ -377,11 +774,137 @@ Func_10c96: ; 10c96 (4:4c96)
call DisableSRAM
ret
-Func_10cbb: ; 10cbb (4:4cbb)
- INCROM $10cbb, $10cea
+; copies current BG and OP pals,
+; wBackgroundPalettesCGB and wObjectPalettesCGB
+; to sGfxBuffer2
+CopyPalsToSRAMBuffer: ; 10cbb (4:4cbb)
+ ldh a, [hBankSRAM]
+
+ push af
+ cp BANK("SRAM1")
+ jr z, .ok
+ debug_nop
+.ok
+ ld a, BANK("SRAM1")
+ call BankswitchSRAM
+ ld hl, sGfxBuffer2
+ ld a, [wBGP]
+ ld [hli], a
+ ld a, [wOBP0]
+ ld [hli], a
+ ld a, [wOBP1]
+ ld [hli], a
+ ld e, l
+ ld d, h
+ ld hl, wBackgroundPalettesCGB
+ ld bc, NUM_BACKGROUND_PALETTES palettes + NUM_OBJECT_PALETTES palettes
+ call CopyDataHLtoDE_SaveRegisters
+ pop af
+
+ call BankswitchSRAM
+ call DisableSRAM
+ ret
+; 0x10cea
+
+; loads BG and OP pals,
+; wBackgroundPalettesCGB and wObjectPalettesCGB
+; from sGfxBuffer2
+LoadPalsFromSRAMBuffer: ; 10cea (4:4cea)
+ ldh a, [hBankSRAM]
+
+ push af
+ cp BANK("SRAM1")
+ jr z, .ok
+ debug_nop
+.ok
+ ld a, BANK("SRAM1")
+ call BankswitchSRAM
+ ld hl, sGfxBuffer2
+ ld a, [hli]
+ ld [wBGP], a
+ ld a, [hli]
+ ld [wOBP0], a
+ ld a, [hli]
+ ld [wOBP1], a
+ ld de, wBackgroundPalettesCGB
+ ld bc, NUM_BACKGROUND_PALETTES palettes + NUM_OBJECT_PALETTES palettes
+ call CopyDataHLtoDE_SaveRegisters
+ pop af
+
+ call BankswitchSRAM
+ call DisableSRAM
+ ret
+; 0x10d17
+
+; backs up all palettes
+; and writes 4 BG pals with white pal
+Func_10d17: ; 10d17 (4:4d17)
+ ld a, [wBGP]
+ ld [wd294], a
+ ld a, [wOBP0]
+ ld [wd295], a
+ ld a, [wOBP1]
+ ld [wd296], a
+ ld hl, wBackgroundPalettesCGB
+ ld de, wTempBackgroundPalettesCGB
+ ld bc, NUM_BACKGROUND_PALETTES palettes + NUM_OBJECT_PALETTES palettes
+ call CopyDataHLtoDE_SaveRegisters
+
+ ld a, [wd293]
+ ld [wBGP], a
+ ld de, PALRGB_WHITE
+ ld hl, wBackgroundPalettesCGB
+ ld bc, 4 palettes
+ call FillMemoryWithDE
+ call FlushAllPalettes
-Func_10cea: ; 10cea (4:4cea)
- INCROM $10cea, $10d98
+ ld a, $10
+ ld [wd317], a
+ ret
+; 0x10d50
+
+Func_10d50: ; 10d50 (4:4d50)
+ ld a, [wd293]
+ ld [wd294], a
+ ld a, [wOBP0]
+ ld [wd295], a
+ ld a, [wOBP1]
+ ld [wd296], a
+ ld de, PALRGB_WHITE
+ ld hl, wTempBackgroundPalettesCGB
+ ld bc, 4 palettes
+ call FillMemoryWithDE
+ ld a, $10
+ ld [wd317], a
+ ret
+; 0x10d74
+
+; does stuff according to bottom 2 bits from wd317:
+; - if equal to %01, modify wBGP
+; - if bottom bit not set, fade BG pals 0 and 1
+; - if bottom bit is set, fade BG pals 4 and 5
+; and Flush Palettes
+; then decrements wd317
+; does nothing if wd317 is 0
+Func_10d74: ; 10d74 (4:4d74)
+ ld a, [wd317]
+ or a
+ ret z
+ and %11
+ ld c, a
+ cp $1
+ call z, Func_10b85
+ bit 0, c
+ call z, FadeBGPalIntoTemp1
+ bit 0, c
+ call nz, FadeBGPalIntoTemp2
+ bit 0, c
+ call nz, FlushAllPalettes
+ ld a, [wd317]
+ dec a
+ ld [wd317], a
+ ret
+; 0x10d98
Unknown_10d98: ; 10d98 (4:4d98)
INCROM $10d98, $10da9
@@ -394,7 +917,7 @@ Func_10dba: ; 10dba (4:4dba)
farcall Func_c29b
ld a, [wd0ba]
ld hl, Unknown_10e17
- farcall Func_111e9
+ farcall InitAndPrintPauseMenu
.asm_10dca
call DoFrameIfLCDEnabled
call HandleMenuInput
@@ -1079,17 +1602,153 @@ OverworldMap_ContinuePlayerWalkingAnimation: ; 11184 (4:5184)
dec [hl]
ret
+; prints $ff-terminated list of text to text box
+; given 2 bytes for text alignment and 2 bytes for text ID
Func_111b3: ; 111b3 (4:51b3)
- INCROM $111b3, $111e9
+ ldh a, [hffb0]
+ push af
+ ld a, $02
+ ldh [hffb0], a
-Func_111e9: ; 111e9 (4:51e9)
- INCROM $111e9, $11238
+ push hl
+.loop_text_print_1
+ ld d, [hl]
+ inc hl
+ bit 7, d
+ jr nz, .next
+ inc hl
+ ld a, [hli]
+ push hl
+ ld h, [hl]
+ ld l, a
+ call PrintTextNoDelay
+ pop hl
+ inc hl
+ jr .loop_text_print_1
-Func_11238: ; 11238 (4:5238)
- INCROM $11238, $1124d
+.next
+ pop hl
+ pop af
+ ldh [hffb0], a
+.loop_text_print_2
+ ld d, [hl]
+ inc hl
+ bit 7, d
+ ret nz
+ ld e, [hl]
+ inc hl
+ call AdjustCoordinatesForBGScroll
+ call InitTextPrinting
+ ld a, [hli]
+ push hl
+ ld h, [hl]
+ ld l, a
+ call PrintTextNoDelay
+ pop hl
+ inc hl
+ jr .loop_text_print_2
+; 0x111e9
-Func_1124d: ; 1124d (4:524d)
- INCROM $1124d, $1127f
+InitAndPrintPauseMenu: ; 111e9 (4:51e9)
+ push hl
+ push bc
+ push de
+ push af
+ ld d, [hl]
+ inc hl
+ ld e, [hl]
+ inc hl
+ ld b, [hl]
+ inc hl
+ ld c, [hl]
+ inc hl
+ push hl
+ call AdjustCoordinatesForBGScroll
+ farcall Func_c3ca
+ call DrawRegularTextBox
+ call DoFrameIfLCDEnabled
+ pop hl
+ call Func_111b3
+ pop af
+ call InitializeMenuParameters
+ pop de
+ pop bc
+ pop hl
+ ret
+; 0x1120f
+
+; xors sb800
+; this has the effect of invalidating the save data checksum
+; which the game interprets as being having no save data
+InvalidateSaveData: ; 1120f (4:520f)
+ push hl
+ ldh a, [hBankSRAM]
+
+ push af
+ ld a, $02
+ call BankswitchSRAM
+ ld a, $08
+ xor $ff
+ ld [sb800 + 0], a
+ ld a, $00
+ xor $ff
+ ld [sb800 + 1], a
+ pop af
+
+ call BankswitchSRAM
+ call DisableSRAM
+ call EnableSRAM
+ bank1call DiscardSavedDuelData
+ call DisableSRAM
+ pop hl
+ ret
+; 0x11238
+
+; saves all data to SRAM, including
+; General save data and Album/Deck data
+; and backs up in SRAM2
+SaveAndBackupData: ; 11238 (4:5238)
+ push de
+ ld de, sGeneralSaveData
+ call SaveGeneralSaveDataFromDE
+ ld de, sAlbumProgress
+ call UpdateAlbumProgress
+ call WriteBackupGeneralSaveData
+ call WriteBackupCardAndDeckSaveData
+ pop de
+ ret
+; 0x1124d
+
+_SaveGeneralSaveData: ; 1124d (4:524d)
+ push de
+ call GetReceivedLegendaryCards
+ ld de, sGeneralSaveData
+ call SaveGeneralSaveDataFromDE
+ ld de, sAlbumProgress
+ call UpdateAlbumProgress
+ pop de
+ ret
+; 0x1125f
+
+; de = pointer to general game data in SRAM
+SaveGeneralSaveDataFromDE: ; 1125f (4:525f)
+ push hl
+ push bc
+ call EnableSRAM
+ push de
+ farcall TryGiveMedalPCPacks
+ ld [wMedalCount], a
+ farcall OverworldMap_GetOWMapID
+ ld [wCurOverworldMap], a
+ pop de
+ push de
+ call CopyGeneralSaveDataToSRAM
+ pop de
+ call DisableSRAM
+ pop bc
+ pop hl
+ ret
+; 0x1127f
; writes in de total num of cards collected
; and in (de + 1) total num of cards to collect
@@ -1113,45 +1772,324 @@ UpdateAlbumProgress: ; 1127f (4:527f)
ret
; 0x11299
- INCROM $11299, $11320
+; save values that are listed in WRAMToSRAMMapper
+; from WRAM to SRAM, and calculate its checksum
+CopyGeneralSaveDataToSRAM: ; 11299 (4:5299)
+ push hl
+ push bc
+ push de
+ push de
+ ld hl, sGeneralSaveDataHeaderEnd - sGeneralSaveData
+ add hl, de
+ ld e, l
+ ld d, h
+ xor a
+ ld [wGeneralSaveDataByteCount + 0], a
+ ld [wGeneralSaveDataByteCount + 1], a
+ ld [wGeneralSaveDataCheckSum + 0], a
+ ld [wGeneralSaveDataCheckSum + 1], a
+
+ ld hl, WRAMToSRAMMapper
+.loop_map
+ ld a, [hli]
+ ld [wTempPointer + 0], a
+ ld c, a
+ ld a, [hli]
+ ld [wTempPointer + 1], a
+ or c
+ jr z, .done_copy
+ ld a, [hli]
+ ld c, a ; number of bytes LO
+ ld a, [hli]
+ ld b, a ; number of bytes HI
+ ld a, [wGeneralSaveDataByteCount + 0]
+ add c
+ ld [wGeneralSaveDataByteCount + 0], a
+ ld a, [wGeneralSaveDataByteCount + 1]
+ adc b
+ ld [wGeneralSaveDataByteCount + 1], a
+ call .CopyBytesToSRAM
+ inc hl
+ inc hl
+ jr .loop_map
-Func_11320: ; 11320 (4:5320)
- INCROM $11320, $11343
+.done_copy
+ pop hl
+ ld a, $08
+ ld [hli], a
+ ld a, $00
+ ld [hli], a
+ ld a, [wGeneralSaveDataByteCount + 0]
+ ld [hli], a
+ ld a, [wGeneralSaveDataByteCount + 1]
+ ld [hli], a
+ ld a, [wGeneralSaveDataCheckSum + 0]
+ ld [hli], a
+ ld a, [wGeneralSaveDataCheckSum + 1]
+ ld [hli], a
+ pop de
+ pop bc
+ pop hl
+ ret
-Func_11343: ; 11343 (4:5343)
- INCROM $11343, $11416
+.CopyBytesToSRAM
+ push hl
+ ld a, [wTempPointer + 0]
+ ld l, a
+ ld a, [wTempPointer + 1]
+ ld h, a
+.loop_bytes
+ push bc
+ ld a, [hli]
+ ld [de], a
+ inc de
+ ld c, a
+ ld a, [wGeneralSaveDataCheckSum + 0]
+ add c
+ ld [wGeneralSaveDataCheckSum + 0], a
+ ld a, [wGeneralSaveDataCheckSum + 1]
+ adc 0
+ ld [wGeneralSaveDataCheckSum + 1], a
+ pop bc
+ dec bc
+ ld a, c
+ or b
+ jr nz, .loop_bytes
+ ld a, l
+ ld [wTempPointer + 0], a
+ ld a, h
+ ld [wTempPointer + 1], a
+ pop hl
+ ret
+; 0x11320
-Func_11416: ; 11416 (4:5416)
- INCROM $11416, $11430
+; returns carry if no error
+; is found in sBackupGeneralSaveData
+ValidateBackupGeneralSaveData: ; 11320 (4:5320)
+ push de
+ ldh a, [hBankSRAM]
+ push af
+ ld a, BANK(sBackupGeneralSaveData)
+ call BankswitchSRAM
+ ld de, sBackupGeneralSaveData
+ call ValidateGeneralSaveDataFromDE
+ ld de, sAlbumProgress
+ call LoadAlbumProgressFromSRAM
+ pop af
+ call BankswitchSRAM
+ call DisableSRAM
+ pop de
+ ld a, [wNumSRAMValidationErrors]
+ cp 1
+ ret
+; 0x11343
-Func_11430: ; 11430 (4:5430)
+; returns carry if no error
+; is found in sGeneralSaveData
+_ValidateGeneralSaveData: ; 11343 (4:5343)
push de
- ld de, sb800
- call .Func_11439
+ call EnableSRAM
+ ld de, sGeneralSaveData
+ call ValidateGeneralSaveDataFromDE
+ ld de, sAlbumProgress
+ call LoadAlbumProgressFromSRAM
+ call DisableSRAM
pop de
+ ld a, [wNumSRAMValidationErrors]
+ cp 1
ret
+; 0x1135d
-.Func_11439
+; validates the general game data saved in SRAM
+; de = pointer to general game data in SRAM
+ValidateGeneralSaveDataFromDE: ; 1135d (4:535d)
push hl
push bc
+ push de
+ xor a
+ ld [wNumSRAMValidationErrors], a
+ push de
+
+ push de
+ inc de
+ inc de
+ ld a, [de]
+ inc de
+ ld [wGeneralSaveDataByteCount + 0], a
+ ld a, [de]
+ inc de
+ ld [wGeneralSaveDataByteCount + 1], a
+ ld a, [de]
+ inc de
+ ld [wGeneralSaveDataCheckSum + 0], a
+ ld a, [de]
+ inc de
+ ld [wGeneralSaveDataCheckSum + 1], a
+ pop de
+
+ ld hl, sGeneralSaveDataHeaderEnd - sGeneralSaveData
+ add hl, de
+ ld e, l
+ ld d, h
+ ld hl, WRAMToSRAMMapper
+.loop
+ ld a, [hli]
+ ld c, a
+ ld a, [hli]
+ or c
+ jr z, .exit_loop
+ ld a, [hli]
+ ld c, a ; number of bytes LO
+ ld a, [hli]
+ ld b, a ; number of bytes HI
+ ld a, [wGeneralSaveDataByteCount + 0]
+ sub c
+ ld [wGeneralSaveDataByteCount + 0], a
+ ld a, [wGeneralSaveDataByteCount + 1]
+ sbc b
+ ld [wGeneralSaveDataByteCount + 1], a
+
+; loop all the bytes of this struct
+.loop_bytes
+ push hl
+ push bc
+ ld a, [de]
+ push af
+ ld c, a
+ ld a, [wGeneralSaveDataCheckSum + 0]
+ sub c
+ ld [wGeneralSaveDataCheckSum + 0], a
+ ld a, [wGeneralSaveDataCheckSum + 1]
+ sbc 0
+ ld [wGeneralSaveDataCheckSum + 1], a
+ pop af
+
+ ; check if it's within the specified values
+ cp [hl] ; min value
+ jr c, .error
+ inc hl
+ cp [hl] ; max value
+ jr z, .next_byte
+ jr c, .next_byte
+.error
+ ld a, [wNumSRAMValidationErrors]
+ inc a
+ ld [wNumSRAMValidationErrors], a
+.next_byte
+ inc de
+ pop bc
+ pop hl
+ dec bc
+ ld a, c
+ or b
+ jr nz, .loop_bytes
+ ; next mapped struct
+ inc hl
+ inc hl
+ jr .loop
+
+.exit_loop
+ pop hl
+ ld a, [hli]
+ sub $8
+ ld c, a
+ ld a, [hl]
+ sub 0
+ or c
+ ld hl, wGeneralSaveDataByteCount
+ or [hl]
+ inc hl
+ or [hl]
+ ld hl, wGeneralSaveDataCheckSum
+ or [hl]
+ inc hl
+ or [hl]
+ jr z, .no_header_error
+ ld hl, wNumSRAMValidationErrors
+ inc [hl]
+.no_header_error
+ pop de
+ ; copy play time minutes and hours
+ ld hl, (sPlayTimeCounter + 2) - sGeneralSaveData
+ add hl, de
+ ld a, [hli]
+ ld [wPlayTimeHourMinutes + 0], a
+ ld a, [hli]
+ ld [wPlayTimeHourMinutes + 1], a
+ ld a, [hli]
+ ld [wPlayTimeHourMinutes + 2], a
+
+ ; copy medal count and current overworld map
+ ld hl, sGeneralSaveDataHeaderEnd - sGeneralSaveData
+ add hl, de
+ ld a, [hli]
+ ld [wMedalCount], a
+ ld a, [hl]
+ ld [wCurOverworldMap], a
+ pop bc
+ pop hl
+ ret
+; 0x1140a
+
+LoadAlbumProgressFromSRAM: ; 1140a (4:540a)
+ push de
+ ld a, [de]
+ ld [wTotalNumCardsCollected], a
+ inc de
+ ld a, [de]
+ ld [wTotalNumCardsToCollect], a
+ pop de
+ ret
+; 0x11416
+
+; first copies data from backup SRAM to main SRAM
+; then loads it to WRAM from main SRAM
+LoadBackupSaveData: ; 11416 (4:5416)
+ push hl
+ push de
call EnableSRAM
- call .Func_11447
+ bank1call DiscardSavedDuelData
+ call DisableSRAM
+ call LoadBackupGeneralSaveData
+ call LoadBackupCardAndDeckSaveData
+ ld de, sGeneralSaveData
+ call LoadGeneralSaveDataFromDE
+ pop de
+ pop hl
+ ret
+; 0x11430
+
+_LoadGeneralSaveData: ; 11430 (4:5430)
+ push de
+ ld de, sGeneralSaveData
+ call LoadGeneralSaveDataFromDE
+ pop de
+ ret
+; 0x11439
+
+; de = pointer to save data
+LoadGeneralSaveDataFromDE: ; 11439 (4:5439)
+ push hl
+ push bc
+ call EnableSRAM
+ call .LoadData
call DisableSRAM
pop bc
pop hl
ret
-.Func_11447
+.LoadData
push hl
push bc
push de
ld a, e
- add $08
- ld [wTempPointer], a
+ add sGeneralSaveDataHeaderEnd - sGeneralSaveData
+ ld [wTempPointer + 0], a
ld a, d
adc 0
ld [wTempPointer + 1], a
- ld hl, .wram_map
+
+ ld hl, WRAMToSRAMMapper
.asm_11459
ld a, [hli]
ld e, a
@@ -1166,7 +2104,7 @@ Func_11430: ; 11430 (4:5430)
; copy bc bytes from wTempPointer to de
push hl
- ld a, [wTempPointer]
+ ld a, [wTempPointer + 0]
ld l, a
ld a, [wTempPointer + 1]
ld h, a
@@ -1180,7 +2118,7 @@ Func_11430: ; 11430 (4:5430)
jr nz, .loop_copy
ld a, l
- ld [wTempPointer], a
+ ld [wTempPointer + 0], a
ld a, h
ld [wTempPointer + 1], a
pop hl
@@ -1199,48 +2137,61 @@ Func_11430: ; 11430 (4:5430)
pop bc
pop hl
ret
-
-.wram_map
+; 0x11498
+
+wram_sram_map: MACRO
+ dw \1 ; WRAM address
+ dw \2 ; number of bytes
+ db \3 ; min allowed value
+ db \4 ; max allowed value
+ENDM
+
+; maps WRAM addresses to SRAM addresses in order
+; to save and subsequently retreive them on game load
+; also works as a test in order check whether
+; the saved values is SRAM are legal, within the given value range
+WRAMToSRAMMapper: ; 11498 (4:5498)
; pointer, number of bytes, unknown
- dw wd3cc, 1, $ff00 ; sb808
- dw wd3cb, 1, $ff00 ; sb809
- dw wPlayTimeCounter + 0, 1, $ff00 ; sPlayTimeCounter
- dw wPlayTimeCounter + 1, 1, $ff00
- dw wPlayTimeCounter + 2, 1, $ff00
- dw wPlayTimeCounter + 3, 2, $ff00
- dw wOverworldMapSelection, 1, $ff00 ; sOverworldMapSelection
- dw wTempMap, 1, $ff00 ; sTempMap
- dw wTempPlayerXCoord, 1, $ff00 ; sTempPlayerXCoord
- dw wTempPlayerYCoord, 1, $ff00 ; sTempPlayerYCoord
- dw wTempPlayerDirection, 1, $ff00 ; sTempPlayerDirection
- dw wd0c2, 1, $ff00 ; sb814
- dw wDuelResult, 1, $ff00 ; sDuelResult
- dw wNPCDuelist, 1, $ff00 ; sNPCDuelist
- dw wChallengeHallNPC, 1, $ff00 ; sChallengeHallNPC
- dw wd698, 4, $ff00 ; sb818
- dw wOWMapEvents, 11, $ff00 ; sOWMapEvents
- dw Data_1156c, 1, $ff00 ; sb827
- dw wd0b8, 1, $ff00 ; sb828
- dw wd0b9, 1, $ff00 ; sb829
- dw wd11b, 1, $ff00 ; sb82a
- dw wd0ba, 1, $ff00 ; sb82b
- dw wPCPackSelection, 1, $0e00 ; sPCPackSelection
- dw wPCPacks, 15, $ff00 ; sPCPacks
- dw wDefaultSong, 1, $ff00 ; sDefaultSong
- dw wcad5, 1, $ff00 ; sb83d
- dw wd3b8, 1, $ff00 ; sb83e
- dw wd3bb, 10, $ff00 ; sb83f
- dw wd0c5, 1, $ff00 ; sb849
- dw wMultichoiceTextboxResult_ChooseDeckToDuelAgainst, 1, $ff00 ; sMultichoiceTextboxResult_ChooseDeckToDuelAgainst
- dw wd10e, 1, $ff00 ; sb84b
- dw Data_1156c, 15, $ff00 ; sb84c
- dw Data_1156c, 16, $ff00 ; sb85b
- dw Data_1156c, 16, $ff00 ; sb86b
- dw wEventVars, 64, $ff00 ; sEventVars
+ wram_sram_map wMedalCount, 1, $00, $ff ; sMedalCount
+ wram_sram_map wCurOverworldMap, 1, $00, $ff ; sCurOverworldMap
+ wram_sram_map wPlayTimeCounter + 0, 1, $00, $ff ; sPlayTimeCounter
+ wram_sram_map wPlayTimeCounter + 1, 1, $00, $ff
+ wram_sram_map wPlayTimeCounter + 2, 1, $00, $ff
+ wram_sram_map wPlayTimeCounter + 3, 2, $00, $ff
+ wram_sram_map wOverworldMapSelection, 1, $00, $ff ; sOverworldMapSelection
+ wram_sram_map wTempMap, 1, $00, $ff ; sTempMap
+ wram_sram_map wTempPlayerXCoord, 1, $00, $ff ; sTempPlayerXCoord
+ wram_sram_map wTempPlayerYCoord, 1, $00, $ff ; sTempPlayerYCoord
+ wram_sram_map wTempPlayerDirection, 1, $00, $ff ; sTempPlayerDirection
+ wram_sram_map wd0c2, 1, $00, $ff ; sb814
+ wram_sram_map wDuelResult, 1, $00, $ff ; sDuelResult
+ wram_sram_map wNPCDuelist, 1, $00, $ff ; sNPCDuelist
+ wram_sram_map wChallengeHallNPC, 1, $00, $ff ; sChallengeHallNPC
+ wram_sram_map wd698, 4, $00, $ff ; sb818
+ wram_sram_map wOWMapEvents, NUM_MAP_EVENTS, $00, $ff ; sOWMapEvents
+ wram_sram_map .EmptySRAMSlot, 1, $00, $ff ; sb827
+ wram_sram_map wd0b8, 1, $00, $ff ; sb828
+ wram_sram_map wd0b9, 1, $00, $ff ; sb829
+ wram_sram_map wd11b, 1, $00, $ff ; sb82a
+ wram_sram_map wd0ba, 1, $00, $ff ; sb82b
+ wram_sram_map wPCPackSelection, 1, 0, 14 ; sPCPackSelection
+ wram_sram_map wPCPacks, NUM_PC_PACKS, $00, $ff ; sPCPacks
+ wram_sram_map wDefaultSong, 1, $00, $ff ; sDefaultSong
+ wram_sram_map wcad5, 1, $00, $ff ; sb83d
+ wram_sram_map wRonaldIsInMap, 1, $00, $ff ; sRonaldIsInMap
+ wram_sram_map wMastersBeatenList, 10, $00, $ff ; sMastersBeatenList
+ wram_sram_map wd0c5, 1, $00, $ff ; sb849
+ wram_sram_map wMultichoiceTextboxResult_ChooseDeckToDuelAgainst, 1, $00, $ff ; sMultichoiceTextboxResult_ChooseDeckToDuelAgainst
+ wram_sram_map wd10e, 1, $00, $ff ; sb84b
+ wram_sram_map .EmptySRAMSlot, 15, $00, $ff ; sb84c
+ wram_sram_map .EmptySRAMSlot, 16, $00, $ff ; sb85b
+ wram_sram_map .EmptySRAMSlot, 16, $00, $ff ; sb86b
+ wram_sram_map wEventVars, 64, $00, $ff ; sEventVars
dw NULL
; 0x1156c
-Data_1156c: ; 1156c (4:556c)
+; fills an empty SRAM slot with zero
+.EmptySRAMSlot: ; 1156c (4:556c)
db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
; 0x1157c
@@ -1267,7 +2218,7 @@ _SaveGame: ; 1157c (4:557c)
ld [wOverworldMapSelection], a
.save
- call Func_11238
+ call SaveAndBackupData
ret
_AddCardToCollectionAndUpdateAlbumProgress: ; 115a3 (4:55a3)
@@ -1299,7 +2250,74 @@ _AddCardToCollectionAndUpdateAlbumProgress: ; 115a3 (4:55a3)
ret
; 0x115d4
- INCROM $115d4, $1162a
+WriteBackupCardAndDeckSaveData: ; 115d4 (4:55d4)
+ ld bc, sCardAndDeckSaveDataEnd - sCardAndDeckSaveData
+ ld hl, sCardCollection
+ jr WriteDataToBackup
+
+WriteBackupGeneralSaveData: ; 115dc (4:55dc)
+ ld bc, sGeneralSaveDataEnd - sGeneralSaveData
+ ld hl, sGeneralSaveData
+; fallthrough
+
+; bc = number of bytes to copy to backup
+; hl = pointer in SRAM of data to backup
+WriteDataToBackup: ; 115e2 (4:55e2)
+ ldh a, [hBankSRAM]
+ push af
+.loop
+ xor a ; SRAM0
+ call BankswitchSRAM
+ ld a, [hl]
+ push af
+ ld a, BANK("SRAM2")
+ call BankswitchSRAM
+ pop af
+ ld [hli], a
+ dec bc
+ ld a, b
+ or c
+ jr nz, .loop
+ pop af
+ call BankswitchSRAM
+ call DisableSRAM
+ ret
+; 0x115ff
+
+LoadBackupCardAndDeckSaveData: ; 115ff (4:55ff)
+ ld bc, sCardAndDeckSaveDataEnd - sCardAndDeckSaveData
+ ld hl, sCardCollection
+ jr LoadDataFromBackup
+
+LoadBackupGeneralSaveData: ; 11607 (4:5607)
+ ld bc, sGeneralSaveDataEnd - sGeneralSaveData
+ ld hl, sGeneralSaveData
+; fallthrough
+
+; bc = number of bytes to load from backup
+; hl = pointer in SRAM of backup data
+LoadDataFromBackup: ; 1160d (4:560d)
+ ldh a, [hBankSRAM]
+ push af
+
+.loop
+ ld a, BANK("SRAM2")
+ call BankswitchSRAM
+ ld a, [hl]
+ push af
+ xor a
+ call BankswitchSRAM
+ pop af
+ ld [hli], a
+ dec bc
+ ld a, b
+ or c
+ jr nz, .loop
+ pop af
+ call BankswitchSRAM
+ call DisableSRAM
+ ret
+; 0x1162a
INCLUDE "data/map_scripts.asm"
@@ -1325,17 +2343,17 @@ LoadNPCSpriteData: ; 11857 (4:5857)
ld a, [hli]
ld [wNPCSpriteID], a
ld a, [hli]
- ld [wd3b1], a
+ ld [wNPCAnim], a
ld a, [hli]
push af
ld a, [hli]
- ld [wd3b2], a
+ ld [wNPCAnimFlags], a
pop bc
ld a, [wConsole]
cp CONSOLE_CGB
jr nz, .not_cgb
ld a, b
- ld [wd3b1], a
+ ld [wNPCAnim], a
.not_cgb
pop bc
pop hl
@@ -2812,13 +3830,13 @@ _GameLoop: ; 126d1 (4:66d1)
inc [hl]
farcall SetIntroSGBBorder
ld a, $ff
- ld [wd627], a
+ ld [wLastSelectedStartMenuItem], a
.main_menu_loop
ld a, PLAYER_TURN
ldh [hWhoseTurn], a
farcall Func_c1f8
- farcall Func_1d078
- ld a, [wd628]
+ farcall HandleTitleScreen
+ ld a, [wStartMenuChoice]
ld hl, MainMenuFunctionTable
call JumpToFunctionInTable
jr c, .main_menu_loop ; return to main menu
@@ -2850,7 +3868,7 @@ MainMenu_NewGame: ; 12704 (4:6704)
ld a, MUSIC_OVERWORLD
ld [wDefaultSong], a
call PlayDefaultSong
- farcall Func_1d306
+ farcall DrawPlayerPortraitAndPrintNewGameText
ld a, GAME_EVENT_OVERWORLD
ld [wGameEvent], a
farcall $03, ExecuteGameEvent
@@ -2860,7 +3878,7 @@ MainMenu_NewGame: ; 12704 (4:6704)
MainMenu_ContinueFromDiary: ; 12741 (4:6741)
ld a, MUSIC_STOP
call PlaySong
- call Func_11320
+ call ValidateBackupGeneralSaveData
jr nc, MainMenu_NewGame
farcall Func_c1ed
farcall SetMainSGBBorder
@@ -2888,8 +3906,8 @@ MainMenu_CardPop: ; 12768 (4:6768)
MainMenu_ContinueDuel: ; 1277e (4:677e)
ld a, MUSIC_STOP
call PlaySong
- farcall Func_c9cb
- farcall $04, Func_3a40
+ farcall ClearEvents
+ farcall $04, LoadGeneralSaveData
farcall SetMainSGBBorder
ld a, GAME_EVENT_CONTINUE_DUEL
ld [wGameEvent], a
@@ -2907,7 +3925,22 @@ Func_12871: ; 12871 (4:6871)
INCROM $12871, $1288c
Func_1288c: ; 1288c (4:688c)
- INCROM $1288c, $128a9
+ push hl
+ push bc
+ push de
+ ld a, %11100100
+ ld [wBGP], a
+ ld [wOBP0], a
+ ld [wOBP1], a
+ ld a, 4
+ ld [wTextBoxFrameType], a
+ bank1call SetDefaultPalettes
+ call FlushAllPalettes
+ pop de
+ pop bc
+ pop hl
+ ret
+; 0x128a9
DisplayPlayerNamingScreen:: ; 128a9 (4:68a9)
; clear the name buffer.
@@ -3061,24 +4094,26 @@ FillNewSpriteAnimBufferEntry: ; 129d9 (4:69d9)
pop hl
ret
-Func_129fa: ; 129fa (4:69fa)
+DisableCurSpriteAnim: ; 129fa (4:69fa)
ld a, [wWhichSprite]
; fallthrough
-Func_129fd: ; 129fd (4:69fd)
+; sets SPRITE_ANIM_ENABLED to false
+; of sprite in register a
+DisableSpriteAnim: ; 129fd (4:69fd)
push af
ld a, [wd5d7]
or a
- jr z, .asm_12a06
+ jr z, .disable
pop af
ret
-.asm_12a06
+.disable
pop af
push hl
push bc
ld c, SPRITE_ANIM_ENABLED
call GetSpriteAnimBufferProperty_SpriteInA
- ld [hl], $00
+ ld [hl], FALSE
pop bc
pop hl
ret
@@ -3096,7 +4131,7 @@ GetSpriteAnimCounter: ; 12a13 (4:6a13)
ret
; 0x12a21
-HandleAllSpriteAnimations: ; 12a21 (4:6a21)
+_HandleAllSpriteAnimations: ; 12a21 (4:6a21)
push af
ld a, [wd5d7] ; skip animating this frame if enabled
or a
@@ -3220,6 +4255,8 @@ StartSpriteAnimation: ; 12ac0 (4:6ac0)
ret
; 0x12ac9
+; a = sprite animation
+; c = animation counter value
Func_12ac9: ; 12ac9 (4:6ac9)
push bc
ld b, a
@@ -3259,7 +4296,7 @@ LoadSpriteAnimPointers: ; 12ae2 (4:6ae2)
pop hl ; hl is animation bank
ld a, [wTempPointerBank]
ld [hli], a
- ld a, [wTempPointer]
+ ld a, [wTempPointer + 0]
ld [hli], a
ld c, a
ld a, [wTempPointer + 1]
@@ -3293,7 +4330,7 @@ HandleAnimationFrame: ; 12b13 (4:6b13)
inc hl
inc hl
ld a, [hl] ; SPRITE_ANIM_FRAME_OFFSET_POINTER
- ld [wTempPointer], a
+ ld [wTempPointer + 0], a
add SPRITE_FRAME_OFFSET_SIZE ; advance FRAME_OFFSET_POINTER by 1 frame, 4 bytes
ld [hli], a
ld a, [hl]
@@ -3357,7 +4394,7 @@ GetAnimFramePointerFromOffset: ; 12b6a (4:6b6a)
ld a, [hli]
ld [wTempPointerBank], a
ld a, [hli]
- ld [wTempPointer], a
+ ld [wTempPointer + 0], a
ld a, [hli]
ld [wTempPointer + 1], a
pop hl
diff --git a/src/engine/bank05.asm b/src/engine/bank05.asm
index f8ed5d7..6927121 100644
--- a/src/engine/bank05.asm
+++ b/src/engine/bank05.asm
@@ -7064,10 +7064,10 @@ CheckIfOpponentHasBossDeckID: ; 17414 (5:7414)
ret
; sets carry if not a boss fight
-; and if s0a00a == 0
+; and if hasn't received legendary cards yet
CheckIfNotABossDeckID: ; 17426 (5:7426)
call EnableSRAM
- ld a, [s0a00a]
+ ld a, [sReceivedLegendaryCards]
call DisableSRAM
or a
jr nz, .no_carry
diff --git a/src/engine/bank06.asm b/src/engine/bank06.asm
index 1e728fd..d0c928c 100644
--- a/src/engine/bank06.asm
+++ b/src/engine/bank06.asm
@@ -1955,7 +1955,7 @@ LoadRegistersFromIRDataBuffer: ; 198d0 (6:58d0)
; 0x198e7
; empties screen and replaces
-; wVBlankFunctionTrampoline with Func_3cb4
+; wVBlankFunctionTrampoline with HandleAllSpriteAnimations
Func_198e7: ; 198e7 (6:58e7)
call EmptyScreen
call Set_OBJ_8x8
@@ -1966,9 +1966,9 @@ Func_198e7: ; 198e7 (6:58e7)
ld de, wVBlankFunctionTrampolineBackup
call BackupVBlankFunctionTrampoline
di
- ld [hl], LOW(Func_3cb4)
+ ld [hl], LOW(HandleAllSpriteAnimations)
inc hl
- ld [hl], HIGH(Func_3cb4)
+ ld [hl], HIGH(HandleAllSpriteAnimations)
ei
ret
; 0x19907
@@ -2101,7 +2101,7 @@ Func_1996e: ; 1996e (6:596e)
ld [s0a009], a
ld [s0a004], a
ld [sTotalCardPopsDone], a
- ld [s0a00a], a
+ ld [sReceivedLegendaryCards], a
farcall Func_8cf9
call DisableSRAM
ret
diff --git a/src/engine/bank07.asm b/src/engine/bank07.asm
index 85de56b..2286921 100644
--- a/src/engine/bank07.asm
+++ b/src/engine/bank07.asm
@@ -1,4 +1,55 @@
- INCROM $1c000, $1c056
+Func_1c000: ; 1c000 (7:4000)
+ jp Set_WD_off
+; 0x1c003
+
+; unreferenced debug function
+; prints player's coordinates by pressing B
+; and draws palettes by pressing A
+Func_1c003: ; 1c003 (7:4003)
+ ld a, [wCurMap]
+ or a
+ jr z, Func_1c000
+ ld a, [wOverworldMode]
+ cp OWMODE_START_SCRIPT
+ jr nc, Func_1c000
+
+ ldh a, [hKeysHeld]
+ ld b, a
+ and A_BUTTON | B_BUTTON
+ cp b
+ jr nz, Func_1c000
+ and B_BUTTON
+ jr z, Func_1c000
+
+ ld bc, $20
+ ld a, [wPlayerXCoord]
+ bank1call WriteTwoByteNumberInTxSymbolFormat
+ ld bc, $320
+ ld a, [wPlayerYCoord]
+ bank1call WriteTwoByteNumberInTxSymbolFormat
+ ld a, $77
+ ldh [hWX], a
+ ld a, $88
+ ldh [hWY], a
+
+ ldh a, [hKeysPressed]
+ and A_BUTTON
+ jr z, .skip_load_scene
+ ld a, SCENE_COLOR_PALETTE
+ lb bc, 0, 33
+ call LoadScene
+.skip_load_scene
+ ldh a, [hKeysHeld]
+ and A_BUTTON
+ jr z, .set_wd_on
+ ld a, $67
+ ldh [hWX], a
+ ld a, $68
+ ldh [hWY], a
+.set_wd_on
+ call Set_WD_on
+ ret
+; 0x1c056
Func_1c056: ; 1c056 (7:4056)
push hl
@@ -94,8 +145,22 @@ LoadMapHeader: ; 1c33b (7:433b)
INCLUDE "data/map_headers.asm"
-Func_1c440: ; 1c440 (7:4440)
- INCROM $1c440, $1c455
+ClearNPCs: ; 1c440 (7:4440)
+ push hl
+ push bc
+ ld hl, wLoadedNPCs
+ ld c, LOADED_NPC_MAX * LOADED_NPC_LENGTH
+ xor a
+.loop
+ ld [hli], a
+ dec c
+ jr nz, .loop
+ ld [wNumLoadedNPCs], a
+ ld [wRonaldIsInMap], a
+ pop bc
+ pop hl
+ ret
+; 0x1c455
GetNPCDirection: ; 1c455 (7:4455)
push hl
@@ -106,22 +171,25 @@ GetNPCDirection: ; 1c455 (7:4455)
pop hl
ret
-Func_1c461: ; 1c461 (7:4461)
+; sets new position to active NPC
+; and updates its tile permissions
+; bc = new coords
+SetNPCPosition: ; 1c461 (7:4461)
push hl
push bc
- call Func_1c719
+ call UpdateNPCsTilePermission
ld a, [wLoadedNPCTempIndex]
ld l, LOADED_NPC_COORD_X
call GetItemInLoadedNPCIndex
ld a, b
ld [hli], a
ld [hl], c
- call Func_1c6e3
+ call SetNPCsTilePermission
pop bc
pop hl
ret
-Func_1c477: ; 1c477 (7:4477)
+GetNPCPosition: ; 1c477 (7:4477)
push hl
ld a, [wLoadedNPCTempIndex]
ld l, LOADED_NPC_COORD_X
@@ -133,7 +201,7 @@ Func_1c477: ; 1c477 (7:4477)
ret
; Loads NPC Sprite Data
-Func_1c485: ; 1c485 (7:4485)
+LoadNPC: ; 1c485 (7:4485)
push hl
push bc
push de
@@ -173,65 +241,68 @@ Func_1c485: ; 1c485 (7:4485)
ld [hli], a
ld a, [wLoadNPCDirection]
ld [hli], a
- ld a, [wd3b2]
+ ld a, [wNPCAnimFlags]
ld [hli], a
- ld a, [wd3b1]
+ ld a, [wNPCAnim]
ld [hli], a
ld a, [wLoadNPCDirection]
ld [hli], a
- call Func_1c58e
- call Func_1c5b9
- ld hl, wd349
+ call UpdateNPCAnimation
+ call ApplyRandomCountToNPCAnim
+ ld hl, wNumLoadedNPCs
inc [hl]
pop hl
- call Func_1c665
- call Func_1c6e3
+
+ call UpdateNPCSpritePosition
+ call SetNPCsTilePermission
+
ld a, [wTempNPC]
- call Func_1c4fa
+ call CheckIfNPCIsRonald
jr nc, .exit
- ld a, $01
- ld [wd3b8], a
+ ld a, TRUE
+ ld [wRonaldIsInMap], a
.exit
pop de
pop bc
pop hl
ret
-Func_1c4fa: ; 1c4fa (7:44fa)
+; returns carry if input NPC ID in register a is Ronald
+CheckIfNPCIsRonald: ; 1c4fa (7:44fa)
cp NPC_RONALD1
- jr z, .asm_1c508
+ jr z, .set_carry
cp NPC_RONALD2
- jr z, .asm_1c508
+ jr z, .set_carry
cp NPC_RONALD3
- jr z, .asm_1c508
+ jr z, .set_carry
or a
ret
-.asm_1c508
+.set_carry
scf
ret
-Func_1c50a: ; 1c50a (7:450a)
+UnloadNPC: ; 1c50a (7:450a)
push hl
- call Func_1c719
+ call UpdateNPCsTilePermission
ld a, [wLoadedNPCTempIndex]
call GetLoadedNPCID
ld a, [hl]
or a
- jr z, .asm_1c52c
- call Func_1c4fa
- jr nc, .asm_1c521
- xor a
- ld [wd3b8], a
+ jr z, .exit
+ call CheckIfNPCIsRonald
+ jr nc, .not_ronald
+ xor a ; FALSE
+ ld [wRonaldIsInMap], a
+.not_ronald
-.asm_1c521
xor a
ld [hli], a
ld a, [hl]
- farcall Func_129fd
- ld hl, wd349
+ farcall DisableSpriteAnim
+ ld hl, wNumLoadedNPCs
dec [hl]
-.asm_1c52c
+.exit
pop hl
ret
@@ -239,7 +310,7 @@ Func_1c52e: ; 1c52e (7:452e)
push hl
push af
ld a, [wLoadedNPCTempIndex]
- ld l, LOADED_NPC_FIELD_07
+ ld l, LOADED_NPC_UNKNOWN
call GetItemInLoadedNPCIndex
pop af
ld [hl], a
@@ -254,7 +325,7 @@ Func_1c53f: ; 1c53f (7:453f)
ld l, LOADED_NPC_DIRECTION
call GetItemInLoadedNPCIndex
ld a, [hl]
- ld bc, $0003
+ ld bc, LOADED_NPC_UNKNOWN - LOADED_NPC_DIRECTION
add hl, bc
ld [hl], a
push af
@@ -288,21 +359,22 @@ Func_1c557: ; 1c557 (7:4557)
pop bc
ret
-Func_1c57b: ; 1c57b (7:457b)
+; a = NPC animation
+SetNPCAnimation: ; 1c57b (7:457b)
push hl
push bc
push af
ld a, [wLoadedNPCTempIndex]
- ld l, LOADED_NPC_FIELD_06
+ ld l, LOADED_NPC_ANIM
call GetItemInLoadedNPCIndex
pop af
ld [hl], a
- call Func_1c58e
+ call UpdateNPCAnimation
pop bc
pop hl
ret
-Func_1c58e: ; 1c58e (7:458e)
+UpdateNPCAnimation: ; 1c58e (7:458e)
push hl
push bc
ld a, [wWhichSprite]
@@ -314,13 +386,13 @@ Func_1c58e: ; 1c58e (7:458e)
jr z, .quit
ld a, [hl]
ld [wWhichSprite], a
- ld bc, LOADED_NPC_FIELD_06 - LOADED_NPC_SPRITE
+ ld bc, LOADED_NPC_ANIM - LOADED_NPC_SPRITE
add hl, bc
- ld a, [hld]
- bit 4, [hl]
+ ld a, [hld] ; LOADED_NPC_ANIM
+ bit NPC_FLAG_DIRECTIONLESS_F, [hl] ; LOADED_NPC_FLAGS
jr nz, .asm_1c5ae
dec hl
- add [hl]
+ add [hl] ; LOADED_NPC_ANIM + LOADED_NPC_DIRECTION
inc hl
.asm_1c5ae
farcall StartNewSpriteAnimation
@@ -330,36 +402,250 @@ Func_1c58e: ; 1c58e (7:458e)
pop bc
pop hl
ret
+; 0x1c5b9
-Func_1c5b9: ; 1c5b9 (7:45b9)
- INCROM $1c5b9, $1c5e9
+; if NPC's sprite has an animation,
+; give it a random initial value
+; this makes it so that all NPCs are out of phase
+; when they are loaded into a map
+ApplyRandomCountToNPCAnim: ; 1c5b9 (7:45b9)
+ push hl
+ push bc
+ ld a, [wWhichSprite]
+ push af
+ ld a, [wLoadedNPCTempIndex]
+ call GetLoadedNPCID
+ ld a, [hli]
+ or a
+ jr z, .done
+ ld a, [hl]
+ ld [wWhichSprite], a
+ ld c, SPRITE_ANIM_COUNTER
+ call GetSpriteAnimBufferProperty
+ ld a, [hl]
+ or a
+ jr z, .done
+ cp $ff
+ jr z, .done
+ dec a
+ call Random
+ ld c, a
+ ld a, [hl]
+ sub c
+ ld [hl], a
+.done
+ pop af
+ ld [wWhichSprite], a
+ pop bc
+ pop hl
+ ret
+; 0x1c5e9
+; sets the loaded NPC's direction
+; to the direction that is in LOADED_NPC_UNKNOWN
Func_1c5e9: ; 1c5e9 (7:45e9)
push hl
push bc
ld a, [wLoadedNPCTempIndex]
- ld l, LOADED_NPC_FIELD_07
+ ld l, LOADED_NPC_UNKNOWN
call GetItemInLoadedNPCIndex
ld a, [hl]
- ld bc, -3
+ ld bc, LOADED_NPC_DIRECTION - LOADED_NPC_UNKNOWN
add hl, bc
ld [hl], a
- call Func_1c58e
+ call UpdateNPCAnimation
pop bc
pop hl
ret
; 0x1c5ff
-Func_1c5ff: ; 1c5ff (7:45ff)
- INCROM $1c5ff, $1c610
+; a = new direction
+SetNPCDirection: ; 1c5ff (7:45ff)
+ push hl
+ push af
+ ld a, [wLoadedNPCTempIndex]
+ ld l, LOADED_NPC_DIRECTION
+ call GetItemInLoadedNPCIndex
+ pop af
+ ld [hl], a
+ call UpdateNPCAnimation
+ pop hl
+ ret
+; 0x1c610
+
+HandleAllNPCMovement: ; 1c610 (7:4610)
+ push hl
+ push bc
+ push de
+ xor a
+ ld [wIsAnNPCMoving], a
+ ld a, [wNumLoadedNPCs]
+ or a
+ jr z, .exit
+
+ ld c, LOADED_NPC_MAX
+ ld hl, wLoadedNPCs
+ ld de, LOADED_NPC_LENGTH
+.loop_npcs
+ ld a, [hl]
+ or a
+ jr z, .next_npc
+ push bc
+ inc hl
+ ld a, [hld]
+ ld [wWhichSprite], a
+ call UpdateNPCMovementStep
+ call .UpdateSpriteAnimFlag
+ call UpdateNPCSpritePosition
+ call UpdateIsAnNPCMovingFlag
+ pop bc
+.next_npc
+ add hl, de
+ dec c
+ jr nz, .loop_npcs
+.exit
+ pop de
+ pop bc
+ pop hl
+ ret
+
+.UpdateSpriteAnimFlag
+ push hl
+ push bc
+ ld bc, LOADED_NPC_COORD_X
+ add hl, bc
+ ld b, [hl]
+ inc hl
+ ld c, [hl]
+ call GetPermissionOfMapPosition
+ and $10
+ push af
+ ld c, SPRITE_ANIM_FLAGS
+ call GetSpriteAnimBufferProperty
+ pop af
+ ld a, [hl]
+ jr z, .reset_flag
+ set SPRITE_ANIM_FLAG_UNSKIPPABLE, [hl]
+ jr .done
+.reset_flag
+ res SPRITE_ANIM_FLAG_UNSKIPPABLE, [hl]
+.done
+ pop bc
+ pop hl
+ ret
+; 0x1c665
+
+UpdateNPCSpritePosition: ; 1c665 (7:4665)
+ push hl
+ push bc
+ push de
+ call .GetOffset
+
+ ; get NPC and sprite coords
+ push bc
+ ld de, LOADED_NPC_COORD_X
+ add hl, de
+ ld e, l
+ ld d, h
+ ld c, SPRITE_ANIM_COORD_X
+ call GetSpriteAnimBufferProperty
+ pop bc
+
+ ; hl = sprite coords
+ ; de = NPC coords
+ ld a, [de] ; x
+ sla a
+ sla a
+ sla a
+ add $8
+ sub b
+ ld [hli], a
+ inc de
+ ld a, [de] ; y
+ sla a
+ sla a
+ sla a
+ add $10
+ sub c
+ ld [hli], a
+ pop de
+ pop bc
+ pop hl
+ ret
+
+; outputs in bc the coordinate offsets
+; given NPCs direction and its movement step
+.GetOffset
+ push hl
+ ld bc, $0
+ ld de, LOADED_NPC_FLAGS
+ add hl, de
+ ld e, 0
+ ld a, [hl]
+ and NPC_FLAG_MOVING
+ jr z, .got_direction
+ dec hl
+ ld a, [hl] ; LOADED_NPC_DIRECTION
+ ld de, LOADED_NPC_MOVEMENT_STEP - LOADED_NPC_DIRECTION
+ add hl, de
+ ld e, [hl] ; LOADED_NPC_MOVEMENT_STEP
+.got_direction
+ ld hl, .function_table
+ call JumpToFunctionInTable
+ pop hl
+ ret
+
+.function_table
+ dw .north
+ dw .east
+ dw .south
+ dw .west
+
+.west
+ ld a, e
+ cpl
+ inc a
+ ld e, a
+.east
+ ld b, e
+ ldh a, [hSCX]
+ sub b
+ ld b, a
+ ldh a, [hSCY]
+ ld c, a
+ ret
-Func_1c610: ; 1c610 (7:4610)
- INCROM $1c610, $1c665
+.north
+ ld a, e
+ cpl
+ inc a
+ ld e, a
+.south
+ ld c, e
+ ldh a, [hSCY]
+ sub c
+ ld c, a
+ ldh a, [hSCX]
+ ld b, a
+ ret
+; 0x1c6d3
-Func_1c665: ; 1c665 (7:4665)
- INCROM $1c665, $1c6e3
+; ands wIsAnNPCMoving with the current
+; NPC's NPC_FLAG_MOVING_F
+UpdateIsAnNPCMovingFlag: ; 1c6d3 (7:46d3)
+ push hl
+ push bc
+ ld bc, LOADED_NPC_FLAGS
+ add hl, bc
+ ld a, [wIsAnNPCMoving]
+ or [hl]
+ ld [wIsAnNPCMoving], a
+ pop bc
+ pop hl
+ ret
+; 0x1c6e3
-Func_1c6e3: ; 1c6e3 (7:46e3)
+SetNPCsTilePermission: ; 1c6e3 (7:46e3)
push hl
push bc
ld a, [wLoadedNPCTempIndex]
@@ -374,10 +660,33 @@ Func_1c6e3: ; 1c6e3 (7:46e3)
pop hl
ret
-Func_1c6f8: ; 1c6f8 (7:46f8)
- INCROM $1c6f8, $1c719
+SetAllNPCTilePermissions: ; 1c6f8 (7:46f8)
+ push hl
+ push bc
+ push de
+ ld b, $00
+ ld c, LOADED_NPC_MAX
+ ld hl, wLoadedNPCs
+ ld de, LOADED_NPC_LENGTH
+.loop_npcs
+ ld a, [hl]
+ or a
+ jr z, .next_npc
+ ld a, b
+ ld [wLoadedNPCTempIndex], a
+ call SetNPCsTilePermission
+.next_npc
+ add hl, de
+ inc b
+ dec c
+ jr nz, .loop_npcs
+ pop de
+ pop bc
+ pop hl
+ ret
+; 0x1c719
-Func_1c719: ; 1c719 (7:4719)
+UpdateNPCsTilePermission: ; 1c719 (7:4719)
push hl
push bc
ld a, [wLoadedNPCTempIndex]
@@ -452,7 +761,7 @@ SetNewScriptNPC: ; 1c768 (7:4768)
ld a, [wPlayerDirection]
xor $02
ld [hl], a
- call Func_1c58e
+ call UpdateNPCAnimation
ld a, $02
farcall Func_c29b
ld a, [wLoadedNPCTempIndex]
@@ -462,103 +771,264 @@ SetNewScriptNPC: ; 1c768 (7:4768)
pop hl
ret
-Func_1c78d: ; 1c78d (7:478d)
+StartNPCMovement: ; 1c78d (7:478d)
push hl
+; set NPC as moving
ld a, [wLoadedNPCTempIndex]
- ld l, LOADED_NPC_FIELD_05
+ ld l, LOADED_NPC_FLAGS
call GetItemInLoadedNPCIndex
- set 5, [hl]
+ set NPC_FLAG_MOVING_F, [hl]
+
+; reset its movement step
ld a, [wLoadedNPCTempIndex]
- ld l, LOADED_NPC_FIELD_08
+ ld l, LOADED_NPC_MOVEMENT_STEP
call GetItemInLoadedNPCIndex
xor a
ld [hli], a
-.asm_1c7a2
- ld [hl], c
+.loop_movement
+ ld [hl], c ; LOADED_NPC_MOVEMENT_PTR
inc hl
ld [hl], b
dec hl
call GetNextNPCMovementByte
cp $f0
- jr nc, .asm_1c7bb
+ jr nc, .special_command
push af
- and $7f
- call Func_1c5ff
+ and DIRECTION_MASK
+ call SetNPCDirection
pop af
+ ; if it was not a rotation, exit...
bit 7, a
- jr z, .asm_1c7dc
+ jr z, .exit
+ ; ...otherwise jump to next movement instruction
inc bc
- jr .asm_1c7a2
+ jr .loop_movement
-.asm_1c7bb
+.special_command
cp $ff
- jr z, .asm_1c7d2
+ jr z, .stop_movement
+; jump to a movement command
+ ; read its argument
inc bc
call GetNextNPCMovementByte
push hl
ld l, a
ld h, $0
bit 7, l
- jr z, .asm_1c7cc
- dec h
-
-.asm_1c7cc
+ jr z, .got_offset
+ dec h ; $ff
+.got_offset
+ ; add the offset to bc
add hl, bc
ld c, l
ld b, h
pop hl
- jr .asm_1c7a2
+ jr .loop_movement
-.asm_1c7d2
+.stop_movement
ld a, [wLoadedNPCTempIndex]
- ld l, LOADED_NPC_FIELD_05
+ ld l, LOADED_NPC_FLAGS
call GetItemInLoadedNPCIndex
- res 5, [hl]
+ res NPC_FLAG_MOVING_F, [hl]
-.asm_1c7dc
+.exit
pop hl
ret
-Func_1c7de: ; 1c7de (7:47de)
- ld a, [wc3b7]
- and $20
+; returns nz if there is an NPC currently moving
+CheckIsAnNPCMoving: ; 1c7de (7:47de)
+ ld a, [wIsAnNPCMoving]
+ and NPC_FLAG_MOVING
ret
; 0x1c7e4
- INCROM $1c7e4, $1c82e
+; while the NPC is moving, increment its movement step by 1
+; once it reaches a value greater than 16, update
+; its tile permission and its position and start next movement
+UpdateNPCMovementStep: ; 1c7e4 (7:47e4)
+ push hl
+ push bc
+ push de
+ ld bc, LOADED_NPC_FLAGS
+ add hl, bc
+ bit NPC_FLAG_MOVING_F, [hl]
+ jr z, .exit
+ ld bc, LOADED_NPC_MOVEMENT_STEP - LOADED_NPC_FLAGS
+ add hl, bc
+ inc [hl] ; increment movement step
+ bit 4, [hl]
+ jr z, .exit ; still hasn't reached the next tile
+ call UpdateNPCsTilePermission
+ call UpdateNPCPosition
+ inc hl
+ ld c, [hl] ; LOADED_NPC_MOVEMENT_PTR
+ inc hl
+ ld b, [hl]
+ inc bc
+ call StartNPCMovement
+ call SetNPCsTilePermission
+.exit
+ pop de
+ pop bc
+ pop hl
+ ret
+; 0x1c80d
-Func_1c82e: ; 1c82e (7:482e)
- INCROM $1c82e, $1c83d
+UpdateNPCPosition: ; 1c80d (7:480d)
+ push hl
+ push bc
+ ld a, [wLoadedNPCTempIndex]
+ ld l, LOADED_NPC_DIRECTION
+ call GetItemInLoadedNPCIndex
+ ld a, [hld]
+ push hl
+ rlca ; *2
+ ld c, a
+ ld b, $00
+ ld hl, PlayerMovementOffsetTable_Tiles
+ add hl, bc
+ ld b, [hl] ; x offset
+ inc hl
+ ld c, [hl] ; y offset
+ pop hl
+ ld a, [hl] ; LOADED_NPC_COORD_Y
+ add c
+ ld [hld], a
+ ld a, [hl] ; LOADED_NPC_COORD_X
+ add b
+ ld [hl], a
+ pop bc
+ pop hl
+ ret
+; 0x1c82e
-Func_1c83d: ; 1c83d (7:483d)
+ClearMasterBeatenList: ; 1c82e (7:482e)
+ push hl
+ push bc
+ ld c, $a
+ ld hl, wMastersBeatenList
+ xor a
+.loop
+ ld [hli], a
+ dec c
+ jr nz, .loop
+ pop bc
+ pop hl
+ ret
+; 0x1c83d
+
+; writes Master in register a to
+; first empty slot in wMastersBeatenList
+AddMasterBeatenToList: ; 1c83d (7:483d)
push hl
push bc
ld b, a
ld c, $a
- ld hl, wd3bb
-.asm_1c845
+ ld hl, wMastersBeatenList
+.loop
ld a, [hl]
or a
- jr z, .asm_1c853
+ jr z, .found_empty_slot
cp b
- jr z, .asm_1c855
+ jr z, .exit
inc hl
dec c
- jr nz, .asm_1c845
+ jr nz, .loop
debug_nop
- jr .asm_1c855
+ jr .exit
-.asm_1c853
+.found_empty_slot
ld a, b
ld [hl], a
-.asm_1c855
+.exit
pop bc
pop hl
ret
-Func_1c858: ; 1c858 (7:4858)
- INCROM $1c858, $1c8bc
+; iterates all masters and attempts to
+; add each of them to wMastersBeatenList
+AddAllMastersToMastersBeatenList: ; 1c858 (7:4858)
+ ld a, $01
+.loop
+ push af
+ call AddMasterBeatenToList
+ pop af
+ inc a
+ cp $0b
+ jr c, .loop
+ ret
+; 0x1c865
+
+ ret ; stray ret
+
+; unreferenced debug function
+; adjusts hSCX and hSCY by using the arrow keys
+; pressing B makes it scroll faster
+Func_1c866: ; 1c866 (7:4866)
+ ldh a, [hKeysHeld]
+ and B_BUTTON
+ call nz, .asm_1c86d ; executes following part twice
+.asm_1c86d
+ ldh a, [hSCX]
+ ld b, a
+ ldh a, [hSCY]
+ ld c, a
+ ldh a, [hKeysHeld]
+ bit D_UP_F, a
+ jr z, .check_d_down
+ inc c
+.check_d_down
+ bit D_DOWN_F, a
+ jr z, .check_d_left
+ dec c
+.check_d_left
+ bit D_LEFT_F, a
+ jr z, .check_d_right
+ inc b
+.check_d_right
+ bit D_RIGHT_F, a
+ jr z, .asm_1c889
+ dec b
+.asm_1c889
+ ld a, b
+ ldh [hSCX], a
+ ld a, c
+ ldh [hSCY], a
+ ret
+; 0x1c890
+
+; unreferenced
+; sets some flags on a given sprite
+Func_1c890: ; 1c890 (7:4890)
+ ld a, [wVBlankCounter]
+ and %111111
+ ret nz
+
+ ld a, [wd41b]
+ cp $11
+ jr z, .asm_1c8a3
+ cp $0e
+ ret c
+ cp $10
+ ret nc
+
+; wd41b == $11 || (wd41b >= $0e && wd41b < $10)
+.asm_1c8a3
+ ld a, [wd41c]
+ ld [wWhichSprite], a
+ ld c, SPRITE_ANIM_FLAGS
+ call GetSpriteAnimBufferProperty
+ call UpdateRNGSources
+ and (1 << SPRITE_ANIM_FLAG_X_SUBTRACT)
+ jr nz, .asm_1c8b9
+ res SPRITE_ANIM_FLAG_SPEED, [hl]
+ jr .asm_1c8bb
+.asm_1c8b9
+ set SPRITE_ANIM_FLAG_SPEED, [hl]
+.asm_1c8bb
+ ret
+; 0x1c8bc
Func_1c8bc: ; 1c8bc (7:48bc)
push hl
@@ -962,7 +1432,7 @@ Func_1cac5: ; 1cac5 (7:4ac5)
farcall GetSpriteAnimCounter
cp $ff
jr nz, .next
- farcall Func_129fa
+ farcall DisableCurSpriteAnim
ld a, $ff
ld [hl], a
@@ -1019,7 +1489,7 @@ Func_1cb18: ; 1cb18 (7:4b18)
cp $ff
jr z, .asm_1cb4b
ld [wWhichSprite], a
- farcall Func_129fa
+ farcall DisableCurSpriteAnim
ld a, $ff
ld [hl], a
.asm_1cb4b
@@ -1060,7 +1530,7 @@ Func_1cb5e: ; 1cb5e (7:4b5e)
ld [wVRAMTileOffset], a
ld [wd4cb], a
- ld a, $25
+ ld a, PALETTE_37
farcall LoadPaletteData
call Func_1cba6
@@ -1140,7 +1610,9 @@ Func_1cbcc: ; 1cbcc (7:4bcc)
ret
; 0x1cbfd
- INCROM $1cbfd, $1cc03
+; unreferenced data?
+ db $f0, $f8, $00, $08, $f8, $f0
+; 0x1cc03
Func_1cc03: ; 1cc03 (7:4c03)
ld a, [wDuelAnimDamage]
@@ -1429,7 +1901,7 @@ WhiteFlashScreen: ; 1cd76 (7:4d76)
ld de, wTempBackgroundPalettesCGB
ld bc, 8 palettes
call CopyDataHLtoDE_SaveRegisters
- ld de, $7fff ; rgb 31, 31, 31
+ ld de, PALRGB_WHITE
ld hl, wBackgroundPalettesCGB
ld bc, (8 palettes) / 2
call FillMemoryWithDE
@@ -1522,76 +1994,112 @@ Func_1ce03: ; 1ce03 (7:4e03)
INCLUDE "data/duel_animations.asm"
-Func_1d078: ; 1d078 (7:5078)
- ld a, [wd627]
+; plays the Opening sequence, and handles player selection
+; in the Title Screen and Start Menu
+HandleTitleScreen: ; 1d078 (7:5078)
+; if last selected item in Start Menu is 0 (Card Pop!)
+; then skip straight to the Start Menu
+; this makes it so that returning from Card Pop!
+; doesn't play the Opening sequence
+ ld a, [wLastSelectedStartMenuItem]
or a
- jr z, .asm_1d0c7
-.asm_1d07e
+ jr z, .start_menu
+
+.play_opening
ld a, MUSIC_STOP
call PlaySong
call Func_3ca0
- call Func_1d335
- call Func_1d3ce
+ call PlayOpeningSequence
+ call LoadTitleScreenSprites
+
xor a
ld [wd635], a
ld a, $3c
- ld [wd626], a
-.asm_1d095
+ ld [wTitleScreenIgnoreInputCounter], a
+.loop
call DoFrameIfLCDEnabled
call UpdateRNGSources
- call Func_1d614
+ call AnimateRandomTitleScreenOrb
ld hl, wd635
inc [hl]
call AssertSongFinished
or a
- jr nz, .asm_1d0ae
+ jr nz, .song_playing
+ ; reset back to the opening sequence
farcall Func_10ab4
- jr .asm_1d07e
-.asm_1d0ae
- ld hl, wd626
+ jr .play_opening
+
+.song_playing
+ ; should we ignore user input?
+ ld hl, wTitleScreenIgnoreInputCounter
ld a, [hl]
or a
- jr z, .asm_1d0b8
+ jr z, .check_keys
+ ; ignore input, decrement the counter
dec [hl]
- jr .asm_1d095
-.asm_1d0b8
+ jr .loop
+
+.check_keys
ldh a, [hKeysPressed]
and A_BUTTON | START
- jr z, .asm_1d095
+ jr z, .loop
ld a, SFX_02
call PlaySFX
farcall Func_10ab4
-.asm_1d0c7
- call Func_1d0fa
- call Func_1d11c
- ld a, [wd628]
- cp $2
- jr nz, .asm_1d0db
- call Func_1d289
- jr c, Func_1d078
- jr .asm_1d0e7
-.asm_1d0db
- ld a, [wd628]
- cp $1
- jr nz, .asm_1d0e7
- call Func_1d2b8
- jr c, Func_1d078
-.asm_1d0e7
- ld a, [wd628]
- cp $0
- jr nz, .asm_1d0f3
- call Func_1d2dd
- jr c, Func_1d078
-.asm_1d0f3
+.start_menu
+ call CheckIfHasSaveData
+ call HandleStartMenu
+
+; new game
+ ld a, [wStartMenuChoice]
+ cp START_MENU_NEW_GAME
+ jr nz, .continue_from_diary
+ call DeleteSaveDataForNewGame
+ jr c, HandleTitleScreen
+ jr .card_pop
+.continue_from_diary
+ ld a, [wStartMenuChoice]
+ cp START_MENU_CONTINUE_FROM_DIARY
+ jr nz, .card_pop
+ call AskToContinueFromDiaryWithDuelData
+ jr c, HandleTitleScreen
+.card_pop
+ ld a, [wStartMenuChoice]
+ cp START_MENU_CARD_POP
+ jr nz, .continue_duel
+ call ShowCardPopCGBDisclaimer
+ jr c, HandleTitleScreen
+.continue_duel
call ResetDoFrameFunction
call Func_3ca0
ret
+; 0x1d0fa
+
+; updates wHasSaveData and wHasDuelSaveData
+; depending on whether the save data is valid or not
+CheckIfHasSaveData: ; 1d0fa (7:50fa)
+ farcall ValidateBackupGeneralSaveData
+ ld a, TRUE
+ jr c, .no_error
+ ld a, FALSE
+.no_error
+ ld [wHasSaveData], a
+ cp $00 ; or a
+ jr z, .write_has_duel_data
+ bank1call ValidateSavedNonLinkDuelData
+ ld a, TRUE
+ jr nc, .write_has_duel_data
+ ld a, FALSE
+.write_has_duel_data
+ ld [wHasDuelSaveData], a
+ farcall ValidateBackupGeneralSaveData
+ ret
+; 0x1d11c
-Func_1d0fa: ; 1d0fa (7:50fa)
- INCROM $1d0fa, $1d11c
-
-Func_1d11c: ; 1d11c (7:511c)
+; handles printing the Start Menu
+; and getting player input and choice
+HandleStartMenu: ; 1d11c (7:511c)
ld a, MUSIC_PC_MAIN_MENU
call PlaySong
call DisableLCD
@@ -1601,68 +2109,356 @@ Func_1d11c: ; 1d11c (7:511c)
call Func_3ca0
xor a
ld [wLineSeparation], a
- call Func_1d1e1
- call Func_1d17f
+ call .DrawPlayerPortrait
+ call .SetStartMenuParams
+
ld a, $ff
- ld [wd626], a
- ld a, [wd627]
+ ld [wTitleScreenIgnoreInputCounter], a
+ ld a, [wLastSelectedStartMenuItem]
cp $4
- jr c, .asm_1d14f
- ld a, [wd624]
+ jr c, .init_menu
+ ld a, [wHasSaveData]
or a
- jr z, .asm_1d14f
- ld a, $1
-.asm_1d14f
- ld hl, wd636
- farcall Func_111e9
- farcall Func_10031
-.asm_1d15a
+ jr z, .init_menu
+ ld a, 1 ; start at second menu option
+.init_menu
+ ld hl, wStartMenuParams
+ farcall InitAndPrintPauseMenu
+ farcall FlashWhiteScreen
+
+.wait_input
call DoFrameIfLCDEnabled
call UpdateRNGSources
call HandleMenuInput
push af
- call Func_1d1e9
+ call PrintStartMenuDescriptionText
pop af
- jr nc, .asm_1d15a
+ jr nc, .wait_input
ldh a, [hCurMenuItem]
cp e
- jr nz, .asm_1d15a
- ld [wd627], a
- ld a, [wd624]
+ jr nz, .wait_input
+
+ ld [wLastSelectedStartMenuItem], a
+ ld a, [wHasSaveData]
or a
- jr nz, .asm_1d17a
+ jr nz, .no_adjustment
+ ; New Game is 3rd option
+ ; but when there's no save data,
+ ; it's the 1st in menu list, so adjust it
inc e
inc e
-.asm_1d17a
+.no_adjustment
ld a, e
- ld [wd628], a
+ ld [wStartMenuChoice], a
+ ret
+
+.SetStartMenuParams
+ ld hl, .StartMenuParams
+ ld de, wStartMenuParams
+ ld bc, .StartMenuParamsEnd - .StartMenuParams
+ call CopyDataHLtoDE
+
+ ld e, 0
+ ld a, [wHasSaveData]
+ or a
+ jr z, .get_text_id ; New Game
+ inc e
+ ld a, 2
+ call .AddItems
+ ld a, [wHasDuelSaveData]
+ or a
+ jr z, .get_text_id ; Continue From Diary
+ inc e
+ ld a, 1
+ call .AddItems
+ ; Continue Duel
+
+.get_text_id
+ sla e
+ ld d, $00
+ ld hl, .StartMenuTextIDs
+ add hl, de
+ ; set text ID as Start Menu param
+ ld a, [hli]
+ ld [wStartMenuParams + 6], a
+ ld a, [hl]
+ ld [wStartMenuParams + 7], a
+ ret
+
+; adds c items to start menu list
+; this means adding 2 units per item to the text box height
+; and adding to the number of items
+.AddItems
+ push bc
+ ld c, a
+ ; number of items in menu
+ ld a, [wStartMenuParams + 12]
+ add c
+ ld [wStartMenuParams + 12], a
+ ; height of text box
+ sla c
+ ld a, [wStartMenuParams + 3]
+ add c
+ ld [wStartMenuParams + 3], a
+ pop bc
ret
-Func_1d17f: ; 1d17f (7:517f)
- INCROM $1d17f, $1d1e1
+.StartMenuParams
+ db 0, 0 ; start menu coords
+ db 14, 4 ; start menu text box dimensions
+
+ db 2, 2 ; text alignment for InitTextPrinting
+ tx NewGameText
+ db $ff
+
+ db 1, 2 ; cursor x, cursor y
+ db 2 ; y displacement between items
+ db 1 ; number of items
+ db SYM_CURSOR_R ; cursor tile number
+ db SYM_SPACE ; tile behind cursor
+ dw NULL ; function pointer if non-0
+.StartMenuParamsEnd
+
+.StartMenuTextIDs
+ tx NewGameText
+ tx CardPopContinueDiaryNewGameText
+ tx CardPopContinueDiaryNewGameContinueDuelText
+
+.DrawPlayerPortrait
+ lb bc, 14, 1
+ farcall $4, DrawPlayerPortrait
+ ret
+; 0x1d1e9
+
+; prints the description for the current selected item
+; in the Start Menu in the text box
+PrintStartMenuDescriptionText: ; 1d1e9 (7:51e9)
+ push hl
+ push bc
+ push de
+ ; don't print if it's already showing
+ ld a, [wCurMenuItem]
+ ld e, a
+ ld a, [wCurHighlightedStartMenuItem]
+ cp e
+ jr z, .skip
+ ld a, [wHasSaveData]
+ or a
+ jr nz, .has_data
+ ; New Game option is 3rd element
+ ; in function table, so add 2
+ inc e
+ inc e
+.has_data
-Func_1d1e1: ; 1d1e1 (7:51e1)
- INCROM $1d1e1, $1d1e9
+ ld a, e
+ push af
+ lb de, 0, 10
+ lb bc, 20, 8
+ call DrawRegularTextBox
+ pop af
+ ld hl, .StartMenuDescriptionFunctionTable
+ call JumpToFunctionInTable
+.skip
+ ld a, [wCurMenuItem]
+ ld [wCurHighlightedStartMenuItem], a
+ pop de
+ pop bc
+ pop hl
+ ret
-Func_1d1e9: ; 1d1e9 (7:51e9)
- INCROM $1d1e9, $1d289
+.StartMenuDescriptionFunctionTable
+ dw .CardPop
+ dw .ContinueFromDiary
+ dw .NewGame
+ dw .ContinueDuel
+
+.CardPop
+ lb de, 1, 12
+ call InitTextPrinting
+ ldtx hl, WhenYouCardPopWithFriendText
+ call PrintTextNoDelay
+ ret
-Func_1d289: ; 1d289 (7:5289)
- INCROM $1d289, $1d2b8
+.ContinueDuel
+ lb de, 1, 12
+ call InitTextPrinting
+ ldtx hl, TheGameWillContinueFromThePointInTheDuelText
+ call PrintTextNoDelay
+ ret
-Func_1d2b8: ; 1d2b8 (7:52b8)
- INCROM $1d2b8, $1d2dd
+.NewGame
+ lb de, 1, 12
+ call InitTextPrinting
+ ldtx hl, StartANewGameText
+ call PrintTextNoDelay
+ ret
-Func_1d2dd: ; 1d2dd (7:52dd)
- INCROM $1d2dd, $1d306
+.ContinueFromDiary
+ ; get OW map name
+ ld a, [wCurOverworldMap]
+ add a
+ ld c, a
+ ld b, $00
+ ld hl, OverworldMapNames
+ add hl, bc
+ ld a, [hli]
+ ld [wTxRam2 + 0], a
+ ld a, [hl]
+ ld [wTxRam2 + 1], a
-Func_1d306: ; 1d306 (7:5306)
- INCROM $1d306, $1d335
+ ; get medal count
+ ld a, [wMedalCount]
+ ld [wTxRam3 + 0], a
+ xor a
+ ld [wTxRam3 + 1], a
-Func_1d335: ; 1d335 (7:5335)
- INCROM $1d335, $1d386
+ ; print text
+ lb de, 1, 10
+ call InitTextPrinting
+ ldtx hl, ContinueFromDiarySummaryText
+ call PrintTextNoDelay
-Titlescreen_1d386: ; 1d386 (7:5386)
+ ld a, [wTotalNumCardsCollected]
+ ld d, a
+ ld a, [wTotalNumCardsToCollect]
+ ld e, a
+ ld bc, $90e
+ farcall Func_1024f
+ ld bc, $a10
+ farcall Func_101df
+ ret
+; 0x1d289
+
+; asks the player whether it's okay to delete
+; the save data in order to create a new one
+; if player answers "yes", delete it
+DeleteSaveDataForNewGame: ; 1d289 (7:5289)
+; exit if there no save data
+ ld a, [wHasSaveData]
+ or a
+ ret z
+
+ call DisableLCD
+ farcall Func_10000
+ call Func_3ca0
+ farcall FlashWhiteScreen
+ call DoFrameIfLCDEnabled
+ ldtx hl, SavedDataAlreadyExistsText
+ call PrintScrollableText_NoTextBoxLabel
+ ldtx hl, OKToDeleteTheDataText
+ call YesOrNoMenuWithText
+ ret c ; quit if chose "no"
+ farcall InvalidateSaveData
+ ldtx hl, AllDataWasDeletedText
+ call PrintScrollableText_NoTextBoxLabel
+ or a
+ ret
+; 0x1d2b8
+
+; asks the player if the game should resume
+; from diary even though there is Duel save data
+; returns carry if "no" was selected
+AskToContinueFromDiaryWithDuelData: ; 1d2b8 (7:52b8)
+; return if there's no duel save data
+ ld a, [wHasDuelSaveData]
+ or a
+ ret z
+
+ call DisableLCD
+ farcall Func_10000
+ call Func_3ca0
+ farcall FlashWhiteScreen
+ call DoFrameIfLCDEnabled
+ ldtx hl, DataExistsWhenPowerWasTurnedOFFDuringDuelText
+ call PrintScrollableText_NoTextBoxLabel
+ ldtx hl, ContinueFromDiaryText
+ call YesOrNoMenuWithText
+ ret c
+ or a
+ ret
+; 0x1d2dd
+
+; shows disclaimer for Card Pop!
+; in case player is not playing in CGB
+; return carry if disclaimer was shown
+ShowCardPopCGBDisclaimer: ; 1d2dd (7:52dd)
+; return if playing in CGB
+ ld a, [wConsole]
+ cp CONSOLE_CGB
+ ret z
+
+ lb de, 0, 10
+ lb bc, 20, 8
+ call DrawRegularTextBox
+ lb de, 1,12
+ call InitTextPrinting
+ ldtx hl, YouCanAccessCardPopOnlyWithGameBoyColorsText
+ call PrintTextNoDelay
+ lb bc, SYM_CURSOR_D, SYM_BOX_BOTTOM
+ lb de, 18, 17
+ call SetCursorParametersForTextBox
+ call WaitForButtonAorB
+ scf
+ ret
+; 0x1d306
+
+DrawPlayerPortraitAndPrintNewGameText: ; 1d306 (7:5306)
+ call DisableLCD
+ farcall Func_10a9b
+ farcall Func_10000
+ call Func_3ca0
+ ld hl, HandleAllSpriteAnimations
+ call SetDoFrameFunction
+ lb bc, 7, 3
+ farcall $4, DrawPlayerPortrait
+ farcall Func_10af9
+ call DoFrameIfLCDEnabled
+ ldtx hl, IsCrazyAboutPokemonAndPokemonCardCollectingText
+ call PrintScrollableText_NoTextBoxLabel
+ call ResetDoFrameFunction
+ call Func_3ca0
+ ret
+; 0x1d335
+
+PlayOpeningSequence: ; 1d335 (7:5335)
+ call DisableLCD
+ farcall Func_10a9b
+ farcall Func_10000
+ call Func_3ca0
+ ld hl, HandleAllSpriteAnimations
+ call SetDoFrameFunction
+ call LoadTitleScreenSprites
+
+ ld a, LOW(OpeningSequence)
+ ld [wSequenceCmdPtr + 0], a
+ ld a, HIGH(OpeningSequence)
+ ld [wSequenceCmdPtr + 1], a
+
+ xor a
+ ld [wd317], a
+ ld [wOpeningSequencePalsNeedUpdate], a
+ ld [wSequenceDelay], a
+ farcall FlashWhiteScreen
+
+.loop_cmds
+ call DoFrameIfLCDEnabled
+ call UpdateRNGSources
+ ldh a, [hKeysPressed]
+ and A_BUTTON | START
+ jr nz, .jump_to_title_screen
+ ld a, [wOpeningSequencePalsNeedUpdate]
+ or a
+ jr z, .no_pal_update
+ farcall Func_10d74
+.no_pal_update
+ call ExecuteOpeningSequenceCmd
+ ld a, [wSequenceDelay]
+ cp $ff
+ jr nz, .loop_cmds
+ jr .asm_1d39f
+
+.jump_to_title_screen
call AssertSongFinished
or a
jr nz, .asm_1d39f
@@ -1672,54 +2468,191 @@ Titlescreen_1d386: ; 1d386 (7:5386)
lb bc, 0, 0
ld a, SCENE_TITLE_SCREEN
call LoadScene
- call Func_1d59c
+ call OpeningSequenceEmptyFunc
.asm_1d39f
call Func_3ca0
- call Func_1d3a9
+ call .ShowPressStart
call EnableLCD
ret
-Func_1d3a9: ; 1d3a9 (7:53a9)
- INCROM $1d3a9, $1d3ce
-
-Func_1d3ce: ; 1d3ce (7:53ce)
- INCROM $1d3ce, $1d42e
+.ShowPressStart
+ ld a, SPRITE_PRESS_START
+ farcall CreateSpriteAndAnimBufferEntry
+ ld c, SPRITE_ANIM_COORD_X
+ call GetSpriteAnimBufferProperty
+ ld a, 48
+ ld [hli], a ; x
+ ld a, 112
+ ld [hl], a ; y
+ ld c, $be
+ ld a, [wConsole]
+ cp CONSOLE_CGB
+ jr nz, .asm_1d3c5
+ ld c, $bf
+.asm_1d3c5
+ ld a, c
+ ld bc, 60
+ farcall Func_12ac9
+ ret
+; 0x1d3ce
-Func_1d42e: ; 1d42e (7:542e)
- INCROM $1d42e, $1d519
+LoadTitleScreenSprites: ; 1d3ce (7:53ce)
+ xor a
+ ld [wd4ca], a
+ ld [wd4cb], a
+ ld a, PALETTE_30
+ farcall LoadPaletteData
-Titlescreen_1d519: ; 1d519 (7:5519)
- ld a, MUSIC_TITLESCREEN
- call PlaySong
- call Func_1d42e
- scf
+ ld bc, 0
+ ld de, wTitleScreenSprites
+.loop_load_sprites
+ push bc
+ push de
+ ld hl, .TitleScreenSpriteList
+ add hl, bc
+ ld a, [hl]
+ farcall CreateSpriteAndAnimBufferEntry
+ ld a, [wWhichSprite]
+ ld [de], a
+ call GetFirstSpriteAnimBufferProperty
+ inc hl
+ ld a, [hl] ; SPRITE_ANIM_ATTRIBUTES
+ or c
+ ld [hl], a
+ pop de
+ pop bc
+ inc de
+ inc c
+ ld a, c
+ cp $7
+ jr c, .loop_load_sprites
ret
-; 0x1d523
- INCROM $1d523, $1d59c
+.TitleScreenSpriteList
+ db SPRITE_GRASS
+ db SPRITE_FIRE
+ db SPRITE_WATER
+ db SPRITE_COLORLESS
+ db SPRITE_LIGHTNING
+ db SPRITE_PSYCHIC
+ db SPRITE_FIGHTING
+; 0x1d408
+
+; TODO place in main.asm when possible
+INCLUDE "engine/sequences/opening_sequence_commands.asm"
+INCLUDE "data/sequences/opening_sequence.asm"
+
+; once every 63 frames randomly choose an orb sprite
+; to animate, i.e. circle around the screen
+AnimateRandomTitleScreenOrb: ; 1d614 (7:5614)
+ ld a, [wConsole]
+ cp CONSOLE_CGB
+ call z, .UpdateSpriteAttributes
+ ld a, [wd635]
+ and 63
+ ret nz ; don't pick an orb now
+
+.pick_orb
+ ld a, $7
+ call Random
+ ld c, a
+ ld b, $00
+ ld hl, wTitleScreenSprites
+ add hl, bc
+ ld a, [hl]
+ ld [wWhichSprite], a
+ farcall GetSpriteAnimCounter
+ cp $ff
+ jr nz, .pick_orb
-Func_1d59c: ; 1d59c (7:559c)
- INCROM $1d59c, $1d614
+ ld c, SPRITE_ANIM_ATTRIBUTES
+ call GetSpriteAnimBufferProperty
+ ld a, [wConsole]
+ cp CONSOLE_CGB
+ jr nz, .set_coords
+ set SPRITE_ANIM_FLAG_UNSKIPPABLE, [hl]
-Func_1d614: ; 1d614 (7:5614)
- INCROM $1d614, $1d6ad
+.set_coords
+ inc hl
+ ld a, 248
+ ld [hli], a ; SPRITE_ANIM_COORD_X
+ ld a, 14
+ ld [hl], a ; SPRITE_ANIM_COORD_Y
+ ld a, [wConsole]
+ cp CONSOLE_CGB
+ ld a, $d7
+ jr nz, .start_anim
+ ld a, $d8
+.start_anim
+ farcall StartSpriteAnimation
+ ret
+
+.UpdateSpriteAttributes
+ ld c, $7
+ ld de, wTitleScreenSprites
+.loop_orbs
+ push bc
+ ld a, [de]
+ ld [wWhichSprite], a
+ ld c, SPRITE_ANIM_COORD_X
+ call GetSpriteAnimBufferProperty
+ ld a, [hld]
+ cp 152
+ jr nz, .skip
+ res SPRITE_ANIM_FLAG_UNSKIPPABLE, [hl]
+.skip
+ pop bc
+ inc de
+ dec c
+ jr nz, .loop_orbs
+ ret
+; 0x1d67b
+
+; unreferenced
+; shows Copyright information for 300 frames
+; or until Start button is pressed
+Func_1d67b: ; 1d67b (7:567b)
+ call DisableLCD
+ farcall Func_10a9b
+ farcall Func_10000
+ ld bc, $0
+ ld a, SCENE_COPYRIGHT
+ call LoadScene
+ farcall Func_10af9
+ ld bc, 300
+.loop_frame
+ push bc
+ call DoFrameIfLCDEnabled
+ call UpdateRNGSources
+ pop bc
+ ldh a, [hKeysPressed]
+ and START
+ jr nz, .exit
+ dec bc
+ ld a, b
+ or c
+ jr nz, .loop_frame
+.exit
+ farcall Func_10ab4
+ ret
+; 0x1d6ad
Credits_1d6ad: ; 1d6ad (7:56ad)
ld a, MUSIC_STOP
call PlaySong
call Func_1d705
- call Func_1c858
+ call AddAllMastersToMastersBeatenList
xor a
ld [wOWMapEvents + 1], a
ld a, MUSIC_CREDITS
call PlaySong
- farcall Func_10031
- call Func_1d7fc
+ farcall FlashWhiteScreen
+ call SetCreditsSequenceCmdPtr
.asm_1d6c8
call DoFrameIfLCDEnabled
call Func_1d765
- call Func_1d80b
- ld a, [wd633]
+ call ExecuteCreditsSequenceCmd
+ ld a, [wSequenceDelay]
cp $ff
jr nz, .asm_1d6c8
call WaitForSongToFinish
@@ -1740,16 +2673,160 @@ Credits_1d6ad: ; 1d6ad (7:56ad)
ret
Func_1d705: ; 1d705 (7:5705)
- INCROM $1d705, $1d758
+ call DisableLCD
+ farcall Func_10a9b
+ call Func_3ca0
+ farcall Func_10000
+ call Func_1d7ee
+ ld hl, Func_3e31
+ call SetDoFrameFunction
+ call .Func_1d720 ; can be fallthrough
+ ret
+
+.Func_1d720
+ ld a, $91
+ ld [wd647], a
+ ld [wd649], a
+ ld a, $01
+ ld [wd648], a
+ ld [wd64a], a
+ call Func_1d765
+ call Set_WD_on
+ call .Func_1d73a ; can bee fallthrough
+ ret
+
+.Func_1d73a
+ push hl
+ di
+ xor a
+ ld [wd657], a
+ ld hl, wLCDCFunctionTrampoline + 1
+ ld [hl], LOW(Func_3e44)
+ inc hl
+ ld [hl], HIGH(Func_3e44)
+ ei
+
+ ld hl, rSTAT
+ set STAT_LYC, [hl]
+ xor a
+ ldh [rLYC], a
+ ld hl, rIE
+ set INT_LCD_STAT, [hl]
+ pop hl
+ ret
+; 0x1d758
Func_1d758: ; 1d758 (7:5758)
- INCROM $1d758, $1d765
+ push hl
+ ld hl, rSTAT
+ res STAT_LYC, [hl]
+ ld hl, rIE
+ res INT_LCD_STAT, [hl]
+ pop hl
+ ret
+; 0x1d765
Func_1d765: ; 1d765 (7:5765)
- INCROM $1d765, $1d7fc
+ push hl
+ push bc
+ push de
+ xor a
+ ldh [hWY], a
+
+ ld hl, wd659
+ ld de, wd65f
+ ld a, [wd648]
+ or a
+ jr nz, .asm_1d785
+ ld a, $a7
+ ldh [hWX], a
+ ld [hli], a
+ push hl
+ ld hl, wLCDC
+ set 1, [hl]
+ pop hl
+ jr .asm_1d7e2
-Func_1d7fc: ; 1d7fc (7:57fc)
- INCROM $1d7fc, $1d80b
+.asm_1d785
+ ld a, [wd647]
+ or a
+ jr z, .asm_1d79e
+ dec a
+ ld [de], a
+ inc de
+ ld a, $a7
+ ldh [hWX], a
+ ld [hli], a
+ push hl
+ ld hl, wLCDC
+ set 1, [hl]
+ pop hl
+ ld a, $07
+ jr .asm_1d7a9
-Func_1d80b: ; 1d80b (7:580b)
- INCROM $1d80b, $1e1c4
+.asm_1d79e
+ ld a, $07
+ ldh [hWX], a
+ push hl
+ ld hl, wLCDC
+ res 1, [hl]
+ pop hl
+.asm_1d7a9
+ ld [hli], a
+ ld a, [wd647]
+ dec a
+ ld c, a
+ ld a, [wd648]
+ add c
+ ld c, a
+ ld a, [wd649]
+ dec a
+ cp c
+ jr c, .asm_1d7d4
+ jr z, .asm_1d7d4
+ ld a, c
+ ld [de], a
+ inc de
+ push af
+ ld a, $a7
+ ld [hli], a
+ pop bc
+ ld a, [wd64a]
+ or a
+ jr z, .asm_1d7e2
+ ld a, [wd649]
+ dec a
+ ld [de], a
+ inc de
+ ld a, $07
+ ld [hli], a
+
+.asm_1d7d4
+ ld a, [wd649]
+ dec a
+ ld c, a
+ ld a, [wd64a]
+ add c
+ ld [de], a
+ inc de
+ ld a, $a7
+ ld [hli], a
+.asm_1d7e2
+ ld a, $ff
+ ld [de], a
+ ld a, $01
+ ld [wd665], a
+ pop de
+ pop bc
+ pop hl
+ ret
+; 0x1d7ee
+
+Func_1d7ee: ; 1d7ee (7:57ee)
+ xor a
+ lb de, 0, 32
+ lb bc, 20, 18
+ lb hl, 0, 0
+ call FillRectangle
+ ret
+; 0x1d7fc
diff --git a/src/engine/bank20.asm b/src/engine/bank20.asm
index daf4004..5481d17 100644
--- a/src/engine/bank20.asm
+++ b/src/engine/bank20.asm
@@ -867,8 +867,7 @@ LoadPaletteDataToBuffer: ; 80456 (20:4456)
ret
; 0x8047b
-; unreferenced?
-Func_8047b: ; 8047b (20:447b)
+ClearNumLoadedFramesetSubgroups: ; 8047b (20:447b)
xor a
ld [wNumLoadedFramesetSubgroups], a
ret
@@ -1416,7 +1415,7 @@ Func_80cd7: ; 80cd7 (20:4cd7)
.loop
call DoFrameIfLCDEnabled
call .HandleInput
- call Func_3cb4
+ call HandleAllSpriteAnimations
ldh a, [hKeysPressed]
and SELECT ; if select is pressed, exit
jr z, .loop
diff --git a/src/engine/home.asm b/src/engine/home.asm
index 0b60609..6935e0b 100644
--- a/src/engine/home.asm
+++ b/src/engine/home.asm
@@ -10600,10 +10600,10 @@ OverworldDoFrameFunction: ; 380e (0:380e)
call BankswitchROM
call SetScreenScrollWram
call Func_c554
- ld a, BANK(Func_1c610)
+ ld a, BANK(HandleAllNPCMovement)
call BankswitchROM
- call Func_1c610
- call Func_3cb4
+ call HandleAllNPCMovement
+ call HandleAllSpriteAnimations
ld a, BANK(DoLoadedFramesetSubgroupsFrame)
call BankswitchROM
call DoLoadedFramesetSubgroupsFrame
@@ -10698,7 +10698,7 @@ GameEvent_Duel: ; 38c0 (0:38c0)
xor a
ld [sba44], a
call DisableSRAM
- call Func_3a3b
+ call SaveGeneralSaveData
bank1call StartDuel
scf
ret
@@ -10736,11 +10736,11 @@ GameEvent_Credits: ; 3911 (0:3911)
or a
ret
-Func_3917: ; 3917 (0:3917)
+GetReceivedLegendaryCards: ; 3917 (0:3917)
ld a, EVENT_RECEIVED_LEGENDARY_CARDS
farcall GetEventValue
call EnableSRAM
- ld [s0a00a], a
+ ld [sReceivedLegendaryCards], a
call DisableSRAM
ret
@@ -10948,9 +10948,11 @@ PlayDefaultSong: ; 39fc (0:39fc)
; returns [wDefaultSong] or MUSIC_RONALD in a
GetDefaultSong: ; 3a1f (0:3a1f)
- ld a, [wd3b8]
+ ld a, [wRonaldIsInMap]
or a
jr z, .default_song
+ ; only return Ronald's theme if it's
+ ; not in one of the following maps
ld a, [wOverworldMapSelection]
cp OWMAP_ISHIHARAS_HOUSE
jr z, .default_song
@@ -10964,16 +10966,16 @@ GetDefaultSong: ; 3a1f (0:3a1f)
ld a, [wDefaultSong]
ret
-Func_3a3b: ; 3a3b (0:3a3b)
- farcall Func_1124d
+SaveGeneralSaveData: ; 3a3b (0:3a3b)
+ farcall _SaveGeneralSaveData
ret
-Func_3a40: ; 3a40 (0:3a40)
- farcall Func_11430
+LoadGeneralSaveData: ; 3a40 (0:3a40)
+ farcall _LoadGeneralSaveData
ret
-Func_3a45: ; 3a45 (0:3a45)
- farcall Func_11343
+ValidateGeneralSaveData: ; 3a45 (0:3a45)
+ farcall _ValidateGeneralSaveData
ret
; adds card with card ID in register a to collection
@@ -11236,7 +11238,7 @@ Func_3ba2: ; 3ba2 (0:3ba2)
ld a, BANK(Func_1cac5)
call BankswitchROM
call Func_1cac5
- call Func_3cb4
+ call HandleAllSpriteAnimations
pop af
call BankswitchROM
ret
@@ -11248,7 +11250,7 @@ Func_3bb5: ; 3bb5 (0:3bb5)
push af
ld a, [wDuelAnimReturnBank]
call BankswitchROM
- call Func_3cb4
+ call HandleAllSpriteAnimations
call CallHL2
pop af
call BankswitchROM
@@ -11448,12 +11450,12 @@ Func_3ca4: ; 3ca4 (0:3ca4)
call BankswitchROM
ret
-Func_3cb4: ; 3cb4 (0:3cb4)
+HandleAllSpriteAnimations: ; 3cb4 (0:3cb4)
ldh a, [hBankROM]
push af
- ld a, BANK(HandleAllSpriteAnimations)
+ ld a, BANK(_HandleAllSpriteAnimations)
call BankswitchROM
- call HandleAllSpriteAnimations
+ call _HandleAllSpriteAnimations
pop af
call BankswitchROM
ret
@@ -11700,7 +11702,7 @@ LoadScene: ; 3df3 (0:3df3)
ret
; draws player's portrait at b,c
-Func_3e10: ; 3e10 (0:3e10)
+DrawPlayerPortrait: ; 3e10 (0:3e10)
ld a, $1
ld [wd61e], a
ld a, TILEMAP_PLAYER
@@ -11726,7 +11728,7 @@ Func_3e2a: ; 3e2a (0:3e2a)
Func_3e31: ; 3e31 (0:3e31)
ldh a, [hBankROM]
push af
- call Func_3cb4
+ call HandleAllSpriteAnimations
ld a, BANK(DoLoadedFramesetSubgroupsFrame)
call BankswitchROM
call DoLoadedFramesetSubgroupsFrame
diff --git a/src/engine/sequences/credits_sequence_commands.asm b/src/engine/sequences/credits_sequence_commands.asm
new file mode 100644
index 0000000..5a7d4eb
--- /dev/null
+++ b/src/engine/sequences/credits_sequence_commands.asm
@@ -0,0 +1,484 @@
+SetCreditsSequenceCmdPtr: ; 1d7fc (7:57fc)
+ ld a, LOW(CreditsSequence)
+ ld [wSequenceCmdPtr + 0], a
+ ld a, HIGH(CreditsSequence)
+ ld [wSequenceCmdPtr + 1], a
+ xor a
+ ld [wSequenceDelay], a
+ ret
+; 0x1d80b
+
+ExecuteCreditsSequenceCmd: ; 1d80b (7:580b)
+ ld a, [wSequenceDelay]
+ or a
+ jr z, .call_func
+ cp $ff
+ ret z ; sequence ended
+
+ dec a ; still waiting
+ ld [wSequenceDelay], a
+ ret
+
+.call_func
+ ld a, [wSequenceCmdPtr + 0]
+ ld l, a
+ ld a, [wSequenceCmdPtr + 1]
+ ld h, a
+ ld a, [hli]
+ ld e, a
+ ld a, [hli]
+ ld d, a
+ push de
+ ld a, [hli]
+ ld c, a
+ ld a, [hli]
+ ld b, a
+ ld a, [hli]
+ ld e, a
+ ld a, [hli]
+ ld d, a
+ pop hl
+ call CallHL2
+ jr ExecuteCreditsSequenceCmd
+; 0x1d834
+
+ ret ; stray ret
+
+AdvanceCreditsSequenceCmdPtrBy2: ; 1d835 (7:5835)
+ ld a, 2
+ jr AdvanceCreditsSequenceCmdPtr
+
+AdvanceCreditsSequenceCmdPtrBy3: ; 1d839 (7:5839)
+ ld a, 3
+ jr AdvanceCreditsSequenceCmdPtr
+
+AdvanceCreditsSequenceCmdPtrBy5: ; 1d83d (7:583d)
+ ld a, 5
+ jr AdvanceCreditsSequenceCmdPtr
+
+AdvanceCreditsSequenceCmdPtrBy6: ; 1d841 (7:5841)
+ ld a, 6
+ jr AdvanceCreditsSequenceCmdPtr
+
+AdvanceCreditsSequenceCmdPtrBy4: ; 1d845 (7:5845)
+ ld a, 4
+; fallthrough
+
+AdvanceCreditsSequenceCmdPtr: ; 1d847 (7:5847)
+ push hl
+ ld hl, wSequenceCmdPtr
+ add [hl]
+ ld [hli], a
+ ld a, [hl]
+ adc 0
+ ld [hl], a
+ pop hl
+ ret
+; 0x1d853
+
+CreditsSequenceCmd_Wait: ; 1d853 (7:5853)
+ ld a, c
+ ld [wSequenceDelay], a
+ jp AdvanceCreditsSequenceCmdPtrBy3
+; 0x1d85a
+
+CreditsSequenceCmd_LoadScene: ; 1d85a (7:585a)
+ push bc
+ push de
+ farcall ClearNumLoadedFramesetSubgroups
+ call EmptyScreen
+ xor a
+ ldh [hSCX], a
+ ldh [hSCY], a
+ farcall Func_1288c
+ pop de
+ pop bc
+ ld a, c
+ ld c, b
+ ld b, a
+ ld a, e
+ call LoadScene
+ jp AdvanceCreditsSequenceCmdPtrBy5
+; 0x1d878
+
+CreditsSequenceCmd_LoadBooster: ; 1d878 (7:5878)
+ push bc
+ push de
+ farcall ClearNumLoadedFramesetSubgroups
+ call EmptyScreen
+ xor a
+ ldh [hSCX], a
+ ldh [hSCY], a
+ farcall Func_1288c
+ pop de
+ pop bc
+ ld a, c
+ ld c, b
+ ld b, a
+ ld a, e
+ farcall LoadBoosterGfx
+ jp AdvanceCreditsSequenceCmdPtrBy5
+; 0x1d897
+
+CreditsSequenceCmd_LoadClubMap: ; 1d897 (7:5897)
+ ld b, $00
+ ld hl, wMastersBeatenList
+ add hl, bc
+ ld a, [hl]
+ or a
+ jr nz, .at_least_1
+ inc a
+.at_least_1
+ dec a
+ ld c, a
+ add a
+ add a
+ add c ; *5
+ ld c, a
+ ld hl, .CreditsOWClubMaps
+ add hl, bc
+ ld a, [hli] ; map x coord
+ ld c, a
+ ld a, [hli] ; map y coord
+ ld b, a
+ ld a, [hli] ; map ID
+ ld e, a
+ push hl
+ call LoadOWMapForCreditsSequence
+ pop hl
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ or h
+ jr z, .done
+
+.loop_npcs
+ ld a, [hli] ; NPC ID
+ or a
+ jr z, .done
+ ld d, a
+ ld a, [hli] ; NPC x coord
+ ld c, a
+ ld a, [hli] ; NPC y coord
+ ld b, a
+ ld a, [hli] ; NPC direction
+ ld e, a
+ push hl
+ call LoadNPCForCreditsSequence
+ pop hl
+ jr .loop_npcs
+
+.done
+ jp AdvanceCreditsSequenceCmdPtrBy3
+
+credits_club_map: MACRO
+ db \1 ; x
+ db \2 ; y
+ db \3 ; OW map
+ dw \4 ; list of NPCs to load
+ENDM
+
+.CreditsOWClubMaps
+ credits_club_map 16, 0, FIGHTING_CLUB, .CreditsNPCs_FightingClub
+ credits_club_map 32, 0, ROCK_CLUB, .CreditsNPCs_RockClub
+ credits_club_map 64, 0, WATER_CLUB, .CreditsNPCs_WaterClub
+ credits_club_map 32, 0, LIGHTNING_CLUB, .CreditsNPCs_LightningClub
+ credits_club_map 32, 0, GRASS_CLUB, .CreditsNPCs_GrassClub
+ credits_club_map 32, 16, PSYCHIC_CLUB, .CreditsNPCs_PsychicClub
+ credits_club_map 0, 0, SCIENCE_CLUB, .CreditsNPCs_ScienceClub
+ credits_club_map 32, 0, FIRE_CLUB, .CreditsNPCs_FireClub
+ credits_club_map 32, 0, CHALLENGE_HALL, .CreditsNPCs_ChallengeHall
+ credits_club_map 48, 0, POKEMON_DOME, .CreditsNPCs_PokemonDome
+
+.CreditsNPCs_FightingClub
+ ; NPC ID, x, y, direction
+ db NPC_CHRIS, 4, 8, SOUTH
+ db NPC_MICHAEL, 14, 10, SOUTH
+ db NPC_JESSICA, 18, 6, EAST
+ db NPC_MITCH, 10, 4, SOUTH
+ db NPC_PLAYER_CREDITS, 10, 6, NORTH
+ db $00
+
+.CreditsNPCs_RockClub
+ ; NPC ID, x, y, direction
+ db NPC_RYAN, 20, 14, EAST
+ db NPC_GENE, 12, 6, SOUTH
+ db NPC_PLAYER_CREDITS, 12, 8, NORTH
+ db $00
+
+.CreditsNPCs_WaterClub
+ ; NPC ID, x, y, direction
+ db NPC_JOSHUA, 22, 8, SOUTH
+ db NPC_AMY, 22, 4, NORTH
+ db NPC_PLAYER_CREDITS, 18, 10, NORTH
+ db $00
+
+.CreditsNPCs_LightningClub
+ ; NPC ID, x, y, direction
+ db NPC_NICHOLAS, 6, 10, SOUTH
+ db NPC_BRANDON, 22, 12, NORTH
+ db NPC_ISAAC, 12, 4, NORTH
+ db NPC_PLAYER_CREDITS, 12, 10, NORTH
+ db $00
+
+.CreditsNPCs_GrassClub
+ ; NPC ID, x, y, direction
+ db NPC_KRISTIN, 4, 10, EAST
+ db NPC_HEATHER, 14, 16, SOUTH
+ db NPC_NIKKI, 12, 4, SOUTH
+ db NPC_PLAYER_CREDITS, 12, 6, NORTH
+ db $00
+
+.CreditsNPCs_PsychicClub
+ ; NPC ID, x, y, direction
+ db NPC_DANIEL, 8, 8, NORTH
+ db NPC_STEPHANIE, 22, 12, EAST
+ db NPC_MURRAY1, 12, 6, SOUTH
+ db NPC_PLAYER_CREDITS, 12, 8, NORTH
+ db $00
+
+.CreditsNPCs_ScienceClub
+ ; NPC ID, x, y, direction
+ db NPC_JOSEPH, 10, 10, WEST
+ db NPC_RICK, 4, 4, SOUTH
+ db NPC_PLAYER_CREDITS, 4, 6, NORTH
+ db $00
+
+.CreditsNPCs_FireClub
+ ; NPC ID, x, y, direction
+ db NPC_ADAM, 8, 14, SOUTH
+ db NPC_JONATHAN, 18, 10, SOUTH
+ db NPC_KEN, 14, 4, SOUTH
+ db NPC_PLAYER_CREDITS, 14, 6, NORTH
+ db $00
+
+.CreditsNPCs_ChallengeHall
+ ; NPC ID, x, y, direction
+ db NPC_HOST, 14, 4, SOUTH
+ db NPC_RONALD1, 18, 8, WEST
+ db NPC_PLAYER_CREDITS, 12, 8, EAST
+ db $00
+
+.CreditsNPCs_PokemonDome
+ ; NPC ID, x, y, direction
+ db NPC_COURTNEY, 18, 4, SOUTH
+ db NPC_STEVE, 22, 4, SOUTH
+ db NPC_JACK, 8, 4, SOUTH
+ db NPC_ROD, 14, 6, SOUTH
+ db NPC_PLAYER_CREDITS, 14, 10, NORTH
+ db $00
+; 0x1d9a6
+
+; bc = coordinates
+; e = OW map
+LoadOWMapForCreditsSequence: ; 1d9a6 (7:59a6)
+ push bc
+ push de
+ call EmptyScreen
+ pop de
+ pop bc
+
+ ; set input coordinates and map
+ ld a, c
+ ldh [hSCX], a
+ ld a, b
+ ldh [hSCY], a
+ ld a, e
+ ld [wCurMap], a
+
+ farcall LoadMapTilesAndPals
+ farcall Func_c9c7
+ farcall SafelyCopyBGMapFromSRAMToVRAM
+ farcall DoMapOWFrame
+ xor a
+ ld [wd4ca], a
+ ld [wd4cb], a
+ ld a, PALETTE_29
+ farcall LoadPaletteData
+ ret
+; 0x1d9d5
+
+CreditsSequenceCmd_LoadOWMap: ; 1d9d5 (7:59d5)
+ call LoadOWMapForCreditsSequence
+ jp AdvanceCreditsSequenceCmdPtrBy5
+; 0x1d9db
+
+CreditsSequenceCmd_DisableLCD: ; 1d9db (7:59db)
+ call DisableLCD
+ jp AdvanceCreditsSequenceCmdPtrBy2
+; 0x1d9e1
+
+CreditsSequenceCmd_FadeIn: ; 1d9e1 (7:59e1)
+ call DisableLCD
+ call Set_WD_on
+ farcall Func_10af9
+ jp AdvanceCreditsSequenceCmdPtrBy2
+; 0x1d9ee
+
+CreditsSequenceCmd_FadeOut: ; 1d9ee (7:59ee)
+ farcall Func_10ab4
+ call Func_3ca4
+ call EnableLCD
+ call DoFrameIfLCDEnabled
+ call DisableLCD
+ call Set_WD_off
+ jp AdvanceCreditsSequenceCmdPtrBy2
+; 0x1da04
+
+CreditsSequenceCmd_DrawRectangle: ; 1da04 (7:5a04)
+ ld a, c
+ or $20
+ ld e, a
+ ld d, $00
+ ld c, b
+ ld b, 20
+ xor a
+ lb hl, 0, 0
+ call FillRectangle
+ jp AdvanceCreditsSequenceCmdPtrBy4
+; 0x1da17
+
+CreditsSequenceCmd_PrintText: ; 1da17 (7:5a17)
+ ld a, $01
+ ld [wLineSeparation], a
+ push de
+ ld d, c
+ ld a, b
+ or $20
+ ld e, a
+ call InitTextPrinting
+ pop hl
+ call PrintTextNoDelay
+ jp AdvanceCreditsSequenceCmdPtrBy6
+; 0x1da2c
+
+CreditsSequenceCmd_PrintTextBox: ; 1da2c (7:5a2c)
+ ld a, $01
+ ld [wLineSeparation], a
+ push de
+ ld d, c
+ ld e, b
+ call InitTextPrinting
+ pop hl
+ call PrintTextNoDelay
+ jp AdvanceCreditsSequenceCmdPtrBy6
+; 0x1da3e
+
+CreditsSequenceCmd_InitOverlay: ; 1da3e (7:5a3e)
+ ld a, c
+ ld [wd647], a
+ ld a, b
+ ld [wd648], a
+ ld a, e
+ ld [wd649], a
+ ld a, d
+ ld [wd64a], a
+ call Func_1d765
+ jp AdvanceCreditsSequenceCmdPtrBy6
+; 0x1da54
+
+CreditsSequenceCmd_LoadNPC: ; 1da54 (7:5a54)
+ call LoadNPCForCreditsSequence
+ jp AdvanceCreditsSequenceCmdPtrBy6
+; 0x1da5a
+
+; bc = coordinates
+; e = direction
+; d = NPC ID
+LoadNPCForCreditsSequence: ; 1da5a (7:5a5a)
+ ld a, c
+ ld [wLoadNPCXPos], a
+ ld a, b
+ ld [wLoadNPCYPos], a
+ ld a, e
+ ld [wLoadNPCDirection], a
+ ld a, d
+ farcall LoadNPCSpriteData
+ ld a, [wNPCSpriteID]
+ farcall CreateSpriteAndAnimBufferEntry
+
+ ld c, SPRITE_ANIM_COORD_X
+ call GetSpriteAnimBufferProperty
+ ldh a, [hSCX]
+ ld c, a
+ ld a, [wLoadNPCXPos]
+ add a
+ add a
+ add a ; *8
+ add 8
+ sub c
+ ld [hli], a ; x
+ ldh a, [hSCY]
+ ld c, a
+ ld a, [wLoadNPCYPos]
+ add a
+ add a
+ add a ; *8
+ add 16
+ sub c
+ ld [hli], a ; y
+
+ ld a, [wNPCAnim]
+ ld c, a
+ ld a, [wLoadNPCDirection]
+ add c
+ farcall StartNewSpriteAnimation
+ ret
+; 0x1da9e
+
+CreditsSequenceCmd_InitVolcanoSprite: ; 1da9e (7:5a9e)
+ farcall OverworldMap_InitVolcanoSprite
+ jp AdvanceCreditsSequenceCmdPtrBy2
+; 0x1daa5
+
+CreditsSequenceCmd_TransformOverlay: ; 1daa5 (7:5aa5)
+; either stretches or shrinks overlay
+; to the input configurations
+ ld l, 0
+ ld a, [wd647]
+ call .Func_1dade
+ ld [wd647], a
+ ld a, [wd648]
+ ld c, b
+ call .Func_1dade
+ ld [wd648], a
+ ld a, [wd649]
+ ld c, e
+ call .Func_1dade
+ ld [wd649], a
+ ld a, [wd64a]
+ ld c, d
+ call .Func_1dade
+ ld [wd64a], a
+ ld a, l
+ or a
+ jr z, .advance_sequence
+ ld a, 1
+ ld [wSequenceDelay], a
+ ret
+
+.advance_sequence
+ call Func_1d765
+ jp AdvanceCreditsSequenceCmdPtrBy6
+
+; compares a with c
+; if it's smaller: increase by 2 and increment l
+; if it's larger: decrease by 2 and increment l
+; if it's equal or $ff: do nothing
+.Func_1dade
+ cp $ff
+ jr z, .done
+ cp c
+ jr z, .done
+ inc l
+ jr c, .incr_a
+; decr a
+ dec a
+ dec a
+ jr .done
+.incr_a
+ inc a
+ inc a
+.done
+ ret
+; 0x1daef
diff --git a/src/engine/sequences/opening_sequence_commands.asm b/src/engine/sequences/opening_sequence_commands.asm
new file mode 100644
index 0000000..8846c88
--- /dev/null
+++ b/src/engine/sequences/opening_sequence_commands.asm
@@ -0,0 +1,350 @@
+ExecuteOpeningSequenceCmd: ; 1d408 (7:5408)
+ ld a, [wSequenceDelay]
+ or a
+ jr z, .call_function
+ cp $ff
+ ret z ; sequence ended
+
+ dec a ; still waiting
+ ld [wSequenceDelay], a
+ ret
+
+.call_function
+ ld a, [wSequenceCmdPtr + 0]
+ ld l, a
+ ld a, [wSequenceCmdPtr + 1]
+ ld h, a
+ ld a, [hli]
+ ld e, a
+ ld a, [hli]
+ ld d, a
+ ld a, [hli]
+ ld c, a
+ ld a, [hli]
+ ld b, a
+ ld l, e
+ ld h, d
+ call CallHL2
+ jr c, ExecuteOpeningSequenceCmd
+ ret
+; 0x1d42e
+
+AdvanceOpeningSequenceCmdPtrBy2: ; 1d42e (7:542e)
+ ld a, 2
+ jr AdvanceOpeningSequenceCmdPtr
+
+AdvanceOpeningSequenceCmdPtrBy3: ; 1d432 (7:5432)
+ ld a, 3
+ jr AdvanceOpeningSequenceCmdPtr
+
+AdvanceOpeningSequenceCmdPtrBy4: ; 1d436 (7:5436)
+ ld a, 4
+; fallthrough
+
+AdvanceOpeningSequenceCmdPtr: ; 1d438 (7:5438)
+ push hl
+ ld hl, wSequenceCmdPtr
+ add [hl]
+ ld [hli], a
+ ld a, [hl]
+ adc 0
+ ld [hl], a
+ pop hl
+ ret
+; 0x1d444
+
+OpeningSequenceCmd_WaitOrbsAnimation: ; 1d444 (7:5444)
+ ld c, $7
+ ld de, wTitleScreenSprites
+.loop
+ ld a, [de]
+ ld [wWhichSprite], a
+ farcall GetSpriteAnimCounter
+ cp $ff
+ jr nz, .no_carry
+ inc de
+ dec c
+ jr nz, .loop
+ call AdvanceOpeningSequenceCmdPtrBy2
+ scf
+ ret
+
+.no_carry
+ or a
+ ret
+; 0x1d460
+
+OpeningSequenceCmd_Wait: ; 1d460 (7:5460)
+ ld a, c
+ ld [wSequenceDelay], a
+ call AdvanceOpeningSequenceCmdPtrBy3
+ scf
+ ret
+; 0x1d469
+
+OpeningSequenceCmd_SetOrbsAnimations: ; 1d469 (7:5469)
+ ld l, c
+ ld h, b
+
+ ld c, $7
+ ld de, wTitleScreenSprites
+.loop
+ push bc
+ push de
+ ld a, [de]
+ ld [wWhichSprite], a
+ ld a, [hli]
+ farcall StartSpriteAnimation
+ pop de
+ pop bc
+ inc de
+ dec c
+ jr nz, .loop
+
+ call AdvanceOpeningSequenceCmdPtrBy4
+ scf
+ ret
+; 0x1d486
+
+OpeningSequenceCmd_SetOrbsCoordinates: ; 1d486 (7:5486)
+ ld l, c
+ ld h, b
+
+ ld c, $7
+ ld de, wTitleScreenSprites
+.loop
+ push bc
+ push de
+ ld a, [de]
+ ld [wWhichSprite], a
+ push hl
+ ld c, SPRITE_ANIM_COORD_X
+ call GetSpriteAnimBufferProperty
+ ld e, l
+ ld d, h
+ pop hl
+ ld a, [hli]
+ add 8
+ ld [de], a ; x
+ inc de
+ ld a, [hli]
+ add 16
+ ld [de], a ; y
+ pop de
+ pop bc
+ inc de
+ dec c
+ jr nz, .loop
+
+ call AdvanceOpeningSequenceCmdPtrBy4
+ scf
+ ret
+; 0x1d4b0
+
+OpeningOrbAnimations_CharizardScene: ; 1d4b0 (7:54b0)
+ db $c0 ; GRASS
+ db $c1 ; FIRE
+ db $c1 ; WATER
+ db $c0 ; COLORLESS
+ db $c1 ; LIGHTNING
+ db $c0 ; PSYCHIC
+ db $c1 ; FIGHTING
+; 0x1d4b7
+
+OpeningOrbCoordinates_CharizardScene: ; 1d4b7 (7:54b7)
+ ; x coord, y coord
+ db 240, 28 ; GRASS
+ db 160, 120 ; FIRE
+ db 160, 8 ; WATER
+ db 240, 64 ; COLORLESS
+ db 160, 84 ; LIGHTNING
+ db 240, 100 ; PSYCHIC
+ db 160, 44 ; FIGHTING
+; 0x1d4c5
+
+OpeningOrbAnimations_ScytherScene: ; 1d4c5 (7:54c5)
+ db $c1 ; GRASS
+ db $c0 ; FIRE
+ db $c0 ; WATER
+ db $c1 ; COLORLESS
+ db $c0 ; LIGHTNING
+ db $c1 ; PSYCHIC
+ db $c0 ; FIGHTING
+; 0x1d4cc
+
+OpeningOrbCoordinates_ScytherScene: ; 1d4cc (7:54cc)
+ ; x coord, y coord
+ db 160, 28 ; GRASS
+ db 240, 120 ; FIRE
+ db 240, 8 ; WATER
+ db 160, 64 ; COLORLESS
+ db 240, 84 ; LIGHTNING
+ db 160, 100 ; PSYCHIC
+ db 240, 44 ; FIGHTING
+; 0x1d4da
+
+OpeningOrbAnimations_AerodactylScene: ; 1d4da (7:54da)
+ db $c2 ; GRASS
+ db $c5 ; FIRE
+ db $c8 ; WATER
+ db $cb ; COLORLESS
+ db $ce ; LIGHTNING
+ db $d1 ; PSYCHIC
+ db $d4 ; FIGHTING
+; 0x1d4e1
+
+OpeningOrbCoordinates_AerodactylScene: ; 1d4e1 (7:54e1)
+ ; x coord, y coord
+ db 240, 32 ; GRASS
+ db 160, 112 ; FIRE
+ db $A0, 16 ; WATER
+ db 240, 64 ; COLORLESS
+ db 160, 80 ; LIGHTNING
+ db 240, 96 ; PSYCHIC
+ db 160, 48 ; FIGHTING
+; 0x1d4ef
+
+OpeningOrbAnimations_InitialTitleScreen: ; 1d4ef (7:54ef)
+ db $c3 ; GRASS
+ db $c6 ; FIRE
+ db $c9 ; WATER
+ db $cc ; COLORLESS
+ db $cf ; LIGHTNING
+ db $d2 ; PSYCHIC
+ db $d5 ; FIGHTING
+; 0x1d4f6
+
+OpeningOrbCoordinates_InitialTitleScreen: ; 1d4f6 (7:54f6)
+ ; x coord, y coord
+ db 112, 144 ; GRASS
+ db 12, 144 ; FIRE
+ db 32, 144 ; WATER
+ db 92, 144 ; COLORLESS
+ db 52, 144 ; LIGHTNING
+ db 132, 144 ; PSYCHIC
+ db 72, 144 ; FIGHTING
+; 0x1d504
+
+OpeningOrbAnimations_InTitleScreen: ; 1d504 (7:5504)
+ db $c4 ; GRASS
+ db $c7 ; FIRE
+ db $ca ; WATER
+ db $cd ; COLORLESS
+ db $d0 ; LIGHTNING
+ db $d3 ; PSYCHIC
+ db $d6 ; FIGHTING
+; 0x1d50b
+
+OpeningOrbCoordinates_InTitleScreen: ; 1d50b (7:550b)
+ ; x coord, y coord
+ db 112, 76 ; GRASS
+ db 0, 28 ; FIRE
+ db 32, 76 ; WATER
+ db 92, 252 ; COLORLESS
+ db 52, 252 ; LIGHTNING
+ db 144, 28 ; PSYCHIC
+ db 72, 76 ; FIGHTING
+; 0x1d519
+
+OpeningSequenceCmd_PlayTitleScreenMusic: ; 1d519 (7:5519)
+ ld a, MUSIC_TITLESCREEN
+ call PlaySong
+ call AdvanceOpeningSequenceCmdPtrBy2
+ scf
+ ret
+; 0x1d523
+
+OpeningSequenceCmd_WaitSFX: ; 1d523 (7:5523)
+ call AssertSFXFinished
+ or a
+ jr nz, .no_carry
+ call AdvanceOpeningSequenceCmdPtrBy2
+ scf
+ ret
+
+.no_carry
+ or a
+ ret
+; 0x1d530
+
+OpeningSequenceCmd_PlaySFX: ; 1d530 (7:5530)
+ ld a, c
+ call PlaySFX
+ call AdvanceOpeningSequenceCmdPtrBy3
+ scf
+ ret
+; 0x1d539
+
+OpeningSequenceCmd_FadeIn: ; 1d539 (7:5539)
+ ld a, TRUE
+ ld [wOpeningSequencePalsNeedUpdate], a
+ call AdvanceOpeningSequenceCmdPtrBy2
+ scf
+ ret
+; 0x1d543
+
+OpeningSequenceCmd_FadeOut: ; 1d543 (7:5543)
+ farcall Func_10d50
+ ld a, TRUE
+ ld [wOpeningSequencePalsNeedUpdate], a
+ call AdvanceOpeningSequenceCmdPtrBy2
+ scf
+ ret
+; 0x1d551
+
+OpeningSequenceCmd_LoadCharizardScene: ; 1d551 (7:5551)
+ lb bc, 6, 3
+ ld a, SCENE_CHARIZARD_INTRO
+ jr LoadOpeningSceneAndUpdateSGBBorder
+
+OpeningSequenceCmd_LoadScytherScene: ; 1d558 (7:5558)
+ lb bc, 6, 3
+ ld a, SCENE_SCYTHER_INTRO
+ jr LoadOpeningSceneAndUpdateSGBBorder
+
+OpeningSequenceCmd_LoadAerodactylScene: ; 1d55f (7:555f)
+ lb bc, 6, 3
+ ld a, SCENE_AERODACTYL_INTRO
+; fallthrough
+
+LoadOpeningSceneAndUpdateSGBBorder: ; 1d564 (7:5564)
+ call LoadOpeningScene
+ ld l, %001010
+ lb bc, 0, 0
+ lb de, 20, 18
+ farcall Func_70498
+ scf
+ ret
+; 0x1d575
+
+OpeningSequenceCmd_LoadTitleScreenScene: ; 1d575 (7:5575)
+ lb bc, 0, 0
+ ld a, SCENE_TITLE_SCREEN
+ call LoadOpeningScene
+ call OpeningSequenceEmptyFunc
+ scf
+ ret
+; 0x1d582
+
+; a = scene ID
+; bc = coordinates for scene
+LoadOpeningScene: ; 1d582 (7:5582)
+ push af
+ push bc
+ call DisableLCD
+ pop bc
+ pop af
+
+ farcall _LoadScene ; TODO change func name?
+ farcall Func_10d17
+
+ xor a
+ ld [wOpeningSequencePalsNeedUpdate], a
+ call AdvanceOpeningSequenceCmdPtrBy2
+ call EnableLCD
+ ret
+; 0x1d59c
+
+OpeningSequenceEmptyFunc: ; 1d59c (7:559c)
+ ret
+; 0x1d59d