shithub: pokered

Download patch

ref: 1d86932cc9c38815434409f07d14c2bfe4e7a836
parent: e607199397cb36565f61703a58d99efdc21891c5
author: YamaArashi <shadow962@live.com>
date: Sun Jul 19 13:52:26 EDT 2015

naming

--- a/constants/misc_constants.asm
+++ b/constants/misc_constants.asm
@@ -121,6 +121,18 @@
 DAYCARE_DATA      EQU 3
 BATTLE_MON_DATA   EQU 4
 
+; player direction constants
+
+PLAYER_DIR_BIT_RIGHT EQU 0
+PLAYER_DIR_BIT_LEFT  EQU 1
+PLAYER_DIR_BIT_DOWN  EQU 2
+PLAYER_DIR_BIT_UP    EQU 3
+
+PLAYER_DIR_RIGHT EQU (1 << PLAYER_DIR_BIT_RIGHT)
+PLAYER_DIR_LEFT  EQU (1 << PLAYER_DIR_BIT_LEFT)
+PLAYER_DIR_DOWN  EQU (1 << PLAYER_DIR_BIT_DOWN)
+PLAYER_DIR_UP    EQU (1 << PLAYER_DIR_BIT_UP)
+
 ; serial
 
 ESTABLISH_CONNECTION_WITH_INTERNAL_CLOCK EQU $01
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -6296,7 +6296,7 @@
 	predef WriteMonMoves ; get moves based on current level
 .loadMovePPs
 	ld hl, wEnemyMonMoves
-	ld de, wEnemyMonSpecial + 1
+	ld de, wEnemyMonPP - 1
 	predef LoadMovePPs
 	ld hl, W_MONHBASESTATS
 	ld de, wEnemyMonBaseStats
@@ -6957,7 +6957,7 @@
 	ld [wLetterPrintingDelayFlags], a
 	pop af
 	ld [wMapPalOffset], a
-	ld a, [wd0d4]
+	ld a, [wSavedTilesetType]
 	ld [hTilesetType], a
 	scf
 	ret
--- a/engine/battle/init_battle_variables.asm
+++ b/engine/battle/init_battle_variables.asm
@@ -1,6 +1,6 @@
 InitBattleVariables: ; 525af (14:65af)
 	ld a, [hTilesetType]
-	ld [wd0d4], a
+	ld [wSavedTilesetType], a
 	xor a
 	ld [wActionResultOrTookBattleTurn], a
 	ld [wBattleResult], a
--- a/engine/hidden_object_functions7.asm
+++ b/engine/hidden_object_functions7.asm
@@ -78,7 +78,7 @@
 	ld [H_DOWNARROWBLINKCNT2], a
 	call DisplayTextID
 	xor a
-	ld [wd528], a
+	ld [wPlayerMovingDirection], a
 	ld a, SAFARI_ZONE_ENTRANCE
 	ld [H_DOWNARROWBLINKCNT1], a
 	ld a, $3
--- a/engine/items/items.asm
+++ b/engine/items/items.asm
@@ -591,14 +591,14 @@
 	jp LoadWalkingPlayerSpriteGraphics
 ; uses a simulated button press to make the player move forward
 .makePlayerMoveForward
-	ld a,[wd52a] ; direction the player is going
-	bit 3,a
+	ld a,[wPlayerDirection] ; direction the player is going
+	bit PLAYER_DIR_BIT_UP,a
 	ld b,D_UP
 	jr nz,.storeSimulatedButtonPress
-	bit 2,a
+	bit PLAYER_DIR_BIT_DOWN,a
 	ld b,D_DOWN
 	jr nz,.storeSimulatedButtonPress
-	bit 1,a
+	bit PLAYER_DIR_BIT_LEFT,a
 	ld b,D_LEFT
 	jr nz,.storeSimulatedButtonPress
 	ld b,D_RIGHT
