summaryrefslogtreecommitdiff
path: root/engine/menu/main_menu.asm
diff options
context:
space:
mode:
Diffstat (limited to 'engine/menu/main_menu.asm')
-rwxr-xr-xengine/menu/main_menu.asm298
1 files changed, 153 insertions, 145 deletions
diff --git a/engine/menu/main_menu.asm b/engine/menu/main_menu.asm
index 756c7755..6c109cec 100755
--- a/engine/menu/main_menu.asm
+++ b/engine/menu/main_menu.asm
@@ -1,22 +1,21 @@
MainMenu: ; 5af2 (1:5af2)
; 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
@@ -25,34 +24,35 @@ MainMenu: ; 5af2 (1:5af2)
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 [wOptionsInitialized],a
+ jp .mainMenuLoop
+.choseContinue
+ call DisplayContinueGameInfo
ld hl,wd126
set 5,[hl]
-.next6
+.inputLoop
xor a
ld [hJoyPressed],a
ld [hJoyReleased],a
@@ -98,18 +100,18 @@ 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
@@ -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
+
+InitOptions: ; 5bff (1:5bff)
+ ld a,1 ; no delay
+ ld [wLetterPrintingDelayFlags],a
+ ld a,3 ; medium speed
ld [W_OPTIONS],a
ret
LinkMenu: ; 5c0a (1:5c0a)
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 [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
@@ -300,11 +304,11 @@ LinkCanceledText: ; 5d4d (1:5d4d)
TX_FAR _LinkCanceledText
db "@"
-Func_5d52: ; 5d52 (1:5d52)
+StartNewGame: ; 5d52 (1:5d52)
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
@@ -319,7 +323,7 @@ SpecialEnterMap: ; 5d5f (1:5d5f)
call ResetPlayerSpriteData
ld c, 20
call DelayFrames
- ld a, [wcc47]
+ ld a, [wEnteringCableClub]
and a
ret nz
jp EnterMap
@@ -331,89 +335,89 @@ NewGameText: ; 5d87 (1:5d87)
db "NEW GAME", $4e
db "OPTION@"
-TradeCenterText: ; 5d97 (1:5d97)
+CableClubOptionsText: ; 5d97 (1:5d97)
db "TRADE CENTER", $4e
db "COLOSSEUM", $4e
db "CANCEL@"
-ContinueGame: ; 5db5 (1:5db5)
+DisplayContinueGameInfo: ; 5db5 (1:5db5)
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)
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: ; 5e2f (1:5e2f)
push hl
ld hl, W_OBTAINEDBADGES
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: ; 5e42 (1:5e42)
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)
+PrintPlayTime: ; 5e55 (1:5e55)
ld de, W_PLAYTIMEHOURS + 1
- ld bc, $103
+ lb bc, 1, 3
call PrintNumber
ld [hl], $6d
inc hl
ld de, W_PLAYTIMEMINUTES + 1
- ld bc, $8102
+ lb bc, LEADING_ZEROES | 1, 2
jp PrintNumber
SaveScreenInfoText: ; 5e6a (1:5e6a)
@@ -423,40 +427,40 @@ SaveScreenInfoText: ; 5e6a (1:5e6a)
next "TIME@"
DisplayOptionMenu: ; 5e8a (1:5e8a)
- hlCoord 0, 0
+ 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,7 +575,7 @@ 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)
@@ -592,7 +596,7 @@ OptionMenuCancelText: ; 6018 (1:6018)
; sets the options variable according to the current placement of the menu cursors in the options menu
SetOptionsFromCursorPositions: ; 601f (1:601f)
ld hl,TextSpeedOptionData
- ld a,[wWhichTrade] ; text speed cursor X coordinate
+ ld a,[wOptionsTextSpeedCursorX] ; text speed cursor X coordinate
ld c,a
.loop
ld a,[hli]
@@ -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
@@ -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
@@ -677,28 +681,32 @@ TextSpeedOptionData: ; 6096 (1:6096)
db 7 ; default X coordinate (Medium)
db $ff ; terminator
-Func_609e: ; 609e (1:609e)
- ld a, $a
- ld [$0], a
+CheckForPlayerNameInSRAM: ; 609e (1:609e)
+; 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