summaryrefslogtreecommitdiff
path: root/home/overworld.asm
diff options
context:
space:
mode:
Diffstat (limited to 'home/overworld.asm')
-rw-r--r--home/overworld.asm959
1 files changed, 489 insertions, 470 deletions
diff --git a/home/overworld.asm b/home/overworld.asm
index c5c180c7..ec8f1925 100644
--- a/home/overworld.asm
+++ b/home/overworld.asm
@@ -1,16 +1,14 @@
HandleMidJump::
; Handle the player jumping down
; a ledge in the overworld.
- ld b, BANK(_HandleMidJump)
- ld hl, _HandleMidJump
- jp Bankswitch
+ jpba _HandleMidJump
EnterMap::
; Load a new map.
ld a, $ff
ld [wJoyIgnore], a
call LoadMapData
- callba ClearVariablesAfterLoadingMapData
+ callba ClearVariablesOnEnterMap
ld hl, wd72c
bit 0, [hl] ; has the player already made 3 steps since the last battle?
jr z, .skipGivingThreeStepsOfNoRandomBattles
@@ -34,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,9 +59,9 @@ OverworldLoopLessDelay::
res 3,[hl]
jp nz,WarpFound2
ld a,[wd732]
- and a,1 << 4 | 1 << 3 ; fly warp or dungeon warp
+ and 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]
@@ -106,27 +104,28 @@ OverworldLoopLessDelay::
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
dec a
- ld a,$00
- ld [wcc47],a
+ ld a,0
+ ld [wEnteringCableClub],a
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
@@ -134,100 +133,112 @@ OverworldLoopLessDelay::
ld hl,wFlags_0xcd60
res 2,[hl]
call UpdateSprites
- ld a,$01
- ld [wcc4b],a
- ld a,[wd528] ; the direction that was pressed last time
+ ld a, 1
+ ld [wCheckFor180DegreeTurn],a
+ ld a,[wPlayerMovingDirection] ; the direction that was pressed last time
and a
jp 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
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 [wSpriteStateData1 + 5],a
+ ld a, 1
+ ld [wSpriteStateData1 + 5],a ; delta X
+
+
.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
-; the code below is strange
-; it computes whether or not the player did a 180 degree turn, but then overwrites the result
-; also, it does a seemingly pointless loop afterwards
+; Check whether the player did a 180-degree turn.
+; It appears that this code was supposed to show the player rotate by having
+; the player's sprite face an intermediate direction before facing the opposite
+; direction (instead of doing an instantaneous about-face), but the intermediate
+; direction is only set for a short period of time. It is unlikely for it to
+; ever be visible because DelayFrame is called at the start of OverworldLoop and
+; normally not enough cycles would be executed between then and the time the
+; direction is set for V-blank to occur while the direction is still set.
swap a ; put old direction in upper half
or b ; put new direction in lower half
- cp a,$48 ; change dir from down to up
+ cp a,(PLAYER_DIR_DOWN << 4) | PLAYER_DIR_UP ; change dir from down to up
jr nz,.notDownToUp
- ld a,$02
- ld [wd528],a
- jr .oddLoop
+ ld a,PLAYER_DIR_LEFT
+ ld [wPlayerMovingDirection],a
+ jr .holdIntermediateDirectionLoop
.notDownToUp
- cp a,$84 ; change dir from up to down
+ cp a,(PLAYER_DIR_UP << 4) | PLAYER_DIR_DOWN ; change dir from up to down
jr nz,.notUpToDown
- ld a,$01
- ld [wd528],a
- jr .oddLoop
+ ld a,PLAYER_DIR_RIGHT
+ ld [wPlayerMovingDirection],a
+ jr .holdIntermediateDirectionLoop
.notUpToDown
- cp a,$12 ; change dir from right to left
+ cp a,(PLAYER_DIR_RIGHT << 4) | PLAYER_DIR_LEFT ; change dir from right to left
jr nz,.notRightToLeft
- ld a,$04
- ld [wd528],a
- jr .oddLoop
+ ld a,PLAYER_DIR_DOWN
+ ld [wPlayerMovingDirection],a
+ jr .holdIntermediateDirectionLoop
.notRightToLeft
- cp a,$21 ; change dir from left to right
- jr nz,.oddLoop
- ld a,$08
- ld [wd528],a
-.oddLoop
+ cp a,(PLAYER_DIR_LEFT << 4) | PLAYER_DIR_RIGHT ; change dir from left to right
+ jr nz,.holdIntermediateDirectionLoop
+ ld a,PLAYER_DIR_UP
+ ld [wPlayerMovingDirection],a
+.holdIntermediateDirectionLoop
ld hl,wFlags_0xcd60
set 2,[hl]
- ld hl,wcc4b
+ ld hl,wCheckFor180DegreeTurn
dec [hl]
- jr nz,.oddLoop
- ld a,[wd52a]
- ld [wd528],a
+ jr nz,.holdIntermediateDirectionLoop
+ ld a,[wPlayerDirection]
+ ld [wPlayerMovingDirection],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
+ cp $02 ; surfing
jr z,.surfing
; not surfing
call CollisionCheckOnLand
@@ -244,20 +255,24 @@ OverworldLoopLessDelay::
pop hl
jp c,CheckWarpsCollision
jp OverworldLoop
+
.surfing
call CollisionCheckOnWater
jp c,OverworldLoop
+
.noCollision
ld a,$08
ld [wWalkCounter],a
jr .moveAhead2
+
.moveAhead
ld a,[wd736]
bit 7,a
jr z,.noSpinning
- callba LoadSpinnerArrowTiles ; spin while moving
+ callba LoadSpinnerArrowTiles
.noSpinning
- call UpdateSprites ; move sprites
+ call UpdateSprites
+
.moveAhead2
ld hl,wFlags_0xcd60
res 2,[hl]
@@ -267,7 +282,7 @@ OverworldLoopLessDelay::
ld a,[wd736]
bit 6,a ; jumping a ledge?
jr nz,.normalPlayerSpriteAdvancement
- call BikeSpeedup ; if riding a bike and not jumping a ledge
+ call DoBikeSpeedup
.normalPlayerSpriteAdvancement
call AdvancePlayerSprite
ld a,[wWalkCounter]
@@ -289,19 +304,18 @@ OverworldLoopLessDelay::
ld hl,wd72c
res 0,[hl] ; indicate that the player has stepped thrice since the last battle
.doneStepCounting
- ld a,[wd790]
- bit 7,a ; in the safari zone?
+ CheckEvent EVENT_IN_SAFARI_ZONE
jr z,.notSafariZone
callba SafariZoneCheckSteps
ld a,[wSafariZoneGameOver]
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
- ld a,[wd12d]
+ ld a,[wOutOfBattleBlackout]
and a
jp nz,HandleBlackOut ; if all pokemon fainted
.newBattle
@@ -312,41 +326,40 @@ 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]
- cp a,CINNABAR_GYM
+ ld a,[wCurMap]
+ cp CINNABAR_GYM
jr nz,.notCinnabarGym
- ld hl,wd79b
- set 7,[hl]
+ SetEvent EVENT_2A7
.notCinnabarGym
ld hl,wd72e
set 5,[hl]
- ld a,[W_CURMAP]
- cp a,OAKS_LAB
+ ld a,[wCurMap]
+ cp OAKS_LAB
jp z,.noFaintCheck ; no blacking out if the player lost to the rival in Oak's lab
callab AnyPartyAlive
ld a,d
and a
jr z,.allPokemonFainted
.noFaintCheck
- ld c,$0a
+ ld c,10
call DelayFrames
jp EnterMap
.allPokemonFainted
ld a,$ff
- ld [W_ISINBATTLE],a
+ ld [wIsInBattle],a
call RunMapScript
jp HandleBlackOut
; function to determine if there will be a battle and execute it (either a trainer battle or wild battle)
; sets carry if a battle occurred and unsets carry if not
-NewBattle:: ; 0683 (0:0683)
+NewBattle::
ld a,[wd72d]
bit 4,a
jr nz,.noBattle
@@ -355,41 +368,39 @@ NewBattle:: ; 0683 (0:0683)
ld a,[wd72e]
bit 4,a
jr nz,.noBattle
- ld b, BANK(InitBattle)
- ld hl, InitBattle
- jp Bankswitch
+ jpba InitBattle
.noBattle
and a
ret
; function to make bikes twice as fast as walking
-BikeSpeedup:: ; 06a0 (0:06a0)
+DoBikeSpeedup::
ld a,[wNPCMovementScriptPointerTableNum]
and a
ret nz
- ld a,[W_CURMAP]
- cp a,ROUTE_17 ; Cycling Road
+ ld a,[wCurMap]
+ cp ROUTE_17 ; Cycling Road
jr nz,.goFaster
ld a,[hJoyHeld]
- and a,D_UP | D_LEFT | D_RIGHT
+ and D_UP | D_LEFT | D_RIGHT
ret nz
.goFaster
jp AdvancePlayerSprite
; check if the player has stepped onto a warp after having not collided
-CheckWarpsNoCollision:: ; 06b4 (0:06b4)
+CheckWarpsNoCollision::
ld a,[wNumberOfWarps]
and a
jp z,CheckMapConnections
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)
+CheckWarpsNoCollisionLoop::
ld a,[hli] ; check if the warp's Y position matches
cp d
jr nz,CheckWarpsNoCollisionRetry1
@@ -412,7 +423,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
@@ -421,30 +432,30 @@ CheckWarpsNoCollisionLoop:: ; 06cc (0:06cc)
pop bc
pop de
ld a,[hJoyHeld]
- and a,D_DOWN | D_UP | D_LEFT | D_RIGHT
+ and D_DOWN | D_UP | D_LEFT | D_RIGHT
jr z,CheckWarpsNoCollisionRetry2 ; if directional buttons aren't being pressed, do not pass through the warp
jr WarpFound1
; check if the player has stepped onto a warp after having collided
-CheckWarpsCollision:: ; 0706 (0:0706)
+CheckWarpsCollision::
ld a,[wNumberOfWarps]
ld c,a
ld hl,wWarpEntries
.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]
ld [wDestinationWarpID],a
ld a,[hl]
- ld [$ff8b],a ; save target map
+ ld [hWarpDestinationMap],a
jr WarpFound2
.retry1
inc hl
@@ -455,35 +466,35 @@ CheckWarpsCollision:: ; 0706 (0:0706)
jr nz,.loop
jp OverworldLoop
-CheckWarpsNoCollisionRetry1:: ; 072f (0:072f)
+CheckWarpsNoCollisionRetry1::
inc hl
-CheckWarpsNoCollisionRetry2:: ; 0730 (0:0730)
+CheckWarpsNoCollisionRetry2::
inc hl
inc hl
jp ContinueCheckWarpsNoCollisionLoop
-WarpFound1:: ; 0735 (0:0735)
+WarpFound1::
ld a,[hli]
ld [wDestinationWarpID],a
ld a,[hli]
- ld [$ff8b],a ; save target map
+ ld [hWarpDestinationMap],a
-WarpFound2:: ; 073c (0:073c)
+WarpFound2::
ld a,[wNumberOfWarps]
sub c
- ld [wd73b],a ; save ID of used warp
- ld a,[W_CURMAP]
- ld [wd73c],a
+ ld [wWarpedFromWhichWarp],a ; save ID of used warp
+ 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 [wd366],a
- ld a,[$ff8b] ; destination map number
- ld [W_CURMAP],a ; change current map to destination map
- cp a,ROCK_TUNNEL_1
+ ld a,[wCurMapWidth]
+ ld [wUnusedD366],a ; not read
+ ld a,[hWarpDestinationMap]
+ ld [wCurMap],a
+ cp ROCK_TUNNEL_1
jr nz,.notRockTunnel
ld a,$06
ld [wMapPalOffset],a
@@ -491,15 +502,17 @@ WarpFound2:: ; 073c (0:073c)
.notRockTunnel
call PlayMapChangeSound
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
+
+; 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
- cp a,$ff
+ ld a,[hWarpDestinationMap] ; destination map
+ cp $ff
jr z,.goBackOutside
; if not going back to the previous map
- ld [W_CURMAP],a ; current map number
+ ld [wCurMap],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
@@ -516,7 +529,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
@@ -526,39 +539,39 @@ WarpFound2:: ; 073c (0:073c)
call IgnoreInputForHalfSecond
jp EnterMap
-ContinueCheckWarpsNoCollisionLoop:: ; 07b5 (0:07b5)
+ContinueCheckWarpsNoCollisionLoop::
inc b ; increment warp number
dec c ; decrement number of warps
jp nz,CheckWarpsNoCollisionLoop
; if no matching warp was found
-CheckMapConnections:: ; 07ba (0:07ba)
+CheckMapConnections::
.checkWestMap
- ld a,[W_XCOORD]
- cp a,$ff
+ ld a,[wXCoord]
+ cp $ff
jr nz,.checkEastMap
- ld a,[W_MAPCONN3PTR]
- ld [W_CURMAP],a
- ld a,[wd38f] ; new X coordinate upon entering west map
- ld [W_XCOORD],a
- ld a,[W_YCOORD]
+ ld a,[wMapConn3Ptr]
+ ld [wCurMap],a
+ ld a,[wWestConnectedMapXAlignment] ; new X coordinate upon entering west map
+ ld [wXCoord],a
+ ld a,[wYCoord]
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 [wYCoord],a
+ 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 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
@@ -568,33 +581,34 @@ CheckMapConnections:: ; 07ba (0:07ba)
ld a,h
ld [wCurrentTileBlockMapViewPointer + 1],a
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 [W_XCOORD],a
- ld a,[W_YCOORD]
+ ld a,[wMapConn4Ptr]
+ ld [wCurMap],a
+ ld a,[wEastConnectedMapXAlignment] ; new X coordinate upon entering east map
+ ld [wXCoord],a
+ ld a,[wYCoord]
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 [wYCoord],a
+ 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 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
@@ -604,25 +618,26 @@ CheckMapConnections:: ; 07ba (0:07ba)
ld a,h
ld [wCurrentTileBlockMapViewPointer + 1],a
jp .loadNewMap
+
.checkNorthMap
- ld a,[W_YCOORD]
- cp a,$ff
+ ld a,[wYCoord]
+ cp $ff
jr nz,.checkSouthMap
- ld a,[W_MAPCONN1PTR]
- ld [W_CURMAP],a
- ld a,[wd378] ; new Y coordinate upon entering north map
- ld [W_YCOORD],a
- ld a,[W_XCOORD]
+ ld a,[wMapConn1Ptr]
+ ld [wCurMap],a
+ ld a,[wNorthConnectedMapYAlignment] ; new Y coordinate upon entering north map
+ ld [wYCoord],a
+ ld a,[wXCoord]
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 [wXCoord],a
+ 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
@@ -630,26 +645,27 @@ CheckMapConnections:: ; 07ba (0:07ba)
ld a,h
ld [wCurrentTileBlockMapViewPointer + 1],a
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 [W_YCOORD],a
- ld a,[W_XCOORD]
+ ld a,[wMapConn2Ptr]
+ ld [wCurMap],a
+ ld a,[wSouthConnectedMapYAlignment] ; new Y coordinate upon entering south map
+ ld [wYCoord],a
+ ld a,[wXCoord]
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 [wXCoord],a
+ 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
@@ -658,26 +674,27 @@ 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
call LoadTileBlockMap
jp OverworldLoopLessDelay
+
.didNotEnterConnectedMap
jp OverworldLoop
; function to play a sound when changing maps
-PlayMapChangeSound:: ; 08c9 (0:08c9)
+PlayMapChangeSound::
aCoord 8, 8 ; upper left tile of the 4x4 square the player's sprite is standing on
- cp a,$0b ; door tile in tileset 0
+ cp $0b ; door tile in tileset 0
jr nz,.didNotGoThroughDoor
- ld a,(SFX_02_57 - SFX_Headers_02) / 3
+ ld a,SFX_GO_INSIDE
jr .playSound
.didNotGoThroughDoor
- ld a,(SFX_02_5c - SFX_Headers_02) / 3
+ ld a,SFX_GO_OUTSIDE
.playSound
call PlaySound
ld a,[wMapPalOffset]
@@ -685,9 +702,9 @@ PlayMapChangeSound:: ; 08c9 (0:08c9)
ret nz
jp GBFadeOutToBlack
-CheckIfInOutsideMap:: ; 08e1 (0:08e1)
+CheckIfInOutsideMap::
; 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
@@ -699,8 +716,8 @@ CheckIfInOutsideMap:: ; 08e1 (0:08e1)
; "function 1" passes when the player is at the edge of the map and is facing towards the outside of the map
; "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]
+ExtraWarpCheck::
+ ld a, [wCurMap]
cp SS_ANNE_3
jr z, .useFunction1
cp ROCKET_HIDEOUT_1
@@ -711,7 +728,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
@@ -729,7 +746,7 @@ ExtraWarpCheck:: ; 08e9 (0:08e9)
ld b, BANK(IsWarpTileInFrontOfPlayer)
jp Bankswitch
-MapEntryAfterBattle:: ; 091f (0:091f)
+MapEntryAfterBattle::
callba IsPlayerStandingOnWarp ; for enabling warp testing after collisions
ld a,[wMapPalOffset]
and a
@@ -750,16 +767,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 +787,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
@@ -778,14 +795,12 @@ HandleFlyWarpOrDungeonWarp::
call LeaveMapAnim
ld a, Bank(SpecialWarpIn)
ld [H_LOADEDROMBANK], a
- ld [$2000], a
+ ld [MBC1RomBank], a
call SpecialWarpIn
jp SpecialEnterMap
LeaveMapAnim::
- ld b, BANK(_LeaveMapAnim)
- ld hl, _LeaveMapAnim
- jp Bankswitch
+ jpba _LeaveMapAnim
LoadPlayerSpriteGraphics::
; Load sprite graphics based on whether the player is standing, biking, or surfing.
@@ -830,13 +845,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
@@ -855,22 +870,22 @@ IsBikeRidingAllowed::
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]
+LoadTilesetTilePatternData::
+ 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
; it can also load partial tile maps of connected maps into a border of length 3 around the current map
-LoadTileBlockMap:: ; 09fc (0:09fc)
+LoadTileBlockMap::
; fill C6E8-CBFB with the background tile
ld hl,wOverworldMap
- ld a,[wd3ad] ; background tile number
+ ld a,[wMapBackgroundTile]
ld d,a
ld bc,$0514
.backgroundTileLoop
@@ -883,27 +898,27 @@ 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 [$ff8c],a
- add a,$06 ; border (east and west)
- ld [$ff8b],a ; map width + border
- ld b,$00
+ ld a,[wCurMapWidth]
+ ld [hMapWidth],a
+ add 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 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
- ld a,[$ff8c] ; map width (without border)
+ ld a,[hMapWidth] ; map width (without border)
ld c,a
.rowInnerLoop
ld a,[de]
@@ -913,7 +928,7 @@ LoadTileBlockMap:: ; 09fc (0:09fc)
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
@@ -922,86 +937,86 @@ LoadTileBlockMap:: ; 09fc (0:09fc)
dec b
jr nz,.rowLoop
.northConnection
- ld a,[W_MAPCONN1PTR]
- cp a,$ff
+ ld a,[wMapConn1Ptr]
+ cp $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
+ ld a,[wMapConn2Ptr]
+ cp $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
+ ld a,[wMapConn3Ptr]
+ cp $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
+ ld a,[wMapConn4Ptr]
+ cp $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:: ; 0ade (0:0ade)
- ld c,$03
+LoadNorthSouthConnectionsTileMap::
+ 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]
@@ -1011,14 +1026,14 @@ LoadNorthSouthConnectionsTileMap:: ; 0ade (0:0ade)
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
+ ld a,[wCurMapWidth]
+ add MAP_BORDER * 2
add e
ld e,a
jr nc,.noCarry2
@@ -1028,10 +1043,10 @@ LoadNorthSouthConnectionsTileMap:: ; 0ade (0:0ade)
jr nz,.loop
ret
-LoadEastWestConnectionsTileMap:: ; 0b02 (0:0b02)
+LoadEastWestConnectionsTileMap::
push hl
push de
- ld c,$03
+ ld c,MAP_BORDER
.innerLoop
ld a,[hli]
ld [de],a
@@ -1040,14 +1055,14 @@ LoadEastWestConnectionsTileMap:: ; 0b02 (0:0b02)
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
+ ld a,[wCurMapWidth]
+ add MAP_BORDER * 2
add e
ld e,a
jr nc,.noCarry2
@@ -1060,18 +1075,18 @@ LoadEastWestConnectionsTileMap:: ; 0b02 (0:0b02)
; function to check if there is a sign or sprite in front of the player
; if so, it is stored in [hSpriteIndexOrTextID]
; if not, [hSpriteIndexOrTextID] is set to 0
-IsSpriteOrSignInFrontOfPlayer:: ; 0b23 (0:0b23)
+IsSpriteOrSignInFrontOfPlayer::
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
predef GetTileAndCoordsInFrontOfPlayer ; get the coordinates in front of the player in de
- ld hl,wd4b1 ; start of sign coordinates
- ld a,[wd4b0] ; number of signs in the map
+ ld hl,wSignCoords
+ ld a,[wNumSigns]
ld b,a
- ld c,$00
+ ld c,0
.signLoop
inc c
ld a,[hli] ; sign Y
@@ -1087,8 +1102,8 @@ IsSpriteOrSignInFrontOfPlayer:: ; 0b23 (0:0b23)
; found sign
push hl
push bc
- ld hl,wd4d1 ; start of sign text ID's
- ld b,$00
+ ld hl,wSignTextIDs
+ ld b,0
dec c
add hl,bc
ld a,[hl]
@@ -1102,8 +1117,8 @@ 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 b,$03
+ 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
ld a,[hli]
@@ -1114,47 +1129,50 @@ IsSpriteOrSignInFrontOfPlayer:: ; 0b23 (0:0b23)
; part of the above function, but sometimes its called on its own, when signs are irrelevant
; the caller must zero [hSpriteIndexOrTextID]
-IsSpriteInFrontOfPlayer:: ; 0b6b (0:0b6b)
+IsSpriteInFrontOfPlayer::
ld d,$10 ; talking range in pixels (normal range)
-IsSpriteInFrontOfPlayer2:: ; 0b6d (0:0b6d)
- ld bc,$3c40 ; Y and X position of player sprite
+IsSpriteInFrontOfPlayer2::
+ 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 a,[W_NUMSPRITES] ; number of sprites
+ ld [wPlayerDirection],a
+ ld a,[wNumSprites] ; number of sprites
and a
ret z
; if there are sprites
@@ -1192,15 +1210,15 @@ 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
; function to check if the player will jump down a ledge and check if the tile ahead is passable (when not surfing)
; sets the carry flag if there is a collision, and unsets it if there isn't a collision
-CollisionCheckOnLand:: ; 0bd1 (0:0bd1)
+CollisionCheckOnLand::
ld a,[wd736]
bit 6,a ; is the player jumping?
jr nz,.noCollision
@@ -1208,7 +1226,7 @@ CollisionCheckOnLand:: ; 0bd1 (0:0bd1)
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
@@ -1226,10 +1244,10 @@ CollisionCheckOnLand:: ; 0bd1 (0:0bd1)
call CheckTilePassable
jr nc,.noCollision
.collision
- ld a,[wc02a]
- cp a,(SFX_02_5b - SFX_Headers_02) / 3 ; check if collision sound is already playing
+ ld a,[wChannelSoundIDs + Ch4]
+ cp SFX_COLLISION ; check if collision sound is already playing
jr z,.setCarry
- ld a,(SFX_02_5b - SFX_Headers_02) / 3
+ ld a,SFX_COLLISION
call PlaySound ; play collision sound (if it's not already playing)
.setCarry
scf
@@ -1240,11 +1258,11 @@ CollisionCheckOnLand:: ; 0bd1 (0:0bd1)
; function that checks if the tile in front of the player is passable
; clears carry if it is, sets carry if not
-CheckTilePassable:: ; 0c10 (0:0c10)
+CheckTilePassable::
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
@@ -1263,7 +1281,7 @@ CheckTilePassable:: ; 0c10 (0:0c10)
; and check for collisions that only occur between certain pairs of tiles
; Input: hl - address of directional collision data
; sets carry if there is a collision and unsets carry if not
-CheckForJumpingAndTilePairCollisions:: ; 0c2a (0:0c2a)
+CheckForJumpingAndTilePairCollisions::
push hl
predef GetTileAndCoordsInFrontOfPlayer ; get the tile in front of the player
push de
@@ -1278,18 +1296,18 @@ CheckForJumpingAndTilePairCollisions:: ; 0c2a (0:0c2a)
ret nz
; if not jumping
-CheckForTilePairCollisions2:: ; 0c44 (0:0c44)
+CheckForTilePairCollisions2::
aCoord 8, 9 ; tile the player is on
- ld [wcf0e],a
+ ld [wTilePlayerStandingOn],a
-CheckForTilePairCollisions:: ; 0c4a (0:0c4a)
+CheckForTilePairCollisions::
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
+ cp $ff
jr z,.noMatch
cp b
jr z,.tilesetMatches
@@ -1298,7 +1316,7 @@ CheckForTilePairCollisions:: ; 0c4a (0:0c4a)
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
@@ -1332,7 +1350,7 @@ CheckForTilePairCollisions:: ; 0c4a (0:0c4a)
; these entries indicate that the player may not cross between tile 1 and tile 2
; it's mainly used to simulate differences in elevation
-TilePairCollisionsLand:: ; 0c7e (0:0c7e)
+TilePairCollisionsLand::
db CAVERN, $20, $05
db CAVERN, $41, $05
db FOREST, $30, $2E
@@ -1346,19 +1364,19 @@ TilePairCollisionsLand:: ; 0c7e (0:0c7e)
db FOREST, $5F, $2E
db $FF
-TilePairCollisionsWater:: ; 0ca0 (0:0ca0)
+TilePairCollisionsWater::
db FOREST, $14, $2E
db FOREST, $48, $2E
db CAVERN, $14, $05
db $FF
; this builds a tile map from the tile block map based on the current X/Y coordinates of the player's character
-LoadCurrentMapView:: ; 0caa (0:0caa)
+LoadCurrentMapView::
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 [$2000],a ; switch to ROM bank that contains tile data
+ ld [MBC1RomBank],a ; switch to ROM bank that contains tile data
ld a,[wCurrentTileBlockMapViewPointer] ; address of upper left corner of current map view
ld e,a
ld a,[wCurrentTileBlockMapViewPointer + 1]
@@ -1388,8 +1406,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 MAP_BORDER * 2
add e
ld e,a
jr nc,.noCarry
@@ -1408,22 +1426,22 @@ 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
- 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
@@ -1440,10 +1458,10 @@ LoadCurrentMapView:: ; 0caa (0:0caa)
jr nz,.rowLoop2
pop af
ld [H_LOADEDROMBANK],a
- ld [$2000],a ; restore previous ROM bank
+ ld [MBC1RomBank],a ; restore previous ROM bank
ret
-AdvancePlayerSprite:: ; 0d27 (0:0d27)
+AdvancePlayerSprite::
ld a,[wSpriteStateData1 + 3] ; delta Y
ld b,a
ld a,[wSpriteStateData1 + 5] ; delta X
@@ -1452,12 +1470,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
@@ -1524,7 +1542,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
@@ -1550,7 +1568,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
@@ -1562,7 +1580,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
@@ -1574,7 +1592,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
@@ -1618,7 +1636,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
@@ -1641,7 +1659,7 @@ AdvancePlayerSprite:: ; 0d27 (0:0d27)
; the following four functions are used to move the pointer to the upper left
; corner of the tile block map in the direction of motion
-MoveTileBlockMapPointerEast:: ; 0e65 (0:0e65)
+MoveTileBlockMapPointerEast::
ld a,[de]
add a,$01
ld [de],a
@@ -1652,7 +1670,7 @@ MoveTileBlockMapPointerEast:: ; 0e65 (0:0e65)
ld [de],a
ret
-MoveTileBlockMapPointerWest:: ; 0e6f (0:0e6f)
+MoveTileBlockMapPointerWest::
ld a,[de]
sub a,$01
ld [de],a
@@ -1663,8 +1681,8 @@ MoveTileBlockMapPointerWest:: ; 0e6f (0:0e6f)
ld [de],a
ret
-MoveTileBlockMapPointerSouth:: ; 0e79 (0:0e79)
- add a,$06
+MoveTileBlockMapPointerSouth::
+ add a,MAP_BORDER * 2
ld b,a
ld a,[de]
add b
@@ -1676,8 +1694,8 @@ MoveTileBlockMapPointerSouth:: ; 0e79 (0:0e79)
ld [de],a
ret
-MoveTileBlockMapPointerNorth:: ; 0e85 (0:0e85)
- add a,$06
+MoveTileBlockMapPointerNorth::
+ add a,MAP_BORDER * 2
ld b,a
ld a,[de]
sub b
@@ -1692,20 +1710,20 @@ MoveTileBlockMapPointerNorth:: ; 0e85 (0:0e85)
; the following 6 functions are used to tell the V-blank handler to redraw
; the portion of the map that was newly exposed due to the player's movement
-ScheduleNorthRowRedraw:: ; 0e91 (0:0e91)
- hlCoord 0, 0
- call CopyToScreenEdgeTiles
+ScheduleNorthRowRedraw::
+ coord hl, 0, 0
+ 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
- ld c,2 * 20
+CopyToRedrawRowOrColumnSrcTiles::
+ ld de,wRedrawRowOrColumnSrcTiles
+ ld c,2 * SCREEN_WIDTH
.loop
ld a,[hli]
ld [de],a
@@ -1714,9 +1732,9 @@ CopyToScreenEdgeTiles:: ; 0ea6 (0:0ea6)
jr nz,.loop
ret
-ScheduleSouthRowRedraw:: ; 0eb2 (0:0eb2)
- hlCoord 0, 16
- call CopyToScreenEdgeTiles
+ScheduleSouthRowRedraw::
+ coord hl, 0, 16
+ call CopyToRedrawRowOrColumnSrcTiles
ld a,[wMapViewVRAMPointer]
ld l,a
ld a,[wMapViewVRAMPointer + 1]
@@ -1724,36 +1742,36 @@ ScheduleSouthRowRedraw:: ; 0eb2 (0:0eb2)
ld bc,$0200
add hl,bc
ld a,h
- and a,$03
- or a,$98
- ld [H_SCREENEDGEREDRAWADDR + 1],a
+ and $03
+ or $98
+ 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)
- hlCoord 18, 0
+ScheduleEastColumnRedraw::
+ coord hl, 18, 0
call ScheduleColumnRedrawHelper
ld a,[wMapViewVRAMPointer]
ld c,a
- and a,$e0
+ and $e0
ld b,a
ld a,c
- add a,18
- and a,$1f
+ add 18
+ and $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 c,$12
+ScheduleColumnRedrawHelper::
+ ld de,wRedrawRowOrColumnSrcTiles
+ ld c,SCREEN_HEIGHT
.loop
ld a,[hli]
ld [de],a
@@ -1771,32 +1789,32 @@ ScheduleColumnRedrawHelper:: ; 0ef2 (0:0ef2)
jr nz,.loop
ret
-ScheduleWestColumnRedraw:: ; 0f08 (0:0f08)
- hlCoord 0, 0
+ScheduleWestColumnRedraw::
+ 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)
+DrawTileBlock::
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
ld b,a
- and a,$f0
+ and $f0
ld c,a
ld a,b
- and a,$0f
+ and $0f
ld b,a ; bc = tile block ID * 0x10
add hl,bc
ld d,h
@@ -1825,20 +1843,20 @@ DrawTileBlock:: ; 0f1d (0:0f1d)
ret
; function to update joypad state and simulate button presses
-JoypadOverworld:: ; 0f4d (0:0f4d)
+JoypadOverworld::
xor a
ld [wSpriteStateData1 + 3],a
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]
- cp a,ROUTE_17 ; Cycling Road
+ ld a,[wCurMap]
+ cp ROUTE_17 ; Cycling Road
jr nz,.notForcedDownwards
ld a,[hJoyHeld]
- and a,D_DOWN | D_UP | D_LEFT | D_RIGHT | B_BUTTON | A_BUTTON
+ and D_DOWN | D_UP | D_LEFT | D_RIGHT | B_BUTTON | A_BUTTON
jr nz,.notForcedDownwards
ld a,D_DOWN
ld [hJoyHeld],a ; on the cycling road, if there isn't a trainer and the player isn't pressing buttons, simulate a down press
@@ -1870,6 +1888,7 @@ JoypadOverworld:: ; 0f4d (0:0f4d)
ld [hJoyPressed],a
ld [hJoyReleased],a
ret
+
; if done simulating button presses
.doneSimulating
xor a
@@ -1880,7 +1899,7 @@ JoypadOverworld:: ; 0f4d (0:0f4d)
ld [hJoyHeld],a
ld hl,wd736
ld a,[hl]
- and a,$f8
+ and $f8
ld [hl],a
ld hl,wd730
res 7,[hl]
@@ -1895,11 +1914,11 @@ JoypadOverworld:: ; 0f4d (0:0f4d)
; so the old value of c is used. 2429 is always called before this function,
; and 2429 always sets c to 0xF0. There is no 0xF0 background tile, so it
; is considered impassable and it is detected as a collision.
-CollisionCheckOnWater:: ; 0fb7 (0:0fb7)
+CollisionCheckOnWater::
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
@@ -1917,7 +1936,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
@@ -1929,10 +1948,10 @@ CollisionCheckOnWater:: ; 0fb7 (0:0fb7)
jr z,.stopSurfing ; stop surfing if the tile is passable
jr .loop
.collision
- ld a,[wc02a]
- cp a,(SFX_02_5b - SFX_Headers_02) / 3 ; check if collision sound is already playing
+ ld a,[wChannelSoundIDs + Ch4]
+ cp SFX_COLLISION ; check if collision sound is already playing
jr z,.setCarry
- ld a,(SFX_02_5b - SFX_Headers_02) / 3
+ ld a,SFX_COLLISION
call PlaySound ; play collision sound (if it's not already playing)
.setCarry
scf
@@ -1948,13 +1967,13 @@ 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
; function to run the current map's script
-RunMapScript:: ; 101b (0:101b)
+RunMapScript::
push hl
push de
push bc
@@ -1968,9 +1987,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
@@ -1980,24 +1999,24 @@ RunMapScript:: ; 101b (0:101b)
.return
ret
-LoadWalkingPlayerSpriteGraphics:: ; 104d (0:104d)
- ld de,RedSprite ; $4180
+LoadWalkingPlayerSpriteGraphics::
+ ld de,RedSprite
ld hl,vNPCSprites
jr LoadPlayerSpriteGraphicsCommon
-LoadSurfingPlayerSpriteGraphics:: ; 1055 (0:1055)
+LoadSurfingPlayerSpriteGraphics::
ld de,SeelSprite
ld hl,vNPCSprites
jr LoadPlayerSpriteGraphicsCommon
-LoadBikePlayerSpriteGraphics:: ; 105d (0:105d)
+LoadBikePlayerSpriteGraphics::
ld de,RedCyclingSprite
ld hl,vNPCSprites
-LoadPlayerSpriteGraphicsCommon:: ; 1063 (0:1063)
+LoadPlayerSpriteGraphicsCommon::
push de
push hl
- ld bc,(BANK(RedSprite) << 8) + $0c
+ lb bc, BANK(RedSprite), $0c
call CopyVideoData
pop hl
pop de
@@ -2008,25 +2027,25 @@ LoadPlayerSpriteGraphicsCommon:: ; 1063 (0:1063)
inc d
.noCarry
set 3,h
- ld bc,$050c
+ lb bc, BANK(RedSprite), $0c
jp CopyVideoData
; function to load data from the map header
-LoadMapHeader:: ; 107c (0:107c)
+LoadMapHeader::
callba MarkTownVisitedAndLoadMissableObjects
- ld a,[W_CURMAPTILESET]
- ld [wd119],a
- ld a,[W_CURMAP]
+ ld a,[wCurMapTileset]
+ ld [wUnusedD119],a
+ ld a,[wCurMap]
call SwitchToMapRomBank
- ld a,[W_CURMAPTILESET]
+ ld a,[wCurMapTileset]
ld b,a
res 7,a
- ld [W_CURMAPTILESET],a
- ld [$ff8b],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
@@ -2040,7 +2059,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]
@@ -2050,46 +2069,46 @@ 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]
- 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
@@ -2109,16 +2128,16 @@ LoadMapHeader:: ; 107c (0:107c)
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
ld c,a
- ld de,wd4d1 ; base address of sign text IDs
+ ld de,wSignTextIDs
ld a,d
- ld [$ff95],a
+ ld [hSignCoordPointer],a
ld a,e
- ld [$ff96],a
- ld de,wd4b1 ; base address of sign coordinates
+ ld [hSignCoordPointer + 1],a
+ ld de,wSignCoords
.signLoop
ld a,[hli]
ld [de],a
@@ -2127,17 +2146,17 @@ LoadMapHeader:: ; 107c (0:107c)
ld [de],a
inc de
push de
- ld a,[$ff95]
+ ld a,[hSignCoordPointer]
ld d,a
- ld a,[$ff96]
+ ld a,[hSignCoordPointer + 1]
ld e,a
ld a,[hli]
ld [de],a
inc de
ld a,d
- ld [$ff95],a
+ ld [hSignCoordPointer],a
ld a,e
- ld [$ff96],a
+ ld [hSignCoordPointer + 1],a
pop de
dec c
jr nz,.signLoop
@@ -2146,7 +2165,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
@@ -2170,7 +2189,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
@@ -2191,24 +2210,24 @@ LoadMapHeader:: ; 107c (0:107c)
ld a,[hli]
ld [de],a ; store movement byte 1 at C2X6
ld a,[hli]
- ld [$ff8d],a ; save movement byte 2
+ ld [hLoadSpriteTemp1],a ; save movement byte 2
ld a,[hli]
- ld [$ff8e],a ; save text ID and flags byte
+ ld [hLoadSpriteTemp2],a ; save text ID and flags byte
push bc
push hl
ld b,$00
- ld hl,W_MAPSPRITEDATA
+ ld hl,wMapSpriteData
add hl,bc
- ld a,[$ff8d]
+ ld a,[hLoadSpriteTemp1]
ld [hli],a ; store movement byte 2 in byte 0 of sprite entry
- ld a,[$ff8e]
+ ld a,[hLoadSpriteTemp2]
ld [hl],a ; this appears pointless, since the value is overwritten immediately after
- ld a,[$ff8e]
- ld [$ff8d],a
+ ld a,[hLoadSpriteTemp2]
+ ld [hLoadSpriteTemp1],a
and a,$3f
ld [hl],a ; store text ID in byte 1 of sprite entry
pop hl
- ld a,[$ff8d]
+ ld a,[hLoadSpriteTemp1]
bit 6,a
jr nz,.trainerSprite
bit 7,a
@@ -2216,25 +2235,25 @@ LoadMapHeader:: ; 107c (0:107c)
jr .regularSprite
.trainerSprite
ld a,[hli]
- ld [$ff8d],a ; save trainer class
+ ld [hLoadSpriteTemp1],a ; save trainer class
ld a,[hli]
- ld [$ff8e],a ; save trainer number (within class)
+ ld [hLoadSpriteTemp2],a ; save trainer number (within class)
push hl
- ld hl,W_MAPSPRITEEXTRADATA
+ ld hl,wMapSpriteExtraData
add hl,bc
- ld a,[$ff8d]
+ ld a,[hLoadSpriteTemp1]
ld [hli],a ; store trainer class in byte 0 of the entry
- ld a,[$ff8e]
+ ld a,[hLoadSpriteTemp2]
ld [hl],a ; store trainer number in byte 1 of the entry
pop hl
jr .nextSprite
.itemBallSprite
ld a,[hli]
- ld [$ff8d],a ; save item number
+ ld [hLoadSpriteTemp1],a ; save item number
push hl
- ld hl,W_MAPSPRITEEXTRADATA
+ ld hl,wMapSpriteExtraData
add hl,bc
- ld a,[$ff8d]
+ ld a,[hLoadSpriteTemp1]
ld [hli],a ; store item number in byte 0 of the entry
xor a
ld [hl],a ; zero byte 1, since it is not used
@@ -2242,7 +2261,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
@@ -2263,35 +2282,35 @@ 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 [wd524],a ; store map height in 2x2 tile blocks
- ld a,[W_CURMAPWIDTH] ; map width in 4x4 tile blocks
+ ld [wCurrentMapHeight2],a ; store map height in 2x2 tile blocks
+ ld a,[wCurMapWidth] ; map width in 4x4 tile blocks
add a ; double it
- ld [wd525],a ; map width in 2x2 tile blocks
- ld a,[W_CURMAP]
+ ld [wCurrentMapWidth2],a ; map width in 2x2 tile blocks
+ ld a,[wCurMap]
ld c,a
ld b,$00
ld a,[H_LOADEDROMBANK]
push af
ld a, BANK(MapSongBanks)
ld [H_LOADEDROMBANK],a
- ld [$2000],a
+ ld [MBC1RomBank],a
ld hl, MapSongBanks
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 [$2000],a
+ ld [MBC1RomBank],a
ret
; function to copy map connection data from ROM to WRAM
; Input: hl = source, de = destination
-CopyMapConnectionHeader:: ; 1238 (0:1238)
+CopyMapConnectionHeader::
ld c,$0b
.loop
ld a,[hli]
@@ -2302,7 +2321,7 @@ CopyMapConnectionHeader:: ; 1238 (0:1238)
ret
; function to load map data
-LoadMapData:: ; 1241 (0:1241)
+LoadMapData::
ld a,[H_LOADEDROMBANK]
push af
call DisableLCD
@@ -2313,9 +2332,9 @@ LoadMapData:: ; 1241 (0:1241)
ld [hSCY],a
ld [hSCX],a
ld [wWalkCounter],a
- ld [wd119],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
@@ -2323,7 +2342,7 @@ LoadMapData:: ; 1241 (0:1241)
call LoadTilesetTilePatternData
call LoadCurrentMapView
; copy current map view to VRAM
- ld hl,wTileMap
+ coord hl, 0, 0
ld de,vBGMap0
ld b,18
.vramCopyLoop
@@ -2345,26 +2364,26 @@ 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
- ld [$2000],a
+ ld [MBC1RomBank],a
ret
; function to switch to the ROM bank that a map is stored in
; Input: a = map number
-SwitchToMapRomBank:: ; 12bc (0:12bc)
+SwitchToMapRomBank::
push hl
push bc
ld c,a
@@ -2378,26 +2397,26 @@ SwitchToMapRomBank:: ; 12bc (0:12bc)
call BankswitchBack
ld a,[$ffe8]
ld [H_LOADEDROMBANK],a
- ld [$2000],a ; switch to map ROM bank
+ ld [MBC1RomBank],a ; switch to map ROM bank
pop bc
pop hl
ret
-IgnoreInputForHalfSecond: ; 12da (0:12da)
+IgnoreInputForHalfSecond:
ld a, 30
ld [wIgnoreInputCounter], a
ld hl, wd730
ld a, [hl]
- or $26
+ or %00100110
ld [hl], a ; set ignore input bit
ret
-ResetUsingStrengthOutOfBattleBit: ; 12e7 (0:12e7)
+ResetUsingStrengthOutOfBattleBit:
ld hl, wd728
res 0, [hl]
ret
-ForceBikeOrSurf:: ; 12ed (0:12ed)
+ForceBikeOrSurf::
ld b, BANK(RedSprite)
ld hl, LoadPlayerSpriteGraphics
call Bankswitch