ref: 395ebd83866161a93276f030bbf67f6ac0895f0f
parent: abf3858fc4bc317f8cd43e04b46d5a11d14927de
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Sat May 16 18:25:52 EDT 2020
Format all CopyTilemapAtOnce variations the same way
--- a/engine/menus/savemenu_copytilemapatonce.asm
+++ b/engine/menus/savemenu_copytilemapatonce.asm
@@ -3,33 +3,37 @@
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 @@
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 @@
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
--- a/engine/phone/phonering_copytilemapatonce.asm
+++ b/engine/phone/phonering_copytilemapatonce.asm
@@ -6,15 +6,18 @@
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 @@
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 @@
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 @@
.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
--- a/home/tilemap.asm
+++ b/home/tilemap.asm
@@ -58,13 +58,13 @@
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 @@
.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 @@
ldh [hBGMapMode], a
ret
-.StackPointerMagic:
+.CopyBGMapViaStack:
; Copy all tiles to vBGMap
ld [hSPBuffer], sp
ld sp, hl
@@ -122,7 +122,7 @@
ldh a, [c]
and b
jr nz, .loop\@
-; load BGMap0
+; load vBGMap
ld [hl], e
inc l
ld [hl], d