-
Notifications
You must be signed in to change notification settings - Fork 0
/
ansi.asm
925 lines (685 loc) · 8.97 KB
/
ansi.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
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
case on
mcopy ansi.mac
dummy start
end
RDMAINRAM gequ $E0C002 ; Read from main memory
RDCARDRAM gequ $E0C003 ; Read from auxiliary memory
WRMAINRAM gequ $E0C004 ; Write to main memory
WRCARDRAM gequ $E0C005 ; Write to auxiliary memory
tables privdata
;
; each line is 160 pixels.
; top/bottom margin is 4 lines (4*160 pixels)
rows anop
dc i2'0*8*160+4*160+$2000'
dc i2'1*8*160+4*160+$2000'
dc i2'2*8*160+4*160+$2000'
dc i2'3*8*160+4*160+$2000'
dc i2'4*8*160+4*160+$2000'
dc i2'5*8*160+4*160+$2000'
dc i2'6*8*160+4*160+$2000'
dc i2'7*8*160+4*160+$2000'
dc i2'8*8*160+4*160+$2000'
dc i2'9*8*160+4*160+$2000'
dc i2'10*8*160+4*160+$2000'
dc i2'11*8*160+4*160+$2000'
dc i2'12*8*160+4*160+$2000'
dc i2'13*8*160+4*160+$2000'
dc i2'14*8*160+4*160+$2000'
dc i2'15*8*160+4*160+$2000'
dc i2'16*8*160+4*160+$2000'
dc i2'17*8*160+4*160+$2000'
dc i2'18*8*160+4*160+$2000'
dc i2'19*8*160+4*160+$2000'
dc i2'20*8*160+4*160+$2000'
dc i2'21*8*160+4*160+$2000'
dc i2'22*8*160+4*160+$2000'
dc i2'23*8*160+4*160+$2000'
dc i2'24*8*160+4*160+$2000'
;
; columns are simply x * 2
;
end
cursor_data privdata
cursor_offset dc i2'0'
cursor_bits dc i2'0'
end
;
;ReverseScrollRegion(line1, line2)
;
ReverseScrollRegion START
line2 equ 9
line1 equ 7
_rtlb equ 3
_d equ 1
using tables
; brk $ea
phb
phd
tsc
tcd
lda <line1
bmi exit
lda <line2
cmp #25
bcs exit
lda <line1
cmp <line2
bcs exit
asl line1
asl line2
; count = (line2 - line1) * 8 * 160 - 1
ldx <line2
lda >rows,x
clc ; dec a
ldx <line1
sbc >rows,x
pha
;
; mvn:
; do { src[y++] = dest[x++]; } while (--c != 0xffff)
;
; mvp:
; do { src[y--] = dest[x--]; } while (--c != 0xffff)
; y = dest address = $2000 + 640 + (line2 + 1) * 8 * 160 -1
; x = src address = dest - 160*8
ldx <line2
lda >rows,x
dec a
tay
sec
sbc #160*8
tax
pla ; length
mvp $e10000,$e10000
;
; now empty first line
;
ldx <line1
jsr _ClearLine
exit anop
lda <_rtlb
sta <line1
lda <_rtlb+2
sta <line2
pld
pla
pla
plb
rtl
END
;
; ScrollRegion(line1, line2);
;
ScrollRegion START
using tables
line2 equ 9
line1 equ 7
_rtlb equ 3
_d equ 1
; brk $ea
phb
phd
tsc
tcd
lda <line1
bmi exit
lda <line2
cmp #25
bcs exit
lda <line1
cmp <line2
bcs exit
asl line1
asl line2
; a = (line2 - line1) * 8 * 160 - 1
ldx <line2
lda >rows,x
clc ; dec a
ldx <line1
sbc >rows,x
pha
; src address = $2000 + line1
; ldx #$e12000+1920 ; src address
; ldy #$e12000+640 ; dest address
; dest = $2000 + 640 + line1 * 8 * 160
; src = dest + 1280
ldx <line1
lda >rows,x
tay
clc
adc #8*160
tax
pla ; length
mvn $e10000,$e10000
;
; now empty last line
;
ldx line2
dex
dex
jsr _ClearLine
exit anop
lda <_rtlb
sta <line1
lda <_rtlb+2
sta <line2
pld
pla
pla
plb
rtl
END
;
; scroll 1 line
;
;
ScrollDown START
using tables
phb
;
; mvn:
; while (--a != -1)
; dest[y++] = dest[x++];
;
; mvp:
; while(--a != -1)
; dest[y--] = dest[x--];
lda #29440-1 ; length -1 ->23*8*160
ldx #$e12000+1920 ; src address
ldy #$e12000+640 ; dest address
; ldx #$2000+1280
; ldy #$2000
mvn $e10000,$e10000
;
; now empty outline #24
;
ldx #23
jsr _ClearLine
plb
rtl
END
; clear line in X (which has been pre-multiplied)
_ClearLine PRIVATE
using tables
lda >rows,x
tax
lda #0
sta >$e10000,x ; stick a 0 in there
txy ; destination address (src + 2)
iny
iny
lda #8*160-3 ; length -1
mvn $e10000,$e10000
rts
END
;
; ClearLine(int line_no); clears the line
;
ClearLine START
line equ 7
_rtlb equ 3
_d equ 1
; brk $ea
phb
phd
tsc
tcd
lda <line
cmp #24
bcs exit
asl a
tax
jsr _ClearLine
exit anop
lda <_rtlb+2
sta <_rtlb+4
lda <_rtlb
sta <_rtlb+2
pld
pla
plb
rtl
END
;
; ClearScreen2(int start, int end);
;
ClearScreen2 START
using tables
line2 equ 9
line1 equ 7
_rtlb equ 3
_d equ 1
; brk $ea
phb
phd
tsc
tcd
lda <line1
bmi exit
lda line2
cmp #25
bcs exit
lda <line1
cmp <line2
bcs exit
asl line1
asl line2
ldx <line2
lda >rows,x
clc
ldx <line1
sbc >rows,x
dec a
dec a
pha ; save length
ldx <line1
lda >rows,x
tax
tay
iny
iny
lda #0
sta >$e10000,x
pla ; restore length
mvn $e10000,$e10000
exit anop
lda <_rtlb+2
sta <line2
lda <_rtlb
sta <line1
pld
pla
pla
plb
rtl
END
;
; ClearLine2(int line, int start, int end);
;
;
; clear a section of a given line.
;
ClearLine2 START
using tables
end equ 11
start equ 9
line equ 7
_rtlb equ 3
_d equ 1
phb
phd
tsc
tcd
pea $e1e1
plb
plb
lda start
bmi exit
lda end
cmp #81
bcs exit
lda start
cmp end
bcs exit
sec
lda end
sbc start
; bmi exit
; beq exit
tay ; counter
asl start ; x 2
asl line
ldx <line
lda >rows,x
clc
adc start
tax
loop anop
stz |0,x
stz |160,x
stz |320,x
stz |480,x
stz |640,x
stz |800,x
stz |960,x
stz |1120,x
inx
inx
dey
bne loop
exit anop
lda <_rtlb+2
sta <end
lda <_rtlb
sta <start
pld
pla
pla
pla
plb
rtl
END
;
; clear the screen to black (or whatnot)
;
ClearScreen START
phb
pea $e1e1
plb
plb
lda #0
ldy #32000
loop anop
sta |$2000-2,y
dey
dey
bne loop
plb
rtl
END
;
; draw a character at the current Xpos & Ypos
;
;
; PrintChar(x, y, char, andMask, xorMask)
PrintChar START
using tables
xorMask equ 15
andMask equ 13
char equ 11
yy equ 9
xx equ 7
_rtlb equ 3
_d equ 1
; brk $ea
phb
phd
tsc
tcd
; sanity check on Xpos && Ypos
ldx xx
cpx #80
bcc ok2
exit2 anop
brl exit
ok2 anop
ldy yy
cpy #24
bcs exit2
lda <char
cmp #$7f
bcs space
sec
sbc #$20
bmi space
asl a ; x2
asl a ; x4
asl a ; x8
asl a ; x16
sta char
bra ok
space anop
stz <char
ok anop
pea $e1e1
plb
plb
asl xx
asl yy
ldx yy
lda >rows,x
clc
adc xx
tay
;
; $e12000 + pos = location to start drawing the character
;
;
; each char takes up 16 bytes :. the offset is (char - $20) * 16
;
ldx char
lda >CHAR_SPACE,x
eor <xorMask
and <andMask
sta |0,y ; blast it to the screen
lda >CHAR_SPACE+2,x
eor <xorMask
and <andMask
sta |160,y
lda >CHAR_SPACE+4,x
eor <xorMask
and <andMask
sta |320,y
lda >CHAR_SPACE+6,x
eor <xorMask
and <andMask
sta |480,y
lda >CHAR_SPACE+8,x
eor <xorMask
and <andMask
sta |640,y
lda >CHAR_SPACE+10,x
eor <xorMask
and <andMask
sta |800,y
lda >CHAR_SPACE+12,x
eor <xorMask
and <andMask
sta |960,y
lda >CHAR_SPACE+14,x
eor <xorMask
and <andMask
sta |1120,y
exit anop
lda <_rtlb+2
sta <xorMask
lda <_rtlb
sta <andMask
pld
pla
pla
pla
pla
pla
plb
rtl
end
; FillChar(char, andMask, xorMask)
gen on
FillChar START
using tables
subroutine (2:char,2:andMask,2:xorMask),(16:cdata)
xx equ andMask
yy equ xorMask
lda <char
cmp #$7f
bcs space
sec
sbc #$20
bmi space
asl a ; x2
asl a ; x4
asl a ; x8
asl a ; x16
tax
bra ok
space anop
ldx #0 ; char
ok anop
; pre-calc the char mask to data.
lda CHAR_SPACE,x
eor <xorMask
and <andMask
sta cdata
lda CHAR_SPACE+2,x
eor <xorMask
and <andMask
sta cdata+2
lda CHAR_SPACE+4,x
eor <xorMask
and <andMask
sta cdata+4
lda CHAR_SPACE+6,x
eor <xorMask
and <andMask
sta cdata+6
lda CHAR_SPACE+8,x
eor <xorMask
and <andMask
sta cdata+8
lda CHAR_SPACE+10,x
eor <xorMask
and <andMask
sta cdata+10
lda CHAR_SPACE+12,x
eor <xorMask
and <andMask
sta cdata+12
lda CHAR_SPACE+14,x
eor <xorMask
and <andMask
sta cdata+14
pea $e1e1
plb
plb
lda #24
sta yy
ldx #0*8*160+4*160+$2000
yloop anop
lda cdata+0
jsr one_line
lda cdata+2
jsr one_line
lda cdata+4
jsr one_line
lda cdata+6
jsr one_line
lda cdata+8
jsr one_line
lda cdata+10
jsr one_line
lda cdata+12
jsr one_line
lda cdata+14
jsr one_line
dec yy
bne yloop
exit anop
return
end
one_line private
; a = character data
; x = memory address
ldy #80
loop anop
sta |$0000,x
inx
inx
dey
bne loop
rts
end
HideCursor start
using cursor_data
ldx cursor_offset
beq exit
lda cursor_bits
sta >$e10000,x
stz cursor_offset
exit rtl
end
ShowCursor start
using cursor_data
using tables
yy equ 9
xx equ 7
_rtlb equ 3
_d equ 1
phb
phd
tsc
tcd
ldx cursor_offset
beq off
* hide old cursor.
lda cursor_bits
sta >$e10000,x
stz cursor_offset
off anop
lda <xx
cmp #80
bcs exit
lda <yy
cmp #24
bcs exit
asl xx
asl yy
ldx yy
lda rows,x
clc
adc xx
adc #160*7
sta cursor_offset
tax
lda >$e10000,x
sta cursor_bits
lda #-1
sta >$e10000,x
exit anop
lda _rtlb+2
sta yy
lda _rtlb
sta xx
pld
pla
pla
plb
rtl
end
;Cursor START
;StartCursor ENTRY
; pha
;; ~ReadBParam #$2f
; pla
; sta blinkRate
; stz savedX
; stz savedY
;; ~SetHeartBeat #CursorHB
; rtl
;StopCursor ENTRY
;; ~DelHeartBeat #CursorHB
; rtl
;notSafe ENTRY
; ds 2
;blinkRate ds 2
;savedX ds 2
;savedY ds 2
;CursorHB anop
; dc i4'0'
;count dc i2'30'
; dc h'5AA5'
; longa off
; phb
; phk
; plb
; php
;; long ai
; lda notSafe
; bne exit
; lda Xpos
; cmp savedX
; bne moved
; lda Ypos
; cmp savedY
; bne moved
; bra exit
;moved jsr drawCursor
;exit anop
; plp
; plb
; clc
; rtl
;drawCursor anop
; rts
; END