-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw.asm
287 lines (260 loc) · 4.93 KB
/
draw.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
; A = digit
; DE = VRAM address
draw_digit:
bit 6,a
jr nz,clear_digit ; "Clear digit" flag ?
and $F ; Compute digits_map table index
sla a ; *8
sla a
sla a
ld b,a
sla a ; *16
add b ; = *24
ld h,0
ld l,a
ld bc,digits_map
add hl,bc
ld c,6 ; Height
--:
ld b,4 ; Width
-:
ldi a,(hl)
ld (de),a
inc de
dec b
jr nz,-
ld a,e
add 28 ; DE+=(32-4) Next tile line
ld e,a
jr nc,+
inc d
+:
dec c
jr nz,--
ret
clear_digit:
ld c,6 ; Height
--:
xor a
ld b,4 ; Width
-:
ld (de),a
inc de
dec b
jr nz,-
ld a,e
add 28 ; DE+=(32-4) Next tile line
ld e,a
jr nc,+
inc d
+:
dec c
jr nz,--
ret
state_0:
ld hl,STATE ; Inc state
inc (hl)
ld a,(DIGIT_3)
bit 7,a
jr nz,state_1 ; Skip flag
ld de,$9800+(32*6)+1
call draw_digit
ret
state_1:
ld hl,STATE ; Inc state
inc (hl)
ld a,(DIGIT_2)
bit 7,a
jr nz,state_2 ; Skip flag
ld de,$9800+(32*6)+5
call draw_digit
ret
state_2:
ld hl,STATE ; Inc state
inc (hl)
ld a,(DIGIT_1)
bit 7,a
jr nz,state_3 ; Skip flag
ld de,$9800+(32*6)+9
call draw_digit
ret
state_3:
ld hl,STATE ; Inc state
inc (hl)
ld a,(DIGIT_0) ; Can't skip units
ld de,$9800+(32*6)+13
call draw_digit
ret
state_4:
ld hl,STATE ; Inc state
inc (hl)
;ld a,(HV_ENABLE)
;bit 7,a
;jr z,state_5 ; Skip flag
;res 7,a
;ld (HV_ENABLE),a
;rrca ; HV flag in carry
;ld a,28 ; "OFF"
;jr nc,+
;ld a,22 ; "ON"
+:
;ld bc,$0302
;ld hl,$9800+(32*4)+9
;call map_inc
ret
state_5:
ld hl,STATE ; Inc state
inc (hl)
ld a,(GRAPH_UPDATE) ; Need an update ?
or a
jp z,state_reset
xor a
ld (GRAPH_UPDATE),a ; Clear update request
; Draw new vertical line in graph
ld a,(GRAPH_V)
cpl
add 40+1
ld c,a ; Y=41-GRAPH_V
ld a,(GRAPH_X)
add $77
and $7F
call graph_plot
ld a,(GRAPH_V) ; Total number of pixels to plot
ld b,a
-:
ld a,(hl) ; Plot
or e
ld c,l
ldi (hl),a
ld a,l
xor c ; Detect tile boundary
bit 4,a
jr nz,+ ; Jump if got out of tile
inc hl ; Skip bitplane
dec b
jr nz,-
+:
dec hl ; Cancel inc of previous LDI
ld a,l ; Restart at beginning of tile
and $F0
ld l,a
inc h ; Jump 16 tiles (256 bytes)
inc l ; Skip first bitplane
dec b
jr nz,-
ld a,(GRAPH_X) ; Scroll value in pixels
ld d,a
and 7
jp nz,+++ ; Did a whole tile column go by ?
; Clear tiles of column
srl d ; /8
srl d
srl d
ld a,d ; D = column number
dec a
swap a ; *16
and $F0
ld l,a
ld h,$88 ; HL=$88x0
ld b,5
--:
dec hl ; Hack
-:
ldh a,($41) ; Wait for the right VRAM mode
and 3
cp 3
jr nz,-
-:
ldh a,($41)
and 3
cp 3
jr z,-
xor a ; Clear one tile data
inc hl
ldi (hl),a
ldi (hl),a
ldi (hl),a
ldi (hl),a
ldi (hl),a
ldi (hl),a
ldi (hl),a
ldi (hl),a
ldi (hl),a
ldi (hl),a
ldi (hl),a
ldi (hl),a
ldi (hl),a
ldi (hl),a
ldi (hl),a
ld (hl),a ; Hack
inc h
ld a,l
sub 15 ; Hack
ld l,a
dec b
jr nz,--
; Remap new column
ld hl,$998F
ld a,d ; Column number
and $1F
add l
and %10011111 ; Mask out eventual carry to wrap on $1F and keep $80
ld l,a
push hl
ld a,d ; Column number
dec a
and $F
or $80
ld c,a
ld de,32
ld b,5
-:
ldh a,($41) ; Wait for the right VRAM mode
and 3
cp 3
jr nz,-
-:
ldh a,($41)
and 3
cp 3
jr z,-
ld a,c
-:
ld (hl),a
add 16
add hl,de ; HL+=32
dec b
jr nz,-
; Clear old column map
pop hl
ld a,5
add l
and %10011111
ld l,a
ld de,32
ld b,5
-:
ldh a,($41) ; Wait for the right VRAM mode
and 3
cp 3
jr nz,-
-:
ldh a,($41)
and 3
cp 3
jr z,-
xor a
-:
ld (hl),a
add hl,de ; HL+=32
dec b
jr nz,-
+++:
ld a,(GRAPH_X)
inc a
ld (GRAPH_X),a
ret
state_reset:
xor a ; Reset cycle
ld (STATE),a
ret