A Comparision of Keywords on the QL and ZX Spectrum
Overview
The following is a list of keywords, operators and delimiters used on the QL and ZX Spectrum. The Sinclair QL uses a different version of BASIC to the ZX Spectrum called SuperBASIC. It resembles Sinclair BASIC in many ways and shares many keywords. There are differences however, for one the display is of a higher resolution so many of the graphics statements act quite differently. But the main difference is its use of structure within programs. Converting programs to run on the ZX Spectrum is not as difficult to overcome as it may seem and where possible I have included in the right-hand column short conversion code for whichever micro requires it.
The QL comes complete with two microdrive units built in, these are similar to the ZX units but differ in they format they use. QL formatted cartridges are not compatible with ZX and vice versa and comparisons are done on a keyword basis only. A standard ZX Spectrum with Interface 1 will be the comparison.
Some direct commands such as AUTO and EDIT have been left out of this list as they do not relate directly to a program needing conversion.
Microdrive and Tape statements have also been left out of this list and will be dealt with seperately.
Commands
Keyword
Meaning
Comments
CLEAR n
ZX Spectrum (command)
CLEAR n (ZX Spectrum)
Result: Clears the screen, deletes all variables, resets PLOT and PRINT positions and clears the GOSUB stack then RAMTOP is lowered to n. (ZX Spectrum)
CLEAR statement on the QL only deletes all variables and releases space for Qdos.
See also CLEAR statement
CONTINUE
CONTINUE
Result: After error report 9 (STOP Statement) or report L (BREAK into program) CONTINUE will execute the next line after the error occurred. (ZX Spectrum)
Result: Continues program after it has been halted. (QL)
CONTINUE is shortened to CONT on the ZX Spectrum keyboard.
RETRY on the QL has a similar effect.
See also RETRY.
EXEC
EXEC_W
EXEC[_W] device_program
Result: Load a sequence of programs and execute them in parallel and return to the command processor. EXEC_W will wait until all processes have terminated before returning.(QL only)
QL only. The ZX Spectrum cannot execute programs in parallel.
LIST
i)LIST (ZX Spectrum & QL)
ii)LIST n (ZX Spectrum)
ii)LIST n (QL)
iv)LIST x TO y (QL)
Result i: Display complete program listing.
Result ii: Display program listing from line n. (ZX Spectrum)
Result iii) List program line n. (QL)
Result iv: List program from line x TO line y. (QL)
The ZX Spectrum will display the message 'scroll?' if the listing will not fit onto one page. Pressing 'y' will continue the listing.
Also possible on the QL is :
LIST TO y
LIST x TO
to list from start of listing to line y or from line x to the end of the program.
LLIST
LLIST [n]
Result: Send program listing from line n (or line 0 is no line number specified) to the ZX Printer.
The QL cannot use the ZX Printer.
NEW
NEW
Result: Deletes program and variables and memory up to and including the address held in the system variable RAMTOP. (ZX Spectrum)
Result: Clears old program, variables and channels except 0,1 and 2. (QL)
Similar on both micros. The ZX Spectrum also preserves the system variables UDG, P-RAMT, RASP and PIP.
RUN
RUN [n]
Result: Perform CLEAR and GO TO line n (or line 0 if n not specified). (ZX Spectrum)
Result: Perform GO TO line n (or line 0 if n not specified). (QL)
Similar on both micros.
Statements
Keyword
Meaning
Comments
ADATE (QL)
br>ADATE x
Result: Adjusts clock by x seconds.
Not on the ZX Spectrum.
Although the ZX Spectrum's internal clock can be set from addresses 23672 to 23674, there is no simple solution in BASIC to adjust the clock a fixed amount of seconds. A machine code solution would be preferable.
ARC
ARC_R
i) ARC[_R] [channel,] x,y TO x1,y1,angle[, ...]
ii) ARC[_R] [channel,] TO x,y,angle [, ...]
Result i: Draw an arc from x,y to x1,y1 turning through angle. Multiple arcs may be drawn with one line statement but adding more parameters.
Result ii: Draw an arc from last point specified to x,y turning through angle.
A channel may be optionally selected to direct output to a window.
ARC_R uses the relative coordinate system.
QL only. The Spectrum's DRAW statement can be made to perform a similar function.
Note: One of the ZX Spectrum prototypes (ZX82) originally had an ARC keyword instead of CIRCLE.
AT
AT x,y (ZX Spectrum)
AT [channel,] x,y (QL)
Result: Changes PRINT or INPUT position to x,y.
On the QL only AT may be directed to window attached to a channel.
On the ZX Spectrum AT must follow a PRINT or INPUT statement:
PRINT AT 10,10;"Arthur"
The QL AT statement must precede a PRINT or INPUT statement.
Result: Sound emitted for x seconds at pitch y. (ZX Spectrum)
Result: Sound emitted for duration (in steps of 72 microseconds) at pitch (pitch value is inversely proportional to the pitch of the sound produced) (QL)
Other parameters for QL beep are available but not directly compatible with the ZX Spectrum.
BEEP on both micros is quite different.
On the Spectrum BEEP has only two parameters and duration is measured in seconds (or parts of). Pitch value is proportional to the pitch of the sound produced (the higher the value the higher the pitch).
On the QL duration is measured in steps of 72μseconds and pitch value is inversely proportional (the lower the value, the higher the pitch).
BLOCK
BLOCK [channel,] height,width,x,y,colour
Result: Fill a rectangle of width*height at position x,y in a window attached to a channel (QL only)
QL only, but the Spectrum can easily fill a rectangle either at character or pixel resolution with a small subroutine.
BORDER
BORDER m (ZX Spectrum)
BORDER [channel,] width [, colour] (QL)
Result: Changes screen border colour to m. (ZX Spectrum)
Result: Create a border (optionally directed to channel) of width and colour. (QL)
BORDER on the ZX Spectrum changes the outer area of the screen up to and including the edge of the display.
On the QL BORDER changes the colour at edge of a window. The outer edge of the display stays black.
Result: Draws a circle of radius z at position x,y. (ZX Spectrum & QL)
Result: Draw an ellipse at x,y with the parameters major_axis, eccentricity, angle.
QL can optionally display to a numbered channel.
CIRCLE_R works the same but will display using relative coordinate system.
The CIRCLE statement on the ZX Spectrum cannot handle ellipses which will require extra programming to produce.
The QL will not produce an error if the circle goes 'off screen' unlike the Spectrum which will produce an 'Integer out of range' error.
On the QL the keyword ELLIPSE may be used instead of CIRCLE.
CLEAR
ZX Spectrum & QL
(statment)
CLEAR (ZX Spectrum)
CLEAR (QL)
Result: Clears the screen, deletes all variables, resets PLOT and PRINT positions and clears the GOSUB stack. (ZX Spectrum)
Result: Deletes all variables. (QL)
CLEAR on the QL only deletes all variables and releases space for Qdos.
See also CLEAR n (command).
CLS
CLS (ZX Spectrum & QL)
CLS [channel,] [part] (QL)
Result: Clears the screen (ZX Spectrum)
Result: Clears the current window (or part thereof) (QL).
Where part is: 0 = whole screen 1 = top excluding cursor line 2 = bottom excluding cursor line 3 = whole of the cursor line 4 = right end of cursor line including cursor position
May be directed to a channel (window) on the QL.
Parts of the ZX Spectrum display can easily be cleared with PRINT statements and/or machine code routines.
COPY
COPY
Result: Sends the contents of the screen to the ZX Printer.
The COPY statement on the QL has a completely different meaning.
CSIZE
CZISE [channel,] width,height
Result: Changes character size(QL only)
QL only. Other ways may be found to change the character size on the Spectrum.
CURSOR
CURSOR [channel,] x,y [,x1,y1]
Result: Changes cursor position(QL only)
If four parameters are specified then the first pair of coordinates x,y are the graphics coordinates and the second pair x1,y1 are the cursor position.
QL only. On the ZX Spectrum use
PRINT AT x,y;
to change the PRINT cursor position.
Use system variable COORDS by setting addresses 23677 and 23678 to the appropriate values to change the PLOT (pixel) position.
DATA
DATA e1,e2,e3, ...
Result: Stores data in a list.
Same on both micros.
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.
ZX Spectrum only. On the QL user defined functions must be defined within the DEFine FUNCtion...END DEFine structure.
DIM
DIM α(n1,...,nk) (ZX Spectrum & QL)
DIM α$(n1,...,nk) (ZX Spectrum & QL)
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) (ZX Spectrum) or CHR$(0) (QL).
QL arrays have a base of 0, unlike the ZX Spectrum which has a base of 1, so the code for an array of 10 numbers on the QL would be
DIM A(9)
whereas on the ZX Spectrum it would be
DIM A(10)
DRAW
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.
ZX Spectrum only. The QL uses the LINE statement for similar effect.
EXIT
EXITidentifier
Result: Exit FOR loop or REPEAT and continue processing. (QL only)
QL only. Other methods can be used on the Spectrum, possibly, but not ideally, GO TO.
FILL
FILL [identifier,] switch
Result: Turn on or off switch which controls whether a shape should be drawn filled or not. (QL only)
1 sets FILL, 0 unsets FILL.
QL only. Filled shapes on the ZX Spectrum are possible in BASIC or machine code (faster).
FLASH
FLASH n (ZX Spectrum)
FLASH [channel,] n (QL)
Result: If n is set to 1 flash effect is turned on. If n is set to zero then flash effect is turned off. On the QL FLASH may be directed to a channel attached to a window.
Similar effect on both micros.
GO SUB
GO SUB n
Result: Stack GO SUB line number and branch (GO TO) line n.
Same on both micros. The ZX Spectrum manual is inconsistent with the spelling of GO SUB, using both GO SUB and GOSUB!
GO SUB on the QL is only included for compatibility and PROCedures should be used instead.
GO TO
GO TO n
Result: Branch or GO TO line n.
Again, like above the same on both micros.
For compatibility purposes only on the QL and other structures should be used instead.
It is possible to structure a ZX Spectrum not to use GO TO as well.
INK
INK n (ZX Spectrum)
INK [channel,] n (QL)
Result: Sets foreground colour of characters/pixels to be displayed. When n=0 to 7 a colour is selected. When n=8 transparency is selected. When n=9 contrast is selected. (ZX Spectrum)
Result: Sets foreground colour of characters/pixels to be displayed. If n is greater than 7 then ink colour will be a mixture of two stippled colours. May be directed to a channel attached to a window. (QL)
Similar on both micros with some differences with transparency, contrast and stippling.
INPUT
INPUT v (ZX Spectrum)
INPUT [channel] v (QL)
INPUT v1,v2,v3... (ZX Spectrum & QL)
INPUT LINE v$ (ZX Spectrum only)
Result: Computer waits for input of an expression then passes the value of this to the variable v.
INPUT on the QL can be directed to a channel for output to a window.
ZX Spectrum 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 QL, INK & PAPER could be reversed for the same effect.
LET (ZX Spectrum)
[LET] (QL)
LET v=e (ZX Spectrum)
[LET] v=e (QL)
Result: Assign the value e to the variable v.
LET is optional on the QL, i.e. :
α$="some text"
LINE
LINE_R
i) LINE[_R] [channel,] x,y TO x1,y1 [, ...]
ii)LINE[_R] [channel,] TO x,y
iii)LINE[_R] [channel,] x,y
Result i: Draw a line from x,y to x1,y1. Multiple lines may be drawn with one line statement but adding more parameters.
Result ii: Draw a line from last point specified to x,y.
Result iii: Move the graphics cursor to x,y.
A channel may be optionally selected to direct output to a window.
LINE_R uses the relative coordinate system.
QL only. The Spectrum's DRAW statement can be made to perform a similar function.
The LINE parameter on the ZX Spectrum has a couple of completely different meanings.
LOCal
LOCalidentifier [, ...]
Result: Creates an identifier within a procedure or function. The identifier acts as a temporary variable. (QL only)
QL only. Local variables are not available on the ZX Spectrum.
A type of local variable can be achieved on the Spectrum with the following:
REM A subroutine
LET local a=a
[code which uses a goes here]
LET a=local a
RETURN
The above works for numeric variables but not loop variables (FOR...NEXT)
For strings:
REM A subroutine
LET b$=a$
[code which uses a$ goes here]
LET a$=b$
RETURN
LPRINT
LPRINT ...
Result: Send a line of items to be printed to the ZX Printer.
The QL cannot use the ZX Printer.
MODE
MODE n
Result: Clears all windows and changes screen mode. (QL only)
8 or 256 will select low resolution mode.
4 or 512 will select high resolution mode.
QL only. The standard ZX Spectrum has only one display mode.
MOVE
MOVE [channel,] distance
Result: Move the graphics turtle by a specified distance. When no channel is specified the default window selected. (QL only)
QL only but turtle graphics can easily be represented on the ZX Spectrum with a short subroutine.
The MOVE statement on a ZX Spectrum fitted with Interface 1 has a different meaning.
OUT
OUT m,n
Result: Outputs byte n to port m.
The Motorola 68008 I/O ports are memory mapped so this statement is not applicable to the QL. POKE would be used instead.
OVER
OVER n (ZX Spectrum)
OVER [channel,] n (QL)
Result: If n=0 characters obliterate those already at that position. If n=1 characters are merged with those already at that position. (ZX Spectrum)
Result: If n=0 ink will print on strip, If n=1 ink will print on transparent strip, if n=-1 printing will be XOR'd with that on the screen. channel selects the window OVER is to be directed to. (QL)
On the ZX Spectrum 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).
On the QL
OVER -1
is the equivelent of
OVER 1
on the ZX Spectrum.
PAN
PAN [channel,] distance [,part]
Result: Move the contents of a window by a specified distance left or right. When no channel is specified the default window selected. (QL only)
When part=0 whole screen is panned. When part=3 whole of cursor line is panned. When part=4 right end of cursor line including cursor is panned.
QL only but PANning on the ZX Spectrum is possible with a machine code subroutine.
PAPER
PAPER n (ZX Spectrum)
PAPER [channel,] n (QL)
Result: Sets background colour of characters/pixels to be displayed. When n=0 to 7 a colour is selected. When n=8 transparency is selected. When n=9 contrast is selected. (ZX Spectrum)
Result: Sets background colour of characters/pixels to be displayed. If n is greater than 7 then paper colour will be a mixture of two stippled colours. May be directed to a channel attached to a window. (QL)
Similar on both micros with some differences with transparency, contrast and stippling.
PAUSE
PAUSE n
Result: Stop program execution for n*1/50seconds or until a key is pressed.
Same on both micros.
PENUP
and
PENDOWN
PENUP [channel]
Result: Raise the turtle pen in a window attached to a channel. (QL only)
PENDOWN [channel]
Result: Lower the turtle pen in a window attached to a channel. (QL only)
QL only but turtle graphics can easily be represented on the ZX Spectrum with a short subroutine.
PLOT
PLOT [c;] m,n
Result: Sets pixel ink at position m,n subject to c (INK/PAPER/OVER/INVERSE).
On the QL the keyword POINT performs a similar task to PLOT, this is different to the function POINT on the Spectrum.
POINT
POINT_R
(QL statements)
POINT[_R] [channel,] x,y [,x1,y1...xk,yk]
Result: Plot a point on the screen at position x,y or in a window attached to a channel (QL only)
POINT_R uses the relative coordinate system.
Almost the same as the ZX Spectrum's PLOT statement i.e.
POINT x,y
on the QL performs almost the same task as:
PLOT x,y
on the Spectrum.
Multiple parameters in a POINT statement such as
POINT 50,50,25,100
would require two seperate PLOT statements on the Spectrum.
POKE (ZX Spectrum & QL)
POKE_W (QL)
POKE_L (QL)
POKE m,n (ZX Spectrum & QL)
POKE_W m,n (QL only)
POKE_L m,n (QL only)
Result: Load data n into memory address m. (ZX Spectrum & QL)
POKE_W will place word (double-byte or 16 bit) data into address starting at m. (QL only)
POKE_L will place long word (32 bit) data into address starting at m. (QL only)
POKE same on both micros.
POKE_W can be acheived on the Spectrum with the following code:
POKE m,n-256*INT(n/256)
POKE m+1,INT(n/256)
PRINT
PRINT ...
Result: Send a series of items to the display, printer or output device (or a window on the QL) subject to control characters and (AT/TAB and colour/INVERSE/FLASH/OVER on the ZX Spectrum).
Similar on both micros with exceptions.
PRINT TO
(QL)
PRINT TO n ; ... (QL)
Result: Move tab position to n.
QL only, but the same as TAB on ZX Spectrum.
See also TAB.
RANDOMIZE
(ZX Spectrum)
or
RANDOMISE
(QL)
RANDOMIZE [n] (ZX Spectrum)
RANDOMISE [n] (QL)
Result: Sets system variable SEED to n which will be the basis for pseudo-random numbers (RND).
Same on both micros (except spelling - QL uses the english spelling, ZX Spectrum use the american spelling). ZX Spectrum keyboard shows shortened RAND and not RANDOMISE.
Note: QL RANDOMISE is the same spelling as the ZX80.
READ
READ e1,e2,e3, ...
Result: Read from DATA statement and pass to a variable or variables e1,e2,e3, ..
Same on both micros.
RECOL
RECOL [channel,] c0,c1,c2,c3,c4,c5,c6,c7
Result: Recolour pixels in window attached to a channel. Each parameter represent a colour (c0=black, c1=blue...) and the number entered for each parameter represents the colour to be changed to.
QL only. Although the ZX Spectrum cannot recolour individual pixels (only character squares) a short BASIC or machine code subroutine could be written to perform a similar task.
REM (ZX Spectrum)
REMark (QL)
REM ... (ZX Spectrum)
REMark ... (QL)
Result: None, display comment in program listing.
Same on both micros.
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.
Same on both micros.
RETURN (ZX Spectrum)
RETurn (QL)
i) RETURN (ZX Spectrum)
i) RETurn (QL)
Result i: Take line number off GO SUB stack and GO TO the line after that line number.(ZX Spectrum & QL)
ii) RETurn [value]
Result ii: Force an exit from a procedure or function. May also return a function's value.
(QL only)
RETURN from GO SUB work the same on both micros.
QL also use RETurn to exit from procedures and function.
STOP
Type: Program execution statement
STOP
Result: Stops program execution with Report 9. (ZX Spectrum)
Result: Stops program execution. (QL)
Similar on both micros.
SCALE
SCALE [channel,] scale,origin_x,origin_y (QL)
Result: Changes scale of graphics procedures.
QL only.
Not on the Spectrum but could possibly be simulated by adding a scale multiplier to PLOT, DRAW or CIRCLE statements e.g. :
PLOT scaleX*x,scaleY*y
STRIP
STRIPcolour1 [,colour2 [,stipple]] (QL)
Result: Set colour strip to colour1 and optionally colour2 with stipple.
QL only. An effect similar to STRIP can be acheived on the ZX Spectrum by combined INK, PAPER , OVER and block graphics or 'checkerboard' or 'stripe' UDG's.
TAB
TAB x
Result: Changes PRINT, LPRINT or INPUT tab position to x.
Not on the QL, PRINT TO n has exactly the same effect.
See also comma (PRINT delimiter).
TURN
and
TURNTO
TURN [channel,] angle
Result: Turn the turtle through a specified angle. Turtle is turned in the window attached to a channel. (QL only)
TURNTO [channel,] angle
Result: Turn the turtle to the specified angle. Turtle is turned in the window attached to a channel. (QL only)
QL only but turtle graphics can easily be represented on the ZX Spectrum with a short subroutine.
WIDTH
WIDTH [channel,] line_width (QL)
Result: Sets width of device attached to channel.
QL only.
On the ZX Spectrum+ 128K, ZX Spectrum +2 and the ZX Spectrum +3 the width setting of the printer is set in the system variables at memory location 23396.
WINDOW
WINDOW [channel,] width,depth,x,y (QL)
Result: Create a window of width and depth at position x,y and attach to a channel.
QL only.
The ZX Spectrum is capable of creating QL style windows with additional software such as YS MegaBASIC.
UNDER
UNDER [channel,] n (QL)
Result: Turns underlining on or off for subsequent output lines.
n=0, underline off n=1, underline on.(QL only)
QL only
The ZX Spectrum can imitate underlining by OVERprinting underscores '_' (CHR$ 95).
Compound & Structured statements
Keyword
Meaning
Comments
FOR...NEXT loop
(FOR, TO, [STEP,] NEXT) (ZX Spectrum)
(FOR, TO, [STEP,] [NEXT,] END FOR) (QL)
FOR α=x TO y [STEP z] (ZX Spectrum & QL)
[section of program to be repeated goes here]
NEXT α
FOR α=x TO y [STEP z] : (QL short form)
[section of program to be repeated continues after the colon until the end of the line] Note the lack of NEXT statement.
FOR α=x TO y [STEP z] (QL long form)
[section of program to be repeated goes here]
END FOR α
Result: Sets up and executes the loop α from x to y with a step of z.
[Note] Step of +1 assumed if STEP omitted)
Similar on both micros.
On the QL a NEXT statement may be used within the FOR...END FOR loop.
Although NEXT statement is not compounded within the FOR statement as TO and STEP are, it is included here for completeness.
IF..THEN
IF..THEN (ZX Spectrum & QL)
IF..THEN..[ELSE]..ENDIF (QL)
IF x THEN s (ZX Spectrum & QL)
IF x THEN s1 [:ELSE s2] s (QL short form)
IF x THEN s1 (QL long form)
[ELSE s2]
END IF
Result: If x is true (non-zero) then s will be executed.
Similar on both micros.
ELSE can be simulated on the ZX Spectrum by skipping the line immediately after the IF..THEN if the condition is true.
IFconditionTHENstatement : GO TO next_statement
else_statement
next_statement
ON...
ON...GOTO
ON...GOSUB
ON x GOTO m1 [,m2...,mk]
ON x GOSUB m1 [,m2...,mk]
Result: Branch to line m if x is true.
QL only
The ZX Spectrum can simulate ON..GOTO/GOSUB with
GO TO (m1AND x=1)+(m2AND x=2)+ (mkAND x=k)
REPeat...END REPeat
REPeatidentifier : statements (QL short form)
REPeatidentifier (QL long form)
statements
END REPeatidentifier
Result: Sets up and executes the loop identifier and performs statements. END REPeat closes the loop and EXIT will exit the loop. There will normally be at least one EXIT statement in a REPeat...END REPeat loop.
Not on the ZX Spectrum but a REPeat loop to wait for a keypress can be achieved with the following code.
LET exit=1
FOR r=0 TO 0 STEP 0
IF INKEY$<>"" THEN LET r=exit
NEXT r
Explanation:
The exit variable is set to '1'. This is just a convenient name to make the program easier to follow.
The FOR loop is a dummy loop which will be our REPeat.
Next comes the line which checks for a keypress. If true r, the REPeat loop variable, will be set to exit or 1, and the loop will be exited at NEXT r
NEXT r completes the loop, this is the eqivalent of END REPeat.
SELect...END SELect
SELect ONselect_variable (QL short form) = statement :
SELect ONselect_variable (QL long form)
[ONselect_variable = statement]
[ONselect_variable = REMAINDER]
END SELect
Result: statement is acted on depending on the select_variable being true.
ON REMAINDER will catch any cases not captured by the list of select_variables.
QL only
The ZX Spectrum must use individual IF statements instead.
Functions
Keyword
Meaning
Comments
ABS
ABS x (ZX Spectrum)
ABS(x) (QL)
Returns: Absolute magnitude of x, i.e. distance on number line from zero, -1=1 -2=2
Same on both micros.
ACS (ZX Spectrum)
ACOS (QL)
ACS x (ZX Spectrum)
ACOS(x) (QL)
Returns: Arccosine (inverse cosine) of x in radians.
Same on both micros.
ACOT
ACOT(x)
Returns: Arc Cotangent (inverse cotangent) of x in radians.
Not on the ZX Spectrum.
The arc cotangent can be found with the following code:
LET ACOT=PI/2-ATN x
ASN (ZX Spectrum)
ASIN (QL)
ASN x (ZX Spectrum)
ASIN(x) (QL)
Returns: Arcsine (inverse sine) of x in radians.
Same on both micros.
ATN (ZX Spectrum)
ATAN (QL)
ATN x (ZX Spectrum)
ATAN(x) (QL)
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.
There does not appear to be an equivelent of the ATTR function on the QL.
BEEPING
BEEPING has no operands.
Returns: Zero if not beeping. One if beeping.
Not on the ZX Spectrum.
Since the Spectrum's BEEP statement disables the interupts there is no way to pass a value to a function to detect if the Spectrum is beeping while the BEEP statement is in use.
BIN
Type: Numeric notation
BIN b
Returns: decimal value of a base2 (binary) 16 bit number.
Only on Spectrum.
CHR$
CHR$ x (ZX Spectrum)
CHR$(x) (QL)
Returns: Single character from position x in the character set.
The CHR$ function performs mostly the same task on both computers The end result will be different as although the Spectrum's character set is based on the ASCII code, just like the QL's, there are some differences with non-standard characters, keywords and escape codes.
CODE
CODE α$ (ZX Spectrum)
CODE(α$) (QL)
Returns: Numeric value (between 0 and 255) representing the position in the character set of α$. This is the inverse of the CHR$ function.
The CODE function performs mostly the same task on both computers Like CHR$ above, the end result may be different as although the Spectrum's character set is based on the ASCII code, just like the QL's, there are some differences with non-standard characters, keywords and escape codes.
COS
COS x (ZX Spectrum)
COS(x) (QL)
Returns: Cosine of x in radians.
Same for both micros.
COT
COT(x)
Returns: Cotangent of x in radians.
Not on the ZX Spectrum.
The cotangent can be found with the following code:
LET COT=1/TAN x
DATE$
and
DATE
<>DATE$[(x)]
Returns: String containing the date held in the internal clock in the format "yyyy mmm dd hh:mm:ss".
When x is specified date is calculated from x instead of the internal clock.
Type: Time function
DATE
Returns: Floating point number representing the date held in the internal clock.
Not on the ZX Spectrum.
The Spectrum cannot retrieve a date from its internal clock but a subroutine could calculate the current date from x.
DAY$
DAY$
Returns: String containing the day of the week held in the internal clock in the format "ddd".
Not on the ZX Spectrum.
The Spectrum cannot retrieve the day of the week from its internal clock but a subroutine could calculate the day for a certain date.
DIMN
DIMN(array [,function])
Returns: Maximum size of an array. If dimension is specified the maximum size of that dimension within the array is specified.
Not on the ZX Spectrum.
DIMN could be emulated with a machine code routine to read the VARS table and return a result from that.
EXP
EXP x (ZX Spectrum)
EXP(x) (QL)
Returns: Numeric value for the function ex where e=2.7182818...
Same on both micros.
FILL$
FILL$(α$,m)
Returns: String filled with characters in α$ upto a length of m.
Not on the ZX Spectrum.
Easily emulated with this short subroutine.
1000 REM FILL$
1010 LET f$=f$+f$
1020 IF LEN f$>l THEN LET f$=f$(TO l) : RETURN
1030 GO TO 1010
Where f$ is the string to be repeated and l is the maximum length of the output string.
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.
For the QL see DEFine FuNction.
See also DEF FN.
INKEY$
INKEY$[channel] (ZX Spectrum)
INKEY$[(channel,)][(time)] (QL)
Returns: Single character from a keypress. May be attached to a channel. (ZX Spectrum or QL) Optional timeout measured in frames can be specified by time.
Typical usage would be
PRINT INKEY$
LET A$=INKEY$ or
10 IF INKEY$="" THEN GO TO 10
Also for the QL.
PRINT INKEY$(50)
Wait for 50 frames before returning.
Similar on both micros.
The QL's timeout can be simulated on the Spectrum by adding a PAUSE statement before INKEY$. A PAUSE 50 will be roughly the same as INKEY$(50).
IN
IN m
Returns: numeric value between 0 and 255 for the port m.
The Motorola 68008 I/O ports are memory mapped so this statement is not applicable to the QL. PEEK would be used instead.
INT
INT x (ZX Spectrum)
INT(x) (QL)
Returns: x rounded down to the nearest integer.
Same on both micros except ZX Spectrum's INT bug (see note below).
[Note] On the ZX Spectrum when INT -65536 is performed the wrong result is given as -1.
KEYROW
KEYROW(n)
Returns: Numeric value based upon the keys pressed in row n
Not on the ZX Spectrum.
Possibly could be simulated with this function.
DEF FN k(n)=IN (254+256*(255-2↑n))
The ZX Spectrum's keyboard is laid out quite differently to the QL's (half-rows being read instead of the QL's full-rows), however the effect is similar, that is a half-row can be read and the numeric result passed to FN k(n).
LEN
LEN α$ (ZX Spectrum)
LEN(α$) (QL)
Returns: numeric value for the length of α$.
Same on both micros.
LN
LN x (ZX Spectrum)
LN(x) (QL)
Returns: numeric value for the natural logarithm of x.
Same on both micros.
LOG10
LOG10(x) (QL)
Returns: numeric value for the common logarithm of x.
QL only.
The common logarithm can be found on the Spectrum with
LET LOG10=LN x/LN 10
PEEK (ZX Spectrum & QL)
PEEK_W (QL)
PEEK_L (QL)
PEEK m (ZX Spectrum & QL)
PEEK_W m (QL only)
PEEK_L m (QL only)
Result: Return the contents of memory address m. (ZX Spectrum & QL)
PEEK_W will read a word (double-byte or 16 bit) starting at address m. (QL only)
PEEK_L will read a long word (32 bit) from address starting at m. (QL only)
PEEK_W can be acheived on the Spectrum with the following code:
PEEK m+256*PEEK (m+1)
PI
PI has no operands.
Returns: 3.1415927 (π) Ratio of circumference of a circle to its diameter
Typical usage might be:
LET R=C/(2*PI)
Same on both micros.
[Note] PI is stored on the ZX Spectrum as 10 digits but will only display 8 digits. On the QL only 7 digits are displayed.
POINT
(ZX Spectrum)
POINT (x,y)
Returns: 0 or 1 for the screen location x,y.
Not on the QL. The ZX Spectrum POINT statement is the inverse of the QL POINT statement which behaves like The Spectrum's PLOT.
RAD
RAD(x)
Result: Converts x degrees to radians.
Not on the ZX Spectrum.
Degrees can be converted to radians with the following code:
LET RADians=DEGrees*PI/180
RND
RND (ZX Spectrum & QL)
RND([m] [TO n]) (QL only)
Returns (ZX Spectrum & QL)
A pseudo-random number between 0 and 1 is generated. On the ZX Spectrum no operands are required.
An example of usage would be
LET X=INT(RND*42)+1 (ZX Spectrum)
LET X=RND(42) (QL)
RND with no operands behaves the same on both micros.
To the simulate QL's RND (m TO n) the following function should suffice:
DEF FN r(m,n)=INT(RND*n)+m
SCREEN$
SCREEN$ (x,y)
Returns: character displayed at location x,y.
Not on the ZX80.
SGN
SGN x
Returns: signum (or sign) of x, for instance -1 if x<0, 0 if x=0 or 1 if x>1.
Surprisingly not on the QL but can be emulated with the following function:
DEFine FuNction SiGNum(x)
RETurn -1*(x<0)+(x>0)
END DEFine
I have used the name SiGNum to fit in with SuperBASIC nomenclature but SGN could just as well be used.
SQR (ZX Spectrum)
SQRT (QL)
SQR x (ZX Spectrum)
SQRT(x) (QL)
Returns: square root of x.
Same on both micros.
STR$
STR$ x (ZX Spectrum)
Result: string comprising of the numeric value of x.
Not required on the QL.
The ZX Spectrum line:
LET a$=STR$ b
on the QL would be much simplified with:
a$=b
TAN
TAN x (ZX Spectrum)
TAN(x) (QL)
Returns: Tangent of x in radians.
Same on both micros.
USR
USR x
Returns: contents of the bc register pair after calling machine code at memory location x.
ZX Spectrum only.
The QL uses CALL to execute machine code.
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.
Other methods of defining user graphics must be found on the QL.
VAL
VAL α$
Returns: numeric value evaluated from the string α$.
Not required on the QL.
The ZX Spectrum line:
LET a=VAL b$
on the QL would be much simplified with:
a=b$
VAL$
VAL$ α$
Returns: string evaluated from the string α$.
There does not appear to be a simple way to simulate VAL$ in QL SuperBASIC although it may be possible to write a function for this.
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.
Note: On the QL only either or both x and y can be numeric strings.
Same on both micros with the exception that the QL can subtract a number contained in a string just as STR$ and VAL are used on the Spectrum.
+
Addition
x+y
Result: a numeric value resulting from y being added to x.
Note: On the QL only either or both x and y can be numeric strings.
Same on both micros with the exception that the QL can add a number contained in a string just as STR$ and VAL are used on the Spectrum.
+ (ZX Spectrum)
& (QL)
String concatenation
α$+β$ (ZX Spectrum)
α$&β$ (QL)
Result: concatenates (joins together) string α with string β to form a new string.
Same on both micros with the exception that the ZX Spectrum uses a plus sign '+' and the QL uses an ampersand '&' as the operator.
/
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.
↑ (ZX Spectrum)
^ (QL)
Raise to the power of
x↑y (ZX Spectrum)
x^y (QL)
Result: a numeric value resulting from x being raised to the power of y.
Same meaning on both micros with a slight difference in the up arrow used.
<
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 (ZX Spectrum)
x<=y (QL)
Where x and y can be either numeric or strings but cannot be mixed.
Result: 1 if x≤y otherwise 0.
Same result on both micros. On the Spectrum <= is a keyword and not two seperate characters.
>=
Greater than or equal to
x>=y (ZX Spectrum)
x>=y (QL)
Where x and y can be either numeric or strings but cannot be mixed.
Result: 1 if x≥y otherwise 0.
Same result on both micros. On the Spectrum >= is a keyword and not two seperate characters.
=
Is equal to
x=y
Where x and y can be either numeric or strings but cannot be mixed. (ZX Spectrum)
Where x and y can be either numeric or strings. Numeric variables and string variables may be mixed and processed using coersion (just like VAL and STR$). (QL)
Result: 1 if x=y otherwise 0.
Similar on both micros.
==
Is equvilent or approximately equal to
x==y
Where x and y can be either numeric or strings. Numeric variables and string variables may be mixed and processed using coersion (just like VAL and STR$). (QL only)
Result: 1 if x==y otherwise 0.
QL only.
The following function should simulate the QL's
x==y
on the ZX Spectrum.
DEF FN e(x,y)=(ABS (x-y)<=.0000004)
<>
Is not equal to
x<>y (ZX Spectrum)
x<>y (QL)
Where x and y can be either numeric or strings but cannot be mixed. (ZX Spectrum)
Where x and y can be either numeric or strings. Numeric variables and string variables may be mixed and processed using coersion (just like VAL and STR$). (QL)
Result: 1 if x≠y otherwise 0.
Same result on both micros. On the Spectrum <> is a keyword and not two seperate characters.
&&
Bitwise AND
x&&y
Where x and y are a numbers or numeric strings.
Returns: decimal number based on a bit-by-bit AND of x and y.
Not on the ZX Spectrum.
A short machine code routine could simulate bitwise AND.
||
(Two vertical lines)
Bitwise OR
x||y
Where x and y are a numbers or numeric strings.
Returns: decimal number based on a bit-by-bit OR of x and y.
Not on the ZX Spectrum.
A short machine code routine could simulate bitwise OR.
^^
Bitwise XOR
x^^y
Where x and y are a numbers or numeric strings.
Returns: decimal number based on a bit-by-bit XOR of x and y.
Not on the ZX Spectrum.
A short machine code routine could simulate bitwise XOR.
~~
Bitwise NOT
~~x
Where x is a number or numeric string.
Returns: decimal number based on a bit-by-bit NOT of x.
Not on the ZX Spectrum.
The bitwise NOT just performs a two's complement on x. This can be simulated in BASIC with the following function.
DEF FN n(x)=-1*(x+1)
AND
x AND y
Where x is a number or a string, and y is always numeric. (ZX Spectrum)
Where x and y are a number or a numeric string. (QL)
Returns: x if y is true (non-zero) or 0 if y is false (zero).
On the QL standard character strings cannot be tested directly with AND (numeric strings can be tested with coersion).
MOD
m MOD n
Returns: Modulus (remainder) of m divided by n.
QL only.
The modulus can be found on the Spectrum with the function:
DEF FN M(m,n)=INT(m-(INT(m/n)*n))
See also DIV, INT.
DIV
m DIV n
Returns: An integer from m divided by n.
QL only.
Quite simply on the ZX Spectrum this would be:
INT (m/n)
NOT
NOT x
Returns: zero if x≠0, 1 if x=0
On the QL x may be a numeric string.
Same on both micros
OR
br>x OR y
Returns: 1 if x or y≠0, value of x if b=0.
On the QL x or y may be numeric strings.
Same on both micros
XOR
x XOR y
Where x and y are a number or a numeric string.
Returns: x if y is true (non-zero) or 0 if y is false (zero).
Logical XOR does not exist on the Spectrum but this can be coded in BASIC as follows.
DEF FN X(x,y)=(x OR y) AND NOT (x AND y)
INSTR
α$ INSTR β$
Returns: Position in string β of sub-string α$ or zero if false.
Not on the ZX Spectrum but a short BASIC routine can simulate INSTR.
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 including the pointless v$( TO )!
Delimiters
Keyword
Meaning
Comments
PRINT/INPUT item seperator
;
Semi-colon
PRINT ; (ZX Spectrum & QL)
LPRINT ; (ZX Spectrum)
INPUT ; (ZX Spectrum & QL)
Result: separates items within a PRINT (ZX Spectrum & QL), LPRINT (ZX Spectrum only) or INPUT (ZX Spectrum & QL) statement.
Same on both micros (except LPRINT which the QL lacks).
New line
' Apostrophe (ZX Spectrum)
\ Back slash (QL)
PRINT ' (ZX Spectrum)
LPRINT ' (ZX Spectrum)
INPUT ' (ZX Spectrum)
PRINT \ (QL)
INPUT \ (QL)
Result: Moves the PRINT, INPUT or LPRINT (ZX Spectrum only) position down a line.
Same on both micros (except LPRINT which the QL lacks).
TAB seperator
,
Comma
PRINT , (ZX Spectrum & QL)
LPRINT , (ZX Spectrum)
INPUT , (ZX Spectrum & QL)
Result: Moves the PRINT position across the screen (or printer) or to the start of the next line if PRINT position is greater or equal to the last tab position.
Similar on both micros (except LPRINT which the QL lacks).
Automatic tabs are 8 characters across on the QL and 16 on the ZX Spectrum or ZX Printer.
Operand delimiter
,
Comma
Separates operands within a statement.
Examples:
POKE x,y (ZX Spectrum & QL)
ATTR (x,y) (ZX Spectrum)
Result: Separates operands within a statement.
Same on both micros.
Stream prefix
#
Hash
PRINT #m (ZX Spectrum & QL)
LPRINT #m (ZX Spectrum only)
INPUT #m (ZX Spectrum & QL)
Result: Output to stream m.
Note: There are too many examples for the QL to show here, needless to say most statements which handle input or output (including the display) may direct a stream through a channel.
Similar on both micros.
On the QL a stream may be directed to a window.
Statement delimiter
:
Colon
s1 : s2 : s3 ...
Result: Allows more than one statement per line number to be entered.
Same on both micros.
String encloser
"
Double quotation mark
α$="Marvin" (ZX Spectrum & QL)
PRINT "Marvin" (ZX Spectrum & QL)
LPRINT "Marvin" (ZX Spectrum)
INPUT "Marvin" (ZX Spectrum & QL)
Result: Encloses text within a string. Encloses text with a PRINT, LPRINT (ZX Spectrum only) or INPUT statement.
Same on both micros.
QL can also use a pair of apostrophes to enclose a string.
String encloser
'
Apostrophe
α$='Marvin'
PRINT 'Marvin'
INPUT 'Marvin'
Result: Encloses text within a string. Encloses text with a PRINT or INPUT statement.
QL only.
An alternative to the pair of double quotation marks that normally enclose a string.
Double quotation escape
"
Double quotation mark
PRINT "This is a ""Test""." (ZX Spectrum)
Result:
This is a "Test".
Within a string enclosed with a pair of double quotes an escape double quote followed by another double quote must be used if a pair of double quotes is required within a string. The escape double quote is not displayed, only the double quote which follows it.
ZX Spectrum only (sort of)
The QL can do this but not quite in the same way. The double quotes (or single quote) are not escaped so enclosed text must be followed by a semi-colon, on a PRINT line, before anymore text can be added to that PRINT line.
Within a string the & (ampersand) concatenation character must follow enclosed text before continuing further.
A pair of single quotes may surround a double quote or vice versa.
Examples for the QL.
PRINT 'This is a ';'"Test"';'.'
Will produce the same output as the Spectrum example whereas
PRINT "This is a ";"'Test'";"."
Will display
This is a 'Test'.
String example
α$="This is a "&'"Test"'&"."
Nomenclature
This list uses the same letters to represent variables, expressions and sequences etc. as the ZX Spectrum BASIC and QL 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.
Items in italics are parameters in explanatory word form.
A short note on brackets. Where curved brackets '(' or ')' are shown they are mandatory, this includes the ZX Spectrum 'two parameter' functions and user defined functions.
Where square brackets '[' or ']' are shown the statement, parameter or value inside the bracket is optional.
For a more detailed explanation of the nomenclature used on this site, click here.
Notes on Sinclair QL coersion
The QL dispenses with the statements VAL & STR$ by means of coersion. This involves holding numbers in a string and passing them directly to a numeric variable and vice versa. One type of variable is coersed into becoming another type of variable. When referring to the Sinlair QL on this website, such strings which hold numbers prior to coersion are called numeric strings. This is a non-standard term and is used to avoid confusion with character strings which can hold any ASCII characters.
A note on QL abbreviations. Abbreviations are allowed with some QL statements and these are shown with the standard QL format of UPPER-CASElower-case i.e. REM becomes REMark for remark.
References
Sinclair ZX Spectrum BASIC Programming, Steven Vickers (author), Robin Bradbeer (editor)
Sinclair QL User Guide, Steven Berry (editor)