mirror of
https://gitlab.com/xCrystal/pokecrystal-board.git
synced 2024-09-09 09:51:34 -07:00
Use LCD STAT interrupt more efficiently (#2)
This commit is contained in:
parent
5f0cdcaa85
commit
0d8fb09612
@ -36,7 +36,8 @@ DEF LCD_STAT EQU 1
|
|||||||
DEF TIMER EQU 2
|
DEF TIMER EQU 2
|
||||||
DEF SERIAL EQU 3
|
DEF SERIAL EQU 3
|
||||||
DEF JOYPAD EQU 4
|
DEF JOYPAD EQU 4
|
||||||
DEF IE_DEFAULT EQU (1 << SERIAL) | (1 << TIMER) | (1 << LCD_STAT) | (1 << VBLANK)
|
DEF IE_DEFAULT EQU (1 << SERIAL) | (1 << LCD_STAT) | (1 << VBLANK)
|
||||||
|
DEF IE_DEFAULT_WO_LCD_STAT EQU (1 << SERIAL) | (1 << VBLANK)
|
||||||
|
|
||||||
; OAM attribute flags
|
; OAM attribute flags
|
||||||
DEF OAM_TILE_BANK EQU 3
|
DEF OAM_TILE_BANK EQU 3
|
||||||
|
@ -104,7 +104,7 @@ endc
|
|||||||
|
|
||||||
xor a
|
xor a
|
||||||
ldh [rIF], a
|
ldh [rIF], a
|
||||||
ld a, (1 << JOYPAD) | (1 << SERIAL) | (1 << TIMER) | (1 << VBLANK)
|
ld a, (1 << JOYPAD) | (1 << SERIAL) | (1 << VBLANK)
|
||||||
ldh [rIE], a
|
ldh [rIE], a
|
||||||
|
|
||||||
call Link_CopyRandomNumbers
|
call Link_CopyRandomNumbers
|
||||||
@ -280,7 +280,7 @@ endc
|
|||||||
|
|
||||||
xor a
|
xor a
|
||||||
ldh [rIF], a
|
ldh [rIF], a
|
||||||
ld a, (1 << JOYPAD) | (1 << SERIAL) | (1 << TIMER) | (1 << VBLANK)
|
ld a, (1 << JOYPAD) | (1 << SERIAL) | (1 << VBLANK)
|
||||||
ldh [rIE], a
|
ldh [rIE], a
|
||||||
ld de, MUSIC_NONE
|
ld de, MUSIC_NONE
|
||||||
call PlayMusic
|
call PlayMusic
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
ClearedLevelScreen:
|
ClearedLevelScreen:
|
||||||
xor a
|
xor a
|
||||||
ldh [hMapAnims], a
|
ldh [hMapAnims], a
|
||||||
|
ldh [hLCDStatIntRequired], a
|
||||||
ldh [hSCY], a
|
ldh [hSCY], a
|
||||||
ld a, -$4
|
ld a, -$4
|
||||||
ldh [hSCX], a
|
ldh [hSCX], a
|
||||||
|
@ -14,6 +14,7 @@ GameMenu:
|
|||||||
GameMenu_KeepMusic:
|
GameMenu_KeepMusic:
|
||||||
xor a
|
xor a
|
||||||
ldh [hMapAnims], a
|
ldh [hMapAnims], a
|
||||||
|
ldh [hLCDStatIntRequired], a
|
||||||
call ClearTilemap
|
call ClearTilemap
|
||||||
call LoadFrame
|
call LoadFrame
|
||||||
call LoadStandardFont
|
call LoadStandardFont
|
||||||
|
@ -4,6 +4,7 @@ LevelSelectionMenu::
|
|||||||
ldh [hMapAnims], a
|
ldh [hMapAnims], a
|
||||||
ldh [hSCY], a
|
ldh [hSCY], a
|
||||||
ldh [hSCX], a
|
ldh [hSCX], a
|
||||||
|
ldh [hLCDStatIntRequired], a
|
||||||
ld a, 1 << DONT_CLEAR_SHADOW_OAM_IN_SPRITE_ANIMS_F
|
ld a, 1 << DONT_CLEAR_SHADOW_OAM_IN_SPRITE_ANIMS_F
|
||||||
ld [wStateFlags], a
|
ld [wStateFlags], a
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ MainMenu:
|
|||||||
.loop
|
.loop
|
||||||
xor a
|
xor a
|
||||||
ldh [hMapAnims], a
|
ldh [hMapAnims], a
|
||||||
|
ldh [hLCDStatIntRequired], a
|
||||||
call ClearTilemap
|
call ClearTilemap
|
||||||
call LoadFrame
|
call LoadFrame
|
||||||
call LoadStandardFont
|
call LoadStandardFont
|
||||||
|
@ -13,6 +13,8 @@ IntroSequence:
|
|||||||
; fallthrough
|
; fallthrough
|
||||||
|
|
||||||
StartTitleScreen:
|
StartTitleScreen:
|
||||||
|
ld a, TRUE
|
||||||
|
ldh [hLCDStatIntRequired], a
|
||||||
ldh a, [rSVBK]
|
ldh a, [rSVBK]
|
||||||
push af
|
push af
|
||||||
ld a, BANK(wLYOverrides)
|
ld a, BANK(wLYOverrides)
|
||||||
|
@ -8,6 +8,9 @@ Credits::
|
|||||||
.okay
|
.okay
|
||||||
ld [wJumptableIndex], a
|
ld [wJumptableIndex], a
|
||||||
|
|
||||||
|
ld a, TRUE
|
||||||
|
ldh [hLCDStatIntRequired], a
|
||||||
|
|
||||||
ldh a, [rSVBK]
|
ldh a, [rSVBK]
|
||||||
push af
|
push af
|
||||||
ld a, BANK(wGBCPalettes)
|
ld a, BANK(wGBCPalettes)
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
CrystalIntro:
|
CrystalIntro:
|
||||||
|
ld a, TRUE
|
||||||
|
ldh [hLCDStatIntRequired], a
|
||||||
ldh a, [rSVBK]
|
ldh a, [rSVBK]
|
||||||
push af
|
push af
|
||||||
ld a, BANK(wGBCPalettes)
|
ld a, BANK(wGBCPalettes)
|
||||||
|
@ -3,6 +3,8 @@ SECTION "Events", ROMX
|
|||||||
OverworldLoop::
|
OverworldLoop::
|
||||||
xor a ; MAPSTATUS_START
|
xor a ; MAPSTATUS_START
|
||||||
ld [wMapStatus], a
|
ld [wMapStatus], a
|
||||||
|
ld a, TRUE
|
||||||
|
ld [hLCDStatIntRequired], a
|
||||||
.loop
|
.loop
|
||||||
ld a, [wMapStatus]
|
ld a, [wMapStatus]
|
||||||
ld hl, .Jumptable
|
ld hl, .Jumptable
|
||||||
|
@ -151,7 +151,8 @@ Init::
|
|||||||
|
|
||||||
xor a
|
xor a
|
||||||
ldh [rIF], a
|
ldh [rIF], a
|
||||||
ld a, IE_DEFAULT
|
ldh [hLCDStatIntRequired], a
|
||||||
|
ld a, IE_DEFAULT_WO_LCD_STAT
|
||||||
ldh [rIE], a
|
ldh [rIE], a
|
||||||
ei
|
ei
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ Serial_ExchangeByte::
|
|||||||
|
|
||||||
.not_player_1_or_timed_out
|
.not_player_1_or_timed_out
|
||||||
ldh a, [rIE]
|
ldh a, [rIE]
|
||||||
and (1 << SERIAL) | (1 << TIMER) | (1 << LCD_STAT) | (1 << VBLANK)
|
and IE_DEFAULT
|
||||||
cp 1 << SERIAL
|
cp 1 << SERIAL
|
||||||
jr nz, .loop
|
jr nz, .loop
|
||||||
ld a, [wLinkByteTimeout]
|
ld a, [wLinkByteTimeout]
|
||||||
@ -180,7 +180,7 @@ Serial_ExchangeByte::
|
|||||||
xor a
|
xor a
|
||||||
ldh [hSerialReceivedNewData], a
|
ldh [hSerialReceivedNewData], a
|
||||||
ldh a, [rIE]
|
ldh a, [rIE]
|
||||||
and (1 << SERIAL) | (1 << TIMER) | (1 << LCD_STAT) | (1 << VBLANK)
|
and IE_DEFAULT
|
||||||
sub 1 << SERIAL
|
sub 1 << SERIAL
|
||||||
jr nz, .non_serial_interrupts_enabled
|
jr nz, .non_serial_interrupts_enabled
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ Serial_ExchangeByte::
|
|||||||
|
|
||||||
.timed_out
|
.timed_out
|
||||||
ldh a, [rIE]
|
ldh a, [rIE]
|
||||||
and (1 << SERIAL) | (1 << TIMER) | (1 << LCD_STAT) | (1 << VBLANK)
|
and IE_DEFAULT
|
||||||
cp 1 << SERIAL
|
cp 1 << SERIAL
|
||||||
ld a, SERIAL_NO_DATA_BYTE
|
ld a, SERIAL_NO_DATA_BYTE
|
||||||
ret z
|
ret z
|
||||||
|
@ -35,12 +35,12 @@ VBlank::
|
|||||||
reti
|
reti
|
||||||
|
|
||||||
.VBlanks:
|
.VBlanks:
|
||||||
dw VBlank0
|
dw VBlank0 ; normal operation
|
||||||
dw VBlank1
|
dw VBlank1 ; battle transition, battle anims (double speed mode)
|
||||||
dw VBlank2
|
dw VBlank2 ; link
|
||||||
dw VBlank3
|
dw VBlank3 ; battle anims (regular speed mode)
|
||||||
dw VBlank4
|
dw VBlank4 ; printer
|
||||||
dw VBlank5
|
dw VBlank5 ; credits
|
||||||
dw VBlank6
|
dw VBlank6
|
||||||
dw VBlank0 ; just in case
|
dw VBlank0 ; just in case
|
||||||
|
|
||||||
@ -118,6 +118,7 @@ VBlank0::
|
|||||||
ldh [hVBlankOccurred], a
|
ldh [hVBlankOccurred], a
|
||||||
|
|
||||||
; if hWindowHUDLY is active, enable interrupts so the LCD interrupt can trigger
|
; if hWindowHUDLY is active, enable interrupts so the LCD interrupt can trigger
|
||||||
|
; while non-vblank-sensitive operations are executed.
|
||||||
ldh a, [hWindowHUDLY]
|
ldh a, [hWindowHUDLY]
|
||||||
and a
|
and a
|
||||||
jr z, .next2
|
jr z, .next2
|
||||||
@ -163,10 +164,9 @@ VBlank0::
|
|||||||
ldh a, [hROMBankBackup]
|
ldh a, [hROMBankBackup]
|
||||||
rst Bankswitch
|
rst Bankswitch
|
||||||
|
|
||||||
; if hWindowHUDLY is not active, we're done
|
|
||||||
ldh a, [hWindowHUDLY]
|
ldh a, [hWindowHUDLY]
|
||||||
and a
|
and a
|
||||||
ret z
|
jr z, .no_window_hud
|
||||||
|
|
||||||
; interrupts must be enabled in the cycle that rLY becomes [hWindowHUDLY] to prevent flickering
|
; interrupts must be enabled in the cycle that rLY becomes [hWindowHUDLY] to prevent flickering
|
||||||
; wait until [hWindowHUDLY] - [rLY] is NOT between 0 and 2 before disabling interrupts
|
; wait until [hWindowHUDLY] - [rLY] is NOT between 0 and 2 before disabling interrupts
|
||||||
@ -178,9 +178,17 @@ VBlank0::
|
|||||||
cp 2 + 1
|
cp 2 + 1
|
||||||
jr c, .wait_loop
|
jr c, .wait_loop
|
||||||
|
|
||||||
; restore normal interrupts: enable ints besides joypad and let vblank finish
|
.no_window_hud
|
||||||
|
; if hWindowHUDLY is active, only LCD_STAT is enabled.
|
||||||
|
; if hLCDStatIntRequired changeed during last frame, interrupts to request have changed.
|
||||||
|
; so, restore normal interrupts: enable ints besides joypad (and maybe lcd stat) and let vblank finish.
|
||||||
di
|
di
|
||||||
|
ld a, [hLCDStatIntRequired]
|
||||||
|
and a
|
||||||
ld a, IE_DEFAULT
|
ld a, IE_DEFAULT
|
||||||
|
jr nz, .enable_ints
|
||||||
|
ld a, IE_DEFAULT_WO_LCD_STAT
|
||||||
|
.enable_ints
|
||||||
ldh [rIE], a
|
ldh [rIE], a
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
@ -13,6 +13,8 @@ hVBlankOccurred:: db
|
|||||||
|
|
||||||
hROMBank:: db
|
hROMBank:: db
|
||||||
hVBlank:: db
|
hVBlank:: db
|
||||||
|
hLCDStatIntRequired:: db
|
||||||
|
|
||||||
hMapEntryMethod:: db
|
hMapEntryMethod:: db
|
||||||
|
|
||||||
hJoypadReleased:: db
|
hJoypadReleased:: db
|
||||||
|
Loading…
Reference in New Issue
Block a user