Although your ZX80 (both ROMs) or ZX81 does not have READ, DATA or RESTORE functions, you can easily mimic them with other functions.
Some background: String variables are like numerical variables, which we’ve already discussed–they are named by a letter and you assign values to them. Unlike numerical variables, the value you give a string variable is always a string of characters and these characters can be letters or numbers. String variable names always contain one letter and a dollar sign (A$, Q$) and the string itself is in quotation marks.
ZX80/81s always save variable values, whether strings or numbers. Thus, after running a program and entering values, you can save them on tape with the program. To use them again, remember to type GO TO X, where X is a line number after the variable assignment statements. RUN, CLEAR or NEW will erase the values you saved.
To simulate READ, DATA and RESTORE functions (described last month), you can just assign each string to a different string variable. Put the assignment lines at the beginning of your program:
10 INPUT A$
20 INPUT B$
The strings you enter for A$ and B$ will save with your program. To use them later, type GO TO 30. The program will execute from line 30 on, and not ask you to input A$ and B$ again. It will use the strings you already entered.
A way to more closely simulate READ, DATA and RESTORE is to use subroutines. You assign different values to only one string variable. This method also uses the ZX80/81’s ability to GO TO a calculated line number. The 4K program accompanying our telephone dialer project (Feb. 81) is a simple example.
The program stores names and telephone numbers. To put names into the program, you list them in short subroutines at the end (like DATA statements). We’ll ignore the phone numbers here. Use D$ as the string variable and put a RETURN after each:
700 LET D$="UNCLE JIM"
704 RETURN
710 LET D$="DIR. ASSISTANCE"
714 RETURN
720 LET D$="EMERGENCY"
724 RETURN
Notice that each set of line numbers differs only by 10. This lets us call the subroutines easily.
At the front of the program we find:
100 FOR G=1 TO 10
120 GO SUB 690+G*10
130 PRINT D$
140 NEXT G
If G=1 then 690+G*10=700, the first subroutine’s line number. The computer goes to 700, assigns D$ the string “UNCLE JIM”, then returns to the line after the GO SUB (line 130). Now it prints UNCLE JIM and goes to the next line, 140. Line 140, the end of the FOR-NEXT loop, sends it back to line 100. Now G=2, so the GO SUB in line 120 send the computer to 690+2*10, or line 710. Line 710 assigns another string, “DIR. ASSISTANCE”, to D$. Line 714 returns the computer to line 130. The cycle continues till all values for D$ have been read.
In this example, the GO SUB within the FOR-NEXT loop acts as a READ statement. The short subroutines assigning values act as DATA statements.
To simulate RESTORE, you need only use a GO TO 100 statement. This sends the computer back to the first “READ” line to start all over. When you save this program, you can type RUN because the values are not stored as variables but as program lines.
These methods work on both ROMs.
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.