-
Notifications
You must be signed in to change notification settings - Fork 3
/
Graphics.spin
1669 lines (1290 loc) · 123 KB
/
Graphics.spin
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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
''***************************************
''* Graphics Driver v1.0 *
''* Author: Chip Gracey *
''* Copyright (c) 2005 Parallax, Inc. *
''* See end of file for terms of use. *
''***************************************
''
'' Theory of Operation:
''
'' A cog is launched which processes commands via the PUB routines.
''
'' Points, lines, arcs, sprites, text, and polygons are rasterized into
'' a specified stretch of memory which serves as a generic bitmap buffer.
''
'' The bitmap can be displayed by the TV.SRC or VGA.SRC driver.
''
'' See GRAPHICS_DEMO.SRC for usage example.
''
CON
#1, _setup, _color, _width, _plot, _line, _arc, _vec, _vecarc, _pix, _pixarc, _text, _textarc, _textmode, _fill, _loop
VAR
long cog
long command
long bitmap_base 'bitmap data
long bitmap_longs
word bases[32]
long pixel_width 'pixel data
long slices[8]
long text_xs, text_ys, text_sp, text_just 'text data (these 4 must be contiguous)
PUB start : okay
'' Start graphics driver - starts a cog
'' returns false if no cog available
fontptr := @font 'set font pointer (same for all instances)
stop
okay := cog := cognew(@loop, @command) + 1
PUB stop
'' Stop graphics driver - frees a cog
if cog
cogstop(cog~ - 1)
command~
PUB setup(x_tiles, y_tiles, x_origin, y_origin, base_ptr) | bases_ptr, slices_ptr
'' Set bitmap parameters
''
'' x_tiles - number of x tiles (tiles are 16x16 pixels each)
'' y_tiles - number of y tiles
'' x_origin - relative-x center pixel
'' y_origin - relative-y center pixel
'' base_ptr - base address of bitmap
setcommand(_loop, 0) 'make sure last command finished
repeat bases_ptr from 0 to x_tiles - 1 <# 31 'write bases
bases[bases_ptr] := base_ptr + bases_ptr * y_tiles << 6
y_tiles <<= 4 'adjust arguments and do setup command
y_origin := y_tiles - y_origin - 1
bases_ptr := @bases
slices_ptr := @slices
setcommand(_setup, @x_tiles)
bitmap_base := base_ptr 'retain high-level bitmap data
bitmap_longs := x_tiles * y_tiles
PUB clear
'' Clear bitmap
setcommand(_loop, 0) 'make sure last command finished
longfill(bitmap_base, 0, bitmap_longs) 'clear bitmap
PUB copy(dest_ptr)
'' Copy bitmap
'' use for double-buffered display (flicker-free)
''
'' dest_ptr - base address of destination bitmap
setcommand(_loop, 0) 'make sure last command finished
longmove(dest_ptr, bitmap_base, bitmap_longs) 'copy bitmap
PUB color(c)
'' Set pixel color to two-bit pattern
''
'' c - color code in bits[1..0]
setcommand(_color, @colors[c & 3]) 'set color
PUB width(w) | pixel_passes, r, i, p
'' Set pixel width
'' actual width is w[3..0] + 1
''
'' w - 0..15 for round pixels, 16..31 for square pixels
r := not w & $10 'determine pixel shape/width
w &= $F
pixel_width := w
pixel_passes := w >> 1 + 1
setcommand(_width, @w) 'do width command now to avoid updating slices when busy
p := w ^ $F 'update slices to new shape/width
repeat i from 0 to w >> 1
slices[i] := true >> (p << 1) << (p & $E)
if r and pixels[w] & |< i
p += 2
if r and i == pixel_passes - 2
p += 2
PUB colorwidth(c, w)
'' Set pixel color and width
color(c)
width(w)
PUB plot(x, y)
'' Plot point
''
'' x,y - point
setcommand(_plot, @x)
PUB line(x, y)
'' Draw a line to point
''
'' x,y - endpoint
setcommand(_line, @x)
PUB arc(x, y, xr, yr, angle, anglestep, steps, arcmode)
'' Draw an arc
''
'' x,y - center of arc
'' xr,yr - radii of arc
'' angle - initial angle in bits[12..0] (0..$1FFF = 0°..359.956°)
'' anglestep - angle step in bits[12..0]
'' steps - number of steps (0 just leaves (x,y) at initial arc position)
'' arcmode - 0: plot point(s)
'' 1: line to point(s)
'' 2: line between points
'' 3: line from point(s) to center
setcommand(_arc, @x)
PUB vec(x, y, vecscale, vecangle, vecdef_ptr)
'' Draw a vector sprite
''
'' x,y - center of vector sprite
'' vecscale - scale of vector sprite ($100 = 1x)
'' vecangle - rotation angle of vector sprite in bits[12..0]
'' vecdef_ptr - address of vector sprite definition
''
''
'' Vector sprite definition:
''
'' word $8000|$4000+angle 'vector mode + 13-bit angle (mode: $4000=plot, $8000=line)
'' word length 'vector length
'' ... 'more vectors
'' ...
'' word 0 'end of definition
setcommand(_vec, @x)
PUB vecarc(x, y, xr, yr, angle, vecscale, vecangle, vecdef_ptr)
'' Draw a vector sprite at an arc position
''
'' x,y - center of arc
'' xr,yr - radii of arc
'' angle - angle in bits[12..0] (0..$1FFF = 0°..359.956°)
'' vecscale - scale of vector sprite ($100 = 1x)
'' vecangle - rotation angle of vector sprite in bits[12..0]
'' vecdef_ptr - address of vector sprite definition
setcommand(_vecarc, @x)
PUB pix(x, y, pixrot, pixdef_ptr)
'' Draw a pixel sprite
''
'' x,y - center of vector sprite
'' pixrot - 0: 0°, 1: 90°, 2: 180°, 3: 270°, +4: mirror
'' pixdef_ptr - address of pixel sprite definition
''
''
'' Pixel sprite definition:
''
'' word 'word align, express dimensions and center, define pixels
'' byte xwords, ywords, xorigin, yorigin
'' word %%xxxxxxxx,%%xxxxxxxx
'' word %%xxxxxxxx,%%xxxxxxxx
'' word %%xxxxxxxx,%%xxxxxxxx
'' ...
setcommand(_pix, @x)
PUB pixarc(x, y, xr, yr, angle, pixrot, pixdef_ptr)
'' Draw a pixel sprite at an arc position
''
'' x,y - center of arc
'' xr,yr - radii of arc
'' angle - angle in bits[12..0] (0..$1FFF = 0°..359.956°)
'' pixrot - 0: 0°, 1: 90°, 2: 180°, 3: 270°, +4: mirror
'' pixdef_ptr - address of pixel sprite definition
setcommand(_pixarc, @x)
PUB text(x, y, string_ptr) | justx, justy
'' Draw text
''
'' x,y - text position (see textmode for sizing and justification)
'' string_ptr - address of zero-terminated string (it may be necessary to call .finish
'' immediately afterwards to prevent subsequent code from clobbering the
'' string as it is being drawn
justify(string_ptr, @justx) 'justify string and draw text
setcommand(_text, @x)
PUB textarc(x, y, xr, yr, angle, string_ptr) | justx, justy
'' Draw text at an arc position
''
'' x,y - center of arc
'' xr,yr - radii of arc
'' angle - angle in bits[12..0] (0..$1FFF = 0°..359.956°)
'' string_ptr - address of zero-terminated string (it may be necessary to call .finish
'' immediately afterwards to prevent subsequent code from clobbering the
'' string as it is being drawn
justify(string_ptr, @justx) 'justify string and draw text
setcommand(_textarc, @x)
PUB textmode(x_scale, y_scale, spacing, justification)
'' Set text size and justification
''
'' x_scale - x character scale, should be 1+
'' y_scale - y character scale, should be 1+
'' spacing - character spacing, 6 is normal
'' justification - bits[1..0]: 0..3 = left, center, right, left
'' bits[3..2]: 0..3 = bottom, center, top, bottom
longmove(@text_xs, @x_scale, 4) 'retain high-level text data
setcommand(_textmode, @x_scale) 'set text mode
PUB box(x, y, box_width, box_height) | x2, y2, pmin, pmax
'' Draw a box with round/square corners, according to pixel width
''
'' x,y - box left, box bottom
if box_width > pixel_width and box_height > pixel_width
pmax := pixel_width - (pmin := pixel_width >> 1) 'get pixel-half-min and pixel-half-max
x += pmin 'adjust coordinates to accomodate width
y += pmin
x2 := x + box_width - 1 - pixel_width
y2 := y + box_height - 1 - pixel_width
plot(x, y) 'plot round/square corners
plot(x, y2)
plot(x2, y)
plot(x2, y2)
fill(x, y2 + pmax, 0, (x2 - x) << 16, 0, 0, pmax) 'fill gaps
fill(x, y, 0, (x2 - x) << 16, 0, 0, pmin)
fill(x - pmin, y2, 0, (x2 - x + pixel_width) << 16, 0, 0, y2 - y)
PUB quad(x1, y1, x2, y2, x3, y3, x4, y4)
'' Draw a solid quadrilateral
'' vertices must be ordered clockwise or counter-clockwise
tri(x1, y1, x2, y2, x3, y3) 'draw two triangle to make 4-sides polygon
tri(x3, y3, x4, y4, x1, y1)
PUB tri(x1, y1, x2, y2, x3, y3) | xy[2]
'' Draw a solid triangle
' reorder vertices by descending y
case (y1 => y2) & %100 | (y2 => y3) & %010 | (y1 => y3) & %001
%000:
longmove(@xy, @x1, 2)
longmove(@x1, @x3, 2)
longmove(@x3, @xy, 2)
%010:
longmove(@xy, @x1, 2)
longmove(@x1, @x2, 4)
longmove(@x3, @xy, 2)
%011:
longmove(@xy, @x1, 2)
longmove(@x1, @x2, 2)
longmove(@x2, @xy, 2)
%100:
longmove(@xy, @x3, 2)
longmove(@x2, @x1, 4)
longmove(@x1, @xy, 2)
%101:
longmove(@xy, @x2, 2)
longmove(@x2, @x3, 2)
longmove(@x3, @xy, 2)
' draw triangle
fill(x1, y1, (x3 - x1) << 16 / (y1 - y3 + 1), (x2 - x1) << 16 / (y1 - y2 + 1), (x3 - x2) << 16 / (y2 - y3 + 1), y1 - y2, y1 - y3)
PUB finish
'' Wait for any current graphics command to finish
'' use this to insure that it is safe to manually manipulate the bitmap
setcommand(_loop, 0) 'make sure last command finished
PRI fill(x, y, da, db, db2, linechange, lines_minus_1)
setcommand(_fill, @x)
PRI justify(string_ptr, justptr) | x
x := (strsize(string_ptr) - 1) * text_xs * text_sp + text_xs * 5 - 1
long[justptr] := -lookupz(text_just >> 2 & 3: 0, x >> 1, x, 0)
long[justptr][1] := -lookupz(text_just & 3: 0, text_ys << 3, text_ys << 4, 0)
PRI setcommand(cmd, argptr)
command := cmd << 16 + argptr 'write command and pointer
repeat while command 'wait for command to be cleared, signifying receipt
CON
' Vector font primitives
xa0 = %000 << 0 'x line start / arc center
xa1 = %001 << 0
xa2 = %010 << 0
xa3 = %011 << 0
xa4 = %100 << 0
xa5 = %101 << 0
xa6 = %110 << 0
xa7 = %111 << 0
ya0 = %0000 << 3 'y line start / arc center
ya1 = %0001 << 3
ya2 = %0010 << 3
ya3 = %0011 << 3
ya4 = %0100 << 3
ya5 = %0101 << 3
ya6 = %0110 << 3
ya7 = %0111 << 3
ya8 = %1000 << 3
ya9 = %1001 << 3
yaA = %1010 << 3
yaB = %1011 << 3
yaC = %1100 << 3
yaD = %1101 << 3
yaE = %1110 << 3
yaF = %1111 << 3
xb0 = %000 << 7 'x line end
xb1 = %001 << 7
xb2 = %010 << 7
xb3 = %011 << 7
xb4 = %100 << 7
xb5 = %101 << 7
xb6 = %110 << 7
xb7 = %111 << 7
yb0 = %0000 << 10 'y line end
yb1 = %0001 << 10
yb2 = %0010 << 10
yb3 = %0011 << 10
yb4 = %0100 << 10
yb5 = %0101 << 10
yb6 = %0110 << 10
yb7 = %0111 << 10
yb8 = %1000 << 10
yb9 = %1001 << 10
ybA = %1010 << 10
ybB = %1011 << 10
ybC = %1100 << 10
ybD = %1101 << 10
ybE = %1110 << 10
ybF = %1111 << 10
ax1 = %0 << 7 'x arc radius
ax2 = %1 << 7
ay1 = %00 << 8 'y arc radius
ay2 = %01 << 8
ay3 = %10 << 8
ay4 = %11 << 8
a0 = %0000 << 10 'arc start/length
a1 = %0001 << 10 'bits[1..0] = start (0..3 = 0°, 90°, 180°, 270°)
a2 = %0010 << 10 'bits[3..2] = length (0..3 = 360°, 270°, 180°, 90°)
a3 = %0011 << 10
a4 = %0100 << 10
a5 = %0101 << 10
a6 = %0110 << 10
a7 = %0111 << 10
a8 = %1000 << 10
a9 = %1001 << 10
aA = %1010 << 10
aB = %1011 << 10
aC = %1100 << 10
aD = %1101 << 10
aE = %1110 << 10
aF = %1111 << 10
fline = %0 << 14 'line command
farc = %1 << 14 'arc command
more = %1 << 15 'another arc/line
DAT
' Color codes
colors long %%0000000000000000
long %%1111111111111111
long %%2222222222222222
long %%3333333333333333
' Round pixel recipes
pixels byte %00000000,%00000000,%00000000,%00000000 '0,1,2,3
byte %00000000,%00000000,%00000010,%00000101 '4,5,6,7
byte %00001010,%00001010,%00011010,%00011010 '8,9,A,B
byte %00110100,%00111010,%01110100,%01110100 'C,D,E,F
' Vector font - standard ascii characters ($21-$7E)
font word fline + xa2 + yaC + xb2 + yb7 + more '!
word fline + xa2 + ya5 + xb2 + yb4
word fline + xa1 + yaD + xb1 + ybC + more '"
word fline + xa3 + yaD + xb3 + ybC
word fline + xa1 + yaA + xb1 + yb6 + more '#
word fline + xa3 + yaA + xb3 + yb6 + more
word fline + xa0 + ya9 + xb4 + yb9 + more
word fline + xa0 + ya7 + xb4 + yb7
word farc + xa2 + ya9 + a9 + ax2 + ay1 + more '$
word farc + xa2 + ya7 + aB + ax2 + ay1 + more
word fline + xa0 + ya6 + xb2 + yb6 + more
word fline + xa2 + yaA + xb4 + ybA + more
word fline + xa2 + yaA + xb2 + ybB + more
word fline + xa2 + ya6 + xb2 + yb5
word farc + xa1 + yaA + a0 + ax1 + ay1 + more '%
word farc + xa3 + ya6 + a0 + ax1 + ay1 + more
word fline + xa0 + ya6 + xb4 + ybA
word farc + xa2 + yaA + a7 + ax1 + ay1 + more '&
word farc + xa2 + ya7 + a5 + ax2 + ay2 + more
word fline + xa1 + yaA + xb4 + yb5
word fline + xa2 + yaD + xb2 + ybC ' '
word farc + xa3 + ya9 + aD + ax1 + ay4 + more '(
word farc + xa3 + ya7 + aE + ax1 + ay4 + more
word fline + xa2 + ya7 + xb2 + yb9
word farc + xa1 + ya9 + aC + ax1 + ay4 + more ')
word farc + xa1 + ya7 + aF + ax1 + ay4 + more
word fline + xa2 + ya7 + xb2 + yb9
word fline + xa4 + ya6 + xb0 + ybA + more '*
word fline + xa0 + ya6 + xb4 + ybA + more
word fline + xa2 + yaB + xb2 + yb5
word fline + xa0 + ya8 + xb4 + yb8 + more '+
word fline + xa2 + yaA + xb2 + yb6
word fline + xa2 + ya4 + xb1 + yb3 ',
word fline + xa0 + ya8 + xb4 + yb8 '-
word fline + xa2 + ya5 + xb2 + yb4 '.
word fline + xa0 + ya4 + xb4 + ybC '/
word farc + xa2 + ya8 + a0 + ax2 + ay4 '0
word fline + xa0 + ya4 + xb4 + yb4 + more '1
word fline + xa2 + ya4 + xb2 + ybC + more
word fline + xa0 + yaA + xb2 + ybC
word farc + xa2 + yaA + a8 + ax2 + ay2 + more '2
word farc + xa2 + yaA + aF + ax2 + ay3 + more
word farc + xa2 + ya4 + aD + ax2 + ay3 + more
word fline + xa0 + ya4 + xb4 + yb4
word farc + xa2 + yaA + a7 + ax2 + ay2 + more '3
word farc + xa2 + ya6 + a6 + ax2 + ay2
word fline + xa2 + yaC + xb0 + yb7 + more '4
word fline + xa0 + ya7 + xb4 + yb7 + more
word fline + xa3 + ya4 + xb3 + yb8
word farc + xa2 + ya6 + aB + ax2 + ay2 + more '5
word fline + xa4 + yaC + xb0 + ybC + more
word fline + xa0 + yaC + xb0 + yb8 + more
word fline + xa0 + ya8 + xb2 + yb8 + more
word fline + xa0 + ya4 + xb2 + yb4
word farc + xa2 + ya6 + a0 + ax2 + ay2 + more '6
word farc + xa2 + ya8 + aD + ax2 + ay4 + more
word fline + xa0 + ya6 + xb0 + yb8 + more
word fline + xa2 + yaC + xb3 + ybC
word fline + xa0 + yaC + xb4 + ybC + more '7
word fline + xa1 + ya4 + xb4 + ybC
word farc + xa2 + ya6 + a0 + ax2 + ay2 + more '8
word farc + xa2 + yaA + a0 + ax2 + ay2
word farc + xa2 + yaA + a0 + ax2 + ay2 + more '9
word farc + xa2 + ya8 + aF + ax2 + ay4 + more
word fline + xa4 + ya8 + xb4 + ybA + more
word fline + xa1 + ya4 + xb2 + yb4
word fline + xa2 + ya6 + xb2 + yb7 + more ':
word fline + xa2 + yaA + xb2 + yb9
word fline + xa2 + ya4 + xb1 + yb3 + more ';
word fline + xa2 + ya8 + xb2 + yb7
word fline + xa0 + ya8 + xb4 + ybA + more '<
word fline + xa0 + ya8 + xb4 + yb6
word fline + xa0 + yaA + xb4 + ybA + more '=
word fline + xa0 + ya6 + xb4 + yb6
word fline + xa4 + ya8 + xb0 + ybA + more '>
word fline + xa4 + ya8 + xb0 + yb6
word farc + xa2 + yaB + a8 + ax2 + ay1 + more '?
word farc + xa3 + yaB + aF + ax1 + ay2 + more
word farc + xa3 + ya7 + aD + ax1 + ay2 + more
word fline + xa2 + ya5 + xb2 + yb4
word farc + xa2 + ya8 + a0 + ax1 + ay1 + more '@
word farc + xa2 + ya8 + a4 + ax2 + ay3 + more
word farc + xa3 + ya8 + aF + ax1 + ay1 + more
word farc + xa2 + ya6 + aF + ax2 + ay1 + more
word fline + xa3 + ya7 + xb3 + yb9
word farc + xa2 + yaA + a8 + ax2 + ay2 + more 'A
word fline + xa0 + ya4 + xb0 + ybA + more
word fline + xa4 + ya4 + xb4 + ybA + more
word fline + xa0 + ya8 + xb4 + yb8
word farc + xa2 + yaA + aB + ax2 + ay2 + more 'B
word farc + xa2 + ya6 + aB + ax2 + ay2 + more
word fline + xa0 + ya4 + xb0 + ybC + more
word fline + xa0 + ya4 + xb2 + yb4 + more
word fline + xa0 + ya8 + xb2 + yb8 + more
word fline + xa0 + yaC + xb2 + ybC
word farc + xa2 + yaA + a8 + ax2 + ay2 + more 'C
word farc + xa2 + ya6 + aA + ax2 + ay2 + more
word fline + xa0 + ya6 + xb0 + ybA
word farc + xa2 + yaA + aC + ax2 + ay2 + more 'D
word farc + xa2 + ya6 + aF + ax2 + ay2 + more
word fline + xa0 + ya4 + xb0 + ybC + more
word fline + xa4 + ya6 + xb4 + ybA + more
word fline + xa0 + ya4 + xb2 + yb4 + more
word fline + xa0 + yaC + xb2 + ybC
word fline + xa0 + ya4 + xb0 + ybC + more 'E
word fline + xa0 + ya4 + xb4 + yb4 + more
word fline + xa0 + ya8 + xb3 + yb8 + more
word fline + xa0 + yaC + xb4 + ybC
word fline + xa0 + ya4 + xb0 + ybC + more 'F
word fline + xa0 + ya8 + xb3 + yb8 + more
word fline + xa0 + yaC + xb4 + ybC
word farc + xa2 + yaA + a8 + ax2 + ay2 + more 'G
word farc + xa2 + ya6 + aA + ax2 + ay2 + more
word fline + xa0 + ya6 + xb0 + ybA + more
word fline + xa4 + ya4 + xb4 + yb7 + more
word fline + xa3 + ya7 + xb4 + yb7
word fline + xa0 + ya4 + xb0 + ybC + more 'H
word fline + xa4 + ya4 + xb4 + ybC + more
word fline + xa0 + ya8 + xb4 + yb8
word fline + xa2 + ya4 + xb2 + ybC + more 'I
word fline + xa0 + ya4 + xb4 + yb4 + more
word fline + xa0 + yaC + xb4 + ybC
word farc + xa2 + ya6 + aA + ax2 + ay2 + more 'J
word fline + xa4 + ya6 + xb4 + ybC
word fline + xa0 + ya4 + xb0 + ybC + more 'K
word fline + xa4 + yaC + xb0 + yb8 + more
word fline + xa4 + ya4 + xb0 + yb8
word fline + xa0 + ya4 + xb0 + ybC + more 'L
word fline + xa0 + ya4 + xb4 + yb4
word fline + xa0 + ya4 + xb0 + ybC + more 'M
word fline + xa4 + ya4 + xb4 + ybC + more
word fline + xa2 + ya8 + xb0 + ybC + more
word fline + xa2 + ya8 + xb4 + ybC
word fline + xa0 + ya4 + xb0 + ybC + more 'N
word fline + xa4 + ya4 + xb4 + ybC + more
word fline + xa4 + ya4 + xb0 + ybC
word farc + xa2 + yaA + a8 + ax2 + ay2 + more '0
word farc + xa2 + ya6 + aA + ax2 + ay2 + more
word fline + xa0 + ya6 + xb0 + ybA + more
word fline + xa4 + ya6 + xb4 + ybA
word farc + xa2 + yaA + aB + ax2 + ay2 + more 'P
word fline + xa0 + ya4 + xb0 + ybC + more
word fline + xa0 + ya8 + xb2 + yb8 + more
word fline + xa0 + yaC + xb2 + ybC
word farc + xa2 + yaA + a8 + ax2 + ay2 + more 'Q
word farc + xa2 + ya6 + aA + ax2 + ay2 + more
word fline + xa0 + ya6 + xb0 + ybA + more
word fline + xa4 + ya6 + xb4 + ybA + more
word fline + xa2 + ya6 + xb4 + yb3
word farc + xa2 + yaA + aB + ax2 + ay2 + more 'R
word fline + xa0 + ya4 + xb0 + ybC + more
word fline + xa0 + ya8 + xb2 + yb8 + more
word fline + xa0 + yaC + xb2 + ybC + more
word fline + xa4 + ya4 + xb2 + yb8
word farc + xa2 + yaA + a4 + ax2 + ay2 + more 'S
word farc + xa2 + ya6 + a6 + ax2 + ay2
word fline + xa2 + ya4 + xb2 + ybC + more 'T
word fline + xa0 + yaC + xb4 + ybC
word farc + xa2 + ya6 + aA + ax2 + ay2 + more 'U
word fline + xa0 + ya6 + xb0 + ybC + more
word fline + xa4 + ya6 + xb4 + ybC
word fline + xa2 + ya4 + xb0 + ybC + more 'V
word fline + xa2 + ya4 + xb4 + ybC
word fline + xa0 + yaC + xb0 + yb4 + more 'W
word fline + xa4 + yaC + xb4 + yb4 + more
word fline + xa2 + ya8 + xb0 + yb4 + more
word fline + xa2 + ya8 + xb4 + yb4
word fline + xa4 + ya4 + xb0 + ybC + more 'X
word fline + xa0 + ya4 + xb4 + ybC
word fline + xa0 + yaC + xb2 + yb8 + more 'Y
word fline + xa4 + yaC + xb2 + yb8 + more
word fline + xa2 + ya4 + xb2 + yb8
word fline + xa0 + yaC + xb4 + ybC + more 'Z
word fline + xa0 + ya4 + xb4 + ybC + more
word fline + xa0 + ya4 + xb4 + yb4
word fline + xa2 + yaD + xb2 + yb3 + more '[
word fline + xa2 + yaD + xb4 + ybD + more
word fline + xa2 + ya3 + xb4 + yb3
word fline + xa4 + ya4 + xb0 + ybC '\
word fline + xa2 + yaD + xb2 + yb3 + more '[
word fline + xa2 + yaD + xb0 + ybD + more
word fline + xa2 + ya3 + xb0 + yb3
word fline + xa2 + yaA + xb0 + yb6 + more '^
word fline + xa2 + yaA + xb4 + yb6
word fline + xa0 + ya1 + xa4 + yb1 '_
word fline + xa1 + ya9 + xb3 + yb7 '`
word farc + xa2 + ya6 + a0 + ax2 + ay2 + more 'a
word fline + xa4 + ya4 + xb4 + yb8
word farc + xa2 + ya6 + a0 + ax2 + ay2 + more 'b
word fline + xa0 + ya4 + xb0 + ybC
word farc + xa2 + ya6 + a9 + ax2 + ay2 + more 'c
word fline + xa2 + ya4 + xb4 + yb4 + more
word fline + xa2 + ya8 + xb4 + yb8
word farc + xa2 + ya6 + a0 + ax2 + ay2 + more 'd
word fline + xa4 + ya4 + xb4 + ybC
word farc + xa2 + ya6 + a4 + ax2 + ay2 + more 'e
word fline + xa0 + ya6 + xb4 + yb6 + more
word fline + xa2 + ya4 + xb4 + yb4
word farc + xa4 + yaA + aD + ax2 + ay2 + more 'f
word fline + xa0 + ya8 + xb4 + yb8 + more
word fline + xa2 + ya4 + xb2 + ybA
word farc + xa2 + ya6 + a0 + ax2 + ay2 + more 'g
word farc + xa2 + ya3 + aF + ax2 + ay2 + more
word fline + xa4 + ya3 + xb4 + yb8 + more
word fline + xa1 + ya1 + xb2 + yb1
word farc + xa2 + ya6 + a8 + ax2 + ay2 + more 'h
word fline + xa0 + ya4 + xb0 + ybC + more
word fline + xa4 + ya4 + xb4 + yb6
word fline + xa1 + ya4 + xb3 + yb4 + more 'i
word fline + xa2 + ya4 + xb2 + yb8 + more
word fline + xa1 + ya8 + xb2 + yb8 + more
word fline + xa2 + yaB + xb2 + ybA
word farc + xa0 + ya3 + aF + ax2 + ay2 + more 'j
word fline + xa2 + ya3 + xb2 + yb8 + more
word fline + xa1 + ya8 + xb2 + yb8 + more
word fline + xa2 + yaB + xb2 + ybA
word fline + xa0 + ya4 + xb0 + ybC + more 'k
word fline + xa0 + ya6 + xb2 + yb6 + more
word fline + xa2 + ya6 + xb4 + yb8 + more
word fline + xa2 + ya6 + xb4 + yb4
word fline + xa1 + ya4 + xb3 + yb4 + more 'l
word fline + xa2 + ya4 + xb2 + ybC + more
word fline + xa1 + yaC + xb2 + ybC
word farc + xa1 + ya7 + a8 + ax1 + ay1 + more 'm
word farc + xa3 + ya7 + a8 + ax1 + ay1 + more
word fline + xa0 + ya4 + xb0 + yb8 + more
word fline + xa2 + ya4 + xb2 + yb7 + more
word fline + xa4 + ya4 + xb4 + yb7
word farc + xa2 + ya6 + a8 + ax2 + ay2 + more 'n
word fline + xa0 + ya4 + xb0 + yb8 + more
word fline + xa4 + ya4 + xb4 + yb6
word farc + xa2 + ya6 + a0 + ax2 + ay2 'o
word farc + xa2 + ya6 + a0 + ax2 + ay2 + more 'p
word fline + xa0 + ya1 + xb0 + yb8
word farc + xa2 + ya6 + a0 + ax2 + ay2 + more 'q
word fline + xa4 + ya1 + xb4 + yb8
word farc + xa2 + ya7 + a8 + ax2 + ay1 + more 'r
word fline + xa0 + ya4 + xb0 + yb8
word farc + xa2 + ya7 + a9 + ax2 + ay1 + more 's
word farc + xa2 + ya5 + aB + ax2 + ay1 + more
word fline + xa0 + ya4 + xb2 + yb4 + more
word fline + xa2 + ya8 + xb4 + yb8
word farc + xa4 + ya6 + aE + ax2 + ay2 + more 't
word fline + xa0 + ya8 + xb4 + yb8 + more
word fline + xa2 + ya6 + xb2 + ybA
word farc + xa2 + ya6 + aA + ax2 + ay2 + more 'u
word fline + xa0 + ya6 + xb0 + yb8 + more
word fline + xa4 + ya4 + xb4 + yb8
word fline + xa0 + ya8 + xb2 + yb4 + more 'v
word fline + xa4 + ya8 + xb2 + yb4
word farc + xa1 + ya5 + aA + ax1 + ay1 + more 'w
word farc + xa3 + ya5 + aA + ax1 + ay1 + more
word fline + xa0 + ya5 + xb0 + yb8 + more
word fline + xa2 + ya5 + xb2 + yb6 + more
word fline + xa4 + ya5 + xb4 + yb8
word fline + xa0 + ya8 + xb4 + yb4 + more 'x
word fline + xa0 + ya4 + xb4 + yb8
word farc + xa2 + ya6 + aA + ax2 + ay2 + more 'y
word farc + xa2 + ya3 + aF + ax2 + ay2 + more
word fline + xa4 + ya3 + xb4 + yb8 + more
word fline + xa0 + ya6 + xb0 + yb8 + more
word fline + xa1 + ya1 + xb2 + yb1
word fline + xa0 + ya8 + xb4 + yb8 + more 'z
word fline + xa4 + ya8 + xb0 + yb4 + more
word fline + xa0 + ya4 + xb4 + yb4
word farc + xa3 + yaA + aD + ax1 + ay3 + more '{
word farc + xa1 + ya6 + aC + ax1 + ay2 + more
word farc + xa1 + yaA + aF + ax1 + ay2 + more
word farc + xa3 + ya6 + aE + ax1 + ay3
word fline + xa2 + ya3 + xb2 + ybD '|
word farc + xa1 + yaA + aC + ax1 + ay3 + more '}
word farc + xa3 + ya6 + aD + ax1 + ay2 + more
word farc + xa3 + yaA + aE + ax1 + ay2 + more
word farc + xa1 + ya6 + aF + ax1 + ay3
word farc + xa1 + ya8 + a8 + ax1 + ay1 + more '~
word farc + xa3 + ya8 + aA + ax1 + ay1
' Vector font - custom characters ($7F+)
word fline + xa2 + ya9 + xb0 + yb4 + more 'delta
word fline + xa2 + ya9 + xb4 + yb4 + more
word fline + xa0 + ya4 + xb4 + yb4
word farc + xa2 + ya7 + a8 + ax2 + ay2 + more 'omega
word farc + xa1 + ya7 + aE + ax1 + ay2 + more
word farc + xa3 + ya7 + aF + ax1 + ay2 + more
word fline + xa1 + ya5 + xb1 + yb4 + more
word fline + xa3 + ya5 + xb3 + yb4 + more
word fline + xa0 + ya4 + xb1 + yb4 + more
word fline + xa4 + ya4 + xb3 + yb4
word farc + xa2 + ya8 + a0 + ax1 + ay1 'bullet
CON fx = 3 'number of custom characters
DAT
'*************************************
'* Assembly language graphics driver *
'*************************************
org
'
'
' Graphics driver - main loop
'
loop rdlong t1,par wz 'wait for command
if_z jmp #loop
movd :arg,#arg0 'get 8 arguments
mov t2,t1
mov t3,#8
:arg rdlong arg0,t2
add :arg,d0
add t2,#4
djnz t3,#:arg
wrlong zero,par 'zero command to signify received
call #setd 'set dx,dy from arg0,arg1
ror t1,#16+2 'lookup command address
add t1,#jumps
movs :table,t1
rol t1,#2
shl t1,#3
:table mov t2,0
shr t2,t1
and t2,#$FF
jmp t2 'jump to command
jumps byte 0 '0
byte setup_ '1
byte color_ '2
byte width_ '3
byte plot_ '4
byte line_ '5
byte arc_ '6
byte vec_ '7
byte vecarc_ '8
byte pix_ '9
byte pixarc_ 'A
byte text_ 'B
byte textarc_ 'C
byte textmode_ 'D
byte fill_ 'E
byte loop 'F
'
'
' setup(x_tiles, y_tiles*16, x_origin, y_origin, base_ptr) bases_ptr, slices_ptr
'
setup_ mov xlongs,arg0 'set xlongs, ylongs
mov ylongs,arg1
mov xorigin,arg2 'set xorigin, yorigin
mov yorigin,arg3
mov basesptr,arg5 'set pointers
mov slicesptr,arg6
jmp #loop
'
'
' color(c)
'
color_ mov pcolor,arg0 'set pixel color
jmp #loop
'
'
' width(w) pixel_passes
'
width_ mov pwidth,arg0 'set pixel width
mov passes,arg1 'set pixel passes
jmp #loop
'
'
' plot(x, y)
'
plot_ call #plotd
jmp #loop
'
'
' line(x, y)
'
line_ call #linepd
jmp #loop
'
'
' arc(x, y, xr, yr, angle, anglestep, iterations, mode)
'
arc_ and arg7,#3 'limit mode
:loop call #arca 'get arc dx,dy
cmp arg7,#1 wz 'if not mode 1, set px,py
if_nz mov px,dx
if_nz mov py,dy
tjz arg6,#loop 'if no points exit with new px,py
cmp arg7,#3 wz 'if mode 3, set center
if_z call #setd
test arg7,#1 wz 'if mode 0 or 2, plot point
if_z call #plotp
test arg7,#1 wz 'if mode 1 or 3, plot line
if_nz call #linepd
cmp arg7,#2 wz 'if mode 2, set mode 1
if_z mov arg7,#1