READ-DATA-RESTORE for Sinclair ZX-81
by David Nowotnik
from ZX Computing, February 1987

We have received several enquiries from avid 81ers about the possibility of
adding RESTORE, DATA and READ to the ZX81.

There have been several methods which have simulated these oeprations such
as storing DATA in REM lines and PEEKing it into variables, but the most
efficient that I have encountered was written by our own regular writer
David Nowotnik for us in the heyday of the ZX81 in 1983. As many existing
users will undoubtedly have missed this system I have no hesitation in
reprinting it, especially in light of the recent requests for such a
routine.

[The original article written by David Nowotnik appear in Home Computing
Weekly, 28 June - 4 Jul 1983]

Restore/Data/Read
-----------------
The program consists of two routines whcih must be located int he first REM
line statement of the program. The length is a mere 128 bytes.

RESTORE resets the program pointer to the start of the DATA line and is
used by the command RAND USR 16520.

READ has two possible forms, LET C$=A$(TO USR 16530) to read string or
character data, and LET C=VAL A$(TO USR 16530).

DATA lines are stored in any line but with REM and the graphic obtained on
shifted key A following it (a 'grey' square).

9999
----
A final indicator to the routine that it has reached the end of the program
is required and this is provided in the form of a line 999 REM followed by
the inverse space (black square). This line is ESSENTIAL.

The DIM A$ and CLEAR commands instructions are important in the main
program as it ensures that the variables A$ is the first in the variable
area of memory and the main routine can locate it.

you may find that LIST produces just 1 REM, to overcome this use LIST 2 (or
3 or 100 or 3000 etc).

Data REMs should have the number of data itmes as the first character
following the grey square after the REM. For example:

170 REM #4,EENY,MEENY,MINY,MO      [where # represents graphic shifted 'A']

Finally, note that you cannot mix numeric and string data on the same data
line, two or more lines will be required and dummy READs will be needed to
jump over the unrequired data.

[It is actually possible to mix numeric and string data so long as the
user's program knows how to interprete each piece of data returned. The
first item does not have to be the number of data items, which is only
required for the example program presented. If there are no data items in
the program then an error message is displayed and an infinite will occur
because the routine attempts to wrap back to the beginning of the program
and search for the first data item. If an out of data condition occurs then
an error message is displayed but the routine assumes that an expanded
display file exists, i.e. there is 3.25K or more of RAM present, and so
corruption of the variables area will occur if this is not the case, e.g.
if the SCROLL command has been used.]
