shithub: pokered

Download patch

ref: 93255d6d17fbb3702a0f8670d7ecc2ed627af2a7
parent: 7f6d0d49b61a77cfba76057d99881634b882486b
author: YamaArashi <shadow962@live.com>
date: Sat Jul 25 15:26:54 EDT 2015

yet more naming

--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -2310,7 +2310,7 @@
 	call GetItemName
 	call CopyStringToCF4B ; copy name
 	xor a
-	ld [wd152], a
+	ld [wPseudoItemID], a
 	call UseItem
 	call LoadHudTilePatterns
 	call ClearSprites
--- a/engine/hidden_object_functions17.asm
+++ b/engine/hidden_object_functions17.asm
@@ -349,12 +349,21 @@
 	add hl, de
 	ld a, [hli]
 
-	ld [$ffdb], a
+; There is a bug in this code. It should calculate a value in the range [0, 3]
+; but if the mask and random number don't have any 1 bits in common, then
+; the result of the AND will be 0. When 1 is subtracted from that, the value
+; will become $ff. This will result in 255 being added to hl, which will cause
+; hl to point to one of the zero bytes that pad the end of the ROM bank.
+; Trash can 0 was intended to be able to have the second lock only when the
+; first lock was in trash can 1 or 3. However, due to this bug, trash can 0 can
+; have the second lock regardless of which trash can had the first lock.
+
+	ld [hGymTrashCanRandNumMask], a
 	push hl
 	call Random
 	swap a
 	ld b, a
-	ld a, [$ffdb]
+	ld a, [hGymTrashCanRandNumMask]
 	and b
 	dec a
 	pop hl
@@ -398,6 +407,12 @@
 	jp PrintPredefTextID
 
 GymTrashCans: ; 5de7d (17:5e7d)
+; byte 0: mask for random number
+; bytes 1-4: indices of the trash cans that can have the second lock
+;            (but see the comment above explaining a bug regarding this)
+; Note that the mask is simply the number of valid trash can indices that
+; follow. The remaining bytes are filled with 0 to pad the length of each entry
+; to 5 bytes.
 	db 2,  1,  3,  0,  0 ; 0
 	db 3,  0,  2,  4,  0 ; 1
 	db 2,  1,  5,  0,  0 ; 2
--- a/engine/hidden_object_functions18.asm
+++ b/engine/hidden_object_functions18.asm
@@ -19,7 +19,7 @@
 	jr .loop
 .match
 	ld b, [hl]
-	ld a, [wd72a]
+	ld a, [wBeatGymFlags]
 	and b
 	cp b
 	tx_pre_id GymStatueText2
--- a/engine/hidden_object_functions7.asm
+++ b/engine/hidden_object_functions7.asm
@@ -125,11 +125,11 @@
 CinnabarGymQuiz: ; 1ea25 (7:6a25)
 	TX_ASM
 	xor a
-	ld [wda38], a
+	ld [wOpponentAfterWrongAnswer], a
 	ld a, [wHiddenObjectFunctionArgument]
 	push af
 	and $f
-	ld [$ffdb], a
+	ld [hGymGateIndex], a
 	pop af
 	and $f0
 	swap a
@@ -136,10 +136,10 @@
 	ld [$ffdc], a
 	ld hl, CinnabarGymQuizIntroText
 	call PrintText
-	ld a, [$ffdb]
+	ld a, [hGymGateIndex]
 	dec a
 	add a
-	ld d, $0
+	ld d, 0
 	ld e, a
 	ld hl, CinnabarQuizQuestions
 	add hl, de
@@ -198,10 +198,10 @@
 	ld c, a
 	ld a, [wCurrentMenuItem]
 	cp c
-	jr nz, .asm_1eab8
+	jr nz, .wrongAnswer
 	ld hl, wd126
 	set 5, [hl]
-	ld a, [$ffdb]
+	ld a, [hGymGateIndex]
 	ld [$ffe0], a
 	ld hl, CinnabarGymQuizCorrectText
 	call PrintText
@@ -211,7 +211,7 @@
 	ld b, FLAG_SET
 	call CinnabarGymGateFlagAction
 	jp UpdateCinnabarGymGateTileBlocks_
-.asm_1eab8
+.wrongAnswer
 	call WaitForSoundToFinish
 	ld a, SFX_DENIED
 	call PlaySound
@@ -218,7 +218,7 @@
 	call WaitForSoundToFinish
 	ld hl, CinnabarGymQuizIncorrectText
 	call PrintText
-	ld a, [$ffdb]
+	ld a, [hGymGateIndex]
 	add $2
 	AdjustEventBit EVENT_BEAT_CINNABAR_GYM_TRAINER_0, 2
 	ld c, a
@@ -228,9 +228,9 @@
 	ld a, c
 	and a
 	ret nz
-	ld a, [$ffdb]
+	ld a, [hGymGateIndex]
 	add $2
-	ld [wda38], a
+	ld [wOpponentAfterWrongAnswer], a
 	ret
 
 CinnabarGymQuizCorrectText: ; 1eae3 (7:6ae3)
@@ -261,9 +261,9 @@
 ; Update the overworld map with open floor blocks or locked gate blocks
 ; depending on event flags.
 	ld a, 6
-	ld [$ffdb], a
+	ld [hGymGateIndex], a
 .loop
