Classic Computer Magazine Archive ANTIC VOL. 1, NO. 1 / APRIL 1982

Forth Factory

by Bob Gonsalves

In this premier issue of ANTIC I would like to introduce a facility I believe many programmers using the Atari 800/400 will find very useful. The tiny MULTI-TASKING kernel described here allows one to easily create machine language routines that run as part of the vertical blanking interrupt servicing routines. These routines may perform such diverse tasks as moving a player/missile image, blinking the cursor, fine scrolling of the bit map, and various musical applications.

The run-time kernel of the multi-tasking system is contained on screen 36 and 37. There are three variables that are accessed by the routine. TASKS indicates which of several tasks will execute during the current vertical blanking interval. It is used to index into a table, called TASK-TABLE. The table is 16 bytes long, and holds the entry points for up to 8 separate machine code tasks. TASKS indicates which of these entries is to be executed; the entry point address is transferred from the indexed location in the task table, to JUMPER and an indirect jump is made through JUMPER.

The routines of scr#37 perform the necessary run-time operations. The master vblank routine is called NEW-VBLANK. It in turn calls two other routines. The first, WHOSE-TURN, uses the value of TASKS to find the appropriate slot in the task table, which contains the address of a subroutine. Notice that if the most significant byte of the entry in the table is set to 0, we can assume that the slot really does not contain a valid address. Otherwise, the entry point address held at that slot is transferred to JUMPER and we vector through JUMPER to the actual subroutine that we want to execute.

When we return from that subroutine, we next execute NEXT-TASK, which simply bumps TASKS by 1, rolling over to 0 if it is greater thaP three. We then leave the NEW-VBLANK routine by jumping to the code in the Atari Operating System that updates various hardware registers from their shadow registers.

Screen 35 establishes the equates for interfacing with the OS. SET-VBLANKD provides the linkage between Forth and Atari supplied routine for changing the vertical blanking vectors and countdown timers. To install a new vertical blanking vector, you simply push the new routine address onto the stack before call SET-VBLANKD.

Screens 38 and 39 provide us with a means of adding and deleting entries from the task-table. The routines MTOFF and MTON disable and enable the multi-tasking respectively, by changing the deferred vertical blanking vector, using our SET-VBLANKD routine. SNEAK is a way of ensuring that operations that change some variable read by the multi-tasking do so only when the multi-tasking is disabled. SCANTASKS is used to find an entry in the task table. It can be used to either find an available slot (an entry in the table = 0) or to find the slot holding the address of a task routine. INSTALL and REMOVE will perform these actions for us. They can be used in the form

INSTALL BLINK (for example)

where BLINK is one of the tasks we have defined.

TASK: and ;TASK are defining type words which will allow us to create machine code routines, which are subsequently installed in the task table. An important feature of the compilation security of these words is that the routines are not installed into the task table if some sort of structural error was generated by assembling them.

Finally, we can show some screens, that, when compiled, will install some tasks into the multi-tasking system. Once this is done, the routines operate independently of what you are doing as you program in the high level language. They have been integrated into the interrupt structure of the Atari Operating System. Screen 41 provides a task which will periodically blink the cursor. Once installed, you can vary the rate of blinking by writing a value to variable RATE.

Screens 42 & 43 show another amusing background task. Here we monitor the keyboard hardware register (address D209 hex). If the value there is different from the value contained at OLD.KEY, then we change the variable SOUNDING to indicate that we want to make noise. The current key value then becomes the OLD.KEY value. The key value is also stored to the channel 1 audio frequency register. The next time the routine executes, we store a value, derived from the envelope table, into the channel 1 audio control register. The index variable INTO is decremented by 1 each time, until it is less than 0 (we've loaded the last value from the envelope). At this point SOUNDING is set to 0 and we resume checking the hardware register.

Other routines that various people have designed for BASIC could be integrated into this system. These would include the joystick controlled text cursor, and using some keys (space bar, Start key, etc) to temporarily halt program execution. Those who are contemplating purchasing the Forth system produced by Pink Noise Studios might be interested to know that a complete player graphics system is supported using this multi-tasking system to refresh the player images.

Should you have any questions regarding this column or pns fig FORTH--address them to me in care of ANTIC.


The FORTH language is commercially available for the ATARI from three sources.

Mountain View Press
P.O. Box 4656
Mountain View, CA 94040
Publishes "pns" Fig Forth

ATARI Program Exchange (APX)
P.O. Box 427
155 Moffett Park Drive
Sunnyvale, CA 94086
Publishes Fig Forth

Quality Software
6660 Reseda Blvd.
Suite 105
Reseda, CA 91335
Publishes Fig Forth

If you want to find out what all the excitement is about get one of the Forth implementations listed above and this book. Oh, and read FORTH FACTORY. Bob Gonsalves writes this column for us and is the implementor of the version available from Mountain View Press. Watch for a comparison of these three products in a future issue.