shithub: pokered

Download patch

ref: 1a987d1e1ab96ca9553d4253c72858057332a03a
parent: fb0a630c062cbb18026abe2792339dea27fac4d8
parent: 696cffd3ae51d23855a7eb1fc5b62e69198dbf36
author: Daniel Harding <corrnondacqb@yahoo.com>
date: Tue Aug 18 06:32:50 EDT 2015

Merge pull request #114 from YamaArashi/master

Commented SGB palettes and other things

--- a/constants/connection_constants.asm
+++ b/constants/connection_constants.asm
@@ -1,3 +1,7 @@
+; width of east/west connections
+; height of north/south connections
+MAP_BORDER EQU 3
+
 ; connection directions
 EAST  EQU 1
 WEST  EQU 2
--- a/constants/misc_constants.asm
+++ b/constants/misc_constants.asm
@@ -15,6 +15,7 @@
 HOF_TEAM_CAPACITY EQU 50
 
 NAME_LENGTH EQU 11
+ITEM_NAME_LENGTH EQU 13
 
 A_BUTTON EQU %00000001
 B_BUTTON EQU %00000010
@@ -25,14 +26,15 @@
 D_UP     EQU %01000000
 D_DOWN   EQU %10000000
 
-PIXELS_PER_TILE EQU 8
-
 SCREEN_WIDTH  EQU 20
 SCREEN_HEIGHT EQU 18
 
-SCREEN_WIDTH_PIXELS  EQU SCREEN_WIDTH * PIXELS_PER_TILE
-SCREEN_HEIGHT_PIXELS EQU SCREEN_HEIGHT * PIXELS_PER_TILE
+SCREEN_WIDTH_PIXELS  EQU SCREEN_WIDTH * 8
+SCREEN_HEIGHT_PIXELS EQU SCREEN_HEIGHT * 8
 
+BG_MAP_WIDTH  EQU 32
+BG_MAP_HEIGHT EQU 32
+
 NPC_MOVEMENT_DOWN  EQU $00
 NPC_MOVEMENT_UP    EQU $40
 NPC_MOVEMENT_LEFT  EQU $80
@@ -158,6 +160,14 @@
 
 LEFT_ALIGN EQU     (1 << BIT_LEFT_ALIGN)
 LEADING_ZEROES EQU (1 << BIT_LEADING_ZEROES)
+
+; HP bar
+HP_BAR_GREEN  EQU 0
+HP_BAR_YELLOW EQU 1
+HP_BAR_RED    EQU 2
+
+; D733 flags
+BIT_TEST_BATTLE EQU 0
 
 ; serial
 
--- a/constants/palette_constants.asm
+++ b/constants/palette_constants.asm
@@ -1,3 +1,19 @@
+SET_PAL_BATTLE_BLACK         EQU $00
+SET_PAL_BATTLE               EQU $01
+SET_PAL_TOWN_MAP             EQU $02
+SET_PAL_STATUS_SCREEN        EQU $03
+SET_PAL_POKEDEX              EQU $04
+SET_PAL_SLOTS                EQU $05
+SET_PAL_TITLE_SCREEN         EQU $06
+SET_PAL_NIDORINO_INTRO       EQU $07
+SET_PAL_GENERIC              EQU $08
+SET_PAL_OVERWORLD            EQU $09
+SET_PAL_PARTY_MENU           EQU $0A
+SET_PAL_POKEMON_WHOLE_SCREEN EQU $0B
+SET_PAL_GAME_FREAK_INTRO     EQU $0C
+SET_PAL_TRAINER_CARD         EQU $0D
+UPDATE_PARTY_MENU_BLK_PACKET EQU $FC
+
 ; super game boy palettes
 const_value = 0
 
--- a/data/sgb_packets.asm
+++ b/data/sgb_packets.asm
@@ -60,11 +60,11 @@
 
 BlkPacket_Battle: ; 721b5 (1c:61b5)
 	ATTR_BLK 5
-	ATTR_BLK_DATA %111, 2,2,0, 00,12, 19,17
-	ATTR_BLK_DATA %011, 1,1,0, 01,00, 10,03
-	ATTR_BLK_DATA %011, 0,0,0, 10,07, 19,10
-	ATTR_BLK_DATA %011, 2,2,0, 00,04, 08,11
-	ATTR_BLK_DATA %011, 3,3,0, 11,00, 19,06
+	ATTR_BLK_DATA %111, 2,2,0, 00,12, 19,17 ; message box: pal 2
+	ATTR_BLK_DATA %011, 1,1,0, 01,00, 10,03 ; enemy HP bar: pal 1
+	ATTR_BLK_DATA %011, 0,0,0, 10,07, 19,10 ; player HP bar: pal 0
+	ATTR_BLK_DATA %011, 2,2,0, 00,04, 08,11 ; player mon: pal 2
+	ATTR_BLK_DATA %011, 3,3,0, 11,00, 19,06 ; enemy mon : pal 3
 
 	db $03,$00,$00,$13,$0b,$00
 	db $03,$00,$0c,$13,$11,$02
@@ -76,7 +76,7 @@
 
 BlkPacket_StatusScreen: ; 721fa (1c:61fa)
 	ATTR_BLK 1
-	ATTR_BLK_DATA %111, 1,1,0, 01,00, 07,06
+	ATTR_BLK_DATA %111, 1,1,0, 01,00, 07,06 ; mon: pal 1, HP bar: pal 0
 	ds 8
 
 	db $02,$00,$00,$11,$00,$03
@@ -86,7 +86,7 @@
 
 BlkPacket_Pokedex: ; 72222 (1c:6222)
 	ATTR_BLK 1
-	ATTR_BLK_DATA %111, 1,1,0, 01,01, 08,08
+	ATTR_BLK_DATA %111, 1,1,0, 01,01, 08,08 ; mon: pal 1, everything else: pal 0
 	ds 8
 
 	db $02,$00,$00,$11,$00,$01
@@ -97,11 +97,11 @@
 
 BlkPacket_Slots: ; 7224f (1c:624f)
 	ATTR_BLK 5
-	ATTR_BLK_DATA %011, 1,1,0, 00,00, 19,11
-	ATTR_BLK_DATA %011, 2,2,0, 00,04, 19,09
-	ATTR_BLK_DATA %010, 3,3,0, 00,06, 19,07
-	ATTR_BLK_DATA %011, 0,0,0, 04,04, 15,09
-	ATTR_BLK_DATA %011, 0,0,0, 00,12, 19,17
+	ATTR_BLK_DATA %011, 1,1,0, 00,00, 19,11 ; "3" rows and top of screen: pal 1
+	ATTR_BLK_DATA %011, 2,2,0, 00,04, 19,09 ; "2" rows: pal 2
+	ATTR_BLK_DATA %010, 3,3,0, 00,06, 19,07 ; "1" row: pal 3
+	ATTR_BLK_DATA %011, 0,0,0, 04,04, 15,09 ; slot reels: pal 0
+	ATTR_BLK_DATA %011, 0,0,0, 00,12, 19,17 ; message box: pal 0
 
 	db $03,$00,$00,$13,$0b,$01
 	db $03,$00,$04,$13,$09,$02
@@ -112,9 +112,9 @@
 
 BlkPacket_Titlescreen: ; 7228e (1c:628e)
 	ATTR_BLK 3
-	ATTR_BLK_DATA %011, 0,0,0, 00,00, 19,07
-	ATTR_BLK_DATA %010, 1,1,0, 00,08, 19,09
-	ATTR_BLK_DATA %011, 2,2,0, 00,10, 19,17
+	ATTR_BLK_DATA %011, 0,0,0, 00,00, 19,07 ; pokemon logo: pal 0
+	ATTR_BLK_DATA %010, 1,1,0, 00,08, 19,09 ; version text: pal 1
+	ATTR_BLK_DATA %011, 2,2,0, 00,10, 19,17 ; player, mon, copyright text: pal 2
 	ds 12
 
 	db $03,$00,$00,$13,$07,$00
@@ -124,9 +124,9 @@
 
 BlkPacket_NidorinoIntro: ; 722c1 (1c:62c1)
 	ATTR_BLK 3
-	ATTR_BLK_DATA %011, 1,1,0, 00,00, 19,03
-	ATTR_BLK_DATA %011, 0,0,0, 00,04, 19,13
-	ATTR_BLK_DATA %011, 1,1,0, 00,14, 19,17
+	ATTR_BLK_DATA %011, 1,1,0, 00,00, 19,03 ; upper black bar: pal 1
+	ATTR_BLK_DATA %011, 0,0,0, 00,04, 19,13 ; letterbox: pal 0
+	ATTR_BLK_DATA %011, 1,1,0, 00,14, 19,17 ; lower black bar: pal 1
 	ds 12
 
 	db $03,$00,$00,$13,$03,$01
@@ -136,13 +136,13 @@
 
 BlkPacket_PartyMenu: ; 722f4 (1c:62f4)
 	ATTR_BLK 7
-	ATTR_BLK_DATA %110, 0,0,1, 01,00, 02,12
-	ATTR_BLK_DATA %010, 0,0,0, 05,01, 11,01
-	ATTR_BLK_DATA %010, 0,0,0, 05,03, 11,03
-	ATTR_BLK_DATA %010, 0,0,0, 05,05, 11,05
-	ATTR_BLK_DATA %010, 0,0,0, 05,07, 11,07
-	ATTR_BLK_DATA %010, 0,0,0, 05,09, 11,09
-	ATTR_BLK_DATA %010, 0,0,0, 05,11, 11,11
+	ATTR_BLK_DATA %110, 0,0,1, 01,00, 02,12 ; mon sprites: pal 0, everything else: pal 1
+	ATTR_BLK_DATA %010, 0,0,0, 05,01, 11,01 ; HP bar 0: pal set dynamically
+	ATTR_BLK_DATA %010, 0,0,0, 05,03, 11,03 ; HP bar 1: pal set dynamically
+	ATTR_BLK_DATA %010, 0,0,0, 05,05, 11,05 ; HP bar 2: pal set dynamically
+	ATTR_BLK_DATA %010, 0,0,0, 05,07, 11,07 ; HP bar 3: pal set dynamically
+	ATTR_BLK_DATA %010, 0,0,0, 05,09, 11,09 ; HP bar 4: pal set dynamically
+	ATTR_BLK_DATA %010, 0,0,0, 05,11, 11,11 ; HP bar 5: pal set dynamically
 	ds 4
 
 	db $02,$00,$00,$11,$01,$03
@@ -158,16 +158,16 @@
 
 BlkPacket_TrainerCard: ; 72360 (1c:6360)
 	ATTR_BLK 10
-	ATTR_BLK_DATA %010, 0,0,0, 03,12, 04,13
-	ATTR_BLK_DATA %010, 1,1,0, 07,12, 08,13
-	ATTR_BLK_DATA %010, 3,3,0, 11,12, 12,13
-	ATTR_BLK_DATA %010, 2,2,0, 16,11, 17,12
-	ATTR_BLK_DATA %010, 1,1,0, 14,13, 15,14
-	ATTR_BLK_DATA %010, 3,3,0, 16,13, 17,14
-	ATTR_BLK_DATA %010, 2,2,0, 03,15, 04,16
-	ATTR_BLK_DATA %010, 3,3,0, 07,15, 08,16
-	ATTR_BLK_DATA %010, 2,2,0, 11,15, 12,16
-	ATTR_BLK_DATA %010, 1,1,0, 15,15, 16,16
+	ATTR_BLK_DATA %010, 0,0,0, 03,12, 04,13 ; Boulder Badge
+	ATTR_BLK_DATA %010, 1,1,0, 07,12, 08,13 ; Cascade Badge
+	ATTR_BLK_DATA %010, 3,3,0, 11,12, 12,13 ; Thunder Badge
+	ATTR_BLK_DATA %010, 2,2,0, 16,11, 17,12 ; Rainbow Badge
+	ATTR_BLK_DATA %010, 1,1,0, 14,13, 15,14 ; Rainbow Badge
+	ATTR_BLK_DATA %010, 3,3,0, 16,13, 17,14 ; Rainbow Badge
+	ATTR_BLK_DATA %010, 2,2,0, 03,15, 04,16 ; Soul Badge
+	ATTR_BLK_DATA %010, 3,3,0, 07,15, 08,16 ; Marsh Badge
+	ATTR_BLK_DATA %010, 2,2,0, 11,15, 12,16 ; Volcano Badge
+	ATTR_BLK_DATA %010, 1,1,0, 15,15, 16,16 ; Earth Badge
 	ds 2
 
 	db $03,$03,$0c,$04,$0d,$00
@@ -184,9 +184,9 @@
 
 BlkPacket_GameFreakIntro: ; 723dd (1c:63dd)
 	ATTR_BLK 3
-	ATTR_BLK_DATA %111, 1,1,0, 05,11, 07,13
-	ATTR_BLK_DATA %010, 2,2,0, 08,11, 09,13
-	ATTR_BLK_DATA %011, 3,3,0, 12,11, 14,13
+	ATTR_BLK_DATA %111, 1,1,0, 05,11, 07,13 ; falling stars (left): pal 1, GameFreak logo: pal 0
+	ATTR_BLK_DATA %010, 2,2,0, 08,11, 09,13 ; falling stars (middle): pal 2
+	ATTR_BLK_DATA %011, 3,3,0, 12,11, 14,13 ; falling stars (right): pal 3
 	ds 12
 
 	db $03,$00,$00,$13,$0a,$00
--- a/engine/battle/animations.asm
+++ b/engine/battle/animations.asm
@@ -2170,8 +2170,8 @@
 	pop af
 	ld [wBattleMonSpecies2], a
 .done
-	ld b, $1
-	jp GoPAL_SET
+	ld b, SET_PAL_BATTLE
+	jp RunPaletteCommand
 
 AnimationHideEnemyMonPic: ; 797d8 (1e:57d8)
 ; Hides the enemy mon's sprite
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -184,8 +184,8 @@
 	inc a
 	ld [H_AUTOBGTRANSFERENABLED], a
 	call Delay3
-	ld b, $1
-	call GoPAL_SET
+	ld b, SET_PAL_BATTLE
+	call RunPaletteCommand
 	call HideSprites
 	jpab PrintBeginningBattleText
 
@@ -788,7 +788,7 @@
 
 HandleEnemyMonFainted: ; 3c525 (f:4525)
 	xor a
-	ld [wccf0], a
+	ld [wInHandlePlayerMonFainted], a
 	call FaintEnemyPokemon
 	call AnyPartyAlive
 	ld a, d
@@ -888,9 +888,9 @@
 	ld a, [hli]
 	or [hl]
 	jr nz, .playermonnotfaint
-	ld a, [wccf0]
-	and a
-	jr nz, .playermonnotfaint
+	ld a, [wInHandlePlayerMonFainted]
+	and a ; was this called by HandlePlayerMonFainted?
+	jr nz, .playermonnotfaint ; if so, don't call RemoveFaintedPlayerMon twice
 	call RemoveFaintedPlayerMon
 .playermonnotfaint
 	call AnyPartyAlive
@@ -950,11 +950,13 @@
 	db "@"
 
 EndLowHealthAlarm: ; 3c643 (f:4643)
+; This function is called when the player has the won the battle. It turns off
+; the low health alarm and prevents it from reactivating until the next battle.
 	xor a
-	ld [wLowHealthAlarm], a ;disable low health alarm
+	ld [wLowHealthAlarm], a ; turn off low health alarm
 	ld [wChannelSoundIDs + CH4], a
 	inc a
-	ld [wccf6], a
+	ld [wLowHealthAlarmDisabled], a ; prevent it from reactivating
 	ret
 
 AnyEnemyPokemonAliveCheck: ; 3c64f (f:464f)
@@ -976,7 +978,7 @@
 
 ; stores whether enemy ran in Z flag
 ReplaceFaintedEnemyMon: ; 3c664 (f:4664)
-	ld hl, wcf1e
+	ld hl, wEnemyHPBarColor
 	ld e, $30
 	call GetBattleHealthBarColor
 	callab DrawEnemyPokeballs
@@ -1053,8 +1055,8 @@
 	jp Delay3
 
 HandlePlayerMonFainted: ; 3c700 (f:4700)
-	ld a, $1
-	ld [wccf0], a
+	ld a, 1
+	ld [wInHandlePlayerMonFainted], a
 	call RemoveFaintedPlayerMon
 	call AnyPartyAlive     ; test if any more mons are alive
 	ld a, d
