If you have ever tried converting programs written for other computers to run on the TS 1000 then you are probably aware that the DATA, READ, and RESTORE statements are frequently used commands which are not available in SINCLAIR 8K BASIC. The machine code programs presented in this article can be used to replace these basic statements.
Listing 1 contains three separate routines; READ, RESTORE, and BUMP, which require two dedicated variables, D$ and V$, which should be thought of as the DATA$ and VALUE$.
The data statement is replaced by a properly formatted D$;
XX10 LET D$="1,2,3,4,A,B,C,D,"
will be the data list to be read. Note that each data item is separated by a comma and that the last character in D$ is also a comma. Very long data lists can be most easily created by string concatenation;
XX10 LET D$="A,B,C,D,E,"
XX20 LET D$=D$+"1,2,3,4,5,".
The value of the data item read from D$, whether string text or a numeric expression, will always be returned as V$, therefore, if a numeric result is expected VAL V$ must be used.
READ (USR 16550)
If both D$ and V$ have been initiallized, then each time READ is called it will locate the current data item in D$, transfer it to V$, then increment the data word pointer to the next data item to be read.
RESTORE (USR 16693)
This short routine will just reset the data word pointer to the start of the data list.
BUMP (USR 16652)
This is a versatile routine which can be used in several ways. When BUMP is called, it will move the data word pointer forward in the data list by “JUMP” items and then READ that item. The JUMP value must first be set by POKEing address 16393 with a value of 1 to 255. Unlike a true BUMP statement, direct negative (backward) jumps are not supported.
BUMP would be useful, for example, in reading each third data item from a long data list, such as telephone numbers, important dates, etc.; call RESTORE, POKE 16393,3, and then use BUMP in a FOR-NEXT loop.
BUMP can also be used as a form of the command SETW TO (set word to) by setting the data pointer to a predetermined item in the data list and starting READ there. For example, to start reading at the 27’th item in the data list; call RESTORE, POKE 16393,26, call BUMP.
LISTING 1. READ, RESTORE, AND BUMP MACHINE CODE
ENTER DATA FROM LEFT TO RIGHT AND FROM TOP TO BOTTOM
0E 49 ED 5B 10 40 EB 7E B9 28
0C FE 80 CA 4B 0D C5 CD F2 09
C1 10 EF FE 5B 23 4E C8 23 46
23 E5 09 EB E1 C9 CD 82 40 ED
4B 7B 40 09 C5 C5 01 00 00 E5
A7 ED 52 E1 38 02 CF 1A 7E FE
1A 28 04 23 03 18 EE 03 E1 09
22 7B 40 0B 78 B1 20 02 CF 1B
C5 0E 5B CD 84 40 E5 23 46 E5
09 D1 CD 5D 0A E1 C1 71 23 70
23 E5 ED 43 40 40 CD 9E 09 CD
82 40 D1 C1 09 D5 ED 4B 40 40
C5 ED B0 C1 E1 3E 8C ED A1 20
04 2B 36 1A 23 E0 18 F5 CD 82
40 3A 09 40 3D 28 91 D5 C1 ED
5B 7B 40 19 F5 7E E5 A7 ED 42
E1 30 95 FE 1A 23 13 20 F2 F1
3D 20 ED ED 53 7B 40 18 DE 21
00 00 22 7B 40 C9
Using the SETW TO form of BUMP can also be used to replace any RESTORE nnnn statements when converting programs.
Using BUMP, in conjunction with RESTORE, it is possible to move the data word pointer to any data item in the data list, forward or backwards.
LISTING 2. HEX LOADER
1 REM **>MINIMUM OF 190 BYTES
10 LET L=16514
20 PRINT "INPUT CODE."
30 REM **>ENTER ""S"" TO STOP
40 INPUT C$
50 SCROLL
60 IF C$="" THEN GOTO 20
70 IF C$="S" THEN STOP
80 PRINT L;" ";C$
90 POKE L,16*CODE C$+CODE C$(2)-476
100 LET L=L+1
110 GOTO 20
ERROR CONDITIONS
When using READ and BUMP the following ERROR REPORTS may occur;
R Out of data, attempting to READ past the data
list.
S Undeclared data item, a data item separator (,)
has been used withou an associated data item.
2 Undefined variable, D$ and/or V$ not
initiallized, or the text of VAL V$ forms a
valid, but not defined, variable name. Occurs
if string text inadvertantly used as a numeric
expression.
C The data item in V$ does not form a valid
numeric expression when converted by VAL V$.
LISTING 3. READ, RESTORE AND BUMP DEMO
0 REM [illegible]
3 REM READ, RESTORE, AND BUMP BY GREGORY C. HARDER
10 REM **** USR CALLS ****
20 LET READ=16550
30 LET BUMP=16652
40 LET RESTORE=16693
50 LET JUMP=16393
60 REM **** READ DEMP ****
70 PRINT AT 20,10;"READ DEMO"
80 LET V$=""
90 LET B=10
100 LET V=0
110 REM **** USE KEYWORDS FOR **** FUNCTIONS IN D$.
120 LET D$="THIS,IS,A,DEMO,PROGRAM,FOR,READ,30,2*6,8+7,B*B*10,COS 0,INT 8.3,INT SIN 90,"
130 REM **** RESET DATA POINTER
140 IF USR RESTORE THEN
150 FOR N=1 TO 14
160 IF USR READ THEN
170 SCROLL
180 IF N>7 THEN LET V=VAL V$
190 PRINT "DATA ITEM ";N;" = ";V$;TAB 25;"V= ";V
200 NEXT N
210 SCROLL
220 SCROLL
230 PRINT AT 0,0;D$
240 GOSUB 520
250 REM **** BUMP DEMO ****
260 PRINT AT 0,10;"BUMP DEMO",,,
270 LET A$="A,B,1,C,D,2,E,F,3,G,H,4,I,J,5,K,L,6,M,N,7,O,P,8,Q,R,9,S,T,10,U,V,11,W,X,12,Y,Z,13,"
280 LET D$=A$+D$
290 REM **** SET JUMP VALUE ***
300 POKE JUMP,3
310 IF USR RESTORE THEN
320 REM **** READ EACH 3RD ITEM
330 FOR N=1 TO 16
340 IF USR BUMP THEN
350 PRINT "DATA ITEM NO. ";N*3;TAB 18;" = ";TAB 22;V$
360 NEXT N
370 SCROLL
380 SCROLL
390 PRINT AT 16,0;D$
400 GOSUB 520
410 REM **** SETW TO DEMO ****
420 PRINT AT 0,8;"SETW TO DEMO"
430 POKE JUMP,8
440 IF USR RESTORE THEN
450 IF USR BUMP THEN
460 FOR N=1 TO 9
470 IF USR READ THEN
480 PRINT "DATA ITEM NO.";N+8;TAB 15;"=";TAB 17;V$;TAB 20;"READ NO.= ";N
490 NEXT N
500 PRINT ,,D$
510 STOP
520 PRINT AT 21,0;"PRESS ENTER TO CONTINUE."
530 INPUT G$
540 CLS
550 RETURN
9000 SAVE "REA▒"
9010 LIST 3
PROGRAMMERS NOTES
Both READ and BUMP will return to BASIC with register BC reset to zero. A convenient method of expressing a numeric result, in one line, would therefore be;
XX10 LET A=USR READ+VAL V$
which would be equivalent to READ A.
For string data items, a graphic pound sign in the data string will be converted to a comma in V$, this is so data string such as “Denver,Co.” can be printed. Use a graphic pound sign whenever a comma is required.
Address 16507 contains the data word pointer which should not be altered until the READ/BUMP routines are completed.
LOADING THE PROGRAM
Use the HEX LOADER shown in listing 3, or some other suitable loader. REM line one must contain at least 190 bytes. Enter the code as shown in listing 1, check your inputs for any errors. When done, POKE 16510,0 and then delete all lines greater than zero.
READ, RESTORE, and bump are now ready to be used in your basic programs, save the routines to tape.
Listing 3 illustrates how to use the routines and some of the programming possibilities.
RELOCATING THE ROUTINES
Use listing 4 to move the routines to a different area of memory. When prompted, input the destination. When the transfer is completed the new USR calls will be printed, write them down.
LISTING 4. RELOCATOR
10 FAST
20 PRINT "INPUT DESTINATION",,
30 INPUT D
40 RAND D
50 POKE 16551,PEEK 16434
60 POKE 16552,PEEK 16435
70 RAND (D+2)
80 POKE 16598,PEEK 16434
90 POKE 16599,PEEK 16435
100 POKE 16624,PEEK 16551
110 POKE 16625,PEEK 16552
120 POKE 16653,PEEK 16551
130 POKE 16654,PEEK 16552
140 FOR N=0 TO 189
150 POKE (D+N),PEEK (16514+N)
160 NEXT N
170 PRINT "READ=";D+36,,"BUMP=";D+138;,,"RESTORE=";D+179
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.