BBC Command Reference

Variables

integer real string
example 346 9.847 "HELLO"
typical variables A% A A$
name SIZE% SIZE SIZE$
max size 2,147,483,647 1.7x1038 255 chars
accuracy 1 digit 9 sig figs -
stored in 32 bits 40 bits ASCII values

ADVAL - analogue to digital converter value

returns value from analogue input channel x=adval(-1) - number of characters in keyboard buffer
x=adval(-2) - number of characters in RS423 input buffer
x=adval(-3) - free spaces in RS423 output buffer
x=adval(-4) - free spaces in pritner output buffer
x=adval(-5) - free spaces on SOUND channel 0
x=adval(-6) - free spaces on SOUND channel 1
x=adval(-7) - free spaces on SOUND channel 2
x=adval(-8) - free spaces on SOUND channel 3
x=adval(-9) - free spaces in SPEECH buffer

AND

Logical or bitwise operation.

ASC

returns ASCII value of a character

ASN

arc-sine

ATN

arc-tan

AUTO

auto start, increment
generates line numbers from start incrementing by increment

CALL

executes machine code at specified address.

CHAIN

allows one program to load and run another program automatically. Clears all variables except @% and A% to Z%

CHR$(value)

Generates ASCII character related to number value

CLEAR

Clears all resident integer numeric variables.

CLOSE#

Closes a disc or tape file. CLOSE#0 closes all files, CLOSE#1 a specific file.

CLG

Clears graphics screen. Moves cursor to location 0,0

CLS

Clears the text screen. Moves cursor to 0,0

Colour

Selects background and foreground colours. Use COLOUR number to set foreground and background. E.g. COLOUR 2, COLOUR 129 sets the foreground to green and the background to red in MODE 2. The default colours may be altered by the VDU command.
Two colour modes (0,3,4,6)
foreground background default colour
0 128 black
1 129 white

Four colour modes (1,5)
foreground background default colour
0 128 black
1 129 red
2 130 yellow
3 131 white

Mode 2 - 16 colour mode
foreground background default colour
0 128 black
1 129 red
2 130 yellow
3 131 white
4 132 black
5 133 red
6 134 yellow
7 135 white
8 136 black
9 137 red
10 138 yellow
11 139 white
12 140 black
13 141 red
14 142 yellow
15 143 white

COS(number)

Returns cosine of angle number

COUNT

Counts the total number of characters printed (either to screen, RS423 or printer) since the last newline.

DATA

Comma separated list of data. e.g. DATA "test,test", text, 1234, 0181-123 4567

DEF

Used to define procedure or function. e.g. FUNCTION
100 DEF FNVAT(number)=1.175*number
110 a = FNVAT(100)

e.g. PROCEDURE
100 DEF PROCINIT(X)
110 REM clears screen
120 COLOUR 128+X
130 CLS
140 ENDPROC

DEG(radians)

Converts radians to degrees.

DELETE

Deletes a range of BASIC program lines. Cannot be used as part of a program.
e.g. DELETE 120, 150 deletes from line 120 to 150

DIM arrayname(rows,cols)

Dimension an array. Starts at element 0. Can also be used to reserve memory e.g. DIM X 33 would save 34 bytes. The start address is given by X
e.g. DIM test(10,30) or DIM name$(10,20)

DIV

Gives whole number part of a division of two numbers. E.g. A = X DIV Y

DRAW

Draws lines on the screen in MODEs 0, 1, 2, 4 and 5. The screen is address as X (0-1279) and Y (0-1023). Origin is a bottom left of screen (0,0). The arguments are DRAW x,y where x and y are the endpoints of the line.

END

Informs the program it has reached the end. Can be used as many times in a program as required but is optional.

ENDPROC

Used to end the procedure declaration of DEF PROC

ENVELOPE

USAGE: ENVELOPE N, T, PI1, PI2, PI3, PN1, PN2, PN3, AA, AD, AS, AR, ALA, ALD
parameter range function
N 1 to 4 envelope number
T bits 0-6 0 to 127 length of each step in hundredths of seconds
T bit 7 0 or 1 0 - auto repeat, 1 - don't autorepeat
PI1 -128 to 127 change of pitch per step in section 1
PI2 -128 to 127 change of pitch per step in section 2
PI3 -128 to 127 change of pitch per step in section 3
PN1 0 to 255 number of steps in section 1
PN2 0 to 255 number of steps in section 2
PN3 0 to 255 number of steps in section 3
AA -127 to 127 change of amplitude per step during attack phase
AD -127 to 127 change of amplitude per step during decay phase
AS -127 to 0 change of amplitude per step during sustain phase
AR -127 to 0 change of amplitude per step during release phase
ALA 0 to 126 target of level at end of attack phase
ALD 0 to 126 target of level at end of decay phase
Envelope diagram