-	ld a, [$ffdb]
+	ld a, [hGymGateIndex]
 	dec a
 	add a
 	add a
@@ -276,9 +276,9 @@
 	ld c, a
 	inc hl
 	ld a, [hl]
-	ld [wd12f], a
+	ld [wGymGateTileBlock], a
 	push bc
-	ld a, [$ffdb]
+	ld a, [hGymGateIndex]
 	ld [$ffe0], a
 	AdjustEventBit EVENT_CINNABAR_GYM_GATE0_UNLOCKED, 0
 	ld c, a
@@ -287,7 +287,7 @@
 	ld a, c
 	and a
 	jr nz, .unlocked
-	ld a, [wd12f]
+	ld a, [wGymGateTileBlock]
 	jr .next
 .unlocked
 	ld a, $e
@@ -295,7 +295,7 @@
 	pop bc
 	ld [wNewTileBlockID], a
 	predef ReplaceTileBlock
-	ld hl, $ffdb
+	ld hl, hGymGateIndex
 	dec [hl]
 	jr nz, .loop
 	ret
--- a/engine/items/items.asm
+++ b/engine/items/items.asm
@@ -628,7 +628,7 @@
 	ld a,[wWhichPokemon]
 	push af
 	ld a,[wcf91]
-	ld [wd156],a
+	ld [wEvoStoneItemID],a
 	push af
 	ld a,EVO_STONE_PARTY_MENU
 	ld [wPartyMenuTypeOrMessageID],a
@@ -679,7 +679,7 @@
 	ld [wPartyMenuTypeOrMessageID],a
 	ld a,$ff
 	ld [wUpdateSpritesEnabled],a
-	ld a,[wd152]
+	ld a,[wPseudoItemID]
 	and a ; using Softboiled?
 	jr z,.notUsingSoftboiled
 ; if using softboiled
@@ -712,7 +712,7 @@
 	ld [wcf91],a
 	pop af
 	ld [wWhichPokemon],a
-	ld a,[wd152]
+	ld a,[wPseudoItemID]
 	and a ; using Softboiled?
 	jr z,.checkItemType
 ; if using softboiled
@@ -865,7 +865,7 @@
 	ld [wHPBarMaxHP+1],a
 	ld a,[hl]
 	ld [wHPBarMaxHP],a ; max HP stored at wHPBarMaxHP (2 bytes, big-endian)
-	ld a,[wd152]
+	ld a,[wPseudoItemID]
 	and a ; using Softboiled?
 	jp z,.notUsingSoftboiled2
 ; if using softboiled
@@ -1052,7 +1052,7 @@
 	call ItemUseNoEffect
 	jp .done
 .doneHealing
-	ld a,[wd152]
+	ld a,[wPseudoItemID]
 	and a ; using Softboiled?
 	jr nz,.skipRemovingItem ; no item to remove if using Softboiled
 	push hl
@@ -1107,7 +1107,7 @@
 	pop af
 	pop af
 .done
-	ld a,[wd152]
+	ld a,[wPseudoItemID]
 	and a ; using Softboiled?
 	ret nz ; if so, return
 	call GBPalWhiteOut
@@ -1381,7 +1381,7 @@
 	inc a
 	ld [wEscapedFromBattle],a
 	ld [wActionResultOrTookBattleTurn],a ; item used
-	ld a,[wd152]
+	ld a,[wPseudoItemID]
 	and a ; using Dig?
 	ret nz ; if so, return
 	call ItemUseReloadOverworldData
@@ -1419,7 +1419,7 @@
 ; The Card Key is handled in a different way.
 ItemUseCardKey: ; e022 (3:6022)
 	xor a
-	ld [wd71f],a
+	ld [wUnusedD71F],a
 	call GetTileAndCoordsInFrontOfPlayer
 	ld a,[GetTileAndCoordsInFrontOfPlayer] ; $4586
 	cp a,$18
@@ -1451,7 +1451,7 @@
 	cp e
 	jr nz,.nextEntry3
 	ld a,[hl]
-	ld [wd71f],a
+	ld [wUnusedD71F],a
 	jr .done
 .nextEntry1
 	inc hl
--- a/engine/menu/main_menu.asm
+++ b/engine/menu/main_menu.asm
@@ -278,7 +278,7 @@
 	ld [wSerialExchangeNybbleSendData], a
 	inc a ; LINK_STATE_IN_CABLE_CLUB
 	ld [wLinkState], a
-	ld [wcc47], a
+	ld [wEnteringCableClub], a
 	jr SpecialEnterMap
 .choseCancel
 	xor a
@@ -322,7 +322,7 @@
 	call ResetPlayerSpriteData
 	ld c, 20
 	call DelayFrames
-	ld a, [wcc47]
+	ld a, [wEnteringCableClub]
 	and a
 	ret nz
 	jp EnterMap
--- a/engine/menu/party_menu.asm
+++ b/engine/menu/party_menu.asm
@@ -167,7 +167,7 @@
 	dec hl
 	dec hl
 	ld b,[hl]
-	ld a,[wd156] ; evolution stone item ID
+	ld a,[wEvoStoneItemID] ; the stone the player used
 	inc hl
 	inc hl
 	inc hl
--- a/engine/menu/prize_menu.asm
+++ b/engine/menu/prize_menu.asm
@@ -65,11 +65,11 @@
 ; (distinguishing between Pokemon names
 ; and Items (specifically TMs) names)
 	ld a,[hSpriteIndexOrTextID]
