-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathclassic.asm
4232 lines (4167 loc) · 52.7 KB
/
classic.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
; NASM listing: Make some MASM directives harmless up front.
%macro IGNORE1 1+ ; One or more parameters
%endmacro
%define IGNORE ; no parameters
%define PAGE IGNORE
%define CSEG IGNORE1
%define ASSUME IGNORE1
%define PROC IGNORE1
%define TITLE IGNORE1
%define OFFSET IGNORE
%define END IGNORE1
; ENDP can only be made harmless by commenting the whole line out
; `comment x' is replace by `%if 0' constructions.
; PAGE 66,106
TITLE FIG-FORTH FOR IBM-PC 1.0
%if 0
FIG-FORTH
implemented by: Charlie Krajewski
205 ( BIG ) Blue Rd.
Middletown, CT 06457
NASM assembler version by:
Albert van der Horst
HCC Forth user group
The Netherlands
www.forth.hccnet.nl
This implementation supports only one 64k segment
The listing has been made possible by the
prior work of:
Thomas Newman, Hayward, Ca.
: other_acknowledgements
John_Cassidy
Kim_Harris
George_Flammer
Robert_D._Villwock ;
To upgrade, modify, and understand Fig Forth, the
value of the following book cannot be overstated:
Systems Guide to FIG Forth
C. H. Ting, PhD
It is available through MVP. See any recent issue
of FORTH Dimensions for their ad.
No one who programs with FORTH can afford to be without:
Starting Forth
Leo Brodie
Get it. Available through FORTH Interest Group.
Can also be found in many book stores.
Chapter 3 serves as a guide for the EDITOR that you
will probably type in from the FIG-Forth installation
manual.
Although there is much to be said for typing in your own
listing and getting it running, there is much to be said
not typing in your own listing. If you feel that 100+
pages of plinking is nutty, contact me for availability
of a disc with source & executable files. Obtainable at
a bargain basement price, prepare yourself for bargain
basement support.
All publications of the FORTH Interest Group are public domain.
They may be further distributed by the inclusion of this
credit notice:
This publication has been made available by:
FORTH Interest Group
P.O. Box 1105
San Carlos, Ca. 94070
%endif
PAGE
FIGREL EQU 1 ; FIG RELEASE #
FIGREV EQU 0 ;FIG REVISION #
USRVER EQU 0 ; USER VERSION NUMBER
;
; ASCII CHARACTER EQUIVALENTS
;
ABL EQU 20H ; SPACE
ACR EQU 0DH ; CR
ADOT EQU 2EH ; PERIOD
BELL EQU 07H ; ^G
BSIN EQU 08H ; INPUT DELETE CHARACTER
BSOUT EQU 08H ; OUTPUT BACKSPACE ( ^H )
DLE EQU 10H ; ( ^P ) MAKE PRINTER OUTPUT DEVICE
LF EQU 0AH ; LINE FEED
FF EQU 0CH ; FORM FEED
;
; MEMORY + I/O CONSTANTS
;
SEC_DSK EQU 360
PRINTER_NO EQU 0
EM EQU 04000H ; END OF MEMORY + 1
NSCR EQU 2 ; NO. 1024 BYTE SCREENS
KBBUF EQU 512 ;DATA BYTES PER DISK BUFFER
US EQU 40H ; USER VARIABLE SPACE
RTS EQU 0A0H ; RETURN STACK & TERM BUFFER
;
CO EQU KBBUF+4 ; DISK BUFFER + 4 BYTES
NBUF EQU NSCR*1024/KBBUF ; NO. OF BUFFERS
BUF1 EQU EM-CO*NBUF ; FIRST DISK BUFFER
INITR0 EQU BUF1-US ; ( RO )
INITS0 EQU INITR0-RTS ; ( S0 )
;
PAGE
CSEG SEGMENT PARA PUBLIC 'CODE'
ASSUME CS:CSEG,DS:CSEG,SS:CSEG,ES:CSEG
ORG 100H ; FOR EXE2BIN COMMAND AFTER LINK
; SEE PG 10-14 OF DOS 2.0 MANUAL
; FOR EXPLANATION OF EXE2BIN
ORIG PROC FAR ; SEE PG 5-31, MACRO ASSEMBLER
NOP
JMP LCLD ;VECTOR TO COLD START
NOP
JMP WRM ; VECTOR TO WARM START
;
DB FIGREL ; FIG RELEASE #
DB FIGREV ; FIG REVISION #
DB USRVER ; USER REVISION #
DB 0EH ; VERSION ATTRIBUTES
DW TASK-7 ; TOP WORD IN FORTH VOCABULARY
DW BSIN ; BACKSPACE
DW INITR0 ; INIT (UP)
;
; <<<<< following used in COLD start >>>>>
; <<<<< must be in same order as user variables >>>>>
;
DW INITS0 ; INIT (S0)
DW INITR0 ; INIT (R0)
DW INITS0 ; INIT (TIB)
DW 32 ; INIT (WIDTH)
DW 0 ; INIT (WARNING)
DW INITDP ; INIT (FENCE)
DW INITDP ; INIT (DP)
DW FORTH+6 ; INIT (VOC-LINK)
;
; <<<<< end of data used by cold start >>>>>
;
; The following is the CPU's name, printed
; during cold start.
; The name is 32 bits in base 32.
;
DW 5H,0B328H ; '8088'
UP DW INITR0 ; USER AREA POINTER
RPP DW INITR0 ; RETURNS STACK POINTER
PAGE
%if 0
FORTH REGISTERS
FORTH 8088 FORTH PRESERVATION RULES
----- ---- ----- ------------ -----
IP SI Interpreter pointer. Must be preserved
across FORTH words.
W DX Working register. Jump to 'DPUSH' will
push contents onto the parameter stack
before executing 'APUSH'.
SP SP Parameter stack pointer. Must be preserved
across FORTH words.
RP BP Return stack. Must be preserved across
FORTH words.
AX General register. Must be preserved across
FORTH words.
BX General purpose register.
CX General purpose register.
DI General purpose register.
CS Segment register. Must be preserved
across FORTH words.
DS ditto
SS ibid
ES Temporary segment register only used by
a few words.
----------------------------------------------------------
%endif
PAGE
%if 0
---------------------------------------------
COMMENT CONVENTIONS
------- -----------
= IS EQUAL TO
<- ASSIGNMENT
NAME = Address of name
(NAME) = Contents of name
((NAME)) = Indirect contents
CFA = Address of CODE FIELD
LFA = Address of LINK FIELD
NFA = Address of NAME FIELD
PFA = Address of PARAMETER FIELD
S1 = Parameter stack - 1st word
S2 = Parameter stack - 2nd word
R1 = Return stack - 1st word
R2 = Return stack - 2nd word
LSB = Least significant bit
MSB = Most significant bit
LB = Low byte
HB = High byte
LW = Low word
------------------------------------------------------------
%endif
PAGE
%if 0
DEBUG SUPPORT
THIS ROUTINE WILL ALLOW YOU TO STEP THRU FORTH PROGRAMS
EVERY TIME 'NEXT' IS EXECUTED.
IN ORDER TO USE THE STEP FEATURE YOU MUST DO THE FOLLOWING:
1. PATCH THE INSTRUCTION IN 'NEXT' WITH A JUMP
TO 'TNEXT'
2. PATCH YOUR BREAKPOINT ROUTINE AT
LABEL 'BREAK'
3. SET VARIABLES, `BIP' & `BIPE' TO THE
ADDRESSES YOU WANT TO STEP THRU.
THE CONTENTS OF THE 2 VARIABLES 'BIP` AND `BIPE'
ARE INTERPRETED AS FOLLOWS:
BIP BIPE DEBUG-CONDITION
--- ---- ---------------
0 X OFF
-1 X TRACE ALL `NEXT' CALLS
ADDR1 0 TRACE `ADDR1' ONLY
ADDR1 ADDR2 TRACE `ADDR1' TO `ADDR1'
NOTE: THE ABOVE ADDRESSES CAN'T POINT TO A
`CODE FIELD ADDRESS'.
X = DON'T CARE
-----------------------------------------------------
%endif
BIP DW 0 ; BREAKPOINT START ADDRESS
BIPE DW 0 ; BREAKPOINT END ADDR
PAGE
; THIS IS THE `NEXT' WITH DEBUG SUPPORT
TNEXT: PUSHF ;SAVE REGISTER
PUSH AX
MOV AX,[BIP] ; BREAKPOINT START ADDR
OR AX,AX ; ZERO?
JZ TNEXT2 ; NO BREAKPOINT
CMP AX,-1
JZ TNEXT1 ; STEP ALL POINTS
CMP AX,SI ; IN BREAKPOINT RANGE?
JZ TNEXT1 ; STEP THIS LOCATION
JA TNEXT2 ; NO
MOV AX,[BIPE] ; BREAKPOINT END ADDR
OR AX,AX ; ZERO?
JZ TNEXT2 ; ONLY 1 LOCATION
CMP AX,SI ; IN RANGE STILL?
JB TNEXT2 ; NO
; PAUSE ON ADDRESS
;
TNEXT1: POPF
;
;******** ADD YOUR BREAKPOINT HERE **********
;
BREAK: JMP SHORT TNEXT3 ;CONT WITH PROGRAM
;
; NO BREAKPOINT PAUSE - RESTORE REGISTERS
;
TNEXT2: POP AX
POPF
TNEXT3: LODSW ; AX <- (IP)
MOV BX,AX
JMP SHORT NEXT1
PAGE
DPUSH: PUSH DX
APUSH: PUSH AX
%if 0
Patch the next 3 locations
( using a DBUG monitor )
with a `JMP TNEXT' for tracing through
high level FORTH words.
%endif
NEXT: LODSW ;AX <- (IP)
MOV BX,AX
;
;
NEXT1: MOV DX,BX ; (W) <- (IP)
INC DX ; (W) <- (W) + 1
JMP [BX] ; TO `CFA'
PAGE
DP0 DB 83H
DB 'LI'
DB 'T'+80H
DW 0 ; START OF DICTIONARY
LIT DW $+2 ; (S1) <- ((IP))
LODSW ; AX <- LITERAL
JMP SHORT APUSH ; TO TOP OF STACK
; EXECUTE
;
DB 87H
DB 'EXECUT'
DB 'E'+80H
DW LIT-6
EXEC DW $+2
POP BX ; GET CFA
JMP SHORT NEXT1 ; EXECUTE NEXT
;
; BRANCH
;
DB 86H ; BRANCH
DB 'BRANC'
DB 'H'+80H
DW EXEC-0AH
BRAN DW $+2
BRAN1: ADD SI,[SI]
JMP SHORT NEXT ; JUMP TO OFFSET
;
; 0BRANCH
;
DB 87H
DB '0BRANC'
DB 'H'+80H
DW BRAN-9
ZBRAN DW $+2
POP AX ; GET STACK VALUE
OR AX,AX ; ZERO?
JZ BRAN1 ; YES, BRANCH
INC SI ; NO - CONTINUE...
INC SI
JMP SHORT NEXT
;
PAGE
;
; (LOOP)
DB 86H
DB '(LOOP'
DB ')'+80H
DW ZBRAN-0AH
XLOOP DW $+2
MOV BX,1 ; INCREMENT
XLOO1: ADD [BP],BX ; INDEX = INDEX + INCR
MOV AX,[BP] ; GET NEW INDEX
SUB AX,[2+BP] ; COMPARE WITH LIMIT
XOR AX,BX ; TEST SIGN
JS BRAN1 ; KEEP LOOPING
;
; END OF `DO' LOOP
ADD BP,BYTE 4 ; ADJ RETURN STACK
INC SI ; BYPASS BRANCH OFFSET
INC SI
JMP SHORT NEXT
; DEBUG STUFF
;
DB 84H
DB 'NOO'
DB 'P'+80H
DW XLOOP-9
NOOP DW $+4
NOP0 DW $+2
JMP SHORT NEXT
NOP1 DW $+2
JMP SHORT NEXT
NOP2 DW $+2
JMP SHORT NEXT
;
; (+LOOP)
;
DB 87H
DB '(+LOOP'
DB ')'+80H
DW NOOP-7
XPLOO DW $+2
POP BX ; GET LOOP VALUE
JMP SHORT XLOO1
;
; (DO)
;
DB 84H
DB '(DO'
DB ')'+80H
DW XPLOO-0AH
XDO DW $+2
POP DX ; INITIAL INDEX VALUE
POP AX ; LIMIT VALUE
XCHG BP,SP ; GET RETURN STACK
PUSH AX
PUSH DX
XCHG BP,SP ; GET PARAMETER STACK
JMP NEXT
PAGE
;
; I
;
DB 81H
DB 'I'+80H
DW XDO-7
IDO DW $+2 ; (SI) <- (RI)
MOV AX,[BP] ; GET INDEX VALUE
JMP APUSH ; TO PARAMETER STACK
;
DB 85H
DB 'DIGI'
DB 'T'+80H
DW IDO-4
DIGIT DW $+2
POP DX ;NUMBER BASE
POP AX ;ASCII DIGIT
SUB AL,'0'
JB DIGI2 ;NUMBER ERROR
CMP AL,9
JBE DIGI1 ;NUMBER = 0 THRU 9
SUB AL,7
CMP AL,10 ;NUMBER 'A' THRU 'Z'?
JB DIGI2 ;NO
DIGI1: CMP AL,DL ; COMPARE NUMBER TO BASE
JAE DIGI2 ;NUMBER ERROR
SUB DX,DX ;ZERO
MOV DL,AL ;NEW BINARY NUMBER
MOV AL,1 ;TRUE FLAG
JMP DPUSH ;ADD TO STACK
; NUMBER ERROR
DIGI2: SUB AX,AX ;FALSE FLAG
JMP APUSH
PAGE
;
DB 86H
DB '(FIND'
DB ')'+80H
DW DIGIT-8
PFIND DW $+2
MOV AX,DS
MOV ES,AX ;ES = DS
POP BX ;NFA
POP CX ;STRING ADDR
;
; SEARCH LOOP
PFIN1: MOV DI,CX ;GET ADDR
MOV AL,[BX] ;GET WORD LENGTH
MOV DL,AL ;SAVE WORD LENGTH
XOR AL,[DI]
AND AL,3FH ;CHECK LENGTHS
JNZ PFIN5 ;LENGTHS DIFFER
;
; LENGTHS MATCH - CHECK EACH CHARACTER IN NAME
PFIN2: INC BX
INC DI ; NEXT CHAR OF NAME
MOV AL,[BX]
XOR AL,[DI] ;COMPARE NAMES
ADD AL,AL ;THIS WILL BE TEST BIT 8
JNZ PFIN5 ;NO MATCH
JNB PFIN2 ;MATCH SO FAR - LOOP
;
; FOUND END OF NAME (BIT 8 SET) - A MATCH
ADD BX,BYTE 5 ; BX = PFA
PUSH BX ; (S3) <- PFA
MOV AX,1 ;TRUE VALUE
SUB DH,DH
JMP DPUSH
;
; NO NAME MATCH - TRY ANOTHER
;
; GET NEXT LINK FIELD ADDR (LFA)
; ( ZERO = FIRST WORD OF DICTIONARY )
;
PFIN5: INC BX ;NEXT ADDR
JB PFIN6 ;END OF NAME
MOV AL,[BX] ;GET NEXT CHAR
ADD AL,AL ;SET/RESET CARRY
JMP SHORT PFIN5 ;LOOP UNTIL FOUND
;
PFIN6: MOV BX,[BX] ; GET LINK FIELD ADDR
OR BX,BX ; START OF DICT ( 0 )
JNZ PFIN1 ; NO , LOOK MORE
MOV AX,0 ; FALSE FLAG
JMP APUSH ; DONE ( NO MATCH FOUND )
;
PAGE
DB 87H
DB 'ENCLOS'
DB 'E'+80H
DW PFIND-9
ENCL DW $+2
POP AX ;S1 - TERMINATOR CHAR
POP BX ;S2 - TEXT ADDR
PUSH BX ;ADDR - BACK TO STACK ( IT RHYMES )
MOV AH,0 ;ZERO
MOV DX,-1 ;CHAR OFFSET COUNTER
DEC BX ;ADDR -1
;
; SCAN TO FIRST NON-TERMINATOR CHARACTER
ENCL1: INC BX ;ADDR+1
INC DX ;COUNT+1
CMP AL,[BX]
JZ ENCL1 ;WAIT FOR NON-TERMINATOR
PUSH DX ;OFFSET TO 1ST TEXT CHAR
CMP AH,[BX] ;NULL CHAR?
JNZ ENCL2 ;NO
;
; FOUND NULL BEFORE 1ST NON-TERM CHAR
MOV AX,DX ;COPY COUNTER
INC DX ; +1
JMP DPUSH
;
; FOUND FIRST TEXT CHAR - COUNT THE CHARS
ENCL2: INC BX ; ADDR+1
INC DX ;COUNT+1
CMP AL,[BX] ;TERMINATOR CHAR?
JZ ENCL4 ;YES
CMP AH,[BX] ;NULL CHAR?
JNZ ENCL2 ;NO, LOOP AGAIN
;
; FOUND NULL AT END OF TEXT
ENCL3: MOV AX,DX ;COUNTERS ARE EQUAL
JMP DPUSH
;
; FOUND TERMINATOR CHARACTER
ENCL4: MOV AX,DX
INC AX ;COUNT+1
JMP DPUSH
PAGE
; At line LINE ~500
; EMIT
DB 84H
DB 'EMI'
DB 'T'+80H
DW ENCL-0AH
EMIT DW DOCOL
DW PEMIT
DW ONE,OUTT
DW PSTOR,SEMIS
;
; KEY
DB 83H
DB 'KE'
DB 'Y'+80H
DW EMIT-7
KEY DW $+2
JMP PKEY
;
; ?TERMINAL
DB 89H
DB '?TERMINA'
DB 'L'+80H
DW KEY-6
QTERM DW $+2
JMP PQTER
;
; CR
DB 82H
DB 'C'
DB 'R'+80H
DW QTERM-0CH
CR DW $+2
JMP PCR
PAGE
; CMOVE
DB 85H
DB 'CMOV'
DB 'E'+80H
DW CR-5
LCMOVE DW $+2
CLD ;INC DIRECTION
MOV BX,SI ;SAVE IF
POP CX ;COUNT
POP DI ;DEST
POP SI ;SOURCE
MOV AX,DS
MOV ES,AX ;ES <- DS
REP MOVSB ;THAT'S THE MOVE
MOV SI,BX ;GET BACK IP
JMP NEXT
;
; U*
;
DB 82H
DB 'U'
DB '*'+80H
DW LCMOVE-8
USTAR DW $+2
POP AX
POP BX
MUL BX ;UNSIGNED
XCHG AX,DX ;AX NOW = MSW
JMP DPUSH ;STORE DOUBLE WORD
;
; U/
;
DB 82H
DB 'U'
DB '/'+80H
DW USTAR-5
USLAS DW $+2
POP BX ;DIVISOR
POP DX ;MSW OF DIVIDEND
POP AX ;LSW OF DIVIDEND
CMP DX,BX ;DICIDE BY 0?
JNB DZERO ; ERROR - ZERO DIVIDE
DIV BX ;16 BIT DIVIDE
JMP DPUSH ;STORE QUOT/REM
;
; DIVIDE BY ZERO ERROR - SHOW MAX NUMBERS
DZERO: MOV AX,-1
MOV DX,AX
JMP DPUSH ;STORE QUOT/REM
PAGE
; AND
;
DB 83H
DB 'AN'
DB 'D'+80H
DW USLAS-5
ANDD DW $+2
POP AX
POP BX
AND AX,BX
JMP APUSH
;
; OR
;
DB 82H
DB 'O'
DB 'R'+80H
DW ANDD-6
ORR DW $+2 ; (S1) <- (S1) OR (S2)
POP AX
POP BX
OR AX,BX
JMP APUSH
;
; XOR
;
DB 83H
DB 'XO'
DB 'R'+80H
DW ORR-5
XORR DW $+2 ; (S1) <- (S1) XOR (S2)
POP AX
POP BX
XOR AX,BX
JMP APUSH
PAGE
; SP@
;
DB 83H
DB 'SP'
DB '@'+80H
DW XORR-6
SPAT DW $+2 ; (S1) <- (SP)
MOV AX,SP
JMP APUSH
;
; SP!
;
DB 83H
DB 'SP'
DB '!'+80H
DW SPAT-6
SPSTO DW $+2
MOV BX,[UP] ;USER VAR BASE ADDR
MOV SP,[6+BX] ;RESET PARAM STACK POINTER
JMP NEXT
;
; RP@
;
DB 83H
DB 'RP'
DB '@'+80H
DW SPSTO-6
RPAT DW $+2 ;(S1) <- (RP)
MOV AX,BP ;RETURN STACK ADDR
JMP APUSH
;
; RP!
;
DB 83H
DB 'RP'
DB '!'+80H
DW RPAT-6
RPSTO DW $+2
MOV BX,[UP] ;(AX) <- USR VAR BASE
MOV BP,[8+BX] ;RESET RETURN STACK PTR
JMP NEXT
;
PAGE
; ;S
;
; END OF SCREEN OR RUN TIME COLON WORDS
;
DB 82H
DB ';'
DB 'S'+80H
DW RPSTO-6
SEMIS DW $+2
MOV SI,[BP] ;(IP) <- (R1)
INC BP
INC BP ;ADJUST STACK
JMP NEXT
;
; LEAVE
;
DB 85H
DB 'LEAV'
DB 'E'+80H
DW SEMIS-5
LLEAV DW $+2 ;LIMIT <- INDEX
MOV AX,[BP] ;GET INDEX
MOV [2+BP],AX ;STORE IT AT LIMIT
JMP NEXT
PAGE
;
; >R
;
DB 82H
DB '>'
DB 'R'+80H
DW LLEAV-8
TOR DW $+2 ; (R1) <- (S1)
POP BX ;GET STACK PARAMETER
DEC BP
DEC BP ;MOVE RETURN STACK DOWN
MOV [BP],BX ;ADD TO RETURN STACK
JMP NEXT
;
; R>
;
DB 82H
DB 'R'
DB '>'+80H
DW TOR-5
FROMR DW $+2 ;(S1) <- (R1)
MOV AX,[BP] ; GET RETURN STACK VALUE
INC BP ;DELETE FROM STACK
INC BP
JMP APUSH
;
; R
;
DB 81H
DB 'R'+80H
DW FROMR-5
RR DW IDO+2
PAGE
; 0=
;
DB 82H
DB '0'
DB '='+80H
DW RR-4
ZEQU DW $+2
POP AX
OR AX,AX ;DO TEST
MOV AX,1 ;TRUE
JZ ZEQU1 ;IT'S 0
DEC AX ;FALSE
ZEQU1: JMP APUSH
;
; 0<
;
DB 82H
DB '0'
DB '<'+80H
DW ZEQU-5
ZLESS DW $+2
POP AX
OR AX,AX ;SET FLAGS
MOV AX,1 ;TRUE
JS ZLESS1
DEC AX ;FALSE
ZLESS1: JMP APUSH
;
; +
;
DB 81H
DB '+'+80H
DW ZLESS-5
PLUS DW $+2 ;(S1) <- (S1) + (S2)
POP AX
POP BX
ADD AX,BX
JMP APUSH
PAGE
; D+
;
; XLW XHW YLW YHW --> SLW SHW
; S4 S3 S2 S1 S2 S1
;
DB 82H
DB 'D'
DB '+'+80H
DW PLUS-4
DPLUS DW $+2
POP AX ; YHW
POP DX ; YLW
POP BX ; XHW
POP CX ; XLW
ADD DX,CX ; SLW
ADC AX,BX ; SHW
JMP DPUSH
;
; MINUS
;
DB 85H
DB 'MINU'
DB 'S'+80H
DW DPLUS-5
MINUS DW $+2
POP AX
NEG AX
JMP APUSH
;
; DMINUS
;
DB 86H
DB 'DMINU'
DB 'S'+80H
DW MINUS-8
DMINU DW $+2
POP BX
POP CX
SUB AX,AX
MOV DX,AX
SUB DX,CX ; MAKE 2'S COMPLEMENT
SBB AX,BX ; HIGH WORD
JMP DPUSH
PAGE
;
; OVER
;
DB 84H
DB 'OVE'
DB 'R'+80H
DW DMINU-9
OVER DW $+2
POP DX
POP AX
PUSH AX
JMP DPUSH
;
; DROP
;
DB 84H
DB 'DRO'
DB 'P'+80H
DW OVER-7
DROP DW $+2
POP AX
JMP NEXT
;
; SWAP
;
DB 84H
DB 'SWA'
DB 'P'+80H
DW DROP-7
SWAP DW $+2
POP DX
POP AX
JMP DPUSH
;
; DUP
;
DB 83H
DB 'DU'
DB 'P'+80H
DW SWAP-7
DUPE DW $+2
POP AX
PUSH AX
JMP APUSH
PAGE
; 2DUP
;
DB 84H
DB '2DU'
DB 'P'+80H
DW DUPE-6
TDUP DW $+2
POP AX
POP DX
PUSH DX
PUSH AX
JMP DPUSH
;
; +!
;
DB 82H
DB '+'
DB '!'+80H
DW TDUP-7
PSTOR DW $+2
POP BX ;ADDRESS
POP AX ;INCREMENT
ADD [BX],AX
JMP NEXT
;
; TOGGLE
;
DB 86H
DB 'TOGGL'
DB 'E'+80H
DW PSTOR-5
TOGGL DW $+2
POP AX ;BIT PATTERN
POP BX ;ADDR
XOR [BX],AL ;
JMP NEXT
;
; @
;
DB 81H
DB '@'+80H
DW TOGGL-9
FETCH DW $+2
POP BX
MOV AX,[BX]
JMP APUSH
PAGE
; C@
;
DB 82H
DB 'C'
DB '@'+80H
DW FETCH-4
CAT DW $+2
POP BX
MOV AL,[BX]
SUB AH,AH
JMP APUSH
;
; 2@
;
DB 82H
DB '2'
DB '@'+80H
DW CAT-5
TAT DW $+2
POP BX ;ADDR
MOV AX,[BX] ;MSW
MOV DX,[2+BX] ;LSW
JMP DPUSH
;
; !
;
DB 81H
DB '!'+80H
DW TAT-5
STORE DW $+2
POP BX ;ADDR
POP AX ;DATA
MOV [BX],AX
JMP NEXT
;
; C!
;
DB 82H
DB 'C'
DB '!'+80H
DW STORE-4
CSTOR DW $+2
POP BX ;ADDR
POP AX ;DATA
MOV [BX],AL
JMP NEXT
;
; 2!
;
DB 82H
DB '2'
DB '!'+80H
DW CSTOR-5
TSTOR DW $+2
POP BX ;ADDR
POP AX ;MSW
MOV [BX],AX
POP AX ;LSW
MOV [2+BX],AX
JMP NEXT
;
; L@
;
DB 82H ;( SEG# IP -- N )