AUTO-REM for Sinclair ZX-81
by Andy Scott
from Your Computer, November 1983

To store machine code routines on the ZX-81, the usual method is to
create a REM statement at the beginning of a Basic program containing
a number of characters corresponding to the length of the machine
code. For large machine code routines this can be tedious.

The short machine code program described here will automatically
create a REM statement of the correct length. The routine will be
stored above RAMtop and uses 54 bytes, plus two bytes to store the
size of the REM. Since no absolute address calls within itself are
used it can, in fact, be located anywhere.

First type in Listing 1. To load the hexadecimal code RUN 100 (N/L).
Input the code from Listing 2 either as single bytes; eg. ED plus N/L
or as multiple bytes; eg. ED4BFE7FC521 plus N/L. Always enter each
byte as two digits - eg. 06 and not 6. On completion of the loading,
enter S plus N/L. Now delete lines 100 onwards and SAVE on tape.

To use the program, RAMtop will have to be lowered to accommodate the
routine. Assuming a 16K ZX-81 and it is to be stored at the top of RAM:
	POKE 16388,200 (N/L)
	POKE 16389,127 (N/L)
	NEW (N/L)
Now load your previously SAVEd program and RUN. This will relocate the
machine code to above RAMtop. NEW can be performed now if it is
wished.

Locations 32766 and 32767 - the top two bytes of the machine code -
are used to store the amount of memory that is required in the AutoREM
statement - low byte and high byte respectively. These can either be
POKEd with the correct number or the short program in Listing 3 can be
used.

To enable the AutoREM to work, at least one Basic line must be present
before using it - eg. 10 REM. This may later be deleted of course. To
operate AutoREM, after having initialised 32766/7:
	RAND USR 32712
Now LIST. A new line 0 has been created with the correct number of
locations within the REM - these are filled with 0.


Changes must be made

If another area is to be used to store Listing 2, changes will have to
be made to RAMtop, to line 30 in Listing 1 and Lines 1060 and 1070 in
Listing 3. Also a different RAND USR number will be needed - this
points to the first byte of the machine code program. 

If, for some reason, your created line 0 needs to be deleted
	POKE 16510,1
- this changes its line number to 1 - then delete line 1. This is
because it is not possible to delete line 0.

The routine is suitable for both old and new Sinclair ROMs.