@@ -1115,9 +1117,15 @@
 	call SlideDownFaintedMonPic
 	ld a, $1
 	ld [wBattleResult], a
-	ld a, [wccf0]
-	and a
-	ret z
+
+; When the player mon and enemy mon faint at the same time and the fact that the
+; enemy mon has fainted is detected first (e.g. when the player mon knocks out
+; the enemy mon using a move with recoil and faints due to the recoil), don't
+; play the player mon's cry or show the "[player mon] fainted!" message.
+	ld a, [wInHandlePlayerMonFainted]
+	and a ; was this called by HandleEnemyMonFainted?
+	ret z ; if so, return
+
 	ld a, [wBattleMonSpecies]
 	call PlayCry
 	ld hl, PlayerMonFaintedText
@@ -1199,7 +1207,7 @@
 	call GBPalWhiteOut
 	call LoadHudTilePatterns
 	call LoadScreenTilesFromBuffer1
-	call GoPAL_SET_CF1C
+	call RunDefaultPaletteCommand
 	call GBPalNormal
 	call SendOutMon
 	ld hl, wEnemyMonHP
@@ -1228,8 +1236,8 @@
 	cp OAKS_LAB
 	ret z            ; starter battle in oak's lab: don't black out
 .notSony1Battle
-	ld b, $0
-	call GoPAL_SET
+	ld b, SET_PAL_BATTLE_BLACK
+	call RunPaletteCommand
 	ld hl, PlayerBlackedOutText2
 	ld a, [wLinkState]
 	cp LINK_STATE_BATTLING
@@ -1494,8 +1502,8 @@
 	coord hl, 0, 0
 	lb bc, 4, 11
 	call ClearScreenArea
-	ld b,1
-	call GoPAL_SET
+	ld b, SET_PAL_BATTLE
+	call RunPaletteCommand
 	call GBPalNormal
 	ld hl,TrainerSentOutText
 	call PrintText
@@ -1829,8 +1837,8 @@
 	ld [W_PLAYERDISABLEDMOVE], a
 	ld [wPlayerDisabledMoveNumber], a
 	ld [wPlayerMonMinimized], a
-	ld b, $1
-	call GoPAL_SET
+	ld b, SET_PAL_BATTLE
+	call RunPaletteCommand
 	ld hl, W_ENEMYBATTSTATUS1
 	res UsingTrappingMove, [hl]
 	ld a, $1
@@ -1926,17 +1934,17 @@
 	predef DrawHP
 	ld a, $1
 	ld [H_AUTOBGTRANSFERENABLED], a
-	ld hl, wcf1d
+	ld hl, wPlayerHPBarColor
 	call GetBattleHealthBarColor
 	ld hl, wBattleMonHP
 	ld a, [hli]
 	or [hl]
 	jr z, .asm_3cdd9
-	ld a, [wccf6]
-	and a
-	ret nz
-	ld a, [wcf1d]
-	cp $2
+	ld a, [wLowHealthAlarmDisabled]
+	and a ; has the alarm been disabled because the player has already won?
+	ret nz ; if so, return
+	ld a, [wPlayerHPBarColor]
+	cp HP_BAR_RED
 	jr z, .asm_3cde6
 .asm_3cdd9
 	ld hl, wLowHealthAlarm
@@ -2039,7 +2047,7 @@
 	call DrawHPBar
 	ld a, $1
 	ld [H_AUTOBGTRANSFERENABLED], a
-	ld hl, wcf1e
+	ld hl, wEnemyHPBarColor
 
 GetBattleHealthBarColor: ; 3ce90 (f:4e90)
 	ld b, [hl]
@@ -2047,8 +2055,8 @@
 	ld a, [hl]
 	cp b
 	ret z
-	ld b, $1
-	jp GoPAL_SET
+	ld b, SET_PAL_BATTLE
+	jp RunPaletteCommand
 
 ; center's mon's name on the battle screen
 ; if the name is 1 or 2 letters long, it is printed 2 spaces more to the right than usual
@@ -2397,7 +2405,7 @@
 	call GBPalWhiteOut
 	call LoadHudTilePatterns
 	call LoadScreenTilesFromBuffer2
-	call GoPAL_SET_CF1C
+	call RunDefaultPaletteCommand
 	call GBPalNormal
 	jp DisplayBattleMenu
 .partyMonDeselected
@@ -2486,7 +2494,7 @@
 	call ClearSprites
 	call LoadHudTilePatterns
 	call LoadScreenTilesFromBuffer1
-	call GoPAL_SET_CF1C
+	call RunDefaultPaletteCommand
 	call GBPalNormal
 ; fall through to SwitchPlayerMon
 
@@ -2634,7 +2642,7 @@
 	cp LINK_STATE_BATTLING
 	jr z, .matchedkeyspicked
 	ld a, [W_FLAGS_D733]
-	bit 0, a
+	bit BIT_TEST_BATTLE, a
 	ld b, D_UP | D_DOWN | A_BUTTON | B_BUTTON | SELECT
 	jr z, .matchedkeyspicked
 	ld b, $ff
@@ -2662,7 +2670,7 @@
 	jr .select
 .battleselect
 	ld a, [W_FLAGS_D733]
-	bit 0, a
+	bit BIT_TEST_BATTLE, a
 	jr nz, .select
 	call PrintMenuItem
 	ld a, [wMenuItemToSwap]
@@ -6170,8 +6178,8 @@
 .player
 	ld de, W_PLAYERMOVENUM
 	ld a, [W_FLAGS_D733]
-	bit 0, a
-	ld a, [wccd9]
+	bit BIT_TEST_BATTLE, a
+	ld a, [wTestBattlePlayerSelectedMove]
 	jr nz, .selected
 	ld a, [wPlayerSelectedMove]
 .selected
@@ -6201,7 +6209,7 @@
 	call GetMonHeader
 	ld a, [W_ENEMYBATTSTATUS3]
 	bit Transformed, a ; is enemy mon transformed?
-	ld hl, wcceb ; copied DVs from when it used Transform
+	ld hl, wTransformedEnemyMonOriginalDVs ; original DVs before transforming
 	ld a, [hli]
 	ld b, [hl]
 	jr nz, .storeDVs
@@ -6879,7 +6887,7 @@
 	ld [wEnemyMonPartyPos], a
 	ld a, $2
 	ld [W_ISINBATTLE], a
-	jp InitBattle_Common
+	jp _InitBattleCommon
 
 InitWildBattle: ; 3ef8b (f:6f8b)
 	ld a, $1
@@ -6931,9 +6939,9 @@
 	predef CopyUncompressedPicToTilemap
 
 ; common code that executes after init battle code specific to trainer or wild battles
-InitBattle_Common: ; 3efeb (f:6feb)
-	ld b, $0
-	call GoPAL_SET
+_InitBattleCommon: ; 3efeb (f:6feb)
+	ld b, SET_PAL_BATTLE_BLACK
+	call RunPaletteCommand
 	call SlidePlayerAndEnemySilhouettesOnScreen
 	xor a
 	ld [H_AUTOBGTRANSFERENABLED], a
--- a/engine/battle/experience.asm
+++ b/engine/battle/experience.asm
@@ -76,11 +76,11 @@
 	ld b, [hl]
 	ld a, [wPlayerID + 1]
 	cp b
-	ld a, $0
+	ld a, 0
 	jr z, .next
 .tradedMon
 	call BoostExp ; traded mon exp boost
-	ld a, $1
+	ld a, 1
 .next
 	ld [wGainBoostedExp], a
 	ld a, [W_ISINBATTLE]
@@ -92,12 +92,12 @@
 ; add the gained exp to the party mon's exp
 	ld b, [hl]
 	ld a, [H_QUOTIENT + 3]
-	ld [wcf4c], a
+	ld [wExpAmountGained + 1], a
 	add b
 	ld [hld], a
 	ld b, [hl]
 	ld a, [H_QUOTIENT + 2]
-	ld [wcf4b], a
+	ld [wExpAmountGained], a
 	adc b
 	ld [hl], a
 	jr nc, .noCarry
--- a/engine/battle/init_battle_variables.asm
+++ b/engine/battle/init_battle_variables.asm
@@ -16,9 +16,9 @@
 	ld [wPlayerMonNumber], a
 	ld [wEscapedFromBattle], a
 	ld [wMapPalOffset], a
-	ld hl, wcf1d
-	ld [hli], a
-	ld [hl], a
+	ld hl, wPlayerHPBarColor
+	ld [hli], a ; wPlayerHPBarColor
+	ld [hl], a ; wEnemyHPBarColor
 	ld hl, wCanEvolveFlags
 	ld b, $3c
 .loop
@@ -25,8 +25,8 @@
 	ld [hli], a
 	dec b
 	jr nz, .loop
-	inc a
-	ld [wccd9], a
+	inc a ; POUND
+	ld [wTestBattlePlayerSelectedMove], a
 	ld a, [W_CURMAP]
 	cp SAFARI_ZONE_EAST
 	jr c, .notSafariBattle
--- a/engine/battle/moveEffects/transform_effect.asm
+++ b/engine/battle/moveEffects/transform_effect.asm
@@ -67,12 +67,12 @@
 	ld a, [H_WHOSETURN]
 	and a
 	jr z, .next
-; save enemy mon DVs in wcceb/wccec (enemy turn only)
+; save enemy mon DVs at wTransformedEnemyMonOriginalDVs
 	ld a, [de]
-	ld [wcceb], a
+	ld [wTransformedEnemyMonOriginalDVs], a
 	inc de
 	ld a, [de]
-	ld [wccec], a
+	ld [wTransformedEnemyMonOriginalDVs + 1], a
 	dec de
 .next
 ; DVs
--- a/engine/battle/scroll_draw_trainer_pic.asm
+++ b/engine/battle/scroll_draw_trainer_pic.asm
@@ -3,8 +3,8 @@
 ; the screen from the right.
 	xor a
 	ld [wEnemyMonSpecies2], a
-	ld b, $1
-	call GoPAL_SET
+	ld b, SET_PAL_BATTLE
+	call RunPaletteCommand
 	callab _LoadTrainerPic
 	coord hl, 19, 0
 	ld c, $0
--- a/engine/cable_club.asm
+++ b/engine/cable_club.asm
@@ -836,7 +836,7 @@
 	call ClearScreen
 	call LoadHpBarAndStatusTilePatterns
 	xor a
-	ld [wcc5b], a
+	ld [wUnusedCC5B], a
 	ld a, [hSerialConnectionStatus]
 	cp USING_EXTERNAL_CLOCK
 	jr z, .usingExternalClock
--- a/engine/clear_save.asm
+++ b/engine/clear_save.asm
@@ -1,6 +1,6 @@
 DoClearSaveDialogue: ; 1c98a (7:498a)
 	call ClearScreen
-	call GoPAL_SET_CF1C
+	call RunDefaultPaletteCommand
 	call LoadFontTilePatterns
 	call LoadTextBoxTilePatterns
 	ld hl, ClearSaveDataText
--- a/engine/evolution.asm
+++ b/engine/evolution.asm
@@ -21,8 +21,8 @@
 	ld [H_AUTOBGTRANSFERENABLED], a
 	ld [hTilesetType], a
 	ld a, [wEvoOldSpecies]
-	ld [wcf1d], a
-	ld c, $0
+	ld [wWholeScreenPaletteMonSpecies], a
+	ld c, 0
 	call EvolutionSetWholeScreenPalette
 	ld a, [wEvoNewSpecies]
 	ld [wcf91], a
@@ -46,7 +46,7 @@
 	call PlayMusic
 	ld c, 80
 	call DelayFrames
-	ld c, $1
+	ld c, 1 ; set PAL_BLACK instead of mon palette
 	call EvolutionSetWholeScreenPalette
 	lb bc, $1, $10
 .animLoop
@@ -66,13 +66,13 @@
 	call Evolution_ChangeMonPic ; show the new species pic
 	ld a, [wEvoNewSpecies]
 .done
-	ld [wcf1d], a
+	ld [wWholeScreenPaletteMonSpecies], a
 	ld a, $ff
 	ld [wNewSoundID], a
 	call PlaySound
-	ld a, [wcf1d]
+	ld a, [wWholeScreenPaletteMonSpecies]
 	call PlayCry
-	ld c, $0
+	ld c, 0
 	call EvolutionSetWholeScreenPalette
 	pop af
 	ld [wd0b5], a
@@ -94,8 +94,8 @@
 	jr .done
 
 EvolutionSetWholeScreenPalette: ; 7beb4 (1e:7eb4)
-	ld b, $b
-	jp GoPAL_SET
+	ld b, SET_PAL_POKEMON_WHOLE_SCREEN
+	jp RunPaletteCommand
 
 Evolution_LoadPic: ; 7beb9 (1e:7eb9)
 	call GetMonHeader
--- a/engine/game_corner_slots2.asm
+++ b/engine/game_corner_slots2.asm
@@ -3,7 +3,7 @@
 	and $8
 	jr z, .done ; not able
 	ld b, COIN_CASE
-	predef IsItemInBag_  ; IsItemInBag_
+	predef GetQuantityOfItemInBag
 	ld a, b
 	and a
 	ld b, (GameCornerCoinCaseText_id - TextPredefs) / 2 + 1
--- a/engine/hall_of_fame.asm
+++ b/engine/hall_of_fame.asm
@@ -104,7 +104,7 @@
 	ld [wcf91], a
 	ld [wd0b5], a
 	ld [wBattleMonSpecies2], a
-	ld [wcf1d], a
+	ld [wWholeScreenPaletteMonSpecies], a
 	ld a, [wHoFMonOrPlayer]
 	and a
 	jr z, .showMon
@@ -117,9 +117,9 @@
 	call LoadFrontSpriteByMonIndex
 	predef LoadMonBackPic
 .next1
-	ld b, $b
-	ld c, $0
-	call GoPAL_SET
+	ld b, SET_PAL_POKEMON_WHOLE_SCREEN
+	ld c, 0
+	call RunPaletteCommand
 	ld a, %11100100
 	ld [rBGP], a
 	ld c, $31 ; back pic
@@ -243,7 +243,7 @@
 	call HoFPrintTextAndDelay
 	ld hl, DexRatingText
 	call HoFPrintTextAndDelay
-	ld hl, wcc5d
+	ld hl, wDexRatingText
 
 HoFPrintTextAndDelay: ; 703e2 (1c:43e2)
 	call PrintText
--- a/engine/intro.asm
+++ b/engine/intro.asm
@@ -1,3 +1,7 @@
+MOVE_GENGAR_RIGHT   EQU $00
+MOVE_GENGAR_LEFT    EQU $01
+MOVE_NIDORINO_RIGHT EQU $ff
+
 PlayIntro: ; 41682 (10:5682)
 	xor a
 	ld [hJoyHeld], a
@@ -14,8 +18,8 @@
 	ret
 
 PlayIntroScene: ; 4169d (10:569d)
-	ld b, $7
-	call GoPAL_SET
+	ld b, SET_PAL_NIDORINO_INTRO
+	call RunPaletteCommand
 	ld a, %11100100
 	ld [rBGP], a
 	ld [rOBP0], a
@@ -30,7 +34,7 @@
 	ld [W_BASECOORDY], a
 	lb bc, 6, 6
 	call InitIntroNidorinoOAM
-	ld de, $28ff ; move Nidorino right by 80 pixels
+	lb de, 80 / 2, MOVE_NIDORINO_RIGHT
 	call IntroMoveMon
 	ret c
 
@@ -69,7 +73,7 @@
 	call IntroCopyTiles
 	ld a, SFX_INTRO_RAISE
 	call PlaySound
-	ld de, $401 ; move Gengar left by 8 pixels
+	lb de, 8 / 2, MOVE_GENGAR_LEFT
 	call IntroMoveMon
 	ld c, $1e
 	call CheckForUserInterruption
@@ -80,7 +84,7 @@
 	call IntroCopyTiles
 	ld a, SFX_INTRO_CRASH
 	call PlaySound
-	ld de, $800 ; move Gengar right by 16 pixels
+	lb de, 16 / 2, MOVE_GENGAR_RIGHT
 	call IntroMoveMon
 ; hip
 	ld a, SFX_INTRO_HIP
@@ -93,7 +97,7 @@
 	call CheckForUserInterruption
 	ret c
 
