-
Notifications
You must be signed in to change notification settings - Fork 2
/
timer.asm
60 lines (52 loc) · 796 Bytes
/
timer.asm
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
59
60
.ifndef TIMER_INC
TIMER_INC = 1
.include "debug.asm"
.macro SET_TIMER ticks, vector
lda #<ticks
sta timer
lda #>ticks
sta timer+1
lda #<vector
sta timervec
lda #>vector
sta timervec+1
.endmacro
; timing
frame_num: .byte 0
timer: .word 0
timervec: .word timer_done
timer_tick:
lda timer
bne @dec_timer
lda timer+1
bne @dec_timer
jmp timer_done
@dec_timer:
sec
lda timer
sbc #1
sta timer
lda timer+1
sbc #0
sta timer+1
@check_timer:
lda timer
bne timer_done
lda timer+1
bne timer_done
jmp (timervec)
timer_done:
rts
timer_clear:
stz timer
stz timer+1
lda #<timer_done
sta timervec
lda #>timer_done
sta timervec+1
rts
timer_flush:
stz timer
stz timer+1
jmp (timervec)
.endif