summaryrefslogtreecommitdiff
path: root/home
diff options
context:
space:
mode:
Diffstat (limited to 'home')
-rw-r--r--home/audio.asm161
-rw-r--r--home/copy2.asm12
-rw-r--r--home/init.asm44
-rw-r--r--home/overworld.asm366
-rw-r--r--home/pic.asm15
-rw-r--r--home/predef.asm2
-rw-r--r--home/text.asm80
-rw-r--r--home/vblank.asm17
-rw-r--r--home/vcopy.asm79
9 files changed, 398 insertions, 378 deletions
diff --git a/home/audio.asm b/home/audio.asm
index 94cf999c..52f29b9b 100644
--- a/home/audio.asm
+++ b/home/audio.asm
@@ -3,56 +3,68 @@ PlayDefaultMusic:: ; 216b (0:216b)
xor a
ld c, a
ld d, a
- ld [wcfca], a
- jr asm_2188
+ ld [wLastMusicSoundID], a
+ jr PlayDefaultMusicCommon
-Func_2176:: ; 2176 (0:2176)
- ld c, $a
- ld d, $0
+PlayDefaultMusicFadeOutCurrent:: ; 2176 (0:2176)
+; Fade out the current music and then play the default music.
+ ld c, 10
+ ld d, 0
ld a, [wd72e]
- bit 5, a
- jr z, asm_2188
+ bit 5, a ; has a battle just ended?
+ jr z, PlayDefaultMusicCommon
xor a
- ld [wcfca], a
- ld c, $8
+ ld [wLastMusicSoundID], a
+ ld c, 8
ld d, c
-asm_2188: ; 2118 (0:2118)
+PlayDefaultMusicCommon:: ; 2118 (0:2118)
ld a, [wWalkBikeSurfState]
and a
- jr z, .asm_21ac
+ jr z, .walking
cp $2
- jr z, .asm_219b
+ jr z, .surfing
call Func_21c8
jr c, .asm_21ac
ld a, $d2 ; MUSIC_BIKE_RIDING
- jr .asm_219d
-.asm_219b
+ jr .next
+
+.surfing
ld a, $d6 ; MUSIC_SURFING
-.asm_219d
+
+.next
ld b, a
ld a, d
- and a
+ and a ; should current music be faded out first?
ld a, $1f ; BANK(Music_BikeRiding)
- jr nz, .asm_21a7
- ld [wc0ef], a
-.asm_21a7
- ld [wc0f0], a
- jr .asm_21b5
-.asm_21ac
- ld a, [wd35b]
+ jr nz, .next2
+
+; Only change the audio ROM bank if the current music isn't going to be faded
+; out before the default music begins.
+ ld [wAudioROMBank], a
+
+.next2
+; [wAudioSavedROMBank] will be copied to [wAudioROMBank] after fading out the
+; current music (if the current music is faded out).
+ ld [wAudioSavedROMBank], a
+ jr .next3
+
+.walking
+ ld a, [wMapMusicSoundID]
ld b, a
- call Func_21f5
- jr c, .asm_21ba
-.asm_21b5
- ld a, [wcfca]
- cp b
- ret z
-.asm_21ba
+ call CompareMapMusicBankWithCurrentBank
+ jr c, .next4
+
+.next3
+ ld a, [wLastMusicSoundID]
+ cp b ; is the default music already playing?
+ ret z ; if so, do nothing
+
+.next4
ld a, c
- ld [wMusicHeaderPointer], a
+ ld [wAudioFadeOutControl], a
ld a, b
- ld [wcfca], a
- ld [wc0ee], a
+ ld [wLastMusicSoundID], a
+ ld [wNewSoundID], a
jp PlaySound
Func_21c8:: ; 21c8 (0:21c8)
@@ -87,7 +99,7 @@ Func_21e3:: ; 21e5 (0:21e5)
ret
;Func_235f:: ; 235f (0:235f)
-; ld a, [wc0ef]
+; ld a, [wAudioROMBank]
; ld b, a
; cp BANK(Music2_UpdateMusic)
; jr nz, .checkForBank08
@@ -114,34 +126,41 @@ Func_21e3:: ; 21e5 (0:21e5)
; jr nz, .asm_237a
; ret
-Func_21f5:: ; 21f5 (0:21f5)
- ld a, [wd35c]
+CompareMapMusicBankWithCurrentBank:: ; 21f5 (0:21f5)
+; Compares the map music's audio ROM bank with the current audio ROM bank
+; and updates the audio ROM bank variables.
+; Returns whether the banks are different in carry.
+ ld a, [wMapMusicROMBank]
ld e, a
- ld a, [wc0ef]
+ ld a, [wAudioROMBank]
cp e
- jr nz, .asm_2204
- ld [wc0f0], a
+ jr nz, .differentBanks
+ ld [wAudioSavedROMBank], a
and a
ret
-.asm_2204
- ld a, c
+.differentBanks
+ ld a, c ; this is a fade-out counter value and it's always non-zero
and a
ld a, e
- jr nz, .asm_220c
- ld [wc0ef], a
-.asm_220c
- ld [wc0f0], a
+ jr nz, .next
+; If the fade-counter is non-zero, we don't change the audio ROM bank because
+; it's needed to keep playing the music as it fades out. The FadeOutAudio
+; routine will take care of copying [wAudioSavedROMBank] to [wAudioROMBank]
+; when the music has faded out.
+ ld [wAudioROMBank], a
+.next
+ ld [wAudioSavedROMBank], a
scf
ret
PlayMusic:: ; 2211 (0:2211)
ld b, a
- ld [wc0ee], a
+ ld [wNewSoundID], a
xor a
- ld [wMusicHeaderPointer], a
+ ld [wAudioFadeOutControl], a
ld a, c
- ld [wc0ef], a
- ld [wc0f0], a
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
ld a, b
jr PlaySound
@@ -163,42 +182,42 @@ PlaySound:: ; 2238 (0:2238)
push de
push bc
ld b, a
- ld a, [wc0ee]
+ ld a, [wNewSoundID]
and a
- jr z, .asm_224f
+ jr z, .next
xor a
ld [wc02a], a
ld [wc02b], a
ld [wc02c], a
ld [wc02d], a
-.asm_224f
- ld a, [wMusicHeaderPointer]
+.next
+ ld a, [wAudioFadeOutControl]
and a
- jr z, .asm_226a
- ld a, [wc0ee]
+ jr z, .noFadeOut
+ ld a, [wNewSoundID]
and a
- jr z, .asm_2284
+ jr z, .done
xor a
- ld [wc0ee], a
- ld a, [wcfca]
+ ld [wNewSoundID], a
+ ld a, [wLastMusicSoundID]
cp $ff
- jr nz, .asm_2273
+ jr nz, .fadeOut
xor a
ld [wMusicHeaderPointer], a
-.asm_226a
+.noFadeOut
xor a
ld [wc0ee], a
call Func_22ec
- jr .asm_2284
-.asm_2273
+ jr .done
+.fadeOut
ld a,b
- ld [wcfca],a
- ld a,[wMusicHeaderPointer]
- ld [wcfc8],a
- ld [wcfc9],a
+ ld [wLastMusicSoundID],a
+ ld a,[wAudioFadeOutControl]
+ ld [wAudioFadeOutCounterReloadValue],a
+ ld [wAudioFadeOutCounter],a
ld a,b
- ld [wMusicHeaderPointer],a
-.asm_2284
+ ld [wAudioFadeOutControl],a
+.done
pop bc
pop de
pop hl
@@ -207,13 +226,13 @@ PlaySound:: ; 2238 (0:2238)
Func_2288:: ; 2288 (0:2288)
ld a,[H_LOADEDROMBANK]
push af
- ld a, [wc0ef]
+ ld a, [wAudioROMBank]
call BankswitchCommon
ld d,$0
ld a,c
add a
ld e,a
- ld hl,wc006
+ ld hl,wChannelCommandPointers
add hl,de
ld a,[hli]
ld e,a
@@ -263,7 +282,7 @@ Func_22d6:: ; 22d6 (0:22d6)
Func_22ec:: ; 22ec (0:22ec)
ld a,[H_LOADEDROMBANK]
push af
- ld a,[wc0ef]
+ ld a,[wAudioROMBank]
call BankswitchCommon
cp BANK(Func_984e)
jr nz, .checkForBank08
diff --git a/home/copy2.asm b/home/copy2.asm
index 086ebc1a..bd1c0f78 100644
--- a/home/copy2.asm
+++ b/home/copy2.asm
@@ -165,7 +165,7 @@ Func_1681:: ; 1681 (0:1681)
ClearScreenArea:: ; 1692 (0:1692)
; Clear tilemap area cxb at hl.
- ld a, $7f ; blank tile
+ ld a, " " ; blank tile
ld de, 20 ; screen width
.y
push hl
@@ -188,17 +188,17 @@ CopyScreenTileBufferToVRAM:: ; 16a4 (0:16a4)
ld c, 6
ld hl, $600 * 0
- ld de, wTileMap + 20 * 6 * 0
+ coord de, 0, 6 * 0
call .setup
call DelayFrame
ld hl, $600 * 1
- ld de, wTileMap + 20 * 6 * 1
+ coord de, 0, 6 * 1
call .setup
call DelayFrame
ld hl, $600 * 2
- ld de, wTileMap + 20 * 6 * 2
+ coord de, 0, 6 * 2
call .setup
jp DelayFrame
@@ -221,8 +221,8 @@ ClearScreen:: ; 16dd (0:16dd)
; for the bg map to update.
ld bc, 20 * 18
inc b
- ld hl, wTileMap
- ld a, $7f
+ coord hl, 0, 0
+ ld a, " "
.loop
ld [hli], a
dec c
diff --git a/home/init.asm b/home/init.asm
index 168524b8..8d0aeab3 100644
--- a/home/init.asm
+++ b/home/init.asm
@@ -1,7 +1,7 @@
SoftReset:: ; 1d08 (0:1d08)
call StopAllSounds
call GBPalWhiteOut
- ld c, $20
+ ld c, 32
call DelayFrames
; fallthrough
@@ -23,17 +23,17 @@ rLCDC_DEFAULT EQU %11100011
xor a
ld [rIF], a
ld [rIE], a
- ld [$ff43], a
- ld [$ff42], a
+ ld [rSCX], a
+ ld [rSCY], a
ld [rSB], a
ld [rSC], a
- ld [$ff4b], a
- ld [$ff4a], a
- ld [$ff06], a
- ld [$ff07], a
- ld [$ff47], a
- ld [$ff48], a
- ld [$ff49], a
+ ld [rWX], a
+ ld [rWY], a
+ ld [rTMA], a
+ ld [rTAC], a
+ ld [rBGP], a
+ ld [rOBP0], a
+ ld [rOBP1], a
ld a, rLCDC_ENABLE_MASK
ld [rLCDC], a
@@ -66,10 +66,10 @@ rLCDC_DEFAULT EQU %11100011
xor a
ld [hTilesetType], a
- ld [$ff41], a
+ ld [rSTAT], a
ld [hSCX], a
ld [hSCY], a
- ld [$ff0f], a
+ ld [rIF], a
ld [wc0f3], a
ld [wc0f4], a
ld a, 1 << VBLANK + 1 << TIMER + 1 << SERIAL
@@ -100,12 +100,12 @@ rLCDC_DEFAULT EQU %11100011
predef LoadSGB
ld a, $1f ; BANK(SFX_1f_67)
- ld [wc0ef], a
- ld [wc0f0], a
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
ld a, $9c
- ld [$ffbd], a
+ ld [H_AUTOBGTRANSFERDEST + 1], a
xor a
- ld [$ffbc], a
+ ld [H_AUTOBGTRANSFERDEST], a
dec a
ld [wUpdateSpritesEnabled], a
@@ -128,11 +128,11 @@ ClearVram: ; 1dc6 (0:1dc6)
StopAllSounds::
- ld a, BANK(Music2_UpdateMusic)
- ld [wc0ef], a
- ld [wc0f0], a
+ ld a, BANK(Audio1_UpdateMusic)
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
xor a
- ld [wMusicHeaderPointer], a
- ld [wc0ee], a
- ld [wcfca], a
+ ld [wAudioFadeOutControl], a
+ ld [wNewSoundID], a
+ ld [wLastMusicSoundID], a
jp StopAllMusic
diff --git a/home/overworld.asm b/home/overworld.asm
index 4ae1d36a..7b9fadfa 100644
--- a/home/overworld.asm
+++ b/home/overworld.asm
@@ -108,9 +108,9 @@ OverworldLoopLessDelay:: ; 0245 (0:0245)
bit 0,a
jr nz,.checkForOpponent
aCoord 8, 9
- ld [wcf0e],a
+ ld [wTilePlayerStandingOn],a ; unused?
call DisplayTextID ; display either the start menu or the NPC/sign text
- ld a,[wcc47]
+ ld a,[wEnteringCableClub]
and a
jr z,.checkForOpponent
xor a
@@ -136,55 +136,55 @@ OverworldLoopLessDelay:: ; 0245 (0:0245)
xor a
ld [wd435], a
ld a, $1
- ld [wcc4b],a
- ld a,[wd528] ; the direction that was pressed last time
+ ld [wCheckFor180DegreeTurn],a
+ ld a,[wPlayerMovingDirection] ; the direction that was pressed last time
and a
jr z, .overworldloop
; if a direction was pressed last time
- ld [wd529],a ; save the last direction
+ ld [wPlayerLastStopDirection],a ; save the last direction
xor a
- ld [wd528],a ; zero the direction
+ ld [wPlayerMovingDirection],a ; zero the direction
.overworldloop
jp OverworldLoop
.checkIfDownButtonIsPressed
ld a,[hJoyHeld] ; current joypad state
bit 7,a ; down button
jr z,.checkIfUpButtonIsPressed
- ld a,$01
- ld [wSpriteStateData1 + 3],a
- ld a,$04
+ ld a,1
+ ld [wSpriteStateData1 + 3],a ; delta Y
+ ld a,PLAYER_DIR_DOWN
jr .handleDirectionButtonPress
.checkIfUpButtonIsPressed
bit 6,a ; up button
jr z,.checkIfLeftButtonIsPressed
- ld a,$ff
- ld [wSpriteStateData1 + 3],a
- ld a,$08
+ ld a,-1
+ ld [wSpriteStateData1 + 3],a ; delta Y
+ ld a,PLAYER_DIR_UP
jr .handleDirectionButtonPress
.checkIfLeftButtonIsPressed
bit 5,a ; left button
jr z,.checkIfRightButtonIsPressed
- ld a,$ff
- ld [wSpriteStateData1 + 5],a
- ld a,$02
+ ld a,-1
+ ld [wSpriteStateData1 + 5],a ; delta X
+ ld a,PLAYER_DIR_LEFT
jr .handleDirectionButtonPress
.checkIfRightButtonIsPressed
bit 4,a ; right button
jr z,.noDirectionButtonsPressed
- ld a,$01
+ ld a,$1
ld [wSpriteStateData1 + 5],a
ld a,$1
.handleDirectionButtonPress
- ld [wd52a],a ; new direction
+ ld [wPlayerDirection],a ; new direction
ld a,[wd730]
bit 7,a ; are we simulating button presses?
jr nz,.noDirectionChange ; ignore direction changes if we are
- ld a,[wcc4b]
+ ld a,[wCheckFor180DegreeTurn]
and a
jr z,.noDirectionChange
- ld a,[wd52a] ; new direction
+ ld a,[wPlayerDirection] ; new direction
ld b,a
- ld a,[wd529] ; old direction
+ ld a,[wPlayerLastStopDirection] ; old direction
cp b
jr z,.noDirectionChange
ld a,$8
@@ -193,15 +193,15 @@ OverworldLoopLessDelay:: ; 0245 (0:0245)
ld hl,wFlags_0xcd60
set 2,[hl]
xor a
- ld [wcc4b],a
+ ld [wCheckFor180DegreeTurn],a
ld a,[wd52a]
ld [wd528],a
call NewBattle
jp c,.battleOccurred
jp OverworldLoop
.noDirectionChange
- ld a,[wd52a] ; current direction
- ld [wd528],a ; save direction
+ ld a,[wPlayerDirection] ; current direction
+ ld [wPlayerMovingDirection],a ; save direction
call UpdateSprites
ld a,[wWalkBikeSurfState]
cp a,$02 ; surfing
@@ -256,7 +256,7 @@ OverworldLoopLessDelay:: ; 0245 (0:0245)
and a
jp nz,CheckWarpsNoCollision
predef ApplyOutOfBattlePoisonDamage ; also increment daycare mon exp
- ld a,[wd12d]
+ ld a,[wOutOfBattleBlackout]
and a
jp nz,HandleBlackOut ; if all pokemon fainted
.newBattle
@@ -290,7 +290,7 @@ OverworldLoopLessDelay:: ; 0245 (0:0245)
and a
jr z,AllPokemonFainted
.noFaintCheck
- ld c,$0a
+ ld c,10
call DelayFrames
jp EnterMap
@@ -329,9 +329,7 @@ NewBattle:: ; 0480 (0:0480)
ld a,[wd72e]
bit 4,a
jr nz,.noBattle
- ld b, BANK(InitBattle)
- ld hl, InitBattle ; 3d:5ff2
- jp Bankswitch
+ jpba InitBattle ; 3d:5ff2
.noBattle
and a
ret
@@ -435,7 +433,7 @@ CheckWarpsCollision:: ; 051a (0:051a)
ld a,[hli]
ld [wDestinationWarpID],a
ld a,[hl]
- ld [$ff8b],a ; save target map
+ ld [hWarpDestinationMap],a
jr WarpFound2
.retry1
inc hl
@@ -450,23 +448,23 @@ WarpFound1:: ; 0543 (0:0543)
ld a,[hli]
ld [wDestinationWarpID],a
ld a,[hli]
- ld [$ff8b],a ; save target map
+ ld [hWarpDestinationMap],a
WarpFound2:: ; 054a (0:054a)
ld a,[wNumberOfWarps]
sub c
- ld [wd73b],a ; save ID of used warp
+ ld [wWarpedFromWhichWarp],a ; save ID of used warp
ld a,[W_CURMAP]
- ld [wd73c],a
+ ld [wWarpedFromWhichMap],a
call CheckIfInOutsideMap
jr nz,.indoorMaps
; this is for handling "outside" maps that can't have the 0xFF destination map
ld a,[W_CURMAP]
ld [wLastMap],a
ld a,[W_CURMAPWIDTH]
- ld [wd366],a
- ld a,[$ff8b] ; destination map number
- ld [W_CURMAP],a ; change current map to destination map
+ ld [wUnusedD366],a ; not read
+ ld a,[hWarpDestinationMap]
+ ld [W_CURMAP],a
cp a,ROCK_TUNNEL_1
jr nz,.notRockTunnel
ld a,$06
@@ -478,13 +476,13 @@ WarpFound2:: ; 054a (0:054a)
jr .done
; for maps that can have the 0xFF destination map, which means to return to the outside map; not all these maps are necessarily indoors, though
.indoorMaps
- ld a,[$ff8b] ; destination map
+ ld a,[hWarpDestinationMap] ; destination map
cp a,$ff
jr z,.goBackOutside
; if not going back to the previous map
- ld [W_CURMAP],a ; current map number
+ ld [W_CURMAP],a
callba IsPlayerStandingOnWarpPadOrHole
- ld a,[wcd5b]
+ ld a,[wStandingOnWarpPadOrHole]
dec a ; is the player on a warp pad?
jr nz,.notWarpPad
; if the player is on a warp pad
@@ -521,26 +519,26 @@ CheckMapConnections:: ; 05db (0:05db)
jr nz,.checkEastMap
ld a,[W_MAPCONN3PTR]
ld [W_CURMAP],a
- ld a,[wd38f] ; new X coordinate upon entering west map
+ ld a,[wWestConnectedMapXAlignment] ; new X coordinate upon entering west map
ld [W_XCOORD],a
ld a,[W_YCOORD]
ld c,a
- ld a,[wd38e] ; Y adjustment upon entering west map
+ ld a,[wWestConnectedMapYAlignment] ; Y adjustment upon entering west map
add c
ld c,a
ld [W_YCOORD],a
- ld a,[wd390] ; pointer to upper left corner of map without adjustment for Y position
+ ld a,[wWestConnectedMapViewPointer] ; pointer to upper left corner of map without adjustment for Y position
ld l,a
- ld a,[wd391]
+ ld a,[wWestConnectedMapViewPointer + 1]
ld h,a
srl c
jr z,.savePointer1
.pointerAdjustmentLoop1
- ld a,[wd38d] ; width of connected map
- add a,$06
+ ld a,[wWestConnectedMapWidth] ; width of connected map
+ add a,MAP_BORDER * 2
ld e,a
- ld d,$00
- ld b,$00
+ ld d,0
+ ld b,0
add hl,de
dec c
jr nz,.pointerAdjustmentLoop1
@@ -552,31 +550,31 @@ CheckMapConnections:: ; 05db (0:05db)
jp .loadNewMap
.checkEastMap
ld b,a
- ld a,[wd525] ; map width
+ ld a,[wCurrentMapWidth2] ; map width
cp b
jr nz,.checkNorthMap
ld a,[W_MAPCONN4PTR]
ld [W_CURMAP],a
- ld a,[wd39a] ; new X coordinate upon entering east map
+ ld a,[wEastConnectedMapXAlignment] ; new X coordinate upon entering east map
ld [W_XCOORD],a
ld a,[W_YCOORD]
ld c,a
- ld a,[wd399] ; Y adjustment upon entering east map
+ ld a,[wEastConnectedMapYAlignment] ; Y adjustment upon entering east map
add c
ld c,a
ld [W_YCOORD],a
- ld a,[wd39b] ; pointer to upper left corner of map without adjustment for Y position
+ ld a,[wEastConnectedMapViewPointer] ; pointer to upper left corner of map without adjustment for Y position
ld l,a
- ld a,[wd39c]
+ ld a,[wEastConnectedMapViewPointer + 1]
ld h,a
srl c
jr z,.savePointer2
.pointerAdjustmentLoop2
- ld a,[wd398]
- add a,$06
+ ld a,[wEastConnectedMapWidth]
+ add a,MAP_BORDER * 2
ld e,a
- ld d,$00
- ld b,$00
+ ld d,0
+ ld b,0
add hl,de
dec c
jr nz,.pointerAdjustmentLoop2
@@ -592,19 +590,19 @@ CheckMapConnections:: ; 05db (0:05db)
jr nz,.checkSouthMap
ld a,[W_MAPCONN1PTR]
ld [W_CURMAP],a
- ld a,[wd378] ; new Y coordinate upon entering north map
+ ld a,[wNorthConnectedMapYAlignment] ; new Y coordinate upon entering north map
ld [W_YCOORD],a
ld a,[W_XCOORD]
ld c,a
- ld a,[wd379] ; X adjustment upon entering north map
+ ld a,[wNorthConnectedMapXAlignment] ; X adjustment upon entering north map
add c
ld c,a
ld [W_XCOORD],a
- ld a,[wd37a] ; pointer to upper left corner of map without adjustment for X position
+ ld a,[wNorthConnectedMapViewPointer] ; pointer to upper left corner of map without adjustment for X position
ld l,a
- ld a,[wd37b]
+ ld a,[wNorthConnectedMapViewPointer + 1]
ld h,a
- ld b,$00
+ ld b,0
srl c
add hl,bc
ld a,l
@@ -614,24 +612,24 @@ CheckMapConnections:: ; 05db (0:05db)
jp .loadNewMap
.checkSouthMap
ld b,a
- ld a,[wd524]
+ ld a,[wCurrentMapHeight2]
cp b
jr nz,.didNotEnterConnectedMap
ld a,[W_MAPCONN2PTR]
ld [W_CURMAP],a
- ld a,[wd383] ; new Y coordinate upon entering south map
+ ld a,[wSouthConnectedMapYAlignment] ; new Y coordinate upon entering south map
ld [W_YCOORD],a
ld a,[W_XCOORD]
ld c,a
- ld a,[wd384] ; X adjustment upon entering south map
+ ld a,[wSouthConnectedMapXAlignment] ; X adjustment upon entering south map
add c
ld c,a
ld [W_XCOORD],a
- ld a,[wd385] ; pointer to upper left corner of map without adjustment for X position
+ ld a,[wSouthConnectedMapViewPointer] ; pointer to upper left corner of map without adjustment for X position
ld l,a
- ld a,[wd386]
+ ld a,[wSouthConnectedMapViewPointer + 1]
ld h,a
- ld b,$00
+ ld b,0
srl c
add hl,bc
ld a,l
@@ -645,9 +643,9 @@ CheckMapConnections:: ; 05db (0:05db)
ld a,$2
ld [wd431],a
call LoadMapHeader ; 0dab (0:0dab)
- call Func_2176 ; music
- ld b,$09
- call GoPAL_SET
+ call PlayDefaultMusicFadeOutCurrent ; music
+ ld b,SET_PAL_OVERWORLD
+ call RunPaletteCommand
; Since the sprite set shouldn't change, this will just update VRAM slots at
; $C2XE without loading any tile patterns.
call InitMapSprites
@@ -666,10 +664,10 @@ PlayMapChangeSound:: ; 06ef (0:06ef)
aCoord 8, 8 ; upper left tile of the 4x4 square the player's sprite is standing on
cp UNDERGROUND ; door tile in tileset 0
jr nz,.didNotGoThroughDoor
- ld a, $ad ; (SFX_02_57 - SFX_Headers_02) / 3
+ ld a, $ad ; SFX_GO_INSIDE
jr .playSound
.didNotGoThroughDoor
- ld a, $b5 ; (SFX_02_5c - SFX_Headers_02) / 3
+ ld a, $b5 ; SFX_GO_OUTSIDE
.playSound
call PlaySound
ld a,[wMapPalOffset]
@@ -740,14 +738,14 @@ HandleBlackOut:: ; 0762 (0:0762)
switchbank SpecialWarpIn ; also Bank(SpecialEnterMap)
callab ResetStatusAndHalveMoneyOnBlackout ; 3c:4274
call SpecialWarpIn
- call Func_2176
+ call PlayDefaultMusicFadeOutCurrent
jp SpecialEnterMap
StopMusic:: ; 0788 (0:0788)
ld [wMusicHeaderPointer], a
call StopAllMusic
.wait
- ld a, [wMusicHeaderPointer]
+ ld a, [wAudioFadeOutControl]
and a
jr nz, .wait
jp StopAllSounds
@@ -767,11 +765,6 @@ HandleFlyWarpOrDungeonWarp:: ; 0794 (0:0794)
callbs SpecialWarpIn
jp SpecialEnterMap
-LeaveMapAnim:: ; 07bc (0:07bc)
- ld b, BANK(_LeaveMapAnim)
- ld hl, _LeaveMapAnim
- jp Bankswitch
-
Func_07c4:: ; 07c4 (0:07c4)
ld a, [wWalkBikeSurfState]
and a
@@ -874,16 +867,16 @@ LoadTileBlockMap:: ; 083c (0:083c)
; a 3-byte border at the edges of the map is kept so that there is space for map connections
ld hl,wOverworldMap
ld a,[W_CURMAPWIDTH]
- ld [$ff8c],a
- add a,$06 ; border (east and west)
- ld [$ff8b],a ; map width + border
- ld b,$00
+ ld [hMapWidth],a
+ add a,MAP_BORDER * 2 ; east and west
+ ld [hMapStride],a ; map width + border
+ ld b,0
ld c,a
; make space for north border (next 3 lines)
add hl,bc
add hl,bc
add hl,bc
- ld c,$03
+ ld c,MAP_BORDER
add hl,bc ; this puts us past the (west) border
ld a,[W_MAPDATAPTR] ; tile map pointer
ld e,a
@@ -893,7 +886,7 @@ LoadTileBlockMap:: ; 083c (0:083c)
ld b,a
.rowLoop ; copy one row each iteration
push hl
- ld a,[$ff8c] ; map width (without border)
+ ld a,[hMapWidth] ; map width (without border)
ld c,a
.rowInnerLoop
ld a,[de]
@@ -903,7 +896,7 @@ LoadTileBlockMap:: ; 083c (0:083c)
jr nz,.rowInnerLoop
; add the map width plus the border to the base address of the current row to get the next row's address
pop hl
- ld a,[$ff8b] ; map width + border
+ ld a,[hMapStride] ; map width + border
add l
ld l,a
jr nc,.noCarry
@@ -916,82 +909,82 @@ LoadTileBlockMap:: ; 083c (0:083c)
cp a,$ff
jr z,.southConnection
call SwitchToMapRomBank
- ld a,[wd372]
+ ld a,[wNorthConnectionStripSrc]
ld l,a
- ld a,[wd373]
+ ld a,[wNorthConnectionStripSrc + 1]
ld h,a
- ld a,[wd374]
+ ld a,[wNorthConnectionStripDest]
ld e,a
- ld a,[wd375]
+ ld a,[wNorthConnectionStripDest + 1]
ld d,a
- ld a,[wd376]
- ld [$ff8b],a
- ld a,[wd377]
- ld [$ff8c],a
+ ld a,[wNorthConnectionStripWidth]
+ ld [hNorthSouthConnectionStripWidth],a
+ ld a,[wNorthConnectedMapWidth]
+ ld [hNorthSouthConnectedMapWidth],a
call LoadNorthSouthConnectionsTileMap
.southConnection
ld a,[W_MAPCONN2PTR]
cp a,$ff
jr z,.westConnection
call SwitchToMapRomBank
- ld a,[wd37d]
+ ld a,[wSouthConnectionStripSrc]
ld l,a
- ld a,[wd37e]
+ ld a,[wSouthConnectionStripSrc + 1]
ld h,a
- ld a,[wd37f]
+ ld a,[wSouthConnectionStripDest]
ld e,a
- ld a,[wd380]
+ ld a,[wSouthConnectionStripDest + 1]
ld d,a
- ld a,[wd381]
- ld [$ff8b],a
- ld a,[wd382]
- ld [$ff8c],a
+ ld a,[wSouthConnectionStripWidth]
+ ld [hNorthSouthConnectionStripWidth],a
+ ld a,[wSouthConnectedMapWidth]
+ ld [hNorthSouthConnectedMapWidth],a
call LoadNorthSouthConnectionsTileMap
.westConnection
ld a,[W_MAPCONN3PTR]
cp a,$ff
jr z,.eastConnection
call SwitchToMapRomBank
- ld a,[wd388]
+ ld a,[wWestConnectionStripSrc]
ld l,a
- ld a,[wd389]
+ ld a,[wWestConnectionStripSrc + 1]
ld h,a
- ld a,[wd38a]
+ ld a,[wWestConnectionStripDest]
ld e,a
- ld a,[wd38b]
+ ld a,[wWestConnectionStripDest + 1]
ld d,a
- ld a,[wd38c]
+ ld a,[wWestConnectionStripHeight]
ld b,a
- ld a,[wd38d]
- ld [$ff8b],a
+ ld a,[wWestConnectedMapWidth]
+ ld [hEastWestConnectedMapWidth],a
call LoadEastWestConnectionsTileMap
.eastConnection
ld a,[W_MAPCONN4PTR]
cp a,$ff
jr z,.done
call SwitchToMapRomBank
- ld a,[wd393]
+ ld a,[wEastConnectionStripSrc]
ld l,a
- ld a,[wd394]
+ ld a,[wEastConnectionStripSrc + 1]
ld h,a
- ld a,[wd395]
+ ld a,[wEastConnectionStripDest]
ld e,a
- ld a,[wd396]
+ ld a,[wEastConnectionStripDest + 1]
ld d,a
- ld a,[wd397]
+ ld a,[wEastConnectionStripHeight]
ld b,a
- ld a,[wd398]
- ld [$ff8b],a
+ ld a,[wEastConnectedMapWidth]
+ ld [hEastWestConnectedMapWidth],a
call LoadEastWestConnectionsTileMap
.done
ret
LoadNorthSouthConnectionsTileMap:: ; 0919 (0:0919)
- ld c,$03
+ ld c,MAP_BORDER
.loop
push de
push hl
- ld a,[$ff8b] ; width of connection
+ ld a,[hNorthSouthConnectionStripWidth]
ld b,a
.innerLoop
ld a,[hli]
@@ -1001,14 +994,14 @@ LoadNorthSouthConnectionsTileMap:: ; 0919 (0:0919)
jr nz,.innerLoop
pop hl
pop de
- ld a,[$ff8c] ; width of connected map
+ ld a,[hNorthSouthConnectedMapWidth]
add l
ld l,a
jr nc,.noCarry1
inc h
.noCarry1
ld a,[W_CURMAPWIDTH]
- add a,$06
+ add a,MAP_BORDER * 2
add e
ld e,a
jr nc,.noCarry2
@@ -1021,7 +1014,7 @@ LoadNorthSouthConnectionsTileMap:: ; 0919 (0:0919)
LoadEastWestConnectionsTileMap:: ; 093d (0:093d)
push hl
push de
- ld c,$03
+ ld c,MAP_BORDER
.innerLoop
ld a,[hli]
ld [de],a
@@ -1030,14 +1023,14 @@ LoadEastWestConnectionsTileMap:: ; 093d (0:093d)
jr nz,.innerLoop
pop de
pop hl
- ld a,[$ff8b] ; width of connected map
+ ld a,[hEastWestConnectedMapWidth]
add l
ld l,a
jr nc,.noCarry1
inc h
.noCarry1
ld a,[W_CURMAPWIDTH]
- add a,$06
+ add a,MAP_BORDER * 2
add e
ld e,a
jr nc,.noCarry2
@@ -1052,7 +1045,7 @@ LoadEastWestConnectionsTileMap:: ; 093d (0:093d)
IsSpriteOrSignInFrontOfPlayer:: ; 095e (0:095e)
xor a
ld [hSpriteIndexOrTextID],a
- ld a,[wd4b0] ; number of signs in the map
+ ld a,[wNumSigns]
and a
jr z,.extendRangeOverCounter
; if there are signs
@@ -1063,7 +1056,7 @@ IsSpriteOrSignInFrontOfPlayer:: ; 095e (0:095e)
; check if the player is front of a counter in a pokemon center, pokemart, etc. and if so, extend the range at which he can talk to the NPC
predef GetTileAndCoordsInFrontOfPlayer ; get the tile in front of the player in c
ld hl,W_TILESETTALKINGOVERTILES ; list of tiles that extend talking range (counter tiles)
- ld b,$03
+ ld b,3
ld d,$20 ; talking range in pixels (long range)
.counterTilesLoop
ld a,[hli]
@@ -1076,43 +1069,43 @@ IsSpriteOrSignInFrontOfPlayer:: ; 095e (0:095e)
IsSpriteInFrontOfPlayer:: ; 0983 (0:0983)
ld d,$10 ; talking range in pixels (normal range)
IsSpriteInFrontOfPlayer2:: ; 0985 (0:0985)
- ld bc,$3c40 ; Y and X position of player sprite
+ lb bc,$3c, $40 ; Y and X position of player sprite
ld a,[wSpriteStateData1 + 9] ; direction the player is facing
.checkIfPlayerFacingUp
- cp a,$04
+ cp SPRITE_FACING_UP
jr nz,.checkIfPlayerFacingDown
; facing up
ld a,b
sub d
ld b,a
- ld a,$08
+ ld a,PLAYER_DIR_UP
jr .doneCheckingDirection
.checkIfPlayerFacingDown
- cp a,$00
+ cp SPRITE_FACING_DOWN
jr nz,.checkIfPlayerFacingRight
; facing down
ld a,b
add d
ld b,a
- ld a,$04
+ ld a,PLAYER_DIR_DOWN
jr .doneCheckingDirection
.checkIfPlayerFacingRight
- cp a,$0c
+ cp SPRITE_FACING_RIGHT
jr nz,.playerFacingLeft
; facing right
ld a,c
add d
ld c,a
- ld a,$01
+ ld a,PLAYER_DIR_RIGHT
jr .doneCheckingDirection
.playerFacingLeft
; facing left
ld a,c
sub d
ld c,a
- ld a,$02
+ ld a,PLAYER_DIR_LEFT
.doneCheckingDirection
- ld [wd52a],a
+ ld [wPlayerDirection],a
ld hl,wSpriteStateData1 + $10
; yellow does not have the "if sprites are existant" check
ld e,$01
@@ -1209,7 +1202,7 @@ CollisionCheckOnLand:: ; 0a1c (0:0a1c)
ld a,[wSimulatedJoypadStatesIndex]
and a
jr nz,.noCollision ; no collisions when the player's movements are being controlled by the game
- ld a,[wd52a] ; the direction that the player is trying to go in
+ ld a,[wPlayerDirection] ; the direction that the player is trying to go in
ld d,a
ld a,[wSpriteStateData1 + 12] ; the player sprite's collision data (bit field) (set in the sprite movement code)
and d ; check if a sprite is in the direction the player is trying to go
@@ -1244,10 +1237,10 @@ CollisionCheckOnLand:: ; 0a1c (0:0a1c)
call CheckTilePassable
jr nc,.noCollision
.collision
- ld a,[wc02a]
- cp $b4 ; (SFX_02_5b - SFX_Headers_02) / 3 ; check if collision sound is already playing
+ ld a,[wChannelSoundIDs + CH4]
+ cp $b4 ; SFX_COLLISION ; check if collision sound is already playing
jr z,.setCarry
- ld a, $b4 ; (SFX_02_5b - SFX_Headers_02) / 3
+ ld a, $b4 ; SFX_COLLISION
call PlaySound ; play collision sound (if it's not already playing)
.setCarry
scf
@@ -1287,7 +1280,7 @@ CheckForJumpingAndTilePairCollisions:: ; 0a86 (0:0a86)
CheckForTilePairCollisions2:: ; 0aa0 (0:0aa0)
aCoord 8, 9 ; tile the player is on
- ld [wcf0e],a
+ ld [wTilePlayerStandingOn],a
CheckForTilePairCollisions:: ; 0aa6 (0:0aa6)
ld a,[wTileInFrontOfPlayer]
@@ -1305,7 +1298,7 @@ CheckForTilePairCollisions:: ; 0aa6 (0:0aa6)
inc hl
jr .tilePairCollisionLoop
.tilesetMatches
- ld a,[wcf0e] ; tile the player is on
+ ld a,[wTilePlayerStandingOn] ; tile the player is on
ld b,a
ld a,[hl]
cp b
@@ -1395,7 +1388,7 @@ LoadCurrentMapView:: ; 0b06 (0:0b06)
; update tile block map pointer to next row's address
pop de
ld a,[W_CURMAPWIDTH]
- add a,$06
+ add a,MAP_BORDER * 2
add e
ld e,a
jr nc,.noCarry
@@ -1426,10 +1419,10 @@ LoadCurrentMapView:: ; 0b06 (0:0b06)
ld bc,$0002
add hl,bc
.copyToVisibleAreaBuffer
- ld de,wTileMap ; base address for the tiles that are directly transfered to VRAM during V-blank
- ld b,$12
+ coord de, 0, 0 ; base address for the tiles that are directly transferred to VRAM during V-blank
+ ld b, SCREEN_HEIGHT
.rowLoop2
- ld c,$14
+ ld c, SCREEN_WIDTH
.rowInnerLoop2
ld a,[hli]
ld [de],a
@@ -1465,18 +1458,18 @@ AdvancePlayerSprite:: ; 0b7f (0:0b7f)
ScheduleNorthRowRedraw:: ; 0b95 (0:0b95)
hlCoord 0, 0
- call CopyToScreenEdgeTiles
+ call CopyToRedrawRowOrColumnSrcTiles
ld a,[wMapViewVRAMPointer]
ld [H_SCREENEDGEREDRAWADDR],a
ld a,[wMapViewVRAMPointer + 1]
- ld [H_SCREENEDGEREDRAWADDR + 1],a
- ld a,REDRAWROW
- ld [H_SCREENEDGEREDRAW],a
+ ld [hRedrawRowOrColumnDest + 1],a
+ ld a,REDRAW_ROW
+ ld [hRedrawRowOrColumnMode],a
ret
-CopyToScreenEdgeTiles:: ; 0baa (0:0baa)
- ld de,wScreenEdgeTiles
- ld c,2 * 20
+CopyToRedrawRowOrColumnSrcTiles:: ; 0baa (0:0baa)
+ ld de,wRedrawRowOrColumnSrcTiles
+ ld c,2 * SCREEN_WIDTH
.loop
ld a,[hli]
ld [de],a
@@ -1486,8 +1479,8 @@ CopyToScreenEdgeTiles:: ; 0baa (0:0baa)
ret
ScheduleSouthRowRedraw:: ; 0bb6 (0:0bb6)
- hlCoord 0, 16
- call CopyToScreenEdgeTiles
+ coord hl, 0, 16
+ call CopyToRedrawRowOrColumnSrcTiles
ld a,[wMapViewVRAMPointer]
ld l,a
ld a,[wMapViewVRAMPointer + 1]
@@ -1497,15 +1490,15 @@ ScheduleSouthRowRedraw:: ; 0bb6 (0:0bb6)
ld a,h
and a,$03
or a,$98
- ld [H_SCREENEDGEREDRAWADDR + 1],a
+ ld [hRedrawRowOrColumnDest + 1],a
ld a,l
- ld [H_SCREENEDGEREDRAWADDR],a
- ld a,REDRAWROW
- ld [H_SCREENEDGEREDRAW],a
+ ld [hRedrawRowOrColumnDest],a
+ ld a,REDRAW_ROW
+ ld [hRedrawRowOrColumnMode],a
ret
ScheduleEastColumnRedraw:: ; 0bd6 (0:0bd7)
- hlCoord 18, 0
+ coord hl, 18, 0
call ScheduleColumnRedrawHelper
ld a,[wMapViewVRAMPointer]
ld c,a
@@ -1515,16 +1508,16 @@ ScheduleEastColumnRedraw:: ; 0bd6 (0:0bd7)
add a,18
and a,$1f
or b
- ld [H_SCREENEDGEREDRAWADDR],a
+ ld [hRedrawRowOrColumnDest],a
ld a,[wMapViewVRAMPointer + 1]
- ld [H_SCREENEDGEREDRAWADDR + 1],a
- ld a,REDRAWCOL
- ld [H_SCREENEDGEREDRAW],a
+ ld [hRedrawRowOrColumnDest + 1],a
+ ld a,REDRAW_COL
+ ld [hRedrawRowOrColumnMode],a
ret
ScheduleColumnRedrawHelper:: ; 0bf6 (0:0bf6)
- ld de,wScreenEdgeTiles
- ld c,$12
+ ld de,wRedrawRowOrColumnSrcTiles
+ ld c,SCREEN_HEIGHT
.loop
ld a,[hli]
ld [de],a
@@ -1543,14 +1536,14 @@ ScheduleColumnRedrawHelper:: ; 0bf6 (0:0bf6)
ret
ScheduleWestColumnRedraw:: ; 0c0c (0:0c0c)
- hlCoord 0, 0
+ coord hl, 0, 0
call ScheduleColumnRedrawHelper
ld a,[wMapViewVRAMPointer]
- ld [H_SCREENEDGEREDRAWADDR],a
+ ld [hRedrawRowOrColumnDest],a
ld a,[wMapViewVRAMPointer + 1]
- ld [H_SCREENEDGEREDRAWADDR + 1],a
- ld a,REDRAWCOL
- ld [H_SCREENEDGEREDRAW],a
+ ld [hRedrawRowOrColumnDest + 1],a
+ ld a,REDRAW_COL
+ ld [hRedrawRowOrColumnMode],a
ret
; function to write the tiles that make up a tile block to memory
@@ -1688,7 +1681,7 @@ CollisionCheckOnWater:: ; 0cca (0:0cca)
ld a,[wd730]
bit 7,a
jp nz,.noCollision ; return and clear carry if button presses are being simulated
- ld a,[wd52a] ; the direction that the player is trying to go in
+ ld a,[wPlayerDirection] ; the direction that the player is trying to go in
ld d,a
ld a,[wSpriteStateData1 + 12] ; the player sprite's collision data (bit field) (set in the sprite movement code)
and d ; check if a sprite is in the direction the player is trying to go
@@ -1704,10 +1697,10 @@ CollisionCheckOnWater:: ; 0cca (0:0cca)
call IsTilePassable
jr nc,.stopSurfing
.collision
- ld a,[wc02a]
- cp $b4 ; (SFX_02_5b - SFX_Headers_02) / 3 ; check if collision sound is already playing
+ ld a,[wChannelSoundIDs + CH4]
+ cp $b4 ; SFX_COLLISION
jr z,.setCarry
- ld a, $b4 ; (SFX_02_5b - SFX_Headers_02) / 3
+ ld a, $b4 ; SFX_COLLISION
call PlaySound ; play collision sound (if it's not already playing)
.setCarry
scf
@@ -1765,7 +1758,6 @@ LoadWalkingPlayerSpriteGraphics:: ; 0d5e (0:0d5e)
ld [wd473],a
ld b,BANK(RedSprite)
ld de,RedSprite ; $4180
- jr LoadPlayerSpriteGraphicsCommon
LoadSurfingPlayerSpriteGraphics2:: ; 0d69 (0:0d69)
ld a,[wd473]
@@ -1819,14 +1811,14 @@ LoadMapHeader:: ; 0dab (0:0dab)
callba Func_f0a55 ; 3c:4a55
.asm_0dbd
ld a,[W_CURMAPTILESET]
- ld [wd119],a
+ ld [wUnusedD119],a
ld a,[W_CURMAP]
call SwitchToMapRomBank
ld a,[W_CURMAPTILESET]
ld b,a
res 7,a
ld [W_CURMAPTILESET],a
- ld [$ff8b],a
+ ld [hPreviousTileset],a
bit 7,b
ret nz
call GetMapHeaderPointer
@@ -1870,17 +1862,17 @@ LoadMapHeader:: ; 0dab (0:0dab)
call CopyMapConnectionHeader
.getObjectDataPointer
ld a,[hli]
- ld [wd3a9],a
+ ld [wObjectDataPointerTemp],a
ld a,[hli]
- ld [wd3aa],a
+ ld [wObjectDataPointerTemp + 1],a
push hl
- ld a,[wd3a9]
+ ld a,[wObjectDataPointerTemp]
ld l,a
- ld a,[wd3aa]
+ ld a,[wObjectDataPointerTemp + 1]
ld h,a ; hl = base of object data
- ld de,wd3ad ; background tile ID
+ ld de,wMapBackgroundTile
ld a,[hli]
- ld [de],a ; save background tile ID
+ ld [de],a
.loadWarpData
ld a,[hli]
ld [wNumberOfWarps],a
@@ -1900,7 +1892,7 @@ LoadMapHeader:: ; 0dab (0:0dab)
jr nz,.warpLoop
.loadSignData
ld a,[hli] ; number of signs
- ld [wd4b0],a ; save the number of signs
+ ld [wNumSigns],a
and a ; are there any signs?
jr z,.loadSpriteData ; if not, skip this
call CopySignData ; 0eb3 (0:0eb3)
@@ -1920,10 +1912,10 @@ LoadMapHeader:: ; 0dab (0:0dab)
pop hl ; restore hl from before going to the warp/sign/sprite data (this value was saved for seemingly no purpose)
ld a,[W_CURMAPHEIGHT] ; map height in 4x4 tile blocks
add a ; double it
- ld [wd524],a ; store map height in 2x2 tile blocks
+ ld [wCurrentMapHeight2],a ; store map height in 2x2 tile blocks
ld a,[W_CURMAPWIDTH] ; map width in 4x4 tile blocks
add a ; double it
- ld [wd525],a ; map width in 2x2 tile blocks
+ ld [wCurrentMapWidth2],a ; map width in 2x2 tile blocks
ld a,[W_CURMAP]
ld c,a
ld b,$00
@@ -1934,9 +1926,9 @@ LoadMapHeader:: ; 0dab (0:0dab)
add hl,bc
add hl,bc
ld a,[hli]
- ld [wd35b],a ; music 1
+ ld [wMapMusicSoundID],a ; music 1
ld a,[hl]
- ld [wd35c],a ; music 2
+ ld [wMapMusicROMBank],a ; music 2
pop af
call BankswitchCommon
ret
@@ -2047,7 +2039,7 @@ ResetMapVariables:: ; 0f56 (0:0f56)
ld [hSCY],a
ld [hSCX],a
ld [wWalkCounter],a
- ld [wd119],a
+ ld [wUnusedD119],a
ld [W_SPRITESETID],a
ld [wWalkBikeSurfStateCopy],a
ret
diff --git a/home/pic.asm b/home/pic.asm
index 28f27b79..28ffcbc7 100644
--- a/home/pic.asm
+++ b/home/pic.asm
@@ -28,7 +28,7 @@ _UncompressSpriteData:: ; 2410 (0:2410)
xor a
ld [W_SPRITECURPOSX], a
ld [W_SPRITECURPOSY], a
- ld [W_SPRITELOADFLAGS], a ; wd0a8
+ ld [W_SPRITELOADFLAGS], a
call ReadNextInputByte ; first byte of input determines sprite width (high nybble) and height (low nybble) in tiles (8x8 pixels)
ld b, a
and $f
@@ -54,13 +54,13 @@ _UncompressSpriteData:: ; 2410 (0:2410)
; note that this is an endless loop which is terminated during a call to MoveToNextBufferPosition by manipulating the stack
UncompressSpriteDataLoop:: ; 244c (0:244c)
ld hl, S_SPRITEBUFFER1
- ld a, [W_SPRITELOADFLAGS] ; wd0a8
+ ld a, [W_SPRITELOADFLAGS]
bit 0, a
jr z, .useSpriteBuffer1 ; check which buffer to use
ld hl, S_SPRITEBUFFER2
.useSpriteBuffer1
call StoreSpriteOutputPointer
- ld a, [W_SPRITELOADFLAGS] ; wd0a8
+ ld a, [W_SPRITELOADFLAGS]
bit 1, a
jr z, .startDecompression ; check if last iteration
call ReadNextInputBit ; if last chunk, read 1-2 bit unpacking mode
@@ -192,12 +192,12 @@ MoveToNextBufferPosition:: ; 24ce (0:24ce)
pop hl
xor a
ld [W_SPRITECURPOSX], a
- ld a, [W_SPRITELOADFLAGS] ; wd0a8
+ ld a, [W_SPRITELOADFLAGS]
bit 1, a
jr nz, .done ; test if there is one more sprite to go
xor $1
set 1, a
- ld [W_SPRITELOADFLAGS], a ; wd0a8
+ ld [W_SPRITELOADFLAGS], a
jp UncompressSpriteDataLoop
.done
jp UnpackSprite
@@ -535,8 +535,13 @@ ReverseNybble:: ; 272d (0:272d)
ret
; resets sprite buffer pointers to buffer 1 and 2, depending on W_SPRITELOADFLAGS
+<<<<<<< HEAD
ResetSpriteBufferPointers:: ; 2737 (0:2737)
ld a, [W_SPRITELOADFLAGS] ; wd0a8
+=======
+ResetSpriteBufferPointers:: ; 2841 (0:2841)
+ ld a, [W_SPRITELOADFLAGS]
+>>>>>>> 1a987d1e1ab96ca9553d4253c72858057332a03a
bit 0, a
jr nz, .buffer2Selected
ld de, S_SPRITEBUFFER1
diff --git a/home/predef.asm b/home/predef.asm
index 07188019..5d879ddc 100644
--- a/home/predef.asm
+++ b/home/predef.asm
@@ -14,7 +14,7 @@ Predef:: ; 3eb4 (0:3eb4)
push af
ld a, BANK(GetPredefPointer)
ld [H_LOADEDROMBANK], a
- ld [$2000], a
+ ld [MBC1RomBank], a
call GetPredefPointer
diff --git a/home/text.asm b/home/text.asm
index c2c224e3..fcb1d439 100644
--- a/home/text.asm
+++ b/home/text.asm
@@ -65,20 +65,20 @@ Char4ETest:: ; 172d (0:172d)
ld a,[hFlags_0xFFFA]
bit 2,a
jr z,.next2
- ld bc,$14
+ ld bc,SCREEN_WIDTH
.next2
pop hl
add hl,bc
push hl
- jp Next17B6 ; 17b6
+ jp PlaceNextChar_inc ; 17b6
.next
cp $4F
jr nz,.next3
pop hl
- hlCoord 1, 16
+ coord hl, 1, 16
push hl
- jp Next17B6
+ jp PlaceNextChar_inc
.next3 ; Check against a dictionary
and a
@@ -123,7 +123,7 @@ Char4ETest:: ; 172d (0:172d)
jp z,Char5A
ld [hli],a
call PrintLetterDelay
-Next17B6:: ; 17b6 (0:17b6)
+PlaceNextChar_inc:: ; 17b6 (0:17b6)
inc de
jp PlaceNextChar
@@ -207,7 +207,7 @@ MonsterNameCharsCommon:: ; 1a37 (0:1a37)
ld de,wBattleMonNick ; player active monster name
jr FinishDTE
-.Enemy ; 1A40
+.Enemy
; print “Enemy ”
ld de,Char5AText
call PlaceString
@@ -272,7 +272,7 @@ Char58:: ; 1863 (0:1863)
Next1870:: ; 1870 (0:1870)
call ProtectedDelay3 ; 1913
call ManualTextScroll ; 388e
- ld a,$7F ; space
+ ld a, " " ; space
Coorda 18, 16
Char57:: ; 1aad (0:1aad)
pop hl
@@ -289,14 +289,14 @@ Char51:: ; 1882 (0:1882)
Coorda 18, 16
call ProtectedDelay3
call ManualTextScroll
- hlCoord 1, 13
- ld bc,$0412
+ coord hl, 1, 13
+ lb bc, 4, 18
call ClearScreenArea
- ld c,$14
+ ld c,20
call DelayFrames
pop de
- hlCoord 1, 14
- jp Next17B6
+ coord hl, 1, 14
+ jp PlaceNextChar_inc
Char49:: ; 18a3 (0:18a3)
ld a,[hFlags_0xFFFA]
@@ -311,16 +311,16 @@ Char49:: ; 18a3 (0:18a3)
Coorda 18, 16
call ProtectedDelay3
call ManualTextScroll
- hlCoord 1, 10
- ld bc,$0712
+ coord hl, 1, 10
+ lb bc, 7, 18
call ClearScreenArea
- ld c,$14
+ ld c,20
call DelayFrames
pop de
pop hl
- hlCoord 1, 11
+ coord hl, 1, 11
push hl
- jp Next17B6
+ jp PlaceNextChar_inc
Char4B:: ; 18d1 (0:18d1)
ld a,$EE
@@ -329,30 +329,30 @@ Char4B:: ; 18d1 (0:18d1)
push de
call ManualTextScroll
pop de
- ld a,$7F
+ ld a, " "
Coorda 18, 16
;fall through
Char4C:: ; 18e3 (0:18e3)
push de
call Next18F1 ; 18f1
call Next18F1
- hlCoord 1, 16
+ coord hl, 1, 16
pop de
- jp Next17B6
+ jp PlaceNextChar_inc
Next18F1:: ; 18f1 (0:18f1)
- hlCoord 0, 14
- deCoord 0, 13
- ld b,$3C
+ coord hl, 0, 14
+ coord de, 0, 13
+ ld b, 60
.next
ld a,[hli]
ld [de],a
inc de
dec b
jr nz,.next
- hlCoord 1, 16
- ld a,$7F
- ld b,$12
+ coord hl, 1, 16
+ ld a, " "
+ ld b,SCREEN_WIDTH - 2
.next2
ld [hli],a
dec b
@@ -374,24 +374,24 @@ ProtectedDelay3:: ; 1913 (0:1913)
ret
TextCommandProcessor:: ; 1919 (0:1919)
- ld a,[wd358]
+ ld a,[wLetterPrintingDelayFlags]
push af
set 1,a
ld e,a
ld a,[$fff9]
xor e
- ld [wd358],a
+ ld [wLetterPrintingDelayFlags],a
ld a,c
- ld [wcc3a],a
+ ld [wUnusedCC3A],a
ld a,b
- ld [wcc3b],a
+ ld [wUnusedCC3B],a
NextTextCommand:: ; 192e (0:192e)
ld a,[hli]
cp a, "@" ; terminator
jr nz,.doTextCommand
pop af
- ld [wd358],a
+ ld [wLetterPrintingDelayFlags],a
ret
.doTextCommand
push hl
@@ -493,10 +493,10 @@ TextCommand02:: ; 197e (0:197e)
TextCommand03:: ; 1990 (0:1990)
pop hl
ld a,[hli]
- ld [wcc3a],a
+ ld [wUnusedCC3A],a
ld c,a
ld a,[hli]
- ld [wcc3b],a
+ ld [wUnusedCC3B],a
ld b,a
jp NextTextCommand
@@ -505,7 +505,7 @@ TextCommand03:: ; 1990 (0:1990)
; (no arguments)
TextCommand05:: ; 199e (0:199e)
pop hl
- bcCoord 1, 16 ; address of second line of dialogue text box
+ coord bc, 1, 16 ; address of second line of dialogue text box
jp NextTextCommand
; blink arrow and wait for A or B to be pressed
@@ -534,7 +534,7 @@ TextCommand07:: ; 19c0 (0:19c0)
call Next18F1 ; scroll up text
call Next18F1
pop hl
- bcCoord 1, 16 ; address of second line of dialogue text box
+ coord bc, 1, 16 ; address of second line of dialogue text box
jp NextTextCommand
; execute asm inline
@@ -567,7 +567,7 @@ TextCommand09:: ; 19d8 (0:19d8)
ld a,b
and a,$f0
swap a
- set 6,a
+ set BIT_LEFT_ALIGN,a
ld b,a
call PrintNumber
ld b,h
@@ -582,7 +582,7 @@ TextCommand0A:: ; 19f6 (0:19f6)
push bc
call Joypad
ld a,[hJoyHeld]
- and a,%00000011 ; A and B buttons
+ and a,A_BUTTON | B_BUTTON
jr nz,.skipDelay
ld c,30
call DelayFrames
@@ -660,7 +660,7 @@ TextCommand0C:: ; 1a51 (0:1a51)
call Joypad
pop de
ld a,[hJoyHeld] ; joypad state
- and a,%00000011 ; is A or B button pressed?
+ and a,A_BUTTON | B_BUTTON
jr nz,.skipDelay ; if so, skip the delay
ld c,10
call DelayFrames
@@ -696,7 +696,7 @@ TextCommand17:: ; 1a7c (0:1a7c)
ld d,a
ld a,[hli]
ld [H_LOADEDROMBANK],a
- ld [$2000],a
+ ld [MBC1RomBank],a
push hl
ld l,e
ld h,d
@@ -704,7 +704,7 @@ TextCommand17:: ; 1a7c (0:1a7c)
pop hl
pop af
ld [H_LOADEDROMBANK],a
- ld [$2000],a
+ ld [MBC1RomBank],a
jp NextTextCommand
TextCommandJumpTable:: ; 1a9a (0:1a9a)
diff --git a/home/vblank.asm b/home/vblank.asm
index 66158e50..8eff5bab 100644
--- a/home/vblank.asm
+++ b/home/vblank.asm
@@ -11,14 +11,14 @@ VBlank:: ; 1de5 (0:1de5)
ld [rVBK], a ; reset vram bank to 0
ld a, [H_LOADEDROMBANK]
- ld [wd122], a
+ ld [wVBlankSavedROMBank], a
ld a, [hSCX]
ld [rSCX], a
ld a, [hSCY]
ld [rSCY], a
- ld a, [wd0a0]
+ ld a, [wDisableVBlankWYUpdate]
and a
jr nz, .ok
ld a, [hWY]
@@ -27,7 +27,7 @@ VBlank:: ; 1de5 (0:1de5)
call AutoBgMapTransfer
call VBlankCopyBgMap
- call RedrawExposedScreenEdge
+ call RedrawRowOrColumn
call VBlankCopy
call VBlankCopyDouble
call UpdateMovingBgTiles
@@ -45,19 +45,18 @@ VBlank:: ; 1de5 (0:1de5)
ld a, [H_VBLANKOCCURRED]
and a
- jr z, .vblanked
+ jr z, .skipZeroing
xor a
ld [H_VBLANKOCCURRED], a
-.vblanked
+.skipZeroing
ld a, [H_FRAMECOUNTER]
and a
- jr z, .decced
+ jr z, .skipDec
dec a
ld [H_FRAMECOUNTER], a
-.decced
- call Func_27c2
+ call FadeOutAudio
ld a, $8
call BankswitchCommon
@@ -69,7 +68,7 @@ VBlank:: ; 1de5 (0:1de5)
call SerialFunction ; add this
- ld a, [wd122]
+ ld a, [wVBlankSavedROMBank]
ld [H_LOADEDROMBANK], a
ld [MBC1RomBank], a
diff --git a/home/vcopy.asm b/home/vcopy.asm
index 4ce297d2..da85e3e7 100644
--- a/home/vcopy.asm
+++ b/home/vcopy.asm
@@ -33,32 +33,35 @@ ClearBgMap:: ; 1cf0 (0:1cf0)
jr nz,.loop
ret
-; When the player takes a step, a row or column of 2x2 tile blocks at the edge
-; of the screen toward which they moved is exposed and has to be redrawn.
-; This function does the redrawing.
-RedrawExposedScreenEdge:: ; 1ada (0:1ada)
- ld a,[H_SCREENEDGEREDRAW]
+; This function redraws a BG row of height 2 or a BG column of width 2.
+; One of its main uses is redrawing the row or column that will be exposed upon
+; scrolling the BG when the player takes a step. Redrawing only the exposed
+; row or column is more efficient than redrawing the entire screen.
+; However, this function is also called repeatedly to redraw the whole screen
+; when necessary. It is also used in trade animation and elevator code.
+RedrawRowOrColumn:: ; 1ada (0:1ada)
+ ld a,[hRedrawRowOrColumnMode]
and a
ret z
ld b,a
xor a
- ld [H_SCREENEDGEREDRAW],a
+ ld [hRedrawRowOrColumnMode],a
dec b
jr nz,.redrawRow
.redrawColumn
- ld hl,wScreenEdgeTiles
- ld a,[H_SCREENEDGEREDRAWADDR]
+ ld hl,wRedrawRowOrColumnSrcTiles
+ ld a,[hRedrawRowOrColumnDest]
ld e,a
- ld a,[H_SCREENEDGEREDRAWADDR + 1]
+ ld a,[hRedrawRowOrColumnDest + 1]
ld d,a
- ld c,18 ; screen height
+ ld c,SCREEN_HEIGHT
.loop1
ld a,[hli]
ld [de],a
inc de
ld a,[hli]
ld [de],a
- ld a,31
+ ld a,BG_MAP_WIDTH - 1
add e
ld e,a
jr nc,.noCarry
@@ -72,23 +75,24 @@ RedrawExposedScreenEdge:: ; 1ada (0:1ada)
dec c
jr nz,.loop1
xor a
- ld [H_SCREENEDGEREDRAW],a
+ ld [hRedrawRowOrColumnMode],a
ret
.redrawRow
- ld hl,wScreenEdgeTiles
- ld a,[H_SCREENEDGEREDRAWADDR]
+ ld hl,wRedrawRowOrColumnSrcTiles
+ ld a,[hRedrawRowOrColumnDest]
ld e,a
- ld a,[H_SCREENEDGEREDRAWADDR + 1]
+ ld a,[hRedrawRowOrColumnDest + 1]
ld d,a
push de
- call .drawHalf ; draw upper half
+ call .DrawHalf ; draw upper half
pop de
- ld a,32 ; width of VRAM background map
+ ld a,BG_MAP_WIDTH ; width of VRAM background map
add e
ld e,a
- ; draw lower half
-.drawHalf
- ld c,10
+ ; fall through and draw lower half
+
+.DrawHalf
+ ld c,SCREEN_WIDTH / 2
.loop2
ld a,[hli]
ld [de],a
@@ -113,7 +117,7 @@ RedrawExposedScreenEdge:: ; 1ada (0:1ada)
; background per V-blank. It cycles through which third it draws.
; This transfer is turned off when walking around the map, but is turned
; on when talking to sprites, battling, using menus, etc. This is because
-; the above function, RedrawExposedScreenEdge, is used when walking to
+; the above function, RedrawRowOrColumn, is used when walking to
; improve efficiency.
AutoBgMapTransfer:: ; 1b30 (0:1b30)
ld a,[H_AUTOBGTRANSFERENABLED]
@@ -126,7 +130,7 @@ AutoBgMapTransfer:: ; 1b30 (0:1b30)
dec a
jr z,.transferMiddleThird
.transferBottomThird
- hlCoord 0, 12
+ coord hl, 0, 12
ld sp,hl
ld a,[H_AUTOBGTRANSFERDEST + 1]
ld h,a
@@ -137,7 +141,7 @@ AutoBgMapTransfer:: ; 1b30 (0:1b30)
xor a ; TRANSFERTOP
jr .doTransfer
.transferTopThird
- hlCoord 0, 0
+ coord hl, 0, 0
ld sp,hl
ld a,[H_AUTOBGTRANSFERDEST + 1]
ld h,a
@@ -146,7 +150,7 @@ AutoBgMapTransfer:: ; 1b30 (0:1b30)
ld a,TRANSFERMIDDLE
jr .doTransfer
.transferMiddleThird
- hlCoord 0, 6
+ coord hl, 0, 6
ld sp,hl
ld a,[H_AUTOBGTRANSFERDEST + 1]
ld h,a
@@ -283,12 +287,11 @@ VBlankCopyDouble:: ; 1bd1 (0:1bd1)
VBlankCopy:: ; 1c21 (0:1c21)
-; Copy [H_VBCOPYSIZE] 2bpp tiles
+; Copy [H_VBCOPYSIZE] 2bpp tiles (or 16 * [H_VBCOPYSIZE] tile map entries)
; from H_VBCOPYSRC to H_VBCOPYDEST.
-; Source and destination addresses
-; are updated, so transfer can
-; continue in subsequent calls.
+; Source and destination addresses are updated,
+; so transfer can continue in subsequent calls.
ld a, [H_VBCOPYSIZE]
and a
@@ -354,21 +357,23 @@ UpdateMovingBgTiles:: ; 1c75 (0:1c75)
cp $90 ; check if not in vblank period??? (maybe if vblank is too long)
ret c
- ld a, [$ffd8]
+ ld a, [hMovingBGTilesCounter1]
inc a
- ld [$ffd8], a
- cp $14
+ ld [hMovingBGTilesCounter1], a
+ cp 20
ret c
- cp $15
+ cp 21
jr z, .flower
+; water
+
ld hl, vTileset + $14 * $10
ld c, $10
- ld a, [wd085]
+ ld a, [wMovingBGTilesCounter2]
inc a
and 7
- ld [wd085], a
+ ld [wMovingBGTilesCounter2], a
and 4
jr nz, .left
@@ -391,14 +396,14 @@ UpdateMovingBgTiles:: ; 1c75 (0:1c75)
ret nc
; if in a cave, no flower animations
xor a
- ld [$ffd8], a
+ ld [hMovingBGTilesCounter1], a
ret
.flower
xor a
- ld [$ffd8], a
+ ld [hMovingBGTilesCounter1], a
- ld a, [wd085]
+ ld a, [wMovingBGTilesCounter2]
and 3
cp 2
ld hl, FlowerTile1