-	ld de, $401 ; move Gengar left by 8 pixels
+	lb de, 8 / 2, MOVE_GENGAR_LEFT
 	call IntroMoveMon
 	ld b, $3
 	call IntroCopyTiles
@@ -298,8 +302,8 @@
 	jp FarCopyData2
 
 PlayShootingStar: ; 4188a (10:588a)
-	ld b, $c
-	call GoPAL_SET
+	ld b, SET_PAL_GAME_FREAK_INTRO
+	call RunPaletteCommand
 	callba LoadCopyrightAndTextBoxTiles
 	ld a, $e4
 	ld [rBGP], a
--- a/engine/items/items.asm
+++ b/engine/items/items.asm
@@ -127,7 +127,7 @@
 	ld hl,W_NUMSAFARIBALLS
 	dec [hl]
 .skipSafariZoneCode
-	call GoPAL_SET_CF1C
+	call RunDefaultPaletteCommand
 	ld a,$43
 	ld [wd11e],a
 	call LoadScreenTilesFromBuffer1	;restore screenBuffer from Backup
@@ -364,7 +364,7 @@
 	jr .next16
 .next15
 	set Transformed,[hl]
-	ld hl,wcceb
+	ld hl,wTransformedEnemyMonOriginalDVs
 	ld a,[wEnemyMonDVs]
 	ld [hli],a
 	ld a,[wEnemyMonDVs + 1]
@@ -1111,7 +1111,7 @@
 	and a ; using Softboiled?
 	ret nz ; if so, return
 	call GBPalWhiteOut
-	call z,GoPAL_SET_CF1C
+	call z,RunDefaultPaletteCommand
 	ld a,[W_ISINBATTLE]
 	and a
 	ret nz
@@ -1324,7 +1324,7 @@
 BaitRockCommon: ; df7f (3:5f7f)
 	ld [W_ANIMATIONID],a
 	xor a
-	ld [wcc5b],a
+	ld [wAnimationType],a
 	ld [H_WHOSETURN],a
 	ld [de],a ; zero escape factor (for bait), zero bait factor (for rock)
 .randomLoop ; loop until a random number less than 5 is generated
@@ -1928,7 +1928,7 @@
 	pop af
 	ld [wWhichPokemon],a
 	call GBPalWhiteOut
-	call GoPAL_SET_CF1C
+	call RunDefaultPaletteCommand
 	jp RemoveUsedItem
 .afterRestoringPP ; after using a (Max) Ether/Elixir
 	ld a,[wWhichPokemon]
@@ -2032,7 +2032,7 @@
 	call ItemUseNoEffect
 .itemNotUsed
 	call GBPalWhiteOut
-	call GoPAL_SET_CF1C
+	call RunDefaultPaletteCommand
 	pop af
 	xor a
 	ld [wActionResultOrTookBattleTurn],a ; item use failed
@@ -2105,9 +2105,9 @@
 	push af
 .chooseMon
 	ld hl,wcf4b
-	ld de,wd036
+	ld de,wTempMoveNameBuffer
 	ld bc,14
-	call CopyData
+	call CopyData ; save the move name because DisplayPartyMenu will overwrite it
 	ld a,$ff
 	ld [wUpdateSpritesEnabled],a
 	ld a,TMHM_PARTY_MENU
@@ -2114,7 +2114,7 @@
 	ld [wPartyMenuTypeOrMessageID],a
 	call DisplayPartyMenu
 	push af
-	ld hl,wd036
+	ld hl,wTempMoveNameBuffer
 	ld de,wcf4b
 	ld bc,14
 	call CopyData
@@ -2125,7 +2125,7 @@
 	pop af
 	call GBPalWhiteOutWithDelay3
 	call ClearSprites
-	call GoPAL_SET_CF1C
+	call RunDefaultPaletteCommand
 	jp LoadScreenTilesFromBuffer1 ; restore saved screen
 .checkIfAbleToLearnMove
 	predef CanLearnTM ; check if the pokemon can learn the move
@@ -2201,7 +2201,7 @@
 	jr ItemUseFailed
 
 ThrowBallAtTrainerMon: ; e58b (3:658b)
-	call GoPAL_SET_CF1C
+	call RunDefaultPaletteCommand
 	call LoadScreenTilesFromBuffer1 ; restore saved screen
 	call Delay3
 	ld a,TOSS_ANIM
--- a/engine/learn_move.asm
+++ b/engine/learn_move.asm
@@ -4,7 +4,7 @@
 	ld hl, wPartyMonNicks
 	call GetPartyMonName
 	ld hl, wcd6d
-	ld de, wd036
+	ld de, wLearnMoveMonName
 	ld bc, NAME_LENGTH
 	call CopyData
 
@@ -16,13 +16,13 @@
 	ld d, h
 	ld e, l
 	ld b, NUM_MOVES
-.asm_6e6b
+.findEmptyMoveSlotLoop
 	ld a, [hl]
 	and a
-	jr z, .asm_6e8b
+	jr z, .next
 	inc hl
 	dec b
-	jr nz, .asm_6e6b
+	jr nz, .findEmptyMoveSlotLoop
 	push de
 	call TryingToLearn
 	pop de
@@ -35,7 +35,7 @@
 	call PrintText
 	pop de
 	pop hl
-.asm_6e8b
+.next
 	ld a, [wMoveNum]
 	ld [hl], a
 	ld bc, wPartyMon1PP - wPartyMon1Moves
@@ -86,13 +86,13 @@
 	jp nz, DontAbandonLearning
 	ld hl, DidNotLearnText
 	call PrintText
-	ld b, $0
+	ld b, 0
 	ret
 
 PrintLearnedMove: ; 6efe (1:6efe)
 	ld hl, LearnedMove1Text
 	call PrintText
-	ld b, $1
+	ld b, 1
 	ret
 
 TryingToLearn: ; 6f07 (1:6f07)
@@ -108,7 +108,7 @@
 	ld a, [wCurrentMenuItem]
 	rra
 	ret c
-	ld bc, - NUM_MOVES
+	ld bc, -NUM_MOVES
 	add hl, bc
 	push hl
 	ld de, wMoves
@@ -121,8 +121,8 @@
 	ld hl, WhichMoveToForgetText
 	call PrintText
 	coord hl, 4, 7
-	ld b, $4
-	ld c, $e
+	ld b, 4
+	ld c, 14
 	call TextBoxBorder
 	coord hl, 6, 8
 	ld de, wMovesString
@@ -160,7 +160,7 @@
 	push hl
 	ld a, [wCurrentMenuItem]
 	ld c, a
-	ld b, $0
+	ld b, 0
 	add hl, bc
 	ld a, [hl]
 	push af
--- a/engine/menu/bills_pc.asm
+++ b/engine/menu/bills_pc.asm
@@ -450,7 +450,7 @@
 	predef StatusScreen2
 	call LoadScreenTilesFromBuffer1
 	call ReloadTilesetTilePatterns
-	call GoPAL_SET_CF1C
+	call RunDefaultPaletteCommand
 	call LoadGBPal
 	jr .loop
 
--- a/engine/menu/diploma.asm
+++ b/engine/menu/diploma.asm
@@ -55,8 +55,8 @@
 
 	call EnableLCD
 	callba LoadTrainerInfoTextBoxTiles
-	ld b, $8
-	call GoPAL_SET
+	ld b, SET_PAL_GENERIC
+	call RunPaletteCommand
 	call Delay3
 	call GBPalNormal
 	ld a, $90
--- a/engine/menu/league_pc.asm
+++ b/engine/menu/league_pc.asm
@@ -47,7 +47,7 @@
 	res 6, [hl]
 	call GBPalWhiteOutWithDelay3
 	call ClearScreen
-	call GoPAL_SET_CF1C
+	call RunDefaultPaletteCommand
 	jp GBPalNormal
 
 LeaguePCShowTeam: ; 765e5 (1d:65e5)
@@ -86,15 +86,15 @@
 	ld [wcf91], a
 	ld [wd0b5], a
 	ld [wBattleMonSpecies2], a
-	ld [wcf1d], a
+	ld [wWholeScreenPaletteMonSpecies], a
 	ld a, [hli]
 	ld [wHoFMonLevel], a
 	ld de, wcd6d
 	ld bc, NAME_LENGTH
 	call CopyData
-	ld b, $0B
+	ld b, SET_PAL_POKEMON_WHOLE_SCREEN
 	ld c, 0
-	call GoPAL_SET
+	call RunPaletteCommand
 	coord hl, 12, 5
 	call GetMonHeader
 	call LoadFrontSpriteByMonIndex
--- a/engine/menu/main_menu.asm
+++ b/engine/menu/main_menu.asm
@@ -24,7 +24,7 @@
 	ld hl,wd72e
 	res 6,[hl]
 	call ClearScreen
-	call GoPAL_SET_CF1C
+	call RunDefaultPaletteCommand
 	call LoadTextBoxTilePatterns
 	call LoadFontTilePatterns
 	ld hl,wd730
@@ -150,7 +150,7 @@
 	ld de, CableClubOptionsText
 	call PlaceString
 	xor a
-	ld [wcd37], a
+	ld [wUnusedCD37], a
 	ld [wd72d], a
 	ld hl, wTopMenuItemY
 	ld a, $7
--- a/engine/menu/naming_screen.asm
+++ b/engine/menu/naming_screen.asm
@@ -88,8 +88,8 @@
 	call GBPalWhiteOutWithDelay3
 	call ClearScreen
 	call UpdateSprites
-	ld b, $8
-	call GoPAL_SET
+	ld b, SET_PAL_GENERIC
+	call RunPaletteCommand
 	call LoadHpBarAndStatusTilePatterns
 	call LoadEDTile
 	callba LoadMonPartySpriteGfx
@@ -163,7 +163,7 @@
 	call GBPalWhiteOutWithDelay3
 	call ClearScreen
 	call ClearSprites
-	call GoPAL_SET_CF1C
+	call RunDefaultPaletteCommand
 	call GBPalNormal
 	xor a
 	ld [W_SUBANIMTRANSFORM], a
--- a/engine/menu/party_menu.asm
+++ b/engine/menu/party_menu.asm
@@ -29,13 +29,13 @@
 	cp a,SWAP_MONS_PARTY_MENU
 	jp z,.printMessage
 	call ErasePartyMenuCursors
-	callba SendBlkPacket_PartyMenu
+	callba InitPartyMenuBlkPacket
 	coord hl, 3, 0
 	ld de,wPartySpecies
 	xor a
 	ld c,a
 	ld [hPartyMonIndex],a
-	ld [wcf2d],a
+	ld [wWhichPartyMenuHPBar],a
 .loop
 	ld a,[de]
 	cp a,$FF ; reached the terminator?
@@ -96,7 +96,7 @@
 	ld a,[hFlags_0xFFF6]
 	res 0,a
 	ld [hFlags_0xFFF6],a
-	call SetPartyMenuHealthBarColor ; color the HP bar (on SGB)
+	call SetPartyMenuHPBarColor ; color the HP bar (on SGB)
 	pop hl
 	jr .printLevel
 .teachMoveMenu
@@ -188,8 +188,8 @@
 .notAbleToEvolveText
 	db "NOT ABLE@"
 .afterDrawingMonEntries
-	ld b,$0A
-	call GoPAL_SET
+	ld b, SET_PAL_PARTY_MENU
+	call RunPaletteCommand
 .printMessage
 	ld hl,wd730
 	ld a,[hl]
@@ -311,15 +311,15 @@
 	db $06
 	db "@"
 
-SetPartyMenuHealthBarColor: ; 12ec7 (4:6ec7)
-	ld hl, wcf1f
-	ld a, [wcf2d]
+SetPartyMenuHPBarColor: ; 12ec7 (4:6ec7)
+	ld hl, wPartyMenuHPBarColors
+	ld a, [wWhichPartyMenuHPBar]
 	ld c, a
-	ld b, $0
+	ld b, 0
 	add hl, bc
 	call GetHealthBarColor
-	ld b, $fc
-	call GoPAL_SET
-	ld hl, wcf2d
+	ld b, UPDATE_PARTY_MENU_BLK_PACKET
+	call RunPaletteCommand
+	ld hl, wWhichPartyMenuHPBar
 	inc [hl]
 	ret
--- a/engine/menu/pokedex.asm
+++ b/engine/menu/pokedex.asm
@@ -12,8 +12,8 @@
 	ld [wd11e],a
 	ld [hJoy7],a
 .setUpGraphics
-	ld b,$08
-	call GoPAL_SET
+	ld b, SET_PAL_GENERIC
+	call RunPaletteCommand
 	callab LoadPokedexTilePatterns
 .doPokemonListMenu
 	ld hl,wTopMenuItemY
@@ -41,7 +41,7 @@
 	pop af
 	ld [wListScrollOffset],a
 	call GBPalWhiteOutWithDelay3
-	call GoPAL_SET_CF1C
+	call RunDefaultPaletteCommand
 	jp ReloadMapData
 .goToSideMenu
 	call HandlePokedexSideMenu
@@ -404,8 +404,8 @@
 	ld a,[wd11e] ; pokemon ID
 	ld [wcf91],a
 	push af
-	ld b,04
-	call GoPAL_SET
+	ld b, SET_PAL_POKEDEX
+	call RunPaletteCommand
 	pop af
 	ld [wd11e],a
 	ld a,[hTilesetType]
@@ -561,7 +561,7 @@
 	ld [hTilesetType],a
 	call GBPalWhiteOut
 	call ClearScreen
-	call GoPAL_SET_CF1C
+	call RunDefaultPaletteCommand
 	call LoadTextBoxTilePatterns
 	call GBPalNormal
 	ld hl,wd72c
--- a/engine/menu/start_sub_menus.asm
+++ b/engine/menu/start_sub_menus.asm
@@ -297,7 +297,7 @@
 
 ItemMenuLoop: ; 132fc (4:72fc)
 	call LoadScreenTilesFromBuffer2DisableBGTransfer ; restore saved screen
-	call GoPAL_SET_CF1C
+	call RunDefaultPaletteCommand
 
 StartMenu_Item: ; 13302 (4:7302)
 	ld a,[wLinkState]
@@ -506,14 +506,14 @@
 	ld [hTilesetType],a
 	call DrawTrainerInfo
 	predef DrawBadges ; draw badges
-	ld b,$0d
-	call GoPAL_SET
+	ld b, SET_PAL_TRAINER_CARD
+	call RunPaletteCommand
 	call GBPalNormal
 	call WaitForTextScrollButtonPress ; wait for button press
 	call GBPalWhiteOut
 	call LoadFontTilePatterns
 	call LoadScreenTilesFromBuffer2 ; restore saved screen
-	call GoPAL_SET_CF1C
+	call RunDefaultPaletteCommand
 	call ReloadMapData
 	call LoadGBPal
 	pop af
--- a/engine/menu/status_screen.asm
+++ b/engine/menu/status_screen.asm
@@ -121,10 +121,10 @@
 	call PlaceString ; "TYPE1/"
 	coord hl, 11, 3
 	predef DrawHP
-	ld hl, wcf25
+	ld hl, wStatusScreenHPBarColor
 	call GetHealthBarColor
-	ld b, $3
-	call GoPAL_SET ; SGB palette
+	ld b, SET_PAL_STATUS_SCREEN
+	call RunPaletteCommand
 	coord hl, 16, 6
 	ld de, wLoadedMonStatus
 	call PrintStatusCondition
--- a/engine/mon_party_sprites.asm
+++ b/engine/mon_party_sprites.asm
@@ -5,15 +5,15 @@
 	inc a
 	jr GetAnimationSpeed
 
-; wcf1f contains the party mon's health bar colors
+; wPartyMenuHPBarColors contains the party mon's health bar colors
 ; 0: green
 ; 1: yellow
 ; 2: red
 AnimatePartyMon: ; 716ff (1c:56ff)
-	ld hl, wcf1f
+	ld hl, wPartyMenuHPBarColors
 	ld a, [wCurrentMenuItem]
 	ld c, a
-	ld b, $0
+	ld b, 0
 	add hl, bc
 	ld a, [hl]
 
@@ -42,7 +42,7 @@
 	jp DelayFrame
 .resetSprites
 	push bc
-	ld hl, wcc5b
+	ld hl, wMonPartySpritesSavedOAM
 	ld de, wOAMBuffer
 	ld bc, $60
 	call CopyData
