From 05448d7a7eb444cbcdf213a6a367acaa9b926d29 Mon Sep 17 00:00:00 2001 From: xCrystal Date: Fri, 28 Jul 2023 00:07:07 +0200 Subject: [PATCH] Remove RTC (#1) and remove time of day dependence on RTC (#7) [Commit #2] --- constants/misc_constants.asm | 3 +- constants/script_constants.asm | 30 +++++----- data/default_options.asm | 3 - data/events/special_pointers.asm | 1 - engine/debug/debug_room.asm | 40 +------------- engine/menus/intro_menu.asm | 8 +-- engine/menus/menu.asm | 8 +-- engine/overworld/time.asm | 94 ++++++++++---------------------- engine/overworld/variables.asm | 2 - engine/pokegear/pokegear.asm | 14 ----- home/init.asm | 1 - home/map_objects.asm | 2 +- home/sram.asm | 9 +-- home/time.asm | 43 ++++++++++++++- home/vblank.asm | 3 - ram/hram.asm | 6 -- ram/sram.asm | 4 +- ram/wram.asm | 6 +- 18 files changed, 100 insertions(+), 177 deletions(-) diff --git a/constants/misc_constants.asm b/constants/misc_constants.asm index b909d57c7..6344151d4 100644 --- a/constants/misc_constants.asm +++ b/constants/misc_constants.asm @@ -31,7 +31,8 @@ DEF MORN_HOUR EQU 4 ; 4 AM DEF DAY_HOUR EQU 10 ; 10 AM DEF NITE_HOUR EQU 18 ; 6 PM DEF NOON_HOUR EQU 12 ; 12 PM -DEF MAX_HOUR EQU 24 ; 12 AM + +DEF MAX_DAYS EQU 36 * 7 ; 252 ; significant money values DEF START_MONEY EQU 3000 diff --git a/constants/script_constants.asm b/constants/script_constants.asm index 0ac73ad23..ad7671f4a 100644 --- a/constants/script_constants.asm +++ b/constants/script_constants.asm @@ -55,22 +55,20 @@ DEF STRING_BUFFER_LENGTH EQU 19 const VAR_BADGES ; 07 const VAR_MOVEMENT ; 08 const VAR_FACING ; 09 - const VAR_HOUR ; 0a - const VAR_WEEKDAY ; 0b - const VAR_MAPGROUP ; 0c - const VAR_MAPNUMBER ; 0d - const VAR_UNOWNCOUNT ; 0e - const VAR_ENVIRONMENT ; 0f - const VAR_BOXSPACE ; 10 - const VAR_CONTESTMINUTES ; 11 - const VAR_XCOORD ; 12 - const VAR_YCOORD ; 13 - const VAR_SPECIALPHONECALL ; 14 - const VAR_KURT_APRICORNS ; 15 - const VAR_CALLERID ; 16 - const VAR_BLUECARDBALANCE ; 17 - const VAR_BUENASPASSWORD ; 18 - const VAR_KENJI_BREAK ; 19 + const VAR_WEEKDAY ; 0a + const VAR_MAPGROUP ; 0b + const VAR_MAPNUMBER ; 0c + const VAR_UNOWNCOUNT ; 0d + const VAR_ENVIRONMENT ; 0e + const VAR_BOXSPACE ; 0f + const VAR_CONTESTMINUTES ; 10 + const VAR_XCOORD ; 11 + const VAR_YCOORD ; 12 + const VAR_SPECIALPHONECALL ; 13 + const VAR_KURT_APRICORNS ; 14 + const VAR_CALLERID ; 15 + const VAR_BLUECARDBALANCE ; 16 + const VAR_BUENASPASSWORD ; 17 DEF NUM_VARS EQU const_value ; variable action types diff --git a/data/default_options.asm b/data/default_options.asm index 76de34387..a541b8a51 100644 --- a/data/default_options.asm +++ b/data/default_options.asm @@ -11,8 +11,5 @@ DefaultOptions: db GBPRINTER_NORMAL ; wOptions2: menu account on db 1 << MENU_ACCOUNT - - db $00 - db $00 .End assert DefaultOptions.End - DefaultOptions == wOptionsEnd - wOptions diff --git a/data/events/special_pointers.asm b/data/events/special_pointers.asm index 65fca70aa..55543a08d 100644 --- a/data/events/special_pointers.asm +++ b/data/events/special_pointers.asm @@ -127,7 +127,6 @@ SpecialsPointers:: add_special BuenasPassword add_special BuenaPrize add_special GiveDratini - add_special SampleKenjiBreakCountdown add_special BeastsCheck add_special MonCheck add_special SetPlayerPalette diff --git a/engine/debug/debug_room.asm b/engine/debug/debug_room.asm index 4c0ade57e..2f6592145 100644 --- a/engine/debug/debug_room.asm +++ b/engine/debug/debug_room.asm @@ -1378,12 +1378,12 @@ DebugRoom_SaveRTC: call YesNoBox ret c ld hl, wDebugRoomRTCSec - call DebugRoom_SetClock +; call DebugRoom_SetClock ret DebugRoomMenu_RTCEdit_UpdateClock: ld hl, wDebugRoomRTCCurSec - call DebugRoom_GetClock +; call DebugRoom_GetClock ld de, DebugRoom_DayHTimeString hlcoord 3, 14 call PlaceString @@ -1418,42 +1418,6 @@ DebugRoomMenu_RTCEdit_UpdateClock: DebugRoom_DayHTimeString: db "DAY HTIME@" -DebugRoom_GetClock: - ld a, SRAM_ENABLE - ld [MBC3SRamEnable], a - xor a - ld [MBC3LatchClock], a - inc a - ld [MBC3LatchClock], a - ld b, RTC_DH - RTC_S + 1 - ld c, RTC_S -.loop - ld a, c - ld [MBC3SRamBank], a - ld a, [MBC3RTC] - ld [hli], a - inc c - dec b - jr nz, .loop - call CloseSRAM - ret - -DebugRoom_SetClock: - ld a, SRAM_ENABLE - ld [MBC3SRamEnable], a - ld b, RTC_DH - RTC_S + 1 - ld c, RTC_S -.loop - ld a, c - ld [MBC3SRamBank], a - ld a, [hli] - ld [MBC3RTC], a - inc c - dec b - jr nz, .loop - call CloseSRAM - ret - DebugRoomMenu_RTCEdit_Page1Values: db 5 paged_value wDebugRoomRTCSec, 0, 60 - 1, 0, .SecondString, NULL, FALSE diff --git a/engine/menus/intro_menu.asm b/engine/menus/intro_menu.asm index f602721b3..b8d6e4be0 100644 --- a/engine/menus/intro_menu.asm +++ b/engine/menus/intro_menu.asm @@ -9,9 +9,6 @@ Intro_MainMenu: farcall MainMenu jp StartTitleScreen -IntroMenu_DummyFunction: ; unreferenced - ret - PrintDayOfWeek: push de ld hl, .Days @@ -57,6 +54,7 @@ NewGame: ld [wDebugFlags], a call ResetWRAM call NewGame_ClearTilemapEtc + call InitTime ; set wStartDay through wStartSecond to $00 call AreYouABoyOrAreYouAGirl call OakSpeech call InitializeWorld @@ -97,14 +95,10 @@ _ResetWRAM: xor a call ByteFill - ldh a, [rLY] - ldh [hUnusedBackup], a call DelayFrame ldh a, [hRandomSub] ld [wPlayerID], a - ldh a, [rLY] - ldh [hUnusedBackup], a call DelayFrame ldh a, [hRandomAdd] ld [wPlayerID + 1], a diff --git a/engine/menus/menu.asm b/engine/menus/menu.asm index 1d090be11..6b65c895f 100644 --- a/engine/menus/menu.asm +++ b/engine/menus/menu.asm @@ -233,7 +233,7 @@ MenuJoypadLoop: .loop call Move2DMenuCursor call .BGMap_OAM - call Do2DMenuRTCJoypad + call Do2DMenuJoypad jr nc, .done call _2DMenuInterpretJoypad jr c, .done @@ -261,14 +261,14 @@ MenuJoypadLoop: ldh [hBGMapMode], a ret -Do2DMenuRTCJoypad: -.loopRTC +Do2DMenuJoypad: +.loop call UpdateTimeSensitivePals call Menu_WasButtonPressed ret c ld a, [w2DMenuFlags1] bit 7, a - jr z, .loopRTC + jr z, .loop and a ret diff --git a/engine/overworld/time.asm b/engine/overworld/time.asm index 34ac01272..157a5645e 100644 --- a/engine/overworld/time.asm +++ b/engine/overworld/time.asm @@ -2,7 +2,7 @@ _InitializeStartDay: call InitializeStartDay ret -ClearDailyTimers: +ClearDailyTimers:: xor a ld [wLuckyNumberDayTimer], a ld [wDailyResetTimer], a @@ -80,12 +80,12 @@ RestartReceiveCallDelay: ld hl, wReceiveCallDelay_MinsRemaining ld [hl], a ld hl, wReceiveCallDelay_StartTime - call CopyDayHourMinToHL + call CopyHourMinToHL ret CheckReceiveCallDelay: ld hl, wReceiveCallDelay_StartTime - call CalcMinsHoursDaysSince + call CalcMinsHoursSince call GetMinutesSinceIfLessThan60 ld hl, wReceiveCallDelay_MinsRemaining call UpdateTimeRemaining @@ -105,40 +105,20 @@ CheckDailyResetTimer:: ld [hli], a ; wDailyFlags2 ld [hli], a ; wSwarmFlags ld [hl], a ; wSwarmFlags + 1 - ld hl, wKenjiBreakTimer - ld a, [hl] - and a - jr z, .RestartKenjiBreakCountdown - dec [hl] - jr nz, .DontRestartKenjiBreakCountdown -.RestartKenjiBreakCountdown: - call SampleKenjiBreakCountdown -.DontRestartKenjiBreakCountdown: jr RestartDailyResetTimer -SampleKenjiBreakCountdown: -; Generate a random number between 3 and 6 - call Random - and %11 - add 3 - ld [wKenjiBreakTimer], a - ret - StartBugContestTimer: ld a, BUG_CONTEST_MINUTES ld [wBugContestMinsRemaining], a ld a, BUG_CONTEST_SECONDS ld [wBugContestSecsRemaining], a ld hl, wBugContestStartTime - call CopyDayHourMinSecToHL + call CopyHourMinSecToHL ret CheckBugContestTimer:: ld hl, wBugContestStartTime - call CalcSecsMinsHoursDaysSince - ld a, [wDaysSince] - and a - jr nz, .timed_out + call CalcSecsMinsHoursSince ld a, [wHoursSince] and a jr nz, .timed_out @@ -231,9 +211,6 @@ UpdateTimeRemaining: ret GetSecondsSinceIfLessThan60: ; unreferenced - ld a, [wDaysSince] - and a - jr nz, GetTimeElapsed_ExceedsUnitLimit ld a, [wHoursSince] and a jr nz, GetTimeElapsed_ExceedsUnitLimit @@ -243,9 +220,6 @@ GetSecondsSinceIfLessThan60: ; unreferenced ret GetMinutesSinceIfLessThan60: - ld a, [wDaysSince] - and a - jr nz, GetTimeElapsed_ExceedsUnitLimit ld a, [wHoursSince] and a jr nz, GetTimeElapsed_ExceedsUnitLimit @@ -253,9 +227,6 @@ GetMinutesSinceIfLessThan60: ret GetHoursSinceIfLessThan24: ; unreferenced - ld a, [wDaysSince] - and a - jr nz, GetTimeElapsed_ExceedsUnitLimit ld a, [wHoursSince] ret @@ -271,22 +242,19 @@ CalcDaysSince: xor a jr _CalcDaysSince -CalcHoursDaysSince: ; unreferenced +CalcHoursSince: ; unreferenced + xor a + jr _CalcHoursSince + +CalcMinsHoursSince: inc hl xor a - jr _CalcHoursDaysSince + jr _CalcMinsHoursSince -CalcMinsHoursDaysSince: +CalcSecsMinsHoursSince: inc hl inc hl - xor a - jr _CalcMinsHoursDaysSince - -CalcSecsMinsHoursDaysSince: - inc hl - inc hl - inc hl - ldh a, [hSeconds] + ld a, [wGameTimeSeconds] ld c, a sub [hl] jr nc, .skip @@ -296,8 +264,8 @@ CalcSecsMinsHoursDaysSince: dec hl ld [wSecondsSince], a ; seconds since -_CalcMinsHoursDaysSince: - ldh a, [hMinutes] +_CalcMinsHoursSince: + ld a, [wGameTimeMinutes] ld c, a sbc [hl] jr nc, .skip @@ -307,36 +275,32 @@ _CalcMinsHoursDaysSince: dec hl ld [wMinutesSince], a ; minutes since -_CalcHoursDaysSince: - ldh a, [hHours] +_CalcHoursSince: +; assumes differentials below 256 hours + ld a, [wGameTimeHours + 1] ld c, a - sbc [hl] - jr nc, .skip - add MAX_HOUR -.skip + sub [hl] ld [hl], c ; current hours - dec hl ld [wHoursSince], a ; hours since + ret _CalcDaysSince: ld a, [wCurDay] ld c, a sbc [hl] jr nc, .skip - add 20 * 7 + add MAX_DAYS .skip ld [hl], c ; current days ld [wDaysSince], a ; days since ret -CopyDayHourMinSecToHL: - ld a, [wCurDay] +CopyHourMinSecToHL: + ld a, [wGameTimeHours + 1] ld [hli], a - ldh a, [hHours] + ld a, [wGameTimeMinutes] ld [hli], a - ldh a, [hMinutes] - ld [hli], a - ldh a, [hSeconds] + ld a, [wGameTimeSeconds] ld [hli], a ret @@ -345,11 +309,9 @@ CopyDayToHL: ld [hl], a ret -CopyDayHourMinToHL: - ld a, [wCurDay] +CopyHourMinToHL: + ld a, [wGameTimeHours + 1] ld [hli], a - ldh a, [hHours] - ld [hli], a - ldh a, [hMinutes] + ld a, [wGameTimeMinutes] ld [hli], a ret diff --git a/engine/overworld/variables.asm b/engine/overworld/variables.asm index f3e967fdd..a757eff9f 100644 --- a/engine/overworld/variables.asm +++ b/engine/overworld/variables.asm @@ -48,7 +48,6 @@ _GetVarAction:: dwb .CountBadges, RETVAR_EXECUTE dwb wPlayerState, RETVAR_ADDR_DE dwb .PlayerFacing, RETVAR_EXECUTE - dwb hHours, RETVAR_STRBUF2 dwb .DayOfWeek, RETVAR_EXECUTE dwb wMapGroup, RETVAR_STRBUF2 dwb wMapNumber, RETVAR_STRBUF2 @@ -63,7 +62,6 @@ _GetVarAction:: dwb wCurCaller, RETVAR_ADDR_DE dwb wBlueCardBalance, RETVAR_ADDR_DE dwb wBuenasPassword, RETVAR_ADDR_DE - dwb wKenjiBreakTimer, RETVAR_STRBUF2 dwb NULL, RETVAR_STRBUF2 .CountCaughtMons: diff --git a/engine/pokegear/pokegear.asm b/engine/pokegear/pokegear.asm index f7134890c..18e6c8fdb 100644 --- a/engine/pokegear/pokegear.asm +++ b/engine/pokegear/pokegear.asm @@ -1161,20 +1161,6 @@ PokegearPhoneContactSubmenu: dw .Call dw .Cancel -GetAMPMHours: ; unreferenced - ldh a, [hHours] - cp NOON_HOUR - jr c, .am - sub NOON_HOUR - ld [wTempByteValue], a - scf - ret - -.am - ld [wTempByteValue], a - and a - ret - Pokegear_SwitchPage: ld de, SFX_READ_TEXT_2 call PlaySFX diff --git a/home/init.asm b/home/init.asm index 9f022dcc1..278719256 100644 --- a/home/init.asm +++ b/home/init.asm @@ -141,7 +141,6 @@ Init:: ldh [hBGMapAddress], a xor a ; SRAM_DISABLE - ld [MBC3LatchClock], a ld [MBC3SRamEnable], a ldh a, [hCGB] diff --git a/home/map_objects.asm b/home/map_objects.asm index 50c00c7fb..0a66dfdf8 100644 --- a/home/map_objects.asm +++ b/home/map_objects.asm @@ -270,7 +270,7 @@ CheckObjectTime:: ld hl, MAPOBJECT_HOUR_2 add hl, bc ld e, [hl] - ld hl, hHours + ld hl, wGameTimeHours + 1 ld a, d cp e jr z, .yes diff --git a/home/sram.asm b/home/sram.asm index 6999f7ed8..4a30257eb 100644 --- a/home/sram.asm +++ b/home/sram.asm @@ -23,10 +23,7 @@ endc .valid: ; switch to sram bank a push af -; latch clock data - ld a, 1 - ld [MBC3LatchClock], a -; enable sram/clock write +; enable sram write ld a, SRAM_ENABLE ld [MBC3SRamEnable], a ; select sram bank @@ -37,9 +34,7 @@ endc CloseSRAM:: push af ld a, SRAM_DISABLE -; reset clock latch for next time - ld [MBC3LatchClock], a -; disable sram/clock write +; disable sram write ld [MBC3SRamEnable], a pop af ret diff --git a/home/time.asm b/home/time.asm index 4253f091b..303015735 100644 --- a/home/time.asm +++ b/home/time.asm @@ -1,4 +1,43 @@ -; Functions relating to the timer interrupt. - Timer:: reti + +InitTime:: + ld hl, wStartDay + ld [hli], a ; wStartDay + ld [hli], a ; wStartHour + ld [hli], a ; wStartMinute + ld [hl], a ; wStartSecond + ret + +AdvanceTimeOfDay:: + ld hl, .TimeOfDayOrder + ld a, [wTimeOfDay] + maskbits NUM_DAYTIMES +.loop + cp [hl] + inc hl + jr z, .gotTimeOfDay + jr .loop +.gotTimeOfDay + ld a, [hl] + ld [wTimeOfDay], a + cp MORN_F + ret nz + +; advance wCurDay and clear daily timers on a transition from NITE to MORN + ld a, [wCurDay] + cp MAX_DAYS + jr z, .restart_days + inc a + jr .set_days +.restart_days + xor a +.set_days + ld [wCurDay], a + + call ClearDailyTimers + + ret + +.TimeOfDayOrder: + db MORN_F, DAY_F, NITE_F, MORN_F, MORN_F diff --git a/home/vblank.asm b/home/vblank.asm index 2cbddd677..0f42130f3 100644 --- a/home/vblank.asm +++ b/home/vblank.asm @@ -139,9 +139,6 @@ VBlank0:: ldh a, [hROMBankBackup] rst Bankswitch - ldh a, [hSeconds] - ldh [hUnusedBackup], a - ret VBlank2:: diff --git a/ram/hram.asm b/ram/hram.asm index 4204efdf2..9cf0fa861 100644 --- a/ram/hram.asm +++ b/ram/hram.asm @@ -5,10 +5,6 @@ hFarByte:: hTempBank:: db hSRAMBank:: db -hHours:: db -hMinutes:: db -hSeconds:: db - hVBlankCounter:: db hROMBank:: db @@ -125,8 +121,6 @@ hLastTalked:: db hRandomAdd:: db hRandomSub:: db -hUnusedBackup:: db - hBattleTurn:: ; Which trainer's turn is it? 0: player, 1: opponent trainer db diff --git a/ram/sram.asm b/ram/sram.asm index ed0d23429..2d84c925f 100644 --- a/ram/sram.asm +++ b/ram/sram.asm @@ -31,9 +31,11 @@ for n, 1, MAILBOX_CAPACITY + 1 sMailbox{d:n}Backup:: mailmsg sMailbox{d:n}Backup endr -sRTCStatusFlags:: db sLuckyNumberDay:: db sLuckyIDNumber:: dw +if DEF(_DEBUG) +sRTCStatusFlags:: db +endc SECTION "Backup Save", SRAM diff --git a/ram/wram.asm b/ram/wram.asm index 078325ec5..94568cad1 100644 --- a/ram/wram.asm +++ b/ram/wram.asm @@ -1269,7 +1269,6 @@ wGBPrinterBrightness:: wOptions2:: ; bit 1: menu account off/on db - ds 2 wOptionsEnd:: ; Time buffer, for counting the amount of time since @@ -2202,7 +2201,7 @@ wMapReentryScriptAddress:: dw wTimeCyclesSinceLastCall:: db wReceiveCallDelay_MinsRemaining:: db -wReceiveCallDelay_StartTime:: ds 3 +wReceiveCallDelay_StartTime:: ds 2 ; hour, min wBugContestMinsRemaining:: db wBugContestSecsRemaining:: db @@ -2425,11 +2424,10 @@ wLuckyNumberDayTimer:: dw wSpecialPhoneCallID:: db -wBugContestStartTime:: ds 4 ; day, hour, min, sec +wBugContestStartTime:: ds 3 ; hour, min, sec wBuenasPassword:: db wBlueCardBalance:: db -wKenjiBreakTimer:: ds 2 ; Kenji wYanmaMapGroup:: db wYanmaMapNumber:: db