summaryrefslogtreecommitdiff
path: root/engine/menu
diff options
context:
space:
mode:
Diffstat (limited to 'engine/menu')
-rw-r--r--engine/menu/bills_pc.asm456
-rwxr-xr-xengine/menu/diploma.asm60
-rw-r--r--engine/menu/draw_badges.asm120
-rw-r--r--engine/menu/draw_start_menu.asm89
-rwxr-xr-xengine/menu/league_pc.asm78
-rwxr-xr-xengine/menu/main_menu.asm364
-rwxr-xr-xengine/menu/naming_screen.asm437
-rwxr-xr-xengine/menu/oaks_pc.asm17
-rwxr-xr-xengine/menu/party_menu.asm92
-rwxr-xr-xengine/menu/pc.asm101
-rwxr-xr-xengine/menu/players_pc.asm214
-rwxr-xr-xengine/menu/pokedex.asm243
-rwxr-xr-xengine/menu/prize_menu.asm232
-rwxr-xr-xengine/menu/start_menu.asm25
-rwxr-xr-xengine/menu/start_sub_menus.asm309
-rwxr-xr-xengine/menu/status_screen.asm306
-rw-r--r--engine/menu/swap_items.asm149
-rw-r--r--engine/menu/text_box.asm767
-rwxr-xr-xengine/menu/vending_machine.asm93
19 files changed, 2665 insertions, 1487 deletions
diff --git a/engine/menu/bills_pc.asm b/engine/menu/bills_pc.asm
index 61e6204e..85a546e1 100644
--- a/engine/menu/bills_pc.asm
+++ b/engine/menu/bills_pc.asm
@@ -1,90 +1,87 @@
-Func_213c8:: ; 213c8 (8:53c8)
+DisplayPCMainMenu::
xor a
ld [H_AUTOBGTRANSFERENABLED], a
call SaveScreenTilesToBuffer2
- ld a, [wd5a2]
+ ld a, [wNumHoFTeams]
and a
- jr nz, .asm_213f3
- ld a, [wd74b]
- bit 5, a
- jr z, .asm_213ea
- ld a, [wd5a2]
+ jr nz, .leaguePCAvailable
+ CheckEvent EVENT_GOT_POKEDEX
+ jr z, .noOaksPC
+ ld a, [wNumHoFTeams]
and a
- jr nz, .asm_213f3
- ld hl, wTileMap
- ld b, $8
- ld c, $e
- jr .asm_213fa
-.asm_213ea
- ld hl, wTileMap
- ld b, $6
- ld c, $e
- jr .asm_213fa
-.asm_213f3
- ld hl, wTileMap
- ld b, $a
- ld c, $e
-.asm_213fa
+ jr nz, .leaguePCAvailable
+ coord hl, 0, 0
+ ld b, 8
+ ld c, 14
+ jr .next
+.noOaksPC
+ coord hl, 0, 0
+ ld b, 6
+ ld c, 14
+ jr .next
+.leaguePCAvailable
+ coord hl, 0, 0
+ 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
- hlCoord 2, 2
+ CheckEvent EVENT_MET_BILL
+ jr nz, .metBill
+ coord hl, 2, 2
ld de, SomeonesPCText
- jr .asm_2141a
-.asm_21414
- hlCoord 2, 2
+ jr .next2
+.metBill
+ coord hl, 2, 2
ld de, BillsPCText
-.asm_2141a
+.next2
call PlaceString
- hlCoord 2, 4
+ coord hl, 2, 4
ld de, wPlayerName
call PlaceString
ld l, c
ld h, b
ld de, PlayersPCText
call PlaceString
- ld a, [wd74b]
- bit 5, a
- jr z, .asm_21462
- hlCoord 2, 6
+ CheckEvent EVENT_GOT_POKEDEX
+ jr z, .noOaksPC2
+ coord hl, 2, 6
ld de, OaksPCText
call PlaceString
- ld a, [wd5a2]
+ ld a, [wNumHoFTeams]
and a
- jr z, .asm_2145a
- ld a, $4
+ jr z, .noLeaguePC
+ ld a, 4
ld [wMaxMenuItem], a
- hlCoord 2, 8
+ coord hl, 2, 8
ld de, PKMNLeaguePCText
call PlaceString
- hlCoord 2, 10
+ coord hl, 2, 10
ld de, LogOffPCText
- jr .asm_2146d
-.asm_2145a
- hlCoord 2, 8
+ jr .next3
+.noLeaguePC
+ coord hl, 2, 8
ld de, LogOffPCText
- jr .asm_2146d
-.asm_21462
+ jr .next3
+.noOaksPC2
ld a, $2
ld [wMaxMenuItem], a
- hlCoord 2, 6
+ coord hl, 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
@@ -95,107 +92,109 @@ OaksPCText: db "PROF.OAK's PC@"
PKMNLeaguePCText: db $4a, "LEAGUE@"
LogOffPCText: db "LOG OFF@"
-BillsPC_:: ; 0x214c2
+BillsPC_::
ld hl, wd730
set 6, [hl]
xor a
- ld [wccd3], a
+ ld [wParentMenuItem], a
inc a ; MONSTER_NAME
ld [wNameListType], a
call LoadHpBarAndStatusTilePatterns
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]
+ ld a, [wParentMenuItem]
ld [wCurrentMenuItem], a
ld hl, vChars2 + $780
ld de, PokeballTileGraphics
- ld bc, (BANK(PokeballTileGraphics) << 8) + $01
+ lb bc, BANK(PokeballTileGraphics), $01
call CopyVideoData
call LoadScreenTilesFromBuffer2DisableBGTransfer
- ld hl, wTileMap
- ld b, $a
- ld c, $c
+ coord hl, 0, 0
+ ld b, 10
+ ld c, 12
call TextBoxBorder
- hlCoord 2, 2
+ coord hl, 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
+ coord hl, 9, 14
+ 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
+ coord hl, 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
+ coord hl, 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:
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,166 +204,164 @@ Func_21588: ; 21588 (8:5588)
res 6, [hl]
ret
-Func_215ac: ; 215ac (8:55ac)
BillsPCDeposit:
ld a, [wPartyCount]
dec a
- jr nz, .asm_215bb
+ jr nz, .partyLargeEnough
ld hl, CantDepositLastMonText
call PrintText
jp BillsPCMenu
-.asm_215bb
- ld a, [W_NUMINBOX]
+.partyLargeEnough
+ ld a, [wNumInBox]
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
call PlaySoundWaitForCurrent
- ld a, $1
- ld [wcf95], a
- call Func_3a68
+ ld a, PARTY_TO_BOX
+ ld [wMoveMonType], a
+ call MoveMon
xor a
- ld [wcf95], a
+ 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], "@"
ld hl, MonWasStoredText
call PrintText
jp BillsPCMenu
-Func_21618: ; 21618 (8:5618)
- ld a, [W_NUMINBOX]
+BillsPCWithdraw:
+ ld a, [wNumInBox]
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
- ld hl, W_NUMINBOX
- call Func_216be
- jp c, Func_214e8
- call Func_2174b
- jp nc, Func_214e8
+ jp BillsPCMenu
+.partyNotFull
+ ld hl, wNumInBox
+ call DisplayMonListMenu
+ jp c, BillsPCMenu
+ call DisplayDepositWithdrawMenu
+ jp nc, BillsPCMenu
ld a, [wWhichPokemon]
ld hl, wBoxMonNicks
call GetPartyMonName
ld a, [wcf91]
call GetCryData
call PlaySoundWaitForCurrent
- xor a
- ld [wcf95], a
- call Func_3a68
- ld a, $1
- ld [wcf95], a
+ xor a ; BOX_TO_PARTY
+ ld [wMoveMonType], a
+ call MoveMon
+ ld a, 1
+ ld [wRemoveMonFromBox], a
call RemovePokemon
call WaitForSoundToFinish
ld hl, MonIsTakenOutText
call PrintText
- jp Func_214e8
+ jp BillsPCMenu
-Func_21673: ; 21673 (8:5673)
- ld a, [W_NUMINBOX]
+BillsPCRelease:
+ ld a, [wNumInBox]
and a
- jr nz, .asm_21682
+ jr nz, .loop
ld hl, NoMonText
call PrintText
- jp Func_214e8
-.asm_21682
- ld hl, W_NUMINBOX
- call Func_216be
- jp c, Func_214e8
+ jp BillsPCMenu
+.loop
+ ld hl, wNumInBox
+ 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 [wcf95], a
+ ld [wRemoveMonFromBox], a
call RemovePokemon
call WaitForSoundToFinish
ld a, [wcf91]
call PlayCry
ld hl, MonWasReleasedText
call PrintText
- jp Func_214e8
+ jp BillsPCMenu
-Func_216b3: ; 216b3 (8:56b3)
+BillsPCChangeBox:
callba ChangeBox
- jp Func_214e8
+ jp BillsPCMenu
-Func_216be: ; 216be (8:56be)
+DisplayMonListMenu:
ld a, l
- ld [wList], a
+ ld [wListPointer], a
ld a, h
- ld [wList + 1], a
+ ld [wListPointer + 1], a
xor a
- ld [wcf93], a
+ ld [wPrintItemPrices], a
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)
+BillsPCMenuText:
db "WITHDRAW ", $4a
next "DEPOSIT ", $4a
next "RELEASE ", $4a
next "CHANGE BOX"
-IF DEF(_YELLOW)
- next "PRINT BOX"
-ENDC
next "SEE YA!"
db "@"
-BoxNoPCText: ; 21713 (8:5713)
+BoxNoPCText:
db "BOX No.@"
-Func_2171b:: ; 2171b (8:571b)
+KnowsHMMove::
+; returns whether mon with party index [wWhichPokemon] knows an HM move
ld hl, wPartyMon1Moves
ld bc, wPartyMon2 - wPartyMon1
- jr .asm_21729 ; 0x21721 $6
+ 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,11 +372,11 @@ Func_2171b:: ; 2171b (8:571b)
pop hl
ret c
dec b
- jr nz, .asm_21731 ; 0x21741 $ee
+ jr nz, .loop
and a
ret
-HMMoveArray: ; 21745 (8:5745)
+HMMoveArray:
db CUT
db FLY
db SURF
@@ -387,72 +384,72 @@ HMMoveArray: ; 21745 (8:5745)
db FLASH
db -1
-Func_2174b: ; 2174b (8:574b)
- hlCoord 9, 10
- ld b, $6
- ld c, $9
+DisplayDepositWithdrawMenu:
+ coord hl, 9, 10
+ 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
- hlCoord 11, 12
+.next
+ coord hl, 11, 12
call PlaceString
- hlCoord 11, 14
+ coord hl, 11, 14
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
call ReloadTilesetTilePatterns
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
call LoadGBPal
- jr .asm_2178f
+ jr .loop
DepositPCText: db "DEPOSIT@"
WithdrawPCText: db "WITHDRAW@"
@@ -460,91 +457,89 @@ StatsCancelPCText:
db "STATS"
next "CANCEL@"
-SwitchOnText: ; 0x217e9
+SwitchOnText:
TX_FAR _SwitchOnText
db "@"
-WhatText: ; 0x217ee
+WhatText:
TX_FAR _WhatText
db "@"
-DepositWhichMonText: ; 0x217f3
+DepositWhichMonText:
TX_FAR _DepositWhichMonText
db "@"
-MonWasStoredText: ; 0x217f8
+MonWasStoredText:
TX_FAR _MonWasStoredText
db "@"
-CantDepositLastMonText: ; 0x217fd
+CantDepositLastMonText:
TX_FAR _CantDepositLastMonText
db "@"
-BoxFullText: ; 0x21802
+BoxFullText:
TX_FAR _BoxFullText
db "@"
-MonIsTakenOutText: ; 0x21807
+MonIsTakenOutText:
TX_FAR _MonIsTakenOutText
db "@"
-NoMonText: ; 0x2180c
+NoMonText:
TX_FAR _NoMonText
db "@"
-CantTakeMonText: ; 0x21811
+CantTakeMonText:
TX_FAR _CantTakeMonText
db "@"
-ReleaseWhichMonText: ; 0x21816
+ReleaseWhichMonText:
TX_FAR _ReleaseWhichMonText
db "@"
-OnceReleasedText: ; 0x2181b
+OnceReleasedText:
TX_FAR _OnceReleasedText
db "@"
-MonWasReleasedText: ; 0x21820
+MonWasReleasedText:
TX_FAR _MonWasReleasedText
db "@"
-CableClubLeftGameboy:: ; 5824 (8:5825)
+CableClubLeftGameboy::
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
ret z
ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
cp SPRITE_FACING_RIGHT
ret nz
- ld a, [W_CURMAP]
- cp BATTLE_CENTER
+ ld a, [wCurMap]
+ cp TRADE_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
- ld a, $22 ; JustAMomentText
- jp PrintPredefTextID
+ tx_pre_jump JustAMomentText
-CableClubRightGameboy:: ; 5845 (8:5845)
+CableClubRightGameboy::
ld a, [hSerialConnectionStatus]
cp USING_INTERNAL_CLOCK
ret z
ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
cp SPRITE_FACING_LEFT
ret nz
- ld a, [W_CURMAP]
- cp BATTLE_CENTER
+ ld a, [wCurMap]
+ cp TRADE_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
- ld a, $22 ; JustAMomentText
- jp PrintPredefTextID
+ tx_pre_jump JustAMomentText
-JustAMomentText:: ; 21865 (8:5865)
+JustAMomentText::
TX_FAR _JustAMomentText
db "@"
@@ -552,9 +547,8 @@ JustAMomentText:: ; 21865 (8:5865)
cp SPRITE_FACING_UP
ret nz
call EnableAutoTextBoxDrawing
- ld a, $23
- jp PrintPredefTextID
+ tx_pre_jump OpenBillsPCText
-PredefText23:: ; 21878 (8:5878)
+OpenBillsPCText::
db $FD ; FuncTX_BillsPC
diff --git a/engine/menu/diploma.asm b/engine/menu/diploma.asm
index 1624ed70..09ba123e 100755
--- a/engine/menu/diploma.asm
+++ b/engine/menu/diploma.asm
@@ -1,4 +1,4 @@
-DisplayDiploma: ; 566e2 (15:66e2)
+DisplayDiploma:
call SaveScreenTilesToBuffer2
call GBPalWhiteOutWithDelay3
call ClearScreen
@@ -7,15 +7,15 @@ DisplayDiploma: ; 566e2 (15:66e2)
ld hl, wd730
set 6, [hl]
call DisableLCD
- ld hl, CircleTile ; $7d88
+ ld hl, CircleTile
ld de, vChars2 + $700
ld bc, $0010
ld a, BANK(CircleTile)
call FarCopyData2
- ld hl, wTileMap
- ld bc, $1012
+ coord hl, 0, 0
+ lb bc, 16, 18
predef Diploma_TextBoxBorder
- ld hl, DiplomaTextPointersAndCoords ; $6784
+ ld hl, DiplomaTextPointersAndCoords
ld c, $5
.asm_56715
push bc
@@ -32,31 +32,35 @@ DisplayDiploma: ; 566e2 (15:66e2)
inc hl
pop bc
dec c
- jr nz, .asm_56715 ; 0x56725 $ee
- hlCoord 10, 4
+ jr nz, .asm_56715
+ coord hl, 10, 4
ld de, wPlayerName
call PlaceString
- callba Func_44dd
+ callba DrawPlayerCharacter
+
+; Move the player 33 pixels right and set the priority bit so he appears
+; behind the background layer.
ld hl, wOAMBuffer + $01
- ld bc, $8028
-.asm_5673e
- ld a, [hl]
- add $21
+ lb bc, $80, $28
+.adjustPlayerGfxLoop
+ ld a, [hl] ; X
+ add 33
ld [hli], a
inc hl
ld a, b
- ld [hli], a
+ ld [hli], a ; attributes
inc hl
dec c
- jr nz, .asm_5673e ; 0x56747 $f5
+ jr nz, .adjustPlayerGfxLoop
+
call EnableLCD
callba LoadTrainerInfoTextBoxTiles
- ld b, $8
- call GoPAL_SET
+ ld b, SET_PAL_GENERIC
+ call RunPaletteCommand
call Delay3
call GBPalNormal
ld a, $90
- ld [$ff48], a
+ ld [rOBP0], a
call WaitForTextScrollButtonPress
ld hl, wd730
res 6, [hl]
@@ -65,27 +69,29 @@ DisplayDiploma: ; 566e2 (15:66e2)
call Delay3
jp GBPalNormal
-Func_56777: ; 56777 (15:6777)
+UnusedPlayerNameLengthFunc:
+; Unused function that does a calculation involving the length of the player's
+; name.
ld hl, wPlayerName
ld bc, $ff00
-.asm_5677d
+.loop
ld a, [hli]
- cp $50
+ cp "@"
ret z
dec c
- jr .asm_5677d ; 0x56782 $f9
+ jr .loop
-DiplomaTextPointersAndCoords: ; 56784 (15:6784)
+DiplomaTextPointersAndCoords:
dw DiplomaText
- dw wTileMap + $2d
+ dwCoord 5, 2
dw DiplomaPlayer
- dw wTileMap + $53
+ dwCoord 3, 4
dw DiplomaEmptyText
- dw wTileMap + $5f
+ dwCoord 15, 4
dw DiplomaCongrats
- dw wTileMap + $7a
+ dwCoord 2, 6
dw DiplomaGameFreak
- dw wTileMap + $149
+ dwCoord 9, 16
DiplomaText:
db $70,"Diploma",$70,"@"
diff --git a/engine/menu/draw_badges.asm b/engine/menu/draw_badges.asm
new file mode 100644
index 00000000..9e6262a0
--- /dev/null
+++ b/engine/menu/draw_badges.asm
@@ -0,0 +1,120 @@
+DrawBadges:
+; Draw 4x2 gym leader faces, with the faces replaced by
+; badges if they are owned. Used in the player status screen.
+
+; In Japanese versions, names are displayed above faces.
+; Instead of removing relevant code, the name graphics were erased.
+
+; Tile ids for face/badge graphics.
+ ld de, wBadgeOrFaceTiles
+ ld hl, .FaceBadgeTiles
+ ld bc, 8
+ call CopyData
+
+; Booleans for each badge.
+ ld hl, wTempObtainedBadgesBooleans
+ ld bc, 8
+ xor a
+ call FillMemory
+
+; Alter these based on owned badges.
+ ld de, wTempObtainedBadgesBooleans
+ ld hl, wBadgeOrFaceTiles
+ ld a, [wObtainedBadges]
+ ld b, a
+ ld c, 8
+.CheckBadge
+ srl b
+ jr nc, .NextBadge
+ ld a, [hl]
+ add 4 ; Badge graphics are after each face
+ ld [hl], a
+ ld a, 1
+ ld [de], a
+.NextBadge
+ inc hl
+ inc de
+ dec c
+ jr nz, .CheckBadge
+
+; Draw two rows of badges.
+ ld hl, wBadgeNumberTile
+ ld a, $d8 ; [1]
+ ld [hli], a
+ ld [hl], $60 ; First name
+
+ coord hl, 2, 11
+ ld de, wTempObtainedBadgesBooleans
+ call .DrawBadgeRow
+
+ coord hl, 2, 14
+ ld de, wTempObtainedBadgesBooleans + 4
+; call .DrawBadgeRow
+; ret
+
+.DrawBadgeRow
+; Draw 4 badges.
+
+ ld c, 4
+.DrawBadge
+ push de
+ push hl
+
+; Badge no.
+ ld a, [wBadgeNumberTile]
+ ld [hli], a
+ inc a
+ ld [wBadgeNumberTile], a
+
+; Names aren't printed if the badge is owned.
+ ld a, [de]
+ and a
+ ld a, [wBadgeNameTile]
+ jr nz, .SkipName
+ call .PlaceTiles
+ jr .PlaceBadge
+
+.SkipName
+ inc a
+ inc a
+ inc hl
+
+.PlaceBadge
+ ld [wBadgeNameTile], a
+ ld de, SCREEN_WIDTH - 1
+ add hl, de
+ ld a, [wBadgeOrFaceTiles]
+ call .PlaceTiles
+ add hl, de
+ call .PlaceTiles
+
+; Shift badge array back one byte.
+ push bc
+ ld hl, wBadgeOrFaceTiles + 1
+ ld de, wBadgeOrFaceTiles
+ ld bc, 8
+ call CopyData
+ pop bc
+
+ pop hl
+ ld de, 4
+ add hl, de
+
+ pop de
+ inc de
+ dec c
+ jr nz, .DrawBadge
+ ret
+
+.PlaceTiles
+ ld [hli], a
+ inc a
+ ld [hl], a
+ inc a
+ ret
+
+.FaceBadgeTiles
+ db $20, $28, $30, $38, $40, $48, $50, $58
+
+GymLeaderFaceAndBadgeTileGraphics:
+ INCBIN "gfx/badges.2bpp"
diff --git a/engine/menu/draw_start_menu.asm b/engine/menu/draw_start_menu.asm
new file mode 100644
index 00000000..4df9de27
--- /dev/null
+++ b/engine/menu/draw_start_menu.asm
@@ -0,0 +1,89 @@
+; function that displays the start menu
+DrawStartMenu:
+ CheckEvent EVENT_GOT_POKEDEX
+; menu with pokedex
+ coord hl, 10, 0
+ ld b,$0e
+ ld c,$08
+ jr nz,.drawTextBoxBorder
+; shorter menu if the player doesn't have the pokedex
+ coord hl, 10, 0
+ ld b,$0c
+ ld c,$08
+.drawTextBoxBorder
+ call TextBoxBorder
+ ld a,D_DOWN | D_UP | START | B_BUTTON | A_BUTTON
+ ld [wMenuWatchedKeys],a
+ ld a,$02
+ ld [wTopMenuItemY],a ; Y position of first menu choice
+ ld a,$0b
+ ld [wTopMenuItemX],a ; X position of first menu choice
+ ld a,[wBattleAndStartSavedMenuItem] ; remembered menu selection from last time
+ ld [wCurrentMenuItem],a
+ ld [wLastMenuItem],a
+ xor a
+ ld [wMenuWatchMovingOutOfBounds],a
+ ld hl,wd730
+ set 6,[hl] ; no pauses between printing each letter
+ coord hl, 12, 2
+ CheckEvent EVENT_GOT_POKEDEX
+; case for not having pokdex
+ ld a,$06
+ jr z,.storeMenuItemCount
+; case for having pokedex
+ ld de,StartMenuPokedexText
+ call PrintStartMenuItem
+ ld a,$07
+.storeMenuItemCount
+ ld [wMaxMenuItem],a ; number of menu items
+ ld de,StartMenuPokemonText
+ call PrintStartMenuItem
+ ld de,StartMenuItemText
+ call PrintStartMenuItem
+ ld de,wPlayerName ; player's name
+ call PrintStartMenuItem
+ ld a,[wd72e]
+ bit 6,a ; is the player using the link feature?
+; case for not using link feature
+ ld de,StartMenuSaveText
+ jr z,.printSaveOrResetText
+; case for using link feature
+ ld de,StartMenuResetText
+.printSaveOrResetText
+ call PrintStartMenuItem
+ ld de,StartMenuOptionText
+ call PrintStartMenuItem
+ ld de,StartMenuExitText
+ call PlaceString
+ ld hl,wd730
+ res 6,[hl] ; turn pauses between printing letters back on
+ ret
+
+StartMenuPokedexText:
+ db "POKéDEX@"
+
+StartMenuPokemonText:
+ db "POKéMON@"
+
+StartMenuItemText:
+ db "ITEM@"
+
+StartMenuSaveText:
+ db "SAVE@"
+
+StartMenuResetText:
+ db "RESET@"
+
+StartMenuExitText:
+ db "EXIT@"
+
+StartMenuOptionText:
+ db "OPTION@"
+
+PrintStartMenuItem:
+ push hl
+ call PlaceString
+ pop hl
+ ld de,SCREEN_WIDTH * 2
+ add hl,de
+ ret
diff --git a/engine/menu/league_pc.asm b/engine/menu/league_pc.asm
index a6dd7021..170c0ef3 100755
--- a/engine/menu/league_pc.asm
+++ b/engine/menu/league_pc.asm
@@ -1,4 +1,4 @@
-PKMNLeaguePC: ; 0x7657e
+PKMNLeaguePC:
ld hl, AccessedHoFPCText
call PrintText
ld hl, wd730
@@ -10,33 +10,35 @@ PKMNLeaguePC: ; 0x7657e
push af
xor a
ld [hTilesetType], a
- ld [W_SPRITEFLIPPED], a
+ ld [wSpriteFlipped], a
ld [wUpdateSpritesEnabled], a
- ld [wTrainerScreenX], a
- ld [wcd42], a
- ld a, [wd5a2]
+ ld [wHoFTeamIndex2], a
+ ld [wHoFTeamNo], a
+ ld a, [wNumHoFTeams]
ld b, a
- cp NUM_HOF_TEAMS + 1
- jr c, .first
- ld b, NUM_HOF_TEAMS
+ cp HOF_TEAM_CAPACITY + 1
+ jr c, .loop
+; If the total number of hall of fame teams is greater than the storage
+; capacity, then calculate the number of the first team that is still recorded.
+ ld b, HOF_TEAM_CAPACITY
sub b
- ld [wcd42], a
-.first
- ld hl, wcd42
+ ld [wHoFTeamNo], a
+.loop
+ ld hl, wHoFTeamNo
inc [hl]
push bc
- ld a, [wTrainerScreenX]
- ld [wWhichTrade], a
+ ld a, [wHoFTeamIndex2]
+ ld [wHoFTeamIndex], a
callba LoadHallOfFameTeams
- call Func_765e5
+ call LeaguePCShowTeam
pop bc
- jr c, .second
- ld hl, wTrainerScreenX
+ jr c, .doneShowingTeams
+ ld hl, wHoFTeamIndex2
inc [hl]
ld a, [hl]
cp b
- jr nz, .first
-.second
+ jr nz, .loop
+.doneShowingTeams
pop af
ld [hTilesetType], a
pop af
@@ -45,14 +47,14 @@ PKMNLeaguePC: ; 0x7657e
res 6, [hl]
call GBPalWhiteOutWithDelay3
call ClearScreen
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
jp GBPalNormal
-Func_765e5: ; 765e5 (1d:65e5)
+LeaguePCShowTeam:
ld c, PARTY_LENGTH
.loop
push bc
- call Func_76610
+ call LeaguePCShowMon
call WaitForTextScrollButtonPress
ld a, [hJoyHeld]
bit 1, a
@@ -75,46 +77,44 @@ Func_765e5: ; 765e5 (1d:65e5)
scf
ret
-Func_76610: ; 76610 (1d:6610)
+LeaguePCShowMon:
call GBPalWhiteOutWithDelay3
call ClearScreen
ld hl, wHallOfFame
ld a, [hli]
- ld [wWhichTrade], a
+ ld [wHoFMonSpecies], a
ld [wcf91], a
ld [wd0b5], a
ld [wBattleMonSpecies2], a
- ld [wcf1d], a
+ ld [wWholeScreenPaletteMonSpecies], a
ld a, [hli]
- ld [wTrainerFacingDirection], a
+ ld [wHoFMonLevel], a
ld de, wcd6d
- ld bc, $000B
+ ld bc, NAME_LENGTH
call CopyData
- ld b, $0B
+ ld b, SET_PAL_POKEMON_WHOLE_SCREEN
ld c, 0
- call GoPAL_SET
- hlCoord 12, 5
+ call RunPaletteCommand
+ coord hl, 12, 5
call GetMonHeader
call LoadFrontSpriteByMonIndex
call GBPalNormal
- hlCoord 0, 13
+ coord hl, 0, 13
ld b, 2
ld c, $12
call TextBoxBorder
- hlCoord 1, 15
+ coord hl, 1, 15
ld de, HallOfFameNoText
call PlaceString
- hlCoord 16, 15
- ld de, wcd42
- ld bc, $0103
+ coord hl, 16, 15
+ ld de, wHoFTeamNo
+ lb bc, 1, 3
call PrintNumber
- ld b, BANK(Func_702f0)
- ld hl, Func_702f0
- jp Bankswitch
+ jpba HoFDisplayMonInfo
-HallOfFameNoText: ; 76670 (1d:6670)
+HallOfFameNoText:
db "HALL OF FAME No @"
-AccessedHoFPCText: ; 76683 (1d:6683)
+AccessedHoFPCText:
TX_FAR _AccessedHoFPCText
db "@"
diff --git a/engine/menu/main_menu.asm b/engine/menu/main_menu.asm
index 756c7755..cd4198b6 100755
--- a/engine/menu/main_menu.asm
+++ b/engine/menu/main_menu.asm
@@ -1,58 +1,58 @@
-MainMenu: ; 5af2 (1:5af2)
+MainMenu:
; Check save file
- call Func_5bff
+ call InitOptions
xor a
- ld [wd08a],a
+ ld [wOptionsInitialized],a
inc a
- ld [wd088],a
- call Func_609e
- jr nc,.next0
+ ld [wSaveFileStatus],a
+ call CheckForPlayerNameInSRAM
+ jr nc,.mainMenuLoop
- ; Predef 52 loads the save from SRAM to RAM
predef LoadSAV
-.next0
+.mainMenuLoop
ld c,20
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
ld [hl],a
- ld [W_ANIMATIONID],a
+ ld [wDefaultMap],a
ld hl,wd72e
res 6,[hl]
call ClearScreen
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
call LoadTextBoxTilePatterns
call LoadFontTilePatterns
ld hl,wd730
set 6,[hl]
- ld a,[wd088]
+ ld a,[wSaveFileStatus]
cp a,1
- jr z,.next1
- hlCoord 0, 0
+ jr z,.noSaveFile
+; there's a save file
+ coord hl, 0, 0
ld b,6
ld c,13
call TextBoxBorder
- hlCoord 2, 2
+ coord hl, 2, 2
ld de,ContinueText
call PlaceString
jr .next2
-.next1
- hlCoord 0, 0
+.noSaveFile
+ coord hl, 0, 0
ld b,4
ld c,13
call TextBoxBorder
- hlCoord 2, 2
+ coord hl, 2, 2
ld de,NewGameText
call PlaceString
.next2
ld hl,wd730
res 6,[hl]
- call UpdateSprites ; OAM?
+ call UpdateSprites
xor a
ld [wCurrentMenuItem],a
ld [wLastMenuItem],a
@@ -61,36 +61,38 @@ MainMenu: ; 5af2 (1:5af2)
ld [wTopMenuItemX],a
inc a
ld [wTopMenuItemY],a
- ld a,$B
+ ld a,A_BUTTON | B_BUTTON | START
ld [wMenuWatchedKeys],a
- ld a,[wd088]
+ ld a,[wSaveFileStatus]
ld [wMaxMenuItem],a
call HandleMenuInput
- bit 1,a
- jp nz,LoadTitlescreenGraphics ; load title screen (gfx and arrangement)
+ bit 1,a ; pressed B?
+ jp nz,DisplayTitleScreen ; if so, go back to the title screen
ld c,20
call DelayFrames
ld a,[wCurrentMenuItem]
ld b,a
- ld a,[wd088]
+ ld a,[wSaveFileStatus]
cp a,2
- jp z,.next3
- inc b ; adjust MenuArrow_Counter
-.next3
+ jp z,.skipInc
+; If there's no save file, increment the current menu item so that the numbers
+; are the same whether or not there's a save file.
+ inc b
+.skipInc
ld a,b
and a
- jr z,.next4 ; if press_A on Continue
+ jr z,.choseContinue
cp a,1
- jp z,Func_5d52 ; if press_A on NewGame
- call DisplayOptionMenu ; if press_a on Options
+ jp z,StartNewGame
+ call DisplayOptionMenu
ld a,1
- ld [wd08a],a
- jp .next0
-.next4
- call ContinueGame
- ld hl,wd126
+ ld [wOptionsInitialized],a
+ jp .mainMenuLoop
+.choseContinue
+ call DisplayContinueGameInfo
+ ld hl,wCurrentMapScriptFlags
set 5,[hl]
-.next6
+.inputLoop
xor a
ld [hJoyPressed],a
ld [hJoyReleased],a
@@ -98,21 +100,21 @@ MainMenu: ; 5af2 (1:5af2)
call Joypad
ld a,[hJoyHeld]
bit 0,a
- jr nz,.next5
+ jr nz,.pressedA
bit 1,a
- jp nz,.next0
- jr .next6
-.next5
+ jp nz,.mainMenuLoop ; pressed B
+ jr .inputLoop
+.pressedA
call GBPalWhiteOutWithDelay3
call ClearScreen
- ld a,4
- ld [wd52a],a
+ ld a,PLAYER_DIR_DOWN
+ ld [wPlayerDirection],a
ld c,10
call DelayFrames
- ld a,[wd5a2]
+ ld a,[wNumHoFTeams]
and a
jp z,SpecialEnterMap
- ld a,[W_CURMAP] ; map ID
+ ld a,[wCurMap] ; map ID
cp a,HALL_OF_FAME
jp nz,SpecialEnterMap
xor a
@@ -121,16 +123,17 @@ MainMenu: ; 5af2 (1:5af2)
set 2,[hl] ; fly warp or dungeon warp
call SpecialWarpIn
jp SpecialEnterMap
-Func_5bff: ; 5bff (1:5bff)
- ld a,1
- ld [wd358],a
- ld a,3
- ld [W_OPTIONS],a
+
+InitOptions:
+ ld a,1 ; no delay
+ ld [wLetterPrintingDelayFlags],a
+ ld a,3 ; medium speed
+ ld [wOptions],a
ret
-LinkMenu: ; 5c0a (1:5c0a)
+LinkMenu:
xor a
- ld [wd358], a
+ ld [wLetterPrintingDelayFlags], a
ld hl, wd72e
set 6, [hl]
ld hl, TextTerminator_6b20
@@ -138,16 +141,16 @@ LinkMenu: ; 5c0a (1:5c0a)
call SaveScreenTilesToBuffer1
ld hl, WhereWouldYouLikeText
call PrintText
- hlCoord 5, 5
+ coord hl, 5, 5
ld b, $6
ld c, $d
call TextBoxBorder
call UpdateSprites
- hlCoord 7, 7
- ld de, TradeCenterText
+ coord hl, 7, 7
+ ld de, CableClubOptionsText
call PlaceString
xor a
- ld [wcd37], a
+ ld [wUnusedCD37], a
ld [wd72d], a
ld hl, wTopMenuItemY
ld a, $7
@@ -160,7 +163,8 @@ LinkMenu: ; 5c0a (1:5c0a)
ld a, $2
ld [hli], a
inc a
- ld [hli], a
+ ; ld a, A_BUTTON | B_BUTTON
+ ld [hli], a ; wMenuWatchedKeys
xor a
ld [hl], a
.waitForInputLoop
@@ -208,7 +212,7 @@ LinkMenu: ; 5c0a (1:5c0a)
ld a, b
ld [wLinkMenuSelectionSendBuffer], a
and $3
- ld [wCurrentMenuItem], a ; wCurrentMenuItem
+ ld [wCurrentMenuItem], a
.doneChoosingMenuSelection
ld a, [hSerialConnectionStatus]
cp USING_INTERNAL_CLOCK
@@ -254,28 +258,28 @@ LinkMenu: ; 5c0a (1:5c0a)
ld [wWalkBikeSurfState], a ; start walking
ld a, [wCurrentMenuItem]
and a
- ld a, TRADE_CENTER
+ ld a, COLOSSEUM
jr nz, .next
- ld a, BATTLE_CENTER
+ ld a, TRADE_CENTER
.next
ld [wd72d], a
ld hl, PleaseWaitText
call PrintText
- ld c, $32
+ ld c, 50
call DelayFrames
ld hl, wd732
res 1, [hl]
- ld a, [W_ANIMATIONID]
+ ld a, [wDefaultMap]
ld [wDestinationMap], a
call SpecialWarpIn
- ld c, $14
+ ld c, 20
call DelayFrames
xor a
ld [wMenuJoypadPollCount], a
ld [wSerialExchangeNybbleSendData], a
inc a ; LINK_STATE_IN_CABLE_CLUB
ld [wLinkState], a
- ld [wcc47], a
+ ld [wEnteringCableClub], a
jr SpecialEnterMap
.choseCancel
xor a
@@ -288,27 +292,27 @@ LinkMenu: ; 5c0a (1:5c0a)
res 6, [hl]
ret
-WhereWouldYouLikeText: ; 5d43 (1:5d43)
+WhereWouldYouLikeText:
TX_FAR _WhereWouldYouLikeText
db "@"
-PleaseWaitText: ; 5d48 (1:5d48)
+PleaseWaitText:
TX_FAR _PleaseWaitText
db "@"
-LinkCanceledText: ; 5d4d (1:5d4d)
+LinkCanceledText:
TX_FAR _LinkCanceledText
db "@"
-Func_5d52: ; 5d52 (1:5d52)
+StartNewGame:
ld hl, wd732
res 1, [hl]
call OakSpeech
- ld c, $14
+ ld c, 20
call DelayFrames
; enter map after using a special warp or loading the game from the main menu
-SpecialEnterMap: ; 5d5f (1:5d5f)
+SpecialEnterMap:
xor a
ld [hJoyPressed], a
ld [hJoyHeld], a
@@ -319,144 +323,144 @@ SpecialEnterMap: ; 5d5f (1:5d5f)
call ResetPlayerSpriteData
ld c, 20
call DelayFrames
- ld a, [wcc47]
+ ld a, [wEnteringCableClub]
and a
ret nz
jp EnterMap
-ContinueText: ; 5d7e (1:5d7e)
+ContinueText:
db "CONTINUE", $4e
-NewGameText: ; 5d87 (1:5d87)
- db "NEW GAME", $4e
- db "OPTION@"
+NewGameText:
+ db "NEW GAME"
+ next "OPTION@"
-TradeCenterText: ; 5d97 (1:5d97)
- db "TRADE CENTER", $4e
- db "COLOSSEUM", $4e
- db "CANCEL@"
+CableClubOptionsText:
+ db "TRADE CENTER"
+ next "COLOSSEUM"
+ next "CANCEL@"
-ContinueGame: ; 5db5 (1:5db5)
+DisplayContinueGameInfo:
xor a
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
- hlCoord 4, 7
- ld b, $8
- ld c, $e
+ ld [H_AUTOBGTRANSFERENABLED], a
+ coord hl, 4, 7
+ ld b, 8
+ ld c, 14
call TextBoxBorder
- hlCoord 5, 9
+ coord hl, 5, 9
ld de, SaveScreenInfoText
call PlaceString
- hlCoord 12, 9
- ld de, wPlayerName ; wd158
+ coord hl, 12, 9
+ ld de, wPlayerName
call PlaceString
- hlCoord 17, 11
- call Func_5e2f
- hlCoord 16, 13
- call Func_5e42
- hlCoord 13, 15
- call Func_5e55
- ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
- ld c, $1e
+ coord hl, 17, 11
+ call PrintNumBadges
+ coord hl, 16, 13
+ call PrintNumOwnedMons
+ coord hl, 13, 15
+ call PrintPlayTime
+ ld a, 1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld c, 30
jp DelayFrames
-PrintSaveScreenText: ; 5def (1:5def)
+PrintSaveScreenText:
xor a
ld [H_AUTOBGTRANSFERENABLED], a
- ld hl, wTileMap + $4
+ coord hl, 4, 0
ld b, $8
ld c, $e
call TextBoxBorder
call LoadTextBoxTilePatterns
call UpdateSprites
- ld hl, wTileMap + $2d
+ coord hl, 5, 2
ld de, SaveScreenInfoText
call PlaceString
- ld hl, wTileMap + $34
+ coord hl, 12, 2
ld de, wPlayerName
call PlaceString
- ld hl, wTileMap + $61
- call Func_5e2f
- ld hl, wTileMap + $88
- call Func_5e42
- ld hl, wTileMap + $ad
- call Func_5e55
+ coord hl, 17, 4
+ call PrintNumBadges
+ coord hl, 16, 6
+ call PrintNumOwnedMons
+ coord hl, 13, 8
+ call PrintPlayTime
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
- ld c, $1e
+ ld c, 30
jp DelayFrames
-Func_5e2f: ; 5e2f (1:5e2f)
+PrintNumBadges:
push hl
- ld hl, W_OBTAINEDBADGES
+ ld hl, wObtainedBadges
ld b, $1
call CountSetBits
pop hl
- ld de, wd11e
- ld bc, $102
+ ld de, wNumSetBits
+ lb bc, 1, 2
jp PrintNumber
-Func_5e42: ; 5e42 (1:5e42)
+PrintNumOwnedMons:
push hl
- ld hl, wPokedexOwned ; wPokedexOwned
+ ld hl, wPokedexOwned
ld b, wPokedexOwnedEnd - wPokedexOwned
call CountSetBits
pop hl
- ld de, wd11e
- ld bc, $103
+ ld de, wNumSetBits
+ lb bc, 1, 3
jp PrintNumber
-Func_5e55: ; 5e55 (1:5e55)
- ld de, W_PLAYTIMEHOURS + 1
- ld bc, $103
+PrintPlayTime:
+ ld de, wPlayTimeHours
+ lb bc, 1, 3
call PrintNumber
ld [hl], $6d
inc hl
- ld de, W_PLAYTIMEMINUTES + 1
- ld bc, $8102
+ ld de, wPlayTimeMinutes
+ lb bc, LEADING_ZEROES | 1, 2
jp PrintNumber
-SaveScreenInfoText: ; 5e6a (1:5e6a)
+SaveScreenInfoText:
db "PLAYER"
next "BADGES "
next "#DEX "
next "TIME@"
-DisplayOptionMenu: ; 5e8a (1:5e8a)
- hlCoord 0, 0
+DisplayOptionMenu:
+ coord hl, 0, 0
ld b,3
ld c,18
call TextBoxBorder
- hlCoord 0, 5
+ coord hl, 0, 5
ld b,3
ld c,18
call TextBoxBorder
- hlCoord 0, 10
+ coord hl, 0, 10
ld b,3
ld c,18
call TextBoxBorder
- hlCoord 1, 1
+ coord hl, 1, 1
ld de,TextSpeedOptionText
call PlaceString
- hlCoord 1, 6
+ coord hl, 1, 6
ld de,BattleAnimationOptionText
call PlaceString
- hlCoord 1, 11
+ coord hl, 1, 11
ld de,BattleStyleOptionText
call PlaceString
- hlCoord 2, 16
+ coord hl, 2, 16
ld de,OptionMenuCancelText
call PlaceString
xor a
ld [wCurrentMenuItem],a
ld [wLastMenuItem],a
inc a
- ld [wd358],a
- ld [wTrainerScreenY],a
+ ld [wLetterPrintingDelayFlags],a
+ ld [wUnusedCD40],a
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
@@ -468,7 +472,7 @@ DisplayOptionMenu: ; 5e8a (1:5e8a)
call JoypadLowSensitivity
ld a,[hJoy5]
ld b,a
- and a,%11111011 ; any key besides select pressed?
+ and a,A_BUTTON | B_BUTTON | START | D_RIGHT | D_LEFT | D_UP | D_DOWN ; any key besides select pressed?
jr z,.getJoypadStateLoop
bit 1,b ; B button pressed?
jr nz,.exitMenu
@@ -480,8 +484,8 @@ DisplayOptionMenu: ; 5e8a (1:5e8a)
cp a,16 ; is the cursor on Cancel?
jr nz,.loop
.exitMenu
- ld a,(SFX_02_40 - SFX_Headers_02) / 3
- call PlaySound ; play sound
+ ld a,SFX_PRESS_AB
+ call PlaySound
ret
.eraseOldMenuCursor
ld [wTopMenuItemX],a
@@ -506,7 +510,7 @@ DisplayOptionMenu: ; 5e8a (1:5e8a)
.downPressed
cp a,16
ld b,-13
- ld hl,wWhichTrade
+ ld hl,wOptionsTextSpeedCursorX
jr z,.updateMenuVariables
ld b,5
cp a,3
@@ -521,7 +525,7 @@ DisplayOptionMenu: ; 5e8a (1:5e8a)
.upPressed
cp a,8
ld b,-5
- ld hl,wWhichTrade
+ ld hl,wOptionsTextSpeedCursorX
jr z,.updateMenuVariables
cp a,13
inc hl
@@ -540,17 +544,17 @@ DisplayOptionMenu: ; 5e8a (1:5e8a)
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
@@ -561,7 +565,7 @@ DisplayOptionMenu: ; 5e8a (1:5e8a)
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
@@ -571,28 +575,28 @@ DisplayOptionMenu: ; 5e8a (1:5e8a)
.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)
+TextSpeedOptionText:
db "TEXT SPEED"
next " FAST MEDIUM SLOW@"
-BattleAnimationOptionText: ; 5fde (1:5fde)
+BattleAnimationOptionText:
db "BATTLE ANIMATION"
next " ON OFF@"
-BattleStyleOptionText: ; 5ffd (1:5ffd)
+BattleStyleOptionText:
db "BATTLE STYLE"
next " SHIFT SET@"
-OptionMenuCancelText: ; 6018 (1:6018)
+OptionMenuCancelText:
db "CANCEL@"
; sets the options variable according to the current placement of the menu cursors in the options menu
-SetOptionsFromCursorPositions: ; 601f (1:601f)
+SetOptionsFromCursorPositions:
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]
@@ -603,7 +607,7 @@ SetOptionsFromCursorPositions: ; 601f (1:601f)
.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
@@ -612,7 +616,7 @@ SetOptionsFromCursorPositions: ; 601f (1:601f)
.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
@@ -622,13 +626,13 @@ SetOptionsFromCursorPositions: ; 601f (1:601f)
res 6,d
.storeOptions
ld a,d
- ld [W_OPTIONS],a
+ ld [wOptions],a
ret
; reads the options variable and places menu cursors in the correct positions within the options menu
-SetCursorPositionsFromOptions: ; 604c (1:604c)
+SetCursorPositionsFromOptions:
ld hl,TextSpeedOptionData + 1
- ld a,[W_OPTIONS]
+ ld a,[wOptions]
ld c,a
and a,$3f
push bc
@@ -637,27 +641,27 @@ SetCursorPositionsFromOptions: ; 604c (1:604c)
pop bc
dec hl
ld a,[hl]
- ld [wWhichTrade],a ; text speed cursor X coordinate
- hlCoord 0, 3
+ ld [wOptionsTextSpeedCursorX],a ; text speed cursor X coordinate
+ coord hl, 0, 3
call .placeUnfilledRightArrow
sla c
ld a,1 ; On
jr nc,.storeBattleAnimationCursorX
ld a,10 ; Off
.storeBattleAnimationCursorX
- ld [wTrainerEngageDistance],a ; battle animation cursor X coordinate
- hlCoord 0, 8
+ ld [wOptionsBattleAnimCursorX],a ; battle animation cursor X coordinate
+ coord hl, 0, 8
call .placeUnfilledRightArrow
sla c
ld a,1
jr nc,.storeBattleStyleCursorX
ld a,10
.storeBattleStyleCursorX
- ld [wTrainerFacingDirection],a ; battle style cursor X coordinate
- hlCoord 0, 13
+ ld [wOptionsBattleStyleCursorX],a ; battle style cursor X coordinate
+ coord hl, 0, 13
call .placeUnfilledRightArrow
; cursor in front of Cancel
- hlCoord 0, 16
+ coord hl, 0, 16
ld a,1
.placeUnfilledRightArrow
ld e,a
@@ -670,35 +674,39 @@ SetCursorPositionsFromOptions: ; 604c (1:604c)
; Format:
; 00: X coordinate of menu cursor
; 01: delay after printing a letter (in frames)
-TextSpeedOptionData: ; 6096 (1:6096)
+TextSpeedOptionData:
db 14,5 ; Slow
db 7,3 ; Medium
db 1,1 ; Fast
db 7 ; default X coordinate (Medium)
db $ff ; terminator
-Func_609e: ; 609e (1:609e)
- ld a, $a
- ld [$0], a
+CheckForPlayerNameInSRAM:
+; Check if the player name data in SRAM has a string terminator character
+; (indicating that a name may have been saved there) and return whether it does
+; in carry.
+ ld a, SRAM_ENABLE
+ ld [MBC1SRamEnable], a
ld a, $1
- ld [$6000], a
- ld [$4000], a
- ld b, $b
- ld hl, $a598
-.asm_60b0
+ ld [MBC1SRamBankingMode], a
+ ld [MBC1SRamBank], a
+ ld b, NAME_LENGTH
+ ld hl, sPlayerName
+.loop
ld a, [hli]
- cp $50
- jr z, .asm_60c1
+ cp "@"
+ jr z, .found
dec b
- jr nz, .asm_60b0
+ jr nz, .loop
+; not found
xor a
- ld [$0], a
- ld [$6000], a
+ ld [MBC1SRamEnable], a
+ ld [MBC1SRamBankingMode], a
and a
ret
-.asm_60c1
+.found
xor a
- ld [$0], a
- ld [$6000], a
+ ld [MBC1SRamEnable], a
+ ld [MBC1SRamBankingMode], a
scf
ret
diff --git a/engine/menu/naming_screen.asm b/engine/menu/naming_screen.asm
index df862d69..2628da48 100755
--- a/engine/menu/naming_screen.asm
+++ b/engine/menu/naming_screen.asm
@@ -1,131 +1,131 @@
-AskName: ; 64eb (1:64eb)
+AskName:
call SaveScreenTilesToBuffer1
call GetPredefRegisters
push hl
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
dec a
- ld hl, wTileMap
- ld b, $4
- ld c, $b
- call z, ClearScreenArea ; only if in wild batle
+ coord hl, 0, 0
+ ld b, 4
+ ld c, 11
+ call z, ClearScreenArea ; only if in wild battle
ld a, [wcf91]
ld [wd11e], a
call GetMonName
ld hl, DoYouWantToNicknameText
call PrintText
- hlCoord 14, 7
- ld bc, $80f
+ coord hl, 14, 7
+ lb bc, 8, 15
ld a, TWO_OPTION_MENU
ld [wTextBoxID], a
call DisplayTextBoxID
pop hl
ld a, [wCurrentMenuItem]
and a
- jr nz, .asm_654c
+ jr nz, .declinedNickname
ld a, [wUpdateSpritesEnabled]
push af
xor a
ld [wUpdateSpritesEnabled], a
push hl
- ld a, $2
- ld [wd07d], a
+ ld a, NAME_MON_SCREEN
+ ld [wNamingScreenType], a
call DisplayNamingScreen
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
and a
- jr nz, .asm_653e
+ jr nz, .inBattle
call ReloadMapSpriteTilePatterns
-.asm_653e
+.inBattle
call LoadScreenTilesFromBuffer1
pop hl
pop af
ld [wUpdateSpritesEnabled], a
ld a, [wcf4b]
- cp $50
+ cp "@"
ret nz
-.asm_654c
+.declinedNickname
ld d, h
ld e, l
ld hl, wcd6d
- ld bc, $000b
+ ld bc, NAME_LENGTH
jp CopyData
-DoYouWantToNicknameText: ; 0x6557
+DoYouWantToNicknameText:
TX_FAR _DoYouWantToNicknameText
db "@"
-Func_655c: ; 655c (1:655c)
- ld hl, wHPBarMaxHP
+DisplayNameRaterScreen:
+ ld hl, wBuffer
xor a
ld [wUpdateSpritesEnabled], a
- ld a, $2
- ld [wd07d], a
+ ld a, NAME_MON_SCREEN
+ ld [wNamingScreenType], a
call DisplayNamingScreen
call GBPalWhiteOutWithDelay3
call RestoreScreenTilesAndReloadTilePatterns
call LoadGBPal
ld a, [wcf4b]
- cp $50
- jr z, .asm_6594
+ cp "@"
+ jr z, .playerCancelled
ld hl, wPartyMonNicks
- ld bc, $b
+ ld bc, NAME_LENGTH
ld a, [wWhichPokemon]
call AddNTimes
ld e, l
ld d, h
- ld hl, wHPBarMaxHP
- ld bc, $b
+ ld hl, wBuffer
+ ld bc, NAME_LENGTH
call CopyData
and a
ret
-.asm_6594
+.playerCancelled
scf
ret
-DisplayNamingScreen: ; 6596 (1:6596)
+DisplayNamingScreen:
push hl
ld hl, wd730
set 6, [hl]
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
- hlCoord 0, 4
- ld b, $9
- ld c, $12
+ coord hl, 0, 4
+ ld b, 9
+ ld c, 18
call TextBoxBorder
call PrintNamingText
- ld a, $3
+ ld a, 3
ld [wTopMenuItemY], a
- ld a, $1
+ ld a, 1
ld [wTopMenuItemX], a
ld [wLastMenuItem], a
ld [wCurrentMenuItem], a
ld a, $ff
ld [wMenuWatchedKeys], a
- ld a, $7
+ ld a, 7
ld [wMaxMenuItem], a
- ld a, $50
+ ld a, "@"
ld [wcf4b], a
xor a
- ld hl, wHPBarMaxHP + 1
+ ld hl, wNamingScreenSubmitName
ld [hli], a
ld [hli], a
- ld [wPartyMonAnimCounter], a
-.asm_65ed
+ ld [wAnimCounter], a
+.selectReturnPoint
call PrintAlphabet
call GBPalNormal
-.asm_65f3
- ld a, [wHPBarMaxHP + 1]
+.ABStartReturnPoint
+ ld a, [wNamingScreenSubmitName]
and a
- jr nz, .asm_662d
- call Func_680e
-.asm_65fc
+ jr nz, .submitNickname
+ call PrintNicknameAndUnderscores
+.dPadReturnPoint
call PlaceMenuCursor
-.asm_65ff
+.inputLoop
ld a, [wCurrentMenuItem]
push af
callba AnimatePartyMon_ForceSpeed1
@@ -134,17 +134,17 @@ DisplayNamingScreen: ; 6596 (1:6596)
call JoypadLowSensitivity
ld a, [hJoyPressed]
and a
- jr z, .asm_65ff
- ld hl, .unknownPointerTable_665e
-.asm_661a
+ jr z, .inputLoop
+ ld hl, .namingScreenButtonFunctions
+.checkForPressedButton
sla a
- jr c, .asm_6624
+ jr c, .foundPressedButton
inc hl
inc hl
inc hl
inc hl
- jr .asm_661a
-.asm_6624
+ jr .checkForPressedButton
+.foundPressedButton
ld a, [hli]
ld e, a
ld a, [hli]
@@ -153,272 +153,279 @@ DisplayNamingScreen: ; 6596 (1:6596)
ld h, [hl]
ld l, a
push de
- jp [hl]
-.asm_662d
+ jp hl
+
+.submitNickname
pop de
ld hl, wcf4b
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
call GBPalWhiteOutWithDelay3
call ClearScreen
call ClearSprites
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
call GBPalNormal
xor a
- ld [W_SUBANIMTRANSFORM], a
+ ld [wAnimCounter], a
ld hl, wd730
res 6, [hl]
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
and a
jp z, LoadTextBoxTilePatterns
- ld hl, LoadHudTilePatterns
- ld b, BANK(LoadHudTilePatterns)
- jp Bankswitch
+ jpab LoadHudTilePatterns
-.unknownPointerTable_665e: ; 665e (1:665e)
- dw .asm_65fc
- dw .asm_673e
- dw .asm_65fc
- dw .asm_672c
- dw .asm_65fc
- dw .asm_6718
- dw .asm_65fc
- dw .asm_6702
- dw .asm_65f3
- dw .asm_668c
- dw .asm_65ed
- dw .asm_6683
- dw .asm_65f3
- dw .deleteLetter
- dw .asm_65f3
- dw .asm_6692
+.namingScreenButtonFunctions
+ dw .dPadReturnPoint
+ dw .pressedDown
+ dw .dPadReturnPoint
+ dw .pressedUp
+ dw .dPadReturnPoint
+ dw .pressedLeft
+ dw .dPadReturnPoint
+ dw .pressedRight
+ dw .ABStartReturnPoint
+ dw .pressedStart
+ dw .selectReturnPoint
+ dw .pressedSelect
+ dw .ABStartReturnPoint
+ dw .pressedB
+ dw .ABStartReturnPoint
+ dw .pressedA
-.asm_667e
+.pressedA_changedCase
pop de
- ld de, .asm_65ed ; $65ed
+ ld de, .selectReturnPoint
push de
-.asm_6683
- ld a, [wHPBarOldHP]
+.pressedSelect
+ ld a, [wAlphabetCase]
xor $1
- ld [wHPBarOldHP], a
+ ld [wAlphabetCase], a
ret
-.asm_668c
- ld a, $1
- ld [wHPBarMaxHP + 1], a
+
+.pressedStart
+ ld a, 1
+ ld [wNamingScreenSubmitName], a
ret
-.asm_6692
+
+.pressedA
ld a, [wCurrentMenuItem]
- cp $5
- jr nz, .asm_66a0
+ cp $5 ; "ED" row
+ jr nz, .didNotPressED
ld a, [wTopMenuItemX]
- cp $11
- jr z, .asm_668c
-.asm_66a0
+ cp $11 ; "ED" column
+ jr z, .pressedStart
+.didNotPressED
ld a, [wCurrentMenuItem]
- cp $6
- jr nz, .asm_66ae
+ cp $6 ; case switch row
+ jr nz, .didNotPressCaseSwtich
ld a, [wTopMenuItemX]
- cp $1
- jr z, .asm_667e
-.asm_66ae
+ cp $1 ; case switch column
+ jr z, .pressedA_changedCase
+.didNotPressCaseSwtich
ld hl, wMenuCursorLocation
ld a, [hli]
ld h, [hl]
ld l, a
inc hl
ld a, [hl]
- ld [wHPBarNewHP], a
+ ld [wNamingScreenLetter], a
call CalcStringLength
- ld a, [wHPBarNewHP]
+ ld a, [wNamingScreenLetter]
cp $e5
- ld de, Dakutens ; $6885
- jr z, .asm_66e3
+ ld de, Dakutens
+ jr z, .dakutensAndHandakutens
cp $e4
- ld de, Handakutens ; $68d6
- jr z, .asm_66e3
- ld a, [wd07d]
- cp $2
+ ld de, Handakutens
+ jr z, .dakutensAndHandakutens
+ ld a, [wNamingScreenType]
+ cp NAME_MON_SCREEN
jr nc, .checkMonNameLength
- ld a, [wHPBarMaxHP]
+ ld a, [wNamingScreenNameLength]
cp $7 ; max length of player/rival names
jr .checkNameLength
.checkMonNameLength
- ld a, [wHPBarMaxHP]
+ ld a, [wNamingScreenNameLength]
cp $a ; max length of pokemon nicknames
.checkNameLength
jr c, .addLetter
ret
-.asm_66e3
+
+.dakutensAndHandakutens
push hl
- call Func_6871
+ call DakutensAndHandakutens
pop hl
ret nc
dec hl
.addLetter
- ld a, [wHPBarNewHP]
+ ld a, [wNamingScreenLetter]
ld [hli], a
- ld [hl], $50
- ld a, (SFX_02_40 - SFX_Headers_02) / 3
+ ld [hl], "@"
+ ld a, SFX_PRESS_AB
call PlaySound
ret
-.deleteLetter
- ld a, [wHPBarMaxHP]
+.pressedB
+ ld a, [wNamingScreenNameLength]
and a
ret z
call CalcStringLength
dec hl
- ld [hl], $50
+ ld [hl], "@"
ret
-.asm_6702
+.pressedRight
ld a, [wCurrentMenuItem]
cp $6
- ret z
+ ret z ; can't scroll right on bottom row
ld a, [wTopMenuItemX]
- cp $11
- jp z, .asm_6714
+ cp $11 ; max
+ jp z, .wrapToFirstColumn
inc a
inc a
- jr .asm_6755
-.asm_6714
+ jr .done
+.wrapToFirstColumn
ld a, $1
- jr .asm_6755
-.asm_6718
+ jr .done
+.pressedLeft
ld a, [wCurrentMenuItem]
cp $6
- ret z
+ ret z ; can't scroll right on bottom row
ld a, [wTopMenuItemX]
dec a
- jp z, .asm_6728
+ jp z, .wrapToLastColumn
dec a
- jr .asm_6755
-.asm_6728
- ld a, $11
- jr .asm_6755
-.asm_672c
+ jr .done
+.wrapToLastColumn
+ ld a, $11 ; max
+ jr .done
+.pressedUp
ld a, [wCurrentMenuItem]
dec a
ld [wCurrentMenuItem], a
and a
ret nz
- ld a, $6
+ ld a, $6 ; wrap to bottom row
ld [wCurrentMenuItem], a
- ld a, $1
- jr .asm_6755
-.asm_673e
+ ld a, $1 ; force left column
+ jr .done
+.pressedDown
ld a, [wCurrentMenuItem]
inc a
ld [wCurrentMenuItem], a
cp $7
- jr nz, .asm_6750
+ jr nz, .wrapToTopRow
ld a, $1
ld [wCurrentMenuItem], a
- jr .asm_6755
-.asm_6750
+ jr .done
+.wrapToTopRow
cp $6
ret nz
ld a, $1
-.asm_6755
+.done
ld [wTopMenuItemX], a
jp EraseMenuCursor
-LoadEDTile: ; 675b (1:675b)
+LoadEDTile:
ld de, ED_Tile
ld hl, vFont + $700
- ld bc, $1
+ ld bc, (ED_TileEnd - ED_Tile) / $8
+ ; to fix the graphical bug on poor emulators
+ ;lb bc, BANK(ED_Tile), (ED_TileEnd - ED_Tile) / $8
jp CopyVideoDataDouble
-ED_Tile: ; 6767 (1:6767)
+ED_Tile:
INCBIN "gfx/ED_tile.1bpp"
+ED_TileEnd:
-PrintAlphabet: ; 676f (1:676f)
+PrintAlphabet:
xor a
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
- ld a, [wHPBarOldHP]
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld a, [wAlphabetCase]
and a
- ld de, LowerCaseAlphabet ; $679e
- jr nz, .asm_677e
- ld de, UpperCaseAlphabet ; $67d6
-.asm_677e
- hlCoord 2, 5
- ld bc, $509
-.asm_6784
+ ld de, LowerCaseAlphabet
+ jr nz, .lowercase
+ ld de, UpperCaseAlphabet
+.lowercase
+ coord hl, 2, 5
+ lb bc, 5, 9 ; 5 rows, 9 columns
+.outerLoop
push bc
-.asm_6785
+.innerLoop
ld a, [de]
ld [hli], a
inc hl
inc de
dec c
- jr nz, .asm_6785
- ld bc, $16
+ jr nz, .innerLoop
+ ld bc, SCREEN_WIDTH + 2
add hl, bc
pop bc
dec b
- jr nz, .asm_6784
+ jr nz, .outerLoop
call PlaceString
ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
jp Delay3
-LowerCaseAlphabet: ; 679e (1:679e)
- db "abcdefghijklmnopqrstuvwxyz ×():;[]",$e1,$e2,"-?!♂♀/",$f2,",¥UPPER CASE@"
+LowerCaseAlphabet:
+ db "abcdefghijklmnopqrstuvwxyz ×():;[]",$e1,$e2,"-?!♂♀/⠄,¥UPPER CASE@"
-UpperCaseAlphabet: ; 67d6 (1:67d6)
- db "ABCDEFGHIJKLMNOPQRSTUVWXYZ ×():;[]",$e1,$e2,"-?!♂♀/",$f2,",¥lower case@"
+UpperCaseAlphabet:
+ db "ABCDEFGHIJKLMNOPQRSTUVWXYZ ×():;[]",$e1,$e2,"-?!♂♀/⠄,¥lower case@"
-Func_680e: ; 680e (1:680e)
+PrintNicknameAndUnderscores:
call CalcStringLength
ld a, c
- ld [wHPBarMaxHP], a
- hlCoord 10, 2
- ld bc, $10a
+ ld [wNamingScreenNameLength], a
+ coord hl, 10, 2
+ lb bc, 1, 10
call ClearScreenArea
- hlCoord 10, 2
+ coord hl, 10, 2
ld de, wcf4b
call PlaceString
- hlCoord 10, 3
- ld a, [wd07d]
- cp $2
- jr nc, .asm_6835
- ld b, $7
- jr .asm_6837
-.asm_6835
- ld b, $a
-.asm_6837
- ld a, $76
-.asm_6839
+ coord hl, 10, 3
+ ld a, [wNamingScreenType]
+ cp NAME_MON_SCREEN
+ jr nc, .pokemon1
+ ld b, 7 ; player or rival max name length
+ jr .playerOrRival1
+.pokemon1
+ ld b, 10 ; pokemon max name length
+.playerOrRival1
+ ld a, $76 ; underscore tile id
+.placeUnderscoreLoop
ld [hli], a
dec b
- jr nz, .asm_6839
- ld a, [wd07d]
- cp $2
- ld a, [wHPBarMaxHP]
- jr nc, .asm_684b
- cp $7
- jr .asm_684d
-.asm_684b
- cp $a
-.asm_684d
- jr nz, .asm_6867
+ jr nz, .placeUnderscoreLoop
+ ld a, [wNamingScreenType]
+ cp NAME_MON_SCREEN
+ ld a, [wNamingScreenNameLength]
+ jr nc, .pokemon2
+ cp 7 ; player or rival max name length
+ jr .playerOrRival2
+.pokemon2
+ cp 10 ; pokemon max name length
+.playerOrRival2
+ jr nz, .emptySpacesRemaining
+ ; when all spaces are filled, force the cursor onto the ED tile
call EraseMenuCursor
- ld a, $11
+ ld a, $11 ; "ED" x coord
ld [wTopMenuItemX], a
- ld a, $5
+ ld a, $5 ; "ED" y corrd
ld [wCurrentMenuItem], a
- ld a, [wd07d]
- cp $2
- ld a, $9
- jr nc, .asm_6867
- ld a, $6
-.asm_6867
+ ld a, [wNamingScreenType]
+ cp NAME_MON_SCREEN
+ ld a, 9 ; keep the last underscore raised
+ jr nc, .pokemon3
+ ld a, 6 ; keep the last underscore raised
+.pokemon3
+.emptySpacesRemaining
ld c, a
ld b, $0
- hlCoord 10, 3
+ coord hl, 10, 3
add hl, bc
- ld [hl], $77
+ ld [hl], $77 ; raised underscore tile id
ret
-Func_6871: ; 6871 (1:6871)
+DakutensAndHandakutens:
push de
call CalcStringLength
dec hl
@@ -429,10 +436,10 @@ Func_6871: ; 6871 (1:6871)
ret nc
inc hl
ld a, [hl]
- ld [wHPBarNewHP], a
+ ld [wNamingScreenLetter], a
ret
-Dakutens: ; 6885 (1:6885)
+Dakutens:
db "かが", "きぎ", "くぐ", "けげ", "こご"
db "さざ", "しじ", "すず", "せぜ", "そぞ"
db "ただ", "ちぢ", "つづ", "てで", "とど"
@@ -443,26 +450,26 @@ Dakutens: ; 6885 (1:6885)
db "ハバ", "ヒビ", "フブ", "へべ", "ホボ"
db $ff
-Handakutens: ; 68d6 (1:68d6)
+Handakutens:
db "はぱ", "ひぴ", "ふぷ", "へぺ", "ほぽ"
db "ハパ", "ヒピ", "フプ", "へぺ", "ホポ"
db $ff
; calculates the length of the string at wcf4b and stores it in c
-CalcStringLength: ; 68eb (1:68eb)
+CalcStringLength:
ld hl, wcf4b
ld c, $0
-.asm_68f0
+.loop
ld a, [hl]
- cp $50
+ cp "@"
ret z
inc hl
inc c
- jr .asm_68f0
+ jr .loop
-PrintNamingText: ; 68f8 (1:68f8)
- hlCoord 0, 1
- ld a, [wd07d]
+PrintNamingText:
+ coord hl, 0, 1
+ ld a, [wNamingScreenType]
ld de, YourTextString
and a
jr z, .notNickname
@@ -476,12 +483,12 @@ PrintNamingText: ; 68f8 (1:68f8)
pop af
ld [wd11e], a
call GetMonName
- hlCoord 4, 1
+ coord hl, 4, 1
call PlaceString
ld hl, $1
add hl, bc
ld [hl], $c9
- hlCoord 1, 3
+ coord hl, 1, 3
ld de, NicknameTextString
jr .placeString
.notNickname
@@ -492,14 +499,14 @@ PrintNamingText: ; 68f8 (1:68f8)
.placeString
jp PlaceString
-YourTextString: ; 693f (1:693f)
+YourTextString:
db "YOUR @"
-RivalsTextString: ; 6945 (1:6945)
+RivalsTextString:
db "RIVAL's @"
-NameTextString: ; 694d (1:694d)
+NameTextString:
db "NAME?@"
-NicknameTextString: ; 6953 (1:6953)
+NicknameTextString:
db "NICKNAME?@"
diff --git a/engine/menu/oaks_pc.asm b/engine/menu/oaks_pc.asm
index 6e7edda2..03c9b8f1 100755
--- a/engine/menu/oaks_pc.asm
+++ b/engine/menu/oaks_pc.asm
@@ -1,27 +1,28 @@
-OpenOaksPC: ; 1e915 (7:6915)
+OpenOaksPC:
call SaveScreenTilesToBuffer2
ld hl, AccessedOaksPCText
call PrintText
ld hl, GetDexRatedText
call PrintText
call YesNoChoice
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
+ ld a, [wCurrentMenuItem]
and a
- jr nz, .asm_1e932
+ jr nz, .closePC
predef DisplayDexRating
-.asm_1e932
+.closePC
ld hl, ClosedOaksPCText
call PrintText
jp LoadScreenTilesFromBuffer2
-GetDexRatedText: ; 1e93b (7:693b)
+GetDexRatedText:
TX_FAR _GetDexRatedText
db "@"
-ClosedOaksPCText: ; 1e940 (7:6940)
+ClosedOaksPCText:
TX_FAR _ClosedOaksPCText
- db $0d,"@"
+ TX_WAIT
+ db "@"
-AccessedOaksPCText: ; 1e946 (7:6946)
+AccessedOaksPCText:
TX_FAR _AccessedOaksPCText
db "@"
diff --git a/engine/menu/party_menu.asm b/engine/menu/party_menu.asm
index 242edd40..a35524ed 100755
--- a/engine/menu/party_menu.asm
+++ b/engine/menu/party_menu.asm
@@ -1,4 +1,4 @@
-; [wd07d] = menu type / message ID
+; [wPartyMenuTypeOrMessageID] = menu type / message ID
; if less than $F0, it is a menu type
; menu types:
; 00: normal pokemon menu (e.g. Start menu)
@@ -17,25 +17,25 @@
; f6: health returned
; f7: revitalized
; f8: leveled up
-DrawPartyMenu_: ; 12cd2 (4:6cd2)
+DrawPartyMenu_:
xor a
ld [H_AUTOBGTRANSFERENABLED],a
call ClearScreen
- call UpdateSprites ; move sprites
+ call UpdateSprites
callba LoadMonPartySpriteGfxWithLCDDisabled ; load pokemon icon graphics
-RedrawPartyMenu_: ; 12ce3 (4:6ce3)
- ld a,[wd07d]
- cp a,$04
+RedrawPartyMenu_:
+ ld a,[wPartyMenuTypeOrMessageID]
+ cp a,SWAP_MONS_PARTY_MENU
jp z,.printMessage
call ErasePartyMenuCursors
- callba SendBlkPacket_PartyMenu ; loads some data to wcf2e
- hlCoord 3, 0
+ 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?
@@ -70,15 +70,15 @@ RedrawPartyMenu_: ; 12ce3 (4:6ce3)
dec hl
dec hl
dec hl
- ld a,$EC ; unfilled right arrow menu cursor
+ ld a,"▷" ; unfilled right arrow menu cursor
ld [hli],a ; place the cursor
inc hl
inc hl
.skipUnfilledRightArrow
- ld a,[wd07d] ; menu type
- cp a,$03
+ ld a,[wPartyMenuTypeOrMessageID] ; menu type
+ cp a,TMHM_PARTY_MENU
jr z,.teachMoveMenu
- cp a,$05
+ cp a,EVO_STONE_PARTY_MENU
jr z,.evolutionStoneMenu
push hl
ld bc,14 ; 14 columns to the right
@@ -87,7 +87,7 @@ RedrawPartyMenu_: ; 12ce3 (4:6ce3)
call PrintStatusCondition
pop hl
push hl
- ld bc,20 + 1 ; down 1 row and right 1 column
+ ld bc,SCREEN_WIDTH + 1 ; down 1 row and right 1 column
ld a,[hFlags_0xFFF6]
set 0,a
ld [hFlags_0xFFF6],a
@@ -96,7 +96,7 @@ RedrawPartyMenu_: ; 12ce3 (4:6ce3)
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
@@ -150,7 +150,7 @@ RedrawPartyMenu_: ; 12ce3 (4:6ce3)
ld l,a
ld de,wcd6d
ld a,BANK(EvosMovesPointerTable)
- ld bc,13
+ ld bc,Mon133_EvosEnd - Mon133_EvosMoves
call FarCopyData
ld hl,wcd6d
ld de,.notAbleToEvolveText
@@ -167,7 +167,7 @@ RedrawPartyMenu_: ; 12ce3 (4:6ce3)
dec hl
dec hl
ld b,[hl]
- ld a,[wd156] ; evolution stone item ID
+ ld a,[wEvoStoneItemID] ; the stone the player used
inc hl
inc hl
inc hl
@@ -188,15 +188,15 @@ RedrawPartyMenu_: ; 12ce3 (4:6ce3)
.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]
push af
push hl
set 6,[hl] ; turn off letter printing delay
- ld a,[wd07d] ; message ID
+ ld a,[wPartyMenuTypeOrMessageID] ; message ID
cp a,$F0
jr nc,.printItemUseMessage
add a
@@ -227,14 +227,14 @@ RedrawPartyMenu_: ; 12ce3 (4:6ce3)
ld h,[hl]
ld l,a
push hl
- ld a,[wcf06]
+ ld a,[wUsedItemOnWhichPokemon]
ld hl,wPartyMonNicks
call GetPartyMonName
pop hl
call PrintText
jr .done
-PartyMenuItemUseMessagePointers: ; 12e61 (4:6e61)
+PartyMenuItemUseMessagePointers:
dw AntidoteText
dw BurnHealText
dw IceHealText
@@ -245,7 +245,7 @@ PartyMenuItemUseMessagePointers: ; 12e61 (4:6e61)
dw ReviveText
dw RareCandyText
-PartyMenuMessagePointers: ; 12e73 (4:6e73)
+PartyMenuMessagePointers:
dw PartyMenuNormalText
dw PartyMenuItemUseText
dw PartyMenuBattleText
@@ -253,73 +253,73 @@ PartyMenuMessagePointers: ; 12e73 (4:6e73)
dw PartyMenuSwapMonText
dw PartyMenuItemUseText
-PartyMenuNormalText: ; 12e7f (4:6e7f)
+PartyMenuNormalText:
TX_FAR _PartyMenuNormalText
db "@"
-PartyMenuItemUseText: ; 12e84 (4:6e84)
+PartyMenuItemUseText:
TX_FAR _PartyMenuItemUseText
db "@"
-PartyMenuBattleText: ; 12e89 (4:6e89)
+PartyMenuBattleText:
TX_FAR _PartyMenuBattleText
db "@"
-PartyMenuUseTMText: ; 12e8e (4:6e8e)
+PartyMenuUseTMText:
TX_FAR _PartyMenuUseTMText
db "@"
-PartyMenuSwapMonText: ; 12e93 (4:6e93)
+PartyMenuSwapMonText:
TX_FAR _PartyMenuSwapMonText
db "@"
-PotionText: ; 12e98 (4:6e98)
+PotionText:
TX_FAR _PotionText
db "@"
-AntidoteText: ; 12e9d (4:6e9d)
+AntidoteText:
TX_FAR _AntidoteText
db "@"
-ParlyzHealText: ; 12ea2 (4:6ea2)
+ParlyzHealText:
TX_FAR _ParlyzHealText
db "@"
-BurnHealText: ; 12ea7 (4:6ea7)
+BurnHealText:
TX_FAR _BurnHealText
db "@"
-IceHealText: ; 12eac (4:6eac)
+IceHealText:
TX_FAR _IceHealText
db "@"
-AwakeningText: ; 12eb1 (4:6eb1)
+AwakeningText:
TX_FAR _AwakeningText
db "@"
-FullHealText: ; 12eb6 (4:6eb6)
+FullHealText:
TX_FAR _FullHealText
db "@"
-ReviveText: ; 12ebb (4:6ebb)
+ReviveText:
TX_FAR _ReviveText
db "@"
-RareCandyText: ; 12ec0 (4:6ec0)
+RareCandyText:
TX_FAR _RareCandyText
- db $0B
- db $06
+ TX_SFX_ITEM_1 ; probably supposed to play SFX_LEVEL_UP but the wrong music bank is loaded
+ TX_BLINK
db "@"
-SetPartyMenuHealthBarColor: ; 12ec7 (4:6ec7)
- ld hl, wcf1f
- ld a, [wcf2d]
+SetPartyMenuHPBarColor:
+ 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
diff --git a/engine/menu/pc.asm b/engine/menu/pc.asm
index 97895ca6..c9e2cf08 100755
--- a/engine/menu/pc.asm
+++ b/engine/menu/pc.asm
@@ -1,16 +1,16 @@
-ActivatePC: ; 17e2c (5:7e2c)
- call SaveScreenTilesToBuffer2 ;XXX: copy background from wTileMap to wTileMapBackup2
- ld a, (SFX_02_45 - SFX_Headers_02) / 3
- call PlaySound ;XXX: play sound or stop music
+ActivatePC:
+ call SaveScreenTilesToBuffer2
+ ld a, SFX_TURN_ON_PC
+ call PlaySound
ld hl, TurnedOnPC1Text
call PrintText
- call WaitForSoundToFinish ;XXX: wait for sound to be done
+ call WaitForSoundToFinish
ld hl, wFlags_0xcd60
set 3, [hl]
- call LoadScreenTilesFromBuffer2 ;XXX: restore saved screen
+ call LoadScreenTilesFromBuffer2
call Delay3
-PCMainMenu: ; 17e48 (5:7e48)
- callba Func_213c8
+PCMainMenu:
+ callba DisplayPCMainMenu
ld hl, wFlags_0xcd60
set 5, [hl]
call HandleMenuInput
@@ -51,31 +51,30 @@ PCMainMenu: ; 17e48 (5:7e48)
ld hl, wFlags_0xcd60
res 5, [hl]
set 3, [hl]
- ld a, (SFX_02_47 - SFX_Headers_02) / 3
- call PlaySound ;XXX: play sound or stop music
- call WaitForSoundToFinish ;XXX: wait for sound to be done
+ ld a, SFX_ENTER_PC
+ call PlaySound
+ call WaitForSoundToFinish
ld hl, AccessedMyPCText
call PrintText
callba PlayerPC
jr ReloadMainMenu
-OaksPC: ; 17ec0 (5:7ec0)
- ld a, (SFX_02_47 - SFX_Headers_02) / 3
- call PlaySound ;XXX: play sound or stop music
- call WaitForSoundToFinish ;XXX: wait for sound to be done
+OaksPC:
+ ld a, SFX_ENTER_PC
+ call PlaySound
+ call WaitForSoundToFinish
callba OpenOaksPC
jr ReloadMainMenu
-PKMNLeague: ; 17ed2 (5:7ed2)
- ld a, (SFX_02_47 - SFX_Headers_02) / 3
- call PlaySound ;XXX: play sound or stop music
- call WaitForSoundToFinish ;XXX: wait for sound to be done
+PKMNLeague:
+ ld a, SFX_ENTER_PC
+ call PlaySound
+ call WaitForSoundToFinish
callba PKMNLeaguePC
jr ReloadMainMenu
-BillsPC: ; 17ee4 (5:7ee4)
- ld a, (SFX_02_47 - SFX_Headers_02) / 3
- call PlaySound ;XXX: play sound or stop music
- call WaitForSoundToFinish ;XXX: wait for sound to be done
- ld a, [wd7f1] ;has to do with having met Bill
- bit 0, a
+BillsPC:
+ ld a, SFX_ENTER_PC
+ call PlaySound
+ call WaitForSoundToFinish
+ CheckEvent EVENT_MET_BILL
jr nz, .billsPC ;if you've met bill, use that bill's instead of someone's
ld hl, AccessedSomeonesPCText
jr .printText
@@ -84,59 +83,59 @@ BillsPC: ; 17ee4 (5:7ee4)
.printText
call PrintText
callba BillsPC_
-ReloadMainMenu: ; 17f06 (5:7f06)
+ReloadMainMenu:
xor a
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
call ReloadMapData
- call UpdateSprites ;XXX: moves sprites
+ call UpdateSprites
jp PCMainMenu
-LogOff: ; 17f13 (5:7f13)
- ld a, (SFX_02_46 - SFX_Headers_02) / 3
- call PlaySound ;XXX: play sound or stop music
- call WaitForSoundToFinish ;XXX: wait for sound to be done
+LogOff:
+ ld a, SFX_TURN_OFF_PC
+ call PlaySound
+ call WaitForSoundToFinish
ld hl, wFlags_0xcd60
res 3, [hl]
res 5, [hl]
ret
-TurnedOnPC1Text: ; 17f23 (5:7f23)
+TurnedOnPC1Text:
TX_FAR _TurnedOnPC1Text
db "@"
-AccessedBillsPCText: ; 17f28 (5:7f28)
+AccessedBillsPCText:
TX_FAR _AccessedBillsPCText
db "@"
-AccessedSomeonesPCText: ; 17f2d (5:7f2d)
+AccessedSomeonesPCText:
TX_FAR _AccessedSomeonesPCText
db "@"
-AccessedMyPCText: ; 17f32 (5:7f32)
+AccessedMyPCText:
TX_FAR _AccessedMyPCText
db "@"
-; removes one of the specified item ID [$FFdb] from bag (if existent)
-RemoveItemByID: ; 17f37 (5:7f37)
- ld hl, wBagItems ; wd31e
- ld a, [$ffdb]
+; removes one of the specified item ID [hItemToRemoveID] from bag (if existent)
+RemoveItemByID:
+ ld hl, wBagItems
+ ld a, [hItemToRemoveID]
ld b, a
xor a
- ld [$ffdc], a
-.asm_17f40
+ ld [hItemToRemoveIndex], a
+.loop
ld a, [hli]
- cp $ff
+ cp -1 ; reached terminator?
ret z
cp b
- jr z, .asm_17f4f
+ jr z, .foundItem
inc hl
- ld a, [$ffdc]
+ ld a, [hItemToRemoveIndex]
inc a
- ld [$ffdc], a
- jr .asm_17f40
-.asm_17f4f
+ ld [hItemToRemoveIndex], a
+ jr .loop
+.foundItem
ld a, $1
- ld [wcf96], a
- ld a, [$ffdc]
- ld [wWhichPokemon], a ; wWhichPokemon
- ld hl, wNumBagItems ; wNumBagItems
+ ld [wItemQuantity], a
+ ld a, [hItemToRemoveIndex]
+ ld [wWhichPokemon], a
+ ld hl, wNumBagItems
jp RemoveItemFromInventory
diff --git a/engine/menu/players_pc.asm b/engine/menu/players_pc.asm
index 147a27a4..bc2be4ef 100755
--- a/engine/menu/players_pc.asm
+++ b/engine/menu/players_pc.asm
@@ -1,301 +1,303 @@
-PlayerPC: ; 78e6 (1:78e6)
+PlayerPC:
ld hl, wd730
set 6, [hl]
ld a, ITEM_NAME
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
- ld a, (SFX_02_45 - SFX_Headers_02) / 3
+ bit 3, a ; accessing player's PC through another PC?
+ jr nz, PlayerPCMenu
+; accessing it directly
+ ld a, SFX_TURN_ON_PC
call PlaySound
ld hl, TurnedOnPC2Text
call PrintText
-Func_790c: ; 790c (1:790c)
- ld a, [wccd3]
+PlayerPCMenu:
+ ld a, [wParentMenuItem]
ld [wCurrentMenuItem], a
ld hl, wFlags_0xcd60
set 5, [hl]
call LoadScreenTilesFromBuffer2
- ld hl, wTileMap
+ coord hl, 0, 0
ld b, $8
ld c, $e
call TextBoxBorder
call UpdateSprites
- hlCoord 2, 2
+ coord hl, 2, 2
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:
ld a, [wFlags_0xcd60]
- bit 3, a
- jr nz, .asm_797c
- ld a, (SFX_02_46 - SFX_Headers_02) / 3
+ bit 3, a ; accessing player's PC through another PC?
+ jr nz, .next
+; accessing it directly
+ ld a, SFX_TURN_OFF_PC
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
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
ret
-Func_7995: ; 7995 (1:7995)
+PlayerPCDeposit:
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
ld a, l
- ld [wList], a
+ ld [wListPointer], a
ld a, h
- ld [wList + 1], a
+ ld [wListPointer + 1], a
xor a
- ld [wcf93], a
- ld a, $3
+ ld [wPrintItemPrices], a
+ ld a, ITEMLISTMENU
ld [wListMenuID], a
call DisplayListMenuID
- jp c, Func_790c
+ jp c, PlayerPCMenu
call IsKeyItem
- ld a, $1
- ld [wcf96], a
- ld a, [wd124]
+ 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
- ld a, (SFX_02_55 - SFX_Headers_02) / 3
+ ld a, SFX_WITHDRAW_DEPOSIT
call PlaySound
call WaitForSoundToFinish
ld hl, ItemWasStoredText
call PrintText
- jp Func_79ab
+ jp .loop
-Func_7a12: ; 7a12 (1:7a12)
+PlayerPCWithdraw:
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
ld a, l
- ld [wList], a
+ ld [wListPointer], a
ld a, h
- ld [wList + 1], a
+ ld [wListPointer + 1], a
xor a
- ld [wcf93], a
- ld a, $3
+ ld [wPrintItemPrices], a
+ ld a, ITEMLISTMENU
ld [wListMenuID], a
call DisplayListMenuID
- jp c, Func_790c
+ jp c, PlayerPCMenu
call IsKeyItem
- ld a, $1
- ld [wcf96], a
- ld a, [wd124]
+ 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
- ld a, (SFX_02_55 - SFX_Headers_02) / 3
+ ld a, SFX_WITHDRAW_DEPOSIT
call PlaySound
call WaitForSoundToFinish
ld hl, WithdrewItemText
call PrintText
- jp Func_7a28
+ jp .loop
-Func_7a8f: ; 7a8f (1:7a8f)
+PlayerPCToss:
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
ld a, l
- ld [wList], a
+ ld [wListPointer], a
ld a, h
- ld [wList + 1], a
+ ld [wListPointer + 1], a
xor a
- ld [wcf93], a
- ld a, $3
+ ld [wPrintItemPrices], a
+ 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 [wcf96], a
- ld a, [wd124]
+ 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
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)
+PlayersPCMenuEntries:
db "WITHDRAW ITEM"
next "DEPOSIT ITEM"
next "TOSS ITEM"
next "LOG OFF@"
-TurnedOnPC2Text: ; 7b22 (1:7b22)
+TurnedOnPC2Text:
TX_FAR _TurnedOnPC2Text
db "@"
-WhatDoYouWantText: ; 7b27 (1:7b27)
+WhatDoYouWantText:
TX_FAR _WhatDoYouWantText
db "@"
-WhatToDepositText: ; 7b2c (1:7b2c)
+WhatToDepositText:
TX_FAR _WhatToDepositText
db "@"
-DepositHowManyText: ; 7b31 (1:7b31)
+DepositHowManyText:
TX_FAR _DepositHowManyText
db "@"
-ItemWasStoredText: ; 7b36 (1:7b36)
+ItemWasStoredText:
TX_FAR _ItemWasStoredText
db "@"
-NothingToDepositText: ; 7b3b (1:7b3b)
+NothingToDepositText:
TX_FAR _NothingToDepositText
db "@"
-NoRoomToStoreText: ; 7b40 (1:7b40)
+NoRoomToStoreText:
TX_FAR _NoRoomToStoreText
db "@"
-WhatToWithdrawText: ; 7b45 (1:7b45)
+WhatToWithdrawText:
TX_FAR _WhatToWithdrawText
db "@"
-WithdrawHowManyText: ; 7b4a (1:7b4a)
+WithdrawHowManyText:
TX_FAR _WithdrawHowManyText
db "@"
-WithdrewItemText: ; 7b4f (1:7b4f)
+WithdrewItemText:
TX_FAR _WithdrewItemText
db "@"
-NothingStoredText: ; 7b54 (1:7b54)
+NothingStoredText:
TX_FAR _NothingStoredText
db "@"
-CantCarryMoreText: ; 7b59 (1:7b59)
+CantCarryMoreText:
TX_FAR _CantCarryMoreText
db "@"
-WhatToTossText: ; 7b5e (1:7b5e)
+WhatToTossText:
TX_FAR _WhatToTossText
db "@"
-TossHowManyText: ; 7b63 (1:7b63)
+TossHowManyText:
TX_FAR _TossHowManyText
db "@"
diff --git a/engine/menu/pokedex.asm b/engine/menu/pokedex.asm
index 4351ae4c..2da3a0f6 100755
--- a/engine/menu/pokedex.asm
+++ b/engine/menu/pokedex.asm
@@ -1,7 +1,7 @@
-ShowPokedexMenu: ; 40000 (10:4000)
+ShowPokedexMenu:
call GBPalWhiteOut
call ClearScreen
- call UpdateSprites ; move sprites
+ call UpdateSprites
ld a,[wListScrollOffset]
push af
xor a
@@ -12,8 +12,8 @@ ShowPokedexMenu: ; 40000 (10:4000)
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
@@ -22,17 +22,17 @@ ShowPokedexMenu: ; 40000 (10:4000)
xor a
ld [hli],a ; top menu item X
inc a
- ld [wcc37],a
+ ld [wMenuWatchMovingOutOfBounds],a
inc hl
inc hl
ld a,6
ld [hli],a ; max menu item ID
- ld [hl],%00110011 ; menu watched keys (Left, Right, B button, A button)
+ ld [hl],D_LEFT | D_RIGHT | B_BUTTON | A_BUTTON
call HandlePokedexListMenu
jr c,.goToSideMenu ; if the player chose a pokemon from the list
.exitPokedex
xor a
- ld [wcc37],a
+ ld [wMenuWatchMovingOutOfBounds],a
ld [wCurrentMenuItem],a
ld [wLastMenuItem],a
ld [hJoy7],a
@@ -41,7 +41,7 @@ ShowPokedexMenu: ; 40000 (10:4000)
pop af
ld [wListScrollOffset],a
call GBPalWhiteOutWithDelay3
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
jp ReloadMapData
.goToSideMenu
call HandlePokedexSideMenu
@@ -57,7 +57,7 @@ ShowPokedexMenu: ; 40000 (10:4000)
; 00: showed pokemon data or area
; 01: the player chose Quit
; 02: the pokemon has not been seen yet or the player pressed the B button
-HandlePokedexSideMenu: ; 4006d (10:406d)
+HandlePokedexSideMenu:
call PlaceUnfilledArrowMenuCursor
ld a,[wCurrentMenuItem]
push af
@@ -71,8 +71,8 @@ HandlePokedexSideMenu: ; 4006d (10:406d)
ld [wd11e],a
ld a,[wd11e]
push af
- ld a,[wWhichTrade]
- push af
+ ld a,[wDexMaxSeenMon]
+ push af ; this doesn't need to be preserved
ld hl,wPokedexSeen
call IsPokemonBitSet
ld b,2
@@ -88,10 +88,11 @@ HandlePokedexSideMenu: ; 4006d (10:406d)
inc hl
ld a,3
ld [hli],a ; max menu item ID
+ ;ld a, A_BUTTON | B_BUTTON
ld [hli],a ; menu watched keys (A button and B button)
xor a
ld [hli],a ; old menu item ID
- ld [wcc37],a
+ ld [wMenuWatchMovingOutOfBounds],a
.handleMenuInput
call HandleMenuInput
bit 1,a ; was the B button pressed?
@@ -108,7 +109,7 @@ HandlePokedexSideMenu: ; 4006d (10:406d)
ld b,1
.exitSideMenu
pop af
- ld [wWhichTrade],a
+ ld [wDexMaxSeenMon],a
pop af
ld [wd11e],a
pop af
@@ -118,30 +119,34 @@ HandlePokedexSideMenu: ; 4006d (10:406d)
pop af
ld [wCurrentMenuItem],a
push bc
- hlCoord 0, 3
+ coord hl, 0, 3
ld de,20
- ld bc,$7f0d ; 13 blank tiles
+ lb bc, " ", 13
call DrawTileLine ; cover up the menu cursor in the pokemon list
pop bc
ret
+
.buttonBPressed
push bc
- hlCoord 15, 10
+ coord hl, 15, 10
ld de,20
- ld bc,$7f07 ; 7 blank tiles
+ lb bc, " ", 7
call DrawTileLine ; cover up the menu cursor in the side menu
pop bc
jr .exitSideMenu
+
.choseData
call ShowPokedexDataInternal
ld b,0
jr .exitSideMenu
+
; play pokemon cry
.choseCry
ld a,[wd11e]
- call GetCryData ; get cry data
- call PlaySound ; play sound
+ call GetCryData
+ call PlaySound
jr .handleMenuInput
+
.choseArea
predef LoadTownMap_Nest ; display pokemon areas
ld b,0
@@ -149,47 +154,47 @@ HandlePokedexSideMenu: ; 4006d (10:406d)
; handles the list of pokemon on the left of the pokedex screen
; sets carry flag if player presses A, unsets carry flag if player presses B
-HandlePokedexListMenu: ; 40111 (10:4111)
+HandlePokedexListMenu:
xor a
ld [H_AUTOBGTRANSFERENABLED],a
; draw the horizontal line separating the seen and owned amounts from the menu
- hlCoord 15, 8
- ld a,$7a ; horizontal line tile
+ coord hl, 15, 8
+ ld a,"─"
ld [hli],a
ld [hli],a
ld [hli],a
ld [hli],a
ld [hli],a
- hlCoord 14, 0
+ coord hl, 14, 0
ld [hl],$71 ; vertical line tile
- hlCoord 14, 1
+ coord hl, 14, 1
call DrawPokedexVerticalLine
- hlCoord 14, 9
+ coord hl, 14, 9
call DrawPokedexVerticalLine
ld hl,wPokedexSeen
ld b,wPokedexSeenEnd - wPokedexSeen
call CountSetBits
- ld de,wd11e
- hlCoord 16, 3
- ld bc,$0103
+ ld de, wNumSetBits
+ coord hl, 16, 3
+ lb bc, 1, 3
call PrintNumber ; print number of seen pokemon
ld hl,wPokedexOwned
ld b,wPokedexOwnedEnd - wPokedexOwned
call CountSetBits
- ld de,wd11e
- hlCoord 16, 6
- ld bc,$0103
+ ld de, wNumSetBits
+ coord hl, 16, 6
+ lb bc, 1, 3
call PrintNumber ; print number of owned pokemon
- hlCoord 16, 2
+ coord hl, 16, 2
ld de,PokedexSeenText
call PlaceString
- hlCoord 16, 5
+ coord hl, 16, 5
ld de,PokedexOwnText
call PlaceString
- hlCoord 1, 1
+ coord hl, 1, 1
ld de,PokedexContentsText
call PlaceString
- hlCoord 16, 10
+ coord hl, 16, 10
ld de,PokedexMenuItemsText
call PlaceString
; find the highest pokedex number among the pokemon the player has seen
@@ -205,20 +210,21 @@ HandlePokedexListMenu: ; 40111 (10:4111)
dec c
jr nz,.maxSeenPokemonInnerLoop
jr .maxSeenPokemonLoop
+
.storeMaxSeenPokemon
ld a,b
- ld [wWhichTrade],a ; max seen pokemon
+ ld [wDexMaxSeenMon],a
.loop
xor a
ld [H_AUTOBGTRANSFERENABLED],a
- hlCoord 4, 2
- ld bc,$0e0a
+ coord hl, 4, 2
+ lb bc, 14, 10
call ClearScreenArea
- hlCoord 1, 3
+ coord hl, 1, 3
ld a,[wListScrollOffset]
ld [wd11e],a
ld d,7
- ld a,[wWhichTrade]
+ ld a,[wDexMaxSeenMon]
cp a,7
jr nc,.printPokemonLoop
ld d,a
@@ -233,12 +239,12 @@ HandlePokedexListMenu: ; 40111 (10:4111)
push af
push de
push hl
- ld de,-20
+ ld de,-SCREEN_WIDTH
add hl,de
ld de,wd11e
- ld bc,$8103
+ lb bc, LEADING_ZEROES | 1, 3
call PrintNumber ; print the pokedex number
- ld de,20
+ ld de,SCREEN_WIDTH
add hl,de
dec hl
push hl
@@ -266,7 +272,7 @@ HandlePokedexListMenu: ; 40111 (10:4111)
inc hl
call PlaceString
pop hl
- ld bc,2 * 20
+ ld bc,2 * SCREEN_WIDTH
add hl,bc
pop de
pop af
@@ -294,9 +300,9 @@ HandlePokedexListMenu: ; 40111 (10:4111)
bit 7,a ; was Down pressed?
jr z,.checkIfRightPressed
.downPressed ; scroll down one row
- ld a,[wWhichTrade]
+ ld a,[wDexMaxSeenMon]
cp a,7
- jp c,.loop
+ jp c,.loop ; can't if the list is shorter than 7
sub a,7
ld b,a
ld a,[wListScrollOffset]
@@ -309,9 +315,9 @@ HandlePokedexListMenu: ; 40111 (10:4111)
bit 4,a ; was Right pressed?
jr z,.checkIfLeftPressed
.rightPressed ; scroll down 7 rows
- ld a,[wWhichTrade]
+ ld a,[wDexMaxSeenMon]
cp a,7
- jp c,.loop
+ jp c,.loop ; can't if the list is shorter than 7
sub a,6
ld b,a
ld a,[wListScrollOffset]
@@ -341,9 +347,9 @@ HandlePokedexListMenu: ; 40111 (10:4111)
and a
ret
-DrawPokedexVerticalLine: ; 4028e (10:428e)
+DrawPokedexVerticalLine:
ld c,9 ; height of line
- ld de,20 ; width of screen
+ ld de,SCREEN_WIDTH
ld a,$71 ; vertical line tile
.loop
ld [hl],a
@@ -353,78 +359,80 @@ DrawPokedexVerticalLine: ; 4028e (10:428e)
jr nz,.loop
ret
-PokedexSeenText: ; 4029d (10:429d)
+PokedexSeenText:
db "SEEN@"
-PokedexOwnText: ; 402a2 (10:42a2)
+PokedexOwnText:
db "OWN@"
-PokedexContentsText: ; 402a6 (10:42a6)
+PokedexContentsText:
db "CONTENTS@"
-PokedexMenuItemsText: ; 402af (10:42af)
+PokedexMenuItemsText:
db "DATA"
next "CRY"
next "AREA"
-IF DEF(_YELLOW)
- next "PRNT"
-ENDC
next "QUIT@"
; tests if a pokemon's bit is set in the seen or owned pokemon bit fields
; INPUT:
; [wd11e] = pokedex number
; hl = address of bit field
-IsPokemonBitSet: ; 402c2 (10:42c2)
+IsPokemonBitSet:
ld a,[wd11e]
dec a
ld c,a
- ld b,2
+ ld b,FLAG_TEST
predef FlagActionPredef
ld a,c
and a
ret
; function to display pokedex data from outside the pokedex
-ShowPokedexData: ; 402d1 (10:42d1)
+ShowPokedexData:
call GBPalWhiteOutWithDelay3
call ClearScreen
call UpdateSprites
callab LoadPokedexTilePatterns ; load pokedex tiles
; function to display pokedex data from inside the pokedex
-ShowPokedexDataInternal: ; 402e2 (10:42e2)
+ShowPokedexDataInternal:
ld hl,wd72c
set 1,[hl]
ld a,$33 ; 3/7 volume
- ld [$ff24],a
+ ld [rNR50],a
call GBPalWhiteOut ; zero all palettes
call ClearScreen
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]
push af
xor a
ld [hTilesetType],a
- hlCoord 0, 0
+
+ coord hl, 0, 0
ld de,1
- ld bc,$6414
+ lb bc, $64, SCREEN_WIDTH
call DrawTileLine ; draw top border
- hlCoord 0, 17
- ld b,$6f
+
+ coord hl, 0, 17
+ ld b, $6f
call DrawTileLine ; draw bottom border
- hlCoord 0, 1
+
+ coord hl, 0, 1
ld de,20
- ld bc,$6610
+ lb bc, $66, $10
call DrawTileLine ; draw left border
- hlCoord 19, 1
+
+ coord hl, 19, 1
ld b,$67
call DrawTileLine ; draw right border
+
ld a,$63 ; upper left corner tile
Coorda 0, 0
ld a,$65 ; upper right corner tile
@@ -433,15 +441,19 @@ ShowPokedexDataInternal: ; 402e2 (10:42e2)
Coorda 0, 17
ld a,$6e ; lower right corner tile
Coorda 19, 17
- hlCoord 0, 9
+
+ coord hl, 0, 9
ld de,PokedexDataDividerLine
call PlaceString ; draw horizontal divider line
- hlCoord 9, 6
+
+ coord hl, 9, 6
ld de,HeightWeightText
call PlaceString
+
call GetMonName
- hlCoord 9, 2
+ coord hl, 9, 2
call PlaceString
+
ld hl,PokedexEntryPointers
ld a,[wd11e]
dec a
@@ -452,22 +464,26 @@ ShowPokedexDataInternal: ; 402e2 (10:42e2)
ld a,[hli]
ld e,a
ld d,[hl] ; de = address of pokedex entry
- hlCoord 9, 4
+
+ coord hl, 9, 4
call PlaceString ; print species name
+
ld h,b
ld l,c
push de
ld a,[wd11e]
push af
call IndexToPokedex
- hlCoord 2, 8
+
+ coord hl, 2, 8
ld a, "№"
ld [hli],a
- ld a,$f2
+ ld a,"⠄"
ld [hli],a
ld de,wd11e
- ld bc,$8103
+ lb bc, LEADING_ZEROES | 1, 3
call PrintNumber ; print pokedex number
+
ld hl,wPokedexOwned
call IsPokemonBitSet
pop af
@@ -475,35 +491,39 @@ ShowPokedexDataInternal: ; 402e2 (10:42e2)
ld a,[wcf91]
ld [wd0b5],a
pop de
+
push af
push bc
push de
push hl
+
call Delay3
call GBPalNormal
call GetMonHeader ; load pokemon picture location
- hlCoord 1, 1
+ coord hl, 1, 1
call LoadFlippedFrontSpriteByMonIndex ; draw pokemon picture
ld a,[wcf91]
call PlayCry ; play pokemon cry
+
pop hl
pop de
pop bc
pop af
+
ld a,c
and a
jp z,.waitForButtonPress ; if the pokemon has not been owned, don't print the height, weight, or description
inc de ; de = address of feet (height)
ld a,[de] ; reads feet, but a is overwritten without being used
- hlCoord 12, 6
- ld bc,$0102
+ coord hl, 12, 6
+ lb bc, 1, 2
call PrintNumber ; print feet (height)
ld a,$60 ; feet symbol tile (one tick)
ld [hl],a
inc de
inc de ; de = address of inches (height)
- hlCoord 15, 6
- ld bc,$8102
+ coord hl, 15, 6
+ lb bc, LEADING_ZEROES | 1, 2
call PrintNumber ; print inches (height)
ld a,$61 ; inches symbol tile (two ticks)
ld [hl],a
@@ -512,25 +532,25 @@ ShowPokedexDataInternal: ; 402e2 (10:42e2)
inc de
inc de ; de = address of upper byte of weight
push de
-; put weight in big-endian order at $ff8b
- ld hl,$ff8b
- ld a,[hl] ; save existing value of [$ff8b]
+; put weight in big-endian order at hDexWeight
+ ld hl,hDexWeight
+ ld a,[hl] ; save existing value of [hDexWeight]
push af
ld a,[de] ; a = upper byte of weight
- ld [hli],a ; store upper byte of weight in [$ff8b]
- ld a,[hl] ; save existing value of [$ff8c]
+ ld [hli],a ; store upper byte of weight in [hDexWeight]
+ ld a,[hl] ; save existing value of [hDexWeight + 1]
push af
dec de
ld a,[de] ; a = lower byte of weight
- ld [hl],a ; store lower byte of weight in [$ff8c]
- ld de,$ff8b
- hlCoord 11, 8
- ld bc,$0205 ; no leading zeroes, right-aligned, 2 bytes, 5 digits
+ ld [hl],a ; store lower byte of weight in [hDexWeight + 1]
+ ld de,hDexWeight
+ coord hl, 11, 8
+ lb bc, 2, 5 ; 2 bytes, 5 digits
call PrintNumber ; print weight
- hlCoord 14, 8
- ld a,[$ff8c]
+ coord hl, 14, 8
+ ld a,[hDexWeight + 1]
sub a,10
- ld a,[$ff8b]
+ ld a,[hDexWeight]
sbc a,0
jr nc,.next
ld [hl],"0" ; if the weight is less than 10, put a 0 before the decimal point
@@ -538,14 +558,14 @@ ShowPokedexDataInternal: ; 402e2 (10:42e2)
inc hl
ld a,[hli]
ld [hld],a ; make space for the decimal point by moving the last digit forward one tile
- ld [hl],$f2 ; decimal point tile
+ ld [hl],"⠄" ; decimal point tile
pop af
- ld [$ff8c],a ; restore original value of [$ff8c]
+ ld [hDexWeight + 1],a ; restore original value of [hDexWeight + 1]
pop af
- ld [$ff8b],a ; restore original value of [$ff8b]
+ ld [hDexWeight],a ; restore original value of [hDexWeight]
pop hl
inc hl ; hl = address of pokedex description text
- bcCoord 1, 11
+ coord bc, 1, 11
ld a,2
ld [$fff4],a
call TextCommandProcessor ; print pokedex description text
@@ -554,35 +574,36 @@ ShowPokedexDataInternal: ; 402e2 (10:42e2)
.waitForButtonPress
call JoypadLowSensitivity
ld a,[hJoy5]
- and a,%00000011 ; A button and B button
+ and a,A_BUTTON | B_BUTTON
jr z,.waitForButtonPress
pop af
ld [hTilesetType],a
call GBPalWhiteOut
call ClearScreen
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
call LoadTextBoxTilePatterns
call GBPalNormal
ld hl,wd72c
res 1,[hl]
ld a,$77 ; max volume
- ld [$ff24],a
+ ld [rNR50],a
ret
-HeightWeightText: ; 40448 (10:4448)
- db "HT ?",$60,"??",$61,$4E,"WT ???lb@"
+HeightWeightText:
+ db "HT ?",$60,"??",$61
+ next "WT ???lb@"
; XXX does anything point to this?
-Unknown_4045D: ; 4045d (10:445d)
- db $54,$50
+PokeText:
+ db "#@"
; horizontal line that divides the pokedex text description from the rest of the data
-PokedexDataDividerLine: ; 4045f (10:445f)
+PokedexDataDividerLine:
db $68,$69,$6B,$69,$6B
db $69,$6B,$69,$6B,$6B
db $6B,$6B,$69,$6B,$69
db $6B,$69,$6B,$69,$6A
- db $50
+ db "@"
; draws a line of tiles
; INPUT:
@@ -590,7 +611,7 @@ PokedexDataDividerLine: ; 4045f (10:445f)
; c = number of tile ID's to write
; de = amount to destination address after each tile (1 for horizontal, 20 for vertical)
; hl = destination address
-DrawTileLine: ; 40474 (10:4474)
+DrawTileLine:
push bc
push de
.loop
@@ -604,7 +625,7 @@ DrawTileLine: ; 40474 (10:4474)
INCLUDE "data/pokedex_entries.asm"
-PokedexToIndex: ; 40ff9 (10:4ff9)
+PokedexToIndex:
; converts the Pokédex number at wd11e to an index
push bc
push hl
@@ -625,7 +646,7 @@ PokedexToIndex: ; 40ff9 (10:4ff9)
pop bc
ret
-IndexToPokedex: ; 41010 (10:5010)
+IndexToPokedex:
; converts the indexédex number at wd11e to a Pokédex number
push bc
push hl
diff --git a/engine/menu/prize_menu.asm b/engine/menu/prize_menu.asm
index 0e904200..f6ca013b 100755
--- a/engine/menu/prize_menu.asm
+++ b/engine/menu/prize_menu.asm
@@ -1,4 +1,4 @@
-CeladonPrizeMenu: ; 5271b (14:671b)
+CeladonPrizeMenu:
ld b,COIN_CASE
call IsItemInBag
jr nz,.havingCoinCase
@@ -13,7 +13,7 @@ CeladonPrizeMenu: ; 5271b (14:671b)
xor a
ld [wCurrentMenuItem],a
ld [wLastMenuItem],a
- ld a,$03
+ ld a,A_BUTTON | B_BUTTON
ld [wMenuWatchedKeys],a
ld a,$03
ld [wMaxMenuItem],a
@@ -21,55 +21,55 @@ CeladonPrizeMenu: ; 5271b (14:671b)
ld [wTopMenuItemY],a
ld a,$01
ld [wTopMenuItemX],a
- call PrintPrizePrice ; 687A
- hlCoord 0, 2
- ld b,$08
- ld c,$10
+ call PrintPrizePrice
+ coord hl, 0, 2
+ ld b, 8
+ ld c, 16
call TextBoxBorder
- call GetPrizeMenuId ;678E
+ call GetPrizeMenuId
call UpdateSprites
ld hl,WhichPrizeTextPtr
call PrintText
call HandleMenuInput ; menu choice handler
bit 1,a ; keypress = B (Cancel)
- jr nz,.NoChoice
+ jr nz, .noChoice
ld a,[wCurrentMenuItem]
- cp a,$03 ; "NO,THANKS" choice
- jr z,.NoChoice
- call HandlePrizeChoice ; 14:68C6
-.NoChoice
+ cp 3 ; "NO,THANKS" choice
+ jr z, .noChoice
+ call HandlePrizeChoice
+.noChoice
ld hl,wd730
res 6,[hl]
ret
-RequireCoinCaseTextPtr: ; 5277e (14:677e)
+RequireCoinCaseTextPtr:
TX_FAR _RequireCoinCaseText
- db $0D
+ TX_WAIT
db "@"
-ExchangeCoinsForPrizesTextPtr: ; 52784 (14:6784)
+ExchangeCoinsForPrizesTextPtr:
TX_FAR _ExchangeCoinsForPrizesText
db "@"
-WhichPrizeTextPtr: ; 52789 (14:6789)
+WhichPrizeTextPtr:
TX_FAR _WhichPrizeText
db "@"
-GetPrizeMenuId: ; 5278e (14:678e)
+GetPrizeMenuId:
; determine which one among the three
; prize-texts has been selected
-; using the text ID (stored in [$FF8C])
+; using the text ID (stored in [hSpriteIndexOrTextID])
; load the three prizes at wd13d-wd13f
; load the three prices at wd141-wd146
; display the three prizes' names
; (distinguishing between Pokemon names
; and Items (specifically TMs) names)
- ld a,[$FF8C]
- sub a,$03 ; prize-texts' id are 3, 4 and 5
- ld [wd12f],a ; prize-texts' id (relative, i.e. 0, 1 or 2)
+ ld a,[hSpriteIndexOrTextID]
+ sub 3 ; prize-texts' id are 3, 4 and 5
+ ld [wWhichPrizeWindow],a ; prize-texts' id (relative, i.e. 0, 1 or 2)
add a
add a
- ld d,$00
+ ld d,0
ld e,a
ld hl,PrizeDifferentMenuPtrs
add hl,de
@@ -78,223 +78,229 @@ GetPrizeMenuId: ; 5278e (14:678e)
ld e,a
inc hl
push hl
- ld hl,W_PRIZE1
- call CopyString ; XXX what does this do
+ ld hl,wPrize1
+ call CopyString
pop hl
ld a,[hli]
ld h,[hl]
ld l,a
- ld de,wd141
- ld bc,$0006
+ ld de,wPrize1Price
+ ld bc,6
call CopyData
- ld a,[wd12f]
- cp a,$02 ;is TM_menu?
+ ld a,[wWhichPrizeWindow]
+ cp 2 ;is TM_menu?
jr nz,.putMonName
- ld a,[W_PRIZE1]
+ ld a,[wPrize1]
ld [wd11e],a
call GetItemName
- hlCoord 2, 4
+ coord hl, 2, 4
call PlaceString
- ld a,[W_PRIZE2]
+ ld a,[wPrize2]
ld [wd11e],a
call GetItemName
- hlCoord 2, 6
+ coord hl, 2, 6
call PlaceString
- ld a,[W_PRIZE3]
+ ld a,[wPrize3]
ld [wd11e],a
call GetItemName
- hlCoord 2, 8
+ coord hl, 2, 8
call PlaceString
jr .putNoThanksText
-.putMonName ; 14:67EC
- ld a,[W_PRIZE1]
+.putMonName
+ ld a,[wPrize1]
ld [wd11e],a
call GetMonName
- hlCoord 2, 4
+ coord hl, 2, 4
call PlaceString
- ld a,[W_PRIZE2]
+ ld a,[wPrize2]
ld [wd11e],a
call GetMonName
- hlCoord 2, 6
+ coord hl, 2, 6
call PlaceString
- ld a,[W_PRIZE3]
+ ld a,[wPrize3]
ld [wd11e],a
call GetMonName
- hlCoord 2, 8
+ coord hl, 2, 8
call PlaceString
-.putNoThanksText ; 14:6819
- hlCoord 2, 10
+.putNoThanksText
+ coord hl, 2, 10
ld de,NoThanksText
call PlaceString
; put prices on the right side of the textbox
- ld de,wd141
- hlCoord 13, 5
+ ld de,wPrize1Price
+ coord hl, 13, 5
; reg. c:
; [low nybble] number of bytes
; [bit 765 = %100] space-padding (not zero-padding)
ld c,(1 << 7 | 2)
; Function $15CD displays BCD value (same routine
; used by text-command $02)
- call PrintBCDNumber ; Print_BCD
- ld de,wd143
- hlCoord 13, 7
- ld c,(%1 << 7 | 2)
call PrintBCDNumber
- ld de,wd145
- hlCoord 13, 9
+ ld de,wPrize2Price
+ coord hl, 13, 7
+ ld c,(1 << 7 | 2)
+ call PrintBCDNumber
+ ld de,wPrize3Price
+ coord hl, 13, 9
ld c,(1 << 7 | 2)
jp PrintBCDNumber
INCLUDE "data/prizes.asm"
-PrintPrizePrice: ; 5287a (14:687a)
- hlCoord 11, 0
- ld b,$01
- ld c,$07
+PrintPrizePrice:
+ coord hl, 11, 0
+ ld b, 1
+ ld c, 7
call TextBoxBorder
- call UpdateSprites ; XXX save OAM?
- hlCoord 12, 0
- ld de,.CoinText
+ call UpdateSprites
+ coord hl, 12, 0
+ ld de, .CoinString
call PlaceString
- hlCoord 13, 1
- ld de,.SixSpacesText
+ coord hl, 13, 1
+ ld de, .SixSpacesString
call PlaceString
- hlCoord 13, 1
+ coord hl, 13, 1
ld de,wPlayerCoins
ld c,%10000010
call PrintBCDNumber
ret
-.CoinText ; 14:68A5
+.CoinString:
db "COIN@"
-.SixSpacesText ; 14:68AA
+.SixSpacesString:
db " @"
-LoadCoinsToSubtract: ; 528b1 (14:68b1)
- ld a,[wd139] ; backup of selected menu_entry
+LoadCoinsToSubtract:
+ ld a,[wWhichPrize]
add a
- ld d,$00
+ ld d,0
ld e,a
- ld hl,wd141 ; first prize's price
+ ld hl,wPrize1Price
add hl,de ; get selected prize's price
xor a
- ld [$FF9F],a
+ ld [hUnusedCoinsByte],a
ld a,[hli]
- ld [$FFA0],a
+ ld [hCoins],a
ld a,[hl]
- ld [$FFA1],a
+ ld [hCoins + 1],a
ret
-HandlePrizeChoice: ; 528c6 (14:68c6)
- ld a,[wCurrentMenuItem] ; selected menu_entry
- ld [wd139],a
- ld d,$00
+HandlePrizeChoice:
+ ld a,[wCurrentMenuItem]
+ ld [wWhichPrize],a
+ ld d,0
ld e,a
- ld hl,W_PRIZE1
+ ld hl,wPrize1
add hl,de
ld a,[hl]
ld [wd11e],a
- ld a,[wd12f]
- cp a,$02 ; is prize a TM?
- jr nz,.GetMonName
+ ld a,[wWhichPrizeWindow]
+ cp 2 ; is prize a TM?
+ jr nz, .getMonName
call GetItemName
- jr .GivePrize
-.GetMonName ; 14:68E3
+ jr .givePrize
+.getMonName
call GetMonName
-.GivePrize ; 14:68E6
+.givePrize
ld hl,SoYouWantPrizeTextPtr
call PrintText
- call YesNoChoice ; yes/no textbox
+ call YesNoChoice
ld a,[wCurrentMenuItem] ; yes/no answer (Y=0, N=1)
and a
- jr nz,.PrintOhFineThen
+ jr nz, .printOhFineThen
call LoadCoinsToSubtract
call HasEnoughCoins
- jr c,.NotEnoughCoins
- ld a,[wd12f]
- cp a,$02
- jr nz,.GiveMon
+ jr c, .notEnoughCoins
+ ld a,[wWhichPrizeWindow]
+ cp $02
+ jr nz, .giveMon
ld a,[wd11e]
ld b,a
ld a,1
ld c,a
- call GiveItem ; GiveItem
- jr nc,.BagFull
- jr .SubtractCoins
-.GiveMon ; 14:6912
+ call GiveItem
+ jr nc, .bagFull
+ jr .subtractCoins
+.giveMon
ld a,[wd11e]
ld [wcf91],a
push af
- call GetPrizeMonLevel ; 14:6977
+ call GetPrizeMonLevel
ld c,a
pop af
ld b,a
call GivePokemon
+
+; If either the party or box was full, wait after displaying message.
push af
- ld a,[wccd3] ; XXX is there room?
+ ld a,[wAddedToParty]
and a
call z,WaitForTextScrollButtonPress
pop af
+
+; If the mon couldn't be given to the player (because both the party and box
+; were full), return without subtracting coins.
ret nc
-.SubtractCoins ; 14:692C
+
+.subtractCoins
call LoadCoinsToSubtract
- ld hl,$FFA1
+ ld hl,hCoins + 1
ld de,wPlayerCoins + 1
ld c,$02 ; how many bytes
- predef SubBCDPredef ; subtract coins (BCD daa operations)
+ predef SubBCDPredef
jp PrintPrizePrice
-.BagFull
+.bagFull
ld hl,PrizeRoomBagIsFullTextPtr
jp PrintText
-.NotEnoughCoins ; 14:6945
+.notEnoughCoins
ld hl,SorryNeedMoreCoinsText
jp PrintText
-.PrintOhFineThen ; 14:694B
+.printOhFineThen
ld hl,OhFineThenTextPtr
jp PrintText
-UnknownData52951: ; 52951 (14:6951)
+UnknownPrizeData:
; XXX what's this?
db $00,$01,$00,$01,$00,$01,$00,$00,$01
-HereYouGoTextPtr: ; 5295a (14:695a)
+HereYouGoTextPtr:
TX_FAR _HereYouGoText
- db $0D
+ TX_WAIT
db "@"
-SoYouWantPrizeTextPtr: ; 52960 (14:6960)
+SoYouWantPrizeTextPtr:
TX_FAR _SoYouWantPrizeText
db "@"
-SorryNeedMoreCoinsText: ; 52965 (14:6965)
+SorryNeedMoreCoinsText:
TX_FAR _SorryNeedMoreCoinsText
- db $0D
+ TX_WAIT
db "@"
-PrizeRoomBagIsFullTextPtr: ; 5296b (14:696b)
+PrizeRoomBagIsFullTextPtr:
TX_FAR _OopsYouDontHaveEnoughRoomText
- db $0D
+ TX_WAIT
db "@"
-OhFineThenTextPtr: ; 52971 (14:6971)
+OhFineThenTextPtr:
TX_FAR _OhFineThenText
- db $0D ; wait keypress (A/B) without blink
+ TX_WAIT
db "@"
-GetPrizeMonLevel: ; 52977 (14:6977)
+GetPrizeMonLevel:
ld a,[wcf91]
ld b,a
ld hl,PrizeMonLevelDictionary
-.loop ; 14:697E
+.loop
ld a,[hli]
cp b
jr z,.matchFound
inc hl
jr .loop
-.matchFound ; 14:6985
+.matchFound
ld a,[hl]
- ld [W_CURENEMYLVL],a
+ ld [wCurEnemyLVL],a
ret
INCLUDE "data/prize_mon_levels.asm"
diff --git a/engine/menu/start_menu.asm b/engine/menu/start_menu.asm
index da17822b..029d8c01 100755
--- a/engine/menu/start_menu.asm
+++ b/engine/menu/start_menu.asm
@@ -1,16 +1,16 @@
-DisplayStartMenu:: ; 2acd (0:2acd)
- ld a,$04 ; hardcoded Bank, not sure what's it refers to
+DisplayStartMenu::
+ ld a,BANK(StartMenu_Pokedex)
ld [H_LOADEDROMBANK],a
- ld [$2000],a ; ROM bank 4
+ ld [MBC1RomBank],a
ld a,[wWalkBikeSurfState] ; walking/biking/surfing
ld [wWalkBikeSurfStateCopy],a
- ld a, (SFX_02_3f - SFX_Headers_02) / 3 ; Start menu sound
+ ld a, SFX_START_MENU
call PlaySound
-RedisplayStartMenu:: ; 2adf (0:2adf)
+RedisplayStartMenu::
callba DrawStartMenu
callba PrintSafariZoneSteps ; print Safari Zone info, if in Safari Zone
- call UpdateSprites ; move sprites
+ call UpdateSprites
.loop
call HandleMenuInput
ld b,a
@@ -24,8 +24,7 @@ RedisplayStartMenu:: ; 2adf (0:2adf)
and a
jr nz,.loop
; if the player pressed tried to go past the top item, wrap around to the bottom
- ld a,[wd74b]
- bit 5,a ; does the player have the pokedex?
+ CheckEvent EVENT_GOT_POKEDEX
ld a,6 ; there are 7 menu items with the pokedex, so the max index is 6
jr nz,.wrapMenuItemId
dec a ; there are only 6 menu items without the pokedex
@@ -37,8 +36,7 @@ RedisplayStartMenu:: ; 2adf (0:2adf)
bit 7,a
jr z,.buttonPressed
; if the player pressed tried to go past the bottom item, wrap around to the top
- ld a,[wd74b]
- bit 5,a ; does the player have the pokedex?
+ CheckEvent EVENT_GOT_POKEDEX
ld a,[wCurrentMenuItem]
ld c,7 ; there are 7 menu items with the pokedex
jr nz,.checkIfPastBottom
@@ -54,13 +52,12 @@ RedisplayStartMenu:: ; 2adf (0:2adf)
.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
call SaveScreenTilesToBuffer2 ; copy background from wTileMap to wTileMapBackup2
- ld a,[wd74b]
- bit 5,a ; does the player have the pokedex?
+ CheckEvent EVENT_GOT_POKEDEX
ld a,[wCurrentMenuItem]
jr nz,.displayMenuItem
inc a ; adjust position to account for missing pokedex menu item
@@ -79,7 +76,7 @@ RedisplayStartMenu:: ; 2adf (0:2adf)
jp z,StartMenu_Option
; EXIT falls through to here
-CloseStartMenu:: ; 2b70 (0:2b70)
+CloseStartMenu::
call Joypad
ld a,[hJoyPressed]
bit 0,a ; was A button newly pressed?
diff --git a/engine/menu/start_sub_menus.asm b/engine/menu/start_sub_menus.asm
index 589224ab..251d7ae4 100755
--- a/engine/menu/start_sub_menus.asm
+++ b/engine/menu/start_sub_menus.asm
@@ -1,4 +1,4 @@
-StartMenu_Pokedex: ; 13095 (4:7095)
+StartMenu_Pokedex:
predef ShowPokedexMenu
call LoadScreenTilesFromBuffer2 ; restore saved screen
call Delay3
@@ -6,20 +6,20 @@ StartMenu_Pokedex: ; 13095 (4:7095)
call UpdateSprites
jp RedisplayStartMenu
-StartMenu_Pokemon: ; 130a9 (4:70a9)
+StartMenu_Pokemon:
ld a,[wPartyCount]
and a
jp z,RedisplayStartMenu
xor a
ld [wMenuItemToSwap],a
- ld [wd07d],a
+ ld [wPartyMenuTypeOrMessageID],a
ld [wUpdateSpritesEnabled],a
call DisplayPartyMenu
jr .checkIfPokemonChosen
.loop
xor a
ld [wMenuItemToSwap],a
- ld [wd07d],a
+ ld [wPartyMenuTypeOrMessageID],a
call GoBackToPartyMenu
.checkIfPokemonChosen
jr nc,.chosePokemon
@@ -33,14 +33,14 @@ StartMenu_Pokemon: ; 130a9 (4:70a9)
ld a,FIELD_MOVE_MON_MENU
ld [wTextBoxID],a
call DisplayTextBoxID ; display pokemon menu options
- ld hl,wWhichTrade
- ld bc,$020c ; max menu item ID, top menu item Y
+ ld hl,wFieldMoves
+ lb bc, 2, 12 ; max menu item ID, top menu item Y
ld e,5
.adjustMenuVariablesLoop
dec e
jr z,.storeMenuVariables
ld a,[hli]
- and a
+ and a ; end of field moves?
jr z,.storeMenuVariables
inc b
dec c
@@ -50,14 +50,14 @@ StartMenu_Pokemon: ; 130a9 (4:70a9)
ld hl,wTopMenuItemY
ld a,c
ld [hli],a ; top menu item Y
- ld a,[$fff7]
+ ld a,[hFieldMoveMonMenuTopMenuItemX]
ld [hli],a ; top menu item X
xor a
ld [hli],a ; current menu item ID
inc hl
ld a,b
ld [hli],a ; max menu item ID
- ld a,%00000011 ; A button, B button
+ ld a,A_BUTTON | B_BUTTON
ld [hli],a ; menu watched keys
xor a
ld [hl],a
@@ -81,22 +81,22 @@ StartMenu_Pokemon: ; 130a9 (4:70a9)
jp z,.choseStats
ld c,a
ld b,0
- ld hl,wWhichTrade
+ ld hl,wFieldMoves
add hl,bc
jp .choseOutOfBattleMove
.choseSwitch
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
- ld a,$04 ; swap pokemon positions menu
- ld [wd07d],a
+ call SwitchPartyMon_InitVarOrSwapData ; init [wMenuItemToSwap]
+ ld a,SWAP_MONS_PARTY_MENU
+ ld [wPartyMenuTypeOrMessageID],a
call GoBackToPartyMenu
jp .checkIfPokemonChosen
.choseStats
call ClearSprites
- xor a
- ld [wcc49],a
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation],a
predef StatusScreen
predef StatusScreen2
call ReloadMapData
@@ -117,7 +117,7 @@ StartMenu_Pokemon: ; 130a9 (4:70a9)
ld a,[hli]
ld h,[hl]
ld l,a
- ld a,[W_OBTAINEDBADGES] ; badges obtained
+ ld a,[wObtainedBadges] ; badges obtained
jp [hl]
.outOfBattleMovePointers
dw .cut
@@ -153,23 +153,23 @@ StartMenu_Pokemon: ; 130a9 (4:70a9)
bit 1,a ; does the player have the Cascade Badge?
jp z,.newBadgeRequired
predef UsedCut
- ld a,[wcd6a]
+ ld a,[wActionResultOrTookBattleTurn]
and a
jp z,.loop
jp CloseTextDisplay
.surf
bit 4,a ; does the player have the Soul Badge?
jp z,.newBadgeRequired
- callba CheckForForcedBikeSurf
+ callba IsSurfingAllowed
ld hl,wd728
bit 1,[hl]
res 1,[hl]
jp z,.loop
ld a,SURFBOARD
ld [wcf91],a
- ld [wd152],a
+ ld [wPseudoItemID],a
call UseItem
- ld a,[wcd6a]
+ ld a,[wActionResultOrTookBattleTurn]
and a
jp z,.loop
call GBPalWhiteOutWithDelay3
@@ -195,9 +195,9 @@ StartMenu_Pokemon: ; 130a9 (4:70a9)
.dig
ld a,ESCAPE_ROPE
ld [wcf91],a
- ld [wd152],a
+ ld [wPseudoItemID],a
call UseItem
- ld a,[wcd6a]
+ ld a,[wActionResultOrTookBattleTurn]
and a
jp z,.loop
call GBPalWhiteOutWithDelay3
@@ -222,7 +222,7 @@ StartMenu_Pokemon: ; 130a9 (4:70a9)
res 4,[hl]
ld c,60
call DelayFrames
- call GBPalWhiteOutWithDelay3 ; zero all three palettes and wait 3 V-blanks
+ call GBPalWhiteOutWithDelay3
jp .goBackToMap
.warpToLastPokemonCenterText
TX_FAR _WarpToLastPokemonCenterText
@@ -256,14 +256,14 @@ StartMenu_Pokemon: ; 130a9 (4:70a9)
ld a,[H_QUOTIENT + 2]
sbc b
jp nc,.notHealthyEnough
- ld a,[wcc2b]
+ ld a,[wPartyAndBillsPCSavedMenuItem]
push af
ld a,POTION
ld [wcf91],a
- ld [wd152],a
+ ld [wPseudoItemID],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
@@ -284,8 +284,8 @@ StartMenu_Pokemon: ; 130a9 (4:70a9)
db "@"
; writes a blank tile to all possible menu cursor positions on the party menu
-ErasePartyMenuCursors: ; 132ed (4:72ed)
- hlCoord 0, 1
+ErasePartyMenuCursors:
+ coord hl, 0, 1
ld bc,2 * 20 ; menu cursor positions are 2 rows apart
ld a,6 ; 6 menu cursor positions
.loop
@@ -295,11 +295,11 @@ ErasePartyMenuCursors: ; 132ed (4:72ed)
jr nz,.loop
ret
-ItemMenuLoop: ; 132fc (4:72fc)
+ItemMenuLoop:
call LoadScreenTilesFromBuffer2DisableBGTransfer ; restore saved screen
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
-StartMenu_Item: ; 13302 (4:7302)
+StartMenu_Item:
ld a,[wLinkState]
dec a ; is the player in the Colosseum or Trade Centre?
jr nz,.notInCableClubRoom
@@ -308,24 +308,24 @@ StartMenu_Item: ; 13302 (4:7302)
jr .exitMenu
.notInCableClubRoom
ld bc,wNumBagItems
- ld hl,wList
+ ld hl,wListPointer
ld a,c
ld [hli],a
- ld [hl],b ; store item bag pointer at wList (for DisplayListMenuID)
+ ld [hl],b ; store item bag pointer in wListPointer (for DisplayListMenuID)
xor a
- ld [wcf93],a
+ 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
call LoadTextBoxTilePatterns
- call UpdateSprites ; move sprites
+ call UpdateSprites
jp RedisplayStartMenu
.choseItem
; erase menu cursor (blank each tile in front of an item name)
@@ -354,7 +354,7 @@ StartMenu_Item: ; 13302 (4:7302)
inc hl
inc a ; a = 1
ld [hli],a ; max menu item ID
- ld a,%00000011 ; A button, B button
+ ld a,A_BUTTON | B_BUTTON
ld [hli],a ; menu watched keys
xor a
ld [hl],a ; old menu item id
@@ -381,8 +381,8 @@ StartMenu_Item: ; 13302 (4:7302)
ld a,[wCurrentMenuItem]
and a
jr nz,.tossItem
-.useItem
- ld [wd152],a
+; use item
+ ld [wPseudoItemID],a ; a must be 0 due to above conditional jump
ld a,[wcf91]
cp a,HM_01
jr nc,.useItem_partyMenu
@@ -399,9 +399,9 @@ StartMenu_Item: ; 13302 (4:7302)
jp ItemMenuLoop
.useItem_closeMenu
xor a
- ld [wd152],a
+ ld [wPseudoItemID],a
call UseItem
- ld a,[wcd6a]
+ ld a,[wActionResultOrTookBattleTurn]
and a
jp z,ItemMenuLoop
jp CloseStartMenu
@@ -409,7 +409,7 @@ StartMenu_Item: ; 13302 (4:7302)
ld a,[wUpdateSpritesEnabled]
push af
call UseItem
- ld a,[wcd6a]
+ ld a,[wActionResultOrTookBattleTurn]
cp a,$02
jp z,.partyMenuNotDisplayed
call GBPalWhiteOutWithDelay3
@@ -423,7 +423,7 @@ StartMenu_Item: ; 13302 (4:7302)
jp ItemMenuLoop
.tossItem
call IsKeyItem
- ld a,[wd124]
+ ld a,[wIsKeyItem]
and a
jr nz,.skipAskingQuantity
ld a,[wcf91]
@@ -438,16 +438,16 @@ StartMenu_Item: ; 13302 (4:7302)
.tossZeroItems
jp ItemMenuLoop
-CannotUseItemsHereText: ; 1342a (4:742a)
+CannotUseItemsHereText:
TX_FAR _CannotUseItemsHereText
db "@"
-CannotGetOffHereText: ; 1342f (4:742f)
+CannotGetOffHereText:
TX_FAR _CannotGetOffHereText
db "@"
; items which bring up the party menu when used
-UsableItems_PartyMenu: ; 13434 (4:7434)
+UsableItems_PartyMenu:
db MOON_STONE
db ANTIDOTE
db BURN_HEAL
@@ -487,7 +487,7 @@ UsableItems_PartyMenu: ; 13434 (4:7434)
db $ff
; items which close the item menu when used
-UsableItems_CloseMenu: ; 13459 (4:7459)
+UsableItems_CloseMenu:
db ESCAPE_ROPE
db ITEMFINDER
db POKE_FLUTE
@@ -496,24 +496,24 @@ UsableItems_CloseMenu: ; 13459 (4:7459)
db SUPER_ROD
db $ff
-StartMenu_TrainerInfo: ; 13460 (4:7460)
+StartMenu_TrainerInfo:
call GBPalWhiteOut
call ClearScreen
- call UpdateSprites ; move sprites
+ call UpdateSprites
ld a,[hTilesetType]
push af
xor a
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
@@ -521,39 +521,39 @@ StartMenu_TrainerInfo: ; 13460 (4:7460)
jp RedisplayStartMenu
; loads tile patterns and draws everything except for gym leader faces / badges
-DrawTrainerInfo: ; 1349a (4:749a)
+DrawTrainerInfo:
ld de,RedPicFront
- ld bc,(BANK(RedPicFront) << 8) | $01
- predef Predef3B
+ lb bc, BANK(RedPicFront), $01
+ predef DisplayPicCenteredOrUpperRight
call DisableLCD
- hlCoord 0, 2
+ coord hl, 0, 2
ld a," "
call TrainerInfo_DrawVerticalLine
- hlCoord 1, 2
+ coord hl, 1, 2
call TrainerInfo_DrawVerticalLine
ld hl,vChars2 + $70
ld de,vChars2
ld bc,$70 * 4
call CopyData
- ld hl,TrainerInfoTextBoxTileGraphics ; $7b98 ; trainer info text box tile patterns
+ ld hl,TrainerInfoTextBoxTileGraphics ; trainer info text box tile patterns
ld de,vChars2 + $770
ld bc,$0080
push bc
call TrainerInfo_FarCopyData
- ld hl,BlankLeaderNames ; $7c28
+ ld hl,BlankLeaderNames
ld de,vChars2 + $600
ld bc,$0170
call TrainerInfo_FarCopyData
pop bc
- ld hl,BadgeNumbersTileGraphics ; $7d98 ; badge number tile patterns
+ ld hl,BadgeNumbersTileGraphics ; badge number tile patterns
ld de,vChars1 + $580
call TrainerInfo_FarCopyData
- ld hl,GymLeaderFaceAndBadgeTileGraphics ; $6a9e ; gym leader face and badge tile patterns
+ ld hl,GymLeaderFaceAndBadgeTileGraphics ; gym leader face and badge tile patterns
ld de,vChars2 + $200
ld bc,$0400
ld a,$03
call FarCopyData2
- ld hl,TextBoxGraphics ; $6288
+ ld hl,TextBoxGraphics
ld de,$00d0
add hl,de ; hl = colon tile pattern
ld de,vChars1 + $560
@@ -562,80 +562,80 @@ DrawTrainerInfo: ; 1349a (4:749a)
push bc
call FarCopyData2
pop bc
- ld hl,TrainerInfoTextBoxTileGraphics + $80 ; $7c18 ; background tile pattern
+ ld hl,TrainerInfoTextBoxTileGraphics + $80 ; background tile pattern
ld de,vChars1 + $570
call TrainerInfo_FarCopyData
call EnableLCD
- ld hl,wWhichTrade
+ ld hl,wTrainerInfoTextBoxWidthPlus1
ld a,18 + 1
ld [hli],a
dec a
ld [hli],a
ld [hl],1
- hlCoord 0, 0
+ coord hl, 0, 0
call TrainerInfo_DrawTextBox
- ld hl,wWhichTrade
+ ld hl,wTrainerInfoTextBoxWidthPlus1
ld a,16 + 1
ld [hli],a
dec a
ld [hli],a
ld [hl],3
- hlCoord 1, 10
+ coord hl, 1, 10
call TrainerInfo_DrawTextBox
- hlCoord 0, 10
+ coord hl, 0, 10
ld a,$d7
call TrainerInfo_DrawVerticalLine
- hlCoord 19, 10
+ coord hl, 19, 10
call TrainerInfo_DrawVerticalLine
- hlCoord 6, 9
+ coord hl, 6, 9
ld de,TrainerInfo_BadgesText
call PlaceString
- hlCoord 2, 2
+ coord hl, 2, 2
ld de,TrainerInfo_NameMoneyTimeText
call PlaceString
- hlCoord 7, 2
+ coord hl, 7, 2
ld de,wPlayerName
call PlaceString
- hlCoord 8, 4
+ coord hl, 8, 4
ld de,wPlayerMoney
ld c,$e3
call PrintBCDNumber
- hlCoord 9, 6
- ld de,W_PLAYTIMEHOURS + 1 ; hours
- ld bc,$4103
+ coord hl, 9, 6
+ ld de,wPlayTimeHours ; hours
+ lb bc, LEFT_ALIGN | 1, 3
call PrintNumber
ld [hl],$d6 ; colon tile ID
inc hl
- ld de,W_PLAYTIMEMINUTES + 1 ; minutes
- ld bc,$8102
+ ld de,wPlayTimeMinutes ; minutes
+ lb bc, LEADING_ZEROES | 1, 2
jp PrintNumber
-TrainerInfo_FarCopyData: ; 1357f (4:757f)
- ld a,$0b
+TrainerInfo_FarCopyData:
+ ld a,BANK(TrainerInfoTextBoxTileGraphics)
jp FarCopyData2
-TrainerInfo_NameMoneyTimeText: ; 13584 (4:7584)
+TrainerInfo_NameMoneyTimeText:
db "NAME/"
next "MONEY/"
next "TIME/@"
; $76 is a circle tile
-TrainerInfo_BadgesText: ; 13597 (4:7597)
+TrainerInfo_BadgesText:
db $76,"BADGES",$76,"@"
; draws a text box on the trainer info screen
; 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
-TrainerInfo_DrawTextBox: ; 135a0 (4:75a0)
+; [wTrainerInfoTextBoxWidthPlus1] = width
+; [wTrainerInfoTextBoxWidth] = width - 1
+; [wTrainerInfoTextBoxNextRowOffset] = distance from the end of a text box row to the start of the next
+TrainerInfo_DrawTextBox:
ld a,$79 ; upper left corner tile ID
- ld de,$7a7b ; top edge and upper right corner tile ID's
+ lb de, $7a, $7b ; 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
@@ -647,11 +647,11 @@ TrainerInfo_DrawTextBox: ; 135a0 (4:75a0)
dec c
jr nz,.loop
ld a,$7d ; lower left corner tile ID
- ld de,$777e ; bottom edge and lower right corner tile ID's
+ lb de,$77, $7e ; bottom edge and lower right corner tile ID's
-TrainerInfo_DrawHorizontalEdge: ; 135c3 (4:75c3)
+TrainerInfo_DrawHorizontalEdge:
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
@@ -662,8 +662,8 @@ TrainerInfo_DrawHorizontalEdge: ; 135c3 (4:75c3)
ld [hl],a ; place right corner tile
ret
-TrainerInfo_NextTextBoxRow: ; 135d0 (4:75d0)
- ld a,[wTrainerFacingDirection] ; distance to the start of the next row
+TrainerInfo_NextTextBoxRow:
+ ld a,[wTrainerInfoTextBoxNextRowOffset] ; distance to the start of the next row
.loop
inc hl
dec a
@@ -674,8 +674,8 @@ TrainerInfo_NextTextBoxRow: ; 135d0 (4:75d0)
; INPUT:
; hl = address of top tile in the line
; a = tile ID
-TrainerInfo_DrawVerticalLine: ; 135d8 (4:75d8)
- ld de,20
+TrainerInfo_DrawVerticalLine:
+ ld de,SCREEN_WIDTH
ld c,8
.loop
ld [hl],a
@@ -684,7 +684,7 @@ TrainerInfo_DrawVerticalLine: ; 135d8 (4:75d8)
jr nz,.loop
ret
-StartMenu_SaveReset: ; 135e3 (4:75e3)
+StartMenu_SaveReset:
ld a,[wd72e]
bit 6,a ; is the player using the link feature?
jp nz,Init
@@ -692,7 +692,7 @@ StartMenu_SaveReset: ; 135e3 (4:75e3)
call LoadScreenTilesFromBuffer2 ; restore saved screen
jp HoldTextDisplayOpen
-StartMenu_Option: ; 135f6 (4:75f6)
+StartMenu_Option:
xor a
ld [H_AUTOBGTRANSFERENABLED],a
call ClearScreen
@@ -703,63 +703,66 @@ StartMenu_Option: ; 135f6 (4:75f6)
call UpdateSprites
jp RedisplayStartMenu
-SwitchPartyMon: ; 13613 (4:7613)
- call SwitchPartyMon_Stats
- ld a, [wWhichTrade] ; wWhichTrade
- call SwitchPartyMon_OAM
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
- call SwitchPartyMon_OAM
+SwitchPartyMon:
+ call SwitchPartyMon_InitVarOrSwapData ; swap data
+ ld a, [wSwappedMenuItem]
+ call SwitchPartyMon_ClearGfx
+ ld a, [wCurrentMenuItem]
+ call SwitchPartyMon_ClearGfx
jp RedrawPartyMenu_
-SwitchPartyMon_OAM: ; 13625 (4:7625)
+SwitchPartyMon_ClearGfx:
push af
- ld hl, wTileMap
- ld bc, $28
+ coord hl, 0, 0
+ ld bc, SCREEN_WIDTH * 2
call AddNTimes
- ld c, $28
- ld a, $7f
-.asm_13633
+ ld c, SCREEN_WIDTH * 2
+ ld a, " "
+.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
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
+ ld a, SFX_SWAP
jp PlaySound
-SwitchPartyMon_Stats: ; 13653 (4:7653)
+SwitchPartyMon_InitVarOrSwapData:
+; This is used to initialise [wMenuItemToSwap] and to actually swap the data.
ld a, [wMenuItemToSwap]
- and a
- jr nz, .asm_13661
- ld a, [wWhichPokemon] ; wWhichPokemon
- inc a
+ 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 ; [wMenuItemToSwap] counts from 1
ld [wMenuItemToSwap], a
ret
-.asm_13661
+.pickedMonsToSwap
xor a
- ld [wd07d], a
+ ld [wPartyMenuTypeOrMessageID], a
ld a, [wMenuItemToSwap]
dec a
ld b, a
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
- ld [wWhichTrade], a ; wWhichTrade
- cp b
- jr nz, .asm_1367b
+ ld a, [wCurrentMenuItem]
+ 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 [wd07d], a
+ ld [wPartyMenuTypeOrMessageID], a
ret
-.asm_1367b
+.swappingDifferentMons
ld a, b
ld [wMenuItemToSwap], a
push hl
@@ -767,85 +770,85 @@ SwitchPartyMon_Stats: ; 13653 (4:7653)
ld hl, wPartySpecies
ld d, h
ld e, l
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
+ 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 ; $ff95 (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
+ ld [hSwapTemp], a
ld a, [de]
ld [hl], a
- ld a, [H_DIVIDEND] ; $ff95 (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
+ ld a, [hSwapTemp]
ld [de], a
ld hl, wPartyMons
ld bc, wPartyMon2 - wPartyMon1
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
+ ld a, [wCurrentMenuItem]
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 ; wd273
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
+ ld hl, wPartyMonOT
+ ld a, [wCurrentMenuItem]
call SkipFixedLengthTextEntries
push hl
ld de, wSwitchPartyMonTempBuffer
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
- ld hl, wPartyMonOT ; wd273
+ ld hl, wPartyMonOT
ld a, [wMenuItemToSwap]
call SkipFixedLengthTextEntries
pop de
push hl
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
pop de
ld hl, wSwitchPartyMonTempBuffer
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
- ld hl, wPartyMonNicks ; wPartyMonNicks
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
+ ld hl, wPartyMonNicks
+ ld a, [wCurrentMenuItem]
call SkipFixedLengthTextEntries
push hl
ld de, wSwitchPartyMonTempBuffer
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
- ld hl, wPartyMonNicks ; wPartyMonNicks
+ ld hl, wPartyMonNicks
ld a, [wMenuItemToSwap]
call SkipFixedLengthTextEntries
pop de
push hl
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
pop de
ld hl, wSwitchPartyMonTempBuffer
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
ld a, [wMenuItemToSwap]
- ld [wWhichTrade], a ; wWhichTrade
+ ld [wSwappedMenuItem], a
xor a
ld [wMenuItemToSwap], a
- ld [wd07d], a
+ ld [wPartyMenuTypeOrMessageID], a
pop de
pop hl
ret
diff --git a/engine/menu/status_screen.asm b/engine/menu/status_screen.asm
index b5254694..ef94f13c 100755
--- a/engine/menu/status_screen.asm
+++ b/engine/menu/status_screen.asm
@@ -1,15 +1,15 @@
-DrawHP: ; 128ef (4:68ef)
+DrawHP:
; Draws the HP bar in the stats screen
call GetPredefRegisters
ld a, $1
jr DrawHP_
-DrawHP2: ; 128f6 (4:68f6)
+DrawHP2:
; Draws the HP bar in the party screen
call GetPredefRegisters
ld a, $2
-DrawHP_: ; 128fb (4:68fb)
+DrawHP_:
ld [wHPBarType], a
push hl
ld a, [wLoadedMonHP]
@@ -50,12 +50,12 @@ DrawHP_: ; 128fb (4:68fb)
.printFraction
add hl, bc
ld de, wLoadedMonHP
- ld bc, $203
+ lb bc, 2, 3
call PrintNumber
ld a, "/"
ld [hli], a
ld de, wLoadedMonMaxHP
- ld bc, $203
+ lb bc, 2, 3
call PrintNumber
pop hl
pop de
@@ -63,14 +63,15 @@ DrawHP_: ; 128fb (4:68fb)
; Predef 0x37
-StatusScreen: ; 12953 (4:6953)
+StatusScreen:
call LoadMonData
- ld a, [wcc49]
- cp $2 ; 2 means we're in a PC box
- jr c, .DontRecalculate ; 0x1295b $14
+ 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
+ ld [wCurEnemyLVL], a
ld hl, wLoadedMonHPExp - 1
ld de, wLoadedMonStats
ld b, $1
@@ -79,95 +80,95 @@ StatusScreen: ; 12953 (4:6953)
ld hl, wd72c
set 1, [hl]
ld a, $33
- ld [$ff24], a ; Reduce the volume
+ ld [rNR50], a ; Reduce the volume
call GBPalWhiteOutWithDelay3
call ClearScreen
- call UpdateSprites ; move sprites (?)
+ call UpdateSprites
call LoadHpBarAndStatusTilePatterns
- ld de, BattleHudTiles1 ; $6080 ; source
+ ld de, BattleHudTiles1 ; source
ld hl, vChars2 + $6d0 ; dest
- ld bc, (BANK(BattleHudTiles1) << 8) + $03 ; bank bytes/8
+ lb bc, BANK(BattleHudTiles1), $03
call CopyVideoDataDouble ; ·│ :L and halfarrow line end
- ld de, BattleHudTiles2 ; $6098
+ ld de, BattleHudTiles2
ld hl, vChars2 + $780
- ld bc, (BANK(BattleHudTiles2) << 8) + $01
+ lb bc, BANK(BattleHudTiles2), $01
call CopyVideoDataDouble ; │
- ld de, BattleHudTiles3 ; $60b0
+ ld de, BattleHudTiles3
ld hl, vChars2 + $760
- ld bc, (BANK(BattleHudTiles3) << 8) + $02
+ lb bc, BANK(BattleHudTiles3), $02
call CopyVideoDataDouble ; ─┘
ld de, PTile
ld hl, vChars2 + $720
- ld bc,(BANK(PTile) << 8 | $01)
+ lb bc, BANK(PTile), (PTileEnd - PTile) / $8
call CopyVideoDataDouble ; P (for PP), inline
ld a, [hTilesetType]
push af
xor a
ld [hTilesetType], a
- hlCoord 19, 1
- ld bc, $060a
+ coord hl, 19, 1
+ lb bc, 6, 10
call DrawLineBox ; Draws the box around name, HP and status
- ld de, $fffa
+ ld de, -6
add hl, de
- ld [hl], $f2 ; . after No ("." is a different one)
+ ld [hl], "⠄" ; . after No ("." is a different one)
dec hl
ld [hl], "№"
- hlCoord 19, 9
- ld bc, $0806
+ coord hl, 19, 9
+ lb bc, 8, 6
call DrawLineBox ; Draws the box around types, ID No. and OT
- hlCoord 10, 9
+ coord hl, 10, 9
ld de, Type1Text
call PlaceString ; "TYPE1/"
- hlCoord 11, 3
+ coord hl, 11, 3
predef DrawHP
- ld hl, wcf25
+ ld hl, wStatusScreenHPBarColor
call GetHealthBarColor
- ld b, $3
- call GoPAL_SET ; SGB palette
- hlCoord 16, 6
+ ld b, SET_PAL_STATUS_SCREEN
+ call RunPaletteCommand
+ coord hl, 16, 6
ld de, wLoadedMonStatus
call PrintStatusCondition
- jr nz, .StatusWritten ; 0x129fc $9
- hlCoord 16, 6
+ jr nz, .StatusWritten
+ coord hl, 16, 6
ld de, OKText
call PlaceString ; "OK"
.StatusWritten
- hlCoord 9, 6
+ coord hl, 9, 6
ld de, StatusText
call PlaceString ; "STATUS/"
- hlCoord 14, 2
+ coord hl, 14, 2
call PrintLevel ; Pokémon level
- ld a, [W_MONHDEXNUM]
+ ld a, [wMonHIndex]
ld [wd11e], a
ld [wd0b5], a
predef IndexToPokedex
- hlCoord 3, 7
+ coord hl, 3, 7
ld de, wd11e
- ld bc, $8103 ; Zero-padded, 3
+ lb bc, LEADING_ZEROES | 1, 3
call PrintNumber ; Pokémon no.
- hlCoord 11, 10
+ coord hl, 11, 10
predef PrintMonType
- ld hl, NamePointers2 ; $6a9d
- call .unk_12a7e
+ ld hl, NamePointers2
+ call .GetStringPointer
ld d, h
ld e, l
- hlCoord 9, 1
+ coord hl, 9, 1
call PlaceString ; Pokémon name
- ld hl, OTPointers ; $6a95
- call .unk_12a7e
+ ld hl, OTPointers
+ call .GetStringPointer
ld d, h
ld e, l
- hlCoord 12, 16
+ coord hl, 12, 16
call PlaceString ; OT
- hlCoord 12, 14
+ coord hl, 12, 14
ld de, wLoadedMonOTID
- ld bc, $8205 ; 5
+ lb bc, LEADING_ZEROES | 2, 5
call PrintNumber ; ID Number
ld d, $0
call PrintStatsBox
call Delay3
call GBPalNormal
- hlCoord 1, 0
+ coord hl, 1, 0
call LoadFlippedFrontSpriteByMonIndex ; draw Pokémon picture
ld a, [wcf91]
call PlayCry ; play Pokémon cry
@@ -175,89 +176,92 @@ StatusScreen: ; 12953 (4:6953)
pop af
ld [hTilesetType], a
ret
-.unk_12a7e ; 0x12a7e ; 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
-OTPointers: ; 12a95 (4:6a95)
+OTPointers:
dw wPartyMonOT
dw wEnemyMonOT
dw wBoxMonOT
- dw W_DAYCAREMONOT
+ dw wDayCareMonOT
-NamePointers2: ; 12a9d (4:6a9d)
+NamePointers2:
dw wPartyMonNicks
dw wEnemyMonNicks
dw wBoxMonNicks
- dw W_DAYCAREMONNAME
+ dw wDayCareMonName
-Type1Text: ; 12aa5 (4:6aa5)
+Type1Text:
db "TYPE1/", $4e
-Type2Text: ; 12aac (4:6aac)
+Type2Text:
db "TYPE2/", $4e
-IDNoText: ; 12ab3 (4:6ab3)
- db $73, "№", "/", $4e
+IDNoText:
+ db $73, "№/", $4e
-OTText: ; 12ab7 (4:6ab7)
- db "OT/", $4e, "@"
+OTText:
+ db "OT/"
+ next "@"
-StatusText: ; 12abc (4:6abc)
+StatusText:
db "STATUS/@"
-OKText: ; 12ac4 (4:6ac4)
+OKText:
db "OK@"
; Draws a line starting from hl high b and wide c
-DrawLineBox ; 0x12ac7
- ld de, $0014 ; New line
+DrawLineBox:
+ ld de, SCREEN_WIDTH ; New line
.PrintVerticalLine
ld [hl], $78 ; │
add hl, de
dec b
- jr nz, .PrintVerticalLine ; 0x12ace $fa
+ jr nz, .PrintVerticalLine
ld [hl], $77 ; ┘
dec hl
.PrintHorizLine
ld [hl], $76 ; ─
dec hl
dec c
- jr nz, .PrintHorizLine ; 0x12ad7 $fa
+ jr nz, .PrintHorizLine
ld [hl], $6f ; ← (halfarrow ending)
ret
-PTile: ; 12adc (4:6adc) ; This is a single 1bpp "P" tile
+PTile: ; This is a single 1bpp "P" tile
INCBIN "gfx/p_tile.1bpp"
+PTileEnd:
-PrintStatsBox: ; 12ae4 (4:6ae4)
+PrintStatsBox:
ld a, d
and a ; a is 0 from the status screen
- jr nz, .DifferentBox ; 0x12ae6 $12
- hlCoord 0, 8
- ld b, $8
- ld c, $8
+ jr nz, .DifferentBox
+ coord hl, 0, 8
+ ld b, 8
+ ld c, 8
call TextBoxBorder ; Draws the box
- hlCoord 1, 9 ; Start printing stats from here
+ coord hl, 1, 9 ; Start printing stats from here
ld bc, $0019 ; Number offset
- jr .PrintStats ; 0x12af8 $10
+ jr .PrintStats
.DifferentBox
- hlCoord 9, 2
- ld b, $8
- ld c, $9
+ coord hl, 9, 2
+ ld b, 8
+ ld c, 9
call TextBoxBorder
- hlCoord 11, 3
+ coord hl, 11, 3
ld bc, $0018
.PrintStats
push bc
@@ -268,7 +272,7 @@ PrintStatsBox: ; 12ae4 (4:6ae4)
pop bc
add hl, bc
ld de, wLoadedMonAttack
- ld bc, $0203 ; three digits
+ lb bc, 2, 3
call PrintStat
ld de, wLoadedMonDefense
call PrintStat
@@ -276,27 +280,27 @@ PrintStatsBox: ; 12ae4 (4:6ae4)
call PrintStat
ld de, wLoadedMonSpecial
jp PrintNumber
-PrintStat
+PrintStat:
push hl
call PrintNumber
pop hl
- ld de, $0028
+ ld de, SCREEN_WIDTH * 2
add hl, de
ret
-StatsText: ; 12b3a (4:6b3a)
+StatsText:
db "ATTACK"
next "DEFENSE"
next "SPEED"
next "SPECIAL@"
-StatusScreen2: ; 12b57 (4:6b57)
+StatusScreen2:
ld a, [hTilesetType]
push af
xor a
ld [hTilesetType], a
- ld [$ffba], a
- ld bc, $0005
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld bc, NUM_MOVES + 1
ld hl, wMoves
call FillMemory
ld hl, wLoadedMonMoves
@@ -304,42 +308,42 @@ StatusScreen2: ; 12b57 (4:6b57)
ld bc, NUM_MOVES
call CopyData
callab FormatMovesString
- hlCoord 9, 2
- ld bc, $050a
+ coord hl, 9, 2
+ lb bc, 5, 10
call ClearScreenArea ; Clear under name
- hlCoord 19, 3
+ coord hl, 19, 3
ld [hl], $78
- hlCoord 0, 8
- ld b, $8
- ld c, $12
+ coord hl, 0, 8
+ ld b, 8
+ ld c, 18
call TextBoxBorder ; Draw move container
- hlCoord 2, 9
+ coord hl, 2, 9
ld de, wMovesString
call PlaceString ; Print moves
- ld a, [wcd6c]
+ ld a, [wNumMovesMinusOne]
inc a
ld c, a
ld a, $4
sub c
ld b, a ; Number of moves ?
- hlCoord 11, 10
- ld de, $0028
- ld a, $72
- call Func_12ccb ; Print "PP"
+ coord hl, 11, 10
+ ld de, SCREEN_WIDTH * 2
+ ld a, $72 ; special P tile id
+ call StatusScreen_PrintPP ; Print "PP"
ld a, b
and a
- jr z, .InitPP ; 0x12bb3 $6
+ jr z, .InitPP
ld c, a
ld a, "-"
- call Func_12ccb ; Fill the rest with --
-.InitPP ; 12bbb
+ call StatusScreen_PrintPP ; Fill the rest with --
+.InitPP
ld hl, wLoadedMonMoves
- deCoord 14, 10
- ld b, $0
-.PrintPP ; 12bc3
+ coord de, 14, 10
+ ld b, 0
+.PrintPP
ld a, [hli]
and a
- jr z, .PPDone ; 0x12bc5 $4a
+ jr z, .PPDone
push bc
push hl
push de
@@ -356,24 +360,24 @@ StatusScreen2: ; 12b57 (4:6b57)
pop de
pop hl
push hl
- ld bc, $0014
+ ld bc, wPartyMon1PP - wPartyMon1Moves - 1
add hl, bc
ld a, [hl]
and $3f
- ld [wcd71], a
+ ld [wStatusScreenCurrentPP], a
ld h, d
ld l, e
push hl
- ld de, wcd71
- ld bc, $0102
+ ld de, wStatusScreenCurrentPP
+ lb bc, 1, 2
call PrintNumber
ld a, "/"
ld [hli], a
- ld de, wd11e
- ld bc, $0102
+ ld de, wMaxPP
+ lb bc, 1, 2
call PrintNumber
pop hl
- ld de, $0028
+ ld de, SCREEN_WIDTH * 2
add hl, de
ld d, h
ld e, l
@@ -382,19 +386,19 @@ StatusScreen2: ; 12b57 (4:6b57)
inc b
ld a, b
cp $4
- jr nz, .PrintPP ; 0x12c0f $b2
+ jr nz, .PrintPP
.PPDone
- hlCoord 9, 3
- ld de, EXPPointsText
+ coord hl, 9, 3
+ ld de, StatusScreenExpText
call PlaceString
- ld a, [wLoadedMonLevel] ; level
+ ld a, [wLoadedMonLevel]
push af
cp MAX_LEVEL
- jr z, .Level100 ; 0x12c20 $4
+ jr z, .Level100
inc a
ld [wLoadedMonLevel], a ; Increase temporarily if not 100
.Level100
- hlCoord 14, 6
+ coord hl, 14, 6
ld [hl], $70 ; 1-tile "to"
inc hl
inc hl
@@ -402,25 +406,25 @@ StatusScreen2: ; 12b57 (4:6b57)
pop af
ld [wLoadedMonLevel], a
ld de, wLoadedMonExp
- hlCoord 12, 4
- ld bc, $0307
+ coord hl, 12, 4
+ lb bc, 3, 7
call PrintNumber ; exp
- call .asm_12c86
+ call CalcExpToLevelUp
ld de, wLoadedMonExp
- hlCoord 7, 6
- ld bc, $0307
- call PrintNumber
- hlCoord 9, 0
- call Func_12cc3
- hlCoord 9, 1
- call Func_12cc3
- ld a, [W_MONHDEXNUM]
+ coord hl, 7, 6
+ lb bc, 3, 7
+ call PrintNumber ; exp needed to level up
+ coord hl, 9, 0
+ call StatusScreen_ClearName
+ coord hl, 9, 1
+ call StatusScreen_ClearName
+ ld a, [wMonHIndex]
ld [wd11e], a
call GetMonName
- hlCoord 9, 1
+ coord hl, 9, 1
call PlaceString
ld a, $1
- ld [$ffba], a
+ ld [H_AUTOBGTRANSFERENABLED], a
call Delay3
call WaitForTextScrollButtonPress ; wait for button
pop af
@@ -428,28 +432,29 @@ StatusScreen2: ; 12b57 (4:6b57)
ld hl, wd72c
res 1, [hl]
ld a, $77
- ld [$ff24], a
+ ld [rNR50], a
call GBPalWhiteOut
jp ClearScreen
-.asm_12c86 ; This does some magic with lvl/exp?
- ld a, [wLoadedMonLevel] ; Load level
+
+CalcExpToLevelUp:
+ ld a, [wLoadedMonLevel]
cp MAX_LEVEL
- jr z, .asm_12ca7 ; 0x12c8b $1a ; If 100
+ jr z, .atMaxLevel
inc a
ld d, a
callab CalcExperience
ld hl, wLoadedMonExp + 2
- ld a, [$ff98]
+ ld a, [hExperience + 2]
sub [hl]
ld [hld], a
- ld a, [$ff97]
+ ld a, [hExperience + 1]
sbc [hl]
ld [hld], a
- ld a, [$ff96]
+ ld a, [hExperience]
sbc [hl]
ld [hld], a
ret
-.asm_12ca7
+.atMaxLevel
ld hl, wLoadedMonExp
xor a
ld [hli], a
@@ -457,21 +462,20 @@ StatusScreen2: ; 12b57 (4:6b57)
ld [hl], a
ret
-EXPPointsText: ; 12caf (4:6caf)
- db "EXP POINTS", $4e
-
-LevelUpText: ; 12cba (4:6cba)
- db "LEVEL UP@"
+StatusScreenExpText:
+ db "EXP POINTS"
+ next "LEVEL UP@"
-Func_12cc3: ; 12cc3 (4:6cc3)
- ld bc, $a
- ld a, $7f
+StatusScreen_ClearName:
+ ld bc, 10
+ ld a, " "
jp FillMemory
-Func_12ccb: ; 12ccb (4:6ccb)
+StatusScreen_PrintPP:
+; print PP or -- c times, going down two rows each time
ld [hli], a
ld [hld], a
add hl, de
dec c
- jr nz, Func_12ccb
+ jr nz, StatusScreen_PrintPP
ret
diff --git a/engine/menu/swap_items.asm b/engine/menu/swap_items.asm
new file mode 100644
index 00000000..b1fa78be
--- /dev/null
+++ b/engine/menu/swap_items.asm
@@ -0,0 +1,149 @@
+HandleItemListSwapping:
+ ld a,[wListMenuID]
+ cp a,ITEMLISTMENU
+ jp nz,DisplayListMenuIDLoop ; only rearrange item list menus
+ push hl
+ ld hl,wListPointer
+ ld a,[hli]
+ ld h,[hl]
+ ld l,a
+ inc hl ; hl = beginning of list entries
+ ld a,[wCurrentMenuItem]
+ ld b,a
+ ld a,[wListScrollOffset]
+ add b
+ add a
+ ld c,a
+ ld b,0
+ add hl,bc ; hl = address of currently selected item entry
+ ld a,[hl]
+ pop hl
+ inc a
+ jp z,DisplayListMenuIDLoop ; ignore attempts to swap the Cancel menu item
+ ld a,[wMenuItemToSwap] ; ID of item chosen for swapping (counts from 1)
+ and a ; has the first item to swap already been chosen?
+ jr nz,.swapItems
+; if not, set the currently selected item as the first item
+ ld a,[wCurrentMenuItem]
+ inc a
+ ld b,a
+ ld a,[wListScrollOffset] ; index of top (visible) menu item within the list
+ add b
+ ld [wMenuItemToSwap],a ; ID of item chosen for swapping (counts from 1)
+ ld c,20
+ call DelayFrames
+ jp DisplayListMenuIDLoop
+.swapItems
+ ld a,[wCurrentMenuItem]
+ inc a
+ ld b,a
+ ld a,[wListScrollOffset]
+ add b
+ ld b,a
+ ld a,[wMenuItemToSwap] ; ID of item chosen for swapping (counts from 1)
+ cp b ; is the currently selected item the same as the first item to swap?
+ jp z,DisplayListMenuIDLoop ; ignore attempts to swap an item with itself
+ dec a
+ ld [wMenuItemToSwap],a ; ID of item chosen for swapping (counts from 1)
+ ld c,20
+ call DelayFrames
+ push hl
+ push de
+ ld hl,wListPointer
+ ld a,[hli]
+ ld h,[hl]
+ ld l,a
+ inc hl ; hl = beginning of list entries
+ ld d,h
+ ld e,l ; de = beginning of list entries
+ ld a,[wCurrentMenuItem]
+ ld b,a
+ ld a,[wListScrollOffset]
+ add b
+ add a
+ ld c,a
+ ld b,0
+ add hl,bc ; hl = address of currently selected item entry
+ ld a,[wMenuItemToSwap] ; ID of item chosen for swapping (counts from 1)
+ add a
+ add e
+ ld e,a
+ jr nc,.noCarry
+ inc d
+.noCarry ; de = address of first item to swap
+ ld a,[de]
+ ld b,a
+ ld a,[hli]
+ cp b
+ jr z,.swapSameItemType
+.swapDifferentItems
+ ld [$ff95],a ; [$ff95] = second item ID
+ ld a,[hld]
+ ld [$ff96],a ; [$ff96] = second item quantity
+ ld a,[de]
+ ld [hli],a ; put first item ID in second item slot
+ inc de
+ ld a,[de]
+ ld [hl],a ; put first item quantity in second item slot
+ ld a,[$ff96]
+ ld [de],a ; put second item quantity in first item slot
+ dec de
+ ld a,[$ff95]
+ ld [de],a ; put second item ID in first item slot
+ xor a
+ ld [wMenuItemToSwap],a ; 0 means no item is currently being swapped
+ pop de
+ pop hl
+ jp DisplayListMenuIDLoop
+.swapSameItemType
+ inc de
+ ld a,[hl]
+ ld b,a
+ ld a,[de]
+ add b ; a = sum of both item quantities
+ cp a,100 ; is the sum too big for one item slot?
+ jr c,.combineItemSlots
+; swap enough items from the first slot to max out the second slot if they can't be combined
+ sub a,99
+ ld [de],a
+ ld a,99
+ ld [hl],a
+ jr .done
+.combineItemSlots
+ ld [hl],a ; put the sum in the second item slot
+ ld hl,wListPointer
+ ld a,[hli]
+ ld h,[hl]
+ ld l,a
+ dec [hl] ; decrease the number of items
+ ld a,[hl]
+ ld [wListCount],a ; update number of items variable
+ cp a,1
+ jr nz,.skipSettingMaxMenuItemID
+ ld [wMaxMenuItem],a ; if the number of items is only one now, update the max menu item ID
+.skipSettingMaxMenuItemID
+ dec de
+ ld h,d
+ ld l,e
+ inc hl
+ inc hl ; hl = address of item after first item to swap
+.moveItemsUpLoop ; erase the first item slot and move up all the following item slots to fill the gap
+ ld a,[hli]
+ ld [de],a
+ inc de
+ inc a ; reached the $ff terminator?
+ jr z,.afterMovingItemsUp
+ ld a,[hli]
+ ld [de],a
+ inc de
+ jr .moveItemsUpLoop
+.afterMovingItemsUp
+ xor a
+ ld [wListScrollOffset],a
+ ld [wCurrentMenuItem],a
+.done
+ xor a
+ ld [wMenuItemToSwap],a ; 0 means no item is currently being swapped
+ pop de
+ pop hl
+ jp DisplayListMenuIDLoop
diff --git a/engine/menu/text_box.asm b/engine/menu/text_box.asm
new file mode 100644
index 00000000..12067dd4
--- /dev/null
+++ b/engine/menu/text_box.asm
@@ -0,0 +1,767 @@
+; function to draw various text boxes
+DisplayTextBoxID_:
+ ld a,[wTextBoxID]
+ cp a,TWO_OPTION_MENU
+ jp z,DisplayTwoOptionMenu
+ ld c,a
+ ld hl,TextBoxFunctionTable
+ ld de,3
+ call SearchTextBoxTable
+ jr c,.functionTableMatch
+ ld hl,TextBoxCoordTable
+ ld de,5
+ call SearchTextBoxTable
+ jr c,.coordTableMatch
+ ld hl,TextBoxTextAndCoordTable
+ ld de,9
+ call SearchTextBoxTable
+ jr c,.textAndCoordTableMatch
+.done
+ ret
+.functionTableMatch
+ ld a,[hli]
+ ld h,[hl]
+ ld l,a ; hl = address of function
+ ld de,.done
+ push de
+ jp [hl] ; jump to the function
+.coordTableMatch
+ call GetTextBoxIDCoords
+ call GetAddressOfScreenCoords
+ call TextBoxBorder
+ ret
+.textAndCoordTableMatch
+ call GetTextBoxIDCoords
+ push hl
+ call GetAddressOfScreenCoords
+ call TextBoxBorder
+ pop hl
+ call GetTextBoxIDText
+ ld a,[wd730]
+ push af
+ ld a,[wd730]
+ set 6,a ; no pauses between printing each letter
+ ld [wd730],a
+ call PlaceString
+ pop af
+ ld [wd730],a
+ call UpdateSprites
+ ret
+
+; function to search a table terminated with $ff for a byte matching c in increments of de
+; sets carry flag if a match is found and clears carry flag if not
+SearchTextBoxTable:
+ dec de
+.loop
+ ld a,[hli]
+ cp a,$ff
+ jr z,.notFound
+ cp c
+ jr z,.found
+ add hl,de
+ jr .loop
+.found
+ scf
+.notFound
+ ret
+
+; function to load coordinates from the TextBoxCoordTable or the TextBoxTextAndCoordTable
+; INPUT:
+; hl = address of coordinates
+; OUTPUT:
+; b = height
+; c = width
+; d = row of upper left corner
+; e = column of upper left corner
+GetTextBoxIDCoords:
+ ld a,[hli] ; column of upper left corner
+ ld e,a
+ ld a,[hli] ; row of upper left corner
+ ld d,a
+ ld a,[hli] ; column of lower right corner
+ sub e
+ dec a
+ ld c,a ; c = width
+ ld a,[hli] ; row of lower right corner
+ sub d
+ dec a
+ ld b,a ; b = height
+ ret
+
+; function to load a text address and text coordinates from the TextBoxTextAndCoordTable
+GetTextBoxIDText:
+ ld a,[hli]
+ ld e,a
+ ld a,[hli]
+ ld d,a ; de = address of text
+ push de ; save text address
+ ld a,[hli]
+ ld e,a ; column of upper left corner of text
+ ld a,[hl]
+ ld d,a ; row of upper left corner of text
+ call GetAddressOfScreenCoords
+ pop de ; restore text address
+ ret
+
+; function to point hl to the screen coordinates
+; INPUT:
+; d = row
+; e = column
+; OUTPUT:
+; hl = address of upper left corner of text box
+GetAddressOfScreenCoords:
+ push bc
+ coord hl, 0, 0
+ ld bc,20
+.loop ; loop to add d rows to the base address
+ ld a,d
+ and a
+ jr z,.addedRows
+ add hl,bc
+ dec d
+ jr .loop
+.addedRows
+ pop bc
+ add hl,de
+ ret
+
+; Format:
+; 00: text box ID
+; 01-02: function address
+TextBoxFunctionTable:
+ dbw MONEY_BOX, DisplayMoneyBox
+ dbw BUY_SELL_QUIT_MENU, DoBuySellQuitMenu
+ dbw FIELD_MOVE_MON_MENU, DisplayFieldMoveMonMenu
+ db $ff ; terminator
+
+; Format:
+; 00: text box ID
+; 01: column of upper left corner
+; 02: row of upper left corner
+; 03: column of lower right corner
+; 04: row of lower right corner
+TextBoxCoordTable:
+ db MESSAGE_BOX, 0, 12, 19, 17
+ db $03, 0, 0, 19, 14
+ db $07, 0, 0, 11, 6
+ db LIST_MENU_BOX, 4, 2, 19, 12
+ db $10, 7, 0, 19, 17
+ db MON_SPRITE_POPUP, 6, 4, 14, 13
+ db $ff ; terminator
+
+; Format:
+; 00: text box ID
+; 01: column of upper left corner
+; 02: row of upper left corner
+; 03: column of lower right corner
+; 04: row of lower right corner
+; 05-06: address of text
+; 07: column of beginning of text
+; 08: row of beginning of text
+; table of window positions and corresponding text [key, start column, start row, end column, end row, text pointer [2 bytes], text column, text row]
+TextBoxTextAndCoordTable:
+ db JP_MOCHIMONO_MENU_TEMPLATE
+ db 0,0,14,17 ; text box coordinates
+ dw JapaneseMochimonoText
+ db 3,0 ; text coordinates
+
+ db USE_TOSS_MENU_TEMPLATE
+ db 13,10,19,14 ; text box coordinates
+ dw UseTossText
+ db 15,11 ; text coordinates
+
+ db JP_SAVE_MESSAGE_MENU_TEMPLATE
+ db 0,0,7,5 ; text box coordinates
+ dw JapaneseSaveMessageText
+ db 2,2 ; text coordinates
+
+ db JP_SPEED_OPTIONS_MENU_TEMPLATE
+ db 0,6,5,10 ; text box coordinates
+ dw JapaneseSpeedOptionsText
+ db 2,7 ; text coordinates
+
+ db BATTLE_MENU_TEMPLATE
+ db 8,12,19,17 ; text box coordinates
+ dw BattleMenuText
+ db 10,14 ; text coordinates
+
+ db SAFARI_BATTLE_MENU_TEMPLATE
+ db 0,12,19,17 ; text box coordinates
+ dw SafariZoneBattleMenuText
+ db 2,14 ; text coordinates
+
+ db SWITCH_STATS_CANCEL_MENU_TEMPLATE
+ db 11,11,19,17 ; text box coordinates
+ dw SwitchStatsCancelText
+ db 13,12 ; text coordinates
+
+ db BUY_SELL_QUIT_MENU_TEMPLATE
+ db 0,0,10,6 ; text box coordinates
+ dw BuySellQuitText
+ db 2,1 ; text coordinates
+
+ db MONEY_BOX_TEMPLATE
+ db 11,0,19,2 ; text box coordinates
+ dw MoneyText
+ db 13,0 ; text coordinates
+
+ db JP_AH_MENU_TEMPLATE
+ db 7,6,11,10 ; text box coordinates
+ dw JapaneseAhText
+ db 8,8 ; text coordinates
+
+ db JP_POKEDEX_MENU_TEMPLATE
+ db 11,8,19,17 ; text box coordinates
+ dw JapanesePokedexMenu
+ db 12,10 ; text coordinates
+
+; note that there is no terminator
+
+BuySellQuitText:
+ db "BUY"
+ next "SELL"
+ next "QUIT@@"
+
+UseTossText:
+ db "USE"
+ next "TOSS@"
+
+JapaneseSaveMessageText:
+ db "きろく"
+ next "メッセージ@"
+
+JapaneseSpeedOptionsText:
+ db "はやい"
+ next "おそい@"
+
+MoneyText:
+ db "MONEY@"
+
+JapaneseMochimonoText:
+ db "もちもの@"
+
+JapaneseMainMenuText:
+ db "つづきから"
+ next "さいしょから@"
+
+BattleMenuText:
+ db "FIGHT ",$E1,$E2
+ next "ITEM RUN@"
+
+SafariZoneBattleMenuText:
+ db "BALL× BAIT"
+ next "THROW ROCK RUN@"
+
+SwitchStatsCancelText:
+ db "SWITCH"
+ next "STATS"
+ next "CANCEL@"
+
+JapaneseAhText:
+ db "アッ!@"
+
+JapanesePokedexMenu:
+ db "データをみる"
+ next "なきごえ"
+ next "ぶんぷをみる"
+ next "キャンセル@"
+
+DisplayMoneyBox:
+ ld hl, wd730
+ set 6, [hl]
+ ld a, MONEY_BOX_TEMPLATE
+ ld [wTextBoxID], a
+ call DisplayTextBoxID
+ coord hl, 13, 1
+ ld b, 1
+ ld c, 6
+ call ClearScreenArea
+ coord hl, 12, 1
+ ld de, wPlayerMoney
+ ld c, $a3
+ call PrintBCDNumber
+ ld hl, wd730
+ res 6, [hl]
+ ret
+
+CurrencyString:
+ db " ¥@"
+
+DoBuySellQuitMenu:
+ ld a, [wd730]
+ set 6, a ; no printing delay
+ ld [wd730], a
+ xor a
+ ld [wChosenMenuItem], a
+ ld a, BUY_SELL_QUIT_MENU_TEMPLATE
+ ld [wTextBoxID], a
+ call DisplayTextBoxID
+ ld a, A_BUTTON | B_BUTTON
+ ld [wMenuWatchedKeys], a
+ ld a, $2
+ ld [wMaxMenuItem], a
+ ld a, $1
+ ld [wTopMenuItemY], a
+ ld a, $1
+ ld [wTopMenuItemX], a
+ xor a
+ ld [wCurrentMenuItem], a
+ ld [wLastMenuItem], a
+ ld [wMenuWatchMovingOutOfBounds], a
+ ld a, [wd730]
+ res 6, a ; turn on the printing delay
+ ld [wd730], a
+ call HandleMenuInput
+ call PlaceUnfilledArrowMenuCursor
+ bit 0, a ; was A pressed?
+ jr nz, .pressedA
+ bit 1, a ; was B pressed? (always true since only A/B are watched)
+ jr z, .pressedA
+ ld a, CANCELLED_MENU
+ ld [wMenuExitMethod], a
+ jr .quit
+.pressedA
+ ld a, CHOSE_MENU_ITEM
+ ld [wMenuExitMethod], a
+ ld a, [wCurrentMenuItem]
+ ld [wChosenMenuItem], a
+ ld b, a
+ ld a, [wMaxMenuItem]
+ cp b
+ jr z, .quit
+ ret
+.quit
+ ld a, CANCELLED_MENU
+ ld [wMenuExitMethod], a
+ ld a, [wCurrentMenuItem]
+ ld [wChosenMenuItem], a
+ scf
+ ret
+
+; displays a menu with two options to choose from
+; b = Y of upper left corner of text region
+; c = X of upper left corner of text region
+; hl = address where the text box border should be drawn
+DisplayTwoOptionMenu:
+ push hl
+ 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 [wChosenMenuItem], a
+ ld [wMenuExitMethod], a
+
+ ld a, A_BUTTON | B_BUTTON
+ ld [wMenuWatchedKeys], a
+ ld a, $1
+ ld [wMaxMenuItem], a
+ ld a, b
+ ld [wTopMenuItemY], a
+ ld a, c
+ ld [wTopMenuItemX], a
+ xor a
+ ld [wLastMenuItem], a
+ ld [wMenuWatchMovingOutOfBounds], a
+ push hl
+ ld hl, wTwoOptionMenuID
+ bit 7, [hl] ; select second menu item by default?
+ res 7, [hl]
+ jr z, .storeCurrentMenuItem
+ inc a
+.storeCurrentMenuItem
+ ld [wCurrentMenuItem], a
+ pop hl
+ push hl
+ push hl
+ call TwoOptionMenu_SaveScreenTiles
+ ld a, [wTwoOptionMenuID]
+ ld hl, TwoOptionMenuStrings
+ ld e, a
+ ld d, $0
+ ld a, $5
+.menuStringLoop
+ add hl, de
+ dec a
+ jr nz, .menuStringLoop
+ ld a, [hli]
+ ld c, a
+ ld a, [hli]
+ ld b, a
+ ld e, l
+ ld d, h
+ pop hl
+ push de
+ ld a, [wTwoOptionMenuID]
+ cp TRADE_CANCEL_MENU
+ jr nz, .notTradeCancelMenu
+ call CableClub_TextBoxBorder
+ jr .afterTextBoxBorder
+.notTradeCancelMenu
+ call TextBoxBorder
+.afterTextBoxBorder
+ call UpdateSprites
+ pop hl
+ ld a, [hli]
+ and a ; put blank line before first menu item?
+ ld bc, 20 + 2
+ jr z, .noBlankLine
+ ld bc, 2 * 20 + 2
+.noBlankLine
+ ld a, [hli]
+ ld e, a
+ ld a, [hli]
+ ld d, a
+ pop hl
+ add hl, bc
+ call PlaceString
+ ld hl, wd730
+ res 6, [hl] ; turn on the printing delay
+ ld a, [wTwoOptionMenuID]
+ cp NO_YES_MENU
+ jr nz, .notNoYesMenu
+; No/Yes menu
+; this menu type ignores the B button
+; it only seems to be used when confirming the deletion of a save file
+ xor a
+ ld [wTwoOptionMenuID], a
+ ld a, [wFlags_0xcd60]
+ push af
+ push hl
+ ld hl, wFlags_0xcd60
+ bit 5, [hl]
+ set 5, [hl] ; don't play sound when A or B is pressed in menu
+ pop hl
+.noYesMenuInputLoop
+ call HandleMenuInput
+ bit 1, a ; A button pressed?
+ jr nz, .noYesMenuInputLoop ; try again if A was not pressed
+ pop af
+ pop hl
+ ld [wFlags_0xcd60], a
+ ld a, SFX_PRESS_AB
+ call PlaySound
+ jr .pressedAButton
+.notNoYesMenu
+ xor a
+ ld [wTwoOptionMenuID], a
+ call HandleMenuInput
+ pop hl
+ bit 1, a ; A button pressed?
+ jr nz, .choseSecondMenuItem ; automatically choose the second option if B is pressed
+.pressedAButton
+ ld a, [wCurrentMenuItem]
+ ld [wChosenMenuItem], a
+ and a
+ jr nz, .choseSecondMenuItem
+; chose first menu item
+ ld a, CHOSE_FIRST_ITEM
+ ld [wMenuExitMethod], a
+ ld c, 15
+ call DelayFrames
+ call TwoOptionMenu_RestoreScreenTiles
+ and a
+ ret
+.choseSecondMenuItem
+ ld a, 1
+ ld [wCurrentMenuItem], a
+ ld [wChosenMenuItem], a
+ ld a, CHOSE_SECOND_ITEM
+ ld [wMenuExitMethod], a
+ ld c, 15
+ call DelayFrames
+ call TwoOptionMenu_RestoreScreenTiles
+ scf
+ ret
+
+; Some of the wider/taller two option menus will not have the screen areas
+; they cover be fully saved/restored by the two functions below.
+; The bottom and right edges of the menu may remain after the function returns.
+
+TwoOptionMenu_SaveScreenTiles:
+ ld de, wBuffer
+ lb bc, 5, 6
+.loop
+ ld a, [hli]
+ ld [de], a
+ inc de
+ dec c
+ jr nz, .loop
+ push bc
+ ld bc, SCREEN_WIDTH - 6
+ add hl, bc
+ pop bc
+ ld c, $6
+ dec b
+ jr nz, .loop
+ ret
+
+TwoOptionMenu_RestoreScreenTiles:
+ ld de, wBuffer
+ lb bc, 5, 6
+.loop
+ ld a, [de]
+ inc de
+ ld [hli], a
+ dec c
+ jr nz, .loop
+ push bc
+ ld bc, SCREEN_WIDTH - 6
+ add hl, bc
+ pop bc
+ ld c, 6
+ dec b
+ jr nz, .loop
+ call UpdateSprites
+ ret
+
+; Format:
+; 00: byte width
+; 01: byte height
+; 02: byte put blank line before first menu item
+; 03: word text pointer
+TwoOptionMenuStrings:
+ db 4,3,0
+ dw .YesNoMenu
+ db 6,3,0
+ dw .NorthWestMenu
+ db 6,3,0
+ dw .SouthEastMenu
+ db 6,3,0
+ dw .YesNoMenu
+ db 6,3,0
+ dw .NorthEastMenu
+ db 7,3,0
+ dw .TradeCancelMenu
+ db 7,4,1
+ dw .HealCancelMenu
+ db 4,3,0
+ dw .NoYesMenu
+
+.NoYesMenu
+ db "NO"
+ next "YES@"
+.YesNoMenu
+ db "YES"
+ next "NO@"
+.NorthWestMenu
+ db "NORTH"
+ next "WEST@"
+.SouthEastMenu
+ db "SOUTH"
+ next "EAST@"
+.NorthEastMenu
+ db "NORTH"
+ next "EAST@"
+.TradeCancelMenu
+ db "TRADE"
+ next "CANCEL@"
+.HealCancelMenu
+ db "HEAL"
+ next "CANCEL@"
+
+DisplayFieldMoveMonMenu:
+ xor a
+ ld hl, wFieldMoves
+ ld [hli], a ; wFieldMoves
+ ld [hli], a ; wFieldMoves + 1
+ ld [hli], a ; wFieldMoves + 2
+ ld [hli], a ; wFieldMoves + 3
+ ld [hli], a ; wNumFieldMoves
+ ld [hl], 12 ; wFieldMovesLeftmostXCoord
+ call GetMonFieldMoves
+ ld a, [wNumFieldMoves]
+ and a
+ jr nz, .fieldMovesExist
+
+; no field moves
+ coord hl, 11, 11
+ ld b, 5
+ ld c, 7
+ call TextBoxBorder
+ call UpdateSprites
+ ld a, 12
+ ld [hFieldMoveMonMenuTopMenuItemX], a
+ coord hl, 13, 12
+ ld de, PokemonMenuEntries
+ jp PlaceString
+
+.fieldMovesExist
+ push af
+
+; Calculate the text box position and dimensions based on the leftmost X coord
+; of the field move names before adjusting for the number of field moves.
+ coord hl, 0, 11
+ ld a, [wFieldMovesLeftmostXCoord]
+ dec a
+ ld e, a
+ ld d, 0
+ add hl, de
+ ld b, 5
+ ld a, 18
+ sub e
+ ld c, a
+ pop af
+
+; For each field move, move the top of the text box up 2 rows while the leaving
+; the bottom of the text box at the bottom of the screen.
+ ld de, -SCREEN_WIDTH * 2
+.textBoxHeightLoop
+ add hl, de
+ inc b
+ inc b
+ dec a
+ jr nz, .textBoxHeightLoop
+
+; Make space for an extra blank row above the top field move.
+ ld de, -SCREEN_WIDTH
+ add hl, de
+ inc b
+
+ call TextBoxBorder
+ call UpdateSprites
+
+; Calculate the position of the first field move name to print.
+ coord hl, 0, 12
+ ld a, [wFieldMovesLeftmostXCoord]
+ inc a
+ ld e, a
+ ld d, 0
+ add hl, de
+ ld de, -SCREEN_WIDTH * 2
+ ld a, [wNumFieldMoves]
+.calcFirstFieldMoveYLoop
+ add hl, de
+ dec a
+ jr nz, .calcFirstFieldMoveYLoop
+
+ xor a
+ ld [wNumFieldMoves], a
+ ld de, wFieldMoves
+.printNamesLoop
+ push hl
+ ld hl, FieldMoveNames
+ ld a, [de]
+ and a
+ jr z, .donePrintingNames
+ inc de
+ ld b, a ; index of name
+.skipNamesLoop ; skip past names before the name we want
+ dec b
+ jr z, .reachedName
+.skipNameLoop ; skip past current name
+ ld a, [hli]
+ cp "@"
+ jr nz, .skipNameLoop
+ jr .skipNamesLoop
+.reachedName
+ ld b, h
+ ld c, l
+ pop hl
+ push de
+ ld d, b
+ ld e, c
+ call PlaceString
+ ld bc, SCREEN_WIDTH * 2
+ add hl, bc
+ pop de
+ jr .printNamesLoop
+
+.donePrintingNames
+ pop hl
+ ld a, [wFieldMovesLeftmostXCoord]
+ ld [hFieldMoveMonMenuTopMenuItemX], a
+ coord hl, 0, 12
+ ld a, [wFieldMovesLeftmostXCoord]
+ inc a
+ ld e, a
+ ld d, 0
+ add hl, de
+ ld de, PokemonMenuEntries
+ jp PlaceString
+
+FieldMoveNames:
+ db "CUT@"
+ db "FLY@"
+ db "@"
+ db "SURF@"
+ db "STRENGTH@"
+ db "FLASH@"
+ db "DIG@"
+ db "TELEPORT@"
+ db "SOFTBOILED@"
+
+PokemonMenuEntries:
+ db "STATS"
+ next "SWITCH"
+ next "CANCEL@"
+
+GetMonFieldMoves:
+ ld a, [wWhichPokemon]
+ ld hl, wPartyMon1Moves
+ ld bc, wPartyMon2 - wPartyMon1
+ call AddNTimes
+ ld d, h
+ ld e, l
+ ld c, NUM_MOVES + 1
+ ld hl, wFieldMoves
+.loop
+ push hl
+.nextMove
+ dec c
+ jr z, .done
+ ld a, [de] ; move ID
+ and a
+ jr z, .done
+ ld b, a
+ inc de
+ ld hl, FieldMoveDisplayData
+.fieldMoveLoop
+ ld a, [hli]
+ cp $ff
+ jr z, .nextMove ; if the move is not a field move
+ cp b
+ jr z, .foundFieldMove
+ inc hl
+ inc hl
+ jr .fieldMoveLoop
+.foundFieldMove
+ ld a, b
+ ld [wLastFieldMoveID], a
+ ld a, [hli] ; field move name index
+ ld b, [hl] ; field move leftmost X coordinate
+ pop hl
+ ld [hli], a ; store name index in wFieldMoves
+ ld a, [wNumFieldMoves]
+ inc a
+ ld [wNumFieldMoves], a
+ ld a, [wFieldMovesLeftmostXCoord]
+ cp b
+ jr c, .skipUpdatingLeftmostXCoord
+ ld a, b
+ ld [wFieldMovesLeftmostXCoord], a
+.skipUpdatingLeftmostXCoord
+ ld a, [wLastFieldMoveID]
+ ld b, a
+ jr .loop
+.done
+ pop hl
+ ret
+
+; Format: [Move id], [name index], [leftmost tile]
+; Move id = id of move
+; Name index = index of name in FieldMoveNames
+; Leftmost tile = -1 + tile column in which the first letter of the move's name should be displayed
+; "SOFTBOILED" is $08 because it has 4 more letters than "SURF", for example, whose value is $0C
+FieldMoveDisplayData:
+ db CUT, $01, $0C
+ db FLY, $02, $0C
+ db $B4, $03, $0C ; unused field move
+ db SURF, $04, $0C
+ db STRENGTH, $05, $0A
+ db FLASH, $06, $0C
+ db DIG, $07, $0C
+ db TELEPORT, $08, $0A
+ db SOFTBOILED, $09, $08
+ db $ff ; list terminator
diff --git a/engine/menu/vending_machine.asm b/engine/menu/vending_machine.asm
index 88cfcf65..aab4adf4 100755
--- a/engine/menu/vending_machine.asm
+++ b/engine/menu/vending_machine.asm
@@ -1,4 +1,4 @@
-VendingMachineMenu: ; 74ee0 (1d:4ee0)
+VendingMachineMenu:
ld hl, VendingMachineText1
call PrintText
ld a, MONEY_BOX
@@ -7,65 +7,66 @@ VendingMachineMenu: ; 74ee0 (1d:4ee0)
xor a
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
- ld a, $3
+ ld a, A_BUTTON | B_BUTTON
ld [wMenuWatchedKeys], a
- ld a, $3
+ ld a, 3
ld [wMaxMenuItem], a
- ld a, $5
+ ld a, 5
ld [wTopMenuItemY], a
- ld a, $1
+ ld a, 1
ld [wTopMenuItemX], a
ld hl, wd730
set 6, [hl]
- hlCoord 0, 3
- ld b, $8
- ld c, $c
+ coord hl, 0, 3
+ ld b, 8
+ ld c, 12
call TextBoxBorder
call UpdateSprites
- hlCoord 2, 5
+ coord hl, 2, 5
ld de, DrinkText
call PlaceString
- hlCoord 9, 6
+ coord hl, 9, 6
ld de, DrinkPriceText
call PlaceString
ld hl, wd730
res 6, [hl]
call HandleMenuInput
- bit 1, a
- jr nz, .asm_74f93
+ bit 1, a ; pressed B?
+ jr nz, .notThirsty
ld a, [wCurrentMenuItem]
- cp $3
- jr z, .asm_74f93
+ cp 3 ; chose Cancel?
+ jr z, .notThirsty
xor a
- ld [$ff9f], a
- ld [$ffa1], a
+ ld [hMoney], a
+ ld [hMoney + 2], a
ld a, $2
- ld [$ffa0], a
+ ld [hMoney + 1], a
call HasEnoughMoney
jr nc, .enoughMoney
ld hl, VendingMachineText4
jp PrintText
.enoughMoney
- call Func_74fe7
- ld a, [$ffdb]
+ call LoadVendingMachineItem
+ ld a, [hVendingMachineItem]
ld b, a
ld c, 1
call GiveItem
jr nc, .BagFull
- ld b, $3c ; number of times to play the "brrrrr" sound
-.playDeliverySound ; 0x74f63
- ld c, $2
+
+ ld b, 60 ; number of times to play the "brrrrr" sound
+.playDeliverySound
+ ld c, 2
call DelayFrames
push bc
- ld a, (SFX_02_53 - SFX_Headers_02) / 3
+ ld a, SFX_PUSH_BOULDER
call PlaySound
pop bc
dec b
jr nz, .playDeliverySound
-.asm_74f72
+
ld hl, VendingMachineText5
call PrintText
- ld hl, $ffde
+ ld hl, hVendingMachinePrice + 2
ld de, wPlayerMoney + 2
ld c, $3
predef SubBCDPredef
@@ -75,60 +76,64 @@ VendingMachineMenu: ; 74ee0 (1d:4ee0)
.BagFull
ld hl, VendingMachineText6
jp PrintText
-.asm_74f93
+.notThirsty
ld hl, VendingMachineText7
jp PrintText
-VendingMachineText1: ; 74f99 (1d:4f99)
+VendingMachineText1:
TX_FAR _VendingMachineText1
db "@"
-DrinkText: ; 74f9e (1d:4f9e)
+DrinkText:
db "FRESH WATER"
next "SODA POP"
next "LEMONADE"
next "CANCEL@"
-DrinkPriceText: ; 74fc3 (1d:4fc3)
+DrinkPriceText:
db "¥200"
next "¥300"
- next "¥350",$4E,"@"
+ next "¥350"
+ next "@"
-VendingMachineText4: ; 74fd3 (1d:4fd3)
+VendingMachineText4:
TX_FAR _VendingMachineText4
db "@"
-VendingMachineText5: ; 74fd8 (1d:4fd8)
+VendingMachineText5:
TX_FAR _VendingMachineText5
db "@"
-VendingMachineText6: ; 74fdd (1d:4fdd)
+VendingMachineText6:
TX_FAR _VendingMachineText6
db "@"
-VendingMachineText7: ; 74fe2 (1d:4fe2)
+VendingMachineText7:
TX_FAR _VendingMachineText7
db "@"
-Func_74fe7: ; 74fe7 (1d:4fe7)
+LoadVendingMachineItem:
ld hl, VendingPrices
ld a, [wCurrentMenuItem]
add a
add a
- ld d, $0
+ ld d, 0
ld e, a
add hl, de
ld a, [hli]
- ld [$ffdb], a
+ ld [hVendingMachineItem], a
ld a, [hli]
- ld [$ffdc], a
+ ld [hVendingMachinePrice], a
ld a, [hli]
- ld [$ffdd], a
+ ld [hVendingMachinePrice + 1], a
ld a, [hl]
- ld [$ffde], a
+ ld [hVendingMachinePrice + 2], a
ret
-VendingPrices: ; 75000 (1d:5000)
- db FRESH_WATER,$00,$02,$00
- db SODA_POP, $00,$03,$00
- db LEMONADE, $00,$03,$50
+VendingPrices:
+ db FRESH_WATER
+ money 200
+ db SODA_POP
+ money 300
+ db LEMONADE
+ money 350