home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / psion / forth / forth.txt < prev   
Encoding:
Text File  |  1995-04-12  |  5.6 KB  |  209 lines

  1. Psion 3a/Pocketbook II FORTH language
  2. =====================================
  3.  
  4. BETA TEST VERSION 1.24 - 12/04/95
  5.  
  6. This software is copyright Steve Godfrey
  7.  
  8. These notes assume you are familiar with the Forth language.
  9.  
  10. Installation:
  11.  
  12. Copy Forth.opa into any \APP\       directory
  13. Copy Forth.bin into any \APP\Forth\ directory
  14. Copy  Demo.sav into any \APP\Forth\ directory
  15.  
  16. and install Forth.opa in the usual way. Saved files are listed
  17. below the Forth icon on the system screen.
  18.  
  19. The demo has the following words defined: (most pointless!)
  20. -----------------------------------------
  21.  
  22. test   tests if the number on the stack is positive or negative
  23. star   displays a star
  24. stars  displays n stars, where n is removed from the stack
  25. trian  displays a triangle of stars
  26. n!     works out factorial (upto 7! due to 16bit maths)
  27. nums   displays numbers 0 to 99, 10 on a row
  28. show   shows contents of stack without removing numbers from stack
  29. bars   draws bars on screen (shows use of graphics commands)
  30.  
  31. Please inform me of any suggestions, bugs etc by email to:
  32.  
  33. stevegodfrey@cix.compulink.co.uk
  34. stevegodfrey@warp10.demon.co.uk
  35.  
  36. or arcade user #897
  37.  
  38. ****** WARNING: Mis-use of the Forth language could
  39.                 crash your psion. Please save any
  40.                 unsaved data in other applications
  41.                 before using.
  42.  
  43. The core of this FORTH language is written entirely
  44. in assembler for maximum speed. An OPL front end is
  45. used for simplicity. All commands entered are compiled
  46. before being executed. Any new definitions you create
  47. are compiled ready for future use.
  48.  
  49. Later versions will allow the use of ROM routines
  50. for graphics drawing, serial i/o, sound etc.
  51.  
  52. Words defined in version 1.21 of Psion 3a Forth
  53. -----------------------------------------------
  54.  
  55. forget   time     +        -        *        /        /mod     mod
  56. .        u.       d.       ."       at       cr       do       loop
  57. +loop    if       else     then     drop     dup      emit     i
  58. i'       j        >r       r>       r@       over     pick     roll
  59. rot      swap     vlist    2*       2/       2+       2-       1+
  60. 1-       and      or       not      xor      <>       0>       0<
  61. 0=       d-       leave    cls      negate   >        <        =
  62. <=       >=       sp@      s0       @        stack    variable !
  63. draw     box      fill
  64.  
  65. Notes:
  66. ======
  67.  
  68. There is no real limit to the number of nested do...loops
  69. or if...else...then statements.
  70.  
  71. When using the if statement, you *must* use all three parts
  72. ie:
  73.  
  74.  
  75. if <statements> else <statements> then <statements>
  76.  
  77. nested if statements must be of the form:
  78.  
  79. if ... if ... else ... then ... else ... then ...
  80.  
  81. or
  82.  
  83. if ... else ... if ... else ... then ... then ...
  84.  
  85. or
  86.  
  87. if ... if ... else ... then ... else ... if ... else ... then ... then ...
  88.  
  89. DO NOT USE EG:
  90.  
  91. if ... if ... else ... else ... then ... then ...
  92.  
  93. A maximum of 8 if statements can be nested, but you can use another if
  94. statement for every then used.
  95.  
  96. There are currently no checks on the state of the stack except with the
  97. . u. and d. functions. It is up to you to make sure that the stack has sufficient
  98. entries for the function used ie 'rot' requires 3 numbers on the stack but
  99. will work without. It may, however, crash the computer.
  100.  
  101. Mis-use of the language will usually give a harmless Panic 60 error, but worst case
  102. could require the psion to be reset, which could lose any unsaved data in
  103. other applications that are running.
  104.  
  105. Each word you enter must be seperated by a space.
  106.  
  107. Defining new words:
  108. ===================
  109.  
  110. You may define new words as follows.
  111.  
  112. : <word> <func1> <func2> <func3> ... ;
  113.  
  114. ie to define a function to print a given number of stars, you could use:
  115.  
  116. : stars 0 do 42 emit loop cr ;
  117.  
  118. You can then type '5 stars' to print 5 stars, or '10 stars' to print 10 stars etc.
  119.  
  120. You can use any defined word in furthur words, eg: another word could then be
  121. defined to print a triangle of stars as follows:
  122.  
  123. : triangle 10 1 do i stars loop ;
  124.  
  125. Entering 'triangle' would produce:
  126.  
  127. *
  128. **
  129. ***
  130. ****
  131. *****
  132. ******
  133. *******
  134. ********
  135. *********
  136.  
  137. Remember that forth uses reverse polish notation for calculations.
  138.  
  139. To add and print the sum of 5 and 7, enter
  140.  
  141. 5 7 + .
  142.  
  143. To print (5*6)+(9-7)*88, enter:
  144.  
  145. 5 6 * 9 7 - 88 * + .
  146.  
  147. / returns the int of the division. mod returns the remainder.
  148. /mod returns both the remainder and the quotient on the stack.
  149.  
  150. Any number of do..loops can be nested, eg:
  151.  
  152. : test 10 0 do 10 0 do i j * . loop cr loop ;
  153.  
  154. which prints the multiplication tables from 0 to 9 (no print formatting
  155. available yet).
  156.  
  157. Strings are used as follows:
  158.  
  159. : sqr dup dup ." The square of " . ." is " * . ;
  160.  
  161. Which produces:
  162.  
  163. >5 sqr
  164. The square of 5 is 25
  165.  
  166. Any space before the terminating " will be printed as part of the string.
  167. The space is not required to work, but you must have a space after the ."
  168.  
  169. You can do a reverse counting loop using +loop. Ie to print 10 to 1 enter
  170.  
  171. 1 10 do i . -1 +loop
  172.  
  173. Or to count in 2s, use
  174.  
  175. 10 0 do i . 2 +loop
  176.  
  177. For long words you can split the definition over several lines, eg:
  178.  
  179. >: stars
  180.     10 1
  181.     do
  182.       i
  183.       0
  184.       do
  185.         42 emit
  186.       loop
  187.       cr
  188.     loop
  189.     ;
  190. >
  191.  
  192. Each definition must end with a ; and start with a :
  193.  
  194. If you try and use an unknown word in a new definition, the new entry
  195. is aborted with an error.
  196.  
  197. If you have an unequal number of dos and loops or ifs, elses and thens
  198. an error will be reported and compilation aborted.
  199.  
  200. You can save the words you have defined using the menu. Any saved
  201. files in the \APP\Forth directory with extension .sav will appear
  202. under the system icon. Starting the language with a saved file
  203. will load the saved definitions. Saved files can be loaded
  204. into DATA for editing.
  205.  
  206. -----------------------
  207. Steve Godfrey, 12/04/95
  208. -----------------------
  209.