--- a/engine/menu/main_menu.asm
+++ b/engine/menu/main_menu.asm
@@ -107,8 +107,8 @@
 .pressedA
 	call GBPalWhiteOutWithDelay3
 	call ClearScreen
-	ld a,4
-	ld [wd52a],a
+	ld a,PLAYER_DIR_DOWN
+	ld [wPlayerDirection],a
 	ld c,10
 	call DelayFrames
 	ld a,[wNumHoFTeams]
--- a/engine/overworld/movement.asm
+++ b/engine/overworld/movement.asm
@@ -25,24 +25,24 @@
 	ld a, [wWalkCounter]
 	and a
 	jr nz, .moving
-	ld a, [wd528]
+	ld a, [wPlayerMovingDirection]
 ; check if down
-	bit 2, a
+	bit PLAYER_DIR_BIT_DOWN, a
 	jr z, .checkIfUp
 	xor a ; ld a, SPRITE_FACING_DOWN
 	jr .next
 .checkIfUp
-	bit 3, a
+	bit PLAYER_DIR_BIT_UP, a
 	jr z, .checkIfLeft
 	ld a, SPRITE_FACING_UP
 	jr .next
 .checkIfLeft
-	bit 1, a
+	bit PLAYER_DIR_BIT_LEFT, a
 	jr z, .checkIfRight
 	ld a, SPRITE_FACING_LEFT
 	jr .next
 .checkIfRight
-	bit 0, a
+	bit PLAYER_DIR_BIT_RIGHT, a
 	jr z, .notMoving
 	ld a, SPRITE_FACING_RIGHT
 	jr .next
@@ -405,23 +405,23 @@
 	bit 5, a
 	jr nz, notYetMoving
 	res 7, [hl]
-	ld a, [wd52a]
-	bit 3, a
+	ld a, [wPlayerDirection]
+	bit PLAYER_DIR_BIT_UP, a
 	jr z, .notFacingDown
-	ld c, $0                ; make sprite face down
+	ld c, SPRITE_FACING_DOWN
 	jr .facingDirectionDetermined
 .notFacingDown
-	bit 2, a
+	bit PLAYER_DIR_BIT_DOWN, a
 	jr z, .notFacingUp
-	ld c, $4                ; make sprite face up
+	ld c, SPRITE_FACING_UP
 	jr .facingDirectionDetermined
 .notFacingUp
-	bit 1, a
+	bit PLAYER_DIR_BIT_LEFT, a
 	jr z, .notFacingRight
-	ld c, $c                ; make sprite face right
+	ld c, SPRITE_FACING_RIGHT
 	jr .facingDirectionDetermined
 .notFacingRight
-	ld c, $8                ; make sprite face left
+	ld c, SPRITE_FACING_LEFT
 .facingDirectionDetermined
 	ld a, [H_CURRENTSPRITEOFFSET]
 	add $9
--- a/home/overworld.asm
+++ b/home/overworld.asm
@@ -134,43 +134,43 @@
 	call UpdateSprites
 	ld a,$01
 	ld [wcc4b],a
-	ld a,[wd528] ; the direction that was pressed last time
+	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 ; PLAYER_DIR_RIGHT
+	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
@@ -177,9 +177,9 @@
 	ld a,[wcc4b]
 	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
@@ -187,28 +187,28 @@
 ; also, it does a seemingly pointless loop afterwards
 	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
+	ld a,PLAYER_DIR_LEFT
+	ld [wPlayerMovingDirection],a
 	jr .oddLoop
 .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
+	ld a,PLAYER_DIR_RIGHT
+	ld [wPlayerMovingDirection],a
 	jr .oddLoop
 .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
+	ld a,PLAYER_DIR_DOWN
+	ld [wPlayerMovingDirection],a
 	jr .oddLoop
 .notRightToLeft
-	cp a,$21 ; change dir from left to right
+	cp a,(PLAYER_DIR_LEFT << 4) | PLAYER_DIR_RIGHT ; change dir from left to right
 	jr nz,.oddLoop
