ref: 4a8c9993ad182296131ef87111e1b6d6e2af4201
parent: 99df5f0fd79f063ee4c7ec364eadd175a3d83c42
author: YamaArashi <shadow962@live.com>
date: Sun Jul 12 19:00:48 EDT 2015
named wram variables
--- a/constants/list_constants.asm
+++ b/constants/list_constants.asm
@@ -12,3 +12,9 @@
PLAYEROT_NAME EQU 5
ENEMYOT_NAME EQU 6
TRAINER_NAME EQU 7
+
+INIT_ENEMYOT_LIST EQU 1
+INIT_BAG_ITEM_LIST EQU 2
+INIT_OTHER_ITEM_LIST EQU 3
+INIT_PLAYEROT_LIST EQU 4
+INIT_MON_LIST EQU 5
\ No newline at end of file
--- a/constants/misc_constants.asm
+++ b/constants/misc_constants.asm
@@ -58,6 +58,14 @@
HEAL_CANCEL_MENU EQU 6
NO_YES_MENU EQU 7
+; menu exit method constants for list menus and the buy/sell/quit menu
+CHOSE_MENU_ITEM EQU 1 ; pressed A
+CANCELLED_MENU EQU 2 ; pressed B
+
+; menu exit method constants for two-option menus
+CHOSE_FIRST_ITEM EQU 1
+CHOSE_SECOND_ITEM EQU 2
+
; serial
ESTABLISH_CONNECTION_WITH_INTERNAL_CLOCK EQU $01
--- a/engine/battle/bank_e_misc.asm
+++ b/engine/battle/bank_e_misc.asm
@@ -53,8 +53,8 @@
; XXX this is called in a few places, but it doesn't appear to do anything useful
InitList: ; 39bd5 (e:5bd5)
- ld a, [wd11b]
- cp $1
+ ld a, [wInitListType]
+ cp INIT_ENEMYOT_LIST
jr nz, .notEnemy
ld hl, wEnemyPartyCount
ld de, wEnemyMonOT
@@ -61,7 +61,7 @@
ld a, ENEMYOT_NAME
jr .done
.notEnemy
- cp $4
+ cp INIT_PLAYEROT_LIST
jr nz, .notPlayer
ld hl, wPartyCount
ld de, wPartyMonOT
@@ -68,7 +68,7 @@
ld a, PLAYEROT_NAME
jr .done
.notPlayer
- cp $5
+ cp INIT_MON_LIST
jr nz, .notMonster
ld hl, wStringBuffer2 + 11
ld de, MonsterNames
@@ -75,7 +75,7 @@
ld a, MONSTER_NAME
jr .done
.notMonster
- cp $2
+ cp INIT_BAG_ITEM_LIST
jr nz, .notBag
ld hl, wNumBagItems
ld de, ItemNames
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -1142,8 +1142,8 @@
ld a, TWO_OPTION_MENU
ld [wTextBoxID], a
call DisplayTextBoxID
- ld a, [wd12e]
- cp $2 ; did the player choose NO?
+ ld a, [wMenuExitMethod]
+ cp CHOSE_SECOND_ITEM ; did the player choose NO?
jr z, .tryRunning ; if the player chose NO, try running
and a ; reset carry
ret
@@ -2296,7 +2296,7 @@
DisplayBagMenu:
xor a
- ld [wcf93], a
+ ld [wPrintItemPrices], a
ld a, ITEMLISTMENU
ld [wListMenuID], a
ld a, [wcc2c]
--- a/engine/cable_club.asm
+++ b/engine/cable_club.asm
@@ -357,9 +357,9 @@
dec a
ld [wCurrentMenuItem], a
.displayEnemyMonStats
- ld a, $1
- ld [wd11b], a
- callab InitList
+ ld a, INIT_ENEMYOT_LIST
+ ld [wInitListType], a
+ callab InitList ; the list isn't used
ld hl, wEnemyMons
call TradeCenter_DisplayStats
jp .getNewInput
@@ -416,9 +416,9 @@
jr z, .playerMonMenu_ANotPressed
jp .chosePlayerMon ; jump if A button pressed
; unreachable code
- ld a, $4
- ld [wd11b], a
- callab InitList
+ ld a, INIT_PLAYEROT_LIST
+ ld [wInitListType], a
+ callab InitList ; the list isn't used
call TradeCenter_DisplayStats
jp .getNewInput
.playerMonMenu_ANotPressed
@@ -511,9 +511,9 @@
.displayPlayerMonStats
pop af
ld [wCurrentMenuItem], a
- ld a, $4
- ld [wd11b], a
- callab InitList
+ ld a, INIT_PLAYEROT_LIST
+ ld [wInitListType], a
+ callab InitList ; the list isn't used
call TradeCenter_DisplayStats
call LoadScreenTilesFromBuffer1
jp .playerMonMenu
--- a/engine/items/items.asm
+++ b/engine/items/items.asm
@@ -450,7 +450,7 @@
ret nz
ld hl,wNumBagItems
inc a
- ld [wcf96],a
+ ld [wItemQuantity],a
jp RemoveItemFromInventory
ItemUseBallText00: ; d937 (3:5937)
;"It dodged the thrown ball!"
@@ -655,7 +655,7 @@
ld [wWhichPokemon],a
ld hl,wNumBagItems
ld a,1 ; remove 1 stone
- ld [wcf96],a
+ ld [wItemQuantity],a
jp RemoveItemFromInventory
.noEffect
call ItemUseNoEffect
@@ -2193,7 +2193,7 @@
RemoveUsedItem: ; e571 (3:6571)
ld hl,wNumBagItems
ld a,1 ; one item
- ld [wcf96],a ; store quantity
+ ld [wItemQuantity],a
jp RemoveItemFromInventory
ItemUseNoEffect: ; e57c (3:657c)
@@ -2464,7 +2464,7 @@
; hl = address of inventory (either wNumBagItems or wNumBoxItems)
; [wcf91] = item ID
; [wWhichPokemon] = index of item within inventory
-; [wcf96] = quantity to toss
+; [wItemQuantity] = quantity to toss
; OUTPUT:
; clears carry flag if the item is tossed, sets carry flag if not
TossItem_: ; e6f1 (3:66f1)
@@ -2475,7 +2475,7 @@
jr c,.tooImportantToToss
push hl
call IsKeyItem_
- ld a,[wd124]
+ ld a,[wIsKeyItem]
pop hl
and a
jr nz,.tooImportantToToss
@@ -2491,11 +2491,11 @@
ld a,TWO_OPTION_MENU
ld [wTextBoxID],a
call DisplayTextBoxID ; yes/no menu
- ld a,[wd12e]
- cp a,2
+ ld a,[wMenuExitMethod]
+ cp a,CHOSE_SECOND_ITEM
pop hl
scf
- ret z
+ ret z ; return if the player chose No
; if the player chose Yes
push hl
ld a,[wWhichPokemon]
@@ -2533,12 +2533,12 @@
; INPUT:
; [wcf91] = item ID
; OUTPUT:
-; [wd124] = result
+; [wIsKeyItem] = result
; 00: item is not key item
; 01: item is key item
IsKeyItem_: ; e764 (3:6764)
ld a,$01
- ld [wd124],a
+ ld [wIsKeyItem],a
ld a,[wcf91]
cp a,HM_01 ; is the item an HM or TM?
jr nc,.checkIfItemIsHM
@@ -2562,7 +2562,7 @@
call IsItemHM
ret c
xor a
- ld [wd124],a
+ ld [wIsKeyItem],a
ret
INCLUDE "data/key_items.asm"
--- a/engine/menu/bills_pc.asm
+++ b/engine/menu/bills_pc.asm
@@ -231,7 +231,7 @@
call PlaySoundWaitForCurrent
ld a, $1
ld [wcf95], a
- call Func_3a68
+ call MoveMon
xor a
ld [wcf95], a
call RemovePokemon
@@ -283,7 +283,7 @@
call PlaySoundWaitForCurrent
xor a
ld [wcf95], a
- call Func_3a68
+ call MoveMon
ld a, $1
ld [wcf95], a
call RemovePokemon
@@ -329,7 +329,7 @@
ld a, h
ld [wList + 1], a
xor a
- ld [wcf93], a
+ ld [wPrintItemPrices], a
ld [wListMenuID], a
inc a ; MONSTER_NAME
ld [wNameListType], a
--- a/engine/menu/pc.asm
+++ b/engine/menu/pc.asm
@@ -135,7 +135,7 @@
jr .asm_17f40
.asm_17f4f
ld a, $1
- ld [wcf96], a
+ ld [wItemQuantity], a
ld a, [$ffdc]
ld [wWhichPokemon], a
ld hl, wNumBagItems
--- a/engine/menu/players_pc.asm
+++ b/engine/menu/players_pc.asm
@@ -101,7 +101,7 @@
ld a, h
ld [wList + 1], a
xor a
- ld [wcf93], a
+ ld [wPrintItemPrices], a
ld a, $3
ld [wListMenuID], a
call DisplayListMenuID
@@ -108,8 +108,8 @@
jp c, Func_790c
call IsKeyItem
ld a, $1
- ld [wcf96], a
- ld a, [wd124]
+ ld [wItemQuantity], a
+ ld a, [wIsKeyItem]
and a
jr nz, .asm_79e7
ld hl, DepositHowManyText
@@ -155,7 +155,7 @@
ld a, h
ld [wList + 1], a
xor a
- ld [wcf93], a
+ ld [wPrintItemPrices], a
ld a, $3
ld [wListMenuID], a
call DisplayListMenuID
@@ -162,8 +162,8 @@
jp c, Func_790c
call IsKeyItem
ld a, $1
- ld [wcf96], a
- ld a, [wd124]
+ ld [wItemQuantity], a
+ ld a, [wIsKeyItem]
and a
jr nz, .asm_7a64
ld hl, WithdrawHowManyText
@@ -209,7 +209,7 @@
ld a, h
ld [wList + 1], a
xor a
- ld [wcf93], a
+ ld [wPrintItemPrices], a
ld a, $3
ld [wListMenuID], a
push hl
@@ -220,8 +220,8 @@
call IsKeyItem
pop hl
ld a, $1
- ld [wcf96], a
- ld a, [wd124]
+ ld [wItemQuantity], a
+ ld a, [wIsKeyItem]
and a
jr nz, .asm_7aef
ld a, [wcf91]
--- a/engine/menu/start_sub_menus.asm
+++ b/engine/menu/start_sub_menus.asm
@@ -313,7 +313,7 @@
ld [hli],a
ld [hl],b ; store item bag pointer at wList (for DisplayListMenuID)
xor a
- ld [wcf93],a
+ ld [wPrintItemPrices],a
ld a,ITEMLISTMENU
ld [wListMenuID],a
ld a,[wcc2c]
@@ -423,7 +423,7 @@
jp ItemMenuLoop
.tossItem
call IsKeyItem
- ld a,[wd124]
+ ld a,[wIsKeyItem]
and a
jr nz,.skipAskingQuantity
ld a,[wcf91]
--- a/engine/oak_speech.asm
+++ b/engine/oak_speech.asm
@@ -46,7 +46,7 @@
ld a,POTION
ld [wcf91],a
ld a,1
- ld [wcf96],a
+ ld [wItemQuantity],a
call AddItemToInventory ; give one potion
ld a,[W_ANIMATIONID]
ld [wDestinationMap],a
--- a/engine/overworld/pokemart.asm
+++ b/engine/overworld/pokemart.asm
@@ -1,9 +1,9 @@
DisplayPokemartDialogue_: ; 6c20 (1:6c20)
ld a,[wListScrollOffset]
- ld [wd07e],a
+ ld [wSavedListScrollOffset],a
call UpdateSprites
xor a
- ld [wcf0a],a ; flag that is set if something is sold or bought
+ ld [wBoughtOrSoldItemInMart],a
.loop
xor a
ld [wListScrollOffset],a
@@ -10,21 +10,25 @@
ld [wCurrentMenuItem],a
ld [wPlayerMonNumber],a
inc a
- ld [wcf93],a
+ ld [wPrintItemPrices],a
ld a,MONEY_BOX
ld [wTextBoxID],a
- call DisplayTextBoxID ; draw money text box
+ call DisplayTextBoxID
ld a,BUY_SELL_QUIT_MENU
ld [wTextBoxID],a
- call DisplayTextBoxID ; do buy/sell/quit menu
- ld hl,wd128 ; pointer to this pokemart's inventory
+ call DisplayTextBoxID
+
+; This code is useless. It copies the address of the pokemart's inventory to hl,
+; but the address is never used.
+ ld hl,wItemListPointer
ld a,[hli]
ld l,[hl]
- ld h,a ; hl = address of inventory
- ld a,[wd12e]
- cp a,$02
+ ld h,a
+
+ ld a,[wMenuExitMethod]
+ cp a,CANCELLED_MENU
jp z,.done
- ld a,[wd12d] ; ID of the chosen menu item
+ ld a,[wChosenMenuItem]
and a ; buying?
jp z,.buyMenu
dec a ; selling?
@@ -32,11 +36,14 @@
dec a ; quitting?
jp z,.done
.sellMenu
+
+; the same variables are set again below, so this code has no effect
xor a
- ld [wcf93],a
- ld a,$02
- ld [wd11b],a
+ ld [wPrintItemPrices],a
+ ld a,INIT_BAG_ITEM_LIST
+ ld [wInitListType],a
callab InitList
+
ld a,[wNumBagItems]
and a
jp z,.bagEmpty
@@ -54,7 +61,7 @@
ld a,h
ld [wList + 1],a
xor a
- ld [wcf93],a
+ ld [wPrintItemPrices],a
ld [wCurrentMenuItem],a
ld a,ITEMLISTMENU
ld [wListMenuID],a
@@ -61,8 +68,8 @@
call DisplayListMenuID
jp c,.returnToMainPokemartMenu ; if the player closed the menu
.confirmItemSale ; if the player is trying to sell a specific item
- call IsKeyItem ; check if item is unsellable
- ld a,[wd124]
+ call IsKeyItem
+ ld a,[wIsKeyItem]
and a
jr nz,.unsellableItem
ld a,[wcf91]
@@ -70,7 +77,7 @@
jr c,.unsellableItem
ld a,PRICEDITEMLISTMENU
ld [wListMenuID],a
- ld [$ff8e],a ; halve prices when selling
+ ld [hHalveItemPrices],a ; halve prices when selling
call DisplayChooseQuantityMenu
inc a
jr z,.sellMenuLoop ; if the player closed the choose quantity menu with the B button
@@ -82,18 +89,22 @@
ld a,TWO_OPTION_MENU
ld [wTextBoxID],a
call DisplayTextBoxID ; yes/no menu
- ld a,[wd12e]
- cp a,$02
- jr z,.sellMenuLoop ; if the player pressed the B button
- ld a,[wd12d] ; ID of the chosen menu item
+ ld a,[wMenuExitMethod]
+ cp a,CHOSE_SECOND_ITEM
+ jr z,.sellMenuLoop ; if the player chose No or pressed the B button
+
+; The following code is supposed to check if the player chose No, but the above
+; check already catches it.
+ ld a,[wChosenMenuItem]
dec a
- jr z,.sellMenuLoop ; if the player chose No
+ jr z,.sellMenuLoop
+
.sellItem
- ld a,[wcf0a] ; flag that is set if something is sold or bought
+ ld a,[wBoughtOrSoldItemInMart]
and a
jr nz,.skipSettingFlag1
inc a
- ld [wcf0a],a
+ ld [wBoughtOrSoldItemInMart],a
.skipSettingFlag1
call AddAmountSoldToMoney
ld hl,wNumBagItems
@@ -106,22 +117,25 @@
.bagEmpty
ld hl,PokemartItemBagEmptyText
call PrintText
- call SaveScreenTilesToBuffer1 ; save screen
+ call SaveScreenTilesToBuffer1
jp .returnToMainPokemartMenu
.buyMenu
- ld a,$01
- ld [wcf93],a
- ld a,$03
- ld [wd11b],a
+
+; the same variables are set again below, so this code has no effect
+ ld a,1
+ ld [wPrintItemPrices],a
+ ld a,INIT_OTHER_ITEM_LIST
+ ld [wInitListType],a
callab InitList
+
ld hl,PokemartBuyingGreetingText
call PrintText
- call SaveScreenTilesToBuffer1 ; save screen
+ call SaveScreenTilesToBuffer1
.buyMenuLoop
- call LoadScreenTilesFromBuffer1 ; restore saved screen
+ call LoadScreenTilesFromBuffer1
ld a,MONEY_BOX
ld [wTextBoxID],a
- call DisplayTextBoxID ; draw money text box
+ call DisplayTextBoxID
ld hl,wStringBuffer2 + 11
ld a,l
ld [wList],a
@@ -130,15 +144,15 @@
xor a
ld [wCurrentMenuItem],a
inc a
- ld [wcf93],a
+ ld [wPrintItemPrices],a
inc a ; a = 2 (PRICEDITEMLISTMENU)
ld [wListMenuID],a
call DisplayListMenuID
jr c,.returnToMainPokemartMenu ; if the player closed the menu
- ld a,$63
- ld [wcf97],a
+ ld a,99
+ ld [wMaxItemQuantity],a
xor a
- ld [$ff8e],a
+ ld [hHalveItemPrices],a ; don't halve item prices when buying
call DisplayChooseQuantityMenu
inc a
jr z,.buyMenuLoop ; if the player closed the choose quantity menu with the B button
@@ -153,12 +167,16 @@
ld a,TWO_OPTION_MENU
ld [wTextBoxID],a
call DisplayTextBoxID ; yes/no menu
- ld a,[wd12e]
- cp a,$02
- jp z,.buyMenuLoop ; if the player pressed the B button
- ld a,[wd12d] ; ID of the chosen menu item
+ ld a,[wMenuExitMethod]
+ cp a,CHOSE_SECOND_ITEM
+ jp z,.buyMenuLoop ; if the player chose No or pressed the B button
+
+; The following code is supposed to check if the player chose No, but the above
+; check already catches it.
+ ld a,[wChosenMenuItem]
dec a
- jr z,.buyMenuLoop ; if the player chose No
+ jr z,.buyMenuLoop
+
.buyItem
call .isThereEnoughMoney
jr c,.notEnoughMoney
@@ -166,11 +184,11 @@
call AddItemToInventory
jr nc,.bagFull
call SubtractAmountPaidFromMoney
- ld a,[wcf0a] ; flag that is set if something is sold or bought
+ ld a,[wBoughtOrSoldItemInMart]
and a
jr nz,.skipSettingFlag2
- ld a,$01
- ld [wcf0a],a
+ ld a,1
+ ld [wBoughtOrSoldItemInMart],a
.skipSettingFlag2
ld a,(SFX_02_5a - SFX_Headers_02) / 3
call PlaySoundWaitForCurrent
@@ -182,7 +200,7 @@
call LoadScreenTilesFromBuffer1
ld a,MONEY_BOX
ld [wTextBoxID],a
- call DisplayTextBoxID ; draw money text box
+ call DisplayTextBoxID
ld hl,PokemartAnythingElseText
call PrintText
jp .loop
@@ -202,10 +220,10 @@
.done
ld hl,PokemartThankYouText
call PrintText
- ld a,$01
+ ld a,1
ld [wUpdateSpritesEnabled],a
call UpdateSprites
- ld a,[wd07e]
+ ld a,[wSavedListScrollOffset]
ld [wListScrollOffset],a
ret
--- a/engine/predefs7.asm
+++ b/engine/predefs7.asm
@@ -11,7 +11,7 @@
xor a
ld [wCurrentMenuItem], a
ld [wListScrollOffset], a
- ld [wcf93], a
+ ld [wPrintItemPrices], a
ld a, $4
ld [wListMenuID], a
call DisplayListMenuID
--- a/home.asm
+++ b/home.asm
@@ -1201,8 +1201,8 @@
pop hl
inc hl
call LoadItemList
- ld a,$02
- ld [wListMenuID],a ; selects between subtypes of menus
+ ld a,PRICEDITEMLISTMENU
+ ld [wListMenuID],a
ld a,[H_LOADEDROMBANK]
push af
ld a,Bank(DisplayPokemartDialogue_)
@@ -1219,12 +1219,12 @@
db "@"
LoadItemList:: ; 2a5a (0:2a5a)
- ld a,$01
+ ld a,1
ld [wUpdateSpritesEnabled],a
ld a,h
- ld [wd128],a
+ ld [wItemListPointer],a
ld a,l
- ld [wd129],a
+ ld [wItemListPointer + 1],a
ld de,wStringBuffer2 + 11
.loop
ld a,[hli]
@@ -1336,7 +1336,7 @@
; INPUT:
; HL = address of inventory (either wNumBagItems or wNumBoxItems)
; [wWhichPokemon] = index (within the inventory) of the item to remove
-; [wcf96] = quantity to remove
+; [wItemQuantity] = quantity to remove
RemoveItemFromInventory:: ; 2bbb (0:2bbb)
ld a,[H_LOADEDROMBANK]
push af
@@ -1353,7 +1353,7 @@
; INPUT:
; HL = address of inventory (either wNumBagItems or wNumBoxItems)
; [wcf91] = item ID
-; [wcf96] = item quantity
+; [wItemQuantity] = item quantity
; sets carry flag if successful, unsets carry flag if unsuccessful
AddItemToInventory:: ; 2bcf (0:2bcf)
push bc
@@ -1461,9 +1461,12 @@
.buttonAPressed
ld a,[wCurrentMenuItem]
call PlaceUnfilledArrowMenuCursor
+
+; pointless because both values are overwritten before they are read
ld a,$01
- ld [wd12e],a
- ld [wd12d],a
+ ld [wMenuExitMethod],a
+ ld [wChosenMenuItem],a
+
xor a
ld [wcc37],a
ld a,[wCurrentMenuItem]
@@ -1506,7 +1509,7 @@
; if it's an item menu
inc hl
ld a,[hl] ; a = item quantity
- ld [wcf97],a
+ ld [wMaxItemQuantity],a
.skipGettingQuantity
ld a,[wcf91]
ld [wd0b5],a
@@ -1527,10 +1530,10 @@
.storeChosenEntry ; store the menu entry that the player chose and return
ld de,wcd6d
call CopyStringToCF4B ; copy name to wcf4b
- ld a,$01
- ld [wd12e],a
+ ld a,CHOSE_MENU_ITEM
+ ld [wMenuExitMethod],a
ld a,[wCurrentMenuItem]
- ld [wd12d],a
+ ld [wChosenMenuItem],a
xor a
ld [hJoy7],a ; joypad state update flag
ld hl,wd730
@@ -1584,7 +1587,7 @@
ld de,InitialQuantityText
call PlaceString
xor a
- ld [wcf96],a ; initialize current quantity to 0
+ ld [wItemQuantity],a ; initialize current quantity to 0
jp .incrementQuantity
.waitForKeyPressLoop
call JoypadLowSensitivity
@@ -1599,10 +1602,10 @@
jr nz,.decrementQuantity
jr .waitForKeyPressLoop
.incrementQuantity
- ld a,[wcf97] ; max quantity
+ ld a,[wMaxItemQuantity]
inc a
ld b,a
- ld hl,wcf96 ; current quantity
+ ld hl,wItemQuantity ; current quantity
inc [hl]
ld a,[hl]
cp b
@@ -1612,11 +1615,11 @@
ld [hl],a
jr .handleNewQuantity
.decrementQuantity
- ld hl,wcf96 ; current quantity
+ ld hl,wItemQuantity ; current quantity
dec [hl]
jr nz,.handleNewQuantity
; wrap to the max quantity if the player goes below 1
- ld a,[wcf97] ; max quantity
+ ld a,[wMaxItemQuantity]
ld [hl],a
.handleNewQuantity
hlCoord 17, 10
@@ -1625,7 +1628,7 @@
jr nz,.printQuantity
.printPrice
ld c,$03
- ld a,[wcf96]
+ ld a,[wItemQuantity]
ld b,a
ld hl,$ff9f ; total price
; initialize total price to 0
@@ -1641,7 +1644,7 @@
pop bc
dec b
jr nz,.addLoop
- ld a,[$ff8e]
+ ld a,[hHalveItemPrices]
and a ; should the price be halved (for selling items)?
jr z,.skipHalvingPrice
xor a
@@ -1666,7 +1669,7 @@
call PrintBCDNumber
hlCoord 9, 10
.printQuantity
- ld de,wcf96 ; current quantity
+ ld de,wItemQuantity ; current quantity
ld bc,$8102 ; print leading zeroes, 1 byte, 2 digits
call PrintNumber
jp .waitForKeyPressLoop
@@ -1688,9 +1691,9 @@
ExitListMenu:: ; 2e3b (0:2e3b)
ld a,[wCurrentMenuItem]
- ld [wd12d],a
- ld a,$02
- ld [wd12e],a
+ ld [wChosenMenuItem],a
+ ld a,CANCELLED_MENU
+ ld [wMenuExitMethod],a
ld [wcc37],a
xor a
ld [hJoy7],a
@@ -1775,7 +1778,7 @@
call PlaceString
pop de
pop hl
- ld a,[wcf93]
+ ld a,[wPrintItemPrices]
and a ; should prices be printed?
jr z,.skipPrintingItemPrice
.printItemPrice
@@ -1839,7 +1842,7 @@
ld a,[wd11e]
ld [wcf91],a
call IsKeyItem ; check if item is unsellable
- ld a,[wd124]
+ ld a,[wIsKeyItem]
and a ; is the item unsellable?
jr nz,.skipPrintingItemQuantity ; if so, don't print the quantity
push hl
@@ -1850,7 +1853,7 @@
ld a,[wd11e]
push af
ld a,[de]
- ld [wcf97],a
+ ld [wMaxItemQuantity],a
push de
ld de,wd11e
ld [de],a
@@ -2101,7 +2104,7 @@
; hl = address of inventory (either wNumBagItems or wNumBoxItems)
; [wcf91] = item ID
; [wWhichPokemon] = index of item within inventory
-; [wcf96] = quantity to toss
+; [wItemQuantity] = quantity to toss
; OUTPUT:
; clears carry flag if the item is tossed, sets carry flag if not
TossItem:: ; 30c4 (0:30c4)
@@ -2121,7 +2124,7 @@
; INPUT:
; [wcf91] = item ID
; OUTPUT:
-; [wd124] = result
+; [wIsKeyItem] = result
; 00: item is not key item
; 01: item is key item
IsKeyItem:: ; 30d9 (0:30d9)
@@ -3826,13 +3829,13 @@
ld [MBC1RomBank], a
ret
-Func_3a68:: ; 3a68 (0:3a68)
+MoveMon:: ; 3a68 (0:3a68)
ld a, [H_LOADEDROMBANK]
push af
- ld a, BANK(MoveMon)
+ ld a, BANK(_MoveMon)
ld [H_LOADEDROMBANK], a
ld [MBC1RomBank], a
- call MoveMon
+ call _MoveMon
pop bc
ld a, b
ld [H_LOADEDROMBANK], a
@@ -4568,7 +4571,7 @@
ld [wd11e], a
ld [wcf91], a
ld a, c
- ld [wcf96], a
+ ld [wItemQuantity], a
ld hl,wNumBagItems
call AddItemToInventory
ret nc
--- a/home/overworld.asm
+++ b/home/overworld.asm
@@ -301,7 +301,7 @@
and a
jp nz,CheckWarpsNoCollision
predef ApplyOutOfBattlePoisonDamage ; also increment daycare mon exp
- ld a,[wd12d]
+ ld a,[wOutOfBattleBlackout]
and a
jp nz,HandleBlackOut ; if all pokemon fainted
.newBattle
--- a/hram.asm
+++ b/hram.asm
@@ -26,6 +26,8 @@
hPartyMonIndex EQU $FF8C
+hHalveItemPrices EQU $FF8E
+
; Multiplcation and division variables are meant
; to overlap for back-to-back usage. Big endian.
--- a/main.asm
+++ b/main.asm
@@ -1457,7 +1457,7 @@
set 6, a ; no printing delay
ld [wd730], a
xor a
- ld [wd12d], a
+ ld [wChosenMenuItem], a
ld a, BUY_SELL_QUIT_MENU_TEMPLATE
ld [wTextBoxID], a
call DisplayTextBoxID
@@ -1482,14 +1482,14 @@
jr nz, .pressedA
bit 1, a ; was B pressed? (always true since only A/B are watched)
jr z, .pressedA
- ld a, $2
- ld [wd12e], a
+ ld a, CANCELLED_MENU
+ ld [wMenuExitMethod], a
jr .quit
.pressedA
- ld a, $1
- ld [wd12e], a
+ ld a, CHOSE_MENU_ITEM
+ ld [wMenuExitMethod], a
ld a, [wCurrentMenuItem]
- ld [wd12d], a
+ ld [wChosenMenuItem], a
ld b, a
ld a, [wMaxMenuItem]
cp b
@@ -1496,10 +1496,10 @@
jr z, .quit
ret
.quit
- ld a, $2
- ld [wd12e], a
+ ld a, CANCELLED_MENU
+ ld [wMenuExitMethod], a
ld a, [wCurrentMenuItem]
- ld [wd12d], a
+ ld [wChosenMenuItem], a
scf
ret
@@ -1512,9 +1512,12 @@
ld a, [wd730]
set 6, a ; no printing delay
ld [wd730], a
+
+; pointless because both values are overwritten before they are read
xor a
- ld [wd12d], a
- ld [wd12e], a
+ ld [wChosenMenuItem], a
+ ld [wMenuExitMethod], a
+
ld a, A_BUTTON | B_BUTTON
ld [wMenuWatchedKeys], a
ld a, $1
@@ -1614,12 +1617,12 @@
jr nz, .choseSecondMenuItem ; automatically choose the second option if B is pressed
.pressedAButton
ld a, [wCurrentMenuItem]
- ld [wd12d], a
+ ld [wChosenMenuItem], a
and a
jr nz, .choseSecondMenuItem
; chose first menu item
- ld a, $1
- ld [wd12e], a
+ ld a, CHOSE_FIRST_ITEM
+ ld [wMenuExitMethod], a
ld c, 15
call DelayFrames
call TwoOptionMenu_RestoreScreenTiles
@@ -1626,11 +1629,11 @@
and a
ret
.choseSecondMenuItem
- ld a, $1
+ ld a, 1
ld [wCurrentMenuItem], a
- ld [wd12d], a
- ld a, $2
- ld [wd12e], a
+ ld [wChosenMenuItem], a
+ ld a, CHOSE_SECOND_ITEM
+ ld [wMenuExitMethod], a
ld c, 15
call DelayFrames
call TwoOptionMenu_RestoreScreenTiles
@@ -2631,7 +2634,7 @@
.noBlackOut
xor a
.done
- ld [wd12d], a
+ ld [wOutOfBattleBlackout], a
ret
LoadTilesetHeader: ; c754 (3:4754)
@@ -2777,10 +2780,10 @@
; INPUT:
; hl = address of inventory (either wNumBagItems or wNumBoxItems)
; [wcf91] = item ID
-; [wcf96] = item quantity
+; [wItemQuantity] = item quantity
; sets carry flag if successful, unsets carry flag if unsuccessful
AddItemToInventory_: ; ce04 (3:4e04)
- ld a,[wcf96] ; a = item quantity
+ ld a,[wItemQuantity] ; a = item quantity
push af
push bc
push de
@@ -2827,12 +2830,12 @@
add hl,bc ; hl = address to store the item
ld a,[wcf91]
ld [hli],a ; store item ID
- ld a,[wcf96]
+ ld a,[wItemQuantity]
ld [hli],a ; store item quantity
ld [hl],$ff ; store terminator
jp .success
.increaseItemQuantity ; increase the quantity of an item already in the inventory
- ld a,[wcf96]
+ ld a,[wItemQuantity]
ld b,a ; b = quantity to add
ld a,[hl] ; a = existing item quantity
add b ; a = new item quantity
@@ -2841,7 +2844,7 @@
; if the new quantity is greater than or equal to 100,
; try to max out the current slot and add the rest in a new slot
sub a,99
- ld [wcf96],a ; a = amount left over (to put in the new slot)
+ ld [wItemQuantity],a ; a = amount left over (to put in the new slot)
ld a,d
and a ; is there room for a new item slot?
jr z,.increaseItemQuantityFailed
@@ -2864,7 +2867,7 @@
pop bc
pop bc
ld a,b
- ld [wcf96],a ; restore the initial value from when the function was called
+ ld [wItemQuantity],a ; restore the initial value from when the function was called
ret
; function to remove an item (in varying quantities) from the player's bag or PC box
@@ -2871,7 +2874,7 @@
; INPUT:
; hl = address of inventory (either wNumBagItems or wNumBoxItems)
; [wWhichPokemon] = index (within the inventory) of the item to remove
-; [wcf96] = quantity to remove
+; [wItemQuantity] = quantity to remove
RemoveItemFromInventory_: ; ce74 (3:4e74)
push hl
inc hl
@@ -2883,12 +2886,12 @@
inc h
.noCarry
inc hl
- ld a,[wcf96] ; quantity being removed
+ ld a,[wItemQuantity] ; quantity being removed
ld e,a
ld a,[hl] ; a = current quantity
sub e
ld [hld],a ; store new quantity
- ld [wcf97],a
+ ld [wMaxItemQuantity],a
and a
jr nz,.skipMovingUpSlots
; if the remaining quantity is 0,
@@ -2909,7 +2912,7 @@
ld [wListScrollOffset],a
ld [wCurrentMenuItem],a
ld [wcc2c],a
- ld [wd07e],a
+ ld [wSavedListScrollOffset],a
pop hl
ld a,[hl] ; a = number of items in inventory
dec a ; decrement the number of items
@@ -3863,7 +3866,7 @@
and a
ret ; return success
-MoveMon: ; f51e (3:751e)
+_MoveMon: ; f51e (3:751e)
ld a, [wcf95]
and a
jr z, .checkPartyMonSlots
--- a/scripts/ceruleanhouse2.asm
+++ b/scripts/ceruleanhouse2.asm
@@ -26,7 +26,7 @@
ld a, h
ld [wList + 1], a
xor a
- ld [wcf93], a
+ ld [wPrintItemPrices], a
ld [wMenuItemToSwap], a
ld a, SPECIALLISTMENU
ld [wListMenuID], a
--- a/scripts/daycarem.asm
+++ b/scripts/daycarem.asm
@@ -49,7 +49,7 @@
ld [W_DAYCARE_IN_USE], a
ld a, $3
ld [wcf95], a
- call Func_3a68
+ call MoveMon
xor a
ld [wcf95], a
call RemovePokemon
@@ -158,7 +158,7 @@
predef SubBCDPredef
ld a, (SFX_02_5a - SFX_Headers_02) / 3
call PlaySoundWaitForCurrent
- ld a, $13
+ ld a, MONEY_BOX
ld [wTextBoxID], a
call DisplayTextBoxID
ld hl, DayCareMText_5644f
@@ -165,7 +165,7 @@
call PrintText
ld a, $2
ld [wcf95], a
- call Func_3a68
+ call MoveMon
ld a, [wDayCareMonSpecies]
ld [wcf91], a
ld a, [wPartyCount]
--- a/scripts/oakslab.asm
+++ b/scripts/oakslab.asm
@@ -641,7 +641,7 @@
ld a, c
ld [wWhichPokemon], a
ld a, $1
- ld [wcf96], a
+ ld [wItemQuantity], a
jp RemoveItemFromInventory
OaksLabScript_1d02b: ; 1d02b (7:502b)
--- a/wram.asm
+++ b/wram.asm
@@ -746,7 +746,13 @@
wcf08:: ds 1 ; used as a storage value for the bank to return to after a BankswitchHome (bankswitch in homebank)
wcf09:: ds 1 ; used as a temp storage value for the bank to switch to
-wcf0a:: ds 1 ; used as flags for Poke Mart
+
+wBoughtOrSoldItemInMart:: ; cf0a
+; 0 = nothing bought or sold in pokemart
+; 1 = bought or sold something in pokemart
+; this value is not used for anything
+ ds 1
+
wBattleResult:: ; cf0b
; $00 - win
; $01 - lose
@@ -831,7 +837,9 @@
; which pokemon you selected
ds 1
-wcf93:: ds 1 ; used with lists
+wPrintItemPrices:: ; cf93
+; if non-zero, then print item prices when displaying lists
+ ds 1
wHPBarType:: ; cf94
; type of HP bar
@@ -844,9 +852,13 @@
ds 1
wcf95:: ds 1 ; used with RemovePokemon (BoxMons, Daycare, Trades, etc.)
-wcf96:: ds 1 ; used with removing items
-wcf97:: ds 1 ; used with printing item quantities?
+wItemQuantity:: ; cf96
+ ds 1
+
+wMaxItemQuantity:: ; cf97
+ ds 1
+
; LoadMonData copies mon data here
wLoadedMon:: party_struct wLoadedMon ; cf98
@@ -1126,8 +1138,14 @@
ds 1
wd07d:: ds 1 ; used with naming functions and party display type
-wd07e:: ds 3 ; used with mart and inventory
+wSavedListScrollOffset:: ; d07e
+; used by the pokemart code to save the existing value of wListScrollOffset
+; so that it can be restored when the player is done with the pokemart NPC
+ ds 1
+
+ ds 2
+
; base coordinates of frame block
W_BASECOORDX:: ; d081
ds 1
@@ -1353,7 +1371,10 @@
; wWalkBikeSurfState is sometimes copied here, but it doesn't seem to be used for anything
ds 1
-wd11b:: ds 1 ; used with mart text box and cable club
+wInitListType:: ; d11b
+; the type of list for InitList to init
+ ds 1
+
wd11c:: ds 1 ; temp storage value for catching pokemon
wd11d:: ds 1 ; used with battle switchout and testing if the enemy mon fainted
wd11e:: ds 1 ; used as a Pokemon and Item storage value. Also used as an output value for CountSetBits
@@ -1365,7 +1386,7 @@
wd121:: ds 1 ; used with evolving pokemon
wd122:: ds 2 ; saved ROM bank number for vblank
-wd124:: ds 1 ; used as an output value when determining if an item is a key item
+wIsKeyItem:: ds 1 ; d124
wTextBoxID:: ; d125
ds 1
@@ -1375,16 +1396,35 @@
W_CURENEMYLVL:: ; d127
ds 1
-wd128:: ds 1 ; used as a pointer to displaying Poke Mart inventory, also used to store the pointer of LoadItemList (pointer to item list initially in hl)
-wd129:: ds 1 ; second half of above mentioned pointer
+wItemListPointer:: ; d128
+; pointer to list of items terminated by $FF
+ ds 2
+
wd12a:: ds 1 ; Number of list entries for displaying a list
wLinkState:: ; d12b
ds 1
-wTwoOptionMenuID:: ds 1
-wd12d:: ds 1 ; used with item menus and pokemart menu, also used with testing if all Pokemon Fainted?
-wd12e:: ds 1 ; used as an output value to determine if A or B was pressed in a yes/no box
+wTwoOptionMenuID:: ; d12c
+ ds 1
+
+wChosenMenuItem:: ; d12d
+; the id of the menu item the player ultimately chose
+
+wOutOfBattleBlackout:: ; d12d
+; non-zero when the whole party has fainted due to out-of-battle poison damage
+ ds 1
+
+wMenuExitMethod:: ; d12e
+; the way the user exited a menu
+; for list menus and the buy/sell/quit menu:
+; $01 = the user pressed A to choose a menu item
+; $02 = the user pressed B to cancel
+; for two-option menus:
+; $01 = the user pressed A with the first menu item selected
+; $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