Contents / Reference section / BASIC keywords / Previous letter / Next letter / Index


C

CALL transfer control to a machine code subroutine

Purpose

This statement makes the computer execute a piece of machine code which the user has previously placed in the computer's memory. Before using this powerful statement you should have a good understanding of machine code and assembly language as incorrect use can destroy a program completely! Unfortunately there is not enough room in this book to teach assembly language programming but brief guidance for those familiar with 6502 assembly language is given in section 43.

Examples

50 rotate=&0270

60 CALL rotate,J,K,L

200 CALL 1234,A$,M,J$

Description

A statement to call a piece of machine code. The number of parameters passed is variable and may be zero. The parameters are variable parameters and may be changed on execution of the subroutine. The addresses of parameters are passed in a Parameter Block starting at location 0600 hex.

On entry to the subroutine the processor's A,X, Y registers are initialised to the least significant bytes of the integer variables A%, X% and Y%. The carry flag is set to the least significant bit of the C% variable.

On entry a Parameter Block is set up by the computer and it contains the following list:

Number of parameters - 1 byte
parameter address - 2 bytes
parameter type - 1 byte

parameter address
parameter type
} { repeated as often
as necessary.

Parameter types:

0- 8 bit byte(e.g.?X)
4- 32 bit integer variable (e.g. !X or X%)
5- 40 bit floating point number (e.g. V)
128- A string at a defined address (e.g. $X - terminated by a &0D)
129- A string variable such as A$

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

Syntax

CALL <numeric>{,<num-var>|<string-var>}

Associated keywords

USR

CHAIN

Purpose

CHAIN enables a program to be split up into a number of small sections.

The CHAIN statement is used to enable one program to LOAD and RUN another program automatically. For example, one program might enable the user to enter the number of hours worked by employees and that program might CHAIN a second program which would print out the payslips. In turn that might then CHAIN a third program which would do a coin analysis on the data held on the file.

CHAIN is also useful in a game with a lot of instructions. The instructions could all be stored as one file which could then

CHAIN the main game - thus releasing a lot of the computer's memory.

CHAIN"" will chain the next program (on a tape). This will not work with other file systems where you must give the file name. For that reason it must not be used in programs which may be used on disc systems.

Examples

900 CHAIN "GAME_1"

1234 CHAIN "NEWPROG"

CHAIN A$

Description

A statement which will load and run the program whose name is specified in the argument. All variables except @% and A% to Z% are cleared.

Syntax

CHAIN <string>

Associated keywords

LOAD, SAVE

CHR$ character string

Purpose

To generate a character (single letter or number etc.) from the number given. The character generated will be the ASCII character at the position given in the ASCII table. See the description of ASC and the full ASCII table on page 486.

The statement VDU has a similar effect to PRINT CHR$ and may be more useful in some applications.

Examples

220 RED$=CHR$(129)

1070 PRINT CHR$(8);

makes the cursor move left one position.

PRINT CHR$(7)

causes a short note to be emitted by the loudspeaker.

Description

A string function whose value is a single character string containing the ASCII character specified by the least significant byte of the numeric argument. Thus CHR$(-1) would give ASCII character number 255.

Note that the statement VDU is probably more useful when sending characters to the screen, since it involves less typing. CHR$ is needed when you wish to put a special character into a string.

Syntax

<string-var> = CHR$(<numeric>)

Associated keywords

ASC, STR$, VAL, VDU

CLEAR

Purpose

This tells the computer to forget all variables in use previously, including string variables and arrays but excluding the "resident integer variables" @% and A% to Z% which are not affected in any way. See page 62 for an explanation of integer and string variables.

Examples

350 CLEAR

CLEAR

Description

A statement which deletes all variables except the resident integer numeric variables @%..Z%

Syntax

CLEAR

Associated keywords

None

CLOSE#

Purpose

To inform the computer that you have completely finished with a particular file (see page 188 for an explanation of "files"). The computer then transfers any data still in memory to cassette, disc or Econet as needed. See the chapter on file handling (page 188) for more information.

Example

90 CLOSE#N

Description

A statement used to CLOSE a specific disc or cassette file. CLOSE# 0 will close all files.

Syntax

CLOSE# <numeric>

Associated keywords

OPENIN, OPENOUT, EXT#, PTR#, PRINT#, INPUT#, BGET#, BPUT#, EOF#

CLG clear the graphics screen

Purpose

To clear the graphics area of the screen. The graphics area of the screen is left in the colour selected as the "current graphics background colour". See the keyword GCOL, page 262, for more information. The graphics cursor is then moved to its home position (0,0) which is at the bottom left of the graphics area.

Examples

870 CLG

CLG

Description

Clears the current graphics area of the screen and sets this area to the current graphics background colour in addition. The statement then moves the graphics cursor to the graphics origin (0,0).

Syntax

CLG

Associated keywords

CLS, GCOL

CLS clear the text screen

Purpose

To clear the text area of the screen. Any graphics in this area will also be cleared. The text area will be left in the "current text background colour". The text cursor will then be moved to its "home" position at the top left of the text area. See the keyword COLOUR on page 222 for more information about text background colours.

Examples

560 CLS

CLS

Description

Clears the current text area and sets this area of the screen to the current text background colour. The statement then causes the text cursor to move to the text origin (0,0) at the top left of the current text area.

Syntax

CLS

Associated keywords

CLG, COLOUR

COLOUR

Purpose

This statement selects the colour in which the computer is to print the text and also its background. The command has a number of variations which are most easily explained by example

Type in the following:

MODE 5

COLOUR 1

COLOUR 2

COLOUR 3

and press RETURN at the end of each line as usual.

As you will have seen, these commands change the colour of the text. This is often called the "text foreground colour". Now try

COLOUR 129

COLOUR 130

COLOUR 128

These numbers change the "text background colour"

In any two colour mode (MODE 0,3,4 or 6) the following normally apply:

foreground background colour
0 128 black
1 129 white

In any four-colour mode (MODE 1 or 5) the following normally apply:

foreground background colour
0 128 black
1 129 red
2 130 yellow
3 131 white

In MODE 2 the following normally apply:

foreground background colour
0 128 black (normal background)
1 129 red
2 130 green
3 131 yellow
4 132 blue
5 133 magenta (blue-red)
6 134 cyan (blue-green)
7 135 white (normal foreground)
8 136 flashing black-white
9 137 flashing red-cyan
10 138 flashing green-magenta
11 139 flashing yellow-blue
12 140 flashing blue-yellow
13 141 flashing magenta-green
14 142 flashing cyan-red
15 143 flashing white-black

If you are not familiar with BASIC then you may already have had too much of this! Nevertheless, it is possible, for example in a four colour mode to select any four colours from the available sixteen effects by using another command. Remember that the colours given above (black, red, yellow, white) will be available as soon as a four colour mode is selected - but you can then select others colours later.

Try the following:

MODE 5

COLOUR 1

VDU 19,1,4,0,0,0

VDU 19,1,5,0,0,0

COLOUR 2

VDU 19 2,4 0,0,0

VDU 19,1,3,0,0,0

As you will see the statement VDU 19, can be used to change the "actual colour" of COLOUR 1 or 2.

The number which follows the VDU 19, is the number that is referred to by the COLOUR statement. It is referred to as a "logical colour".

The number which follows the "logical colour" referred to as the "actual colour" and is as follows:

0 black
1 red
2 green
3 yellow
4 blue
5 magenta (blue-red)
6 cyan (blue-green)
7 white
8 flashing black-white
9 flashing red-cyan
10 flashing green-magenta
11 flashing yellow-blue
12 flashing blue-yellow
13 flashing magenta-green
14 flashing cyan-red
15 flashing white-black

thus the statement VDU 19,3,6,0,0,0 will set logical colour 3 to be cyan. So if in MODE 4, a two colour mode, you wanted black letters on a yellow background you would issue the command:

VDU 19,1,0,0,0,0

VDU 19,0,3,0,0,0

Alternatively, you could string the whole lot together as

VDU 19,1,0,0,0,0,19,0,3,0,0,0

This combination of the COLOUR statement and the VDU 19 statement enables a very wide range of effects to be obtained. There are also calls which enable the flash rates of the colours to be altered as well. See the chapter on FX calls.

Syntax

COLOUR <numeric>

Associated keywords

VDU,GCOL

COS cosine

Purpose

To calculate the cosine of an angle. Note that the number in brackets (the angle) is expressed in radians and not in degrees. To convert from degrees to radians use the function RAD .

Examples

PRINT COS (2. 45)

780 X=COS(Y)

655 Number=COS (RAD (45))

Description

A function giving the cosine of its argument. The argument must be given in radians.

Syntax

<num-var> =COS(<numeric>)

Associated keywords

SIN, TAN, ACS, ASN, ATN, DEG, RAD

COUNT

Purpose

COUNT counts all the characters printed using PRINT, whether to screen, printer or RS423 output channel.

On the other hand POS returns the current position of the actual text cursor on the screen.

Examples

290 A=COUNT

75 fred=COUNT

PRINT COUNT

Description

A function returning the number of characters printed since the last new line. COUNT is set to zero if the output stream is changed.

Syntax

<num-var>=COUNT

Associated keywords

POS

Demonstration program

5 REM to print a row of 16 * signs

7 REM this is not the easiest way!

10 X=16

20 REPEAT PRINT "*";

30 UNTIL COUNT=X

Exit: BBC Microcomputer User Guide; Kasoft Typesetting; Archer


The BBC Microcomputer User Guide was written by John Coll and edited by David Allen for the British Broadcasting Corporation.

Optical character recognition and original formatting effort by Mark Usher.

HTML version maintained by: Kade "Archer" Hansson; e-mail: archer@dialix.com.au

Last updated: Monday 12th February 2001