-	ld a,$08
-	ld [wd528],a
+	ld a,PLAYER_DIR_UP
+	ld [wPlayerMovingDirection],a
 .oddLoop
 	ld hl,wFlags_0xcd60
 	set 2,[hl]
@@ -215,14 +215,14 @@
 	ld hl,wcc4b
 	dec [hl]
 	jr nz,.oddLoop
-	ld a,[wd52a]
-	ld [wd528],a
+	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
@@ -566,7 +566,7 @@
 	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]
@@ -628,7 +628,7 @@
 	jp .loadNewMap
 .checkSouthMap
 	ld b,a
-	ld a,[wd524]
+	ld a,[wCurrentMapHeight2]
 	cp b
 	jr nz,.didNotEnterConnectedMap
 	ld a,[W_MAPCONN2PTR]
@@ -864,7 +864,7 @@
 LoadTileBlockMap:: ; 09fc (0:09fc)
 ; 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
@@ -1057,15 +1057,15 @@
 IsSpriteOrSignInFrontOfPlayer:: ; 0b23 (0:0b23)
 	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
@@ -1081,8 +1081,8 @@
 ; 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]
@@ -1097,7 +1097,7 @@
 .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 b,3
 	ld d,$20 ; talking range in pixels (long range)
 .counterTilesLoop
 	ld a,[hli]
@@ -1111,7 +1111,7 @@
 IsSpriteInFrontOfPlayer:: ; 0b6b (0:0b6b)
 	ld d,$10 ; talking range in pixels (normal range)
 IsSpriteInFrontOfPlayer2:: ; 0b6d (0:0b6d)
-	ld bc,$3c40 ; Y and X position of player sprite
+	lb bc, $3c, $40 ; Y and X position of player sprite
 	ld a,[wSpriteStateData1 + 9] ; direction the player is facing
 .checkIfPlayerFacingUp
 	cp SPRITE_FACING_UP
@@ -1120,7 +1120,7 @@
 	ld a,b
 	sub d
 	ld b,a
-	ld a,$08
+	ld a,PLAYER_DIR_UP
 	jr .doneCheckingDirection
 .checkIfPlayerFacingDown
 	cp SPRITE_FACING_DOWN
@@ -1129,7 +1129,7 @@
 	ld a,b
 	add d
 	ld b,a
-	ld a,$04
+	ld a,PLAYER_DIR_DOWN
 	jr .doneCheckingDirection
 .checkIfPlayerFacingRight
 	cp SPRITE_FACING_RIGHT
@@ -1138,7 +1138,7 @@
 	ld a,c
 	add d
 	ld c,a
-	ld a,$01
+	ld a,PLAYER_DIR_RIGHT
 	jr .doneCheckingDirection
 .playerFacingLeft
 ; facing left
@@ -1145,9 +1145,9 @@
 	ld a,c
 	sub d
 	ld c,a
-	ld a,$02
+	ld a,PLAYER_DIR_LEFT
 .doneCheckingDirection
-	ld [wd52a],a
+	ld [wPlayerDirection],a
 	ld a,[W_NUMSPRITES] ; number of sprites
 	and a
 	ret z
@@ -1202,7 +1202,7 @@
 	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
@@ -1893,7 +1893,7 @@
 	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
@@ -2073,17 +2073,17 @@
 	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
@@ -2103,16 +2103,16 @@
 	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
@@ -2121,17 +2121,17 @@
 	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
@@ -2259,10 +2259,10 @@
 	pop hl ; restore hl from before going to the warp/sign/sprite data (this value was saved for seemingly no purpose)
 	ld a,[W_CURMAPHEIGHT] ; map height in 4x4 tile blocks
 	add a ; double it
-	ld [wd524],a ; store map height in 2x2 tile blocks
+	ld [wCurrentMapHeight2],a ; store map height in 2x2 tile blocks
 	ld a,[W_CURMAPWIDTH] ; map width in 4x4 tile blocks
 	add a ; double it
