home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / lambda / soundpot / f / figforth.lbr / FORTH.DZC / FORTH.DOC
Encoding:
Text File  |  1993-10-26  |  11.3 KB  |  264 lines

  1. This documentation describes the extensions to FORTH which make up 
  2. KFORTH. If you are not familiar with the FORTH language you will 
  3. need to get a book to describe the structure, syntax, and vocabulary
  4. of the language. A very popular beginning FORTH book is:
  5.  
  6.         Starting FORTH
  7.          By Leo Brodie
  8.         Prentice-Hall 1981
  9.  
  10. The book will teach you the basics of FORTH. This documentation provides
  11. you with the information to use this version of FORTH which we call
  12. KFORTH.
  13.  
  14. A Few Words About Forth
  15.  
  16. To start FORTH you run the KFORTH.COM file just as any other .COM file
  17. by typing KFORTH <carriage return>. To get out of FORTH type BYE <CR>.
  18.  
  19. FORTH does not create or use standard CP/M files as you are used to seeing.
  20. In FORTH the "file" you work with is called a screen. KFORTH provides you
  21. with 150 screens per disk which are kept within a 150 K CP/M file called
  22. FORTH.SCR. This allows you to put CP/M files on the remainder of the disk
  23. without getting into your FORTH workspace.
  24.  
  25. It is possible to create a file FORTH.SCR which is less than 150 K. You 
  26. should avoid this since KFORTH expects to have the full 150 K available
  27. and will try to read your CP/M files as if they were a FORTH screen. It is 
  28. easy to avoid this by creating a screen or having a FORTH.SCR file on the
  29. disk with KFORTH.COM. To create a 150 K FORTH.SCR on a blank, formatted
  30. disk use the FORTH extension MAKE-NEW described below. Or you can use an
  31. existing FORTH.SCR like the one on this disk. The way you get into trouble
  32. is when you run KFORTH.COM on a disk that has no FORTH.SCR or use the  
  33. FORTH extension BACK-UP-DISK (described below) without have an empty
  34. FORTH.SCR in drive B. In either of these cases, KFORTH just builds a 
  35. file FORTH.SCR but only reserves the blocks it needs. Then if you PIP 
  36. CP/M files onto that disk they may fill in the unreserved blocks. The 
  37. next time you use KFORTH, it expects to be able to use all of its 150 K
  38. workspace even though it never reserved it. If you LIST a screen that
  39. has a CP/M file residing in its place, well, thats when things get weird.
  40.  
  41. It is also a good idea if you are new at FORTH, not to put a disk in drive
  42. B with CP/M files on it unless there is a FORTH.SCR on it as well.
  43.  
  44. _____________________________________________________________________________
  45. FORTH.COM--------------------------------------------------------------------
  46.  
  47. This is the fig-FORTH kernel. It was written in assembly language and 
  48. provides the interpreting core to make it possible to write in FORTH.
  49. In addition to the source for the
  50. kernel we will also include any extensions to our KFORTH that are submitted 
  51. as they come in (or until the disk is full).
  52.  
  53. FORTH.COM is the core of KFORTH.COM. You may extend the FORTH.COM to become
  54. KFORTH.COM by using the FORTH screens on this disk in the file FORTH.SCR. 
  55.  
  56. To do this use PIP to transfer FORTH.COM and FORTH.SCR to another disk
  57. (blank and formatted). Then use SYSGEN.COM to put your system tracks on
  58. this disk as well. Now place this disk in drive A and hit the reset
  59. button. Once you get the system prompt ( A> ), type in FORTH and a 
  60. carriage return. FORTH will ask you for the date and you may respond or
  61. answer with a carriage return. Then type in 50 LOAD (must be uppercase)
  62. and a carriage return. This will cause FORTH to load into memory an 
  63. executable version of the extensions. It will display the first line of
  64. each screen that it loads. After it has loaded about half of the extensions
  65. it will type to the screen:
  66.  
  67.         ENTER YOUR INITIALS IN THREE LETTERS
  68.  
  69. and wait for you to do so. This will customize your editor so that it will
  70. put your initials on the first line of the FORTH screen whenever you edit.
  71.  
  72. After you do this FORTH will load the rest of the extensions. Finally 
  73. FORTH will return control to you and give you the OK prompt. Exit FORTH
  74. by entering:
  75.  
  76.         BYE<carriage return>
  77.  
  78. Forth will then respond with:
  79.  
  80.         Forth is 61 Records Long
  81.         LEAVING FORTH Have A Nice Day
  82.  
  83. The number of records is the number of 256 byte pages of memory that FORTH
  84. now occupies with all of its extensions. But the extended version of FORTH
  85. is still in memory! To save it on disk as a .COM file you must now enter:
  86.  
  87.         SAVE 61 KFORTH.COM<carriage return>
  88.  
  89. You now have a file on that disk which is identical to KFORTH.COM on this
  90. distribution disk but now it will leave your initials in a screen that you
  91. edit instead of BOB.
  92.  
  93. _____________________________________________________________________________
  94. FORTH.SCR--------------------------------------------------------------------
  95.  
  96. This file contains the screens that have the source for the FORTH extensions.
  97. Some of the extensions are in the vocabulary of KFORTH and others have to be
  98. LOADed before they may be used. First lets look at the "built-in" extensions.
  99.  
  100. STATUS
  101.  
  102. The line of text at the top of the CRT when you are in KFORTH is due to this
  103. extension. STATUS shows you the contents of the stack, the number base you
  104. are working in, and the vocabulary you are working in. Screen 16.
  105.  
  106. WHERE
  107.  
  108. This extension will find an error in compilation and underline it. Screen 17.
  109.  
  110. OOPS ERR
  111.  
  112. ERR replaces the standard FORTH word ERROR and uses WHERE to find and
  113. underline a mistake. OOPS puts you in the EDITOR and positions the cursor
  114. at the mistake. Screen 18.
  115.  
  116. PATCH
  117.  
  118. This extension allows you to redefine a word without having to re-compile.
  119. Puts a call to the new word at the beginning of the old word. Screen 13.
  120.  
  121. CP/M
  122.  
  123. This extension has some utilities to allow you to make a CP/M file on disk
  124. B. Screens 25-27.
  125.  
  126. SCREEN-ORIENTED EDITOR
  127.  
  128. The screen editor is loaded into the KFORTH vocabulary. It is very easy to
  129. use once you get started. The source for this editor is in screens 61-97.
  130. To use the screen editor you enter the number of the screen you wish to
  131. edit followed by an E. For example
  132.  
  133. 100 E              will edit screen 100 (empty on this disk)
  134.  
  135. If you enter that when you are in KFORTH it will display it on the screen
  136. after it pulls it from the disk. You are now in the editor. A ^Q will
  137. display the HELP screen which shows you the keypad usage map. The cursor 
  138. control (arrow) keys will move you about the screen and you may edit text
  139. as you please. To exit either choose exit with no update of the disk file
  140. or exit and write to disk (^Q to see the HELP screen). After you exit the
  141. editor the screen will not be written out to disk until you (or a FORTH
  142. utility) FLUSH the buffer. (Enter FLUSH just to make sure). If you did
  143. the editor customization above the next time you view the screen you just
  144. edited your initials and today's date should be on the first line of the
  145. screen. 
  146.  
  147. The editor also has some FORTH words to re-direct the output while you
  148. are in FORTH. These are:
  149.  
  150.     PRINTER-ENABLE -- send the output to the printer instead of the CRT
  151.     CRT-ENABLE -- un-does the above (output goes to CRT)
  152.     BOTH-ENABLE -- output to printer and CRT
  153.  
  154.     PRINTER-EMIT -- same as EMIT but to printer
  155.     BOTH-EMIT -- EMIT to CRT and printer
  156.  
  157. The ASSEMBLER
  158.  
  159. The assembler is an 8080 assembler and is on screens 108-114. This allows
  160. you to enter and include 8080 mnemonics in your FORTH programs. The assembler
  161. works as a standard FORTH assembler does. All code entry must be in reverse
  162. polish notation. The code segment should start with the FORTH word CODE
  163. and end with C; (another FORTH word). An example segment would be:
  164.  
  165. CODE BOP H POP, H PUSH, H PUSH, H PUSH, NEXT, C;
  166.   ^   ^    ^       ^       ^       ^     ^    ^
  167.   |   |    |       |       |       |     |    |___________end code segment
  168.   |   |    |       |       |       |     |___________return to interpreter
  169.   |   |    |       |       |       |________________push H and L registers
  170.   |   |    |       |       |________________________push H and L registers
  171.   |   |    |       |________________________________push H and L registers
  172.   |   |    |________________________________________pop  H and L registers
  173.   |   |_________________________________________name for this code segment  
  174.   |_____________________________________________________begin code segment
  175.   
  176. This section of code (BOP by name) duplicates the top stack item twice. To
  177. test this in KFORTH enter the line above (don't forget the commas after the
  178. instructions). The assembler will create the word BOP and put it in your
  179. dictionary (type VLIST to confirm this). Then put a number on the stack
  180. (by typing the number and a carriage return) and then type BOP.
  181.  
  182. Look at the contents of your stack. The number you entered should now be 
  183. there three times.
  184.  
  185. DECOMPILER
  186.  
  187. The decompiler source is in screens 102-106. It allows you to decompile
  188. FORTH words that you do not have the source for.
  189.  
  190. As an example you could decompile the FORTH word LIST. To do this you
  191. would enter:
  192.  
  193.         GOESINTO LIST <carriage return>
  194.  
  195. Now each time you hit the space bar you will get the next FORTH word used
  196. by LIST. If you see one of these FORTH words (say PAGE) and want to 
  197. decompile it you may hit the carriage return and the decompiler will work
  198. on that word, showing you the lower FORTH words that make up that word.
  199.  
  200. To exit the decompiling session just hit the space bar until the 
  201. decompilation is complete.
  202.  
  203. NUMBER-BASE 
  204.  
  205. When KFORTH begins the number base is set to DECIMAL. You may choose three
  206. other bases to use, HEX, BINARY, or OCTAL. Entering any of these words will
  207. change the number base you are working in. The base you are presently in is
  208. displayed at the top of the screen by STATUS.
  209.  
  210. _____________________________________________________________________________
  211. Extensions Which Are Not Loaded Into KFORTH.COM------------------------------
  212.  
  213. There are some other FORTH extensions in these screens that are not loaded
  214. to become part of the KFORTH.COM file. To use these utilities you must load
  215. them into memory by using the LOAD command. To do this type in the number
  216. of the screen where it is located followed by a space and the word LOAD. 
  217. Then you may type in the FORTH word and it will execute.
  218.  
  219. Screen #32   LOG 
  220.  
  221. This word will copy what is on the CRT into a CP/M file on drive B called
  222. FORTH.LOG. It will begin copying when you type START-LOG and stop when
  223. you type END-LOG. It does not terminate lines with a carriage return/
  224. line feed, only a carriage return. If you would want to make a file record
  225. of the words in your FORTH dictionary enter:
  226.  
  227.             32 LOAD
  228.             START-LOG
  229.             VLIST
  230.             END-LOG
  231.  
  232. Screen #33   BACK-UP-DISK 
  233.  
  234. This word will copy any screen with something written in the first line
  235. to drive B. Backs up all screens. You should have a FORTH.SCR with all
  236. screens empty in drive B.
  237.  
  238. To use enter:        33 LOAD
  239.             BACK-UP-DISK
  240.  
  241. Screen #34   TRIAD-THRU 
  242.  
  243. Use this word to list screens in groups of three followed by a form-feed.
  244. If you want it to go to the printer, don't forget to type PRINTER-ENABLE
  245. first. You need to type a beginning screen # and an ending screen #.
  246. To list screens 30-35 to the printer enter:
  247.  
  248.             34 LOAD
  249.             PRINTER-ENABLE
  250.             30 35 TRIAD-THRU
  251.  
  252. Screen #40   MAKE-NEW
  253.  
  254. This constructs the CP/M file FORTH.SCR with empty screens. Place a blank
  255. formatted disk in drive B and enter:
  256.  
  257.             40 LOAD
  258.             MAKE-NEW
  259.  
  260. Do this before using BACK-UP-DISK or any time you need a new FORTH 
  261. workspace. Place KFORTH.COM on a disk with this new FORTH.SCR and start
  262. FORTH with a new slate.
  263.  
  264.