home *** CD-ROM | disk | FTP | other *** search
- Psion 3a/Pocketbook II FORTH language
- =====================================
-
- BETA TEST VERSION 1.24 - 12/04/95
-
- This software is copyright Steve Godfrey
-
- These notes assume you are familiar with the Forth language.
-
- Installation:
-
- Copy Forth.opa into any \APP\ directory
- Copy Forth.bin into any \APP\Forth\ directory
- Copy Demo.sav into any \APP\Forth\ directory
-
- and install Forth.opa in the usual way. Saved files are listed
- below the Forth icon on the system screen.
-
- The demo has the following words defined: (most pointless!)
- -----------------------------------------
-
- test tests if the number on the stack is positive or negative
- star displays a star
- stars displays n stars, where n is removed from the stack
- trian displays a triangle of stars
- n! works out factorial (upto 7! due to 16bit maths)
- nums displays numbers 0 to 99, 10 on a row
- show shows contents of stack without removing numbers from stack
- bars draws bars on screen (shows use of graphics commands)
-
- Please inform me of any suggestions, bugs etc by email to:
-
- stevegodfrey@cix.compulink.co.uk
- stevegodfrey@warp10.demon.co.uk
-
- or arcade user #897
-
- ****** WARNING: Mis-use of the Forth language could
- crash your psion. Please save any
- unsaved data in other applications
- before using.
-
- The core of this FORTH language is written entirely
- in assembler for maximum speed. An OPL front end is
- used for simplicity. All commands entered are compiled
- before being executed. Any new definitions you create
- are compiled ready for future use.
-
- Later versions will allow the use of ROM routines
- for graphics drawing, serial i/o, sound etc.
-
- Words defined in version 1.21 of Psion 3a Forth
- -----------------------------------------------
-
- forget time + - * / /mod mod
- . u. d. ." at cr do loop
- +loop if else then drop dup emit i
- i' j >r r> r@ over pick roll
- rot swap vlist 2* 2/ 2+ 2- 1+
- 1- and or not xor <> 0> 0<
- 0= d- leave cls negate > < =
- <= >= sp@ s0 @ stack variable !
- draw box fill
-
- Notes:
- ======
-
- There is no real limit to the number of nested do...loops
- or if...else...then statements.
-
- When using the if statement, you *must* use all three parts
- ie:
-
-
- if <statements> else <statements> then <statements>
-
- nested if statements must be of the form:
-
- if ... if ... else ... then ... else ... then ...
-
- or
-
- if ... else ... if ... else ... then ... then ...
-
- or
-
- if ... if ... else ... then ... else ... if ... else ... then ... then ...
-
- DO NOT USE EG:
-
- if ... if ... else ... else ... then ... then ...
-
- A maximum of 8 if statements can be nested, but you can use another if
- statement for every then used.
-
- There are currently no checks on the state of the stack except with the
- . u. and d. functions. It is up to you to make sure that the stack has sufficient
- entries for the function used ie 'rot' requires 3 numbers on the stack but
- will work without. It may, however, crash the computer.
-
- Mis-use of the language will usually give a harmless Panic 60 error, but worst case
- could require the psion to be reset, which could lose any unsaved data in
- other applications that are running.
-
- Each word you enter must be seperated by a space.
-
- Defining new words:
- ===================
-
- You may define new words as follows.
-
- : <word> <func1> <func2> <func3> ... ;
-
- ie to define a function to print a given number of stars, you could use:
-
- : stars 0 do 42 emit loop cr ;
-
- You can then type '5 stars' to print 5 stars, or '10 stars' to print 10 stars etc.
-
- You can use any defined word in furthur words, eg: another word could then be
- defined to print a triangle of stars as follows:
-
- : triangle 10 1 do i stars loop ;
-
- Entering 'triangle' would produce:
-
- *
- **
- ***
- ****
- *****
- ******
- *******
- ********
- *********
-
- Remember that forth uses reverse polish notation for calculations.
-
- To add and print the sum of 5 and 7, enter
-
- 5 7 + .
-
- To print (5*6)+(9-7)*88, enter:
-
- 5 6 * 9 7 - 88 * + .
-
- / returns the int of the division. mod returns the remainder.
- /mod returns both the remainder and the quotient on the stack.
-
- Any number of do..loops can be nested, eg:
-
- : test 10 0 do 10 0 do i j * . loop cr loop ;
-
- which prints the multiplication tables from 0 to 9 (no print formatting
- available yet).
-
- Strings are used as follows:
-
- : sqr dup dup ." The square of " . ." is " * . ;
-
- Which produces:
-
- >5 sqr
- The square of 5 is 25
-
- Any space before the terminating " will be printed as part of the string.
- The space is not required to work, but you must have a space after the ."
-
- You can do a reverse counting loop using +loop. Ie to print 10 to 1 enter
-
- 1 10 do i . -1 +loop
-
- Or to count in 2s, use
-
- 10 0 do i . 2 +loop
-
- For long words you can split the definition over several lines, eg:
-
- >: stars
- 10 1
- do
- i
- 0
- do
- 42 emit
- loop
- cr
- loop
- ;
- >
-
- Each definition must end with a ; and start with a :
-
- If you try and use an unknown word in a new definition, the new entry
- is aborted with an error.
-
- If you have an unequal number of dos and loops or ifs, elses and thens
- an error will be reported and compilation aborted.
-
- You can save the words you have defined using the menu. Any saved
- files in the \APP\Forth directory with extension .sav will appear
- under the system icon. Starting the language with a saved file
- will load the saved definitions. Saved files can be loaded
- into DATA for editing.
-
- -----------------------
- Steve Godfrey, 12/04/95
- -----------------------
-