-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphics.asm
429 lines (394 loc) · 5.16 KB
/
graphics.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
; vim: set syntax=z80:
#local
#code _CODE
; Stores corresponding addresses of scanlines
.align 512
scanline_table:
dw 0x4000
dw 0x4100
dw 0x4200
dw 0x4300
dw 0x4400
dw 0x4500
dw 0x4600
dw 0x4700
dw 0x4020
dw 0x4120
dw 0x4220
dw 0x4320
dw 0x4420
dw 0x4520
dw 0x4620
dw 0x4720
dw 0x4040
dw 0x4140
dw 0x4240
dw 0x4340
dw 0x4440
dw 0x4540
dw 0x4640
dw 0x4740
dw 0x4060
dw 0x4160
dw 0x4260
dw 0x4360
dw 0x4460
dw 0x4560
dw 0x4660
dw 0x4760
dw 0x4080
dw 0x4180
dw 0x4280
dw 0x4380
dw 0x4480
dw 0x4580
dw 0x4680
dw 0x4780
dw 0x40A0
dw 0x41A0
dw 0x42A0
dw 0x43A0
dw 0x44A0
dw 0x45A0
dw 0x46A0
dw 0x47A0
dw 0x40C0
dw 0x41C0
dw 0x42C0
dw 0x43C0
dw 0x44C0
dw 0x45C0
dw 0x46C0
dw 0x47C0
dw 0x40E0
dw 0x41E0
dw 0x42E0
dw 0x43E0
dw 0x44E0
dw 0x45E0
dw 0x46E0
dw 0x47E0
dw 0x4800
dw 0x4900
dw 0x4A00
dw 0x4B00
dw 0x4C00
dw 0x4D00
dw 0x4E00
dw 0x4F00
dw 0x4820
dw 0x4920
dw 0x4A20
dw 0x4B20
dw 0x4C20
dw 0x4D20
dw 0x4E20
dw 0x4F20
dw 0x4840
dw 0x4940
dw 0x4A40
dw 0x4B40
dw 0x4C40
dw 0x4D40
dw 0x4E40
dw 0x4F40
dw 0x4860
dw 0x4960
dw 0x4A60
dw 0x4B60
dw 0x4C60
dw 0x4D60
dw 0x4E60
dw 0x4F60
dw 0x4880
dw 0x4980
dw 0x4A80
dw 0x4B80
dw 0x4C80
dw 0x4D80
dw 0x4E80
dw 0x4F80
dw 0x48A0
dw 0x49A0
dw 0x4AA0
dw 0x4BA0
dw 0x4CA0
dw 0x4DA0
dw 0x4EA0
dw 0x4FA0
dw 0x48C0
dw 0x49C0
dw 0x4AC0
dw 0x4BC0
dw 0x4CC0
dw 0x4DC0
dw 0x4EC0
dw 0x4FC0
dw 0x48E0
dw 0x49E0
dw 0x4AE0
dw 0x4BE0
dw 0x4CE0
dw 0x4DE0
dw 0x4EE0
dw 0x4FE0
dw 0x5000
dw 0x5100
dw 0x5200
dw 0x5300
dw 0x5400
dw 0x5500
dw 0x5600
dw 0x5700
dw 0x5020
dw 0x5120
dw 0x5220
dw 0x5320
dw 0x5420
dw 0x5520
dw 0x5620
dw 0x5720
dw 0x5040
dw 0x5140
dw 0x5240
dw 0x5340
dw 0x5440
dw 0x5540
dw 0x5640
dw 0x5740
dw 0x5060
dw 0x5160
dw 0x5260
dw 0x5360
dw 0x5460
dw 0x5560
dw 0x5660
dw 0x5760
dw 0x5080
dw 0x5180
dw 0x5280
dw 0x5380
dw 0x5480
dw 0x5580
dw 0x5680
dw 0x5780
dw 0x50A0
dw 0x51A0
dw 0x52A0
dw 0x53A0
dw 0x54A0
dw 0x55A0
dw 0x56A0
dw 0x57A0
dw 0x50C0
dw 0x51C0
dw 0x52C0
dw 0x53C0
dw 0x54C0
dw 0x55C0
dw 0x56C0
dw 0x57C0
dw 0x50E0
dw 0x51E0
dw 0x52E0
dw 0x53E0
dw 0x54E0
dw 0x55E0
dw 0x56E0
dw 0x57E0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; void plot_point(unsigned char x, unsigned char y) ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#local
_plot_point::
pop af
pop bc
push bc
push af
_plot_point_fastcall::
; load scanline address
ld l, b
ld h, scanline_table >> 9
add hl, hl
ld e, (hl)
inc hl
ld d, (hl)
; horizontal offset
ld a, c
and 0xF8
rrca
rrca
rrca
or e
ld e, a
; load a with bit to set
ld h, _BitmapBits >> 8
ld a, c
and 0x07
ld l, a
ld a, (hl)
; write bit
ex de, hl
or (hl)
ld (hl), a
ret
#endlocal
.align 256
_BitmapBits::
db 0x80
db 0x40
db 0x20
db 0x10
db 0x08
db 0x04
db 0x02
db 0x01
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; void plot_line(byte x1, byte y1, byte x2, byte y2) ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Bresenham's Algorithm
_plot_line:
#local
; l = x1, h = y1, e = x2, d = y2
pop af
pop hl
pop de
push de
push hl
push af
push ix
ld ix, 0
add ix, sp
; ensure vectors are in left-to-right order
ld a, e
sub l
jr nc, correct_order
ex de, hl
neg
correct_order:
push hl
ld b, a
; if y1 > y2
ld a, d
sub h
jr c, negative_gradient
; non-negative gradient
; store dx, dy
ld c, a
push bc
cp b
jr nc, dy_ge_1
; dx > dy
; TODO
dy_ge_1:
; dy >= dx
; store 2dx-2dy, 2dx
ld a, b
sub c
add a, a
ld c, a
ld a, b
add a, a
ld b, a
push bc
; store decision variable, loop counter
ld c, (ix-4)
sub c
ld b, a
dec c
push bc
; draw first pixel
ld c, l
ld b, h
call _plot_point_fastcall
cont2:
; check decision variable
ld a, (ix-7)
add a, a
jr nc, decision_ge_zero2
; p < 0
; plot_point(x, ++y)
ld c, (ix-2)
ld b, (ix-1)
inc b
ld (ix-1), b
call _plot_point_fastcall
; p += 2dx
ld a, (ix-7)
add a, (ix-6)
ld (ix-7), a
jp decision_end2
decision_ge_zero2:
; pk >= 0
; plot_point(++x, ++y)
ld c, (ix-2)
inc c
ld (ix-2), c
ld b, (ix-1)
inc b
ld (ix-1), b
call _plot_point_fastcall
; p += 2dx - 2dy
ld a, (ix-7)
add a, (ix-5)
ld (ix-7), a
decision_end2:
dec (ix-8)
jr nz, cont2
ld sp, ix
pop ix
ret
negative_gradient:
; negative gradient
; store dx, dy
neg
ld c, a
push bc
; TODO
#endlocal
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Byte *GetDisplay(Byte x, Byte y) ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#local
_GetDisplay::
pop af
pop bc ; b = $y, c = $x
push bc
push af
; load scanline address
ld l, b
ld h, scanline_table >> 9
add hl, hl
ld e, (hl)
inc hl
ld d, (hl)
; horizontal offset
ld a, c
and 0xF8
rrca
rrca
rrca
or e
ld e, a
ex de, hl
ret
#endlocal
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Byte GetDisplayMask(Byte x) ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#local
_GetDisplayMask::
pop af
dec sp
pop bc ; b = $x
push bc
inc sp
push af
ld h, _BitmapBits >> 8
ld a, b
and 0x07
ld l, a
ld l, (hl)
ret
#endlocal
#endlocal