-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpm.asm
133 lines (119 loc) · 2.06 KB
/
cpm.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
compute_cpm:
; Shift AVG_BUFFER
ld b,(30-1)*2
ld de,AVG_BUFFER+(30*2)-1
ld h,d
ld l,e
dec hl
dec hl
-:
ldd a,(hl)
ld (de),a
dec de
dec b
jr nz,-
ld hl,COUNT_ACC
rst $10
xor a
ldd (hl),a
ld (hl),a
ld hl,AVG_BUFFER
rst $18
; Compute average
ld b,30*2
ld de,0
ld hl,AVG_BUFFER
-:
ld a,e
add (hl)
ld e,a
inc hl
ld a,d
adc (hl)
ld d,a
inc hl
dec b
jr nz,-
push de
sla e ; *2
rl d
ld h,d
ld l,e
;ld hl,0 ; *60 = *4 + *8 + *16 + *32
;sla e ; *4
;rl d
;sla e
;rl d
;add hl,de
;sla e ; *8
;rl d
;add hl,de
;sla e ; *16
;rl d
;add hl,de
;sla e ; *32
;rl d
;add hl,de
; Hex to BCD
ld a,(DIGIT_0)
ld d,a
call div10 ; Don't call remzero on units to keep at least one zero displayed
cp d
jr nz,+
ld a,%10000000 ; Skip if same
+:
ld (DIGIT_0),a
ld a,(DIGIT_1)
ld d,a
call div10
call remzero
cp d
jr nz,+
ld a,%10000000 ; Skip if same
+:
ld (DIGIT_1),a
ld a,(DIGIT_2)
ld d,a
call div10
call remzero
cp d
jr nz,+
ld a,%10000000 ; Skip if same
+:
ld (DIGIT_2),a
ld a,(DIGIT_3)
ld d,a
call div10
call remzero
cp d
jr nz,+
ld a,%10000000 ; Skip if same
+:
ld (DIGIT_3),a
pop de
srl d ; /32
rr e
srl d
rr e
srl d
rr e
srl d
rr e
srl d
rr e
ld a,e
;srl a ; /4 + 1
;srl a
inc a
ld (GRAPH_V),a
ret
remzero:
or a
ret nz
ld b,a
ld a,l
or h
ld a,b
ret nz
ld a,%01000000 ; Set "Clear digit" flag
ret