-	ld [wd525],a ; map width in 2x2 tile blocks
+	ld [wCurrentMapWidth2],a ; map width in 2x2 tile blocks
 	ld a,[W_CURMAP]
 	ld c,a
 	ld b,$00
--- a/hram.asm
+++ b/hram.asm
@@ -82,6 +82,9 @@
 
 hSpritePriority EQU $FF94
 
+; 2 bytes
+hSignCoordPointer EQU $FF95
+
 hNPCMovementDirections2Index EQU $FF95
 
 ; CalcPositionOfPlayerRelativeToNPC
--- a/scripts/ceruleancity.asm
+++ b/scripts/ceruleancity.asm
@@ -44,15 +44,15 @@
 	jr nc, .asm_194f7
 	ld a, [wCoordIndex]
 	cp $1
-	ld a, $8
+	ld a, PLAYER_DIR_UP
 	ld b, SPRITE_FACING_DOWN
 	jr nz, .asm_194e6
-	ld a, $4
+	ld a, PLAYER_DIR_DOWN
 	ld b, SPRITE_FACING_UP
 .asm_194e6
-	ld [wd528], a
+	ld [wPlayerMovingDirection], a
 	ld a, b
-	ld [wSpriteStateData1 + $29], a
+	ld [wSpriteStateData1 + 2 * $10 + $9], a
 	call Delay3
 	ld a, $2
 	ld [hSpriteIndexOrTextID], a
--- a/scripts/cinnabargym.asm
+++ b/scripts/cinnabargym.asm
@@ -54,14 +54,14 @@
 	ld [H_SPRITEINDEX], a
 	cp $4
 	jr nz, .asm_757c3
-	ld a, $4
-	ld [wd528], a
+	ld a, PLAYER_DIR_DOWN
+	ld [wPlayerMovingDirection], a
 	ld de, MovementData_757d7
 	jr .asm_757cb
 .asm_757c3
 	ld de, MovementData_757da
-	ld a, $1
-	ld [wd528], a
+	ld a, PLAYER_DIR_RIGHT
+	ld [wPlayerMovingDirection], a
 .asm_757cb
 	call MoveSprite
 	ld a, $1
--- a/scripts/cinnabarisland.asm
+++ b/scripts/cinnabarisland.asm
@@ -24,8 +24,8 @@
 	ld a, [W_XCOORD]
 	cp $12
 	ret nz
-	ld a, $8
-	ld [wd528], a
+	ld a, PLAYER_DIR_UP
+	ld [wPlayerMovingDirection], a
 	ld a, $8
 	ld [hSpriteIndexOrTextID], a
 	call DisplayTextID
--- a/scripts/fightingdojo.asm
+++ b/scripts/fightingdojo.asm
@@ -42,9 +42,9 @@
 	ret nz
 	ld a, $1
 	ld [wcf0d], a
+	ld a, PLAYER_DIR_RIGHT
+	ld [wPlayerMovingDirection], a
 	ld a, $1
-	ld [wd528], a
-	ld a, $1
 	ld [H_SPRITEINDEX], a
 	ld a, SPRITE_FACING_LEFT
 	ld [hSpriteFacingDirection], a
@@ -61,8 +61,8 @@
 	ld a, [wcf0d]
 	and a
 	jr z, .asm_5cde4
-	ld a, $1
-	ld [wd528], a
+	ld a, PLAYER_DIR_RIGHT
+	ld [wPlayerMovingDirection], a
 	ld a, $1
 	ld [H_SPRITEINDEX], a
 	ld a, SPRITE_FACING_LEFT
--- a/scripts/gary.asm
+++ b/scripts/gary.asm
@@ -139,8 +139,8 @@
 	ld a, [wd730]
 	bit 0, a
 	ret nz
