-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathforth11.asm
More file actions
3430 lines (2805 loc) · 118 KB
/
forth11.asm
File metadata and controls
3430 lines (2805 loc) · 118 KB
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
;*******************************************************************************
; FORTH11.ASM fig-FORTH for the Motorola MC68HC11A1
; October 30, 1990
;******************************************************************************
; Memory Map
;
; $0000 - $00ff 68hc11 internal ram
; $1000 - $103F 68hc11 internal registers
; $2000 - $7FFF 8k RAM
; $E000 - $FFFF 8k EPROM w/FORTH and 68hc11 vectors
;******************************************************************************
; Forth interpreter/compiler
;******************************************************************************
MEMTOP equ $7FFF
RAMTOP equ $7600
OPTION equ $1039
; each disk buffer block is one 256 byte sector
; with a 2 byte block id and a 2 byte null terminator
; 8 - 256 byte blocks = 2 - 1024 byte screens
NBLK equ 8
MEMEND equ 260*NBLK+RAMTOP
REGS equ $1000 ; start of registers
BAUD equ REGS+$2B ; SCI baud reg
SCCR1 equ REGS+$2C ; SCI control1 reg
SCCR2 equ REGS+$2D ; SCI control2 reg
SCSR equ REGS+$2E ; SCI status reg
SCDAT equ REGS+$2F ; SCI data reg
PORTA equ REGS+$00
PACTL equ REGS+$26
TMSK2 equ REGS+$24
TFLG2 equ REGS+$25
;******************************************************************************
#RAM 0 ; zero page memory
;******************************************************************************
N rmb 32 ; scratch for (FIND),ENCLOSE,CMOVE
; EMIT,KEY,SP@,SWAP,DOES>,COLD
;-------------------------------------- ; registers used by the FORTH virtual machine
W rmb 2 ; instruction reg points to 6800 code
IP rmb 2 ; inst. pointer points to pointer to 6800 code
RP rmb 2 ; return stack pointer
UP rmb 2 ; pointer to base of current user's 'USER' table
; ( altered during multitasking )
;******************************************************************************
; system parameters initialized by COLD or WARM
; names refer to FORTH words of similar ( no X ) name
;******************************************************************************
#RAM $2000
UORIG rmb 6 ; user variables
XSPZER rmb 2 ; initial top of data stack for user
XRZERO rmb 2 ; initial top of return stack
XTIB rmb 2 ; start of terminal input buffer
XWIDTH rmb 2 ; name field width
XWARN rmb 2 ; warning message mode (0 = no disc)
XFENCE rmb 2 ; fence for FORGET
XDP rmb 2 ; dictionary pointer
XVOCL rmb 2 ; vocabulary linking
XBLK rmb 2 ; disk block being accessed
XIN rmb 2 ; scan pointer into the block
XOUT rmb 2 ; cursor position
XSCR rmb 2 ; disc screen being accessed
XOFSET rmb 2 ; disc sector offset for multi disc
XCONT rmb 2 ; last word in primary search vocab.
XCURR rmb 2 ; last word in extensible vocabulary
XSTATE rmb 2 ; interpret/compile mode flag
XBASE rmb 2 ; number base for i/o numeric conversion
XDPL rmb 2 ; decimal point place
XFLD rmb 2
XCSP rmb 2 ; current stack pos, for compile checks
XRNUM rmb 2
XHLD rmb 2
XDELAY rmb 2 ; carriage return delay count
XCOLUM rmb 2 ; carriage width
IOSTAT rmb 2 ; last ACIA status from read/write
;-------------------------------------- ; common system variables
XUSE rmb 2
XPREV rmb 2
XTRACK rmb 2 ; ( 4 spares ! )
XSECTOR rmb 2
XDSTAT rmb 2
XBLOCK rmb 2
XBUFFER rmb 2
;--------------------------------------
; code here through REND is overwritten at time of cold load.
;--------------------------------------
fcb $C5
fcc 'FORT'
fcb $C8
fdb NOOP-7
FORTH fdb DODOES,DOVOC,$81A0,TASK-7
fdb 0
fcc '(C) Forth Interest Group, 1979'
fcb $C4
fcc 'TAS'
fcb $CB
fdb FORTH-8
TASK fdb DOCOL,SEMIS
REND equ * ; first empty location in dictionary
;******************************************************************************
#ROM $E000
;******************************************************************************
; Initialize
INIT sei
lda #$B3
sta OPTION
;-------------------------------------- ; init SCI for 9600 baud at 8.0 mhz
lda #$30
sta BAUD ; baud register
lda #$00
sta SCCR1
lda #$0C
sta SCCR2 ; enable
;******************************************************************************
; cold entry
;******************************************************************************
ORIG nop
jmp CENT
;******************************************************************************
; warm entry
;******************************************************************************
nop
jmp WENT ; warm start
; keeps current dictionary intact
;******************************************************************************
; startup parameters
;******************************************************************************
fdb $6811,0001 ; cpu and revision
fdb 0 ; topmost word in FORTH vocabulary
BACKSP fdb $08 ; backspace character for editing
UPINIT fdb UORIG ; initial user area
SINIT fdb RAMTOP-$100 ; initial top of data stack
RINIT fdb RAMTOP-2 ; initial top of return stack
fdb RAMTOP-$D0 ; terminal input buffer
fdb 31 ; initial name field width
fdb 0 ; initial warning mode (0 = no disc)
FENCIN fdb REND ; initial fence
DPINIT fdb REND ; cold start value for DP
VOCINT fdb FORTH+8 ; cold start value for VOC-LINK
COLINT fdb 80 ; initial terminal carriage width
DELINT fdb 4 ; initial carriage return delay
PULABX puld ; get data word
STABX std ,x ; store at address
bra NEXT
GETX ldd ,x ; get data from address
PUSHBA pshd ; and save on stack
; *=================== the virtual machine =====================================
NEXT ldx IP
inx:2 ; pre-increment mode
stx IP
NEXT2 ldx ,x ; get W which points to CFA of word to be done
NEXT3 stx W
NEXT5 ldx ,x ; get VECT which points to executable code
jmp ,x ; and then do it
nop ; align 2
; *=============================================================================
; *=======>> 1 << LIT ; primitive
fcb $83
fcc 'LI'
fcb $D4
fdb 0 ; link of zero to terminate dictionary scan
LIT fdb *+2
ldx IP ; get instruction pointer
inx:2
stx IP ; x points to next instruction
ldd ,x ; next instruction is 16 bit literal
bra PUSHBA ; so push it on stack
; *=======>> 3 << EXECUTE ; primitive
fcb $87
fcc 'EXECUT'
fcb $C5
fdb LIT-6
EXEC fdb *+2
tsx ; move stack pointer to x
ldx ,x ; get code field address (CFA)
ins:2 ; pop stack
bra NEXT3 ; go execute word that cfa points to
; *=======>> 4 << BRANCH
fcb $86
fcc 'BRANC'
fcb $C8
fdb EXEC-10
BRAN fdb ZBYES ; go do unconditional branch
; *=======>> 5 << 0BRANCH ; primitive
fcb $87
fcc '0BRANC'
fcb $C8
fdb BRAN-9
ZBRAN fdb *+2
puld ; get flag
aba ; add together to see if zero
bne ZBNO ; a and b are not zero - don't branch
bcs ZBNO ; if overflow a and b are not zero !
; flag is false ( zero ) - branch
ZBYES ldx IP ; code is shared with BRANCH, (+LOOP),(LOOP)
ldd 2,X ; get offset
addd IP ; add offset to instruction pointer
std IP ; save it
bra NEXT ; go branch !
; flag is true ( non-zero ) - don't branch
ZBNO ldx IP ; no branch. this code is shared with (+LOOP),(LOOP)
inx:2 ; jump over branch delta
stx IP ; save pointer
bra NEXT ; go do next instruction
; *=======>> 6 << (LOOP) ; primitive
fcb $86
fcc '(LOOP'
fcb $A9
fdb ZBRAN-10
XLOOP fdb *+2
clra ; upper 8 is zero
ldb #1 ; get set to increment counter by 1
bra XPLOP2 ; go steal other guy's code
; *=======>> 7 << (+LOOP) ; primitive
fcb $87
fcc '(+LOOP'
fcb $A9
fdb XLOOP-9
XPLOOP fdb *+2 ; +LOOP has an unsigned loop counter
puld ; get increment value
XPLOP2 tsta check if forward or backward looping
bpl XPLOF ; forward looping
ldx RP
addd 2,X
std 2,X
sec
sbcb 5,X
sbca 4,X
bpl ZBYES
bra XPLONO ; fall thru
XPLOF nop
ldx RP
addd 2,X
std 2,X
; bsr XPLOPS
subd 4,X
bmi ZBYES
XPLONO inx:4 ; done, don't branch back
stx RP
bra ZBNO
; *=======>> 8 << (DO) ; primitive
fcb $84
fcc '(DO'
fcb $A9
fdb XPLOOP-10
XDO1 fdb *+2 ; this is the RUN-TIME DO, not the COMPILING DO
ldx RP ; get copy of return pointer
dex:4
stx RP
puld ; pull data word off stack
std 2,X ; save on return stack
puld ; pull ??? off stack
std 4,X ; save on return stack
jmp NEXT
; *=======>> 9 << I ; primitive
fcb $81 ; I
fcb $C9
fdb XDO1-7
I fdb *+2
ldx RP ; looks like I is kept on return stack
inx:2
jmp GETX
; *=======>> 10 << DIGIT
fcb $85
fcc 'DIGI'
fcb $D4
fdb I-4
DIGIT fdb *+2 ; legal input range is 0-9, A-Z
tsx ; copy stack pointer to x
lda 3,X
suba #'0' ; ASCII zero
bmi DIGIT2 ; if less than '0', ILLEGAL
cmpa #10
bmi DIGIT0 ; if '9' or less
cmpa #$11
bmi DIGIT2 ; if less than 'A'
cmpa #$2B
bpl DIGIT2 ; if greater than 'Z'
suba #7 ; translate 'A' thru 'F'
DIGIT0 cmpa 1,X
bpl DIGIT2 ; if not less than the base
ldb #1 ; set flag
sta 3,X ; store digit
DIGIT1 stb 1,X ; store the flag
jmp NEXT
DIGIT2 clrb
ins:2 ; pop bottom number
tsx
stb ,x ; make sure both bytes are 00
bra DIGIT1
; the word format in the dictionary is :
; NFA char-count + 80 lowest address
; char 1
; char 2
; char n + $80
; LFA link high byte \___ point to previous word
; link low byte /
; CFA CFA high byte \___ point to 6800 code
; CFA low byte /
; PFA parameter fields
; ' '
; ' '
; *=======>> 11 << (FIND)
fcb $86
fcc '(FIND'
fcb $A9
fdb DIGIT-8
PFIND fdb *+2
nop:2
PD equ N ; pointer to dict word being checked
PA0 equ N+2
PA equ N+4
PC equ N+6
ldx #PD
ldb #4
PFIND0 pula ; loop to get arguments off stack
sta ,x
inx
decb
bne PFIND0
ldx PD
PFIND1 ldb ,x ; get count dict count
stb PC
andb #$3F
inx
stx PD ; update PD
ldx PA0
lda ,x ; get count from arg
inx
stx PA ; initialize PA
cba ; compare lengths
bne PFIND4
PFIND2 ldx PA
lda ,x
inx
stx PA
ldx PD
ldb ,x
inx
stx PD
tstb is dict entry neg. ?
bpl PFIND8
andb #$7F ; clear sign
cba
beq FOUND
PFIND3 ldx ,x ; get new link
bne PFIND1 ; continue if link not = 0
;-------------------------------------- ; not found
clrd
jmp PUSHBA
PFIND8 cba
beq PFIND2
PFIND4 ldx PD
PFIND9 ldb ,x ; scan forward to end of this name
inx
bpl PFIND9 ; read until bit 7 is found set
bra PFIND3
FOUND ldd PD ; compute CFA
addd #4
pshd ; and push on stack
lda PC ; push dictionary count
psha
clra
psha ; with upper 8 bits zero
ldb #1 ; construct a true flag
jmp PUSHBA ; and go push on stack
; *=======>> 12 << ENCLOSE
fcb $87
fcc 'ENCLOS'
fcb $C5
fdb PFIND-9
; FC means offset (bytes) to first character of next word
; EW ' ' ' to end of word
; NC ' ' ' to next character to start next enclose at
ENCLOS fdb *+2
ins
pulb ; now, get low byte, for an 8 bit delimiter
tsx ; copy stack pointer
ldx ,x ; get address to start enclose at
clr N ; clear counter
; wait for a non-delimiter or a NUL
ENCL2 lda ,x ; get a character
beq ENCL6 ; found null
cba ; is it the delimiter ?
bne ENCL3 ; yes
inx ; no
inc N ; bump count
bra ENCL2 ; try it again
; found first character. Push FC
ENCL3 lda N ; found first character
psha ; push count
clra
psha ; push $00
; wait for a delimiter or a NUL
ENCL4 lda ,x ; get another character
beq ENCL7 ; it's a null
cba ; check for a delimiter
beq ENCL5 ; yes - it is the delimiter
inx ; no
inc N ; increment count
bra ENCL4 ; see if we can find it somewhere
; found end of word
ENCL5 ldb N ; get count
clra ; upper 8 = 0
pshd ; push EW
; advance and push NC
incb ; increment
jmp PUSHBA
; found NUL before non-delimiter, therefore there is no word
ENCL6 ldb N ; found NUL
pshd
incb
bra ENCL7+2
; found NUL following the word instead of SPACE
ENCL7 ldb N
pshd
ENCL8 ldb N
jmp PUSHBA
; the next 4 words call system dependent I/O subroutines
; which are listed after '-->' in the dictionary
; *=======>> 13 << EMIT
fcb $84
fcc 'EMI'
fcb $D4
fdb ENCLOS-10
EMIT fdb *+2
pula:2 ; get data
stb N ; save B
stx N+1 ; save X
EMIT1 ldb SCSR ; read status
bitb #$40
beq EMIT1
anda #$7F ; mask parity
sta SCDAT ; send character
ldb N ; recover B & X
ldx N+1
jmp NEXT
; *=======>> 14 << KEY
fcb $83
fcc 'KE'
fcb $D9
fdb EMIT-7
KEY fdb *+2
stb N ; save b and x
stx N+1
INSCI lda SCSR ; read status reg
anda #$20
beq INSCI ; jump if rdrf=0
lda SCDAT ; read data register
anda #$7F ; mask parity
ldb N ; restore b and x
ldx N+1
psha ; push data byte
clra
psha ; push a zero byte
jmp NEXT
; *=======>> 15 << ?TERMINAL
fcb $89
fcc '?TERMINA'
fcb $CC
fdb KEY-6
QTERM fdb *+2
lda SCSR
anda #$20 ; rdrf set ?
beq QTERM1
lda SCDAT ; yes - read data to clear it
lda #$01 ; flag = true
bra QTERM2
QTERM1 clra ; flag = false
QTERM2 clrb
jmp PUSHBA ; stack the flag
; *=======>> 16 << CR
fcb $82
fcc 'C'
fcb $D2
fdb QTERM-12
CR fdb *+2
lda #$D ; carriage return
CR1 ldb SCSR ; read status
bitb #$40
beq CR1 ; loop until tC=1
anda #$7F ; mask parity
sta SCDAT ; send character
lda #$A ; line feed
CR2 ldb SCSR ; read status
bitb #$40
beq CR2 ; loop until tC=1
anda #$7F ; mask parity
sta SCDAT ; send character
jmp NEXT
; *=======>> 17 << CMOVE ; source, destination, count
fcb $85
fcc 'CMOV'
fcb $C5
fdb CR-5
CMOVE fdb *+2
ldx #N ; find temp storage area
ldb #6 ; byte count
; n = count ; n+2 = destination ; n+4 = source
CMOV1 pula ; pop 6 bytes off stack
sta ,x ; move parameters to scratch area
inx
decb
bne CMOV1
CMOV2 ldd N ; get count
subd #1 ; subtract one
std N ; save count
bcs CMOV3 ; we be done ?
ldx N+4 ; get source address
lda ,x ; get source data
inx
stx N+4 ; save source pointer
ldx N+2 ; get destination pointer
sta ,x ; write it to destination
inx
stx N+2 ; save destination pointer
_CMOV2 bra CMOV2
CMOV3 jmp NEXT
; *=======>> 18 << U*
fcb $82
fcc 'U'
fcb $AA
fdb CMOVE-8
USTAR fdb *+2
lda #16 ; bits/word counter
psha
clra
clrb
tsx
USTAR2 ror 3,X ; shift multiplier
ror 4,X
dec ,x ; done ?
bmi USTAR4 ; yes
bcc USTAR3
addd 1,X
USTAR3 rora
rorb ; shift result
bra USTAR2
USTAR4 ins ; dump counter
ins
ins
jmp PUSHBA ; leave high word
; *=======>> 19 << U/
fcb $82
fcc 'U'
fcb $AF
fdb USTAR-5
USLASH fdb *+2
lda #17
psha
tsx
ldd 3,X
USL1 cmpa 1,X
bhi USL3
bcs USL2
cmpb 2,X
bcc USL3
USL2 clc
bra USL4
USL3 subd 1,X
sec
USL4 rol 6,X
rol 5,X
dec ,x
beq USL5
rolb
rola
bcc USL1
bra USL3
USL5 ins
ins
ins
ins
ins
jmp SWAP+4 ; reverse quotient and remainder
; *=======>> 20 << AND
fcb $83
fcc 'AN'
fcb $C4
fdb USLASH-5
AND fdb *+2
puld ; pop data off stack
tsx ; copy stack pointer
andb 1,X ; AND the D acc with data on stack
anda ,x
jmp STABX ; go save result
; *=======>> 21 << OR
fcb $82
fcc 'O'
fcb $D2
fdb AND-6
OR fdb *+2
puld ; pop data off stack
tsx ; copy stack pointer
orab 1,X ; OR the D acc with data on stack
oraa ,x
jmp STABX ; go save result
; *=======>> 22 << XOR
fcb $83
fcc 'XO'
fcb $D2
fdb OR-5
XOR fdb *+2
puld ; pop data
tsx ; copy stack pointer
eorb 1,X ; XOR the D acc with data on stack
eora ,x
jmp STABX ; go save result
; SP@
fcb $83
fcc 'SP'
fcb $C0
fdb XOR-6
SPAT fdb *+2
tsx ; copy stack pointer
stx N ; save in scratch area
ldx #N ; this doesn't make sense to me !!
jmp GETX
; *=======>> 24 << SP!
fcb $83
fcc 'SP'
fcb $A1
fdb SPAT-6
SPSTOR fdb *+2
ldx UP ; get user pointer
ldx XSPZER-UORIG,X ; find initialization value for sp
txs ; watch it! X and S are not equal
jmp NEXT
; *=======>> 25 << RP!
fcb $83
fcc 'RP'
fcb $A1
fdb SPSTOR-6
RPSTOR fdb *+2
ldx RINIT ; initialize from rom constant
stx RP ; save new return pointer
jmp NEXT
; *=======>> 26 << ;S
fcb $82
fcc ';'
fcb $D3
fdb RPSTOR-6
SEMIS fdb *+2
ldx RP ; get return pointer
inx:2
stx RP
ldx ,x ; get address we have just finished
jmp NEXT+2 ; increment the return address & do next word
; *=======>> 27 << LEAVE
fcb $85
fcc 'LEAV'
fcb $C5
fdb SEMIS-5
LEAVE fdb *+2
ldx RP
ldd 2,X
std 4,X
jmp NEXT
; *=======>> 28 << >R
fcb $82
fcc '>'
fcb $D2
fdb LEAVE-8
TOR fdb *+2
ldx RP ; find return stack
dex:2 ; make room on return stack
stx RP
puld ; pop data
std 2,X ; and save on return stack
jmp NEXT
; *=======>> 29 << R>
fcb $82
fcc 'R'
fcb $BE
fdb TOR-5
FROMR fdb *+2
ldx RP ; find return stack
ldd 2,X ; get data
inx:2 ; toss out 2 bytes
stx RP ; save pointer
jmp PUSHBA ; push data back on stack
; *=======>> 30 << R
fcb $81 ; R
fcb $D2
fdb FROMR-5
R fdb *+2
ldx RP ; find pointer
inx:2
jmp GETX ; copy data and push on data stack
; *=======>> 31 << 0=
fcb $82
fcc '0'
fcb $BD
fdb R-4
ZEQU fdb *+2
tsx ; copy stack pointer
clra
clrb
ldx ,x ; now get data off stack
bne ZEQU2 ; not zero so leave false flag
incb ; it is zero so leave true flag
ZEQU2 tsx
jmp STABX ; save flag
; *=======>> 32 << 0<
fcb $82
fcc '0'
fcb $BC
fdb ZEQU-5
ZLESS fdb *+2
tsx ; copy stack pointer
lda #$80 ; check the sign bit
anda ,x
beq ZLESS2
clra ; if negative
ldb #1 ; leave true flag as it is less than zero
jmp STABX
ZLESS2 clrb ; leave false - it's greater than zero
jmp STABX
; *=======>> 33 << +
fcb $81 ; +
fcb $AB
fdb ZLESS-5
PLUS fdb *+2
puld ; pop data
tsx ; copy stack pointer
addd ,x ; add two words
jmp STABX ; and leave result on stack
; *=======>> 34 << D+
fcb $82
fcc 'D'
fcb $AB
fdb PLUS-4
DPLUS fdb *+2
tsx ; copy stack pointer
clc
ldb #4 ; double word is 4 bytes
DPLUS2 lda 3,X ; point to byte of bottom
adca 7,X ; add to byte of top
sta 7,X ; save result
dex
decb ; knock down count
bne DPLUS2 ; do until 4 bytes complete
ins ; toss 2 words
ins
ins
ins
jmp NEXT
; *=======>> 35 << MINUS ; change sign of word on stack
fcb $85
fcc 'MINU'
fcb $D3
fdb DPLUS-5
MINUS fdb *+2
tsx ; copy stack pointer
neg 1,X ; negate bottom byte
bcs MINUS2
neg ,x ; negate upper byte
bra MINUS3
MINUS2 com ,x
MINUS3 jmp NEXT
; *=======>> 36 << DMINUS ; change sign of double word on stack
fcb $86
fcc 'DMINU'
fcb $D3
fdb MINUS-8
DMINUS fdb *+2
tsx ; copy stack pointer
com ,x
com 1,X
com 2,X
neg 3,X
bne DMINX ; figure this out later
inc 2,X
bne DMINX
inc 1,X
bne DMINX
inc ,x
DMINX jmp NEXT
; *=======>> 37 << OVER
fcb $84
fcc 'OVE'
fcb $D2
fdb DMINUS-9
OVER fdb *+2
tsx ; copy stack pointer
ldd 2,X ; get second word on stack
jmp PUSHBA ; and copy it to top
; *=======>> 38 << DROP
fcb $84
fcc 'DRO'
fcb $D0
fdb OVER-7
DROP fdb *+2
ins ; knock sp twice
ins ; to remove top item froom stack
jmp NEXT
; *=======>> 39 << SWAP
fcb $84
fcc 'SWA'
fcb $D0
fdb DROP-7
SWAP fdb *+2
puld ; get top item of stack
tsx ; copy sp
ldx ,x ; copy second item
ins:2
pshd ; save top item as second item
stx N ; now go save second as top
ldx #N
jmp GETX
; *=======>> 40 << DUP
fcb $83
fcc 'DU'
fcb $D0
fdb SWAP-7
DUP fdb *+2
puld ; get data
pshd ; push data
jmp PUSHBA ; push it again to duplicate
; *=======>> 41 << +!
fcb $82
fcc '+'
fcb $A1
fdb DUP-6
PSTORE fdb *+2
tsx ; copy stack pointer
ldx ,x ; get address
ins:2
puld ; get data from stack
addb 1,X ; add and store low byte
stb 1,X
adca ,x ; add and store high byte