-	sub a,$03       ; prize-texts' id are 3, 4 and 5
-	ld [wd12f],a    ; prize-texts' id (relative, i.e. 0, 1 or 2)
+	sub a,3       ; prize-texts' id are 3, 4 and 5
+	ld [wWhichPrizeWindow],a    ; prize-texts' id (relative, i.e. 0, 1 or 2)
 	add a
 	add a
-	ld d,$00
+	ld d,0
 	ld e,a
 	ld hl,PrizeDifferentMenuPtrs
 	add hl,de
@@ -84,10 +84,10 @@
 	ld a,[hli]
 	ld h,[hl]
 	ld l,a
-	ld de,wd141
-	ld bc,$0006
+	ld de,wPrize1Price
+	ld bc,6
 	call CopyData
-	ld a,[wd12f]
+	ld a,[wWhichPrizeWindow]
 	cp a,$02        ;is TM_menu?
 	jr nz,.putMonName
 	ld a,[W_PRIZE1]
@@ -127,7 +127,7 @@
 	ld de,NoThanksText
 	call PlaceString
 ; put prices on the right side of the textbox
-	ld de,wd141
+	ld de,wPrize1Price
 	coord hl, 13, 5
 ; reg. c:
 ; [low nybble] number of bytes
@@ -136,11 +136,11 @@
 ; Function $15CD displays BCD value (same routine
 ; used by text-command $02)
 	call PrintBCDNumber
-	ld de,wd143
+	ld de,wPrize2Price
 	coord hl, 13, 7
 	ld c,(%1 << 7 | 2)
 	call PrintBCDNumber
-	ld de,wd145
+	ld de,wPrize3Price
 	coord hl, 13, 9
 	ld c,(1 << 7 | 2)
 	jp PrintBCDNumber
@@ -172,11 +172,11 @@
 	db "      @"
 
 LoadCoinsToSubtract: ; 528b1 (14:68b1)
-	ld a,[wd139] ; backup of selected menu_entry
+	ld a,[wWhichPrize]
 	add a
-	ld d,$00
+	ld d,0
 	ld e,a
-	ld hl,wd141 ; first prize's price
+	ld hl,wPrize1Price
 	add hl,de ; get selected prize's price
 	xor a
 	ld [hUnusedCoinsByte],a
@@ -187,15 +187,15 @@
 	ret
 
 HandlePrizeChoice: ; 528c6 (14:68c6)
-	ld a,[wCurrentMenuItem] ; selected menu_entry
-	ld [wd139],a
-	ld d,$00
+	ld a,[wCurrentMenuItem]
+	ld [wWhichPrize],a
+	ld d,0
 	ld e,a
 	ld hl,W_PRIZE1
 	add hl,de
 	ld a,[hl]
 	ld [wd11e],a
-	ld a,[wd12f]
+	ld a,[wWhichPrizeWindow]
 	cp a,$02 ; is prize a TM?
 	jr nz,.GetMonName
 	call GetItemName
@@ -205,7 +205,7 @@
 .GivePrize
 	ld hl,SoYouWantPrizeTextPtr
 	call PrintText
-	call YesNoChoice ; yes/no textbox
+	call YesNoChoice
 	ld a,[wCurrentMenuItem] ; yes/no answer (Y=0, N=1)
 	and a
 	jr nz,.PrintOhFineThen
@@ -212,7 +212,7 @@
 	call LoadCoinsToSubtract
 	call HasEnoughCoins
 	jr c,.NotEnoughCoins
-	ld a,[wd12f]
+	ld a,[wWhichPrizeWindow]
 	cp a,$02
 	jr nz,.GiveMon
 	ld a,[wd11e]
--- a/engine/menu/start_sub_menus.asm
+++ b/engine/menu/start_sub_menus.asm
@@ -167,7 +167,7 @@
 	jp z,.loop
 	ld a,SURFBOARD
 	ld [wcf91],a
-	ld [wd152],a
+	ld [wPseudoItemID],a
 	call UseItem
 	ld a,[wActionResultOrTookBattleTurn]
 	and a
@@ -195,7 +195,7 @@
 .dig
 	ld a,ESCAPE_ROPE
 	ld [wcf91],a
-	ld [wd152],a
+	ld [wPseudoItemID],a
 	call UseItem
 	ld a,[wActionResultOrTookBattleTurn]
 	and a
@@ -260,7 +260,7 @@
 	push af
 	ld a,POTION
 	ld [wcf91],a
-	ld [wd152],a
+	ld [wPseudoItemID],a
 	call UseItem
 	pop af
 	ld [wPartyAndBillsPCSavedMenuItem],a
@@ -381,8 +381,8 @@
 	ld a,[wCurrentMenuItem]
 	and a
 	jr nz,.tossItem
-.useItem
-	ld [wd152],a
+; use item
+	ld [wPseudoItemID],a ; a must be 0 due to above conditional jump
 	ld a,[wcf91]
 	cp a,HM_01
 	jr nc,.useItem_partyMenu
@@ -399,7 +399,7 @@
 	jp ItemMenuLoop
 .useItem_closeMenu
 	xor a
-	ld [wd152],a
+	ld [wPseudoItemID],a
 	call UseItem
 	ld a,[wActionResultOrTookBattleTurn]
 	and a
