2023-07-27 15:07:07 -07:00
|
|
|
ClearDailyTimers::
|
2015-10-02 19:49:26 -07:00
|
|
|
xor a
|
2020-12-23 13:29:30 -08:00
|
|
|
ld [wLuckyNumberDayTimer], a
|
2015-10-24 07:34:19 -07:00
|
|
|
ld [wDailyResetTimer], a
|
2015-10-02 19:49:26 -07:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
InitCallReceiveDelay::
|
2015-10-02 19:49:26 -07:00
|
|
|
xor a
|
2015-10-24 07:34:19 -07:00
|
|
|
ld [wTimeCyclesSinceLastCall], a
|
2015-10-02 19:49:26 -07:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
NextCallReceiveDelay:
|
2015-10-24 07:34:19 -07:00
|
|
|
ld a, [wTimeCyclesSinceLastCall]
|
2015-10-02 19:49:26 -07:00
|
|
|
cp 3
|
2015-10-24 07:34:19 -07:00
|
|
|
jr c, .okay
|
2015-10-02 19:49:26 -07:00
|
|
|
ld a, 3
|
|
|
|
|
2015-10-24 07:34:19 -07:00
|
|
|
.okay
|
2015-10-02 19:49:26 -07:00
|
|
|
ld e, a
|
|
|
|
ld d, 0
|
2015-10-24 07:34:19 -07:00
|
|
|
ld hl, .ReceiveCallDelays
|
2015-10-02 19:49:26 -07:00
|
|
|
add hl, de
|
|
|
|
ld a, [hl]
|
2020-07-13 10:05:05 -07:00
|
|
|
if DEF(_DEBUG)
|
|
|
|
ld h, a
|
|
|
|
ld a, BANK(sDebugTimeCyclesSinceLastCall)
|
|
|
|
call OpenSRAM
|
|
|
|
ld a, [sDebugTimeCyclesSinceLastCall]
|
|
|
|
call CloseSRAM
|
|
|
|
dec a
|
|
|
|
cp 2
|
|
|
|
jr nc, .debug_ok
|
|
|
|
xor 1
|
|
|
|
ld h, a
|
|
|
|
.debug_ok
|
|
|
|
ld a, h
|
|
|
|
endc
|
2015-10-24 07:34:19 -07:00
|
|
|
jp RestartReceiveCallDelay
|
2015-10-02 19:49:26 -07:00
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.ReceiveCallDelays:
|
2015-10-02 19:49:26 -07:00
|
|
|
db 20, 10, 5, 3
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CheckReceiveCallTimer:
|
2015-10-24 07:34:19 -07:00
|
|
|
call CheckReceiveCallDelay ; check timer
|
2015-10-02 19:49:26 -07:00
|
|
|
ret nc
|
2015-10-24 07:34:19 -07:00
|
|
|
ld hl, wTimeCyclesSinceLastCall
|
2015-10-02 19:49:26 -07:00
|
|
|
ld a, [hl]
|
|
|
|
cp 3
|
2015-10-24 07:34:19 -07:00
|
|
|
jr nc, .ok
|
2015-10-02 19:49:26 -07:00
|
|
|
inc [hl]
|
|
|
|
|
2015-10-24 07:34:19 -07:00
|
|
|
.ok
|
|
|
|
call NextCallReceiveDelay ; restart timer
|
2015-10-02 19:49:26 -07:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
InitOneDayCountdown:
|
2015-10-02 19:49:26 -07:00
|
|
|
ld a, 1
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
InitNDaysCountdown:
|
2015-10-02 19:49:26 -07:00
|
|
|
ld [hl], a
|
2023-07-27 11:32:15 -07:00
|
|
|
inc hl ; wLuckyNumberDayTimer + 1 or wDailyResetTimer + 1 (both are dw)
|
2023-09-30 15:10:44 -07:00
|
|
|
ld a, [wCurDay]
|
|
|
|
ld [hl], a
|
2015-10-02 19:49:26 -07:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CheckDayDependentEventHL:
|
2015-10-02 19:49:26 -07:00
|
|
|
inc hl
|
|
|
|
push hl
|
2015-10-24 07:34:19 -07:00
|
|
|
call CalcDaysSince
|
|
|
|
call GetDaysSince
|
2015-10-02 19:49:26 -07:00
|
|
|
pop hl
|
|
|
|
dec hl
|
2015-10-24 07:34:19 -07:00
|
|
|
call UpdateTimeRemaining
|
2015-10-02 19:49:26 -07:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
RestartReceiveCallDelay:
|
2015-10-24 07:34:19 -07:00
|
|
|
ld hl, wReceiveCallDelay_MinsRemaining
|
2015-10-02 19:49:26 -07:00
|
|
|
ld [hl], a
|
2015-10-24 07:34:19 -07:00
|
|
|
ld hl, wReceiveCallDelay_StartTime
|
2023-07-27 15:07:07 -07:00
|
|
|
call CopyHourMinToHL
|
2015-10-02 19:49:26 -07:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CheckReceiveCallDelay:
|
2015-10-24 07:34:19 -07:00
|
|
|
ld hl, wReceiveCallDelay_StartTime
|
2023-07-27 15:07:07 -07:00
|
|
|
call CalcMinsHoursSince
|
2015-10-24 07:34:19 -07:00
|
|
|
call GetMinutesSinceIfLessThan60
|
|
|
|
ld hl, wReceiveCallDelay_MinsRemaining
|
|
|
|
call UpdateTimeRemaining
|
2015-10-02 19:49:26 -07:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
RestartDailyResetTimer:
|
2015-10-24 07:34:19 -07:00
|
|
|
ld hl, wDailyResetTimer
|
|
|
|
jp InitOneDayCountdown
|
2015-10-02 19:49:26 -07:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CheckDailyResetTimer::
|
2015-10-24 07:34:19 -07:00
|
|
|
ld hl, wDailyResetTimer
|
2015-10-16 10:35:43 -07:00
|
|
|
call CheckDayDependentEventHL
|
2015-10-02 19:49:26 -07:00
|
|
|
ret nc
|
|
|
|
xor a
|
2018-08-06 10:43:54 -07:00
|
|
|
ld hl, wDailyFlags1
|
|
|
|
ld [hli], a ; wDailyFlags1
|
|
|
|
ld [hli], a ; wDailyFlags2
|
2018-01-22 12:59:24 -08:00
|
|
|
ld [hli], a ; wSwarmFlags
|
|
|
|
ld [hl], a ; wSwarmFlags + 1
|
2015-10-24 07:34:19 -07:00
|
|
|
jr RestartDailyResetTimer
|
2015-10-02 19:49:26 -07:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
StartBugContestTimer:
|
2018-01-11 09:00:01 -08:00
|
|
|
ld a, BUG_CONTEST_MINUTES
|
2015-10-24 07:34:19 -07:00
|
|
|
ld [wBugContestMinsRemaining], a
|
2018-01-11 09:00:01 -08:00
|
|
|
ld a, BUG_CONTEST_SECONDS
|
2015-10-24 07:34:19 -07:00
|
|
|
ld [wBugContestSecsRemaining], a
|
|
|
|
ld hl, wBugContestStartTime
|
2023-07-27 15:07:07 -07:00
|
|
|
call CopyHourMinSecToHL
|
2015-10-02 19:49:26 -07:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CheckBugContestTimer::
|
2015-10-24 07:34:19 -07:00
|
|
|
ld hl, wBugContestStartTime
|
2023-07-27 15:07:07 -07:00
|
|
|
call CalcSecsMinsHoursSince
|
2015-10-24 07:34:19 -07:00
|
|
|
ld a, [wHoursSince]
|
2015-10-02 19:49:26 -07:00
|
|
|
and a
|
2015-10-24 07:34:19 -07:00
|
|
|
jr nz, .timed_out
|
|
|
|
ld a, [wSecondsSince]
|
2015-10-02 19:49:26 -07:00
|
|
|
ld b, a
|
2015-10-24 07:34:19 -07:00
|
|
|
ld a, [wBugContestSecsRemaining]
|
2015-10-02 19:49:26 -07:00
|
|
|
sub b
|
2015-10-24 07:34:19 -07:00
|
|
|
jr nc, .okay
|
|
|
|
add 60
|
|
|
|
|
|
|
|
.okay
|
|
|
|
ld [wBugContestSecsRemaining], a
|
|
|
|
ld a, [wMinutesSince]
|
2015-10-02 19:49:26 -07:00
|
|
|
ld b, a
|
2015-10-24 07:34:19 -07:00
|
|
|
ld a, [wBugContestMinsRemaining]
|
2015-10-02 19:49:26 -07:00
|
|
|
sbc b
|
2015-10-24 07:34:19 -07:00
|
|
|
ld [wBugContestMinsRemaining], a
|
|
|
|
jr c, .timed_out
|
2015-10-02 19:49:26 -07:00
|
|
|
and a
|
|
|
|
ret
|
2015-10-24 07:34:19 -07:00
|
|
|
|
|
|
|
.timed_out
|
2015-10-02 19:49:26 -07:00
|
|
|
xor a
|
2015-10-24 07:34:19 -07:00
|
|
|
ld [wBugContestMinsRemaining], a
|
|
|
|
ld [wBugContestSecsRemaining], a
|
2015-10-02 19:49:26 -07:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CheckPokerusTick::
|
2023-09-30 15:10:44 -07:00
|
|
|
ld hl, .Day0
|
2015-10-24 07:34:19 -07:00
|
|
|
call CalcDaysSince
|
|
|
|
call GetDaysSince
|
2015-10-02 19:49:26 -07:00
|
|
|
and a
|
2016-01-10 14:44:09 -08:00
|
|
|
jr z, .done ; not even a day has passed since game start
|
2015-10-02 19:49:26 -07:00
|
|
|
ld b, a
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall ApplyPokerusTick
|
2015-10-24 07:34:19 -07:00
|
|
|
.done
|
2015-10-02 19:49:26 -07:00
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2023-09-30 15:10:44 -07:00
|
|
|
.Day0:
|
|
|
|
db 0
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
RestartLuckyNumberCountdown:
|
2015-10-10 14:03:04 -07:00
|
|
|
call .GetDaysUntilNextFriday
|
2020-12-23 13:29:30 -08:00
|
|
|
ld hl, wLuckyNumberDayTimer
|
2015-10-24 07:34:19 -07:00
|
|
|
jp InitNDaysCountdown
|
2015-10-02 19:49:26 -07:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.GetDaysUntilNextFriday:
|
2015-10-02 19:49:26 -07:00
|
|
|
call GetWeekday
|
|
|
|
ld c, a
|
2015-10-10 14:03:04 -07:00
|
|
|
ld a, FRIDAY
|
2015-10-02 19:49:26 -07:00
|
|
|
sub c
|
2015-10-10 14:03:04 -07:00
|
|
|
jr z, .friday_saturday
|
2018-01-11 09:00:01 -08:00
|
|
|
jr nc, .earlier ; could have done "ret nc"
|
2015-10-02 19:49:26 -07:00
|
|
|
|
2015-10-10 14:03:04 -07:00
|
|
|
.friday_saturday
|
|
|
|
add 7
|
2015-10-02 19:49:26 -07:00
|
|
|
|
2015-10-10 14:03:04 -07:00
|
|
|
.earlier
|
2015-10-02 19:49:26 -07:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
_CheckLuckyNumberShowFlag:
|
2020-12-23 13:29:30 -08:00
|
|
|
ld hl, wLuckyNumberDayTimer
|
2015-10-16 10:35:43 -07:00
|
|
|
jp CheckDayDependentEventHL
|
2015-10-02 19:49:26 -07:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
UpdateTimeRemaining:
|
2015-10-24 07:34:19 -07:00
|
|
|
; If the amount of time elapsed exceeds the capacity of its
|
|
|
|
; unit, skip this part.
|
2015-10-04 11:14:51 -07:00
|
|
|
cp -1
|
2015-10-24 07:34:19 -07:00
|
|
|
jr z, .set_carry
|
2015-10-02 19:49:26 -07:00
|
|
|
ld c, a
|
2015-10-24 07:34:19 -07:00
|
|
|
ld a, [hl] ; time remaining
|
2015-10-02 19:49:26 -07:00
|
|
|
sub c
|
2015-10-04 11:14:51 -07:00
|
|
|
jr nc, .ok
|
2015-10-02 19:49:26 -07:00
|
|
|
xor a
|
|
|
|
|
2015-10-04 11:14:51 -07:00
|
|
|
.ok
|
2015-10-02 19:49:26 -07:00
|
|
|
ld [hl], a
|
2015-10-24 07:34:19 -07:00
|
|
|
jr z, .set_carry
|
2015-10-02 19:49:26 -07:00
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2015-10-24 07:34:19 -07:00
|
|
|
.set_carry
|
2015-10-02 19:49:26 -07:00
|
|
|
xor a
|
|
|
|
ld [hl], a
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2020-10-26 12:45:57 -07:00
|
|
|
GetSecondsSinceIfLessThan60: ; unreferenced
|
2015-10-24 07:34:19 -07:00
|
|
|
ld a, [wHoursSince]
|
2015-10-02 19:49:26 -07:00
|
|
|
and a
|
2015-10-24 07:34:19 -07:00
|
|
|
jr nz, GetTimeElapsed_ExceedsUnitLimit
|
|
|
|
ld a, [wMinutesSince]
|
|
|
|
jr nz, GetTimeElapsed_ExceedsUnitLimit
|
|
|
|
ld a, [wSecondsSince]
|
2015-10-02 19:49:26 -07:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
GetMinutesSinceIfLessThan60:
|
2015-10-24 07:34:19 -07:00
|
|
|
ld a, [wHoursSince]
|
2015-10-02 19:49:26 -07:00
|
|
|
and a
|
2015-10-24 07:34:19 -07:00
|
|
|
jr nz, GetTimeElapsed_ExceedsUnitLimit
|
|
|
|
ld a, [wMinutesSince]
|
2015-10-02 19:49:26 -07:00
|
|
|
ret
|
|
|
|
|
2020-10-26 12:45:57 -07:00
|
|
|
GetHoursSinceIfLessThan24: ; unreferenced
|
2015-10-24 07:34:19 -07:00
|
|
|
ld a, [wHoursSince]
|
2015-10-02 19:49:26 -07:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
GetDaysSince:
|
2015-10-24 07:34:19 -07:00
|
|
|
ld a, [wDaysSince]
|
2015-10-02 19:49:26 -07:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
GetTimeElapsed_ExceedsUnitLimit:
|
2015-10-24 07:34:19 -07:00
|
|
|
ld a, -1
|
2015-10-02 19:49:26 -07:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CalcDaysSince:
|
2015-10-02 19:49:26 -07:00
|
|
|
xor a
|
2015-10-24 07:34:19 -07:00
|
|
|
jr _CalcDaysSince
|
2015-10-02 19:49:26 -07:00
|
|
|
|
2023-07-27 15:07:07 -07:00
|
|
|
CalcHoursSince: ; unreferenced
|
2015-10-02 19:49:26 -07:00
|
|
|
xor a
|
2023-07-27 15:07:07 -07:00
|
|
|
jr _CalcHoursSince
|
2015-10-02 19:49:26 -07:00
|
|
|
|
2023-07-27 15:07:07 -07:00
|
|
|
CalcMinsHoursSince:
|
2016-05-04 08:46:23 -07:00
|
|
|
inc hl
|
2015-10-02 19:49:26 -07:00
|
|
|
xor a
|
2023-07-27 15:07:07 -07:00
|
|
|
jr _CalcMinsHoursSince
|
2015-10-02 19:49:26 -07:00
|
|
|
|
2023-07-27 15:07:07 -07:00
|
|
|
CalcSecsMinsHoursSince:
|
2016-05-10 09:31:49 -07:00
|
|
|
inc hl
|
|
|
|
inc hl
|
2023-07-27 15:07:07 -07:00
|
|
|
ld a, [wGameTimeSeconds]
|
2015-10-02 19:49:26 -07:00
|
|
|
ld c, a
|
|
|
|
sub [hl]
|
2015-10-24 07:34:19 -07:00
|
|
|
jr nc, .skip
|
2015-10-02 19:49:26 -07:00
|
|
|
add 60
|
2015-10-24 07:34:19 -07:00
|
|
|
.skip
|
|
|
|
ld [hl], c ; current seconds
|
2015-10-02 19:49:26 -07:00
|
|
|
dec hl
|
2015-10-24 07:34:19 -07:00
|
|
|
ld [wSecondsSince], a ; seconds since
|
2015-10-02 19:49:26 -07:00
|
|
|
|
2023-07-27 15:07:07 -07:00
|
|
|
_CalcMinsHoursSince:
|
|
|
|
ld a, [wGameTimeMinutes]
|
2015-10-02 19:49:26 -07:00
|
|
|
ld c, a
|
|
|
|
sbc [hl]
|
2015-10-24 07:34:19 -07:00
|
|
|
jr nc, .skip
|
2015-10-02 19:49:26 -07:00
|
|
|
add 60
|
2015-10-24 07:34:19 -07:00
|
|
|
.skip
|
|
|
|
ld [hl], c ; current minutes
|
2015-10-02 19:49:26 -07:00
|
|
|
dec hl
|
2015-10-24 07:34:19 -07:00
|
|
|
ld [wMinutesSince], a ; minutes since
|
2015-10-02 19:49:26 -07:00
|
|
|
|
2023-07-27 15:07:07 -07:00
|
|
|
_CalcHoursSince:
|
|
|
|
; assumes differentials below 256 hours
|
|
|
|
ld a, [wGameTimeHours + 1]
|
2015-10-02 19:49:26 -07:00
|
|
|
ld c, a
|
2023-07-27 15:07:07 -07:00
|
|
|
sub [hl]
|
2015-10-24 07:34:19 -07:00
|
|
|
ld [hl], c ; current hours
|
|
|
|
ld [wHoursSince], a ; hours since
|
2023-07-27 15:07:07 -07:00
|
|
|
ret
|
2015-10-02 19:49:26 -07:00
|
|
|
|
2015-10-24 07:34:19 -07:00
|
|
|
_CalcDaysSince:
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wCurDay]
|
2015-10-02 19:49:26 -07:00
|
|
|
ld c, a
|
|
|
|
sbc [hl]
|
|
|
|
jr nc, .skip
|
2023-07-27 15:07:07 -07:00
|
|
|
add MAX_DAYS
|
2015-10-02 19:49:26 -07:00
|
|
|
.skip
|
2015-10-24 07:34:19 -07:00
|
|
|
ld [hl], c ; current days
|
|
|
|
ld [wDaysSince], a ; days since
|
2015-10-02 19:49:26 -07:00
|
|
|
ret
|
|
|
|
|
2023-07-27 15:07:07 -07:00
|
|
|
CopyHourMinSecToHL:
|
|
|
|
ld a, [wGameTimeHours + 1]
|
2015-10-02 19:49:26 -07:00
|
|
|
ld [hli], a
|
2023-07-27 15:07:07 -07:00
|
|
|
ld a, [wGameTimeMinutes]
|
2015-10-02 19:49:26 -07:00
|
|
|
ld [hli], a
|
2023-07-27 15:07:07 -07:00
|
|
|
ld a, [wGameTimeSeconds]
|
2015-10-02 19:49:26 -07:00
|
|
|
ld [hli], a
|
|
|
|
ret
|
|
|
|
|
2023-07-27 15:07:07 -07:00
|
|
|
CopyHourMinToHL:
|
|
|
|
ld a, [wGameTimeHours + 1]
|
2015-10-02 19:49:26 -07:00
|
|
|
ld [hli], a
|
2023-07-27 15:07:07 -07:00
|
|
|
ld a, [wGameTimeMinutes]
|
2015-10-02 19:49:26 -07:00
|
|
|
ld [hli], a
|
|
|
|
ret
|