forked from ptorric/figforth
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfiginst.txt
5474 lines (3497 loc) · 187 KB
/
figinst.txt
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
fig-FORTH
INSTALLATION MANUAL
GLOSSARY
MODEL
EDITOR
RELEASE 1
WITH COMPILER SECURITY
AND
VARIABLE LENGTH NAMES
BY
WILLIAM F. RAGSDALE
November 1980
Provided through the courtesy of the FORTH INTEREST GROUP, PO Box
1105, San Carlos, CA 94070
Further distribution of this public domain publication must include
this notice.
fig-FORTH INSTALLATION MANUAL
1.0 INTRODUCTION
2.0 DISTRIBUTION
3.0 MODEL ORGANIZATION
4.0 INSTALLATION
5.0 MEMORY MAP
6.0 DOCUMENTATION SUMMARY
1.0 INTRODUCTION
The fig-FORTH implementation project occurred because a key group of
Forth fanciers wished to make this valuable tool available on a
personal computing level. In June of 1978, we gathered a team of
nine systems level programmers, each with a particular target
computer. The charter of the group was to translate a common model
of Forth into assembly language listings for each computer. It was
agreed that the group's work would be distributed in the public
domain by FIG. This publication series is the conclusion of the
work.
2.0 DISTRIBUTION
All publications of the Forth Interest Group are public domain.
They may be further reproduced and distributed by inclusion of this
credit notice:
This publication has been made available
by the Forth Interest Group,
P. O. box 1105, San Carlos, CA 94070
We intend that our primary recipients of the Implementation Project
be computer users groups, libraries, and commercial vendors. We
expect that each will further customize for particular computers and
redistribute. No restrictions are placed on cost, but we expect
faithfulness to the model. FIG does not intend to distribute
machine readable versions, as that entails customization, revision,
and customer support better reserved for commercial vendors. Of
course, another broad group of recipients of the work is the
community of personal computer users. We hope that our publications
will aid in the use of Forth and increase the user expectation of
the performance of high level computer languages.
1
3.0 MODEL ORGANIZATION
The fig-FORTH model deviates a bit from the usual loading method of
Forth. Existing systems load about 2k bytes in object form and then
self-compile the resident system (6 to 8 k bytes). This technique
allows customization within the high level portion, but is
impractical for new implementors.
Our model has 4 to 5 k bytes written as assembler listings. The
remainder may be compiled typing in the Forth high-level source, by
more assembly source, or by disc compilation. This method enhances
transportability, although the larger portion in assembly code
entails more effort. About 8k bytes of memory is used plus 2 to 8k
for workspace.
3.1 MODEL OVER-VIEW
The model consists of 7 distinct areas. They occur sequentially
from low memory to high.
Boot-up parameters
Machine code definitions
High level utility definitions
Installation dependent code
High level definitions
System tools (optional)
RAM memory workspace
3.2 MODEL DETAILS
Boot-up Parameters
This area consists of 34 bytes containing a jump to the cold start,
jump to the warm re-start and initial values for user variables and
registers. These values are altered as you make permanent
extensions to your installation.
Machine Code Definitions
This area consists of about 600 to 800 bytes of machine executable
code in the form of Forth word definitions. Its purpose is to
convert your computer into a standard Forth stack computer. Above
this code, the balance of Forth contains a pseudo-code compiled of
"execution-addresses" which are sequences of the machine address of
the "code-fields" of other Forth definitions. All execution
ultimately refers to the machine code definitions.
2
High-level Utility Definitions
These are colon-definitions, user variables, constants, and
variables that allow you to control the "Forth stack computer".
They comprise the bulk of the system, enabling you to execute and
compile from the terminal. If disc storage (or a RAM simulation of
disc) is available, you may also execute and compile from this
facility. Changes in the high-level area are infrequent. They may
be made thru the assembler source listings.
Installation Dependent Code
This area is the only portion that need change between different
installations of the same computer cpu. There are four code
fragments:
(KEY) Push the next ascii value (7 bits) from the terminal
keystroke to the computation stack and execute NEXT. High 9
bits are zero. Do not echo this character, especially a
control character.
(EMIT) Pop the computation stack (16 bit value). Display the
low 7 bits on the terminal device, then execute NEXT. Control
characters have their natural functions.
(?TERMINAL) For terminals with a break key, wait till released
and push to the computation stack 0001 if it was found
depressed; otherwise 0000. Execute NEXT. If no break key is
available, sense any key depression as a break (sense but don't
wait for a key). If both the above are unavailable, simply
push 0000 and execute NEXT.
(CR) Execute a terminal carriage return and line feed. Execute
NEXT.
When each of these words is executed, the interpreter vectors from
the definition header to these code sequences. On specific
implementations it may be necessary to preserve certain registers
and observe operating system protocols. Understand the implementors
methods in the listing before proceeding!
R/W This colon-definition is the standard linkage to your
disc. It requests the read or write of a disc sector. It
usually requires supporting code definitions. It may consist
of self-contained code or call ROM monitor code. When R/W is
assembled, its code field address is inserted once in BLOCK and
once in BUFFER.
An alternate version of R/W is included that simulates disc
storage in RAM. If you have over 16 k bytes this is practical
for startup and limited operation with cassette.
3
High-level Definitions
The next section contains about 30 definitions involving user
interaction: compiling aids, finding, forgetting, listing, and
number formatting. These definitions are placed above the
installation dependent code to facilitate modification. That is,
once your full system is up, you may FORGET part of the high-level
and re-compile altered definitions from disc.
System Tools
A text editor and machine code assembler are normally resident. We
are including a sample editor, and hope to provide Forth assemblers.
The editor is compiled from the terminal the first time, and then
used to place the editor and assembler source code on disc.
It is essential that you regard the assembly listing as just a way
to get Forth installed on your system. Additions and changes must
be planned and tested at the usual Forth high level and then the
assembly routines updated. Forth work planned and executed only at
an assembly level tends to be non-portable, and confusing.
RAM Workspace
For a single user system, at least 2k bytes must be available above
the compiled system (the dictionary). A 16k byte total system is
most typical.
The RAM workspace contains the computation and return stacks, user
area, terminal input buffer, disc buffer and compilation space for
the dictionary.
4.0 INSTALLATION
We see the following methods of getting a functioning fig-FORTH
system:
1. Buy loadable object code from a vendor who has customized.
2. Obtain an assembly listing with the installation dependent code
supplied by the vendor. Assemble and execute.
3. Edit the FIG assembly listing on your system, re-write the I-O
routines, and assemble.
4. Load someone else's object code up to the installation dependent
code. Hand assemble equivalents for your system and poke in
with your monitor. Begin execution and type in (self-compile)
the rest of the system. This takes about two hours once you
understand the structure of Forth (but that will take much more
time!).
4
Let us examine Step 3, above, in fuller detail. If you wish to
bring up Forth only from this model, here are the sequential steps:
4.1 Familiarize yourself with the model written in Forth, the
glossary, and specific assembly listings.
4.2 Edit the assembly listings into your system. Set the boot-up
parameters at origin offset 0A, 0B (bytes) to 0000
(warning=00).
4.3 Alter the terminal support code (KEY, EMIT, etc,) to match your
system. Observe register protocol specific to your
implementation!
4.4 Place a break to your monitor at the end of NEXT, just before
indirectly jumping via register W to execution. W is the Forth
name for the register holding a code field address, and may be
differently referenced in your listings.
4.5 Enter the cold start at the origin. Upon the break, check that
the interpretive pointer IP points within ABORT and W points to
SP!. If COLD is a colon-definition, then the IP has been
initialized on the way to NEXT and your testing will begin in
COLD. The purpose of COLD is to initialize IP, SP, RP, UP, and
some user variables from the start-up parameters at the origin.
4.6 Continue execution one word at a time. Clever individuals
could write a simple trace routine to print IP, W, SP, RP and
the top of the stacks. Run in this single step mode until the
greeting message is printed. Note that the interpretation is
several hundred cycles to this stage!
4.7 Execution errors may be localized by observing the above
pointers when a crash occurs.
4.8 After the word QUIT is executed (incrementally), and you can
input a "return" key and get OK printed, remove the break. You
may have some remaining errors, but a reset and examination of
the above registers will again localize problems.
4.9 When the system is interpreting from the keyboard, execute
EMPTY-BUFFERS to clear the disc buffer area. You may test the
disc access by typing: 0 BLOCK 64 TYPE
This should bring sector zero from the disc to a buffer and
type the first 64 characters. This sector usually contains
ascii text of the disc directory. If BLOCK (and R/W) doesn't
function--happy hunting!
5.0 If your disc driver differs from the assembly version, you must
create your own R/W. This word does a range check (with error
message), modulo math to derive sector, track, and drive and
passes values to a sector-read and sector-write routine.
5
RAM DISC SIMULATION
If disc is not available, a simulation of BLOCK and BUFFER may be
made in RAM. The following definitions setup high memory as mass
storage. Referenced 'screens' are then brought to the 'disc buffer'
area. This is a good method to test the start-up program even if
disc may be available.
HEX
4000 CONSTANT LO ( START OF BUFFER AREA )
6800 CONSTANT HI ( 10 SCREEN EQUIVALENT )
: R/W >R ( save boolean )
B/BUF * LO + DUP
HI > 6 ?ERROR ( range check )
R> IF ( read ) SWAP ENDIF
B/BUF CMOVE ;
Insert the code field address of R/W into BLOCK and BUFFER and
proceed as if testing disc. R/W simulates screens 0 thru 9 when
B/BUF is 128, in the memory area $4000 thru $6BFF.
fig-FORTH VARIABLE NAME FIELD
A major FIG innovation in this model, is the introduction of
variable length definition names in compiled dictionary entries.
Previous methods only saved three letters and the character count.
The user may select the letter count saved, up to the full natural
length. See the glossary definition for WIDTH.
In this model, the following conventions have been established.
1. The first byte of the name field has the natural character count
in the low 5 bits.
2. The sixth bit = 1 when smudged, and will prevent a match by
(FIND).
3. The seventh bit = 1 for IMMEDIATE definitions; it is called the
precedence bit.
4. The eighth or sign bit is always = 1.
5. The following bytes contain the names' letters, up to the value
in WIDTH.
6. In the byte containing the last letter saved, the sign bit = 1.
7. In word addressing computer, a name may be padded with a blank to
a word boundary.
6
The above methods are implemented in CREATE. Remember that -FIND
uses BL WORD to bring the next text to HERE with the count
preceding. All that is necessary, is to limit by WIDTH and toggle
the proper delimiting bits.
5.0 MEMORY MAP
The following memory map is broadly used. Specific installations may
require alterations but you may forfeit functions in future FIG
offerings.
The disc buffer area is at the upper bound of RAM memory. It is
comprised of an integral number of buffers, each B/BUF+4 bytes.
B/BUF is the number of bytes read from the disc, usually one sector.
B/BUF must be a power of two (64, 128, 256, 512 or 1024). The
constant FIRST has the value of the address of the start of the
first buffer. LIMIT has the value of the first address beyond the
top buffer. The distance between FIRST and LIMIT must be
N*(B/BUF+4) bytes. This N must be two or more.
Constant B/SCR has the value of the number of buffers per screen;
i.e. 1024 / B/BUF.
The user area must be at least 34 bytes; 48 is more appropriate. In
a multi-user system, each user has his own user area, for his copy
of system variables. This method allows re-entrant use of the Forth
vocabulary.
The terminal input buffer is decimal 80 bytes (the hex 50 in QUERY)
plus 2 at the end. If a different value is desired, change the
limit in QUERY. A parameter in the boot-up literals locates the
address of this area for TIB. The backspace character is also in
the boot-up origin parameters. It is universally expected that
"rubout" is the backspace.
The return stack grows downward from the user area toward the
terminal buffer. Forty-eight bytes are sufficient. The origin is
in R0 (R-zero) and is loaded from a boot-up literal.
The computation stack grows downward from the terminal buffer toward
the dictionary, which grows upward. The origin of the stack is in
variable S0 (S-zero) and is loaded from a boot-up literal.
After a cold start, the user variables contain the addresses of the
above memory assignments. An advanced user may relocate while the
system is running. A newcomer should alter the startup literals and
execute COLD. The word +ORIGIN is provided for this purpose.
+ORIGIN gives the address byte or word relative to the origin
depending on the computer addressing method. To change the
backspace to control H type:
HEX 08 0E +ORIGIN ! ( byte addresses)
7
6.0 DOCUMENTATION SUMMARY
The following manuals are in print:
Caltech FORTH Manual, an advanced manual with internal details of
Forth. Has some implementation peculiarities. Approx. $6.50 from
the Caltech Book Store, Pasadena, CA.
Kitt Peak Forth Primer, $20.00 postpaid from the Forth Interest
Group, P.O. Box 1105, San Carlos, CA 94070.
microFORTH Primer, $15.00 Forth, Inc. 815 Manhattan Ave. Manhattan
Beach, CA 90266
Forth Dimensions, newsletter of the Forth Interest Group, $5.00 for
6 issues including membership. F.I.G. P.O. Box 1105 San Carlos, CA.
94070
8
STANDARD
fig-FORTH MEMORY MAP
LIMIT ---> +----------------------------------+ <--- USE
| |
| DISC BUFFERS |
| |
FIRST ---> +----------------------------------+ <--- PREV
+----------------------------------+
| |
| USER AREA |
| |
UP ---> +----------------------------------+
R0 ---> +----------------------------------+
| | \
| RETURN STACK | \
| | ^ | \ IN
| v | | /
| TERMINAL BUFFER | /
| | /
RP ---> +----------------------------------+ <--- TIB
S0 ---> +----------------------------------+
| | |
| | STACK |
| v |
SP ---> +----------------------------------+
+----------------------------------+
| |
| TEXT BUFFER |
| |
+----------------------------------+ <--- PAD
"WORD" BUFFER
DP ---> +----------------------------------+
| |
| DICTIONARY |
| |
+----------------------------------+
+----------------------------------+
| |
| BOOT-UP LITERALS |
| |
+----------------------------------+ <--- 0 +ORIGIN
9
6502
fig-FORTH MEMORY MAP
LIMIT ---> +----------------------------------+ <--- USE
| |
| DISC BUFFERS |
| |
FIRST ---> +----------------------------------+ <--- PREV
+----------------------------------+
| |
| USER AREA |
| |
UP ---> +----------------------------------+
+----------------------------------+
| |
| TEXT BUFFER |
| |
+----------------------------------+ <--- PAD
"WORD" BUFFER
DP ---> +----------------------------------+
| |
| DICTIONARY |
| |
| -------------------------------- |
| |
$200 | BOOT-UP LITERALS |
| |
+----------------------------------+ <--- 0 +ORIGIN
$01FF ---> +----------------------------------+
R0 | | \
| RETURN STACK | \
| | ^ | \ IN
| V | | /
RP ---> | TERMINAL BUFFER | /
| | /
$0100 ---> +----------------------------------+ <--- TIB
+----------------------------------+
| |
Z-PAGE | UP N IP W |
| |
+----------------------------------+
S0 ---> +----------------------------------+ SP IS X REGISTER
| | | RP IS STACK POINTER
| | STACK | OF CPU
| | $009F - $0010 |
| v |
SP ---> +----------------------------------+
10
fig-FORTH GLOSSARY
This glossary contains all of the word definitions in Release 1 of
fig-FORTH. The definitions are present in order of their ascii
sort.
The first line of each entry shows a symbolic description of the
action of the procedure on the parameter stack. The symbols
indicate the order in which input parameters have been placed on the
stack. The three dashes "---" indicate the execution point; any
parameters left on the stack are listed. In this notation, the top
of the stack is to the right.
The symbols include:
addr memory address
b 8 bit byte (ie. hi 8 bits zero)
c 7 bit ascii character (hi 9 bits zero)
d 32 bit signed double integer, most significant portion
with sign on top of stack.
f boolean flag. 0=false, non-zero=true
ff boolean false flag=0
n 16 bit signed integer number
u 16 bit unsigned integer
tf boolean true flag=non zero
The capital letters on the right show definition characteristics:
C May only be used within a colon definition. A digit
indicates number of memory addresses used, if other than
one.
E Intended for execution only.
L0 Level Zero definition of FORTH-78
L1 Level One definition of FORTH-78
P Has precedence bit set. Will execute even when compiling.
U A user variable.
Unless otherwise noted, all references to numbers are for 16 bit
signed integers. On 8 bit data bus computers, the high byte of a
number is on top of the stack, with the sign in the leftmost bit.
For 32 bit signed double numbers, the most significant (with the
sign) is on top.
All arithmetic is implicitly 16 bit signed integer math, with error
and under-flow indication unspecified.
11
! n addr --- L0
Store 16 bits of n at address. Pronounced "store".
!CSP
Save the stack position in CSP. Used as part of the
compiler security.
# d1 --- d2 L0
Generate from a double number d1, the next ascii character
which is placed in an output string. Result d2 is the
quotient after division by BASE, and is maintained for
further processing. Used between <# and #>. See #S.
#> d --- addr count L0
Terminates numeric output conversion by dropping d,
leaving the text address and character count suitable for
TYPE.
#S d1 --- d2 L0
Generates ascii text in the text output buffer, by the use
of #, until a zero double number n2 results. Used between
<# and #>.
' --- addr P,L0
Used in the form:
' nnnn
Leaves the parameter field address of dictionary word
nnnn. As a compiler directive, executes in a colon
definition to compile the address as a literal. If the
word is not found after a search of CONTEXT and CURRENT,
an appropriate error message is given. Pronounced "tick".
( P,L0
Used in the form:
( cccc)
Ignore a comment that will be delimited by a right
parenthesis on the same line. May occur during execution
or in a colon-definition. A blank after the leading
parenthesis is required.
(.") C+
The run-time procedure, compiled by ." which transmits the
following in-line text to the selected output device. See
."
(;CODE) C
The run-time procedure, compiled by ;CODE, that rewrites
the code field of the most recently defined word to point
to the following machine code sequence. See ;CODE.
(+LOOP) n --- C2
The run-time procedure compiled by +LOOP, which increments
the loop index by n and tests for loop completion. See
+LOOP.
12
(ABORT)
Executes after an error when WARNING is -1. This word
normally executes ABORT, but may be altered (with care) to
a user's alternative procedure.
(DO) C
The run-time procedure compiled by DO which moves the loop
control parameters to the return stack. See DO.
(FIND) addr1 addr2 --- pfa b tf (ok)
addr1 addr2 --- ff (bad)
Searches the dictionary starting at the name field address
addr2, matching to the text at addr1. Returns parameter
field address, length byte of name field and boolean true
for a good match. If no match is found, only a boolean
false is left.
(LINE) n1 n2 --- addr count
Convert the line number n1 and the screen n2 to the disc
buffer address containing the data. A count of 64
indicates the full line text length.
(LOOP) C2
The run-time procedure compiled by LOOP which increments
the loop index and tests for loop completion. See LOOP.
(NUMBER) d1 addr1 --- d2 addr2
Convert the ascii text beginning at addr1+1 with regard to
BASE. The new value is accumulated into double number d1,
being left as d2. Addr2 is the address of the first
unconvertable digit. Used by NUMBER.
* n1 n2 --- prod L0
Leave the signed product of two signed numbers.
*/ n1 n2 n3 --- n4 L0
Leave the ratio n4 = n1*n2/n3 where all are signed
numbers. Retention of an intermediate 31 bit product
permits greater accuracy than would be available with the
sequence: n1 n2 * n3 /
*/MOD n1 n2 n3 --- n4 n5 L0
Leave the quotient n5 and remainder n4 of the operation
n1*n2/n3. A 31 bit intermediate product is used as for
*/.
+ n1 n2 --- sum L0
Leave the sum of n1+n2.
+! n addr --- L0
Add n to the value at the address. Pronounced "plus-
store".
13
+- n1 n2 --- n3
Apply the sign of n2 to n1, which is left as n3.
+BUF addr1 --- addr2 f
Advance the disc buffer address addr1 to the address of
the next buffer addr2. Boolean f is false when addr2 is
the buffer presently pointed to by variable PREV.