@@ -86,7 +86,7 @@
 ; that each frame lasts for green HP, yellow HP, and red HP in order.
 ; On the naming screen, the yellow HP speed is always used.
 PartyMonSpeeds: ; 71769 (1c:5769)
-	db $05,$10,$20
+	db 5, 16, 32
 
 LoadMonPartySpriteGfx: ; 7176c (1c:576c)
 ; Load mon party sprite tile patterns into VRAM during V-blank.
@@ -372,7 +372,7 @@
 
 WriteMonPartySpriteOAM: ; 718c3 (1c:58c3)
 ; Write the OAM blocks for the first animation frame into the OAM buffer and
-; make a copy at wcc5b.
+; make a copy at wMonPartySpritesSavedOAM.
 	push af
 	ld c, $10
 	ld h, wOAMBuffer / $100
@@ -392,7 +392,7 @@
 ; we can flip back to it from the second frame by copying it back.
 .makeCopy
 	ld hl, wOAMBuffer
-	ld de, wcc5b
+	ld de, wMonPartySpritesSavedOAM
 	ld bc, $60
 	jp CopyData
 
--- a/engine/overworld/cinnabar_lab.asm
+++ b/engine/overworld/cinnabar_lab.asm
@@ -5,7 +5,7 @@
 	ld [wCurrentMenuItem], a
 	ld a, A_BUTTON | B_BUTTON
 	ld [wMenuWatchedKeys], a
-	ld a, [wcd37]
+	ld a, [wFilteredBagItemsCount]
 	dec a
 	ld [wMaxMenuItem], a
 	ld a, 2
@@ -12,7 +12,7 @@
 	ld [wTopMenuItemY], a
 	ld a, 1
 	ld [wTopMenuItemX], a
-	ld a, [wcd37]
+	ld a, [wFilteredBagItemsCount]
 	dec a
 	ld bc, 2
 	ld hl, 3
@@ -29,9 +29,9 @@
 	call HandleMenuInput
 	bit 1, a ; pressed B?
 	jr nz, .cancelledGivingFossil
-	ld hl, wcc5b
+	ld hl, wFilteredBagItems
 	ld a, [wCurrentMenuItem]
-	ld d, $0
+	ld d, 0
 	ld e, a
 	add hl, de
 	ld a, [hl]
@@ -90,9 +90,9 @@
 
 PrintFossilsInBag: ; 610c2 (18:50c2)
 ; Prints each fossil in the player's bag on a separate line in the menu.
-	ld hl, wcc5b
+	ld hl, wFilteredBagItems
 	xor a
-	ld [hFossilCounter], a
+	ld [hItemCounter], a
 .loop
 	ld a, [hli]
 	cp $ff
@@ -101,12 +101,12 @@
 	ld [wd11e], a
 	call GetItemName
 	coord hl, 2, 2
-	ld a, [hFossilCounter]
+	ld a, [hItemCounter]
 	ld bc, SCREEN_WIDTH * 2
 	call AddNTimes
 	ld de, wcd6d
 	call PlaceString
-	ld hl, hFossilCounter
+	ld hl, hItemCounter
 	inc [hl]
 	pop hl
 	jr .loop
--- a/engine/overworld/hidden_items.asm
+++ b/engine/overworld/hidden_items.asm
@@ -51,7 +51,7 @@
 
 HiddenCoins: ; 76799 (1d:6799)
 	ld b, COIN_CASE
-	predef IsItemInBag_
+	predef GetQuantityOfItemInBag
 	ld a, b
 	and a
 	ret z
--- a/engine/overworld/oaks_aide.asm
+++ b/engine/overworld/oaks_aide.asm
@@ -18,7 +18,7 @@
 .giveItem
 	ld hl, OaksAideHereYouGoText
 	call PrintText
-	ld a, [hOaksAideItemReward]
+	ld a, [hOaksAideRewardItem]
 	ld b, a
 	ld c, 1
 	call GiveItem
--- a/engine/palettes.asm
+++ b/engine/palettes.asm
@@ -1,33 +1,33 @@
-Func_71ddf: ; 71ddf (1c:5ddf)
+_RunPaletteCommand: ; 71ddf (1c:5ddf)
 	call GetPredefRegisters
 	ld a, b
 	cp $ff
-	jr nz, .asm_71dea
-	ld a, [wcf1c]
-.asm_71dea
-	cp $fc
-	jp z, Func_71fc2
+	jr nz, .next
+	ld a, [wDefaultPaletteCommand] ; use default command if command ID is $ff
+.next
+	cp UPDATE_PARTY_MENU_BLK_PACKET
+	jp z, UpdatePartyMenuBlkPacket
 	ld l, a
-	ld h, $0
+	ld h, 0
 	add hl, hl
-	ld de, PointerTable_71f73
+	ld de, SetPalFunctions
 	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
-	ld de, Func_72156
+	ld de, SendSGBPackets
 	push de
 	jp [hl]
 
-SendPalPacket_Black: ; 71dff (1c:5dff)
+SetPal_BattleBlack: ; 71dff (1c:5dff)
 	ld hl, PalPacket_Black
 	ld de, BlkPacket_Battle
 	ret
 
 ; uses PalPacket_Empty to build a packet based on mon IDs and health color
-BuildBattlePalPacket: ; 71e06 (1c:5e06)
+SetPal_Battle: ; 71e06 (1c:5e06)
 	ld hl, PalPacket_Empty
-	ld de, wcf2d
+	ld de, wPalPacket
 	ld bc, $10
 	call CopyData
 	ld a, [W_PLAYERBATTSTATUS3]
@@ -38,12 +38,12 @@
 	ld hl, wEnemyMonSpecies2
 	call DeterminePaletteID
 	ld c, a
-	ld hl, wcf2e
-	ld a, [wcf1d]
+	ld hl, wPalPacket + 1
+	ld a, [wPlayerHPBarColor]
 	add PAL_GREENBAR
 	ld [hli], a
 	inc hl
-	ld a, [wcf1e]
+	ld a, [wEnemyHPBarColor]
 	add PAL_GREENBAR
 	ld [hli], a
 	inc hl
@@ -52,21 +52,21 @@
 	inc hl
 	ld a, c
 	ld [hl], a
-	ld hl, wcf2d
+	ld hl, wPalPacket
 	ld de, BlkPacket_Battle
-	ld a, $1
-	ld [wcf1c], a
+	ld a, SET_PAL_BATTLE
+	ld [wDefaultPaletteCommand], a
 	ret
 
-SendPalPacket_TownMap: ; 71e48 (1c:5e48)
+SetPal_TownMap: ; 71e48 (1c:5e48)
 	ld hl, PalPacket_TownMap
 	ld de, BlkPacket_WholeScreen
 	ret
 
 ; uses PalPacket_Empty to build a packet based the mon ID
-BuildStatusScreenPalPacket: ; 71e4f (1c:5e4f)
+SetPal_StatusScreen: ; 71e4f (1c:5e4f)
 	ld hl, PalPacket_Empty
-	ld de, wcf2d
+	ld de, wPalPacket
 	ld bc, $10
 	call CopyData
 	ld a, [wcf91]
@@ -76,67 +76,67 @@
 .pokemon
 	call DeterminePaletteIDOutOfBattle
 	push af
-	ld hl, wcf2e
-	ld a, [wcf25]
+	ld hl, wPalPacket + 1
+	ld a, [wStatusScreenHPBarColor]
 	add PAL_GREENBAR
 	ld [hli], a
 	inc hl
 	pop af
 	ld [hl], a
-	ld hl, wcf2d
+	ld hl, wPalPacket
 	ld de, BlkPacket_StatusScreen
 	ret
 
-SendPalPacket_PartyMenu: ; 71e7b (1c:5e7b)
+SetPal_PartyMenu: ; 71e7b (1c:5e7b)
 	ld hl, PalPacket_PartyMenu
-	ld de, wcf2e
+	ld de, wPartyMenuBlkPacket
 	ret
 
-SendPalPacket_Pokedex: ; 71e82 (1c:5e82)
+SetPal_Pokedex: ; 71e82 (1c:5e82)
 	ld hl, PalPacket_Pokedex
-	ld de, wcf2d
+	ld de, wPalPacket
 	ld bc, $10
 	call CopyData
 	ld a, [wcf91]
 	call DeterminePaletteIDOutOfBattle
-	ld hl, wcf30
+	ld hl, wPalPacket + 3
 	ld [hl], a
-	ld hl, wcf2d
+	ld hl, wPalPacket
 	ld de, BlkPacket_Pokedex
 	ret
 
-SendPalPacket_Slots: ; 71e9f (1c:5e9f)
+SetPal_Slots: ; 71e9f (1c:5e9f)
 	ld hl, PalPacket_Slots
 	ld de, BlkPacket_Slots
 	ret
 
-SendPalPacket_Titlescreen: ; 71ea6 (1c:5ea6)
+SetPal_TitleScreen: ; 71ea6 (1c:5ea6)
 	ld hl, PalPacket_Titlescreen
 	ld de, BlkPacket_Titlescreen
 	ret
 
 ; used mostly for menus and the Oak intro
-SendPalPacket_Generic: ; 71ead (1c:5ead)
+SetPal_Generic: ; 71ead (1c:5ead)
 	ld hl, PalPacket_Generic
 	ld de, BlkPacket_WholeScreen
 	ret
 
-SendPalPacket_NidorinoIntro: ; 71eb4 (1c:5eb4)
+SetPal_NidorinoIntro: ; 71eb4 (1c:5eb4)
 	ld hl, PalPacket_NidorinoIntro
 	ld de, BlkPacket_NidorinoIntro
 	ret
 
-SendPalPacket_GameFreakIntro: ; 71ebb (1c:5ebb)
+SetPal_GameFreakIntro: ; 71ebb (1c:5ebb)
 	ld hl, PalPacket_GameFreakIntro
 	ld de, BlkPacket_GameFreakIntro
-	ld a, $8
-	ld [wcf1c], a
+	ld a, SET_PAL_GENERIC
+	ld [wDefaultPaletteCommand], a
 	ret
 
 ; uses PalPacket_Empty to build a packet based on the current map
-BuildOverworldPalPacket: ; 71ec7 (1c:5ec7)
+SetPal_Overworld: ; 71ec7 (1c:5ec7)
 	ld hl, PalPacket_Empty
-	ld de, wcf2d
+	ld de, wPalPacket
 	ld bc, $10
 	call CopyData
 	ld a, [W_CURMAPTILESET]
@@ -162,12 +162,12 @@
 	jr c, .town
 	ld a, PAL_ROUTE - 1
 .town
-	inc a ; a town's pallete ID is its map ID + 1
-	ld hl, wcf2e
+	inc a ; a town's palette ID is its map ID + 1
+	ld hl, wPalPacket + 1
 	ld [hld], a
 	ld de, BlkPacket_WholeScreen
-	ld a, $9
-	ld [wcf1c], a
+	ld a, SET_PAL_OVERWORLD
+	ld [wDefaultPaletteCommand], a
 	ret
 .PokemonTowerOrAgatha
 	ld a, PAL_GREYMON - 1
@@ -181,131 +181,143 @@
 
 ; used when a Pokemon is the only thing on the screen
 ; such as evolution, trading and the Hall of Fame
-SendPokemonPalette_WholeScreen: ; 71f17 (1c:5f17)
+SetPal_PokemonWholeScreen: ; 71f17 (1c:5f17)
 	push bc
 	ld hl, PalPacket_Empty
-	ld de, wcf2d
+	ld de, wPalPacket
 	ld bc, $10
 	call CopyData
 	pop bc
 	ld a, c
 	and a
-	ld a, $1e
-	jr nz, .asm_71f31
-	ld a, [wcf1d]
+	ld a, PAL_BLACK
+	jr nz, .next
+	ld a, [wWholeScreenPaletteMonSpecies]
 	call DeterminePaletteIDOutOfBattle
-.asm_71f31
-	ld [wcf2e], a
-	ld hl, wcf2d
+.next
+	ld [wPalPacket + 1], a
+	ld hl, wPalPacket
 	ld de, BlkPacket_WholeScreen
 	ret
 
-BuildTrainerCardPalPacket: ; 71f3b (1c:5f3b)
+SetPal_TrainerCard: ; 71f3b (1c:5f3b)
 	ld hl, BlkPacket_TrainerCard
-	ld de, wcc5b
+	ld de, wTrainerCardBlkPacket
 	ld bc, $40
 	call CopyData
-	ld de, LoopCounts_71f8f
-	ld hl, wcc5d
+	ld de, BadgeBlkDataLengths
+	ld hl, wTrainerCardBlkPacket + 2
 	ld a, [W_OBTAINEDBADGES]
-	ld c, $8
-.asm_71f52
+	ld c, 8
+.badgeLoop
 	srl a
 	push af
-	jr c, .asm_71f62
+	jr c, .haveBadge
+; The player doens't have the badge, so zero the badge's blk data.
 	push bc
 	ld a, [de]
 	ld c, a
 	xor a
-.asm_71f5b
+.zeroBadgeDataLoop
 	ld [hli], a
 	dec c
-	jr nz, .asm_71f5b
+	jr nz, .zeroBadgeDataLoop
 	pop bc
-	jr .asm_71f67
-.asm_71f62
+	jr .nextBadge
+.haveBadge
+; The player does have the badge, so skip past the badge's blk data.
 	ld a, [de]
-.asm_71f63
+.skipBadgeDataLoop
 	inc hl
 	dec a
-	jr nz, .asm_71f63
-.asm_71f67
+	jr nz, .skipBadgeDataLoop
+.nextBadge
 	pop af
 	inc de
 	dec c
-	jr nz, .asm_71f52
+	jr nz, .badgeLoop
 	ld hl, PalPacket_TrainerCard
-	ld de, wcc5b
+	ld de, wTrainerCardBlkPacket
 	ret
 
-PointerTable_71f73: ; 71f73 (1c:5f73)
-	dw SendPalPacket_Black
-	dw BuildBattlePalPacket
-	dw SendPalPacket_TownMap
-	dw BuildStatusScreenPalPacket
-	dw SendPalPacket_Pokedex
-	dw SendPalPacket_Slots
-	dw SendPalPacket_Titlescreen
-	dw SendPalPacket_NidorinoIntro
-	dw SendPalPacket_Generic
-	dw BuildOverworldPalPacket
-	dw SendPalPacket_PartyMenu
-	dw SendPokemonPalette_WholeScreen
-	dw SendPalPacket_GameFreakIntro
-	dw BuildTrainerCardPalPacket
+SetPalFunctions: ; 71f73 (1c:5f73)
+	dw SetPal_BattleBlack
+	dw SetPal_Battle
+	dw SetPal_TownMap
+	dw SetPal_StatusScreen
+	dw SetPal_Pokedex
+	dw SetPal_Slots
+	dw SetPal_TitleScreen
+	dw SetPal_NidorinoIntro
+	dw SetPal_Generic
+	dw SetPal_Overworld
+	dw SetPal_PartyMenu
+	dw SetPal_PokemonWholeScreen
+	dw SetPal_GameFreakIntro
+	dw SetPal_TrainerCard
 
-; each byte is the number of loops to make in .asm_71f5b for each badge
-LoopCounts_71f8f: ; 71f8f (1c:5f8f)
-	db $06,$06,$06,$12,$06,$06,$06,$06
+; The length of the blk data of each badge on the Trainer Card.
+; The Rainbow Badge has 3 entries because of its many colors.
+BadgeBlkDataLengths: ; 71f8f (1c:5f8f)
+	db 6     ; Boulder Badge
+	db 6     ; Cascade Badge
+	db 6     ; Thunder Badge
+	db 6 * 3 ; Rainbow Badge
+	db 6     ; Soul Badge
+	db 6     ; Marsh Badge
+	db 6     ; Volcano Badge
+	db 6     ; Earth Badge
 
 DeterminePaletteID: ; 71f97 (1c:5f97)
-	bit 3, a                 ; bit 3 of battle status 3, set if current Pokemon is transformed
-	ld a, PAL_GREYMON        ; if yes, use Ditto's palette
+	bit Transformed, a ; a is battle status 3
+	ld a, PAL_GREYMON  ; if the mon has used Transform, use Ditto's palette
 	ret nz
 	ld a, [hl]
 DeterminePaletteIDOutOfBattle: ; 71f9d (1c:5f9d)
 	ld [wd11e], a