-	ld a, $2
-	ld [wd528], a
+	ld a, PLAYER_DIR_LEFT
+	ld [wPlayerMovingDirection], a
 	ld a, $1
 	ld [H_SPRITEINDEX], a
 	ld a, SPRITE_FACING_LEFT
--- a/scripts/halloffameroom.asm
+++ b/scripts/halloffameroom.asm
@@ -80,19 +80,19 @@
 	ld a, [wSimulatedJoypadStatesIndex]
 	and a
 	ret nz
+	ld a, PLAYER_DIR_RIGHT
+	ld [wPlayerMovingDirection], a
 	ld a, $1
-	ld [wd528], a
-	ld a, $1
 	ld [H_SPRITEINDEX], a
 	call SetSpriteMovementBytesToFF
-	ld a, $8
+	ld a, SPRITE_FACING_LEFT
 	ld [hSpriteFacingDirection], a
 	call SetSpriteFacingDirectionAndDelay
 	call Delay3
 	xor a
 	ld [wJoyIgnore], a
-	inc a
-	ld [wd528], a
+	inc a ; PLAYER_DIR_RIGHT
+	ld [wPlayerMovingDirection], a
 	ld a, $1
 	ld [hSpriteIndexOrTextID], a
 	call DisplayTextID
--- a/scripts/oakslab.asm
+++ b/scripts/oakslab.asm
@@ -178,8 +178,8 @@
 	ld a, D_UP
 	ld [wSimulatedJoypadStatesEnd], a
 	call StartSimulatingJoypadStates
-	ld a, $8
-	ld [wd528], a
+	ld a, PLAYER_DIR_UP
+	ld [wPlayerMovingDirection], a
 
 	ld a, $7
 	ld [W_OAKSLABCURSCRIPT], a
@@ -354,8 +354,8 @@
 	xor a ; SPRITE_FACING_DOWN
 	ld [hSpriteFacingDirection], a
 	call SetSpriteFacingDirectionAndDelay
-	ld a, $8
-	ld [wd528], a
+	ld a, PLAYER_DIR_UP
+	ld [wPlayerMovingDirection], a
 	ld c, BANK(Music_MeetRival)
 	ld a, MUSIC_MEET_RIVAL
 	call PlayMusic
@@ -414,8 +414,8 @@
 	set 7, [hl]
 	xor a
 	ld [wJoyIgnore], a
-	ld a, $8
-	ld [wd528], a
+	ld a, PLAYER_DIR_UP
+	ld [wPlayerMovingDirection], a
 	ld a, $c
 	ld [W_OAKSLABCURSCRIPT], a
 	ret
@@ -423,8 +423,8 @@
 OaksLabScript12: ; 1ce03 (7:4e03)
 	ld a, $f0
 	ld [wJoyIgnore], a
-	ld a, $8
-	ld [wd528], a
+	ld a, PLAYER_DIR_UP
+	ld [wPlayerMovingDirection], a
 	call UpdateSprites
 	ld a, $1
 	ld [wSpriteIndex], a
--- a/scripts/pallettown.asm
+++ b/scripts/pallettown.asm
@@ -28,8 +28,8 @@
 	ret nz
 	xor a
 	ld [hJoyHeld],a
-	ld a,4
-	ld [wd528],a
+	ld a,PLAYER_DIR_DOWN
+	ld [wPlayerMovingDirection],a
 	ld a,$FF
 	call PlaySound ; stop music
 	ld a, BANK(Music_MeetProfOak)
@@ -190,8 +190,8 @@
 	ld [wEmotionBubbleSpriteIndex],a ; player's sprite
 	ld [wWhichEmotionBubble],a ; EXCLAMATION_BUBBLE
 	predef EmotionBubble
-	ld a,4
-	ld [wd528],a
+	ld a,PLAYER_DIR_DOWN
+	ld [wPlayerMovingDirection],a
 	jp TextScriptEnd
 
 OakWalksUpText: ; 18fce (6:4fce)
