2018-06-24 07:09:41 -07:00
|
|
|
ResetGameTime::
|
2013-09-03 15:58:16 -07:00
|
|
|
xor a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wGameTimeCap], a
|
|
|
|
ld [wGameTimeHours], a
|
|
|
|
ld [wGameTimeHours + 1], a
|
|
|
|
ld [wGameTimeMinutes], a
|
|
|
|
ld [wGameTimeSeconds], a
|
|
|
|
ld [wGameTimeFrames], a
|
2013-09-03 15:58:16 -07:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
GameTimer::
|
2013-09-03 15:58:16 -07:00
|
|
|
nop
|
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [rSVBK]
|
2013-09-03 15:58:16 -07:00
|
|
|
push af
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, BANK(wGameTime)
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSVBK], a
|
2013-09-03 15:58:16 -07:00
|
|
|
|
2020-06-16 12:49:32 -07:00
|
|
|
call .Function
|
2013-09-03 15:58:16 -07:00
|
|
|
|
|
|
|
pop af
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [rSVBK], a
|
2013-09-03 15:58:16 -07:00
|
|
|
ret
|
|
|
|
|
2020-10-29 20:23:57 -07:00
|
|
|
.Function:
|
2013-09-03 15:58:16 -07:00
|
|
|
; Increment the game timer by one frame.
|
|
|
|
; The game timer is capped at 999:59:59.00.
|
|
|
|
|
|
|
|
; Don't update if game logic is paused.
|
2016-05-08 11:11:24 -07:00
|
|
|
ld a, [wGameLogicPaused]
|
2013-09-03 15:58:16 -07:00
|
|
|
and a
|
|
|
|
ret nz
|
|
|
|
|
|
|
|
; Is the timer paused?
|
2020-10-28 10:35:39 -07:00
|
|
|
ld hl, wGameTimerPaused
|
2023-09-30 15:10:44 -07:00
|
|
|
bit GAME_TIMER_COUNTING_F, [hl]
|
2013-09-03 15:58:16 -07:00
|
|
|
ret z
|
|
|
|
|
|
|
|
; Is the timer already capped?
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wGameTimeCap
|
2013-09-03 15:58:16 -07:00
|
|
|
bit 0, [hl]
|
|
|
|
ret nz
|
|
|
|
|
|
|
|
; +1 frame
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wGameTimeFrames
|
2013-09-03 15:58:16 -07:00
|
|
|
ld a, [hl]
|
|
|
|
inc a
|
|
|
|
|
|
|
|
cp 60 ; frames/second
|
|
|
|
jr nc, .second
|
|
|
|
|
|
|
|
ld [hl], a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.second
|
|
|
|
xor a
|
|
|
|
ld [hl], a
|
|
|
|
|
|
|
|
; +1 second
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wGameTimeSeconds
|
2013-09-03 15:58:16 -07:00
|
|
|
ld a, [hl]
|
|
|
|
inc a
|
|
|
|
|
|
|
|
cp 60 ; seconds/minute
|
|
|
|
jr nc, .minute
|
|
|
|
|
|
|
|
ld [hl], a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.minute
|
|
|
|
xor a
|
|
|
|
ld [hl], a
|
|
|
|
|
|
|
|
; +1 minute
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wGameTimeMinutes
|
2013-09-03 15:58:16 -07:00
|
|
|
ld a, [hl]
|
|
|
|
inc a
|
|
|
|
|
|
|
|
cp 60 ; minutes/hour
|
|
|
|
jr nc, .hour
|
|
|
|
|
|
|
|
ld [hl], a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.hour
|
|
|
|
xor a
|
|
|
|
ld [hl], a
|
|
|
|
|
|
|
|
; +1 hour
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wGameTimeHours]
|
2013-09-03 15:58:16 -07:00
|
|
|
ld h, a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wGameTimeHours + 1]
|
2013-09-03 15:58:16 -07:00
|
|
|
ld l, a
|
|
|
|
inc hl
|
|
|
|
|
|
|
|
; Cap the timer after 1000 hours.
|
|
|
|
ld a, h
|
2017-12-25 10:40:10 -08:00
|
|
|
cp HIGH(1000)
|
2013-09-03 15:58:16 -07:00
|
|
|
jr c, .ok
|
|
|
|
|
|
|
|
ld a, l
|
2017-12-25 10:40:10 -08:00
|
|
|
cp LOW(1000)
|
2013-09-03 15:58:16 -07:00
|
|
|
jr c, .ok
|
|
|
|
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wGameTimeCap
|
2013-09-03 15:58:16 -07:00
|
|
|
set 0, [hl]
|
|
|
|
|
|
|
|
ld a, 59 ; 999:59:59.00
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wGameTimeMinutes], a
|
|
|
|
ld [wGameTimeSeconds], a
|
2013-09-03 15:58:16 -07:00
|
|
|
ret
|
|
|
|
|
|
|
|
.ok
|
|
|
|
ld a, h
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wGameTimeHours], a
|
2013-09-03 15:58:16 -07:00
|
|
|
ld a, l
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wGameTimeHours + 1], a
|
2013-09-03 15:58:16 -07:00
|
|
|
ret
|