shithub: pokered

Download patch

ref: 6ef36800b0dcb86100a7c716172015667e60dc99
parent: 35deb771130a9012ee4494b1db097761f2fe2919
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Fri Jul 3 18:11:35 EDT 2020

Replace raw hex values with HRAM constants

To do: turn constants into labels and use ldh

--- a/audio/engine_1.asm
+++ b/audio/engine_1.asm
@@ -925,7 +925,7 @@
 	ld e, [hl]
 	inc hl
 	ld d, [hl]
-	ld hl, $ff30 ; wave pattern RAM
+	ld hl, rWave_0
 	ld b, $f
 	ld a, $0 ; stop hardware channel 3
 	ld [rNR30], a
--- a/audio/engine_2.asm
+++ b/audio/engine_2.asm
@@ -936,7 +936,7 @@
 	ld e, [hl]
 	inc hl
 	ld d, [hl]
-	ld hl, $ff30 ; wave pattern RAM
+	ld hl, rWave_0
 	ld b, $f
 	ld a, $0 ; stop hardware channel 3
 	ld [rNR30], a
--- a/audio/engine_3.asm
+++ b/audio/engine_3.asm
@@ -925,7 +925,7 @@
 	ld e, [hl]
 	inc hl
 	ld d, [hl]
-	ld hl, $ff30 ; wave pattern RAM
+	ld hl, rWave_0
 	ld b, $f
 	ld a, $0 ; stop hardware channel 3
 	ld [rNR30], a
--- a/audio/pokedex_rating_sfx.asm
+++ b/audio/pokedex_rating_sfx.asm
@@ -1,5 +1,5 @@
 PlayPokedexRatingSfx::
-	ld a, [$ffdc]
+	ld a, [hDexRatingNumMonsOwned]
 	ld c, $0
 	ld hl, OwnedMonValues
 .getSfxPointer
--- a/audio/wave_instruments.asm
+++ b/audio/wave_instruments.asm
@@ -13,7 +13,7 @@
 ; these are the definitions for the channel 3 instruments
 ; each instrument definition is made up of 32 points (nibbles) that form
 ; the graph of the wave
-; the current instrument is copied to $FF30
+; the current instrument is copied to rWave_0--rWave_f
 .wave0
 	db $02,$46,$8A,$CE,$FF,$FE,$ED,$DC,$CB,$A9,$87,$65,$44,$33,$22,$11
 
--- a/constants/hardware_constants.asm
+++ b/constants/hardware_constants.asm
@@ -64,6 +64,22 @@
 rNR50       EQU $ff24 ; Channel control / ON-OFF / Volume (R/W)
 rNR51       EQU $ff25 ; Selection of Sound output terminal (R/W)
 rNR52       EQU $ff26 ; Sound on/off
+rWave_0     EQU $ff30
+rWave_1     EQU $ff31
+rWave_2     EQU $ff32
+rWave_3     EQU $ff33
+rWave_4     EQU $ff34
+rWave_5     EQU $ff35
+rWave_6     EQU $ff36
+rWave_7     EQU $ff37
+rWave_8     EQU $ff38
+rWave_9     EQU $ff39
+rWave_a     EQU $ff3a
+rWave_b     EQU $ff3b
+rWave_c     EQU $ff3c
+rWave_d     EQU $ff3d
+rWave_e     EQU $ff3e
+rWave_f     EQU $ff3f
 rLCDC       EQU $ff40 ; LCD Control (R/W)
 rLCDC_ENABLE EQU 7
 rLCDC_ENABLE_MASK EQU 1 << rLCDC_ENABLE
--- a/data/events/hidden_objects.asm
+++ b/data/events/hidden_objects.asm
@@ -224,7 +224,7 @@
 	db $FF
 ViridianPokecenterHiddenObjects:
 	db $04,$00,$08
-	db Bank(PrintBenchGuyText)
+	db BANK(PrintBenchGuyText)
 	dw PrintBenchGuyText
 	db $03,$0d,$04
 	db BANK(OpenPokemonCenterPC)
@@ -234,7 +234,7 @@
 	db $FF
 ViridianSchoolHiddenObjects:
 	db $04,$03,(ViridianSchoolNotebook_id - TextPredefs) / 2 + 1
-	db Bank(PrintNotebookText)
+	db BANK(PrintNotebookText)
 	dw PrintNotebookText
 	db $00,$03,(ViridianSchoolBlackboard_id - TextPredefs) / 2 + 1
 	db BANK(PrintBlackboardLinkCableText)
@@ -262,7 +262,7 @@
 	db $FF
 PewterPokecenterHiddenObjects:
 	db $04,$00,$08
-	db Bank(PrintBenchGuyText)
+	db BANK(PrintBenchGuyText)
 	dw PrintBenchGuyText
 	db $03,$0d,$04
 	db BANK(OpenPokemonCenterPC)
@@ -270,7 +270,7 @@
 	db $FF
 CeruleanPokecenterHiddenObjects:
 	db $04,$00,$08
-	db Bank(PrintBenchGuyText)
+	db BANK(PrintBenchGuyText)
 	dw PrintBenchGuyText
 	db $03,$0d,$04
 	db BANK(OpenPokemonCenterPC)
@@ -286,7 +286,7 @@
 	db $FF
 LavenderPokecenterHiddenObjects:
 	db $04,$00,$08
-	db Bank(PrintBenchGuyText)
+	db BANK(PrintBenchGuyText)
 	dw PrintBenchGuyText
 	db $03,$0d,$04
 	db BANK(OpenPokemonCenterPC)
@@ -297,7 +297,7 @@
 	db BANK(OpenPokemonCenterPC)
 	dw OpenPokemonCenterPC
 	db $04,$00,$04
-	db Bank(PrintBenchGuyText)
+	db BANK(PrintBenchGuyText)
 	dw PrintBenchGuyText
 	db $FF
 VermilionGymHiddenObjects:
@@ -345,7 +345,7 @@
 	db $FF
 CeladonPokecenterHiddenObjects:
 	db $04,$00,$08
-	db Bank(PrintBenchGuyText)
+	db BANK(PrintBenchGuyText)
 	dw PrintBenchGuyText
 	db $03,$0d,$04
 	db BANK(OpenPokemonCenterPC)
@@ -460,7 +460,7 @@
 	db BANK(OpenPokemonCenterPC)
 	dw OpenPokemonCenterPC
 	db $04,$00,$08
-	db Bank(PrintBenchGuyText)
+	db BANK(PrintBenchGuyText)
 	dw PrintBenchGuyText
 	db $FF
 FuchsiaPokecenterHiddenObjects:
@@ -468,7 +468,7 @@
 	db BANK(OpenPokemonCenterPC)
 	dw OpenPokemonCenterPC
 	db $04,$00,$04
-	db Bank(PrintBenchGuyText)
+	db BANK(PrintBenchGuyText)
 	dw PrintBenchGuyText
 	db $FF
 FuchsiaGymHiddenObjects:
@@ -481,27 +481,27 @@
 	db $0d,$11,$04
 	dbw BANK(GymStatues),GymStatues
 	db $07,$0f,$01
-	db Bank(PrintCinnabarQuiz)
+	db BANK(PrintCinnabarQuiz)
 	dw PrintCinnabarQuiz
 	db $01,$0a,$12
-	db Bank(PrintCinnabarQuiz)
+	db BANK(PrintCinnabarQuiz)
 	dw PrintCinnabarQuiz
 	db $07,$09,$13
-	db Bank(PrintCinnabarQuiz)
+	db BANK(PrintCinnabarQuiz)
 	dw PrintCinnabarQuiz
 	db $0d,$09,$14
-	db Bank(PrintCinnabarQuiz)
+	db BANK(PrintCinnabarQuiz)
 	dw PrintCinnabarQuiz
 	db $0d,$01,$05
-	db Bank(PrintCinnabarQuiz)
+	db BANK(PrintCinnabarQuiz)
 	dw PrintCinnabarQuiz
 	db $07,$01,$16
-	db Bank(PrintCinnabarQuiz)
+	db BANK(PrintCinnabarQuiz)
 	dw PrintCinnabarQuiz
 	db $FF
 CinnabarPokecenterHiddenObjects:
 	db $04,$00,$04
-	db Bank(PrintBenchGuyText)
+	db BANK(PrintBenchGuyText)
 	dw PrintBenchGuyText
 	db $03,$0d,$04
 	db BANK(OpenPokemonCenterPC)
@@ -513,7 +513,7 @@
 	db $FF
 MtMoonPokecenterHiddenObjects:
 	db $04,$00,$08
-	db Bank(PrintBenchGuyText)
+	db BANK(PrintBenchGuyText)
 	dw PrintBenchGuyText
 	db $03,$0d,$04
 	db BANK(OpenPokemonCenterPC)
@@ -521,7 +521,7 @@
 	db $FF
 RockTunnelPokecenterHiddenObjects:
 	db $04,$00,$08
-	db Bank(PrintBenchGuyText)
+	db BANK(PrintBenchGuyText)
 	dw PrintBenchGuyText
 	db $03,$0d,$04
 	db BANK(OpenPokemonCenterPC)
