pokecrystal-board/engine/overworld/time.asm

400 lines
6.3 KiB
NASM
Raw Normal View History

2018-06-24 07:09:41 -07:00
_InitializeStartDay:
2015-10-24 07:34:19 -07:00
call InitializeStartDay
ret
2018-06-24 07:09:41 -07:00
ClearDailyTimers:
xor a
ld [wLuckyNumberDayTimer], a
2015-10-24 07:34:19 -07:00
ld [wUnusedTwoDayTimer], a
ld [wDailyResetTimer], a
ret
2018-06-24 07:09:41 -07:00
InitCallReceiveDelay::
xor a
2015-10-24 07:34:19 -07:00
ld [wTimeCyclesSinceLastCall], a
2018-06-24 07:09:41 -07:00
NextCallReceiveDelay:
2015-10-24 07:34:19 -07:00
ld a, [wTimeCyclesSinceLastCall]
cp 3
2015-10-24 07:34:19 -07:00
jr c, .okay
ld a, 3
2015-10-24 07:34:19 -07:00
.okay
ld e, a
ld d, 0
2015-10-24 07:34:19 -07:00
ld hl, .ReceiveCallDelays
add hl, de
ld a, [hl]
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
.ReceiveCallDelays:
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
ret nc
2015-10-24 07:34:19 -07:00
ld hl, wTimeCyclesSinceLastCall
ld a, [hl]
cp 3
2015-10-24 07:34:19 -07:00
jr nc, .ok
inc [hl]
2015-10-24 07:34:19 -07:00
.ok
call NextCallReceiveDelay ; restart timer
scf
ret
2018-06-24 07:09:41 -07:00
InitOneDayCountdown:
ld a, 1
2018-06-24 07:09:41 -07:00
InitNDaysCountdown:
ld [hl], a
push hl
call UpdateTime
pop hl
inc hl
2015-10-24 07:34:19 -07:00
call CopyDayToHL
ret
2018-06-24 07:09:41 -07:00
CheckDayDependentEventHL:
inc hl
push hl
2015-10-24 07:34:19 -07:00
call CalcDaysSince
call GetDaysSince
pop hl
dec hl
2015-10-24 07:34:19 -07:00
call UpdateTimeRemaining
ret
2018-06-24 07:09:41 -07:00
RestartReceiveCallDelay:
2015-10-24 07:34:19 -07:00
ld hl, wReceiveCallDelay_MinsRemaining
ld [hl], a
call UpdateTime
2015-10-24 07:34:19 -07:00
ld hl, wReceiveCallDelay_StartTime
call CopyDayHourMinToHL
ret
2018-06-24 07:09:41 -07:00
CheckReceiveCallDelay:
2015-10-24 07:34:19 -07:00
ld hl, wReceiveCallDelay_StartTime
call CalcMinsHoursDaysSince
call GetMinutesSinceIfLessThan60
ld hl, wReceiveCallDelay_MinsRemaining
call UpdateTimeRemaining
ret
2018-06-24 07:09:41 -07:00
RestartDailyResetTimer:
2015-10-24 07:34:19 -07:00
ld hl, wDailyResetTimer
jp InitOneDayCountdown
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
ret nc
xor a
ld hl, wDailyFlags1
ld [hli], a ; wDailyFlags1
ld [hli], a ; wDailyFlags2
ld [hli], a ; wSwarmFlags
ld [hl], a ; wSwarmFlags + 1
ld hl, wKenjiBreakTimer
ld a, [hl]
and a
2015-10-24 07:34:19 -07:00
jr z, .RestartKenjiBreakCountdown
dec [hl]
2015-10-24 07:34:19 -07:00
jr nz, .DontRestartKenjiBreakCountdown
.RestartKenjiBreakCountdown:
call SampleKenjiBreakCountdown
.DontRestartKenjiBreakCountdown:
2015-10-24 07:34:19 -07:00
jr RestartDailyResetTimer
2018-06-24 07:09:41 -07:00
SampleKenjiBreakCountdown:
2016-03-01 19:31:21 -08:00
; Generate a random number between 3 and 6
call Random
2018-01-11 09:00:01 -08:00
and %11
add 3
ld [wKenjiBreakTimer], a
ret
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
call UpdateTime
2015-10-24 07:34:19 -07:00
ld hl, wBugContestStartTime
call CopyDayHourMinSecToHL
ret
2018-06-24 07:09:41 -07:00
CheckBugContestTimer::
2015-10-24 07:34:19 -07:00
ld hl, wBugContestStartTime
call CalcSecsMinsHoursDaysSince
ld a, [wDaysSince]
and a
2015-10-24 07:34:19 -07:00
jr nz, .timed_out
ld a, [wHoursSince]
and a
2015-10-24 07:34:19 -07:00
jr nz, .timed_out
ld a, [wSecondsSince]
ld b, a
2015-10-24 07:34:19 -07:00
ld a, [wBugContestSecsRemaining]
sub b
2015-10-24 07:34:19 -07:00
jr nc, .okay
add 60
.okay
ld [wBugContestSecsRemaining], a
ld a, [wMinutesSince]
ld b, a
2015-10-24 07:34:19 -07:00
ld a, [wBugContestMinsRemaining]
sbc b
2015-10-24 07:34:19 -07:00
ld [wBugContestMinsRemaining], a
jr c, .timed_out
and a
ret
2015-10-24 07:34:19 -07:00
.timed_out
xor a
2015-10-24 07:34:19 -07:00
ld [wBugContestMinsRemaining], a
ld [wBugContestSecsRemaining], a
scf
ret
2018-06-24 07:09:41 -07:00
InitializeStartDay:
call UpdateTime
2018-01-23 14:39:09 -08:00
ld hl, wTimerEventStartDay
2015-10-24 07:34:19 -07:00
call CopyDayToHL
ret
2018-06-24 07:09:41 -07:00
CheckPokerusTick::
2018-01-23 14:39:09 -08:00
ld hl, wTimerEventStartDay
2015-10-24 07:34:19 -07:00
call CalcDaysSince
call GetDaysSince
and a
2016-01-10 14:44:09 -08:00
jr z, .done ; not even a day has passed since game start
ld b, a
2017-12-24 09:47:30 -08:00
farcall ApplyPokerusTick
2015-10-24 07:34:19 -07:00
.done
xor a
ret
SetUnusedTwoDayTimer: ; unreferenced
2015-10-24 07:34:19 -07:00
ld a, 2
ld hl, wUnusedTwoDayTimer
ld [hl], a
call UpdateTime
2015-10-24 07:34:19 -07:00
ld hl, wUnusedTwoDayTimerStartDate
call CopyDayToHL
ret
2018-06-24 07:09:41 -07:00
CheckUnusedTwoDayTimer:
2015-10-24 07:34:19 -07:00
ld hl, wUnusedTwoDayTimerStartDate
call CalcDaysSince
call GetDaysSince
ld hl, wUnusedTwoDayTimer
call UpdateTimeRemaining
ret
UnusedSetSwarmFlag: ; unreferenced
ld hl, wDailyFlags1
set DAILYFLAGS1_FISH_SWARM_F, [hl]
ret
UnusedCheckSwarmFlag: ; unreferenced
and a
ld hl, wDailyFlags1
bit DAILYFLAGS1_FISH_SWARM_F, [hl]
ret nz
scf
ret
2018-06-24 07:09:41 -07:00
RestartLuckyNumberCountdown:
call .GetDaysUntilNextFriday
ld hl, wLuckyNumberDayTimer
2015-10-24 07:34:19 -07:00
jp InitNDaysCountdown
2018-06-24 07:09:41 -07:00
.GetDaysUntilNextFriday:
call GetWeekday
ld c, a
ld a, FRIDAY
sub c
jr z, .friday_saturday
2018-01-11 09:00:01 -08:00
jr nc, .earlier ; could have done "ret nc"
.friday_saturday
add 7
.earlier
ret
2018-06-24 07:09:41 -07:00
_CheckLuckyNumberShowFlag:
ld hl, wLuckyNumberDayTimer
2015-10-16 10:35:43 -07:00
jp CheckDayDependentEventHL
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
ld c, a
2015-10-24 07:34:19 -07:00
ld a, [hl] ; time remaining
sub c
2015-10-04 11:14:51 -07:00
jr nc, .ok
xor a
2015-10-04 11:14:51 -07:00
.ok
ld [hl], a
2015-10-24 07:34:19 -07:00
jr z, .set_carry
xor a
ret
2015-10-24 07:34:19 -07:00
.set_carry
xor a
ld [hl], a
scf
ret
GetSecondsSinceIfLessThan60: ; unreferenced
2015-10-24 07:34:19 -07:00
ld a, [wDaysSince]
and a
2015-10-24 07:34:19 -07:00
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wHoursSince]
and a
2015-10-24 07:34:19 -07:00
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wMinutesSince]
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wSecondsSince]
ret
2018-06-24 07:09:41 -07:00
GetMinutesSinceIfLessThan60:
2015-10-24 07:34:19 -07:00
ld a, [wDaysSince]
and a
2015-10-24 07:34:19 -07:00
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wHoursSince]
and a
2015-10-24 07:34:19 -07:00
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wMinutesSince]
ret
GetHoursSinceIfLessThan24: ; unreferenced
2015-10-24 07:34:19 -07:00
ld a, [wDaysSince]
and a
2015-10-24 07:34:19 -07:00
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wHoursSince]
ret
2018-06-24 07:09:41 -07:00
GetDaysSince:
2015-10-24 07:34:19 -07:00
ld a, [wDaysSince]
ret
2018-06-24 07:09:41 -07:00
GetTimeElapsed_ExceedsUnitLimit:
2015-10-24 07:34:19 -07:00
ld a, -1
ret
2018-06-24 07:09:41 -07:00
CalcDaysSince:
xor a
2015-10-24 07:34:19 -07:00
jr _CalcDaysSince
CalcHoursDaysSince: ; unreferenced
inc hl
xor a
2015-10-24 07:34:19 -07:00
jr _CalcHoursDaysSince
2018-06-24 07:09:41 -07:00
CalcMinsHoursDaysSince:
inc hl
inc hl
xor a
2015-10-24 07:34:19 -07:00
jr _CalcMinsHoursDaysSince
2018-06-24 07:09:41 -07:00
CalcSecsMinsHoursDaysSince:
inc hl
inc hl
inc hl
ldh a, [hSeconds]
ld c, a
sub [hl]
2015-10-24 07:34:19 -07:00
jr nc, .skip
add 60
2015-10-24 07:34:19 -07:00
.skip
ld [hl], c ; current seconds
dec hl
2015-10-24 07:34:19 -07:00
ld [wSecondsSince], a ; seconds since
2018-06-24 07:09:41 -07:00
_CalcMinsHoursDaysSince:
ldh a, [hMinutes]
ld c, a
sbc [hl]
2015-10-24 07:34:19 -07:00
jr nc, .skip
add 60
2015-10-24 07:34:19 -07:00
.skip
ld [hl], c ; current minutes
dec hl
2015-10-24 07:34:19 -07:00
ld [wMinutesSince], a ; minutes since
2018-06-24 07:09:41 -07:00
_CalcHoursDaysSince:
ldh a, [hHours]
ld c, a
sbc [hl]
2015-10-24 07:34:19 -07:00
jr nc, .skip
2022-01-10 17:57:40 -08:00
add MAX_HOUR
2015-10-24 07:34:19 -07:00
.skip
ld [hl], c ; current hours
dec hl
2015-10-24 07:34:19 -07:00
ld [wHoursSince], a ; hours since
2015-10-24 07:34:19 -07:00
_CalcDaysSince:
2018-01-23 14:39:09 -08:00
ld a, [wCurDay]
ld c, a
sbc [hl]
jr nc, .skip
add 20 * 7
.skip
2015-10-24 07:34:19 -07:00
ld [hl], c ; current days
ld [wDaysSince], a ; days since
ret
2018-06-24 07:09:41 -07:00
CopyDayHourMinSecToHL:
2018-01-23 14:39:09 -08:00
ld a, [wCurDay]
ld [hli], a
ldh a, [hHours]
ld [hli], a
ldh a, [hMinutes]
ld [hli], a
ldh a, [hSeconds]
ld [hli], a
ret
2018-06-24 07:09:41 -07:00
CopyDayToHL:
2018-01-23 14:39:09 -08:00
ld a, [wCurDay]
ld [hl], a
ret
CopyDayHourToHL: ; unreferenced
2018-01-23 14:39:09 -08:00
ld a, [wCurDay]
ld [hli], a
ldh a, [hHours]
ld [hli], a
ret
2018-06-24 07:09:41 -07:00
CopyDayHourMinToHL:
2018-01-23 14:39:09 -08:00
ld a, [wCurDay]
ld [hli], a
ldh a, [hHours]
ld [hli], a
ldh a, [hMinutes]
ld [hli], a
ret