--- a/scripts/pokemontower2.asm
+++ b/scripts/pokemontower2.asm
@@ -33,15 +33,15 @@
 	res 6, [hl]
 	ld a, [wCoordIndex]
 	cp $1
-	ld a, $8
+	ld a, PLAYER_DIR_UP
 	ld b, SPRITE_FACING_DOWN
 	jr nz, .asm_60544
 	ld hl, wd764
 	set 6, [hl]
-	ld a, $2
+	ld a, PLAYER_DIR_LEFT
 	ld b, SPRITE_FACING_RIGHT
 .asm_60544
-	ld [wd528], a
+	ld [wPlayerMovingDirection], a
 	ld a, $1
 	ld [H_SPRITEINDEX], a
 	ld a, b
--- a/scripts/redshouse2f.asm
+++ b/scripts/redshouse2f.asm
@@ -11,8 +11,8 @@
 RedsHouse2FScript0: ; 5c0c0 (17:40c0)
 	xor a
 	ld [hJoyHeld],a
-	ld a,8
-	ld [wd528],a
+	ld a,PLAYER_DIR_UP
+	ld [wPlayerMovingDirection],a
 	ld a,1
 	ld [W_REDSHOUSE2CURSCRIPT],a
 	ret
--- a/scripts/route22.asm
+++ b/scripts/route22.asm
@@ -67,8 +67,8 @@
 	ld [hJoyHeld], a
 	ld a, $f0
 	ld [wJoyIgnore], a
-	ld a, $2
-	ld [wd528], a
+	ld a, PLAYER_DIR_LEFT
+	ld [wPlayerMovingDirection], a
 	ld a, [wd7eb]
 	bit 0, a ; is this the rival battle at the beginning of the game?
 	jr nz, .firstRivalBattle
@@ -111,8 +111,8 @@
 	ld a, [wcf0d]
 	cp $1
 	jr nz, .asm_50f78
-	ld a, $4
-	ld [wd528], a
+	ld a, PLAYER_DIR_DOWN
+	ld [wPlayerMovingDirection], a
 	ld a, SPRITE_FACING_UP
 	jr .asm_50f7a
 .asm_50f78
@@ -270,13 +270,13 @@
 	ld a, [wcf0d]
 	cp $1
 	jr nz, .asm_510a1
-	ld a, $4
-	ld [wd528], a
+	ld a, PLAYER_DIR_DOWN
+	ld [wPlayerMovingDirection], a
 	ld a, SPRITE_FACING_UP
 	jr .asm_510a8
 .asm_510a1
-	ld a, $2
-	ld [wd528], a
+	ld a, PLAYER_DIR_LEFT
+	ld [wPlayerMovingDirection], a
 	ld a, SPRITE_FACING_RIGHT
 .asm_510a8
 	ld [hSpriteFacingDirection], a
@@ -314,13 +314,13 @@
 	ld a, [wcf0d]
 	cp $1
 	jr nz, .asm_510fb
-	ld a, $4
-	ld [wd528], a
+	ld a, PLAYER_DIR_DOWN
+	ld [wPlayerMovingDirection], a
 	ld a, SPRITE_FACING_UP
 	jr .asm_51102
 .asm_510fb
-	ld a, $2
-	ld [wd528], a
+	ld a, PLAYER_DIR_LEFT
+	ld [wPlayerMovingDirection], a
 	ld a, SPRITE_FACING_RIGHT
 .asm_51102
 	ld [hSpriteFacingDirection], a
--- a/scripts/route5gate.asm
+++ b/scripts/route5gate.asm
@@ -22,8 +22,8 @@
 	ld hl, CoordsData_1df8f
 	call ArePlayerCoordsInArray
 	ret nc
-	ld a, $2
-	ld [wd528], a
+	ld a, PLAYER_DIR_LEFT
+	ld [wPlayerMovingDirection], a
 	xor a
 	ld [hJoyHeld], a
 	callba RemoveGuardDrink