-	and a
-	jr z, .idZero
+	and a ; is the mon index 0?
+	jr z, .skipDexNumConversion
 	push bc
-	predef IndexToPokedex               ; turn Pokemon ID number into Pokedex number
+	predef IndexToPokedex
 	pop bc
 	ld a, [wd11e]
-.idZero
+.skipDexNumConversion
 	ld e, a
-	ld d, $00
-	ld hl, MonsterPalettes   ; not just for Pokemon, Trainers use it too
+	ld d, 0
+	ld hl, MonsterPalettes ; not just for Pokemon, Trainers use it too
 	add hl, de
 	ld a, [hl]
 	ret
 
-SendBlkPacket_PartyMenu: ; 71fb6 (1c:5fb6)
+InitPartyMenuBlkPacket: ; 71fb6 (1c:5fb6)
 	ld hl, BlkPacket_PartyMenu
-	ld de, wcf2e
+	ld de, wPartyMenuBlkPacket
 	ld bc, $30
 	jp CopyData
 
-Func_71fc2: ; 71fc2 (1c:5fc2)
-	ld hl, wcf1f
-	ld a, [wcf2d]
+UpdatePartyMenuBlkPacket: ; 71fc2 (1c:5fc2)
+; Update the blk packet with the palette of the HP bar that is
+; specified in [wWhichPartyMenuHPBar].
+	ld hl, wPartyMenuHPBarColors
+	ld a, [wWhichPartyMenuHPBar]
 	ld e, a
-	ld d, $0
+	ld d, 0
 	add hl, de
 	ld e, l
 	ld d, h
 	ld a, [de]
 	and a
-	ld e, $5
-	jr z, .asm_71fdb
+	ld e, (1 << 2) | 1 ; green
+	jr z, .next
 	dec a
-	ld e, $a
-	jr z, .asm_71fdb
-	ld e, $f
-.asm_71fdb
+	ld e, (2 << 2) | 2 ; yellow
+	jr z, .next
+	ld e, (3 << 2) | 3 ; red
+.next
 	push de
-	ld hl, wcf37
-	ld bc, $6
-	ld a, [wcf2d]
+	ld hl, wPartyMenuBlkPacket + 8 + 1
+	ld bc, 6
+	ld a, [wWhichPartyMenuHPBar]
 	call AddNTimes
 	pop de
 	ld [hl], e
@@ -321,11 +333,9 @@
 .loop2
 ; save B for later use
 	push bc
-; load a non-zero value in $fff9 to disable the routine that checks actual
-; joypad input (said routine, located at $15f, does nothing if $fff9 is not
-; zero)
-	ld a,$01
-	ld [$fff9],a
+; disable ReadJoypad to prevent it from interfering with sending the packet
+	ld a, 1
+	ld [hDisableJoypadPolling], a
 ; send RESET signal (P14=LOW, P15=LOW)
 	xor a
 	ld [rJOYP],a
@@ -367,7 +377,7 @@
 	ld a,$30
 	ld [rJOYP],a
 	xor a
-	ld [$fff9],a
+	ld [hDisableJoypadPolling],a
 ; wait for about 70000 cycles
 	call Wait7000
 ; restore (previously pushed) number of packets
@@ -383,39 +393,39 @@
 	ld [wOnSGB], a
 	call CheckSGB
 	ret nc
-	ld a, $1
+	ld a, 1
 	ld [wOnSGB], a
 	ld a, [wGBC]
 	and a
-	jr z, .asm_7203f
+	jr z, .notGBC
 	ret
-.asm_7203f
+.notGBC
 	di
-	call Func_72075
+	call PrepareSuperNintendoVRAMTransfer
 	ei
-	ld a, $1
-	ld [wcf2d], a
+	ld a, 1
+	ld [wCopyingSGBTileData], a
 	ld de, ChrTrnPacket
 	ld hl, SGBBorderGraphics
-	call Func_7210b
+	call CopyGfxToSuperNintendoVRAM
 	xor a
-	ld [wcf2d], a
+	ld [wCopyingSGBTileData], a
 	ld de, PctTrnPacket
 	ld hl, BorderPalettes
-	call Func_7210b
+	call CopyGfxToSuperNintendoVRAM
 	xor a
-	ld [wcf2d], a
+	ld [wCopyingSGBTileData], a
 	ld de, PalTrnPacket
 	ld hl, SuperPalettes
-	call Func_7210b
+	call CopyGfxToSuperNintendoVRAM
 	call ClearVram
 	ld hl, MaskEnCancelPacket
 	jp SendSGBPacket
 
-Func_72075: ; 72075 (1c:6075)
-	ld hl, PointerTable_72089
-	ld c, $9
-.asm_7207a
+PrepareSuperNintendoVRAMTransfer: ; 72075 (1c:6075)
+	ld hl, .packetPointers
+	ld c, 9
+.loop
 	push bc
 	ld a, [hli]
 	push hl
@@ -426,10 +436,11 @@
 	inc hl
 	pop bc
 	dec c
-	jr nz, .asm_7207a
+	jr nz, .loop
 	ret
 
-PointerTable_72089: ; 72089 (1c:6089)
+.packetPointers
+; Only the first packet is needed.
 	dw MaskEnFreezePacket
 	dw DataSnd_72548
 	dw DataSnd_72558
@@ -441,17 +452,18 @@
 	dw DataSnd_725b8
 
 CheckSGB: ; 7209b (1c:609b)
+; Returns whether the game is running on an SGB in carry.
 	ld hl, MltReq2Packet
 	di
 	call SendSGBPacket
-	ld a, $1
-	ld [$fff9], a
+	ld a, 1
+	ld [hDisableJoypadPolling], a
 	ei
 	call Wait7000
 	ld a, [rJOYP]
 	and $3
 	cp $3
-	jr nz, .asm_720fd
+	jr nz, .isSGB
 	ld a, $20
 	ld [rJOYP], a
 	ld a, [rJOYP]
@@ -482,21 +494,21 @@
 	ld a, [rJOYP]
 	and $3
 	cp $3
-	jr nz, .asm_720fd
-	call Func_72102
+	jr nz, .isSGB
+	call SendMltReq1Packet
 	and a
 	ret
-.asm_720fd
-	call Func_72102
+.isSGB
+	call SendMltReq1Packet
 	scf
 	ret
 
-Func_72102: ; 72102 (1c:6102)
+SendMltReq1Packet: ; 72102 (1c:6102)
 	ld hl, MltReq1Packet
 	call SendSGBPacket
 	jp Wait7000
 
-Func_7210b: ; 7210b (1c:610b)
+CopyGfxToSuperNintendoVRAM: ; 7210b (1c:610b)
 	di
 	push de
 	call DisableLCD
@@ -503,29 +515,29 @@
 	ld a, $e4
 	ld [rBGP], a
 	ld de, vChars1
-	ld a, [wcf2d]
+	ld a, [wCopyingSGBTileData]
 	and a
-	jr z, .asm_72122
-	call Func_72188
-	jr .asm_72128
-.asm_72122
+	jr z, .notCopyingTileData
+	call CopySGBBorderTiles
+	jr .next
+.notCopyingTileData
 	ld bc, $1000
 	call CopyData
-.asm_72128
+.next
 	ld hl, vBGMap0
 	ld de, $c
 	ld a, $80
 	ld c, $d
-.asm_72132
+.loop
 	ld b, $14
-.asm_72134
+.innerLoop
 	ld [hli], a
 	inc a
 	dec b
-	jr nz, .asm_72134
+	jr nz, .innerLoop
 	add hl, de
 	dec c
-	jr nz, .asm_72132
+	jr nz, .loop
 	ld a, $e3
 	ld [rLCDC], a
 	pop hl
@@ -548,27 +560,27 @@
 	jr nz, .loop
 	ret
 
-Func_72156: ; 72156 (1c:6156)
+SendSGBPackets: ; 72156 (1c:6156)
 	ld a, [wGBC]
 	and a
-	jr z, .asm_72165
+	jr z, .notGBC
 	push de
-	call Func_7216d
+	call InitGBCPalettes
 	pop hl
-	call Func_72187
+	call EmptyFunc5
 	ret
-.asm_72165
+.notGBC
 	push de
 	call SendSGBPacket
 	pop hl
 	jp SendSGBPacket
 
-Func_7216d: ; 7216d (1c:616d)
-	ld a, $80
-	ld [$ff68], a
+InitGBCPalettes: ; 7216d (1c:616d)
+	ld a, $80 ; index 0 with auto-increment
+	ld [rBGPI], a
 	inc hl
 	ld c, $20
-.asm_72174
+.loop
 	ld a, [hli]
 	inc hl
 	add a
@@ -576,37 +588,48 @@
 	add a
 	ld de, SuperPalettes
 	add e
-	jr nc, .asm_72180
+	jr nc, .noCarry
 	inc d
-.asm_72180
+.noCarry
 	ld a, [de]
-	ld [$ff69], a
+	ld [rBGPD], a
 	dec c
-	jr nz, .asm_72174
+	jr nz, .loop
 	ret
 
-Func_72187: ; 72187 (1c:6187)
+EmptyFunc5: ; 72187 (1c:6187)
 	ret
 
-Func_72188: ; 72188 (1c:6188)
-	ld b, $80
-.asm_7218a
-	ld c, $10
-.asm_7218c
+CopySGBBorderTiles: ; 72188 (1c:6188)
+; SGB tile data is stored in a 4BPP planar format.
+; Each tile is 32 bytes. The first 16 bytes contain bit planes 1 and 2, while
+; the second 16 bytes contain bit planes 3 and 4.
+; This function converts 2BPP planar data into this format by mapping
+; 2BPP colors 0-3 to 4BPP colors 0-3. 4BPP colors 4-15 are not used.
+	ld b, 128
+
+.tileLoop
+
+; Copy bit planes 1 and 2 of the tile data.
+	ld c, 16
+.copyLoop
 	ld a, [hli]
 	ld [de], a
 	inc de
 	dec c
-	jr nz, .asm_7218c
-	ld c, $10
+	jr nz, .copyLoop
+
+; Zero bit planes 3 and 4.
+	ld c, 16
 	xor a
-.asm_72195
+.zeroLoop
 	ld [de], a
 	inc de
 	dec c
-	jr nz, .asm_72195
+	jr nz, .zeroLoop
+
 	dec b
-	jr nz, .asm_7218a
+	jr nz, .tileLoop
 	ret
 
 INCLUDE "data/sgb_packets.asm"
--- a/engine/pokedex_rating.asm
+++ b/engine/pokedex_rating.asm
@@ -33,7 +33,7 @@
 	callba PlayPokedexRatingSfx
 	jp WaitForTextScrollButtonPress
 .hallOfFame
-	ld de, wcc5b
+	ld de, wDexRatingNumMonsSeen
 	ld a, [hDexRatingNumMonsSeen]
 	ld [de], a
 	inc de
--- a/engine/predefs.asm
+++ b/engine/predefs.asm
@@ -80,7 +80,7 @@
 	add_predef LoadTilesetHeader
 	add_predef LearnMoveFromLevelUp
 	add_predef LearnMove
-	add_predef IsItemInBag_
+	add_predef GetQuantityOfItemInBag
 	dbw $03,CheckForHiddenObjectOrBookshelfOrCardKeyDoor ; for these two, the bank number is actually 0
 	dbw $03,GiveItem
 	add_predef ChangeBGPalColor0_4Frames
@@ -121,7 +121,7 @@
 	add_predef SetPartyMonTypes
 	add_predef CanLearnTM
 	add_predef TMToMove
-	add_predef Func_71ddf
+	add_predef _RunPaletteCommand
 	add_predef StarterDex ; 46
 	add_predef _AddPartyMon
 	add_predef UpdateHPBar2
--- a/engine/predefs7.asm
+++ b/engine/predefs7.asm
@@ -21,7 +21,7 @@
 	ret c
 	ld hl, wd126
 	set 7, [hl]
-	ld hl, wcc5b
+	ld hl, wElevatorWarpMaps
 	ld a, [wWhichPokemon]
 	add a
 	ld d, 0
--- a/engine/save.asm
+++ b/engine/save.asm
@@ -644,7 +644,7 @@
 	call AddNTimes
 	ld e, l
 	ld d, h
-	ld hl, wcc5b
+	ld hl, wHallOfFame
 	ld bc, HOF_TEAM
 	jr HallOfFame_Copy
 
@@ -653,7 +653,7 @@
 	ld de, sHallOfFame
 	ld bc, HOF_TEAM * (HOF_TEAM_CAPACITY - 1)
 	call HallOfFame_Copy
-	ld hl, wcc5b
+	ld hl, wHallOfFame
 	ld de, sHallOfFame + HOF_TEAM * (HOF_TEAM_CAPACITY - 1)
 	ld bc, HOF_TEAM
 	jr HallOfFame_Copy
@@ -663,7 +663,7 @@
 	ld bc, HOF_TEAM
 	ld a, [wHoFTeamIndex]
 	call AddNTimes
-	ld de, wcc5b
+	ld de, wHallOfFame
 	ld bc, HOF_TEAM
 	; fallthrough
 
--- a/engine/slot_machine.asm
+++ b/engine/slot_machine.asm
@@ -21,8 +21,8 @@
 	call GBPalWhiteOutWithDelay3
 	call LoadSlotMachineTiles
 	call LoadFontTilePatterns
-	ld b, $5
-	call GoPAL_SET
+	ld b, SET_PAL_SLOTS
+	call RunPaletteCommand
 	call GBPalNormal
 	ld a, $e4
 	ld [rOBP0], a
@@ -41,7 +41,7 @@
 	call GBPalWhiteOutWithDelay3
 	ld a, $1
 	ld [wUpdateSpritesEnabled], a
-	call GoPAL_SET_CF1C
+	call RunDefaultPaletteCommand
 	call ReloadMapSpriteTilePatterns
 	call ReloadTilesetTilePatterns
 .done
--- a/engine/titlescreen.asm
+++ b/engine/titlescreen.asm
@@ -134,8 +134,8 @@
 	call LoadScreenTilesFromBuffer2
 	ld a, vBGMap0 / $100
 	call TitleScreenCopyTileMapToVRAM
-	ld b, $6
-	call GoPAL_SET
+	ld b, SET_PAL_TITLE_SCREEN
+	call RunPaletteCommand
 	call GBPalNormal
 	ld a, %11100100
 	ld [rOBP0], a
@@ -215,7 +215,7 @@
 	ld [wNewSoundID], a
 	call PlaySound
 	xor a
-	ld [wcc5b], a
+	ld [wUnusedCC5B], a
 
 ; Keep scrolling in new mons indefinitely until the user performs input.
 .awaitUserInterruptionLoop
--- a/engine/town_map.asm
+++ b/engine/town_map.asm
@@ -314,8 +314,8 @@
 	jr .nextTile
 .done
 	call EnableLCD
-	ld b, $2
-	call GoPAL_SET
+	ld b, SET_PAL_TOWN_MAP
+	call RunPaletteCommand
 	call Delay3
 	call GBPalNormal
 	xor a
@@ -338,7 +338,7 @@
 	call LoadPlayerSpriteGraphics
 	call LoadFontTilePatterns
 	call UpdateSprites
-	jp GoPAL_SET_CF1C
+	jp RunDefaultPaletteCommand
 
 DrawPlayerOrBirdSprite: ; 711c4 (1c:51c4)
 ; a = map number
--- a/engine/trade.asm
+++ b/engine/trade.asm
@@ -268,8 +268,8 @@
 	call Trade_ClearTileMap
 	ld b, vBGMap0 / $100
 	call CopyScreenTileBufferToVRAM
-	ld b, $8
-	call GoPAL_SET
+	ld b, SET_PAL_GENERIC
+	call RunPaletteCommand
 
 ; This function call is pointless. It just copies blank tiles to VRAM that was
 ; already filled with blank tiles.
@@ -552,14 +552,14 @@
 ; continues when the screen is scrolled.
 	push hl
 	coord hl, 0, 4
-	call CopyToScreenEdgeTiles
+	call CopyToRedrawRowOrColumnSrcTiles
 	pop hl
 	ld a, h
-	ld [H_SCREENEDGEREDRAWADDR + 1], a
+	ld [hRedrawRowOrColumnDest + 1], a
 	ld a, l
