Functional stub of title menus [Commit 1] (#17)

This commit is contained in:
xCrystal 2023-10-01 00:10:44 +02:00
parent e53ae0eac9
commit a16322350f
24 changed files with 567 additions and 531 deletions

View File

@ -28,8 +28,7 @@ DEF AUTO_INPUT EQU $ff
const WILDMON ; 4 const WILDMON ; 4
; wGameTimerPaused:: ; wGameTimerPaused::
DEF GAME_TIMER_PAUSED_F EQU 0 DEF GAME_TIMER_COUNTING_F EQU 0
DEF GAME_TIMER_MOBILE_F EQU 7
; wJoypadDisable:: ; wJoypadDisable::
DEF JOYPAD_DISABLE_MON_FAINT_F EQU 6 DEF JOYPAD_DISABLE_MON_FAINT_F EQU 6
@ -63,7 +62,6 @@ DEF NUM_FRAMES EQU const_value
const_def const_def
const FAST_TEXT_DELAY_F ; 0 const FAST_TEXT_DELAY_F ; 0
const TEXT_DELAY_F ; 1 const TEXT_DELAY_F ; 1
const TEXT_2BPP_F ; 2
; wGBPrinterBrightness:: ; wGBPrinterBrightness::
DEF GBPRINTER_LIGHTEST EQU $00 DEF GBPRINTER_LIGHTEST EQU $00
@ -178,10 +176,6 @@ DEF SCRIPT_RUNNING EQU 2
const SCRIPT_WAIT_MOVEMENT const SCRIPT_WAIT_MOVEMENT
const SCRIPT_WAIT const SCRIPT_WAIT
; wSpawnAfterChampion::
DEF SPAWN_LANCE EQU 1
DEF SPAWN_RED EQU 2
; wCurDay:: ; wCurDay::
const_def const_def
const SUNDAY ; 0 const SUNDAY ; 0

View File

@ -102,7 +102,7 @@ endc
engine_flag wSwarmFlags, SWARMFLAGS_BUENAS_PASSWORD_F engine_flag wSwarmFlags, SWARMFLAGS_BUENAS_PASSWORD_F
engine_flag wSwarmFlags, SWARMFLAGS_GOLDENROD_DEPT_STORE_SALE_F engine_flag wSwarmFlags, SWARMFLAGS_GOLDENROD_DEPT_STORE_SALE_F
engine_flag wGameTimerPaused, GAME_TIMER_MOBILE_F engine_flag wGameTimerPaused, 7 ; unused
engine_flag wPlayerGender, PLAYERGENDER_FEMALE_F engine_flag wPlayerGender, PLAYERGENDER_FEMALE_F

View File

@ -31,7 +31,7 @@
- **PrintText1bpp**, **FarPrintText1bpp**: SpeechTextbox1bpp + UpdateSprites + ApplyTilemap + ClearTextbox + PrintTextboxText - **PrintText1bpp**, **FarPrintText1bpp**: SpeechTextbox1bpp + UpdateSprites + ApplyTilemap + ClearTextbox + PrintTextboxText
- **PrintText2bpp**: SpeechTextbox2bpp + UpdateSprites + ApplyTilemap + ClearTextbox + PrintTextboxText - **PrintText2bpp**: SpeechTextbox2bpp + UpdateSprites + ApplyTilemap + ClearTextbox + PrintTextboxText
- **MapTextbox**: ClearTextbox + redraw tile behind cursor + SafeUpdateSprites + disable OAM update + ApplyTilemap + PrintTextboxText + enable OAM update - **MapTextbox**: ClearTextbox + redraw tile behind cursor + SafeUpdateSprites + disable OAM update + ApplyTilemap + PrintTextboxText + enable OAM update
- **MenuBox**: Calls Textbox1bpp or Textbox2bpp, depending on the value at wTextboxFlags[TEXT_2BPP_F], with menu location and dimensions. - **MenuBox**: Calls Textbox1bpp or Textbox2bpp, depending on the value of wText2bpp, with menu location and dimensions.
#### Overworld map scrolling #### Overworld map scrolling

View File

@ -368,8 +368,8 @@ BoardMenu_OpenSubmenu:
call LoadStandardMenuHeader call LoadStandardMenuHeader
farcall FadeOutPalettesToWhite farcall FadeOutPalettesToWhite
call DisableOverworldHUD call DisableOverworldHUD
ld hl, wTextboxFlags ld a, FALSE
res TEXT_2BPP_F, [hl] ld [wText2bpp], a
call LoadStandardFont call LoadStandardFont
call LoadFrame call LoadFrame
call ClearSprites call ClearSprites
@ -378,8 +378,8 @@ BoardMenu_OpenSubmenu:
BoardMenu_CloseSubmenu: BoardMenu_CloseSubmenu:
call ClearBGPalettes call ClearBGPalettes
ld hl, wTextboxFlags ld a, TRUE
set TEXT_2BPP_F, [hl] ld [wText2bpp], a
call EnableOverworldHUD call EnableOverworldHUD
call ReloadTilesetAndPalettes call ReloadTilesetAndPalettes
call UpdateSprites call UpdateSprites

View File

@ -7,8 +7,6 @@ HallOfFame::
ld a, 1 ld a, 1
ld [wGameLogicPaused], a ld [wGameLogicPaused], a
call DisableSpriteUpdates call DisableSpriteUpdates
ld a, SPAWN_LEVEL_1
ld [wSpawnAfterChampion], a
; Enable the Pokégear map to cycle through all of Kanto ; Enable the Pokégear map to cycle through all of Kanto
ld hl, wStatusFlags ld hl, wStatusFlags
@ -49,8 +47,6 @@ RedCredits::
ld c, 8 ld c, 8
call DelayFrames call DelayFrames
call DisableSpriteUpdates call DisableSpriteUpdates
ld a, SPAWN_LEVEL_1
ld [wSpawnAfterChampion], a
ld a, [wStatusFlags] ld a, [wStatusFlags]
ld b, a ld b, a
farcall Credits farcall Credits

121
engine/menus/game_menu.asm Executable file
View File

@ -0,0 +1,121 @@
; GameMenu.String and GameMenu.Jumptable indexes
const_def
const GAMEMENU_WORLD_MAP
const GAMEMENU_SHOP
GameMenu:
ld de, MUSIC_NONE
call PlayMusic
call DelayFrame
ld de, MUSIC_MAIN_MENU
call PlayMusic
; fallthrough
GameMenu_KeepMusic:
call ClearTilemap
call LoadFrame
call LoadStandardFont
call ClearMenuAndWindowData
ld b, CGB_DIPLOMA
call GetCGBLayout
call SetPalettes
xor a
ld [wWhichIndexSet], a
ld hl, .MenuHeader
call LoadMenuHeader
call GameMenuJoypadLoop
call CloseWindow
jr c, .quit
call ClearTilemap
ld a, [wMenuSelection]
ld hl, .Jumptable
rst JumpTable
jr GameMenu
.quit
ret
.MenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 0, 0, 16, 7
dw .MenuData
db 1 ; default option
.MenuData:
db STATICMENU_CURSOR ; flags
db 0 ; items
dw GameMenuItems
dw PlaceMenuStrings
dw .Strings
.Strings:
; entries correspond to GAMEMENUITEM_* constants
db "WORLD MAP@"
db "SHOP@"
.Jumptable:
; entries correspond to GAMEMENUITEM_* constants
dw GameMenu_WorldMap
dw GameMenu_Shop
GameMenuItems:
db 2
db GAMEMENU_WORLD_MAP
db GAMEMENU_SHOP
db -1
GameMenuJoypadLoop:
call SetUpMenu
.loop
ld a, [w2DMenuFlags1]
set 5, a
ld [w2DMenuFlags1], a
call GetScrollingMenuJoypad
ld a, [wMenuJoypad]
cp B_BUTTON
jr z, .b_button
cp A_BUTTON
jr z, .a_button
jr .loop
.a_button
call PlayClickSFX
and a
ret
.b_button
scf
ret
GameMenu_WorldMap:
ld a, [wSaveFileInOverworld]
and a
jr z, .not_in_overworld
ld a, $8
ld [wMusicFade], a
ld a, LOW(MUSIC_NONE)
ld [wMusicFadeID], a
ld a, HIGH(MUSIC_NONE)
ld [wMusicFadeID + 1], a
call ClearBGPalettes
call ClearTilemap
ld c, 20
call DelayFrames
farcall JumpRoamMons
ld a, MAPSETUP_CONTINUE
ldh [hMapEntryMethod], a
xor a
ld [wDontPlayMapMusicOnReload], a
ld [wLinkMode], a
ld hl, wGameTimerPaused
set GAME_TIMER_COUNTING_F, [hl]
farcall OverworldLoop
jp GameMenu
.not_in_overworld
farcall LevelSelectionMenu
ret
GameMenu_Shop:
ret

View File

@ -1,14 +1,3 @@
Intro_MainMenu:
ld de, MUSIC_NONE
call PlayMusic
call DelayFrame
ld de, MUSIC_MAIN_MENU
ld a, e
ld [wMapMusic], a
call PlayMusic
farcall MainMenu
jp StartTitleScreen
PrintDayOfWeek: PrintDayOfWeek:
push de push de
ld hl, .Days ld hl, .Days
@ -36,15 +25,6 @@ PrintDayOfWeek:
.Day: .Day:
db "DAY@" db "DAY@"
NewGame_ClearTilemapEtc:
xor a
ldh [hMapAnims], a
call ClearTilemap
call LoadFrame
call LoadStandardFont
call ClearMenuAndWindowData
ret
Option: Option:
farcall _Option farcall _Option
ret ret
@ -53,24 +33,32 @@ NewGame:
xor a xor a
ld [wDebugFlags], a ld [wDebugFlags], a
call ResetWRAM call ResetWRAM
call NewGame_ClearTilemapEtc xor a
ldh [hMapAnims], a
call ClearTilemap
call LoadFrame
call LoadStandardFont
call ClearMenuAndWindowData
call InitTime ; set wStartDay through wStartSecond to $00 call InitTime ; set wStartDay through wStartSecond to $00
call AreYouABoyOrAreYouAGirl
call OakSpeech
call InitializeWorld
ld a, LANDMARK_LEVEL_1
ld [wPrevLandmark], a
ld a, SPAWN_LEVEL_1
ld [wDefaultSpawnpoint], a
ld a, MAPSETUP_WARP
ldh [hMapEntryMethod], a
jp FinishContinueFunction
AreYouABoyOrAreYouAGirl:
farcall InitGender farcall InitGender
call .SetPlayerName
farcall AutoSaveGameOutsideOverworld
jp GameMenu
.SetPlayerName
ld hl, wPlayerName
ld a, "D"
ld [hli], a
ld a, "E"
ld [hli], a
ld a, "B"
ld [hli], a
ld a, "U"
ld [hli], a
ld a, "G"
ld [hli], a
ld a, "@"
ld [hl], a
ret ret
ResetWRAM: ResetWRAM:
@ -267,12 +255,6 @@ InitializeNPCNames:
.Green: db "GREEN@" .Green: db "GREEN@"
.Mom: db "MOM@" .Mom: db "MOM@"
InitializeWorld:
call ShrinkPlayer
farcall SpawnPlayer
farcall _InitializeStartDay
ret
LoadOrRegenerateLuckyIDNumber: LoadOrRegenerateLuckyIDNumber:
ld a, BANK(sLuckyIDNumber) ld a, BANK(sLuckyIDNumber)
call OpenSRAM call OpenSRAM
@ -302,90 +284,11 @@ LoadOrRegenerateLuckyIDNumber:
Continue: Continue:
farcall TryLoadSaveFile farcall TryLoadSaveFile
jr c, .FailToLoad jr c, .FailToLoad
call LoadStandardMenuHeader jp GameMenu_KeepMusic
call DisplaySaveInfoOnContinue
ld a, $1
ldh [hBGMapMode], a
ld c, 20
call DelayFrames
call ConfirmContinue
jr nc, .CheckPass
call CloseWindow
jr .FailToLoad
.CheckPass:
ld a, $8
ld [wMusicFade], a
ld a, LOW(MUSIC_NONE)
ld [wMusicFadeID], a
ld a, HIGH(MUSIC_NONE)
ld [wMusicFadeID + 1], a
call ClearBGPalettes
call CloseWindow
call ClearTilemap
ld c, 20
call DelayFrames
farcall JumpRoamMons
ld a, [wSpawnAfterChampion]
cp SPAWN_N_A
jr z, .SpawnAfterE4
ld a, MAPSETUP_CONTINUE
ldh [hMapEntryMethod], a
jp FinishContinueFunction
.FailToLoad: .FailToLoad:
ret ret
.SpawnAfterE4:
ld a, SPAWN_LEVEL_1
ld [wDefaultSpawnpoint], a
call PostCreditsSpawn
jp FinishContinueFunction
SpawnAfterRed:
ld a, SPAWN_LEVEL_1
ld [wDefaultSpawnpoint], a
PostCreditsSpawn:
xor a
ld [wSpawnAfterChampion], a
ld a, MAPSETUP_WARP
ldh [hMapEntryMethod], a
ret
ConfirmContinue:
.loop
call DelayFrame
call GetJoypad
ld hl, hJoyPressed
bit A_BUTTON_F, [hl]
jr nz, .PressA
bit B_BUTTON_F, [hl]
jr z, .loop
scf
ret
.PressA:
ret
FinishContinueFunction:
.loop
xor a
ld [wDontPlayMapMusicOnReload], a
ld [wLinkMode], a
ld hl, wGameTimerPaused
set GAME_TIMER_PAUSED_F, [hl]
res GAME_TIMER_MOBILE_F, [hl]
farcall OverworldLoop
ld a, [wSpawnAfterChampion]
cp SPAWN_N_A
jr z, .AfterRed
jp Reset
.AfterRed:
call SpawnAfterRed
jr .loop
DisplaySaveInfoOnContinue: DisplaySaveInfoOnContinue:
lb de, 4, 8 lb de, 4, 8
call DisplayNormalContinueData call DisplayNormalContinueData
@ -829,309 +732,3 @@ Intro_PlacePlayerSprite:
db 9 * TILE_WIDTH + 4, 10 * TILE_WIDTH, 1 db 9 * TILE_WIDTH + 4, 10 * TILE_WIDTH, 1
db 10 * TILE_WIDTH + 4, 9 * TILE_WIDTH, 2 db 10 * TILE_WIDTH + 4, 9 * TILE_WIDTH, 2
db 10 * TILE_WIDTH + 4, 10 * TILE_WIDTH, 3 db 10 * TILE_WIDTH + 4, 10 * TILE_WIDTH, 3
const_def
const TITLESCREENOPTION_MAIN_MENU
const TITLESCREENOPTION_DELETE_SAVE_DATA
const TITLESCREENOPTION_RESTART
const TITLESCREENOPTION_UNUSED
DEF NUM_TITLESCREENOPTIONS EQU const_value
IntroSequence:
callfar SplashScreen
jr c, StartTitleScreen
farcall CrystalIntro
; fallthrough
StartTitleScreen:
ldh a, [rSVBK]
push af
ld a, BANK(wLYOverrides)
ldh [rSVBK], a
call .TitleScreen
call DelayFrame
.loop
call RunTitleScreen
jr nc, .loop
call ClearSprites
call ClearBGPalettes
pop af
ldh [rSVBK], a
ld hl, rLCDC
res rLCDC_SPRITE_SIZE, [hl] ; 8x8
call ClearScreen
call WaitBGMap2
xor a
ldh [hLCDCPointer], a
ldh [hSCX], a
ldh [hSCY], a
ld a, $7
ldh [hWX], a
ld a, $90
ldh [hWY], a
ld b, CGB_DIPLOMA
call GetCGBLayout
call UpdateTimePals
ld a, [wTitleScreenSelectedOption]
cp NUM_TITLESCREENOPTIONS
jr c, .ok
xor a
.ok
ld e, a
ld d, 0
ld hl, .dw
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.dw
dw Intro_MainMenu
dw DeleteSaveData
dw IntroSequence
dw IntroSequence
.TitleScreen:
farcall _TitleScreen
ret
RunTitleScreen:
ld a, [wJumptableIndex]
bit 7, a
jr nz, .done_title
call TitleScreenScene
farcall SuicuneFrameIterator
call DelayFrame
and a
ret
.done_title
scf
ret
UnusedTitlePerspectiveScroll: ; unreferenced
; Similar behavior to Intro_PerspectiveScrollBG.
ldh a, [hVBlankCounter]
and $7
ret nz
ld hl, wLYOverrides + $5f
ld a, [hl]
dec a
ld bc, 2 * SCREEN_WIDTH
call ByteFill
ret
TitleScreenScene:
ld e, a
ld d, 0
ld hl, .scenes
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.scenes
dw TitleScreenEntrance
dw TitleScreenTimer
dw TitleScreenMain
dw TitleScreenEnd
TitleScreenNextScene: ; unreferenced
ld hl, wJumptableIndex
inc [hl]
ret
TitleScreenEntrance:
; Animate the logo:
; Move each line by 4 pixels until our count hits 0.
ldh a, [hSCX]
and a
jr z, .done
sub 4
ldh [hSCX], a
; Lay out a base (all lines scrolling together).
ld e, a
ld hl, wLYOverrides
ld bc, 8 * 10 ; logo height
call ByteFill
; Reversed signage for every other line's position.
; This is responsible for the interlaced effect.
ld a, e
xor $ff
inc a
ld b, 8 * 10 / 2 ; logo height / 2
ld hl, wLYOverrides + 1
.loop
ld [hli], a
inc hl
dec b
jr nz, .loop
farcall AnimateTitleCrystal
ret
.done
; Next scene
ld hl, wJumptableIndex
inc [hl]
xor a
ldh [hLCDCPointer], a
; Play the title screen music.
ld de, MUSIC_TITLE
call PlayMusic
ld a, $88
ldh [hWY], a
ret
TitleScreenTimer:
; Next scene
ld hl, wJumptableIndex
inc [hl]
; Start a timer
ld hl, wTitleScreenTimer
ld de, 73 * 60 + 36
ld [hl], e
inc hl
ld [hl], d
ret
TitleScreenMain:
; Run the timer down.
ld hl, wTitleScreenTimer
ld e, [hl]
inc hl
ld d, [hl]
ld a, e
or d
jr z, .end
dec de
ld [hl], d
dec hl
ld [hl], e
; Save data can be deleted by pressing Up + B + Select.
call GetJoypad
ld hl, hJoyDown
ld a, [hl]
and D_UP + B_BUTTON + SELECT
cp D_UP + B_BUTTON + SELECT
jr z, .delete_save_data
; Press Start or A to start the game.
ld a, [hl]
and START | A_BUTTON
jr nz, .incave
ret
.incave
ld a, TITLESCREENOPTION_MAIN_MENU
jr .done
.delete_save_data
ld a, TITLESCREENOPTION_DELETE_SAVE_DATA
.done
ld [wTitleScreenSelectedOption], a
; Return to the intro sequence.
ld hl, wJumptableIndex
set 7, [hl]
ret
.end
; Next scene
ld hl, wJumptableIndex
inc [hl]
; Fade out the title screen music
xor a ; MUSIC_NONE
ld [wMusicFadeID], a
ld [wMusicFadeID + 1], a
ld hl, wMusicFade
ld [hl], 8 ; 1 second
ld hl, wTitleScreenTimer
inc [hl]
ret
TitleScreenEnd:
; Wait until the music is done fading.
ld hl, wTitleScreenTimer
inc [hl]
ld a, [wMusicFade]
and a
ret nz
ld a, TITLESCREENOPTION_RESTART
ld [wTitleScreenSelectedOption], a
; Back to the intro.
ld hl, wJumptableIndex
set 7, [hl]
ret
DeleteSaveData:
farcall _DeleteSaveData
jp Init
Copyright:
call ClearTilemap
call LoadFrame
ld de, CopyrightGFX
ld hl, vTiles2 tile $60
lb bc, BANK(CopyrightGFX), 29
call Request2bpp
hlcoord 2, 7
ld de, CopyrightString
jp PlaceString
CopyrightString:
; ©1995-2001 Nintendo
db $60, $61, $62, $63, $64, $65, $66
db $67, $68, $69, $6a, $6b, $6c
; ©1995-2001 Creatures inc.
next $60, $61, $62, $63, $64, $65, $66
db $6d, $6e, $6f, $70, $71, $72, $7a, $7b, $7c
; ©1995-2001 GAME FREAK inc.
next $60, $61, $62, $63, $64, $65, $66
db $73, $74, $75, $76, $77, $78, $79, $7a, $7b, $7c
db "@"
GameInit::
farcall TryLoadSaveData
call ClearMenuAndWindowData
call ClearBGPalettes
call ClearTilemap
ld a, HIGH(vBGMap0)
ldh [hBGMapAddress + 1], a
xor a ; LOW(vBGMap0)
ldh [hBGMapAddress], a
ldh [hJoyDown], a
ldh [hSCX], a
ldh [hSCY], a
ld a, $90
ldh [hWY], a
call WaitBGMap
jp IntroSequence

View File

@ -132,6 +132,7 @@ LevelSelectionMenu::
ld [wMusicFadeID + 1], a ld [wMusicFadeID + 1], a
call ClearBGPalettes call ClearBGPalettes
call ClearTilemap call ClearTilemap
farcall ClearSpriteAnims
call ClearSprites call ClearSprites
xor a xor a
ld [wVramState], a ld [wVramState], a
@ -149,7 +150,7 @@ LevelSelectionMenu::
ld a, PLAYER_NORMAL ld a, PLAYER_NORMAL
ld [wPlayerState], a ; this may need to be set on a per-level basis (e.g. if specific level starts with player in surf state) ld [wPlayerState], a ; this may need to be set on a per-level basis (e.g. if specific level starts with player in surf state)
ld hl, wGameTimerPaused ld hl, wGameTimerPaused
set GAME_TIMER_PAUSED_F, [hl] ; start game timer counter set GAME_TIMER_COUNTING_F, [hl] ; start game timer counter
farcall OverworldLoop farcall OverworldLoop
ret ret
@ -161,6 +162,7 @@ LevelSelectionMenu::
call LevelSelectionMenu_Delay10Frames call LevelSelectionMenu_Delay10Frames
call ClearBGPalettes call ClearBGPalettes
call ClearTilemap call ClearTilemap
farcall ClearSpriteAnims
call ClearSprites call ClearSprites
xor a xor a
ld [wVramState], a ld [wVramState], a

View File

@ -1,25 +1,29 @@
; MainMenuItems indexes ; MainMenuItems indexes
const_def const_def
const MAINMENU_NEW_GAME ; 0 const MAINMENU_NEW_GAME ; 0
const MAINMENU_CONTINUE ; 1 const MAINMENU_CONTINUE ; 1
; MainMenu.Strings and MainMenu.Jumptable indexes ; MainMenu.Strings and MainMenu.Jumptable indexes
const_def const_def
const MAINMENUITEM_CONTINUE ; 0 const MAINMENUITEM_CONTINUE ; 0
const MAINMENUITEM_NEW_GAME ; 1 const MAINMENUITEM_NEW_GAME ; 1
const MAINMENUITEM_OPTION ; 2 const MAINMENUITEM_OPTION ; 2
const MAINMENUITEM_DEBUG_ROOM ; 3 const MAINMENUITEM_DEBUG_ROOM ; 3
MainMenu: MainMenu:
.loop .loop
xor a xor a
ld [wDisableTextAcceleration], a ld [wDisableTextAcceleration], a
call ClearTilemapEtc ldh [hMapAnims], a
call ClearTilemap
call LoadFrame
call LoadStandardFont
call ClearMenuAndWindowData
ld b, CGB_DIPLOMA ld b, CGB_DIPLOMA
call GetCGBLayout call GetCGBLayout
call SetPalettes call SetPalettes
ld hl, wGameTimerPaused ld hl, wGameTimerPaused
res GAME_TIMER_PAUSED_F, [hl] res GAME_TIMER_COUNTING_F, [hl]
call MainMenu_GetWhichMenu call MainMenu_GetWhichMenu
ld [wWhichIndexSet], a ld [wWhichIndexSet], a
call MainMenu_PrintCurrentTimeAndDay call MainMenu_PrintCurrentTimeAndDay
@ -88,9 +92,6 @@ endc
db -1 db -1
MainMenu_GetWhichMenu: MainMenu_GetWhichMenu:
nop
nop
nop
ld a, [wSaveFileExists] ld a, [wSaveFileExists]
and a and a
jr nz, .next jr nz, .next
@ -206,25 +207,16 @@ MainMenu_PrintCurrentTimeAndDay:
db "NITE@" db "NITE@"
db "EVE@" db "EVE@"
ClearTilemapEtc:
xor a
ldh [hMapAnims], a
call ClearTilemap
call LoadFrame
call LoadStandardFont
call ClearMenuAndWindowData
ret
MainMenu_NewGame: MainMenu_NewGame:
farcall NewGame call NewGame
ret ret
MainMenu_Option: MainMenu_Option:
farcall Option call Option
ret ret
MainMenu_Continue: MainMenu_Continue:
farcall Continue call Continue
ret ret
if DEF(_DEBUG) if DEF(_DEBUG)

View File

@ -22,6 +22,36 @@ SaveMenu:
scf scf
ret ret
AutoSaveGameInOverworld:
call PauseGameLogic
; Prevent joypad interrupts
xor a
ldh [hJoypadReleased], a
ldh [hJoypadPressed], a
ldh [hJoypadSum], a
ldh [hJoypadDown], a
; Signal that we're saving inside a level
ld a, TRUE
ld [wSaveFileInOverworld], a
call SaveGameData
call ResumeGameLogic
ret
AutoSaveGameOutsideOverworld:
call PauseGameLogic
; Prevent joypad interrupts
xor a
ldh [hJoypadReleased], a
ldh [hJoypadPressed], a
ldh [hJoypadSum], a
ldh [hJoypadDown], a
; Signal that we're not saving inside a level
xor a ; FALSE
ld [wSaveFileInOverworld], a
call SaveGameData
call ResumeGameLogic
ret
SaveAfterLinkTrade: SaveAfterLinkTrade:
call PauseGameLogic call PauseGameLogic
call SavePokemonData call SavePokemonData
@ -166,10 +196,6 @@ AddHallOfFameEntry:
"MOBILE_EVENT_OBJECT_GS_BALL is no longer equal to $0b." "MOBILE_EVENT_OBJECT_GS_BALL is no longer equal to $0b."
ret ret
SaveGameData:
call _SaveGameData
ret
AskOverwriteSaveFile: AskOverwriteSaveFile:
ld a, [wSaveFileExists] ld a, [wSaveFileExists]
and a and a
@ -230,7 +256,9 @@ CompareLoadedAndSavedPlayerID:
_SavingDontTurnOffThePower: _SavingDontTurnOffThePower:
call SavingDontTurnOffThePower call SavingDontTurnOffThePower
SavedTheGame: SavedTheGame:
call _SaveGameData ld a, TRUE
ld [wSaveFileInOverworld], a
call SaveGameData
; wait 32 frames ; wait 32 frames
ld c, 32 ld c, 32
call DelayFrames call DelayFrames
@ -254,7 +282,7 @@ SavedTheGame:
call DelayFrames call DelayFrames
ret ret
_SaveGameData: SaveGameData:
ld a, TRUE ld a, TRUE
ld [wSaveFileExists], a ld [wSaveFileExists], a
call ValidateSave call ValidateSave

View File

@ -13,8 +13,8 @@
StartMenu:: StartMenu::
call ClearMenuAndWindowData call ClearMenuAndWindowData
ld hl, wTextboxFlags ld a, FALSE
res TEXT_2BPP_F, [hl] ld [wText2bpp], a
ld de, SFX_MENU ld de, SFX_MENU
call PlaySFX call PlaySFX

313
engine/menus/titlescreen.asm Executable file
View File

@ -0,0 +1,313 @@
const_def
const TITLESCREENOPTION_MAIN_MENU
const TITLESCREENOPTION_DELETE_SAVE_DATA
const TITLESCREENOPTION_RESTART
const TITLESCREENOPTION_UNUSED
DEF NUM_TITLESCREENOPTIONS EQU const_value
IntroSequence:
callfar SplashScreen
jr c, StartTitleScreen
farcall CrystalIntro
; fallthrough
StartTitleScreen:
ldh a, [rSVBK]
push af
ld a, BANK(wLYOverrides)
ldh [rSVBK], a
call .TitleScreen
call DelayFrame
.loop
call RunTitleScreen
jr nc, .loop
call ClearSprites
call ClearBGPalettes
pop af
ldh [rSVBK], a
ld hl, rLCDC
res rLCDC_SPRITE_SIZE, [hl] ; 8x8
call ClearScreen
call WaitBGMap2
xor a
ldh [hLCDCPointer], a
ldh [hSCX], a
ldh [hSCY], a
ld a, $7
ldh [hWX], a
ld a, $90
ldh [hWY], a
ld b, CGB_DIPLOMA
call GetCGBLayout
call UpdateTimePals
ld a, [wTitleScreenSelectedOption]
cp NUM_TITLESCREENOPTIONS
jr c, .ok
xor a
.ok
ld e, a
ld d, 0
ld hl, .dw
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.dw
dw Intro_MainMenu
dw DeleteSaveData
dw IntroSequence
dw IntroSequence
.TitleScreen:
farcall _TitleScreen
ret
RunTitleScreen:
ld a, [wJumptableIndex]
bit 7, a
jr nz, .done_title
call TitleScreenScene
farcall SuicuneFrameIterator
call DelayFrame
and a
ret
.done_title
scf
ret
UnusedTitlePerspectiveScroll: ; unreferenced
; Similar behavior to Intro_PerspectiveScrollBG.
ldh a, [hVBlankCounter]
and $7
ret nz
ld hl, wLYOverrides + $5f
ld a, [hl]
dec a
ld bc, 2 * SCREEN_WIDTH
call ByteFill
ret
TitleScreenScene:
ld e, a
ld d, 0
ld hl, .scenes
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.scenes
dw TitleScreenEntrance
dw TitleScreenTimer
dw TitleScreenMain
dw TitleScreenEnd
TitleScreenNextScene: ; unreferenced
ld hl, wJumptableIndex
inc [hl]
ret
TitleScreenEntrance:
; Animate the logo:
; Move each line by 4 pixels until our count hits 0.
ldh a, [hSCX]
and a
jr z, .done
sub 4
ldh [hSCX], a
; Lay out a base (all lines scrolling together).
ld e, a
ld hl, wLYOverrides
ld bc, 8 * 10 ; logo height
call ByteFill
; Reversed signage for every other line's position.
; This is responsible for the interlaced effect.
ld a, e
xor $ff
inc a
ld b, 8 * 10 / 2 ; logo height / 2
ld hl, wLYOverrides + 1
.loop
ld [hli], a
inc hl
dec b
jr nz, .loop
farcall AnimateTitleCrystal
ret
.done
; Next scene
ld hl, wJumptableIndex
inc [hl]
xor a
ldh [hLCDCPointer], a
; Play the title screen music.
ld de, MUSIC_TITLE
call PlayMusic
ld a, $88
ldh [hWY], a
ret
TitleScreenTimer:
; Next scene
ld hl, wJumptableIndex
inc [hl]
; Start a timer
ld hl, wTitleScreenTimer
ld de, 73 * 60 + 36
ld [hl], e
inc hl
ld [hl], d
ret
TitleScreenMain:
; Run the timer down.
ld hl, wTitleScreenTimer
ld e, [hl]
inc hl
ld d, [hl]
ld a, e
or d
jr z, .end
dec de
ld [hl], d
dec hl
ld [hl], e
; Save data can be deleted by pressing Up + B + Select.
call GetJoypad
ld hl, hJoyDown
ld a, [hl]
and D_UP + B_BUTTON + SELECT
cp D_UP + B_BUTTON + SELECT
jr z, .delete_save_data
; Press Start or A to start the game.
ld a, [hl]
and START | A_BUTTON
jr nz, .incave
ret
.incave
ld a, TITLESCREENOPTION_MAIN_MENU
jr .done
.delete_save_data
ld a, TITLESCREENOPTION_DELETE_SAVE_DATA
.done
ld [wTitleScreenSelectedOption], a
; Return to the intro sequence.
ld hl, wJumptableIndex
set 7, [hl]
ret
.end
; Next scene
ld hl, wJumptableIndex
inc [hl]
; Fade out the title screen music
xor a ; MUSIC_NONE
ld [wMusicFadeID], a
ld [wMusicFadeID + 1], a
ld hl, wMusicFade
ld [hl], 8 ; 1 second
ld hl, wTitleScreenTimer
inc [hl]
ret
TitleScreenEnd:
; Wait until the music is done fading.
ld hl, wTitleScreenTimer
inc [hl]
ld a, [wMusicFade]
and a
ret nz
ld a, TITLESCREENOPTION_RESTART
ld [wTitleScreenSelectedOption], a
; Back to the intro.
ld hl, wJumptableIndex
set 7, [hl]
ret
Intro_MainMenu:
ld de, MUSIC_NONE
call PlayMusic
call DelayFrame
ld de, MUSIC_MAIN_MENU
call PlayMusic
call MainMenu
jp StartTitleScreen
DeleteSaveData:
farcall _DeleteSaveData
jp Init
Copyright:
call ClearTilemap
call LoadFrame
ld de, CopyrightGFX
ld hl, vTiles2 tile $60
lb bc, BANK(CopyrightGFX), 29
call Request2bpp
hlcoord 2, 7
ld de, CopyrightString
jp PlaceString
CopyrightString:
; ©1995-2001 Nintendo
db $60, $61, $62, $63, $64, $65, $66
db $67, $68, $69, $6a, $6b, $6c
; ©1995-2001 Creatures inc.
next $60, $61, $62, $63, $64, $65, $66
db $6d, $6e, $6f, $70, $71, $72, $7a, $7b, $7c
; ©1995-2001 GAME FREAK inc.
next $60, $61, $62, $63, $64, $65, $66
db $73, $74, $75, $76, $77, $78, $79, $7a, $7b, $7c
db "@"
GameInit::
farcall TryLoadSaveData
call ClearMenuAndWindowData
call ClearBGPalettes
call ClearTilemap
ld a, HIGH(vBGMap0)
ldh [hBGMapAddress + 1], a
xor a ; LOW(vBGMap0)
ldh [hBGMapAddress], a
ldh [hJoyDown], a
ldh [hSCX], a
ldh [hSCY], a
ld a, $90
ldh [hWY], a
call WaitBGMap
jp IntroSequence

View File

@ -13,7 +13,9 @@ OverworldLoop::
.done .done
call DisableOverworldHUD call DisableOverworldHUD
ld hl, wGameTimerPaused ld hl, wGameTimerPaused
res GAME_TIMER_PAUSED_F, [hl] ; stop game timer counter res GAME_TIMER_COUNTING_F, [hl] ; stop game timer counter
ld a, FALSE
ld [wText2bpp], a
ret ret
.Jumptable: .Jumptable:

View File

@ -2428,14 +2428,14 @@ CheckObjectCoveredByTextbox:
jr c, .object_not_in_textbox jr c, .object_not_in_textbox
;.object_in_textbox ;.object_in_textbox
ld a, [wTextboxFlags] ld a, [wText2bpp]
bit TEXT_2BPP_F, a and a
jr z, .disappear jr z, .disappear
jr .ok8 jr .ok8
.object_not_in_textbox .object_not_in_textbox
ld a, [wTextboxFlags] ld a, [wText2bpp]
bit TEXT_2BPP_F, a and a
jr nz, .not_disappear jr nz, .not_disappear
.ok8 .ok8
@ -2453,8 +2453,8 @@ CheckObjectCoveredByTextbox:
; if we managed make it here without returning early, there are only two options: ; if we managed make it here without returning early, there are only two options:
; - if 1bpp text, the sprite is wholly outside of a textbox ; - if 1bpp text, the sprite is wholly outside of a textbox
; - if 2bpp text, the sprite is wholly inside a textbox ; - if 2bpp text, the sprite is wholly inside a textbox
ld a, [wTextboxFlags] ld a, [wText2bpp]
bit TEXT_2BPP_F, a and a
jr z, .not_disappear jr z, .not_disappear
.disappear .disappear

View File

@ -2315,10 +2315,10 @@ Script_endall:
Script_halloffame: Script_halloffame:
ld hl, wGameTimerPaused ld hl, wGameTimerPaused
res GAME_TIMER_PAUSED_F, [hl] res GAME_TIMER_COUNTING_F, [hl]
farcall HallOfFame farcall HallOfFame
ld hl, wGameTimerPaused ld hl, wGameTimerPaused
set GAME_TIMER_PAUSED_F, [hl] set GAME_TIMER_COUNTING_F, [hl]
jr ReturnFromCredits jr ReturnFromCredits
Script_credits: Script_credits:

View File

@ -1,7 +1,3 @@
_InitializeStartDay:
call InitializeStartDay
ret
ClearDailyTimers:: ClearDailyTimers::
xor a xor a
ld [wLuckyNumberDayTimer], a ld [wLuckyNumberDayTimer], a
@ -63,7 +59,8 @@ InitOneDayCountdown:
InitNDaysCountdown: InitNDaysCountdown:
ld [hl], a ld [hl], a
inc hl ; wLuckyNumberDayTimer + 1 or wDailyResetTimer + 1 (both are dw) inc hl ; wLuckyNumberDayTimer + 1 or wDailyResetTimer + 1 (both are dw)
call CopyDayToHL ld a, [wCurDay]
ld [hl], a
ret ret
CheckDayDependentEventHL: CheckDayDependentEventHL:
@ -147,13 +144,8 @@ CheckBugContestTimer::
scf scf
ret ret
InitializeStartDay:
ld hl, wTimerEventStartDay
call CopyDayToHL
ret
CheckPokerusTick:: CheckPokerusTick::
ld hl, wTimerEventStartDay ld hl, .Day0
call CalcDaysSince call CalcDaysSince
call GetDaysSince call GetDaysSince
and a and a
@ -164,6 +156,9 @@ CheckPokerusTick::
xor a xor a
ret ret
.Day0:
db 0
RestartLuckyNumberCountdown: RestartLuckyNumberCountdown:
call .GetDaysUntilNextFriday call .GetDaysUntilNextFriday
ld hl, wLuckyNumberDayTimer ld hl, wLuckyNumberDayTimer
@ -304,11 +299,6 @@ CopyHourMinSecToHL:
ld [hli], a ld [hli], a
ret ret
CopyDayToHL:
ld a, [wCurDay]
ld [hl], a
ret
CopyHourMinToHL: CopyHourMinToHL:
ld a, [wGameTimeHours + 1] ld a, [wGameTimeHours + 1]
ld [hli], a ld [hli], a

View File

@ -33,7 +33,7 @@ GameTimer::
; Is the timer paused? ; Is the timer paused?
ld hl, wGameTimerPaused ld hl, wGameTimerPaused
bit GAME_TIMER_PAUSED_F, [hl] bit GAME_TIMER_COUNTING_F, [hl]
ret z ret z
; Is the timer already capped? ; Is the timer already capped?

View File

@ -120,7 +120,7 @@ endr
ConstructAndEnableOverworldHUD:: ConstructAndEnableOverworldHUD::
; map setup command used by MAPSETUP_ENTERLEVEL and MAPSETUP_CONTINUE ; map setup command used by MAPSETUP_ENTERLEVEL and MAPSETUP_CONTINUE
ld hl, wTextboxFlags ld a, TRUE
set TEXT_2BPP_F, [hl] ld [wText2bpp], a
call ConstructOverworldHUDTilemap call ConstructOverworldHUDTilemap
jp EnableOverworldHUD jp EnableOverworldHUD

View File

@ -1934,8 +1934,8 @@ ReloadTilesetAndPalettes::
call DisableLCD call DisableLCD
call ClearSprites call ClearSprites
farcall RefreshSprites farcall RefreshSprites
ld a, [wTextboxFlags] ld a, [wText2bpp]
bit TEXT_2BPP_F, a and a
jr nz, .2bpp jr nz, .2bpp
call LoadStandardFont call LoadStandardFont
call LoadFrame call LoadFrame

View File

@ -209,8 +209,8 @@ MenuBox::
call GetMenuBoxDims call GetMenuBoxDims
dec b dec b
dec c dec c
ld a, [wTextboxFlags] ld a, [wText2bpp]
bit TEXT_2BPP_F, a and a
jp z, Textbox1bpp jp z, Textbox1bpp
ld d, h ld d, h
ld e, l ld e, l

View File

@ -167,8 +167,8 @@ Textbox2bpp::
SpeechTextbox: SpeechTextbox:
; Standard 1bpp or 2bpp textbox according to wTextboxFlags[TEXT_2BPP_F] ; Standard 1bpp or 2bpp textbox according to wTextboxFlags[TEXT_2BPP_F]
ld a, [wTextboxFlags] ld a, [wText2bpp]
bit TEXT_2BPP_F, a and a
jr z, SpeechTextbox1bpp jr z, SpeechTextbox1bpp
jr SpeechTextbox2bpp jr SpeechTextbox2bpp

View File

@ -46,8 +46,8 @@ OpenText2bpp::
ld a, BANK(ReanchorBGMap_NoOAMUpdate) ld a, BANK(ReanchorBGMap_NoOAMUpdate)
rst Bankswitch rst Bankswitch
ld hl, wTextboxFlags ld a, TRUE
set TEXT_2BPP_F, [hl] ld [wText2bpp], a
; assumes that the overworld 2bpp font and frame are loaded when calling this ; assumes that the overworld 2bpp font and frame are loaded when calling this
call ReanchorBGMap_NoOAMUpdate ; anchor bgmap call ReanchorBGMap_NoOAMUpdate ; anchor bgmap
@ -68,8 +68,8 @@ OpenText1bpp::
rst Bankswitch rst Bankswitch
; note: 1bpp text is NOT compatible with the overworld HUD enabled because it uses 2bpp font tiles. ; note: 1bpp text is NOT compatible with the overworld HUD enabled because it uses 2bpp font tiles.
ld hl, wTextboxFlags ld a, FALSE
res TEXT_2BPP_F, [hl] ld [wText2bpp], a
call ReanchorBGMap_NoOAMUpdate ; anchor bgmap call ReanchorBGMap_NoOAMUpdate ; anchor bgmap
call SpeechTextbox1bpp call SpeechTextbox1bpp

View File

@ -1,9 +1,12 @@
SECTION "bank1", ROMX SECTION "bank1", ROMX
INCLUDE "engine/menus/titlescreen.asm"
INCLUDE "engine/menus/main_menu.asm"
INCLUDE "engine/menus/intro_menu.asm"
INCLUDE "engine/menus/game_menu.asm"
INCLUDE "engine/link/place_waiting_text.asm" INCLUDE "engine/link/place_waiting_text.asm"
INCLUDE "engine/gfx/load_push_oam.asm" INCLUDE "engine/gfx/load_push_oam.asm"
INCLUDE "engine/overworld/map_objects.asm" INCLUDE "engine/overworld/map_objects.asm"
INCLUDE "engine/menus/intro_menu.asm"
INCLUDE "engine/overworld/init_map.asm" INCLUDE "engine/overworld/init_map.asm"
INCLUDE "engine/pokemon/learn.asm" INCLUDE "engine/pokemon/learn.asm"
INCLUDE "engine/pokemon/correct_nick_errors.asm" INCLUDE "engine/pokemon/correct_nick_errors.asm"
@ -176,7 +179,6 @@ INCLUDE "engine/items/pack_kris.asm"
INCLUDE "engine/events/move_tutor.asm" INCLUDE "engine/events/move_tutor.asm"
INCLUDE "engine/gfx/crystal_layouts.asm" INCLUDE "engine/gfx/crystal_layouts.asm"
INCLUDE "engine/events/celebi.asm" INCLUDE "engine/events/celebi.asm"
INCLUDE "engine/menus/main_menu.asm"
INCLUDE "engine/pokemon/search_owned.asm" INCLUDE "engine/pokemon/search_owned.asm"
INCLUDE "engine/events/buena_menu.asm" INCLUDE "engine/events/buena_menu.asm"

View File

@ -1231,6 +1231,19 @@ wOBP1:: db
wNumHits:: db wNumHits:: db
; Time buffer, for counting the amount of time since
; an event began.
wSecondsSince:: db
wMinutesSince:: db
wHoursSince:: db
wDaysSince:: db
wText2bpp:: db
wWhichHUD::
; index to LoadHUD
db
wOptions:: wOptions::
; bit 0-2: number of frames to delay when printing text ; bit 0-2: number of frames to delay when printing text
; fast 1; mid 3; slow 5 ; fast 1; mid 3; slow 5
@ -1262,17 +1275,6 @@ wOptions2::
db db
wOptionsEnd:: wOptionsEnd::
; Time buffer, for counting the amount of time since
; an event began.
wSecondsSince:: db
wMinutesSince:: db
wHoursSince:: db
wDaysSince:: db
wWhichHUD::
; index to LoadHUD
db
SECTION "WRAM 1", WRAMX SECTION "WRAM 1", WRAMX
@ -2257,7 +2259,6 @@ wPlayerGender::
wSavedAtLeastOnce:: db wSavedAtLeastOnce:: db
wSaveFileInOverworld:: db wSaveFileInOverworld:: db
wSpawnAfterChampion:: db
; init time set at newgame ; init time set at newgame
wStartDay:: db wStartDay:: db
@ -2438,8 +2439,6 @@ wDailyFlags1:: db
wDailyFlags2:: db wDailyFlags2:: db
wSwarmFlags:: db wSwarmFlags:: db
wTimerEventStartDay:: db
wFruitTreeFlags:: flag_array NUM_FRUIT_TREES wFruitTreeFlags:: flag_array NUM_FRUIT_TREES
wLuckyNumberDayTimer:: dw wLuckyNumberDayTimer:: dw