MULTILINE DELETE (ZX81)
by Chris Dellarocas, Athens, Greece
from Your Computer (April 1983) page 144

The lack of a DELETE command in ZX-81 BASIC has been in my opinion a major
shortcoming in a machine where the lack of DATA/READ, the lack of a
machine-code monitor and the limitations of memory have been forcing
programmers to create and then line-by-line delete lengthy loaders and
initialisers. Just think of the initialisation program of Simon Lane's Dog
Race  Your Computer July 1982. It comprises 126 lines.

Such reasons have prompted me to write the Multiline Delete routine. It
just takes 54 bytes and can be used without problem in both 1K and 16K
systems, in FAST or SLOW mode. The routine deletes any number of any
program lines  including line 0  contained between two given line numbers
 POKEd to locations FirstL and LastL, see programs. While  and this is
most important  conserving all existing BASIC variables.

The routine is relocatable with no changes to be made when moving it up or
down in memory. The only point needed to be taken into account is the
locations of the two words FirstL, and LastL. I consider it more useful to
move it above RAMtop and have it sit there during LOADs and SAVEs. That is
why I have written an optional relocator occupying 12 more bytes. You can
easily omit that if you wish to do so.

The routine is written around two very useful ROM routines. The first,
starting at 09D8H, returns the starling address of a given BASIC line in HL
and is used to determine the limits of the block of memory that is to be
deleted. The second, starting at 09ADH, changes all pointers  that is,
system variables between DFILE and STKEND  that do not point lower than
HL, by adding them to the value in BC.

I have written a short BASIC program to relocate, lines 10-20, drive the
routine and also demonstrate some of its features.

The program will be SAVEd under the name DEL and then automatically RUN.
Lines 10-20 will relocate the DEL routine to 7F00. while lines 30-70 will
use the same routine to delete unwanted lines 0-199. When you now LIST, you
will find yourself left with lines 9000 onwards. Type GOTO 9000 to discover
that A$ has been kept intact. You can now use the program through the BASIC
driver  lines 9988-9999  and its operation should present no problems.
However, you should note some of the following points: you do not have to
enter the exact starting and finishing lines of the block you want deleted.

The routine usually  but not always  causes the BASIC program from which
it is called to halt the report code.

Under normal operation the program cannot crash. But never enter a first
line number larger than the very last line of the resident BASIC program.
Also, avoid last line numbers larger than 16382. First line numbers should
never be larger than last line numbers.

1K users will probably want to leave the routine sitting in the REM
statement. Also, they will have to change the locations of FirstL and LastL
in memory by changing their references in locations 16523-24 respectively.

Calling addresses are:

    USR 16514 for the DEL routine if not moved
    USR 16568 for the Relocator