--- a/engine/overworld/npc_movement.asm
+++ b/engine/overworld/npc_movement.asm
@@ -178,7 +178,7 @@
 	dec a
 	ld [wSimulatedJoypadStatesIndex], a
 	xor a
-	ld [wd12f], a
+	ld [wWhichPewterGuy], a
 	predef PewterGuys
 	ld hl, wNPCMovementDirections2
 	ld de, RLEList_PewterMuseumGuy
@@ -234,8 +234,8 @@
 	call DecodeRLEList
 	dec a
 	ld [wSimulatedJoypadStatesIndex], a
-	ld a, $1
-	ld [wd12f], a
+	ld a, 1
+	ld [wWhichPewterGuy], a
 	predef PewterGuys
 	ld hl, wNPCMovementDirections2
 	ld de, RLEList_PewterGymGuy
--- a/engine/overworld/pewter_guys.asm
+++ b/engine/overworld/pewter_guys.asm
@@ -9,7 +9,7 @@
 	ld d, h
 	ld e, l
 	ld hl, PointerTable_37ce6
-	ld a, [wd12f]
+	ld a, [wWhichPewterGuy]
 	add a
 	ld b, 0
 	ld c, a
@@ -21,17 +21,17 @@
 	ld b, a
 	ld a, [W_XCOORD]
 	ld c, a
-.asm_37cc7
+.findMatchingCoordsLoop
 	ld a, [hli]
 	cp b
-	jr nz, .asm_37ce1
+	jr nz, .nextEntry1
 	ld a, [hli]
 	cp c
-	jr nz, .asm_37ce2
+	jr nz, .nextEntry2
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
-.asm_37cd2
+.copyMovementDataLoop
 	ld a, [hli]
 	cp $ff
 	ret z
@@ -40,13 +40,13 @@
 	ld a, [wSimulatedJoypadStatesIndex]
 	inc a
 	ld [wSimulatedJoypadStatesIndex], a
-	jr .asm_37cd2
-.asm_37ce1
+	jr .copyMovementDataLoop
+.nextEntry1
 	inc hl
-.asm_37ce2
+.nextEntry2
 	inc hl
 	inc hl
-	jr .asm_37cc7
+	jr .findMatchingCoordsLoop
 
 PointerTable_37ce6: ; 37ce6 (d:7ce6)
 	dw PewterMuseumGuyCoords
--- a/engine/overworld/trainers.asm
+++ b/engine/overworld/trainers.asm
@@ -24,16 +24,16 @@
 	ld [H_SPRITEINDEX], a
 	call GetSpriteDataPointer
 	ld a, [hli] ; c1x4 (screen Y pos)
-	ld [wd130], a
+	ld [wSavedSpriteScreenY], a
 	inc hl
 	ld a, [hl] ; c1x6 (screen X pos)
-	ld [wd131], a
+	ld [wSavedSpriteScreenX], a
 	ld de, $104 - $6
 	add hl, de
 	ld a, [hli] ; c2x4 (map Y pos)
-	ld [wd132], a
+	ld [wSavedSpriteMapY], a
 	ld a, [hl] ; c2x5 (map X pos)
-	ld [wd133], a
+	ld [wSavedSpriteMapX], a
 	ret
 
 _SetSpritePosition1: ; 5683d (15:683d)
@@ -61,16 +61,16 @@
 	ld a, [wSpriteIndex]
 	ld [H_SPRITEINDEX], a
 	call GetSpriteDataPointer
-	ld a, [wd130]
+	ld a, [wSavedSpriteScreenY]
 	ld [hli], a
 	inc hl
-	ld a, [wd131]
+	ld a, [wSavedSpriteScreenX]
 	ld [hl], a
 	ld de, $00fe
 	add hl, de
-	ld a, [wd132]
+	ld a, [wSavedSpriteMapY]
 	ld [hli], a
-	ld a, [wd133]
+	ld a, [wSavedSpriteMapX]
 	ld [hl], a
 	ret
 
--- a/home.asm
+++ b/home.asm
@@ -1144,7 +1144,7 @@
 	jr nz,HoldTextDisplayOpen
 
 AfterDisplayingTextID:: ; 29d6 (0:29d6)
-	ld a,[wcc47]
+	ld a,[wEnteringCableClub]
 	and a
 	jr nz,HoldTextDisplayOpen
 	call WaitForTextScrollButtonPress ; wait for a button press after displaying all the text
@@ -4162,7 +4162,7 @@
 
 ; The following code either enables or disables the automatic drawing of
 ; text boxes by DisplayTextID. Both functions cause DisplayTextID to wait
-; for a button press after displaying text (unless [wcc47] is set).
+; for a button press after displaying text (unless [wEnteringCableClub] is set).
 
 EnableAutoTextBoxDrawing:: ; 3c3c (0:3c3c)
 	xor a
--- a/home/overworld.asm
+++ b/home/overworld.asm
@@ -106,13 +106,14 @@
 	aCoord 8, 9
 	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 [wDestinationMap],a
@@ -470,9 +471,9 @@
 WarpFound2:: ; 073c (0:073c)
 	ld a,[wNumberOfWarps]
 	sub c
-	ld [wd73b],a ; save ID of used warp
+	ld [wWarpedFromWhichWarp],a ; save ID of used warp
 	ld a,[W_CURMAP]
