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 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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 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:
db 5
paged_value wDebugRoomRTCSec, 0, 60 - 1, 0, .SecondString, NULL, FALSE

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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

View File

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

View File

@ -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

View File

@ -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

View File

@ -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

View File

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

View File

@ -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

View File

@ -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

View File

@ -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