From 11db1300b2a48b3861636f8a092c901e01d110ce Mon Sep 17 00:00:00 2001 From: xCrystal Date: Mon, 28 Aug 2023 12:03:32 +0200 Subject: [PATCH] Window HUD: Handle Window being fully shown during reanchor map (#15) --- engine/battle/battle_transition.asm | 3 +-- engine/overworld/init_map.asm | 7 +++++-- home/window.asm | 23 +++++++++++++++++------ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/engine/battle/battle_transition.asm b/engine/battle/battle_transition.asm index 703a4dacc..c626b033f 100644 --- a/engine/battle/battle_transition.asm +++ b/engine/battle/battle_transition.asm @@ -70,8 +70,7 @@ DoBattleTransition: call DelayFrame call .LoadPokeballTiles call CopyTilemapAtOnce - ld a, SCREEN_HEIGHT_PX - ldh [hWY], a + call HideWindow_EnableLCDInt call DelayFrame xor a ldh [hBGMapMode], a diff --git a/engine/overworld/init_map.asm b/engine/overworld/init_map.asm index 2a8ea4667..c394f3799 100644 --- a/engine/overworld/init_map.asm +++ b/engine/overworld/init_map.asm @@ -34,7 +34,11 @@ ReanchorBGMap_NoOAMUpdate:: farcall ApplyPals ld a, TRUE ldh [hCGBPalUpdate], a + ; display window while BG map is reanchored. + ; disable LCD interrupt to prevent cropping the window due to hWindowHUD + ; (caller must re-enable when window is hidden again). xor a + ldh [rSTAT], a ldh [hBGMapMode], a ldh [hWY], a farcall HDMATransfer_FillBGMap0WithBlack ; no need to farcall @@ -63,8 +67,7 @@ LoadFont_NoOAMUpdate:: ldh [hOAMUpdate], a call LoadFrame - ld a, $90 - ldh [hWY], a + call HideWindow_EnableLCDInt call SafeUpdateSprites call LoadStandardFont diff --git a/home/window.asm b/home/window.asm index b2611c384..002ce6dc1 100644 --- a/home/window.asm +++ b/home/window.asm @@ -7,8 +7,7 @@ RefreshScreen:: call ReanchorBGMap_NoOAMUpdate call _OpenAndCloseMenu_HDMATransferTilemapAndAttrmap - ld a, $90 - ldh [hWY], a + call HideWindow_EnableLCDInt pop af rst Bankswitch @@ -51,8 +50,7 @@ OpenText2bpp:: call ReanchorBGMap_NoOAMUpdate ; clear bgmap call SpeechTextbox2bpp call _OpenAndCloseMenu_HDMATransferTilemapAndAttrmap ; anchor bgmap - ld a, $90 - ldh [hWY], a + call HideWindow_EnableLCDInt pop af rst Bankswitch @@ -109,6 +107,18 @@ SafeUpdateSprites:: ldh [hOAMUpdate], a ret +HideWindow_EnableLCDInt:: + ld a, $90 + ldh [hWY], a + ldh a, [hWindowHUD] + and a + ld a, 1 << rSTAT_INT_HBLANK + jr z, .ok + ld a, 1 << rSTAT_INT_LYC +.ok + ldh [rSTAT], a + ret + OVERWORLD_HUD_HEIGHT EQU 8 EnableOverworldWindowHUD:: @@ -119,11 +129,12 @@ EnableWindowHUD: ldh [hWindowHUD], a ; configure LCD interrupt ldh [rLYC], a - ld a, 1 << rSTAT_INT_LYC ; LYC=LC - ldh [rSTAT], a ; make window hidden this frame to prevent graphical glitches ld a, $90 ldh [hWY], a + ; configure LCD interrupt + ld a, 1 << rSTAT_INT_LYC ; LYC=LC + ldh [rSTAT], a ret DisableWindowHUD::