                      Block deletion



            A useful utility for the Spectrum,

           courtesy of Rodney Francis of Essex.



This program in machine code, with a BASIC starter, has

been written to provide a very fast method of deleting a

block of BASIC program. It saves all the tediousness of

deleting one line at a time.

   The machine code is relocatable anywhere above RAMtop,

but for demonstration purposes it starts at address 32000

(7D00 Hex). If it is relocated, the last line of the BASIC

program must be altered accordingly.

   The BASIC program, which has been deliberately numbered

to be at the end of your own program and is called by a

GO TO 9992 command, starts by asking for the limiting line

numbers. These are checked for obvious inconsistencies and

are then POKEd into a temporary store in the printer buffer

for use by the machine code routine. The machine code

routine is then run. All that is now necessary is to delete

the first line number of the block in the normal way.

  Care should be taken to ensure that both the first and

last line numbers actually exist in the program. If the

first line does not exist the result will not be too

disastrous, but you will have to delete the next existing

line number in the normal way to complete the deletion.

However, more critical would be entering a last line which

does not exist, because the resulting deletion would

include the next existing line following the line entered.

===========================================================

ld hl,(23296)-+

call 6510     |Find the address of the first byte of the

inc hl        |line length for the first line to be deleted

inc hl        |and put it on the stack.

push hl      -+

ld hl,(23298)-+

call 6510     |Find the address of the first byte of the

inc hl        |line length for the last line to be deleted.

inc hl       -+



ld e,(hl)    -+

inc hl        |Find the length of the last line and hence

ld d,(hl)     |find the address following the end of the

inc hl        |last line.

add hl,de    -+

pop de       -+

push de       |Recover the address of the first byte of the

and a         |line length of the first line to be deleted

sbc hl,de     |and restore it on the stack; then calculate

dec hl        |the total number of bytes (excluding the

dec hl       -+first four) to be deleted.

ex de,hl     -+

pop hl        |Insert this number into the line length of

ld (hl),e     |the first number to be deleted.

inc hl        |

ld (hl),d     |

ret          -+

Fig. 2. The mnemonics and description of the machine code

routine.

===========================================================

The deletion of the first line causes the deletion of the

whole block because the machine code routine has altered

its line length to include all the following data which is

to be removed. The computer now thinks that the first line

of the block extends to the end of the last line.



[The TZX contains first the BASIC starter program, which

 does not auto-run (because it should be MERGEd with your

 program anyway), and which does not auto-load the machine

 code, either. After that comes the machine code, which,

 therefore, you must load yourself at the resired address -

 as mentioned, it's relocatable. Don't forget to CLEAR.]