pokecrystal/engine/time.asm

466 lines
7.2 KiB
NASM
Raw Normal View History

2015-10-24 14:34:19 +00:00
_InitializeStartDay: ; 113d6
call InitializeStartDay
ret
; 113da
2015-10-24 14:34:19 +00:00
ClearDailyTimers: ; 113da
xor a
ld [wLuckyNumberDayBuffer], a
2015-10-24 14:34:19 +00:00
ld [wUnusedTwoDayTimer], a
ld [wDailyResetTimer], a
ret
; 113e5
2015-10-24 14:34:19 +00:00
InitCallReceiveDelay:: ; 113e5
xor a
2015-10-24 14:34:19 +00:00
ld [wTimeCyclesSinceLastCall], a
2015-10-24 14:34:19 +00:00
NextCallReceiveDelay: ; 113e9
ld a, [wTimeCyclesSinceLastCall]
cp 3
2015-10-24 14:34:19 +00:00
jr c, .okay
ld a, 3
2015-10-24 14:34:19 +00:00
.okay
ld e, a
ld d, 0
2015-10-24 14:34:19 +00:00
ld hl, .ReceiveCallDelays
add hl, de
ld a, [hl]
2015-10-24 14:34:19 +00:00
jp RestartReceiveCallDelay
; 113fd
.ReceiveCallDelays:
db 20, 10, 5, 3
; 11401
2015-10-24 14:34:19 +00:00
CheckReceiveCallTimer: ; 11401
call CheckReceiveCallDelay ; check timer
ret nc
2015-10-24 14:34:19 +00:00
ld hl, wTimeCyclesSinceLastCall
ld a, [hl]
cp 3
2015-10-24 14:34:19 +00:00
jr nc, .ok
inc [hl]
2015-10-24 14:34:19 +00:00
.ok
call NextCallReceiveDelay ; restart timer
scf
ret
; 11413
2015-10-24 14:34:19 +00:00
InitOneDayCountdown: ; 11413
ld a, 1
2015-10-24 14:34:19 +00:00
InitNDaysCountdown: ; 11415
ld [hl], a
push hl
call UpdateTime
pop hl
inc hl
2015-10-24 14:34:19 +00:00
call CopyDayToHL
ret
; 11420
2015-10-16 17:35:43 +00:00
CheckDayDependentEventHL: ; 11420
inc hl
push hl
2015-10-24 14:34:19 +00:00
call CalcDaysSince
call GetDaysSince
pop hl
dec hl
2015-10-24 14:34:19 +00:00
call UpdateTimeRemaining
ret
; 1142e
2015-10-24 14:34:19 +00:00
RestartReceiveCallDelay: ; 1142e
ld hl, wReceiveCallDelay_MinsRemaining
ld [hl], a
call UpdateTime
2015-10-24 14:34:19 +00:00
ld hl, wReceiveCallDelay_StartTime
call CopyDayHourMinToHL
ret
; 1143c
2015-10-24 14:34:19 +00:00
CheckReceiveCallDelay: ; 1143c
ld hl, wReceiveCallDelay_StartTime
call CalcMinsHoursDaysSince
call GetMinutesSinceIfLessThan60
ld hl, wReceiveCallDelay_MinsRemaining
call UpdateTimeRemaining
ret
; 1144c
2015-10-24 14:34:19 +00:00
RestartDailyResetTimer: ; 1144c
ld hl, wDailyResetTimer
jp InitOneDayCountdown
; 11452
2015-10-24 14:34:19 +00:00
CheckDailyResetTimer:: ; 11452
ld hl, wDailyResetTimer
2015-10-16 17:35:43 +00:00
call CheckDayDependentEventHL
ret nc
xor a
ld hl, wDailyFlags
ld [hli], a ; wDailyFlags
ld [hli], a ; wWeeklyFlags
ld [hli], a ; wSwarmFlags
ld [hl], a ; wSwarmFlags + 1
ld hl, wDailyRematchFlags
rept 4
ld [hli], a
endr
ld hl, wDailyPhoneItemFlags
rept 4
ld [hli], a
endr
ld hl, wDailyPhoneTimeOfDayFlags
rept 4
ld [hli], a
endr
ld hl, wKenjiBreakTimer
ld a, [hl]
and a
2015-10-24 14:34:19 +00:00
jr z, .RestartKenjiBreakCountdown
dec [hl]
2015-10-24 14:34:19 +00:00
jr nz, .DontRestartKenjiBreakCountdown
.RestartKenjiBreakCountdown:
call SampleKenjiBreakCountdown
.DontRestartKenjiBreakCountdown:
2015-10-24 14:34:19 +00:00
jr RestartDailyResetTimer
; 11485
SampleKenjiBreakCountdown: ; 11485
2016-03-02 03:31:21 +00:00
; Generate a random number between 3 and 6
call Random
2018-01-11 17:00:01 +00:00
and %11
add 3
ld [wKenjiBreakTimer], a
ret
; 11490
2015-10-24 14:34:19 +00:00
StartBugContestTimer: ; 11490
2018-01-11 17:00:01 +00:00
ld a, BUG_CONTEST_MINUTES
2015-10-24 14:34:19 +00:00
ld [wBugContestMinsRemaining], a
2018-01-11 17:00:01 +00:00
ld a, BUG_CONTEST_SECONDS
2015-10-24 14:34:19 +00:00
ld [wBugContestSecsRemaining], a
call UpdateTime
2015-10-24 14:34:19 +00:00
ld hl, wBugContestStartTime
call CopyDayHourMinSecToHL
ret
; 114a4
2015-10-24 14:34:19 +00:00
CheckBugContestTimer:: ; 114a4 (4:54a4)
ld hl, wBugContestStartTime
call CalcSecsMinsHoursDaysSince
ld a, [wDaysSince]
and a
2015-10-24 14:34:19 +00:00
jr nz, .timed_out
ld a, [wHoursSince]
and a
2015-10-24 14:34:19 +00:00
jr nz, .timed_out
ld a, [wSecondsSince]
ld b, a
2015-10-24 14:34:19 +00:00
ld a, [wBugContestSecsRemaining]
sub b
2015-10-24 14:34:19 +00:00
jr nc, .okay
add 60
.okay
ld [wBugContestSecsRemaining], a
ld a, [wMinutesSince]
ld b, a
2015-10-24 14:34:19 +00:00
ld a, [wBugContestMinsRemaining]
sbc b
2015-10-24 14:34:19 +00:00
ld [wBugContestMinsRemaining], a
jr c, .timed_out
and a
ret
2015-10-24 14:34:19 +00:00
.timed_out
xor a
2015-10-24 14:34:19 +00:00
ld [wBugContestMinsRemaining], a
ld [wBugContestSecsRemaining], a
scf
ret
2015-10-24 14:34:19 +00:00
InitializeStartDay: ; 114dd
call UpdateTime
2018-01-23 22:39:09 +00:00
ld hl, wTimerEventStartDay
2015-10-24 14:34:19 +00:00
call CopyDayToHL
ret
; 114e7
2016-01-05 13:46:37 +00:00
CheckPokerusTick:: ; 114e7
2018-01-23 22:39:09 +00:00
ld hl, wTimerEventStartDay
2015-10-24 14:34:19 +00:00
call CalcDaysSince
call GetDaysSince
and a
2016-01-10 22:44:09 +00:00
jr z, .done ; not even a day has passed since game start
ld b, a
2017-12-24 17:47:30 +00:00
farcall ApplyPokerusTick
2015-10-24 14:34:19 +00:00
.done
xor a
ret
; 114fc
2015-10-24 14:34:19 +00:00
SetUnusedTwoDayTimer: ; 114fc
ld a, 2
ld hl, wUnusedTwoDayTimer
ld [hl], a
call UpdateTime
2015-10-24 14:34:19 +00:00
ld hl, wUnusedTwoDayTimerStartDate
call CopyDayToHL
ret
; 1150c
2015-10-24 14:34:19 +00:00
CheckUnusedTwoDayTimer: ; 1150c
ld hl, wUnusedTwoDayTimerStartDate
call CalcDaysSince
call GetDaysSince
ld hl, wUnusedTwoDayTimer
call UpdateTimeRemaining
ret
; 1151c
; unused
ld hl, wDailyFlags
set DAILYFLAGS_FISH_SWARM_F, [hl]
ret
; 11522
; unused
and a
ld hl, wDailyFlags
bit DAILYFLAGS_FISH_SWARM_F, [hl]
ret nz
scf
ret
; 1152b
2015-10-24 14:34:19 +00:00
RestartLuckyNumberCountdown: ; 1152b
call .GetDaysUntilNextFriday
ld hl, wLuckyNumberDayBuffer
2015-10-24 14:34:19 +00:00
jp InitNDaysCountdown
; 11534
.GetDaysUntilNextFriday: ; 11534
call GetWeekday
ld c, a
ld a, FRIDAY
sub c
jr z, .friday_saturday
2018-01-11 17:00:01 +00:00
jr nc, .earlier ; could have done "ret nc"
.friday_saturday
add 7
.earlier
ret
; 11542
_CheckLuckyNumberShowFlag: ; 11542
ld hl, wLuckyNumberDayBuffer
2015-10-16 17:35:43 +00:00
jp CheckDayDependentEventHL
; 11548
2015-10-24 14:34:19 +00:00
DoMysteryGiftIfDayHasPassed: ; 11548
ld a, BANK(sMysteryGiftTimer)
call GetSRAMBank
2015-10-24 14:34:19 +00:00
ld hl, sMysteryGiftTimer
ld a, [hli]
2018-01-23 22:39:09 +00:00
ld [wBuffer1], a
ld a, [hl]
2018-01-23 22:39:09 +00:00
ld [wBuffer2], a
call CloseSRAM
2015-10-24 14:34:19 +00:00
2018-01-23 22:39:09 +00:00
ld hl, wBuffer1
2015-10-16 17:35:43 +00:00
call CheckDayDependentEventHL
2015-10-24 14:34:19 +00:00
jr nc, .not_timed_out
2018-01-23 22:39:09 +00:00
ld hl, wBuffer1
2015-10-24 14:34:19 +00:00
call InitOneDayCountdown
call CloseSRAM
2017-12-24 17:47:30 +00:00
farcall Function1050c8
2015-10-24 14:34:19 +00:00
.not_timed_out
ld a, BANK(sMysteryGiftTimer)
call GetSRAMBank
2018-01-23 22:39:09 +00:00
ld hl, wBuffer1
ld a, [hli]
2015-10-24 14:34:19 +00:00
ld [sMysteryGiftTimer], a
ld a, [hl]
2015-10-24 14:34:19 +00:00
ld [sMysteryGiftTimer + 1], a
call CloseSRAM
ret
; 11586
2015-10-24 14:34:19 +00:00
UpdateTimeRemaining: ; 11586
; If the amount of time elapsed exceeds the capacity of its
; unit, skip this part.
2015-10-04 18:14:51 +00:00
cp -1
2015-10-24 14:34:19 +00:00
jr z, .set_carry
ld c, a
2015-10-24 14:34:19 +00:00
ld a, [hl] ; time remaining
sub c
2015-10-04 18:14:51 +00:00
jr nc, .ok
xor a
2015-10-04 18:14:51 +00:00
.ok
ld [hl], a
2015-10-24 14:34:19 +00:00
jr z, .set_carry
xor a
ret
2015-10-24 14:34:19 +00:00
.set_carry
xor a
ld [hl], a
scf
ret
; 11599
2015-10-24 14:34:19 +00:00
GetSecondsSinceIfLessThan60: ; 11599
ld a, [wDaysSince]
and a
2015-10-24 14:34:19 +00:00
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wHoursSince]
and a
2015-10-24 14:34:19 +00:00
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wMinutesSince]
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wSecondsSince]
ret
; 115ae
2015-10-24 14:34:19 +00:00
GetMinutesSinceIfLessThan60: ; 115ae
ld a, [wDaysSince]
and a
2015-10-24 14:34:19 +00:00
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wHoursSince]
and a
2015-10-24 14:34:19 +00:00
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wMinutesSince]
ret
; 115be
2015-10-24 14:34:19 +00:00
GetHoursSinceIfLessThan24: ; 115be
ld a, [wDaysSince]
and a
2015-10-24 14:34:19 +00:00
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wHoursSince]
ret
; 115c8
2015-10-24 14:34:19 +00:00
GetDaysSince: ; 115c8
ld a, [wDaysSince]
ret
; 115cc
2015-10-24 14:34:19 +00:00
GetTimeElapsed_ExceedsUnitLimit: ; 115cc
ld a, -1
ret
; 115cf
2015-10-24 14:34:19 +00:00
CalcDaysSince: ; 115cf
xor a
2015-10-24 14:34:19 +00:00
jr _CalcDaysSince
; 115d2
2015-10-24 14:34:19 +00:00
CalcHoursDaysSince: ; 115d2
inc hl
xor a
2015-10-24 14:34:19 +00:00
jr _CalcHoursDaysSince
; 115d6
2015-10-24 14:34:19 +00:00
CalcMinsHoursDaysSince: ; 115d6
inc hl
inc hl
xor a
2015-10-24 14:34:19 +00:00
jr _CalcMinsHoursDaysSince
; 115db
2015-10-24 14:34:19 +00:00
CalcSecsMinsHoursDaysSince: ; 115db
inc hl
inc hl
inc hl
ld a, [hSeconds]
ld c, a
sub [hl]
2015-10-24 14:34:19 +00:00
jr nc, .skip
add 60
2015-10-24 14:34:19 +00:00
.skip
ld [hl], c ; current seconds
dec hl
2015-10-24 14:34:19 +00:00
ld [wSecondsSince], a ; seconds since
2015-10-24 14:34:19 +00:00
_CalcMinsHoursDaysSince: ; 115eb
ld a, [hMinutes]
ld c, a
sbc [hl]
2015-10-24 14:34:19 +00:00
jr nc, .skip
add 60
2015-10-24 14:34:19 +00:00
.skip
ld [hl], c ; current minutes
dec hl
2015-10-24 14:34:19 +00:00
ld [wMinutesSince], a ; minutes since
2015-10-24 14:34:19 +00:00
_CalcHoursDaysSince: ; 115f8
ld a, [hHours]
ld c, a
sbc [hl]
2015-10-24 14:34:19 +00:00
jr nc, .skip
add 24
2015-10-24 14:34:19 +00:00
.skip
ld [hl], c ; current hours
dec hl
2015-10-24 14:34:19 +00:00
ld [wHoursSince], a ; hours since
2015-10-24 14:34:19 +00:00
_CalcDaysSince:
2018-01-23 22:39:09 +00:00
ld a, [wCurDay]
ld c, a
sbc [hl]
jr nc, .skip
add 20 * 7
.skip
2015-10-24 14:34:19 +00:00
ld [hl], c ; current days
ld [wDaysSince], a ; days since
ret
; 11613
2015-10-24 14:34:19 +00:00
CopyDayHourMinSecToHL: ; 11613
2018-01-23 22:39:09 +00:00
ld a, [wCurDay]
ld [hli], a
ld a, [hHours]
ld [hli], a
ld a, [hMinutes]
ld [hli], a
ld a, [hSeconds]
ld [hli], a
ret
; 11621
2015-10-24 14:34:19 +00:00
CopyDayToHL: ; 11621
2018-01-23 22:39:09 +00:00
ld a, [wCurDay]
ld [hl], a
ret
; 11626
2015-10-24 14:34:19 +00:00
CopyDayHourToHL: ; 11626
2018-01-23 22:39:09 +00:00
ld a, [wCurDay]
ld [hli], a
ld a, [hHours]
ld [hli], a
ret
; 1162e
2015-10-24 14:34:19 +00:00
CopyDayHourMinToHL: ; 1162e
2018-01-23 22:39:09 +00:00
ld a, [wCurDay]
ld [hli], a
ld a, [hHours]
ld [hli], a
ld a, [hMinutes]
ld [hli], a
ret
; 11639