EOF#(channel)

Returns -1 if end of file reached on channel. 0 if not.

EOR

Exclusive-OR
e.g. R = X EOR Y

ERL

Returns line number of the line where the last error occured.

ERR

Error number of last error.
examples.
10 wrong = ERR
100 IF ERR=17 THEN PRINT "YOU CAN'T ESCAPE"

EVAL

Evaluates a string as a mathematical expression.

EXT#(channel)

Returns the number of bytes allocated to a file on channel number. Only works on disc and network files.

FALSE

Boolean value equivalent to 0

FNname

Used with the DEF statement to define a function.
e.g. 1000 DEF FNmean(x,y) = (x+y)/2

FOR start TO end STEP increment

Standard FOR loop. Uses NEXT variable_name

GCOL mode,colour

0 plot the colour specified
1 OR specified colour with the one that is already there
2 AND specified colour with the one that is already there
3 XOR specified colour with the one that is already there
4 invert the colour already there

GET

Waits for keyboard input and returns the ASCII number of the key pressed

GET$

Waits for keyboard to be pressed and returns string containing result.

GOSUBlinenumber

Goes to a sub-routine

GOTOlinenumber

Goes to a line number.

HIMEM

Contains address of highest memory address.

IF condition THEN statement ELSE statement

e.g. IF x=12 THEN PRINT "okay" ELSE PRINT "not okay"

INKEY

Waits specified time whilst testing if a key has been pressed.
Can also test if a specific key has been pressed at that instant.
Use key = INKEY(10) to wait 10 centi-seconds for the keypress and puts ASCII value in variable key
Also, INKEY(-number) to test for a particular key. See following table for key codes
Key Number Key Number
f0 -33 1 -49
f1 -114 2 -50
f2 -115 3 -18
f3 -116 4 -19
f4 -21 5 -20
f5 -117 6 -53
f6 -118 7 -37
f7 -23 8 -22
f8 -119 9 -39
f9 -120 0 -40
A -66 0 -24
B -101 \ -25
C -83 \ -121
D -51 @ -72
E -35 [ -57
F -68 _ -41
G -84 ; -88
H -85 : -73
I -38 ] -89
J -70 ' -103
K -71 . -104
L -87 / -105
M -102 ESCAPE -113
N -86 TAB -97
O -55 CAPSLOCK -65
P -56 CTRL -2
Q -17 SHIFT LOCK -81
R -52 SHIFT -1
S -82 SPACEBAR -99
T -36 DELETE -90
U -54 COPY -106
V -100 RETURN -74
W -34 CRSR UP -58
X -67 CRSR DOWN -42
Y -69 CRSR LEFT -26
Z -98 CRSR RIGHT -122

INKEY$

Waits specified time for keypress and returns string containing the character pressed. e.g. letter$=INKEY$(100) waits 100 centi-seconds

INPUT "message", variable

Waits for input from keyboard. Displays message to prompt user. Can have multiple messages and variables. e.g. INPUT "Your age",AGE or INPUT "Input three numbers", A, B, C

INPUT#

Retrieves information from tape or disc. e.g. INPUT# channel, name$, age$

INSTR(source$, test$, fromCharacter)

Test source$ for occurence of test$ starting at fromCharacter number. fromCharacter number may be left out.

INT(number)

Converts a number to integer.

LEFT$(source$,number)

Copies the first number characters from source string. e.g. a$ = left$(test,3) would assign "tes" to a$

LEN(string$)

Returns integer number for length of string.

LET

Assigns variabkes. LET X=0. Not needed since X=0 does the same.

LIST from,to

Lists BASIC program. List n would list line number n. List ,n would list from start to n. List n, would list from n to end. List n,m would list from n to m.

LISTO option

Allows the LIST command to insert spaces in BASIC listings. Indenting after line number, FOR..NEXT loops or REPEAT...UNTIL loops. Use
0 - for no spaces
1 - for a space after line number
2 - for spaces during FOR...NEXT loops
4 - for spaces in REPEAT..UNTIL loops
The options can be added, hence LISTO 3 would insert spaces after line numbers and during FOR...NEXT loops.

LN(number)

Returns natural log of number

LOAD"name"

Loads program into memory. Load"" loads next program on tape.

LOCAL variable names

Makes variables local to procedure or function.

LOG(number)

Returns log base 10 of number

LOMEM