-	ld [H_SCREENEDGEREDRAWADDR], a
-	ld a, REDRAWROW
-	ld [H_SCREENEDGEREDRAW], a
+	ld [hRedrawRowOrColumnDest], a
+	ld a, REDRAW_ROW
+	ld [hRedrawRowOrColumnMode], a
 	ld c, 10
 	jp DelayFrames
 
@@ -727,10 +727,10 @@
 Trade_LoadMonSprite: ; 415a4 (10:55a4)
 	ld [wcf91], a
 	ld [wd0b5], a
-	ld [wcf1d], a
-	ld b, $b
-	ld c, $0
-	call GoPAL_SET
+	ld [wWholeScreenPaletteMonSpecies], a
+	ld b, SET_PAL_POKEMON_WHOLE_SCREEN
+	ld c, 0
+	call RunPaletteCommand
 	ld a, [H_AUTOBGTRANSFERENABLED]
 	xor $1
 	ld [H_AUTOBGTRANSFERENABLED], a
@@ -849,5 +849,5 @@
 Trade_ShowAnimation: ; 41676 (10:5676)
 	ld [W_ANIMATIONID], a
 	xor a
-	ld [wcc5b], a
+	ld [wAnimationType], a
 	predef_jump MoveAnimation
--- a/home.asm
+++ b/home.asm
@@ -2706,7 +2706,7 @@
 ; set zero flag if item isn't in player's bag
 ; else reset zero flag
 ; related to Pokémon Tower and ghosts
-	predef IsItemInBag_
+	predef GetQuantityOfItemInBag
 	ld a,b
 	and a
 	ret
@@ -4469,7 +4469,7 @@
 	call ReloadMapSpriteTilePatterns
 	call LoadScreenTilesFromBuffer2
 	call LoadTextBoxTilePatterns
-	call GoPAL_SET_CF1C
+	call RunDefaultPaletteCommand
 	jr Delay3
 
 
@@ -4499,13 +4499,13 @@
 	ret
 
 
-GoPAL_SET_CF1C:: ; 3ded (0:3ded)
+RunDefaultPaletteCommand:: ; 3ded (0:3ded)
 	ld b,$ff
-GoPAL_SET:: ; 3def (0:3def)
+RunPaletteCommand:: ; 3def (0:3def)
 	ld a,[wOnSGB]
 	and a
 	ret z
-	predef_jump Func_71ddf
+	predef_jump _RunPaletteCommand
 
 GetHealthBarColor::
 ; Return at hl the palette of
--- a/home/overworld.asm
+++ b/home/overworld.asm
@@ -555,10 +555,10 @@
 	jr z,.savePointer1
 .pointerAdjustmentLoop1
 	ld a,[wWestConnectedMapWidth] ; width of connected map
-	add a,$06
+	add a,MAP_BORDER * 2
 	ld e,a
-	ld d,$00
-	ld b,$00
+	ld d,0
+	ld b,0
 	add hl,de
 	dec c
 	jr nz,.pointerAdjustmentLoop1
@@ -591,10 +591,10 @@
 	jr z,.savePointer2
 .pointerAdjustmentLoop2
 	ld a,[wEastConnectedMapWidth]
-	add a,$06
+	add a,MAP_BORDER * 2
 	ld e,a
-	ld d,$00
-	ld b,$00
+	ld d,0
+	ld b,0
 	add hl,de
 	dec c
 	jr nz,.pointerAdjustmentLoop2
@@ -659,8 +659,8 @@
 .loadNewMap ; load the connected map that was entered
 	call LoadMapHeader
 	call PlayDefaultMusicFadeOutCurrent
-	ld b,$09
-	call GoPAL_SET
+	ld b, SET_PAL_OVERWORLD
+	call RunPaletteCommand
 ; Since the sprite set shouldn't change, this will just update VRAM slots at
 ; $C2XE without loading any tile patterns.
 	callba InitMapSprites
@@ -883,15 +883,15 @@
 	ld hl,wOverworldMap
 	ld a,[W_CURMAPWIDTH]
 	ld [hMapWidth],a
-	add a,$06 ; border (east and west)
+	add a,MAP_BORDER * 2 ; east and west
 	ld [hMapStride],a ; map width + border
-	ld b,$00
+	ld b,0
 	ld c,a
 ; make space for north border (next 3 lines)
 	add hl,bc
 	add hl,bc
 	add hl,bc
-	ld c,$03
+	ld c,MAP_BORDER
 	add hl,bc ; this puts us past the (west) border
 	ld a,[W_MAPDATAPTR] ; tile map pointer
 	ld e,a
@@ -995,7 +995,7 @@
 	ret
 
 LoadNorthSouthConnectionsTileMap:: ; 0ade (0:0ade)
-	ld c,$03
+	ld c,MAP_BORDER
 .loop
 	push de
 	push hl
@@ -1016,7 +1016,7 @@
 	inc h
 .noCarry1
 	ld a,[W_CURMAPWIDTH]
-	add a,$06
+	add a,MAP_BORDER * 2
 	add e
 	ld e,a
 	jr nc,.noCarry2
@@ -1029,7 +1029,7 @@
 LoadEastWestConnectionsTileMap:: ; 0b02 (0:0b02)
 	push hl
 	push de
-	ld c,$03
+	ld c,MAP_BORDER
 .innerLoop
 	ld a,[hli]
 	ld [de],a
@@ -1045,7 +1045,7 @@
 	inc h
 .noCarry1
 	ld a,[W_CURMAPWIDTH]
-	add a,$06
+	add a,MAP_BORDER * 2
 	add e
 	ld e,a
 	jr nc,.noCarry2
@@ -1387,7 +1387,7 @@
 ; update tile block map pointer to next row's address
 	pop de
 	ld a,[W_CURMAPWIDTH]
-	add a,$06
+	add a,MAP_BORDER * 2
 	add e
 	ld e,a
 	jr nc,.noCarry
@@ -1418,7 +1418,7 @@
 	ld bc,$0002
 	add hl,bc
 .copyToVisibleAreaBuffer
-	coord de, 0, 0 ; base address for the tiles that are directly transfered to VRAM during V-blank
+	coord de, 0, 0 ; base address for the tiles that are directly transferred to VRAM during V-blank
 	ld b, SCREEN_HEIGHT
 .rowLoop2
 	ld c, SCREEN_WIDTH
@@ -1662,7 +1662,7 @@
 	ret
 
 MoveTileBlockMapPointerSouth:: ; 0e79 (0:0e79)
-	add a,$06
+	add a,MAP_BORDER * 2
 	ld b,a
 	ld a,[de]
 	add b
@@ -1675,7 +1675,7 @@
 	ret
 
 MoveTileBlockMapPointerNorth:: ; 0e85 (0:0e85)
-	add a,$06
+	add a,MAP_BORDER * 2
 	ld b,a
 	ld a,[de]
 	sub b
@@ -1692,17 +1692,17 @@
 
 ScheduleNorthRowRedraw:: ; 0e91 (0:0e91)
 	coord hl, 0, 0
-	call CopyToScreenEdgeTiles
+	call CopyToRedrawRowOrColumnSrcTiles
 	ld a,[wMapViewVRAMPointer]
-	ld [H_SCREENEDGEREDRAWADDR],a
+	ld [hRedrawRowOrColumnDest],a
 	ld a,[wMapViewVRAMPointer + 1]
-	ld [H_SCREENEDGEREDRAWADDR + 1],a
-	ld a,REDRAWROW
-	ld [H_SCREENEDGEREDRAW],a
+	ld [hRedrawRowOrColumnDest + 1],a
+	ld a,REDRAW_ROW
+	ld [hRedrawRowOrColumnMode],a
 	ret
 
-CopyToScreenEdgeTiles:: ; 0ea6 (0:0ea6)
-	ld de,wScreenEdgeTiles
+CopyToRedrawRowOrColumnSrcTiles:: ; 0ea6 (0:0ea6)
+	ld de,wRedrawRowOrColumnSrcTiles
 	ld c,2 * SCREEN_WIDTH
 .loop
 	ld a,[hli]
@@ -1714,7 +1714,7 @@
 
 ScheduleSouthRowRedraw:: ; 0eb2 (0:0eb2)
 	coord hl, 0, 16
-	call CopyToScreenEdgeTiles
+	call CopyToRedrawRowOrColumnSrcTiles
 	ld a,[wMapViewVRAMPointer]
 	ld l,a
 	ld a,[wMapViewVRAMPointer + 1]
@@ -1724,11 +1724,11 @@
 	ld a,h
 	and a,$03
 	or a,$98
-	ld [H_SCREENEDGEREDRAWADDR + 1],a
+	ld [hRedrawRowOrColumnDest + 1],a
 	ld a,l
-	ld [H_SCREENEDGEREDRAWADDR],a
-	ld a,REDRAWROW
-	ld [H_SCREENEDGEREDRAW],a
+	ld [hRedrawRowOrColumnDest],a
+	ld a,REDRAW_ROW
+	ld [hRedrawRowOrColumnMode],a
 	ret
 
 ScheduleEastColumnRedraw:: ; 0ed3 (0:0ed3)
@@ -1742,15 +1742,15 @@
 	add a,18
 	and a,$1f
 	or b
-	ld [H_SCREENEDGEREDRAWADDR],a
+	ld [hRedrawRowOrColumnDest],a
 	ld a,[wMapViewVRAMPointer + 1]
-	ld [H_SCREENEDGEREDRAWADDR + 1],a
-	ld a,REDRAWCOL
-	ld [H_SCREENEDGEREDRAW],a
+	ld [hRedrawRowOrColumnDest + 1],a
+	ld a,REDRAW_COL
+	ld [hRedrawRowOrColumnMode],a
 	ret
 
 ScheduleColumnRedrawHelper:: ; 0ef2 (0:0ef2)
-	ld de,wScreenEdgeTiles
+	ld de,wRedrawRowOrColumnSrcTiles
 	ld c,SCREEN_HEIGHT
 .loop
 	ld a,[hli]
@@ -1773,11 +1773,11 @@
 	coord hl, 0, 0
 	call ScheduleColumnRedrawHelper
 	ld a,[wMapViewVRAMPointer]
-	ld [H_SCREENEDGEREDRAWADDR],a
+	ld [hRedrawRowOrColumnDest],a
 	ld a,[wMapViewVRAMPointer + 1]
-	ld [H_SCREENEDGEREDRAWADDR + 1],a
-	ld a,REDRAWCOL
-	ld [H_SCREENEDGEREDRAW],a
+	ld [hRedrawRowOrColumnDest + 1],a
+	ld a,REDRAW_COL
+	ld [hRedrawRowOrColumnMode],a
 	ret
 
 ; function to write the tiles that make up a tile block to memory
@@ -2343,8 +2343,8 @@
 	ld a,$01
 	ld [wUpdateSpritesEnabled],a
 	call EnableLCD
-	ld b,$09
-	call GoPAL_SET
+	ld b, SET_PAL_OVERWORLD
+	call RunPaletteCommand
 	call LoadPlayerSpriteGraphics
 	ld a,[wd732]
 	and a,1 << 4 | 1 << 3 ; fly warp or dungeon warp
--- a/home/vblank.asm
+++ b/home/vblank.asm
@@ -22,7 +22,7 @@
 
 	call AutoBgMapTransfer
 	call VBlankCopyBgMap
-	call RedrawExposedScreenEdge
+	call RedrawRowOrColumn
 	call VBlankCopy
 	call VBlankCopyDouble
 	call UpdateMovingBgTiles
@@ -74,7 +74,7 @@
 
 	callba TrackPlayTime ; keep track of time played
 
-	ld a, [$fff9]
+	ld a, [hDisableJoypadPolling]
 	and a
 	call z, ReadJoypad
 
--- a/home/vcopy.asm
+++ b/home/vcopy.asm
@@ -33,23 +33,26 @@
 	jr nz,.loop
 	ret
 
-; When the player takes a step, a row or column of 2x2 tile blocks at the edge
-; of the screen toward which they moved is exposed and has to be redrawn.
-; This function does the redrawing.
-RedrawExposedScreenEdge:: ; 1d01 (0:1d01)
-	ld a,[H_SCREENEDGEREDRAW]
+RedrawRowOrColumn:: ; 1d01 (0:1d01)
+; This function redraws a BG row of height 2 or a BG column of width 2.
+; One of its main uses is redrawing the row or column that will be exposed upon
+; scrolling the BG when the player takes a step. Redrawing only the exposed
+; row or column is more efficient than redrawing the entire screen.
+; However, this function is also called repeatedly to redraw the whole screen
+; when necessary. It is also used in trade animation and elevator code.
+	ld a,[hRedrawRowOrColumnMode]
 	and a
 	ret z
 	ld b,a
 	xor a
-	ld [H_SCREENEDGEREDRAW],a
+	ld [hRedrawRowOrColumnMode],a
 	dec b
 	jr nz,.redrawRow
 .redrawColumn
-	ld hl,wScreenEdgeTiles
-	ld a,[H_SCREENEDGEREDRAWADDR]
+	ld hl,wRedrawRowOrColumnSrcTiles
+	ld a,[hRedrawRowOrColumnDest]
 	ld e,a
-	ld a,[H_SCREENEDGEREDRAWADDR + 1]
+	ld a,[hRedrawRowOrColumnDest + 1]
 	ld d,a
 	ld c,SCREEN_HEIGHT
 .loop1
@@ -58,7 +61,7 @@
 	inc de
 	ld a,[hli]
 	ld [de],a
-	ld a,31
+	ld a,BG_MAP_WIDTH - 1
 	add e
 	ld e,a
 	jr nc,.noCarry
@@ -72,23 +75,24 @@
 	dec c
 	jr nz,.loop1
 	xor a
-	ld [H_SCREENEDGEREDRAW],a
+	ld [hRedrawRowOrColumnMode],a
 	ret
 .redrawRow
-	ld hl,wScreenEdgeTiles
-	ld a,[H_SCREENEDGEREDRAWADDR]
+	ld hl,wRedrawRowOrColumnSrcTiles
+	ld a,[hRedrawRowOrColumnDest]
 	ld e,a
-	ld a,[H_SCREENEDGEREDRAWADDR + 1]
+	ld a,[hRedrawRowOrColumnDest + 1]
 	ld d,a
 	push de
-	call .drawHalf ; draw upper half
+	call .DrawHalf ; draw upper half
 	pop de
-	ld a,32 ; width of VRAM background map
+	ld a,BG_MAP_WIDTH ; width of VRAM background map
 	add e
 	ld e,a
-			 ; draw lower half
-.drawHalf
-	ld c,10
+	; fall through and draw lower half
+
+.DrawHalf
+	ld c,SCREEN_WIDTH / 2
 .loop2
 	ld a,[hli]
 	ld [de],a
@@ -113,7 +117,7 @@
 ; background per V-blank. It cycles through which third it draws.
 ; This transfer is turned off when walking around the map, but is turned
 ; on when talking to sprites, battling, using menus, etc. This is because
-; the above function, RedrawExposedScreenEdge, is used when walking to
+; the above function, RedrawRowOrColumn, is used when walking to
 ; improve efficiency.
 AutoBgMapTransfer:: ; 1d57 (0:1d57)
 	ld a,[H_AUTOBGTRANSFERENABLED]
@@ -302,12 +306,11 @@
 
 
 VBlankCopy::
-; Copy [H_VBCOPYSIZE] 2bpp tiles
+; Copy [H_VBCOPYSIZE] 2bpp tiles (or 16 * [H_VBCOPYSIZE] tile map entries)
 ; from H_VBCOPYSRC to H_VBCOPYDEST.
 
-; Source and destination addresses
-; are updated, so transfer can
-; continue in subsequent calls.
+; Source and destination addresses are updated,
+; so transfer can continue in subsequent calls.
 
 	ld a, [H_VBCOPYSIZE]
 	and a
--- a/hram.asm
+++ b/hram.asm
@@ -242,12 +242,12 @@
 ; 00 = no redraw
 ; 01 = redraw column
 ; 02 = redraw row
-H_SCREENEDGEREDRAW EQU $FFD0
+hRedrawRowOrColumnMode EQU $FFD0
 
-REDRAWCOL EQU 1
-REDRAWROW EQU 2
+REDRAW_COL EQU 1
+REDRAW_ROW EQU 2
 
-H_SCREENEDGEREDRAWADDR EQU $FFD1
+hRedrawRowOrColumnDest EQU $FFD1
 
 hRandomAdd EQU $FFD3
 hRandomSub EQU $FFD4
