Fleet Forth is not a multi user Forth system. It was designed for one person to use at a time on a Commodore 64. Fleet Forth supports multitasking with background tasks. With this in mind the Fleet Forth system has only ten user variables. More user variables can be added.
The user area for the foreground task is not part of the loadable image, it is in a section of unused memory on the Commodore 64; therefore, the first eight user variables need initialized at bootup. Fleet Forth's boot area holds the bootup values for the first seven user variables.
Code:
ENTRY -- Points to next task's user area or itself if no other tasks.
READY -- Flag. TRUE - task is awake. FALSE - task is asleep.
TOS -- Holds the return stack pointer when a task is switched out.
RP0 -- Base of return stack.
SP0 -- Base of data stack.
AP0 -- Base of auxiliary stack.
DP -- Dictionary Pointer.
The first six user variables are initialized by the word UNLINK , which also sets the user pointer UP to the address of the foreground task's user area. This unlinks all background tasks and restores control to the main task. UNLINK is included in a routine included in the coldstart and warmstart routines.
The word EMPTY initializes DP from this bootup area and branches into the body of FORGET to handle any necessary pruning. EMPTY is included in the coldstart routine.
These are the next three user variables:
Code:
BASE -- Base for numeric conversion to or from text.
DPL -- Decimal place.
HLD -- Holds the address for the next character during conversion
from text to a double number.
DECIMAL , which sets BASE to decimal, is included in the routine which is included in the coldstart and warmstart routines.
DPL and HLD are not initialized during coldstart or warmstart. It is not required. NUMBER? initializes DPL and <# initializes HLD .
The Fleet Forth system has only ten user variables. The other variables in the system are not user variables as they should not be needed in background tasks.
As I mentioned, Fleet Forth allows the defining of new user variables. The word for this is USER . It takes a number and is followed by a name.
Code:
<USER.AREA.OFFSET> USER <NAME.OF.USER.VARIABLE>
For example:
Code:
#20 USER STOOGES
To make defining new user variables easier (some may be defined in different sources), Fleet Forth has a 'system value' or 'soft constant' #USER .
The source for Fleet Forth's USER .
Code:
: USER ( N -- )
DUP 2+ #USER UMAX (IS) #USER
CREATE C,
;CODE ( -- N )
2 # LDY CLC
W )Y LDA UP ADC
UP 1+ LDY CS IF INY THEN
AYPUSH JMP END-CODE
If #USER has the value #20, the following:
Code:
#USER USER LARRY
#USER USER CURLY
#USER USER MOE
will create the user variable LARRY with the user area offset #20, the user variable CURLY with the user area offset #22, and the user variable MOE with the user area offset #24.
To set aside more of the user area for a particular user variable, the following can be done.
Code:
#USER USER LAUREL
#USER 8 + USER HARDY
This will 'allot' eight more bytes in the user area for the user variable LAUREL .