Classic Computer Magazine Archive COMPUTE! ISSUE 61 / JUNE 1985 / PAGE 106

Apple ProDOS Variable Lister

Paul F. Stuever

This fast machine language utility takes the pain out of debugging BASIC programs by listing the current value of every program variable. You can also make a hardcopy of the variable list. ProDOS is required.

How many times have you run a program, only to get a message like OVERFLOW ERROR IN 240, or worse yet, BAD SUBSCRIPT ERROR IN 240? When you list the line in question, it may look something like this:

240 A$(X +XZ,2 * (B / 4 = C + 1),B / 4) = STR$ (Z)

To locate the error, you'll need to type PRINT X, followed by PRINT XZ and so on, to find the current value of each variable. This is a slow, tedious way to debug a program, especially when you find that some of these variables were defined with other formulas.

"Apple Variable Lister" takes the drudgery out of such debugging tasks by quickly listing the current value of every variable in your program. The program is written in machine language and works on any Apple II series computer with ProDOS.

You can use this utility even if you don't understand machine language: The BASIC loader program listed below creates the machine language and saves it on your disk. Type in the loader, and save a copy before you run it in case you made a typing error. The program has a checksum to catch errors and identify any lines that have mistakes. If no errors are found, it prints OK and saves the utility with the filename VAR.LIST on your disk as a binary file.

Once this is done, you're ready to use the lister. Enter BLOAD VAR. LIST to load it into memory, followed by HIMEM: 31000 to set the top of memory. You will ordinarily want to do this at the beginning of a programming session. To list your variables, simply type CALL 32000 and press RETURN. The same command can run the routine from within a BASIC program. To make a hardcopy of the variable list, enter PR#1 before calling the routine.

A Chronological List

Variable Lister displays your program's arrays first, followed by floating point, string, and integer variables. The variables are displayed in chronological order (the order they are used in the program), not alphabetically. Although Applesoft BASIC allows arrays with up to 88 dimensions and as many elements per dimension as available memory will allow, Variable Lister is more restrictive. For this program, arrays are limited to three dimensions and a maximum of 254 elements per dimension. Attempting to list a larger array—for example, the one created by DIM A$(500)—crashes the utility.

Note that Variable Lister cannot display a variable until it has actually been used in the program. For instance, consider the following line:

10 A$="YES" : IF A$="NO" THEN B$="OK"

Since the IF condition can never be satisfied, B$ will not appear on the variable list unless the program uses it elsewhere. This is no problem when debugging, since you're interested only in variables that were used up to the time the program crashed. However, to make a complete variable list for permanent documentation, you'll need to run your program until you know that every variable has been used.