-	ld [wd73c],a
+	ld [wWarpedFromWhichMap],a
 	call CheckIfInOutsideMap
 	jr nz,.indoorMaps
 ; this is for handling "outside" maps that can't have the 0xFF destination map
@@ -479,7 +480,7 @@
 	ld a,[W_CURMAP]
 	ld [wLastMap],a
 	ld a,[W_CURMAPWIDTH]
-	ld [wd366],a
+	ld [wUnusedD366],a ; not read
 	ld a,[hWarpDestinationMap]
 	ld [W_CURMAP],a
 	cp a,ROCK_TUNNEL_1
--- a/home/text.asm
+++ b/home/text.asm
@@ -376,9 +376,9 @@
 	xor e
 	ld [wLetterPrintingDelayFlags],a
 	ld a,c
-	ld [wcc3a],a
+	ld [wUnusedCC3A],a
 	ld a,b
-	ld [wcc3b],a
+	ld [wUnusedCC3B],a
 
 NextTextCommand:: ; 1b55 (0:1b55)
 	ld a,[hli]
@@ -487,10 +487,10 @@
 TextCommand03:: ; 1bb7 (0:1bb7)
 	pop hl
 	ld a,[hli]
-	ld [wcc3a],a
+	ld [wUnusedCC3A],a
 	ld c,a
 	ld a,[hli]
-	ld [wcc3b],a
+	ld [wUnusedCC3B],a
 	ld b,a
 	jp NextTextCommand
 
--- a/hram.asm
+++ b/hram.asm
@@ -265,6 +265,10 @@
 
 hFossilCounter EQU $FFDB
 
+hGymGateIndex EQU $FFDB
+
+hGymTrashCanRandNumMask EQU $FFDB
+
 hItemToRemoveID    EQU $FFDB
 hItemToRemoveIndex EQU $FFDC
 
--- a/main.asm
+++ b/main.asm
@@ -687,9 +687,9 @@
 	ld a, [wWhichDungeonWarp]
 	ld c, a
 	ld hl, DungeonWarpList
-	ld de, $0
-	ld a, $6
-	ld [wd12f], a
+	ld de, 0
+	ld a, 6
+	ld [wDungeonWarpDataEntrySize], a
 .dungeonWarpListLoop
 	ld a, [hli]
 	cp b
@@ -701,7 +701,7 @@
 	cp c
 	jr z, .matchedDungeonWarpID
 .nextDungeonWarp
-	ld a, [wd12f]
+	ld a, [wDungeonWarpDataEntrySize]
 	add e
 	ld e, a
 	jr .dungeonWarpListLoop
@@ -2063,7 +2063,7 @@
 	ld [hJoyReleased], a
 	ld [hJoyHeld], a
 	ld [wActionResultOrTookBattleTurn], a
-	ld [wd5a3], a
+	ld [wUnusedD5A3], a
 	ld hl, wCardKeyDoorY
 	ld [hli], a
 	ld [hl], a
@@ -3640,8 +3640,8 @@
 	ld b, FLAG_TEST
 	ld hl, wPokedexOwned
 	call FlagAction
-	ld a, c
-	ld [wd153], a
+	ld a, c ; whether the mon was already flagged as owned
+	ld [wUnusedD153], a ; not read
 	ld a, [wd11e]
 	dec a
 	ld c, a
@@ -4463,7 +4463,7 @@
 	ld [wPlayerID + 1], a
 
 	ld a, $ff
-	ld [wd71b], a                 ; XXX what's this?
+	ld [wUnusedD71B], a
 
 	ld hl, wPartyCount
 	call InitializeEmptyList
--- a/scripts/celadongym.asm
+++ b/scripts/celadongym.asm
@@ -62,7 +62,7 @@
 .asm_4898c
 	ld hl, W_OBTAINEDBADGES
 	set 3, [hl]
-	ld hl, wd72a
+	ld hl, wBeatGymFlags
 	set 3, [hl]
 
 	; deactivate gym trainers
--- a/scripts/celadonmartelevator.asm
+++ b/scripts/celadonmartelevator.asm
@@ -16,9 +16,9 @@
 
 CeladonMartElevatorScript_4861c: ; 4861c (12:461c)
 	ld hl, wWarpEntries
-	ld a, [wd73b]
+	ld a, [wWarpedFromWhichWarp]
 	ld b, a
-	ld a, [wd73c]
+	ld a, [wWarpedFromWhichMap]
 	ld c, a
 	call CeladonMartElevatorScript_4862a
 
--- a/scripts/ceruleangym.asm
+++ b/scripts/ceruleangym.asm
@@ -62,7 +62,7 @@
 .asm_5c736
 	ld hl, W_OBTAINEDBADGES
 	set 1, [hl]
-	ld hl, wd72a
+	ld hl, wBeatGymFlags
 	set 1, [hl]
 
 	; deactivate gym trainers
--- a/scripts/cinnabargym.asm
+++ b/scripts/cinnabargym.asm
@@ -32,7 +32,7 @@
 	ld [wJoyIgnore], a
 	ld [W_CINNABARGYMCURSCRIPT], a
 	ld [W_CURMAPSCRIPT], a
-	ld [wda38], a
+	ld [wOpponentAfterWrongAnswer], a
 	ret
 
 CinnabarGymScript_757a0: ; 757a0 (1d:57a0)
