Chapter Nine

SINCLAIR ZX81




Introduction

The Translation program on the cassette is the latest addition to the BASICODE system although the ZX81 has been available for some years. There have been two major problems to overcome:
  1. Memory capacity: Early models did not have enough space for the translation program. This problem has now been largely overcome with the availability of more memory.
  2. The Sinclair BASIC: The type of BASIC used in the ZX81 is not immediately compatible with the form used in BASICODE-2. The Sinclair ZX81 is not able to cope with more than one statement per line whereas we allowed this in BASICODE to avoid long programs.

How to use the Translation program

Load the program on Side 1 of the cassette for the ZX81. Use LOAD'' to do this. The program consists of two routines, the Reading routine designed to make the ZX81 read the BASICODE program off the radio, and the Translation program to convert what has been read into a form that can be dealt with by the ZX81.

After loading the program, the routine should present itself and the ZX81 will give an error message '7/9090'. This is normal. Your ZX81 is now operating the FAST mode which is essential for the Reading routine.

You are now ready to load a program recorded off the radio. Remember to keep the recording levels as high as possible, without distortion. Having got a recording, wind it back to the start and cue up the cassette so you can hear the start tone. This is the steady tone that starts all BASICODE programs.

Now type in RAND USR 16618
Start your tape recorder in the playback mode and press (NEWLINE). The BASICODE program should now start loading. The process will stop if:
  1. You press BREAK
  2. The memory is full
  3. An ETX CHR is loaded.
Now type in LIST 999 and on that line you should see a REM statement. What comes after the REM has been loaded by the computer.

If the BASICODE program hasn't loaded correctly, it may be due to the volume control on your tape recording being set too low. This will result in meaningless information after the REM on some or all lines. If the whole program is nonsense, start again from the beginning and try a different volume setting. If only the last part has gone wrong, there is no reason why you shouldn't start loading half-way through the BASICODE program rather than winding it back to the start. It may take some experimenting at first, but you should find a point where the process goes smoothly.

Now that we're in the position of having loaded the BASICODE program, it has to be translated into a form that the ZX81 recognises as an ordinary ZX81 program. You start this process by typing in RAND USR 17165 (NEW LINE)
The Translation program now starts looking at the BASICODE material, line by line. A statement is replaced by a token and when it comes across a second statement on one line it generates a new line for this second statement. LET and GOTO statements are inserted when necessary, and when this is complete, the REM statement is erased. You can therefore expect the following result.

Original After Loading From RadioNew Version
1210REM A=400:B=21210LET A=400
  1211LET B=2
1220REM LET A$="ABC":B$="FGH"1220LET A$="ABC"
  1221LET B$="FGH"
1225REM IF A>B THEN A=B:PRINT "A WAS <> B":13001225IF NOT (A>B) THEN GOTO 1230
  1226LET A=B
  1227PRINT "A WAS <> B"
  1228GOTO 1300
1230REM PRINT A:PRINT B1230PRINT A
  1231PRINT B
1300REM PRINT "END VB",A$1300PRINT "END VB",A$

You can test this system out by using RAND USR 16618 (NEWLINE).

You don't need a cassette, but you will need to press BREAK. You can now type in a few test lines and have them translated by entering RAND USR 17165. If you press BREAK during the translation process, the computer will stop translating and you will once again see the screen. You can go back to translating by using RAND USR 17165 again and the computer will pick up where it left off.

Adjustments

Once you have loaded and translated a BASICODE program you can now try to RUN it. Some programs broadcast in The Chip Shop will run immediately. But there will also be a few that need some changes to be made. These changes will become clear during a test run. Type in RUN (NEWLINE) and note any error messages that come up. Check the line the computer refers to. Remember that unlike other computers in the BASICODE system, the ZX81 does not like string variables and FOR-NEXT variables which consist of more than one character, e.g. 'IN$' and 'FOR IN=0 TO 10'. You will have to change these to variables of a single character instead.

Suppose you choose Z$ to replace IN$ in the program. That is fine, as long as Z$ doesn't appear elsewhere in the BASICODE program with, of course, another meaning. So it's a good idea, once you have chosen your single character variable to check that it doesn't exist in the BASICODE program. To do this type in:
RUN 400,-"1" (for search),-"Z$" (for word)
This simple routine now scans through the entire program and gives the message 'FOUND' if it does find, in this case, Z$. If you don't get this message, then it is safe to replace IN$ in the original by Z$. You do this by typing in:
RUN 400,-"2" (for replace), -"IN$" (for word), -" Z$" (replaced by).
Note: The space before Z$ is deliberate. Both the variables must be the same length, so when you put the single character in, you must leave that space.

DATA-RESTORE-READ process:

In most cases you can replace DATA by DIM D$(…) LET D=1. You must work out the dimensions of D$. The number of DATA elements is the first number, and the length of the longest element is the second. In addition, D$ must be filled with a number of LET statements. RESTORE thus becomes LET D=1, and READ A$ becomes LET A$=D$(D) LET D=D+1.

In most BASICODE programs, programmers tend to put DATA into table form, and use statements elsewhere in the program to manipulate it.
BeforeAfter
2000FOR N=1 TO …2000GOSUB 3000
2010LET READ M$(N)  
2020NEXT N  
    .  
    .  
    .  
3000LET DATA "MO","TU","WE"3000REM M$(1)="MO":M$(2)="TU":M$(3)="WE" RETURN

We don't need lines 2000-2020 in the above example. Instead, the data is rewritten in another form in line 3000. If we now start up the Translation routine using RAAND USR 17165, a number of neat lines will be made from line 3000, each with its own LET statement.
Note: Remember that some other computers allow the table index to be 0, i.e. LET A$(0)="VB".

All we have to check now are LEFT$, MID$, and RIGHT$.

LET A$="ABCDEFG"  
LET B$=LEFT$(A$,3)LET B$=MID$(A$,3,1)LET B$=RIGHT$(A$,4)
B$ is now="ABC"B$ is now="C"B$ is now="DEFG"

But we could also write B$=LEFT$("ABCDEFG",3), and so on, and get the same result. So for the ZX81 this would become:

LET B$=A$(TO 3)LET B$=A$(3 TO 4)LET B$=A$(LEN A$-4) TO)

Line number 998 is a very special line. REM COPY COPY. This is the terminator line and everything after the terminator line with a higher line number (i.e. larger than 998) is erased. You can change this line number if you wish.

Note too that the Reading routine will scrap any lines above 9990, and line numbers will move in steps of 10.