Window HUD: Prevent more Window flickering in blocks that disable interrupts (#15)

This commit is contained in:
xCrystal 2023-08-28 17:31:39 +02:00
parent fd6f02036e
commit f289d5621d
8 changed files with 71 additions and 185 deletions

View File

@ -41,6 +41,18 @@ HDMATransferTilemapAndAttrmap_OverworldEffect::
call PadTilemapForHDMATransfer
call DelayFrame
ldh a, [hWindowHUD]
and a
jr z, .go
; wait until LCD interrupt has ocurred this frame ([rLY] - [hWindowHUD] >= 0)
.wait_lcd
; ldh a, [hWindowHUD]
ld b, a
ldh a, [rLY]
sub b
jr c, .wait_lcd
.go
; Transfer Attrmap and Tilemap to BG map
di
ldh a, [rVBK]
@ -74,6 +86,18 @@ _HDMATransferTilemapAndAttrmap_OpenAndCloseMenu::
call PadTilemapForHDMATransfer
call DelayFrame
ldh a, [hWindowHUD]
and a
jr z, .go
; wait until LCD interrupt has ocurred this frame ([rLY] - [hWindowHUD] >= 0)
.wait_lcd
; ldh a, [hWindowHUD]
ld b, a
ldh a, [rLY]
sub b
jr c, .wait_lcd
.go
; Transfer Attrmap and Tilemap to BG map
di
ldh a, [rVBK]
@ -252,6 +276,18 @@ _continue_HDMATransfer:
cp d
jr nc, .ly_loop
ldh a, [hWindowHUD]
and a
jr z, .go
; wait until LCD interrupt has ocurred this frame ([rLY] - [hWindowHUD] >= 0)
.wait_lcd
; ldh a, [hWindowHUD]
ld b, a
ldh a, [rLY]
sub b
jr c, .wait_lcd
.go
di
; while [rSTAT] & 3: pass
.rstat_loop_1

View File

@ -3,7 +3,7 @@ SaveMenu:
farcall DisplaySaveInfoOnSave
call SpeechTextbox2bpp
call UpdateSprites
farcall SaveMenu_CopyTilemapAtOnce
farcall CopyTilemapAtOnce
ld hl, WouldYouLikeToSaveTheGameText
call SaveTheGame_yesorno
jr nz, .refused
@ -18,7 +18,7 @@ SaveMenu:
.refused
call ExitMenu
farcall SaveMenu_CopyTilemapAtOnce
farcall CopyTilemapAtOnce
scf
ret

View File

@ -1,80 +0,0 @@
SaveMenu_CopyTilemapAtOnce:
; The following is a modified version of _CopyTilemapAtOnce
; that waits for [rLY] to be $60 instead of $80 - 1.
ldh a, [hBGMapMode]
push af
xor a
ldh [hBGMapMode], a
ldh a, [hMapAnims]
push af
xor a
ldh [hMapAnims], a
.wait
ldh a, [rLY]
cp $60
jr c, .wait
di
ld a, BANK(vBGMap2)
ldh [rVBK], a
hlcoord 0, 0, wAttrmap
call .CopyBGMapViaStack
ld a, BANK(vBGMap0)
ldh [rVBK], a
hlcoord 0, 0
call .CopyBGMapViaStack
.wait2
ldh a, [rLY]
cp $60
jr c, .wait2
ei
pop af
ldh [hMapAnims], a
pop af
ldh [hBGMapMode], a
ret
.CopyBGMapViaStack:
; Copy all tiles to vBGMap
ld [hSPBuffer], sp
ld sp, hl
ldh a, [hBGMapAddress + 1]
ld h, a
ld l, 0
ld a, SCREEN_HEIGHT
ldh [hTilesPerCycle], a
ld b, 1 << rSTAT_BUSY ; not in v/hblank
ld c, LOW(rSTAT)
.loop
rept SCREEN_WIDTH / 2
pop de
; if in v/hblank, wait until not in v/hblank
.loop\@
ldh a, [c]
and b
jr nz, .loop\@
; load vBGMap
ld [hl], e
inc l
ld [hl], d
inc l
endr
ld de, BG_MAP_WIDTH - SCREEN_WIDTH
add hl, de
ldh a, [hTilesPerCycle]
dec a
ldh [hTilesPerCycle], a
jr nz, .loop
ldh a, [hSPBuffer]
ld l, a
ldh a, [hSPBuffer + 1]
ld h, a
ld sp, hl
ret

View File

@ -559,6 +559,12 @@ Phone_Wait20Frames:
farcall PhoneRing_CopyTilemapAtOnce
ret
PhoneRing_CopyTilemapAtOnce:
ld a, [wSpriteUpdatesEnabled]
and a
jp z, WaitBGMap
jp CopyTilemapAtOnce
Phone_TextboxWithName:
push bc
call Phone_CallerTextbox

View File

@ -1,84 +0,0 @@
PhoneRing_CopyTilemapAtOnce:
ld a, [wSpriteUpdatesEnabled]
cp $0
jp z, WaitBGMap
; The following is a modified version of _CopyTilemapAtOnce
; that waits for [rLY] to be LY_VBLANK - 1 instead of $80 - 1.
ldh a, [hBGMapMode]
push af
xor a
ldh [hBGMapMode], a
ldh a, [hMapAnims]
push af
xor a
ldh [hMapAnims], a
.wait
ldh a, [rLY]
cp LY_VBLANK - 1
jr c, .wait
di
ld a, BANK(vBGMap2)
ldh [rVBK], a
hlcoord 0, 0, wAttrmap
call .CopyBGMapViaStack
ld a, BANK(vBGMap0)
ldh [rVBK], a
hlcoord 0, 0
call .CopyBGMapViaStack
.wait2
ldh a, [rLY]
cp LY_VBLANK - 1
jr c, .wait2
ei
pop af
ldh [hMapAnims], a
pop af
ldh [hBGMapMode], a
ret
.CopyBGMapViaStack:
; Copy all tiles to vBGMap
ld [hSPBuffer], sp
ld sp, hl
ldh a, [hBGMapAddress + 1]
ld h, a
ld l, 0
ld a, SCREEN_HEIGHT
ldh [hTilesPerCycle], a
ld b, 1 << rSTAT_BUSY ; not in v/hblank
ld c, LOW(rSTAT)
.loop
rept SCREEN_WIDTH / 2
pop de
; if in v/hblank, wait until not in v/hblank
.loop\@
ldh a, [c]
and b
jr nz, .loop\@
; load vBGMap
ld [hl], e
inc l
ld [hl], d
inc l
endr
ld de, BG_MAP_WIDTH - SCREEN_WIDTH
add hl, de
ldh a, [hTilesPerCycle]
dec a
ldh [hTilesPerCycle], a
jr nz, .loop
ldh a, [hSPBuffer]
ld l, a
ldh a, [hSPBuffer + 1]
ld h, a
ld sp, hl
ret

View File

@ -39,9 +39,6 @@ ApplyTilemap::
ret
CopyTilemapAtOnce::
jr _CopyTilemapAtOnce
_CopyTilemapAtOnce:
ldh a, [hBGMapMode]
push af
xor a
@ -52,11 +49,26 @@ _CopyTilemapAtOnce:
xor a
ldh [hMapAnims], a
.wait
ldh a, [rLY]
cp $80 - 1
jr c, .wait
; .wait
; ldh a, [rLY]
; cp $80 - 1
; jr c, .wait
call DelayFrame
ldh a, [hWindowHUD]
and a
jr z, .go
; wait until LCD interrupt has ocurred this frame ([rLY] - [hWindowHUD] >= 0)
.wait_lcd
; ldh a, [hWindowHUD]
ld b, a
ldh a, [rLY]
sub b
jr c, .wait_lcd
.go
di
ld a, BANK(vBGMap2)
ldh [rVBK], a
@ -67,10 +79,10 @@ _CopyTilemapAtOnce:
hlcoord 0, 0
call .CopyBGMapViaStack
.wait2
ldh a, [rLY]
cp $80 - 1
jr c, .wait2
; .wait2
; ldh a, [rLY]
; cp $80 - 1
; jr c, .wait2
ei
pop af
@ -88,13 +100,13 @@ _CopyTilemapAtOnce:
ld l, 0
ld a, SCREEN_HEIGHT
ldh [hTilesPerCycle], a
ld b, 1 << 1 ; not in v/hblank
ld b, 1 << rSTAT_BUSY ; not in v/hblank
ld c, LOW(rSTAT)
.loop
rept SCREEN_WIDTH / 2
pop de
; if in v/hblank, wait until not in v/hblank
; if not in v/hblank, wait until in v/hblank
.loop\@
ldh a, [c]
and b

View File

@ -145,10 +145,8 @@ DisableWindowHUD::
ldh [rLYC], a
ld a, 1 << rSTAT_INT_HBLANK ; hblank (default)
ldh [rSTAT], a
; leave window in default state (enabled and hidden)
; leave window in default state (hidden with WY=$90)
; rLCDC[rLCDC_WINDOW_ENABLE] will be set during next vblank
ld a, $90
ldh [hWY], a
ldh a, [rLCDC]
set rLCDC_WINDOW_ENABLE, a
ldh [rLCDC], a
ret

View File

@ -186,11 +186,9 @@ INCLUDE "engine/tilesets/map_palettes.asm"
INCLUDE "gfx/tileset_palette_maps.asm"
INCLUDE "data/collision/collision_permissions.asm"
INCLUDE "engine/menus/empty_sram.asm"
INCLUDE "engine/menus/savemenu_copytilemapatonce.asm"
INCLUDE "engine/events/checksave.asm"
INCLUDE "data/maps/scenes.asm"
INCLUDE "engine/overworld/load_map_part.asm"
INCLUDE "engine/phone/phonering_copytilemapatonce.asm"
SECTION "bank13_2", ROMX