READ/DATA/RESTORE on the ZX-81/TS-1000

See all articles from QZX v3 n9
Author(s): Clement Wehner
Publication: QZX
Pub Details: QZX v3 n9 (Volume 3, Issue 9)
Date: August 1985
Pages: 7-8

Though the BASIC in the ZX and TS computers is excellent, it does lack READ, DATA,and RESTORE statements. To get around that shortcoming we usually store data in variables. The procedure in this article will give you READ/DATA/RESTORE capability. The idea was inspired by a brilliant article in September 1983 Sync magazine by John Richard Coffey.

What must be done is to enter a short machine language program, store it on tape, then load it into your computer before writing a BASIC program that uses READ and DATA. The entire program will reside in the first line of program (1 REM) and only take 80 bytes. Here’s how to do it:

1. Turn on the computer and type in this program:

1 REM 00000.....(put 80 zeroes in this line)
5 LET X = 0
10 FOR I = 16514 TO 16592
20 PRINT "ENTER NUMBER"
30 INPUT A
40 POKE I,A
50 LET X = X + A
60 CLS
70 NEXT I
80 PRINT "CHECKSUM = "; X

2. Now, RUN the program. Enter the following numbers reading from left to right and top to bottom.

                TABLE 1
33   250  64   62   234  1    255  255
237  177  1    5    0    167  237  66
62   118  190  40   5    9    34   123
64   201  9    24   230  42   123  64
62   118  190  204  133  64   126  35
24   236  42   20   64   43   229  43
43   227  229  205  159  64   225  6
26   184  40   13   119  35   227  52
32   3    35   52   43   227  167  48
233  227  225  0    195  157  20

3. Double check that you entered the numbers correctly. The checksum should equal 8533 . If it doesn’t then you made an error. Run this diagnostic program, by entering it then enter GOTO 100.

100 FOR I = 16514 TO 16592
110 PRINT I ; " = " ; PEEK I
120 NEXT I

Compare the numbers on the screen with Table 1. If you find your error POKE the address that had the error with the correct number. e.g.(POKE 16514,33)

4. Delete all program lines except line 1.

5. Save the program on tape.

To use this new program to write a program using the READ/DATA concept do this:

1. Load the 1 REM program you just saved.

2. Write your BASIC program, making substitutions as follows:

   In place of RESTORE, use RAND USR 16514
   In place of READ, use LET A$=" "
                             RAND USR 16556
    (NOTE:Any string variable may be used).

   In place of DATA, use REM
     NOTE: commas must separate each item
     in the REM statement. Therefore, there
     can be no commas as part of the data.
     There must be a comma following the
     last data item. e.g.:
        100 REM  Mike,Jim,Ben,Kenneth,END,

3. That all there is to it. You may now store data in REM statements. The REMs can be located anywhere in your program. BUT, you cannot have other REM statements (other than line 1 REM) preceding those holding your data. Therefore it’s a good idea to put the data REMs at the beginning of your program (starting with line 2).

To stop the reading of data, have your program check for an END or any data terminator you chose.

4. EXAMPLE PROGRAM 1. Here’s how it works:

10 RAND USR 16514
20 LET A$ = ""
30 RAND USR 16556
40 IF A$= "END" THEN STOP
50 PRINT A$
60 GOTO 20
100 REM MIKE,JIM,BEN,KEN,END,

Line 10 acts like RESTORE and tells the program to read the first data item. Line 20 clears A$. Line 30 reads the first data item in the REM statement (MIKE) and stores it in A$. Line 40 checks for the end. Line 50 prints the contents of A$ (MIKE). Line 60 sends the program back to line 20 to begin reading the next data item (JIM). This looping continues until the program reaches the END.

EXAMPLE PROGRAM 2 “MAILING LABEL MAKER”

2 REM CLEM WEHNER,2135A WILLOWWOOD,
SCOTT IL 62225,
3 REM BILL JONES,1234 S. STREET,
ANYTOWN AZ 76311,
4 REM END,
10 RAND USR 16514
20 LET A$ = ""
30 RAND USR 16556
40 IF A$ = "END" THEN STOP
50 LET B$ = ""
60 RAND USR 16556
70 LET C$ = ""
80 RAND USR 16556
85 REM PRINT LABELS
90 PRINT A$
100 PRINT B$
110 PRINT C$
120 PRINT
130 GOTO 20

IMPORTANT: Note the commas at the end of each REM including the END. Commas are not used within the data elements, but only to separate elements. If you get garbage when you run this program, you probably forgot the commas or forgot to check for the data terminator (END). Line 85 is OK because it is after the last data REM.

This program corrects one of the few major shortcomings of the Timex Sinclair computer. Use it to keep a log, to keep records of parts on hand, etc. I hope it serves you well. (If you don’t want to type it all in, I’ll make a tape copy of the program for you for $3.50. My address is in line 2 of Example Program 2). 73’s es gud hamming.