-
Notifications
You must be signed in to change notification settings - Fork 3
/
listing2.asm
1222 lines (1222 loc) · 19.1 KB
/
listing2.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
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
*
* PROGRAM <<DISPLAY>>
* PAN, SCALE, AND ROTATE CONTENTS OF *POINTS* THEN DISPLAY THE CONTENTS OF *LINES*
*
ORG $7000
*
* BASIC DATA STRUCTURES--THE POINTS AND LINES TO BE DRAWN. POINTS MAINTAINS THE COORDINATES OF THE POINTS
*
POINTS RMB 9*26 STORE THREE COORDS OF THREE BYTES EACH LABELED A..Z FOR THE USER
* UNUSED POINTS HAVE $80 IN THE FIRST BYTE OF EACH COORDINATE
LINES RMB 121 UP TO 30 PAIRS OF POINTS, LAST PAIR FOLLOWED BY -1, POINT L REPRESENTED BY 9*(ASC(L)-ASC(A))
* INTRODUCTORY HOUSEKEEPING TO DISABLE BASIC INTERRUPTS AND CREATE NEW STACK THEN RESTORE ENVIRONMENT FOR RETURN TO BASIC
*
ORCC #$10 DISABLE REGULAR INTERRUPT
LEAU ,S
LDS #$8000 USE HIGH MEMORY FOR HARDWARE STACK
PSHS U
JSR MAIN
PULS U
LEAS ,U RESTORE HARDWARE STACK
ANDCC #$EF ENABLE REGULAR INTERRUPT
RTS
*
* MAIN DISPLAY LOOP--LOOKS FOR A KEY COMMANDING ROTATION, PANNING, OR SCALING AND ORDERS SSAME. INCLUDES AUTO REPEAT
*
MAIN STA $FFC0 SET VDG = 110
STA $FFC3
STA $FFC5
LDA $FF22 SET HI BITS CONTROL REGISTER = $F0
ANDA #7
ORA #$F0
STA $FF22
JSR DISPLA DISPLAY THE PICTURE
KEY JSR [$A000]
BEQ KEY
JSR KEYVAL
CMPA #$8 LEFT ARROW
BNE MAIN1
LDX #PANL
BRA REPEAT
MAIN1 CMPA #$9 RIGHT ARROW
BNE MAIN2
LDX #PANR
BRA REPEAT
MAIN2 CMPA #$5E UP ARROW
BNE MAIN3
LDX #PANU
BRA REPEAT
MAIN3 CMPA #$0A DOWN ARROW
BNE MAIN4
LDX #PAND
BRA REPEAT
MAIN4 CMPA #$78 UNSHIFTED X
BNE MAIN5
LDX #ROTX
BRA REPEAT
MAIN5 CMPA #$58 SHIFTED X
BNE MAIN6
LDX #ROTMX
BRA REPEAT
MAIN6 CMPA #$79 UNSHIFTED Y
BNE MAIN7
LDX #ROTY
BRA REPEAT
MAIN7 CMPA #$59 SHIFTED Y
BNE MAIN8
LDX #ROTMY
BRA REPEAT
MAIN8 CMPA #$7A UNSHIFTED Z
BNE MAIN9
LDX #ROTZ
BRA REPEAT
MAIN9 CMPA #$5A SHIFTED Z
BNE MAIN10
LDX #ROTMZ
BRA REPEAT
MAIN10 CMPA #$62 UNSHIFTED B
BNE MAIN11
LDX #BIGGER
BRA REPEAT
MAIN11 CMPA #$73 UNSHIFTED S
BNE MAIN12
LDX #SMALLR
BRA REPEAT
MAIN12 CMPA #$40 @
BNE KEY NO COMMAND RECOGNIZED
RTS
REPEAT PSHS X,B SAVE ADDRESS OF SUB CALLED BY LAST KEY AND SUM OF KEY BUFFERS
REP1 JSR [1,S] 1,S POINTS TO ADDRESS OF SUBROUTINE CALLED BY LAST KEY PRESSED
JSR DISPLA DISPLAY UPDATED POINTS
JSR [$A000]
JSR KEYVAL
CMPB ,S
BEQ REP1 KEY STILL DEPRESSED
LEAS 3,S RESTORE STACK
LBRA KEY LOOK FOR ANOTHER COMMAND
*
* CREATE A PICTURE USING CURRENT POINTS AND LINES ON THE UNSEEN GRAPHICS SCREEN THEN DISPLAY THAT SCREEN
*
TL FDB $600 CONTAINS THE ADDRESS OF THE FIRST BYTE OF THE PRESENTLY UNSEEN GRAPHICS SCREEN--INITIALIZED SO
*
* PLOT THE CURRENT LINES ON THE UNSEEN GRAPHICS SCREEN THEN DISPLAY THE SCREEN
*
DISPLA CLRA BLANK SCREEN
LDB #$C
LDY #0
LDX TL
DISP1 STY ,X++
DECA
BNE DISP1
DECB
BNE DISP1
*
* PLOT EACH LINE
*
LDU #LINES
DISP3 LDB ,U+
CMPB #$FF
BEQ DISP2 LAST POINT?
CLRA
P1300
ADDD #POINTS
TFR D,Y ADDRESS OF FIRST POINT
LDX ,Y
STX X1
LEAY 3,Y
LDX ,Y
STX Y1
LDB ,U+
CLRA
ADDD #POINTS
TFR D,Y ADDRESS OF SECOND POINT
LDX ,Y
STX X2
LEAY 3,Y
LDX ,Y
STX Y2
PSHS U
JSR LINE
PULS U
BRA DISP3
*
* SWITCH SCREENS TO SHOW NEW PICTURE
*
DISP2 LDX TL
CMPX #$600
BEQ DISP4
STA $FFC7 VIDEO OFFSET=$1E00/$200=$F
STA $FFC9
STA $FFCB
STA $FFCD
STA $FFCE
STA $FFD0
STA $FFD2
STA $FFD4
LDX #$600
STX TL SET TL = FIRST BYTE OF UNUSED SCREEN
RTS
DISP4 STA $FFC7 SET VIDEO OFFSET = $600/$200=$3
STA $FFC9
STA $FFCA
STA $FFCC
STA $FFCE
STA $FFD0
STA $FFD2
LDX #$1E00
STX TL FIRST BYTE OF UNSEEN VIDEO SCREEN
RTS
*
* ROUTINES TO MOVE POINTS
*
*
* PAN LEFT
*
LASTPT SET POINTS+$9*$19
PANL LDX #POINTS
PANL2 LDA ,X
CMPA #$80
BEQ PANL1
LDD ,X GET X COORDINATE AND SUBTRACT 2
SUBD #2
STD ,X
CMPA #-$80
BLE PANL4 POINT OUT OF BOUNDS
PANL1 LEAX 9,X
CMPX #LASTPT
BLS PANL2
RTS
PANL4 LDA ,X SINCE ONE POINT OUT OF BOUNDS, RESTORE ALL POINTS TO ORIGINAL VALUES
CMPA #$80
BEQ PANL5
LDA 1,X
ADDA #2
STA 1,X
LDA ,X
ADCA #0
STA ,X
PANL5 LEAX -9,X
CMPX #POINTS
BHS PANL4
RTS
*
* PAN RIGHT
*
PANR LDX #POINTS
PANR2 LDA ,X
CMPA #$80
BEQ PANR1 IF POINT UNDEFINED
LDD ,X ADD 2 TO X COORDINATE
ADDD #2
STD ,X
CMPA #$10
BGE PANR4 POINT OUT OF BOUNDS
PANR1 LEAX 9,X
CMPX #LASTPT
BLS PANR2
RTS
PANR4 LDA ,X SINCE ONE POINT OUT OF BOUNDS, RESTORE ALL POINTS TO ORIGINAL VALUES
CMPA #$80
BEQ PANR5
LDA 1,X
SUBA #2
STA 1,X
LDA ,X
SBCA #0
STA ,X
PANR5 LEAX -9,X
CMPX #POINTS
BHS PANR4
RTS
*
* PAN DOWN
*
PAND LDX #POINTS
PAND2 LDA ,X
CMPA #$80
BEQ PAND1 IF POINT UNDEFINED
LDD 3,X SUBTRACT 2 FROM Y COORDINATE
SUBD #2
STD 3,X
CMPA #-$10
BLE PAND4 IF POINT OUT OF BOUNDS
PAND1 LEAX 9,X
CMPX #LASTPT
BLS PAND2
RTS
PAND4 LDA ,X SINCE ONE POINT OUT OF BOUNDS, RESTORE ALL POINTS TO ORIGINAL VALUES
CMPA #$80
BEQ PAND5
LDA 4,X
ADDA #2
STA 4,X
LDA 3,X
ADCA #0
STA 3,X
PAND5 LEAX -9,X
CMPX #POINTS
BHS PAND4
RTS
*
* PAN UP
*
PANU LDX #POINTS
PANU2 LDA ,X
CMPA #$80
BEQ PANU1 IF POINT UNDEFINED
LDD 3,X ADD 2 TO Y COORDINATE
ADDD #2
STD 3,X
CMPA #$10
BGE PANU4 POINT OUT OF BOUNDS
PANU1 LEAX 9,X
CMPX #LASTPT
BLS PANU2
RTS
PANU4 LDA ,X SINCE ONE POINT OUT OF BOUNDS, RESTORE ALL POINTS TO ORIGINAL VALUES
CMPA #$80
BEQ PANU5
LDA 4,X
SUBA #2
STA 4,X
LDA 3,X
SBCA #0
STA 3,X
PANU5 LEAX -9,X
CMPX #POINTS
BHS PANU4
RTS
*
* ROTATE POSITIVELY ABOUT X AXIS
*
ROTX LDX #POINTS
ROTX1 LDA ,X
CMPA #$80 CHECK FOR UNDEFINED POINT
BEQ ROTX2
PSHS X
LEAX 3,X ADDRESS OF Y-COORDINATE OF CURRENT POINT
LEAY 3,X ADDRESS OF Z-COORDINATE OF CURRENT POINT
JSR ROTATE
PULS X
LDA 3,X
CMPA #$10
BGE ROTX3
CMPA #-$10
BLE ROTX3 POINT TOO BIG
LDA 6,X
CMPA #$10
BGE ROTX3
CMPA #-$10
BLE ROTX3
ROTX2 LEAX 9,X GET NEXT POINT
CMPX #LASTPT
BLE ROTX1
RTS
ROTX3 PSHS X UNDO ROTATIONS AS ONE POINT TOO LARGE
LDA ,X
CMPA #$80
BEQ RX
LEAY 3,X
LEAX 6,X
JSR ROTATE
RX PULS X
LEAX -9,X
CMPX #POINTS
BHS ROTX3
RTS
*
* ROTATE NEGATIVELY ABOUT X AXIS
*
ROTMX LDX #POINTS
ROTMX1 LDA ,X
CMPA #$80 CHECK FOR UNDEFINED POINT
BEQ ROTMX2
PSHS X
LEAY 3,X ADDRESS OF Y-COORDINATE OF CURRENT POINT
LEAX 6,X ADDRESS OF Z-COORDINATE OF CURRENT POINT
JSR ROTATE
PULS X
LDA 3,X
CMPA #$10
BGE ROTMX3
CMPA #-$10
BLE ROTMX3 POINT TOO BIG
LDA 6,X
CMPA #$10
BGE ROTMX3
CMPA #-$10
BLE ROTMX3
ROTMX2 LEAX 9,X GET NEXT POINT
CMPX #LASTPT
BLE ROTMX1
RTS
ROTMX3 PSHS X UNDO ROTATIONS AS ONE POINT TOO LARGE
LDA ,X
CMPA #$80
BEQ RMX
LEAX 3,X
LEAY 3,X
JSR ROTATE
RMX PULS X
LEAX -9,X
CMPX #POINTS
BHS ROTMX3
RTS
*
* ROTATE POSITIVELY ABOUT Y AXIS
*
ROTY LDX #POINTS
ROTY1 LDA ,X
CMPA #$80 CHECK FOR UNDEFINED POINT
BEQ ROTY2
PSHS X
LEAY ,X ADDRESS OF X-COORDINATE OF CURRENT POINT
LEAX 6,X ADDRESS OF Z-COORDINATE OF CURRENT POINT
JSR ROTATE
PULS X
LDA ,X
CMPA #$10
BGE ROTY3
CMPA #-$10
BLE ROTY3 POINT TOO BIG
LDA 6,X
CMPA #$10
BGE ROTY3
CMPA #-$10
BLE ROTY3
ROTY2 LEAX 9,X GET NEXT POINT
CMPX #LASTPT
BLE ROTY1
RTS
ROTY3 PSHS X UNDO ROTATIONS AS ONE POINT TOO LARGE
LDA ,X
CMPA #$80
BEQ RY
LEAY 6,X
JSR ROTATE
RY PULS X
LEAX -9,X
CMPX #POINTS
BHS ROTY3
RTS
*
* ROTATE NEGATIVELY ABOUT Y AXIS
*
ROTMY LDX #POINTS
ROTMY1 LDA ,X
CMPA #$80 CHECK FOR UNDEFINED POINT
BEQ ROTMY2
PSHS X
LEAY 6,X ADDRESS OF Z-COORDINATE OF CURRENT POINT--X CONTAINS X-COORD
JSR ROTATE
PULS X
LDA ,X
CMPA #$10
BGE ROTMY3
CMPA #-$10
BLE ROTMY3 POINT TOO BIG
LDA 6,X
CMPA #$10
BGE ROTMY3
CMPA #-$10
BLE ROTMY3
ROTMY2 LEAX 9,X GET NEXT POINT
CMPX #LASTPT
BLE ROTMY1
RTS
ROTMY3 PSHS X UNDO ROTATIONS AS ONE POINT TOO LARGE
LDA ,X
CMPA #$80
BEQ RMY
LEAY ,X
LEAX 6,X
JSR ROTATE
RMY PULS X
LEAX -9,X
CMPX #POINTS
BHS ROTMY3
RTS
*
* ROTATE POSITIVELY ABOUT Z AXIS
*
ROTZ LDX #POINTS
ROTZ1 LDA ,X
CMPA #$80 CHECK FOR UNDEFINED POINT
BEQ ROTZ2
PSHS X
LEAY 3,X ADDRESS OF Y-COORDINATE OF CURRENT POINT--X HAS X-COORDINATE
JSR ROTATE
PULS X
LDA ,X
CMPA #$10
BGE ROTZ3
CMPA #-$10
BLE ROTZ3 POINT TOO BIG
LDA 3,X
CMPA #$10
BGE ROTZ3
CMPA #-$10
BLE ROTZ3
ROTZ2 LEAX 9,X GET NEXT POINT
CMPX #LASTPT
BLE ROTZ1
RTS
ROTZ3 PSHS X UNDO ROTATIONS AS ONE POINT TOO LARGE
LDA ,X
CMPA #$80
BEQ RZ
LEAY ,X
LEAX 3,X
JSR ROTATE
RZ PULS X
LEAX -9,X
CMPX #POINTS
BHS ROTZ3
RTS
*
* ROTATE NEGATIVELY ABOUT Z AXIS
*
ROTMZ LDX #POINTS
ROTMZ1 LDA ,X
CMPA #$80 CHECK FOR UNDEFINED POINT
BEQ ROTMZ2
PSHS X
LEAY ,X ADDRESS OF X-COORDINATE OF CURRENT POINT
LEAX 3,X ADDRESS OF Y-COORDINATE OF CURRENT POINT
JSR ROTATE
PULS X
LDA ,X
CMPA #$10
BGE ROTMZ3
CMPA #-$10
BLE ROTMZ3 POINT TOO BIG
LDA 3,X
CMPA #$10
BGE ROTMZ3
CMPA #-$10
BLE ROTMZ3
ROTMZ2 LEAX 9,X GET NEXT POINT
CMPX #LASTPT
BLE ROTMZ1
RTS
ROTMZ3 PSHS X UNDO ROTATIONS AS ONE POINT TOO LARGE
LDA ,X
CMPA #$80
BEQ RMZ
LEAY 3,X
JSR ROTATE
PULS X
RMZ LEAX -9,X
CMPX #POINTS
BHS ROTMZ3
RTS
*
* ROTATE AROUND SOME AXIS AS FOLLOWS: X = COORD POINTED AT BY X-REG, Y=COORD POINTED AT BY Y-REG
* X,Y=(127/128)X-(1/8)Y,(1/8)X+127/128)Y
*
ROTATE LEAU -6,S
LDD ,X
STD ,U
STD 3,U
LDA 2,X
STA 2,U
STA 5,U
ASR 3,U
ROR 4,U
ROR 5,U
ASR 3,U
ROR 4,U
ROR 5,U
ASR 3,U
ROR 4,U
ROR 5,U
ASR 3,U
ROR 4,U
ROR 5,U
ASR 3,U
ROR 4,U
ROR 5,U
ASR 3,U
ROR 4,U
ROR 5,U
ASR 3,U
ROR 4,U
ROR 5,U
LDA 2,U
SUBA 5,U
STA 2,U
LDA 1,U
SBCA 4,U
STA 1,U
LDA ,U
SBCA 3,U
STA ,U
LDD ,Y
STD 3,U
LDA 2,Y
STA 5,U
ASR 3,U
ROR 4,U
ROR 5,U
ASR 3,U
ROR 4,U
ROR 5,U
ASR 3,U
ROR 4,U
ROR 5,U
LDA 2,U
SUBA 5,U
STA 2,U
LDA 1,U
SBCA 4,U
STA 1,U
LDA ,U
SBCA 3,U
STA ,U
LDD ,U
STD ,X
LDA 2,U
STA 2,X
LDD ,Y
STD 3,U
LDA 2,Y
STA 5,U
ASR ,U
ROR 1,U
ROR 2,U
ASR ,U
ROR 1,U
ROR 2,U
ASR ,U
ROR 1,U
ROR 2,U
LDD 1,U
ADDD 4,U
STD 1,U
LDA ,U
ADCA 3,U
STA ,U
ASR 3,U
ROR 4,U
ROR 5,U
ASR 3,U
ROR 4,U
ROR 5,U
ASR 3,U
ROR 4,U
ROR 5,U
ASR 3,U
ROR 4,U
ROR 5,U
ASR 3,U
ROR 4,U
ROR 5,U
ASR 3,U
ROR 4,U
ROR 5,U
ASR 3,U
ROR 4,U
ROR 5,U
LDD 1,U
ADDD 4,U
STD 1,U
LDA ,U
ADCA 3,U
STA ,U
LDD ,U
STD ,Y
LDA 2,U
STA 2,Y
RTS
*
* MAKE THE FIGURE 1/32 BIGGER
*
BIGGER LDX #POINTS
BIG1 LDA ,X CHECK IF POINT IS DEFINED
CMPA #$80
BEQ BIG2
JSR GETBIG INCREASE ALL THREE COORDINATES
LEAX 3,X
JSR GETBIG
LEAX 3,X
JSR GETBIG
LEAX -6,X
LEAY ,X CHEC IF ANY OF 3 COORDS TOO BIG
JSR TOOBIG
BGE BIG3
LEAY 3,Y
JSR TOOBIG
BGE BIG3
LEAY 3,Y
JSR TOOBIG
BGE BIG3
BIG2 LEAX 9,X GET NEXT POINT
CMPX #LASTPT
BLE BIG1
RTS
BIG3 LDA ,X RESTORE POINTS IF ONE MADE OUT OF BOUNDS
CMPA #$80
BNE BIG8
LEAX -9,X
BRA BIG9
BIG8 JSR GETSML
LEAX 3,X
JSR GETSML
LEAX 3,X
JSR GETSML
LEAX -$F,X
BIG9 CMPX #POINTS
BHS BIG3
RTS
GETBIG LEAU -3,S MAKE ONE COORDINATE 1/32 BIGGER
LDD ,X
STD ,U
LDA 2,X
STA 2,U
ASR ,U
ROR 1,U
ROR 2,U
ASR ,U
ROR 1,U
ROR 2,U
ASR ,U
ROR 1,U
ROR 2,U
ASR ,U
ROR 1,U
ROR 2,U
ASR ,U
ROR 1,U
ROR 2,U
LDD 1,X
ADDD 1,U
STD 1,X
LDA ,X
ADCA ,U
STA ,X
RTS
TOOBIG LDA ,Y CHECK IF A COORDINATE TOO BIG--IF FIRST BYTE >= $80 OR <= -$80
CMPA #$10
BGE TB1
NEGA
CMPA #$10
TB1 RTS BGE WILL GO IF NUMBER LOADED INTO A WAS >=$10 OR <=-$10
*
* MAKE THE FIGURE 1/32 SMALLER
*
SMALLR LDX #POINTS
SML1 LDA ,X CHECK IF POINT IS DEFINED
CMPA #$80
BEQ SML2
JSR GETSML
LEAX 3,X
JSR GETSML
LEAX 3,X
JSR GETSML
LEAX 3,X
BRA SMLR1
SML2 LEAX 9,X GET NEXT POINT
SMLR1 CMPX #LASTPT
BLE SML1
* CHECK FOR LINE SEGMENT LENGTH < 1 -- IF ONE FOUND, RESTORE POINTS TO ORIGINAL VALUES
LDU #LINES
SMLR6 CLRA
LDB ,U+
CMPB #$FF
BEQ SMLR5 LAST LINE SEGMENT TESTED
ADDD #POINTS
TFR D,X ADDRESS OF FIRST POINT
CLRA
LDB ,U+
ADDD #POINTS
TFR D,Y ADDRESS OF SECOND POINT
LDD ,X
CMPD ,Y TEST FIRST COORD
BNE SMLR6 INTEGER PARTS NOT EQUAL
LDD 3,X
CMPD 3,Y
BNE SMLR6 INTEGER PARTS OF SECOND COORD NOT EQUAL
LDD 6,X
CMPD 6,Y
BNE SMLR6 INTEGER PARTS OF THIRD COORD NOT EQUAL
* ALL COMPONENTS OF LINE SEGMENT HAVE EQUAL INTEGER PARTS, SO UNDO SMALLER AND RTS FROM BIGGER
LBRA BIGGER
SMLR5 RTS ALL LINE SEGMENTS CHECKED AND LONG ENOUGH
GETSML LEAU -3,S
LDD ,X
STD ,U
LDA 2,X
STA 2,U
ASR ,U
ROR 1,U
ROR 2,U
ASR ,U
ROR 1,U
ROR 2,U
ASR ,U
ROR 1,U
ROR 2,U
ASR ,U
ROR 1,U
ROR 2,U
ASR ,U
ROR 1,U
ROR 2,U
LDD 1,X
SUBD 1,U
STD 1,X
LDA ,X
SBCA ,U
STA ,X
RTS
*
* SUM KEY BUFFERS TO B-REGISTER. USED TO DETERMINE IF KEY STILL DEPRESSED
*
KEYVAL LDB $152
ADDB $153
ADDB $154
ADDB $155
ADDB $156
ADDB $157
ADDB $158
ADDB $159
RTS
*
* DRAW A LINE. X1,X2 TO Y1,Y2 - COORDINATES ARE SIGNED 16 BIT INTEGERS, VISIBLE SCREEN IS -128 TO 127, -95 TO 95 ON USUAL
* X,Y GRAPH
*
BITS FCB $80 FOR SETTING POINTS ON GRAPHICS SCREEN
FCB $40
FCB $20
FCB $10
FCB $8
FCB $4
FCB $2
LASTBT FCB $1
TOP EQU $5F LIMITS OF VIRTUAL SCREEN
BOTTOM EQU -$60
LEFT EQU -$80
RIGHT EQU $7F
X1 RMB 1 2-BYTE COORDINATES FOR TWO POINTS
X1P RMB 1
Y1 RMB 1
Y1P RMB 1
X2 RMB 1
X2P RMB 1
Y2 RMB 1
Y2P RMB 1
SLOPE RMB 1
*
* BEGIN LINE DRAWING ALGORITHM
*
* MAKE SURE X1<X2 OR REVERSE COORDINATES
*
LINE LDD X2
CMPD X1
BGE LN1
LDX X1
STD X1
STX X2
LDX Y1
LDY Y2
STX Y2
STY Y1
*
* CHECK FOR SIGN OF SLOPE
*
LN1 LDD Y2
CMPD Y1
LBLT SELINE
*
* BEGIN DRAWING LINE WITH POSITIVE SLOPE
*
* CHECK FOR NO VISIBLE LINE
*
LDD X1
CMPD #RIGHT
LBGE LNDONE
LDD Y1
CMPD #TOP
LBGE LNDONE
LDD X2
CMPD #LEFT
LBLE LNDONE
LDD Y2
CMPD #BOTTOM
LBLE LNDONE
*
* CHECK IF MUST CLIP LEFT END OF LINE
*
LDD X1
CMPD #LEFT
BLT LN2
LDD Y1
CMPD #BOTTOM
BGE LN3
*
* CLIP LEFT END OF LINE
*
LN2 LDX X2
LDY Y2
PSHS X,Y
LN4 LDD X1 X=(X1+X2)/2
ADDD X2
ASRA
RORB
TFR D,X
LDD Y1 Y=(Y1+Y2)/2
ADDD Y2
ASRA
RORB
TFR D,Y
CMPX #LEFT
BGT LN5
CMPY #TOP
LBGE LNDON1 NO VISIBLE LINE
LN5 CMPX #RIGHT
BLT LN6
CMPY #BOTTOM
LBLE LNDON1 NO VISIBLE LINE
LN6 CMPX #LEFT
BLT LN7
CMPY #BOTTOM
BGE LN8
LN7 STX X1 REPLACE LEFT POINT BY MIDPOINT AND REPEAT
STY Y1
BRA LN4
LN8 CMPX #LEFT
BLE LN9
CMPY #BOTTOM
BLE LN9
STX X2 REPLACE RIGHT POINT BY MIDPOINT
STY Y2
BRA LN4
LN9 STX X1 X1,Y1 NOW ON LEFT OR BOTTOM BOUNDARY
STY Y1
PULS X,Y RECOVER ORIGINAL RIGHT POINT
STX X2
STY Y2
* CHECK IF MUST CLIP RIGHT END OF LINE
*
LN3 LDD X2
CMPD #RIGHT
BGT LN10
LDD Y2
CMPD #TOP
BLE LN18
*
* CLIP RIGHT END OF LINE
*
LN10 LDX X1
LDY Y1
PSHS X,Y
LN11 LDD X1 X=(X1+X2)/2
ADDD X2
ASRA
RORB
TFR D,X
LDD Y1 Y=(Y1+Y2)/2
ADDD Y2
ASRA
RORB
TFR D,Y
CMPX #RIGHT
BGT LN12
CMPY #TOP
BLE LN13
LN12 STX X2 MOVE RIGHT POINT TO MIDPOINT AND REPEAT
STY Y2
BRA LN11
LN13 CMPX #RIGHT
BGE LN14
CMPY #TOP
BGE LN14
STX X1 MOVE LEFT POINT TO MIDPOINT AND REPEAT
STY Y1
BRA LN11
LN14 STX X2 MOVE X2,Y2 TO TOP OR RIGHT BOUNDARY, RECOVER X1,Y1
STY Y2
PULS X,Y
STX X1
STY Y1
*
* DECIDE IF SLOPE > 1
*
LN18 LDA X2P X1P, ETC HOLD CORRECT ONE-BYTE SIGNED VALUES FOR THE COORDINATES, WHICH ARE NOW ON THE VIRTUAL SCREEN
SUBA X1P
PSHS A
LDB Y2P
SUBB Y1P
CMPB ,S+
BLO ENELN
*
* DRAW A LINE WITH POSITIVE SLOPE
*
PSHS B SAVE NUMBER OF POINTS ON LINE - 1
JSR GETSLP SLOPE = DX/DY, AN 8-BIT FRACTION
JSR FRSTBT SET X,U TO POINT TO BYTE AND BIT ON GRAPHICS SCREEN CORRESP. TO X1,Y1
PULS B
CLRA
TFR D,Y
LEAY 1,Y Y=#POINTS ON LINE
CLRB
LN15 LDA ,X SET THE POINTS ON THE GRAPHICS SCREEN FOR THE LINE
ORA ,U GET THE BYTE AND OR IN THE BIT
STA ,X
LEAY -1,Y REDUCE POINT COUNT
LBEQ LNDONE
LEAX -$20,X INCREASE Y-COORDINATE BY 1
ADDB SLOPE INCREASE X-COORDINATE BY SLOPE (A FRACTION)
BCC LN15 B=X MOD 1
LEAU 1,U INCREASE X-COORDINATE BY 1
CMPU #LASTBT TRY TO MOVE RIGHT ONE BIT
BLS LN15
LDU #BITS ELSE USE NEXT BYTE AND LEFT BIT
LEAX 1,X
BRA LN15
*
* DRAW LINE WITH POSITIVE SLOPE <1
*
ENELN PSHS A SAVE # OF POINTS ON LINE - 1
EXG A,B
JSR GETSLP SLOPE = DY/DX
JSR FRSTBT X,U ARE BYTE AND BIT CORRESP. TO X1,Y1
PULS B
CLRA
TFR D,Y
LEAY 1,Y Y=#POINTS ON LINE
CLRB
LN16 LDA ,X DRAW THE LINE
ORA ,U GET THE BYTE, OR IN THE BIT
STA ,X
LEAY -1,Y REDUCE THE POINT COUNT
LBEQ LNDONE
LEAU 1,U MOVE ONE BIT TO RIGHT
CMPU #LASTBT IF POSSIBLE
BLS LN17
LEAX 1,X ELSE MOVE TO NEXT BYTE AND FIRST BIT
LDU #BITS
LN17 ADDB SLOPE
BCC LN16 NO OVERFLO TO NEXT INTEGER WHEN ADDING SLOPE TO Y