@@ -47,7 +47,7 @@
 	dw CinnabarGymScript3
 
 CinnabarGymScript0: ; 757ae (1d:57ae)
-	ld a, [wda38]
+	ld a, [wOpponentAfterWrongAnswer]
 	and a
 	ret z
 	ld [H_SPRITEINDEX], a
@@ -83,7 +83,7 @@
 	ret nz
 	xor a
 	ld [wJoyIgnore], a
-	ld a, [wda38]
+	ld a, [wOpponentAfterWrongAnswer]
 	ld [wTrainerHeaderFlagBit], a
 	ld [hSpriteIndexOrTextID], a
 	jp DisplayTextID
@@ -127,7 +127,7 @@
 	call UpdateCinnabarGymGateTileBlocks
 	xor a
 	ld [wJoyIgnore], a
-	ld [wda38], a
+	ld [wOpponentAfterWrongAnswer], a
 	ld a, $0
 	ld [W_CINNABARGYMCURSCRIPT], a
 	ld [W_CURMAPSCRIPT], a
@@ -159,7 +159,7 @@
 .asm_75880
 	ld hl, W_OBTAINEDBADGES
 	set 6, [hl]
-	ld hl, wd72a
+	ld hl, wBeatGymFlags
 	set 6, [hl]
 
 	; deactivate gym trainers
--- a/scripts/fuchsiagym.asm
+++ b/scripts/fuchsiagym.asm
@@ -62,7 +62,7 @@
 .asm_754c0
 	ld hl, W_OBTAINEDBADGES
 	set 4, [hl]
-	ld hl, wd72a
+	ld hl, wBeatGymFlags
 	set 4, [hl]
 
 	; deactivate gym trainers
--- a/scripts/oakslab.asm
+++ b/scripts/oakslab.asm
@@ -522,11 +522,11 @@
 	ld [wMissableObjectIndex], a
 	predef ShowObject
 	ld a, [wNPCMovementDirections2Index]
-	ld [wd157], a
-	ld b, $0
+	ld [wSavedNPCMovementDirections2Index], a
+	ld b, 0
 	ld c, a
 	ld hl, wNPCMovementDirections2
-	ld a, $40
+	ld a, NPC_MOVEMENT_UP
 	call FillMemory
 	ld [hl], $ff
 	ld a, $1
@@ -604,11 +604,11 @@
 	ld a, HS_OLD_MAN
 	ld [wMissableObjectIndex], a
 	predef ShowObject
-	ld a, [wd157]
-	ld b, $0
+	ld a, [wSavedNPCMovementDirections2Index]
+	ld b, 0
 	ld c, a
 	ld hl, wNPCMovementDirections2
-	xor a
+	xor a ; NPC_MOVEMENT_DOWN
 	call FillMemory
 	ld [hl], $ff
 	ld a, $ff
--- a/scripts/pewtergym.asm
+++ b/scripts/pewtergym.asm
@@ -62,7 +62,7 @@
 .asm_5c408
 	ld hl, W_OBTAINEDBADGES
 	set 0, [hl]
-	ld hl, wd72a
+	ld hl, wBeatGymFlags
 	set 0, [hl]
 
 	ld a, HS_GYM_GUY
@@ -183,7 +183,7 @@
 
 PewterGymText3: ; 5c4df (17:44df)
 	TX_ASM
-	ld a, [wd72a]
+	ld a, [wBeatGymFlags]
 	bit 0, a
 	jr nz, .asm_5c50c
 	ld hl, PewterGymText_5c515
--- a/scripts/pokemontower7.asm
+++ b/scripts/pokemontower7.asm
@@ -57,7 +57,7 @@
 	ld [wJoyIgnore], a
 	ld [wSpriteIndex], a
 	ld [wTrainerHeaderFlagBit], a
-	ld [wda38], a
+	ld [wUnusedDA38], a
 	ld a, $0
 	ld [W_POKEMONTOWER7CURSCRIPT], a
 	ld [W_CURMAPSCRIPT], a
--- a/scripts/rockethideoutelevator.asm
+++ b/scripts/rockethideoutelevator.asm
@@ -16,9 +16,9 @@
 
 RocketHideoutElevatorScript_4572c: ; 4572c (11:572c)
 	ld hl, wWarpEntries
-	ld a, [wd73b]
+	ld a, [wWarpedFromWhichWarp]
 	ld b, a
-	ld a, [wd73c]
+	ld a, [wWarpedFromWhichMap]
 	ld c, a
 	call RocketHideoutElevatorScript_4573a
 
--- a/scripts/saffrongym.asm
+++ b/scripts/saffrongym.asm
@@ -62,7 +62,7 @@
 .asm_5d091
 	ld hl, W_OBTAINEDBADGES
 	set 5, [hl]
-	ld hl, wd72a
+	ld hl, wBeatGymFlags
 	set 5, [hl]
 
 	; deactivate gym trainers
--- a/scripts/seafoamislands5.asm
+++ b/scripts/seafoamislands5.asm
@@ -35,12 +35,12 @@
 	ld a, [wCoordIndex]
 	cp $3
 	jr nc, .asm_467e6
-	ld a, $40
-	ld [wccd4], a
-	ld a, $2
+	ld a, NPC_MOVEMENT_UP
+	ld [wSimulatedJoypadStatesEnd + 1], a
+	ld a, 2
 	jr .asm_467e8
 .asm_467e6
