Remove RTC (#1) and remove time of day dependence on RTC (#7) [Commit #2]

This commit is contained in:
xCrystal 2023-07-28 00:07:07 +02:00
parent 0571144a7b
commit 05448d7a7e
18 changed files with 100 additions and 177 deletions

View File

@ -31,7 +31,8 @@ DEF MORN_HOUR EQU 4 ; 4 AM
DEF DAY_HOUR EQU 10 ; 10 AM DEF DAY_HOUR EQU 10 ; 10 AM
DEF NITE_HOUR EQU 18 ; 6 PM DEF NITE_HOUR EQU 18 ; 6 PM
DEF NOON_HOUR EQU 12 ; 12 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 ; significant money values
DEF START_MONEY EQU 3000 DEF START_MONEY EQU 3000

View File

@ -55,22 +55,20 @@ DEF STRING_BUFFER_LENGTH EQU 19
const VAR_BADGES ; 07 const VAR_BADGES ; 07
const VAR_MOVEMENT ; 08 const VAR_MOVEMENT ; 08
const VAR_FACING ; 09 const VAR_FACING ; 09
const VAR_HOUR ; 0a const VAR_WEEKDAY ; 0a
const VAR_WEEKDAY ; 0b const VAR_MAPGROUP ; 0b
const VAR_MAPGROUP ; 0c const VAR_MAPNUMBER ; 0c
const VAR_MAPNUMBER ; 0d const VAR_UNOWNCOUNT ; 0d
const VAR_UNOWNCOUNT ; 0e const VAR_ENVIRONMENT ; 0e
const VAR_ENVIRONMENT ; 0f const VAR_BOXSPACE ; 0f
const VAR_BOXSPACE ; 10 const VAR_CONTESTMINUTES ; 10
const VAR_CONTESTMINUTES ; 11 const VAR_XCOORD ; 11
const VAR_XCOORD ; 12 const VAR_YCOORD ; 12
const VAR_YCOORD ; 13 const VAR_SPECIALPHONECALL ; 13
const VAR_SPECIALPHONECALL ; 14 const VAR_KURT_APRICORNS ; 14
const VAR_KURT_APRICORNS ; 15 const VAR_CALLERID ; 15
const VAR_CALLERID ; 16 const VAR_BLUECARDBALANCE ; 16
const VAR_BLUECARDBALANCE ; 17 const VAR_BUENASPASSWORD ; 17
const VAR_BUENASPASSWORD ; 18
const VAR_KENJI_BREAK ; 19
DEF NUM_VARS EQU const_value DEF NUM_VARS EQU const_value
; variable action types ; variable action types

View File

@ -11,8 +11,5 @@ DefaultOptions:
db GBPRINTER_NORMAL db GBPRINTER_NORMAL
; wOptions2: menu account on ; wOptions2: menu account on
db 1 << MENU_ACCOUNT db 1 << MENU_ACCOUNT
db $00
db $00
.End .End
assert DefaultOptions.End - DefaultOptions == wOptionsEnd - wOptions assert DefaultOptions.End - DefaultOptions == wOptionsEnd - wOptions

View File

@ -127,7 +127,6 @@ SpecialsPointers::
add_special BuenasPassword add_special BuenasPassword
add_special BuenaPrize add_special BuenaPrize
add_special GiveDratini add_special GiveDratini
add_special SampleKenjiBreakCountdown
add_special BeastsCheck add_special BeastsCheck
add_special MonCheck add_special MonCheck
add_special SetPlayerPalette add_special SetPlayerPalette

View File

@ -1378,12 +1378,12 @@ DebugRoom_SaveRTC:
call YesNoBox call YesNoBox
ret c ret c
ld hl, wDebugRoomRTCSec ld hl, wDebugRoomRTCSec
call DebugRoom_SetClock ; call DebugRoom_SetClock
ret ret
DebugRoomMenu_RTCEdit_UpdateClock: DebugRoomMenu_RTCEdit_UpdateClock:
ld hl, wDebugRoomRTCCurSec ld hl, wDebugRoomRTCCurSec
call DebugRoom_GetClock ; call DebugRoom_GetClock
ld de, DebugRoom_DayHTimeString ld de, DebugRoom_DayHTimeString
hlcoord 3, 14 hlcoord 3, 14
call PlaceString call PlaceString
@ -1418,42 +1418,6 @@ DebugRoomMenu_RTCEdit_UpdateClock:
DebugRoom_DayHTimeString: DebugRoom_DayHTimeString:
db "DAY H<LF>TIME@" db "DAY H<LF>TIME@"
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: DebugRoomMenu_RTCEdit_Page1Values:
db 5 db 5
paged_value wDebugRoomRTCSec, 0, 60 - 1, 0, .SecondString, NULL, FALSE paged_value wDebugRoomRTCSec, 0, 60 - 1, 0, .SecondString, NULL, FALSE

View File

@ -9,9 +9,6 @@ Intro_MainMenu:
farcall MainMenu farcall MainMenu
jp StartTitleScreen jp StartTitleScreen
IntroMenu_DummyFunction: ; unreferenced
ret
PrintDayOfWeek: PrintDayOfWeek:
push de push de
ld hl, .Days ld hl, .Days
@ -57,6 +54,7 @@ NewGame:
ld [wDebugFlags], a ld [wDebugFlags], a
call ResetWRAM call ResetWRAM
call NewGame_ClearTilemapEtc call NewGame_ClearTilemapEtc
call InitTime ; set wStartDay through wStartSecond to $00
call AreYouABoyOrAreYouAGirl call AreYouABoyOrAreYouAGirl
call OakSpeech call OakSpeech
call InitializeWorld call InitializeWorld
@ -97,14 +95,10 @@ _ResetWRAM:
xor a xor a
call ByteFill call ByteFill
ldh a, [rLY]
ldh [hUnusedBackup], a
call DelayFrame call DelayFrame
ldh a, [hRandomSub] ldh a, [hRandomSub]
ld [wPlayerID], a ld [wPlayerID], a
ldh a, [rLY]
ldh [hUnusedBackup], a
call DelayFrame call DelayFrame
ldh a, [hRandomAdd] ldh a, [hRandomAdd]
ld [wPlayerID + 1], a ld [wPlayerID + 1], a

View File

@ -233,7 +233,7 @@ MenuJoypadLoop:
.loop .loop
call Move2DMenuCursor call Move2DMenuCursor
call .BGMap_OAM call .BGMap_OAM
call Do2DMenuRTCJoypad call Do2DMenuJoypad
jr nc, .done jr nc, .done
call _2DMenuInterpretJoypad call _2DMenuInterpretJoypad
jr c, .done jr c, .done
@ -261,14 +261,14 @@ MenuJoypadLoop:
ldh [hBGMapMode], a ldh [hBGMapMode], a
ret ret
Do2DMenuRTCJoypad: Do2DMenuJoypad:
.loopRTC .loop
call UpdateTimeSensitivePals call UpdateTimeSensitivePals
call Menu_WasButtonPressed call Menu_WasButtonPressed
ret c ret c
ld a, [w2DMenuFlags1] ld a, [w2DMenuFlags1]
bit 7, a bit 7, a
jr z, .loopRTC jr z, .loop
and a and a
ret ret

View File

@ -2,7 +2,7 @@ _InitializeStartDay:
call InitializeStartDay call InitializeStartDay
ret ret
ClearDailyTimers: ClearDailyTimers::
xor a xor a
ld [wLuckyNumberDayTimer], a ld [wLuckyNumberDayTimer], a
ld [wDailyResetTimer], a ld [wDailyResetTimer], a
@ -80,12 +80,12 @@ RestartReceiveCallDelay:
ld hl, wReceiveCallDelay_MinsRemaining ld hl, wReceiveCallDelay_MinsRemaining
ld [hl], a ld [hl], a
ld hl, wReceiveCallDelay_StartTime ld hl, wReceiveCallDelay_StartTime
call CopyDayHourMinToHL call CopyHourMinToHL
ret ret
CheckReceiveCallDelay: CheckReceiveCallDelay:
ld hl, wReceiveCallDelay_StartTime ld hl, wReceiveCallDelay_StartTime
call CalcMinsHoursDaysSince call CalcMinsHoursSince
call GetMinutesSinceIfLessThan60 call GetMinutesSinceIfLessThan60
ld hl, wReceiveCallDelay_MinsRemaining ld hl, wReceiveCallDelay_MinsRemaining
call UpdateTimeRemaining call UpdateTimeRemaining
@ -105,40 +105,20 @@ CheckDailyResetTimer::
ld [hli], a ; wDailyFlags2 ld [hli], a ; wDailyFlags2
ld [hli], a ; wSwarmFlags ld [hli], a ; wSwarmFlags
ld [hl], a ; wSwarmFlags + 1 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 jr RestartDailyResetTimer
SampleKenjiBreakCountdown:
; Generate a random number between 3 and 6
call Random
and %11
add 3
ld [wKenjiBreakTimer], a
ret
StartBugContestTimer: StartBugContestTimer:
ld a, BUG_CONTEST_MINUTES ld a, BUG_CONTEST_MINUTES
ld [wBugContestMinsRemaining], a ld [wBugContestMinsRemaining], a
ld a, BUG_CONTEST_SECONDS ld a, BUG_CONTEST_SECONDS
ld [wBugContestSecsRemaining], a ld [wBugContestSecsRemaining], a
ld hl, wBugContestStartTime ld hl, wBugContestStartTime
call CopyDayHourMinSecToHL call CopyHourMinSecToHL
ret ret
CheckBugContestTimer:: CheckBugContestTimer::
ld hl, wBugContestStartTime ld hl, wBugContestStartTime
call CalcSecsMinsHoursDaysSince call CalcSecsMinsHoursSince
ld a, [wDaysSince]
and a
jr nz, .timed_out
ld a, [wHoursSince] ld a, [wHoursSince]
and a and a
jr nz, .timed_out jr nz, .timed_out
@ -231,9 +211,6 @@ UpdateTimeRemaining:
ret ret
GetSecondsSinceIfLessThan60: ; unreferenced GetSecondsSinceIfLessThan60: ; unreferenced
ld a, [wDaysSince]
and a
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wHoursSince] ld a, [wHoursSince]
and a and a
jr nz, GetTimeElapsed_ExceedsUnitLimit jr nz, GetTimeElapsed_ExceedsUnitLimit
@ -243,9 +220,6 @@ GetSecondsSinceIfLessThan60: ; unreferenced
ret ret
GetMinutesSinceIfLessThan60: GetMinutesSinceIfLessThan60:
ld a, [wDaysSince]
and a
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wHoursSince] ld a, [wHoursSince]
and a and a
jr nz, GetTimeElapsed_ExceedsUnitLimit jr nz, GetTimeElapsed_ExceedsUnitLimit
@ -253,9 +227,6 @@ GetMinutesSinceIfLessThan60:
ret ret
GetHoursSinceIfLessThan24: ; unreferenced GetHoursSinceIfLessThan24: ; unreferenced
ld a, [wDaysSince]
and a
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wHoursSince] ld a, [wHoursSince]
ret ret
@ -271,22 +242,19 @@ CalcDaysSince:
xor a xor a
jr _CalcDaysSince jr _CalcDaysSince
CalcHoursDaysSince: ; unreferenced CalcHoursSince: ; unreferenced
xor a
jr _CalcHoursSince
CalcMinsHoursSince:
inc hl inc hl
xor a xor a
jr _CalcHoursDaysSince jr _CalcMinsHoursSince
CalcMinsHoursDaysSince: CalcSecsMinsHoursSince:
inc hl inc hl
inc hl inc hl
xor a ld a, [wGameTimeSeconds]
jr _CalcMinsHoursDaysSince
CalcSecsMinsHoursDaysSince:
inc hl
inc hl
inc hl
ldh a, [hSeconds]
ld c, a ld c, a
sub [hl] sub [hl]
jr nc, .skip jr nc, .skip
@ -296,8 +264,8 @@ CalcSecsMinsHoursDaysSince:
dec hl dec hl
ld [wSecondsSince], a ; seconds since ld [wSecondsSince], a ; seconds since
_CalcMinsHoursDaysSince: _CalcMinsHoursSince:
ldh a, [hMinutes] ld a, [wGameTimeMinutes]
ld c, a ld c, a
sbc [hl] sbc [hl]
jr nc, .skip jr nc, .skip
@ -307,36 +275,32 @@ _CalcMinsHoursDaysSince:
dec hl dec hl
ld [wMinutesSince], a ; minutes since ld [wMinutesSince], a ; minutes since
_CalcHoursDaysSince: _CalcHoursSince:
ldh a, [hHours] ; assumes differentials below 256 hours
ld a, [wGameTimeHours + 1]
ld c, a ld c, a
sbc [hl] sub [hl]
jr nc, .skip
add MAX_HOUR
.skip
ld [hl], c ; current hours ld [hl], c ; current hours
dec hl
ld [wHoursSince], a ; hours since ld [wHoursSince], a ; hours since
ret
_CalcDaysSince: _CalcDaysSince:
ld a, [wCurDay] ld a, [wCurDay]
ld c, a ld c, a
sbc [hl] sbc [hl]
jr nc, .skip jr nc, .skip
add 20 * 7 add MAX_DAYS
.skip .skip
ld [hl], c ; current days ld [hl], c ; current days
ld [wDaysSince], a ; days since ld [wDaysSince], a ; days since
ret ret
CopyDayHourMinSecToHL: CopyHourMinSecToHL:
ld a, [wCurDay] ld a, [wGameTimeHours + 1]
ld [hli], a ld [hli], a
ldh a, [hHours] ld a, [wGameTimeMinutes]
ld [hli], a ld [hli], a
ldh a, [hMinutes] ld a, [wGameTimeSeconds]
ld [hli], a
ldh a, [hSeconds]
ld [hli], a ld [hli], a
ret ret
@ -345,11 +309,9 @@ CopyDayToHL:
ld [hl], a ld [hl], a
ret ret
CopyDayHourMinToHL: CopyHourMinToHL:
ld a, [wCurDay] ld a, [wGameTimeHours + 1]
ld [hli], a ld [hli], a
ldh a, [hHours] ld a, [wGameTimeMinutes]
ld [hli], a
ldh a, [hMinutes]
ld [hli], a ld [hli], a
ret ret

