LINE RENUMBER
by Kenneth Baker
from ZX Computing April 1987


A programming utility from Kenneth Baker.


A good Line Renumber program is, without doubt, one of the most useful
programs that anyone could wish to add to their collection. However, the
problem with most utilities is that they demand a fixed position in
memory, and usually require a small BASIC program to operate them. This
is not the case with this program - because it can be loaded to any
convenient position in memory at any time: it also contains routines to
tell itself where it is located in memory, and to renumber its own
variables accordingly. It also has its own input routines, dispensing
with the need for a BASIC control program.

The routines in the main part of the program have been designed to cater
for every imaginable situation: all forms of GOTO, GOSUB, RUN, RESTORE
and SAVE ... LINE statements can be renumbered (including microdrive),
even when in complex conditional form.

Add to this the data for various captions, and the original renumber
routine, which is a mere thirty-three bytes in length, grows into a
somewhat larger 1140 bytes!

[The next three paragraphs are supposed to describe the hex loader program]
[but, as they bear no relation to the actual hex loader printed in the    ]
[magazine, I haven't bothered to include them.                        JimG]

You can now experiment with the program by renumbering the HEX LOADER
program. Use RANDOMIZE USR 60000 (or whatever address you have chosen)
and, if everything is in order, a prompt will appear in the lower part
of the screen requesting you to: ENTER STARTING LINE, STEP SIZE

This requires you to enter two values separated by a comma, followed by
ENTER. The values entered must be such that the STEP SIZE is not greater
than the STARTING LINE, although the two can be equal. Otherwise you can
enter any values you like - 1,1 - 999,99 - 9000,2 etc. If you type in
rubbish, illegal values, or ENTER with no values at all, the system will
automatically use the values 10,10.

Directly the renumbering process has been completed (in a fraction of a
second with an average program) the program title will appear on the
screen, where it will remain until a key is pressed. The only
restrictions concerning the use of the program are that the first line
of a program to be renumbered must contain a REM statement, and
corresponding addresses must exist for any commands involving line
numbers: a statement like GOTO 100 would be ignored if Line 100 does not
exist.

Normally, assuming that the program is safely stored on cassette, it can
be loaded to any position in memory by using the following sequence:

1. Choose a suitable address.
2. CLEAR address.
3. LOAD "" CODE address.
4. Make sure that first line of program is a REM.
5. RANDOMIZE USR address.
6. ENTER STARTING LINE, STEP SIZE

Machine code buffs will detect instantly that the same address has been
used for all three commands: this is permissible in this case because
the first instruction In the program has the same code as the RAMTOP
marker, LD A,N. RAMTOP can of course be set at any address you desire,
provided that it is somewhere below the [address] concerned.


Display file

It was mentioned earlier that this program could be entered anywhere -
it can also be stored in the Display File (at address 19000) in cases
where renumbering is an afterthought, or where you only intend to use
the program once. You will not need to use the CLEAR command with this
method, but you must use CLS first, so try:

CLS
LOAD "" CODE 19000
RANDOMIZE USR 19000

and the program will execute in the normal way. You will have to reload
the program each time you use this method, as the program will vanish
directly you enter a command, but the method does have many advantages -
principally that, because CLEAR is not used, all of the variables are
left intact, and you are not left with the unwanted renumber program in
the computer once it has performed its brief task.

If you do ever wish to remove the code from the computer, the following
command is suggested:

FOR n=address TO address+1140: POKE n,0: NEXT n


--
Another Fine Product transcribed by:
Jim Grimwood, Weardale, England (http://www.users.globalnet.co.uk/~jimg/)
--
