summaryrefslogtreecommitdiff
path: root/engine/pinball_game/timer.asm
blob: 2e1dc6b8f3ba427372b7faf62f5c03639498c73c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
StartTimer: ; 0x867d
; Starts the timer that counts down with the specified starting time when things
; like CatchEm Mode start.
; input:  b = minutes
;         c = seconds
	ld a, c
	ld [wTimerSeconds], a
	ld a, b
	ld [wTimerMinutes], a
	xor a
	ld [wTimerFrames], a
	ld [wTimeRanOut], a
	ld [wPauseTimer], a
	ld a, $1
	ld [wTimerActive], a
	ld a, $1
	ld [wd580], a
	callba LoadTimerGraphics
	ret

DecrementTimer: ; 0x86a4
	ld a, [wPauseTimer] ;quit unless ??? is 0
	and a
	ret nz
	ld a, [wTimerFrames]
	inc a
	cp 60
	jr c, .IfSecondHasNotPassed ;if frames +1 >= 60, reset it
	xor a
.IfSecondHasNotPassed
	ld [wTimerFrames], a ;inc frames
	ret c ;done if there was no reset
	ld hl, wTimerMinutes
	ld a, [hld]
	or [hl]
	jr nz, .IfTimeLeft ;if minutes or seconds is non-zero, jump, else ret marking that time ran out
	ld a, $1
	ld [wTimeRanOut], a
	ret

.IfTimeLeft
	ld a, [hl]
	sub $1
	daa ;take 1 from seconds
	jr nc, .IfMinuteHasNotPassed ; if < 0, set to 59
	ld a, $59
.IfMinuteHasNotPassed
	ld [hli], a
	ld a, [hl]
	sbc $0 ;sub minutes by 1 only if carry is set from the seconds sub
	daa
	ld [hl], a
	ret

StopTimer: ; 0x86d2
	xor a
	ld [wTimerActive], a
	ret