View File

@ -48,7 +48,6 @@ _GetVarAction::
dwb .CountBadges, RETVAR_EXECUTE dwb .CountBadges, RETVAR_EXECUTE
dwb wPlayerState, RETVAR_ADDR_DE dwb wPlayerState, RETVAR_ADDR_DE
dwb .PlayerFacing, RETVAR_EXECUTE dwb .PlayerFacing, RETVAR_EXECUTE
dwb hHours, RETVAR_STRBUF2
dwb .DayOfWeek, RETVAR_EXECUTE dwb .DayOfWeek, RETVAR_EXECUTE
dwb wMapGroup, RETVAR_STRBUF2 dwb wMapGroup, RETVAR_STRBUF2
dwb wMapNumber, RETVAR_STRBUF2 dwb wMapNumber, RETVAR_STRBUF2
@ -63,7 +62,6 @@ _GetVarAction::
dwb wCurCaller, RETVAR_ADDR_DE dwb wCurCaller, RETVAR_ADDR_DE
dwb wBlueCardBalance, RETVAR_ADDR_DE dwb wBlueCardBalance, RETVAR_ADDR_DE
dwb wBuenasPassword, RETVAR_ADDR_DE dwb wBuenasPassword, RETVAR_ADDR_DE
dwb wKenjiBreakTimer, RETVAR_STRBUF2
dwb NULL, RETVAR_STRBUF2 dwb NULL, RETVAR_STRBUF2
.CountCaughtMons: .CountCaughtMons:

