ref: bd7d9815936decc5b636f4235c0ee745812dcb48
parent: ac78dda7d8a4a6cf9af95f601bdac9fc348c65a6
author: YamaArashi <shadow962@live.com>
date: Wed Jul 15 16:04:58 EDT 2015
menu stuff
--- a/constants/misc_constants.asm
+++ b/constants/misc_constants.asm
@@ -109,6 +109,14 @@
NAME_RIVAL_SCREEN EQU 1
NAME_MON_SCREEN EQU 2
+; mon data locations
+; Note that some values are not supported by all functions that use these values.
+PLAYER_PARTY_DATA EQU 0
+ENEMY_PARTY_DATA EQU 1
+BOX_DATA EQU 2
+DAYCARE_DATA EQU 3
+BATTLE_MON_DATA EQU 4
+
; serial
ESTABLISH_CONNECTION_WITH_INTERNAL_CLOCK EQU $01
--- a/engine/battle/bank_e_misc.asm
+++ b/engine/battle/bank_e_misc.asm
@@ -102,10 +102,10 @@
ld [wItemPrices + 1], a
ret
-; get species of mon e in list [wcc49] for LoadMonData
+; get species of mon e in list [wMonDataLocation] for LoadMonData
GetMonSpecies: ; 39c37 (e:5c37)
ld hl, wPartySpecies
- ld a, [wcc49]
+ ld a, [wMonDataLocation]
and a
jr z, .getSpecies
dec a
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -1809,7 +1809,7 @@
predef LoadMonBackPic
xor a
ld [$ffe1], a
- ld hl, wcc2d
+ ld hl, wBattleAndStartSavedMenuItem
ld [hli], a
ld [hl], a
ld [wBoostExpByExpAll], a
@@ -2123,7 +2123,7 @@
.oldManName
db "OLD MAN@"
.handleBattleMenuInput
- ld a, [wcc2d]
+ ld a, [wBattleAndStartSavedMenuItem]
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
sub 2 ; check if the cursor is in the left column
@@ -2206,7 +2206,7 @@
ld a, [W_BATTLETYPE]
cp $2 ; is it a Safari battle?
ld a, [wCurrentMenuItem]
- ld [wcc2d], a
+ ld [wBattleAndStartSavedMenuItem], a
jr z, .handleMenuSelection
; not Safari battle
; swap the IDs of the item menu and party menu (this is probably because they swapped the positions
@@ -2299,11 +2299,11 @@
ld [wPrintItemPrices], a
ld a, ITEMLISTMENU
ld [wListMenuID], a
- ld a, [wcc2c]
+ ld a, [wBagSavedMenuItem]
ld [wCurrentMenuItem], a
call DisplayListMenuID
ld a, [wCurrentMenuItem]
- ld [wcc2c], a
+ ld [wBagSavedMenuItem], a
ld a, $0
ld [wMenuWatchMovingOutOfBounds], a
ld [wMenuItemToSwap], a
@@ -2435,8 +2435,8 @@
and a ; was Switch selected?
jr z, .switchMon ; if so, jump
; Stats was selected
- xor a
- ld [wcc49], a
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation], a
ld hl, wPartyMon1
call ClearSprites
; display the two status screens
@@ -2935,8 +2935,8 @@
; isn't actually selected (just pointed to by the cursor)
ld a, [wPlayerMonNumber]
ld [wWhichPokemon], a
- ld a, $4
- ld [wcc49], a
+ ld a, BATTLE_MON_DATA
+ ld [wMonDataLocation], a
callab GetMaxPP
ld hl, wCurrentMenuItem
ld c, [hl]
@@ -8243,7 +8243,7 @@
ld a, b
call PlayBattleAnimation
ld a, [de]
- ld [wWhichTrade], a
+ ld [wChargeMoveNum], a
ld hl, ChargeMoveEffectText
jp PrintText
@@ -8250,7 +8250,7 @@
ChargeMoveEffectText: ; 3f8c8 (f:78c8)
TX_FAR _ChargeMoveEffectText
TX_ASM
- ld a, [wWhichTrade]
+ ld a, [wChargeMoveNum]
cp RAZOR_WIND
ld hl, MadeWhirlwindText
jr z, .asm_3f8f8
--- a/engine/battle/end_of_battle.asm
+++ b/engine/battle/end_of_battle.asm
@@ -54,7 +54,7 @@
ld [wd11f], a
ld [wNumRunAttempts], a
ld [wEscapedFromBattle], a
- ld hl, wcc2b
+ ld hl, wPartyAndBillsPCSavedMenuItem
ld [hli], a
ld [hli], a
ld [hli], a
--- a/engine/battle/experience.asm
+++ b/engine/battle/experience.asm
@@ -148,8 +148,8 @@
call GetPartyMonName
ld hl, GainedText
call PrintText
- xor a ; party mon data
- ld [wcc49], a
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation], a
call LoadMonData
pop hl
ld bc, wPartyMon1Level - wPartyMon1Exp
@@ -242,15 +242,15 @@
.printGrewLevelText
ld hl, GrewLevelText
call PrintText
- xor a ; party mon data
- ld [wcc49], a
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation], a
call LoadMonData
ld d, $1
callab PrintStatsBox
call WaitForTextScrollButtonPress
call LoadScreenTilesFromBuffer1
- xor a
- ld [wcc49], a
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation], a
ld a, [wd0b5]
ld [wd11e], a
predef LearnMoveFromLevelUp
--- a/engine/battle/init_battle_variables.asm
+++ b/engine/battle/init_battle_variables.asm
@@ -4,7 +4,7 @@
xor a
ld [wActionResultOrTookBattleTurn], a
ld [wBattleResult], a
- ld hl, wcc2b
+ ld hl, wPartyAndBillsPCSavedMenuItem
ld [hli], a
ld [hli], a
ld [hli], a
--- a/engine/battle/read_trainer_party.asm
+++ b/engine/battle/read_trainer_party.asm
@@ -55,8 +55,8 @@
and a ; have we reached the end of the trainer data?
jr z,.FinishUp
ld [wcf91],a ; write species somewhere (XXX why?)
- ld a,1
- ld [wcc49],a
+ ld a,ENEMY_PARTY_DATA
+ ld [wMonDataLocation],a
push hl
call AddPartyMon
pop hl
@@ -72,8 +72,8 @@
ld [W_CURENEMYLVL],a
ld a,[hli]
ld [wcf91],a
- ld a,1
- ld [wcc49],a
+ ld a,ENEMY_PARTY_DATA
+ ld [wMonDataLocation],a
push hl
call AddPartyMon
pop hl
--- a/engine/evos_moves.asm
+++ b/engine/evos_moves.asm
@@ -55,8 +55,8 @@
push hl
ld a, [wcf91]
push af
- xor a
- ld [wcc49], a
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation], a
call LoadMonData
pop af
ld [wcf91], a
@@ -206,7 +206,7 @@
ld a, [wd0b5]
ld [wd11e], a
xor a
- ld [wcc49], a
+ ld [wMonDataLocation], a
call LearnMoveFromLevelUp
pop hl
predef SetPartyMonTypes
@@ -345,12 +345,13 @@
ld a, [hli] ; move ID
jr nz, .learnSetLoop
ld d, a ; ID of move to learn
- ld a, [wcc49]
+ ld a, [wMonDataLocation]
and a
jr nz, .next
-; if [wcc49] is 0, get the address of the mon's current moves
-; there is no reason to make this conditional because the code wouldn't work properly without doing this
-; every call to this function sets [wcc49] to 0
+; If [wMonDataLocation] is 0 (PLAYER_PARTY_DATA), get the address of the mon's
+; current moves in party data. Every call to this function sets
+; [wMonDataLocation] to 0 because other data locations are not supported.
+; If it is not 0, this function will not work properly.
ld hl, wPartyMon1Moves
ld a, [wWhichPokemon]
ld bc, wPartyMon2 - wPartyMon1
--- a/engine/give_pokemon.asm
+++ b/engine/give_pokemon.asm
@@ -16,7 +16,7 @@
call SetPokedexOwnedFlag
callab SendNewMonToBox
ld hl, wcf4b
- ld a, [wd5a0]
+ ld a, [wCurrentBoxNum]
and $7f
cp 9
jr c, .asm_4fdec
--- a/engine/in_game_trades.asm
+++ b/engine/in_game_trades.asm
@@ -130,11 +130,11 @@
ld a,[wInGameTradeReceiveMonSpecies]
ld [wcf91],a
xor a
- ld [wcc49],a
+ ld [wMonDataLocation],a ; not used
ld [wRemoveMonFromBox],a
call RemovePokemon
- ld a,$80
- ld [wcc49],a
+ ld a,$80 ; prevent the player from naming the mon
+ ld [wMonDataLocation],a
call AddPartyMon
call InGameTrade_CopyDataToReceivedMon
callab EvolveTradeMon
--- a/engine/items/items.asm
+++ b/engine/items/items.asm
@@ -423,8 +423,8 @@
ld a,[wPartyCount]
cp a,PARTY_LENGTH ;is party full?
jr z,.sendToBox
- xor a
- ld [wcc49],a
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation],a
call ClearSprites
call AddPartyMon ;add mon to Party
jr .End
@@ -1265,14 +1265,14 @@
ld [wWhichPokemon],a
ld a,e
ld [wd11e],a
- xor a
- ld [wcc49],a ; load from player's party
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation],a
call LoadMonData
ld d,$01
callab PrintStatsBox ; display new stats text box
call WaitForTextScrollButtonPress ; wait for button press
- xor a
- ld [wcc49],a
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation],a
predef LearnMoveFromLevelUp ; learn level up move, if any
xor a
ld [wForceEvolution],a
@@ -1963,8 +1963,8 @@
; unsets zero flag if PP was restored, sets zero flag if not
; however, this is bugged for Max Ethers and Max Elixirs (see below)
.restorePP
- xor a
- ld [wcc49],a ; party pokemon
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation],a
call GetMaxPP
ld hl,wPartyMon1Moves
ld bc,44
@@ -2379,7 +2379,7 @@
; gets max PP of a pokemon's move (including PP from PP Ups)
; INPUT:
; [wWhichPokemon] = index of pokemon within party/box
-; [wcc49] = pokemon source
+; [wMonDataLocation] = pokemon source
; 00: player's party
; 01: enemy's party
; 02: current box
@@ -2389,7 +2389,7 @@
; OUTPUT:
; [wd11e] = max PP
GetMaxPP: ; e677 (3:6677)
- ld a,[wcc49]
+ ld a,[wMonDataLocation]
and a
ld hl,wPartyMon1Moves
ld bc,wPartyMon2 - wPartyMon1
@@ -2426,7 +2426,7 @@
pop hl
push bc
ld bc,21 ; PP offset if not player's in-battle pokemon data
- ld a,[wcc49]
+ ld a,[wMonDataLocation]
cp a,4 ; player's in-battle pokemon?
jr nz,.addPPOffset
ld bc,17 ; PP offset if player's in-battle pokemon data
--- a/engine/menu/bills_pc.asm
+++ b/engine/menu/bills_pc.asm
@@ -1,44 +1,44 @@
-Func_213c8:: ; 213c8 (8:53c8)
+DisplayPCMainMenu:: ; 213c8 (8:53c8)
xor a
ld [H_AUTOBGTRANSFERENABLED], a
call SaveScreenTilesToBuffer2
ld a, [wNumHoFTeams]
and a
- jr nz, .asm_213f3
+ jr nz, .leaguePCAvailable
ld a, [wd74b]
- bit 5, a
- jr z, .asm_213ea
+ bit 5, a ; received pokedex?
+ jr z, .noOaksPC
ld a, [wNumHoFTeams]
and a
- jr nz, .asm_213f3
+ jr nz, .leaguePCAvailable
hlCoord 0, 0
- ld b, $8
- ld c, $e
- jr .asm_213fa
-.asm_213ea
+ ld b, 8
+ ld c, 14
+ jr .next
+.noOaksPC
hlCoord 0, 0
- ld b, $6
- ld c, $e
- jr .asm_213fa
-.asm_213f3
+ ld b, 6
+ ld c, 14
+ jr .next
+.leaguePCAvailable
hlCoord 0, 0
- ld b, $a
- ld c, $e
-.asm_213fa
+ ld b, 10
+ ld c, 14
+.next
call TextBoxBorder
call UpdateSprites
- ld a, $3
+ ld a, 3
ld [wMaxMenuItem], a
ld a, [wd7f1]
bit 0, a
- jr nz, .asm_21414
+ jr nz, .metBill
hlCoord 2, 2
ld de, SomeonesPCText
- jr .asm_2141a
-.asm_21414
+ jr .next2
+.metBill
hlCoord 2, 2
ld de, BillsPCText
-.asm_2141a
+.next2
call PlaceString
hlCoord 2, 4
ld de, wPlayerName
@@ -48,15 +48,15 @@
ld de, PlayersPCText
call PlaceString
ld a, [wd74b]
- bit 5, a
- jr z, .asm_21462
+ bit 5, a ; received pokedex?
+ jr z, .noOaksPC2
hlCoord 2, 6
ld de, OaksPCText
call PlaceString
ld a, [wNumHoFTeams]
and a
- jr z, .asm_2145a
- ld a, $4
+ jr z, .noLeaguePC
+ ld a, 4
ld [wMaxMenuItem], a
hlCoord 2, 8
ld de, PKMNLeaguePCText
@@ -63,28 +63,28 @@
call PlaceString
hlCoord 2, 10
ld de, LogOffPCText
- jr .asm_2146d
-.asm_2145a
+ jr .next3
+.noLeaguePC
hlCoord 2, 8
ld de, LogOffPCText
- jr .asm_2146d
-.asm_21462
+ jr .next3
+.noOaksPC2
ld a, $2
ld [wMaxMenuItem], a
hlCoord 2, 6
ld de, LogOffPCText
-.asm_2146d
+.next3
call PlaceString
- ld a, $3
+ ld a, A_BUTTON | B_BUTTON
ld [wMenuWatchedKeys], a
- ld a, $2
+ ld a, 2
ld [wTopMenuItemY], a
- ld a, $1
+ ld a, 1
ld [wTopMenuItemX], a
xor a
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
- ld a, $1
+ ld a, 1
ld [H_AUTOBGTRANSFERENABLED], a
ret
@@ -99,7 +99,7 @@
ld hl, wd730
set 6, [hl]
xor a
- ld [wccd3], a
+ ld [wParentMenuItem], a
inc a ; MONSTER_NAME
ld [wNameListType], a
call LoadHpBarAndStatusTilePatterns
@@ -106,16 +106,16 @@
ld a, [wListScrollOffset]
push af
ld a, [wFlags_0xcd60]
- bit 3, a
+ bit 3, a ; accessing Bill's PC through another PC?
jr nz, BillsPCMenu
+; accessing it directly
ld a, $99
call PlaySound
ld hl, SwitchOnText
call PrintText
-Func_214e8: ; 214e8 (8:54e8)
-BillsPCMenu:
- ld a, [wccd3]
+BillsPCMenu: ; 214e8 (8:54e8)
+ ld a, [wParentMenuItem]
ld [wCurrentMenuItem], a
ld hl, vChars2 + $780
ld de, PokeballTileGraphics
@@ -123,79 +123,81 @@
call CopyVideoData
call LoadScreenTilesFromBuffer2DisableBGTransfer
hlCoord 0, 0
- ld b, $a
- ld c, $c
+ ld b, 10
+ ld c, 12
call TextBoxBorder
hlCoord 2, 2
ld de, BillsPCMenuText
call PlaceString
ld hl, wTopMenuItemY
- ld a, $2
- ld [hli], a
+ ld a, 2
+ ld [hli], a ; wTopMenuItemY
dec a
- ld [hli], a
+ ld [hli], a ; wTopMenuItemX
inc hl
inc hl
- ld a, $4
- ld [hli], a
- ld a, $3
- ld [hli], a
+ ld a, 4
+ ld [hli], a ; wMaxMenuItem
+ ld a, A_BUTTON | B_BUTTON
+ ld [hli], a ; wMenuWatchedKeys
xor a
- ld [hli], a
- ld [hli], a
+ ld [hli], a ; wLastMenuItem
+ ld [hli], a ; wPartyAndBillsPCSavedMenuItem
ld hl, wListScrollOffset
- ld [hli], a
- ld [hl], a
+ ld [hli], a ; wListScrollOffset
+ ld [hl], a ; wMenuWatchMovingOutOfBounds
ld [wPlayerMonNumber], a
ld hl, WhatText
call PrintText
hlCoord 9, 14
- ld b, $2
- ld c, $9
+ ld b, 2
+ ld c, 9
call TextBoxBorder
- ld a, [wd5a0]
+ ld a, [wCurrentBoxNum]
and $7f
cp 9
- jr c, .asm_2154f
+ jr c, .singleDigitBoxNum
+; two digit box num
sub 9
hlCoord 17, 16
ld [hl], "1"
add "0"
- jr .asm_21551
-.asm_2154f
+ jr .next
+.singleDigitBoxNum
add "1"
-.asm_21551
+.next
Coorda 18, 16
hlCoord 10, 16
ld de, BoxNoPCText
call PlaceString
- ld a, $1
+ ld a, 1
ld [H_AUTOBGTRANSFERENABLED], a
call Delay3
call HandleMenuInput
bit 1, a
- jp nz, Func_21588 ; b button
+ jp nz, ExitBillsPC ; b button
call PlaceUnfilledArrowMenuCursor
ld a, [wCurrentMenuItem]
- ld [wccd3], a
+ ld [wParentMenuItem], a
and a
- jp z, Func_21618 ; withdraw
+ jp z, BillsPCWithdraw ; withdraw
cp $1
- jp z, Func_215ac ; deposit
+ jp z, BillsPCDeposit ; deposit
cp $2
- jp z, Func_21673 ; release
+ jp z, BillsPCRelease ; release
cp $3
- jp z, Func_216b3 ; change box
+ jp z, BillsPCChangeBox ; change box
-Func_21588: ; 21588 (8:5588)
+ExitBillsPC: ; 21588 (8:5588)
ld a, [wFlags_0xcd60]
- bit 3, a
- jr nz, .asm_2159a
+ bit 3, a ; accessing Bill's PC through another PC?
+ jr nz, .next
+; accessing it directly
call LoadTextBoxTilePatterns
ld a, $9a
call PlaySound
call WaitForSoundToFinish
-.asm_2159a
+.next
ld hl, wFlags_0xcd60
res 5, [hl]
call LoadScreenTilesFromBuffer2
@@ -205,26 +207,25 @@
res 6, [hl]
ret
-Func_215ac: ; 215ac (8:55ac)
-BillsPCDeposit:
+BillsPCDeposit: ; 215ac (8:55ac)
ld a, [wPartyCount]
dec a
- jr nz, .asm_215bb
+ jr nz, .partyLargeEnough
ld hl, CantDepositLastMonText
call PrintText
jp BillsPCMenu
-.asm_215bb
+.partyLargeEnough
ld a, [W_NUMINBOX]
cp MONS_PER_BOX
- jr nz, .asm_215cb
+ jr nz, .boxNotFull
ld hl, BoxFullText
call PrintText
jp BillsPCMenu
-.asm_215cb
+.boxNotFull
ld hl, wPartyCount
- call Func_216be
+ call DisplayMonListMenu
jp c, BillsPCMenu
- call Func_2174b
+ call DisplayDepositWithdrawMenu
jp nc, BillsPCMenu
ld a, [wcf91]
call GetCryData
@@ -236,19 +237,19 @@
ld [wRemoveMonFromBox], a
call RemovePokemon
call WaitForSoundToFinish
- ld hl, wWhichTrade
- ld a, [wd5a0]
+ ld hl, wBoxNumString
+ ld a, [wCurrentBoxNum]
and $7f
cp 9
- jr c, .asm_2160a
+ jr c, .singleDigitBoxNum
sub 9
ld [hl], "1"
inc hl
add "0"
- jr .asm_2160c
-.asm_2160a
+ jr .next
+.singleDigitBoxNum
add "1"
-.asm_2160c
+.next
ld [hli], a
ld [hl], $50
ld hl, MonWasStoredText
@@ -255,26 +256,26 @@
call PrintText
jp BillsPCMenu
-Func_21618: ; 21618 (8:5618)
+BillsPCWithdraw: ; 21618 (8:5618)
ld a, [W_NUMINBOX]
and a
- jr nz, .asm_21627
+ jr nz, .boxNotEmpty
ld hl, NoMonText
call PrintText
- jp Func_214e8
-.asm_21627
+ jp BillsPCMenu
+.boxNotEmpty
ld a, [wPartyCount]
cp PARTY_LENGTH
- jr nz, .asm_21637
+ jr nz, .partyNotFull
ld hl, CantTakeMonText
call PrintText
- jp Func_214e8
-.asm_21637
+ jp BillsPCMenu
+.partyNotFull
ld hl, W_NUMINBOX
- call Func_216be
- jp c, Func_214e8
- call Func_2174b
- jp nc, Func_214e8
+ call DisplayMonListMenu
+ jp c, BillsPCMenu
+ call DisplayDepositWithdrawMenu
+ jp nc, BillsPCMenu
ld a, [wWhichPokemon]
ld hl, wBoxMonNicks
call GetPartyMonName
@@ -290,25 +291,25 @@
call WaitForSoundToFinish
ld hl, MonIsTakenOutText
call PrintText
- jp Func_214e8
+ jp BillsPCMenu
-Func_21673: ; 21673 (8:5673)
+BillsPCRelease: ; 21673 (8:5673)
ld a, [W_NUMINBOX]
and a
- jr nz, .asm_21682
+ jr nz, .loop
ld hl, NoMonText
call PrintText
- jp Func_214e8
-.asm_21682
+ jp BillsPCMenu
+.loop
ld hl, W_NUMINBOX
- call Func_216be
- jp c, Func_214e8
+ call DisplayMonListMenu
+ jp c, BillsPCMenu
ld hl, OnceReleasedText
call PrintText
call YesNoChoice
ld a, [wCurrentMenuItem]
and a
- jr nz, .asm_21682
+ jr nz, .loop
inc a
ld [wRemoveMonFromBox], a
call RemovePokemon
@@ -317,13 +318,13 @@
call PlayCry
ld hl, MonWasReleasedText
call PrintText
- jp Func_214e8
+ jp BillsPCMenu
-Func_216b3: ; 216b3 (8:56b3)
+BillsPCChangeBox: ; 216b3 (8:56b3)
callba ChangeBox
- jp Func_214e8
+ jp BillsPCMenu
-Func_216be: ; 216be (8:56be)
+DisplayMonListMenu: ; 216be (8:56be)
ld a, l
ld [wListPointer], a
ld a, h
@@ -333,11 +334,11 @@
ld [wListMenuID], a
inc a ; MONSTER_NAME
ld [wNameListType], a
- ld a, [wcc2b]
+ ld a, [wPartyAndBillsPCSavedMenuItem]
ld [wCurrentMenuItem], a
call DisplayListMenuID
ld a, [wCurrentMenuItem]
- ld [wcc2b], a
+ ld [wPartyAndBillsPCSavedMenuItem], a
ret
BillsPCMenuText: ; 216e1 (8:56e1)
@@ -354,17 +355,19 @@
BoxNoPCText: ; 21713 (8:5713)
db "BOX No.@"
-Func_2171b:: ; 2171b (8:571b)
+KnowsHMMove:: ; 2171b (8:571b)
+; returns whether mon with party index [wWhichPokemon] knows an HM move
ld hl, wPartyMon1Moves
ld bc, wPartyMon2 - wPartyMon1
- jr .asm_21729
+ jr .next
+; unreachable
ld hl, wBoxMon1Moves
ld bc, wBoxMon2 - wBoxMon1
-.asm_21729
+.next
ld a, [wWhichPokemon]
call AddNTimes
ld b, NUM_MOVES
-.asm_21731
+.loop
ld a, [hli]
push hl
push bc
@@ -375,7 +378,7 @@
pop hl
ret c
dec b
- jr nz, .asm_21731
+ jr nz, .loop
and a
ret
@@ -387,17 +390,17 @@
db FLASH
db -1
-Func_2174b: ; 2174b (8:574b)
+DisplayDepositWithdrawMenu: ; 2174b (8:574b)
hlCoord 9, 10
- ld b, $6
- ld c, $9
+ ld b, 6
+ ld c, 9
call TextBoxBorder
- ld a, [wccd3]
- and a
+ ld a, [wParentMenuItem]
+ and a ; was the Deposit or Withdraw item selected in the parent menu?
ld de, DepositPCText
- jr nz, .asm_21761
+ jr nz, .next
ld de, WithdrawPCText
-.asm_21761
+.next
hlCoord 11, 12
call PlaceString
hlCoord 11, 14
@@ -404,48 +407,48 @@
ld de, StatsCancelPCText
call PlaceString
ld hl, wTopMenuItemY
- ld a, $c
- ld [hli], a
- ld a, $a
- ld [hli], a
+ ld a, 12
+ ld [hli], a ; wTopMenuItemY
+ ld a, 10
+ ld [hli], a ; wTopMenuItemX
xor a
- ld [hli], a
+ ld [hli], a ; wCurrentMenuItem
inc hl
- ld a, $2
- ld [hli], a
- ld a, $3
- ld [hli], a
+ ld a, 2
+ ld [hli], a ; wMaxMenuItem
+ ld a, A_BUTTON | B_BUTTON
+ ld [hli], a ; wMenuWatchedKeys
xor a
- ld [hl], a
+ ld [hl], a ; wLastMenuItem
ld hl, wListScrollOffset
- ld [hli], a
- ld [hl], a
+ ld [hli], a ; wListScrollOffset
+ ld [hl], a ; wMenuWatchMovingOutOfBounds
ld [wPlayerMonNumber], a
- ld [wcc2b], a
-.asm_2178f
+ ld [wPartyAndBillsPCSavedMenuItem], a
+.loop
call HandleMenuInput
- bit 1, a
- jr nz, .asm_2179f
+ bit 1, a ; pressed B?
+ jr nz, .exit
ld a, [wCurrentMenuItem]
and a
- jr z, .asm_217a1
+ jr z, .choseDepositWithdraw
dec a
- jr z, .asm_217a3
-.asm_2179f
+ jr z, .viewStats
+.exit
and a
ret
-.asm_217a1
+.choseDepositWithdraw
scf
ret
-.asm_217a3
+.viewStats
call SaveScreenTilesToBuffer1
- ld a, [wccd3]
+ ld a, [wParentMenuItem]
and a
- ld a, $0
- jr nz, .asm_217b0
- ld a, $2
-.asm_217b0
- ld [wcc49], a
+ ld a, PLAYER_PARTY_DATA
+ jr nz, .next2
+ ld a, BOX_DATA
+.next2
+ ld [wMonDataLocation], a
predef StatusScreen
predef StatusScreen2
call LoadScreenTilesFromBuffer1
@@ -452,7 +455,7 @@
call ReloadTilesetTilePatterns
call GoPAL_SET_CF1C
call LoadGBPal
- jr .asm_2178f
+ jr .loop
DepositPCText: db "DEPOSIT@"
WithdrawPCText: db "WITHDRAW@"
@@ -518,9 +521,9 @@
ld a, [W_CURMAP]
cp BATTLE_CENTER
ld a, LINK_STATE_START_TRADE
- jr z, .asm_2183a
+ jr z, .next
inc a ; LINK_STATE_START_BATTLE
-.asm_2183a
+.next
ld [wLinkState], a
call EnableAutoTextBoxDrawing
tx_pre_jump JustAMomentText
@@ -535,9 +538,9 @@
ld a, [W_CURMAP]
cp BATTLE_CENTER
ld a, LINK_STATE_START_TRADE
- jr z, .asm_2185a
+ jr z, .next
inc a ; LINK_STATE_START_BATTLE
-.asm_2185a
+.next
ld [wLinkState], a
call EnableAutoTextBoxDrawing
tx_pre_jump JustAMomentText
--- a/engine/menu/main_menu.asm
+++ b/engine/menu/main_menu.asm
@@ -16,7 +16,7 @@
call DelayFrames
xor a ; LINK_STATE_NONE
ld [wLinkState],a
- ld hl,wcc2b
+ ld hl,wPartyAndBillsPCSavedMenuItem
ld [hli],a
ld [hli],a
ld [hli],a
@@ -457,7 +457,7 @@
ld a,3 ; text speed cursor Y coordinate
ld [wTopMenuItemY],a
call SetCursorPositionsFromOptions
- ld a,[wWhichTrade] ; text speed cursor X coordinate
+ ld a,[wOptionsTextSpeedCursorX] ; text speed cursor X coordinate
ld [wTopMenuItemX],a
ld a,$01
ld [H_AUTOBGTRANSFERENABLED],a ; enable auto background transfer
@@ -507,7 +507,7 @@
.downPressed
cp a,16
ld b,-13
- ld hl,wWhichTrade
+ ld hl,wOptionsTextSpeedCursorX
jr z,.updateMenuVariables
ld b,5
cp a,3
@@ -522,7 +522,7 @@
.upPressed
cp a,8
ld b,-5
- ld hl,wWhichTrade
+ ld hl,wOptionsTextSpeedCursorX
jr z,.updateMenuVariables
cp a,13
inc hl
@@ -541,17 +541,17 @@
call PlaceUnfilledArrowMenuCursor
jp .loop
.cursorInBattleAnimation
- ld a,[wTrainerEngageDistance] ; battle animation cursor X coordinate
+ ld a,[wOptionsBattleAnimCursorX] ; battle animation cursor X coordinate
xor a,$0b ; toggle between 1 and 10
- ld [wTrainerEngageDistance],a
+ ld [wOptionsBattleAnimCursorX],a
jp .eraseOldMenuCursor
.cursorInBattleStyle
- ld a,[wTrainerFacingDirection] ; battle style cursor X coordinate
+ ld a,[wOptionsBattleStyleCursorX] ; battle style cursor X coordinate
xor a,$0b ; toggle between 1 and 10
- ld [wTrainerFacingDirection],a
+ ld [wOptionsBattleStyleCursorX],a
jp .eraseOldMenuCursor
.pressedLeftInTextSpeed
- ld a,[wWhichTrade] ; text speed cursor X coordinate
+ ld a,[wOptionsTextSpeedCursorX] ; text speed cursor X coordinate
cp a,1
jr z,.updateTextSpeedXCoord
cp a,7
@@ -562,7 +562,7 @@
sub a,7
jr .updateTextSpeedXCoord
.pressedRightInTextSpeed
- ld a,[wWhichTrade] ; text speed cursor X coordinate
+ ld a,[wOptionsTextSpeedCursorX] ; text speed cursor X coordinate
cp a,14
jr z,.updateTextSpeedXCoord
cp a,7
@@ -572,7 +572,7 @@
.fromFastToMedium
add a,6
.updateTextSpeedXCoord
- ld [wWhichTrade],a ; text speed cursor X coordinate
+ ld [wOptionsTextSpeedCursorX],a ; text speed cursor X coordinate
jp .eraseOldMenuCursor
TextSpeedOptionText: ; 5fc0 (1:5fc0)
@@ -593,7 +593,7 @@
; sets the options variable according to the current placement of the menu cursors in the options menu
SetOptionsFromCursorPositions: ; 601f (1:601f)
ld hl,TextSpeedOptionData
- ld a,[wWhichTrade] ; text speed cursor X coordinate
+ ld a,[wOptionsTextSpeedCursorX] ; text speed cursor X coordinate
ld c,a
.loop
ld a,[hli]
@@ -604,7 +604,7 @@
.textSpeedMatchFound
ld a,[hl]
ld d,a
- ld a,[wTrainerEngageDistance] ; battle animation cursor X coordinate
+ ld a,[wOptionsBattleAnimCursorX] ; battle animation cursor X coordinate
dec a
jr z,.battleAnimationOn
.battleAnimationOff
@@ -613,7 +613,7 @@
.battleAnimationOn
res 7,d
.checkBattleStyle
- ld a,[wTrainerFacingDirection] ; battle style cursor X coordinate
+ ld a,[wOptionsBattleStyleCursorX] ; battle style cursor X coordinate
dec a
jr z,.battleStyleShift
.battleStyleSet
@@ -638,7 +638,7 @@
pop bc
dec hl
ld a,[hl]
- ld [wWhichTrade],a ; text speed cursor X coordinate
+ ld [wOptionsTextSpeedCursorX],a ; text speed cursor X coordinate
hlCoord 0, 3
call .placeUnfilledRightArrow
sla c
@@ -646,7 +646,7 @@
jr nc,.storeBattleAnimationCursorX
ld a,10 ; Off
.storeBattleAnimationCursorX
- ld [wTrainerEngageDistance],a ; battle animation cursor X coordinate
+ ld [wOptionsBattleAnimCursorX],a ; battle animation cursor X coordinate
hlCoord 0, 8
call .placeUnfilledRightArrow
sla c
@@ -654,7 +654,7 @@
jr nc,.storeBattleStyleCursorX
ld a,10
.storeBattleStyleCursorX
- ld [wTrainerFacingDirection],a ; battle style cursor X coordinate
+ ld [wOptionsBattleStyleCursorX],a ; battle style cursor X coordinate
hlCoord 0, 13
call .placeUnfilledRightArrow
; cursor in front of Cancel
--- a/engine/menu/pc.asm
+++ b/engine/menu/pc.asm
@@ -10,7 +10,7 @@
call LoadScreenTilesFromBuffer2
call Delay3
PCMainMenu: ; 17e48 (5:7e48)
- callba Func_213c8
+ callba DisplayPCMainMenu
ld hl, wFlags_0xcd60
set 5, [hl]
call HandleMenuInput
--- a/engine/menu/players_pc.asm
+++ b/engine/menu/players_pc.asm
@@ -5,18 +5,19 @@
ld [wNameListType], a
call SaveScreenTilesToBuffer1
xor a
- ld [wcc2c], a
- ld [wccd3], a
+ ld [wBagSavedMenuItem], a
+ ld [wParentMenuItem], a
ld a, [wFlags_0xcd60]
- bit 3, a
- jr nz, Func_790c
+ bit 3, a ; accessing player's PC through another PC?
+ jr nz, PlayerPCMenu
+; accessing it directly
ld a, (SFX_02_45 - SFX_Headers_02) / 3
call PlaySound
ld hl, TurnedOnPC2Text
call PrintText
-Func_790c: ; 790c (1:790c)
- ld a, [wccd3]
+PlayerPCMenu: ; 790c (1:790c)
+ ld a, [wParentMenuItem]
ld [wCurrentMenuItem], a
ld hl, wFlags_0xcd60
set 5, [hl]
@@ -30,51 +31,52 @@
ld de, PlayersPCMenuEntries
call PlaceString
ld hl, wTopMenuItemY
- ld a, $2
- ld [hli], a
+ ld a, 2
+ ld [hli], a ; wTopMenuItemY
dec a
- ld [hli], a
+ ld [hli], a ; wTopMenuItemX
inc hl
inc hl
- ld a, $3
- ld [hli], a
- ld a, $3
- ld [hli], a
+ ld a, 3
+ ld [hli], a ; wMaxMenuItem
+ ld a, A_BUTTON | B_BUTTON
+ ld [hli], a ; wMenuWatchedKeys
xor a
ld [hl], a
ld hl, wListScrollOffset
- ld [hli], a
- ld [hl], a
+ ld [hli], a ; wListScrollOffset
+ ld [hl], a ; wMenuWatchMovingOutOfBounds
ld [wPlayerMonNumber], a
ld hl, WhatDoYouWantText
call PrintText
call HandleMenuInput
bit 1, a
- jp nz, Func_796d
+ jp nz, ExitPlayerPC
call PlaceUnfilledArrowMenuCursor
ld a, [wCurrentMenuItem]
- ld [wccd3], a
+ ld [wParentMenuItem], a
and a
- jp z, Func_7a12
+ jp z, PlayerPCWithdraw
dec a
- jp z, Func_7995
+ jp z, PlayerPCDeposit
dec a
- jp z, Func_7a8f
+ jp z, PlayerPCToss
-Func_796d: ; 796d (1:796d)
+ExitPlayerPC: ; 796d (1:796d)
ld a, [wFlags_0xcd60]
- bit 3, a
- jr nz, .asm_797c
+ bit 3, a ; accessing player's PC through another PC?
+ jr nz, .next
+; accessing it directly
ld a, (SFX_02_46 - SFX_Headers_02) / 3
call PlaySound
call WaitForSoundToFinish
-.asm_797c
+.next
ld hl, wFlags_0xcd60
res 5, [hl]
call LoadScreenTilesFromBuffer2
xor a
ld [wListScrollOffset], a
- ld [wcc2c], a
+ ld [wBagSavedMenuItem], a
ld hl, wd730
res 6, [hl]
xor a
@@ -81,18 +83,17 @@
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
ret
-Func_7995: ; 7995 (1:7995)
+PlayerPCDeposit: ; 7995 (1:7995)
xor a
ld [wCurrentMenuItem], a
ld [wListScrollOffset], a
ld a, [wNumBagItems]
and a
- jr nz, Func_79ab
+ jr nz, .loop
ld hl, NothingToDepositText
call PrintText
- jp Func_790c
-
-Func_79ab: ; 79ab (1:79ab)
+ jp PlayerPCMenu
+.loop
ld hl, WhatToDepositText
call PrintText
ld hl, wNumBagItems
@@ -102,29 +103,30 @@
ld [wListPointer + 1], a
xor a
ld [wPrintItemPrices], a
- ld a, $3
+ ld a, ITEMLISTMENU
ld [wListMenuID], a
call DisplayListMenuID
- jp c, Func_790c
+ jp c, PlayerPCMenu
call IsKeyItem
- ld a, $1
+ ld a, 1
ld [wItemQuantity], a
ld a, [wIsKeyItem]
and a
- jr nz, .asm_79e7
+ jr nz, .next
+; if it's not a key item, there can be more than one of the item
ld hl, DepositHowManyText
call PrintText
call DisplayChooseQuantityMenu
cp $ff
- jp z, Func_79ab
-.asm_79e7
+ jp z, .loop
+.next
ld hl, wNumBoxItems
call AddItemToInventory
- jr c, .asm_79f8
+ jr c, .roomAvailable
ld hl, NoRoomToStoreText
call PrintText
- jp Func_79ab
-.asm_79f8
+ jp .loop
+.roomAvailable
ld hl, wNumBagItems
call RemoveItemFromInventory
call WaitForSoundToFinish
@@ -133,20 +135,19 @@
call WaitForSoundToFinish
ld hl, ItemWasStoredText
call PrintText
- jp Func_79ab
+ jp .loop
-Func_7a12: ; 7a12 (1:7a12)
+PlayerPCWithdraw: ; 7a12 (1:7a12)
xor a
ld [wCurrentMenuItem], a
ld [wListScrollOffset], a
ld a, [wNumBoxItems]
and a
- jr nz, Func_7a28
+ jr nz, .loop
ld hl, NothingStoredText
call PrintText
- jp Func_790c
-
-Func_7a28: ; 7a28 (1:7a28)
+ jp PlayerPCMenu
+.loop
ld hl, WhatToWithdrawText
call PrintText
ld hl, wNumBoxItems
@@ -156,29 +157,30 @@
ld [wListPointer + 1], a
xor a
ld [wPrintItemPrices], a
- ld a, $3
+ ld a, ITEMLISTMENU
ld [wListMenuID], a
call DisplayListMenuID
- jp c, Func_790c
+ jp c, PlayerPCMenu
call IsKeyItem
- ld a, $1
+ ld a, 1
ld [wItemQuantity], a
ld a, [wIsKeyItem]
and a
- jr nz, .asm_7a64
+ jr nz, .next
+; if it's not a key item, there can be more than one of the item
ld hl, WithdrawHowManyText
call PrintText
call DisplayChooseQuantityMenu
cp $ff
- jp z, Func_7a28
-.asm_7a64
+ jp z, .loop
+.next
ld hl, wNumBagItems
call AddItemToInventory
- jr c, .asm_7a75
+ jr c, .roomAvailable
ld hl, CantCarryMoreText
call PrintText
- jp Func_7a28
-.asm_7a75
+ jp .loop
+.roomAvailable
ld hl, wNumBoxItems
call RemoveItemFromInventory
call WaitForSoundToFinish
@@ -187,20 +189,19 @@
call WaitForSoundToFinish
ld hl, WithdrewItemText
call PrintText
- jp Func_7a28
+ jp .loop
-Func_7a8f: ; 7a8f (1:7a8f)
+PlayerPCToss: ; 7a8f (1:7a8f)
xor a
ld [wCurrentMenuItem], a
ld [wListScrollOffset], a
ld a, [wNumBoxItems]
and a
- jr nz, Func_7aa5
+ jr nz, .loop
ld hl, NothingStoredText
call PrintText
- jp Func_790c
-
-Func_7aa5: ; 7aa5 (1:7aa5)
+ jp PlayerPCMenu
+.loop
ld hl, WhatToTossText
call PrintText
ld hl, wNumBoxItems
@@ -210,23 +211,24 @@
ld [wListPointer + 1], a
xor a
ld [wPrintItemPrices], a
- ld a, $3
+ ld a, ITEMLISTMENU
ld [wListMenuID], a
push hl
call DisplayListMenuID
pop hl
- jp c, Func_790c
+ jp c, PlayerPCMenu
push hl
call IsKeyItem
pop hl
- ld a, $1
+ ld a, 1
ld [wItemQuantity], a
ld a, [wIsKeyItem]
and a
- jr nz, .asm_7aef
+ jr nz, .next
ld a, [wcf91]
call IsItemHM
- jr c, .asm_7aef
+ jr c, .next
+; if it's not a key item, there can be more than one of the item
push hl
ld hl, TossHowManyText
call PrintText
@@ -233,10 +235,10 @@
call DisplayChooseQuantityMenu
pop hl
cp $ff
- jp z, Func_7aa5
-.asm_7aef
- call TossItem
- jp Func_7aa5
+ jp z, .loop
+.next
+ call TossItem ; disallows tossing key items
+ jp .loop
PlayersPCMenuEntries: ; 7af5 (1:7af5)
db "WITHDRAW ITEM"
--- a/engine/menu/start_menu.asm
+++ b/engine/menu/start_menu.asm
@@ -54,7 +54,7 @@
.buttonPressed ; A, B, or Start button pressed
call PlaceUnfilledArrowMenuCursor
ld a,[wCurrentMenuItem]
- ld [wcc2d],a ; save current menu item ID
+ ld [wBattleAndStartSavedMenuItem],a ; save current menu selection
ld a,b
and a,%00001010 ; was the Start button or B button pressed?
jp nz,CloseStartMenu
--- a/engine/menu/start_sub_menus.asm
+++ b/engine/menu/start_sub_menus.asm
@@ -81,7 +81,7 @@
jp z,.choseStats
ld c,a
ld b,0
- ld hl,wWhichTrade
+ ld hl,wFieldMoves
add hl,bc
jp .choseOutOfBattleMove
.choseSwitch
@@ -88,7 +88,7 @@
ld a,[wPartyCount]
cp a,2 ; is there more than one pokemon in the party?
jp c,StartMenu_Pokemon ; if not, no switching
- call SwitchPartyMon_Stats
+ call SwitchPartyMon_InitVarOrSwapData ; init [wMenuItemToSwap]
ld a,SWAP_MONS_PARTY_MENU
ld [wPartyMenuTypeOrMessageID],a
call GoBackToPartyMenu
@@ -95,8 +95,8 @@
jp .checkIfPokemonChosen
.choseStats
call ClearSprites
- xor a
- ld [wcc49],a
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation],a
predef StatusScreen
predef StatusScreen2
call ReloadMapData
@@ -256,7 +256,7 @@
ld a,[H_QUOTIENT + 2]
sbc b
jp nc,.notHealthyEnough
- ld a,[wcc2b]
+ ld a,[wPartyAndBillsPCSavedMenuItem]
push af
ld a,POTION
ld [wcf91],a
@@ -263,7 +263,7 @@
ld [wd152],a
call UseItem
pop af
- ld [wcc2b],a
+ ld [wPartyAndBillsPCSavedMenuItem],a
jp .loop
.notHealthyEnough ; if current HP is less than 1/5 of max HP
ld hl,.notHealthyEnoughText
@@ -316,11 +316,11 @@
ld [wPrintItemPrices],a
ld a,ITEMLISTMENU
ld [wListMenuID],a
- ld a,[wcc2c]
+ ld a,[wBagSavedMenuItem]
ld [wCurrentMenuItem],a
call DisplayListMenuID
ld a,[wCurrentMenuItem]
- ld [wcc2c],a
+ ld [wBagSavedMenuItem],a
jr nc,.choseItem
.exitMenu
call LoadScreenTilesFromBuffer2 ; restore saved screen
@@ -566,7 +566,7 @@
ld de,vChars1 + $570
call TrainerInfo_FarCopyData
call EnableLCD
- ld hl,wWhichTrade
+ ld hl,wTrainerInfoTextBoxWidthPlus1
ld a,18 + 1
ld [hli],a
dec a
@@ -574,7 +574,7 @@
ld [hl],1
hlCoord 0, 0
call TrainerInfo_DrawTextBox
- ld hl,wWhichTrade
+ ld hl,wTrainerInfoTextBoxWidthPlus1
ld a,16 + 1
ld [hli],a
dec a
@@ -627,15 +627,15 @@
; height is always 6
; INPUT:
; hl = destination address
-; [wWhichTrade] = width + 1
-; [wTrainerEngageDistance] = width
-; [wTrainerFacingDirection] = distance from the end of a text box row to the start of the next
+; [wTrainerInfoTextBoxWidthPlus1] = width
+; [wTrainerInfoTextBoxWidth] = width - 1
+; [wTrainerInfoTextBoxNextRowOffset] = distance from the end of a text box row to the start of the next
TrainerInfo_DrawTextBox: ; 135a0 (4:75a0)
ld a,$79 ; upper left corner tile ID
ld de,$7a7b ; top edge and upper right corner tile ID's
call TrainerInfo_DrawHorizontalEdge ; draw top edge
call TrainerInfo_NextTextBoxRow
- ld a,[wWhichTrade] ; width of the text box plus one
+ ld a,[wTrainerInfoTextBoxWidthPlus1]
ld e,a
ld d,0
ld c,6 ; height of the text box
@@ -651,7 +651,7 @@
TrainerInfo_DrawHorizontalEdge: ; 135c3 (4:75c3)
ld [hli],a ; place left corner tile
- ld a,[wTrainerEngageDistance] ; width of the text box
+ ld a,[wTrainerInfoTextBoxWidth]
ld c,a
ld a,d
.loop
@@ -663,7 +663,7 @@
ret
TrainerInfo_NextTextBoxRow: ; 135d0 (4:75d0)
- ld a,[wTrainerFacingDirection] ; distance to the start of the next row
+ ld a,[wTrainerInfoTextBoxNextRowOffset] ; distance to the start of the next row
.loop
inc hl
dec a
@@ -704,14 +704,14 @@
jp RedisplayStartMenu
SwitchPartyMon: ; 13613 (4:7613)
- call SwitchPartyMon_Stats
- ld a, [wWhichTrade]
- call SwitchPartyMon_OAM
+ call SwitchPartyMon_InitVarOrSwapData ; swap data
+ ld a, [wSwappedMenuItem]
+ call SwitchPartyMon_ClearGfx
ld a, [wCurrentMenuItem]
- call SwitchPartyMon_OAM
+ call SwitchPartyMon_ClearGfx
jp RedrawPartyMenu_
-SwitchPartyMon_OAM: ; 13625 (4:7625)
+SwitchPartyMon_ClearGfx: ; 13625 (4:7625)
push af
hlCoord 0, 0
ld bc, SCREEN_WIDTH * 2
@@ -718,10 +718,10 @@
call AddNTimes
ld c, SCREEN_WIDTH * 2
ld a, " "
-.asm_13633
+.clearMonBGLoop ; clear the mon's row in the party menu
ld [hli], a
dec c
- jr nz, .asm_13633
+ jr nz, .clearMonBGLoop
pop af
ld hl, wOAMBuffer
ld bc, $10
@@ -728,24 +728,26 @@
call AddNTimes
ld de, $4
ld c, e
-.asm_13645
+.clearMonOAMLoop
ld [hl], $a0
add hl, de
dec c
- jr nz, .asm_13645
+ jr nz, .clearMonOAMLoop
call WaitForSoundToFinish
ld a, (SFX_02_58 - SFX_Headers_02) / 3
jp PlaySound
-SwitchPartyMon_Stats: ; 13653 (4:7653)
+SwitchPartyMon_InitVarOrSwapData: ; 13653 (4:7653)
+; This is used to initialise [wMenuItemToSwap] and to actually swap the data.
ld a, [wMenuItemToSwap]
- and a
- jr nz, .asm_13661
+ and a ; has [wMenuItemToSwap] been initialised yet?
+ jr nz, .pickedMonsToSwap
+; If not, initialise [wMenuItemToSwap] so that it matches the current mon.
ld a, [wWhichPokemon]
- inc a
+ inc a ; [wMenuItemToSwap] counts from 1
ld [wMenuItemToSwap], a
ret
-.asm_13661
+.pickedMonsToSwap
xor a
ld [wPartyMenuTypeOrMessageID], a
ld a, [wMenuItemToSwap]
@@ -752,14 +754,15 @@
dec a
ld b, a
ld a, [wCurrentMenuItem]
- ld [wWhichTrade], a
- cp b
- jr nz, .asm_1367b
+ ld [wSwappedMenuItem], a
+ cp b ; swapping a mon with itself?
+ jr nz, .swappingDifferentMons
+; can't swap a mon with itself
xor a
ld [wMenuItemToSwap], a
ld [wPartyMenuTypeOrMessageID], a
ret
-.asm_1367b
+.swappingDifferentMons
ld a, b
ld [wMenuItemToSwap], a
push hl
@@ -770,20 +773,20 @@
ld a, [wCurrentMenuItem]
add l
ld l, a
- jr nc, .asm_1368e
+ jr nc, .noCarry
inc h
-.asm_1368e
+.noCarry
ld a, [wMenuItemToSwap]
add e
ld e, a
- jr nc, .asm_13696
+ jr nc, .noCarry2
inc d
-.asm_13696
+.noCarry2
ld a, [hl]
- ld [H_DIVIDEND], a ; (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
+ ld [hSwapTemp], a
ld a, [de]
ld [hl], a
- ld a, [H_DIVIDEND] ; (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
+ ld a, [hSwapTemp]
ld [de], a
ld hl, wPartyMons
ld bc, wPartyMon2 - wPartyMon1
@@ -791,19 +794,19 @@
call AddNTimes
push hl
ld de, wSwitchPartyMonTempBuffer
- ld bc, $2c
+ ld bc, wPartyMon2 - wPartyMon1
call CopyData
ld hl, wPartyMons
- ld bc, $2c
+ ld bc, wPartyMon2 - wPartyMon1
ld a, [wMenuItemToSwap]
call AddNTimes
pop de
push hl
- ld bc, $2c
+ ld bc, wPartyMon2 - wPartyMon1
call CopyData
pop de
ld hl, wSwitchPartyMonTempBuffer
- ld bc, $2c
+ ld bc, wPartyMon2 - wPartyMon1
call CopyData
ld hl, wPartyMonOT
ld a, [wCurrentMenuItem]
@@ -842,7 +845,7 @@
ld bc, $b
call CopyData
ld a, [wMenuItemToSwap]
- ld [wWhichTrade], a
+ ld [wSwappedMenuItem], a
xor a
ld [wMenuItemToSwap], a
ld [wPartyMenuTypeOrMessageID], a
--- a/engine/menu/status_screen.asm
+++ b/engine/menu/status_screen.asm
@@ -65,9 +65,10 @@
; Predef 0x37
StatusScreen: ; 12953 (4:6953)
call LoadMonData
- ld a, [wcc49]
- cp $2 ; 2 means we're in a PC box
+ ld a, [wMonDataLocation]
+ cp BOX_DATA
jr c, .DontRecalculate
+; mon is in a box or daycare
ld a, [wLoadedMonBoxLevel]
ld [wLoadedMonLevel], a
ld [W_CURENEMYLVL], a
@@ -148,13 +149,13 @@
hlCoord 11, 10
predef PrintMonType
ld hl, NamePointers2
- call .asm_12a7e
+ call .GetStringPointer
ld d, h
ld e, l
hlCoord 9, 1
call PlaceString ; Pokémon name
ld hl, OTPointers
- call .asm_12a7e
+ call .GetStringPointer
ld d, h
ld e, l
hlCoord 12, 16
@@ -175,17 +176,18 @@
pop af
ld [hTilesetType], a
ret
-.asm_12a7e ; I don't know what this does, iterates over pointers?
- ld a, [wcc49]
+
+.GetStringPointer
+ ld a, [wMonDataLocation]
add a
ld c, a
- ld b, $0
+ ld b, 0
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
- ld a, [wcc49]
- cp $3
+ ld a, [wMonDataLocation]
+ cp DAYCARE_DATA
ret z
ld a, [wWhichPokemon]
jp SkipFixedLengthTextEntries
--- a/engine/save.asm
+++ b/engine/save.asm
@@ -309,7 +309,7 @@
Func_7387b: ; 7387b (1c:787b)
ld hl, PointerTable_73895
- ld a, [wd5a0]
+ ld a, [wCurrentBoxNum]
and $7f
cp NUM_BOXES / 2
ld b, $2
@@ -341,7 +341,7 @@
ld a, [wCurrentMenuItem]
and a
ret nz ; return if No was chosen
- ld hl, wd5a0
+ ld hl, wCurrentBoxNum
bit 7, [hl]
call z, Func_73a29
call Func_7393f
@@ -360,7 +360,7 @@
call Func_7390e
ld a, [wCurrentMenuItem]
set 7, a
- ld [wd5a0], a
+ ld [wCurrentBoxNum], a
call Func_7387b
ld de, W_NUMINBOX
call Func_7390e
@@ -422,7 +422,7 @@
ld [wTopMenuItemX], a
xor a
ld [wMenuWatchMovingOutOfBounds], a
- ld a, [wd5a0]
+ ld a, [wCurrentBoxNum]
and $7f
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
@@ -443,7 +443,7 @@
call PlaceString
ld hl, hFlags_0xFFF6
res 2, [hl]
- ld a, [wd5a0]
+ ld a, [wCurrentBoxNum]
and $7f
cp 9
jr c, .asm_739a6
@@ -561,7 +561,7 @@
ld [MBC1SRamBankingMode], a
ld [MBC1SRamEnable], a
pop hl
- ld a, [wd5a0]
+ ld a, [wCurrentBoxNum]
and $7f
ld c, a
ld b, $0
--- a/home.asm
+++ b/home.asm
@@ -243,7 +243,7 @@
; loads base stats to W_MONHDEXNUM
; INPUT:
; [wWhichPokemon] = index of pokemon within party/box
-; [wcc49] = source
+; [wMonDataLocation] = source
; 00: player's party
; 01: enemy's party
; 02: current box
@@ -376,8 +376,8 @@
call LoadHpBarAndStatusTilePatterns
ld hl, wd730
set 6, [hl] ; turn off letter printing delay
- xor a
- ld [wcc49], a
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation], a
ld [wMenuWatchMovingOutOfBounds], a
ld hl, wTopMenuItemY
inc a
@@ -384,7 +384,7 @@
ld [hli], a ; top menu item Y
xor a
ld [hli], a ; top menu item X
- ld a, [wcc2b]
+ ld a, [wPartyAndBillsPCSavedMenuItem]
push af
ld [hli], a ; current menu item ID
inc hl
@@ -420,7 +420,7 @@
xor a
ld [wd09b],a
ld a,[wCurrentMenuItem]
- ld [wcc2b],a
+ ld [wPartyAndBillsPCSavedMenuItem],a
ld hl,wd730
res 6,[hl] ; turn on letter printing delay
ld a,[wMenuItemToSwap]
@@ -1803,11 +1803,11 @@
ld hl,wPartyCount
ld a,[wListPointer]
cp l ; is it a list of party pokemon or box pokemon?
- ld a,$00
+ ld a,PLAYER_PARTY_DATA
jr z,.next
- ld a,$02
+ ld a,BOX_DATA
.next
- ld [wcc49],a
+ ld [wMonDataLocation],a
ld hl,wWhichPokemon
ld a,[hl]
ld b,a
@@ -1818,7 +1818,7 @@
add b
ld [hl],a
call LoadMonData ; load pokemon info
- ld a,[wcc49]
+ ld a,[wMonDataLocation]
and a ; is it a list of party pokemon or box pokemon?
jr z,.skipCopyingLevel
.copyLevel
@@ -2751,7 +2751,7 @@
; INPUT:
; hl = address of array
; OUTPUT:
-; [wWhichTrade] = if there is match, the matching array index
+; [wCoordIndex] = if there is match, the matching array index
; sets carry if the coordinates are in the array, clears carry if not
ArePlayerCoordsInArray:: ; 34bf (0:34bf)
ld a,[W_YCOORD]
@@ -2762,13 +2762,13 @@
CheckCoords:: ; 34c7 (0:34c7)
xor a
- ld [wWhichTrade],a
+ ld [wCoordIndex],a
.loop
ld a,[hli]
cp a,$ff ; reached terminator?
jr z,.notInArray
push hl
- ld hl,wWhichTrade
+ ld hl,wCoordIndex
inc [hl]
pop hl
.compareYCoord
@@ -2792,7 +2792,7 @@
; hl = address of array
; [H_SPRITEINDEX] = index of boulder sprite
; OUTPUT:
-; [wWhichTrade] = if there is match, the matching array index
+; [wCoordIndex] = if there is match, the matching array index
; sets carry if the coordinates are in the array, clears carry if not
CheckBoulderCoords:: ; 34e4 (0:34e4)
push hl
@@ -4586,8 +4586,8 @@
ld [wcf91], a
ld a, c
ld [W_CURENEMYLVL], a
- xor a
- ld [wcc49], a
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation], a
ld b, BANK(_GivePokemon)
ld hl, _GivePokemon
jp Bankswitch
--- a/hram.asm
+++ b/hram.asm
@@ -44,6 +44,9 @@
; CalcPositionOfPlayerRelativeToNPC
hNPCSpriteOffset EQU $FF95
+; temp value used when swapping bytes
+hSwapTemp EQU $FF95
+
; Multiplcation and division variables are meant
; to overlap for back-to-back usage. Big endian.
@@ -197,6 +200,8 @@
hTilesetType EQU $FFD7
H_CURRENTSPRITEOFFSET EQU $FFDA ; multiple of $10
+
+hNewPartyLength EQU $FFE4
hDividend2 EQU $FFE5
hDivisor2 EQU $FFE6
--- a/main.asm
+++ b/main.asm
@@ -80,7 +80,7 @@
LoadMonData_:
-; Load monster [wWhichPokemon] from list [wcc49]:
+; Load monster [wWhichPokemon] from list [wMonDataLocation]:
; 0: partymon
; 1: enemymon
; 2: boxmon
@@ -90,8 +90,8 @@
ld a, [wDayCareMonSpecies]
ld [wcf91], a
- ld a, [wcc49]
- cp 3
+ ld a, [wMonDataLocation]
+ cp DAYCARE_DATA
jr z, .GetMonHeader
ld a, [wWhichPokemon]
@@ -105,8 +105,8 @@
ld hl, wPartyMons
ld bc, wPartyMon2 - wPartyMon1
- ld a, [wcc49]
- cp 1
+ ld a, [wMonDataLocation]
+ cp ENEMY_PARTY_DATA
jr c, .getMonEntry
ld hl, wEnemyMons
@@ -564,7 +564,7 @@
ld a, 20
ld [W_CURENEMYLVL], a
xor a
- ld [wcc49], a
+ ld [wMonDataLocation], a
ld [W_CURMAP], a
call AddPartyMon
@@ -1090,7 +1090,7 @@
ld [wTopMenuItemY],a ; Y position of first menu choice
ld a,$0b
ld [wTopMenuItemX],a ; X position of first menu choice
- ld a,[wcc2d] ; remembered menu selection from last time
+ ld a,[wBattleAndStartSavedMenuItem] ; remembered menu selection from last time
ld [wCurrentMenuItem],a
ld [wLastMenuItem],a
xor a
@@ -2926,7 +2926,7 @@
xor a
ld [wListScrollOffset],a
ld [wCurrentMenuItem],a
- ld [wcc2c],a
+ ld [wBagSavedMenuItem],a
ld [wSavedListScrollOffset],a
pop hl
ld a,[hl] ; a = number of items in inventory
@@ -3553,36 +3553,40 @@
ret
_AddPartyMon: ; f2e5 (3:72e5)
+; Adds a new mon to the player's or enemy's party.
+; [wMonDataLocation] is used in an unusual way in this function.
+; If the lower nybble is 0, the mon is added to the player's party, else the enemy's.
+; If the entire value is 0, then the player is allowed to name the mon.
ld de, wPartyCount
- ld a, [wcc49]
+ ld a, [wMonDataLocation]
and $f
- jr z, .asm_f2f2
+ jr z, .next
ld de, wEnemyPartyCount
-.asm_f2f2
+.next
ld a, [de]
inc a
cp PARTY_LENGTH + 1
- ret nc
+ ret nc ; return if the party is already full
ld [de], a
ld a, [de]
- ld [$ffe4], a
+ ld [hNewPartyLength], a
add e
ld e, a
- jr nc, .asm_f300
+ jr nc, .noCarry
inc d
-.asm_f300
+.noCarry
ld a, [wcf91]
- ld [de], a
+ ld [de], a ; write species of new mon in party list
inc de
- ld a, $ff
+ ld a, $ff ; terminator
ld [de], a
ld hl, wPartyMonOT
- ld a, [wcc49]
+ ld a, [wMonDataLocation]
and $f
- jr z, .asm_f315
+ jr z, .next2
ld hl, wEnemyMonOT
-.asm_f315
- ld a, [$ffe4]
+.next2
+ ld a, [hNewPartyLength]
dec a
call SkipFixedLengthTextEntries
ld d, h
@@ -3590,24 +3594,24 @@
ld hl, wPlayerName
ld bc, $b
call CopyData
- ld a, [wcc49]
+ ld a, [wMonDataLocation]
and a
- jr nz, .asm_f33f
+ jr nz, .skipNaming
ld hl, wPartyMonNicks
- ld a, [$ffe4]
+ ld a, [hNewPartyLength]
dec a
call SkipFixedLengthTextEntries
ld a, NAME_MON_SCREEN
ld [wNamingScreenType], a
predef AskName
-.asm_f33f
+.skipNaming
ld hl, wPartyMons
- ld a, [wcc49]
+ ld a, [wMonDataLocation]
and $f
- jr z, .asm_f34c
+ jr z, .next3
ld hl, wEnemyMons
-.asm_f34c
- ld a, [$ffe4]
+.next3
+ ld a, [hNewPartyLength]
dec a
ld bc, wPartyMon2 - wPartyMon1
call AddNTimes
@@ -3619,15 +3623,17 @@
call GetMonHeader
ld hl, W_MONHEADER
ld a, [hli]
- ld [de], a
+ ld [de], a ; species
inc de
pop hl
push hl
- ld a, [wcc49]
+ ld a, [wMonDataLocation]
and $f
ld a, $98 ; set enemy trainer mon IVs to fixed average values
ld b, $88
- jr nz, .writeFreshMonData
+ jr nz, .next4
+
+; If the mon is being added to the player's party, update the pokedex.
ld a, [wcf91]
ld [wd11e], a
push de
@@ -3650,24 +3656,29 @@
pop bc
ld hl, wPokedexSeen
call FlagAction
+
pop hl
push hl
+
ld a, [W_ISINBATTLE]
- and a
+ and a ; is this a wild mon caught in battle?
jr nz, .copyEnemyMonData
+
+; Not wild.
call Random ; generate random IVs
ld b, a
call Random
-.writeFreshMonData ; f3b3
+
+.next4
push bc
- ld bc, $1b
+ ld bc, wPartyMon1DVs - wPartyMon1
add hl, bc
pop bc
ld [hli], a
ld [hl], b ; write IVs
- ld bc, $fff4
+ ld bc, (wPartyMon1HPExp - 1) - (wPartyMon1DVs + 1)
add hl, bc
- ld a, $1
+ ld a, 1
ld c, a
xor a
ld b, a
@@ -3679,13 +3690,13 @@
ld [de], a
inc de
xor a
- ld [de], a ; level (?)
+ ld [de], a ; box level
inc de
ld [de], a ; status ailments
inc de
jr .copyMonTypesAndMoves
.copyEnemyMonData
- ld bc, $1b
+ ld bc, wPartyMon1DVs - wPartyMon1
add hl, bc
ld a, [wEnemyMonDVs] ; copy IVs from cur enemy mon
ld [hli], a
@@ -3698,7 +3709,7 @@
ld [de], a
inc de
xor a
- ld [de], a ; level (?)
+ ld [de], a ; box level
inc de
ld a, [wEnemyMonStatus] ; copy status ailments from cur enemy mon
ld [de], a
@@ -3711,7 +3722,7 @@
ld a, [hli] ; type 2
ld [de], a
inc de
- ld a, [hli] ; unused (?)
+ ld a, [hli] ; catch rate (held item in gen 2)
ld [de], a
ld hl, W_MONHMOVES
ld a, [hli]
@@ -4035,7 +4046,7 @@
push hl
srl a
add $2
- ld [wcc49], a
+ ld [wMonDataLocation], a
call LoadMonData
callba CalcLevelFromExperience
ld a, d
@@ -4477,7 +4488,7 @@
inc hl
ld [hl], a
- ld [wcc49], a
+ ld [wMonDataLocation], a
ld hl, W_OBTAINEDBADGES
ld [hli], a
--- a/scripts/daycarem.asm
+++ b/scripts/daycarem.asm
@@ -35,11 +35,11 @@
pop af
ld hl, DayCareMText_56437
jp c, DayCareMScript_56409
- callab Func_2171b
+ callab KnowsHMMove
ld hl, DayCareMText_5644a
jp c, DayCareMScript_56409
xor a
- ld [wcc2b], a
+ ld [wPartyAndBillsPCSavedMenuItem], a
ld a, [wWhichPokemon]
ld hl, wPartyMonNicks
call GetPartyMonName
@@ -62,8 +62,8 @@
xor a
ld hl, W_DAYCAREMONNAME
call GetPartyMonName
- ld a, $3
- ld [wcc49], a
+ ld a, DAYCARE_DATA
+ ld [wMonDataLocation], a
call LoadMonData
callab CalcLevelFromExperience
ld a, d
--- a/scripts/oakslab.asm
+++ b/scripts/oakslab.asm
@@ -898,9 +898,9 @@
call PrintText
ld hl, OaksLabReceivedMonText
call PrintText
- xor a
- ld [wcc49], a
- ld a, $5
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation], a
+ ld a, 5
ld [W_CURENEMYLVL], a
ld a, [wcf91]
ld [wd11e], a
--- a/text.asm
+++ b/text.asm
@@ -1816,7 +1816,7 @@
TX_RAM wcf4b
text " was"
line "stored in Box @"
- TX_RAM wWhichTrade
+ TX_RAM wBoxNumString
text "."
prompt
--- a/wram.asm
+++ b/wram.asm
@@ -236,15 +236,32 @@
; id of previously selected menu item
ds 1
-; group these 3 addresses together because of an ld a,[hli]
-wcc2b:: ds 1 ; used in party menu
-wcc2c:: ds 1 ; used in item related menus (inventory, pc)
-wcc2d:: ds 1 ; also used in inventory, supposed to save an item id
+wPartyAndBillsPCSavedMenuItem:: ; cc2b
+; It is mainly used by the party menu to remember the cursor position while the
+; menu isn't active.
+; It is also used to remember the cursor position of mon lists (for the
+; withdraw/deposit/release actions) in Bill's PC so that it doesn't get lost
+; when you choose a mon from the list and a sub-menu is shown. It's reset when
+; you return to the main Bill's PC menu.
+ ds 1
+wBagSavedMenuItem:: ; cc2c
+; It is used by the bag list to remember the cursor position while the menu
+; isn't active.
+ ds 1
+
+wBattleAndStartSavedMenuItem:: ; cc2d
+; It is used by the start menu to remember the cursor position while the menu
+; isn't active.
+; The battle menu uses it so that the cursor position doesn't get lost when
+; a sub-menu is shown. It's reset at the start of each battle.
+ ds 1
+
wPlayerMoveListIndex:: ; cc2e
ds 1
wPlayerMonNumber:: ; cc2f
+; index in party of currently battling mon
ds 1
wMenuCursorLocation:: ; cc30
@@ -326,7 +343,17 @@
; $00 = player mons
; $01 = enemy mons
-wcc49:: ds 1 ; used in some pokemon related stuff (some kind of species storage byte)
+wMonDataLocation:: ; cc49
+; 0 = player's party
+; 1 = enemy party
+; 2 = current box
+; 3 = daycare
+; 4 = in-battle mon
+;
+; AddPartyMon uses it slightly differently.
+; If the lower nybble is 0, the mon is added to the player's party, else the enemy's.
+; If the entire value is 0, then the player is allowed to name the mon.
+ ds 1
wMenuWrappingEnabled:: ; cc4a
; set to 1 if you can go from the bottom to the top or top to bottom of a menu
@@ -402,6 +429,8 @@
; the list starts above this address and extends downwards in memory until here
; overloaded with below labels
+wParentMenuItem:: ; ccd3
+
wccd3:: ds 1 ; used in battle, pokemon, PC and game corner stuff
wForceEvolution::
wccd4:: ds 1 ; has a direct reference for simulated joypad stuff in vermillion and seafoam
@@ -605,6 +634,18 @@
ds 1
+wChargeMoveNum:: ; cd3d
+
+wCoordIndex:: ; cd3d
+
+wOptionsTextSpeedCursorX:: ; cd3d
+
+wBoxNumString:: ; cd3d
+
+wTrainerInfoTextBoxWidthPlus1:: ; cd3d
+
+wSwappedMenuItem:: ; cd3d
+
wHoFMonSpecies:: ; cd3d
wFieldMoves:: ; cd3d
@@ -648,6 +689,10 @@
wTrainerSpriteOffset:: ; cd3d
ds 1
+wOptionsBattleAnimCursorX:: ; cd3e
+
+wTrainerInfoTextBoxWidth:: ; cd3e
+
wHoFPartyMonIndex:: ; cd3e
wNumCreditsMonsDisplayed:: ; cd3e
@@ -676,6 +721,10 @@
wTrainerEngageDistance:: ; cd3e
ds 1
+wOptionsBattleStyleCursorX:: ; cd3f
+
+wTrainerInfoTextBoxNextRowOffset:: ; cd3f
+
wHoFMonLevel:: ; cd3f
wBadgeOrFaceTiles:: ; cd3f
@@ -850,6 +899,7 @@
wFlags_0xcd60:: ; cd60
; bit 0: is player engaged by trainer (to avoid being engaged by multiple trainers simultaneously)
; bit 1: boulder dust animation (from using Strength) pending
+; bit 3: using generic PC
; bit 5: don't play sound when A or B is pressed in menu
; bit 6: tried pushing against boulder once (you need to push twice before it will move)
ds 1
@@ -1976,7 +2026,8 @@
ds 50 * 2
ds 1 ; end
-wd5a0:: ds 2 ; current box number
+wCurrentBoxNum:: ; d5a0
+ ds 2
wNumHoFTeams:: ; d5a2
; number of HOF teams