Multi-tasking is a function that until recently was not so generally known. The Forth community have been using it for many years, indeed Charles Moore's first Forth's used it. Once used you will wonder how you did without it. The version in the TLM, there are many, is the simplest and called a Round Robin tasker. Basically each task is a separate program that is often self contained. The tasks run until they reach a point where they have to wait for something, at this point a task PAUSEs and the next runs. If the task does not have a natural wait then a PAUSE must be added at some convenient point, or the task STOPped. These tasks are said to be co-operative, that is they must relinquish control of the processor to allow others to have a go. Each task has it's own stack space and an area called USER. Here resides the links to the tasks memory plus variables that may be used only by that task. One example of these is BASE used by the numbers, described elsewhere. A task is given a name and the sizes of the Data stack, Return stack and User area these are then allocated to it by TASK:. The stacks work down from their tops and the user area goes up, as shown below.:
The USER area starts with the task start code called STATUS. The other bytes defined by IRTC are show below:
STATUS UP+0 Either MOV # , PC to jump to the next task if this one is STOPed or a CALL @R6 to RESTORE this task and set it running.
LINK UP+2 The link to other tasks.
DP0 UP+4 The address of the bottom of the Data stack.
PTR UP+6 The pointer for number to ASCII conversion.
BASE UP+8 The radix for number conversion.
VFLAG UP+10 The TO variable flag.
HANDLER UP+12 The exception return address.
PAD UP+26 General area used by number conversion, PTR>PAD number to ASCII, PAD> ASCII to number.
Next available USER address is UP+34.
The Task areas allocated by TASK: which is preceded by three values to set the task data, return and user stack areas.
20 20 40 TASK: <task-name>
Then we must chain the tasks together at runtime. To do this we LINK the tasks.
<task-name> LINK
The LINK process adds a task to the chain but sets the task as RESTing. To make a task run the application we wish, the USER area and the task's stacks must be set to run whatever word we select. The task must be ACTIVATEd.
<task-name> ACTIVATE <word>
This must be inside a : definition. <word> must be an endless loop or terminate with STOP.