GFA BASIC 3.0
The New Standard?
by David Plotkin
When GFA BASIC first reached the United States from Germany, it created quite a stir. It was the first general purpose interpreted language for the ST that was fast, easy to use and accessed GEM in a relatively straightforward manner. It became even more attractive upon the release of the GFA BASIC Compiler, which could turn your program into a standalone .PRG file.
GFA BASIC became the language of choice for many ST owners, especially since it did not need the complicated Compile-Link-Debug cycle required by C. Since its introduction, GFA BASIC has become the most popular ST language for magazine listings as well. (Editor's Note: We receive more program submissions at START in GFA BASIC than in any other language.)
GFA BASIC 3.0, the newest version of this popular language, adds many more features and functions and is considerably faster. Let's look at version 3.0 and see what it has to offer.
The GFA 3.0 editor does not use standard GEM menus. Instead, there are two lines of functions at the top of the screen, similar to version 2.0's editor. To activate a function, you can click on it with the mouse or press the corresponding function key (or Shift-function key combination). The function bar has standard commands such as loading saving printing a listing, block operations and merging. Differences from the GFA 2.0 editor include a real-time clock in the function line at the top of the screen and a toggle that switches the screen to GEM format to let you access desk accessories and load or save programs.
Another new feature is a line counter that keeps track of your place in the program. While GFA BASIC does not use line numbers per se, you can type in the line counter value for a particular line and the editor will jump to that line.
To enter a program in the editor, just type it in or load it from disk. Each line can contain only one command. The editor automatically indents loops and procedures (more on this later) and you can set it to capitalize commands and put variables in upper-lower case automatically. You can also set the format of printed listings by adding headers and footers, setting the maximum line length and doing other things you couldn't do with version 20.
Various key combinations move the cursor around in the editor-you can even set the number pad to control cursor movement much as it does on the PC. Reminiscent of 8-bit Atari BASIC, GFA BASIC 3.0 and 2.0 analyze each line for proper syntax as you go. If you try to leave a line that has a syntax error the bell will sound, a message will appear at the top of the screen and you must correct that line before moving on.
Once you've typed in or loaded a program, you can run it just by clicking on Run in the function bar. If any errors occur, the program will return you to the editor with the cursor on the offending line and a brief error message at the top of the screen. You can also shift to the output screen to give single commands in "direct" mode, useful for checking the values of variables, etc.
Commands, Variables and Operators
In terms of commands, GFA 3.0 is about the most full-featured language I have ever seen, containing more than 400 commands, The "normal" BASIC commands (such as Print. If, etc.) are included, but these just scratch the surface.
The variable types include Byte, Boolean, Word, Integer, Floating Point and String. Each of these can be used in arrays as well. Commands are available to fill an array with a specified value, to set and find the dimensions of an array and to find the addresses of arrays and variables. Further, GFA 3.0 is exceptionally flexible in its variable handling with commands to convert one type of variable to another, convert among octal, binary, decimal and hex, convert numbers to strings and back, swap variable values, do two types of sorts and access memory directly for handling variables. One of the most interesting commands is Inline, which lets you reserve space (for storing a picture or assembly code, for example) right in the program listing, so that the information in that space will be saved and loaded with the program listing itself.
GFA 3.0 provides arithmetic operators for handling floating point and integer operations and a full range of logical operators (such as And, Or and Eqv), string operators and comparison operators (such as >, = and <), mathematical functions including trig and log functions, Max and Min, a square root function and a random number generator. A complete complement of bit operators, such as Shift, Set, Clear, Test and Change round out these functions.
The new key operators in GFA 3.0 let you redefine the function keys. As in version 2.0, file management commands let you use different directories, change drives, erase a file, check for the existence of a file, check the length of a file and determine the amount of space on a disk. Enhancements include the ability to rename a file and to query or set the contents of the disk transfer address. Both versions of GFA BASIC let you set the file pointer value, copy a memory area to and from disk and use random access files so you don't have to keep an entire file in memory at once.
You can communicate with peripherals p1ugged into any of the ST's ports. As in version 2.0, the program provides direct mouse support (including setting the pointer shape), but version 3.0 takes this one step further and lets you (finally) access the joystick. Sound support includes the Wave command and two variations of the Sound command.
about the most full-
featured language I
have ever seen.
With version 3.0, GFA BASIC continues to support structured programming. In addition to the standard If-Else-Endif in version 2.0, you now have Elseif, which largely eliminates the (formerly required) nested Endifs. Select Case structures now allow branching to multiple sections of code based on the value of an expression. Because the value specified for Case can be a single number, a range of numbers or a list of numbers, this feature is very flexible. There's also a Default option so that if none of the Case values are satisfied, the code for the Default is executed. Case can even test for non-numeric characters.
As with version 2.0, the new version supports Repeat Until, While/Wend and Do Loop. However, Do Loop variations now indude Do Until, Do While, Loop Until and Loop While for even more options.
In many BASICs-and in GFA versions 2.0 and 3.0-procedures have replaced subroutines. (A procedure is simply a separate section of code.) In languages that use subroutines, procedures can sometimes be executed accidentally. But in both versions of GFA BASIC, they must be called specifically in order to be executed. Procedures have another advantage over subroutines in that you can pass different parameters to them.
A variable can be declared local to a procedure so that it will not affect a variable with the same name elsewhere in the program. The procedure can also modify the value of a passed parameter if it is declared as a Var parameter (as in Pascal). This gives you a great deal of flexibility. Another nice touch is that a procedure can be called simply by using its name as a command-no longer must you use Gosub or * (although you can if you want).
GFA 3.0 supports two types of functions. Just as in version 2.0, there are single line functions which are defined with Deffn and called with Fn. Parameters can be passed to them, but the values of the parameters cannot be modified. The result of the Fn call will return a value, just like built-in functions such as Sin or Cos. The second type of function is even more powerful; it can be more than one line long-a special kind of procedure that returns the result of a calculation.
Full error handling setting of breakpoints and interrupt programming are also supported. Every ensures that a procedure will be executed repeatedly at specific time intervals. After makes sure that a procedure will be executed once after a specified number of clock ticks.
The GFA 3.0 tracing functions for debugging are very powerful. You can specify a procedure to execute after every command - perhaps the procedure would output the values of important variables to the printer. The system variable Trace$ contains the command being executed, so that you can always find out where you are in the program.
Graphics, GEM and Other Goodies
A complete complement of graphics for circles, boxes, filled shapes, polymarkers, patterns and lines are available. Text attributes and rotation can be specified and text strings can be put on the screen at any location. Limiting graphics to a given screen rectangle (clipping), direct Line-A support (with sprites), bit blitting, 16 graphics modes and a set of commands for simulated Logo "turtle graphics" are all available.
As with GFA 2.0, you can build GEM menus and install them at the top of the screen. On Menu can detect not only when a menu item has been selected, but other "events" such as GEM messages, window events (close box selected, slider clicked on, window moved, etc.), key. strokes and mouse events. Various messages are returned to the application in the array Menu(), enabling the program to detect what happened and respond appropriately. The application can keep an eye out for any combination of events. The built-in window commands let you set a window title and info line, clear a window, set a window's attributes or close it. Four windows can be open; each must have one corner anchored in a corner of the screen, only the center point (where the four windows meet) can be specified. You must modify the Windtab direcdy in order to get around this limitation.
GFA 2.0 and 3.0 support alert boxes and file selector boxes, with the latter returning the full name of the selected file. Also, GEMDOS, BIOS and XBIOS calls are available, but you must supply the number of the desired function as well as any additional parameters. However, three appendices of the GFA 3.0 manual detail the syntax of each command and give a short explanation of its purpose. This is generally not enough to use the function if you are not familiar with it, but a good GEM/BIOS/XBIOS reference guide will fill in the missing information.
GFA's programmers have also provided a complete set of commands in version 3.0 for calling assembly subroutines, using C routines located at a given address (perhaps in a string), for setting 68000 registers and even for loading and running another program.
almost all VDI and
AES calls by name.
Finally. version 3.0 lets you use almost all VDI and AES calls by name; you no longer need to remember the number of the call. You have direct access to those arrays (INTIN. ADDRIN, etc.) that must be initialized before being called. The VDI and AES libraries are amazingly complete, including graphics, object trees (dialog boxes, etc.), event trapping, the shell library menus and windows.
My only major complaint about version 3.0 is the manual. It's a disaster. It's so bad that much of the power of this language may go unrealized, simply because too many users won't be able to figure out how to use important commands. The manual is rife with incomplete sentences, stilted language, missing words and whole sections that make no sense.
Unfortunately, the manual really fails when it comes to the new commands. The German-to-English translator must not have known English very well. Or GFA BASIC. Or both. I'm an experienced GFA programmer and yet I found myself reading sections over and over again and finally giving up. Even worse, at least a third of the program listings simply don't work due to typographical errors. Attempts to enter the programs result in syntax errors and correcting the syntax sometimes resulted in spectacular crashes.
This manual must be rewritten. MichTron is aware of the problem, but it'll probably be a while before a revision comes along. It's not clear at this date whether the revised manual will be provided to current owners. If it is, you'll probably have to return your old manual to MichTron and pay a substantial charge-after all, the manual is over 600 pages. (This is to prevent piracy; MichTron naturally doesn't want you to give your old manual to a friend, although you might lose that friend if you did!)
I also don't like the way the manual is arranged. Similar commands are grouped together-program structure, string management, graphics, etc.- rather than alphabetically by command. While that makes some logical sense in terms of the language structure, it makes it very difficult to find a particular command. You must look a command up in the index in order to find it in the manual.
The Ultimate Question
The question, then, is should you buy this immensely powerful language? The answer is a qualified yes. The only qualification is that unless you need GFA BASIC 3.0's. power right away or are willing to expend the time necessary to decipher the manual, wait until version 3.0 is available with a revised manual.
Contributing Editor David Plotkin has an MS in Chemical Engineering
from UC Berkeley and is a Data Analyst for Chevron Corporation.
GFA BASIC 3.0, $99.95 ($40 for registered owners of earlier versions).
MichTron, Inc., 576 South Telegraph, Pontiac, Ml 48053, (313) 334-5700.
CIRCLE 151 ON READER SERVICE CARD