-
Notifications
You must be signed in to change notification settings - Fork 0
/
vblank.asm
92 lines (73 loc) · 1.63 KB
/
vblank.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
vblank:
xor a ; Reset BG scroll
ldh ($42),a
ldh ($43),a
ld hl,jt_draw ; Rendering is done in a max. 6-frame cycle
ld a,(STATE)
rst $30
call read_inputs
ld a,(INPUTS_ACTIVE) ; A: ???
bit 0,a
jr z,+
+:
ld a,(SECOND) ; Frame counter
cp 30 ; 61 frames =~ 1s.
jr z,+
inc a
ld (SECOND),a
jr ++
+:
xor a
ld (SECOND),a ; Reset counter
call compute_cpm
++:
; Read tick counter
ld a,1
ld ($0000),a ; Latch counter in PISO and set HV on
nop
ld ($4000),a ; Reset counter and PISO shift
ld b,6 ; Read 6-bit tick counter
ld c,0
-:
ld a,($A000) ; Read bit (D0)
srl a ; Shift D0 in carry
rr c ; Shift carry in C
dec b
jr nz,-
xor a
or c
jr z,+
call tick_sfx
ld hl,COUNT_ACC
rst $10
ld h,0
ld l,c
add hl,de
ld d,h
ld e,l
ld hl,COUNT_ACC
rst $18
+:
ld a,($A000) ; Read OVF bit
and 1
ld (OVF_FLAG),a
ld a,($A000) ; Read HV status bit
and 1
ld (CHARGED_FLAG),a
; 0.2s ? = 12.2 frames : 256 / 12.2 = 21
ld a,(GRAPH_TIMER)
add 21
jr nc,+