--- a/scripts/route6gate.asm
+++ b/scripts/route6gate.asm
@@ -16,8 +16,8 @@
 	ld hl, CoordsData_1e08c
 	call ArePlayerCoordsInArray
 	ret nc
-	ld a, $1
-	ld [wd528], a
+	ld a, PLAYER_DIR_RIGHT
+	ld [wPlayerMovingDirection], a
 	xor a
 	ld [hJoyHeld], a
 	callba RemoveGuardDrink
--- a/scripts/route7gate.asm
+++ b/scripts/route7gate.asm
@@ -28,8 +28,8 @@
 	ld hl, CoordsData_1e167
 	call ArePlayerCoordsInArray
 	ret nc
-	ld a, $8
-	ld [wd528], a
+	ld a, PLAYER_DIR_UP
+	ld [wPlayerMovingDirection], a
 	xor a
 	ld [hJoyHeld], a
 	callba RemoveGuardDrink
--- a/scripts/route8gate.asm
+++ b/scripts/route8gate.asm
@@ -27,8 +27,8 @@
 	ld hl, CoordsData_1e22c
 	call ArePlayerCoordsInArray
 	ret nc
-	ld a, $2
-	ld [wd528], a
+	ld a, PLAYER_DIR_LEFT
+	ld [wPlayerMovingDirection], a
 	xor a
 	ld [hJoyHeld], a
 	callba RemoveGuardDrink
--- a/scripts/safarizoneentrance.asm
+++ b/scripts/safarizoneentrance.asm
@@ -72,8 +72,8 @@
 	ret
 
 .SafariZoneEntranceScript5
-	ld a, $4
-	ld [wd528], a
+	ld a, PLAYER_DIR_DOWN
+	ld [wPlayerMovingDirection], a
 	ld hl, wd790
 	bit 6, [hl]
 	res 6, [hl]
--- a/scripts/silphco11.asm
+++ b/scripts/silphco11.asm
@@ -199,7 +199,7 @@
 	db $FF
 
 SilphCo11Script_6221a: ; 6221a (18:621a)
-	ld [wd528], a
+	ld [wPlayerMovingDirection], a
 	ld a, $3
 	ld [H_SPRITEINDEX], a
 	ld a, b
@@ -213,11 +213,11 @@
 	ld a, [wcf0d]
 	cp $1
 	jr z, .asm_6223c
-	ld a, $2
+	ld a, PLAYER_DIR_LEFT
 	ld b, SPRITE_FACING_RIGHT
 	jr .asm_62240
 .asm_6223c
-	ld a, $8
+	ld a, PLAYER_DIR_UP
 	ld b, SPRITE_FACING_DOWN
 .asm_62240
 	call SilphCo11Script_6221a
@@ -247,11 +247,11 @@
 	ld a, [wcf0d]
 	cp $1
 	jr z, .asm_62284
-	ld a, $2
+	ld a, PLAYER_DIR_LEFT
 	ld b, SPRITE_FACING_RIGHT
 	jr .asm_62288
 .asm_62284
-	ld a, $8
+	ld a, PLAYER_DIR_UP
 	ld b, SPRITE_FACING_DOWN
 .asm_62288
 	call SilphCo11Script_6221a
--- a/scripts/silphco7.asm
+++ b/scripts/silphco7.asm
@@ -127,8 +127,8 @@
 	ld [hJoyHeld], a
 	ld a, $f0
 	ld [wJoyIgnore], a
-	ld a, $4
-	ld [wd528], a
+	ld a, PLAYER_DIR_DOWN
+	ld [wPlayerMovingDirection], a
 	ld a, $ff
 	ld [wc0ee], a
 	call PlaySound
@@ -209,8 +209,8 @@
 	ld [wJoyIgnore], a
 	ld hl, wd82f
 	set 0, [hl]
