A Line Renumbering Utility
D. M. Gropper, Newburgh, Indiana
Most programmers developing a program need to insert lines of code into what they have already written. The current version of Atari BASIC does not have a "RENUM" or "RESequence" command available to the user. The following short program was written to give the capability of renumbering BASIC language programs.
9000 PRINT "RENUM UTILITY ACTIVE" 9010 ADDR = PEEK(136) + PEEK(137) * 256 9020 PRINT "INPUT STARTING NUMBER AND" 9030 PRINT "INCREMENT (FORMAT X, Y)" 9040 INPUT START, INCR 9050 LNUM = PEEK(ADDR) + PEEK(ADDR + 1) * 256 9060 NADDR = ADDR + PEEK(ADDR + 2) * 256 9070 IF (LNUM = 32768) OR (LNUM = 9000) THEN GOTO 9110 9080 LOWNUM = INT(START / 256) : HINUM = INT(START - (LOWNUM * 256)) 9090 POKE ADDR, HINUM : POKE ADDR + 1, LOWNUM 9100 START = START + INCR : ADDR = NADR : GOTO 9050 9110 PRINT "RENUMBERING ENDED AT" ; START - INCR 9120 END
LINE 9010; The address of any BASIC programs' first line is given by the contents of locations 136 and 137.
LINE 9050: The first two bytes, starting at the address from line 9010, contain the actual line number.
LINE 9060: The third byte contains the length of the line in bytes, so adding this to the address given by locations 136, 137 will give the address of the next line.
LINE 9070: Here we are testing for the end of the program, L = 32768, or the start of the utility, L = 9000
LINE 9080: The new line number is broken into two bytes,
LINE 9090: And ‘POKEd’ back into the line number bytes.
LINE 9100: Update the line number and address and repeat.
LINE 9110: All done... Let's get out of here and tell the programmer what the last line change was.
9010 D = 256 : S = 100 : I = 10 : X = PEEK(136) + PEEK(137) * D 9020 L = PEEK(X) + PEEK(X + 1) * D : N = X + PEEK(X + 2) : IF (L = 32768) OR(L = 9010) THEN END 9030 HN = INT(S/D) : LN = INT(S - (HN * D)) : POKE X, LN : POKE X + 1, HN : S = S + I : X = N : GOTO 9020
This program occupies 534 bytes. Listing 2 is the same thing only compacted down to 289 bytes for those of us who get tight on memory space. A point to note is that listing 2 assumes starting the line renumbering with a line number of 100 and incrementing by 10.
A not so obvious point is that only the line numbers are changed and not the sequence of execution. For example:
100 X = 100: ? X 110 Y = 200: ? Y 120 Z = 300: ? Z
If we now use listing 1 to resequence starting with 120 and using an increment of-10 (in other words decrementing) then the end result is:
120 X = 100: ? X 110 Y = 200: ? Y 100 Z = 300: ? Z
The output on the screen on running the renumbered program would be:
100 200 300
, because the locations 136 and 137 still point to the first line which is now line number 120. The third byte at this address is still the length of the line in bytes so the next line to be executed is the now-numbered 110, etc.
For those of you who like to experiment — take the above example and renumber starting at number 1 and use an increment of 2 and then "LIST" the result. If you bear in mind the editing capability of the Atari then the reason for the "LISTed" result becomes obvious.
One last point — if you do use this utility then please remember that you will have to manually change any "GOSUB" or "GOTO" line references.