-	ld a, $1
+	ld a, 1
 .asm_467e8
 	ld [wSimulatedJoypadStatesIndex], a
 	ld a, D_UP
--- a/scripts/silphcoelevator.asm
+++ b/scripts/silphcoelevator.asm
@@ -16,9 +16,9 @@
 
 SilphCoElevatorScript_457dc: ; 457dc (11:57dc)
 	ld hl, wWarpEntries
-	ld a, [wd73b]
+	ld a, [wWarpedFromWhichWarp]
 	ld b, a
-	ld a, [wd73c]
+	ld a, [wWarpedFromWhichMap]
 	ld c, a
 	call SilphCoElevatorScript_457ea
 
--- a/scripts/vermilioncity.asm
+++ b/scripts/vermilioncity.asm
@@ -84,8 +84,8 @@
 	ld [wJoyIgnore], a
 	ld a, D_UP
 	ld [wSimulatedJoypadStatesEnd], a
-	ld [wccd4], a
-	ld a, $2
+	ld [wSimulatedJoypadStatesEnd + 1], a
+	ld a, 2
 	ld [wSimulatedJoypadStatesIndex], a
 	call StartSimulatingJoypadStates
 	ld a, $3
--- a/scripts/vermiliongym.asm
+++ b/scripts/vermiliongym.asm
@@ -81,7 +81,7 @@
 .asm_5cad3
 	ld hl, W_OBTAINEDBADGES
 	set 2, [hl]
-	ld hl, wd72a
+	ld hl, wBeatGymFlags
 	set 2, [hl]
 
 	; deactivate gym trainers
@@ -247,7 +247,7 @@
 
 VermilionGymText5: ; 5cbdb (17:4bdb)
 	TX_ASM
-	ld a, [wd72a]
+	ld a, [wBeatGymFlags]
 	bit 2, a
 	jr nz, .asm_5cbeb
 	ld hl, VermilionGymText_5cbf4
--- a/scripts/viridiangym.asm
+++ b/scripts/viridiangym.asm
@@ -156,7 +156,7 @@
 .asm_749be
 	ld hl, W_OBTAINEDBADGES
 	set 7, [hl]
-	ld hl, wd72a
+	ld hl, wBeatGymFlags
 	set 7, [hl]
 
 	; deactivate gym trainers
--- a/wram.asm
+++ b/wram.asm
@@ -295,10 +295,12 @@
 
 	ds 1
 
-; group these two together
-wcc3a:: ds 1 ; both used in home/text.asm
-wcc3b:: ds 1
+wUnusedCC3A:: ; cc3a
+	ds 1
 
+wUnusedCC3B:: ; cc3b
+	ds 1
+
 wDoNotWaitForButtonPressAfterDisplayingText:: ; cc3c
 ; if non-zero, skip waiting for a button press after displaying text in DisplayTextID
 	ds 1
@@ -312,9 +314,8 @@
 wLinkMenuSelectionReceiveBuffer:: ; cc3d
 ; two byte buffer
 ; the received menu selection is stored twice
+	ds 1
 
-wcc3d:: ds 1 ; not used for anything other than mentioned above (haha link function)
-
 wSerialExchangeNybbleReceiveData:: ; cc3e
 ; the final received nybble is stored here by Serial_ExchangeNybble
 	ds 1
@@ -336,9 +337,11 @@
 wUnknownSerialCounter:: ; cc47
 ; 2 bytes
 
-wcc47:: ds 1 ; used in text id stuff
-wcc48:: ds 1 ; part of wUnknownSerialCounter
+wEnteringCableClub:: ; cc47
+	ds 1
 
+	ds 1
+
 wWhichTradeMonSelectionMenu:: ; cc49
 ; $00 = player mons
 ; $01 = enemy mons
@@ -412,10 +415,8 @@
 ; ROM back to return to when the player is done with the slot machine
 	ds 1
 
-	ds 12
+	ds 26
 
-wcc6b:: ds 14 ; doesn't seem to be used for anything, probably just more storage
-
 wAnimPalette:: ; cc79
 	ds 1
 
@@ -452,8 +453,8 @@
 ; Other methods of evolution simply set it by calling TryEvolvingMon.
 	ds 1
 
-wForceEvolution::
-wccd4:: ds 1 ; has a direct reference for simulated joypad stuff in vermillion and seafoam
+wForceEvolution:: ; ccd4
+	ds 1
 
 ; if [ccd5] != 1, the second AI layer is not applied
 wAILayer2Encouragement:: ; ccd5
@@ -1942,13 +1943,37 @@
 ; $02 = the user pressed B or pressed A with the second menu item selected
 	ds 1
 
-wd12f:: ds 1 ; used in some coordinatestuff, npc pathstuff, and game corner prize stuff
-wd130:: ds 1 ; saved value of screen Y coord of trainer sprite
-wd131:: ds 1 ; saved value of screen X coord of trainer sprite
-wd132:: ds 1 ; saved value of map Y coordinate of trainer sprite (not sure for purpose)
-wd133:: ds 6 ; saved value of map X coordinate of trainer sprite
-wd139:: ds 1 ; backup of selected menu entry for game corner prizes
+wDungeonWarpDataEntrySize:: ; d12f
+; the size is always 6, so they didn't need a variable in RAM for this
 