View File

@ -1161,20 +1161,6 @@ PokegearPhoneContactSubmenu:
dw .Call dw .Call
dw .Cancel 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: Pokegear_SwitchPage:
ld de, SFX_READ_TEXT_2 ld de, SFX_READ_TEXT_2
call PlaySFX call PlaySFX

View File

@ -141,7 +141,6 @@ Init::
ldh [hBGMapAddress], a ldh [hBGMapAddress], a
xor a ; SRAM_DISABLE xor a ; SRAM_DISABLE
ld [MBC3LatchClock], a
ld [MBC3SRamEnable], a ld [MBC3SRamEnable], a
ldh a, [hCGB] ldh a, [hCGB]

View File

@ -270,7 +270,7 @@ CheckObjectTime::
ld hl, MAPOBJECT_HOUR_2 ld hl, MAPOBJECT_HOUR_2
add hl, bc add hl, bc
ld e, [hl] ld e, [hl]
ld hl, hHours ld hl, wGameTimeHours + 1
ld a, d ld a, d
cp e cp e
jr z, .yes jr z, .yes

View File

@ -23,10 +23,7 @@ endc
.valid: .valid:
; switch to sram bank a ; switch to sram bank a
push af push af
; latch clock data ; enable sram write
ld a, 1
ld [MBC3LatchClock], a
; enable sram/clock write
ld a, SRAM_ENABLE ld a, SRAM_ENABLE
ld [MBC3SRamEnable], a ld [MBC3SRamEnable], a
; select sram bank ; select sram bank
@ -37,9 +34,7 @@ endc
CloseSRAM:: CloseSRAM::
push af push af
ld a, SRAM_DISABLE ld a, SRAM_DISABLE
; reset clock latch for next time ; disable sram write
ld [MBC3LatchClock], a
; disable sram/clock write
ld [MBC3SRamEnable], a ld [MBC3SRamEnable], a
pop af pop af
ret ret