-	ld a, $4
-	ld [wd528], a
+	ld a, PLAYER_DIR_DOWN
+	ld [wPlayerMovingDirection], a
 	ld a, $9
 	ld [H_SPRITEINDEX], a
 	ld a, SPRITE_FACING_UP
--- a/scripts/ssanne2.asm
+++ b/scripts/ssanne2.asm
@@ -74,8 +74,8 @@
 	ld a, [W_XCOORD]
 	cp $25
 	jr nz, .asm_61426
-	ld a, $2
-	ld [wd528], a
+	ld a, PLAYER_DIR_LEFT
+	ld [wPlayerMovingDirection], a
 	ld a, SPRITE_FACING_RIGHT
 	jr .asm_61427
 .asm_61426
--- a/wram.asm
+++ b/wram.asm
@@ -1701,8 +1701,12 @@
 	flag_array 50 + 5
 	ds 1
 
-wd0d4:: ds 3 ; temp storage for hTilesetType
+wSavedTilesetType:: ; d0d4
+; saved at the start of a battle and then written back at the end of the battle
+	ds 1
 
+	ds 2
+
 W_MONHPADDING:: ; d0d7
 
 
@@ -2066,10 +2070,15 @@
 ; sprite set ID for the current map
 	ds 1
 
-wd3a9:: ds 1 ; used when getting the object data pointer
-wd3aa:: ds 3 ; second part of the pointer
-wd3ad:: ds 1 ; used as the beginning value for copying warp data
+wObjectDataPointerTemp:: ; d3a9
+	ds 2
 
+	ds 2
+
+wMapBackgroundTile:: ; d3ad
+; the tile shown outside the boundaries of the map
+	ds 1
+
 wNumberOfWarps:: ; d3ae
 ; number of warps in current map
 	ds 1
@@ -2084,10 +2093,18 @@
 
 	ds 128
 
-wd4b0:: ds 1 ; number of signs on the map
-wd4b1:: ds 32 ; starting address for sign coords
-wd4d1:: ds 16 ; starting address for sign text IDs
+wNumSigns:: ; d4b0
+; number of signs in the current map (up to 16)
+	ds 1
 
+wSignCoords:: ; d4b1
+; 2 bytes each
+; Y, X
+	ds 32
+
+wSignTextIDs:: ; d4d1
+	ds 16
+
 W_NUMSPRITES:: ; d4e1
 ; number of sprites on the current map
 	ds 1
@@ -2107,16 +2124,35 @@
 ; two bytes per sprite (trainer class/item ID, trainer set ID)
 	ds 32
 
-wd524:: ds 1 ; map height in 2x2 metatiles, also used with checking connections
-wd525:: ds 1 ; map width in 2x2 metatiles, also used with checking connections
+wCurrentMapHeight2:: ; d524
+; map height in 2x2 meta-tiles
+	ds 1
 
+wCurrentMapWidth2:: ; d525
+; map width in 2x2 meta-tiles
+	ds 1
+
 wMapViewVRAMPointer:: ; d526
 ; the address of the upper left corner of the visible portion of the BG tile map in VRAM
 	ds 2
 
-wd528:: ds 1 ; additional storage for directions
-wd529:: ds 1 ; same case as above, but used differently
-wd52a:: ds 1 ; same case as above
+; In the comments for the player direction variables below, "moving" refers to
+; both walking and changing facing direction without taking a step.
+
+wPlayerMovingDirection:: ; d528
+; if the player is moving, the current direction
+; if the player is not moving, zero
+; map scripts write to this in order to change the player's facing direction
+	ds 1
+
+wPlayerLastStopDirection:: ; d529
+; the direction in which the player was moving before the player last stopped
+	ds 1
+
+wPlayerDirection:: ; d52a
+; if the player is moving, the current direction
+; if the player is not moving, the last the direction in which the player moved
+	ds 1
 
 W_TILESETBANK:: ; d52b
 	ds 1