pokered/engine/menu/main_menu.asm

713 lines
14 KiB
NASM
Raw Normal View History

2016-06-12 00:24:04 +00:00
MainMenu:
2014-05-22 22:13:20 +00:00
; Check save file
2015-07-19 03:49:52 +00:00
call InitOptions
2014-05-22 22:13:20 +00:00
xor a
ld [wOptionsInitialized], a
2014-05-22 22:13:20 +00:00
inc a
ld [wSaveFileStatus], a
2015-07-19 03:49:52 +00:00
call CheckForPlayerNameInSRAM
jr nc, .mainMenuLoop
2014-05-22 22:13:20 +00:00
predef LoadSAV
2014-05-22 22:13:20 +00:00
2015-07-19 03:49:52 +00:00
.mainMenuLoop
ld c, 20
2014-05-22 22:13:20 +00:00
call DelayFrames
2015-02-07 10:43:08 +00:00
xor a ; LINK_STATE_NONE
ld [wLinkState], a
ld hl, wPartyAndBillsPCSavedMenuItem
ld [hli], a
ld [hli], a
ld [hli], a
ld [hl], a
ld [wDefaultMap], a
ld hl, wd72e
res 6, [hl]
2014-05-22 22:13:20 +00:00
call ClearScreen
2015-08-12 09:16:56 +00:00
call RunDefaultPaletteCommand
2014-05-22 22:13:20 +00:00
call LoadTextBoxTilePatterns
call LoadFontTilePatterns
ld hl, wd730
set 6, [hl]
ld a, [wSaveFileStatus]
cp 1
jr z, .noSaveFile
2015-07-19 03:49:52 +00:00
; there's a save file
2015-07-18 20:52:03 +00:00
coord hl, 0, 0
ld b, 6
ld c, 13
2014-05-22 22:13:20 +00:00
call TextBoxBorder
2015-07-18 20:52:03 +00:00
coord hl, 2, 2
ld de, ContinueText
2014-05-22 22:13:20 +00:00
call PlaceString
jr .next2
2015-07-19 03:49:52 +00:00
.noSaveFile
2015-07-18 20:52:03 +00:00
coord hl, 0, 0
ld b, 4
ld c, 13
2014-05-22 22:13:20 +00:00
call TextBoxBorder
2015-07-18 20:52:03 +00:00
coord hl, 2, 2
ld de, NewGameText
2014-05-22 22:13:20 +00:00
call PlaceString
.next2
ld hl, wd730
res 6, [hl]
call UpdateSprites
2014-05-22 22:13:20 +00:00
xor a
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
ld [wMenuJoypadPollCount], a
2014-05-22 22:13:20 +00:00
inc a
ld [wTopMenuItemX], a
2014-05-22 22:13:20 +00:00
inc a
ld [wTopMenuItemY], a
ld a, A_BUTTON | B_BUTTON | START
ld [wMenuWatchedKeys], a
ld a, [wSaveFileStatus]
ld [wMaxMenuItem], a
2014-05-22 22:13:20 +00:00
call HandleMenuInput
bit 1, a ; pressed B?
jp nz, DisplayTitleScreen ; if so, go back to the title screen
ld c, 20
2014-05-22 22:13:20 +00:00
call DelayFrames
ld a, [wCurrentMenuItem]
ld b, a
ld a, [wSaveFileStatus]
cp 2
jp z, .skipInc
2015-07-19 03:49:52 +00:00
; 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
2014-05-22 22:13:20 +00:00
and a
jr z, .choseContinue
cp 1
jp z, StartNewGame
2015-07-19 03:49:52 +00:00
call DisplayOptionMenu
ld a, 1
ld [wOptionsInitialized], a
2015-07-19 03:49:52 +00:00
jp .mainMenuLoop
.choseContinue
call DisplayContinueGameInfo
ld hl, wCurrentMapScriptFlags
set 5, [hl]
.inputLoop
2014-05-22 22:13:20 +00:00
xor a
ld [hJoyPressed], a
ld [hJoyReleased], a
ld [hJoyHeld], a
2014-05-25 18:21:48 +00:00
call Joypad
ld a, [hJoyHeld]
bit 0, a
jr nz, .pressedA
bit 1, a
jp nz, .mainMenuLoop ; pressed B
jr .inputLoop
.pressedA
2014-05-22 22:13:20 +00:00
call GBPalWhiteOutWithDelay3
call ClearScreen
ld a, PLAYER_DIR_DOWN
ld [wPlayerDirection], a
ld c, 10
2014-05-22 22:13:20 +00:00
call DelayFrames
ld a, [wNumHoFTeams]
2014-05-22 22:13:20 +00:00
and a
jp z, SpecialEnterMap
ld a, [wCurMap] ; map ID
cp HALL_OF_FAME
jp nz, SpecialEnterMap
2014-05-22 22:13:20 +00:00
xor a
ld [wDestinationMap], a
ld hl, wd732
set 2, [hl] ; fly warp or dungeon warp
2014-09-13 07:50:56 +00:00
call SpecialWarpIn
jp SpecialEnterMap
2016-06-12 00:24:04 +00:00
InitOptions:
ld a, 1 ; no delay
ld [wLetterPrintingDelayFlags], a
ld a, 3 ; medium speed
ld [wOptions], a
2014-05-22 22:13:20 +00:00
ret
2016-06-12 00:24:04 +00:00
LinkMenu:
2014-05-22 22:13:20 +00:00
xor a
2015-07-15 02:46:52 +00:00
ld [wLetterPrintingDelayFlags], a
ld hl, wd72e
2014-05-22 22:13:20 +00:00
set 6, [hl]
2015-02-07 10:43:08 +00:00
ld hl, TextTerminator_6b20
2014-05-22 22:13:20 +00:00
call PrintText
call SaveScreenTilesToBuffer1
ld hl, WhereWouldYouLikeText
call PrintText
2015-07-18 20:52:03 +00:00
coord hl, 5, 5
2014-05-22 22:13:20 +00:00
ld b, $6
ld c, $d
call TextBoxBorder
call UpdateSprites
2015-07-18 20:52:03 +00:00
coord hl, 7, 7
ld de, CableClubOptionsText
2014-05-22 22:13:20 +00:00
call PlaceString
xor a
2015-08-13 05:14:31 +00:00
ld [wUnusedCD37], a
ld [wd72d], a
2015-02-07 10:43:08 +00:00
ld hl, wTopMenuItemY
2014-05-22 22:13:20 +00:00
ld a, $7
ld [hli], a
ld a, $6
ld [hli], a
xor a
ld [hli], a
inc hl
ld a, $2
ld [hli], a
inc a
2015-08-11 05:34:32 +00:00
; ld a, A_BUTTON | B_BUTTON
ld [hli], a ; wMenuWatchedKeys
2014-05-22 22:13:20 +00:00
xor a
ld [hl], a
2015-02-07 10:43:08 +00:00
.waitForInputLoop
2014-05-22 22:13:20 +00:00
call HandleMenuInput
2015-02-07 10:43:08 +00:00
and A_BUTTON | B_BUTTON
2014-05-22 22:13:20 +00:00
add a
add a
ld b, a
2015-02-07 10:43:08 +00:00
ld a, [wCurrentMenuItem]
2014-05-22 22:13:20 +00:00
add b
add $d0
2015-02-07 10:43:08 +00:00
ld [wLinkMenuSelectionSendBuffer], a
ld [wLinkMenuSelectionSendBuffer + 1], a
.exchangeMenuSelectionLoop
call Serial_ExchangeLinkMenuSelection
ld a, [wLinkMenuSelectionReceiveBuffer]
2014-05-22 22:13:20 +00:00
ld b, a
and $f0
cp $d0
jr z, .asm_5c7d
2015-02-07 10:43:08 +00:00
ld a, [wLinkMenuSelectionReceiveBuffer + 1]
2014-05-22 22:13:20 +00:00
ld b, a
and $f0
cp $d0
2015-02-07 10:43:08 +00:00
jr nz, .exchangeMenuSelectionLoop
2014-05-22 22:13:20 +00:00
.asm_5c7d
ld a, b
2015-02-07 10:43:08 +00:00
and $c ; did the enemy press A or B?
jr nz, .enemyPressedAOrB
; the enemy didn't press A or B
ld a, [wLinkMenuSelectionSendBuffer]
and $c ; did the player press A or B?
jr z, .waitForInputLoop ; if neither the player nor the enemy pressed A or B, try again
jr .doneChoosingMenuSelection ; if the player pressed A or B but the enemy didn't, use the player's selection
.enemyPressedAOrB
ld a, [wLinkMenuSelectionSendBuffer]
and $c ; did the player press A or B?
jr z, .useEnemyMenuSelection ; if the enemy pressed A or B but the player didn't, use the enemy's selection
; the enemy and the player both pressed A or B
; The gameboy that is clocking the connection wins.
ld a, [hSerialConnectionStatus]
cp USING_INTERNAL_CLOCK
jr z, .doneChoosingMenuSelection
.useEnemyMenuSelection
2014-05-22 22:13:20 +00:00
ld a, b
2015-02-07 10:43:08 +00:00
ld [wLinkMenuSelectionSendBuffer], a
2014-05-22 22:13:20 +00:00
and $3
ld [wCurrentMenuItem], a
2015-02-07 10:43:08 +00:00
.doneChoosingMenuSelection
ld a, [hSerialConnectionStatus]
cp USING_INTERNAL_CLOCK
jr nz, .skipStartingTransfer
2014-05-22 22:13:20 +00:00
call DelayFrame
call DelayFrame
2015-02-07 10:43:08 +00:00
ld a, START_TRANSFER_INTERNAL_CLOCK
ld [rSC], a
.skipStartingTransfer
2014-05-22 22:13:20 +00:00
ld b, $7f
ld c, $7f
ld d, $ec
2015-02-07 10:43:08 +00:00
ld a, [wLinkMenuSelectionSendBuffer]
and (B_BUTTON << 2) ; was B button pressed?
jr nz, .updateCursorPosition
; A button was pressed
ld a, [wCurrentMenuItem]
2014-05-22 22:13:20 +00:00
cp $2
2015-02-07 10:43:08 +00:00
jr z, .updateCursorPosition
2014-05-22 22:13:20 +00:00
ld c, d
ld d, b
dec a
2015-02-07 10:43:08 +00:00
jr z, .updateCursorPosition
2014-05-22 22:13:20 +00:00
ld b, c
ld c, d
2015-02-07 10:43:08 +00:00
.updateCursorPosition
2014-05-22 22:13:20 +00:00
ld a, b
Coorda 6, 7
2014-05-22 22:13:20 +00:00
ld a, c
Coorda 6, 9
2014-05-22 22:13:20 +00:00
ld a, d
Coorda 6, 11
2015-02-07 10:43:08 +00:00
ld c, 40
2014-05-22 22:13:20 +00:00
call DelayFrames
call LoadScreenTilesFromBuffer1
2015-02-07 10:43:08 +00:00
ld a, [wLinkMenuSelectionSendBuffer]
and (B_BUTTON << 2) ; was B button pressed?
jr nz, .choseCancel ; cancel if B pressed
ld a, [wCurrentMenuItem]
2014-05-22 22:13:20 +00:00
cp $2
2015-02-07 10:43:08 +00:00
jr z, .choseCancel
2014-05-22 22:13:20 +00:00
xor a
2015-02-07 10:43:08 +00:00
ld [wWalkBikeSurfState], a ; start walking
ld a, [wCurrentMenuItem]
2014-05-22 22:13:20 +00:00
and a
ld a, COLOSSEUM
2015-02-07 10:43:08 +00:00
jr nz, .next
ld a, TRADE_CENTER
2015-02-07 10:43:08 +00:00
.next
ld [wd72d], a
2014-05-22 22:13:20 +00:00
ld hl, PleaseWaitText
call PrintText
ld c, 50
2014-05-22 22:13:20 +00:00
call DelayFrames
ld hl, wd732
2014-05-22 22:13:20 +00:00
res 1, [hl]
2015-08-30 00:15:05 +00:00
ld a, [wDefaultMap]
2014-09-13 07:50:56 +00:00
ld [wDestinationMap], a
call SpecialWarpIn
ld c, 20
2014-05-22 22:13:20 +00:00
call DelayFrames
xor a
2015-02-07 10:43:08 +00:00
ld [wMenuJoypadPollCount], a
ld [wSerialExchangeNybbleSendData], a
inc a ; LINK_STATE_IN_CABLE_CLUB
ld [wLinkState], a
2015-07-26 02:26:54 +00:00
ld [wEnteringCableClub], a
2014-09-13 07:50:56 +00:00
jr SpecialEnterMap
2015-02-07 10:43:08 +00:00
.choseCancel
2014-05-22 22:13:20 +00:00
xor a
2015-02-07 10:43:08 +00:00
ld [wMenuJoypadPollCount], a
2014-05-22 22:13:20 +00:00
call Delay3
2015-02-07 10:43:08 +00:00
call CloseLinkConnection
2014-05-22 22:13:20 +00:00
ld hl, LinkCanceledText
call PrintText
ld hl, wd72e
2014-05-22 22:13:20 +00:00
res 6, [hl]
ret
2016-06-12 00:24:04 +00:00
WhereWouldYouLikeText:
2014-05-22 22:13:20 +00:00
TX_FAR _WhereWouldYouLikeText
db "@"
2016-06-12 00:24:04 +00:00
PleaseWaitText:
2014-05-22 22:13:20 +00:00
TX_FAR _PleaseWaitText
db "@"
2016-06-12 00:24:04 +00:00
LinkCanceledText:
2014-05-22 22:13:20 +00:00
TX_FAR _LinkCanceledText
db "@"
2016-06-12 00:24:04 +00:00
StartNewGame:
ld hl, wd732
2014-05-22 22:13:20 +00:00
res 1, [hl]
call OakSpeech
ld c, 20
2014-05-22 22:13:20 +00:00
call DelayFrames
2014-09-13 07:50:56 +00:00
; enter map after using a special warp or loading the game from the main menu
2016-06-12 00:24:04 +00:00
SpecialEnterMap:
2014-05-22 22:13:20 +00:00
xor a
2014-05-25 17:51:53 +00:00
ld [hJoyPressed], a
ld [hJoyHeld], a
ld [hJoy5], a
ld [wd72d], a
ld hl, wd732
2014-09-13 07:50:56 +00:00
set 0, [hl] ; count play time
2014-05-22 22:13:20 +00:00
call ResetPlayerSpriteData
2014-09-13 07:50:56 +00:00
ld c, 20
2014-05-22 22:13:20 +00:00
call DelayFrames
2015-07-26 02:26:54 +00:00
ld a, [wEnteringCableClub]
2014-05-22 22:13:20 +00:00
and a
ret nz
jp EnterMap
2016-06-12 00:24:04 +00:00
ContinueText:
2014-05-22 22:13:20 +00:00
db "CONTINUE", $4e
2016-06-12 00:24:04 +00:00
NewGameText:
2016-07-18 06:17:03 +00:00
db "NEW GAME"
next "OPTION@"
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
CableClubOptionsText:
2016-07-18 06:17:03 +00:00
db "TRADE CENTER"
next "COLOSSEUM"
next "CANCEL@"
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
DisplayContinueGameInfo:
2014-05-22 22:13:20 +00:00
xor a
ld [H_AUTOBGTRANSFERENABLED], a
2015-07-18 20:52:03 +00:00
coord hl, 4, 7
2015-07-19 03:49:52 +00:00
ld b, 8
ld c, 14
2014-05-22 22:13:20 +00:00
call TextBoxBorder
2015-07-18 20:52:03 +00:00
coord hl, 5, 9
2014-05-22 22:13:20 +00:00
ld de, SaveScreenInfoText
call PlaceString
2015-07-18 20:52:03 +00:00
coord hl, 12, 9
ld de, wPlayerName
2014-05-22 22:13:20 +00:00
call PlaceString
2015-07-18 20:52:03 +00:00
coord hl, 17, 11
2015-07-19 03:49:52 +00:00
call PrintNumBadges
2015-07-18 20:52:03 +00:00
coord hl, 16, 13
2015-07-19 03:49:52 +00:00
call PrintNumOwnedMons
2015-07-18 20:52:03 +00:00
coord hl, 13, 15
2015-07-19 03:49:52 +00:00
call PrintPlayTime
ld a, 1
ld [H_AUTOBGTRANSFERENABLED], a
ld c, 30
2014-05-22 22:13:20 +00:00
jp DelayFrames
2016-06-12 00:24:04 +00:00
PrintSaveScreenText:
2014-05-22 22:13:20 +00:00
xor a
ld [H_AUTOBGTRANSFERENABLED], a
2015-07-18 20:52:03 +00:00
coord hl, 4, 0
2014-05-22 22:13:20 +00:00
ld b, $8
ld c, $e
call TextBoxBorder
call LoadTextBoxTilePatterns
call UpdateSprites
2015-07-18 20:52:03 +00:00
coord hl, 5, 2
2014-05-22 22:13:20 +00:00
ld de, SaveScreenInfoText
call PlaceString
2015-07-18 20:52:03 +00:00
coord hl, 12, 2
ld de, wPlayerName
2014-05-22 22:13:20 +00:00
call PlaceString
2015-07-18 20:52:03 +00:00
coord hl, 17, 4
2015-07-19 03:49:52 +00:00
call PrintNumBadges
2015-07-18 20:52:03 +00:00
coord hl, 16, 6
2015-07-19 03:49:52 +00:00
call PrintNumOwnedMons
2015-07-18 20:52:03 +00:00
coord hl, 13, 8
2015-07-19 03:49:52 +00:00
call PrintPlayTime
2014-05-22 22:13:20 +00:00
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
ld c, 30
2014-05-22 22:13:20 +00:00
jp DelayFrames
2016-06-12 00:24:04 +00:00
PrintNumBadges:
2014-05-22 22:13:20 +00:00
push hl
2015-08-31 02:38:41 +00:00
ld hl, wObtainedBadges
2014-05-22 22:13:20 +00:00
ld b, $1
call CountSetBits
pop hl
2015-08-07 11:24:06 +00:00
ld de, wNumSetBits
2015-07-28 01:48:44 +00:00
lb bc, 1, 2
2014-05-22 22:13:20 +00:00
jp PrintNumber
2016-06-12 00:24:04 +00:00
PrintNumOwnedMons:
2014-05-22 22:13:20 +00:00
push hl
ld hl, wPokedexOwned
2014-05-22 22:13:20 +00:00
ld b, wPokedexOwnedEnd - wPokedexOwned
call CountSetBits
pop hl
2015-08-07 11:24:06 +00:00
ld de, wNumSetBits
2015-07-28 01:48:44 +00:00
lb bc, 1, 3
2014-05-22 22:13:20 +00:00
jp PrintNumber
2016-06-12 00:24:04 +00:00
PrintPlayTime:
2016-01-03 19:17:10 +00:00
ld de, wPlayTimeHours
2015-07-28 01:48:44 +00:00
lb bc, 1, 3
2014-05-22 22:13:20 +00:00
call PrintNumber
ld [hl], $6d
inc hl
2016-01-03 19:17:10 +00:00
ld de, wPlayTimeMinutes
2015-07-28 01:48:44 +00:00
lb bc, LEADING_ZEROES | 1, 2
2014-05-22 22:13:20 +00:00
jp PrintNumber
2016-06-12 00:24:04 +00:00
SaveScreenInfoText:
2014-05-22 22:13:20 +00:00
db "PLAYER"
next "BADGES "
next "#DEX "
next "TIME@"
2016-06-12 00:24:04 +00:00
DisplayOptionMenu:
2015-07-18 20:52:03 +00:00
coord hl, 0, 0
ld b, 3
ld c, 18
2014-05-22 22:13:20 +00:00
call TextBoxBorder
2015-07-18 20:52:03 +00:00
coord hl, 0, 5
ld b, 3
ld c, 18
2014-05-22 22:13:20 +00:00
call TextBoxBorder
2015-07-18 20:52:03 +00:00
coord hl, 0, 10
ld b, 3
ld c, 18
2014-05-22 22:13:20 +00:00
call TextBoxBorder
2015-07-18 20:52:03 +00:00
coord hl, 1, 1
ld de, TextSpeedOptionText
2014-05-22 22:13:20 +00:00
call PlaceString
2015-07-18 20:52:03 +00:00
coord hl, 1, 6
ld de, BattleAnimationOptionText
2014-05-22 22:13:20 +00:00
call PlaceString
2015-07-18 20:52:03 +00:00
coord hl, 1, 11
ld de, BattleStyleOptionText
2014-05-22 22:13:20 +00:00
call PlaceString
2015-07-18 20:52:03 +00:00
coord hl, 2, 16
ld de, OptionMenuCancelText
2014-05-22 22:13:20 +00:00
call PlaceString
xor a
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
2014-05-22 22:13:20 +00:00
inc a
ld [wLetterPrintingDelayFlags], a
ld [wUnusedCD40], a
ld a, 3 ; text speed cursor Y coordinate
ld [wTopMenuItemY], a
2014-05-22 22:13:20 +00:00
call SetCursorPositionsFromOptions
ld a, [wOptionsTextSpeedCursorX] ; text speed cursor X coordinate
ld [wTopMenuItemX], a
ld a, $01
ld [H_AUTOBGTRANSFERENABLED], a ; enable auto background transfer
2014-05-22 22:13:20 +00:00
call Delay3
.loop
call PlaceMenuCursor
call SetOptionsFromCursorPositions
.getJoypadStateLoop
2014-05-25 18:21:48 +00:00
call JoypadLowSensitivity
ld a, [hJoy5]
ld b, a
and 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
bit 3, b ; Start button pressed?
jr nz, .exitMenu
bit 0, b ; A button pressed?
jr z, .checkDirectionKeys
ld a, [wTopMenuItemY]
cp 16 ; is the cursor on Cancel?
jr nz, .loop
2014-05-22 22:13:20 +00:00
.exitMenu
ld a, SFX_PRESS_AB
call PlaySound
2014-05-22 22:13:20 +00:00
ret
.eraseOldMenuCursor
ld [wTopMenuItemX], a
2014-05-22 22:13:20 +00:00
call EraseMenuCursor
jp .loop
.checkDirectionKeys
ld a, [wTopMenuItemY]
bit 7, b ; Down pressed?
jr nz, .downPressed
bit 6, b ; Up pressed?
jr nz, .upPressed
cp 8 ; cursor in Battle Animation section?
jr z, .cursorInBattleAnimation
cp 13 ; cursor in Battle Style section?
jr z, .cursorInBattleStyle
cp 16 ; cursor on Cancel?
jr z, .loop
2014-05-22 22:13:20 +00:00
.cursorInTextSpeed
bit 5, b ; Left pressed?
jp nz, .pressedLeftInTextSpeed
2014-05-22 22:13:20 +00:00
jp .pressedRightInTextSpeed
.downPressed
cp 16
ld b, -13
ld hl, wOptionsTextSpeedCursorX
jr z, .updateMenuVariables
ld b, 5
cp 3
2014-05-22 22:13:20 +00:00
inc hl
jr z, .updateMenuVariables
cp 8
2014-05-22 22:13:20 +00:00
inc hl
jr z, .updateMenuVariables
ld b, 3
2014-05-22 22:13:20 +00:00
inc hl
jr .updateMenuVariables
.upPressed
cp 8
ld b, -5
ld hl, wOptionsTextSpeedCursorX
jr z, .updateMenuVariables
cp 13
2014-05-22 22:13:20 +00:00
inc hl
jr z, .updateMenuVariables
cp 16
ld b, -3
2014-05-22 22:13:20 +00:00
inc hl
jr z, .updateMenuVariables
ld b, 13
2014-05-22 22:13:20 +00:00
inc hl
.updateMenuVariables
add b
ld [wTopMenuItemY], a
ld a, [hl]
ld [wTopMenuItemX], a
2014-05-22 22:13:20 +00:00
call PlaceUnfilledArrowMenuCursor
jp .loop
.cursorInBattleAnimation
ld a, [wOptionsBattleAnimCursorX] ; battle animation cursor X coordinate
xor $0b ; toggle between 1 and 10
ld [wOptionsBattleAnimCursorX], a
2014-05-22 22:13:20 +00:00
jp .eraseOldMenuCursor
.cursorInBattleStyle
ld a, [wOptionsBattleStyleCursorX] ; battle style cursor X coordinate
xor $0b ; toggle between 1 and 10
ld [wOptionsBattleStyleCursorX], a
2014-05-22 22:13:20 +00:00
jp .eraseOldMenuCursor
.pressedLeftInTextSpeed
ld a, [wOptionsTextSpeedCursorX] ; text speed cursor X coordinate
cp 1
jr z, .updateTextSpeedXCoord
cp 7
jr nz, .fromSlowToMedium
sub 6
2014-05-22 22:13:20 +00:00
jr .updateTextSpeedXCoord
.fromSlowToMedium
sub 7
2014-05-22 22:13:20 +00:00
jr .updateTextSpeedXCoord
.pressedRightInTextSpeed
ld a, [wOptionsTextSpeedCursorX] ; text speed cursor X coordinate
cp 14
jr z, .updateTextSpeedXCoord
cp 7
jr nz, .fromFastToMedium
add 7
2014-05-22 22:13:20 +00:00
jr .updateTextSpeedXCoord
.fromFastToMedium
add 6
2014-05-22 22:13:20 +00:00
.updateTextSpeedXCoord
ld [wOptionsTextSpeedCursorX], a ; text speed cursor X coordinate
2014-05-22 22:13:20 +00:00
jp .eraseOldMenuCursor
2016-06-12 00:24:04 +00:00
TextSpeedOptionText:
2014-05-22 22:13:20 +00:00
db "TEXT SPEED"
next " FAST MEDIUM SLOW@"
2016-06-12 00:24:04 +00:00
BattleAnimationOptionText:
2014-05-22 22:13:20 +00:00
db "BATTLE ANIMATION"
next " ON OFF@"
2016-06-12 00:24:04 +00:00
BattleStyleOptionText:
2014-05-22 22:13:20 +00:00
db "BATTLE STYLE"
next " SHIFT SET@"
2016-06-12 00:24:04 +00:00
OptionMenuCancelText:
2014-05-22 22:13:20 +00:00
db "CANCEL@"
; sets the options variable according to the current placement of the menu cursors in the options menu
2016-06-12 00:24:04 +00:00
SetOptionsFromCursorPositions:
ld hl, TextSpeedOptionData
ld a, [wOptionsTextSpeedCursorX] ; text speed cursor X coordinate
ld c, a
2014-05-22 22:13:20 +00:00
.loop
ld a, [hli]
2014-05-22 22:13:20 +00:00
cp c
jr z, .textSpeedMatchFound
2014-05-22 22:13:20 +00:00
inc hl
jr .loop
.textSpeedMatchFound
ld a, [hl]
ld d, a
ld a, [wOptionsBattleAnimCursorX] ; battle animation cursor X coordinate
2014-05-22 22:13:20 +00:00
dec a
jr z, .battleAnimationOn
2014-05-22 22:13:20 +00:00
.battleAnimationOff
set 7, d
2014-05-22 22:13:20 +00:00
jr .checkBattleStyle
.battleAnimationOn
res 7, d
2014-05-22 22:13:20 +00:00
.checkBattleStyle
ld a, [wOptionsBattleStyleCursorX] ; battle style cursor X coordinate
2014-05-22 22:13:20 +00:00
dec a
jr z, .battleStyleShift
2014-05-22 22:13:20 +00:00
.battleStyleSet
set 6, d
2014-05-22 22:13:20 +00:00
jr .storeOptions
.battleStyleShift
res 6, d
2014-05-22 22:13:20 +00:00
.storeOptions
ld a, d
ld [wOptions], a
2014-05-22 22:13:20 +00:00
ret
; reads the options variable and places menu cursors in the correct positions within the options menu
2016-06-12 00:24:04 +00:00
SetCursorPositionsFromOptions:
ld hl, TextSpeedOptionData + 1
ld a, [wOptions]
ld c, a
and $3f
2014-05-22 22:13:20 +00:00
push bc
ld de, 2
2014-05-22 22:13:20 +00:00
call IsInArray
pop bc
dec hl
ld a, [hl]
ld [wOptionsTextSpeedCursorX], a ; text speed cursor X coordinate
2015-07-18 20:52:03 +00:00
coord hl, 0, 3
2014-05-22 22:13:20 +00:00
call .placeUnfilledRightArrow
sla c
ld a, 1 ; On
jr nc, .storeBattleAnimationCursorX
ld a, 10 ; Off
2014-05-22 22:13:20 +00:00
.storeBattleAnimationCursorX
ld [wOptionsBattleAnimCursorX], a ; battle animation cursor X coordinate
2015-07-18 20:52:03 +00:00
coord hl, 0, 8
2014-05-22 22:13:20 +00:00
call .placeUnfilledRightArrow
sla c
ld a, 1
jr nc, .storeBattleStyleCursorX
ld a, 10
2014-05-22 22:13:20 +00:00
.storeBattleStyleCursorX
ld [wOptionsBattleStyleCursorX], a ; battle style cursor X coordinate
2015-07-18 20:52:03 +00:00
coord hl, 0, 13
2014-05-22 22:13:20 +00:00
call .placeUnfilledRightArrow
; cursor in front of Cancel
2015-07-18 20:52:03 +00:00
coord hl, 0, 16
ld a, 1
2014-05-22 22:13:20 +00:00
.placeUnfilledRightArrow
ld e, a
ld d, 0
add hl, de
ld [hl], $ec ; unfilled right arrow menu cursor
2014-05-22 22:13:20 +00:00
ret
; table that indicates how the 3 text speed options affect frame delays
; Format:
; 00: X coordinate of menu cursor
; 01: delay after printing a letter (in frames)
2016-06-12 00:24:04 +00:00
TextSpeedOptionData:
2014-05-22 22:13:20 +00:00
db 14,5 ; Slow
db 7,3 ; Medium
db 1,1 ; Fast
db 7 ; default X coordinate (Medium)
db $ff ; terminator
2016-06-12 00:24:04 +00:00
CheckForPlayerNameInSRAM:
2015-07-19 03:49:52 +00:00
; 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
2014-05-22 22:13:20 +00:00
ld a, $1
2015-07-19 03:49:52 +00:00
ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
ld b, NAME_LENGTH
2015-07-19 03:49:52 +00:00
ld hl, sPlayerName
.loop
2014-05-22 22:13:20 +00:00
ld a, [hli]
2015-07-19 03:49:52 +00:00
cp "@"
jr z, .found
2014-05-22 22:13:20 +00:00
dec b
2015-07-19 03:49:52 +00:00
jr nz, .loop
; not found
2014-05-22 22:13:20 +00:00
xor a
2015-07-19 03:49:52 +00:00
ld [MBC1SRamEnable], a
ld [MBC1SRamBankingMode], a
2014-05-22 22:13:20 +00:00
and a
ret
2015-07-19 03:49:52 +00:00
.found
2014-05-22 22:13:20 +00:00
xor a
2015-07-19 03:49:52 +00:00
ld [MBC1SRamEnable], a
ld [MBC1SRamBankingMode], a
2014-05-22 22:13:20 +00:00
scf
ret