-
Notifications
You must be signed in to change notification settings - Fork 4
/
FIG6502.ASM
3829 lines (3820 loc) · 97.7 KB
/
FIG6502.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
;
; Through the courtesy of
;
; FORTH INTEREST GROUP
; P.O. BOX 2154
; OAKLAND, CALIFORNIA
; 94621
;
;
; Release 1.1
;
; with compiler security
; and
; variable length names
;
; Further distribution must include the above notice.
; The FIG installation Manual is required as it contains
; the model of FORTH and glossary of the system.
; Available from FIG at the above address for **.** postpaid.
;
; Translated from the FIG model by W.F. Ragsdale with input-
; output given for the Rockwell System-65. Transportation to
; other systems requires only the alteration of :
; XEMIT, XKEY, XQTER, XCR, AND RSLW
;
; Equates giving memory assignments, machine
; registers, and disk parameters.
;
SSIZE =128 ; sector size in bytes
NBUF =8 ; number of buffers desired in RAM
; (SSIZE*NBUF >= 1024 bytes)
SECTR =800 ; sector per drive
; forcing high drive to zero
SECTL =1600 ; sector limit for two drives
; of 800 per drive.
BMAG =1056 ; total buffer magnitude, in bytes
; expressed by SSIZE+4*NBUF
;
BOS =$20 ; bottom of data stack, in zero-page.
TOS =$9E ; top of data stack, in zero-page.
N =TOS+8 ; scratch workspace.
IP =N+8 ; interpretive pointer.
W =IP+3 ; code field pointer.
UP =W+2 ; user area pointer.
XSAVE =UP+2 ; temporary for X register.
;
TIBX =$0100 ; terminal input buffer of 84 bytes.
ORIG =$0200 ; origin of FORTH's Dictionary.
MEM =$4000 ; top of assigned memory+1 byte.
UAREA =MEM-128 ; 128 bytes of user area
DAREA =UAREA-BMAG ; disk buffer space.
;
; Monitor calls for terminal support
;
IO_PORT =$401C
OUTCH =$D2C1 ; output one ASCII char. to term.
INCH =$D1DC ; input one ASCII char. to term.
TCR =$D0F1 ; terminal return and line feed.
;
; From DAREA downward to the top of the dictionary is free
; space where the user's applications are compiled.
;
; Boot up parameters. This area provides jump vectors
; to Boot up code, and parameters describing the system.
;
;
;
.align 256
.res 2
; User cold entry point
ENTER: NOP ; Vector to COLD entry
JMP COLD+2 ;
REENTR: NOP ; User Warm entry point
JMP WARM ; Vector to WARM entry
.WORD $0004 ; 6502 in radix-36
.WORD $5ED2 ;
.WORD NTOP ; Name address of MON
.WORD $7F ; Backspace Character
.WORD UAREA ; Initial User Area
.WORD TOS ; Initial Top of Stack
.WORD $1FF ; Initial Top of Return Stack
.WORD TIBX ; Initial terminal input buffer
;
;
.WORD 31 ; Initial name field width
.WORD 0 ; 0=nod disk, 1=disk
.WORD TOP ; Initial fence address
.WORD TOP ; Initial top of dictionary
.WORD VL0 ; Initial Vocabulary link ptr.
;
; The following offset adjusts all code fields to avoid an
; address ending $XXFF. This must be checked and altered on
; any alteration , for the indirect jump at W-1 to operate !
;
.res 2
;.org *+2
;
;
; LIT
; SCREEN 13 LINE 1
;
L22: .BYTE $83,"LI",$D4 ; <--- name field
; <----- link field
.WORD 00 ; last link marked by zero
LIT: .WORD *+2 ; <----- code address field
LDA (IP),Y ; <----- start of parameter field
PHA
INC IP
BNE L30
INC IP+1
L30: LDA (IP),Y
L31: INC IP
BNE PUSH
INC IP+1
;
PUSH: DEX
DEX
;
PUT: STA 1,X
PLA
STA 0,X
;
; NEXT is the address interpreter that moves from machine
; level word to word.
;
NEXT: LDY #1
LDA (IP),Y ; Fetch code field address pointed
STA W+1 ; to by IP.
DEY
LDA (IP),Y
STA W
JSR TRACE ; Remove this when all is well
CLC ; Increment IP by two.
LDA IP
ADC #2
STA IP
BCC L54
INC IP+1
L54: JMP W-1 ; Jump to an indirect jump (W) which
; ; vectors to code pointed to by a code
; ; field.
;
; CLIT pushes the next inline byte to data stack
;
L35: .BYTE $84,"CLI",$D4
.WORD L22 ; Link to LIT
CLIT: .WORD *+2
LDA (IP),Y
PHA
TYA
BEQ L31 ; a forced branch into LIT
;
;
; This is a temporary trace routine, to be used until FORTH
; is generally operating. Then NOP the terminal query
; "JSR ONEKEY". This will allow user input to the text
; interpreter. When crashes occur, the display shows IP, W,
; and the word locations of the offending code. When all is
; well, remove : TRACE, TCOLON, PRNAM, DECNP, and the
; following monitor/register equates.
;
;
;
; Monitor routines needed to trace.
;
XBLANK =$D0AF ; print one blank
CRLF =$D0D2 ; print a carriage return and line feed.
HEX2 =$D2CE ; print accum as two hex numbers
LETTER =$D2C1 ; print accum as one ASCII character
ONEKEY =$D1DC ; wait for keystroke
XW =$12 ; scratch reg. to next code field add
NP =$14 ; scratch reg. pointing to name field
;
;
TRACE: STX XSAVE
JSR CRLF
LDA IP+1
JSR HEX2
LDA IP
JSR HEX2 ; print IP, the interpreter pointer
JSR XBLANK
;
;
LDA #0
LDA (IP),Y
STA XW
STA NP ; fetch the next code field pointer
INY
LDA (IP),Y
STA XW+1
STA NP+1
JSR PRNAM ; print dictionary name
;
LDA XW+1
JSR HEX2 ; print code field address
LDA XW
JSR HEX2
JSR XBLANK
;
LDA XSAVE ; print stack location in zero-page
JSR HEX2
JSR XBLANK
;
LDA #1 ; print return stack bottom in page 1
JSR HEX2
TSX
INX
TXA
JSR HEX2
JSR XBLANK
;
JSR ONEKEY ; wait for operator keystroke
LDX XSAVE ; just to pinpoint early problems
LDY #0
RTS
;
; TCOLON is called from DOCOLON to label each point
; where FORTH "nests" one level.
;
TCOLON: STX XSAVE
LDA W
STA NP ; locate the name of the called word
LDA W+1
STA NP+1
JSR CRLF
LDA #$3A ; ':
JSR LETTER
JSR XBLANK
JSR PRNAM
LDX XSAVE
RTS
;
; Print name by it's code field address in NP
;
PRNAM: JSR DECNP
JSR DECNP
JSR DECNP
LDY #0
PN1: JSR DECNP
LDA (NP),Y ; loop till D7 in name set
BPL PN1
PN2: INY
LDA (NP),Y
JSR LETTER ; print letters of name field
LDA (NP),Y
BPL PN2
JSR XBLANK
LDY #0
RTS
;
; Decrement name field pointer
;
DECNP: LDA NP
BNE DECNP1
DEC NP+1
DECNP1: DEC NP
RTS
;
;
SETUP: ASL A
STA N-1
L63: LDA 0,X
STA N,Y
INX
INY
CPY N-1
BNE L63
LDY #0
RTS
;
; EXCECUTE
; SCREEN 14 LINE 11
;
L75: .BYTE $87,"EXECUT",$C5
.WORD L35 ; link to CLIT
EXEC: .WORD *+2
LDA 0,X
STA W
LDA 1,X
STA W+1
INX
INX
JMP W-1 ; to JMP (W) in z-page
;
; BRANCH
; SCREEN 15 LINE 11
;
L89: .BYTE $86,"BRANC",$C8
.WORD L75 ; link to EXCECUTE
BRAN: .WORD *+2
CLC
LDA (IP),Y
ADC IP
PHA
INY
LDA (IP),Y
ADC IP+1
STA IP+1
PLA
STA IP
JMP NEXT +2
;
; 0BRANCH
; SCREEN 15 LINE 6
;
L107: .BYTE $87,"0BRANC",$C8
.WORD L89 ; link to BRANCH
ZBRAN: .WORD *+2
INX
INX
LDA $FE,X
ORA $FF,X
BEQ BRAN+2
;
BUMP: CLC
LDA IP
ADC #2
STA IP
BCC L122
INC IP+1
L122: JMP NEXT
;
; (LOOP)
; SCREEN 16 LINE 1
;
L127: .BYTE $86,"(LOOP",$A9
.WORD L107 ; link to 0BRANCH
PLOOP: .WORD L130
L130: STX XSAVE
TSX
INC $101,X
BNE PL1
INC $102,X
;
PL1: CLC
LDA $103,X
SBC $101,X
LDA $104,X
SBC $102,X
;
PL2: LDX XSAVE
ASL A
BCC BRAN+2
PLA
PLA
PLA
PLA
JMP BUMP
;
; (+LOOP)
; SCREEN 16 LINE 8
;
L154: .BYTE $87,"(+LOOP",$A9
.WORD L127 ; link to (loop)
PPLOO: .WORD *+2
INX
INX
STX XSAVE
LDA $FF,X
PHA
PHA
LDA $FE,X
TSX
INX
INX
CLC
ADC $101,X
STA $101,X
PLA
ADC $102,X
STA $102,X
PLA
BPL PL1
CLC
LDA $101,X
SBC $103,X
LDA $102,X
SBC $104,X
JMP PL2
;
; (DO)
; SCREEN 17 LINE 2
;
L185: .BYTE $84,"(DO",$A9
.WORD L154 ; link to (+LOOP)
PDO: .WORD *+2
LDA 3,X
PHA
LDA 2,X
PHA
LDA 1,X
PHA
LDA 0,X
PHA
;
POPTWO: INX
INX
;
;
;
POP: INX
INX
JMP NEXT
;
; I
; SCREEN 17 LINE 9
;
L207: .BYTE $81,$C9
.WORD L185 ; link to (DO)
I: .WORD R+2 ; share the code for R
;
; DIGIT
; SCREEN 18 LINE 1
;
L214: .BYTE $85,"DIGI",$D4
.WORD L207 ; link to I
DIGIT: .WORD *+2
SEC
LDA 2,X
SBC #$30
BMI L234
CMP #$A
BMI L227
SEC
SBC #7
CMP #$A
BMI L234
L227: CMP 0,X
BPL L234
STA 2,X
LDA #1
PHA
TYA
JMP PUT ; exit true with converted value
L234: TYA
PHA
INX
INX
JMP PUT ; exit false with bad conversion
;
; (FIND)
; SCREEN 19 LINE 1
;
L243: .BYTE $86,"(FIND",$A9
.WORD L214 ; Link to DIGIT
PFIND: .WORD *+2
LDA #2
JSR SETUP
STX XSAVE
L249: LDY #0
LDA (N),Y
EOR (N+2),Y
;
;
AND #$3F
BNE L281
L254: INY
LDA (N),Y
EOR (N+2),Y
ASL A
BNE L280
BCC L254
LDX XSAVE
DEX
DEX
DEX
DEX
CLC
TYA
ADC #5
ADC N
STA 2,X
LDY #0
TYA
ADC N+1
STA 3,X
STY 1,X
LDA (N),Y
STA 0,X
LDA #1
PHA
JMP PUSH
L280: BCS L284
L281: INY
LDA (N),Y
BPL L281
L284: INY
LDA (N),Y
TAX
INY
LDA (N),Y
STA N+1
STX N
ORA N
BNE L249
LDX XSAVE
LDA #0
PHA
JMP PUSH ; exit false upon reading null link
;
; ENCLOSE
; SCREEN 20 LINE 1
;
L301: .BYTE $87,"ENCLOS",$C5
.WORD L243 ; link to (FIND)
ENCL: .WORD *+2
LDA #2
JSR SETUP
TXA
SEC
SBC #8
TAX
STY 3,X
STY 1,X
DEY
L313: INY
LDA (N+2),Y
CMP N
BEQ L313
STY 4,X
L318: LDA (N+2),Y
BNE L327
STY 2,X
STY 0,X
TYA
CMP 4,X
BNE L326
INC 2,X
L326: JMP NEXT
L327: STY 2,X
INY
CMP N
BNE L318
STY 0,X
JMP NEXT
;
; EMIT
; SCREEN 21 LINE 5
;
L337: .BYTE $84,"EMI",$D4
.WORD L301 ; link to ENCLOSE
EMIT: .WORD XEMIT ; Vector to code for KEY
;
; KEY
; SCREEN 21 LINE 7
;
L344: .BYTE $83,"KE",$D9
.WORD L337 ; link to EMIT
KEY: .WORD XKEY ; Vector to code for KEY
;
; ?TERMINAL
; SCREEN 21 LINE 9
;
L351: .BYTE $89,"?TERMINA",$CC
.WORD L344 ; link to KEY
QTERM: .WORD XQTER ; Vector to code for ?TERMINAL
;
;
;
;
;
; CR
; SCREEN 21 LINE 11
;
L358: .BYTE $82,"C",$D2
.WORD L351 ; link to ?TERMINAL
CR: .WORD XCR ; Vector to code for CR
;
; CMOVE
; SCREEN 22 LINE 1
;
L365: .BYTE $85,"CMOV",$C5
.WORD L358 ; link to CR
CMOVE: .WORD *+2
LDA #3
JSR SETUP
L370: CPY N
BNE L375
DEC N+1
BPL L375
JMP NEXT
L375: LDA (N+4),Y
STA (N+2),Y
INY
BNE L370
INC N+5
INC N+3
JMP L370
;
; U*
; SCREEN 23 LINE 1
;
L386: .BYTE $82,"U",$AA
.WORD L365 ; link to CMOVE
USTAR: .WORD *+2
LDA 2,X
STA N
STY 2,X
LDA 3,X
STA N+1
STY 3,X
LDY #16 ; for 16 bits
L396: ASL 2,X
ROL 3,X
ROL 0,X
ROL 1,X
BCC L411
CLC
LDA N
ADC 2,X
STA 2,X
LDA N+1
ADC 3,X
STA 3,X
LDA #0
ADC 0,X
STA 0,X
L411: DEY
BNE L396
JMP NEXT
;
; U/
; SCREEN 24 LINE 1
;
L418: .BYTE $82,"U",$AF
.WORD L386 ; link to U*
USLAS: .WORD *+2
LDA 4,X
LDY 2,X
STY 4,X
ASL A
STA 2,X
LDA 5,X
LDY 3,X
STY 5,X
ROL A
STA 3,X
LDA #16
STA N
L433: ROL 4,X
ROL 5,X
SEC
LDA 4,X
SBC 0,X
TAY
LDA 5,X
SBC 1,X
BCC L444
STY 4,X
STA 5,X
L444: ROL 2,X
ROL 3,X
DEC N
BNE L433
JMP POP
;
; AND
; SCREEN 25 LINE 2
;
L453: .BYTE $83,"AN",$C4
.WORD L418 ; link to U/
ANDD: .WORD *+2
LDA 0,X
AND 2,X
PHA
LDA 1,X
AND 3,X
;
BINARY: INX
INX
JMP PUT
;
; OR
; SCREEN 25 LINE 7
;
L469: .BYTE $82,"O",$D2
.WORD L453 ; link to AND
OR: .WORD *+2
LDA 0,X
ORA 2,X
PHA
LDA 1,X
ORA 3,X
INX
INX
JMP PUT
;
; XOR
; SCREEN 25 LINE 11
;
L484: .BYTE $83,"XO",$D2
.WORD L469 ; link to OR
XOR: .WORD *+2
LDA 0,X
EOR 2,X
PHA
LDA 1,X
EOR 3,X
INX
INX
JMP PUT
;
; SP@
; SCREEN 26 LINE 1
;
L499: .BYTE $83,"SP",$C0
.WORD L484 ; link to XOR
SPAT: .WORD *+2
TXA
;
PUSHOA: PHA
LDA #0
JMP PUSH
;
; SP!
; SCREEN 26 LINE 5
;
;
L511: .BYTE $83,"SP",$A1
.WORD L499 ; link to SP@
SPSTO: .WORD *+2
LDY #6
LDA (UP),Y ; load data stack pointer (X reg) from
TAX ; silent user variable S0.
JMP NEXT
;
; RP!
; SCREEN 26 LINE 8
;
L522: .BYTE $83,"RP",$A1
.WORD L511 ; link to SP!
RPSTO: .WORD *+2
STX XSAVE ; load return stack pointer (machine
LDY #8 ; stack pointer) from silent user
LDA (UP),Y ; VARIABLE R0
TAX
TXS
LDX XSAVE
JMP NEXT
;
; ;S
; SCREEN 26 LINE 12
;
L536: .BYTE $82,";",$D3
.WORD L522 ; link to RP!
SEMIS: .WORD *+2
PLA
STA IP
PLA
STA IP+1
JMP NEXT
;
; LEAVE
; SCREEN 27 LINE 1
;
L548: .BYTE $85,"LEAV",$C5
.WORD L536 ; link to ;S
LEAVE: .WORD *+2
STX XSAVE
TSX
LDA $101,X
STA $103,X
LDA $102,X
STA $104,X
LDX XSAVE
JMP NEXT
;
; >R
; SCREEN 27 LINE 5
;
L563: .BYTE $82,">",$D2
.WORD L548 ; link to LEAVE
TOR: .WORD *+2
LDA 1,X ; move high byte
PHA
LDA 0,X ; then low byte
PHA ; to return stack
INX
INX ; popping off data stack
JMP NEXT
;
; R>
; SCREEN 27 LINE 8
;
L577: .BYTE $82,"R",$BE
.WORD L563 ; link to >R
RFROM: .WORD *+2
DEX ; make room on data stack
DEX
PLA ; high byte
STA 0,X
PLA ; then low byte
STA 1,X ; restored to data stack
JMP NEXT
;
; R
; SCREEN 27 LINE 11
;
L591: .BYTE $81,$D2
.WORD L577 ; link to R>
R: .WORD *+2
STX XSAVE
TSX ; address return stack
LDA $101,X ; copy bottom value
PHA ; to data stack
LDA $102,X
LDX XSAVE
JMP PUSH
;
; 0=
; SCREEN 28 LINE 2
;
L605: .BYTE $82,"0",$BD
.WORD L591 ; link to R
ZEQU: .WORD *+2
LDA 1,X ; Corrected from FD3/2 p69
STY 1,X
ORA 0,X
BNE L613
INY
L613: STY 0,X
JMP NEXT
;
; 0<
; SCREEN 28 LINE 6
;
L619: .BYTE $82,"0",$BC
.WORD L605 ; link to 0=
ZLESS: .WORD *+2
ASL 1,X
TYA
ROL A
STY 1,X
STA 0,X
JMP NEXT
;
; +
; SCREEN 29 LINE 1
;
L632: .BYTE $81,$AB
.WORD L619 ; link to V-ADJ
PLUS: .WORD *+2
CLC
LDA 0,X
ADC 2,X
STA 2,X
LDA 1,X
ADC 3,X
STA 3,X
INX
INX
JMP NEXT
;
; D+
; SCREEN 29 LINE 4
;
L649: .BYTE $82,"D",$AB
.WORD L632 ; LINK TO +
DPLUS: .WORD *+2
CLC
LDA 2,X
ADC 6,X
STA 6,X
LDA 3,X
ADC 7,X
STA 7,X
LDA 0,X
ADC 4,X
STA 4,X
LDA 1,X
ADC 5,X
STA 5,X
JMP POPTWO
;
; MINUS
; SCREEN 29 LINE 9
;
L670: .BYTE $85,"MINU",$D3
.WORD L649 ; link to D+
MINUS: .WORD *+2
SEC
TYA
SBC 0,X
STA 0,X
TYA
SBC 1,X
STA 1,X
JMP NEXT
;
; DMINUS
; SCREEN 29 LINE 12
;
L685: .BYTE $86,"DMINU",$D3
.WORD L670 ; link to MINUS
DMINU: .WORD *+2
SEC
TYA
SBC 2,X
STA 2,X
TYA
SBC 3,X
STA 3,X
JMP MINUS+3
;
; OVER
; SCREEN 30 LINE 1
;
L700: .BYTE $84,"OVE",$D2
.WORD L685 ; link to DMINUS
OVER: .WORD *+2
LDA 2,X
PHA
LDA 3,X
JMP PUSH
;
; DROP
; SCREEN 30 LINE 4
;
L711: .BYTE $84,"DRO",$D0
.WORD L700 ; link to OVER
DROP: .WORD POP
;
; SWAP
; SCREEN 30 LINE 8
;
L718: .BYTE $84,"SWA",$D0
.WORD L711 ; link to DROP
SWAP: .WORD *+2
LDA 2,X
PHA
LDA 0,X
STA 2,X
LDA 3,X
LDY 1,X
STY 3,X
JMP PUT
;
; DUP
; SCREEN 30 LINE 21
;
L733: .BYTE $83,"DU",$D0
.WORD L718 ; link to SWAP
DUP: .WORD *+2
LDA 0,X
PHA
LDA 1,X
JMP PUSH
;
; +!
; SCREEN 31 LINE 2
;
L744: .BYTE $82,"+",$A1
.WORD L733 ; link to DUP
PSTOR: .WORD *+2
CLC
LDA (0,X) ; fetch 16 bit value addressed by
ADC 2,X ; bottom of stack, adding to
STA (0,X) ; second item on stack, and return
INC 0,X ; to memory
BNE L754
INC 1,X
L754: LDA (0,X)
ADC 3,X
STA (0,X)
JMP POPTWO
;
; TOGGLE
; SCREEN 31 LINE 7
;
L762: .BYTE $81,"TOGGL",$C5
.WORD L744 ; link to +!
TOGGL: .WORD *+2
LDA (2,X) ; complement bits in memory address
EOR 0,X ; second on stack, by pattern on
STA (2,X) ; bottom of stack.
JMP POPTWO
;
; @
; SCREEN 32 LINE 1
;
L773: .BYTE $81,$C0
.WORD L762 ; link to TOGGLE
AT: .WORD *+2
LDA (0,X)
PHA
INC 0,X
BNE L781
INC 1,X
L781: LDA (0,X)
JMP PUT
;
; C@
; SCREEN 32 LINE 5
;
L787: .BYTE $82,"C",$C0
.WORD L773 ; link to @