SPACED OUT NUMBERS
Get even with your BASIC programs
by JERRY WHITE and FERNANDO HERRERA
RENUMBER is a utility routine that renumbers any BASIC program. It runs on all Atari computers, and requires 16K RAM and BASIC.
This month's utility is a subroutine that changes line numbers and references to line numbers in Atari BASIC programs.
It is written entirely in Atari BASIC. The subroutine and the program to be renumbered share your computer's RAM. After you type in the program, store it on tape using the command LIST"C:" [RETURN] or on disk with LIST"D:RENUMBER.LST" [RETURN].
To use this program, you must first place the program to be renumbered in RAM, and then ENTER the renumber program from tape or disk. With both programs in memory, press [RESET]. Then use the immediate mode command GOTO 31000 [RETURN].
RENUMBER asks you for a new starting line number and line-increment amount. For example, if you want your program to begin at line 100 and increment each line number by 10, respond with 100 [RETURN] to the first prompt and 10 [RETURN] to the second.
To speed execution, the screen is turned off during the renumbering process. When renumbering is complete, or if an error occurs, the screen is turned back on again.
Test your renumbered program before storing it back onto tape or disk. Store it using the LIST command -- if you use SAVE or CSAVE, you'll store both your program and the renumber utility. To store your renumbered progam on tape, use the command LIST"C:"0,30999 [RETURN]. To store on disk, use the command LIST"D:FILENAME.EXT",0,30999[RETURN].
If you want to store a tokenized or SAVEd version of your renumbered program, you must next erase the program in memory by using the immediate-mode command NEW [RETURN]. Use ENTER to bring your renumbered program back into RAM. Then simply CSAVE or SAVE your program onto tape or disk.
The renumber program begins at line 31000. By using line numbers 0 and 310999 in the list command, you tell BASIC to LIST only the lines in that range. Make sure that the program to be renumbered does not contain any line numbers greater than 30999. This maximum line number also applies to your renumbered program, so keep it in mind when you enter your starting line number and increment.
It must be possible for your program and the renumbering program to coexist in your computer's memory. Note that the renumbering program requires 4,478 bytes of RAM and uses 22 variables. Since Atari BASIC permits a maximum of128 variables, your program cannot use more than 106 unique varible names.
This utility program changes all line number references in commands such as TRAP, GOTO, GOSUB, and RESTORE. When a variable is used to indicate a line number, this program changes only the first occurrence of that variable. The example below shows a short program before and after renumbering. If these sample programs were to be run, the first version would display the numbers 30 and 0. The second version (after renumbering) would display the numbers 130 and 0. To avoid problems when variables are used as line number references, assign only one value and avoid the use of expressions.
15 GOSUB J
20 GOTO 50
30 PRINT J
60 GOSUB 3O
110 GOSUB J
120 GOTO 150
130 PRINT J
160 GOSUB 1304
When The evaluation of an arithmetic or logical expression is used to represent a line number the expression remains unchanged, but its existence is indicated in an error screen listing. Copy any error messages onto paper, and then make any necessary corrections to your program.
The message "LINE NOT FOUND" means that your program has an unreferenced line number. Unless this refers to a TRAP reset command, such as TRAP 40000, this indicates that there's a bug in your program.
The message "VARIABLE NOT DEFINED" means that there is a variable in the variable table that isn't used in your program. This is not a fatal error, and it can be ignored. To get rid of unused variables, store your program using the LIST command, enter a NEW command, reload your program with the ENTER command, and then store your program back on tape or disk using the CSAVE or SAVE command.
The message "LOGIC OR ARITHMETIC EXPRESSION" is used to flag each occurrence of unchanged expressions. You'll have to change these expressions manually to ensure that your renumbered program runs properly.
In future issues of Antic, we'll provide other useful utility subroutines and programs like this one. These routines must often coexist with one of your BASIC programs. In an effort to avoid potential conflicts, we'll use line numbers that are greater than 30000 whenever possible. Keep your line numbers below 30000, and your programs can coexist with our utilities.
If you have any questions on how to do something in Atari BASIC, or requests for utility programs, please send them to Jerry White c/o Antic, 524 Second Street, San Francisco, CA 94107.
Jerry White is an institution in the world of Atari computing, and a long-time Antic Contributing Editor. Fernando Herrera won the first APX (Atari Program Exchange) Star software award in 1981 for My First Alphabet. That award suggested a name for the software publishing firm he founded, First Star Software, a company with which he is still associated.