Renumber VIC-20 BASIC Lines The Easy Way
Charles H. Gould
Computer Science Department
Florida Institute of Technology
Until we have a ROM available, such as the Toolkit, for the VIC-20, here is a simple way to renumber lines in that crowded program you are writing. Simply type in the lines given below, and: RUN 10000. Better still, put this program on a separate tape, load it whenever you start a new program development; when complete, erase these lines. The program uses only 198 bytes, so 95% of your RAM is still there.
As shown, the renumbered lines start at line 10, and increment each line number by 10. But it does not change GOTO or GOSUB line numbers. You must manually change these after renumbering, and before running. An easy way to keep track of the GOTO and GOSUB terminal addresses is to insert "REM line #" at the end of each such statement, renumber, correct GOTO and GOSUB references to the new line numbers, and erase the REMs.
Line 9990 simply protects your program from entering the renumber routine until you want it to. In line 10010, Y7 is the starting line number, and in line 10050, the Y7 = Y7+ 10 sets the increment. Either can be changed. Line 10020 tests to see if we have renumbered up to, but not including, line 9990. Line 10030 changes the line number. Line 10040 searches for the next line. Y6 is the normal start of BASIC text (-1). The BASIC text lines are stored in RAM memory in this way: the first and second (LO and HI) bytes are a link to the next line; the third and fourth bytes are the line number (see line 10030 below); the BASIC statement is then given using tokens; the last byte of the line is a null (ASCII 0). After the last BASIC line, two more nulls are inserted to indicate end of program.
So, until we get support utility ROMs, let's make do.
9990 END 10000 REM RENUMBER 10010 Y6 = 4096 : Y7 = 10 10020 IFPEEK (Y6 + 3) = 6ANDPEEK(Y6 + 4) =39THENEND 10030 Y8 = INT(Y7/256) : Y9 = Y7 - 256 * Y8 : POKE Y6+ 3, Y9 : POKEY6 + 4, Y8 10040 IFPEEK (Y6 + 5)<>0THENY6 = Y6 + 1 : GOTO 10040 10050 Y7 = Y7 + 10 : Y6 = Y6 + 5 : GOTO10020