A Comparision of Keywords on the Dragon 32/64, TRS-80 Color Computer and the ZX Spectrum
Overview
The following is a list of keywords, operators and delimiters used on the Dragon 32/64 & TRS-80 Color Computer 'CoCo' and the ZX Spectrum. The Dragon and TRS machines are contempories of the Spectrum and as such have similar capabilities. There are many differences though, the most significant of which is the processor used by the Dragon and TRS-80 CoCo, the 6809. The 6809 uses a completely different instruction set and registers to the Z80 used by the Spectrum so any machine code used within a BASIC program will have to be rewritten.
Both the Dragon & TRS micros use a different version of BASIC to the ZX Spectrum. The Dragon 32 & 64 use a version of Microsoft BASIC called Microsoft Extended BASIC, the TRS-80 Color Computer uses a version called Microsoft Color BASIC. Both versions appear mostly compatible with each other with just a few differences.
The Dragon 64 was an upgraded model to the Dragon 32 with greater RAM but essentially the same machine with extras. For technical reasons the Radio Shack/Tandy TRS-80 Color Computer or 'CoCo' is mostly compatible with the Dragon but there are a few differences with statement keywords.
Commands
Keyword
Meaning
Comments
AUDIO
AUDIO ON¦OFF
Result: Connects or disconnects cassette output to TV speaker.
Not on the Spectrum.
CLEAR
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 [m][,n] (Dragon 32/64 & TRS-80 CoCo)
Result: Deletes all variables and clears the GOSUB stack. If first parameter is specified then m bytes are reserved for string space. If second parameter is specified then the highest address for BASIC programs will be set to n (This is the equivalent of RAMTOP on the Spectrum).
CLEAR on the Dragon does not clear the screen.
CONT or CONTINUE
CONT (Dragon 32/64 & TRS-80 CoCo)
CONTINUE (ZX Spectrum)
Result: After BREAK error (Dragon) or report L (BREAK into program) CONTINUE will execute the next line after the error occurred.
CONTINUE is shortened to CONT on the Dragon. The ZX Spectrum keyboard shows CONTINUE as CONT.
CSKIPF (Dragon 32/64)
SKIPF (TRS-80 CoCo)
CSKIPF f (Dragon 32/64)
SKIPF f (TRS-80 CoCo)
Result: Load the program immediately following program f from tape (Program f is not loaded),
Not on the Spectrum.
LIST
LIST (Dragon 32/64 & TRS-80 CoCo & ZX Spectrum)
Result: Display complete program listing.
LIST n (ZX Spectrum)
Result: Display program listing from line n or line 0 where no line number specified.
LIST n (Dragon 32/64 & TRS-80 CoCo)
Result: Display single program line n.
LIST [m]-[n] (Dragon 32/64 & TRS-80 CoCo)
Result: Display program listing from line m to line n. If m is omitted listing will begin at the start of the program. If n is omitted then listing will stop at the end of the program. If both m and n are omitted, i.e.LIST - ,the complete program will be listed (same as LIST).
Note: Dragon uses a minus sign as the delimiter in a LIST command.
LLIST
LLIST (Dragon 32/64 & TRS-80 CoCo & ZX Spectrum)
Result: Send a complete program listing to the printer.
LLIST n (ZX Spectrum)
Result: Print the program listing from line n or line 0 where no line number specified.
LLIST n (Dragon 32/64 & TRS-80 CoCo)
Result: Print single program line n.
LLIST [m]-[n] (Dragon 32/64 & TRS-80 CoCo)
Result: Print program listing from line m to line n. If m is omitted listing will begin at the start of the program. If n is omitted then listing will stop at the end of the program. If both m and n are omitted, i.e.LLIST - ,the complete program listing will be printed (same as LLIST).
Note: Dragon uses a minus sign as the delimiter in a LLIST command.
LOAD (ZX Spectrum)
CLOAD (Dragon 32/64 & TRS-80 CoCo)
LOAD "" (ZX Spectrum)
CLOAD (Dragon 32/64 & TRS-80 CoCo)
Result: Load the first program encountered on cassette. On the ZX Spectrum double quotes may be replaced by a string variable as long as it is a null string.
LOAD f (ZX Spectrum)
CLOAD f (Dragon 32/64 & TRS-80 CoCo)
Result: Load program f.
LOAD f[$] DATA () (ZX Spectrum only)
Result: Load array f from cassette into the variables area of memory.
LOAD f CODE [m[,n]] (ZX Spectrum only)
Result: Load data from cassette into the memory location specified when the file was saved. If m is specified then load into memory location m. Optionally n (number of bytes to load) may also be specified)
LOAD f SCREEN$ (ZX Spectrum only)
Result: Load screen data into from tape directly into the display file (same as:LOAD f CODE 16384,6192 )
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 Dragon or TRS-80 CoCo.
MOTOR
MOTOR ON¦OFF
Result: Turns cassette player ON or Off.
No equivalent on the Spectrum.
NEW
NEW
Result (Dragon 32/64 & TRS-80 CoCo): Deletes program and variables.
Result (ZX Spectrum): Deletes program and variables and memory up to and including the address held in the system variable RAMTOP.
Similar on both micros. On the Dragon machines NEW does not clear the screen. On the ZX Spectrum NEW preserves the system variables UDG, P-RAMT, RASP and PIP.
SAVE (ZX Spectrum)
CSAVE (Dragon 32/64 & TRS-80 CoCo)
SAVE f (ZX Spectrum)
CSAVE f (Dragon 32/64 & TRS-80 CoCo)
Result: Save program f to tape. SAVE f LINE m (ZX Spectrum)
Result: Save program f to tape. RUN program from line m when reloaded. CSAVE f ,A (Dragon 32/64 & TRS-80 CoCo)
Result: Save data to tape in ASCII format (note the 'A' parameter after the comma) SAVE f DATA α[$]() (ZX Spectrum)
Result: Save array α to tape. SAVE f CODE m,n (ZX Spectrum)
Result: Save code from memory to tape starting at address m with a length of n bytes. SAVE f SCREEN$ (ZX Spectrum)
Result: Save display file with filename f to tape (same as SAVE f CODE 16384,6192).
Dragon filenames can be up to 8 characters long and must start with a letter. ZX Spectrum filenames can be up to 10 characters long and may contain any ASCII characters including control codes. ZX Spectrum has extra options to save dimensional arrays, code from memory or the display file.
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: Compares program/array/code f from tape with that in memory. Error R if verify fails.
Not available on the Dragon.
Statements
Keyword
Meaning
Comments
AT (ZX Spectrum)
@ (Dragon 32/64 & TRS-80 CoCo)
PRINT AT x,y; (ZX Spectrum)
INPUT AT x,y; (ZX Spectrum)
Result: Changes PRINT or INPUT position to x,y.
PRINT @ x, (Dragon 32/64 & TRS-80 CoCo)
Result: Changes PRINT position to x.
The text grid is laid out differently on the Dragon compared to the Spectrum. The Dragon text mode screen is 16 rows by 32 columns with each cell numbered consecutively whereas the Spectrum text layout is 22 rows by 32 columns (not including the two input lines).
BEEP
BEEP x,y
Result: Sound emitted for x seconds at pitch y.
For the Dragon equivalent sound statement see SOUND. See also PLAY.
BORDER
BORDER m
Result: Changes screen border colour to m.
It is not possible to change the border on the Dragon.
BRIGHT
BRIGHT n
Result: When n=1 permanent brightness is turned on. When n=0 permanent brightness is off.
keywordBRIGHT n
Result: When n=1 temporary brightness is turned on. When n=0 temporary brightness is off.
keyword may be one of PRINT, LPRINT, INPUT, PLOT, DRAW or CIRCLE statements. When BRIGHT is applied to the keyword LPRINT there will be no effect on characters printed on the ZX Printer.
The brightness of the screen cannot be changed on the Dragon.
CIRCLE
CIRCLE x,y,z (ZX Spectrum)
CIRCLE (x,y),z (Dragon 32/64 & TRS-80 CoCo)
Result: Draws a circle of radius z at position x,y.
CIRCLE x,y,z,colour,hwratio,start,end
(Dragon 32/64 & TRS-80 CoCo)
Result: Draws a circle of radius z at position x,y. The colour is one of the available colours in the mode you are working in, (if omitted, the foreground colour is used). The other parameters are for drawing ellipses and arcs.
The Dragon must use one of the high resolution modes to draw a circle.
CLOSE #
CLOSE #device_number (Dragon 32/64 & TRS-80 CoCo)
CLOSE #stream_number (ZX Spectrum)
Result: Close device / stream.
Same effect.
CLS (Dragon 32/64 & TRS-80 CoCo and ZX Spectrum)
PCLS (Dragon 32/64 & TRS-80 CoCo)
CLS (ZX Spectrum)
Result: Clears the screen.
CLS [c] (Dragon 32/64 & TRS-80 CoCo)
Result: Clears the text screen. Optional parameter c changes the background colour.
PCLS [c] (Dragon 32/64 & TRS-80 CoCo)
Result: Clears the high resolution screen. Optional parameter c changes the background colour.
The Dragon's CLS c & PCLS c can be simulated on the ZX Spectrum with :
PAPER c : CLS
bearing in mind the value of c will need to be altered as it will produce a different colour on each machine.
COLOR
COLORforeground,background
Result: Changes the foreground and background colours.
foreground is the code (0 to 8) for the foreground color. background is the code (0 to 8) for the background color.
For a similar result on the Spectrum use INK for foreground and PAPER for background.
COPY
COPY (ZX Spectrum)
Result: Sends the contents of the screen to the ZX Printer.
Not on the Dragon.
DATA
DATA e1,e2,e3, ...
Result: Stores data in a list.
Similar on both micros. The ZX Spectrum requires string data to be surrounded by quotes, the Dragon does not.
DEF FN
DEF FN α(α1, αk)=e (ZX Spectrum)
Result: Defines a function. α and α1 to αk can be a single letter or single letter followed by $ for a string argument.
DEF FN α(α)=e (Dragon)
Result: Defines a function. α must be a single letter.
Similar on both micros. The Dragon may only use one dummy variable in the function and strings are not allowed. The ZX Spectrum may use multiple dummy variables and can handle strings. A definable function on the Spectrum may call itself, on the Dragon it may not.
DEF USR
DEF USRn = address
Result: Defines the address of a USRn function.
n is between 0 and 9 and matches the n in the USR. The address must be
between 0 and 65535 and contain the entry address for USRn.
Not on the Spectrum but can be simulated with:
DIM n(10)
LET n(1)=address1
LET n(2)=address2
LET n(3)=address3 et cetera...
Then to call the machine code subroutine at the address directed to by number:
LET call=USR n(number)
DIM
DIM α(n1,...,nk) (Dragon 32/64 & TRS-80 CoCo & ZX Spectrum)
DIM α$(n1,...,nk) (ZX Spectrum only)
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).
String arrays are not allowed on the Dragon.
DRAW (ZX Spectrum)
DRAW x,y
DRAW x,y,z
Result: DRAW a high resolution line from the current PLOT position moving x horizontally and y vertically rotating through angle z if third parameter is specified.
For the Dragon statement with a similar function to DRAW see LINE.
DRAW (Dragon 32/64 & TRS-80 CoCo)
DRAWstring_expression
Result: Draws a series of lines according to the contents of string_expression.
string_expression may include motion commands, modes, and options.
Motion Commands
M = Move the draw position
U = Up
D = Down
L = Left
R = Right
E = 45-degree angle
F = 135-degree angle
G = 225-degree angle
H = 315-degree angle
X = Execute a substring and return
Modes
C = Color
A = Angle
S = Scale
Options
N = No update of draw position
B = Blank (no draw, just move)
Not on the Spectrum although a small program could be written to simulate the 'macro language' used on the Dragon/TRS-80 CoCo.
END
END
Result: Terminates program and returns control to the user. CONT will not continue program. (Dragon 32/64 & TRS-80 CoCo).
Differs from STOP in the way that END cannot continue a program with CONT from where it left off.
Not on the Spectrum. STOP may be used instead.
For a similar approach to END for ending a program on the Spectrum try redirecting the program flow to line 9999 and include a STOP statement on that line. CONTINUE will not work after the STOP in line 9999.
See also STOP, CONT, CONTINUE.
EXEC
EXEC [(address)]
Result: Transfers control to machine code programs at specified address. If you omit address control is transferred to address set in last CLOADM. (Dragon 32/64 & TRS-80 CoCo).
Not on the Spectrum. Use a USR call instead.
See also DEF USR, USR.
FLASH
FLASH n (ZX Spectrum only)
Result: If n is set to 1 temporary flash effect is turned on. If n is set to zero then temporary flash effect is turned off.
keywordFLASH n (ZX Spectrum only)
Result: If n is set to 1 permanent flash effect is turned on. If n is set to zero then permanent flash effect is turned off.
keyword may be one of PRINT, LPRINT, INPUT, PLOT, DRAW or CIRCLE statements. When FLASH is applied to the keyword LPRINT there will be no effect, obviously.
Although the Dragon has no FLASH statement a similar effect can be acheived by PRINTing and then overPRINTing normal then inverse characters with a FOR...NEXT loop to alter the speed of the FLASH.
GET
GET (x1,y1)-(x2,y2),array_name[,G]
Result: Reads the graphic contents of a rectangle into the array array_name for use with the PUT statement. (Dragon 32/64 & TRS-80 CoCo).
Rectangle is defined at start corner x1,y1 and end corner x2,y2.
array_name is the name of a previously dimensioned array, in which the image is to be stored. The size of the array must match the size of the display rectangle.
The G parameter must be used when using high resolution modes 3 & 4.
Not on the Spectrum. Machine code subroutines are available to accomplish a similar task.
GOSUB or GO SUB
GOSUB n (Dragon 32/64 & TRS-80 CoCo)
GO SUB n (ZX Spectrum)
Result: Stack GO SUB line number and branch (GO TO) line n.
Same result all round with the exception of the spelling, GO SUB with a space for the Spectrum and without (GOSUB) for the Dragon. The ZX Spectrum manual is inconsistent with the spelling of GO SUB, using both GO SUB and GOSUB!
GOTO or GO TO
GOTO n (Dragon 32/64 & TRS-80 CoCo)
GO TO n (ZX Spectrum)
Result: Branch or GO TO line n.
Again, like above the Same result all round with the exception of the spelling, GO TO with a space for the Spectrum and without (GOTO) for the Dragon.
INK
INK n
Result: Sets permanent foreground colour. When n=0 to 7 a colour is selected. When n=8 transparency is selected. When n=9 contrast is selected.
keyword INK n;
Result: Sets temporary foreground colour. When n=0 to 7 a colour is selected. When n=8 transparency is selected. When n=9 contrast is selected.
keyword may be one of PRINT, LPRINT, INPUT, PLOT, DRAW or CIRCLE statements. When INK is applied to the keyword LPRINT there will be no effect on characters printed on the ZX Printer.
The Dragon has different ways of displaying colours. On the text screen (text mode) letters, numbers and symbols are always displayed with a green background and a dark green foreground. Semi-graphics (block graphics) may be displayed with other colours. Hi-res statements have a parameter to change the foreground colour.
Result: Computer waits for input of an expression then passes the value of this to the variable v.
The 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.
On the Dragon and TRS-80 multiple data may be entered in one input line, for instance INPUT A,B may be input as 1,2 or INPUT A$,B$ may be input as "ABC","DEF" (note the double quotes).
LINE INPUT on the Dragon is different to INPUT LINE of the Spectrum. Using the previous example LINE INPUT A$ will allow quotes and commas to be entered as if part of the string.
MID$
(Statement)
MID$(α$,position[,length])=β$
Result (Dragon 32/64* & TRS-80 CoCo).: Replaces part of α$ from the point in the string position with β$.
length is optional, if omitted whole length of β will substitute part of α$.
*Not in the Dragon manual but is emulated on XRoar so would possibly work on a real Dragon.
On the Spectrum MID$ can be emulated with the TO string slicing facility.
See also MID$ (Function), TO.
INVERSE
INVERSE n
Result: Turns permanent inverse video effect on when n=1 or off when n=0.
keywordINVERSE n
Result: Turns temporary inverse video effect on when n=1 or off when n=0.
keyword may be one of PRINT, LPRINT, INPUT, PLOT, DRAW or CIRCLE statements.
The INVERSE statement is not implemented on the Dragon although inverse characters are available in the Dragon character set.
LET (ZX Spectrum)
[LET] (Dragon 32/64 & TRS-80 CoCo)
LET v=e (ZX Spectrum)
[LET] v=e (Dragon 32/64 & TRS-80 CoCo)
Result: Assign the value e to the variable v.
LET is optional on the Dragon, i.e. :
α$="some text"
LINE
(Dragon 32/64 & TRS-80 CoCo)
LINE[(x1,y1)]-(x2,y2),PSET¦PRESET[,B¦BF]
Result (Dragon 32/64 & TRS-80 CoCo): Draws a line from (x1,y1) to (x2,y2).
(x1,y1) are the co-ordinates of the line's start point.
If (x1,y1) is ommited the last end point or (128,96) is used.
(x2,y2) are the co-ordinates of the line's end point.
If PSET is used the line is drawn in the current foreground colour. If PRESET, the line is drawn in the background colour.
The use of B or BF is option. If B is used, a rectangle is drawn instead of a line, the upper corner of the rectangle will be (x1,y1), and the lower right corner (x2,y2). If BF is used, the rectangle is drawn and filled with the current foreground colour.
Not on the Spectrum. Use PLOT and DRAW instead.
LPRINT
LPRINT ...
Result: Send a line of items to be printed to the ZX Printer.
Only on the Spectrum. For the Dragon use:
PRINT #2, ...
instead.
OPEN #
(ZX Spectrum)
OPEN
(Dragon 32/64 & TRS-80 CoCo)
OPEN #m;f1[;n]¦[;n;f2] (ZX Spectrum)
Result: Open a stream m attached to channel f1 with device number n. Microdrives require a filename f2 (ZX Spectrum)
OPEN m,n,f (Dragon 32/64 & TRS-80 CoCo)
Result: Opens specified file (f) for data transmission (m) to specified device (m may be I (Input) or O (Output). n may be #0 (screen or keyboard), #-1 (cassette), or #-2 (printer). (Dragon 32/64 & TRS-80 CoCo)
On the Spectrum the hash symbol after OPEN is not a single character but part of the OPEN # keyword.
OUT
OUT m,n
Result: Outputs byte n to port m.
Not on the Dragon as the 6809 processor is memory mapped for I/O devices.
OVER
OVER n
Result: If n=0 then permanent overprinting is turned off. If n=1 permanent overprinting is tunred on.
keyword OVER n
Result: If n=0 then temporary overprinting is turned off. If n=1 temporary overprinting is tunred on.
keyword may be one of PRINT, LPRINT, INPUT, PLOT, DRAW or CIRCLE statements. No effect when applied to LPRINT.
Not on the Dragon. 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).
PAINT
PAINT(x,y),m,n
Result (Dragon 32/64 & TRS-80 CoCo).: Fills an area of the high-resolution screen starting at point (x,y) with specified color m and stopping at border of color n.
Not on the Spectrum. A short BASIC or machine code subroutine can be used to fill an area of the screen with pixels (colour must be added seperately as individual pixels cannot be coloured in on the Spectrum).
PAPER
PAPER n
Result: Sets permanent background colour. When n=0 to 7 a colour is selected. When n=8 transparency is selected. When n=9 contrast is selected.
keyword PAPER n;
Result: Sets temporary background colour. When n=0 to 7 a colour is selected. When n=8 transparency is selected. When n=9 contrast is selected.
keyword may be one of PRINT, LPRINT, INPUT, PLOT, DRAW or CIRCLE statements. When PAPER is applied to the keyword LPRINT there will be no effect on characters printed on the ZX Printer.
The Dragon has different ways of displaying background colour. On the text screen (text mode) letters, numbers and symbols are always displayed with a green background and a dark green foreground. Hi-res statements have a parameter to change the background colour.
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. The Dragon has no PAUSE statement. The easiest solution would be to use an empty FOR...NEXT loop.
PLAY
PLAY f (Dragon 32/64 & TRS-80 CoCo)
Result: Play a series of musical notes according to octave, volume and tempo data stored in the string f.
PLAY f1[,f2[,f3]] (All ZX Spectrum+ 128k models)
Result: Play a series of musical notes according to octave, volume and tempo data stored in the string f1. All three sound channels (f1,f2,f3) may be played at once.
The Dragon and TRS-80 CoCo can only play one sound channel whereas the ZX Spectrum+ 128k models can play up to three channels at once.
Not on the 16k/48k ZX Spectrum. Melodies may be acheived using BEEP.
See also BEEP, SOUND.
PLOT
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.
For the equivalent Dragon statements see PSET and PRESET.
POKE
POKE m,n
Result: Load byte n into memory address m.
Same result all round.
PRINT
(ZX Spectrum and Dragon 32/64 & TRS-80 CoCo)
? Question Mark
(Dragon 32/64 & TRS-80 CoCo)
PRINT ... (ZX Spectrum and Dragon 32/64 & TRS-80 CoCo)
? ... (Dragon 32/64 & TRS-80 CoCo)
Result: Send a series of items to the display subject to control characters and AT/@/TAB (and TAB/INK/PAPER/INVERSE/FLASH/OVER on the ZX Spectrum).
Similar on both micros with exceptions. On the Dragon and TRS-80 CoCo PRINT may be abbreviated with a question mark '?' e.g.
? "HELLO WORLD"
PRESET
PRESET (x,y) (Dragon 32/64 & TRS-80 CoCo)
Result: Resets (turns off) a pixel at the horizontal (x) and vertical (y) coordinates, on the high resolution screen.
On the ZX Spectrum use:
PLOT INVERSE 1;x,y
PSET
PSET (x,y,c) (Dragon 32/64 & TRS-80 CoCo)
Result: Sets (turns on) a pixel at the horizontal (x) and vertical (y) coordinates, on the high resolution screen with colour c.
On the ZX Spectrum use:
PLOT [INK c;]x,y
bearing in mind that the INK colour c will be different on the Spectrum.
RANDOMIZE
RANDOMIZE (ZX Spectrum)
RANDOMIZE n (ZX Spectrum)
Result: Sets system variable SEED to n which will be the basis for pseudo-random numbers (RND).
Not on the Dragon.
ZX Spectrum keyboard shows shortened RAND and not RANDOMIZE.
READ
READ e1,e2,e3, ...
Result: Read from DATA statement and pass to a variable or variables e1,e2,e3, ..
Similar on both micros with exceptions.
REM
(Dragon 32/64 & TRS-80 CoCo & ZX Spectrum)
' Single Quote
(Dragon 32/64 & TRS-80 CoCo)
REM ... (Dragon 32/64 & TRS-80 CoCo & ZX Spectrum)
' ... (Dragon 32/64 & TRS-80 CoCo)
Result: None, display comment in program listing.
Same result all round. On the Dragon a single quote can also be used in place of REM.
RESET
RESET (x,y) (Dragon 32/64 & TRS-80 CoCo)
Result: Resets (turns off) a graphic square at the horizontal (x) and vertical (y) coordinates, on the text screen.
On the ZX Spectrum block graphics could be used instead. Print a black square at x,y would have the same effect.
Result: Formats item-list. format is a string expression indicating to the computer how to format item-list.
Not on the Spectrum, but a subroutine could simulate PRINT USING
Compound Statements
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 result all round.
Although the NEXT statement is not compounded within the FOR statement as TO and STEP are, it is included here for completeness.
IF..THEN
(Dragon 32/64 & TRS-80 CoCo & ZX Spectrum)
IF..THEN..ELSE
(Dragon 32/64 & TRS-80 CoCo)
IF x THEN s (Dragon 32/64 & TRS-80 CoCo & ZX Spectrum)
Result: If x is true (non-zero) then s will be executed.
IF x THENline number (Dragon 32/64 & TRS-80 CoCo)
Result: If x is true (non-zero) then continue program execution from line number.
IF x THEN s1ELSE s2 (Dragon 32/64 & TRS-80 CoCo)
Result: If x is true (non-zero) then s1 will be executed, otherwise s2 will be executed..
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.
The ZX Spectrum can simulate ON..GOTO/GOSUB with
GO TO (m1AND x=1)+(m2AND x=2)+ (mkAND x=k)
Functions
Keyword
Meaning
Comments
ABS
ABS x (ZX Spectrum)
ABS (x) (Dragon 32/64 & TRS-80 CoCo)
Returns: Absolute magnitude of x, i.e. distance on number line from zero, -1=1 -2=2
Same result all round.
ACS
ACS x
Returns: Arccosine (inverse cosine) of x in radians.
Not on the Dragon. Substitute with a definable function:
DEF FN C(X)=ATN(SQR(1-X*X)/X)
And call with:
FN C(X)
ASC
See CODE
ASN
ASN x
Returns: Arcsine (inverse sine) of x in radians.
Not on the Dragon. Substitute with a definable function:
DEF FN S(X)=ATN(x/SQR(1-X*X))
And call with:
FN S(X)
ATN
ATN x (ZX Spectrum)
ATN (x) (Dragon 32/64 & TRS-80 CoCo)
Returns: Arctangent (inverse tangent) of x in radians.
Same result all round.
ATTR
ATTR (x,y)
Returns: numeric value between 0 and 255 of the attribute at position x,y.
Not on the Dragon. See POINT (Dragon 32/64 & TRS-80 CoCo) and PPOINT function which perform a similar task to the Spectrum's ATTR and POINT functions.
BIN
BIN b
Returns: decimal value of a base2 (binary) 16 bit number.
Only on Spectrum. Not strictly a function but a numerical notation.
A short subroutine could easily be coded to simulate this function on the Dragon.
See also HEX$ function.
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 may be different. Both micros use a character set based on ASCII but the Dragon does not have lower case letters and control codes will be different.
CODE (ZX Spectrum)
ASC (Dragon 32/64 & TRS-80 CoCo)
CODE α$ (ZX Spectrum)
ASC (α$) (Dragon 32/64 & TRS-80 CoCo)
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 / ASC function performs the same task on both computers, just like CHR$ above, the end result may be different.
COS
COS x (ZX Spectrum)
COS (x) (Dragon 32/64 & TRS-80 CoCo)
Returns: Cosine of x in radians.
Same result all round.
EOF
EOF (device)
Returns: zero if there is more data or -1 if the end of file has been read. (Dragon 32/64 & TRS-80 CoCo).
Not on the Spectrum or ZX Interface 1. ZX Interface 1 has its own way to read end of file.
EXP
EXP x (ZX Spectrum)
EXP (x) (Dragon 32/64 & TRS-80 CoCo)
Returns: Numeric value for the function ex where e=2.7182818...
Same result all round.
FIX
FIX (x)
Returns: An integer from the truncation of the decimal fraction part of x. (Dragon 32/64 & TRS-80 CoCo).
Not on the Spectrum. Can be emulated with a definable function:
DEF FN f(x)=INT (ABS x)/SGN x
See also INT
FN
FN α(α1, αk)
Result: Calls a function. α and α1 to αk can be a single letter or for the ZX Spectrum only, a single letter followed by $ for a string argument.
A definable function on the ZX Spectrum may be numeric or string.
The Dragon may have two letters to identify the function (actually more than two letters may be used but only the first two will be used to identify the function).
See also DEF FN.
HEX$
HEX$ (m)
Returns: A string consisting of the hexadecimal (base16) representation of the decimal number m. (Dragon 32/64 & TRS-80 CoCo).
Not on the Spectrum. A definable function could be used to perform the same task.
INKEY$
INKEY$
INKEY$ requires 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 all round.
IN
IN m
Returns: numeric value between 0 and 255 for the port m.
Not on the Dragon as the 6809 processor is memory mapped for I/O devices.
INSTR
INSTR (position,α$,β$)
Returns: The position for the first occurrence of β$ in α$ beginning at position. Returns zero if no match is found. (Dragon 32/64 & TRS-80 CoCo).
Not on the Spectrum. A short subroutine can be written to perform the same task.
INT
INT x (ZX Spectrum)
INT (x) (Dragon 32/64 & TRS-80 CoCo)
Returns: x rounded down to the nearest integer.
Mostly the same result on each micro with the exception that occurs on the ZX Spectrum when INT -65536 is performed (the wrong result is given as -1).
JOYSTK
JOYSTK (m)
Result: Returns the horizontal or vertical coordinate (m) of the left or right joystick (Dragon 32/64 & TRS-80 CoCo):
0 = horizontal. left joystick
1 = vertical, left joystick
2 = horizontal. right joystick
3 = vertical, right joystick
On the ZX Spectrum joystick positions are usually found with IN m, where m is the I/O address of the joystick.
LEFT$
LEFT$(α$,m)
Result (Dragon 32/64 & TRS-80 CoCo).: Returns first m characters of α$.
On the Spectrum LEFT$ can be emulated with the TO string slicing facility:
β$=α$( TO m)
See also MID$ (Function), RIGHT$, TO.
LEN
LEN α$ (ZX Spectrum)
LEN (α$) (Dragon 32/64 & TRS-80 CoCo)
Returns: numeric value for the length of α$.
Same result all round.
LN
(ZX Spectrum)
LOG
((Dragon 32/64 & TRS-80 CoCo)
LN x (ZX Spectrum)
LOG (x) (Dragon 32/64 & TRS-80 CoCo)
Returns: numeric value for the natural logarithm of x.
Same result all round.
LOG
See LN
MEM
MEM
MEM requires no operands.
Result (Dragon 32/64 & TRS-80 CoCo).: Returns amount of free memory available.
On the ZX Spectrum free space can be found by :
PRINT (PEEK 23730+256*PEEK 23731) -USR 7962
MID$
(Function)
MID$(α$,m[,n])
Result (Dragon 32/64 & TRS-80 CoCo).: Returns the n characters of α$, starting at position m. If n is omitted the entire string to the right of m is returned. m must be greater than zero.
On the Spectrum MID$ can be emulated with the TO string slicing facility:
β$=α$(m TO m+n-1)
See also LEFT$, MID$ (Statement), RIGHT$, TO.
PEEK
PEEK m
Returns: numeric value (0 to 255) stored at memory location m.
Same result all round.
PI
PI
PI requires no operands.
Returns: 3.1415927 (π) Ratio of circumference of a circle to its diameter
Typical usage might be:
LET R=C/(2*PI)
Not on the Dragon or TRS-80
Define a function instead to represent π.
DEF FN PI(X)=3.14159265359
(X is a dummy variable)
or as a variable
PI=3.14159265359
[Note] π is stored on the Spectrum as 10 digits but will only display 8 digits.
POINT
(Dragon 32/64 & TRS-80 CoCo & ZX Spectrum)
PPOINT
(Dragon 32/64 & TRS-80 CoCo)
POINT (x,y)
Returns: -1 for a text character or 0 to 8 for the colour of the character square x,y. (Dragon 32/64 & TRS-80 CoCo TEXT MODE)
POINT (x,y)
Returns: 1 if pixel is on or 0 if it is off for the pixel location x,y. (ZX Spectrum)
PPOINT (x,y)
Returns: 0 if pixel is off or colour code of pixel at x,y (Dragon 32/64 & TRS-80 CoCo HI-RES)
Since the ZX Spectrum stores pixels in its memory seperate from the colour attributes POINT will only return whether a pixel is on or off. To acheive a similar result to the Dragon/TRS-80 ATTR and SCREEN$ could be used instead or as well as POINT.
See also ATTR, SCREEN$
POS
POS (device)
Result (Dragon 32/64 & TRS-80 CoCo).: Returns current print position for selected device.
device can either be 0 for output to the screen or -2 for output to the printer.
The ZX Spectrum's returns screen positions on two axes.
For the current row position use:
24-PEEK 23689
For the current column position:
33-PEEK 23688
For the current ZX Printer column position use:
PEEK 23680-(PEEK 23680)<32
RIGHT$
RIGHT$(α$,m)
Result (Dragon 32/64 & TRS-80 CoCo).: Returns last m characters of α$.
On the Spectrum RIGHT$ can be emulated with the TO string slicing facility:
β$=α$(LEN α$-m+1 TO )
See also LEFT$, MID$ (Function), TO.
RND
RND (ZX Spectrum)
Returns (ZX Spectrum):
A pseudo-random number between 0 and 1 is generated.
RND(x) (Dragon 32/64 & TRS-80 CoCo)
Returns (Dragon 32/64 & TRS-80 CoCo) :
If x=0 then a pseudo-random number between 0 and 1 is generated
if x≥1 then a pseudo-random integer between zero and x is generated.
An example of usage would be
LET X=INT(RND*42)+1 (ZX Spectrum)
LET X=RND(42) (Dragon 32/64 & TRS-80 CoCo)
To the simulate Dragon & TRS-80's RND (x), if x>0, the following function should suffice:
DEF FN r(x)=INT(RND*x)+1
SCREEN$
SCREEN$ (x,y)
Returns: character displayed at location x,y.
Not on the Dragon 32/64 or TRS-80 CoCo.
SGN
SGN x (ZX Spectrum)
SGN (x) (Dragon 32/64 & TRS-80 CoCo)
Returns: signum (or sign) of x, for instance -1 if x<0, 0 if x=0 or 1 if x>1.
On the Dragon & TRS-80 brackets are obligatory.
SIN
SIN x (ZX Spectrum)
SIN (x) (Dragon 32/64 & TRS-80 CoCo)
Returns: Sine of x in radians.
Same result all round.
SQR
SQR x (ZX Spectrum)
SQR (x) (Dragon 32/64 & TRS-80 CoCo)
Returns: square root of x.
On the Dragon and TRS-80, if x is negative then the square root of ABS(x) will be returned. If x is negative on the Spectrum an error will occur. To give the same result as the Dragon/TRS use:
SQR ABS x
STR$
STR$ x (ZX Spectrum)
STR$ (x) (Dragon 32/64 & TRS-80 CoCo)
Result: string comprising of the numeric value of x.
Same result all round.
STRING$
STRING$(m,a[$])
Result (Dragon 32/64 & TRS-80 CoCo).: Returns a string of a[$] characters of length m.
a[$] may be the ASCII code (a) or the actual character (a$).
Not on the Spectrum.
A short subroutine could be written to simulate STRING$
TAN
TAN x (ZX Spectrum)
TAN (x) (Dragon 32/64 & TRS-80 CoCo)
Returns: Tangent of x in radians.
Same result all round.
TIMER
TIMER (no operands).
Result (Dragon 32/64 & TRS-80 CoCo).: Returns amount of time (1/50secs UK or 1/60secs North America) since computer was switched on or counter was set to zero.
To set the timer to zero or another time type:
TIMER=n
Where n is a number between 0 and 65535.
On the ZX Spectrum use :
65636*PEEK 23674+256*PEEK 23673+PEEK 23672
To reset clock use:
POKE 23674,0 : POKE 23673,0 : POKE 23672,0
USR
USR m (ZX Spectrum)
Returns: contents of the bc register pair after calling machine code at memory location m.
v=USRm (Dragon 32/64 & TRS-80 CoCo)
Result: calls the machine language subroutine m defined by DEFUSR.
The ZX Spectrum will return the value of the bc register pair (Z80). On Dragon and TRS-80 v is a dummy variable.
[Note] For comparison only. Z80 and 6809 machine language subroutines are totally incompatible with each other and must be completely rewritten to accomodate the machine the code is being ported to.
See also EXEC and DEFUSR.
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 Dragon/TRS-80 CoCo has no UDG's this function is not available on those micros.
VAL
VAL α$ (ZX Spectrum)
VAL (α$) (Dragon 32/64 & TRS-80 CoCo)
Returns: numeric value evaluated from the string α$.
The Dragon and TRS-80 machines will only evaluate numbers anything else will return a zero. The ZX Spectrum will evaluate numbers, mathematical operators, logical operators and variables.
VAL$
VAL$ α$
Returns: string evaluated from the string α$.
There does not appear to be a simple way to simulate this function in Microsoft Basic.
VARPTR
VARPTR(v)
Result (Dragon 32/64 & TRS-80 CoCo).: Returns address of pointer to the specified variable (v).
Not on the Spectrum, however the address of the variables area can be found with the system variable VARS which is located at 23627 and 23628.
Operators
Keyword
Meaning
Comments
-
Unary Minus/Negation
-x
Result: negates x
Same result all round.
-
Binary Minus/Subtraction
x-y
Result: a numeric value resulting from y being subtracted from x.
Same result all round.
+
Addition
x+y
Result: a numeric value resulting from y being added to x.
Same result all round.
+
String concatenation
α$+β$
Result: concatenates (joins together) string α with string β to form a new string.
Same result all round.
/
Division
x/y
Result: a numeric value resulting from x being divided by y.
Same result all round.
*
Multiplication
x*y
Result: a numeric value resulting from x being multiplied by y.
Same result all round.
Note: On the Dragon & TRS-80 CoCo keyboards the symbol for multiplication is * (asterisk) but is displayed on screen as ◆ (solid diamond). For clarity the asterisk is used on this page.
↑
Raise to the power of
x↑y (Dragon 32/64 & TRS-80 and ZX Spectrum)
Result: a numeric value resulting from x being raised to the power of y.
On the Dragon and TRS-80 machines, to give the correct result when x is negative the equation -x↑y requires that the base (the -x part) is enclosed in brackets.
i.e. (-x)↑y
This technique will not work on the ZX Spectrum. If the base number (x) is negative it will produce an 'Invalid Argument' error. A function can be defined to get round this :
DEF FN e(x,y)=(SGN x*(y/2<> INT (y/2)+(y/2=INT (y/2)))*ABS x↑y
<
Less than
x<y
Where x and y can be either numeric or strings but cannot be mixed.
Where x is a number or a string, and y is always numeric. (ZX Spectrum)
Where x and y are both numeric. (Dragon 32/64 & TRS-80 CoCo)
Returns (ZX Spectrum): x if y is true (non-zero) or 0 if y is false (zero).
Result (Dragon 32/64 & TRS-80 CoCo): A bitwise calculation of x and y. Bits in x and y are compared. If bits in both x and y are 1 then the resulting bit after performing a bitwise AND will be 1 otherwise it will be 0.
A similar result may occur on both the Spectrum and the Dragon/TRS-80. See note 2.
To convert the ZX Spectrum's 'Boolean AND' use the following code on the Dragon 32/64 or TRS-80 CoCo:
SGN (x AND y)
OR
x OR y
Where x and y are both numeric.
Returns (ZX Spectrum): 1 if x or y≠0, value of x if y=0.
Result (Dragon 32/64 & TRS-80 CoCo): A bitwise calculation of x and y. Bits in x and y are compared. If bits in either x or y are 1 then the resulting bit after performing a bitwise OR will be 1 otherwise it will be 0.
A similar result may occur on both the Spectrum and the Dragon/TRS-80. See note 2.
To convert the ZX Spectrum's 'Boolean OR' use the following code on the Dragon 32/64 or TRS-80 CoCo:
Z=SGN (x OR y)
IF Z AND ABS(Z)>y THEN Z=x
NOT
NOT x
Where x is numeric.
Returns (ZX Spectrum): zero if x≠0, 1 if x=0.
Result (Dragon 32/64 & TRS-80 CoCo): A bitwise reversal of x. Bits in x are reversed; 0 becomes 1, 1 becomes 0.
A similar result may occur on both the Spectrum and the Dragon/TRS-80.
In the event of a problem converting from one machine to the other the following code may help:
To convert the ZX Spectrum's 'Boolean NOT' use the following code on the Dragon 32/64 or TRS-80 CoCo:
x=ABS(x=0)
To convert from Dragon/TRS-80 to the Spectrum use this code:
LET x=-x-1
Delimiters
Keyword
Meaning
Comments
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).
Not on the Dragon/TRS-80. For the equivalent string slicing statements see LEFT$, MID$ and RIGHT$.
Result: separates items within a PRINT, LPRINT (ZX Spectrum only) or INPUT statement.
message is text within double quotes. v is a numeric or string variable.
Dragon and TRS-80 CoCo models also use a semi-colon within the DRAW and PLAY macros.
'
Apostrophe
PRINT ' (ZX Spectrum, Dragon 32/64 & TRS-80 CoCo)
LPRINT ' (ZX Spectrum only)
INPUT ' (ZX Spectrum only)
Result: Moves the PRINT (or LPRINT) position down a line.
The Dragon 32/65 & TRS-80 CoCo cannot use an apostrophe as a delimiter in an INPUT statement.
,
Comma
as a PRINT item
PRINT , (ZX Spectrum, Dragon 32/64 & TRS-80 CoCo)
LPRINT , (ZX Spectrum only)
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.
*Dragon 32/64 & TRS-80 CoCo may only use a comma within an INPUT statement to seperate operands.
ZX Spectrum INPUT comma works, just like the PRINT comma, by moving the PRINT position 15 characters along.
Result: Encloses text within a string or within a PRINT, INPUT or LPRINT statement (LPRINT is on ZX Spectrum only).
ZX Spectrum can store a single quote within a set of quotation marks like so
""some text""
produces the output:
"some text"
For the same result on the Dragon and TRS micros use the character code CHR$(34), for instance:
PRINT CHR$(34);"some text";CHR$(34)
or for a string variable
α$=CHR$(34)+"some text"+CHR$(34)
Nomenclature
This list uses the same letters to represent variables, expressions and sequences etc. as the ZX Spectrum BASIC manual.
α,β 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 colour item has the form of a PAPER, INK, FLASH, BRIGHT, INVERSE or OVER statement.
References
Sinclair ZX Spectrum BASIC Programming, Steven Vickers (author), Robin Bradbeer (editor)
An introduction to BASIC programming on the Dragon, Richard Wadman (author)
Getting Started with Extended Color BASIC, Radio Shack/Tandy Corporation (publisher)
Notes
[1] Due to the way the Dragon/TRS-80 machines make logical comparisons they will always return -1 if true whereas the Spectrum will return +1. This should not be a problem when converting code between machines but should a problem be encountered use ABS result on the Spectrum to negate the positive result or -result on the Dragon/TRS-80 to negate the -1 and make it positve.
[2] Whether the result is correct or not will depend on the context of the program. If the flow of the program only requires boolean logic then converting programs between machines should not cause many problems. However, if a logical 'bitwise' result is required then this is not possible with standard Sinclair BASIC and machine code should be used to return the desired result.