diff --git a/engine/gfx/dma_transfer.asm b/engine/gfx/dma_transfer.asm index 92e81daa5..be0d8d892 100644 --- a/engine/gfx/dma_transfer.asm +++ b/engine/gfx/dma_transfer.asm @@ -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 diff --git a/engine/menus/save.asm b/engine/menus/save.asm index a083257ba..63aebef9c 100644 --- a/engine/menus/save.asm +++ b/engine/menus/save.asm @@ -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 diff --git a/engine/menus/savemenu_copytilemapatonce.asm b/engine/menus/savemenu_copytilemapatonce.asm deleted file mode 100644 index 1d755a330..000000000 --- a/engine/menus/savemenu_copytilemapatonce.asm +++ /dev/null @@ -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 diff --git a/engine/phone/phone.asm b/engine/phone/phone.asm index f7b3d8102..d06d4c6b8 100644 --- a/engine/phone/phone.asm +++ b/engine/phone/phone.asm @@ -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 diff --git a/engine/phone/phonering_copytilemapatonce.asm b/engine/phone/phonering_copytilemapatonce.asm deleted file mode 100644 index a8b2d266f..000000000 --- a/engine/phone/phonering_copytilemapatonce.asm +++ /dev/null @@ -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 diff --git a/home/tilemap.asm b/home/tilemap.asm index baac2f6df..6466da78a 100644 --- a/home/tilemap.asm +++ b/home/tilemap.asm @@ -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 diff --git a/home/window.asm b/home/window.asm index f9320e6d7..1a05077c9 100644 --- a/home/window.asm +++ b/home/window.asm @@ -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 diff --git a/main.asm b/main.asm index c274f1444..974413334 100644 --- a/main.asm +++ b/main.asm @@ -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