Used to alter/retrieve the memory area used to store user variables in BASIC programs.

MID$(source, start, number)

Takes number of characters from position start in string source

MOD

gives remainder of a division

MODE

Sets graphics mode.
Mode Graphics Colours Text
0 640x256 2 colour display 80x32 text
1 320x256 4 colour display 40x32 text
2 160x256 16 colour display 20x32 text
3   2 colour text only 80x25 text
4 320x256 2 colour display 40x32 text
5 160x256 4 colour display 20x32 text
6   2 colour text only 40x25 text
7   Teletext 40x25 text

MOVE x,y

Moves the graphics cursor to position x,y without drawing a line.

NEW

Clears the computers memory. Does not remove resident integer variables.

NEXT

Standard part of FOR..NEXT loop. Can be used with variable name.

NOT

unary operator.

OLD

Recovers a program after a NEW, only works if no new BASIC program lines are input.

ON

ON value GOTO linenumber,linenumber,...
ON result GOSUB linenumber.linenumber,...
ON ERROR GOTO linenumber
ON ERROR GOSUB linenumber

OPENIN("filename")

Open file for input. Returns channel number if file exists or 0 if it doesn't.

OPENOUT("filename")

Opens file for output. Returns channel numner, deletes file if it already exists, creates a new file if filename does not exist.

OPT number

1 assembler errors supressed, no listing
2 assembler errors supressed, listing
3 assembler errors reported, no listing
4 assembler errors reported, listing

OR

Logical or bitwise.

PAGE

Variable which gives the address in memory where BASIC has/will store users program.

PI

Returns PI.

PLOT k,x,y

Plots to x,y determined by k
0 move relative to last point.
1 draw line relative in the current graphics foreground colour.
2 draw line relative in the logical inverse colour
3 draw line relative in current graphics background colour
4 move to absolute position
5 draw line absolute position
6 draw line absolute in logical inverse colour
7 draw line absolute in curent graphics background colour
8-15 as 0-7 but with the last point in the line omitted to avoid inverting actions
16-23 as 0-7 but with a dotted line
24-31 as 0-7 but with a dotted line and the last point omitted.
32-63 reserved for the Graphics Extension ROM
64-71 as 0-7 but only a single point is plotted
72-79 reserved
80-87 as 0-7 but plot and fill a triangle. Fills between current x,y and last two points visited.
88-255 reserved

POINT(x,y)

return colour at position x,y

POS

returns horizontal position of cursor.

PRINT

Prints to screen.

PRINT# file,data

Writes data to a file.

PROC

Defines a procedure. Used with DEF.

PTR# channel

Pointer, moves a pointer in a serial file, allowing random access.

RAD(angle)

Convert from degrees to radians.

READ

Reads from a DATA statement. Can be used to read numeric or string data. The correct data type must be in the DATA statement.

REM

Remark

RENUMBER start, increment

Renumbers a BASIC program.

REPEAT

REPEAT...UNTIL, repeats a list of BASIC instructions until a certain condition is met.

REPORT

Reports in words the last error.

RESTORE

Resets the data pointer to a particular line of data. Used alone resets to the first data statement.

RETURN

Return from a GOSUB

RIGHT$(source, number)

Returns number characters from the right hand end of a string.

RND(x)

Returns random number from 1 to x, RND(1) goes from 0 to 0.999999

RUN

runs a BASIC program

SAVE"filename"

Saves a BASIC program, filename can be up to 10 characters.

SGN

Returns the sign of a number, -1 for negative, 0 for zero and +1 for positive.

SIN(angle)

Returns sine of angle, angle is in radians

SOUND channel, amplitude, pitch, duration

SPC(number)

Used to print number of spaces in a PRINT statement.

SQR

Square root of a number.

STEP

FOR..NEXT..STEP

STOP

Stops execution of program.

STR$

Converts a number to a string.

STRING$(number, source$)

Produces a string consisting of a number of occurences of a smaller string.

TAB(x)

Prints x tabs in a PRINT or INPUT statemen, TAB(x,y) prints to position x,y.

TAN

Tangent of angle in rads.

THEN

Standard IF..THEN construct.

TIME

Counter in one hundredth second intervals.

TO

FOR... TO... STEP... NEXT

TOP

Returns the first free memory location after the users program.

TRACE

Trace prints out the BASIC line number of each line it executes.

TRUE

represented by the number -1

UNTIL

REPEAT...UNTIL

USR(&addr)

Calls machine code a &addr

VAL

Returns numeric representation of a string.

VDU

Sends arguments to the OS output character routine.

VPOS

Vertical position of cursor.

WIDTH

sets width of screen