summaryrefslogtreecommitdiff
path: root/home
diff options
context:
space:
mode:
authordannye <corrnondacqb@yahoo.com>2016-01-12 18:45:02 -0600
committerdannye <corrnondacqb@yahoo.com>2016-01-12 18:45:02 -0600
commit5914540ba780d7936fd6624d6fde2d67a9f7a773 (patch)
treea1ce27018f39d98f49d89468df426d0291e18560 /home
parentccf4fe54a8e444aaf966fac7b38bc9452c494222 (diff)
parent8a5a7d8e68538b727e0c166488265f395603366e (diff)
Merge branch 'master' of https://github.com/pret/pokered into rgbgfxrgbgfx
Diffstat (limited to 'home')
-rw-r--r--home/audio.asm233
-rw-r--r--home/init.asm14
-rw-r--r--home/overworld.asm342
-rw-r--r--home/pic.asm240
-rw-r--r--home/text.asm2
-rw-r--r--home/vblank.asm16
-rw-r--r--home/vcopy.asm51
7 files changed, 468 insertions, 430 deletions
diff --git a/home/audio.asm b/home/audio.asm
index 033f4067..2c46ec7a 100644
--- a/home/audio.asm
+++ b/home/audio.asm
@@ -3,112 +3,139 @@ PlayDefaultMusic:: ; 2307 (0:2307)
xor a
ld c, a
ld d, a
- ld [wcfca], a
- jr Func_2324
+ ld [wLastMusicSoundID], a
+ jr PlayDefaultMusicCommon
-Func_2312:: ; 2312 (0:2312)
- ld c, $a
- ld d, $0
+PlayDefaultMusicFadeOutCurrent:: ; 2312 (0:2312)
+; 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, Func_2324
+ 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
-Func_2324:: ; 2324 (0:2324)
+
+PlayDefaultMusicCommon:: ; 2324 (0:2324)
ld a, [wWalkBikeSurfState]
and a
- jr z, .asm_2343
+ jr z, .walking
cp $2
- jr z, .asm_2332
+ jr z, .surfing
ld a, MUSIC_BIKE_RIDING
- jr .asm_2334
-.asm_2332
+ jr .next
+
+.surfing
ld a, MUSIC_SURFING
-.asm_2334
+
+.next
ld b, a
ld a, d
- and a
+ and a ; should current music be faded out first?
ld a, BANK(Music_BikeRiding)
- jr nz, .asm_233e
- ld [wc0ef], a
-.asm_233e
- ld [wc0f0], a
- jr .asm_234c
-.asm_2343
- 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_2385
- jr c, .asm_2351
-.asm_234c
- ld a, [wcfca]
- cp b
- ret z
-.asm_2351
+ 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_235f:: ; 235f (0:235f)
- ld a, [wc0ef]
+UpdateMusic6Times:: ; 235f (0:235f)
+; This is called when entering a map, before fading out the current music and
+; playing the default music (i.e. the map's music or biking/surfing music).
+ ld a, [wAudioROMBank]
ld b, a
cp BANK(Audio1_UpdateMusic)
jr nz, .checkForAudio2
-.audio1
+
+; audio 1
ld hl, Audio1_UpdateMusic
- jr .asm_2378
+ jr .next
+
.checkForAudio2
cp BANK(Audio2_UpdateMusic)
jr nz, .audio3
-.audio2
+
+; audio 2
ld hl, Audio2_UpdateMusic
- jr .asm_2378
+ jr .next
+
.audio3
ld hl, Audio3_UpdateMusic
-.asm_2378
- ld c, $6
-.asm_237a
+
+.next
+ ld c, 6
+.loop
push bc
push hl
call Bankswitch
pop hl
pop bc
dec c
- jr nz, .asm_237a
+ jr nz, .loop
ret
-Func_2385:: ; 2385 (0:2385)
- ld a, [wd35c]
+CompareMapMusicBankWithCurrentBank:: ; 2385 (0:2385)
+; 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_2394
- ld [wc0f0], a
+ jr nz, .differentBanks
+ ld [wAudioSavedROMBank], a
and a
ret
-.asm_2394
- 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_239c
- ld [wc0ef], a
-.asm_239c
- 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:: ; 23a1 (0:23a1)
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
; plays music specified by a. If value is $ff, music is stopped
@@ -117,66 +144,74 @@ PlaySound:: ; 23b1 (0:23b1)
push de
push bc
ld b, a
- ld a, [wc0ee]
+ ld a, [wNewSoundID]
and a
- jr z, .asm_23c8
+ jr z, .next
xor a
- ld [wc02a], a
- ld [wc02b], a
- ld [wc02c], a
- ld [wc02d], a
-.asm_23c8
- ld a, [wMusicHeaderPointer]
- and a
- jr z, .asm_23e3
- ld a, [wc0ee]
- and a
- jr z, .asm_2425
+ ld [wChannelSoundIDs + CH4], a
+ ld [wChannelSoundIDs + CH5], a
+ ld [wChannelSoundIDs + CH6], a
+ ld [wChannelSoundIDs + CH7], a
+.next
+ ld a, [wAudioFadeOutControl]
+ and a ; has a fade-out length been specified?
+ jr z, .noFadeOut
+ ld a, [wNewSoundID]
+ and a ; is the new sound ID 0?
+ jr z, .done ; if so, do nothing
xor a
- ld [wc0ee], a
- ld a, [wcfca]
- cp $ff
- jr nz, .asm_2414
+ ld [wNewSoundID], a
+ ld a, [wLastMusicSoundID]
+ cp $ff ; has the music been stopped?
+ jr nz, .fadeOut ; if not, fade out the current music
+; If it has been stopped, start playing the new music immediately.
xor a
- ld [wMusicHeaderPointer], a
-.asm_23e3
+ ld [wAudioFadeOutControl], a
+.noFadeOut
xor a
- ld [wc0ee], a
+ ld [wNewSoundID], a
ld a, [H_LOADEDROMBANK]
- ld [$ffb9], a
- ld a, [wc0ef]
+ ld [hSavedROMBank], a
+ ld a, [wAudioROMBank]
ld [H_LOADEDROMBANK], a
ld [MBC1RomBank], a
- cp BANK(Audio1_9876)
+ cp BANK(Audio1_PlaySound)
jr nz, .checkForAudio2
-.audio1
+
+; audio 1
ld a, b
- call Audio1_9876
- jr .asm_240b
+ call Audio1_PlaySound
+ jr .next2
+
.checkForAudio2
- cp BANK(Audio2_22035)
+ cp BANK(Audio2_PlaySound)
jr nz, .audio3
-.audio2
+
+; audio 2
ld a, b
- call Audio2_22035
- jr .asm_240b
+ call Audio2_PlaySound
+ jr .next2
+
.audio3
ld a, b
- call Audio3_7d8ea
-.asm_240b
- ld a, [$ffb9]
+ call Audio3_PlaySound
+
+.next2
+ ld a, [hSavedROMBank]
ld [H_LOADEDROMBANK], a
ld [MBC1RomBank], a
- jr .asm_2425
-.asm_2414
+ 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_2425
+ ld [wAudioFadeOutControl], a
+
+.done
pop bc
pop de
pop hl
diff --git a/home/init.asm b/home/init.asm
index 624a4d6a..cb5c6583 100644
--- a/home/init.asm
+++ b/home/init.asm
@@ -98,8 +98,8 @@ rLCDC_DEFAULT EQU %11100011
predef LoadSGB
ld a, BANK(SFX_Shooting_Star)
- ld [wc0ef], a
- ld [wc0f0], a
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
ld a, $9c
ld [H_AUTOBGTRANSFERDEST + 1], a
xor a
@@ -127,11 +127,11 @@ ClearVram:
StopAllSounds::
ld a, BANK(Audio1_UpdateMusic)
- ld [wc0ef], a
- ld [wc0f0], a
+ 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
dec a
jp PlaySound
diff --git a/home/overworld.asm b/home/overworld.asm
index f8d6e7e1..e4f58d4a 100644
--- a/home/overworld.asm
+++ b/home/overworld.asm
@@ -32,7 +32,7 @@ EnterMap::
ld hl, wd72d
res 5, [hl]
call UpdateSprites
- ld hl, wd126
+ ld hl, wCurrentMapScriptFlags
set 5, [hl]
set 6, [hl]
xor a
@@ -61,7 +61,7 @@ OverworldLoopLessDelay::
ld a,[wd732]
and a,1 << 4 | 1 << 3 ; fly warp or dungeon warp
jp nz,HandleFlyWarpOrDungeonWarp
- ld a,[W_CUROPPONENT]
+ ld a,[wCurOpponent]
and a
jp nz,.newBattle
ld a,[wd730]
@@ -115,17 +115,17 @@ OverworldLoopLessDelay::
jr z,.changeMap
; XXX can this code be reached?
predef LoadSAV
- ld a,[W_CURMAP]
+ ld a,[wCurMap]
ld [wDestinationMap],a
call SpecialWarpIn
- ld a,[W_CURMAP]
+ ld a,[wCurMap]
call SwitchToMapRomBank ; switch to the ROM bank of the current map
- ld hl,W_CURMAPTILESET
+ ld hl,wCurMapTileset
set 7,[hl]
.changeMap
jp EnterMap
.checkForOpponent
- ld a,[W_CUROPPONENT]
+ ld a,[wCurOpponent]
and a
jp nz,.newBattle
jp OverworldLoop
@@ -300,7 +300,7 @@ OverworldLoopLessDelay::
and a
jp nz,WarpFound2
.notSafariZone
- ld a,[W_ISINBATTLE]
+ ld a,[wIsInBattle]
and a
jp nz,CheckWarpsNoCollision
predef ApplyOutOfBattlePoisonDamage ; also increment daycare mon exp
@@ -315,21 +315,21 @@ OverworldLoopLessDelay::
.battleOccurred
ld hl,wd72d
res 6,[hl]
- ld hl,W_FLAGS_D733
+ ld hl,wFlags_D733
res 3,[hl]
- ld hl,wd126
+ ld hl,wCurrentMapScriptFlags
set 5,[hl]
set 6,[hl]
xor a
ld [hJoyHeld],a
- ld a,[W_CURMAP]
+ ld a,[wCurMap]
cp a,CINNABAR_GYM
jr nz,.notCinnabarGym
SetEvent EVENT_2A7
.notCinnabarGym
ld hl,wd72e
set 5,[hl]
- ld a,[W_CURMAP]
+ ld a,[wCurMap]
cp a,OAKS_LAB
jp z,.noFaintCheck ; no blacking out if the player lost to the rival in Oak's lab
callab AnyPartyAlive
@@ -342,7 +342,7 @@ OverworldLoopLessDelay::
jp EnterMap
.allPokemonFainted
ld a,$ff
- ld [W_ISINBATTLE],a
+ ld [wIsInBattle],a
call RunMapScript
jp HandleBlackOut
@@ -367,7 +367,7 @@ BikeSpeedup:: ; 06a0 (0:06a0)
ld a,[wNPCMovementScriptPointerTableNum]
and a
ret nz
- ld a,[W_CURMAP]
+ ld a,[wCurMap]
cp a,ROUTE_17 ; Cycling Road
jr nz,.goFaster
ld a,[hJoyHeld]
@@ -384,9 +384,9 @@ CheckWarpsNoCollision:: ; 06b4 (0:06b4)
ld a,[wNumberOfWarps]
ld b,0
ld c,a
- ld a,[W_YCOORD]
+ ld a,[wYCoord]
ld d,a
- ld a,[W_XCOORD]
+ ld a,[wXCoord]
ld e,a
ld hl,wWarpEntries
CheckWarpsNoCollisionLoop:: ; 06cc (0:06cc)
@@ -412,7 +412,7 @@ CheckWarpsNoCollisionLoop:: ; 06cc (0:06cc)
pop hl
jr nc,CheckWarpsNoCollisionRetry2
; if the extra check passed
- ld a,[W_FLAGS_D733]
+ ld a,[wFlags_D733]
bit 2,a
jr nz,WarpFound1
push de
@@ -433,12 +433,12 @@ CheckWarpsCollision:: ; 0706 (0:0706)
.loop
ld a,[hli] ; Y coordinate of warp
ld b,a
- ld a,[W_YCOORD]
+ ld a,[wYCoord]
cp b
jr nz,.retry1
ld a,[hli] ; X coordinate of warp
ld b,a
- ld a,[W_XCOORD]
+ ld a,[wXCoord]
cp b
jr nz,.retry2
ld a,[hli]
@@ -472,17 +472,17 @@ WarpFound2:: ; 073c (0:073c)
ld a,[wNumberOfWarps]
sub c
ld [wWarpedFromWhichWarp],a ; save ID of used warp
- ld a,[W_CURMAP]
+ ld a,[wCurMap]
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 a,[wCurMap]
ld [wLastMap],a
- ld a,[W_CURMAPWIDTH]
+ ld a,[wCurMapWidth]
ld [wUnusedD366],a ; not read
ld a,[hWarpDestinationMap]
- ld [W_CURMAP],a
+ ld [wCurMap],a
cp a,ROCK_TUNNEL_1
jr nz,.notRockTunnel
ld a,$06
@@ -497,7 +497,7 @@ WarpFound2:: ; 073c (0:073c)
cp a,$ff
jr z,.goBackOutside
; if not going back to the previous map
- ld [W_CURMAP],a
+ ld [wCurMap],a
callba IsPlayerStandingOnWarpPadOrHole
ld a,[wStandingOnWarpPadOrHole]
dec a ; is the player on a warp pad?
@@ -516,7 +516,7 @@ WarpFound2:: ; 073c (0:073c)
jr .done
.goBackOutside
ld a,[wLastMap]
- ld [W_CURMAP],a
+ ld [wCurMap],a
call PlayMapChangeSound
xor a
ld [wMapPalOffset],a
@@ -534,19 +534,19 @@ ContinueCheckWarpsNoCollisionLoop:: ; 07b5 (0:07b5)
; if no matching warp was found
CheckMapConnections:: ; 07ba (0:07ba)
.checkWestMap
- ld a,[W_XCOORD]
+ ld a,[wXCoord]
cp a,$ff
jr nz,.checkEastMap
- ld a,[W_MAPCONN3PTR]
- ld [W_CURMAP],a
+ ld a,[wMapConn3Ptr]
+ ld [wCurMap],a
ld a,[wWestConnectedMapXAlignment] ; new X coordinate upon entering west map
- ld [W_XCOORD],a
- ld a,[W_YCOORD]
+ ld [wXCoord],a
+ ld a,[wYCoord]
ld c,a
ld a,[wWestConnectedMapYAlignment] ; Y adjustment upon entering west map
add c
ld c,a
- ld [W_YCOORD],a
+ ld [wYCoord],a
ld a,[wWestConnectedMapViewPointer] ; pointer to upper left corner of map without adjustment for Y position
ld l,a
ld a,[wWestConnectedMapViewPointer + 1]
@@ -555,10 +555,10 @@ CheckMapConnections:: ; 07ba (0:07ba)
jr z,.savePointer1
.pointerAdjustmentLoop1
ld a,[wWestConnectedMapWidth] ; width of connected map
- add a,$06
+ 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
@@ -573,16 +573,16 @@ CheckMapConnections:: ; 07ba (0:07ba)
ld a,[wCurrentMapWidth2] ; map width
cp b
jr nz,.checkNorthMap
- ld a,[W_MAPCONN4PTR]
- ld [W_CURMAP],a
+ ld a,[wMapConn4Ptr]
+ ld [wCurMap],a
ld a,[wEastConnectedMapXAlignment] ; new X coordinate upon entering east map
- ld [W_XCOORD],a
- ld a,[W_YCOORD]
+ ld [wXCoord],a
+ ld a,[wYCoord]
ld c,a
ld a,[wEastConnectedMapYAlignment] ; Y adjustment upon entering east map
add c
ld c,a
- ld [W_YCOORD],a
+ ld [wYCoord],a
ld a,[wEastConnectedMapViewPointer] ; pointer to upper left corner of map without adjustment for Y position
ld l,a
ld a,[wEastConnectedMapViewPointer + 1]
@@ -591,10 +591,10 @@ CheckMapConnections:: ; 07ba (0:07ba)
jr z,.savePointer2
.pointerAdjustmentLoop2
ld a,[wEastConnectedMapWidth]
- add a,$06
+ 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
@@ -605,19 +605,19 @@ CheckMapConnections:: ; 07ba (0:07ba)
ld [wCurrentTileBlockMapViewPointer + 1],a
jp .loadNewMap
.checkNorthMap
- ld a,[W_YCOORD]
+ ld a,[wYCoord]
cp a,$ff
jr nz,.checkSouthMap
- ld a,[W_MAPCONN1PTR]
- ld [W_CURMAP],a
+ ld a,[wMapConn1Ptr]
+ ld [wCurMap],a
ld a,[wNorthConnectedMapYAlignment] ; new Y coordinate upon entering north map
- ld [W_YCOORD],a
- ld a,[W_XCOORD]
+ ld [wYCoord],a
+ ld a,[wXCoord]
ld c,a
ld a,[wNorthConnectedMapXAlignment] ; X adjustment upon entering north map
add c
ld c,a
- ld [W_XCOORD],a
+ ld [wXCoord],a
ld a,[wNorthConnectedMapViewPointer] ; pointer to upper left corner of map without adjustment for X position
ld l,a
ld a,[wNorthConnectedMapViewPointer + 1]
@@ -635,16 +635,16 @@ CheckMapConnections:: ; 07ba (0:07ba)
ld a,[wCurrentMapHeight2]
cp b
jr nz,.didNotEnterConnectedMap
- ld a,[W_MAPCONN2PTR]
- ld [W_CURMAP],a
+ ld a,[wMapConn2Ptr]
+ ld [wCurMap],a
ld a,[wSouthConnectedMapYAlignment] ; new Y coordinate upon entering south map
- ld [W_YCOORD],a
- ld a,[W_XCOORD]
+ ld [wYCoord],a
+ ld a,[wXCoord]
ld c,a
ld a,[wSouthConnectedMapXAlignment] ; X adjustment upon entering south map
add c
ld c,a
- ld [W_XCOORD],a
+ ld [wXCoord],a
ld a,[wSouthConnectedMapViewPointer] ; pointer to upper left corner of map without adjustment for X position
ld l,a
ld a,[wSouthConnectedMapViewPointer + 1]
@@ -658,9 +658,9 @@ CheckMapConnections:: ; 07ba (0:07ba)
ld [wCurrentTileBlockMapViewPointer + 1],a
.loadNewMap ; load the connected map that was entered
call LoadMapHeader
- call Func_2312 ; music
- ld b,$09
- call GoPAL_SET
+ call PlayDefaultMusicFadeOutCurrent
+ 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.
callba InitMapSprites
@@ -687,7 +687,7 @@ PlayMapChangeSound:: ; 08c9 (0:08c9)
CheckIfInOutsideMap:: ; 08e1 (0:08e1)
; If the player is in an outside map (a town or route), set the z flag
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
and a ; most towns/routes have tileset 0 (OVERWORLD)
ret z
cp PLATEAU ; Route 23 / Indigo Plateau
@@ -700,7 +700,7 @@ CheckIfInOutsideMap:: ; 08e1 (0:08e1)
; "function 2" passes when the the tile in front of the player is among a certain set
; sets carry if the check passes, otherwise clears carry
ExtraWarpCheck:: ; 08e9 (0:08e9)
- ld a, [W_CURMAP]
+ ld a, [wCurMap]
cp SS_ANNE_3
jr z, .useFunction1
cp ROCKET_HIDEOUT_1
@@ -711,7 +711,7 @@ ExtraWarpCheck:: ; 08e9 (0:08e9)
jr z, .useFunction2
cp ROCK_TUNNEL_1
jr z, .useFunction2
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
and a ; outside tileset (OVERWORLD)
jr z, .useFunction2
cp SHIP ; S.S. Anne tileset
@@ -750,16 +750,16 @@ HandleBlackOut::
ld [MBC1RomBank], a
call ResetStatusAndHalveMoneyOnBlackout
call SpecialWarpIn
- call Func_2312
+ call PlayDefaultMusicFadeOutCurrent
jp SpecialEnterMap
StopMusic::
- ld [wMusicHeaderPointer], a
+ ld [wAudioFadeOutControl], a
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
.wait
- ld a, [wMusicHeaderPointer]
+ ld a, [wAudioFadeOutControl]
and a
jr nz, .wait
jp StopAllSounds
@@ -770,7 +770,7 @@ HandleFlyWarpOrDungeonWarp::
xor a
ld [wBattleResult], a
ld [wWalkBikeSurfState], a
- ld [W_ISINBATTLE], a
+ ld [wIsInBattle], a
ld [wMapPalOffset], a
ld hl, wd732
set 2, [hl] ; fly warp or dungeon warp
@@ -828,13 +828,13 @@ IsBikeRidingAllowed::
; or maps with tilesets in BikeRidingTilesets.
; Return carry if biking is allowed.
- ld a, [W_CURMAP]
+ ld a, [wCurMap]
cp ROUTE_23
jr z, .allowed
cp INDIGO_PLATEAU
jr z, .allowed
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
ld b, a
ld hl, BikeRidingTilesets
.loop
@@ -854,13 +854,13 @@ INCLUDE "data/bike_riding_tilesets.asm"
; load the tile pattern data of the current tileset into VRAM
LoadTilesetTilePatternData:: ; 09e8 (0:09e8)
- ld a,[W_TILESETGFXPTR]
+ ld a,[wTileSetGFXPtr]
ld l,a
- ld a,[W_TILESETGFXPTR + 1]
+ ld a,[wTileSetGFXPtr + 1]
ld h,a
ld de,vTileset
ld bc,$600
- ld a,[W_TILESETBANK]
+ ld a,[wTileSetBank]
jp FarCopyData2
; this loads the current maps complete tile map (which references blocks, not individual tiles) to C6E8
@@ -881,23 +881,23 @@ LoadTileBlockMap:: ; 09fc (0:09fc)
; load tile map of current map (made of tile block IDs)
; 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 a,[wCurMapWidth]
ld [hMapWidth],a
- add a,$06 ; border (east and west)
+ add a,MAP_BORDER * 2 ; east and west
ld [hMapStride],a ; map width + border
- ld b,$00
+ 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 a,[wMapDataPtr] ; tile map pointer
ld e,a
- ld a,[W_MAPDATAPTR + 1]
+ ld a,[wMapDataPtr + 1]
ld d,a ; de = tile map pointer
- ld a,[W_CURMAPHEIGHT]
+ ld a,[wCurMapHeight]
ld b,a
.rowLoop ; copy one row each iteration
push hl
@@ -920,7 +920,7 @@ LoadTileBlockMap:: ; 09fc (0:09fc)
dec b
jr nz,.rowLoop
.northConnection
- ld a,[W_MAPCONN1PTR]
+ ld a,[wMapConn1Ptr]
cp a,$ff
jr z,.southConnection
call SwitchToMapRomBank
@@ -938,7 +938,7 @@ LoadTileBlockMap:: ; 09fc (0:09fc)
ld [hNorthSouthConnectedMapWidth],a
call LoadNorthSouthConnectionsTileMap
.southConnection
- ld a,[W_MAPCONN2PTR]
+ ld a,[wMapConn2Ptr]
cp a,$ff
jr z,.westConnection
call SwitchToMapRomBank
@@ -956,7 +956,7 @@ LoadTileBlockMap:: ; 09fc (0:09fc)
ld [hNorthSouthConnectedMapWidth],a
call LoadNorthSouthConnectionsTileMap
.westConnection
- ld a,[W_MAPCONN3PTR]
+ ld a,[wMapConn3Ptr]
cp a,$ff
jr z,.eastConnection
call SwitchToMapRomBank
@@ -974,7 +974,7 @@ LoadTileBlockMap:: ; 09fc (0:09fc)
ld [hEastWestConnectedMapWidth],a
call LoadEastWestConnectionsTileMap
.eastConnection
- ld a,[W_MAPCONN4PTR]
+ ld a,[wMapConn4Ptr]
cp a,$ff
jr z,.done
call SwitchToMapRomBank
@@ -995,7 +995,7 @@ LoadTileBlockMap:: ; 09fc (0:09fc)
ret
LoadNorthSouthConnectionsTileMap:: ; 0ade (0:0ade)
- ld c,$03
+ ld c,MAP_BORDER
.loop
push de
push hl
@@ -1015,8 +1015,8 @@ LoadNorthSouthConnectionsTileMap:: ; 0ade (0:0ade)
jr nc,.noCarry1
inc h
.noCarry1
- ld a,[W_CURMAPWIDTH]
- add a,$06
+ ld a,[wCurMapWidth]
+ add a,MAP_BORDER * 2
add e
ld e,a
jr nc,.noCarry2
@@ -1029,7 +1029,7 @@ LoadNorthSouthConnectionsTileMap:: ; 0ade (0:0ade)
LoadEastWestConnectionsTileMap:: ; 0b02 (0:0b02)
push hl
push de
- ld c,$03
+ ld c,MAP_BORDER
.innerLoop
ld a,[hli]
ld [de],a
@@ -1044,8 +1044,8 @@ LoadEastWestConnectionsTileMap:: ; 0b02 (0:0b02)
jr nc,.noCarry1
inc h
.noCarry1
- ld a,[W_CURMAPWIDTH]
- add a,$06
+ ld a,[wCurMapWidth]
+ add a,MAP_BORDER * 2
add e
ld e,a
jr nc,.noCarry2
@@ -1100,7 +1100,7 @@ IsSpriteOrSignInFrontOfPlayer:: ; 0b23 (0:0b23)
; 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
.extendRangeOverCounter
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 hl,wTileSetTalkingOverTiles ; list of tiles that extend talking range (counter tiles)
ld b,3
ld d,$20 ; talking range in pixels (long range)
.counterTilesLoop
@@ -1152,7 +1152,7 @@ IsSpriteInFrontOfPlayer2:: ; 0b6d (0:0b6d)
ld a,PLAYER_DIR_LEFT
.doneCheckingDirection
ld [wPlayerDirection],a
- ld a,[W_NUMSPRITES] ; number of sprites
+ ld a,[wNumSprites] ; number of sprites
and a
ret z
; if there are sprites
@@ -1190,8 +1190,8 @@ IsSpriteInFrontOfPlayer2:: ; 0b6d (0:0b6d)
ld a,l
and a,$f0
inc a
- ld l,a
- set 7,[hl]
+ ld l,a ; hl = $c1x1
+ set 7,[hl] ; set flag to make the sprite face the player
ld a,e
ld [hSpriteIndexOrTextID],a
ret
@@ -1224,7 +1224,7 @@ CollisionCheckOnLand:: ; 0bd1 (0:0bd1)
call CheckTilePassable
jr nc,.noCollision
.collision
- ld a,[wc02a]
+ ld a,[wChannelSoundIDs + CH4]
cp a,SFX_COLLISION ; check if collision sound is already playing
jr z,.setCarry
ld a,SFX_COLLISION
@@ -1242,7 +1242,7 @@ CheckTilePassable:: ; 0c10 (0:0c10)
predef GetTileAndCoordsInFrontOfPlayer ; get tile in front of player
ld a,[wTileInFrontOfPlayer] ; tile in front of player
ld c,a
- ld hl,W_TILESETCOLLISIONPTR ; pointer to list of passable tiles
+ ld hl,wTileSetCollisionPtr ; pointer to list of passable tiles
ld a,[hli]
ld h,[hl]
ld l,a ; hl now points to passable tiles
@@ -1284,7 +1284,7 @@ CheckForTilePairCollisions:: ; 0c4a (0:0c4a)
ld a,[wTileInFrontOfPlayer]
ld c,a
.tilePairCollisionLoop
- ld a,[W_CURMAPTILESET] ; tileset number
+ ld a,[wCurMapTileset] ; tileset number
ld b,a
ld a,[hli]
cp a,$ff
@@ -1354,7 +1354,7 @@ TilePairCollisionsWater:: ; 0ca0 (0:0ca0)
LoadCurrentMapView:: ; 0caa (0:0caa)
ld a,[H_LOADEDROMBANK]
push af
- ld a,[W_TILESETBANK] ; tile data ROM bank
+ ld a,[wTileSetBank] ; tile data ROM bank
ld [H_LOADEDROMBANK],a
ld [MBC1RomBank],a ; switch to ROM bank that contains tile data
ld a,[wCurrentTileBlockMapViewPointer] ; address of upper left corner of current map view
@@ -1386,8 +1386,8 @@ LoadCurrentMapView:: ; 0caa (0:0caa)
jr nz,.rowInnerLoop
; update tile block map pointer to next row's address
pop de
- ld a,[W_CURMAPWIDTH]
- add a,$06
+ ld a,[wCurMapWidth]
+ add a,MAP_BORDER * 2
add e
ld e,a
jr nc,.noCarry
@@ -1406,19 +1406,19 @@ LoadCurrentMapView:: ; 0caa (0:0caa)
ld hl,wTileMapBackup
ld bc,$0000
.adjustForYCoordWithinTileBlock
- ld a,[W_YBLOCKCOORD]
+ ld a,[wYBlockCoord]
and a
jr z,.adjustForXCoordWithinTileBlock
ld bc,$0030
add hl,bc
.adjustForXCoordWithinTileBlock
- ld a,[W_XBLOCKCOORD]
+ ld a,[wXBlockCoord]
and a
jr z,.copyToVisibleAreaBuffer
ld bc,$0002
add hl,bc
.copyToVisibleAreaBuffer
- coord de, 0, 0 ; base address for the tiles that are directly transfered to VRAM during V-blank
+ 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, SCREEN_WIDTH
@@ -1450,12 +1450,12 @@ AdvancePlayerSprite:: ; 0d27 (0:0d27)
dec [hl]
jr nz,.afterUpdateMapCoords
; if it's the end of the animation, update the player's map coordinates
- ld a,[W_YCOORD]
+ ld a,[wYCoord]
add b
- ld [W_YCOORD],a
- ld a,[W_XCOORD]
+ ld [wYCoord],a
+ ld a,[wXCoord]
add c
- ld [W_XCOORD],a
+ ld [wXCoord],a
.afterUpdateMapCoords
ld a,[wWalkCounter] ; walking animation counter
cp a,$07
@@ -1522,7 +1522,7 @@ AdvancePlayerSprite:: ; 0d27 (0:0d27)
and a
jr z,.pointlessJump ; mistake?
.pointlessJump
- ld hl,W_XBLOCKCOORD
+ ld hl,wXBlockCoord
ld a,[hl]
add c
ld [hl],a
@@ -1548,7 +1548,7 @@ AdvancePlayerSprite:: ; 0d27 (0:0d27)
call MoveTileBlockMapPointerWest
jr .updateMapView
.adjustYCoordWithinBlock
- ld hl,W_YBLOCKCOORD
+ ld hl,wYBlockCoord
ld a,[hl]
add b
ld [hl],a
@@ -1560,7 +1560,7 @@ AdvancePlayerSprite:: ; 0d27 (0:0d27)
ld hl,wYOffsetSinceLastSpecialWarp
inc [hl]
ld de,wCurrentTileBlockMapViewPointer
- ld a,[W_CURMAPWIDTH]
+ ld a,[wCurMapWidth]
call MoveTileBlockMapPointerSouth
jr .updateMapView
.checkForMoveToNorthBlock
@@ -1572,7 +1572,7 @@ AdvancePlayerSprite:: ; 0d27 (0:0d27)
ld hl,wYOffsetSinceLastSpecialWarp
dec [hl]
ld de,wCurrentTileBlockMapViewPointer
- ld a,[W_CURMAPWIDTH]
+ ld a,[wCurMapWidth]
call MoveTileBlockMapPointerNorth
.updateMapView
call LoadCurrentMapView
@@ -1616,7 +1616,7 @@ AdvancePlayerSprite:: ; 0d27 (0:0d27)
; shift all the sprites in the direction opposite of the player's motion
; so that the player appears to move relative to them
ld hl,wSpriteStateData1 + $14
- ld a,[W_NUMSPRITES] ; number of sprites
+ ld a,[wNumSprites] ; number of sprites
and a ; are there any sprites?
jr z,.done
ld e,a
@@ -1662,7 +1662,7 @@ MoveTileBlockMapPointerWest:: ; 0e6f (0:0e6f)
ret
MoveTileBlockMapPointerSouth:: ; 0e79 (0:0e79)
- add a,$06
+ add a,MAP_BORDER * 2
ld b,a
ld a,[de]
add b
@@ -1675,7 +1675,7 @@ MoveTileBlockMapPointerSouth:: ; 0e79 (0:0e79)
ret
MoveTileBlockMapPointerNorth:: ; 0e85 (0:0e85)
- add a,$06
+ add a,MAP_BORDER * 2
ld b,a
ld a,[de]
sub b
@@ -1692,17 +1692,17 @@ MoveTileBlockMapPointerNorth:: ; 0e85 (0:0e85)
ScheduleNorthRowRedraw:: ; 0e91 (0:0e91)
coord hl, 0, 0
- call CopyToScreenEdgeTiles
+ call CopyToRedrawRowOrColumnSrcTiles
ld a,[wMapViewVRAMPointer]
- ld [H_SCREENEDGEREDRAWADDR],a
+ ld [hRedrawRowOrColumnDest],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:: ; 0ea6 (0:0ea6)
- ld de,wScreenEdgeTiles
+CopyToRedrawRowOrColumnSrcTiles:: ; 0ea6 (0:0ea6)
+ ld de,wRedrawRowOrColumnSrcTiles
ld c,2 * SCREEN_WIDTH
.loop
ld a,[hli]
@@ -1714,7 +1714,7 @@ CopyToScreenEdgeTiles:: ; 0ea6 (0:0ea6)
ScheduleSouthRowRedraw:: ; 0eb2 (0:0eb2)
coord hl, 0, 16
- call CopyToScreenEdgeTiles
+ call CopyToRedrawRowOrColumnSrcTiles
ld a,[wMapViewVRAMPointer]
ld l,a
ld a,[wMapViewVRAMPointer + 1]
@@ -1724,11 +1724,11 @@ ScheduleSouthRowRedraw:: ; 0eb2 (0:0eb2)
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:: ; 0ed3 (0:0ed3)
@@ -1742,15 +1742,15 @@ ScheduleEastColumnRedraw:: ; 0ed3 (0:0ed3)
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:: ; 0ef2 (0:0ef2)
- ld de,wScreenEdgeTiles
+ ld de,wRedrawRowOrColumnSrcTiles
ld c,SCREEN_HEIGHT
.loop
ld a,[hli]
@@ -1773,20 +1773,20 @@ ScheduleWestColumnRedraw:: ; 0f08 (0:0f08)
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
; Input: c = tile block ID, hl = destination address
DrawTileBlock:: ; 0f1d (0:0f1d)
push hl
- ld a,[W_TILESETBLOCKSPTR] ; pointer to tiles
+ ld a,[wTileSetBlocksPtr] ; pointer to tiles
ld l,a
- ld a,[W_TILESETBLOCKSPTR + 1]
+ ld a,[wTileSetBlocksPtr + 1]
ld h,a
ld a,c
swap a
@@ -1829,10 +1829,10 @@ JoypadOverworld:: ; 0f4d (0:0f4d)
ld [wSpriteStateData1 + 5],a
call RunMapScript
call Joypad
- ld a,[W_FLAGS_D733]
+ ld a,[wFlags_D733]
bit 3,a ; check if a trainer wants a challenge
jr nz,.notForcedDownwards
- ld a,[W_CURMAP]
+ ld a,[wCurMap]
cp a,ROUTE_17 ; Cycling Road
jr nz,.notForcedDownwards
ld a,[hJoyHeld]
@@ -1915,7 +1915,7 @@ CollisionCheckOnWater:: ; 0fb7 (0:0fb7)
jr z,.noCollision ; keep surfing
; check if the [land] tile in front of the player is passable
.checkIfNextTileIsPassable
- ld hl,W_TILESETCOLLISIONPTR ; pointer to list of passable tiles
+ ld hl,wTileSetCollisionPtr ; pointer to list of passable tiles
ld a,[hli]
ld h,[hl]
ld l,a
@@ -1927,7 +1927,7 @@ CollisionCheckOnWater:: ; 0fb7 (0:0fb7)
jr z,.stopSurfing ; stop surfing if the tile is passable
jr .loop
.collision
- ld a,[wc02a]
+ ld a,[wChannelSoundIDs + CH4]
cp a,SFX_COLLISION ; check if collision sound is already playing
jr z,.setCarry
ld a,SFX_COLLISION
@@ -1946,7 +1946,7 @@ CollisionCheckOnWater:: ; 0fb7 (0:0fb7)
call PlayDefaultMusic
jr .noCollision
.checkIfVermilionDockTileset
- ld a, [W_CURMAPTILESET] ; tileset
+ ld a, [wCurMapTileset] ; tileset
cp SHIP_PORT ; Vermilion Dock tileset
jr nz, .noCollision ; keep surfing if it's not the boarding platform tile
jr .stopSurfing ; if it is the boarding platform tile, stop surfing
@@ -1966,9 +1966,9 @@ RunMapScript:: ; 101b (0:101b)
pop de
pop hl
call RunNPCMovementScript
- ld a,[W_CURMAP] ; current map number
+ ld a,[wCurMap] ; current map number
call SwitchToMapRomBank ; change to the ROM bank the map's data is in
- ld hl,W_MAPSCRIPTPTR
+ ld hl,wMapScriptPtr
ld a,[hli]
ld h,[hl]
ld l,a
@@ -2012,19 +2012,19 @@ LoadPlayerSpriteGraphicsCommon:: ; 1063 (0:1063)
; function to load data from the map header
LoadMapHeader:: ; 107c (0:107c)
callba MarkTownVisitedAndLoadMissableObjects
- ld a,[W_CURMAPTILESET]
+ ld a,[wCurMapTileset]
ld [wUnusedD119],a
- ld a,[W_CURMAP]
+ ld a,[wCurMap]
call SwitchToMapRomBank
- ld a,[W_CURMAPTILESET]
+ ld a,[wCurMapTileset]
ld b,a
res 7,a
- ld [W_CURMAPTILESET],a
+ ld [wCurMapTileset],a
ld [hPreviousTileset],a
bit 7,b
ret nz
ld hl,MapHeaderPointers
- ld a,[W_CURMAP]
+ ld a,[wCurMap]
sla a
jr nc,.noCarry1
inc h
@@ -2038,7 +2038,7 @@ LoadMapHeader:: ; 107c (0:107c)
ld h,[hl]
ld l,a ; hl = base of map header
; copy the first 10 bytes (the fixed area) of the map data to D367-D370
- ld de,W_CURMAPTILESET
+ ld de,wCurMapTileset
ld c,$0a
.copyFixedHeaderLoop
ld a,[hli]
@@ -2048,32 +2048,32 @@ LoadMapHeader:: ; 107c (0:107c)
jr nz,.copyFixedHeaderLoop
; initialize all the connected maps to disabled at first, before loading the actual values
ld a,$ff
- ld [W_MAPCONN1PTR],a
- ld [W_MAPCONN2PTR],a
- ld [W_MAPCONN3PTR],a
- ld [W_MAPCONN4PTR],a
+ ld [wMapConn1Ptr],a
+ ld [wMapConn2Ptr],a
+ ld [wMapConn3Ptr],a
+ ld [wMapConn4Ptr],a
; copy connection data (if any) to WRAM
- ld a,[W_MAPCONNECTIONS]
+ ld a,[wMapConnections]
ld b,a
.checkNorth
bit 3,b
jr z,.checkSouth
- ld de,W_MAPCONN1PTR
+ ld de,wMapConn1Ptr
call CopyMapConnectionHeader
.checkSouth
bit 2,b
jr z,.checkWest
- ld de,W_MAPCONN2PTR
+ ld de,wMapConn2Ptr
call CopyMapConnectionHeader
.checkWest
bit 1,b
jr z,.checkEast
- ld de,W_MAPCONN3PTR
+ ld de,wMapConn3Ptr
call CopyMapConnectionHeader
.checkEast
bit 0,b
jr z,.getObjectDataPointer
- ld de,W_MAPCONN4PTR
+ ld de,wMapConn4Ptr
call CopyMapConnectionHeader
.getObjectDataPointer
ld a,[hli]
@@ -2144,7 +2144,7 @@ LoadMapHeader:: ; 107c (0:107c)
bit 5,a ; did a battle happen immediately before this?
jp nz,.finishUp ; if so, skip this because battles don't destroy this data
ld a,[hli]
- ld [W_NUMSPRITES],a ; save the number of sprites
+ ld [wNumSprites],a ; save the number of sprites
push hl
; zero C110-C1FF and C210-C2FF
ld hl,wSpriteStateData1 + $10
@@ -2168,7 +2168,7 @@ LoadMapHeader:: ; 107c (0:107c)
jr nz,.disableSpriteEntriesLoop
pop hl
ld de,wSpriteStateData1 + $10
- ld a,[W_NUMSPRITES] ; number of sprites
+ ld a,[wNumSprites] ; number of sprites
and a ; are there any sprites?
jp z,.finishUp ; if there are no sprites, skip the rest
ld b,a
@@ -2195,7 +2195,7 @@ LoadMapHeader:: ; 107c (0:107c)
push bc
push hl
ld b,$00
- ld hl,W_MAPSPRITEDATA
+ ld hl,wMapSpriteData
add hl,bc
ld a,[hLoadSpriteTemp1]
ld [hli],a ; store movement byte 2 in byte 0 of sprite entry
@@ -2218,7 +2218,7 @@ LoadMapHeader:: ; 107c (0:107c)
ld a,[hli]
ld [hLoadSpriteTemp2],a ; save trainer number (within class)
push hl
- ld hl,W_MAPSPRITEEXTRADATA
+ ld hl,wMapSpriteExtraData
add hl,bc
ld a,[hLoadSpriteTemp1]
ld [hli],a ; store trainer class in byte 0 of the entry
@@ -2230,7 +2230,7 @@ LoadMapHeader:: ; 107c (0:107c)
ld a,[hli]
ld [hLoadSpriteTemp1],a ; save item number
push hl
- ld hl,W_MAPSPRITEEXTRADATA
+ ld hl,wMapSpriteExtraData
add hl,bc
ld a,[hLoadSpriteTemp1]
ld [hli],a ; store item number in byte 0 of the entry
@@ -2240,7 +2240,7 @@ LoadMapHeader:: ; 107c (0:107c)
jr .nextSprite
.regularSprite
push hl
- ld hl,W_MAPSPRITEEXTRADATA
+ ld hl,wMapSpriteExtraData
add hl,bc
; zero both bytes, since regular sprites don't use this extra space
xor a
@@ -2261,13 +2261,13 @@ LoadMapHeader:: ; 107c (0:107c)
predef LoadTilesetHeader
callab LoadWildData
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
+ ld a,[wCurMapHeight] ; map height in 4x4 tile blocks
add a ; double it
ld [wCurrentMapHeight2],a ; store map height in 2x2 tile blocks
- ld a,[W_CURMAPWIDTH] ; map width in 4x4 tile blocks
+ ld a,[wCurMapWidth] ; map width in 4x4 tile blocks
add a ; double it
ld [wCurrentMapWidth2],a ; map width in 2x2 tile blocks
- ld a,[W_CURMAP]
+ ld a,[wCurMap]
ld c,a
ld b,$00
ld a,[H_LOADEDROMBANK]
@@ -2279,9 +2279,9 @@ LoadMapHeader:: ; 107c (0:107c)
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
ld [H_LOADEDROMBANK],a
ld [MBC1RomBank],a
@@ -2313,7 +2313,7 @@ LoadMapData:: ; 1241 (0:1241)
ld [wWalkCounter],a
ld [wUnusedD119],a
ld [wWalkBikeSurfStateCopy],a
- ld [W_SPRITESETID],a
+ ld [wSpriteSetID],a
call LoadTextBoxTilePatterns
call LoadMapHeader
callba InitMapSprites ; load tile pattern data for sprites
@@ -2343,17 +2343,17 @@ LoadMapData:: ; 1241 (0:1241)
ld a,$01
ld [wUpdateSpritesEnabled],a
call EnableLCD
- ld b,$09
- call GoPAL_SET
+ ld b, SET_PAL_OVERWORLD
+ call RunPaletteCommand
call LoadPlayerSpriteGraphics
ld a,[wd732]
and a,1 << 4 | 1 << 3 ; fly warp or dungeon warp
jr nz,.restoreRomBank
- ld a,[W_FLAGS_D733]
+ ld a,[wFlags_D733]
bit 1,a
jr nz,.restoreRomBank
- call Func_235f ; music related
- call Func_2312 ; music related
+ call UpdateMusic6Times
+ call PlayDefaultMusicFadeOutCurrent
.restoreRomBank
pop af
ld [H_LOADEDROMBANK],a
diff --git a/home/pic.asm b/home/pic.asm
index 4bc7b31c..4af12117 100644
--- a/home/pic.asm
+++ b/home/pic.asm
@@ -1,5 +1,5 @@
; bankswitches and runs _UncompressSpriteData
-; bank is given in a, sprite input stream is pointed to in W_SPRITEINPUTPTR
+; bank is given in a, sprite input stream is pointed to in wSpriteInputPtr
UncompressSpriteData:: ; 24fd (0:24fd)
ld b, a
ld a, [H_LOADEDROMBANK]
@@ -19,51 +19,51 @@ UncompressSpriteData:: ; 24fd (0:24fd)
; initializes necessary data to load a sprite and runs UncompressSpriteDataLoop
_UncompressSpriteData:: ; 251a (0:251a)
- ld hl, S_SPRITEBUFFER1
+ ld hl, sSpriteBuffer1
ld c, (2*SPRITEBUFFERSIZE) % $100
ld b, (2*SPRITEBUFFERSIZE) / $100
xor a
call FillMemory ; clear sprite buffer 1 and 2
ld a, $1
- ld [W_SPRITEINPUTBITCOUNTER], a
+ ld [wSpriteInputBitCounter], a
ld a, $3
- ld [W_SPRITEOUTPUTBITOFFSET], a
+ ld [wSpriteOutputBitOffset], a
xor a
- ld [W_SPRITECURPOSX], a
- ld [W_SPRITECURPOSY], a
- ld [W_SPRITELOADFLAGS], a
+ ld [wSpriteCurPosX], a
+ ld [wSpriteCurPosY], a
+ ld [wSpriteLoadFlags], 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
add a
add a
add a
- ld [W_SPRITEHEIGHT], a
+ ld [wSpriteHeight], a
ld a, b
swap a
and $f
add a
add a
add a
- ld [W_SPRITEWITDH], a
+ ld [wSpriteWidth], a
call ReadNextInputBit
- ld [W_SPRITELOADFLAGS], a ; initialite bit1 to 0 and bit0 to the first input bit
- ; this will load two chunks of data to S_SPRITEBUFFER1 and S_SPRITEBUFFER2
+ ld [wSpriteLoadFlags], a ; initialite bit1 to 0 and bit0 to the first input bit
+ ; this will load two chunks of data to sSpriteBuffer1 and sSpriteBuffer2
; bit 0 decides in which one the first chunk is placed
; fall through
-; uncompresses a chunk from the sprite input data stream (pointed to at wd0da) into S_SPRITEBUFFER1 or S_SPRITEBUFFER2
+; uncompresses a chunk from the sprite input data stream (pointed to at wd0da) into sSpriteBuffer1 or sSpriteBuffer2
; each chunk is a 1bpp sprite. A 2bpp sprite consist of two chunks which are merged afterwards
; note that this is an endless loop which is terminated during a call to MoveToNextBufferPosition by manipulating the stack
UncompressSpriteDataLoop:: ; 2556 (0:2556)
- ld hl, S_SPRITEBUFFER1
- ld a, [W_SPRITELOADFLAGS]
+ ld hl, sSpriteBuffer1
+ ld a, [wSpriteLoadFlags]
bit 0, a
jr z, .useSpriteBuffer1 ; check which buffer to use
- ld hl, S_SPRITEBUFFER2
+ ld hl, sSpriteBuffer2
.useSpriteBuffer1
call StoreSpriteOutputPointer
- ld a, [W_SPRITELOADFLAGS]
+ ld a, [wSpriteLoadFlags]
bit 1, a
jr z, .startDecompression ; check if last iteration
call ReadNextInputBit ; if last chunk, read 1-2 bit unpacking mode
@@ -72,7 +72,7 @@ UncompressSpriteDataLoop:: ; 2556 (0:2556)
call ReadNextInputBit ; 1 0 -> mode 1
inc a ; 1 1 -> mode 2
.unpackingMode0
- ld [W_SPRITEUNPACKMODE], a
+ ld [wSpriteUnpackMode], a
.startDecompression
call ReadNextInputBit
and a
@@ -146,69 +146,69 @@ UncompressSpriteDataLoop:: ; 2556 (0:2556)
; also cancels the calling function if the all output is done (by removing the return pointer from stack)
; and calls postprocessing functions according to the unpack mode
MoveToNextBufferPosition:: ; 25d8 (0:25d8)
- ld a, [W_SPRITEHEIGHT]
+ ld a, [wSpriteHeight]
ld b, a
- ld a, [W_SPRITECURPOSY]
+ ld a, [wSpriteCurPosY]
inc a
cp b
jr z, .curColumnDone
- ld [W_SPRITECURPOSY], a
- ld a, [W_SPRITEOUTPUTPTR]
+ ld [wSpriteCurPosY], a
+ ld a, [wSpriteOutputPtr]
inc a
- ld [W_SPRITEOUTPUTPTR], a
+ ld [wSpriteOutputPtr], a
ret nz
- ld a, [W_SPRITEOUTPUTPTR+1]
+ ld a, [wSpriteOutputPtr+1]
inc a
- ld [W_SPRITEOUTPUTPTR+1], a
+ ld [wSpriteOutputPtr+1], a
ret
.curColumnDone
xor a
- ld [W_SPRITECURPOSY], a
- ld a, [W_SPRITEOUTPUTBITOFFSET]
+ ld [wSpriteCurPosY], a
+ ld a, [wSpriteOutputBitOffset]
and a
jr z, .bitOffsetsDone
dec a
- ld [W_SPRITEOUTPUTBITOFFSET], a
- ld hl, W_SPRITEOUTPUTPTRCACHED
+ ld [wSpriteOutputBitOffset], a
+ ld hl, wSpriteOutputPtrCached
ld a, [hli]
- ld [W_SPRITEOUTPUTPTR], a
+ ld [wSpriteOutputPtr], a
ld a, [hl]
- ld [W_SPRITEOUTPUTPTR+1], a
+ ld [wSpriteOutputPtr+1], a
ret
.bitOffsetsDone
ld a, $3
- ld [W_SPRITEOUTPUTBITOFFSET], a
- ld a, [W_SPRITECURPOSX]
+ ld [wSpriteOutputBitOffset], a
+ ld a, [wSpriteCurPosX]
add $8
- ld [W_SPRITECURPOSX], a
+ ld [wSpriteCurPosX], a
ld b, a
- ld a, [W_SPRITEWITDH]
+ ld a, [wSpriteWidth]
cp b
jr z, .allColumnsDone
- ld a, [W_SPRITEOUTPUTPTR]
+ ld a, [wSpriteOutputPtr]
ld l, a
- ld a, [W_SPRITEOUTPUTPTR+1]
+ ld a, [wSpriteOutputPtr+1]
ld h, a
inc hl
jp StoreSpriteOutputPointer
.allColumnsDone
pop hl
xor a
- ld [W_SPRITECURPOSX], a
- ld a, [W_SPRITELOADFLAGS]
+ ld [wSpriteCurPosX], a
+ ld a, [wSpriteLoadFlags]
bit 1, a
jr nz, .done ; test if there is one more sprite to go
xor $1
set 1, a
- ld [W_SPRITELOADFLAGS], a
+ ld [wSpriteLoadFlags], a
jp UncompressSpriteDataLoop
.done
jp UnpackSprite
-; writes 2 bits (from a) to the output buffer (pointed to from W_SPRITEOUTPUTPTR)
+; writes 2 bits (from a) to the output buffer (pointed to from wSpriteOutputPtr)
WriteSpriteBitsToBuffer:: ; 2649 (0:2649)
ld e, a
- ld a, [W_SPRITEOUTPUTBITOFFSET]
+ ld a, [wSpriteOutputBitOffset]
and a
jr z, .offset0
cp $2
@@ -224,9 +224,9 @@ WriteSpriteBitsToBuffer:: ; 2649 (0:2649)
.offset2
swap e
.offset0
- ld a, [W_SPRITEOUTPUTPTR]
+ ld a, [wSpriteOutputPtr]
ld l, a
- ld a, [W_SPRITEOUTPUTPTR+1]
+ ld a, [wSpriteOutputPtr+1]
ld h, a
ld a, [hl]
or e
@@ -235,32 +235,32 @@ WriteSpriteBitsToBuffer:: ; 2649 (0:2649)
; reads next bit from input stream and returns it in a
ReadNextInputBit:: ; 2670 (0:2670)
- ld a, [W_SPRITEINPUTBITCOUNTER]
+ ld a, [wSpriteInputBitCounter]
dec a
jr nz, .curByteHasMoreBitsToRead
call ReadNextInputByte
- ld [W_SPRITEINPUTCURBYTE], a
+ ld [wSpriteInputCurByte], a
ld a, $8
.curByteHasMoreBitsToRead
- ld [W_SPRITEINPUTBITCOUNTER], a
- ld a, [W_SPRITEINPUTCURBYTE]
+ ld [wSpriteInputBitCounter], a
+ ld a, [wSpriteInputCurByte]
rlca
- ld [W_SPRITEINPUTCURBYTE], a
+ ld [wSpriteInputCurByte], a
and $1
ret
; reads next byte from input stream and returns it in a
ReadNextInputByte:: ; 268b (0:268b)
- ld a, [W_SPRITEINPUTPTR]
+ ld a, [wSpriteInputPtr]
ld l, a
- ld a, [W_SPRITEINPUTPTR+1]
+ ld a, [wSpriteInputPtr+1]
ld h, a
ld a, [hli]
ld b, a
ld a, l
- ld [W_SPRITEINPUTPTR], a
+ ld [wSpriteInputPtr], a
ld a, h
- ld [W_SPRITEINPUTPTR+1], a
+ ld [wSpriteInputPtr+1], a
ld a, b
ret
@@ -285,24 +285,24 @@ LengthEncodingOffsetList:: ; 269f (0:269f)
; unpacks the sprite data depending on the unpack mode
UnpackSprite:: ; 26bf (0:26bf)
- ld a, [W_SPRITEUNPACKMODE]
+ ld a, [wSpriteUnpackMode]
cp $2
jp z, UnpackSpriteMode2
and a
jp nz, XorSpriteChunks
- ld hl, S_SPRITEBUFFER1
+ ld hl, sSpriteBuffer1
call SpriteDifferentialDecode
- ld hl, S_SPRITEBUFFER2
+ ld hl, sSpriteBuffer2
; fall through
; decodes differential encoded sprite data
; input bit value 0 preserves the current bit value and input bit value 1 toggles it (starting from initial value 0).
SpriteDifferentialDecode:: ; 26d4 (0:26d4)
xor a
- ld [W_SPRITECURPOSX], a
- ld [W_SPRITECURPOSY], a
+ ld [wSpriteCurPosX], a
+ ld [wSpriteCurPosY], a
call StoreSpriteOutputPointer
- ld a, [W_SPRITEFLIPPED]
+ ld a, [wSpriteFlipped]
and a
jr z, .notFlipped
ld hl, DecodeNybble0TableFlipped
@@ -313,18 +313,18 @@ SpriteDifferentialDecode:: ; 26d4 (0:26d4)
ld de, DecodeNybble1Table
.storeDecodeTablesPointers
ld a, l
- ld [W_SPRITEDECODETABLE0PTR], a
+ ld [wSpriteDecodeTable0Ptr], a
ld a, h
- ld [W_SPRITEDECODETABLE0PTR+1], a
+ ld [wSpriteDecodeTable0Ptr+1], a
ld a, e
- ld [W_SPRITEDECODETABLE1PTR], a
+ ld [wSpriteDecodeTable1Ptr], a
ld a, d
- ld [W_SPRITEDECODETABLE1PTR+1], a
+ ld [wSpriteDecodeTable1Ptr+1], a
ld e, $0 ; last decoded nybble, initialized to 0
.decodeNextByteLoop
- ld a, [W_SPRITEOUTPUTPTR]
+ ld a, [wSpriteOutputPtr]
ld l, a
- ld a, [W_SPRITEOUTPUTPTR+1]
+ ld a, [wSpriteOutputPtr+1]
ld h, a
ld a, [hl]
ld b, a
@@ -338,47 +338,47 @@ SpriteDifferentialDecode:: ; 26d4 (0:26d4)
call DifferentialDecodeNybble ; decode low nybble
or d
ld b, a
- ld a, [W_SPRITEOUTPUTPTR]
+ ld a, [wSpriteOutputPtr]
ld l, a
- ld a, [W_SPRITEOUTPUTPTR+1]
+ ld a, [wSpriteOutputPtr+1]
ld h, a
ld a, b
ld [hl], a ; write back decoded data
- ld a, [W_SPRITEHEIGHT]
+ ld a, [wSpriteHeight]
add l ; move on to next column
jr nc, .noCarry
inc h
.noCarry
- ld [W_SPRITEOUTPUTPTR], a
+ ld [wSpriteOutputPtr], a
ld a, h
- ld [W_SPRITEOUTPUTPTR+1], a
- ld a, [W_SPRITECURPOSX]
+ ld [wSpriteOutputPtr+1], a
+ ld a, [wSpriteCurPosX]
add $8
- ld [W_SPRITECURPOSX], a
+ ld [wSpriteCurPosX], a
ld b, a
- ld a, [W_SPRITEWITDH]
+ ld a, [wSpriteWidth]
cp b
jr nz, .decodeNextByteLoop ; test if current row is done
xor a
ld e, a
- ld [W_SPRITECURPOSX], a
- ld a, [W_SPRITECURPOSY] ; move on to next row
+ ld [wSpriteCurPosX], a
+ ld a, [wSpriteCurPosY] ; move on to next row
inc a
- ld [W_SPRITECURPOSY], a
+ ld [wSpriteCurPosY], a
ld b, a
- ld a, [W_SPRITEHEIGHT]
+ ld a, [wSpriteHeight]
cp b
jr z, .done ; test if all rows finished
- ld a, [W_SPRITEOUTPUTPTRCACHED]
+ ld a, [wSpriteOutputPtrCached]
ld l, a
- ld a, [W_SPRITEOUTPUTPTRCACHED+1]
+ ld a, [wSpriteOutputPtrCached+1]
ld h, a
inc hl
call StoreSpriteOutputPointer
jr .decodeNextByteLoop
.done
xor a
- ld [W_SPRITECURPOSY], a
+ ld [wSpriteCurPosY], a
ret
; decodes the nybble stored in a. Last decoded data is assumed to be in e (needed to determine if initial value is 0 or 1)
@@ -389,7 +389,7 @@ DifferentialDecodeNybble:: ; 276d (0:276d)
ld c, $1
.evenNumber
ld l, a
- ld a, [W_SPRITEFLIPPED]
+ ld a, [wSpriteFlipped]
and a
jr z, .notFlipped ; determine if initial value is 0 or one
bit 3, e ; if flipped, consider MSB of last data
@@ -399,14 +399,14 @@ DifferentialDecodeNybble:: ; 276d (0:276d)
.selectLookupTable
ld e, l
jr nz, .initialValue1 ; load the appropriate table
- ld a, [W_SPRITEDECODETABLE0PTR]
+ ld a, [wSpriteDecodeTable0Ptr]
ld l, a
- ld a, [W_SPRITEDECODETABLE0PTR+1]
+ ld a, [wSpriteDecodeTable0Ptr+1]
jr .tableLookup
.initialValue1
- ld a, [W_SPRITEDECODETABLE1PTR]
+ ld a, [wSpriteDecodeTable1Ptr]
ld l, a
- ld a, [W_SPRITEDECODETABLE1PTR+1]
+ ld a, [wSpriteDecodeTable1Ptr+1]
.tableLookup
ld h, a
ld a, e
@@ -464,25 +464,25 @@ DecodeNybble1TableFlipped:: ; 27bf (0:27bf)
; combines the two loaded chunks with xor (the chunk loaded second is the destination). The source chunk is differeintial decoded beforehand.
XorSpriteChunks:: ; 27c7 (0:27c7)
xor a
- ld [W_SPRITECURPOSX], a
- ld [W_SPRITECURPOSY], a
+ ld [wSpriteCurPosX], a
+ ld [wSpriteCurPosY], a
call ResetSpriteBufferPointers
- ld a, [W_SPRITEOUTPUTPTR] ; points to buffer 1 or 2, depending on flags
+ ld a, [wSpriteOutputPtr] ; points to buffer 1 or 2, depending on flags
ld l, a
- ld a, [W_SPRITEOUTPUTPTR+1]
+ ld a, [wSpriteOutputPtr+1]
ld h, a
call SpriteDifferentialDecode ; decode buffer 1 or 2, depending on flags
call ResetSpriteBufferPointers
- ld a, [W_SPRITEOUTPUTPTR] ; source buffer, points to buffer 1 or 2, depending on flags
+ ld a, [wSpriteOutputPtr] ; source buffer, points to buffer 1 or 2, depending on flags
ld l, a
- ld a, [W_SPRITEOUTPUTPTR+1]
+ ld a, [wSpriteOutputPtr+1]
ld h, a
- ld a, [W_SPRITEOUTPUTPTRCACHED] ; destination buffer, points to buffer 2 or 1, depending on flags
+ ld a, [wSpriteOutputPtrCached] ; destination buffer, points to buffer 2 or 1, depending on flags
ld e, a
- ld a, [W_SPRITEOUTPUTPTRCACHED+1]
+ ld a, [wSpriteOutputPtrCached+1]
ld d, a
.xorChunksLoop
- ld a, [W_SPRITEFLIPPED]
+ ld a, [wSpriteFlipped]
and a
jr z, .notFlipped
push de
@@ -506,24 +506,24 @@ XorSpriteChunks:: ; 27c7 (0:27c7)
xor b
ld [de], a
inc de
- ld a, [W_SPRITECURPOSY]
+ ld a, [wSpriteCurPosY]
inc a
- ld [W_SPRITECURPOSY], a ; go to next row
+ ld [wSpriteCurPosY], a ; go to next row
ld b, a
- ld a, [W_SPRITEHEIGHT]
+ ld a, [wSpriteHeight]
cp b
jr nz, .xorChunksLoop ; test if column finished
xor a
- ld [W_SPRITECURPOSY], a
- ld a, [W_SPRITECURPOSX]
+ ld [wSpriteCurPosY], a
+ ld a, [wSpriteCurPosX]
add $8
- ld [W_SPRITECURPOSX], a ; go to next column
+ ld [wSpriteCurPosX], a ; go to next column
ld b, a
- ld a, [W_SPRITEWITDH]
+ ld a, [wSpriteWidth]
cp b
jr nz, .xorChunksLoop ; test if all columns finished
xor a
- ld [W_SPRITECURPOSX], a
+ ld [wSpriteCurPosX], a
ret
; reverses the bits in the nybble given in register a
@@ -537,26 +537,26 @@ ReverseNybble:: ; 2837 (0:2837)
ld a, [de]
ret
-; resets sprite buffer pointers to buffer 1 and 2, depending on W_SPRITELOADFLAGS
+; resets sprite buffer pointers to buffer 1 and 2, depending on wSpriteLoadFlags
ResetSpriteBufferPointers:: ; 2841 (0:2841)
- ld a, [W_SPRITELOADFLAGS]
+ ld a, [wSpriteLoadFlags]
bit 0, a
jr nz, .buffer2Selected
- ld de, S_SPRITEBUFFER1
- ld hl, S_SPRITEBUFFER2
+ ld de, sSpriteBuffer1
+ ld hl, sSpriteBuffer2
jr .storeBufferPointers
.buffer2Selected
- ld de, S_SPRITEBUFFER2
- ld hl, S_SPRITEBUFFER1
+ ld de, sSpriteBuffer2
+ ld hl, sSpriteBuffer1
.storeBufferPointers
ld a, l
- ld [W_SPRITEOUTPUTPTR], a
+ ld [wSpriteOutputPtr], a
ld a, h
- ld [W_SPRITEOUTPUTPTR+1], a
+ ld [wSpriteOutputPtr+1], a
ld a, e
- ld [W_SPRITEOUTPUTPTRCACHED], a
+ ld [wSpriteOutputPtrCached], a
ld a, d
- ld [W_SPRITEOUTPUTPTRCACHED+1], a
+ ld [wSpriteOutputPtrCached+1], a
ret
; maps each nybble to its reverse
@@ -566,26 +566,26 @@ NybbleReverseTable:: ; 2867 (0:2867)
; combines the two loaded chunks with xor (the chunk loaded second is the destination). Both chunks are differeintial decoded beforehand.
UnpackSpriteMode2:: ; 2877 (0:2877)
call ResetSpriteBufferPointers
- ld a, [W_SPRITEFLIPPED]
+ ld a, [wSpriteFlipped]
push af
xor a
- ld [W_SPRITEFLIPPED], a ; temporarily clear flipped flag for decoding the destination chunk
- ld a, [W_SPRITEOUTPUTPTRCACHED]
+ ld [wSpriteFlipped], a ; temporarily clear flipped flag for decoding the destination chunk
+ ld a, [wSpriteOutputPtrCached]
ld l, a
- ld a, [W_SPRITEOUTPUTPTRCACHED+1]
+ ld a, [wSpriteOutputPtrCached+1]
ld h, a
call SpriteDifferentialDecode
call ResetSpriteBufferPointers
pop af
- ld [W_SPRITEFLIPPED], a
+ ld [wSpriteFlipped], a
jp XorSpriteChunks
; stores hl into the output pointers
StoreSpriteOutputPointer:: ; 2897 (0:2897)
ld a, l
- ld [W_SPRITEOUTPUTPTR], a
- ld [W_SPRITEOUTPUTPTRCACHED], a
+ ld [wSpriteOutputPtr], a
+ ld [wSpriteOutputPtrCached], a
ld a, h
- ld [W_SPRITEOUTPUTPTR+1], a
- ld [W_SPRITEOUTPUTPTRCACHED+1], a
+ ld [wSpriteOutputPtr+1], a
+ ld [wSpriteOutputPtrCached+1], a
ret
diff --git a/home/text.asm b/home/text.asm
index 238af447..a9e7cd60 100644
--- a/home/text.asm
+++ b/home/text.asm
@@ -146,7 +146,7 @@ Char52:: ; 0x19f9 player’s name
Char53:: ; 19ff (0:19ff) ; rival’s name
push de
- ld de,W_RIVALNAME
+ ld de,wRivalName
jr FinishDTE
Char5D:: ; 1a05 (0:1a05) ; TRAINER
diff --git a/home/vblank.asm b/home/vblank.asm
index 6abc3756..f69d4a86 100644
--- a/home/vblank.asm
+++ b/home/vblank.asm
@@ -22,7 +22,7 @@ VBlank::
call AutoBgMapTransfer
call VBlankCopyBgMap
- call RedrawExposedScreenEdge
+ call RedrawRowOrColumn
call VBlankCopy
call VBlankCopyDouble
call UpdateMovingBgTiles
@@ -38,21 +38,21 @@ VBlank::
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_28cb
+.skipDec
+ call FadeOutAudio
- ld a, [wc0ef] ; music ROM bank
+ ld a, [wAudioROMBank] ; music ROM bank
ld [H_LOADEDROMBANK], a
ld [MBC1RomBank], a
@@ -74,7 +74,7 @@ VBlank::
callba TrackPlayTime ; keep track of time played
- ld a, [$fff9]
+ ld a, [hDisableJoypadPolling]
and a
call z, ReadJoypad
diff --git a/home/vcopy.asm b/home/vcopy.asm
index 02caef29..69773cfe 100644
--- a/home/vcopy.asm
+++ b/home/vcopy.asm
@@ -33,23 +33,26 @@ 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:: ; 1d01 (0:1d01)
- ld a,[H_SCREENEDGEREDRAW]
+RedrawRowOrColumn:: ; 1d01 (0:1d01)
+; 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.
+ 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,SCREEN_HEIGHT
.loop1
@@ -58,7 +61,7 @@ RedrawExposedScreenEdge:: ; 1d01 (0:1d01)
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:: ; 1d01 (0:1d01)
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:: ; 1d01 (0:1d01)
; 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:: ; 1d57 (0:1d57)
ld a,[H_AUTOBGTRANSFERENABLED]
@@ -302,12 +306,11 @@ VBlankCopyDouble::
VBlankCopy::
-; 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