Reference

Contents

  1. Literals
    1. Numeric Literals
    2. String Literals
  2. Operators
    1. Special Operators
      1. Selectors
      2. User Defined Functions
      3. Multi-argument Functions
      4. Suffix Operators
    2. Shifts
    3. Unary Functions
    4. Arithmetic Operators
    5. Relations
    6. Logical and Bitwise Operators
  3. Instructions

Literals

Numeric Literals

Decimal

Consist of digits 0123456789, at most one point . separating the integral part from the fractional part. Optionally followed by an order of decimal magnitude separated by e or E and a signed integer.

Examples: 1, 12.5, .75, 6.02214076e23, 6.62607004e-34

Binary

Begin with the BIN keyword, followed by digits 01. An optional point . separates the integral part from the fractional part.

Examples: BIN 1000, BIN 10.1, BIN .1010101010101

Hexadecimal

Begin with the HEX keyword, followed by digits 0123456789ABCDEF (lower case abcdef also allowed). An optional point . separates the integral part from the fractional part.

Examples: HEX 5CB0, HEX 1FFFF.8, HEX .AAAAAAAB

Octal

Begin with the OCT keyword, followed by digits 01234567. An optional point . separates the integral part from the fractional part.

Examples: OCT 7500, OCT 55.2, OCT .5252525253

String Literals

Quoted Strings