@@ -269,7 +269,7 @@
 
 H_CURRENTSPRITEOFFSET EQU $FFDA ; multiple of $10
 
-hFossilCounter EQU $FFDB
+hItemCounter EQU $FFDB
 
 hGymGateIndex EQU $FFDB
 
@@ -285,7 +285,7 @@
 hOaksAideResult       EQU $FFDB
 
 hOaksAideRequirement  EQU $FFDB ; required number of owned mons
-hOaksAideItemReward   EQU $FFDC
+hOaksAideRewardItem   EQU $FFDC
 hOaksAideNumMonsOwned EQU $FFDD
 
 hItemToRemoveID    EQU $FFDB
@@ -316,6 +316,8 @@
 hFlags_0xFFF6 EQU $FFF6
 
 hFieldMoveMonMenuTopMenuItemX EQU $FFF7
+
+hDisableJoypadPolling EQU $FFF9
 
 hJoyInput EQU $FFF8
 
--- a/macros.asm
+++ b/macros.asm
@@ -104,6 +104,14 @@
 	dw wTileMap + 20 * \2 + \1
 	ENDM
 
+;\1 = r
+;\2 = X
+;\3 = Y
+;\4 = map width
+overworldMapCoord: MACRO
+	ld \1, wOverworldMap + ((\2) + 3) + (((\3) + 3) * ((\4) + (3 * 2)))
+	ENDM
+
 ;\1 = Map Width
 ;\2 = Rows above (Y-blocks)
 ;\3 = X movement (X-blocks)
--- a/main.asm
+++ b/main.asm
@@ -3156,7 +3156,7 @@
 	ld [H_AUTOBGTRANSFERENABLED], a
 	ld [hTilesetType], a ; no flower/water BG tile animations
 	call LoadCurrentMapView
-	call GoPAL_SET_CF1C
+	call RunDefaultPaletteCommand
 	ld hl, wMapViewVRAMPointer
 	ld a, [hli]
 	ld h, [hl]
@@ -3184,7 +3184,7 @@
 	add hl, de
 	dec a
 	jr nz, .calcWRAMAddrLoop
-	call CopyToScreenEdgeTiles
+	call CopyToRedrawRowOrColumnSrcTiles
 	pop hl
 	ld de, $20
 	ld a, [$ffbe]
@@ -3196,11 +3196,11 @@
 	or $98
 	dec c
 	jr nz, .calcVRAMAddrLoop
-	ld [H_SCREENEDGEREDRAWADDR + 1], a
+	ld [hRedrawRowOrColumnDest + 1], a
 	ld a, l
-	ld [H_SCREENEDGEREDRAWADDR], a
-	ld a, REDRAWROW
-	ld [H_SCREENEDGEREDRAW], a
+	ld [hRedrawRowOrColumnDest], a
+	ld a, REDRAW_ROW
+	ld [hRedrawRowOrColumnMode], a
 	call DelayFrame
 	ld hl, $ffbe
 	inc [hl]
@@ -4508,21 +4508,23 @@
 	ret
 
 
-IsItemInBag_: ; f8a5 (3:78a5)
+GetQuantityOfItemInBag: ; f8a5 (3:78a5)
+; In: b = item ID
+; Out: b = how many of that item are in the bag
 	call GetPredefRegisters
 	ld hl, wNumBagItems
-.asm_f8ab
+.loop
 	inc hl
 	ld a, [hli]
 	cp $ff
-	jr z, .asm_f8b7
+	jr z, .notInBag
 	cp b
-	jr nz, .asm_f8ab
+	jr nz, .loop
 	ld a, [hl]
 	ld b, a
 	ret
-.asm_f8b7
-	ld b, $0
+.notInBag
+	ld b, 0
 	ret
 
 FindPathToPlayer: ; f8ba (3:78ba)
--- a/scripts/celadonmartelevator.asm
+++ b/scripts/celadonmartelevator.asm
@@ -35,7 +35,7 @@
 	ld hl, CeladonMartElavatorFloors
 	call LoadItemList
 	ld hl, CeldaonMartElevatorWarpMaps
-	ld de, wcc5b
+	ld de, wElevatorWarpMaps
 	ld bc, CeldaonMartElevatorWarpMapsEnd - CeldaonMartElevatorWarpMaps
 	jp CopyData
 
--- a/scripts/celadonmartroof.asm
+++ b/scripts/celadonmartroof.asm
@@ -1,34 +1,35 @@
 CeladonMartRoofScript: ; 483d5 (12:43d5)
 	jp EnableAutoTextBoxDrawing
 
-CeladonMartRoofScript_483d8: ; 483d8 (12:43d8)
+CeladonMartRoofScript_GetDrinksInBag: ; 483d8 (12:43d8)
+; construct a list of all drinks in the player's bag
 	xor a
-	ld [wcd37], a
-	ld de, wcc5b
+	ld [wFilteredBagItemsCount], a
+	ld de, wFilteredBagItems
 	ld hl, CeladonMartRoofDrinkList
-.asm_483e2
+.loop
 	ld a, [hli]
 	and a
-	jr z, .asm_48404
+	jr z, .done
 	push hl
 	push de
 	ld [wd11e], a
 	ld b, a
-	predef IsItemInBag_
+	predef GetQuantityOfItemInBag
 	pop de
 	pop hl
 	ld a, b
 	and a
-	jr z, .asm_483e2
+	jr z, .loop ; if the item isn't in the bag
 	ld a, [wd11e]
 	ld [de], a
 	inc de
 	push hl
-	ld hl, wcd37
+	ld hl, wFilteredBagItemsCount
 	inc [hl]
 	pop hl
-	jr .asm_483e2
-.asm_48404
+	jr .loop
+.done
 	ld a, $ff
 	ld [de], a
 	ret
@@ -39,7 +40,7 @@
 	db LEMONADE
 	db $00
 
-CeladonMartRoofScript_4840c: ; 4840c (12:440c)
+CeladonMartRoofScript_GiveDrinkToGirl: ; 4840c (12:440c)
 	ld hl, wd730
 	set 6, [hl]
 	ld hl, CeladonMartRoofText_484ee
@@ -48,83 +49,84 @@
 	ld [wCurrentMenuItem], a
 	ld a, A_BUTTON | B_BUTTON
 	ld [wMenuWatchedKeys], a
-	ld a, [wcd37]
+	ld a, [wFilteredBagItemsCount]
 	dec a
 	ld [wMaxMenuItem], a
-	ld a, $2
+	ld a, 2
 	ld [wTopMenuItemY], a
-	ld a, $1
+	ld a, 1
 	ld [wTopMenuItemX], a
-	ld a, [wcd37]
+	ld a, [wFilteredBagItemsCount]
 	dec a
-	ld bc, $2
-	ld hl, $3
+	ld bc, 2
+	ld hl, 3
 	call AddNTimes
 	dec l
 	ld b, l
-	ld c, $c
+	ld c, 12
 	coord hl, 0, 0
 	call TextBoxBorder
 	call UpdateSprites
-	call CeladonMartRoofScript_48532
+	call CeladonMartRoofScript_PrintDrinksInBag
 	ld hl, wd730
 	res 6, [hl]
 	call HandleMenuInput
 	bit 1, a ; pressed b
 	ret nz
-	ld hl, wcc5b
+	ld hl, wFilteredBagItems
 	ld a, [wCurrentMenuItem]
-	ld d, $0
+	ld d, 0
 	ld e, a
 	add hl, de
 	ld a, [hl]
-	ld [$ffdb], a
+	ld [hItemToRemoveID], a
 	cp FRESH_WATER
-	jr z, .asm_484b6
+	jr z, .gaveFreshWater
 	cp SODA_POP
-	jr z, .asm_48492
+	jr z, .gaveSodaPop
+; gave Lemonade
 	CheckEvent EVENT_GOT_TM49
-	jr nz, .asm_484e0
+	jr nz, .alreadyGaveDrink
 	ld hl, CeladonMartRoofText_48515
 	call PrintText
 	call RemoveItemByIDBank12
 	lb bc, TM_49, 1
 	call GiveItem
-	jr nc, .BagFull
+	jr nc, .bagFull
 	ld hl, ReceivedTM49Text
 	call PrintText
 	SetEvent EVENT_GOT_TM49
 	ret
-.asm_48492
+.gaveSodaPop
 	CheckEvent EVENT_GOT_TM48
-	jr nz, .asm_484e0
+	jr nz, .alreadyGaveDrink
 	ld hl, CeladonMartRoofText_48504
 	call PrintText
 	call RemoveItemByIDBank12
 	lb bc, TM_48, 1
 	call GiveItem
-	jr nc, .BagFull
+	jr nc, .bagFull
 	ld hl, CeladonMartRoofText_4850a
 	call PrintText
 	SetEvent EVENT_GOT_TM48
 	ret
-.asm_484b6
+.gaveFreshWater
 	CheckEvent EVENT_GOT_TM13
-	jr nz, .asm_484e0
+	jr nz, .alreadyGaveDrink
 	ld hl, CeladonMartRoofText_484f3
 	call PrintText
 	call RemoveItemByIDBank12
 	lb bc, TM_13, 1
 	call GiveItem
-	jr nc, .BagFull
+	jr nc, .bagFull
 	ld hl, CeladonMartRoofText_484f9
 	call PrintText
 	SetEvent EVENT_GOT_TM13
 	ret
-.BagFull
+.bagFull
 	ld hl, CeladonMartRoofText_48526
 	jp PrintText
-.asm_484e0
+.alreadyGaveDrink
 	ld hl, CeladonMartRoofText_4852c
 	jp PrintText
 
@@ -181,11 +183,11 @@
 	db $0d
 	db "@"
 
-CeladonMartRoofScript_48532: ; 48532 (12:4532)
-	ld hl, wcc5b
+CeladonMartRoofScript_PrintDrinksInBag: ; 48532 (12:4532)
+	ld hl, wFilteredBagItems
 	xor a
-	ld [$ffdb], a
-.asm_48538
+	ld [hItemCounter], a
+.loop
 	ld a, [hli]
 	cp $ff
 	ret z
@@ -193,15 +195,15 @@
 	ld [wd11e], a
 	call GetItemName
 	coord hl, 2, 2
-	ld a, [$ffdb]
+	ld a, [hItemCounter]
 	ld bc, SCREEN_WIDTH * 2
 	call AddNTimes
 	ld de, wcd6d
 	call PlaceString
-	ld hl, $ffdb
+	ld hl, hItemCounter
 	inc [hl]
 	pop hl
-	jr .asm_48538
+	jr .loop
 
 CeladonMartRoofTextPointers: ; 4855b (12:455b)
 	dw CeladonMartRoofText1
@@ -217,11 +219,11 @@
 
 CeladonMartRoofText2: ; 4856c (12:456c)
 	TX_ASM
-	call CeladonMartRoofScript_483d8
-	ld a, [wcd37]
+	call CeladonMartRoofScript_GetDrinksInBag
+	ld a, [wFilteredBagItemsCount]
 	and a
-	jr z, .asm_4858f
-	ld a, $1
+	jr z, .noDrinksInBag
+	ld a, 1
 	ld [wDoNotWaitForButtonPressAfterDisplayingText], a
 	ld hl, CeladonMartRoofText4
 	call PrintText
@@ -228,13 +230,13 @@
 	call YesNoChoice
 	ld a, [wCurrentMenuItem]
 	and a
-	jr nz, .asm_48595
-	call CeladonMartRoofScript_4840c
-	jr .asm_48595
-.asm_4858f
+	jr nz, .done
+	call CeladonMartRoofScript_GiveDrinkToGirl
+	jr .done
+.noDrinksInBag
 	ld hl, CeladonMartRoofText3
 	call PrintText
-.asm_48595
+.done
 	jp TextScriptEnd
 
 CeladonMartRoofText3: ; 48598 (12:4598)
--- a/scripts/ceruleanhousetrashed.asm
+++ b/scripts/ceruleanhousetrashed.asm
@@ -10,7 +10,7 @@
 CeruleanHouseTrashedText1: ; 1d68f (7:568f)
 	TX_ASM
 	ld b, $e4
-	predef IsItemInBag_
+	predef GetQuantityOfItemInBag
 	and b
 	jr z, .asm_f8734
 	ld hl, CeruleanHouseTrashedText_1d6b0
--- a/scripts/lab4.asm
+++ b/scripts/lab4.asm
@@ -5,12 +5,11 @@
 	dw Lab4Text1
 	dw Lab4Text2
 
-Lab4Script_75d38: ; 75d38 (1d:5d38)
+Lab4Script_GetFossilsInBag: ; 75d38 (1d:5d38)
 ; construct a list of all fossils in the player's bag
-
 	xor a
-	ld [wcd37], a
-	ld de, wcc5b
+	ld [wFilteredBagItemsCount], a
+	ld de, wFilteredBagItems
 	ld hl, FossilsList
 .loop
 	ld a, [hli]
@@ -20,7 +19,7 @@
 	push de
 	ld [wd11e], a
 	ld b, a
-	predef IsItemInBag_
+	predef GetQuantityOfItemInBag
 	pop de
 	pop hl
 	ld a, b
@@ -32,7 +31,7 @@
 	ld [de], a
 	inc de
 	push hl
-	ld hl, wcd37
+	ld hl, wFilteredBagItemsCount
 	inc [hl]
 	pop hl
 	jr .loop
@@ -53,8 +52,8 @@
 	jr nz, .asm_75d96
 	ld hl, Lab4Text_75dc6
 	call PrintText
-	call Lab4Script_75d38
-	ld a, [wcd37]
+	call Lab4Script_GetFossilsInBag
+	ld a, [wFilteredBagItemsCount]
 	and a
 	jr z, .asm_75d8d
 	callba GiveFossilToCinnabarLab
--- a/scripts/oakslab.asm
+++ b/scripts/oakslab.asm
@@ -449,13 +449,13 @@
 	ld a, [W_XCOORD]
 	cp $4
 	; move left or right depending on where the player is standing
-	jr nz, .asm_1ce5b
-	ld a, $c0
-	jr .asm_1ce5d
-.asm_1ce5b
-	ld a, $80
-.asm_1ce5d
-	ld [wcc5b], a
+	jr nz, .moveLeft
+	ld a, NPC_MOVEMENT_RIGHT
+	jr .next
+.moveLeft
+	ld a, NPC_MOVEMENT_LEFT
+.next
+	ld [wNPCMovementDirections], a
 
 	ld a, $e
 	ld [W_OAKSLABCURSCRIPT], a
@@ -855,7 +855,7 @@
 	ld [hl], SPRITE_FACING_RIGHT
 	ld hl, wd730
 	set 6, [hl]
-	predef StarterDex  ; StarterDex
+	predef StarterDex
 	ld hl, wd730
 	res 6, [hl]
 	call ReloadMapData
--- a/scripts/rockethideoutelevator.asm
+++ b/scripts/rockethideoutelevator.asm
@@ -35,7 +35,7 @@
 	ld hl, RocketHideoutElavatorFloors
 	call LoadItemList
 	ld hl, RocketHideoutElevatorWarpMaps
-	ld de, wcc5b
+	ld de, wElevatorWarpMaps
 	ld bc, RocketHideoutElevatorWarpMapsEnd - RocketHideoutElevatorWarpMaps
 	call CopyData
 	ret
--- a/scripts/route11gateupstairs.asm
+++ b/scripts/route11gateupstairs.asm
@@ -22,13 +22,13 @@
 	ld a, 30 ; pokemon needed
 	ld [hOaksAideRequirement], a
 	ld a, ITEMFINDER ; oak's aide reward
-	ld [hOaksAideItemReward], a
+	ld [hOaksAideRewardItem], a
 	ld [wd11e], a
 	call GetItemName
 	ld h, d
 	ld l, e
-	ld de, wcc5b
-	ld bc, $000d
+	ld de, wOaksAideRewardItemName
+	ld bc, ITEM_NAME_LENGTH
 	call CopyData
 	predef OaksAideScript
 	ld a, [hOaksAideResult]
--- a/scripts/route15gateupstairs.asm
+++ b/scripts/route15gateupstairs.asm
@@ -12,12 +12,12 @@
 	ld a, 50 ; pokemon needed
 	ld [hOaksAideRequirement], a
 	ld a, EXP__ALL ; oak's aide reward
