THE INVISIBLE TOOLKIT for Sinclair ZX-81
by Stuart Clarke
from Your Computer, March 1985

Stuart Clarke presents a number of machine-code routines
for the ZX-81 which are driven by a short Basic menu.


[Having typed in this program I found some errors for which I don't  ]
[as yet have corrections.                                            ]
[1) The program has nine options on the menu, but there's only code  ]
[   to take action on six of them.                                   ]
[2) The menu doesn't work anyway, because the machine code which sets]
[it up sets E_LINE below VARS, so the ROM can't find any of the      ]
[program variables after the first one, as at the end of the first   ]
[pass through its searching loop it finds that its search point is   ]
[above E_LINE, so it stops with the error "2 Undefined variable".    ]


THE INVISIBLE TOOLKIT is a suite of fast, efficient machine-code
routines driven by a short Basic menu. Due to the fact that extensive
use is made of routines already present in the ROM the machine-code is
written in less than 800 bytes which, together with the Basic lines,
occupies less than 1800 bytes of memory.

The program was written to make it easier to modify and develop a
Basic program and even combine two or more Basic programs or routines
- so that the idea of having a library of useful subroutines on
cassette is quite feasible. In addition, the facility to create large
REMs, or delete them at a stroke, is invaluable when assembling
machine code.

The following routines are available:
DOWN CODE - used after Up Code. Downloads the copy in upper memory
into a specified line and Address. Space is automatically created.
DOWN BASIC - used after Up Basic. Brings the Basic copy down into the
Basic area placing it according to the first line number of the block.
LINE ADDRESS - gives the address of the specified line number. The
first character is four bytes further on.
REM EXPAND - expands the REM statement with the specified line number,
from a specified address, by a given number of bytes.
UP CODE - copies a given number of bytes from a given address, into
upper memory.
UP BASIC - copies a block of Basic lines specified by first and last
lines.
BLOCK DELETE - specify first and last lines.
RENUMBER BASIC - renumbers a block of Basic lines specified by first
and last lines. You are allowed to specify both the Increment and the
New first line number. All non-computed GOTOs, GOSUBs, and RUNs will
be correctly changed, provided the line number is in four-digit form;
eg. GOTO 1 as GOTO 0001.
RENUMBER COPY - used after Up Basic. Only requires the Increment and
New first line number to be specified.

The order in which the routines are listed may seem a little odd, but
this is as they appear in the menu. This is dictated by the use of
relative rather than absolute jumps in the machine-code to allow it to
be position independent, and the entire program has been written in
such a way that, as well as the machine code, the Basic menu can be
transferred to upper memory - without overwriting existing upper
memory contents - to allow the Loading of subsequent programs.

When required, the menu can be recalled, and it will not clash with
the existing Basic as its lines are numbered A222 to A239 - 10222 to
10239. This is possible since the ROM checks the validity of a line
number by only comparing the high byte with 40 decimal - 40 times 256
equals 10240, the first "non-valid" line number.

However, line numbers in the range 10000 to 11239 are only obtained by
using the Renumber routine, as 9999 is the largest line you can enter
direct from the keyboard. The menu lines are now tagged on to the end
of the program you have just Loaded.

If the typing seems a bit of a chore, just send your name and address
with a cheque for 3 made payable to Sarglen Software, to [address
removed], and I will send you a quality cassette with two copies each
for machines with and without the "improved ROM", together with an
instruction leaflet.

Type in program 1, then duplicate line 1 using the Edit key so that
you have 12 identical lines, numbered 1 to 12. Now Run program 1.

Type in program 2, and Run it. This is the hex loader. Enter the
address 16514 - or the appropriate address if you are resuming after a
break - and enter the hex codes listed in figure 1. You may enter any
number of bytes at a time, and the screen display should tally with
figure 2. [Figure 2 was actually the "unimproved ROM" POKES, as given
below. JimG] If you make a mistake input "S", which will stop the
program. To recommence, simply GOTO 10, and enter your new starting
address.

When this is complete - and you should have Saved your program at
several stages - Save the program thus far.

If your ZX-81 has the "unimproved" Rom, identified by PRINT PEEK 5404
giving 253, then you must enter the five Pokes in fig. 2 before Saving
and proceeding further.

Figure 2.
POKE 17051,28
POKE 17054,244
POKE 17082,28
POKE 17091,28
POKE 17110,201

Type in program 3. This is most of the Basic required to transfer the
code to upper memory and provide the operating menu. When you have
Saved this, Run it. You should now have the menu on screen, so select
8 - Renumber - and enter the numbers 290, 460, 1, and 10222 in
response to the prompts. Almost immediately, the menu lines will be
renumbered from A222 to A239 - 10222 to 10239.

If all is well, type in program 4, the remaining Basic, and Save the
program again. You are now ready to Save this, the final completed
program in auto-run mode. To do this simply Run the program whilst
recording in the usual way. When the program has Saved, you will find
that the Basic program area has been cleared and the menu lines are
now stored above Ramtop where they will remain until required.
Similarly, this occurs when you Load the auto-run version.

The Invisible Toolkit is now ready to use, so refer to the
instructions and try it out.

Using the toolkit is easy. After Loading,
	RAND USR (ZX81+2)
retrieves the Basic from above Ramtop, and GOTO 10222 displays the
menu. The first prompt requires you to input your selection - 1 to 9 -
and the next four prompts expect numerical input, for example line
number, address - or any number if the menu indicates a blank.

When you wish to Load another program on which to use the toolkit,
there are a couple of things to remember. First make sure that the
menu lines are back above Ramtop - if not, use Copy Basic to do so.
Then note down the contents of locations 16507 and 16508, as you will
need to restore them after Loading. Also, the variable ZX81 will have
to be restored after Loading - also after Run and Clear, which are
best avoided.

After you have LOADed the program you intend to work on, and restored
the system variables 16507 and 16508, and ZX81
	RAND USR (ZX81+2)
and away you go!


--


Report codes.

K/A234  you have attempted to use Down Code when no
        copy exists in upper memory.
T/A233  you have attempted to use Down Basic or Renumber Basic
        when the "live" copy is not Basic.


--


System variables.

16388-16389  RAMtop
16507-16508  Old RAMtop
16444-16451  Poked by menu
ZX81         variable pointing to the first location in the
             "jump table" accessing the machine-code routines.


--