Characters in quotes (") are interpreted as string literals. The quote character itself can be escaped by doubling ("").

Syntax Checked Expressions

Expressions between curly braces { and } are not evaluated, but their syntax is checked upon entering. They are interpreted as strings that can be passed to VAL or VAL$ for actual evaluation.

Operators

Operators are grouped by priority, groups are listed in order of precedence.

Special Operators

Selectors

a$ ?( e0 , e1 )
If a$ is empty, e0 is evaluated, otherwise e1 is. Note that e0 and e1 can be either numeric or string expressions, but they must have the same type. This is going to be the type of the selector expression.
n ?( e0 , e1 ,)
The value of n selects the expression in the comma-separated list to be evaluated, beginning with zero (the first expression evaluates if n = 0). If the value of n is greater or equal to the number of expressions in the list, then the last expression in the list is evaluated. The selectable expressions can be either numeric or string expressions, but they must have the same type. This is going to be the type of the selector expression.

User Defined Functions

FN f ( e ,)
Numeric function with an arbitrary number of arguments, denoted by a single letter f after the FN keyword.
FN f$( e ,)
String function with an arbitrary number of arguments, denoted by a single letter f with a dollar sign $ after the FN keyword.

Multi-argument Functions

ATTR ( row , column )
...
POINT ( x , y )
...
SCREEN$ ( row , column )
...
STICK ( n , m )
Reads direction (odd values of n) or button (even values of n) of controller device (typically joystick) m. Set m = 0 for Kempston joystick, m = 1 for Sinclair joystick 1, m = 2 for Sinclair joystick 2, m = 3 for Cursor joystick. For the button, values 1 or 0 are returned, whether or not the button is pressed, respectively. For the direction, use the table below:
519
408
6210
STICK ( n , a$ )
Reads the keyboard for control with user defined keys. Argument n and the return values are compatible with the game controller version, the user defined keys are read from a$ as follows: the button is the last character of a$, the four directions are the first four characters in right, left, down, up order. Also note that STICK (0, k$ ) can be used to check whether key k$ is pressed or not independently of other keys on the keyboard. Use CHR$ 13 for ENTER, CHR$ 14 for SYM, and CHR$ 227 for SYM, respectively.
STR$ ( x , n , m )
Converts numeric value x to base n string representation (2 ≤ n ≤ 36), with m fractional digits after the point. If m = 0, no point . is included in the result.
STR$ ( x , n )
Equivalent to STR$ ( x , n ,0).

Suffix Operators

a!
Changes every integral bit in the two's complement signed representation of a to its opposite, leaving fractional bits intact. Thus, 0!=-1. This operator can be used to convert NOT a operators from other BASIC dialects that only use bitwise logical operators, such as ZX80.
a$!
Changes every bit in the binary representation string a$ to its opposite.

Shifts

Priority 16

a << n
Bitwise arithmetic shift of number a to the left by n bits. Equivalent to a*2^INT (n+.5).
a >> n
Bitwise arithmetic shift of number a to the right by n bits. Equivalent to a<<-n.
a$ << n
Cyclic bitwise shift of the binary representation of string a$ to the left by n digits. Cycling shifting of a$ to the left by k characters can be accomplished by a$ <<( k *8) or, even faster, by a$ <<( k <<3)
a$ >> n
Cyclic bitwise shift of the binary representation of string a$ to the left by n digits. Equivalent to a$<<-n.

Unary Functions

Priority 16

ABS x
Absolute value of x. Equivalent to x*SGN x
ACS x
Arc cosine of x. Inverse function of COS x.
ASN
Arc sine of x. Inverse function of SIN x.
ATN
Arc tangent of x. Inverse function of TAN x.
CHR$ n
Character at code point n, if n < 256. Otherwise equivalent to CHR$ ( n %256)+CHR$ INT ( n /256). Inverse function of CODE a$.
CODE a$
If a$ is empty, returns zero. If a$ consists of a single character, returns its code point. Otherwise equivalent to CODE a$(1)+256*CODE a$(2 TO). Inverse function of CHR$ n.
COS
Cosine of x. Inverse function of ACS x.
DPEEK n
Returns 16 bit value at memory address n, least siginificant byte first. Equivalent to CODE MEM$( n TO n +1) for 1 ≤ n ≤ 65534.
EXP x
Exponential of x. Equivalent to 2.718281829^ x. Inverse function of LN x.
FPEEK n
Returns the 5-byte (40-bit) value at memory address n.
IN n
Read I/O port n.
INT x
Returns the largest integer that is not greater than x. In other words, rounding x towards negative infinity.
LEN a$
Number of characters in a$. In other words, the length of a$
LN x
Natural logarithm of x. Inverse function of EXP x.
PEEK n
Returns 8 bit value at memory address n. Equivalent to CODE MEM$( n ) for 1 ≤ n ≤ 65535.
SGN x
Returns the sign of x. Equivalent to ( x >0)-( x <0).
SIN x
Sine of x. Inverse function of ASN x.
SQ x
Square of x. Equivalent to x*x. Inverse function of SQR x.
SQR x
Square root of x. Equivalent to x^.5. Inverse function of SQ x.
STR$ x
Turns number x into a string in the decimal literal format. For x > 99999999, exponential notation is used. Note that the STR$ keyword can also be used as a multi-argument function for number formatting.
TAN x
Tangent of x. Inverse function of ATN x.
TIME$ n
Turns a frame counter into a string in hh:mm:ss.ss format.
USR n
Calls machine code at memory address n and returns the value of BC register pair. Discarding the first return address, the topmost element in the calculator stack is returned as a number.
USR a$
Returns the address of the user-defined graphics character (UDG) supplied in a$. By supplying the UDG itself as a$, the address of all 112 possible UDG bitmaps can be accessed. For backwards compatibility, USR also accepts letters, in which case, irrespectively of whether they are capital or lower-case, only the first 26 UDG bitmap addresses can be returned.
VAL a$
Evaluates numeric expression in a$.
VAL$
Evaluates string expression in a$.

Arithmetic Operators

Priority 10

a ^ b
Taking a to the power of b. Requires a ≥ 0 for non-integer b values. By definition, 0^0=1.

Priority 9

-x
Negative value of x. Unary operator, but binding less tightly than other unary operators.

Priority 8

a * b
Product of a and b.
a$ * b
Repeat a$ b times. Negative values of b imply reversing the order of characters in a$. Examples: "abcd"*1.5="abcdab", "abcd"*-2="dcbadcba".
a / b
Division of a by b.
a % b
Remainder after division of a by b. Equivalent to a - b *INT ( a / b )

Priority 6

a + b
Sum of a and b.
a$ + b$
Concatenation of a$ and b$.
a - b
Difference of a and b.

Relations

Priority 5

a = b
True if and only if a equals b.
a$ = b$
True if and only if a$ equals b$.
a <> b
True if and only if a does not equal b.
a$ <> b$
True if and only if a$ does not equal b$.
a < b
True if and only if a is strictly less than b.
a$ < b$
True if and only if a$ precedes b$ in lexicographic order.
a > b
True if and only if a is strictly greater than b.
a$ > b$
True if and only if a$ succeeds b$ in lexicographic order.
a <= b
True if and only if a is less than b or equal.
a$ <= b$
True if and only if a$ precedes or equals b$ in lexicographic order.
a >= b
True if and only if a is greater than b or equal.
a$ >= b$
True if and only if a$ succeeds or equals b$ in lexicographic order.

Logical and Bitwise Operators

Priority 4

NOT x
Logical negation of x. If x=0, returns 1, otherwise 0. Equivalent to x=0.

Priority 3

a AND b
Returns 0 if b = 0, otherwise a.
a$ AND b
Returns empty string if b = 0, otherwise a$.
a & b
Returns bitwise a and b.
a$ & b$
Returns bitwise a$ and b$.

Priority 2

a OR b
Returns a if b = 0, otherwise 1.
a | b
Returns bitwise a or b.
a$ | b$
Returns bitwise a$ or b$.
a >< b
Returns bitwise exclusive a or b.
a$ >< b$
Returns bitwise excusive a$ or b$.

Instructions

AND condition
Evaluates numeric expression condition and stops, if it equals zero, reporting "V Assertion failed" If the expression does not equal zero, it has no effects beyond those of evaluating the expression. Useful for debugging, asserting invariant conditions to find out when they do not hold.
BEEP duration,pitch
...
BORDER color
...
BRIGHT attribute_bit
...
CAT
...
CIRCLE [#stream,] [attributes;] x_coordinate,y_coordinate,radius
...
CLEAR [RAMTOP_value]
...
CLOSE #stream_number
...
CLS
...
CONTINUE
...
COPY [#stream,]
...
DATA item[,...]
...
DEF FN name([argument[,...]])=expression
...
DELETE variable [, variable[,...]]
...
DELETE [line_number][ TO [line_number]]
...
DIM name(dimension[,...])
...
DRAW [#stream,] [attributes;] x_coordinate,y_coordinate[,arc]
...
ELSE [statement[:...]]
...
END IF
...
END PROC
...
END WHILE
...
ERASE
...
EXIT
...
FLASH attribute_bit
...
FOR name=start TO end [STEP step]
...
FORMAT
...
GO SUB destination
...
GO TO destination
...
IF condition [THEN statement[:...]]
...
INK color
...
INPUT [print_items] variable_reference [...]
...
INVERSE attribute_bit
...
@label [(item[,...])]
...
LET variable_reference[operator]=value
...
LIST [line_number][ TO [line_number]]
...
LLIST [line_number][ TO [line_number]]
...
LOAD
...
LOCAL variable_name [=initial_value][,...]
...
LPRINT print_items
...
MERGE
...
MOVE
...
NEW
...
NEXT [variable_name]
Execute the NEXT iteration of a FOR loop. Without arguments, it refers to the innermost loop and the loop variable (which is always local in ZX85 BASIC) is reclaimed after the loop has run its course. Otherwise, the loop variable is incremented past its target without jumping back to after the FOR statement.
ON ERROR
...
OPEN #stream_number,stream_definition
...
OUT port,value
...
OVER attribute_bit
...
PALETTE mode
...
PALETTE color;red,green,blue
...
PAPER color
...
PAUSE delay
...
PLAY music [, ...]
Concurrently play strings containing music definition in a domain-specific language (DSL). It can use PSG or MIDI as output device, as specified in the DSL.
PLOT [#stream,] [attributes;] x_coordinate,y_coordinate
...
POKE address,value [,value...]
...
POP
...
PRINT print_items
...
PROC name([argument [,...]])
...
RANDOMIZE [seed]
...
READ variable_reference [,...]
...
REM remark
...
RENUM
...
REPEAT
...
RESTORE source
...
RETURN [: tail_call]
...
RUN [destination]
...
SAVE
...
STACK [#stream]
Prints the contents of the stack to the main screen or the selected stream.
STEP [#stream,] font width
Sets font width for main screen or selected stream.
STOP [report text,] [report code] [,line nr.] [,statement nr.]
...
TRACE [print_items]
...
UNTIL condition
...
USR address
...
VERIFY
...
WHILE condition
...
YIELD [#stream]
Passes control to next coroutine or the one in selected stream's X channel.