When Sinclair’s 8K ROM came out, many owners were disappointed that the promised READ, DATA and RESTORE functions were removed. But you can get around this limitation. (This is covered briefly in the 8K manual on p.146 and in the ZX81 manual on p.106.)
If the ZX80/1 is your first computer, you may not know the usefulness of READ, DATA and RESTORE.
In other BASICs, you can store numbers, or data, in a DATA line. A DATA line looks like this:
10 DATA 1,2,3,4
This line stores the numbers 1, 2, 3 and 4.
READ lines assign the elements of a DATA line to variables, using each piece of data in order:
10 READ X
20 PRINT X
30 DATA 1,2,3,4
40 GOTO 10
This program prints the numbers 1 to 4. In line 10, the computer goes to the DATA line and assigns the first data value, 1, to X. Line 20 prints X. Line 40 sends the computer back to the READ line. This time it assigns the second value, 2, to X, and so on, until all the data values are used.
RESTORE just tells the computer to start over with the first data value again.
These functions allow you to enter and save data in your program in one DATA line.
In a ZX80/1 (either ROM), you can save variables in arrays. To simulate the READ, DATA, RESTORE functions, you set up an array to hold your data, using the DIM (dimension) statement. Say you want to save 5 numbers. On an 8K machine, DIM A(5). (A is an arbitrary choice of array name; any single letter will do.) Your array elements are A(1)-A(5). On a 4K machine, DIM A(4). Your array elements are A(0)-A(4).
Each array element is zero at the start. An input loop assigns the value you want to each element:
10 DIM A(5) (program 1)
20 FOR X=1 TO 5
30 INPUT A(X)
40 NEXT X
The numbers you enter are now stored as the array A. If you delete these lines, the array A still exists in the computer’s memory and will save on tape. So delete these lines by typing each line number, then NL or ENTER (ENTER is the new name for NL on ZX81s.) Or just type in your program using those line numbers again. The new lines will replace old ones with the same number.
You can use array A in your new program. It stays in memory until you type NEW or CLEAR (which clears everything in memory) or load another program over it.
After typing your new program, save it on tape. Reload it, but DON’T TYPE RUN! Use GOTO (the first line number) instead. RUN also clears all variables in memory, and you’ll lose the values you saved in array A. Here’s a sample program to show you how this method works. You can run it on either a 4K or 8K machine (just change DIM A(5) to DIM A(4) for a 4K ROM, then change X=1 TO 5 to X=0 TO 4.): Type in the input loop (program 1), then RUN. Input any 5 numbers in response the the input prompts. Delete line 40 by typing 40 (NL or ENTER).
10 FOR L=1 TO 5
20 PRINT "ELEMENT NO. ";L;" IS
";A(L)
30 NEXT L
SAVE
LOAD
GOTO 10
Granted, this is a trivial example. But you can use this method to input any data and use it in another program. It mimics the READ, DATA and RESTORE functions by allowing you to enter data only once and use it many times. You save time and bytes by not typing in the numbers each time and using memory for the input lines. Remember to use GOTO and not RUN to use the second program. Otherwise you erase any variables you saved.
Next month we’ll see how to save string variables using this method. Mel Routt’s Job Review program, p.6, uses this method to save numbers and strings. Note his Loading Technique hint, p.8, to remind you to use GOTO instead of RUN to preserve stored variables.
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.