View File

@ -1,4 +1,43 @@
; Functions relating to the timer interrupt.
Timer:: Timer::
reti 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

View File

@ -139,9 +139,6 @@ VBlank0::
ldh a, [hROMBankBackup] ldh a, [hROMBankBackup]
rst Bankswitch rst Bankswitch
ldh a, [hSeconds]
ldh [hUnusedBackup], a
ret ret
VBlank2:: VBlank2::

View File

@ -5,10 +5,6 @@ hFarByte::
hTempBank:: db hTempBank:: db
hSRAMBank:: db hSRAMBank:: db
hHours:: db
hMinutes:: db
hSeconds:: db
hVBlankCounter:: db hVBlankCounter:: db
hROMBank:: db hROMBank:: db
@ -125,8 +121,6 @@ hLastTalked:: db
hRandomAdd:: db hRandomAdd:: db
hRandomSub:: db hRandomSub:: db
hUnusedBackup:: db
hBattleTurn:: hBattleTurn::
; Which trainer's turn is it? 0: player, 1: opponent trainer ; Which trainer's turn is it? 0: player, 1: opponent trainer
db db

View File

@ -31,9 +31,11 @@ for n, 1, MAILBOX_CAPACITY + 1
sMailbox{d:n}Backup:: mailmsg sMailbox{d:n}Backup sMailbox{d:n}Backup:: mailmsg sMailbox{d:n}Backup
endr endr
sRTCStatusFlags:: db
sLuckyNumberDay:: db sLuckyNumberDay:: db
sLuckyIDNumber:: dw sLuckyIDNumber:: dw
if DEF(_DEBUG)
sRTCStatusFlags:: db
endc
SECTION "Backup Save", SRAM SECTION "Backup Save", SRAM

