home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / FORTH / FIG_4TH.ZIP / 4THUG.DOC < prev    next >
Encoding:
Text File  |  1987-01-16  |  92.2 KB  |  2,149 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.                                 User's Guide for
  12.  
  13.  
  14.                               8086/8088 Fig-FORTH
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.                                   Release 1.0
  22.  
  23.                              With Compiler Security
  24.                                       and
  25.                              Variable Length Words
  26.  
  27.  
  28.                                    March 1981
  29.  
  30.  
  31.  
  32.                         ================================
  33.  
  34.  
  35.                       MS-DOS File Interface and Revisions
  36.  
  37.                                    July 1983
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.           This program and documentation are released  to  the  public
  45.           domain.  The FIG-FORTH listing  is  made  available  by  the
  46.           FORTH Interest Group, PO Box 1105, San Carlos, CA 94070
  47.  
  48.           Modified for MS-DOS and documented by J.E.   Smith,  U.   of
  49.           Penn./Dept.of  Chem,  Philadelphia,  PA   19104   (to   whom
  50.           inquiries should be directed). 
  51.  
  52.           Any  further  distribution  of  this  software  is  strictly
  53.           encouraged, as long as you don't get rich and  keep  it  all
  54.           for yourself. 
  55.  
  56.           If you modify this revised version  and  re-distribute  your
  57.           own version, it would be polite  to  notify  the  author  of
  58.           these  revisions,  and  to  take  responsibility  for   your
  59.           modifications.  
  60.           8086/8088 Fig-FORTH User's Guide                    Page   2
  61.  
  62.  
  63.  
  64.  
  65.  
  66.           1  QUICK REFERENCE 
  67.  
  68.           This is a summary of information necessary to use  FIG-FORTH
  69.           and it's documentation. 
  70.  
  71.  
  72.           1.1  System Requirements 
  73.  
  74.           FORTH requires the following system resources:
  75.  
  76.                 * an 8086 or 8088 CPU running MS-DOS version  1.10  or
  77.                   1.25
  78.  
  79.                 * 64K of available RAM, or about 100K total
  80.  
  81.                 * one or two disk drives
  82.  
  83.  
  84.  
  85.           1.2  Invocation 
  86.  
  87.           FORTH is started by typing the following in response to  the
  88.           COMMAND prompt. 
  89.  
  90.                   FORTH <commands>
  91.  
  92.           Where <commands> is an optional list of FORTH  words  to  be
  93.           executed. 
  94.  
  95.           FORTH normally uses a special disk.  To  use  MS-DOS  files,
  96.           the following commands are available:
  97.  
  98.                   A:                      selects drive A
  99.                   B:                      selects drive B
  100.                   DIR" <filename>"        lists matching file information
  101.                   FILES" <filename>"      lists matching file names
  102.                   USING" <filename>"      selects <filename> for screen access
  103.                   EOF                     closes current screen file
  104.                   LOAD" <filename>"       loads the screens in <filename>
  105.                   ERASE" <filename>"      erases any matching files
  106.  
  107.  
  108.           Note:   NEVER change any disk while  FORTH  is  using  a
  109.                   file on that  disk!   Study  the  section  below
  110.                   regarding disk operations. 
  111.  
  112.  
  113.           8086/8088 Fig-FORTH User's Guide                    Page   3
  114.  
  115.  
  116.  
  117.  
  118.  
  119.           1.3  Provided Documentation 
  120.  
  121.           This document contains three main sections:
  122.  
  123.                 * FORTH user's guide
  124.                   The user's guide tells you how to  use  the  special
  125.                   features in this version of FORTH. 
  126.  
  127.                 * FORTH technical reference
  128.                   The   technical   reference   contains   information
  129.                   regarding modifications and additions to  the  FORTH
  130.                   interpreter/compiler    relative    to    the    FIG
  131.                   implementation. 
  132.  
  133.                 * FORTH glossary
  134.                   This is a list and explanation of  each  FORTH  word
  135.                   which has been changed or added to this  version  of
  136.                   FORTH. 
  137.  
  138.  
  139.           8086/8088 Fig-FORTH User's Guide                    Page   4
  140.  
  141.  
  142.  
  143.  
  144.  
  145.           2  INTRODUCTION 
  146.  
  147.           This document describes changes and additions  to  FIG-FORTH
  148.           v1.0 which is distributed by the
  149.  
  150.                   FORTH Interest Group
  151.                   P.O. Box 1105
  152.                   San Carlos, CA 94070
  153.  
  154.           as modified to run under MS-DOS by
  155.  
  156.                   Joe Smith
  157.                   University of Pennsylvania
  158.                   Dept. of Chemistry
  159.                   250 S. 33rd St. 
  160.                   Philadelphia, PA 19104
  161.  
  162.           This  software  and  the   accompanying   documentation   is
  163.           available from
  164.  
  165.                   SIG/86
  166.                   c/o Joseph Boykin
  167.                   47-4 Sheridan Dr. 
  168.                   Shrewsbury, MA 01545
  169.  
  170.           This  version  of  FIG-FORTH  incorporates   a   number   of
  171.           significant changes to the FIG version.  The following is  a
  172.           partial list:
  173.  
  174.                 * written for Microsoft's MACRO-86 assembler
  175.  
  176.                 * full MS-DOS file interaction, as well as usual FORTH
  177.                   disk access
  178.  
  179.                 * all i/o is vectored and may  be  re-directed  within
  180.                   FORTH
  181.  
  182.                 * command line interpretation
  183.  
  184.  
  185.           Modifications   to   the   FIG-FORTH   implementation   were
  186.           undertaken to alleviate several problems.   First,  the  FIG
  187.           version is  for  CP/M-86.   Once  FORTH  was  running  under
  188.           MS-DOS,  the  lack  of  a   file   interface   soon   became
  189.           intolerable.   Also,  the  assembly   source   for   Seattle
  190.           Computer's assembler was not transportable to  other  MS-DOS
  191.           systems.  The translation to Microsoft's MACRO-86 was  begun
  192.           in January  of  1983  and  the  file  system  interface  was
  193.           completed the following June. 
  194.  
  195.           My original goal was to install a language for my  own  use.
  196.           That is still my primary concern.  Accordingly, this version
  197.           of the language is recommended for people who  are  familiar
  198.           with  their  computer,  and  (somewhat   less   importantly)
  199.           8086/8088 Fig-FORTH User's Guide                    Page   5
  200.  
  201.  
  202.  
  203.           familiar with FORTH.  If you are new to FORTH, you will have
  204.           to dig for some of the  basic  information.   (some  helpful
  205.           references are listed at the end of this guide).  If you are
  206.           a person who enjoys understanding  and  tinkering  with  the
  207.           mechanisms (read 'hacker') you should feel  right  at  home.
  208.           If you are an experienced FORTH wizard, you can tell me  all
  209.           the things I did wrong! 
  210.  
  211.           The author (J.E.S.) gratefully acknowledges the  efforts  of
  212.           the FORTH Interest Group in  providing  FORTH  source  code.
  213.           FORTH owes much of it's  popularity  to  the  work  of  this
  214.           organization, it was the first significant software  to  run
  215.           on my system (even before I had disks) and without them this
  216.           implementation would certainly not exist. 
  217.  
  218.           Also, special  thanks  to  Joseph  Boykin,  whose  TOP  text
  219.           processor formatted this document.  
  220.           8086/8088 Fig-FORTH User's Guide                    Page   6
  221.  
  222.  
  223.  
  224.  
  225.  
  226.           3  USER'S GUIDE 
  227.  
  228.           This documentation presents specific  details  necessary  to
  229.           use this version of FORTH under MS-DOS.  It is not a  user's
  230.           guide to FORTH in general.  Several introductory  references
  231.           are given at the end of this guide
  232.  
  233.  
  234.           3.1  System Requirements 
  235.  
  236.           The FORTH interpreter/compiler as distributed requires:
  237.  
  238.                 * an 8086/8088 computer running MS-DOS version 1.10 or
  239.                   1.25
  240.  
  241.                 * 64K of RAM, or 96K total,  including  the  operating
  242.                   system
  243.  
  244.                 * one or more disk drives
  245.  
  246.           These  requirements   may   be   changed   to   almost   any
  247.           configuration by changing options in the assembly source and
  248.           re-assembling.  This process requires:
  249.  
  250.                 * All of the above requirements, plus another  64K  of
  251.                   RAM, or 128K total (for MACRO-86)
  252.  
  253.                 * the MACRO-86 macro assembler, or it's equivalent
  254.  
  255.                 * the LINK-86 linker, or it's equivalent
  256.  
  257.                 * the EXE2BIN program to convert the linker output  to
  258.                   a .COM file
  259.  
  260.           See the section below, "Modifying FORTH", and the  technical
  261.           reference for further information.  
  262.           8086/8088 Fig-FORTH User's Guide                    Page   7
  263.  
  264.  
  265.  
  266.  
  267.  
  268.           3.2  FORTH, Calculator Style 
  269.  
  270.           The simplest mode of interaction with FORTH is  through  the
  271.           system console.  You type commands,  FORTH  interprets  them
  272.           and carries out your  orders;  much  the  same  as  using  a
  273.           powerful, programmable calculator. 
  274.  
  275.  
  276.           3.2.1  Getting Started 
  277.  
  278.           FORTH is invoked from MS-DOS by typing:
  279.  
  280.                   FORTH <optional command list>
  281.  
  282.           in response to COMMAND's prompt.  This will load and execute
  283.           the FORTH interpreter.  FORTH  will  initialize  itself  and
  284.           print a banner something like
  285.  
  286.                   8086 Fig-FORTH Version 1.1A
  287.  
  288.           Then, FORTH begins executing any commands you give  it.   If
  289.           there  was  anything  else  on  the   command   line,   i.e.
  290.           <command list> was present, FORTH attempts to interpret  it.
  291.           Thus, if you wanted to find out what 8086  is  in  hex,  you
  292.           could type:
  293.  
  294.                   A:FORTH 8086 HEX . BYE
  295.  
  296.           and FORTH would reply:
  297.  
  298.                   8086 Fig-FORTH Version 1.1A
  299.  
  300.                   1F96
  301.                   A:
  302.  
  303.           If nothing was passed on  the  command  line,  FORTH  simply
  304.           types a carriage return and waits for you.  The command list
  305.           is limited to a total of  80  characters.   If  you  type  a
  306.           carriage return at this point, FORTH should  respond:  "ok".
  307.           If it doesn't, you have a problem. 
  308.  
  309.  
  310.           3.2.2  Communicating With FORTH 
  311.  
  312.           Keyboard entries are  handled  by  the  FORTH  word  EXPECT.
  313.           EXPECT only recognizes two special keys: <DELETE> and  <CR>.
  314.           Any other key is presumed  to  be  a  valid  character.   No
  315.           MS-DOS editing functions are available.  The exact key which
  316.           FORTH recognizes as <DELETE> defaults to  ASCII  DEL.   This
  317.           may be easily changed to any other key.  The  section  below
  318.           on  modifying  FORTH  tells  how  to  change  the  backspace
  319.           character.  If you type <DELETE>,  EXPECT  will  delete  the
  320.           last character entered.  If you try to go past the beginning
  321.           of the line, the terminal should beep and leave  the  cursor
  322.           8086/8088 Fig-FORTH User's Guide                    Page   8
  323.  
  324.  
  325.  
  326.           in the first column. 
  327.  
  328.  
  329.           3.2.3  Special Functions 
  330.  
  331.           While no editing functions are provided, MS-DOS does respond
  332.           to some other special  keys.   Any  console  output  may  be
  333.           paused by typing ^S.  Printer output is toggled using ^P/^N.
  334.           Because MS-DOS intercepts these keys, FORTH will  never  see
  335.           them.  Another function, the interrupt key ^C, has  variable
  336.           effects.   Normally,  pressing  ^C  causes   the   currently
  337.           executing FORTH word to be interrupted.  Control  is  passed
  338.           to the FORTH word (ABORT) which usually aborts  the  current
  339.           word and  resets  the  interpreter.   This  process  may  be
  340.           changed to  provide  more  intelligent  interrupt  handling.
  341.           Refer to the last part of the technical reference section on
  342.           "Modifying FORTH" for more information. 
  343.  
  344.           There are a number of assembly options which may affect  the
  345.           exact  way  these  keys  are  handled.   See  the  technical
  346.           reference section entitled "installation dependent code" for
  347.           further information. 
  348.  
  349.  
  350.           3.2.4  New Definitions 
  351.  
  352.           One command FORTH accepts is the  colon  ":".   Colon  is  a
  353.           command to begin compiling  the  following  text  as  a  new
  354.           definition.  No "ok" will appear until you have successfully
  355.           completed your definition and ended it with a semicolon ";".
  356.           The definition may be spread out over as many lines  as  you
  357.           need, up to 80 characters on each line.   Until  you  end  a
  358.           line by typing <CR>, you may back up and  change  it.   Once
  359.           you go on to the next line, no editing is  possible.   FORTH
  360.           will make you aware of any errors in the definition.  If you
  361.           make a mistake, the whole definition must be entered again. 
  362.  
  363.           Try the following definition:
  364.  
  365.                : STAR 42 EMIT ;
  366.  
  367.           FORTH should respond "ok" after you hit  return.   Now  test
  368.           STAR by typing: STAR<CR>.  FORTH  should  print  "*ok".   If
  369.           that worked, try this one:
  370.  
  371.                : MILKY-WAY
  372.                  BEGIN
  373.                     STAR SPACE SPACE
  374.                     ?TERMINAL
  375.                  UNTIL ;
  376.  
  377.           Remember, no "ok" will  be  printed  until  you  finish  the
  378.           definition with  the  semicolon.   Any  leading  spaces  are
  379.           ignored.  Test MILKY-WAY as with STAR.  When you  get  tired
  380.           of star-gazing, stop the program by hitting  any  key.   The
  381.           stars  should  stop,  and  FORTH  should  inform  you   that
  382.           8086/8088 Fig-FORTH User's Guide                    Page   9
  383.  
  384.  
  385.  
  386.           everything is "ok".  You can also  pause  the  execution  of
  387.           MILKY-WAY using ^S, or abort it using ^C. 
  388.  
  389.           You can experiment with other definitions, but having no way
  390.           of modifying  the  functions  without  re-typing  them  soon
  391.           becomes a serious problem.  The next section  tells  how  to
  392.           edit and load definitions stored on your  disk.   Don't  try
  393.           any disk operations until you have read the next section. 
  394.  
  395.  
  396.           3.2.5  Exiting FORTH 
  397.  
  398.           To return to MS-DOS, say "BYE" to FORTH.  
  399.           8086/8088 Fig-FORTH User's Guide                    Page  10
  400.  
  401.  
  402.  
  403.  
  404.  
  405.           3.3  Using the Disk 
  406.  
  407.           Standard FORTH supports only  the  most  primitive  of  file
  408.           structures.  FORTH views the  disk  as  a  linear  array  of
  409.           blocks which may be accessed in any  order.   A  disk  block
  410.           formatted as 16 lines of 64 characters is called  a  screen.
  411.           In  the  standard  configuration,  FIG-FORTH  bypasses   the
  412.           operating system file structure.  This means that FORTH must
  413.           have a disk all to itself.  While there  are  advantages  to
  414.           this  arrangement  (no  directory  overhead,   simple   disk
  415.           interface,  portability  across   operating   systems,   for
  416.           instance),  it  is  often  inconvenient  that  FORTH  should
  417.           totally ignore it's host operating system's files. 
  418.  
  419.           To deal with this conflict, and yet  maintain  compatibility
  420.           with standard FORTH disk access,  the  FIG-FORTH  model  was
  421.           changed.  The words which do all disk access, BLOCK-READ and
  422.           BLOCK-WRITE, can now be assigned to any function.  Thus,  by
  423.           telling BLOCK-READ/WRITE to use a file instead of  the  disk
  424.           directly, all of the standard FORTH disk words will refer to
  425.           blocks of that file.  The user can easily switch between the
  426.           two modes, or use one exclusively.  Also, all of  the  usual
  427.           disk words will work on a file as  well  as  the  old  FORTH
  428.           disk. 
  429.  
  430.  
  431.           3.3.1  Creating and editing Definitions 
  432.  
  433.           There  are  three  editors  distributed  with  the  package.
  434.           Unfortunately, there isn't time or space to  describe  their
  435.           use  here.   All  are  described  elsewhere,  however.   The
  436.           editors provided include:
  437.  
  438.                 * two line-oriented editors: the  FORTH  Inc.   editor
  439.                   described in Leo Brodie's "STARTING FORTH"  and  the
  440.                   FIG   portable   editor   described   in   the   FIG
  441.                   installation manual. 
  442.  
  443.                 * a screen editor described  in  Dr.   Dobb's  Journal
  444.                   No. 59.  This editor is configured for the Televideo
  445.                   950 terminal, and must be  modified  for  any  other
  446.                   terminal. 
  447.  
  448.           Any of these may be used with either screen files  or  FORTH
  449.           disks.  All examples in this guide will refer to the  editor
  450.           described by Brodie, which has been compiled and included in
  451.           the FORTH.COM file. 
  452.  
  453.  
  454.           3.3.2  FORTH Disk Access 
  455.  
  456.           After a COLD start, any disk words will access a FORTH disk.
  457.           If you start FORTH and type "4 LIST",  it  assumes  you  are
  458.           asking to see the fourth disk block.  In this mode, all disk
  459.           8086/8088 Fig-FORTH User's Guide                    Page  11
  460.  
  461.  
  462.  
  463.           transfers bypass the file system.  The user  has  access  to
  464.           all blocks on the  disk,  and  if  more  than  one  disk  is
  465.           available, FORTH will treat them as one disk  of  twice  the
  466.           capacity. 
  467.  
  468.           Once you use a screen file, you must execute SWITCH  to  get
  469.           back to the FORTH disk.  This should remind you to  "switch"
  470.           your FIG-FORTH disk for the MS-DOS disk. 
  471.  
  472.           The disk interface allows you to use only one  format  at  a
  473.           time.   That  is,  FORTH  cannot  automatically   adapt   to
  474.           different  FORTH  disk  formats  the  way  MS-DOS  can.   By
  475.           changing the constants  that  describe  the  disk,  you  can
  476.           manually change formats to any supported by your i/o system. 
  477.  
  478.           To find what format FORTH expects, type
  479.  
  480.                   B/BUF REC/BLK / . 
  481.  
  482.           This gives the sector  size  in  bytes.   To  determine  the
  483.           capacity of the disk FORTH expects,  display  the  constants
  484.           BLK/DRIVE, MAXDRIVE, and MAXBLOCK. 
  485.  
  486.           The 8-inch format is 128 bytes/sector, 52 sectors/track,  77
  487.           tracks per disk.  The 5-inch disks are 512  bytes/sector,  8
  488.           sectors/track, 40 tracks per disk. 
  489.  
  490.  
  491.  
  492.           3.3.3  Screen File Access 
  493.  
  494.           This version of FORTH includes an interface  to  the  MS-DOS
  495.           file system.  The assembly source includes a low level  file
  496.           interface, but the higher level functions must  be  compiled
  497.           from a  FORTH  disk.   See  the  following  section  in  the
  498.           technical reference on "Modifying FORTH"  for  details.   In
  499.           order to switch from the FORTH disk to a screen file, type
  500.  
  501.                   USING" <filename>"
  502.  
  503.           where <filename> is any legal, unambiguous MS-DOS  filename.
  504.           FORTH will attempt to open the file and determine if it is a
  505.           file of FORTH screens.  If all goes well,  FORTH  will  tell
  506.           you how many blocks are available in that  file.   The  file
  507.           will look just like the disk to FORTH, except it's  capacity
  508.           will be smaller.  Screen files may not span disks.   If  the
  509.           specified file doesn't exist, FORTH will create it but  will
  510.           not  allocate  any  space  to  it.   The  following  example
  511.           demonstrates the screen file access words. 
  512.  
  513.           Start FORTH, and type
  514.  
  515.                   USING" TRYIT"
  516.  
  517.           FORTH will create a file named TRYIT.SCR and tell  you  that
  518.           the file is empty.  To use the file, you must allocate  some
  519.           8086/8088 Fig-FORTH User's Guide                    Page  12
  520.  
  521.  
  522.  
  523.           space to it.  This is done by entering
  524.  
  525.                   2 EXTEND
  526.  
  527.           EXTEND takes the number on the  stack  and  adds  that  many
  528.           blocks to the end of the screen file.   In  this  case,  the
  529.           file is now 0+2 or 2 screens long (screens 0 and 1).  If you
  530.           were to try and list screen 2, you would get an error.  Note
  531.           that EXTEND does not put anything in the screens  allocated;
  532.           they contain whatever the disk held previously, but now they
  533.           belong to your current screen file.  Clear a working  screen
  534.           by entering the editor and filling screen one with blanks:
  535.  
  536.                   1 SCR ! 
  537.                   EDITOR
  538.                   WIPE
  539.  
  540.           List the screen, select line 0, and enter some text:
  541.  
  542.                   L
  543.                   0 T
  544.                   P ( this is screen 0 line 1 in file TRYIT.SCR )
  545.                   L
  546.  
  547.           Use FLUSH to save the changes, then  type  "L"  again.   The
  548.           screen should be just as  you  left  it.   Try  editing  the
  549.           definitions for STAR and MILKY-WAY onto this  screen.   When
  550.           you finish editing, save it by typing
  551.  
  552.                   EOF
  553.  
  554.           (End Of File) to close the file.  EOF displays the directory
  555.           entry of your file to verify that  everything  is  allright.
  556.           If the file is empty, EOF will notify you and then erase the
  557.           file. 
  558.  
  559.           You are now in limbo as far as the disk  is  concerned.   If
  560.           you try to access the disk, FORTH will remind you to specify
  561.           which kind of disk access you want  to  do:  file  or  FORTH
  562.           disk.  To list the screen again, tell FORTH to use TRYIT.SCR
  563.           (USING" TRYIT").  Now FORTH should find a file with 2 blocks
  564.           in it.  And  if  you  list  screen  1,  you  will  see  your
  565.           definitions, just as  you  left  them.   If  you  need  more
  566.           screens, use  EXTEND  as  before  to  allocate  more  space.
  567.           Remember to WIPE the screen as it will probably be  full  of
  568.           nasty control characters for your terminal to choke on! 
  569.  
  570.           Why not use screen 0?  Well, FORTH can list  screen  0,  and
  571.           you can edit text there, but if you try "0 LOAD", FORTH will
  572.           get very confused.  When FORTH compiles block 0, it actually
  573.           compiles input from the console.   Thus,  block  0  of  each
  574.           screen file cannot be loaded (but, see the following section
  575.           for one use for screen 0). 
  576.  
  577.  
  578.           8086/8088 Fig-FORTH User's Guide                    Page  13
  579.  
  580.  
  581.  
  582.  
  583.  
  584.           3.3.4  Compiling Definitions 
  585.  
  586.  
  587.           As with editing, once you have opened a screen file, you can
  588.           proceed exactly as you would with a FORTH disk.  If you have
  589.           edited some definitions  onto  screen  1,  compile  them  by
  590.           typing 1 LOAD.  If FORTH says "ok", test them as before.  If
  591.           there is an error, edit the definitions and try again. 
  592.  
  593.           There is only one new word with  regard  to  loading  screen
  594.           files.  To make the process of selecting a screen  file  and
  595.           loading it more convenient, use. 
  596.  
  597.                   LOAD" <filename>"
  598.  
  599.           LOAD" opens  the  specified  file,  and  loads  the  screens
  600.           starting with screen one.  Since screen zero is just sitting
  601.           there with nothing to do, LOAD" lists  it  before  beginning
  602.           the load with screen one.  This is  a  good  place  for  any
  603.           special       messages,        advertisements,        secret
  604.           messages...whatever.  LOAD" is defined as simply:
  605.  
  606.                   : LOAD"
  607.                        USING"
  608.                        ( code to list screen 0 )
  609.                        1 LOAD
  610.                        EOF ;
  611.  
  612.           If an error is encountered during the LOAD, that  file  will
  613.           be the current screen file.  
  614.           8086/8088 Fig-FORTH User's Guide                    Page  14
  615.  
  616.  
  617.  
  618.  
  619.  
  620.           3.3.5  Other Functions 
  621.  
  622.           There are several utility functions defined which make FORTH
  623.           more convenient to use with the file  system.   These  words
  624.           apply only to MS-DOS disks and not to FORTH disks. 
  625.  
  626.  
  627.           3.3.5.1  changing the default drive 
  628.  
  629.           As in COMMAND, typing
  630.  
  631.                   A:
  632.           or
  633.                   B:
  634.  
  635.           will change the default drive for all file access. 
  636.  
  637.  
  638.           3.3.5.2  directory information 
  639.  
  640.           Several utilities are available for using MS-DOS disks.  Two
  641.           words which list the disk directory are defined:
  642.  
  643.                   DIR"   <filename>"
  644.                   FILES" <filename>"
  645.  
  646.           DIR" gives a complete directory  listing  of  each  matching
  647.           filename, similar to the MS-DOS DIR command.   FILES"  lists
  648.           only filenames, five  per  line,  much  as  the  MS-DOS  DIR
  649.           command with the "/W" option.  The exact  interpretation  of
  650.           ambiguous filenames differs from  COMMAND's.   The  filename
  651.           must not be blank,  and  any  part  of  the  name  left  out
  652.           defaults to "*".  Thus,
  653.  
  654.                   DIR" .SCR"     = DIR *.SCR
  655.                   DIR" *"        = DIR *
  656.                   DIR" ALL."     = DIR ALL.*
  657.  
  658.           The trailing quote may be replaced with the carriage return,
  659.           and in fact, must be replaced to list  files  with  a  blank
  660.           extension:
  661.  
  662.                   DIR" .<CR>     =DIR *. 
  663.                   DIR" INDEX.<CR>=DIR INDEX. 
  664.  
  665.  
  666.           3.3.5.3  erasing files 
  667.  
  668.           A function is provided to erase files:
  669.  
  670.                   ERASE" <filename>"
  671.  
  672.           The use of this command is similar to  the  directory  words
  673.           above, except that no  part  of  <filename>  has  a  default
  674.           8086/8088 Fig-FORTH User's Guide                    Page  15
  675.  
  676.  
  677.  
  678.           value.  ERASE"  will  accept  ambiguous  filenames,  and  it
  679.           displays the name of each file it  erases.   No  warning  is
  680.           issued when the filename is "*.*", so beware! 
  681.  
  682.  
  683.           3.3.5.4  screen transfer 
  684.  
  685.           To assist in copying screens between FORTH disks and  MS-DOS
  686.           files, two utilities are provided: COPY>FILE  and  COPY>SCR.
  687.           These function very simply.   COPY>FILE  directs  all  block
  688.           reads to the FIG-FORTH disk, and  all  disk  writes  to  the
  689.           current screen file.  COPY>SCR does the reverse.   Then  all
  690.           you need is the usual words for moving screens  around,  and
  691.           magically they appear at the destination.  The  actual  copy
  692.           operation is provided by the word #SCRCOPY, which takes  the
  693.           starting source screen, the starting destination screen  and
  694.           the number of screens to copy off the stack.  Thus,
  695.  
  696.                   USING" NEW"
  697.                   COPY>FILE ... 
  698.                   100 1 14 #SCRCOPY
  699.                   EOF
  700.  
  701.           would copy screens 100-113 on the FORTH disk to screens 1-14
  702.           in the file NEW.SCR.  Note that after you type  COPY>SCR  or
  703.           COPY>FILE, you can still LIST or INDEX the  source  disk  if
  704.           you forget which screens you want to copy. 
  705.  
  706.  
  707.           3.3.5.5  screen file status 
  708.  
  709.           To check on the status of the current screen file,  you  can
  710.           use
  711.  
  712.                   SCREENS /? 
  713.  
  714.           If the screen file is in use, a display similar to the  DIR"
  715.           information is printed; for example,
  716.  
  717.                   A:FORTH   .SCR r w s     10240  06-28-1983  19:59
  718.  
  719.           If the EOF command is given and then /?   is  repeated,  the
  720.           following would be printed:
  721.  
  722.                   A:FORTH   .SCR r w s
  723.  
  724.           showing that the file is not in use.  The  "r w s"  indicate
  725.           that this is a screen or random access file (s),  which  may
  726.           be both read from (r) and written to (w). 
  727.  
  728.           An interesting discrepancy may arise between the DIR" report
  729.           and the /?  information.  
  730.           8086/8088 Fig-FORTH User's Guide                    Page  16
  731.  
  732.  
  733.  
  734.           Examine the following session:
  735.  
  736.                   USING" NEW" empty file
  737.                   5 EXTEND ok
  738.                   DIR" NEW.SCR" 
  739.                   B:NEW     .SCR          0  06-29-1983   0:26   1 file ok
  740.                   SCREENS /? 
  741.                   B:NEW     .SCR r w s       5120  06-29-1983   0:27    ok
  742.                   EOF ok
  743.                   B:NEW     .SCR       5120  06-29-1983   0:27   1 file ok
  744.                   SCREENS /? 
  745.                   B:NEW     .SCR r w s   ok
  746.  
  747.           The differences in the file size and time fields reflect the
  748.           operating system buffering the physical disk output.  The /?
  749.           display is taken from the  file  control  block  in  memory,
  750.           which is immediately updated,  while  the  DIR"  display  is
  751.           taken from the directory and is not updated  until  data  is
  752.           written to the disk when the file is closed by EOF.  
  753.           8086/8088 Fig-FORTH User's Guide                    Page  17
  754.  
  755.  
  756.  
  757.  
  758.  
  759.           3.3.6  Notes 
  760.  
  761.           A  few  features  of  the  above  discussion  bear   further
  762.           emphasis. 
  763.  
  764.                 * NEVER change the disk FORTH  is  using  for  screens
  765.                   while the file is open.  Changing disks  haphazardly
  766.                   is a bad practice in almost all cases, not just  for
  767.                   FORTH.  As can be seen above, the  information  kept
  768.                   on the disk is not always accurate.  If the disk  is
  769.                   changed, the file parameters kept in memory will  be
  770.                   separated from the directory entry for the file, and
  771.                   disaster is almost certain to result. 
  772.  
  773.                 * In light of the above comments, note  that  you  may
  774.                   FLUSH FORTH's disk buffers, but  not  MS-DOS's  disk
  775.                   buffers.  Thus your disk buffers are not  guaranteed
  776.                   to be on the disk until you  close  the  file  using
  777.                   EOF.  If  the  file  interface  is  loaded,  BYE  is
  778.                   redefined to execute EOF before  exiting,  to  force
  779.                   any updated buffers to be saved. 
  780.  
  781.                 * Only one screen file may be active at  once.   FORTH
  782.                   checks this and will not allow another USING"  while
  783.                   the SCREENS file is in use.  This  restriction  only
  784.                   applies to screen files. 
  785.  
  786.                 * The FORTH disk is the default state after COLD,  but
  787.                   before an EOF.  You must specifically request access
  788.                   to a screen file.  Once you use a screen file, FORTH
  789.                   blocks any FORTH disk access until  you  request  it
  790.                   using SWITCH.  Accessing an MS-DOS disk as  a  FORTH
  791.                   disk probably won't destroy it, however, FORTH  will
  792.                   probably get upset and quit talking to  you.   FORTH
  793.                   tries to remind you to pay attention, but it doesn't
  794.                   try to protect you: the burden is  on  YOU  to  keep
  795.                   track of what you are doing! 
  796.  
  797.                 * There is a convention for  the  names  of  the  disk
  798.                   functions.  Since there are two names for each  file
  799.                   (see below) there are two ways to refer to  a  file.
  800.                   Names which begin with a "/" expect  an  address  on
  801.                   the stack.  Names which end in a double-quote expect
  802.                   a  filename,  delimited  by  a  trailing  quote,  to
  803.                   follow.  The  function  that  assigns  filenames  to
  804.                   files, therefore, has both: /IS". 
  805.  
  806.  
  807.  
  808.           3.4  Modifying FORTH 
  809.  
  810.           FORTH is an extremely  flexible  language.   With  a  little
  811.           effort you can make it your own  personal  environment.   In
  812.           addition, since you have the assembly source you can  change
  813.           8086/8088 Fig-FORTH User's Guide                    Page  18
  814.  
  815.  
  816.  
  817.           the inner workings, making it more efficient.  The following
  818.           discussion  is  not  complete,  but  serves   only   as   an
  819.           introduction.  Exploring the territory is half the fun! 
  820.  
  821.  
  822.           3.4.1  FORTH Extensions 
  823.  
  824.  
  825.           One of the nice things about FORTH is the ability to  extend
  826.           the language.  To complement  this  extensibility,  you  can
  827.           save the new FORTH in an executable file and the  extensions
  828.           become immediately available.  Only two things are necessary
  829.           to accomplish this: first,  FORTH's  cold  start  parameters
  830.           must be  updated;  and  second,  the  memory  image  of  the
  831.           modified FORTH must be saved in a file.   This  is  how  the
  832.           FORTH.COM file was constructed for distribution. 
  833.  
  834.           Updating the cold start parameters is  accomplished  by  the
  835.           FORTH word NEW.  Saving the new version can be done  in  two
  836.           ways:  first,  using  DEBUG  and  second,  the  FORTH   word
  837.           SAVE-FORTH" <filename>".  The FORTH word  SIZE?   will  tell
  838.           you the size of the FORTH kernel for writing from DEBUG.  To
  839.           use SAVE-FORTH, first execute NEW to lock the changes.  Make
  840.           sure no files are open before executing NEW, otherwise  they
  841.           will appear to be open when the new  FORTH  executes.   Then
  842.           define an output file and use SAVE-FORTH to write itself  to
  843.           the file.  Since the file was defined after NEW, it will not
  844.           appear in the new version.  Study the following hypothetical
  845.           example:
  846.  
  847.                   9 LOAD 100 LOAD 108 LOAD ok
  848.                   NEW ok
  849.                   current version is A
  850.                   new version (A-Z)? Bok
  851.                   >FILE S4 ok
  852.                   S4 /SAVE-FORTH" X4TH.COM"
  853.                   B:X4TH    .COM      12521  06-29-1983   0:27 ok
  854.  
  855.           Note that because the FIG-FORTH disk is the  default  state,
  856.           you must always modify and load the file definitions from  a
  857.           FORTH disk.  If you FORGET the file words, you can only  use
  858.           the FORTH disk! 
  859.  
  860.  
  861.           3.4.2  Patching 
  862.  
  863.           Many of the parameters which affect the operation  of  FORTH
  864.           are placed in the boot parameter area  at  the  low  end  of
  865.           FORTH.  These may be freely modified using  DEBUG,  or  from
  866.           within FORTH.  On execution of COLD, these  parameters  will
  867.           be used to initialize the interpreter.  The patches can then
  868.           be made permanent as  described  above.   For  example,  the
  869.           following will change the FORTH backspace key:
  870.  
  871.                   KEY 14 +ORIGIN ! 
  872.  
  873.           8086/8088 Fig-FORTH User's Guide                    Page  19
  874.  
  875.  
  876.  
  877.           After you type this and hit return, FORTH will wait for  you
  878.           to hit a key.  The key you type will be placed in  the  boot
  879.           parameters and will be recognized as  your  backspace.   The
  880.           other parameters in this area are clearly commented  in  the
  881.           assembly source, should you want to patch any of them. 
  882.  
  883.  
  884.           3.4.3  Assembly Source Modifications 
  885.  
  886.           Re-assembly  of  FORTH  is  the  least  desirable  form   of
  887.           modification.  It is slow and can  be  difficult  to  debug.
  888.           However, there are modifications which are only possible  in
  889.           this way.  A  great  deal  of  time  has  gone  into  adding
  890.           comments to the assembly source so that you  can  understand
  891.           the way FORTH works.  Almost all of the  comments  appearing
  892.           in the FIG listing are in the new listing, along  with  some
  893.           additional comments.   There  is  more  information  on  the
  894.           assembly source in the technical reference portion  of  this
  895.           documentation. 
  896.  
  897.           Be aware of two problems here: first, it  is  very  easy  to
  898.           lose track of the changes you make.  so document and comment
  899.           each modification.  Second, more changes make  your  version
  900.           of FORTH  more  unique  (or  maybe  just  strange)  and  any
  901.           definitions using that feature  less  portable.   Don't  add
  902.           bells and whistles just to be different. 
  903.  
  904.           8086/8088 Fig-FORTH User's Guide                    Page  20
  905.  
  906.  
  907.  
  908.  
  909.  
  910.           4  TECHNICAL REFERENCE 
  911.  
  912.           This section describes  changes  and  modifications  to  the
  913.           FIG-FORTH model.  It is not an explanation of the FIG model,
  914.           nor of how FORTH works.  The user should refer  to  the  FIG
  915.           installation manual for further information. 
  916.  
  917.  
  918.           4.1  Assembly Source 
  919.  
  920.           The FIG assembly listing on which this version is based  was
  921.           written for the CPM/86 8086 assembler.  For MS-DOS, the  FIG
  922.           listing was translated  into  source  for  Seattle  Computer
  923.           Products 8086 assembler.   Since  the  latter  assembler  is
  924.           peculiar to SCP systems, the code was translated again  into
  925.           source for  Microsoft's  MACRO-86  macro  assembler,  to  be
  926.           portable to any MS-DOS environment. 
  927.  
  928.           Several features of MACRO-86 were used  to  provide  greater
  929.           flexibility.  First, macros were written to build dictionary
  930.           headers for each definition.  These macros make  setting  up
  931.           the dictionary entries  convenient,  but  more  importantly,
  932.           they calculate the link fields.  Because the  links  are  no
  933.           longer  based  on  specific  labels  in  the   source,   the
  934.           dictionary can be split into several files  which  are  then
  935.           INCLUDED at  the  appropriate  points.   This  allows  great
  936.           flexibility and modularity in assembling FORTH. 
  937.  
  938.  
  939.           4.1.1  Source File Organization 
  940.  
  941.           The source is now broken into several separate files:
  942.  
  943.                 * 4TH-MAIN.ASM
  944.                   This is the primary file which INCLUDES  the  others
  945.                   during assembly.  It contains the inner interpreter,
  946.                   code-level kernel, and most of the FORTH vocabulary. 
  947.  
  948.                 * 4TH-SYSD.ASM
  949.                   This file contains (almost) all of the code which is
  950.                   operating system  or  hardware  dependent.   If  you
  951.                   wanted to transport FORTH  to  a  different  system,
  952.                   most of the changes would be in this file. 
  953.  
  954.                 * 4TH-DISK.ASM
  955.                   This file is INCLUDED by 4TH-SYSD and  contains  the
  956.                   actual  disk  interface  for  reading/writing   disk
  957.                   sectors. 
  958.  
  959.                 * 4TH-FILE.ASM
  960.                   Also (optionally) INCLUDED by SYSD,  this  file  has
  961.                   all of  the  words  that  deal  with  files  at  the
  962.                   operating system level.  This code is only assembled
  963.                   if the FILES option is set to TRUE. 
  964.           8086/8088 Fig-FORTH User's Guide                    Page  21
  965.  
  966.  
  967.  
  968.  
  969.                 * 4TH-XTNS.ASM
  970.                   These definitions are code-level extensions  of  the
  971.                   FORTH dictionary.  These  include  array  addressing
  972.                   primitives, long fetch and store operators  and  the
  973.                   port i/o words.  MATCH is also in this  file.   This
  974.                   file is only assembled if the EXTEND option is TRUE. 
  975.  
  976.                 * 4TH-OPTS.H
  977.                   The assembly options  are  located  in  this  header
  978.                   file,  and  are  symbols  which   begin   with   the
  979.                   underscore character.  These are  global  parameters
  980.                   and are used by other modules.   All  other  equates
  981.                   and variables should be local to  the  module  where
  982.                   they are defined. 
  983.  
  984.                   It  is  unfortunate  that  the  modules  cannot   be
  985.                   separately assembled and linked.  The present system
  986.                   requires a lot of memory  and  about  5  minutes  to
  987.                   assemble (on an 8MHz  8086  using  8"  ssdd  disks).
  988.                   This is really tedious for making small changes! 
  989.  
  990.  
  991.                   4.1.2  Macros 
  992.  
  993.                   The macros necessary to assemble FORTH  are  in  the
  994.                   file 4TH-LIB.MAC.  Comments in this file explain the
  995.                   function  of  each  macro.   Beside  the  dictionary
  996.                   macros, there are two macros to do branches  in  the
  997.                   threaded definitions.  The  actions  of  the  macros
  998.                   should be clear after studying their definitions and
  999.                   the manner in which they are used in the code. 
  1000.  
  1001.  
  1002.                   4.1.3  Comments 
  1003.  
  1004.                   The  SCP  assembler  source  was   rather   sparsely
  1005.                   commented.  This  omission  has  been  rectified  by
  1006.                   copying all of the FIG listing comments,  plus  some
  1007.                   additional comments, into  the  MACRO-86  code.   In
  1008.                   addition, each entry in the dictionary has a comment
  1009.                   in the following form:
  1010.  
  1011.                   ;=AB  <name>   <description>   <stack effects>
  1012.  
  1013.                   where  A  is  a  letter  indicating  the   type   of
  1014.                   dictionary entry, and B is  a  character  indicating
  1015.                   whether the function has  been  added  or  modified.
  1016.                   This scheme  allows  automatic  glossary  generation
  1017.                   using a text editor or search utility.  
  1018.           8086/8088 Fig-FORTH User's Guide                    Page  22
  1019.  
  1020.  
  1021.  
  1022.                   The dictionary entry types are:
  1023.  
  1024.                           C = code-level definition
  1025.                           : = colon definition
  1026.                           # = constant
  1027.                           ? = variable
  1028.                           U = user variable
  1029.  
  1030.                   The B character is either a blank,  a  plus,  or  an
  1031.                   asterisk;  indicating   that   the   definition   is
  1032.                   unmodified, added, or modified, respectively. 
  1033.  
  1034.  
  1035.                   4.2  Modifications 
  1036.  
  1037.                   The changes to the FIG listing fall  basically  into
  1038.                   two  categories:  changes  to  clean  up  the   disk
  1039.                   interface and manage buffers more  efficiently,  and
  1040.                   changes to route the i/o functions through execution
  1041.                   vectors.   The  sections  below  describe   specific
  1042.                   changes to the FIG model.  Each section  corresponds
  1043.                   to one in the FIG-FORTH  installation  manual.   Any
  1044.                   changes to that part of the model are listed there. 
  1045.  
  1046.  
  1047.                   4.2.1  Boot Parameters 
  1048.  
  1049.                        BSIN was changed to 127 - ASCII DEL. 
  1050.  
  1051.  
  1052.                   4.2.2  Machine Code Definitions 
  1053.  
  1054.                        Code added to  (FIND)  to  handle  word-aligned
  1055.                   definitions.  May be disabled by setting the  option
  1056.                   ALIGN to FALSE. 
  1057.  
  1058.  
  1059.                   4.2.3  High-level Utility Definitions 
  1060.  
  1061.                        1+ and 2+ were changed to code definitions. 
  1062.                        TRAVERSE was modified  to  handle  word-aligned
  1063.                   LFA's. 
  1064.                        PFA was changed to handle word-aligned PFA's. 
  1065.                        EXPECT backspace was made destructive. 
  1066.                        ID.   was  modified  to  reset  MSB   of   last
  1067.                   character. 
  1068.                        CREATE  can  compile  dictionary  headers  with
  1069.                   word-aligned LFA's.  If DP is  odd  after  compiling
  1070.                   the name field, DP is incremented so that  the  rest
  1071.                   of the definition lies is word addressable.  If byte
  1072.                   values such as character  strings  are  subsequently
  1073.                   compiled into the definition, the alignment  may  be
  1074.                   lost.  Note that the length byte at NFA still  gives
  1075.                   the exact length of the name,  but  not  necessarily
  1076.                   the displacement to the LFA.  The alignment  may  be
  1077.                   disabled by setting the ALIGN  option  to  FALSE  at
  1078.           8086/8088 Fig-FORTH User's Guide                    Page  23
  1079.  
  1080.  
  1081.  
  1082.                   assembly time to save space. 
  1083.                        QUIT prints lower case "ok". 
  1084.                        ABORT prints the user version as well. 
  1085.                        COLD sets execution vectors. 
  1086.                        All system dependent  initialization  is  in  a
  1087.                   subroutine called SYSINIT, located in  4TH-SYSD.ASM,
  1088.                   which is called just prior  to  starting  the  inner
  1089.                   interpreter. 
  1090.  
  1091.  
  1092.                   4.2.4  Installation Dependent Code 
  1093.  
  1094.  
  1095.  
  1096.                   4.2.4.1  console i/o 
  1097.  
  1098.                        KEY, EMIT, and  CR  were  changed  to  use  the
  1099.                   execution vectors @KEY, @EMIT, and @CR respectively.
  1100.                   These vectors are initialized to the CFA's of (KEY),
  1101.                   (EMIT) and (CR); but may be changed by  storing  new
  1102.                   CFA's in the vectors. 
  1103.                        Two options in 4TH-OPTS.H affect  console  i/o:
  1104.                   DIRECTCON and IOBITS.  If DIRECTCON is TRUE, console
  1105.                   i/o is performed by MS-DOS function six  and  seven,
  1106.                   which ignore all special characters.  Thus,  if  you
  1107.                   have an application which has to respond to ^P,  for
  1108.                   example, you should re-assemble with  DIRECTCON  set
  1109.                   to TRUE.  IOBITS is an equate which  determines  how
  1110.                   many bits to send/receive.  Normal  ASCII  terminals
  1111.                   don't use  the  MSB,  so  IOBITS  should  be  seven.
  1112.                   However, the IBM-PC uses all eight bits,  so  IOBITS
  1113.                   should  be  eight.   DIRECTCON  also   disables   ^C
  1114.                   interrupts, except during printer output. 
  1115.  
  1116.  
  1117.                   4.2.4.2  printer i/o 
  1118.  
  1119.                        The variable  controlling  printer  output  was
  1120.                   changed to PRINTER.  If PRINTER is zero, no  printer
  1121.                   output occurs.  If PRINTER is positive, all  console
  1122.                   output also goes to  the  printer.   If  PRINTER  is
  1123.                   negative, output normally going to  the  console  is
  1124.                   sent only to the printer. 
  1125.  
  1126.  
  1127.                   4.2.4.3  disk i/o 
  1128.  
  1129.                        The code to interface to the disk was  factored
  1130.                   into two parts.  All functions that  know  something
  1131.                   about the physical characteristics of the  disk  are
  1132.                   in the  4TH-DISK.ASM  file.   Every  other  function
  1133.                   knows only that disk blocks  are  1024  bytes  long.
  1134.                   This means that BLOCK-READ/WRITE must always deliver
  1135.                   1024 bytes and not one physical sector. 
  1136.  
  1137.           8086/8088 Fig-FORTH User's Guide                    Page  24
  1138.  
  1139.  
  1140.  
  1141.                        The  disk  read/write   routines   (BLOCK-READ,
  1142.                   BLOCK-WRITE)  were  changed  to  use  the  execution
  1143.                   vectors @BLKRD and @BLKWRT.  For normal  FORTH  disk
  1144.                   i/o, @BLKRD and @BLKWRT point to BLKRD  and  BLKWRT.
  1145.                   For screen file access, these  vectors  are  set  to
  1146.                   /BLOCK-READ and /BLOCK-WRITE. 
  1147.                        The variables DRIVE, RECORD,  REC/BLK  and  DTA
  1148.                   are set to the parameters used for each disk  access
  1149.                   and  may  be  examined  if  an  error  occurs.   The
  1150.                   variable DISK-ERROR is set to indicate  the  success
  1151.                   or failure of each disk operation.  If DISK-ERROR is
  1152.                   zero,  the  operation  was  successful.    Otherwise
  1153.                   DISK-ERROR has the MS-DOS error code as described in
  1154.                   it's documentation, except  that  write  errors  are
  1155.                   converted to negative numbers. 
  1156.                        The  buffer   management   was   also   changed
  1157.                   slightly.  When BUFFER has to flush a dirty block to
  1158.                   the disk, it checks and flushes ALL  dirty  buffers.
  1159.                   This requires very little additional  overhead,  and
  1160.                   it is  much  more  efficient  for  copying  multiple
  1161.                   blocks. 
  1162.  
  1163.  
  1164.                   4.2.5  High-level Definitions 
  1165.  
  1166.  
  1167.  
  1168.                   4.2.6  System Tools 
  1169.  
  1170.                   4.2.7  RAM Workspace 
  1171.  
  1172.                   4.2.8  Memory Map 
  1173.  
  1174.                        The memory map was  extended  to  use  all  64K
  1175.                   (LIMIT=0), and 8 1K byte block buffers. 
  1176.  
  1177.  
  1178.                   4.2.9  Other 
  1179.  
  1180.                        COLD  sets  the  ^C  interrupt  vector  to  the
  1181.                   address of  a  code  fragment  which,  on  receiving
  1182.                   control after you  hit  ^C,  examines  the  variable
  1183.                   @BREAK.  If @BREAK is zero,  the  interrupt  handler
  1184.                   simply returns  from  the  interrupt  and  execution
  1185.                   continues.  Unfortunately, a "^C" is always sent  to
  1186.                   the console, and the key is not passed to FORTH.  If
  1187.                   @BREAK is non-zero, the  interrupt  handler  vectors
  1188.                   the inner interpreter to the (presumed CFA)  address
  1189.                   in @BREAK.  @BREAK is set at assembly  time  to  the
  1190.                   CFA of (ABORT), it is not initialized by  COLD.   If
  1191.                   the DIRECTCON option  is  selected,  almost  all  ^C
  1192.                   processing  is  disabled.   The  only  time   a   ^C
  1193.                   interrupt can occur is during printer output. 
  1194.                        BYE exits via INT 20H
  1195.  
  1196.           8086/8088 Fig-FORTH User's Guide                    Page  25
  1197.  
  1198.  
  1199.  
  1200.  
  1201.  
  1202.                   4.3  Additions 
  1203.  
  1204.                   Two new features have been added in this version  of
  1205.                   FIG FORTH.   Command  line  argument  interpretation
  1206.                   allows  you  to  pass  instructions  to  FORTH  from
  1207.                   COMMAND.  Thus, you can run FORTH from a batch  file
  1208.                   if the program doesn't require any  terminal  input.
  1209.                   The file interface allows FORTH to share information
  1210.                   with other MS-DOS programs and utilities. 
  1211.  
  1212.  
  1213.                   4.3.1  Command Line Interpretation 
  1214.  
  1215.                   When FORTH starts execution, it copys any string  of
  1216.                   text on the  command  line  to  the  terminal  input
  1217.                   buffer, and interprets it just as if you  had  typed
  1218.                   it. 
  1219.  
  1220.  
  1221.                   4.3.2  File Interface 
  1222.  
  1223.                   The goal in developing the  file  interface  was  to
  1224.                   allow FORTH  useful  access  to  MS-DOS  files,  not
  1225.                   simply the random access  screens.   The  constraint
  1226.                   was that it had to be accomplished with a minimum of
  1227.                   change to the FIG model.  This discussion is not  as
  1228.                   complete as it could be.  The  reason  for  this  is
  1229.                   that the details will probably  change.   While  the
  1230.                   overall design is (hopefully) sound, the fine points
  1231.                   are not completely worked out.  As they are applied,
  1232.                   they will certainly be improved. 
  1233.  
  1234.                   There are two parts to the file interface:  the  low
  1235.                   level functions defined in 4TH-FILE.ASM and the high
  1236.                   level words in FILES.SCR.  The  low-level  functions
  1237.                   are little more  than  MS-DOS  function  calls  with
  1238.                   FORTH headers.  The high-level definitions  do  most
  1239.                   of  the  work,  making  it  easier  to  modify   the
  1240.                   interface. 
  1241.  
  1242.                   The words defined in FILES.SCR allow you  to  define
  1243.                   files in much the same  way  you  define  variables.
  1244.                   After a file has been defined, the name is  used  to
  1245.                   refer to it.  The name acts just  like  a  variable,
  1246.                   returning an address.  The  address  returned  is  a
  1247.                   pointer to the file header and file  control  block,
  1248.                   or FCB.  The header is a  word  of  data  where  the
  1249.                   file's attributes are kept, this header  address  is
  1250.                   referred to as the file descriptor,  or  FD.   These
  1251.                   attributes are only used by FORTH, MS-DOS never sees
  1252.                   them.  At present, the only  attributes  are:  read,
  1253.                   write, sequential/random access and open.  Following
  1254.                   the header is the FCB which MS-DOS  uses  while  the
  1255.                   file is open. 
  1256.           8086/8088 Fig-FORTH User's Guide                    Page  26
  1257.  
  1258.  
  1259.  
  1260.  
  1261.                   The first part of the FCB is the filespec.  This  is
  1262.                   the drive, filename and extension for the file,  and
  1263.                   is the name by which  MS-DOS  refers  to  the  file.
  1264.                   Before opening a file, these fields must  be  filled
  1265.                   in.  Assigning the filename is accomplished  by  two
  1266.                   methods, one for interactive use  and  one  for  use
  1267.                   inside definitions.  The word FNAME takes  a  target
  1268.                   address and a mode number on  the  stack.   It  then
  1269.                   parses the string at PAD (actually PAD+1, PAD  holds
  1270.                   the count byte), and returns a flag which is true if
  1271.                   the filename was ambiguous.  If FNAME finds that the
  1272.                   given filename is illegal (or  null)  it  prints  an
  1273.                   error and aborts. 
  1274.  
  1275.                   To assign a filename to a file  from  the  terminal,
  1276.                   the word /IS" is provided.  This function  takes  an
  1277.                   fd off the stack and assigns the following  word  in
  1278.                   the input stream as the filename.  The /IS" function
  1279.                   can be used in a definition, but it can't be used to
  1280.                   assign a filename to a file without console input. 
  1281.  
  1282.                   Once the file has been defined, and has a  name,  it
  1283.                   can be opened or created using  /OPEN,  or  /CREATE.
  1284.                   The file can be closed using /CLOSE. 
  1285.  
  1286.                   For character files, /GETC and /PUTC are provided to
  1287.                   read/write  one  character;  and  /READ  and  /WRITE
  1288.                   transfer a number of bytes at  once.   Screen  files
  1289.                   use /BLOCK-READ and /BLOCK-WRITE.   These  functions
  1290.                   are  called   indirectly   through   BLOCK-READ   or
  1291.                   BLOCK-WRITE. 
  1292.  
  1293.                   This  reference  is  admittedly   incomplete.    For
  1294.                   further information, study the glossary for 4TH-FILE
  1295.                   and the FORTH code for the file interface. 
  1296.  
  1297.           8086/8088 Fig-FORTH User's Guide                    Page  27
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.                   5  GLOSSARY 
  1304.  
  1305.                   This  section  is  a  glossary  of  words  added  or
  1306.                   changed, relative to FIG-FORTH v1.0.   The  name  of
  1307.                   the word is given, then it's stack effects, then the
  1308.                   type of definition, where the letter  indicates  the
  1309.                   type of definition:
  1310.  
  1311.                           C = code-level definition
  1312.                           : = colon definition
  1313.                           # = constant
  1314.                           ? = variable
  1315.                           U = user variable
  1316.  
  1317.                   and  the  second  letter   indicates   whether   the
  1318.                   definition was added  (+)  or  modified  (*).   And,
  1319.                   finally, the file where the word is defined.  
  1320.           8086/8088 Fig-FORTH User's Guide                    Page  28
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.                   5.1  Assembly Listing Definitions 
  1327.  
  1328.                   (2ARR)          n1 n2 PFA -- addr               C+ XTNS
  1329.                                   Two dimensional word array primitive
  1330.                   compiled  by  2ARRAY.   The  address  of  the  array
  1331.                   element at row n1, column n2, of an array  beginning
  1332.                   at addr+4 is left on the stack.  It is assumed  that
  1333.                   the number  of  columns  is  stored  at  addr.   The
  1334.                   contents of addr+2 could hold  the  number  of  rows
  1335.                   (perhaps for error checking), but it isn't  used  in
  1336.                   the calculation. 
  1337.  
  1338.                   (2CARR)         n1 n2 PFA -- addr2              C+ XTNS
  1339.                                   Two dimensional byte array primitive
  1340.                   compiled by  STRINGS.   The  address  of  the  array
  1341.                   element at row n1, column n2 of an  array  beginning
  1342.                   at PFA+4 is left on the stack.  It is  assumed  that
  1343.                   the row size is at PFA.  The contents of PFA+2 could
  1344.                   hold the number of rows, but it isn't  used  in  the
  1345.                   calculations. 
  1346.  
  1347.                   (ARRAY)         n PFA -- addr                   C+ XTNS
  1348.                                   Integer  array  primitive  used   by
  1349.                   ARRAY.  The address of the nth element of the  array
  1350.                   beginning at PFA+2 is calculated  and  left  on  the
  1351.                   stack.  The length of the array is stored at PFA. 
  1352.  
  1353.                   (BLKRD)         --                              C+ DISK
  1354.                                   Block  read  primitive   called   by
  1355.                   BLKRD.  This function calls the absolute  disk  read
  1356.                   function (INT 25) to access the disk.  This function
  1357.                   transfers REC/BLK records,  starting  at  RECORD  on
  1358.                   DRIVE to DTA.  The code returned by the interrupt is
  1359.                   placed in DISK-ERROR, zero indicating success. 
  1360.  
  1361.                   (BLKWRT)        --                              C+ DISK
  1362.                                   Block  write  primitive  called   by
  1363.                   BLKWRT.  This function transfers REC/BLK records  on
  1364.                   DRIVE starting at RECORD to DTA.   The  return  code
  1365.                   from INT 26H is negated and  placed  in  DISK-ERROR,
  1366.                   zero means success. 
  1367.  
  1368.                   (CARR)          n PFA -- addr                   C+ XTNS
  1369.                                   Byte  array  primitive  compiled  by
  1370.                   CARRAY.  The address of the  nth  character  in  the
  1371.                   array beginning at PFA+2 is calculated and  left  on
  1372.                   the stack.  The length of the array or  the  current
  1373.                   length of the string may be left at PFA. 
  1374.  
  1375.                   (CLOSE)         FCB -- f                        C+ FILE
  1376.                                   Primitive  function  to  close   FCB
  1377.                   using  DOS  function  10H.   The  flag  is  zero  if
  1378.                   successful, 0FFH if not. 
  1379.  
  1380.           8086/8088 Fig-FORTH User's Guide                    Page  29
  1381.  
  1382.  
  1383.  
  1384.                   (CREATE)        FCB -- f                        C+ FILE
  1385.                                   Create and open a file as  specified
  1386.                   in FCB using DOS function 16H.  The flag returned is
  1387.                   zero if successful, 0FFH if not. 
  1388.  
  1389.                   (FBLKRD)        FCB n -- f                      C+ FILE
  1390.                                   File  block  read  primitive.   This
  1391.                   function reads n  blocks  from  an  open  FCB.   The
  1392.                   blocks read are the size  specified  in  the  record
  1393.                   size field of the FCB.  For normal screen  files,  n
  1394.                   is always 1 and the  record  size  is  set  to  1024
  1395.                   bytes. 
  1396.  
  1397.                   (FBLKWRT)       FCB n -- f                      C+ FILE
  1398.                                   Write n blocks to the file specified
  1399.                   by FCB.  See (FBLKRD) above. 
  1400.  
  1401.                   (FIND)          a1 NFA -- [PFA b] f             C* MAIN
  1402.                                   (FIND)  was   modified   to   handle
  1403.                   aligned  dictionary  headers  (only  when  ALIGN  is
  1404.                   true).  The address list  following  the  header  is
  1405.                   aligned by inserting a  NOP  (90H)  after  the  last
  1406.                   character of the name field.  (FIND) must take  this
  1407.                   into account when looking up a name. 
  1408.  
  1409.                   (FNAME)         FCB addr1 n -- addr2 f          C+ FILE
  1410.                                   Parse  the  string  at  addr1  as  a
  1411.                   filename using mode n, and assign it  to  FCB.   The
  1412.                   first character not parsed and an ambiguous filename
  1413.                   are left on  the  stack.   This  function  uses  DOS
  1414.                   function 29H, which defines the modes. 
  1415.  
  1416.                   (OPEN)          FCB -- f                        C+ FILE
  1417.                                   Open the specified  FCB.   The  flag
  1418.                   returns the success or  failure  of  the  operation:
  1419.                   zero if successful, 0FFH otherwise. 
  1420.  
  1421.                   (READ)          FCB addr -- f                   C+ FILE
  1422.                                   Sequential      read      primitive.
  1423.                   Transfers the next record in the file  specified  by
  1424.                   FCB  to  addr.   The  status  of  the  operation  is
  1425.                   returned in  the  flag  f.   The  flag  is  zero  if
  1426.                   successful, 0FF if not. 
  1427.  
  1428.                   (WRITE)         FCB addr -- f                   C+ FILE
  1429.                                   Sequential write primitive.   Writes
  1430.                   the next record of the file specified  by  FCB  from
  1431.                   addr.  The flag returned by DOS function 15H is left
  1432.                   on the stack. 
  1433.  
  1434.                   (XOF)                   n1 n2 -- [n1]           C+ XTNS
  1435.                                   Control structure primitive compiled
  1436.                   by OF.  If the case being scanned for  (n1)  matches
  1437.                   the current case (n2), the tag n1 is dropped and the
  1438.                   FORTH words following the branch compiled by OF  are
  1439.                   executed.  If the case tags don't match, n1 is  left
  1440.           8086/8088 Fig-FORTH User's Guide                    Page  30
  1441.  
  1442.  
  1443.  
  1444.                   on the stack and the branch is executed to check the
  1445.                   next case. 
  1446.  
  1447.                   +BUF            addr1 -- addr2                  :* MAIN
  1448.                                   Advance the buffer pointer addr1  to
  1449.                   the next buffer at addr2. 
  1450.  
  1451.                   1-              n -- n-1                        C+ MAIN
  1452.                                   Subtract one from the item on top of
  1453.                   the stack. 
  1454.  
  1455.                   2-              n -- n-2                        C+ MAIN
  1456.                                   Subtract two from the item on top of
  1457.                   the stack. 
  1458.  
  1459.                   ?FIRST          FCB addr -- f                   C+ FILE
  1460.                                   Search the disk  directory  for  the
  1461.                   first occurance of FCB.  The flag returned  is  zero
  1462.                   if none are found, 0FF otherwise.   If  a  match  is
  1463.                   found, it's directory entry is placed at addr. 
  1464.  
  1465.                   ?NEXT           addr FCB -- f                   C+ FILE
  1466.                                   Search for  the  next  occurance  of
  1467.                   FCB.  The search FCB must previously have  been  set
  1468.                   up by ?FIRST.  If a match is found, f will  be  0FFH
  1469.                   and the matching directory entry  will  be  left  at
  1470.                   addr. 
  1471.  
  1472.                   @BLKRD          - addr                          U+ MAIN
  1473.                                   Execution vector holding the CFA  of
  1474.                   a function to read one block from  the  disk.   This
  1475.                   vector is either BLKRD  for  FORTH  disk  access  or
  1476.                   FBLKRD for screen file access.  BLOCK-READ uses this
  1477.                   vector. 
  1478.  
  1479.                   @BLKWRT         - addr                          U+ MAIN
  1480.                                   Execution vector holding the CFA  of
  1481.                   a function to write one block  to  the  disk.   This
  1482.                   vector is either BLKWRT for  FORTH  disk  access  or
  1483.                   FBLKWRT for screen file  access.   BLOCK-WRITE  uses
  1484.                   this vector. 
  1485.  
  1486.                   @BREAK          -- addr                         ?+ SYSD
  1487.                                   Execution vector holding the CFA  of
  1488.                   the function to be executed on input if  a  ^C.   If
  1489.                   @BREAK  is  zero,  the  interrupt   handler   simply
  1490.                   returns, effectively ignoring the interrupt. 
  1491.  
  1492.                   @CR             -- addr                         U+ MAIN
  1493.                                   Execution   vector   to   output   a
  1494.                   newline,  usually  carriage  return/linefeed.   COLD
  1495.                   initializes @CR to the CFA of (CR). 
  1496.  
  1497.  
  1498.           8086/8088 Fig-FORTH User's Guide                    Page  31
  1499.  
  1500.  
  1501.  
  1502.                   @EMIT           -- addr                         U+ MAIN
  1503.                                   Execution  vector  to  do  character
  1504.                   output.  Initialized by COLD to the CFA of (EMIT). 
  1505.  
  1506.                   @KEY            -- addr                         U+ MAIN
  1507.                                   Execution  vector  to  do  character
  1508.                   input.  Initialized by COLD to the CFA of (KEY). 
  1509.  
  1510.                   B/SEC           -- n                            C+ FILE
  1511.                                   Calls DOS function 1BH  and  returns
  1512.                   the number of bytes per physical disk sector. 
  1513.  
  1514.                   BLK/DRIVE       -- n                            #+ DISK
  1515.                                   Constant returning the number of  1K
  1516.                   disk blocks per drive. 
  1517.  
  1518.                   BLKRD           addr blk --                     :+ DISK
  1519.                                   This function  reads  block  blk  to
  1520.                   addr.  This is basically an  interface  between  the
  1521.                   BLOCK-READ function and the (BLKRD) functions. 
  1522.  
  1523.                   BLKWRT          addr blk --                     :+ DISK
  1524.                                   This function writes block blk  from
  1525.                   addr.  This is basically an  interface  between  the
  1526.                   BLOCK-WRITE function and the (BLKWRT) functions. 
  1527.  
  1528.                   BLOCK           n -- addr                       :* MAIN
  1529.                                   BLOCK was modified to  check  for  a
  1530.                   disk error. 
  1531.  
  1532.                   BLOCK-READ      addr blk --                     :+ MAIN
  1533.                                   Read one block to addr.   Calls  the
  1534.                   function whose CFA is in @BLKRD  to  do  the  actual
  1535.                   transfer. 
  1536.  
  1537.                   BLOCK-WRITE     addr blk --                     :+ MAIN
  1538.                                   Write one block  from  addr.   Calls
  1539.                   the function whose CFA  is  in  @BLKWRT  to  do  the
  1540.                   actual transfer. 
  1541.  
  1542.                   BUFFER          n -- addr                       :* MAIN
  1543.                                   This function was modified to  flush
  1544.                   all dirty buffers when one is found. 
  1545.  
  1546.                   COLD            --                              :* MAIN
  1547.                                   Added code to  initialize  execution
  1548.                   vectors. 
  1549.  
  1550.                   CR              --                              :* MAIN
  1551.                                   Output a carriage return/linefeed by
  1552.                   calling the function whose CFA is in @CR. 
  1553.  
  1554.  
  1555.           8086/8088 Fig-FORTH User's Guide                    Page  32
  1556.  
  1557.  
  1558.  
  1559.                   CREATE          --                              :* MAIN
  1560.                                   Create a dictionary header  for  the
  1561.                   next word in the input stream.  CREATE was  modified
  1562.                   to align the address list.  The ALIGN option must be
  1563.                   selected for this to occur. 
  1564.  
  1565.                   D&RCALC         n --                            :+ DISK
  1566.                                   Set DRIVE and RECORD  for  block  n.
  1567.                   This function is called by BLKRD/BLKWRT  to  set  up
  1568.                   for (BLKRD)/(BLKWRT). 
  1569.  
  1570.                   DATE!           n1 n2 n3 --                     C+ XTNS
  1571.                                   Date set operator.   The  parameters
  1572.                   are  n1=month,  n2=day,  n3=year.   If  any  of  the
  1573.                   parameters are out of range, no change is made. 
  1574.  
  1575.                   DATE@           -- n1 n2 n3                     C+ XTNS
  1576.                                   Date fetch operator.  The parameters
  1577.                   are  n1=month,  n2=day,  n3=year.   If  any  of  the
  1578.                   parameters are out of range, no change is made. 
  1579.  
  1580.                   DISK            n -- n2                         C+ FILE
  1581.                                   Set the current default drive to  n.
  1582.                   Drive A is zero, B is one.  The  number  of  drives,
  1583.                   n2, is left on the stack. 
  1584.  
  1585.                   DISK@           -- n                            C+ FILE
  1586.                                   Return  the  current  default  drive
  1587.                   number. 
  1588.  
  1589.                   DTA             -- addr                         ?+ MAIN
  1590.                                   Variable holding the address of  the
  1591.                   last disk transfer operation.  This variable is  set
  1592.                   by R/W for use by the transfer functions. 
  1593.  
  1594.                   EMIT            c --                            :* MAIN
  1595.                                   Function  to  do  character  output.
  1596.                   Calls the function whose CFA is in @EMIT to  do  the
  1597.                   actual output. 
  1598.  
  1599.                   EMPTY-BUFFERS   --                              :* MAIN
  1600.                                   This function was  modified  to  set
  1601.                   emptied buffers to block 32767.  FIG-FORTH set  them
  1602.                   to zero. 
  1603.  
  1604.                   FLUSH           --                              :* MAIN
  1605.                                   FLUSH  was  also  modified  so  that
  1606.                   empty buffers are assigned to block 32767. 
  1607.  
  1608.                   FDEL            FCB -- f                        C+ FILE
  1609.                                   Delete the file  specified  by  FCB.
  1610.                   The  flag  returned  is  zero  if  successful,  0FFH
  1611.                   otherwise. 
  1612.  
  1613.  
  1614.           8086/8088 Fig-FORTH User's Guide                    Page  33
  1615.  
  1616.  
  1617.  
  1618.                   FREN            addr -- f                       C+ FILE
  1619.                                   Rename the  file  according  to  the
  1620.                   special FCB at addr.  See the DOS function  17H  for
  1621.                   details on how this is set up. 
  1622.  
  1623.                   KEY             -- c                            :+ MAIN
  1624.                                   Character input function.  KEY calls
  1625.                   the function  whose  CFA  is  in  @KEY  to  get  the
  1626.                   character. 
  1627.  
  1628.                   L!              n seg off --                    C+ XTNS
  1629.                   L@              seg off -- n                    C+ XTNS
  1630.                   LC!             n seg off --                    C+ XTNS
  1631.                   LC@             seg off -- b                    C+ XTNS
  1632.                                   Intersegment fetch/store  operators.
  1633.                   These are similar to  the  usual  FORTH  fetch/store
  1634.                   words, except they use a double-word address.   Note
  1635.                   that   the    absolute    location    accessed    is
  1636.                   seg*16+offset. 
  1637.  
  1638.                   MAXBLOCK        -- n                            #+ DISK
  1639.                                   Constant returning the highest legal
  1640.                   block number.  That is, BLK/DRIVE*(MAXDRIVE+1)-1. 
  1641.  
  1642.                   MAXDRIVE        -- n                            #+ DISK
  1643.                                   Constant returning the highest legal
  1644.                   drive number. 
  1645.  
  1646.                   MYSEG           -- seg                          C+ MYSEG
  1647.                                   This  word  returns  the  value   of
  1648.                   FORTH's  current  segment.   This  allows  the  long
  1649.                   fetch/store operators  to  access  locations  inside
  1650.                   FORTH easily. 
  1651.  
  1652.                   NFA             PFA -- NFA                      :* MAIN
  1653.                   PFA             NFA -- PFA                      :* MAIN
  1654.                                   These  functions  can   adjust   for
  1655.                   aligned definitions, if  ALIGN  is  selected  during
  1656.                   assembly. 
  1657.  
  1658.                   PRINTER         -- addr                         ?+ MAIN
  1659.                                   Flag controlling printer output.  If
  1660.                   PRINTER is zero, nothing is sent to the printer.  If
  1661.                   PRINTER is positive, output to the console also goes
  1662.                   to the printer.   If  PRINTER  is  negative,  output
  1663.                   normally going to the console will be  sent  to  the
  1664.                   printer only.  Note that this is independent of  the
  1665.                   ^P/^N printer echo! 
  1666.  
  1667.                   R/W             addr blk f --                   :* MAIN
  1668.                                   This function was modified to simply
  1669.                   pass the addr  and  blk  on  to  the  BLOCK-READ  or
  1670.                   BLOCK-WRITE functions. 
  1671.  
  1672.  
  1673.           8086/8088 Fig-FORTH User's Guide                    Page  34
  1674.  
  1675.  
  1676.  
  1677.                   REC/BLK         -- n                            #+ DISK
  1678.                                   Constant  returning  the  number  of
  1679.                   disk records required to fill one 1024 byte  buffer.
  1680.                   All disk accesses look to FORTH like  they  transfer
  1681.                   1K of data. 
  1682.  
  1683.                   RECORD          -- addr                         ?+ MAIN
  1684.                                   Variable  holding  the  disk  record
  1685.                   number where the last block  accessed  began.   That
  1686.                   is, if the last block accessed was  2,  then  record
  1687.                   would contain 2*REC/BLK.  This variable  is  set  by
  1688.                   D&RCALC for use by (BLKRD)/(BLKWRT). 
  1689.  
  1690.                   SAVBUF          addr --                         :+ MAIN
  1691.                                   This function saves  the  buffer  at
  1692.                   addr if it has been updated.  The buffer is  flushed
  1693.                   but not emptied. 
  1694.  
  1695.                   SAVE-BUFFERS    --                              :+ MAIN
  1696.                                   This  function   flushes   all   the
  1697.                   buffers but doesn't  empty  them.   SAVE-BUFFERS  is
  1698.                   called by BUFFER when it finds a dirty buffer. 
  1699.  
  1700.                   TIME!           n1 n2 --                        C+ XTNS
  1701.                   TIME@           -- n1 n2                        C+ XTNS
  1702.                                   Set/fetch  the  system  time.    The
  1703.                   parameters  are  n1=[sec/csec],  n2=[hr/min];   each
  1704.                   quantity is a byte, but the four are packed  into  2
  1705.                   words.  Note that the low byte of the top stack item
  1706.                   has the minutes, the high byte holds the hours,  and
  1707.                   so on.  If any of the parameters are out  of  range,
  1708.                   there is no effect.  
  1709.           8086/8088 Fig-FORTH User's Guide                    Page  35
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.                   5.2  Deleted Definitions 
  1716.  
  1717.                   The  following  words  were  deleted  from  the  FIG
  1718.                   listing:
  1719.  
  1720.                           EPRINT
  1721.                           SEC
  1722.                           SECRD
  1723.                           SECWT
  1724.                           SET-DRIVE
  1725.                           SET-IO
  1726.                           T&SCALC
  1727.                           TRACK 
  1728.           8086/8088 Fig-FORTH User's Guide                    Page  36
  1729.  
  1730.  
  1731.  
  1732.  
  1733.  
  1734.                   5.3  High-level Extensions 
  1735.  
  1736.                   The following words were added  by  compiling  FORTH
  1737.                   screens and saving the new version  of  FORTH.   The
  1738.                   FORTH source is included in the screen files. 
  1739.  
  1740.                   ARRAY           n --                            :+ ARRAYS.SCR
  1741.                   2ARRAY          n1 n2 --                        :+ ARRAYS.SCR
  1742.                                   One  and  two  dimensional   integer
  1743.                   array defining words.  Used as:
  1744.  
  1745.                           3 10 ARRAY WEIGHTS
  1746.  
  1747.                   to define a 3 by 10 array of integers which  can  be
  1748.                   accessed by:
  1749.  
  1750.                           0 0 WEIGHTS @  2 9 WEIGHTS ! 
  1751.  
  1752.                   Which would replace the last element by the first. 
  1753.  
  1754.                   STRING          n --                            :+ ARRAYS.SCR
  1755.                   STRINGS         n1 n2 --                        :+ ARRAYS.SCR
  1756.                                   One and two dimensional  byte  array
  1757.                   defining words.  Similar to  the  array  definitions
  1758.                   above, but are accessed by C@ and C!. 
  1759.  
  1760.                   CASE    OF ENDOF        ENDCASE                 :+ CASE.SCR
  1761.                                   These words add a case construct  to
  1762.                   FORTH.   They  have  been  documented   in   several
  1763.                   different places.  Quite a few examples are found in
  1764.                   the ASSEMBLER screens. 
  1765.  
  1766.                   DUMP            addr1 -- addr2                  :+ UTIL.SCR
  1767.                                   This word displays the  contents  of
  1768.                   memory from addr1 to addr2-1.  The address  left  on
  1769.                   the stack can be used to  continue  dumping  without
  1770.                   having to keep track of the address.   The  dump  is
  1771.                   given in the current number base.  A variable  named
  1772.                   SEGMENT is used as the base, with addr1  then  being
  1773.                   an offset in that segment.  SEGMENT  is  initialized
  1774.                   to MYSEG. 
  1775.  
  1776.                   NEW             --                              :+ UTIL.SCR
  1777.                                   NEW updates the start-up  parameters
  1778.                   to reflect the current state of FORTH.  This  allows
  1779.                   compiled definitions to be  retained  when  COLD  is
  1780.                   executed.  Note that if you FORGET the  added  words
  1781.                   after executing NEW, the start-up parameters will be
  1782.                   wrong, and NEW must  be  run  again  before  a  cold
  1783.                   start. 
  1784.  
  1785.  
  1786.           8086/8088 Fig-FORTH User's Guide                    Page  37
  1787.  
  1788.  
  1789.  
  1790.                   SIZE?           --                              :+ UTIL.SCR
  1791.                                   Shows the current size of the  FORTH
  1792.                   dictionary, and the free space remaining.   This  is
  1793.                   primarily useful for saving modified FORTH's. 
  1794.  
  1795.           8086/8088 Fig-FORTH User's Guide                    Page  38
  1796.  
  1797.  
  1798.  
  1799.  
  1800.  
  1801.                   6  Future Extensions 
  1802.  
  1803.                   This version includes almost all of the extensions I
  1804.                   had planned to implement in the "immediate  future".
  1805.                   It will be work enough fixing bugs  and  tuning  the
  1806.                   revisions in  this  package,  without  shooting  for
  1807.                   major revisions. 
  1808.  
  1809.                   But, my list for  the  questionable  future  remains
  1810.                   intact:
  1811.  
  1812.                           Cross/target compiler
  1813.                           Code level floating point/8087 support
  1814.                           Multisegmented > 64K
  1815.                           Multitasking
  1816.                           Tree structured vocabularies/file system
  1817.                           High-level interrupt handling
  1818.  
  1819.                   Should any of  these  interest  you,  or  spark  any
  1820.                   comments,  I  would  be  happy  to  talk  or  trade.
  1821.                   Specifically, I would really love to have some  kind
  1822.                   of floating point package: this is  my  last  excuse
  1823.                   for writing ANYTHING in BASIC! 
  1824.  
  1825.                   The MACRO-86 assembler is really cumbersome at  this
  1826.                   kind of work, and FORTH is ideally suited to writing
  1827.                   new FORTH's.  If I can  get  metaFORTH  going,  that
  1828.                   would make a nice project...  
  1829.           8086/8088 Fig-FORTH User's Guide                    Page  39
  1830.  
  1831.  
  1832.  
  1833.  
  1834.  
  1835.                   7  FORTH sources 
  1836.  
  1837.                   The following are sources of  information  regarding
  1838.                   the implementation and use of FORTH. 
  1839.  
  1840.  
  1841.                 * STARTING FORTH, by Leo Brodie.  Prentice Hall 1981
  1842.                   This is  probably  the  best  introductory  book  on
  1843.                   FORTH. 
  1844.  
  1845.  
  1846.                 * Byte, vol.  5 no.  8, August 1980
  1847.                   This issue was devoted to FORTH, and  contains  good
  1848.                   discussions of defining words and FORTH internals. 
  1849.  
  1850.                 * Dr.  Dobb's Journal, vol.  6 no.  9, September 1980
  1851.                   Dr.  Dobb's Journal, vol.  7 no.  9, September 1981
  1852.                   These issues were both devoted to FORTH topics. 
  1853.  
  1854.                 * Various publications of the Forth Interest Group:
  1855.                   Fig  FORTH  Installation  Guide,  FORTH   DIMENSIONS
  1856.                   bi-monthly journal. 
  1857.  
  1858.                 * Mountain View Press
  1859.                   P.O.  Box 4656, Mountain View, CA 94040
  1860.                   (415) 961-4103
  1861.                   This company has a large selection of  software  and
  1862.                   publications for sale. 
  1863.  
  1864.  
  1865.           8086/8088 Fig-FORTH User's Guide                    Page  40
  1866.           Appendix A - Using execution vectors
  1867.  
  1868.  
  1869.  
  1870.  
  1871.  
  1872.                       Appendix A - Using execution vectors
  1873.  
  1874.  
  1875.  
  1876.           The i/o functions in this version of FORTH have been changed
  1877.           to use execution vectors.  An execution vector is  a  simple
  1878.           way to allow the user to substitute a different function for
  1879.           the function which is vectored in this way. 
  1880.  
  1881.  
  1882.           A.1  Concepts 
  1883.  
  1884.           The way an execution vector works is quite simple.   If  you
  1885.           are familiar with the concept of pointers to data,  this  is
  1886.           nothing new, for execution  vectors  are  only  pointers  to
  1887.           functions.  The pointer may be changed to hold  the  address
  1888.           of any function, and  as  long  as  the  specified  function
  1889.           expects and returns the same parameters and result,  no  one
  1890.           knows the difference. 
  1891.  
  1892.           The FORTH interpreter functions on this principle: it inputs
  1893.           a word, looks it up in the dictionary, and executes it.  The
  1894.           interpreter can totally ignore the action taken by the words
  1895.           it executes.  In standard FORTH, the function which executes
  1896.           a word is called EXEC.  The address that EXEC expects on the
  1897.           stack differs between FORTHs.   In  FIG-FORTH,  the  address
  1898.           must be a Code Field Address, or CFA.  The address  returned
  1899.           by the dictionary search words ( ' and -FIND) is a Parameter
  1900.           Field Address (PFA).   Thus,  to  look  up  a  word  in  the
  1901.           dictionary, you can type
  1902.  
  1903.                   ' MY-WORD
  1904.  
  1905.           but to find and execute MY-WORD, you would type
  1906.  
  1907.                   ' MY-WORD CFA EXEC
  1908.  
  1909.           This is totally equivalent to just typing MY-WORD. 
  1910.  
  1911.           In  this  way,  any  function  can  be  vectored  through  a
  1912.           variable: the variable holds the CFA of the function  to  be
  1913.           executed.  Instead of executing the function  directly,  the
  1914.           variable is fetched and the CFA stored  there  is  executed.
  1915.           Now, instead of jumping  directly  to  code  which  sends  a
  1916.           character to the console, KEY fetches the variable @KEY, and
  1917.           does whatever is at that CFA.  The definition of KEY is thus
  1918.  
  1919.                   : KEY @KEY @ EXEC ;
  1920.  
  1921.           To change the function of KEY, you just  store  a  different
  1922.           CFA in @KEY.  The new function can be defined after KEY, and
  1923.           any function which uses KEY will now call the new  function.
  1924.           The  danger  here  should  be  obvious:  if  the  substitute
  1925.           8086/8088 Fig-FORTH User's Guide                    Page  41
  1926.           Appendix A - Using execution vectors
  1927.  
  1928.  
  1929.  
  1930.           function doesn't have the same stack effects as the standard
  1931.           function, FORTH is going to get really confused. 
  1932.  
  1933.  
  1934.           A.2  An example 
  1935.  
  1936.           Although this arrangement  is  slightly  more  complex,  the
  1937.           power and flexibility make it well worth the  extra  effort.
  1938.           The following example should make this clear. 
  1939.  
  1940.           Suppose you want to do all input in  capital  letters  only.
  1941.           You could write  your  own  specialized  input  routine,  or
  1942.           simply define an upper-case-only version of KEY and redirect
  1943.           KEY to that function.  Here is the definition  for  the  new
  1944.           KEY:
  1945.  
  1946.                   : UC-KEY
  1947.                        (KEY) DUP 96 > OVER 123 < AND
  1948.                        IF ( a-z )
  1949.                           32 -
  1950.                        THEN ;
  1951.  
  1952.           Now all you have  to  do  is  set  @KEY  to  point  to  your
  1953.           function:
  1954.  
  1955.                   ' UC-KEY CFA @KEY ! 
  1956.  
  1957.           and any lower case letter will be converted automatically to
  1958.           upper case.  To restore KEY to the original action,  restore
  1959.           @KEY to (KEY):
  1960.  
  1961.                   ' (KEY) CFA @KEY ! 
  1962.  
  1963.           Note that UC-KEY still calls (KEY)  to  get  the  character.
  1964.           While this is usually the case, it  is  not  necessary:  you
  1965.           could change KEY to get characters from any  source.   Also,
  1966.           be careful that you don't call the  vectored  function  from
  1967.           within your replacement.  If KEY had been  used  instead  of
  1968.           (KEY)  in  the  definition  above,  once   @KEY   had   been
  1969.           re-assigned you  would  have  a  good  example  of  infinite
  1970.           recursion!  Actually it isn't infinite - FORTH  dies  rather
  1971.           quickly... 
  1972.  
  1973.           This discussion applies to all  of  the  i/o  words,  except
  1974.           ?TERMINAL.  The block i/o functions are re-assigned in  this
  1975.           way to use the screen files.  There are more elegant ways of
  1976.           implementing execution vectors, which bypass  the  need  for
  1977.           separate variables, but  they  require  new  defining  words
  1978.           which  would  have  been  inconvenient  to  define  in   the
  1979.           assembler source. 
  1980.  
  1981.           8086/8088 Fig-FORTH User's Guide                    Page  42
  1982.           Appendix B - Building FORTH.COM
  1983.  
  1984.  
  1985.  
  1986.  
  1987.  
  1988.                         Appendix B - Building FORTH.COM
  1989.  
  1990.  
  1991.  
  1992.           The following example serves several  functions.   It  is  a
  1993.           real session with FORTH, it shows how the FORTH.COM file was
  1994.           constructed, and, it demonstrates how to modify and save new
  1995.           versions of FORTH. 
  1996.  
  1997.           After assembling the FORTH source, you are left with a  bare
  1998.           kernel.  To add the  utilities,  editor  and  file  handling
  1999.           functions, several things have to be done:
  2000.  
  2001.                1) The file interface screens must be transferred to  a
  2002.                   FORTH disk.  This process involves  using  DEBUG  to
  2003.                   load the file and write it to the FORTH disk. 
  2004.  
  2005.                2) The file interface is LOADed from the FORTH disk. 
  2006.  
  2007.                3) The utilities and editor  are  /LOAD"ed  from  their
  2008.                   files. 
  2009.  
  2010.                4) FORTH is reset to make the additions permanent,  and
  2011.                   the version number is changed. 
  2012.  
  2013.                5) The utilities for saving FORTH are loaded  and  used
  2014.                   to write the new FORTH to a .COM file. 
  2015.  
  2016.           The following session was  copied  from  a  listing  of  the
  2017.           commands to build FORTH.COM.   An  ellipsis  indicates  that
  2018.           part of the listing has been left out. 
  2019.  
  2020.           This example assumes that you have a FORTH disk in drive  A,
  2021.           and your FORTH system disk with  FORTH.COM  and  the  screen
  2022.           files in drive B. 
  2023.  
  2024.  
  2025.  
  2026.  
  2027.  
  2028.                   B:DEBUG FILES.SCR
  2029.                   -W 100 0 0A 20
  2030.                   -Q
  2031.                   B:
  2032.  
  2033.           Here, DEBUG has loaded the MS-DOS file interface screens  in
  2034.           FILES.SCR and then written the screens to disk A starting at
  2035.           screen 10.  This assumes that one record holds  one  screen.
  2036.           You will have to adjust the record numbers if  this  is  not
  2037.           the case. 
  2038.  
  2039.           8086/8088 Fig-FORTH User's Guide                    Page  43
  2040.           Appendix B - Building FORTH.COM
  2041.  
  2042.  
  2043.  
  2044.                   B:4TH
  2045.  
  2046.                   8086 Fig-FORTH Version 1.0A
  2047.                   11 LOAD 13 LOAD BYE MSG # 4 ok
  2048.                   LATEST ID.  LOAD" ok
  2049.  
  2050.           The newly copied screens residing on disk A are loaded,  the
  2051.           last word now being LOAD".  The first screen loaded  is  11,
  2052.           since the first screen in FILES.SCR is screen 0,  and  can't
  2053.           be LOADed. 
  2054.  
  2055.  
  2056.  
  2057.  
  2058.  
  2059.                   USING" FUTIL" last block in B:FUTIL.SCR is 10 ok
  2060.                   1 LOAD .DIR MSG # 4 ok
  2061.                   2 LOAD ok
  2062.                   3 LOAD ok
  2063.                   7 LOAD ok
  2064.                   LATEST ID.  COPY>SCR ok
  2065.                   EOF B:FUTIL .SCR 11264 07-19-1983 2:37 ok
  2066.  
  2067.           The file interface allows FORTH to  use  the  screen  files.
  2068.           The utilities for listing the directory  and  erasing  files
  2069.           are loaded.  Also, the words for copying screens to and from
  2070.           FORTH disks are loaded from screen 7. 
  2071.  
  2072.  
  2073.  
  2074.  
  2075.  
  2076.                   USING" UTIL" last block in B:UTIL.SCR is 8 ok
  2077.                   8 LOAD ok
  2078.                   3 LOAD 4 LOAD 6 LOAD ok
  2079.                   WORDS
  2080.  
  2081.                   CURRENT and CONTEXT are FORTH
  2082.                   WORDS   TAB     TABSTOP MORE?   DLIST   NEW     SIZE? 
  2083.                   BASE?   VOC?    VOC.    S?      DEPTH   ENDCASE ENDOF
  2084.                   OF      CASE    #SCRCOPY        SCRCOPY ASSIGN-BUF
  2085.                   COPY>SCR        COPY>FILE       PAUSE   ERASE"
  2086.                   . 
  2087.                   . 
  2088.                   . 
  2089.                   EOF B:UTIL .SCR 9216 07-20-1983 19:18 ok
  2090.  
  2091.           More utilities, including  NEW  to  update  the  COLD  start
  2092.           parameters, are loaded  from  the  UTIL  screen  file.   The
  2093.           vocabulary listing word WORDS is tested, and then  the  file
  2094.           is closed. 
  2095.  
  2096.           8086/8088 Fig-FORTH User's Guide                    Page  44
  2097.           Appendix B - Building FORTH.COM
  2098.  
  2099.  
  2100.  
  2101.                   LOAD" EDITOR" last block in B:EDITOR.SCR is 6
  2102.  
  2103.                           FORTH, Inc.  editor
  2104.                   . 
  2105.                   . 
  2106.                   . 
  2107.                           editor loading, please wait... 
  2108.  
  2109.                   I MSG # 4 R MSG # 4
  2110.  
  2111.                   Current screen is 8 B:EDITOR .SCR 7168 07-19-83 2:53 ok
  2112.  
  2113.           The editor described in STARTING FORTH is loaded.  Note that
  2114.           LOAD" first lists screen 0, then begins loading at screen 1,
  2115.           and finally closes the file when the load is complete. 
  2116.  
  2117.  
  2118.  
  2119.  
  2120.  
  2121.                   NEW
  2122.                   current version is A
  2123.                   new version (A-Z)? Bok
  2124.                   USING" FUTIL" last block in B:FUTIL.SCR is 10 ok
  2125.                   4 LOAD ok
  2126.                   EOF B:FUTIL .SCR 11264 07-20-1983 19:32 ok
  2127.  
  2128.           Here, the utilities to save FORTH are loaded.  Note that any
  2129.           words defined after executing NEW will not  be  saved,  and,
  2130.           that the file is closed before writing the new version. 
  2131.  
  2132.                   >FILE S4 ok
  2133.                   S4 /SAVE-FORTH" FORTH.COM"
  2134.                   B:FORTH .COM - w c 13687 07-20-1983 19:41 ok
  2135.                    ok
  2136.                   BYE
  2137.                   B:FORTH
  2138.  
  2139.                   8086 Fig-FORTH Version 1.0B
  2140.                   WORDS
  2141.  
  2142.                   WHERE   EDITOR  LINE    TEXT    WORDS... 
  2143.  
  2144.                   EDITOR WORDS
  2145.  
  2146.                   r       u       i       s       f... 
  2147.  
  2148.                   BYE
  2149.