A Comparision of Keywords on the ZX81 and ZX Spectrum
Overview
The following is a list of keywords, operators and delimiters used on the ZX81 and ZX Spectrum. These two micros share a common base of keywords so I have listed them together with notes stating differences between how the two machines deal with these commands, statements and functions. Where a command or statement is not available on a micro this is also stated in the notes.
Microdrive commands have not been included as these are totally exclusive to the ZX Spectrum and cannot be easily translated to ZX81 BASIC. I have not included the ZX80 in this list as this micro has a few differences which make comparisons difficult in a list like this (no floating-point arithmetic - integer only, DIM base of 0 instead of 1). Neither have I included the QL or Timex variants, these will be dealt with in another article.
Commands
Keyword
Meaning
Comments
CLEAR
CLEAR (ZX81 & ZX Spectrum)
CLEAR n (ZX Spectrum)
Result: Clears the screen, deletes all variables, resets PLOT and PRINT positions and clears the GOSUB stack. If a number is specified then RAMTOP is lowered to n.
CLEAR on the ZX81 only deletes all variables. To lower RAMTOP on the ZX81 the system variable RAMTOP located at 16388 and 16389 must be POKEd with the appropriate values.
CONT or CONTINUE
CONT (ZX81)
CONTINUE (ZX Spectrum)
Result: After error report 9 (STOP Statement) or report L (BREAK into program) CONTINUE will execute the next line after the error occurred.
CONTINUE is shortened to CONT on the ZX81. Error L on the ZX Spectrum is equivelent to error D on the ZX81. The ZX Spectrum keyboard shows CONTINUE as CONT.
LIST
LIST
LIST n
Result: Display program listing from line n or line 0 is no line number specified.
ZX81 will only display one page before stopping and a new LIST statement with the next line number after the last one displayed must be issued. The ZX Spectrum will display the message 'scroll?' if the listing will not fit onto one page. Pressing 'y' will continue the listing.
LLIST
LLIST
LLIST n
Result: Send program listing from line n (or line 0 is no line number specified) to the ZX Printer.
Same on both micros when used with ZX Printer. Other printers and printer interfaces may produce different results.
LOAD
LOAD f (ZX81 & ZX Spectrum)
LOAD f DATA () (ZX Spectrum only)
LOAD f DATA $() (ZX Spectrum only)
LOAD f CODE m,n (ZX Spectrum only)
LOAD f CODE m (ZX Spectrum only)
LOAD f CODE (ZX Spectrum only)
LOAD f SCREEN$ (ZX Spectrum only)
Result: Load program (or code) f from tape into memory.
LOAD f statement same for both micros. ZX Spectrum has extra options to load dimensional arrays, code direct to memory or a screen to the display file.
MERGE
MERGE f
Result: Merge program f with that already in memory overwriting duplicate program lines.
Not on the ZX81.
NEW
NEW
Result: Deletes program and variables and memory up to and including the address held in the system variable RAMTOP.
Similar on both micros. ZX81 deletes up to the byte before RAMTOP. The ZX Spectrum also preserves the system variables UDG, P-RAMT, RASP and PIP.
SAVE
SAVE f (ZX81 & ZX Spectrum)
SAVE f LINE m (ZX Spectrum)
SAVE f DATA () (ZX Spectrum)
SAVE f DATA $() (ZX Spectrum)
SAVE f CODE m,n (ZX Spectrum)
SAVE f SCREEN$ (ZX Spectrum)
Result: Save program f to tape from memory.
SAVE f statement same for both micros. ZX Spectrum has extra options to save dimensional arrays, code from memory or the display file. On the ZX Spectrum the item LINE m will RUN a program from line m once loaded. On the ZX81 the same is achieved by inserting a SAVE command into a program and running the program from the line number where the SAVE statement is. The last letter of the filename will 'invert' and when loaded back the program will run from the line after the SAVE statement. The ZX Spectrum will only allow up to 10 characters for a filename whereas the ZX81 will allow up to 127.
VERIFY
VERIFY f
VERIFY f DATA ()
VERIFY f DATA $()
VERIFY f CODE m,n
VERIFY f CODE m
VERIFY f CODE
VERIFY f SCREEN$*
*This command will be accepted by the Spectrum but taped SCREEN$ code will fail verification.
Result: Compared program f from tape with that in memory. Error R if verify fails.
Not available on ZX81.
Statements
Keyword
Meaning
Comments
AT
AT x,y
Result: Changes PRINT (ZX81 or ZX Spectrum) or INPUT (ZX Spectrum) position to x,y.
INPUT AT x,y only works on ZX Spectrum.
BEEP
BEEP x,y
Result: Sound emitted for x seconds at pitch y.
The ZX81 has no sound facility so BEEP in not possible on that micro.
BORDER
BORDER m
Result: Changes screen border colour to m.
It is not possible to change the border on the ZX81.
The brightness of the screen cannot be changed on the ZX81.
CIRCLE
CIRCLE x,y,z
Result: Draws a circle of radius z at position x,y.
On the Spectrum this command draws a high resolution circle. Although CIRCLE is not available on the ZX81 it is possible to draw a circle using PLOT and the trigonometric functions SIN and COS.
CLS
CLS
Result: Clears the screen.
COPY
COPY
Result: Sends the contents of the screen to the ZX Printer.
Same on both micros when used with ZX Printer. Other printers and printer interfaces may produce different results.
DATA
DATA e1,e2,e3, ...
Result: Stores data in a list.
Not on the ZX81. Dimensional arrays and LET should be used instead.
DEF FN
DEF FN α(α1, αk)=e
Result: Defines a function. α and α1 to αk can be a single letter or single letter followed by $ for a string argument.
Not on the ZX81. Functions may be held inside a string variable and executed with VAL instead.
DIM
DIM α(n1,...,nk)
DIM α$(n1,...,nk)
Result: Sets up an array of numbers or characters with k dimensions. For numeric arrays all values are set to zero. In the case of a string array all values are set to SPACE (CHR$ 32).
ZX81 string dimensional arrays are also set to SPACE but the code is zero (CHR$ 0).
DRAW
DRAW x,y
DRAW x,y,z
Result: DRAW a high resolution line from the currect PLOT position moving x horizontally and y vertically rotating through angle z if third parameter is specified.
Not on ZX81. A PLOT statement within a loop must be used to simulate a low resolution DRAW.
FAST
FAST
Result: Stops display to the screen to speed up program execution. Display is reactivated at end of program. Switched off with SLOW.
ZX81 only. Not on the ZX Spectrum.
FLASH
FLASH n
Result: If n is set to 1 flash effect is turned on. If n is set to zero then flash effect is turned off.
Although the ZX81 has no FLASH statement a similar effect can be acheived by PRINTing and then overPRINTing normal then inverse characters with a PAUSE or FOR...NEXT loop to alter the speed of the FLASH.
GOSUB or GO SUB
GOSUB n (ZX81)
GO SUB n (ZX Spectrum)
Result: Stack GO SUB line number and branch (GO TO) line n.
Same on both micros with the exception of the spelling, GO SUB with a space for the Spectrum and without (GOSUB) for the ZX81. The ZX Spectrum manual is inconsistent with the spelling of GO SUB, using both GO SUB and GOSUB!
GOTO or GO TO
GOTO n (ZX81)
GO TO n (ZX Spectrum)
Result: Branch or GO TO line n.
Again, like above the same on both micros with the exception of the spelling, GO TO with a space for the Spectrum and without (GOTO) for the ZX81.
INK
INK n
Result: Sets foreground colour of chracters to be printed. When n=0 to 7 a colour is selected. When n=8 transparency is selected. When n=9 contrast is selected.
As the ZX81 is a monochrome computer this statement is only available on the Spectrum.
INPUT
INPUT v (ZX81 & ZX Spectrum)
INPUT v1,v2,v3... (ZX Spectrum only)
INPUT LINE α$ (ZX Spectrum only)
Result: Computer waits for input of an expression then passes the value of this to the variable v.
The ZX Spectrum command allows for multiple variables to be input on the same INPUT statement i.e. INPUT v1,v2,v3... ZX Spectrum also allows PRINT items to be used such as INK and PAPER. INPUT LINE v on the Spectrum strips the quotes on the input line and waits for a string to be input.
INVERSE
INVERSE n
Result: If n=0 characters are printed in normal video. If n=1 characters are printed in inverse video.
The INVERSE statement is not implemented on the ZX81 although inverse characters are available in the ZX81 character set.
LET
LET v=e
Result: Assign the value e to the variable v.
Same on both micros.
LPRINT
LPRINT ...
Result: Send a line of items to be printed to the ZX Printer.
Same on both micros when used with ZX Printer with some exceptions.. Other printers and printer interfaces may produce different results.
OUT
OUT m,n
Result: Outputs byte n to port m.
Not on the ZX81 but can be accessed from machine code. POKE is more commonly used on the ZX81 for memory-mapped devices.
OVER
OVER n
Result: If n=0 characters obliterate those already at that position. If n=1 characters are merged with those already at that position.
This is a high resolution display statement and is not available on the ZX81. If n=1 OVER essentially performs an eXclusive OR with the old and new pixels. If both pixels are off (0) they will stay off (0). If the old pixel if off (0) and the new one is on (1) the displayed pixel will be on (1). If both old and new pixels are on (1) the diplayed pixel will be (0).
PAPER
PAPER n
Result: Sets background colour of chracters to be printed. When n=0 to 7 a colour is selected. When n=8 transparency is selected. When n=9 contrast is selected.
As the ZX81 is a monochrome computer this statement is only available on the Spectrum.
PAUSE
PAUSE n
Result: Stop program execution for n*1/50seconds or until a key is pressed.
On the ZX Spectrum PAUSE 0 is not timed but lasts until a key is pressed. On the ZX81 PAUSE 32767 or greater is the same as PAUSE 0 on the Spectrum. POKE 16437,255 must follow this if run in FAST mode.
PLOT
PLOT m,n (ZX81)
PLOT c;m,n (ZX Spectrum)
Result: Sets pixel ink at position m,n subject to c (INK/PAPER/OVER/INVERSE) on the ZX Spectrum.
ZX Spectrum resolution is 4 times higher than the ZX81's so the pixels on the ZX81 will be much chunkier. See also UNPLOT.
POKE
POKE m,n
Result: Load byte n into memory address m.
Same on both micros.
PRINT
PRINT ...
Result: Send a series of items to the display subject to control characters and AT/TAB (and colour/INVERSE/FLASH/OVER on the ZX Spectrum).
Same on both micros with some exceptions. ZX Spectrum can also PRINT to an I/O device using streams and channels.
RAND or RANDOMIZE
RAND (ZX81)
RAND n (ZX81)
RANDOMIZE (ZX Spectrum)
RANDOMIZE n (ZX Spectrum)
Result: Sets system variable SEED to n which will be the basis for pseudo-random numbers (RND).
Same on both micros (except spelling). ZX Spectrum keyboard shows shortened RAND and not RANDOMIZE and as a point of interest the ZX80 keyword spelling was RANDOMISE with an 'S'.
READ
READ e1,e2,e3, ...
Result: Read from DATA statement and pass to a variable or variables e1,e2,e3, ..
Not on the ZX81. Dimensional arrays and LET should be used instead.
REM
REM ...
Result: None, display comment in program listing.
Same on both micros. Incidentally ZX81 users commonly utilise REM statements to store machine code and although the ZX Spectrum is also capable of this it is not used as much as it is easier to place machine code above RAMTOP.
RESTORE
RESTORE
RESTORE n
Result: Restores DATA pointer to line n or first line of program if n is not specified. READ will starting reading from there.
Not on the ZX81. Dimensional arrays and LET should be used instead.
RETURN
RETURN
Result: Take line number off GO SUB stack and GO TO the line after that line number.
Same on both micros.
RUN
RUN
RUN n
Result: Perform CLEAR and GO TO line n (or line 0 if n not specified).
Same on both micros.
SCROLL
SCROLL
Result: Move display up by one character line losing the top row and blanking the bottom row.
ZX81 only but the ZX Spectrum can do the same thing with:
LET scroll=USR 3582
SLOW
SLOW
Result: Resumes display to the screen to during program execution. Switches off FAST statement.
ZX81 only. Not on the ZX Spectrum.
STOP
STOP
Result: Stops program execution with Report 9.
Same on both micros.
TAB
TAB x
Result: Changes PRINT (ZX81 or ZX Spectrum), LPRINT (ZX81 or ZX Spectrum) or INPUT (ZX Spectrum) position to column x.
INPUT TAB x only works on ZX Spectrum.
UNPLOT
UNPLOT m,n
Result: Blanks out pixel at position m,n.
ZX81 only but ZX Spectrum can use
PLOT INVERSE 1;m,n
to blank out a pixel. See PLOT.
Compound Statements & Structured Statments
Keyword
Meaning
Comments
FOR...NEXT loop
(FOR, TO, STEP, NEXT)
FOR α=x TO y STEP z
[section of program to be repeated goes here]
NEXT α
Result: Sets up and executes the loop α from x to y with a step of z.
[Note] Step of +1 assumed if STEP omitted)
Same on both micros.
Although the NEXT statement is not compounded within the FOR statement as TO and STEP are, it is included here for completeness.
IF..THEN
IF x THEN s
Result: If x is true (non-zero) then s will be executed.
Same on both micros.
Functions
Keyword
Meaning
Comments
ABS
ABS x
Returns: Absolute magnitude of x, i.e. distance on number line from zero, -1=1 -2=2
Same on both micros.
ACS
ACS x
Returns: Arccosine (inverse cosine) of x in radians.
Essentially the Same on both micros although floating-point rounding may give slightly different results i.e. ACS -0.1 = 1.6709638 on the ZX81 and 1.6709637 on the Spectrum
ASN
ASN x
Returns: Arcsine (inverse sine) of x in radians.
Same on both micros.
ATN
ATN x
Returns: Arctangent (inverse tangent) of x in radians.
Same on both micros.
ATTR
ATTR (x,y)
Returns: numeric value between 0 and 255 of the attribute at position x,y.
As the ZX81 is a monochrome computer this function is only available on the Spectrum.
BIN
BIN b
Returns: decimal value of a base2 (binary) 16 bit number.
Only on Spectrum. A short subroutine could easily be coded to simulate this function on the ZX81.
CHR$
CHR$ x
Returns: Single character from position x in the character set.
Although the CHR$ function performs the same task on both computers the end result will be different as the Spectrum's character set
is based on the ASCII code, while the ZX81's is unique.
CODE
CODE α$
Returns: Numeric value (between 0 and 255) representing the position in the character set of α$. (This is the inverse of the CHR$ function.
Although the CODE function performs the same task on both computers, just like CHR$ above, the end result will also be different.
COS
COS x
Returns: Cosine of x in radians.
Same result on both micros.
EXP
EXP x
Returns: Numeric value for the function ex where e=2.7182818...
Same result on both micros.
FN
FN α(α1, αk)
Result: Calls a function. α and α1 to αk can be a single letter or single letter followed by $ for a string argument.
Not on the ZX81. Functions may be held inside a string variable and executed with VAL instead.
See also DEF FN.
INKEY$
INKEY$ (no operands)
Returns: Single character from a keypress.
Typical usage would be
PRINT INKEY$
LET A$=INKEY$ or
10 IF INKEY$="" THEN GO TO 10
Same result on both micros.
IN
IN m
Returns: numeric value between 0 and 255 for the port m.
Not on the ZX81 but can be accessed from machine code. PEEK is more commonly used on the ZX81 for memory-mapped devices.
INT
INT x
Returns: x rounded down to the nearest integer.
Mostly the same result on both micros with the exception that occurs on the ZX Spectrum when INT -65536 is performed (the wrong result is given as -1).
LEN
LEN α$
Returns: numeric value for the length of α$.
Same result on both micros.
LN
LN x
Returns: numeric value for the natural logarithm of x.
Same result on both micros.
PEEK
PEEK m
Returns: numeric value (0 to 255) stored at memory location m.
Same on both micros.
PI
PI
Returns: 3.1415927 (π) Ratio of circumference of a circle to its diameter
Typical usage might be:
LET R=C/(2*PI)
Same for both micros. [Note 1] PI is stored on both systems as 10 digits but will only display 8 digits. [Note 2] On the ZX81 keyboard PI is depicted as the greek letter π.
POINT
POINT (x,y)
Returns: 0 or 1 for the screen location x,y.
This is a high resolution function and is not available on the ZX81.
RND
RND (no operands)
Returns: A pseudo-random number between 0 and 1.
An example of usage would be
LET X=INT(RND*6)+1
Same for both micros.
SCREEN$
SCREEN$ (x,y)
Returns: character displayed at location x,y.
Not on the ZX81 but a similar function exists using PEEK.
SGN
SGN x
Returns: signum (or sign) of x, for instance -1 if x<0, 0 if x=0 or 1 if x>1.
Same for both micros.
SQR
SQR x
Returns: square root of x.
Same for both micros.
STR$
STR$ x
Result: string comprising of the numeric value of x.
Same for both micros.
TAN
TAN x
Returns: Tangent of x in radians.
Same result on both micros.
USR
USR x
Returns: contents of the bc register pair after calling machine code at memory location x.
Same for both micros.
USR
USR α$
Returns: location in memory of user defined graphic α$.
The function USR (with string argument) is completely different to USR (numeric argument) above and is used to find the location of a particular user-defined graphic. Since the ZX81 has no UDG's this function is not available on the ZX81.
VAL
VAL α$
Returns: numeric value evaluated from the string α$.
Same for both micros.
VAL$
VAL$ α$
Returns: string evaluated from the string α$.
There does not appear to be a simple way to simulate this function in ZX81 BASIC.
Operators
Keyword
Meaning
Comments
-
Unary Minus/Negation
-x
Result: negates x
Same on both micros.
-
Binary Minus/Subtraction
x-y
Result: a numeric value resulting from y being subtracted from x.
Same on both micros.
+
Addition
x+y
Result: a numeric value resulting from y being added to x.
Same on both micros.
+
String concatenation
α$+β$
Result: concatenates (joins together) string α with string β to form a new string.
Same on both micros.
/
Division
x/y
Result: a numeric value resulting from x being divided by y.
Same on both micros.
*
Multiplication
x*y
Result: a numeric value resulting from x being multiplied by y.
Same on both micros.
** or ↑
Raise to the power of
x**y (ZX81)
x↑y (ZX Spectrum)
Result: a numeric value resulting from x being raised to the power of y.
Same meaning on both micros but the ZX81 uses a double asterisk ** whereas the ZX Spectrum uses an up arrow ↑.
<
Less than
x<y
Where x and y can be either numeric or strings but cannot be mixed.
Result: 1 if x<y otherwise 0.
Same on both micros.
>
Greater than
x>y
Where x and y can be either numeric or strings but cannot be mixed.
Result: 1 if x>y otherwise 0.
Same on both micros.
<=
Less than or equal to
x<=y
Where x and y can be either numeric or strings but cannot be mixed.
Result: 1 if x≤y otherwise 0.
Same on both micros.
>=
Greater than or equal to
x>=y
Where x and y can be either numeric or strings but cannot be mixed.
Result: 1 if x≥y otherwise 0.
Same on both micros.
=
Is equal to
x=y
Where x and y can be either numeric or strings but cannot be mixed.
Result: 1 if x=y otherwise 0.
Same on both micros.
<>
Is not equal to
x<>y
Where x and y can be either numeric or strings but cannot be mixed.
Result: 1 if x≠y otherwise 0.
Same on both micros.
AND
x AND y
Where x is a number or a string, and y is always numeric.
Returns: x if y is true (non-zero) or 0 if y is false (zero).
Same on both micros
OR
x OR y
Returns: 1 if x or y≠0, value of x if b=0.
Same on both micros
NOT
NOT x
Returns: zero if x≠0, 1 if x=0
Same on both micros
TO
v$(x TO y)
v$(x TO)
v$(TO y)
v$( TO ) * This works but is pointless!
Returns: Slices string v from x to y, x to end of string or start of string to y. TO without any operands will return a string unsliced (see fourth example).
Same on both micros
Delimiters
Keyword
Meaning
Comments
;
Semi-colon
PRINT ; (ZX81 & ZX Spectrum)
LPRINT ; (ZX81 & ZX Spectrum)
INPUT ; (ZX Spectrum)
Result: separates items within a PRINT, LPRINT ot INPUT (ZX Spectrum only) statement.
ZX81 cannot use a semi-colon as a delimiter with an INPUT statement.
'
Apostrophe
PRINT ' (ZX81 & ZX Spectrum)
LPRINT ' (ZX81 & ZX Spectrum)
INPUT ' (ZX Spectrum)
Result: Moves the PRINT or LPRINT position down a line.
ZX81 cannot use an apostrophe as a delimiter in an INPUT statement.
,
Comma
PRINT , (ZX81 & ZX Spectrum)
LPRINT , (ZX81 & ZX Spectrum)
INPUT , (ZX Spectrum)
Result: Moves the PRINT position to halfway across the screen (or printer) or to the start of the next line if PRINT position is greater or equal to halfway.
ZX81 cannot use a comma as a delimiter in an INPUT statement.
,
Comma
Separates operands within a statement.
Examples:
POKE x,y (ZX81 & ZX Spectrum)
ATTR (x,y) (ZX Spectrum)
Result: Separates operands within a statement.
ZX81 cannot use a comma as a delimiter in an INPUT statement.
#
Hash
PRINT #m
LPRINT #m
INPUT #m
Result: Output to stream m.
Only on the ZX Spectrum.
:
Colon
s1 : s2 : s3 ...
Result: Allows more than one statement per line number to be entered.
Only on the ZX Spectrum.
"
Single quotation marks
α$="some text" (ZX81 & ZX Spectrum)
PRINT "some text" (ZX81 & ZX Spectrum)
LPRINT "some text" (ZX81 & ZX Spectrum)
INPUT "some text" (ZX Spectrum)
Result: Encloses text within a string. Encloses text with a PRINT, LPRINT or INPUT (ZX Spectrum only) statement.
ZX81 cannot use a single quotes within an INPUT statement.
ZX Spectrum can store a single quote within a set of quotation marks like so
""""
The ZX81 cannot do this but has a double quotation ("") keyword which is entered singly between to single quotation marks
""""
""
Double quotation marks
α$="""MAGRATHEA""" (ZX81)
Result: "MAGRATHEA"
Produces a double quote character for use within a string.
ZX81 only.
Not a delimiter but a character, shown here for comparison with above.
ZX Spectrum uses double-single quotes for the same effect (see above).
Nomenclature
This list uses the same letters to represent variables, expressions and sequences etc. as the ZX81 and ZX Spectrum BASIC manuals.
α,β represents a single letter
v represents a variable
x,y,z represents numerical expressions
m,n represents numerical expressions rounded to the nearest integer
b represents a 16 bit binary number
e represents an expression
f represents a string valued expression
s represents a sequence of statement separated by colons :
c represents a sequence of colour items, each terminated by commas , or semi-colons ; A color item has the form of a PAPER, INK, FLASH, BRIGHT, INVERSE or OVER statement.
References
Sinclair ZX81 BASIC Programming, Steven Vickers (author)
Sinclair ZX Spectrum BASIC Programming, Steven Vickers (author), Robin Bradbeer (editor)