-	ld [hOaksAideItemReward], a
+	ld [hOaksAideRewardItem], a
 	ld [wd11e], a
 	call GetItemName
 	ld hl, wcd6d
-	ld de, wcc5b
-	ld bc, $000d
+	ld de, wOaksAideRewardItemName
+	ld bc, ITEM_NAME_LENGTH
 	call CopyData
 	predef OaksAideScript
 	ld a, [hOaksAideResult]
--- a/scripts/route2gate.asm
+++ b/scripts/route2gate.asm
@@ -12,12 +12,12 @@
 	ld a, 10 ; pokemon needed
 	ld [hOaksAideRequirement], a
 	ld a, HM_05 ; oak's aide reward
-	ld [hOaksAideItemReward], a
+	ld [hOaksAideRewardItem], a
 	ld [wd11e], a
 	call GetItemName
 	ld hl, wcd6d
-	ld de, wcc5b
-	ld bc, $000d
+	ld de, wOaksAideRewardItemName
+	ld bc, ITEM_NAME_LENGTH
 	call CopyData
 	predef OaksAideScript
 	ld a, [hOaksAideResult]
--- a/scripts/silphcoelevator.asm
+++ b/scripts/silphcoelevator.asm
@@ -35,7 +35,7 @@
 	ld hl, SilphCoElavatorFloors
 	call LoadItemList
 	ld hl, SilphCoElevatorWarpMaps
-	ld de, wcc5b
+	ld de, wElevatorWarpMaps
 	ld bc, SilphCoElevatorWarpMapsEnd - SilphCoElevatorWarpMaps
 	call CopyData
 	ret
--- a/scripts/vermilioncity.asm
+++ b/scripts/vermilioncity.asm
@@ -53,7 +53,7 @@
 	CheckEvent EVENT_SS_ANNE_LEFT
 	jr nz, .asm_19810
 	ld b, S_S__TICKET
-	predef IsItemInBag_
+	predef GetQuantityOfItemInBag
 	ld a, b
 	and a
 	ret nz
@@ -171,7 +171,7 @@
 	ld hl, SSAnneWelcomeText9
 	call PrintText
 	ld b, S_S__TICKET
-	predef IsItemInBag_
+	predef GetQuantityOfItemInBag
 	ld a, b
 	and a
 	jr nz, .asm_198e9
--- a/scripts/vermiliondock.asm
+++ b/scripts/vermiliondock.asm
@@ -106,7 +106,7 @@
 	xor a
 	ld [rWY], a
 	ld [hWY], a
-	call VermilionDock_1dc94
+	call VermilionDock_EraseSSAnne
 	ld a, $90
 	ld [hWY], a
 	ld a, $1
@@ -178,21 +178,29 @@
 	jr z, .asm_1dc8e
 	ret
 
-VermilionDock_1dc94: ; 1dc94 (7:5c94)
-	ld hl, wcc5b
-	ld bc, SCREEN_WIDTH * 9
-	ld a, $14
+VermilionDock_EraseSSAnne: ; 1dc94 (7:5c94)
+; Fill the area the S.S. Anne occupies in BG map 0 with water tiles.
+	ld hl, wVermilionDockTileMapBuffer
+	ld bc, (5 * BG_MAP_WIDTH) + SCREEN_WIDTH
+	ld a, $14 ; water tile
 	call FillMemory
-	ld hl, vBGMap0 + 10 * 32
-	ld de, wcc5b
-	ld bc, $000c
+	ld hl, vBGMap0 + 10 * BG_MAP_WIDTH
+	ld de, wVermilionDockTileMapBuffer
+	ld bc, (6 * BG_MAP_WIDTH) / 16
 	call CopyVideoData
-	ld hl, wOverworldMap + 10 + 7 * VERMILION_DOCK_WIDTH ; 10, 7
-	ld a, $d
+
+; Replace the blocks of the lower half of the ship with water blocks. This
+; leaves the upper half alone, but that doesn't matter because replacing any of
+; the blocks is unnecessary because the blocks the ship occupies are south of
+; the player and won't be redrawn when the player automatically walks north and
+; exits the map. This code could be removed without affecting anything.
+	overworldMapCoord hl, 5, 2, VERMILION_DOCK_WIDTH
+	ld a, $d ; water block
 	ld [hli], a
 	ld [hli], a
 	ld [hli], a
 	ld [hl], a
+
 	ld a, SFX_SS_ANNE_HORN
 	call PlaySound
 	ld c, 120
--- a/text.asm
+++ b/text.asm
@@ -100,7 +100,7 @@
 	cont "I'm supposed to"
 	cont "give you an"
 	cont "@"
-	TX_RAM wcc5b
+	TX_RAM wOaksAideRewardItemName
 	text "!"
 
 	para "So, ", $52, "! Have"
@@ -124,7 +124,7 @@
 	text " kinds"
 	line "if you want the"
 	cont "@"
-	TX_RAM wcc5b
+	TX_RAM wOaksAideRewardItemName
 	text "."
 	done
 
@@ -136,7 +136,7 @@
 	db $0
 	line "kinds, come back"
 	cont "for @"
-	TX_RAM wcc5b
+	TX_RAM wOaksAideRewardItemName
 	text "."
 	done
 
@@ -154,7 +154,7 @@
 _OaksAideGotItemText:: ; 802d9 (20:42d9)
 	text $52, " got the"
 	line "@"
-	TX_RAM wcc5b
+	TX_RAM wOaksAideRewardItemName
 	text "!@@"
 
 _OaksAideNoRoomText:: ; 802ec (20:42ec)
@@ -162,7 +162,7 @@
 	line "don't have any"
 	cont "room for the"
 	cont "@"
-	TX_RAM wcc5b
+	TX_RAM wOaksAideRewardItemName
 	text "."
 	done
 
@@ -363,10 +363,10 @@
 
 _DexSeenOwnedText:: ; 8823e (22:423e)
 	text "#DEX   Seen:@"
-	TX_NUM wcc5b, 1, 3
+	TX_NUM wDexRatingNumMonsSeen, 1, 3
 	db $0
 	line "         Owned:@"
-	TX_NUM wcc5c, 1, 3
+	TX_NUM wDexRatingNumMonsOwned, 1, 3
 	db "@"
 
 _DexRatingText:: ; 88267 (22:4267)
@@ -1467,7 +1467,7 @@
 	text "a boosted"
 	cont "@@"
 _ExpPointsText:: ; 89bee (22:5bee)
-	TX_NUM wcf4b, 2, 4
+	TX_NUM wExpAmountGained, 2, 4
 	text " EXP. Points!"
 	prompt
 
@@ -2686,7 +2686,7 @@
 	done
 
 _LearnedMove1Text:: ; a273b (28:673b)
-	TX_RAM wd036
+	TX_RAM wLearnMoveMonName
 	text " learned"
 	line "@"
 	TX_RAM wcf4b
@@ -2705,7 +2705,7 @@
 	done
 
 _DidNotLearnText:: ; a278a (28:678a)
-	TX_RAM wd036
+	TX_RAM wLearnMoveMonName
 	db $0
 	line "did not learn"
 	cont "@"
@@ -2714,7 +2714,7 @@
 	prompt
 
 _TryingToLearnText:: ; a27a4 (28:67a4)
-	TX_RAM wd036
+	TX_RAM wLearnMoveMonName
 	text " is"
 	line "trying to learn"
 	cont "@"
@@ -2722,7 +2722,7 @@
 	text "!"
 
 	para "But, @"
-	TX_RAM wd036
+	TX_RAM wLearnMoveMonName
 	db $0
 	line "can't learn more"
 	cont "than 4 moves!"
@@ -2743,7 +2743,7 @@
 _ForgotAndText:: ; a2830 (28:6830)
 	db $0
 	para "@"
-	TX_RAM wd036
+	TX_RAM wLearnMoveMonName
 	text " forgot"
 	line "@"
 	TX_RAM wcd6d
--- a/wram.asm
+++ b/wram.asm
@@ -287,9 +287,9 @@
 wOverworldMap:: ; c6e8
 	ds 1300
 
-wScreenEdgeTiles:: ; cbfc
-; the tiles of the row or column to be redrawn by RedrawExposedScreenEdge
-	ds 20 * 2
+wRedrawRowOrColumnSrcTiles:: ; cbfc
+; the tiles of the row or column to be redrawn by RedrawRowOrColumn
+	ds SCREEN_WIDTH * 2
 
 ; coordinates of the position of the cursor for the top menu item (id 0)
 wTopMenuItemY:: ; cc24
@@ -477,6 +477,29 @@
 
 	ds 2
 
+wUnusedCC5B:: ; cc5b
+
+wVermilionDockTileMapBuffer:: ; cc5b
+; 180 bytes
+
+wOaksAideRewardItemName:: ; cc5b
+
+wDexRatingNumMonsSeen:: ; cc5b
+
+wFilteredBagItems:: ; cc5b
+; List of bag items that has been filtered to a certain type of items,
+; such as drinks or fossils.
+
+wElevatorWarpMaps:: ; cc5b
+
+wMonPartySpritesSavedOAM:: ; cc5b
+; Saved copy of OAM for the first frame of the animation to make it easy to
+; flip back from the second frame.
+; $60 bytes
+
+wTrainerCardBlkPacket:: ; cc5b
+; $40 bytes
+
 wSlotMachineSevenAndBarModeChance:: ; cc5b
 ; If a random number greater than this value is generated, then the player is
 ; allowed to have three 7 symbols or bar symbols line up.
@@ -490,11 +513,14 @@
 ; values between 0-6. Shake screen horizontally, shake screen vertically, blink Pokemon...
 
 wNPCMovementDirections:: ; cc5b
+	ds 1
 
-wcc5b:: ds 1 ; these upcoming values below are miscellaneous storage values
-wcc5c:: ds 1 ; used in pokedex evaluation as well
-wcc5d:: ds 1 ; used in pokedex evaluation
+wDexRatingNumMonsOwned:: ; cc5c
+	ds 1
 
+wDexRatingText:: ; cc5d
+	ds 1
+
 wSlotMachineSavedROMBank:: ; cc5e
 ; ROM back to return to when the player is done with the slot machine
 	ds 1
@@ -551,8 +577,13 @@
 wEnemySubstituteHP:: ; ccd8
 	ds 1
 
-wccd9:: ds 2 ; used in InitBattleVariablesLoop (written to after the loop is finished)
+wTestBattlePlayerSelectedMove:: ; ccd9
+; The player's selected move during a test battle.
+; InitBattleVariables sets it to the move Pound.
+	ds 1
 
+	ds 1
+
 wMoveMenuType:: ; ccdb
 ; 0=regular, 1=mimic, 2=above message box (relearn, heal pp..)
 	ds 1
@@ -591,8 +622,8 @@
 
 	ds 1
 
-wcceb:: ds 1 ; used to save the dvs of a mon when it uses transform
-wccec:: ds 1 ; also used with above case
+wTransformedEnemyMonOriginalDVs:: ; cceb
+	ds 2
 
 wMonIsDisobedient:: ds 1 ; cced
 
@@ -599,7 +630,10 @@
 wPlayerDisabledMoveNumber:: ds 1 ; ccee
 wEnemyDisabledMoveNumber:: ds 1 ; ccef
 
-wccf0:: ds 1 ; used as a check if a mon fainted
+wInHandlePlayerMonFainted:: ; ccf0
+; When running in the scope of HandlePlayerMonFainted, it equals 1.
+; When running in the scope of HandleEnemyMonFainted, it equals 0.
+	ds 1
 
 wPlayerUsedMove:: ds 1 ; ccf1
 wEnemyUsedMove:: ds 1 ; ccf2
@@ -612,9 +646,14 @@
 ; flags that indicate which party members have fought the current enemy mon
 	flag_array 6
 
-wccf6:: ds 1 ; used in some hp bar thing
-wPlayerMonMinimized:: ds 1 ; ccf7
+wLowHealthAlarmDisabled:: ; ccf6
+; Whether the low health alarm has been disabled due to the player winning the
+; battle.
+	ds 1
 
+wPlayerMonMinimized:: ; ccf7
+	ds 1
+
 	ds 13
 
 wLuckySlotHiddenObjectIndex:: ; cd05
@@ -720,8 +759,12 @@
 
 wNPCMovementDirections2Index:: ; cd37
 
-wcd37:: ds 1 ; used in list menus, like the fossil lab menu or drink girl menu. Also used in link menu.
+wUnusedCD37:: ; cd37
 
+wFilteredBagItemsCount:: ; cd37
+; number of items in wFilteredBagItems list
+	ds 1
+
 wSimulatedJoypadStatesIndex:: ; cd38
 ; the next simulated joypad state is at wSimulatedJoypadStatesEnd plus this value minus 1
 ; 0 if the joypad state is not being simulated
@@ -1283,19 +1326,49 @@
 ; if running on SGB, it's 1, else it's 0
 	ds 1
 
-wcf1c:: ds 1 ; used with sgb palettes
-wcf1d:: ds 1 ; used when displaying palettes for Pokemon
-wcf1e:: ds 1 ; used to display palettes for HP bar
-wcf1f:: ds 6 ; used to display HP bars in Pokemon Menu (probably palettes)
-wcf25:: ds 8 ; used to display HP bar for Pokemon Status Screen (probably palettes too)
-wcf2d:: ds 1 ; also used to display HP bar for Pokemon Menu (something about HP colour)
-wcf2e:: ds 2 ; more HP bar palette stuff.
-wcf30:: ds 7 ; used with palettes (apparently for Pokedex)
-wcf37:: ds 20 ; used with palletes too (used for Party Menu)
-wcf4b:: ds 1 ; storage buffer for various strings
-wcf4c:: ds 1 ; used with displaying EXP value, probably also overflowed with wcf4b
+wDefaultPaletteCommand:: ; cf1c
+	ds 1
+
+wPlayerHPBarColor:: ; cf1d
+
+wWholeScreenPaletteMonSpecies:: ; cf1d
+; species of the mon whose palette is used for the whole screen
+	ds 1
+
+wEnemyHPBarColor:: ; cf1e
+	ds 1
+
+; 0: green
+; 1: yellow
+; 2: red
+wPartyMenuHPBarColors:: ; cf1f
+	ds 6
+
+wStatusScreenHPBarColor:: ; cf25
+	ds 1
+
+	ds 7
+
+wCopyingSGBTileData:: ; c2fd
+
+wWhichPartyMenuHPBar:: ; cf2d
+
+wPalPacket:: ; cf2d
+	ds 1
+
+wPartyMenuBlkPacket:: ; cf2e
+; $30 bytes
+	ds 29
+
+wExpAmountGained:: ; cf4b
+; 2-byte big-endian number
+; the total amount of exp a mon gained
+
+wcf4b:: ds 2 ; storage buffer for various strings
+
 wGainBoostedExp:: ; cf4d
 	ds 1
+
 	ds 17
 
 wGymCityName:: ; cf5f
@@ -1491,8 +1564,13 @@
 wTrainerPicPointer:: ; d033
 	ds 2
 	ds 1
-wd036:: ds 16 ; used as a temporary buffer to print "XXX learned YYY"
 
+wTempMoveNameBuffer:: ; d036
+
+wLearnMoveMonName:: ; d036
+; The name of the mon that is learning a move.
+	ds 16
+
 wTrainerBaseMoney:: ; d046
 ; 2-byte BCD number
 ; money received after battle = base money × level of highest-level enemy mon
@@ -1812,9 +1890,6 @@
 ; 02: move onto the next frame block with no delay and no cleaning OAM buffer
 ; 03: delay, but don't clean OAM buffer
 ; 04: delay, without cleaning OAM buffer, and do not advance [W_FBDESTADDR], so that the next frame block will overwrite this one
-; sprite data is written column by column, each byte contains 8 columns (one for ech bit)
-; for 2bpp sprites, pairs of two consecutive bytes (i.e. pairs of consecutive rows of sprite data)
-; contain the upper and lower bit of each of the 8 pixels, respectively
 	ds 1
 
 wLinkCableAnimBulgeToggle:: ; d09f
@@ -2894,6 +2969,7 @@
 	ds 1
 
 W_FLAGS_D733:: ; d733
+; bit 0: running a test battle
 ; bit 4: use variable [W_CURMAPSCRIPT] instead of the provided index for next frame's map script (used to start battle when talking to trainers)
 ; bit 7: used fly out of battle
 	ds 1