BBC BASIC Keywords

BBC BASIC Keywords

ABS

Absolute value (function)

ABS

Absolute value (function)

 

Returns the absolute positive value of its argument.

ACS

Arc cosine (function)

 

Returns the arc cosine of its argument in radians. The permitted range of the argument is -1 to +1-

For example,

PRINT DEG(ACS(0.5))

will print 60, because COS(60°) is 0.5.

AND (A.)

Logical AND (operator)

 

Performs a bitwise logical AND between two operands which are internally converted to 4 byte integers before the operation.

It is normally used to join two conditions in an IF or UNTIL statement; thus

IF length >10 AND width > 10 THEN PRINT "OK"

ensures that a rectangle is larger than 10 x 10.

ASC

ASCII value (function)

 

Returns the ASCII character value of the first character of the argument string.

PRINT ASC("Cambridge Z88")

gives 90, the ASCII value of "Z".

The brackets are optional, and ASC"", the null string, gives -1.

ASN

Arc sine (function)

 

Returns the arc sine of its argument in radians. The permitted range of the argument is -1 to +1.

ATN

Arc tangent (function)

 

Returns the arc tangent of its argument in radians.

AUTO (AU.)

Automatic numbering (command)

 

Allows lines to be entered without first typing in the number of the line. The line numbers are preceded by the usual prompt (>).

By default the starting line number and increment are both 10, but they may optionally be specified; for example

AUTO 20

will start with line 20, and

AUTO 100,20

will start at line 100 and increment by 20. AUTO will continue generating line numbers until you press 

.

 BGET (B.#)

Byte from data file (function)

 

Returns a byte from the data file whose channel number is its argument. The file pointer is incremented after the byte has been read. For example,

character=BGET#c

reads the next character from file c.

 

 BPUT# (BP.#)

Output a byte (statement)

 

 

Puts a byte to the data file whose channel number is the first argument. The second argument's least significant byte is written to the file. The file pointer is incremented after the byte has been written. Thus

BPUT#channel, char

writes char to file channel.

 CALL (CA.)

Call machine-code (statement)

 

Calls a machine code subroutine at a specified address, passing parameters in a parameter block addressed by the Z80's IX register. The IY register is set to the address of the machine code subroutine being called. The processor's A, B, C, D, E, F, H, and L registers are initialised to the least significant bytes of A%, B%, C%, D%, E%, F%, H%, and L% respectively.

This statement could cause corruption of the Cambridge Z88 memory, and should therefore only be used by experienced programmers.

The parameter block contains the following list:

number of parameters

1 byte

(1X+0)

first parameter type

1 byte

(1X+1)

first parameter address

2 bytes

(1X+2,1X+3)

parameter type

) repeated as often

parameter address

) as necessary

where the parameter types are as follows:

Type

Description

8 bit bytes (eg ?a)

4

32 bit integer variable (eg !b or c%)

5

40 bit floating point number (eg d)

128

A string at a defined address (eg $e terminated by a &0D)

129

A string variable such as f$

In the case of a string variable the parameter address is the address of a String Information Block which gives the current length of the string, number of bytes allocated, and start address, in that order.

muldiv=1234
CALL muldiv,A,B$,C%

CHAIN (CH.)

Load and run program (statement)

 

Loads and runs the program whose name is specified in the argument allowing one program to load another. Information can be passed between programs using the static variables @%, and A% to Z%.

CHR$

ASCII character (function)

 

Returns the ASCII character string specified by the least significant byte of the numeric argument.

A$=CHR$(90)

will set A$ to 70, since ASC"Z" is 90. The characters corresponding to values 32 and above can be displayed on the screen with the line

FOR N%=32 TO 255: PRINT CHR$(N%) ; : NEXT

CLEAR (CL.)

 Clear program (statement)

 

Clears all variables, including strings apart from the static variables @%, and A% to Z%.

CLG

Clears Graphics Window

 

This clears the graphics window (only); it does not affect the position of the graphics cursor.

Note:

CLS can be used to clear the text window and leave the graphics window unchanged.

CLOSE (CL.#)

Close channel (statement)

 

Closes a specified channel. For example,

CLOSE#c

closes channel c.

CLS

Clear text area (statement)

 

Clears the text area of the screen. The text cursor is moved to the 'home' position (0,0) at the top left-hand character position of the text area.

COLOUR

 

 

not implemented.

COS

Cosine (function)

 

Returns the cosine of its argument in radians.

X=COS(angle)

COUNT (COU.)

Character count (function)

 

Returns the number of characters sent to the output stream (VDU or printer) since the last new line. For example,

PRINT A$::REPEAT PRINT ".";:UNTIL COUNT = 72

will pad the line with dots to 72 characters

DATA (D.)

Data (statement)

 

Introduces lists of data for use by the READ statement (see READ).

DEF

Define function/procedure (statement)

 

Precedes declaration of a user-defined function (FN) or procedure (PROC). DEF must be used at the start of a program line.

For example,

DEF FNcelsiusff) = (f-32)*5/9

defines a function to convert Fahrenheit to Celsius.

Executing

PRINT FNcelsius(98.4)

will convert 98.4 to Celsius.

DEG

Degrees (function)

 

Returns the argument converted from radians to degrees. For example

PRINT=DEG(PI/2)

will print 90

DELETE (DEL.)

Delete lines (command)

 

Deletes a group of lines from the program. Both start and end lines of the group will be deleted. For example

DELETE 123,456

will delete all lines between 123 and 456 inclusive, which need not exist.

DIM