@@ -589,7 +589,7 @@
 	db $FF
 SaffronPokecenterHiddenObjects:
 	db $04,$00,$04
-	db Bank(PrintBenchGuyText)
+	db BANK(PrintBenchGuyText)
 	dw PrintBenchGuyText
 	db $03,$0d,$04
 	db BANK(OpenPokemonCenterPC)
@@ -704,7 +704,7 @@
 	db $FF
 SafariZoneRestHouse2HiddenObjects:
 	db $04,$00,$08
-	db Bank(PrintBenchGuyText)
+	db BANK(PrintBenchGuyText)
 	dw PrintBenchGuyText
 	db $03,$0d,$04
 	db BANK(OpenPokemonCenterPC)
@@ -712,7 +712,7 @@
 	db $FF
 SafariZoneRestHouse3HiddenObjects:
 	db $04,$00,$08
-	db Bank(PrintBenchGuyText)
+	db BANK(PrintBenchGuyText)
 	dw PrintBenchGuyText
 	db $03,$0d,$04
 	db BANK(OpenPokemonCenterPC)
@@ -720,7 +720,7 @@
 	db $FF
 SafariZoneRestHouse4HiddenObjects:
 	db $04,$00,$08
-	db Bank(PrintBenchGuyText)
+	db BANK(PrintBenchGuyText)
 	dw PrintBenchGuyText
 	db $03,$0d,$04
 	db BANK(OpenPokemonCenterPC)
@@ -750,7 +750,7 @@
 	db BANK(PrintBlackboardLinkCableText)
 	dw PrintBlackboardLinkCableText
 	db $04,$03,(TMNotebook_id - TextPredefs) / 2 + 1
-	db Bank(PrintNotebookText)
+	db BANK(PrintNotebookText)
 	dw PrintNotebookText
 	db $FF
 FightingDojoHiddenObjects:
--- a/data/maps/hide_show_data.asm
+++ b/data/maps/hide_show_data.asm
@@ -2,7 +2,7 @@
 ; objects for each map ($00-$F8)
 
 ; Table of 2-Byte pointers, one pointer per map,
-; goes up to Map_F7, ends with $FFFF.
+; goes up to Map_F7, ends with -1.
 ; points to table listing all missable object in the area
 MapHSPointers:
 	dw MapHS00
@@ -253,7 +253,7 @@
 	dw MapHSXX
 	dw MapHSXX
 	dw MapHSXX
-	dw $FFFF
+	dw -1 ; end
 
 ; Structure:
 ; 3 bytes per object
--- a/data/wild/grass_water.asm
+++ b/data/wild/grass_water.asm
@@ -247,7 +247,7 @@
 	dw NoMons
 	dw NoMons
 	dw NoMons
-	dw $FFFF
+	dw -1 ; end
 
 ; wild pokemon data is divided into two parts.
 ; first part:  pokemon found in grass
--- a/engine/battle/animations.asm
+++ b/engine/battle/animations.asm
@@ -163,7 +163,7 @@
 
 PlayAnimation:
 	xor a
-	ld [$FF8B], a ; it looks like nothing reads this
+	ld [hROMBankTemp], a ; it looks like nothing reads this
 	ld [wSubAnimTransform], a
 	ld a, [wAnimationID] ; get animation number
 	dec a
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -6870,9 +6870,9 @@
 	ld d, a ; de contains pointer to trainer pic
 	ld a, [wLinkState]
 	and a
