home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_GEN / FORTH_86.ZIP / MANUAL.4TH < prev    next >
Text File  |  1993-12-09  |  48KB  |  1,291 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.     Getting Started
  9.  
  10.            For beginners                                                  1
  11.            Disassembler                                                   2
  12.  
  13.            Entering Numeric values                                        2
  14.            Printing strings                                               3
  15.            Numerics in strings                                            3
  16.            Printing Numeric values                                        3
  17.  
  18.            Defining new words                                             5
  19.            LINK                                                           5
  20.            Using the editor                                               6
  21.            Comments in Code                                              18
  22.  
  23.     Debug utilities
  24.  
  25.            Dumping memory and stack                                       8
  26.            Dump Dictionary                                                8
  27.            DEBUG; TRACEON; TAG                                            8
  28.            TRACEL                                                         9
  29.  
  30.            TM, TD, and SYNONYM                                            9
  31.            differences from normal                                       10
  32.  
  33.     Variables and Constants                                              12
  34.  
  35.            BLOCK                                                         12
  36.            CONST                                                         12
  37.            ,CONST ( comma const)                                         13
  38.  
  39.     Other Words
  40.  
  41.            FLOAD                                                         15
  42.            ON REDEFINE                                                   15
  43.            OFF PRINTLOAD                                                 15
  44.            OMIT                                                          16
  45.  
  46.     Writing Assembly code
  47.  
  48.            BLOAD                                                         15
  49.            :EXIT and :ENTER                                              16
  50.            Inline Assembler                                              16
  51.  
  52.     Cross Compile Mode
  53.  
  54.            CROSS-COMPILE & UNCROSS                                       17
  55.            LOAD & ISAVE                                                  17
  56.            STATUS                                                        19
  57.            MAP                                                           19
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.                                               
  65.  
  66.                                     4TH_86 
  67.             ( based upon United Controls Corporation CP/M80 Forth.) 
  68.  
  69.  
  70.                    Translated for IBM PC with EGA graphics. 
  71.  
  72.  
  73.                       ( Demo ) Version 4.01 December 1993
  74.                                       by 
  75.  
  76.                                   M.F.Buchan 
  77.  
  78.                     Kinnell House 1 Argyle Place, Rothesay, 
  79.                             Isle of Bute, PA20 0AZ, 
  80.                                 Scotland, U.K. 
  81.  
  82.                              Voice:  44-700-505185 
  83.                              Fax:    44-700-504051 
  84.  
  85.                              Compuserve 100012,651 
  86.                      Internet: larryb@rothesay.demon.co.uk 
  87.  
  88.  
  89.             Translation Copyright (c) 1988, 1989, 1993, M.F.Buchan 
  90.  
  91.            Original Copyright (c) 1982 United Controls  Corporation, 
  92.                              Huntsville, Alabama. 
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.      4th_86                    GETTING STARTED                       page 1
  100.     
  101.            The manual provided with this demo version is limited in
  102.     content. The full manual is being updated at the moment and will be
  103.     available with registered versions.
  104.  
  105.            ===============
  106.            Getting Started
  107.            ===============
  108.  
  109.            The registered package provides three versions of the system.
  110.     4TH_86.COM, 4TH_86DD.COM, and 4TH_86FP.COM. The first is a very minimal
  111.     system with no disassembler; DOS shell; etc. 4TH86DD has everything
  112.     except floating point; double precision; and transcendental functions.
  113.     These are added to create 4TH_86FP.COM.
  114.  
  115.            The downloadable demonstration version 4TH86DEM.COM is
  116.     essentially the same as 4TH_86FP.COM -- but starts in tutorial mode --
  117.     uses only page0 video as default -- has additional promotional text
  118.     added -- a 10 second delay on exit -- and has certain other limitations
  119.     as a consequence.
  120.  
  121.            From the DOS prompt, type 4TH86DEM <return> and you will be in
  122.     4th_86.  If you want to get back to DOS, type BYE. (QUIT has been re-
  123.     named to Q-U-IT as it is no longer a preferred exit word]
  124.  
  125.            If you are using the DEMO version you will be automatically
  126.     placed in the split-screen tutorial mode. To exit this type UNSPLIT.
  127.     The tutorial can always be re-entered at any time by typing HELP.
  128.  
  129.            The system words DIR and TYPE can be used from within 4th_86 and
  130.     paths are now implemented. Drive letters from A: through D: are
  131.     implemented and can be used alone to change default drive, or as prefix
  132.     with DIR and TYPE. CD can be used to change directory, but facilities
  133.     like MD, RD, and REName and COPY are done by shelling to DOS first,
  134.     using the word SYS
  135.  
  136.            The screen contents can be dumped to printer using the normal
  137.     IBM-PC keyboard keys SHIFT PRTSC. Also CTRL-P will toggle on and off
  138.     duplication of screen output to printer.
  139.  
  140.            =============
  141.            For beginners
  142.            =============
  143.  
  144.            If you are not familiar at all with FORTH as a language, then a
  145.     good book to read is FORTH: A text and Reference by Mahlon G. Kelly and
  146.     Nicholas Spies -- Prentice Hall -- 1986.
  147.  
  148.            The following tutorial is not dificult to follow however, and
  149.     you should work through it as the specific features which make this
  150.     implementation unique will not be covered in any general text book.
  151.     You also have the built in help facility.
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.      4th_86                    GETTING STARTED                       page 2
  159.     
  160.            The screen display will be easier to follow if you exit from the
  161.     default tutorial mode -- by typing FULLSCREEN -- before you try any of
  162.     the following.
  163.  
  164.            Before we get into the basics of FORTH -- let's just have a
  165.     quick look at the disassembler in order to become familiar with its
  166.     use. This disassembler will be of enormous help when you come to write
  167.     your first FORTH definitions of - as they are called - "words".
  168.  
  169.            ============
  170.            Disassembler
  171.            ============
  172.  
  173.            "DD" is the 4th_86 word which calls up the diassembler. It must
  174.     be followed by the word you want to disassemble.
  175.  
  176.            To show the use of the disassembler, let us see how the word BYE
  177.     is made up. Type DD BYE and then press <return>. This will show you
  178.     that BYE makes use of several other Forth words such as PAGE0, BRKON,
  179.     SECDELAY.
  180.  
  181.            Look at each of these words by typing DD PAGE0 etc. Unlike BYE
  182.     itself - you will see that PAGE0 and BRKON are pure assembly code.
  183.     SECDELAY is interesting in that most of it is assembly code -- but a
  184.     part in the middle is Forth code. It is quite simple to mix assembly
  185.     and Forth source in this manner. The actual source code for SECDELAY is
  186.     provided on disk.
  187.  
  188.            You can also try DD THREAD, DD COLON, and DD SRET if you wish.
  189.     In fact you can type DD followed by any 4th_86 word and it will be
  190.     disassembled.
  191.  
  192.            Perhaps a better word to demonstrate how Forth and Assembly can
  193.     be mixed is the word GC. Type DD GC and then use ctrl-S to pause and
  194.     start the display.
  195.  
  196.            You may get OOPS displayed in the disassembly -- and this simply
  197.     means that the word which ** should ** appear there has been removed
  198.     from the dictionary. There are two reasons for doing this -- to save
  199.     space -- and because a ** very ** large number of the words needed to
  200.     build up the system from source are of no use at all in normal use.
  201.  
  202.            You can not of course disassemble any word which has been
  203.     removed from the dictionary.
  204.  
  205.            The display can be "aborted" at any time by pressing the space
  206.     bar. Ctrl-S will start and stop the display.
  207.  
  208.            Ctrl-C and Ctrl-Brk are normally disabled, as using them would
  209.     dump you back into DOS. The word BRKON turns the ctrl-Brk facility on
  210.     again.
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.      4th_86                    GETTING STARTED                       page 3
  218.     
  219.            =======================
  220.            Entering Numeric Values
  221.            =======================
  222.  
  223.            Here is one place that 4th_86 differs from all other Forths.
  224.     Numbers can be input in Hex, Binary, Decimal or Octal. In 4th_86
  225.     considerable flexibility is introduced by using the same notation as
  226.     when writing ASM code -- a suffix after the number -- 123H -- 123Q ( or
  227.     123O) -- 11011B for Hex, Octal, Binary respectively.
  228.  
  229.            Decimal is the default, so for 123 decimal just type in 123.
  230.     ASCII values can be inserted as "A" rather than 41H -- or "B" "C" "D"
  231.     etc.
  232.  
  233.            ================
  234.            Printing Strings
  235.            ================
  236.  
  237.            Unlike standard Forths, the dot-quote word  (  ."  ) does not
  238.     double as part of the initial string quote. It is a separate word.
  239.  
  240.            4th_86 =>        " this is a test" ."
  241.            Other Forths =>  ."this is a test"
  242.  
  243.            Note also that in 4th_86 a space is needed between the first
  244.     quote sign and the start of the string text. This is because the
  245.     leading " is a Forth word just like any other word. The closing " is
  246.     not a word -- it is an end of string delimiter.
  247.  
  248.            ===================
  249.            Numerics in Strings
  250.            ===================
  251.  
  252.            String values are entered between quotes
  253.  
  254.            " this is a test"
  255.  
  256.           If it is required to enter specific numeric bytes as part of the
  257.     string -- for example 0D Hex and 0A Hex -- this is done by using the
  258.     up-arrow ^
  259.  
  260.            " ^0dh 0ah^this is a test"
  261.            or   " ^13 10^this is a test"
  262.  
  263.  
  264.            The result of course is the same as
  265.  
  266.            crlf " this is a test"
  267.  
  268.            There is a file on disk called FRENCH.4TH which can be loaded [
  269.     type FLOAD FRENCH.4th ] and will demonstrate how special accented
  270.     characters and ascii graphics can be displayed.
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.      4th_86                    GETTING STARTED                       page 4
  278.     
  279.            =======================
  280.            Printing Numeric Values
  281.            =======================
  282.  
  283.            To print out the value on the TOS (top of stack) the operators
  284.     .H .L .HB .C and . are provided.
  285.  
  286.            .H prints a word in Hex with a leading space. .HB prints a byte
  287.     in Hex with leading space. A single period  . prints the TOS in decimal
  288.     with a leading space.
  289.  
  290.            .C prints the ASCII character if one exists -- but with no
  291.     leading space.
  292.  
  293.            .L is the same as . but without a leading space. It's main
  294.     purpose is for sending ANSI control codes requiring numeric parameters.
  295.     A leading space would invalidate the ANSI sequence.
  296.  
  297.            Try the following at the 4th86 prompt
  298.  
  299.            20H 16 "C" + + dup .H crlf dup . crlf 30H - .C
  300.  
  301.            Try also the following
  302.  
  303.            20H 16 "C" + + dup .h 3 spcs dup . 3 spcs 30h - .c
  304.  
  305.            In normal Forths different number bases can not be mixed. It is
  306.     necessary to define a variable BASE as either HEX DECIMAL etc. 4th_86
  307.     does not have this clumsy restriction.
  308.  
  309.  
  310.            Whilst there used to be a variable called BASE in 4th_86 it had
  311.     nothing to do with number bases, and was never used in normal events.
  312.     It was the relocation offset used when meta-compiling stand-alone COM
  313.     programs. It is no longer used in version 4.01.
  314.  
  315.            You may have noticed that to the left of the 4th_86 ■  prompt
  316.     there is a highlighted number, which is usually _0_
  317.  
  318.            This number represents the total number of two byte values
  319.     pushed on the data stack. ( It can become negative if stack underflow
  320.     takes place )
  321.  
  322.            Try typing in numbers 2 <return> 3 <return> 4567 <return> A"
  323.     <return>  and watching the depth  indication increase.
  324.  
  325.            Now print out the stack values one at a time with . . . (or if
  326.     you prefer it .H  .H  .H ) and note the depth indication decrease.
  327.  
  328.            If you print out a value when the stack is empty you will get a
  329.     negative value of depth display.
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.      4th_86                    GETTING STARTED                       page 5
  337.     
  338.            One feature of all FORTHs is that an unrecognised entry clears
  339.     the stack and most other transient variables.
  340.  
  341.            Type in 2  3  4  5  <return> to get some values on the stack,
  342.     then type  sgkdfshk <return> [ or some other garbage entry ] and the
  343.     depth display will become zero.
  344.  
  345.            In addition to the auto-depth display, the word DEPTH is
  346.     available to use within definitions.
  347.  
  348.  
  349.            ==================
  350.            Defining new words
  351.            ==================
  352.  
  353.            Type   : Fred 3 . ;
  354.  
  355.            This defines a word Fred -- which simply prints the value 3
  356.            Type  FRED (or fred FrEd fREd) and you will see  3  printed
  357.            (out of curiosity, disassemble with DD FRED )
  358.  
  359.            Type   : Fred 4 . ;
  360.  
  361.            You will be asked if you want to redefine Fred -- answer Y
  362.            Type FRED and and you will see that  4  is now printed instead
  363.            of 3
  364.  
  365.            Now type
  366.                     : Larry 4 ;
  367.                     : Tom Larry 2 * . ; and then type TOM
  368.  
  369.            You should get an 8 printed -- Larry -- which is 4 -- has been
  370.            multiplied by 2
  371.  
  372.            Let's redefine LARRY
  373.  
  374.                     : Larry 6 ;      ( and of course answer Y )
  375.  
  376.            Now type TOM --- and you will find that you do not get 12
  377.     printed - you still get 8.
  378.  
  379.            The redefinition of LARRY from 4 to 6 has not affected the prior
  380.     definition of TOM. This is the normal way with Forth. When TOM was
  381.     defined -- it used the IMMEDIATELY PRIOR defined value of LARRY. The
  382.     redefinition of LARRY ** after ** the definition of TOM does not affect
  383.     TOM's use of the original LARRY definition.
  384.  
  385.            A clearer picture of all the words you have entered can be seen
  386.     if you type DDICT.
  387.  
  388.                   Now let's see how we can actually replace the old
  389.     definition with a new one.
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.      4th_86                    GETTING STARTED                       page 6
  397.     
  398.            ====
  399.            LINK
  400.            ====
  401.  
  402.            Type DD LARRY  and you will see the constant 6
  403.  
  404.            type FORGET LARRY  and then DD LARRY and you will see that we
  405.     are now back to our original definition of LARRY as the value 4
  406.  
  407.            type  : KEN 6 ;
  408.  
  409.            LINK LARRY KEN     ( ignore the warning message )
  410.  
  411.            TOM
  412.  
  413.            you should get the value 12 printed. All calls to the last LARRY
  414.            are now diverted to KEN instead. Try DD LARRY and DD KEN.
  415.  
  416.  
  417.            The last word linked can be restored with UNLINK
  418.  
  419.            Type UNLINK   which unlinks LARRY from KEN
  420.            type  TOM  and you should get 8
  421.            type DD TOM   DD KEN  and  DD LARRY to confirm
  422.  
  423.            ================
  424.            Using the editor
  425.            ================
  426.  
  427.            Make sure you have read and implemented the instructions in
  428.     INTRO.4TH for configuriing EDITR.BAT and ASMBL.BAT.
  429.  
  430.                   You must first tell 4th_86 the name of the file you want
  431.     to edit. The default name built into 4th_86 is EDHELP.TXT -- so if you
  432.     type EDIT you should get this help message displayed by your editor.
  433.  
  434.            The word USING allows you to change the default file name to
  435.     another one. To edit a different file -- say  SQ.4TH -- first type
  436.     USING SQ.4TH -- then all future uses of the word EDIT (and the words
  437.     REDIT and RELOAD) will call up the file SQ.4TH.
  438.  
  439.            The editor is designed to be much more flexible than this
  440.     however. After editing a Forth source file, the normal procedure would
  441.     be to re-load it for testing and debugging. For this purpose, the words
  442.     RELOAD and REDIT exist.
  443.  
  444.  
  445.            RELOAD behaves the same as FLOAD except that it uses the name
  446.     already specified by USING. Therefore
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.      4th_86                    GETTING STARTED                       page 7
  454.     
  455.            FLOAD SQ.4TH is the same as having executed USING SQ.4TH and
  456.     then executing RELOAD
  457.  
  458.            REDIT also uses the name specified by the previous USING and is
  459.     equivalent to  EDIT followed by RELOAD.
  460.  
  461.            The normal edit => fload => test => re-edit cycle is simplified
  462.  
  463.            Try        USING SQ.4th
  464.                       FLOAD SQ.4th
  465.                       DD OSQUARE
  466.  
  467.            REDIT
  468.            <==> DD OSQUARE
  469.  
  470.            REDIT
  471.            <==> DD OSQUARE   where <==> are the steps to exit from
  472.            the editor you are using.
  473.  
  474.            You will see by the addresses attached to the DD disassembly
  475.            that each REDIT redefines a new OSQUARE, getting higher and
  476.            higher in memory.
  477.  
  478.            To confirm this -- type DDICT and examine how many copies of the
  479.            word OSQUARE you have loaded.
  480.  
  481.                   This multiple redefinition can be avoided by defining a
  482.     dummy word -- say STRT -- and starting your source file with FORGET
  483.     STRT
  484.            Try
  485.  
  486.            USING SQ.4TH
  487.            : STRT ;
  488.            FLOAD SQ.4TH
  489.            DD OSQUARE
  490.  
  491.            REDIT
  492.            <==> DD OSQUARE
  493.            now the re-load of the newly edited file SQ.4TH
  494.            causes deletion of the previously loaded file.
  495.  
  496.            Following this tutorial should now be much easier as a hands-on
  497.     process. Instead of trying to key into 4th_86 lengthy definitions
  498.     directly from the keyboard, they can be edited into a test file, and
  499.     the file loaded.
  500.  
  501.            Lower and upper case are equivalent, whether entered from the
  502.     keyboard or floaded from a file. Of course, case in quoted strings is
  503.     preserved
  504.  
  505.            " Hey There" ." will be printed   Hey There  - not capitalized
  506.            nor all lower case.
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.      4th_86                    GETTING STARTED                       page 8
  514.     
  515.            ========================
  516.            Dumping memory and stack
  517.            ========================
  518.  
  519.  
  520.            DM  8DM  and 16DM are memory dumps -- try 2000H 8DM  etc.
  521.  
  522.            NOTE that there is a number left on the stack after the dump is
  523.     completed. Use .H to display this value and you will see that it is
  524.     2080H. The purpose of this is so that the dump can be continued simply
  525.     by typing 8DM again [ or 16DM or whatever ].
  526.  
  527.            DS and DDS are stack dumps
  528.  
  529.            try   2 3 4 5 DS <return>
  530.            DS  <return> DS <return>
  531.            DDS <return> DS <return>
  532.  
  533.            DS prints out the stack values, and leaves them unchanged
  534.            DDS (destructive dump stack) prints the values and removes them
  535.  
  536.  
  537.            try   2 3 4 5 <return> DS <return> abcd <return>  DS <return>
  538.  
  539.            this is a convenient way to clear and reset the stack -- type in
  540.     any meaningless phrase (i.e. - abcd), press return, and the error
  541.     message clears the stack.
  542.  
  543.            ===============
  544.            Dump Dictionary
  545.            ===============
  546.  
  547.            Type DDICT and you will be presented with a display of the words
  548.     in the dictionary, together with the address of the dictionary entry
  549.     and flag byte (high segment ) and the start offset of the code area (
  550.     low segment ). The display has now been arranged to pause every 15
  551.     items. RETURN produces the next 15 entries. Any other keypress aborts.
  552.  
  553.            Type PDICT DUP and instead of returning all the words in the
  554.     dictionary, you will just get the addresses for the word DUP.
  555.  
  556.            ===================
  557.            DEBUG; TRACEON; TAG
  558.            ===================
  559.  
  560.            We already have TOM defined
  561.  
  562.            Type TRACEON TOM  and then TOM
  563.  
  564.            the word is traced, and stack values are displayed
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.      4th_86                    GETTING STARTED                       page 9
  572.     
  573.            TRACEOFF removes the trace, and TAG (trace-again) restores it
  574.  
  575.            applying TRACEON to another word automatically removes it from
  576.     the old one
  577.  
  578.            any errors -- as well as clearing the stack -- also remove
  579.     TRACEON
  580.  
  581.  
  582.            DEBUG is an on/off toggle.
  583.  
  584.            type TRACEOFF to be sure -- and then type DEBUG  ( to toggle
  585.     debug on)
  586.  
  587.            now type   3 4 5 6 <return>
  588.            . .    <return>
  589.            DDS    (return>
  590.            DEBUG ( to toggle it off)
  591.  
  592.            this display of stack contents is useful.
  593.  
  594.  
  595.  
  596.            ======
  597.            TRACEL
  598.            ======
  599.  
  600.            This is Trace-level and is used for tracing DO...LOOP structures
  601.  
  602.            Type   : SLOOPY  5 0 do I . loop ;
  603.  
  604.            then run it by typing SLOOPY
  605.            you should get  0 1 2 3 4 5  displayed on the screen
  606.  
  607.            now   TRACEON SLOOPY
  608.            SLOOPY   -------- not very impressive
  609.  
  610.            3 TRACEL
  611.            SLOOPY  ---- somewhat better ???
  612.  
  613.  
  614.            ===============
  615.            TM; TD; SYNONYM
  616.            ===============
  617.  
  618.            Type TM and the time will be shown
  619.  
  620.            Type TD <return> and then TD <return> again.
  621.            the elapsed time between the two events is shown
  622.  
  623.            Try  : dly1 1000 0 do loop ;
  624.            : dly td 10 0 do dly1 loop crlf td crlf ;
  625.  
  626.  
  627.  
  628.  
  629.  
  630.  
  631.      4th_86                     GETTING STARTED                     page 10
  632.     
  633.            then run by typing DLY.
  634.  
  635.            The SECOND line shows the elapsed time to complete the word DLY
  636.     -- measured between the first TD and the second TD.
  637.  
  638.            No -- indeed this system is not as fast as many others -- but at
  639.     the moment speed is not the objective. The objective is a user-friendly
  640.     interface which will allow ease of code writing and learning for
  641.     beginners.
  642.  
  643.            So you think TM is too terse and non-standard?
  644.  
  645.            well try   SYNONYM TIMEELAPSED TD
  646.  
  647.            and type TIMEELAPSED -- purists can build synonyms for any word
  648.            they think "non-standard" (or modify the source) and create  a
  649.            new system file using SAVESYS.
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.      4th_86                     GETTING STARTED                     page 11
  657.     
  658.  
  659.            =======================
  660.            differences from normal
  661.            =======================
  662.  
  663.            4th_86 is different from other implementations of FORTH in
  664.     several ways. Some of the differences are because of the targeted
  665.     applications of FORTH such as the fact that the dictionary is stored
  666.     separately from the code so compact stand-alone code can be generated.
  667.     Other differences arise because of adding features not commonly found
  668.     in other FORTHs, different naming conventions, and different
  669.     philosophies in the implementation.
  670.  
  671.            Listed below are some of the minor differences that may
  672.     "disturb" the user of a more conventional FORTH. SYNONYMS or short
  673.     words can be used to re-define the more familiar names. For example:
  674.  
  675.            SYNONYM  EMIT  .C
  676.  
  677.            or
  678.  
  679.            : KEY 0 BEGIN DROP 255 6 MON2 DUP END ;
  680.  
  681.            After the table below is a discussion of several more
  682.     significant differences.
  683.  
  684.            Many FORTHs         4th_86           exact
  685.                               Equivalent       replacement
  686.  
  687.            C@                      B@
  688.            C!                      B!
  689.            EMIT                    .C
  690.  
  691.            KEY                                  0 BEGIN
  692.                                              DROP 255 6 MON2 DUP
  693.                                                     GETCHR  END
  694.  
  695.            TYPE                                 1 DO DUPB@ .C
  696.                                                    1+ LOOP DROP  ."
  697.  
  698.            VARIABLE              DATA[ ...]
  699.            CONSTANT              CONST
  700.            ."string"           " string" ."
  701.            ABORT" string"      " string" 1 ERMSG
  702.            LEAVE                 EXIT
  703.            BEGIN..UNTIL          BEGIN...END
  704.            BEGIN..WHILE..REPEAT  REPEAT..WHILE..ENDWHILE
  705.            D+  D=  etc.          ,+  ,=  etc.
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.      4th_86                     GETTING STARTED                     page 12
  713.     
  714.            In 4th_86, DO..LOOPs terminate when the loop count is exceeded,
  715.     not equaled.  Also in most FORTHs, the loop is always executed at least
  716.     once, while in 4th_86 the loop index is checked against the limit
  717.     before the loop is executed (loop skipped if limit exceeds maximum). In
  718.     4th_86, loops cannot use negative increments, When the word EXIT
  719.     (corresponds to LEAVE) is executed, the loop is exited immediately
  720.     (most FORTHS set the loop limit equal to the current loop index).
  721.  
  722.            The file SHARPS.4th contains source for double precision
  723.     formatted output routines -- it also includes a self loading and
  724.     executing demonstration of these.
  725.  
  726.            CREATE...DOES is not included as such, but the file ARRAY.4th
  727.     shows how defining words can be created. This file also contains a self
  728.     exeuting demonstration.
  729.  
  730.  
  731.            =======================
  732.            Variables and Constants
  733.            =======================
  734.  
  735.  
  736.            BLOCK
  737.            =====
  738.  
  739.            Purpose: Reserves a block of contiguous memory where
  740.            the size of the block is on the TOS and the name of the
  741.            block is the next word. When the name is executed, the
  742.            address of the block of memory associated with it is
  743.            placed on the stack.
  744.  
  745.            ?? block_size --- ??  ( when BLOCK is executed )
  746.  
  747.            ?? --- ?? address     ( when the name of the block
  748.            is executed )
  749.  
  750.            Example:   Reserve 25 bytes of memory and name it
  751.            BUFFER.
  752.            25 BLOCK BUFFER ( A buffer which is 25 bytes long )
  753.  
  754.            Example:  Assume that the address of BUFFER is 453EH.
  755.            Using the word .H print the address of BUFFER.
  756.  
  757.            BUFFER .H
  758.            453E   ( this is printed on the console )
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765.         4th_86              CONSTANTS AND VARIABLES                 page 13
  766.     
  767.            CONST
  768.            =====
  769.  
  770.            Purpose: Defines a constant whose value is on TOS and
  771.            name follows CONST. When the name is executed, the
  772.            value associated with that name is placed on TOS. Only
  773.            single precision integers may be used as the value of a
  774.            constant.
  775.  
  776.            ?? value -- ?? ( when CONST is executed )
  777.            ?? -- ?? value ( when name of constant is executed )
  778.  
  779.            Example: Define the constant B_SIZE whose value is
  780.            1100. Also, using the word . print the value of SIZE.
  781.  
  782.            1100 CONST B_SIZE
  783.            B_SIZE .
  784.            1100  ( this is printed on console )
  785.  
  786.  
  787.  
  788.  
  789.            ,CONST ( comma const)
  790.            ======
  791.  
  792.            Purpose: ,CONST is similar to CONST except a double
  793.            precision constant is defined.
  794.  
  795.            ?? --- ??
  796.  
  797.            Format: value ,CONST name
  798.  
  799.  
  800.  
  801.            DATA[ ( data left bracket)
  802.            ======
  803.  
  804.            Purpose: Defines a block of memory with the values
  805.            between DATA[ and ] with the name of the block
  806.            following ]. The values may be:
  807.  
  808.            1. one byte integers
  809.            2. two byte integers
  810.            3. strings with a length byte
  811.            4. strings without a length byte
  812.  
  813.  
  814.            When the name of the block is executed, the address of
  815.            the block associated with the name is placed on the TOS
  816.  
  817.  
  818.  
  819.  
  820.  
  821.  
  822.         4th_86              CONSTANTS AND VARIABLES                 page 14
  823.     
  824.            There are special words which allow the data type to
  825.            vary as mentioned above. The words are:
  826.  
  827.            BYTE
  828.            WORD
  829.            LENGTH
  830.            NOLENGTH
  831.  
  832.            and are respective to the meanings 1 through 4 above.
  833.            The defaults are WORD and LENGTH. When these words are
  834.            detected, all remaining values have the same data type
  835.            until either a new defining data  type is encountered
  836.            or a ] is found, which ever comes first. Note that '
  837.            and " can be used in DATA[
  838.  
  839.            ?? --- ??
  840.            Example: Define TABLE whose values and format are:
  841.  
  842.            145          ( one byte)
  843.            5394         ( one byte)
  844.            13           ( two bytes)
  845.            " HI"        ( with length byte)
  846.            423EH        ( two bytes)
  847.            " HELLO"     ( no length byte)
  848.  
  849.            and write a word, TEST which prints each value one per
  850.            line.
  851.  
  852.            DATA[ BYTE 145 5394
  853.            WORD 13
  854.            LENGTH " HI"
  855.            WORD 423EH
  856.            NOLENGTH " HELLO" ] TABLE
  857.  
  858.            : TEST
  859.            TABLE DUPB@ . CRLF
  860.            1+ DUPB@ . CRLF
  861.            1+ DUP@ . CRLF
  862.            2+ DUP 4 + SWAP DO
  863.            DUPB@ + 1+ DUP@ .H CRLF
  864.            2+ DUP 4 + SWAP DO
  865.            I B@ ." LOOP ;
  866.  
  867.            TEST
  868.            145
  869.            18
  870.            13 HI
  871.            423E
  872.            HELLO
  873.  
  874.  
  875.  
  876.  
  877.  
  878.  
  879.      4th_86                 OTHER WORDS & FEATURES                  page 15
  880.     
  881.            =====
  882.            FLOAD
  883.            =====
  884.  
  885.            This has already been described. An alternative to FLOAD
  886.     FILE.ABC would be   " FILE.ABC" LOAD. The use of the word FLOAD avoids
  887.     the need for string quotes.
  888.  
  889.            ON REDEFINE
  890.            ============
  891.  
  892.            REDEFINE is a flag which determines whether the compiler will
  893.     give a warning or not when a re-definition is encountered. ON REDEFINE
  894.     allows words to be redefined without warning. OFF REDEFINE causes
  895.     warning messages.
  896.  
  897.            OFF PRINTLOAD
  898.            =============
  899.  
  900.            PRINTLOAD is a flag which determines whether the file will be
  901.     listed on the screen as it is loaded. OFF PRINTLOAD allows the file to
  902.     load without being displayed on the screen. ON and OFF PRINTLOAD can be
  903.     scattered throughout a file if parts are to be observed during loading
  904.     -- as indeed can ON and OFF REDEFINE.
  905.  
  906.            =====
  907.            BLOAD
  908.            =====
  909.  
  910.            BLOAD is used for COM files created by MASM. It does ** NOT **
  911.     check for re-definition so care is needed not to duplicate words.
  912.  
  913.            This feature has been briefly described in INTRO.4TH and will
  914.     not be elaborated in this shortened manual. In-line assembly is
  915.     available and will normally be the preferred method.
  916.  
  917.            There is however a file TEST.ASM provided, which you can use [
  918.     issue the command BLOAD TEST --- do **not** use the .ASM suffix ]. The
  919.     first time you BLOAD this file it will automatically compile into
  920.     TEST.BIN [ provided you have configured ASMBL.BAT properly ] and then
  921.     load the TEST.BIN into 4th_86.
  922.  
  923.             By examining the source for TEST.ASM you will see that it
  924.     defines three words FIRST SECOND and THIRD. If you execute these words
  925.     they each print a message.
  926.  
  927.            BLOAD only compiles the target file into BIN if there is no BIN
  928.     file already existing -- or if its date is earlier than that of the ASM
  929.     file. If you use BLOAD TEST again it will no longer compile TEST.ASM --
  930.     unless you delete TEST.BIN first -- or edit TEST.ASM to give it a later
  931.     date.
  932.  
  933.  
  934.  
  935.  
  936.  
  937.  
  938.      4th_86                 OTHER WORDS & FEATURES                  page 16
  939.     
  940.            ================
  941.            :EXIT and :ENTER
  942.            ================
  943.  
  944.            These allow changes from assembly to colon ( :ENTER) and from
  945.     colon to assembly ( :EXIT) within the same word definition. See the
  946.     file SECDELAY.4TH
  947.  
  948.  
  949.  
  950.            ====
  951.            OMIT
  952.            ====
  953.  
  954.            As the number of words added to the system increases, it soon
  955.     becomes necessary to "prune out" the garbage entries in the dictionary.
  956.     All code entered has a dictionary entry, -- and is referenced by other
  957.     code. A good 50% of the code entered however will never be needed for
  958.     external applications, and maintaining a dictionary pointer to it is
  959.     simply a waste of space.
  960.  
  961.  
  962.  
  963.            ================
  964.            Inline Assembler
  965.            ================
  966.  
  967.            This feature has again been described briefly in INTRO.4TH and
  968.     will not be elaborated on in this limited manual.
  969.  
  970.            There are however two files MASM.TST and MASMTST which were used
  971.     in developing the assembler. These can both be FLOADed -- or examined
  972.     to see the format of entering inline assembly instructions.
  973.  
  974.            Both files end by calling upon the disassembler to display the
  975.     code that was just loaded. The object was to check that the assembler
  976.     and disassembler were consistent.
  977.  
  978.            Many of the source files for the system have both inline
  979.     assembly; BLOADable assembly; and plain FORTH code. Much can be learned
  980.     by examining these.
  981.  
  982.  
  983.  
  984.            =============================
  985.            How to compile demonstrations
  986.            =============================
  987.  
  988.            To create SINE.COM simply bring up 4TH_86 and then type FLOAD
  989.     SINCOM.DEM   The process will end by exiting to DOS. Look at the file
  990.     SINCOM DEM which automates the building process, and the file SIN.4TH
  991.     which is the source for the demonstration, to see what is happening.
  992.  
  993.  
  994.  
  995.  
  996.  
  997.  
  998.         4th_86             ASSEMBLY & CROSS COMPILE                 page 17
  999.     
  1000.            Similarly you can FLOAD SMITH.DEM to produce SMITH.COM -- and of
  1001.     course FLOAD HILCOM.DEM will produce HILBERT.COM.
  1002.  
  1003.            HILSIER2 is used exclusively by HILCOM.DEM to produce
  1004.     HILBERT.COM -- and omits the facility for defining levels and
  1005.     magnification. If you examine the source code however, you will see
  1006.     commented out the relevant code to allow level and magnification to be
  1007.     specified from the 4th_86 command prompt. You can edit HILSIER2.4TH [
  1008.     or use HILSIER.4TH ]  to reinsert the omitted code - and then reload.
  1009.     The easiest way is by using REDIT as already described.
  1010.  
  1011.            =======================
  1012.            CROSS-COMPILE & UNCROSS
  1013.            =======================
  1014.  
  1015.            The demonstrations which you created above were created in
  1016.     CROSS-COMPILE mode. The 4th_86 system provides the user with a means of
  1017.     compiling any system provided either image [ xxx.IMG ] or source code
  1018.     files are available for all the words needed.
  1019.  
  1020.            The cross-compiler is not a separate compiler, instead it is a
  1021.     mode in which the compiler executes. The compiler runs in one of two
  1022.     modes: cross-compile or noncross-compile. Until specified, the compiler
  1023.     will operate in noncross-compile mode. Executing the word CROSS-COMPILE
  1024.     switches to the cross-compile mode.
  1025.  
  1026.            Unlike earlier versions of 4th_86, CROSS-COMPILE now needs no
  1027.     parameters. Because all cross compile activity is in its own dedicated
  1028.     segment, it starts at offset 100H and has it's upper limit close to the
  1029.     64K offset limit.
  1030.  
  1031.            several points need to be noted
  1032.  
  1033.            a) code generated in cross-compile mode can ** NOT ** be run
  1034.     during the process of cross compiling. All offsets are identical to the
  1035.     final code produced -- but the segment is inappropriate.
  1036.  
  1037.            b) all code forming part of the "mother system" can be run in
  1038.     cross-compile just as in noncross mode. Obvously this is essential or
  1039.     the compiler would be "dead".
  1040.  
  1041.            c) cross-compiled definitions can not reference a word which has
  1042.     not already been itself defined in cross-compile. The word may already
  1043.     exist in the mother system -- and be executable -- but attempts to use
  1044.     it in a cross-compie definition will give an error message.
  1045.  
  1046.            d) Cross-compile creates its own dictionary, and FIND will
  1047.     reference this dictionary to determine code addresses ** NOT ** the
  1048.     system dictionary. The system dictionary is only used for words in
  1049.     immediate mode.
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.         4th_86             ASSEMBLY & CROSS COMPILE                 page 18
  1057.     
  1058.            ISAVE
  1059.            =====
  1060.  
  1061.            This is only used during cross-compile. At any stage of partial
  1062.     completion of the cross-compile, the memory image can be saved by using
  1063.     ISAVE  FNAME.IMG
  1064.  
  1065.            ILOAD
  1066.            =====
  1067.  
  1068.            This allows a previously saved xxx.IMG file to be re-loaded in
  1069.     the cross-compile mode. Unlike earlier versions of 4th_86, image files
  1070.     are not system sensitive because cross compile takes place in a
  1071.     dedicated segment - and always at offset 100H.
  1072.  
  1073.            COMMENTS IN CODE
  1074.            ================
  1075.  
  1076.            Forth or in-line assembly code between brackets is treated as
  1077.     comments and ignored by FLOAD.
  1078.  
  1079.            for example  : comment_test  2 ( first variable )
  1080.                                         3 ( second variable )
  1081.                             dup ( stack is 2 3 3 )
  1082.                             *   ( 3 * 3 gives 9 )
  1083.                             +     2 + 9 gives 11 )
  1084.                             .    ( print answer )
  1085.                             ;    ( end word definition )
  1086.  
  1087.            To assist in following complicated if -- then -- else and mixed
  1088.     conditional statements; the usual practice of indenting has not been
  1089.     used. Instead the ascii-graphic character B3 Hex [ 179 decimal ] is
  1090.     ignored by 4th_86 when encountered in FLOADed code. This character is a
  1091.     vertical line and its use is shown by the following sample.
  1092.  
  1093.            : DS ( DISPLAY STACK ELEMENTS IN HEX)
  1094.                   SP@ CLISP @ SWAP - 2 / DUP 0>
  1095.            IF ( SOMETHING ON STACK)
  1096.            │
  1097.            │ BEGIN
  1098.            │ │       DUP 1+ PICK .H   ( PRINT IT)
  1099.            │ │       1 - DUP 0=
  1100.            │ END DROP crlf
  1101.            │
  1102.            ELSE
  1103.            │
  1104.            │ IF ( underflow)
  1105.            │ │       " STACK UNDERFLOW ... RESETTING STACK." 1 ERMSG
  1106.            │ THEN
  1107.            │     " STACK EMPTY." ." CRLF
  1108.            │
  1109.            THEN ;
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.         4th_86             ASSEMBLY & CROSS COMPILE                 page 19
  1117.     
  1118.            ======
  1119.            STATUS
  1120.            ======
  1121.  
  1122.            STATUS is a word which prints out the dictionary and code space
  1123.     available at any stage. In cross-compile mode it prints additional
  1124.     information.
  1125.  
  1126.  
  1127.  
  1128.            ===
  1129.            MAP
  1130.            ===
  1131.  
  1132.            " xxxx.yyy" MAP will create a file xxxx.yyy showing all the
  1133.     words loaded into a system either in cross-compile or noncross mode. It
  1134.     will not list the words already embedded in the "mother" system.
  1135.  
  1136.  
  1137.  
  1138.            ==========
  1139.            CONCLUSION
  1140.            ==========
  1141.  
  1142.            The main features of 4th_86 have been outlined. The Glossary
  1143.     will define individual words -- and the complete manual will give a
  1144.     description of the memory layout and dictionary structure.
  1145.  
  1146.  
  1147.  
  1148.  
  1149.  
  1150.  
  1151.         4th_86                       INDEX                          page 20
  1152.     
  1153.  
  1154.     
  1155.     ,+ ,= etc                                                            11
  1156.     ,CONST                                                               13
  1157.     ."                                                                    3
  1158.     .C                                                                    4
  1159.     .H                                                                    4
  1160.     .HB                                                                   4
  1161.     .L                                                                    4
  1162.     .                                                                     4
  1163.  
  1164.     16DM                                                                  8
  1165.     8DM                                                                   8
  1166.  
  1167.     :ENTER                                                               16
  1168.     :EXIT                                                                16
  1169.     ^                                                                     3
  1170.  
  1171.     ARRAY.4th                                                            12
  1172.     AUTO-DEPTH DISPLAY                                                    4
  1173.  
  1174.     BASE                                                                  4
  1175.     BLOAD                                                                15
  1176.     BLOCK                                                                12
  1177.     BRKON                                                                 2
  1178.     brkon                                                                 2
  1179.     BYE                                                                   2
  1180.  
  1181.     C!                                                                   11
  1182.     C@                                                                   11
  1183.     CD                                                                    1
  1184.     Colon Definitions                                                     5
  1185.     COLON                                                                 2
  1186.     CONST                                                                12
  1187.     CONSTANT                                                             11
  1188.     CREATE .. DOES                                                       12
  1189.     ctrl-Break                                                            2
  1190.     ctrl-Brk                                                              2
  1191.     ctrl-C                                                                2
  1192.     CTRL-P                                                                1
  1193.     ctrl-S                                                                2
  1194.  
  1195.     D+ D= etc.                                                           11
  1196.     DATA[                                                                13
  1197.     DD                                                                    2
  1198.     DDH                                                                   2
  1199.     DDICT                                                                 8
  1200.     DDL                                                                   2
  1201.     DDS                                                                   8
  1202.     DEBUG                                                                 9
  1203.     DEMO version                                                          1
  1204.     DEPTH                                                                 5
  1205.  
  1206.  
  1207.  
  1208.  
  1209.  
  1210.  
  1211.         4th_86                       INDEX                          page 21
  1212.     
  1213.     diassembler                                                           2
  1214.     DIR                                                                   1
  1215.     DM                                                                    8
  1216.     DO..LOOP                                                              9
  1217.     DO..LOOPs                                                            12
  1218.     DS                                                                    8
  1219.  
  1220.     EMIT                                                                 11
  1221.     EXIT                                                                 12
  1222.  
  1223.     FLOAD                                                                15
  1224.     FLOAD                                                                 7
  1225.     FORGET                                                                6
  1226.     FRENCH.4TH                                                            3
  1227.     FULLSCREEN                                                            2
  1228.  
  1229.     HEAD                                                                 15
  1230.     HILSIER2                                                             17
  1231.  
  1232.     ILOAD                                                                18
  1233.     Inline Assembler                                                     16
  1234.     ISAVE                                                                18
  1235.  
  1236.     KEY                                                                  11
  1237.  
  1238.     LAST                                                                 15
  1239.     LEAVE                                                                12
  1240.     LINK                                                                  6
  1241.     LOAD                                                                 15
  1242.  
  1243.     MAP                                                                  19
  1244.  
  1245.     OMIT                                                                 16
  1246.     OOPS                                                                  2
  1247.  
  1248.     PAGE0                                                                 2
  1249.     PDICT                                                                 8
  1250.     PRINTER                                                               1
  1251.     PRINTLOAD                                                            15
  1252.  
  1253.     REDEFINE                                                             15
  1254.     REDIT                                                                 6
  1255.     RELOAD                                                                6
  1256.     RELOAD                                                                7
  1257.  
  1258.     SECDELAY.4TH                                                         16
  1259.     SECDELAY                                                              2
  1260.     SHARPS.4th                                                           12
  1261.     SHIFT PRTSC                                                           1
  1262.     SRET                                                                  2
  1263.     STATUS                                                               19
  1264.     SYNONYM                                                              10
  1265.  
  1266.  
  1267.  
  1268.  
  1269.  
  1270.  
  1271.         4th_86                       INDEX                          page 22
  1272.     
  1273.     SYS                                                                   1
  1274.  
  1275.     TAG                                                                   8
  1276.     TD                                                                    9
  1277.     TEST.ASM                                                             15
  1278.     THREAD                                                                2
  1279.     TM                                                                    9
  1280.     TRACEL                                                                9
  1281.     TRACEOFF                                                              8
  1282.     TRACEON                                                               8
  1283.     TYPE                                                                 11
  1284.     TYPE                                                                  1
  1285.  
  1286.     UNLINK                                                                6
  1287.     UNSPLIT.                                                              1
  1288.     USING                                                                 6
  1289.  
  1290.     VARIABLE                                                             11
  1291.