DATA Statement Simulation

See all articles from SYNC v1 n2

One of the most noticeable shortcomings of the ZX80 Basic is that there are no DATA statements.

With numbers it is possible to simulate the DATA, READ and RESTORE instructions by a simple program.

This can be done using a REM statement. The numbers are placed in a list within the REM statement, as is done with DATA statements, separating each number by a comma, and ending the list with a comma.

The DATA is then read by PEEKing the number out of the REM statement and placing it in a variable, as demonstrated in Demo 1.

10   REM  12, 65, -2165, 9, 0, -1,      DATA STATEMENT
11 LET D = 0 FLAG FOR + OR - NO.
15 LET C = 0 NO. READ FROM DATA
16 LET E = 16427 BEGINNING OF DATA
20 GOSUB 100 EXTRACT FIRST NUMBER
22 IF D = 1 THEN LET C = -C IS D SET? IF SO CHANGE SIGN
23 LET D = 0 RESET FLAG
25 LET E = A + E + 1 POINTER TO NEXT NO. ON DATA
30 PRINT C NO. FROM DATA
40 LET C = 0
50 INPUT A$ PRESS NEWLINE TO EXTRACT NEXT NUMBER
70 GOTO 20
80 STOP

100 FOR A = 0 TO 100
110 LET B = PEEK(E + A) - 28
120 IF B = 188 THEN RETURN CHECK FOR COMMA
125 IF B = 90 THEN STOP CHECK FOR END OF LINE
126 IF NOT B = 192 THEN GOTO 130 CHECK FOR MINUS SIGN
128 LET D = 1 SET FLAG
129 GOTO 140
130 LET C = C * 10 + B
140 NEXT A

Do not use variable A, B, C, D, OR E elsewhere in the program.

Variables

  • A—Dummy in FOR/NEXT loops
  • B—Number read from REM statement should be PEEKing
  • C—Number read from DATA statement
  • D—Sign Flag + (0) – (1)
  • E—Pointer to next number on DATA list

In this case the number is put into variable C. This may then be put into any other variable by using a LET statement such as:

LET A(2) = C

E stores the pointer to the next item of DATA and in this case the start of DATA is at memory location 16427.

LET E = 16427

this will act as the RESTORE statement.

The DATA can be placed anywhere in a program, but the memory location of the start of the data must be found.

The following program finds all the REM statements in a program and prints the memory location where the data will start. Type this in at the end of a program and then erase it after it is used.

2000  LET A = PEEK(16392) + PEEK(16393) * 256
2010 FOR B= 16424 TO A
2020 IF PEEK(B) = 254 THEN PRINT B + 1
2030 NEXT B

The use of this simulation means that one of the faults of the ZX80 Basic may be easily rectified.

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.