diff --git a/engine/menus/savemenu_copytilemapatonce.asm b/engine/menus/savemenu_copytilemapatonce.asm index 51b7ea8fe..2f30b7c7e 100644 --- a/engine/menus/savemenu_copytilemapatonce.asm +++ b/engine/menus/savemenu_copytilemapatonce.asm @@ -3,33 +3,37 @@ SaveMenu_CopyTilemapAtOnce: and a jp z, WaitBGMap -; The following is a modified version of 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 -.WaitLY: + +.wait ldh a, [rLY] cp $60 - jr c, .WaitLY + jr c, .wait di ld a, BANK(vBGMap2) ldh [rVBK], a hlcoord 0, 0, wAttrmap - call .CopyTilemapAtOnce + call .CopyBGMapViaStack ld a, BANK(vBGMap0) ldh [rVBK], a hlcoord 0, 0 - call .CopyTilemapAtOnce -.WaitLY2: + call .CopyBGMapViaStack + +.wait2 ldh a, [rLY] cp $60 - jr c, .WaitLY2 + jr c, .wait2 ei pop af @@ -38,7 +42,8 @@ SaveMenu_CopyTilemapAtOnce: ldh [hBGMapMode], a ret -.CopyTilemapAtOnce: +.CopyBGMapViaStack: +; Copy all tiles to vBGMap ld [hSPBuffer], sp ld sp, hl ldh a, [hBGMapAddress + 1] @@ -46,16 +51,18 @@ SaveMenu_CopyTilemapAtOnce: ld l, 0 ld a, SCREEN_HEIGHT ldh [hTilesPerCycle], a - ld b, 1 << 1 + ld b, 1 << 1 ; 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 diff --git a/engine/phone/phonering_copytilemapatonce.asm b/engine/phone/phonering_copytilemapatonce.asm index 0ddb3c852..029c2958c 100644 --- a/engine/phone/phonering_copytilemapatonce.asm +++ b/engine/phone/phonering_copytilemapatonce.asm @@ -6,15 +6,18 @@ PhoneRing_CopyTilemapAtOnce: cp $0 jp z, WaitBGMap -; What follows is a modified version of CopyTilemapAtOnce. +; 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 @@ -24,11 +27,12 @@ PhoneRing_CopyTilemapAtOnce: ld a, BANK(vBGMap2) ldh [rVBK], a hlcoord 0, 0, wAttrmap - call .CopyTilemapAtOnce + call .CopyBGMapViaStack ld a, BANK(vBGMap0) ldh [rVBK], a hlcoord 0, 0 - call .CopyTilemapAtOnce + call .CopyBGMapViaStack + .wait2 ldh a, [rLY] cp LY_VBLANK - 1 @@ -41,7 +45,8 @@ PhoneRing_CopyTilemapAtOnce: ldh [hBGMapMode], a ret -.CopyTilemapAtOnce: +.CopyBGMapViaStack: +; Copy all tiles to vBGMap ld [hSPBuffer], sp ld sp, hl ldh a, [hBGMapAddress + 1] @@ -55,10 +60,12 @@ PhoneRing_CopyTilemapAtOnce: .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 diff --git a/home/tilemap.asm b/home/tilemap.asm index 379b1464a..56e6182ef 100644 --- a/home/tilemap.asm +++ b/home/tilemap.asm @@ -58,13 +58,13 @@ CGBOnly_CopyTilemapAtOnce:: jr z, WaitBGMap CopyTilemapAtOnce:: - jr .CopyTilemapAtOnce + jr _CopyTilemapAtOnce ; unused farcall HDMATransferAttrmapAndTilemapToWRAMBank3 ret -.CopyTilemapAtOnce: +_CopyTilemapAtOnce: ldh a, [hBGMapMode] push af xor a @@ -77,22 +77,22 @@ CopyTilemapAtOnce:: .wait ldh a, [rLY] - cp $7f + cp $80 - 1 jr c, .wait di - ld a, BANK(vTiles3) + ld a, BANK(vBGMap2) ldh [rVBK], a hlcoord 0, 0, wAttrmap - call .StackPointerMagic - ld a, BANK(vTiles0) + call .CopyBGMapViaStack + ld a, BANK(vBGMap0) ldh [rVBK], a hlcoord 0, 0 - call .StackPointerMagic + call .CopyBGMapViaStack .wait2 ldh a, [rLY] - cp $7f + cp $80 - 1 jr c, .wait2 ei @@ -102,7 +102,7 @@ CopyTilemapAtOnce:: ldh [hBGMapMode], a ret -.StackPointerMagic: +.CopyBGMapViaStack: ; Copy all tiles to vBGMap ld [hSPBuffer], sp ld sp, hl @@ -122,7 +122,7 @@ rept SCREEN_WIDTH / 2 ldh a, [c] and b jr nz, .loop\@ -; load BGMap0 +; load vBGMap ld [hl], e inc l ld [hl], d