Dimension array (statement)

 

Dimensions an array, or reserves an area of memory for special applications. For example,

DIM a$(10,20)

dimensions a two-dimensional string array a$ with elements a$(0,0) up to a$(10,20). Arrays may have one or more dimensions, and may be string arrays, floating-point arrays, or integer arrays.

DIM X%24

reserves 25 bytes and puts the address of byte 0 in the variable X%.

DIV

Integer divide (operator)

 

Gives the integer quotient of two items. The result is always an integer.

X=A DIV B y=(top+bottom+1) DIV 2

DRAW x,y

Draw  black straight line

 

Draws a straight line (in black) between the current position of the graphics cursor and the specified coordinates, then moves the graphics cursor to the specified position.

This statement is identical to PLOT 5.

ELSE (EL.)

Else clause (statement)

 

An optional part of the IF...THEN, or ON...GOSUB, ON...GOTO statements, it introduces the action to be taken if the testable condition evaluates to FALSE, or the ON expression is out of range.

END

End program (statement)

 

Returns to direct mode.

ENDPROC

End procedure (statement)

 

Denotes the end of a procedure defined with DEF PROC.

EOF#

End of file (function)

 

Returns -1 (TRUE) if the end of the specified data file has been reached. For example,

REPEAT

char%=BGET#data

...

UNTIL EOF#data

will read characters until the end of the file whose channel number is the variable data.

EOR

Logical Exclusive-OR (operator)

 

Performs a bitwise integer logical exclusive-or between two operands which are internally converted to 4 byte integers before the operation.

ERL

Error line (function)

 

Returns the line number of the line where the last error occurred. For example,

PRINT "Error number" ERR "at line" ERL

ERR

Error code (function)

 

Returns the error code number of the last error which occurred.

EVAL (EV.)

Evaluate string (function)

 

Returns the result of evaluating the given expression supplied as a string. For example,

a=6 : b=7

PRINT EVAL ("a + b")

EXP

Exponent (function)

 

Returns 'e' (2.71828183) to the power of the argument.

EXT#

Extent of file (function)

 

Returns the total length of the file whose channel number is its argument.

The file must have been opened with OPENIN, OPENUP, or OPENOUT.

FALSE (FA.)

False (function)

 

Returns the value zero representing logical false. For example,

REPEAT PRINT "*" : UNTIL FALSE

will continue forever.

FN

Function (statement)

 

Introduces a user-declared function. The first character of the function name can be a letter, underline, or a number. No spaces are allowed between the function name and the opening bracket of the parameter list (if any).

FOR (F.)

Start FOR loop (statement)

 

Initialises a FOR ... NEXT loop. The loop is executed at least once for each of the values of the control variable in the specified range.

FOR card=1 TO 6 PRINT card;

NEXT card

will print

1    2    3    4    5    6

GCOL

 

 

not implemented.

GET/GET$

Wait for key (function)

 

Waits for a key to be pressed on the keyboard. GET returns the ASCII value, and GET$ returns the corresponding single-character string. For example,

REPEAT UNTIL GET = 13

waits for 

 to be pressed.

GOSUB (GOS.)

Call subroutine (statement)

 

Calls a section of a program as a subroutine at a specified line number. Control returns to the next statement when RETURN is encountered in the subroutine. One subroutine may call another subroutine (or itself).

100 GOSUB 120 110 END 120 PRINT "Hello" 130 RETURN

GOTO (G.)

Go to line (statement)

 

Transfers program control to a line with a specified or calculated line number. For example,

GOTO 100 GOTO (X*10)

The use of the calculated GOTO, as in the second example, is not recommended as it will not be renumbered correctly by the RENUMBER command.

HIMEM (H.)

High memory bound (function)

 

A pseudo-variable which contains the address of the first byte of free memory.

IF

Condition (statement)

 

Sets up a test condition which can be used to control the subsequent flow of the program. It is part of the IF ... THEN ... ELSE structure. The word THEN is optional under most circumstances.

IF length-5 THEN 110 IF A<C OR A>D GOTO 110 IF A>C AND C>-D THEN GOTO 110 ELSE PRINT "CCL"

INKEY/INKEY$

Read key (function)

 

Waits for up to a specified number of clock ticks (10ms each). If no key is pressed in the time limit, INKEY will return -1 and INKEY$ will return a null string; otherwise the INKEY function will return the ASCII value of the key pressed.

INPUT (I.)

Input value (statement)

 

Inputs values from the keyboard.

The INPUT statement normally prints a ? prompt for each variable in the list. Alternatively strings can be included in the list of variables to be printed as prompts; omitting the comma after a string will suppress the question mark. For example:

INPUT"Enter your age:" age%, "and your name",name$

INPUT LINE

(statement)

 

Identical to INPUT except that the entire line, including commas, quotes and leading spaces is input into a string variable.

INPUT LINE A$

INPUT#

Input from file (statement)

 

Reads data from a file into specified variables.

The data should have been written to the file with a corresponding PRINT# statement.

INSTR

Substring (function)

 

Returns the position of a substring within a string, optionally starting the search at a specified place in the string. The leftmost character position is 1. If the sub-string is not found, 0 is returned.

For example,

PRINT INSTR("Cambridge Z88"."8")

will print 12, and

PRINT INSTR("PipeDream","e".5)

will start the search at character 5 and print 7.

INT

Integer (function)

 

Converts a real number to the next lower or equal integer.

INT(99.8) is 99

INT(-12) is -12

INT(-12.1) is -13.

LEFT$

Left of string (function)

web analytics