From a16322350fa704c2564a97c7eb1f47b77e889542 Mon Sep 17 00:00:00 2001 From: xCrystal Date: Sun, 1 Oct 2023 00:10:44 +0200 Subject: [PATCH] Functional stub of title menus [Commit 1] (#17) --- constants/wram_constants.asm | 8 +- data/events/engine_flags.asm | 2 +- docs/develop/index.md | 2 +- engine/board/menu.asm | 8 +- engine/events/halloffame.asm | 4 - engine/menus/game_menu.asm | 121 +++++++ engine/menus/intro_menu.asm | 453 ++------------------------ engine/menus/level_selection_menu.asm | 4 +- engine/menus/main_menu.asm | 38 +-- engine/menus/save.asm | 40 ++- engine/menus/start_menu.asm | 4 +- engine/menus/titlescreen.asm | 313 ++++++++++++++++++ engine/overworld/events.asm | 4 +- engine/overworld/map_objects.asm | 12 +- engine/overworld/scripting.asm | 4 +- engine/overworld/time.asm | 22 +- home/game_time.asm | 2 +- home/hud.asm | 4 +- home/map.asm | 4 +- home/menu.asm | 4 +- home/text.asm | 4 +- home/window.asm | 8 +- main.asm | 6 +- ram/wram.asm | 27 +- 24 files changed, 567 insertions(+), 531 deletions(-) create mode 100755 engine/menus/game_menu.asm create mode 100755 engine/menus/titlescreen.asm diff --git a/constants/wram_constants.asm b/constants/wram_constants.asm index 94a6462de..7037202f7 100644 --- a/constants/wram_constants.asm +++ b/constants/wram_constants.asm @@ -28,8 +28,7 @@ DEF AUTO_INPUT EQU $ff const WILDMON ; 4 ; wGameTimerPaused:: -DEF GAME_TIMER_PAUSED_F EQU 0 -DEF GAME_TIMER_MOBILE_F EQU 7 +DEF GAME_TIMER_COUNTING_F EQU 0 ; wJoypadDisable:: DEF JOYPAD_DISABLE_MON_FAINT_F EQU 6 @@ -63,7 +62,6 @@ DEF NUM_FRAMES EQU const_value const_def const FAST_TEXT_DELAY_F ; 0 const TEXT_DELAY_F ; 1 - const TEXT_2BPP_F ; 2 ; wGBPrinterBrightness:: DEF GBPRINTER_LIGHTEST EQU $00 @@ -178,10 +176,6 @@ DEF SCRIPT_RUNNING EQU 2 const SCRIPT_WAIT_MOVEMENT const SCRIPT_WAIT -; wSpawnAfterChampion:: -DEF SPAWN_LANCE EQU 1 -DEF SPAWN_RED EQU 2 - ; wCurDay:: const_def const SUNDAY ; 0 diff --git a/data/events/engine_flags.asm b/data/events/engine_flags.asm index e30b84802..97cf0a3ce 100644 --- a/data/events/engine_flags.asm +++ b/data/events/engine_flags.asm @@ -102,7 +102,7 @@ endc engine_flag wSwarmFlags, SWARMFLAGS_BUENAS_PASSWORD_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 diff --git a/docs/develop/index.md b/docs/develop/index.md index 5a20d41b4..76b7b7920 100755 --- a/docs/develop/index.md +++ b/docs/develop/index.md @@ -31,7 +31,7 @@ - **PrintText1bpp**, **FarPrintText1bpp**: SpeechTextbox1bpp + 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 -- **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 diff --git a/engine/board/menu.asm b/engine/board/menu.asm index 04743f144..843700a91 100755 --- a/engine/board/menu.asm +++ b/engine/board/menu.asm @@ -368,8 +368,8 @@ BoardMenu_OpenSubmenu: call LoadStandardMenuHeader farcall FadeOutPalettesToWhite call DisableOverworldHUD - ld hl, wTextboxFlags - res TEXT_2BPP_F, [hl] + ld a, FALSE + ld [wText2bpp], a call LoadStandardFont call LoadFrame call ClearSprites @@ -378,8 +378,8 @@ BoardMenu_OpenSubmenu: BoardMenu_CloseSubmenu: call ClearBGPalettes - ld hl, wTextboxFlags - set TEXT_2BPP_F, [hl] + ld a, TRUE + ld [wText2bpp], a call EnableOverworldHUD call ReloadTilesetAndPalettes call UpdateSprites diff --git a/engine/events/halloffame.asm b/engine/events/halloffame.asm index 574824eb7..e2ec625bf 100644 --- a/engine/events/halloffame.asm +++ b/engine/events/halloffame.asm @@ -7,8 +7,6 @@ HallOfFame:: ld a, 1 ld [wGameLogicPaused], a call DisableSpriteUpdates - ld a, SPAWN_LEVEL_1 - ld [wSpawnAfterChampion], a ; Enable the Pokégear map to cycle through all of Kanto ld hl, wStatusFlags @@ -49,8 +47,6 @@ RedCredits:: ld c, 8 call DelayFrames call DisableSpriteUpdates - ld a, SPAWN_LEVEL_1 - ld [wSpawnAfterChampion], a ld a, [wStatusFlags] ld b, a farcall Credits diff --git a/engine/menus/game_menu.asm b/engine/menus/game_menu.asm new file mode 100755 index 000000000..979fe139f --- /dev/null +++ b/engine/menus/game_menu.asm @@ -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 diff --git a/engine/menus/intro_menu.asm b/engine/menus/intro_menu.asm index 5b14a4c47..d4508e135 100644 --- a/engine/menus/intro_menu.asm +++ b/engine/menus/intro_menu.asm @@ -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: push de ld hl, .Days @@ -36,15 +25,6 @@ PrintDayOfWeek: .Day: db "DAY@" -NewGame_ClearTilemapEtc: - xor a - ldh [hMapAnims], a - call ClearTilemap - call LoadFrame - call LoadStandardFont - call ClearMenuAndWindowData - ret - Option: farcall _Option ret @@ -53,24 +33,32 @@ NewGame: xor a ld [wDebugFlags], a 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 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 + 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 ResetWRAM: @@ -267,12 +255,6 @@ InitializeNPCNames: .Green: db "GREEN@" .Mom: db "MOM@" -InitializeWorld: - call ShrinkPlayer - farcall SpawnPlayer - farcall _InitializeStartDay - ret - LoadOrRegenerateLuckyIDNumber: ld a, BANK(sLuckyIDNumber) call OpenSRAM @@ -302,90 +284,11 @@ LoadOrRegenerateLuckyIDNumber: Continue: farcall TryLoadSaveFile jr c, .FailToLoad - call LoadStandardMenuHeader - 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 + jp GameMenu_KeepMusic .FailToLoad: 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: lb de, 4, 8 call DisplayNormalContinueData @@ -829,309 +732,3 @@ Intro_PlacePlayerSprite: db 9 * TILE_WIDTH + 4, 10 * TILE_WIDTH, 1 db 10 * TILE_WIDTH + 4, 9 * TILE_WIDTH, 2 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 diff --git a/engine/menus/level_selection_menu.asm b/engine/menus/level_selection_menu.asm index 4e3458ac0..3afe27495 100755 --- a/engine/menus/level_selection_menu.asm +++ b/engine/menus/level_selection_menu.asm @@ -132,6 +132,7 @@ LevelSelectionMenu:: ld [wMusicFadeID + 1], a call ClearBGPalettes call ClearTilemap + farcall ClearSpriteAnims call ClearSprites xor a ld [wVramState], a @@ -149,7 +150,7 @@ LevelSelectionMenu:: 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 hl, wGameTimerPaused - set GAME_TIMER_PAUSED_F, [hl] ; start game timer counter + set GAME_TIMER_COUNTING_F, [hl] ; start game timer counter farcall OverworldLoop ret @@ -161,6 +162,7 @@ LevelSelectionMenu:: call LevelSelectionMenu_Delay10Frames call ClearBGPalettes call ClearTilemap + farcall ClearSpriteAnims call ClearSprites xor a ld [wVramState], a diff --git a/engine/menus/main_menu.asm b/engine/menus/main_menu.asm index 0f48fb1ec..df01ffa94 100644 --- a/engine/menus/main_menu.asm +++ b/engine/menus/main_menu.asm @@ -1,25 +1,29 @@ ; MainMenuItems indexes const_def - const MAINMENU_NEW_GAME ; 0 - const MAINMENU_CONTINUE ; 1 + const MAINMENU_NEW_GAME ; 0 + const MAINMENU_CONTINUE ; 1 ; MainMenu.Strings and MainMenu.Jumptable indexes const_def - const MAINMENUITEM_CONTINUE ; 0 - const MAINMENUITEM_NEW_GAME ; 1 - const MAINMENUITEM_OPTION ; 2 - const MAINMENUITEM_DEBUG_ROOM ; 3 + const MAINMENUITEM_CONTINUE ; 0 + const MAINMENUITEM_NEW_GAME ; 1 + const MAINMENUITEM_OPTION ; 2 + const MAINMENUITEM_DEBUG_ROOM ; 3 MainMenu: .loop xor a ld [wDisableTextAcceleration], a - call ClearTilemapEtc + ldh [hMapAnims], a + call ClearTilemap + call LoadFrame + call LoadStandardFont + call ClearMenuAndWindowData ld b, CGB_DIPLOMA call GetCGBLayout call SetPalettes ld hl, wGameTimerPaused - res GAME_TIMER_PAUSED_F, [hl] + res GAME_TIMER_COUNTING_F, [hl] call MainMenu_GetWhichMenu ld [wWhichIndexSet], a call MainMenu_PrintCurrentTimeAndDay @@ -88,9 +92,6 @@ endc db -1 MainMenu_GetWhichMenu: - nop - nop - nop ld a, [wSaveFileExists] and a jr nz, .next @@ -206,25 +207,16 @@ MainMenu_PrintCurrentTimeAndDay: db "NITE@" db "EVE@" -ClearTilemapEtc: - xor a - ldh [hMapAnims], a - call ClearTilemap - call LoadFrame - call LoadStandardFont - call ClearMenuAndWindowData - ret - MainMenu_NewGame: - farcall NewGame + call NewGame ret MainMenu_Option: - farcall Option + call Option ret MainMenu_Continue: - farcall Continue + call Continue ret if DEF(_DEBUG) diff --git a/engine/menus/save.asm b/engine/menus/save.asm index 63aebef9c..99018ec97 100644 --- a/engine/menus/save.asm +++ b/engine/menus/save.asm @@ -22,6 +22,36 @@ SaveMenu: scf 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: call PauseGameLogic call SavePokemonData @@ -166,10 +196,6 @@ AddHallOfFameEntry: "MOBILE_EVENT_OBJECT_GS_BALL is no longer equal to $0b." ret -SaveGameData: - call _SaveGameData - ret - AskOverwriteSaveFile: ld a, [wSaveFileExists] and a @@ -230,7 +256,9 @@ CompareLoadedAndSavedPlayerID: _SavingDontTurnOffThePower: call SavingDontTurnOffThePower SavedTheGame: - call _SaveGameData + ld a, TRUE + ld [wSaveFileInOverworld], a + call SaveGameData ; wait 32 frames ld c, 32 call DelayFrames @@ -254,7 +282,7 @@ SavedTheGame: call DelayFrames ret -_SaveGameData: +SaveGameData: ld a, TRUE ld [wSaveFileExists], a call ValidateSave diff --git a/engine/menus/start_menu.asm b/engine/menus/start_menu.asm index d6c2b1173..2e9cbd572 100644 --- a/engine/menus/start_menu.asm +++ b/engine/menus/start_menu.asm @@ -13,8 +13,8 @@ StartMenu:: call ClearMenuAndWindowData - ld hl, wTextboxFlags - res TEXT_2BPP_F, [hl] + ld a, FALSE + ld [wText2bpp], a ld de, SFX_MENU call PlaySFX diff --git a/engine/menus/titlescreen.asm b/engine/menus/titlescreen.asm new file mode 100755 index 000000000..fe64d9417 --- /dev/null +++ b/engine/menus/titlescreen.asm @@ -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 diff --git a/engine/overworld/events.asm b/engine/overworld/events.asm index 42e917702..c221f9e35 100644 --- a/engine/overworld/events.asm +++ b/engine/overworld/events.asm @@ -13,7 +13,9 @@ OverworldLoop:: .done call DisableOverworldHUD 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 .Jumptable: diff --git a/engine/overworld/map_objects.asm b/engine/overworld/map_objects.asm index 073bded8f..3e947544e 100644 --- a/engine/overworld/map_objects.asm +++ b/engine/overworld/map_objects.asm @@ -2428,14 +2428,14 @@ CheckObjectCoveredByTextbox: jr c, .object_not_in_textbox ;.object_in_textbox - ld a, [wTextboxFlags] - bit TEXT_2BPP_F, a + ld a, [wText2bpp] + and a jr z, .disappear jr .ok8 .object_not_in_textbox - ld a, [wTextboxFlags] - bit TEXT_2BPP_F, a + ld a, [wText2bpp] + and a jr nz, .not_disappear .ok8 @@ -2453,8 +2453,8 @@ CheckObjectCoveredByTextbox: ; 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 2bpp text, the sprite is wholly inside a textbox - ld a, [wTextboxFlags] - bit TEXT_2BPP_F, a + ld a, [wText2bpp] + and a jr z, .not_disappear .disappear diff --git a/engine/overworld/scripting.asm b/engine/overworld/scripting.asm index c914cd33b..05c133a2d 100644 --- a/engine/overworld/scripting.asm +++ b/engine/overworld/scripting.asm @@ -2315,10 +2315,10 @@ Script_endall: Script_halloffame: ld hl, wGameTimerPaused - res GAME_TIMER_PAUSED_F, [hl] + res GAME_TIMER_COUNTING_F, [hl] farcall HallOfFame ld hl, wGameTimerPaused - set GAME_TIMER_PAUSED_F, [hl] + set GAME_TIMER_COUNTING_F, [hl] jr ReturnFromCredits Script_credits: diff --git a/engine/overworld/time.asm b/engine/overworld/time.asm index 157a5645e..b4bb1380d 100644 --- a/engine/overworld/time.asm +++ b/engine/overworld/time.asm @@ -1,7 +1,3 @@ -_InitializeStartDay: - call InitializeStartDay - ret - ClearDailyTimers:: xor a ld [wLuckyNumberDayTimer], a @@ -63,7 +59,8 @@ InitOneDayCountdown: InitNDaysCountdown: ld [hl], a inc hl ; wLuckyNumberDayTimer + 1 or wDailyResetTimer + 1 (both are dw) - call CopyDayToHL + ld a, [wCurDay] + ld [hl], a ret CheckDayDependentEventHL: @@ -147,13 +144,8 @@ CheckBugContestTimer:: scf ret -InitializeStartDay: - ld hl, wTimerEventStartDay - call CopyDayToHL - ret - CheckPokerusTick:: - ld hl, wTimerEventStartDay + ld hl, .Day0 call CalcDaysSince call GetDaysSince and a @@ -164,6 +156,9 @@ CheckPokerusTick:: xor a ret +.Day0: + db 0 + RestartLuckyNumberCountdown: call .GetDaysUntilNextFriday ld hl, wLuckyNumberDayTimer @@ -304,11 +299,6 @@ CopyHourMinSecToHL: ld [hli], a ret -CopyDayToHL: - ld a, [wCurDay] - ld [hl], a - ret - CopyHourMinToHL: ld a, [wGameTimeHours + 1] ld [hli], a diff --git a/home/game_time.asm b/home/game_time.asm index 5a6732414..749c0c6a5 100644 --- a/home/game_time.asm +++ b/home/game_time.asm @@ -33,7 +33,7 @@ GameTimer:: ; Is the timer paused? ld hl, wGameTimerPaused - bit GAME_TIMER_PAUSED_F, [hl] + bit GAME_TIMER_COUNTING_F, [hl] ret z ; Is the timer already capped? diff --git a/home/hud.asm b/home/hud.asm index d99d72c7c..b9bcc9be4 100755 --- a/home/hud.asm +++ b/home/hud.asm @@ -120,7 +120,7 @@ endr ConstructAndEnableOverworldHUD:: ; map setup command used by MAPSETUP_ENTERLEVEL and MAPSETUP_CONTINUE - ld hl, wTextboxFlags - set TEXT_2BPP_F, [hl] + ld a, TRUE + ld [wText2bpp], a call ConstructOverworldHUDTilemap jp EnableOverworldHUD diff --git a/home/map.asm b/home/map.asm index b2e83ad2e..8d5d0e234 100644 --- a/home/map.asm +++ b/home/map.asm @@ -1934,8 +1934,8 @@ ReloadTilesetAndPalettes:: call DisableLCD call ClearSprites farcall RefreshSprites - ld a, [wTextboxFlags] - bit TEXT_2BPP_F, a + ld a, [wText2bpp] + and a jr nz, .2bpp call LoadStandardFont call LoadFrame diff --git a/home/menu.asm b/home/menu.asm index 1589f8652..03f21caf0 100644 --- a/home/menu.asm +++ b/home/menu.asm @@ -209,8 +209,8 @@ MenuBox:: call GetMenuBoxDims dec b dec c - ld a, [wTextboxFlags] - bit TEXT_2BPP_F, a + ld a, [wText2bpp] + and a jp z, Textbox1bpp ld d, h ld e, l diff --git a/home/text.asm b/home/text.asm index d282e3ed6..82eb7914b 100644 --- a/home/text.asm +++ b/home/text.asm @@ -167,8 +167,8 @@ Textbox2bpp:: SpeechTextbox: ; Standard 1bpp or 2bpp textbox according to wTextboxFlags[TEXT_2BPP_F] - ld a, [wTextboxFlags] - bit TEXT_2BPP_F, a + ld a, [wText2bpp] + and a jr z, SpeechTextbox1bpp jr SpeechTextbox2bpp diff --git a/home/window.asm b/home/window.asm index 9321ecebe..464862a6b 100644 --- a/home/window.asm +++ b/home/window.asm @@ -46,8 +46,8 @@ OpenText2bpp:: ld a, BANK(ReanchorBGMap_NoOAMUpdate) rst Bankswitch - ld hl, wTextboxFlags - set TEXT_2BPP_F, [hl] + ld a, TRUE + ld [wText2bpp], a ; assumes that the overworld 2bpp font and frame are loaded when calling this call ReanchorBGMap_NoOAMUpdate ; anchor bgmap @@ -68,8 +68,8 @@ OpenText1bpp:: rst Bankswitch ; note: 1bpp text is NOT compatible with the overworld HUD enabled because it uses 2bpp font tiles. - ld hl, wTextboxFlags - res TEXT_2BPP_F, [hl] + ld a, FALSE + ld [wText2bpp], a call ReanchorBGMap_NoOAMUpdate ; anchor bgmap call SpeechTextbox1bpp diff --git a/main.asm b/main.asm index 208251401..fbbdcbf7c 100644 --- a/main.asm +++ b/main.asm @@ -1,9 +1,12 @@ 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/gfx/load_push_oam.asm" INCLUDE "engine/overworld/map_objects.asm" -INCLUDE "engine/menus/intro_menu.asm" INCLUDE "engine/overworld/init_map.asm" INCLUDE "engine/pokemon/learn.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/gfx/crystal_layouts.asm" INCLUDE "engine/events/celebi.asm" -INCLUDE "engine/menus/main_menu.asm" INCLUDE "engine/pokemon/search_owned.asm" INCLUDE "engine/events/buena_menu.asm" diff --git a/ram/wram.asm b/ram/wram.asm index 50a012319..e62c00a53 100644 --- a/ram/wram.asm +++ b/ram/wram.asm @@ -1231,6 +1231,19 @@ wOBP1:: 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:: ; bit 0-2: number of frames to delay when printing text ; fast 1; mid 3; slow 5 @@ -1262,17 +1275,6 @@ wOptions2:: db 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 @@ -2257,7 +2259,6 @@ wPlayerGender:: wSavedAtLeastOnce:: db wSaveFileInOverworld:: db -wSpawnAfterChampion:: db ; init time set at newgame wStartDay:: db @@ -2438,8 +2439,6 @@ wDailyFlags1:: db wDailyFlags2:: db wSwarmFlags:: db -wTimerEventStartDay:: db - wFruitTreeFlags:: flag_array NUM_FRUIT_TREES wLuckyNumberDayTimer:: dw