View File

@ -1269,7 +1269,6 @@ wGBPrinterBrightness::
wOptions2:: wOptions2::
; bit 1: menu account off/on ; bit 1: menu account off/on
db db
ds 2
wOptionsEnd:: wOptionsEnd::
; Time buffer, for counting the amount of time since ; Time buffer, for counting the amount of time since
@ -2202,7 +2201,7 @@ wMapReentryScriptAddress:: dw
wTimeCyclesSinceLastCall:: db wTimeCyclesSinceLastCall:: db
wReceiveCallDelay_MinsRemaining:: db wReceiveCallDelay_MinsRemaining:: db
wReceiveCallDelay_StartTime:: ds 3 wReceiveCallDelay_StartTime:: ds 2 ; hour, min
wBugContestMinsRemaining:: db wBugContestMinsRemaining:: db
wBugContestSecsRemaining:: db wBugContestSecsRemaining:: db
@ -2425,11 +2424,10 @@ wLuckyNumberDayTimer:: dw
wSpecialPhoneCallID:: db wSpecialPhoneCallID:: db
wBugContestStartTime:: ds 4 ; day, hour, min, sec wBugContestStartTime:: ds 3 ; hour, min, sec
wBuenasPassword:: db wBuenasPassword:: db
wBlueCardBalance:: db wBlueCardBalance:: db
wKenjiBreakTimer:: ds 2 ; Kenji
wYanmaMapGroup:: db wYanmaMapGroup:: db
wYanmaMapNumber:: db wYanmaMapNumber:: db