BBC Command Reference

Variables

integerrealstring
example3469.847"HELLO"
typical variablesA%AA$
nameSIZE%SIZESIZE$
max size2,147,483,6471.7x1038255 chars
accuracy1 digit9 sig figs-
stored in32 bits40 bitsASCII 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)
foregroundbackgrounddefault colour
0128black
1129white

Four colour modes (1,5)
foregroundbackgrounddefault colour
0128black
1129red
2130yellow
3131white

Mode 2 - 16 colour mode
foregroundbackgrounddefault colour
0128black
1129red
2130yellow
3131white
4132black
5133red
6134yellow
7135white
8136black
9137red
10138yellow
11139white
12140black
13141red
14142yellow
15143white

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
parameterrangefunction
N1 to 4envelope number
T bits 0-60 to 127length of each step in hundredths of seconds
T bit 70 or 10 - auto repeat, 1 - don't autorepeat
PI1-128 to 127change of pitch per step in section 1
PI2-128 to 127change of pitch per step in section 2
PI3-128 to 127change of pitch per step in section 3
PN10 to 255number of steps in section 1
PN20 to 255number of steps in section 2
PN30 to 255number of steps in section 3
AA-127 to 127change of amplitude per step during attack phase
AD-127 to 127change of amplitude per step during decay phase
AS-127 to 0change of amplitude per step during sustain phase
AR-127 to 0change of amplitude per step during release phase
ALA0 to 126target of level at end of attack phase
ALD0 to 126target 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

0plot the colour specified
1OR specified colour with the one that is already there
2AND specified colour with the one that is already there
3XOR specified colour with the one that is already there
4invert 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
KeyNumberKeyNumber
f0-331-49
f1-1142-50
f2-1153-18
f3-1164-19
f4-215-20
f5-1176-53
f6-1187-37
f7-238-22
f8-1199-39
f9-1200-40
A-660-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-102ESCAPE-113
N-86TAB-97
O-55CAPSLOCK-65
P-56CTRL-2
Q-17SHIFT LOCK-81
R-52SHIFT-1
S-82SPACEBAR-99
T-36DELETE-90
U-54COPY-106
V-100RETURN-74
W-34CRSR UP-58
X-67CRSR DOWN-42
Y-69CRSR LEFT-26
Z-98CRSR 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.
ModeGraphicsColoursText
0640x2562 colour display80x32 text
1320x2564 colour display 40x32 text
2160x25616 colour display20x32 text
3 2 colour text only80x25 text
4320x2562 colour display40x32 text
5160x2564 colour display20x32 text
6 2 colour text only40x25 text
7 Teletext40x25 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
0move relative to last point.
1draw line relative in the current graphics foreground colour.
2draw line relative in the logical inverse colour
3draw line relative in current graphics background colour
4move to absolute position
5draw line absolute position
6draw line absolute in logical inverse colour
7draw line absolute in curent graphics background colour
8-15as 0-7 but with the last point in the line omitted to avoid inverting actions
16-23as 0-7 but with a dotted line
24-31as 0-7 but with a dotted line and the last point omitted.
32-63reserved for the Graphics Extension ROM
64-71as 0-7 but only a single point is plotted
72-79reserved
80-87as 0-7 but plot and fill a triangle. Fills between current x,y and last two points visited.
88-255reserved

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