diff --git a/constants/wram_constants.asm b/constants/wram_constants.asm index c0017fa65..43abf334f 100644 --- a/constants/wram_constants.asm +++ b/constants/wram_constants.asm @@ -299,3 +299,16 @@ DEF DAYCARELADY_HAS_MON_F EQU 0 ; shared flag between wDayCareMan and wDayCareLady DEF DAYCARE_INTRO_SEEN_F EQU 7 + +; hVBlank:: +; VBlankHandlers indexes (see home/vblank.asm) + const_def + const VBLANK_NORMAL ; 0 + const VBLANK_CUTSCENE ; 1 + const VBLANK_SOUND_ONLY ; 2 + const VBLANK_UNUSED_3 ; 3 + const VBLANK_SERIAL ; 4 + const VBLANK_CREDITS ; 5 + const VBLANK_UNUSED_6 ; 6 + const VBLANK_UNUSED_7 ; 7 +DEF NUM_VBLANK_HANDLERS EQU const_value diff --git a/engine/battle/battle_transition.asm b/engine/battle/battle_transition.asm index c22244aa4..7836d55e4 100644 --- a/engine/battle/battle_transition.asm +++ b/engine/battle/battle_transition.asm @@ -22,7 +22,7 @@ DoBattleTransition: ld a, [hl] push af vc_hook Reduce_battle_transition_flashing - ld [hl], $1 + ld [hl], VBLANK_CUTSCENE .loop ld a, [wJumptableIndex] diff --git a/engine/battle_anims/anim_commands.asm b/engine/battle_anims/anim_commands.asm index 21bdc44fe..e0650e3ab 100644 --- a/engine/battle_anims/anim_commands.asm +++ b/engine/battle_anims/anim_commands.asm @@ -15,7 +15,7 @@ PlayBattleAnim: ld a, [hl] push af - ld [hl], 1 + ld [hl], VBLANK_CUTSCENE call BattleAnimRunScript pop af diff --git a/engine/events/magnet_train.asm b/engine/events/magnet_train.asm index 2099c58fb..f2d660e7d 100644 --- a/engine/events/magnet_train.asm +++ b/engine/events/magnet_train.asm @@ -31,7 +31,7 @@ MagnetTrain: ld hl, hVBlank ld a, [hl] push af - ld [hl], 1 + ld [hl], VBLANK_CUTSCENE .loop ld a, [wJumptableIndex] bit 7, a diff --git a/engine/link/link.asm b/engine/link/link.asm index 4e520f726..67358255a 100644 --- a/engine/link/link.asm +++ b/engine/link/link.asm @@ -488,6 +488,7 @@ LinkTimeout: xor a ld [hld], a ld [hl], a + assert VBLANK_NORMAL == 0 ldh [hVBlank], a push de hlcoord 0, 12 @@ -2237,7 +2238,7 @@ CheckLinkTimeout_Receptionist: xor a ld [hl], a call WaitBGMap - ld a, $2 + ld a, VBLANK_SOUND_ONLY ldh [hVBlank], a call DelayFrame call DelayFrame @@ -2259,7 +2260,7 @@ CheckLinkTimeout_Gen2: xor a ld [hl], a call WaitBGMap - ld a, $2 + ld a, VBLANK_SOUND_ONLY ldh [hVBlank], a call DelayFrame call DelayFrame @@ -2456,7 +2457,7 @@ Link_EnsureSync: add $d0 ld [wLinkPlayerSyncBuffer], a ld [wLinkPlayerSyncBuffer + 1], a - ld a, $2 + ld a, VBLANK_SOUND_ONLY ldh [hVBlank], a call DelayFrame call DelayFrame diff --git a/engine/movie/credits.asm b/engine/movie/credits.asm index 7206a99c3..58ee56c73 100644 --- a/engine/movie/credits.asm +++ b/engine/movie/credits.asm @@ -72,7 +72,7 @@ Credits:: ; BUG: Credits sequence changes move selection menu behavior (see docs/bugs_and_glitches.md) ldh a, [hVBlank] push af - ld a, $5 + ld a, VBLANK_CREDITS ldh [hVBlank], a ld a, TRUE ldh [hInMenu], a diff --git a/engine/printer/printer.asm b/engine/printer/printer.asm index 20fc4c2f5..c34118798 100644 --- a/engine/printer/printer.asm +++ b/engine/printer/printer.asm @@ -71,7 +71,7 @@ PrintDexEntry: ld hl, hVBlank ld a, [hl] push af - ld [hl], 4 ; vblank mode that calls AskSerial + ld [hl], VBLANK_SERIAL ld a, 8 ; 16 rows ld [wPrinterQueueLength], a @@ -146,7 +146,7 @@ PrintPCBox: ld hl, hVBlank ld a, [hl] push af - ld [hl], 4 ; vblank mode that calls AskSerial + ld [hl], VBLANK_SERIAL xor a ldh [hBGMapMode], a @@ -227,7 +227,7 @@ PrintUnownStamp: ld hl, hVBlank ld a, [hl] push af - ld [hl], 4 ; vblank mode that calls AskSerial + ld [hl], VBLANK_SERIAL xor a ldh [hBGMapMode], a @@ -297,7 +297,7 @@ PrintMailAndExit: ld hl, hVBlank ld a, [hl] push af - ld [hl], 4 ; vblank mode that calls AskSerial + ld [hl], VBLANK_SERIAL ld a, 18 / 2 ld [wPrinterQueueLength], a @@ -341,7 +341,7 @@ PrintPartymon: ld hl, hVBlank ld a, [hl] push af - ld [hl], 4 ; vblank mode that calls AskSerial + ld [hl], VBLANK_SERIAL ld a, 16 / 2 ld [wPrinterQueueLength], a @@ -399,7 +399,7 @@ _PrintDiploma: ld hl, hVBlank ld a, [hl] push af - ld [hl], 4 ; vblank mode that calls AskSerial + ld [hl], VBLANK_SERIAL ln a, 1, 0 ; to be loaded to wPrinterMargins call Printer_PrepareTilemapForPrint diff --git a/home/vblank.asm b/home/vblank.asm index ccb0a0e59..b49927284 100644 --- a/home/vblank.asm +++ b/home/vblank.asm @@ -13,11 +13,11 @@ VBlank:: push hl ldh a, [hVBlank] - and 7 + maskbits NUM_VBLANK_HANDLERS ld e, a ld d, 0 - ld hl, .VBlanks + ld hl, VBlankHandlers add hl, de add hl, de ld a, [hli] @@ -37,17 +37,20 @@ VBlank:: pop af reti -.VBlanks: - dw VBlank0 - dw VBlank1 - dw VBlank2 - dw VBlank3 - dw VBlank4 - dw VBlank5 - dw VBlank0 ; just in case - dw VBlank0 ; just in case - -VBlank0:: +VBlankHandlers: +; entries correspond to VBLANK_* constants (see constants/wram_constants.asm) + table_width 2, VBlankHandlers + dw VBlank_Normal + dw VBlank_Cutscene + dw VBlank_SoundOnly + dw VBlank_Unused + dw VBlank_Serial + dw VBlank_Credits + dw VBlank_Normal ; unused + dw VBlank_Normal ; unused + assert_table_length NUM_VBLANK_HANDLERS + +VBlank_Normal:: ; normal operation ; rng @@ -146,7 +149,7 @@ VBlank0:: ret -VBlank1:: +VBlank_Cutscene:: ; scx, scy ; palettes ; bg map @@ -225,7 +228,7 @@ UpdatePals:: and a ret -VBlank4:: +VBlank_Serial:: ; bg map ; tiles ; oam @@ -256,13 +259,12 @@ VBlank4:: rst Bankswitch ret -VBlank5:: +VBlank_Credits:: ; scx ; palettes ; bg map ; tiles ; joypad -; ldh a, [hROMBank] ld [wROMBankBackup], a @@ -304,7 +306,7 @@ VBlank5:: ldh [rIE], a ret -VBlank2:: +VBlank_SoundOnly:: ; sound only ldh a, [hROMBank] @@ -321,7 +323,7 @@ VBlank2:: ld [wVBlankOccurred], a ret -VBlank3:: +VBlank_Unused:: ; scx, scy ; palettes ; bg map