-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvga_tile_driver.spin2
949 lines (789 loc) · 25.1 KB
/
vga_tile_driver.spin2
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
{{
'******************************
'* VGA tiled image driver
'******************************
Runs in its own COG. See README.txt for theory of operation.
Four variants are provided:
8 bytes/char: uses full 24 bit color with all effects available
4 bytes/char: uses 8bpp for foreground and background, all effects available
2 bytes/char: uses 16 colors (4bpp) with blinking effect
1 byte/char: only allows 128 characters, 1 bit for blinking, no colors
Methods:
start(params)
Starts the driver. "params" is a pointer to a block of 32 bit parameters longs:
params[0]: base pin to use for the VGA
params[1]: pointer to screen buffer
params[2]: number of columns
params[3]: number of rows
params[4]: pointer to font data
params[5]: font width (for now, must be 8 or 16)
params[6]: font height
params[7]: pixel clock scaling value ($8000_0000 * pixel_clock / system_clock)
params[8]: horizontal front porch
params[9]: hsync pulse length
params[10]: vertical front porch
params[11]: vsync lines
params[12]: vertical back porch
params[13]: polarity: %00 = both positive, %10 = vertical negative, %01 = horizontal negative
params[14]: cell size, i.e. bytes per character (1, 2, 4, or 8)
returns 1 + the number of the COG used, or 0 on failure
}}
CON
intensity = 80 '0..128
FIELD_HANDLER = $300 ' location of pixel subroutine in LUT memory
FIELD_HANDLER_END = $3a0
LINE_HANDLER = $3a0
LINE_HANDLER_END = $3ff
DAT
org 0
'' on entry to the COG, ptra contains the parameter block, and
'' ptrb points to the HUB address of the code (@entry)
entry
' read parameters
basepin_val
rdlong basepin_val, ptra++
buffer_base
rdlong buffer_base, ptra++
text_cols
rdlong text_cols, ptra++
text_rows
rdlong text_rows, ptra++
font_base
rdlong font_base, ptra++
font_width
rdlong font_width, ptra++
font_height
rdlong font_height, ptra++
fpix_scale
rdlong fpix_scale, ptra++
hfront_porch
rdlong hfront_porch, ptra++
hsync_pulse
rdlong hsync_pulse, ptra++
hback_porch
rdlong hback_porch, ptra++
vfront_porch
rdlong vfront_porch, ptra++
vsync_pulse
rdlong vsync_pulse, ptra++
vback_porch
rdlong vback_porch, ptra++
polarity
rdlong polarity, ptra++
' this must be either 8 (for 32 bit color) or 4 (for 8 bit color)
bytes_per_char
rdlong bytes_per_char, ptra++
'
' Setup
'
' this code can be overwritten once we are going
'
vga_start
' calculate things based on parameters
char_cnt
mov char_cnt, text_cols
strikethru_line
shr char_cnt, #1 ' we process 2 characters at a time
vsync_val
mov strikethru_line, font_height
stride
shr strikethru_line, #1 ' divide height by 2
stride_chunks
mov stride, text_cols
hpixels
mul stride, bytes_per_char
vpixels
mov stride_chunks, stride
buffer_ptr
add stride_chunks, #63
font_ptr
shr stride_chunks, #6 ' divide by 64
mycogid
mov hpixels, text_cols
font_line_counter
mul hpixels, font_width
x
mov vpixels, text_rows
y
mul vpixels, font_height
font_line_cnt
' check font width; handle 8 (default) or 16
cmp font_width, #16 wz
if_z shl font_line_bytes, #1
mov font_line_cnt, font_line_bytes
shr font_line_cnt, #2 ' convert to longs
sub font_line_cnt, #1
' copy parameters into settings
curchar
add m_rf_even, font_width
cureff
add m_rf_odd, font_width
bgcolor
add m_bs, hfront_porch
fgcolor
add m_sn, hsync_pulse
add m_bv, hback_porch
add m_vi, hpixels
' put our COG id into the DAC info
cogid mycogid
shl mycogid, #8
or dacmode_s, mycogid
or dacmode_c, mycogid
setxfrq fpix_scale 'set transfer frequency
mov vsync_val, basepin_val
add vsync_val, #4
' set up initial polarity
test polarity, #%10 wc
drvc vsync_val
test polarity, #1 wc
' NOTE: the setcmod instruction puts its argument in the D field (bits 9-17)
' so to set the low bit of the argument, we need to set bit 9 of the instruction
bitc cmodval, #9 ' set bit for cmodval
'set up level scaling
setcy ##intensity << 24 'r set colorspace for rgb
setci ##intensity << 16 'g
setcq ##intensity << 08 'b
cmodval
setcmod #%01_0_000_0 'enable colorspace conversion; note low bit is set above
'RJA dacmodes changed for real P2
wrpin dacmode_s,basepin_val 'enable dac modes in pins 0..3
dirh basepin_val
add basepin_val, #1
wrpin dacmode_c,basepin_val
dirh basepin_val
add basepin_val, #1
wrpin dacmode_c,basepin_val
dirh basepin_val
add basepin_val, #1
wrpin dacmode_c,basepin_val
dirh basepin_val
' save original ptrb
mov pb, ptrb
' load different routines into upper LUT depending on the bytes per char
' 8, 4, 2, or 1
' ptrb still points at @entry; make it point to the code we want to load
'
encod bytes_per_char, bytes_per_char ' convert 1, 2, 4, 8 to 0, 1, 2, 3
cmp font_width, #16 wz
if_z or bytes_per_char, #4 ' offset later in table
alts bytes_per_char, #line_offset_table ' look up in line_offset_table
add pb, 0-0 ' the offset we want for the code to load
' now load the line code into LUT
setq2 #(LINE_HANDLER_END-LINE_HANDLER)-1
rdlong (LINE_HANDLER & $1ff), pb
' and load the field code into LUT
add ptrb, ##(@field_entry - @entry)
setq2 #(FIELD_HANDLER_END-FIELD_HANDLER)-1
rdlong (FIELD_HANDLER&$1ff),ptrb
jmp #\FIELD_HANDLER
'
'
' Initialized data
'RJA: New dacmodes for real P2
dacmode_s long %0000_0000_000_1011000000000_01_00000_0 'hsync is 123-ohm, 3.3V
dacmode_c long %0000_0000_000_1011100000000_01_00000_0 'R/G/B are 75-ohm, 2.0V
m_bs long $7F010000 {+HFRONT_PORCH} 'before sync
m_sn long $7F010000 {+HSYNC} 'sync
m_bv long $7F010000 {+HBACK_PORCH} 'before visible
m_vi long $7F010000 {+HPIXELS} 'visible
m_rf_even long $0F000000 {+FONT_WIDTH} ' 1bpp
m_rf_odd long $0F010000 {+FONT_WIDTH} ' 1bpp LUT immediate
' active character effects for this line
' these bits have the following meanings:
' 01 = hide (show all fgground color)
' 02 = underline
' 04 = strikethrough
' 08 = reserved
' 10 = blinking hide
' 20 = blinking underline
' 40 = blinking strikethrough
' 80 = if hidden, use bgcolor instead of fgcolor
line_effects long 0
' active effects for this field; the blinking ones will be turned off
' on half of the fields
field_effects long 0
' count of elapsed fields, used for blinking
field_count long 0
' number of bytes in a font line (256 for 8 bit wide font)
font_line_bytes long 256
' standard ANSI 256 color palette
color_palette
long $00000000, $80000000, $00800000, $80800000, $00008000, $80008000, $00808000, $c0c0c000
long $80808000, $ff000000, $00ff0000, $ffff0000, $0000ff00, $ff00ff00, $00ffff00, $ffffff00
long $00000000, $00003300, $00006600, $00009900, $0000cc00, $0000ff00, $00330000, $00333300
long $00336600, $00339900, $0033cc00, $0033ff00, $00660000, $00663300, $00666600, $00669900
long $0066cc00, $0066ff00, $00990000, $00993300, $00996600, $00999900, $0099cc00, $0099ff00
long $00cc0000, $00cc3300, $00cc6600, $00cc9900, $00cccc00, $00ccff00, $00ff0000, $00ff3300
long $00ff6600, $00ff9900, $00ffcc00, $00ffff00, $33000000, $33003300, $33006600, $33009900
long $3300cc00, $3300ff00, $33330000, $33333300, $33336600, $33339900, $3333cc00, $3333ff00
long $33660000, $33663300, $33666600, $33669900, $3366cc00, $3366ff00, $33990000, $33993300
long $33996600, $33999900, $3399cc00, $3399ff00, $33cc0000, $33cc3300, $33cc6600, $33cc9900
long $33cccc00, $33ccff00, $33ff0000, $33ff3300, $33ff6600, $33ff9900, $33ffcc00, $33ffff00
long $66000000, $66003300, $66006600, $66009900, $6600cc00, $6600ff00, $66330000, $66333300
long $66336600, $66339900, $6633cc00, $6633ff00, $66660000, $66663300, $66666600, $66669900
long $6666cc00, $6666ff00, $66990000, $66993300, $66996600, $66999900, $6699cc00, $6699ff00
long $66cc0000, $66cc3300, $66cc6600, $66cc9900, $66cccc00, $66ccff00, $66ff0000, $66ff3300
long $66ff6600, $66ff9900, $66ffcc00, $66ffff00, $99000000, $99003300, $99006600, $99009900
long $9900cc00, $9900ff00, $99330000, $99333300, $99336600, $99339900, $9933cc00, $9933ff00
long $99660000, $99663300, $99666600, $99669900, $9966cc00, $9966ff00, $99990000, $99993300
long $99996600, $99999900, $9999cc00, $9999ff00, $99cc0000, $99cc3300, $99cc6600, $99cc9900
long $99cccc00, $99ccff00, $99ff0000, $99ff3300, $99ff6600, $99ff9900, $99ffcc00, $99ffff00
long $cc000000, $cc003300, $cc006600, $cc009900, $cc00cc00, $cc00ff00, $cc330000, $cc333300
long $cc336600, $cc339900, $cc33cc00, $cc33ff00, $cc660000, $cc663300, $cc666600, $cc669900
long $cc66cc00, $cc66ff00, $cc990000, $cc993300, $cc996600, $cc999900, $cc99cc00, $cc99ff00
long $cccc0000, $cccc3300, $cccc6600, $cccc9900, $cccccc00, $ccccff00, $ccff0000, $ccff3300
long $ccff6600, $ccff9900, $ccffcc00, $ccffff00, $ff000000, $ff003300, $ff006600, $ff009900
long $ff00cc00, $ff00ff00, $ff330000, $ff333300, $ff336600, $ff339900, $ff33cc00, $ff33ff00
long $ff660000, $ff663300, $ff666600, $ff669900, $ff66cc00, $ff66ff00, $ff990000, $ff993300
long $ff996600, $ff999900, $ff99cc00, $ff99ff00, $ffcc0000, $ffcc3300, $ffcc6600, $ffcc9900
long $ffcccc00, $ffccff00, $ffff0000, $ffff3300, $ffff6600, $ffff9900, $ffffcc00, $ffffff00
long $08080800, $12121200, $1c1c1c00, $26262600, $30303000, $3a3a3a00, $44444400, $4e4e4e00
long $58585800, $62626200, $6c6c6c00, $76767600, $80808000, $8a8a8a00, $94949400, $9e9e9e00
long $a8a8a800, $b2b2b200, $bcbcbc00, $c6c6c600, $d0d0d000, $dadada00, $e4e4e400, $eeeeee00
' space for 256 bytes of font data (256 characters * 2 byte/char)
font_line byte 0[512]
' table of offsets to the character handling subroutines
line_offset_table
long @char1_loop - @entry
long @char2_loop - @entry
long @char4_loop - @entry
long @char8_loop - @entry
long @word1_loop - @entry
long @word2_loop - @entry
long @word4_loop - @entry
long @word8_loop - @entry
mask_ffff
long $ffff
fit $1f0
org FIELD_HANDLER
'
'
' Field loop
'
field_entry
mov y,vfront_porch 'top blanks
call #blank
mov buffer_ptr, buffer_base
mov font_ptr, font_base
mov font_line_counter, font_height
add field_count, #1
test field_count, #32 wz
if_z mov field_effects, #$ff
if_nz mov field_effects, #$0f
mov y,vpixels 'set visible line
line
call #hsync 'do horizontal sync; also loads up next font line
' now read the character data
' this is stored as 8 byte per character;
' two longs, first containing 24 bit color + character glyph,
' second containing the 24 bit color and a reserved field
rdfast stride_chunks, buffer_ptr
sub font_line_counter, #1 wz
if_z mov font_line_counter, font_height
if_z mov font_ptr, font_base
if_z add buffer_ptr, stride ' next line
'' check for effects on this line
mov line_effects, #$91
cmp font_line_counter, #1 wz
if_z or line_effects, #$22
cmp font_line_counter, strikethru_line wz
if_z or line_effects, #$44
'' turn off blink specific stuff
and line_effects, field_effects
''
'' the main loop processes 2 characters (16 pixels) at a time,
'' ping-ponging between even and odd
''
' we use LUT elements 0,1 and 32,33 to hold the colors, ping-ponging back
' between them
' we have to use 32,33 because the granularity of changing the streamer
' LUT pointer is 5 bits
call #\LINE_HANDLER ' call the pixel loop
djnz y, #line
end_of_line
mov y,vback_porch 'bottom blanks
call #blank
drvnot vsync_val 'sync on
mov y,vsync_pulse 'sync blanks
call #blank
drvnot vsync_val 'sync off
jmp #field_entry 'loop
'
'
' Subroutines
'
blank call #hsync 'blank lines
xcont m_vi,#0
_ret_ djnz y,#blank
hsync xcont m_bs,#0 'horizontal sync
xcont m_sn,#1
xcont m_bv, #0
'setq #63 ' read 64 longs = 256 bytes from font table
setq font_line_cnt ' read data from font table
rdlong font_line, font_ptr
_ret_ add font_ptr, font_line_bytes
fit FIELD_HANDLER_END
''''''''''''''''''''''''''''''''''''''''''''''''''
'' LUT subroutines for 8 pixel wide fonts
'' all of these should process a whole line of
'' output
''
'' timing: generally speaking we process an even
'' and odd character (16 pixels) at a time
'' assuming a 250 MHz system clock this gives us
'' the following requirements:
'' 640x480 25 MHz pixel clock: 10 cycles/pixel
'' so 5*16 == 80 instructions
'' 800x600 40 MHz pixel clock: 6 cycles/pixel
'' so 3*16 == 48 instructions
'' 1024x768 65 MHz pixel clock: 3.75 cycles/pixel
'' or roughly 30 instructions
''
'' for a 160 MHz system clock:
'' 640x480: 50 instructions
'' 800x600: 32 instructions
'' 1024x768: 19 instructions
''''''''''''''''''''''''''''''''''''''''''''''''''
'' 8 bytes/character
'' 24 instructions
org LINE_HANDLER
char8_loop
rep @end_32bppchar, char_cnt
next_32bppchar
'' even pixel
rflong fgcolor
rflong bgcolor
getbyte curchar, fgcolor, #0
test bgcolor, line_effects wz
andn fgcolor, #$FF
andn bgcolor, #$FF
altgb curchar, #font_line ' fetch from font table
getbyte curchar
if_nz or curchar, #$ff ' if effect mask active add a line
xcont m_rf_even, curchar
wrlut bgcolor, #0
wrlut fgcolor, #1
'' odd pixel
rflong fgcolor
rflong bgcolor
getbyte curchar, fgcolor, #0
test bgcolor, line_effects wz
andn fgcolor, #$FF
andn bgcolor, #$FF ' handle in the glyphat code
altgb curchar, #font_line ' fetch from font table
getbyte curchar
if_nz or curchar, #$ff ' if effect mask active add a line
xcont m_rf_odd, curchar
wrlut bgcolor, #32
wrlut fgcolor, #33
''
'' end of loop
end_32bppchar
ret
fit LINE_HANDLER_END
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' 4 bytes/char
'' 30 instructions
org LINE_HANDLER
char4_loop
rep @end_8bppchar, char_cnt
next_8bppchar
'' even character
rfbyte fgcolor
rfbyte bgcolor
rfbyte curchar
rfbyte cureff wc
' do table lookup on colors
alts fgcolor, #color_Palette
mov fgcolor, 0-0
alts bgcolor, #color_Palette
mov bgcolor, 0-0
altgb curchar, #font_line ' fetch from font table
getbyte curchar
and cureff, line_effects wz
if_nz muxnc curchar, #$ff ' if effect mask active add a line
xcont m_rf_even, curchar
wrlut bgcolor, #0
wrlut fgcolor, #1
'' odd character
rfbyte fgcolor
rfbyte bgcolor
rfbyte curchar
rfbyte cureff wc
' do table lookup on colors
alts fgcolor, #color_Palette
mov fgcolor, 0-0
alts bgcolor, #color_Palette
mov bgcolor, 0-0
altgb curchar, #font_line ' fetch from font table
getbyte curchar
and cureff, line_effects wz
' test cureff, #$80 wc
if_nz muxnc curchar, #$ff ' if effect mask active add a line
xcont m_rf_odd, curchar
wrlut bgcolor, #32
wrlut fgcolor, #33
''
'' end of loop
end_8bppchar
ret
fit LINE_HANDLER_END
''''''''''''''''''''''''''''''''''''''''''''''''''
' 2 bytes/char
' this consists of an 8 bit character followed by
' 8 bit effects; 1 bit blink, 3 bits bg color, 4 bits fg color
'
' 30 instructions
org LINE_HANDLER
char2_loop
and line_effects, #$80
rep @end_char16, char_cnt
next_char16
'' even character
rfbyte curchar
rfbyte cureff wc
getnib fgcolor, cureff, #0
getnib bgcolor, cureff, #1
' do table lookup on colors
alts fgcolor, #color_Palette
mov fgcolor, 0-0
alts bgcolor, #color_Palette
mov bgcolor, 0-0
altgb curchar, #font_line ' fetch from font table
getbyte curchar
test cureff, line_effects wz
if_nz xor curchar, #$ff ' if effect mask active add a line
xcont m_rf_even, curchar
wrlut bgcolor, #0
wrlut fgcolor, #1
'' odd character
rfbyte curchar
rfbyte cureff wc
getnib fgcolor, cureff, #0
getnib bgcolor, cureff, #1
' do table lookup on colors
alts fgcolor, #color_Palette
mov fgcolor, 0-0
alts bgcolor, #color_Palette
mov bgcolor, 0-0
altgb curchar, #font_line ' fetch from font table
getbyte curchar
test cureff, line_effects wz
if_nz xor curchar, #$ff ' if effect mask active add a line
xcont m_rf_odd, curchar
wrlut bgcolor, #32
wrlut fgcolor, #33
''
'' end of loop
end_char16
ret
fit LINE_HANDLER_END
''''''''''''''''''''''''''''''''''''''''''''''''''
' 1 bytes/char
' this consists of an 7 bit character; the high bit is
' used for blinking
'
' 16 instructions
org LINE_HANDLER
char1_loop
mov fgcolor, color_Palette+7
mov bgcolor, color_Palette
wrlut bgcolor, #0
wrlut fgcolor, #1
wrlut bgcolor, #32
wrlut fgcolor, #33
and line_effects, #$80
rep @end_char8, char_cnt
next_char8
'' even character
rfbyte curchar
mov cureff, curchar
and curchar, #$7f
and cureff, line_effects wz
altgb curchar, #font_line ' fetch from font table
getbyte curchar
if_nz xor curchar, #$ff ' if effect mask active add a line
xcont m_rf_even, curchar
'' odd character
rfbyte curchar
mov cureff, curchar
and curchar, #$7f
and cureff, line_effects wz
altgb curchar, #font_line ' fetch from font table
getbyte curchar
if_nz xor curchar, #$ff ' if effect mask active add a line
xcont m_rf_odd, curchar
''
'' end of loop
end_char8
ret
fit LINE_HANDLER_END
''''''''''''''''''''''''''''''''''''''''''''''''''
'' LUT subroutines for 16 pixel wide fonts
'' all of these should process a whole line of
'' output
''
'' timing: generally speaking we process an even
'' and odd character (16 pixels) at a time
'' assuming a 250 MHz system clock this gives us
'' the following requirements:
'' 640x480 25 MHz pixel clock: 10 cycles/pixel
'' so 5*16 == 80 instructions
'' 800x600 40 MHz pixel clock: 6 cycles/pixel
'' so 3*16 == 48 instructions
'' 1024x768 65 MHz pixel clock: 3.75 cycles/pixel
'' or roughly 30 instructions
''
'' for a 160 MHz system clock:
'' 640x480: 50 instructions
'' 800x600: 32 instructions
'' 1024x768: 19 instructions
''''''''''''''''''''''''''''''''''''''''''''''''''
'' 8 bytes/character
'' 24 instructions
org LINE_HANDLER
word8_loop
rep @end_32bppword, char_cnt
next_32bppword
'' even pixel
rflong fgcolor
rflong bgcolor
getbyte curchar, fgcolor, #0
test bgcolor, line_effects wz
andn fgcolor, #$FF
andn bgcolor, #$FF
altgw curchar, #font_line ' fetch from font table
getword curchar
if_nz or curchar, mask_ffff ' if effect mask active add a line
xcont m_rf_even, curchar
wrlut bgcolor, #0
wrlut fgcolor, #1
'' odd pixel
rflong fgcolor
rflong bgcolor
getbyte curchar, fgcolor, #0
test bgcolor, line_effects wz
andn fgcolor, #$FF
andn bgcolor, #$FF ' handle in the glyphat code
altgw curchar, #font_line ' fetch from font table
getword curchar
if_nz or curchar, mask_ffff ' if effect mask active add a line
xcont m_rf_odd, curchar
wrlut bgcolor, #32
wrlut fgcolor, #33
''
'' end of loop
end_32bppword
ret
fit LINE_HANDLER_END
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' 4 bytes/char
'' 30 instructions
org LINE_HANDLER
word4_loop
rep @end_8bppword, char_cnt
next_8bppword
'' even character
rfbyte fgcolor
rfbyte bgcolor
rfbyte curchar
rfbyte cureff wc
' do table lookup on colors
alts fgcolor, #color_Palette
mov fgcolor, 0-0
alts bgcolor, #color_Palette
mov bgcolor, 0-0
altgw curchar, #font_line ' fetch from font table
getword curchar
and cureff, line_effects wz
if_nz muxnc curchar, mask_ffff ' if effect mask active add a line
xcont m_rf_even, curchar
wrlut bgcolor, #0
wrlut fgcolor, #1
'' odd character
rfbyte fgcolor
rfbyte bgcolor
rfbyte curchar
rfbyte cureff wc
' do table lookup on colors
alts fgcolor, #color_Palette
mov fgcolor, 0-0
alts bgcolor, #color_Palette
mov bgcolor, 0-0
altgw curchar, #font_line ' fetch from font table
getword curchar
and cureff, line_effects wz
' test cureff, #$80 wc
if_nz muxnc curchar, mask_ffff ' if effect mask active add a line
xcont m_rf_odd, curchar
wrlut bgcolor, #32
wrlut fgcolor, #33
''
'' end of loop
end_8bppword
ret
fit LINE_HANDLER_END
''''''''''''''''''''''''''''''''''''''''''''''''''
' 2 bytes/char
' this consists of an 8 bit character followed by
' 8 bit effects; 1 bit blink, 3 bits bg color, 4 bits fg color
'
' 30 instructions
org LINE_HANDLER
word2_loop
and line_effects, #$80
rep @end_word16, char_cnt
next_word16
'' even character
rfbyte curchar
rfbyte cureff wc
getnib fgcolor, cureff, #0
getnib bgcolor, cureff, #1
' do table lookup on colors
alts fgcolor, #color_Palette
mov fgcolor, 0-0
alts bgcolor, #color_Palette
mov bgcolor, 0-0
altgw curchar, #font_line ' fetch from font table
getword curchar
test cureff, line_effects wz
if_nz xor curchar, mask_ffff ' if effect mask active add a line
xcont m_rf_even, curchar
wrlut bgcolor, #0
wrlut fgcolor, #1
'' odd character
rfbyte curchar
rfbyte cureff wc
getnib fgcolor, cureff, #0
getnib bgcolor, cureff, #1
' do table lookup on colors
alts fgcolor, #color_Palette
mov fgcolor, 0-0
alts bgcolor, #color_Palette
mov bgcolor, 0-0
altgw curchar, #font_line ' fetch from font table
getword curchar
test cureff, line_effects wz
if_nz xor curchar, mask_ffff ' if effect mask active add a line
xcont m_rf_odd, curchar
wrlut bgcolor, #32
wrlut fgcolor, #33
''
'' end of loop
end_word16
ret
fit LINE_HANDLER_END
''''''''''''''''''''''''''''''''''''''''''''''''''
' 1 bytes/char
' this consists of an 7 bit character; the high bit is
' used for blinking
'
' 16 instructions
org LINE_HANDLER
word1_loop
mov fgcolor, color_Palette+7
mov bgcolor, color_Palette
wrlut bgcolor, #0
wrlut fgcolor, #1
wrlut bgcolor, #32
wrlut fgcolor, #33
and line_effects, #$80
rep @end_word8, char_cnt
next_word8
'' even character
rfbyte curchar
mov cureff, curchar
and curchar, #$7f
and cureff, line_effects wz
altgw curchar, #font_line ' fetch from font table
getword curchar
if_nz xor curchar, mask_ffff ' if effect mask active add a line
xcont m_rf_even, curchar
'' odd character
rfbyte curchar
mov cureff, curchar
and curchar, #$7f
and cureff, line_effects wz
altgw curchar, #font_line ' fetch from font table
getword curchar
if_nz xor curchar, mask_ffff ' if effect mask active add a line
xcont m_rf_odd, curchar
''
'' end of loop
end_word8
ret
fit LINE_HANDLER_END
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''
DAT
org 0
' code used to check hardware revision
' in rev A (the original silicon) setq + rdlong pa, ptrb++
' increments ptrb only once
' in rev B (revised silicon) it will increment ptrb appropriately
'
hwcheck
mov pb, ptrb
setq #1
rdlong $1e0, ptrb++
subr pb, ptrb
shr pb, #2 wz
if_z mov pb, #1
wrlong pb, ptra
cogid pa
cogstop pa
'******************************************************************
'* Spin interfaces
'******************************************************************
VAR
long mycog
long hw_rev
PUB start(params) : tmp | ptr
' check what kind of hardware we are using
if hw_rev == 0
hw_rev := check_hw_rev()
if hw_rev == 1
' RevA (old) silicon
' change streamer commands
ptr := @m_bs
tmp := $CF000000
long[ptr][0] := tmp ' before sync
long[ptr][1] := tmp ' sync
long[ptr][2] := tmp ' before visible
long[ptr][3] := tmp ' visible
ptr := @m_rf_even
long[ptr][0] := $8f000000 ' even characters
long[ptr][1] := $8f010000 ' odd characters (different LUT base)
else
' new silicon
ptr := @m_bs
tmp := $7f010000
long[ptr][0] := tmp
long[ptr][1] := tmp
long[ptr][2] := tmp
long[ptr][3] := tmp
ptr := @m_rf_even
long[ptr][0] := $0f000000 ' even characters
long[ptr][1] := $0f010000 ' odd characters
mycog := coginit(16, @entry, params) + 1
return mycog
'
' check the hardware revision
' return 1 for original silicon, 2 for new silicon
' the difference is in how setq+rdlong works for ptra offsets;
' ptra++ is applied the appropriate number of times in rev 2 silicon
'
PRI check_hw_rev() : tmp
tmp := 0
coginit(16, @hwcheck, @tmp)
repeat while tmp == 0
return tmp
PUB stop()
if mycog
cogstop(mycog-1)
mycog := 0
''
'' utility function
'' calculates proper pixel scaling for
'' pixel clock frequency a and system clock frequency b
''