Going Forth. (computer language) (evaluation) Thomas McNamee.
The finest testimony I can give to Valpar International's ValForth language is this: In 20 hours' time I went from complete ignorance in the Forth language to writing my first Pong game, complete with player/missile graphics and sound. I owe it all to Valpar's great documentation, a book they recommended, and of course, the fast and versatile Forth language.
I have been programming on various micros for two years--all in Basic and assembly language. I had heard of Forth through a friend who worked in a similar language, Stoic. Forth offered many advantages over the languages I was familiar with, but one look at a typical program listing scared me off. I remember thinking that the program looked as if the programmer had been making up the language as he went along. And that turned out to be the secret of Forth--you make it up as you go along.
Based on a set of more or less standardized commands, the programmer constructs his own words to meet his needs. This process builds on itself until the whole program can be run by executing just a few words. For example the word SANDWICH might be made up of the words GET-HAM and GET-CHEESE. These would be further defined as smaller and smaller words. Think of each word as a subroutine made up of ever-smaller subroutines.
I picked Pong for my maiden project because it used many of the features needed for most games--player/missile graphics with collision detection, full control over the standard Atari graphics, game controller interface, and sound. The game runs well, with speed far better than Basic, but only about half as fast as assembly language. The speed loss is barely noticeable, however.
The exciting thing is the composition time. Pong could easily have been written in an afternoon by someone who knew the language well. And the words I defined in Pong can be used in my next game if similar functions are needed. The Forth dictionary (really a library of commands) can be extended indefinitely.
I bought three modules from Valpar: ValForth ($39.95), General Utilities and Video Editor ($34.95) and a disk containing Player/Missile Graphics, a Character Set Editor and a Sound Editor ($39.95). The last two require ValForth to run, and are extensions of the dictionary. Time-critical routines are coded in assembly language for speed. The disks are unprotected, so backups for personal use are allowed. FORMAT and DISKCOPY commands are provided, as is a command to produce your own programs on auto-booting, protected disks. Valpar supports programmers wishing to write programs for publication using ValForth, and requires only that credit be given them in the documentation or on the media.
The primary disk contains all the main routines, the interpreter and the operating system for Forth. It features a basic glossary of words and a figForth editor for creating your own source programs. Graphics, color and sound commands are available on this disk as extensions to the dictionary. Many of the graphics words from Atari Basic (DRAWTO, PLOT, etc.) have been copied here so that learning to use this section is easy.
As much as possible, Valpar has written this package so that what you already know about the Atari computer can be put to immediate use. The Atari operating system is supported with familiar words such as OPEN, CLOSE, PUT and GET. There is a group of words used for debugging Forth code, and words for floating point arithmetic are provided.
For applications in which time is critical, this disk contains a powerful 6502 assembler designed to be used with the Forth system. Macros, conditional branching, and conditional loops are supported, and access to the rest of the Forth language is easy. The assembler itself is worth the price of the disk.
General Utilities and Video Editor
The General Utilities and Video Editor disk contains a fine selection of string utilities, array commands, and CASE statements, and a fascinating group of words called High Resolution Text. Many Basic words appear in the string commands, such as LEFT$, RIGHT$ and INSTR. There are provisions for comparison, sorting, and formatted output. The string commands are all very fast, since the address of the string is manipulated instead of the string itself. Time is not wasted in what Basic programmers call garbage collection.
CASE structures are a powerful group of commands permitting decision making similar to ON . . . GOSUB in Basic. The SEL structure allows the same advantage for non-sequential numbers. The final word in this group is COND, which allows conditional execution based on true/false testing.
High Resolution Text is a feature permitting text to be displayed in Graphics 8 mode. Words for superscript, subscript, and overstrike are supplied. Using a combination of backspacing, subscript and overstrike, underlining can be accomplished. Graphics can still be drawn in this mode, so displays of mixed text and graphics are very easy.
The ValForth video editor is a joy to use. Again, Valpar could have sold this all by itself and kept the price the same. It is used for entering Forth source code and has a powerful set of single-stroke commands for insertion, deletion, and buffer management. Each screen, of which there are 180 per disk, can be brought up and edited with ease.
When the source code is finished, you LOAD the screens you want to run. As they load, each word is compiled into the dictionary. If an error occurs during compilation, the WHERE command of the editor displays the screen on which the error occurred. The cursor is positioned over the word or character that caused the error.
A visible buffer to or from which lines can be copied appears at the bottom of the screen. The user can set the number of lines it holds. Seven single-stroke commands support line move, line copy, and buffer clear operations. In this way, sections of code can be moved or copied using the SMOVE and COPY commands. The whole editor design encourages the composition of easy-to-read source code.
Player/Missile Graphics and Friends
The Player/Missile Graphics disk contains an extremely useful set of commands that are a must for any game programmer. Memory allocation, memory clearing, player/missile design, and movement are all reduced to single words. All modes are supported. Player size, multicolor players, and fifth player features are easy to implement. P/M graphics are not destroyed when switching from one graphics mode to another.
Movement is accomplished in two ways. You can either put the player at an absolute X, Y location, or you can move the player relative to its present spot any number of locations.
Collision detection is also available in two ways: boundaries and the standard Atari collision registers. Boundaries can be set for any player or missile. The movement of that character will then be limited to that area. In addition, a variable can be checked to find out when a boundary has been reached and where it is. The direction of movement can then be changed. This is how I made the ball bounce in my Pong game.
Missile-to-playfield, player-to-play-field, missile-to-player and player-to-player collision detection are supported, and there is a general collision flag that is set when anything bumps anything else.
The character set editor allows for the creation of new character sets, as well as the words needed for switching and loading sets. These designs can easily be used in conjunction with player/missile graphics, since a command is available to change any player rapidly to another bit pattern.
The sound editor is a useful "audio pallete' for creating single sounds on any of the four channels. Using joysticks, you adjust the frequency by moving horizontally, and change the distortion by moving vertically. A readout at the bottom of the display shows the current values needed to re-create the sound. In addition, the AUDCTL register can be addressed to produce many interesting sound variations.
Documentation and Support
Each package comes with its own documentation, printed clearly on 8 1/2 X 11 paper and punched for a three-ring binder. All together, there are about 200 pages of information, as well as the source code for each disk. The documentation is excellent, and is very easy to use. It is not a tutorial of Forth, however. The functions common to the language are listed, but the language itself is not explained.
Valpar recommended Starting FORTH by Leo Brodie since I was a first time user, and it turned out to be great advice. I have read many technical works, but none as informative and enjoyable as Brodie's. I never met the man but I like him a great deal.
The ValForth 1.1 documentation of the main disk begins with simple loading instructions and then, very appropriately, a good section on errors, recoveries, and crashes. The next section is on formatting and copying disks. I recommend that anyone who buys ValForth be sure to have a box of clean disks on hand. Backups are encouraged and very useful. After you have loaded all the features you are likely to use, you can create your own system disk. Forth requires a special disk format, so you will want three or four blanks to work on. Sections on graphics, editing and sound complete this package.
All of the ValForth documentation is written in a participatory style. You sit down and follow the instructions, and when the last page is turned, you know how it works. Technical jargon is kept to a minimum, but it is a good idea to keep Brodie's book nearby.
Any command peculiar to the Atari, such as graphics and sound, is explained fully with examples. There are even example programs on the player/missile disk which are valuable references. Each package is accompanied by a stiff command reference card for quick word look-up.
Before buying this package, I spoke to Mike White at Valpar about support. He was knowledgeable and polite, and he assured me that I could write or call anytime with my problems, and I would get help. He was enthusiastic about ValForth, and seemed to represent a company that sells a good product and stands behind it.
ValForth is an excellent implementation of a fast, expandable language.
Products: Valpar International ValForth (computer program language)