+wWhichPewterGuy:: ; d12f
+; 0 = museum guy
+; 1 = gym guy
+
+wWhichPrizeWindow:: ; d12f
+; there are 3 windows, from 0 to 2
+
+wGymGateTileBlock:: ; d12f
+; a horizontal or vertical gate block
+	ds 1
+
+wSavedSpriteScreenY:: ; d130
+	ds 1
+
+wSavedSpriteScreenX:: ; d131
+	ds 1
+
+wSavedSpriteMapY:: ; d132
+	ds 1
+
+wSavedSpriteMapX:: ; d133
+	ds 1
+
+	ds 5
+
+wWhichPrize:: ; d139
+	ds 1
+
 wIgnoreInputCounter:: ; d13a
 ; counts downward each frame
 ; when it hits 0, bit 5 (ignore input bit) of wd730 is reset
@@ -1974,10 +1999,17 @@
 wSerialRandomNumberListBlock:: ; d141
 ; the first 7 bytes are the preamble
 
-wd141:: ds 2 ; prices for prizes
-wd143:: ds 2 ; prices for prizes
-wd145:: ds 3 ; prices for prizes
+wPrize1Price:: ; d141
+	ds 2
 
+wPrize2Price:: ; d143
+	ds 2
+
+wPrize3Price:: ; d145
+	ds 2
+
+	ds 1
+
 wLinkBattleRandomNumberList:: ; d148
 ; shared list of 9 random numbers, indexed by wLinkBattleRandomNumberListIndex
 	ds 10
@@ -1985,12 +2017,24 @@
 wSerialPlayerDataBlock:: ; d152
 ; the first 6 bytes are the preamble
 
-wd152:: ds 1 ; used as a temporary storage for the item used
-wd153:: ds 3 ; written to during pokedex flag action but doesn't seem to be read from
-wd156:: ds 1 ; evolution stone ID used
-wd157:: ds 1 ; used with oak's lab script (related to npc movement directions), possibly indirectly accessed with values below
+wPseudoItemID:: ; d152
+; When a real item is being used, this is 0.
+; When a move is acting as an item, this is the ID of the item it's acting as.
+; For example, out-of-battle Dig is executed using a fake Escape Rope item. In
+; that case, this would be ESCAPE_ROPE.
+	ds 1
 
+wUnusedD153:: ; d153
+	ds 1
 
+	ds 2
+
+wEvoStoneItemID:: ; d156
+	ds 1
+
+wSavedNPCMovementDirections2Index:: ; d157
+	ds 1
+
 wPlayerName:: ; d158
 	ds 11
 
@@ -2092,7 +2136,8 @@
 wLastMap:: ; d365
 	ds 1
 
-wd366:: ds 1 ; W_CURMAPWIDTH of the last outdoor map visited when entering an inside map
+wUnusedD366:: ; d366
+	ds 1
 
 W_CURMAPTILESET:: ; d367
 	ds 1
@@ -2344,7 +2389,8 @@
 ; number of HOF teams
 	ds 1
 
-wd5a3:: ds 1 ; unused? (written to when loading map data)
+wUnusedD5A3:: ; d5a3
+	ds 1
 
 wPlayerCoins:: ; d5a4
 	ds 2 ; BCD
@@ -2635,7 +2681,8 @@
 ; destination map (for certain types of special warps, not ordinary walking)
 	ds 1
 
-wd71b:: ds 1 ; written to but doesn't seem to be read
+wUnusedD71B:: ; d71b
+	ds 1
 
 wTileInFrontOfBoulderAndBoulderCollisionResult:: ; d71c
 ; used to store the tile in front of the boulder when trying to push a boulder
@@ -2650,8 +2697,11 @@
 ; which dungeon warp within the source map was used
 	ds 1
 
-wd71f:: ds 9 ; used with card key
+wUnusedD71F:: ; d71f
+	ds 1
 
+	ds 8
+
 wd728::
 ; bit 0: using Strength outside of battle
 	ds 1
@@ -2658,8 +2708,13 @@
 
 	ds 1
 
-wd72a:: ds 2 ; flags for if a gym is beaten, also used to determine whether to display your name on the gym statues
+wBeatGymFlags:: ; d72a
+; redundant because it matches W_OBTAINEDBADGES
+; used to determine whether to show name on statue and in two NPC text scripts
+	ds 1
 
+	ds 1
+
 wd72c:: ; d72c
 ; bit 0: if not set, the 3 minimum steps between random battles have passed
 	ds 1
@@ -2717,9 +2772,14 @@
 
 	ds 2
 
-wd73b:: ds 1 ; used with elevator warps
-wd73c:: ds 3 ; also used with elevator warps
+wWarpedFromWhichWarp:: ; d73b
+	ds 1
 
+wWarpedFromWhichMap:: ; d73c
+	ds 1
+
+	ds 2
+
 wCardKeyDoorY:: ; d73f
 	ds 1
 
@@ -2767,7 +2827,12 @@
 
 	ds 6
 
-wda38:: ds 1 ; used with cinnabar gym questions and pokemon tower 7F?
+wOpponentAfterWrongAnswer:: ; da38
+; the trainer the player must face after getting a wrong answer in the Cinnabar
+; gym quiz
+
+wUnusedDA38:: ; da38
+	ds 1
 
 W_CURMAPSCRIPT:: ; da39
 ; index of current map script, mostly used as index for function pointer array