-	ld a, Bank(TrainerPics) ; this is where all the trainer pics are (not counting Red's)
+	ld a, BANK(TrainerPics) ; this is where all the trainer pics are (not counting Red's)
 	jr z, .loadSprite
-	ld a, Bank(RedPicFront)
+	ld a, BANK(RedPicFront)
 .loadSprite
 	call UncompressSpriteFromDE
 	ld de, vFrontPic
--- a/engine/battle/scale_sprites.asm
+++ b/engine/battle/scale_sprites.asm
@@ -17,7 +17,7 @@
 .columnInnerLoop
 	push bc
 	ld a, [de]
-	ld bc, -(7*8)+1       ; $ffc9, scale lower nybble and seek to previous output column
+	ld bc, -(7*8)+1       ; -$37, scale lower nybble and seek to previous output column
 	call ScalePixelsByTwo
 	ld a, [de]
 	dec de
@@ -32,7 +32,7 @@
 	dec de
 	dec de
 	ld a, b
-	ld bc, -7*8 ; $ffc8, skip one output column (which has already been written along with the current one)
+	ld bc, -7*8 ; -$38, skip one output column (which has already been written along with the current one)
 	add hl, bc
 	ld b, a
 	dec b
--- a/engine/events/cinnabar_lab.asm
+++ b/engine/events/cinnabar_lab.asm
@@ -35,7 +35,7 @@
 	ld e, a
 	add hl, de
 	ld a, [hl]
-	ld [$ffdb], a
+	ld [hItemToRemoveID], a
 	cp DOME_FOSSIL
 	jr z, .choseDomeFossil
 	cp HELIX_FOSSIL
--- a/engine/events/diploma.asm
+++ b/engine/events/diploma.asm
@@ -73,7 +73,7 @@
 ; Unused function that does a calculation involving the length of the player's
 ; name.
 	ld hl, wPlayerName
-	ld bc, $ff00
+	lb bc, $ff, $00
 .loop
 	ld a, [hli]
 	cp "@"
--- a/engine/events/hidden_objects/bookshelves.asm
+++ b/engine/events/hidden_objects/bookshelves.asm
@@ -24,7 +24,7 @@
 	pop af
 	call PrintPredefTextID
 	xor a
-	ld [$ffdb], a
+	ld [hFFDB], a
 	ret
 .nextBookshelfEntry1
 	inc hl
@@ -33,7 +33,7 @@
 	jr .loop
 .noMatch
 	ld a, $ff
-	ld [$ffdb], a
+	ld [hFFDB], a
 	jpba PrintCardKeyText
 
 INCLUDE "data/tilesets/bookshelf_tile_ids.asm"
--- a/engine/events/hidden_objects/cinnabar_gym_quiz.asm
+++ b/engine/events/hidden_objects/cinnabar_gym_quiz.asm
@@ -16,7 +16,7 @@
 	pop af
 	and $f0
 	swap a
-	ld [$ffdc], a
+	ld [hGymGateAnswer], a
 	ld hl, CinnabarGymQuizIntroText
 	call PrintText
 	ld a, [hGymGateIndex]
@@ -77,7 +77,7 @@
 
 CinnabarGymQuiz_1ea92:
 	call YesNoChoice
-	ld a, [$ffdc]
+	ld a, [hGymGateAnswer]
 	ld c, a
 	ld a, [wCurrentMenuItem]
 	cp c
@@ -85,10 +85,10 @@
 	ld hl, wCurrentMapScriptFlags
 	set 5, [hl]
 	ld a, [hGymGateIndex]
-	ld [$ffe0], a
+	ld [hBackupGymGateIndex], a
 	ld hl, CinnabarGymQuizCorrectText
 	call PrintText
-	ld a, [$ffe0]
+	ld a, [hBackupGymGateIndex]
 	AdjustEventBit EVENT_CINNABAR_GYM_GATE0_UNLOCKED, 0
 	ld c, a
 	ld b, FLAG_SET
@@ -122,7 +122,7 @@
 	TX_BLINK
 	TX_ASM
 
-	ld a, [$ffe0]
+	ld a, [hBackupGymGateIndex]
 	AdjustEventBit EVENT_CINNABAR_GYM_GATE0_UNLOCKED, 0
 	ld c, a
 	ld b, FLAG_TEST
@@ -162,7 +162,7 @@
 	ld [wGymGateTileBlock], a
 	push bc
 	ld a, [hGymGateIndex]
-	ld [$ffe0], a
+	ld [hBackupGymGateIndex], a
 	AdjustEventBit EVENT_CINNABAR_GYM_GATE0_UNLOCKED, 0
 	ld c, a
 	ld b, FLAG_TEST
--- a/engine/events/pick_up_item.asm
+++ b/engine/events/pick_up_item.asm
@@ -15,7 +15,7 @@
 
 .isMissable
 	ld a, [hl]
-	ld [$ffdb], a
+	ld [hMissableObjectIndex], a
 
 	ld hl, wMapSpriteExtraData
 	ld a, [hSpriteIndexOrTextID]
@@ -30,7 +30,7 @@
 	call GiveItem
 	jr nc, .BagFull
 
-	ld a, [$ffdb]
+	ld a, [hMissableObjectIndex]
 	ld [wMissableObjectIndex], a
 	predef HideObject
 	ld a, 1
--- a/engine/events/saffron_guards.asm
+++ b/engine/events/saffron_guards.asm
@@ -2,7 +2,7 @@
 	ld hl, GuardDrinksList
 .drinkLoop
 	ld a, [hli]
-	ld [$ffdb], a
+	ld [hItemToRemoveID], a
 	and a
 	ret z
 	push hl
--- a/engine/gfx/oam_dma.asm
+++ b/engine/gfx/oam_dma.asm
@@ -1,12 +1,12 @@
 WriteDMACodeToHRAM::
 ; Since no other memory is available during OAM DMA,
 ; DMARoutine is copied to HRAM and executed there.
-	ld c, $ff80 % $100
+	ld c, hDMARoutine % $100
 	ld b, DMARoutineEnd - DMARoutine
 	ld hl, DMARoutine
 .copy
 	ld a, [hli]
-	ld [$ff00+c], a
+	ldh [c], a
 	inc c
 	dec b
 	jr nz, .copy
--- a/engine/gfx/screen_effects.asm
+++ b/engine/gfx/screen_effects.asm
@@ -19,7 +19,7 @@
 	ld [wDisableVBlankWYUpdate], a
 	xor a
 .loop
-	ld [$ff96], a
+	ld [hMutateWY], a
 	call .MutateWY
 	call .MutateWY
 	dec b
@@ -30,9 +30,9 @@
 	ret
 
 .MutateWY
-	ld a, [$ff96]
+	ld a, [hMutateWY]
 	xor b
-	ld [$ff96], a
+	ld [hMutateWY], a
 	ld [rWY], a
 	ld c, 3
 	jp DelayFrames
@@ -43,7 +43,7 @@
 	call GetPredefRegisters
 	xor a
 .loop
-	ld [$ff97], a
+	ld [hMutateWX], a
 	call .MutateWX
 	ld c, 1
 	call DelayFrames
@@ -58,9 +58,9 @@
 	ret
 
 .MutateWX
-	ld a, [$ff97]
+	ld a, [hMutateWX]
 	xor b
-	ld [$ff97], a
+	ld [hMutateWX], a
 	bit 7, a
 	jr z, .skipZeroing
 	xor a ; zero a if it's negative
--- a/engine/items/item_effects.asm
+++ b/engine/items/item_effects.asm
@@ -1341,7 +1341,7 @@
 	push hl
 	push de
 	ld d, a
-	callab CalcExperience ; calculate experience for next level and store it at $ff96
+	callab CalcExperience ; calculate experience for next level and store it at hExperience
 	pop de
 	pop hl
 	ld bc, wPartyMon1Exp - wPartyMon1Level
--- a/engine/link/cable_club.asm
+++ b/engine/link/cable_club.asm
@@ -663,7 +663,7 @@
 	push de
 	push hl
 	ld a, c
-	ld [$ff95], a
+	ld [hPastLeadingZeros], a
 	call GetMonName
 	pop hl
 	call PlaceString
@@ -903,7 +903,7 @@
 	ld [wTilesetGfxPtr + 1], a
 	ld a, l
 	ld [wTilesetGfxPtr], a
-	ld a, Bank(Club_GFX)
+	ld a, BANK(Club_GFX)
 	ld [wTilesetBank], a
 	ld hl, Club_Coll
 	ld a, h
--- a/engine/menus/pokedex.asm
+++ b/engine/menus/pokedex.asm
@@ -566,11 +566,11 @@
 	pop hl
 	inc hl ; hl = address of pokedex description text
 	coord bc, 1, 11
-	ld a, 2
-	ld [$fff4], a
+	ld a, %10
+	ld [hClearLetterPrintingDelayFlags], a
 	call TextCommandProcessor ; print pokedex description text
 	xor a
-	ld [$fff4], a
+	ld [hClearLetterPrintingDelayFlags], a
 .waitForButtonPress
 	call JoypadLowSensitivity
 	ld a, [hJoy5]
--- a/engine/menus/save.asm
+++ b/engine/menus/save.asm
@@ -601,9 +601,9 @@
 	ret
 
 SAVCheckRandomID:
-;checks if Sav file is the same by checking player's name 1st letter ($a598)
+; checks if Sav file is the same by checking player's name 1st letter
 ; and the two random numbers generated at game beginning
-;(which are stored at wPlayerID)s
+; (which are stored at wPlayerID)s
 	ld a, $0a
 	ld [MBC1SRamEnable], a
 	ld a, $01
@@ -702,7 +702,7 @@
 
 PadSRAM_FF:
 	ld [MBC1SRamBank], a
-	ld hl, $a000
-	ld bc, $2000
+	ld hl, $a000 ; start of SRAM
+	ld bc, $2000 ; size of SRAM
 	ld a, $ff
 	jp FillMemory
--- a/engine/menus/swap_items.asm
+++ b/engine/menus/swap_items.asm
@@ -77,18 +77,18 @@
 	cp b
 	jr z, .swapSameItemType
 .swapDifferentItems
-	ld [$ff95], a ; [$ff95] = second item ID
+	ld [hSwapItemID], a ; save second item ID
 	ld a, [hld]
-	ld [$ff96], a ; [$ff96] = second item quantity
+	ld [hSwapItemQuantity], a ; save second item quantity
 	ld a, [de]
 	ld [hli], a ; put first item ID in second item slot
 	inc de
 	ld a, [de]
 	ld [hl], a ; put first item quantity in second item slot
-	ld a, [$ff96]
+	ld a, [hSwapItemQuantity]
 	ld [de], a ; put second item quantity in first item slot
 	dec de
-	ld a, [$ff95]
+	ld a, [hSwapItemID]
 	ld [de], a ; put second item ID in first item slot
 	xor a
 	ld [wMenuItemToSwap], a ; 0 means no item is currently being swapped
--- a/engine/movie/oak_speech/oak_speech.asm
+++ b/engine/movie/oak_speech/oak_speech.asm
@@ -57,7 +57,7 @@
 	bit 1, a ; possibly a debug mode bit
 	jp nz, .skipChoosingNames
 	ld de, ProfOakPic
-	lb bc, Bank(ProfOakPic), $00
+	lb bc, BANK(ProfOakPic), $00
 	call IntroDisplayPicCenteredOrUpperRight
 	call FadeInIntroPic
 	ld hl, OakSpeechText1
@@ -76,7 +76,7 @@
 	call GBFadeOutToWhite
 	call ClearScreen
 	ld de, RedPicFront
-	lb bc, Bank(RedPicFront), $00
+	lb bc, BANK(RedPicFront), $00
 	call IntroDisplayPicCenteredOrUpperRight
 	call MovePicLeft
 	ld hl, IntroducePlayerText
@@ -85,7 +85,7 @@
 	call GBFadeOutToWhite
 	call ClearScreen
 	ld de, Rival1Pic
-	lb bc, Bank(Rival1Pic), $00
+	lb bc, BANK(Rival1Pic), $00
 	call IntroDisplayPicCenteredOrUpperRight
 	call FadeInIntroPic
 	ld hl, IntroduceRivalText
@@ -95,7 +95,7 @@
 	call GBFadeOutToWhite
 	call ClearScreen
 	ld de, RedPicFront
-	lb bc, Bank(RedPicFront), $00
+	lb bc, BANK(RedPicFront), $00
 	call IntroDisplayPicCenteredOrUpperRight
 	call GBFadeInFromWhite
 	ld a, [wd72d]
--- a/engine/overworld/hidden_objects.asm
+++ b/engine/overworld/hidden_objects.asm
@@ -14,14 +14,14 @@
 	set 4, [hl]
 	ret
 
-; if a hidden object was found, stores $00 in [$ffee], else stores $ff
+; if a hidden object was found, stores $00 in [hFoundHiddenObject], else stores $ff
 CheckForHiddenObject::
-	ld hl, $ffeb
+	ld hl, hFoundHiddenObjectOrBookshelf
 	xor a
-	ld [hli], a
-	ld [hli], a
-	ld [hli], a
-	ld [hl], a
+	ld [hli], a ; [hFoundHiddenObjectOrBookshelf]
+	ld [hli], a ; [hSavedMapTextPtr]
+	ld [hli], a ; [hSavedMapTextPtr + 1]
+	ld [hl], a  ; [hFoundHiddenObject]
 	ld de, $0
 	ld hl, HiddenObjectMaps
 .hiddenMapLoop
@@ -81,7 +81,7 @@
 	ret
 .noMatch
 	ld a, $ff
-	ld [$ffee], a
+	ld [hFoundHiddenObject], a
 	ret
 
 ; checks if the coordinates in front of the player's sprite match Y in b and X in c
--- a/engine/overworld/missable_objects.asm
+++ b/engine/overworld/missable_objects.asm
@@ -120,7 +120,7 @@
 .notHidden
 	xor a
 .hidden
-	ld [$ffe5], a
+	ld [hIsHiddenMissableObject], a
 	ret
 
 ; adds missable object (items, leg. pokemon, etc.) to the map
--- a/engine/overworld/movement.asm
+++ b/engine/overworld/movement.asm
@@ -475,7 +475,7 @@
 ; tests if sprite is off screen or otherwise unable to do anything
 CheckSpriteAvailability:
 	predef IsObjectHidden
-	ld a, [$ffe5]
+	ld a, [hIsHiddenMissableObject]
 	and a
 	jp nz, .spriteInvisible
 	ld h, wSpriteStateData2 / $100
@@ -564,7 +564,7 @@
 	ld a, [hl]         ; c1x9: facing direction
 	add b
 	ld b, a
-	ld a, [$ff93]  ; current sprite offset
+	ld a, [hTilePlayerStandingOn]
 	add b
 	ld b, a
 	ld a, [hCurrentSpriteOffset]
--- a/engine/overworld/player_state.asm
+++ b/engine/overworld/player_state.asm
@@ -297,7 +297,7 @@
 
 GetTileTwoStepsInFrontOfPlayer:
 	xor a
-	ld [$ffdb], a
+	ld [hPlayerFacing], a
 	ld hl, wYCoord
 	ld a, [hli]
 	ld d, a
@@ -306,7 +306,7 @@
 	and a ; cp SPRITE_FACING_DOWN
 	jr nz, .notFacingDown
 ; facing down
-	ld hl, $ffdb
+	ld hl, hPlayerFacing
 	set 0, [hl]
 	aCoord 8, 13
 	inc d
@@ -315,7 +315,7 @@
 	cp SPRITE_FACING_UP
 	jr nz, .notFacingUp
 ; facing up
-	ld hl, $ffdb
+	ld hl, hPlayerFacing
 	set 1, [hl]
 	aCoord 8, 5
 	dec d
@@ -324,7 +324,7 @@
 	cp SPRITE_FACING_LEFT
 	jr nz, .notFacingLeft
 ; facing left
-	ld hl, $ffdb
+	ld hl, hPlayerFacing
 	set 2, [hl]
 	aCoord 4, 9
 	dec e
@@ -333,7 +333,7 @@
 	cp SPRITE_FACING_RIGHT
 	jr nz, .storeTile
 ; facing right
-	ld hl, $ffdb
+	ld hl, hPlayerFacing
 	set 3, [hl]
 	aCoord 12, 9
 	inc e
@@ -378,33 +378,33 @@
 	ld hl, wSpriteStateData2 + $14
 	add hl, de
 	ld a, [hli] ; map Y position
-	ld [$ffdc], a
+	ld [hPlayerYCoord], a
 	ld a, [hl] ; map X position
-	ld [$ffdd], a
+	ld [hPlayerXCoord], a
 	ld a, [wNumSprites]
 	ld c, a
 	ld de, $f
 	ld hl, wSpriteStateData2 + $14
-	ld a, [$ffdb]
+	ld a, [hPlayerFacing]
 	and $3 ; facing up or down?
 	jr z, .pushingHorizontallyLoop
 .pushingVerticallyLoop
 	inc hl
-	ld a, [$ffdd]
+	ld a, [hPlayerXCoord]
 	cp [hl]
 	jr nz, .nextSprite1 ; if X coordinates don't match
 	dec hl
 	ld a, [hli]
 	ld b, a
-	ld a, [$ffdb]
+	ld a, [hPlayerFacing]
 	rrca
 	jr c, .pushingDown
 ; pushing up
-	ld a, [$ffdc]
+	ld a, [hPlayerYCoord]
 	dec a
 	jr .compareYCoords
 .pushingDown
-	ld a, [$ffdc]
+	ld a, [hPlayerYCoord]
 	inc a
 .compareYCoords
 	cp b
@@ -417,19 +417,19 @@
 .pushingHorizontallyLoop
 	ld a, [hli]
 	ld b, a
-	ld a, [$ffdc]
+	ld a, [hPlayerYCoord]
 	cp b
 	jr nz, .nextSprite2
 	ld b, [hl]
-	ld a, [$ffdb]
+	ld a, [hPlayerFacing]
 	bit 2, a
 	jr nz, .pushingLeft
 ; pushing right
-	ld a, [$ffdd]
+	ld a, [hPlayerXCoord]
 	inc a
 	jr .compareXCoords
 .pushingLeft
-	ld a, [$ffdd]
+	ld a, [hPlayerXCoord]
 	dec a
 .compareXCoords
 	cp b
--- a/engine/overworld/sprite_collisions.asm
+++ b/engine/overworld/sprite_collisions.asm
@@ -31,7 +31,7 @@
 UpdateNonPlayerSprite:
 	dec a
 	swap a
-	ld [$ff93], a  ; $10 * sprite#
+	ld [hTilePlayerStandingOn], a  ; $10 * sprite#
 	ld a, [wNPCMovementScriptSpriteOffset] ; some sprite offset?
 	ld b, a
 	ld a, [hCurrentSpriteOffset]
@@ -79,7 +79,7 @@
 	and $f0
 	or c
 
-	ld [$ff90], a ; store Y coordinate adjusted for direction of movement
+	ld [hFF90], a ; store Y coordinate adjusted for direction of movement
 
 	ld a, [hli] ; a = [$c1i5] (delta X) (-1, 0, or 1)
 	call SetSpriteCollisionValues
@@ -92,7 +92,7 @@
 	and $f0
 	or c
 
-	ld [$ff91], a ; store X coordinate adjusted for direction of movement
+	ld [hFF91], a ; store X coordinate adjusted for direction of movement
 
 	ld a, l
 	add 7
@@ -102,15 +102,15 @@
 	ld [hld], a ; zero [$c1id] XXX what's [$c1id] for?
 	ld [hld], a ; zero [$c1ic] (directions in which collisions occurred)
 
-	ld a, [$ff91]
+	ld a, [hFF91]
 	ld [hld], a ; [$c1ib] = adjusted X coordinate
-	ld a, [$ff90]
+	ld a, [hFF90]
 	ld [hl], a ; [$c1ia] = adjusted Y coordinate
 
 	xor a ; zero the loop counter
 
 .loop
-	ld [$ff8f], a ; store loop counter
+	ld [hFF8F], a ; store loop counter
 	swap a
 	ld e, a
 	ld a, [hCurrentSpriteOffset]
@@ -154,7 +154,7 @@
 	cpl
 	inc a
 .noCarry1
-	ld [$ff90], a ; store the distance between the two sprites' adjusted Y values
+	ld [hFF90], a ; store the distance between the two sprites' adjusted Y values
 
 ; Use the carry flag set by the above subtraction to determine which sprite's
 ; Y coordinate is larger. This information is used later to set [$c1ic],
@@ -176,11 +176,11 @@
 	ld b, 9
 
 .next1
-	ld a, [$ff90] ; a = distance between adjusted Y coordinates
+	ld a, [hFF90] ; a = distance between adjusted Y coordinates
 	sub b
-	ld [$ff92], a ; store distance adjusted using sprite i's direction
+	ld [hFF92], a ; store distance adjusted using sprite i's direction
 	ld a, b
-	ld [$ff90], a ; store 7 or 9 depending on sprite i's delta Y
+	ld [hFF90], a ; store 7 or 9 depending on sprite i's delta Y
 	jr c, .checkXDistance
 
 ; If sprite j's delta Y is 0, then b = 7, else b = 9.
@@ -193,7 +193,7 @@
 	ld b, 9
 
 .next2
-	ld a, [$ff92] ; a = distance adjusted using sprite i's direction
+	ld a, [hFF92] ; a = distance adjusted using sprite i's direction
 	sub b ; adjust distance using sprite j's direction
 	jr z, .checkXDistance
 	jr nc, .next ; go to next sprite if distance is still positive after both adjustments
@@ -225,7 +225,7 @@
 	cpl
 	inc a
 .noCarry2
-	ld [$ff91], a ; store the distance between the two sprites' adjusted X values
+	ld [hFF91], a ; store the distance between the two sprites' adjusted X values
 
 ; Use the carry flag set by the above subtraction to determine which sprite's
 ; X coordinate is larger. This information is used later to set [$c1ic],
@@ -247,11 +247,11 @@
 	ld b, 9
 
 .next3
-	ld a, [$ff91] ; a = distance between adjusted X coordinates
+	ld a, [hFF91] ; a = distance between adjusted X coordinates
 	sub b
-	ld [$ff92], a ; store distance adjusted using sprite i's direction
+	ld [hFF92], a ; store distance adjusted using sprite i's direction
 	ld a, b
-	ld [$ff91], a ; store 7 or 9 depending on sprite i's delta X
+	ld [hFF91], a ; store 7 or 9 depending on sprite i's delta X
 	jr c, .collision
 
 ; If sprite j's delta X is 0, then b = 7, else b = 9.
@@ -264,15 +264,15 @@
 	ld b, 9
 
 .next4
-	ld a, [$ff92] ; a = distance adjusted using sprite i's direction
+	ld a, [hFF92] ; a = distance adjusted using sprite i's direction
 	sub b ; adjust distance using sprite j's direction
 	jr z, .collision
 	jr nc, .next ; go to next sprite if distance is still positive after both adjustments
 
 .collision
-	ld a, [$ff91] ; a = 7 or 9 depending on sprite i's delta X
+	ld a, [hFF91] ; a = 7 or 9 depending on sprite i's delta X
 	ld b, a
-	ld a, [$ff90] ; a = 7 or 9 depending on sprite i's delta Y
+	ld a, [hFF90] ; a = 7 or 9 depending on sprite i's delta Y
 	inc l
 
 ; If delta X isn't 0 and delta Y is 0, then b = %0011, else b = %1100.
@@ -294,7 +294,7 @@
 ; set bit in [$c1ie] or [$c1if] to indicate which sprite the collision occurred with
 	inc l
 	inc l
-	ld a, [$ff8f] ; a = loop counter
+	ld a, [hFF8F] ; a = loop counter
 	ld de, SpriteCollisionBitTable
 	add a
 	add e
@@ -311,7 +311,7 @@
 	ld [hl], a
 
 .next
-	ld a, [$ff8f] ; a = loop counter
+	ld a, [hFF8F] ; a = loop counter
 	inc a
 	cp $10
 	jp nz, .loop
--- a/engine/overworld/tilesets.asm
+++ b/engine/overworld/tilesets.asm
@@ -25,7 +25,7 @@
 	ld a, [hl]
 	ld [hTilesetType], a
 	xor a
-	ld [$ffd8], a
+	ld [hMovingBGTilesCounter1], a
 	pop hl
 	ld a, [wCurMapTileset]
 	push hl
--- a/engine/overworld/trainer_sight.asm
+++ b/engine/overworld/trainer_sight.asm
@@ -5,16 +5,16 @@
 	ld [hSpriteIndex], a
 	call GetSpriteDataPointer
 	ld a, [hli] ; c1x4 (screen Y pos)
-	ld [$ffeb], a
+	ld [hSpriteScreenYCoord], a
 	inc hl
 	ld a, [hl] ; c1x6 (screen X pos)
-	ld [$ffec], a
+	ld [hSpriteScreenXCoord], a
 	ld de, (wSpriteStateData2 + $4) - (wSpriteStateData1 + $6)
 	add hl, de
 	ld a, [hli] ; c2x4 (map Y pos)
-	ld [$ffed], a
+	ld [hSpriteMapYCoord], a
 	ld a, [hl] ; c2x5 (map X pos)
-	ld [$ffee], a
+	ld [hSpriteMapXCoord], a
 	ret
 
 _GetSpritePosition2::
@@ -42,16 +42,16 @@
 	ld a, [wSpriteIndex]
 	ld [hSpriteIndex], a
 	call GetSpriteDataPointer
-	ld a, [$ffeb] ; c1x4 (screen Y pos)
+	ld a, [hSpriteScreenYCoord] ; c1x4 (screen Y pos)
 	ld [hli], a
 	inc hl
-	ld a, [$ffec] ; c1x6 (screen X pos)
+	ld a, [hSpriteScreenXCoord] ; c1x6 (screen X pos)
 	ld [hl], a
 	ld de, (wSpriteStateData2 + $4) - (wSpriteStateData1 + $6)
 	add hl, de
-	ld a, [$ffed] ; c2x4 (map Y pos)
+	ld a, [hSpriteMapYCoord] ; c2x4 (map Y pos)
 	ld [hli], a
-	ld a, [$ffee] ; c2x5 (map X pos)
+	ld a, [hSpriteMapXCoord] ; c2x5 (map X pos)
 	ld [hl], a
 	ret
 
--- a/engine/overworld/update_map.asm
+++ b/engine/overworld/update_map.asm
@@ -63,7 +63,7 @@
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
-	ld de, -2 * 32
+	ld de, -2 * BG_MAP_WIDTH
 	add hl, de
 	ld a, h
 	and $3
@@ -73,8 +73,8 @@
 	ld a, h
 	ld [wBuffer + 1], a ; this copy of the address is not used
 	ld a, 2
-	ld [$ffbe], a
-	ld c, 9 ; number of rows of 2x2 tiles (this covers the whole screen)
+	ld [hRedrawMapViewRowOffset], a
+	ld c, SCREEN_HEIGHT / 2 ; number of rows of 2x2 tiles (this covers the whole screen)
 .redrawRowLoop
 	push bc
 	push hl
@@ -81,7 +81,7 @@
 	push hl
 	ld hl, wTileMap - 2 * SCREEN_WIDTH
 	ld de, SCREEN_WIDTH
-	ld a, [$ffbe]
+	ld a, [hRedrawMapViewRowOffset]
 .calcWRAMAddrLoop
 	add hl, de
 	dec a
@@ -88,8 +88,8 @@
 	jr nz, .calcWRAMAddrLoop
 	call CopyToRedrawRowOrColumnSrcTiles
 	pop hl
-	ld de, $20
-	ld a, [$ffbe]
+	ld de, BG_MAP_WIDTH
+	ld a, [hRedrawMapViewRowOffset]
 	ld c, a
 .calcVRAMAddrLoop
 	add hl, de
@@ -104,7 +104,7 @@
 	ld a, REDRAW_ROW
 	ld [hRedrawRowOrColumnMode], a
 	call DelayFrame
-	ld hl, $ffbe
+	ld hl, hRedrawMapViewRowOffset
 	inc [hl]
 	inc [hl]
 	pop hl
--- a/home.asm
+++ b/home.asm
@@ -199,7 +199,7 @@
 	pop hl
 	ld a, [hLoadedROMBank]
 	push af
-	ld a, Bank(CopyUncompressedPicToHL)
+	ld a, BANK(CopyUncompressedPicToHL)
 	ld [hLoadedROMBank], a
 	ld [MBC1RomBank], a
 	xor a
@@ -832,7 +832,7 @@
 	ret nz
 	ld a, [hLoadedROMBank]
 	push af
-	ld a, Bank(_UpdateSprites)
+	ld a, BANK(_UpdateSprites)
 	ld [hLoadedROMBank], a
 	ld [MBC1RomBank], a
 	call _UpdateSprites
@@ -1104,7 +1104,7 @@
 	ld [wListMenuID], a
 	ld a, [hLoadedROMBank]
 	push af
-	ld a, Bank(DisplayPokemartDialogue_)
+	ld a, BANK(DisplayPokemartDialogue_)
 	ld [hLoadedROMBank], a
 	ld [MBC1RomBank], a
 	call DisplayPokemartDialogue_
@@ -1136,14 +1136,14 @@
 DisplayPokemonCenterDialogue::
 ; zeroing these doesn't appear to serve any purpose
 	xor a
-	ld [$ff8b], a
-	ld [$ff8c], a
-	ld [$ff8d], a
+	ld [hItemPrice], a
+	ld [hItemPrice + 1], a
+	ld [hItemPrice + 2], a
 
 	inc hl
 	ld a, [hLoadedROMBank]
 	push af
-	ld a, Bank(DisplayPokemonCenterDialogue_)
+	ld a, BANK(DisplayPokemonCenterDialogue_)
 	ld [hLoadedROMBank], a
 	ld [MBC1RomBank], a
 	call DisplayPokemonCenterDialogue_
@@ -2794,7 +2794,7 @@
 	ld a, [wLinkState]
 	and a
 	jr nz, .linkBattle
-	ld a, Bank(TrainerPicAndMoneyPointers)
+	ld a, BANK(TrainerPicAndMoneyPointers)
 	call BankswitchHome
 	ld a, [wTrainerClass]
 	dec a
@@ -3185,12 +3185,12 @@
 	ld hl, NamePointers
 	add hl, de
 	ld a, [hli]
-	ld [$ff96], a
+	ld [hSwapTemp + 1], a
 	ld a, [hl]
-	ld [$ff95], a
-	ld a, [$ff95]
+	ld [hSwapTemp], a
+	ld a, [hSwapTemp]
 	ld h, a
-	ld a, [$ff96]
+	ld a, [hSwapTemp + 1]
 	ld l, a
 	ld a, [wd0b5]
 	ld b, a
@@ -3258,7 +3258,7 @@
 	ld [hItemPrice], a
 	jr .done
 .getTMPrice
-	ld a, Bank(GetMachinePrice)
+	ld a, BANK(GetMachinePrice)
 	ld [hLoadedROMBank], a
 	ld [MBC1RomBank], a
 	call GetMachinePrice
@@ -3409,7 +3409,7 @@
 	push bc
 	ld a, [hLoadedROMBank]
 	push af
-	ld a, Bank(_Divide)
+	ld a, BANK(_Divide)
 	ld [hLoadedROMBank], a
 	ld [MBC1RomBank], a
 	call _Divide
@@ -3552,11 +3552,11 @@
 	call Multiply
 	ld a, [hld]
 	ld d, a
-	ld a, [$ff98]
+	ld a, [hProduct + 3]
 	sub d
 	ld a, [hli]
 	ld d, a
-	ld a, [$ff97]
+	ld a, [hProduct + 2]
 	sbc d               ; test if (current stat exp bonus)^2 < stat exp
 	jr c, .statExpLoop
 .statExpDone
@@ -4497,11 +4497,11 @@
 	bit 0, a ; A button
 	jr z, .nothingFound
 ; A button is pressed
-	ld a, Bank(CheckForHiddenObject)
+	ld a, BANK(CheckForHiddenObject)
 	ld [MBC1RomBank], a
 	ld [hLoadedROMBank], a
 	call CheckForHiddenObject
-	ld a, [$ffee]
+	ld a, [hFoundHiddenObject]
 	and a
 	jr nz, .hiddenObjectNotFound
 	ld a, [wHiddenObjectFunctionRomBank]
@@ -4515,13 +4515,13 @@
 	jr .done
 .hiddenObjectNotFound
 	callba PrintBookshelfText
-	ld a, [$ffdb]
+	ld a, [hFFDB]
 	and a
 	jr z, .done
 .nothingFound
 	ld a, $ff
 .done
-	ld [$ffeb], a
+	ld [hFoundHiddenObjectOrBookshelf], a
 	pop af
 	ld [MBC1RomBank], a
 	ld [hLoadedROMBank], a
@@ -4537,17 +4537,17 @@
 
 RestoreMapTextPointer::
 	ld hl, wMapTextPtr
-	ld a, [$ffec]
+	ld a, [hSavedMapTextPtr]
 	ld [hli], a
-	ld a, [$ffec + 1]
+	ld a, [hSavedMapTextPtr + 1]
 	ld [hl], a
 	ret
 
 SetMapTextPointer::
 	ld a, [wMapTextPtr]
-	ld [$ffec], a
+	ld [hSavedMapTextPtr], a
 	ld a, [wMapTextPtr + 1]
-	ld [$ffec + 1], a
+	ld [hSavedMapTextPtr + 1], a
 	ld a, l
 	ld [wMapTextPtr], a
 	ld a, h
--- a/home/init.asm
+++ b/home/init.asm
@@ -53,13 +53,13 @@
 
 	call ClearVram
 
-	ld hl, $ff80
-	ld bc, $ffff - $ff80
+	ld hl, $ff80 ; start of HRAM
+	ld bc, $ffff - $ff80 ; size of HRAM
 	call FillMemory
 
 	call ClearSprites
 
-	ld a, Bank(WriteDMACodeToHRAM)
+	ld a, BANK(WriteDMACodeToHRAM)
 	ld [hLoadedROMBank], a
 	ld [MBC1RomBank], a
 	call WriteDMACodeToHRAM
--- a/home/overworld.asm
+++ b/home/overworld.asm
@@ -88,7 +88,7 @@
 	call IsPlayerCharacterBeingControlledByGame
 	jr nz, .checkForOpponent
 	call CheckForHiddenObjectOrBookshelfOrCardKeyDoor
-	ld a, [$ffeb]
+	ld a, [hFoundHiddenObjectOrBookshelf]
 	and a
 	jp z, OverworldLoop ; jump if a hidden object or bookshelf was found, but not if a card key door was found
 	call IsSpriteOrSignInFrontOfPlayer
@@ -762,7 +762,7 @@
 	call StopMusic
 	ld hl, wd72e
 	res 5, [hl]
-	ld a, Bank(ResetStatusAndHalveMoneyOnBlackout) ; also Bank(SpecialWarpIn) and Bank(SpecialEnterMap)
+	ld a, BANK(ResetStatusAndHalveMoneyOnBlackout) ; also BANK(SpecialWarpIn) and BANK(SpecialEnterMap)
 	ld [hLoadedROMBank], a
 	ld [MBC1RomBank], a
 	call ResetStatusAndHalveMoneyOnBlackout
@@ -793,7 +793,7 @@
 	set 2, [hl] ; fly warp or dungeon warp
 	res 5, [hl] ; forced to ride bike
 	call LeaveMapAnim
-	ld a, Bank(SpecialWarpIn)
+	ld a, BANK(SpecialWarpIn)
 	ld [hLoadedROMBank], a
 	ld [MBC1RomBank], a
 	call SpecialWarpIn
@@ -2388,14 +2388,14 @@
 	push bc
 	ld c, a
 	ld b, $00
-	ld a, Bank(MapHeaderBanks)
+	ld a, BANK(MapHeaderBanks)
 	call BankswitchHome ; switch to ROM bank 3
 	ld hl, MapHeaderBanks
 	add hl, bc
 	ld a, [hl]
-	ld [$ffe8], a ; save map ROM bank
+	ld [hMapROMBank], a ; save map ROM bank
 	call BankswitchBack
-	ld a, [$ffe8]
+	ld a, [hMapROMBank]
 	ld [hLoadedROMBank], a
 	ld [MBC1RomBank], a ; switch to map ROM bank
 	pop bc
--- a/home/text.asm
+++ b/home/text.asm
@@ -365,7 +365,7 @@
 	push af
 	set 1, a
 	ld e, a
-	ld a, [$fff4]
+	ld a, [hClearLetterPrintingDelayFlags]
 	xor e
 	ld [wLetterPrintingDelayFlags], a
 	ld a, c
--- a/home/vblank.asm
+++ b/home/vblank.asm
@@ -26,7 +26,7 @@
 	call VBlankCopy
 	call VBlankCopyDouble
 	call UpdateMovingBgTiles
-	call $ff80 ; hOAMDMA
+	call hDMARoutine
 	ld a, BANK(PrepareOAMData)
 	ld [hLoadedROMBank], a
 	ld [MBC1RomBank], a
--- a/hram.asm
+++ b/hram.asm
@@ -1,3 +1,5 @@
+hDMARoutine EQU $FF80
+
 hSoftReset EQU $FF8A
 ; Initialized to 16.
 ; Decremented each input iteration if the player
@@ -81,6 +83,11 @@
 hSpriteScreenX EQU $FF91
 hSpriteScreenY EQU $FF92
 
+hFF8F EQU $FF8F
+hFF90 EQU $FF90
+hFF91 EQU $FF91
+hFF92 EQU $FF92
+
 hTilePlayerStandingOn EQU $FF93
 
 hSpritePriority EQU $FF94
@@ -90,14 +97,20 @@
 
 hNPCMovementDirections2Index EQU $FF95
 
+hSwapItemID       EQU $FF95
+hSwapItemQuantity EQU $FF96
+
 ; CalcPositionOfPlayerRelativeToNPC
 hNPCSpriteOffset EQU $FF95
 
-; temp value used when swapping bytes
+; temp value used when swapping bytes or words
 hSwapTemp EQU $FF95
 
 hExperience EQU $FF96 ; 3 bytes, big endian
 
+hMutateWY EQU $FF96
+hMutateWX EQU $FF97
+
 ; Multiplication and division variables are meant
 ; to overlap for back-to-back usage. Big endian.
 
@@ -204,6 +217,8 @@
 ; the destination address of the automatic background transfer
 hAutoBGTransferDest EQU $FFBC ; 2 bytes
 
+hRedrawMapViewRowOffset EQU $FFBE
+
 ; temporary storage for stack pointer during memory transfers that use pop
 ; to increase speed
 hSPTemp EQU $FFBF ; 2 bytes
@@ -272,7 +287,8 @@
 
 hItemCounter EQU $FFDB
 
-hGymGateIndex EQU $FFDB
+hGymGateIndex  EQU $FFDB
+hGymGateAnswer EQU $FFDC
 
 hGymTrashCanRandNumMask EQU $FFDB
 
@@ -285,10 +301,18 @@
 ; $FF = player cancelled
 hOaksAideResult       EQU $FFDB
 
+hSavedCoordIndex      EQU $FFDB
+
 hOaksAideRequirement  EQU $FFDB ; required number of owned mons
 hOaksAideRewardItem   EQU $FFDC
 hOaksAideNumMonsOwned EQU $FFDD
 
+hPlayerFacing EQU $FFDB
+hPlayerYCoord EQU $FFDC
+hPlayerXCoord EQU $FFDD
+
+hMissableObjectIndex EQU $FFDB
+
 hItemToRemoveID    EQU $FFDB
 hItemToRemoveIndex EQU $FFDC
 
@@ -295,15 +319,26 @@
 hVendingMachineItem  EQU $FFDB
 hVendingMachinePrice EQU $FFDC ; 3-byte BCD number
 
+hFFDB EQU $FFDB
+hFFDC EQU $FFDC
+
+hBackupGymGateIndex EQU $FFE0
+
+hUnlockedSilphCoDoors EQU $FFE0
+
 ; the first tile ID in a sequence of tile IDs that increase by 1 each step
 hStartTileID EQU $FFE1
 
 hNewPartyLength EQU $FFE4
 
+hIsHiddenMissableObject EQU $FFE5
+
 hDividend2 EQU $FFE5
 hDivisor2  EQU $FFE6
 hQuotient2 EQU $FFE7
 
+hMapROMBank EQU $FFE8
+
 hSpriteVRAMSlotAndFacing EQU $FFE9
 
 hCoordsInFrontOfPlayerMatch EQU $FFEA
@@ -310,7 +345,19 @@
 
 hSpriteAnimFrameCounter EQU $FFEA
 
+hSpriteScreenYCoord EQU $FFEB
+hSpriteScreenXCoord EQU $FFEC
+hSpriteMapYCoord    EQU $FFED
+hSpriteMapXCoord    EQU $FFEE
+
+hFoundHiddenObjectOrBookshelf EQU $FFEB
+hFoundHiddenObject EQU $FFEE
+
+hSavedMapTextPtr EQU $FFEC
+
 hWhoseTurn EQU $FFF3 ; 0 on player’s turn, 1 on enemy’s turn
+
+hClearLetterPrintingDelayFlags EQU $FFF4
 
 ; bit 0: draw HP fraction to the right of bar instead of below (for party menu)
 ; bit 1: menu is double spaced
--- a/scripts/BikeShop.asm
+++ b/scripts/BikeShop.asm
@@ -23,7 +23,7 @@
 	call GiveItem
 	jr nc, .BagFull
 	ld a, BIKE_VOUCHER
-	ld [$ffdb], a
+	ld [hItemToRemoveID], a
 	callba RemoveItemByID
 	SetEvent EVENT_GOT_BICYCLE
 	ld hl, BikeShopText_1d824
--- a/scripts/BillsHouse.asm
+++ b/scripts/BillsHouse.asm
@@ -66,13 +66,13 @@
 	ld a, $2
 	ld [wSpriteIndex], a
 	ld a, $c
-	ld [$ffeb], a
+	ld [hSpriteScreenYCoord], a
 	ld a, $40
-	ld [$ffec], a
+	ld [hSpriteScreenXCoord], a
 	ld a, $6
-	ld [$ffed], a
+	ld [hSpriteMapYCoord], a
 	ld a, $5
-	ld [$ffee], a
+	ld [hSpriteMapXCoord], a
 	call SetSpritePosition1
 	ld a, HS_BILL_1
 	ld [wMissableObjectIndex], a
--- a/scripts/CinnabarGym.asm
+++ b/scripts/CinnabarGym.asm
@@ -96,7 +96,7 @@
 	cp $ff
 	jp z, CinnabarGymScript_75792
 	ld a, [wTrainerHeaderFlagBit]
-	ld [$ffdb], a
+	ld [hGymGateIndex], a
 	AdjustEventBit EVENT_BEAT_CINNABAR_GYM_TRAINER_0, 2
 	ld c, a
 	ld b, FLAG_TEST
@@ -111,7 +111,7 @@
 	call WaitForSoundToFinish
 .asm_7581b
 	ld a, [wTrainerHeaderFlagBit]
-	ld [$ffdb], a
+	ld [hGymGateIndex], a
 	AdjustEventBit EVENT_BEAT_CINNABAR_GYM_TRAINER_0, 2
 	ld c, a
 	ld b, FLAG_SET
--- a/scripts/CopycatsHouse2F.asm
+++ b/scripts/CopycatsHouse2F.asm
@@ -29,7 +29,7 @@
 	ld hl, ReceivedTM31Text
 	call PrintText
 	ld a, POKE_DOLL
-	ld [$ffdb], a
+	ld [hItemToRemoveID], a
 	callba RemoveItemByID
 	SetEvent EVENT_GOT_TM31
 	jr .asm_62ecd
--- a/scripts/OaksLab.asm
+++ b/scripts/OaksLab.asm
@@ -672,9 +672,9 @@
 
 OaksLabScript_1d02b:
 	ld a, $7c
-	ld [$ffeb], a
+	ld [hSpriteScreenYCoord], a
 	ld a, $8
-	ld [$ffee], a
+	ld [hSpriteMapXCoord], a
 	ld a, [wYCoord]
 	cp $3
 	jr nz, .asm_1d045
@@ -703,9 +703,9 @@
 .asm_1d066
 	ld a, $20
 .asm_1d068
-	ld [$ffec], a
+	ld [hSpriteScreenXCoord], a
 	ld a, b
-	ld [$ffed], a
+	ld [hSpriteMapYCoord], a
 	ld a, $1
 	ld [wSpriteIndex], a
 	call SetSpritePosition1
--- a/scripts/PewterCity.asm
+++ b/scripts/PewterCity.asm
@@ -58,13 +58,13 @@
 	ld [hSpriteIndexOrTextID], a
 	call DisplayTextID
 	ld a, $3c
-	ld [$ffeb], a
+	ld [hSpriteScreenYCoord], a
 	ld a, $30
-	ld [$ffec], a
+	ld [hSpriteScreenXCoord], a
 	ld a, $c
-	ld [$ffed], a
+	ld [hSpriteMapYCoord], a
 	ld a, $11
-	ld [$ffee], a
+	ld [hSpriteMapXCoord], a
 	ld a, $3
 	ld [wSpriteIndex], a
 	call SetSpritePosition1
@@ -126,13 +126,13 @@
 	ld [hSpriteIndexOrTextID], a
 	call DisplayTextID
 	ld a, $3c
-	ld [$ffeb], a
+	ld [hSpriteScreenYCoord], a
 	ld a, $40
-	ld [$ffec], a
+	ld [hSpriteScreenXCoord], a
 	ld a, $16
-	ld [$ffed], a
+	ld [hSpriteMapYCoord], a
 	ld a, $10
-	ld [$ffee], a
+	ld [hSpriteMapXCoord], a
 	ld a, $5
 	ld [wSpriteIndex], a
 	call SetSpritePosition1
--- a/scripts/Route5Gate.asm
+++ b/scripts/Route5Gate.asm
@@ -27,7 +27,7 @@
 	xor a
 	ld [hJoyHeld], a
 	callba RemoveGuardDrink
-	ld a, [$ffdb]
+	ld a, [hItemToRemoveID]
 	and a
 	jr nz, .asm_1df82
 	ld a, $2
@@ -74,7 +74,7 @@
 	bit 6, a
 	jr nz, .asm_88856
 	callba RemoveGuardDrink
-	ld a, [$ffdb]
+	ld a, [hItemToRemoveID]
 	and a
 	jr nz, .asm_768a2
 	ld hl, Route5GateText2
--- a/scripts/Route6Gate.asm
+++ b/scripts/Route6Gate.asm
@@ -21,7 +21,7 @@
 	xor a
 	ld [hJoyHeld], a
 	callba RemoveGuardDrink
-	ld a, [$ffdb]
+	ld a, [hItemToRemoveID]
 	and a
 	jr nz, .asm_1e080
 	ld a, $2
--- a/scripts/Route7Gate.asm
+++ b/scripts/Route7Gate.asm
@@ -33,7 +33,7 @@
 	xor a
 	ld [hJoyHeld], a
 	callba RemoveGuardDrink
-	ld a, [$ffdb]
+	ld a, [hItemToRemoveID]
 	and a
 	jr nz, .asm_1e15a
 	ld a, $2
--- a/scripts/Route8Gate.asm
+++ b/scripts/Route8Gate.asm
@@ -32,7 +32,7 @@
 	xor a
 	ld [hJoyHeld], a
 	callba RemoveGuardDrink
-	ld a, [$ffdb]
+	ld a, [hItemToRemoveID]
 	and a
 	jr nz, .asm_1e220
 	ld a, $2
--- a/scripts/SSAnne2F.asm
+++ b/scripts/SSAnne2F.asm
@@ -31,7 +31,7 @@
 	ld a, MUSIC_MEET_RIVAL
 	call PlayMusic
 	ld a, [wCoordIndex]
-	ld [$ffdb], a
+	ld [hSavedCoordIndex], a
 	ld a, HS_SS_ANNE_2F_RIVAL
 	ld [wMissableObjectIndex], a
 	predef ShowObject
@@ -43,7 +43,7 @@
 	ld [hJoyHeld], a
 	ld a, $f0
 	ld [wJoyIgnore], a
-	ld a, [$ffdb]
+	ld a, [hSavedCoordIndex]
 	cp $2
 	jr nz, .asm_61400
 	ld de, MovementData_6140c
--- a/scripts/SSAnneCaptainsRoom.asm
+++ b/scripts/SSAnneCaptainsRoom.asm
@@ -51,7 +51,7 @@
 	ld a, SFX_STOP_ALL_MUSIC
 	ld [wNewSoundID], a
 	call PlaySound
-	ld a, Bank(Music_PkmnHealed)
+	ld a, BANK(Music_PkmnHealed)
 	ld [wAudioROMBank], a
 .asm_61908
 	ld a, MUSIC_PKMN_HEALED
--- a/scripts/SilphCo10F.asm
+++ b/scripts/SilphCo10F.asm
@@ -28,7 +28,7 @@
 	db $FF
 
 SilphCo10Text_5a176:
-	ld a, [$ffe0]
+	ld a, [hUnlockedSilphCoDoors]
 	and a
 	ret z
 	SetEvent EVENT_SILPH_CO_10_UNLOCKED_DOOR
--- a/scripts/SilphCo11F.asm
+++ b/scripts/SilphCo11F.asm
@@ -35,7 +35,7 @@
 	ld a, [hl]
 	ld c, a
 	xor a
-	ld [$ffe0], a
+	ld [hUnlockedSilphCoDoors], a
 	pop hl
 .asm_62143
 	ld a, [hli]
@@ -42,7 +42,7 @@
 	cp $ff
 	jr z, .asm_6215f
 	push hl
-	ld hl, $ffe0
+	ld hl, hUnlockedSilphCoDoors
 	inc [hl]
 	pop hl
 	cp b
@@ -60,11 +60,11 @@
 	ret
 .asm_6215f
 	xor a
-	ld [$ffe0], a
+	ld [hUnlockedSilphCoDoors], a
 	ret
 
 SilphCo11Script_62163:
-	ld a, [$ffe0]
+	ld a, [hUnlockedSilphCoDoors]
 	and a
 	ret z
 	SetEvent EVENT_SILPH_CO_11_UNLOCKED_DOOR
--- a/scripts/SilphCo2F.asm
+++ b/scripts/SilphCo2F.asm
@@ -45,7 +45,7 @@
 	ld a, [hl]
 	ld c, a
 	xor a
-	ld [$ffe0], a
+	ld [hUnlockedSilphCoDoors], a
 	pop hl
 .asm_59d4f
 	ld a, [hli]
@@ -52,7 +52,7 @@
 	cp $ff
 	jr z, .asm_59d6b
 	push hl
-	ld hl, $ffe0
+	ld hl, hUnlockedSilphCoDoors
 	inc [hl]
 	pop hl
 	cp b
@@ -70,12 +70,12 @@
 	ret
 .asm_59d6b
 	xor a
-	ld [$ffe0], a
+	ld [hUnlockedSilphCoDoors], a
 	ret
 
 SilphCo2Script_59d6f:
 	EventFlagAddress hl, EVENT_SILPH_CO_2_UNLOCKED_DOOR1
-	ld a, [$ffe0]
+	ld a, [hUnlockedSilphCoDoors]
 	and a
 	ret z
 	cp $1
--- a/scripts/SilphCo3F.asm
+++ b/scripts/SilphCo3F.asm
@@ -39,7 +39,7 @@
 
 SilphCo3Script_59fad:
 	EventFlagAddress hl, EVENT_SILPH_CO_3_UNLOCKED_DOOR1
-	ld a, [$ffe0]
+	ld a, [hUnlockedSilphCoDoors]
 	and a
 	ret z
 	cp $1
--- a/scripts/SilphCo4F.asm
+++ b/scripts/SilphCo4F.asm
@@ -45,7 +45,7 @@
 	ld a, [hl]
 	ld c, a
 	xor a
-	ld [$ffe0], a
+	ld [hUnlockedSilphCoDoors], a
 	pop hl
 .asm_19d69
 	ld a, [hli]
@@ -52,7 +52,7 @@
 	cp $ff
 	jr z, .asm_19d85
 	push hl
-	ld hl, $ffe0
+	ld hl, hUnlockedSilphCoDoors
 	inc [hl]
 	pop hl
 	cp b
@@ -70,12 +70,12 @@
 	ret
 .asm_19d85
 	xor a
-	ld [$ffe0], a
+	ld [hUnlockedSilphCoDoors], a
 	ret
 
 SilphCo4Script_19d89:
 	EventFlagAddress hl, EVENT_SILPH_CO_4_UNLOCKED_DOOR1
-	ld a, [$ffe0]
+	ld a, [hUnlockedSilphCoDoors]
 	and a
 	ret z
 	cp $1
--- a/scripts/SilphCo5F.asm
+++ b/scripts/SilphCo5F.asm
@@ -49,7 +49,7 @@
 
 SilphCo5Script_19f9e:
 	EventFlagAddress hl, EVENT_SILPH_CO_5_UNLOCKED_DOOR1
-	ld a, [$ffe0]
+	ld a, [hUnlockedSilphCoDoors]
 	and a
 	ret z
 	cp $1
--- a/scripts/SilphCo6F.asm
+++ b/scripts/SilphCo6F.asm
@@ -28,7 +28,7 @@
 	db $FF
 
 SilphCo6Script_1a1e6:
-	ld a, [$ffe0]
+	ld a, [hUnlockedSilphCoDoors]
 	and a
 	ret z
 	SetEvent EVENT_SILPH_CO_6_UNLOCKED_DOOR
--- a/scripts/SilphCo7F.asm
+++ b/scripts/SilphCo7F.asm
@@ -55,7 +55,7 @@
 	ld a, [hl]
 	ld c, a
 	xor a
-	ld [$ffe0], a
+	ld [hUnlockedSilphCoDoors], a
 	pop hl
 .asm_51bd4
 	ld a, [hli]
@@ -62,7 +62,7 @@
 	cp $ff
 	jr z, .asm_51bf0
 	push hl
-	ld hl, $ffe0
+	ld hl, hUnlockedSilphCoDoors
 	inc [hl]
 	pop hl
 	cp b
@@ -80,12 +80,12 @@
 	ret
 .asm_51bf0
 	xor a
-	ld [$ffe0], a
+	ld [hUnlockedSilphCoDoors], a
 	ret
 
 SilphCo7Text_51bf4:
 	EventFlagAddress hl, EVENT_SILPH_CO_7_UNLOCKED_DOOR1
-	ld a, [$ffe0]
+	ld a, [hUnlockedSilphCoDoors]
 	and a
 	ret z
 	cp $1
--- a/scripts/SilphCo8F.asm
+++ b/scripts/SilphCo8F.asm
@@ -35,7 +35,7 @@
 	ld a, [hl]
 	ld c, a
 	xor a
-	ld [$ffe0], a
+	ld [hUnlockedSilphCoDoors], a
 	pop hl
 .asm_5654d
 	ld a, [hli]
@@ -42,7 +42,7 @@
 	cp $ff
 	jr z, .asm_56569
 	push hl
-	ld hl, $ffe0
+	ld hl, hUnlockedSilphCoDoors
 	inc [hl]
 	pop hl
 	cp b
@@ -60,11 +60,11 @@
 	ret
 .asm_56569
 	xor a
-	ld [$ffe0], a
+	ld [hUnlockedSilphCoDoors], a
 	ret
 
 SilphCo8Script_5656d:
-	ld a, [$ffe0]
+	ld a, [hUnlockedSilphCoDoors]
 	and a
 	ret z
 	SetEvent EVENT_SILPH_CO_8_UNLOCKED_DOOR
--- a/scripts/SilphCo9F.asm
+++ b/scripts/SilphCo9F.asm
@@ -65,7 +65,7 @@
 	ld a, [hl]
 	ld c, a
 	xor a
-	ld [$ffe0], a
+	ld [hUnlockedSilphCoDoors], a
 	pop hl
 .asm_5d843
 	ld a, [hli]
@@ -72,7 +72,7 @@
 	cp $ff
 	jr z, .asm_5d85f
 	push hl
-	ld hl, $ffe0
+	ld hl, hUnlockedSilphCoDoors
 	inc [hl]
 	pop hl
 	cp b
@@ -90,12 +90,12 @@
 	ret
 .asm_5d85f
 	xor a
-	ld [$ffe0], a
+	ld [hUnlockedSilphCoDoors], a
 	ret
 
 SilphCo9Script_5d863:
 	EventFlagAddress hl, EVENT_SILPH_CO_9_UNLOCKED_DOOR1
-	ld a, [$ffe0]
+	ld a, [hUnlockedSilphCoDoors]
 	and a
 	ret z
 	cp $1
--- a/scripts/ViridianCity.asm
+++ b/scripts/ViridianCity.asm
@@ -59,14 +59,14 @@
 	ret
 
 ViridianCityScript1:
-	ld a, [wSpriteStateData1 + $34]
-	ld [$ffeb], a
-	ld a, [wSpriteStateData1 + $36]
-	ld [$ffec], a
-	ld a, [wSpriteStateData2 + $34]
-	ld [$ffed], a
-	ld a, [wSpriteStateData2 + $35]
-	ld [$ffee], a
+	ld a, [wSprite03StateData1YPixels]
+	ld [hSpriteScreenYCoord], a
+	ld a, [wSprite03StateData1XPixels]
+	ld [hSpriteScreenXCoord], a
+	ld a, [wSprite03StateData2MapY]
+	ld [hSpriteMapYCoord], a
+	ld a, [wSprite03StateData2MapX]
+	ld [hSpriteMapXCoord], a
 	xor a
 	ld [wListScrollOffset], a
 
@@ -82,14 +82,14 @@
 	ret
 
 ViridianCityScript2:
-	ld a, [$ffeb]
-	ld [wSpriteStateData1 + $34], a
-	ld a, [$ffec]
-	ld [wSpriteStateData1 + $36], a
-	ld a, [$ffed]
-	ld [wSpriteStateData2 + $34], a
-	ld a, [$ffee]
-	ld [wSpriteStateData2 + $35], a
+	ld a, [hSpriteScreenYCoord]
+	ld [wSprite03StateData1YPixels], a
+	ld a, [hSpriteScreenXCoord]
+	ld [wSprite03StateData1XPixels], a
+	ld a, [hSpriteMapYCoord]
+	ld [wSprite03StateData2MapY], a
+	ld a, [hSpriteMapXCoord]
+	ld [wSprite03StateData2MapX], a
 	call UpdateSprites
 	call Delay3
 	xor a
--- a/scripts/WardensHouse.asm
+++ b/scripts/WardensHouse.asm
@@ -32,7 +32,7 @@
 	ld hl, WardenTeethText1
 	call PrintText
 	ld a, GOLD_TEETH
-	ld [$ffdb], a
+	ld [hItemToRemoveID], a
 	callba RemoveItemByID
 	SetEvent EVENT_GAVE_GOLD_TEETH
 .asm_60cba
--- a/wram.asm
+++ b/wram.asm
@@ -1985,7 +1985,7 @@
 	ds 1
 
 wSpriteLoadFlags::
-; bit 0 determines used buffer (0 -> $a188, 1 -> $a310)
+; bit 0 determines used buffer (0 -> sSpriteBuffer1, 1 -> sSpriteBuffer2)
 ; bit 1 loading last sprite chunk? (there are at most 2 chunks per load operation)
 	ds 1
 wSpriteUnpackMode::