RTR logo

R. T. RUSSELL

BBC BASIC (86) Manual



Graphics and Colours

Introduction

BBCBASIC(86) provides support for the MDA, CGA and EGA and limited support for the VGA.

Whilst the commands for positioning and printing text on the screen are similar to other versions of BASIC (TAB and PRINT), BBCBASIC(86) has an extensive range of graphics commands. These commands are identical to those available on a BBC Micro, but different from many other versions of BASIC.

This section draws together the information about graphics facilities and colours given under various keywords. Although it repeats much of the information presented elsewhere in this manual it provides a consolidated explanation of the graphics facilities and colours available.


Display Modes

The MODE (or VDU 22) command sets the screen display mode. The screen is cleared and all the graphics and text parameters (colours, origin, etc) are reset to their default values.

The following example sets the display mode to mode 3.

MODE 3
BBCBASIC(86) does not have a default display mode; it starts in whatever mode MS-DOS was using at the time BBCBASIC(86) was run.

Available Modes

The available display modes and the resolution of which they are capable are listed below. As described later in the Drawing on The Screen sub-section, none of the PC display formats available with any of the display adapters offer identical resolution to the BBC Micro and complete compatibility is not possible. However, in order to make BBCBASIC(86) as compatible as possible with the BBC Micro, the original BBC Micro modes have been mapped on to the PC mode with the closest attribute match. As a consequence, a number of the modes have identical attributes.
Mode Graphics (pixels) Logical Colours Text (chars)
0640x2002 colour display80x25
1320x2004 colour display40x25
2Same as mode 1
3None16 colour text only80x25
4320x2004 colour display40x25
5Same as mode 4
6None16 colour text only40x25
7NoneMonochrome text only80x25
Viewdata emulation40x25
8640x20016 colour80x25
9320x20016 colour40x25
10Same as mode 9
11Same as mode 3
12Same as mode 9
13Same as mode 9
14Same as mode 6
15640x350monochrome display80x25
16640x35016 colour80x25 or
80x43
17Reserved for expansion.
18640x48016 colour80x30 or
80x60
This table indicates the number of logical colours available in each display mode. As described in The Palette sub-section, the number of physical colours available depends upon the display adapter fitted.

Modes 1, 2, 4 and 5 are identical except that, when using the NTSC composite video output, modes 4 and 5 cause the colour subcarrier to be suppressed.

Several display adapters with widely differing capabilities are available for the PC. Because of this difference in capabilities, the display modes available to BBCBASIC(86) depend upon the display adapter fitted to your computer.

(The action of VDU 4 and VDU 5 are explained later in this section under the heading of User Defined Characters.)

Modes 8 to 15 have been mapped as closely as possible (as regards graphics resolution and number of text columns) onto CGA modes 0 to 7. This has been done to simplify conversion of software to use the EGA modes. You simply need to add 8 to the original CGA mode number.

You can automatically map the CGA modes 0 to 7 to the EGA modes 8 to 15 with the *EGA command. Normal operation may be restored by issuing the command *EGA OFF.

Graphics operations in the EGA modes are significantly slower than in the CGA modes. Since all EGA cards also support the CGA modes, you should use the CGA modes 0 to 7 unless you actually need EGA features (16 colours, for example).

Attempting to select a screen mode of which the hardware of the computer is not capable should give the 'Bad mode' error, although the screen may first be cleared. However, some computers may 'crash' if no EGA or VGA card is fitted and an attempt is made to select modes 8 to 18 (or modes 0 to 7 after *EGA). This is due to shortcomings of the BIOS fitted to some PC compatibles.

Graphics Coordinates

It has not been possible to retain the same vertical graphics coordinates as the BBC Micro. It would be possible to scale the coordinates if only graphics were involved, but it is not possible to scale characters.

The address range (logical size) of the graphics screen in the various modes is shown in the following table. The horizontal address range is the same for all modes. Whilst the vertical address range varies between modes, the physical height of the screen remains constant.

ModesScreen Address Range
0, 1, 2,0 to 1279 in the X axis. 0 to 799 in the Y axis.
4, 5,
8, 9, 10,     
12, 13
 
15, 160 to 1279 in the X axis. 0 to1399 in the Y axis.
 
180 to 1279 in the X axis. 0 to 959 in the Y axis.
The graphics origin (X=0, Y=0) is normally at the bottom left-hand corner of the screen. As explained later, it may be changed with the VDU 29 command.


Colours

Introduction

You can set the text and graphics background and foreground colours using the COLOUR and GCOL (Graphics COLour) commands. These commands use numbers to specify the colours.

When BBCBASIC(86) is loaded the colour numbers used by COLOUR and GCOL are set to a physical colour. However you can (with certain limitations) set the actual colour displayed by these colour numbers to any one of the physical colours available by using the VDU 19 command.

Because you can change the actual colour displayed by a colour number to any one of the physical colours available to you, these numbers are called logical colours. You could, if you wished, set all the logical colour numbers to the same physical colour.

It may help you to visualise the logical colours as an artist's palette with up to 16 numbered areas where colours may be placed. You could place any of the colours available to you in any one of the areas on the palette. Once the colours were in place on the palette, you could 'paint by numbers'.

Text Colours

You can set the text foreground and background colours with the COLOUR (or VDU 17) command. The colour referenced by this command is the logical colour. The relationship between logical and physical colours (the palette) is explained later.

The keyword COLOUR is followed by a number. If the number is less than 128, the colour of the text is set. If the number is 128 or greater, the colour of the background is set.

There are up to 16 logical colours, but the number available varies with the mode. The logical colour numbers available to each mode are listed below with the physical colours allocated to them on power-up.

Two Colour Graphics Mode

Mode 0

Foreground  BackgroundColour
COLOUR 0COLOUR 128  Black
COLOUR 1COLOUR 129White
You can change the physical to logical colour mapping (palette) using the VDU 19 command.

Four Colour Graphics Modes

Modes 1, 2, 4 & 5

Foreground  BackgroundColour
COLOUR 0COLOUR 128  Black
COLOUR 1COLOUR 129Magenta
COLOUR 2COLOUR 130Cyan
COLOUR 3COLOUR 131White
You can change the physical to logical colour mapping (palette) using the VDU 19 command.

Sixteen Colour Graphics Modes

Modes 8, 9, 10, 12, 13, 16 and 18

ForegroundBackgroundColour
COLOUR 0COLOUR 128  Black
COLOUR 1COLOUR 129Red
COLOUR 2COLOUR 130Green
COLOUR 3COLOUR 131Yellow
COLOUR 4COLOUR 132Blue
COLOUR 5COLOUR 133Magenta
COLOUR 6COLOUR 134Cyan
COLOUR 7COLOUR 135White
COLOUR 8COLOUR 136Intensified Black
COLOUR 9COLOUR 137Intensified Red
COLOUR 10COLOUR 138Intensified Green
COLOUR 11COLOUR 139Intensified Yellow
COLOUR 12COLOUR 140Intensified Blue
COLOUR 13COLOUR 141Intensified Magenta
COLOUR 14COLOUR 142Intensified Cyan
COLOUR 15  COLOUR 143Intensified White
You can change the physical to logical colour mapping (palette) using the VDU 19 command.

Text Only Modes

Modes 3, 6, 11 & 14

ForegroundBackgroundColour
COLOUR 0COLOUR 128  Black
COLOUR 1COLOUR 129Red
COLOUR 2COLOUR 130Green
COLOUR 3COLOUR 131Yellow
COLOUR 4COLOUR 132Blue
COLOUR 5COLOUR 133Magenta
COLOUR 6COLOUR 134Cyan
COLOUR 7COLOUR 135White
COLOUR 8 Intensified Black
COLOUR 9 Intensified Red
COLOUR 10 Intensified Green
COLOUR 11 Intensified Yellow
COLOUR 12 Intensified Blue
COLOUR 13 Intensified Magenta
COLOUR 14 Intensified Cyan
COLOUR 15 Intensified White
COLOUR 16 Black
COLOUR 17 Flashing red
COLOUR 18 Flashing green
COLOUR 19 Flashing yellow
COLOUR 20 Flashing blue
COLOUR 21 Flashing magenta
COLOUR 22 Flashing cyan
COLOUR 23 Flashing white
COLOUR 24 Intensified Flashing black
COLOUR 25 Intensified Flashing red
COLOUR 26 Intensified Flashing green
COLOUR 27 Intensified Flashing yellow
COLOUR 28 Intensified Flashing blue
COLOUR 29 Intensified Flashing magenta
COLOUR 30 Intensified Flashing cyan
COLOUR 31   Intensified Flashing white
Flashing colours alternate between the specified colour and the current background colour.

You can only use the 'normal' colours for the background.

There is no normal palette in modes 3, 6, 11 and 14. However, you can change the physical to logical colour mapping with the VDU 19 command if you use the enhanced palette.

Graphics Colours

Setting The Colours

You can use the GCOL (or VDU 18) command to set the graphics foreground and background colours. The colour referenced by this command is the logical colour. The relationship between logical and physical colours (the palette) is explained later.

The GCOL command also specifies how the colour is to be plotted on the screen. It can be plotted directly, ANDed, ORed or Exclusive-ORed with the colour already there, or the existing colour can be inverted.

GCOL mode,colour
The first argument specifies the mode of action; the second specifies the logical colour. If the colour is greater than 127, then it defines the graphics background colour.
mode=0 Plot the colour specified.
mode=1 OR the specified colour with the colour that is already there.
mode=2 AND the specified colour with the colour that is already there.
mode=3 Exclusive-OR the specified colour with the colour that is already there.
mode=4 Invert the colour that is already there.
Generally, you will not notice a change in the graphics background colour until you clear the graphics screen with a CLG command.

The logical colours available for each mode and their default physical colours are listed below. You can use the VDU 19 command to change the physical to logical colour mapping (palette). This is described later in this section.

Two Colour Graphics

Modes 0 and 15

Foreground  BackgroundColour
GCOL 0,0GCOL 0,128  Black
GCOL 0,1GCOL 0,129White

Four Colour Graphics

Modes 1, 2, 4 & 5

Foreground  BackgroundColour
GCOL 0,0GCOL 0,128  Black
GCOL 0,1GCOL 0,129Magenta
GCOL 0,2GCOL 0,130Cyan
GCOL 0,3GCOL 0,131White

Sixteen Colour Graphics

Modes 8, 9, 10, 12, 13, 16 and 18

ForegroundBackgroundColour
GCOL 0,0GCOL 0,128  Black
GCOL 0,1GCOL 0,129Red
GCOL 0,2GCOL 0,130Green
GCOL 0,3GCOL 0,131Yellow
GCOL 0,4GCOL 0,132Blue
GCOL 0,5GCOL 0,133Magenta
GCOL 0,6GCOL 0,134Cyan
GCOL 0,7GCOL 0,135White
GCOL 0,8GCOL 0,136Intensified Black
GCOL 0,9GCOL 0,137Intensified Red
GCOL 0,10GCOL 0,138Intensified Green
GCOL 0,11GCOL 0,139Intensified Yellow
GCOL 0,12GCOL 0,140Intensified Blue
GCOL 0,13GCOL 0,141Intensified Magenta
GCOL 0,14GCOL 0,142Intensified Cyan
GCOL 0,15  GCOL 0,143Intensified White

The Palette

In BBCBASIC(86) colours are allocated by number and, depending upon the chosen display mode, up to 16 logical colours are available. These logical colours may be set to any of the physical colours available using the VDU 19 command.

Logical Colours

The number of logical colours available depends upon the chosen display mode.

Physical Colours

The physical colours are also referred to by numbers. However, a physical colour number always refers to the same colour. Depending upon the graphics adapter fitted to your computer, up to 64 physical colours are available. If a VGA is fitted, an 'analogue' colour palette is available.

Palettes Available

With all of the colour display adapters available, the physical colours are different to those used on the BBC Micro. For example, BBC physical colour 1 is red, but PC physical colour 1 is blue. In order to maximise compatibility with the BBC Micro, BBCBASIC(86) translates the colour numbers so that the expected colour is displayed. While the colours available are similar, this translation process is advantageous. However, if more colours are available than on a BBC Micro, it imposes a limitation on the number of colours that can be displayed.

If a CGA is fitted, the number of colours available depends upon the mode used (see later) but, in general, 16 colours are available. However, if an EGA is fitted, it is possible to select from 64 colours and with a VGA, an 'analogue' colour palette is available. It would be disappointing if these colours were not accessible by BBCBASIC(86).

This conflict is overcome by allowing the VDU 19 command to access two palettes. The normal palette maximises the similarity between the results obtained on a BBC Micro and a PC Compatible. The enhanced palette offers all the colours available on the EGA/VGA.

Setting the Palette

VDU 19

VDU 19 sets the physical to logical colour mapping (the palette). It takes the next five characters as parameters. The first parameter is the logical colour to be set and the second is the physical colour that it is to be set to. The next three parameters are used by the VGA enhanced palette. If a CGA or an EGA is used, they must still be present, but they are ignored (set them to 0).
VDU 19,logical,physical,0,0,0

Colours Available

The colours available depend on the graphics adapter fitted and the type of display connected to it.

Normal Palette

Normal Palette - CGA Modes

The colours available (depending on the mode) are listed below.
Colour Number  Physical Colour
0Black (normal background)
1Red
2Green
3Yellow (Brown)
4Blue
5Magenta (blue-red)
6Cyan (blue-green)
7White (normal foreground)
8Intensified Black (grey)
9Intensified Red
10Intensified Green
11Intensified Yellow
12Intensified Blue
13Intensified Magenta
14Intensified Cyan
15Intensified White
It is not possible to provide a true palette when a CGA is used because of limitations imposed by the hardware. The facilities available depend upon the mode used.

CGA 2-Colour Mode

Mode 0

Most EGA cards do not emulate the (peculiar) CGA MODE 0 characteristic. Consequently, the action of the VDU 19 command differs between a CGA and an EGA in MODE 0. Some EGA cards come with a software utility which improves their CGA emulation.

With a CGA, the foreground colour (logical colour 1) can be set to any colour between 0 and 15.

VDU 19,1,physical,0,0,0
and the background colour (logical colour 0) cannot be changed from black. Thus,
VDU 19,0,physical,0,0,0
has no effect.

With an EGA, the palette for mode 0 behaves in a peculiar manner. Instead of altering the foreground colour, setting logical colour 1 alters the background colour and the foreground colour is set to cyan.

CGA 4-Colour Modes

Modes 1, 2, 4 and 5

In Modes 1, 2, 4 and 5, the logical foreground colours can be set to one of two different palettes and the logical background colour can be set to any physical colour between 0 and 15.

If the logical colour number is greater than 0 (a foreground logical colour), the VDU 19 command selects which of two foreground colour palettes will be used depending on the value of the physical colour number. It is not possible to change the foreground colours independently and logical colour numbers between 1 and 3 have the same effect.

The physical colour number selects which of the two palettes are to be used for the foreground colours. If the physical colour number is 0, 1, 2 or 3, then palette No 1 is selected. If the physical colour number is 4, 5, 6 or 7, then palette No 2 is selected. The colours of the two palettes are listed below.

 Palette 1Palette 2
Logical Colour  Physical Colour  Physical Colour
1RedMagenta
2GreenCyan
3YellowWhite
The first example below selects palette No 1 and the second selects palette No 2.
VDU 19,1,2,0,0,0

VDU 19,3,4,0,0,0
By specifying a logical colour of 0, the background/border colour can be set to any colour between 0 and 15. The example below sets logical colour 0 to blue.
VDU 19,0,4,0,0,0

Normal Palette - EGA/VGA Colour Modes

Modes 8, 9, 10, 12,13, 16 and 18

In the EGA and VGA colour graphics modes 16 physical colours are available with the normal palette. These colours are the same as those available in the CGA modes.

For example,

VDU 19,1,4,0,0,0
would set logical colour 1 to blue.

Normal Palette - Text Only Modes

Modes 3, 6, 11 and 14

You cannot change the physical to logical colour number mapping with the normal palette in the text-only modes.

Enhanced Palette

If an EGA or VGA is available, you may use the enhanced palette in any of the colour display modes.

Enhanced Palette - Graphics Modes

Modes 0, 1, 2, 4, 5, 8, 9, 10, 12, 13, 15, 16 and 18

If bit 7 of the logical colour number is set (values 128 to 143), then the enhanced palette is used and the physical colour is taken to be the IBM colour value. The logical colour numbers (plus 128) are those used by BBCBASIC(86).

Unfortunately, this is not as straightforward as it might seem. The actual colours depend upon the mode in use, whether the monitor has 4 or 6 inputs and how it is adjusted.

A 6 input monitor has 2 blue, 2 green and 2 red inputs. A 4 input monitor has a blue, green, red and intensity input. The former is capable of displaying 64 colours and the latter 16 colours. If the monitor is truly IBM compatible, it will only act as a 6 input monitor in mode 16. In all other modes, it will act as a 4 input monitor. This restriction is imposed by the monitor and not by the graphics adapter.

The colour number on a 6 input monitor (in mode 16) is made up as shown below.

Not Used Not Used Red' Green' Blue' Red Green Blue
MSBLSB

Thus, colour 18 would give you a combination of Green' and Green; in other words, bright green, and colour 17 would give you a combination of Green' and Blue.

The colour number on a 4 input monitor (or an IBM compatible 6 input monitor in modes other than 16) is made up in a similar manner as shown below.

Not Used Not Used Not used Intensity Not Used Red Green Blue
MSBLSB

With a 4 input monitor, the colour 18 will still give bright green (Intensity and Green), but colour 17 gives bright blue (Intensity and Blue).

Consequently, the colours displayed on a 4 input monitor are only the same as those displayed on a 6 input monitor for physical colours 0 to 7 (plus some other odd numbers). Thus, you need to know the type of monitor you are programming for.

For example,

VDU 19,129,27,0,0,0
would set logical colour 1 to bright cyan with either a 4 or 6 input monitor (27 is binary 00011011),

and

VDU 19,130,26,0,0,0
would set logical colour 2 to a combination of Green', Green and Blue on a 6 input monitor and bright green on a 4 input monitor (26 is binary 00011010).

Whilst a 4 input monitor only displays 16 colours, the colour numbers in the enhanced palette differ from the normal palette because the normal palette numbers have been translated to maximise compatibility with the BBC Micro.

The enhanced (IBM) colour numbers are not contiguous. With a 4 input VDU, colours 8 to 15, 32 to 39 and 40 to 47 are the same as the 'normal' colours 0 to 7 and colours 24 to 31, 48 to 55 and 56 to 63 are the same as the intensified colours 16 to 23. On the other hand, the enhanced palette colours are in ascending order of luminance and they display as a grey scale on a colour-input-compatible monochrome VDU.

Enhanced Palette - Text Only Modes

Modes 3, 6, 11 and 14

If bit 7 of the logical colour number is set (values 128 to 143), then the enhanced palette is used and the physical colour is taken to be the IBM colour value.

For example, the following command will set logical colour 1 to green.

VDU 19,129,2,0,0,0
The text enhanced palette is the same as the graphics enhanced palette.

Enhanced Palette - VGA

The VGA enhanced palette has two modes. The first offers identical features to the EGA enhanced palette and it is set in an identical manner.

The alternative mode provides an 'analogue' palette by allowing you to set the Red, Green and Blue intensities to any value between 0 and 63. The format of the VGA 'analogue' colour palette command is shown below.

VDU 19,logical,-1,red,green,blue
As before, bit 7 of the logical colour needs to be set in order to indicate that an enhanced palette is to be used. In addition, the 'physical' colour is set to -1 to indicate that the following 3 numbers specify the Red, Green and Blue intensities respectively. These may be set to any value between 0 and 63.

The following example sets colour 0 to a dull blue.

VDU 19,128,-1,0,0,10

Border Colour

With most colour adapters it is possible to change the border colour independently in the CGA text modes 3 and 6, all the EGA modes and the VGA mode. Only the enhanced palette is available.

The border is specified by using -1 as the logical colour number.

The following example sets the border colour to green.

VDU 19,-1,2,0,0,0
Some graphics adapters appear not to allow the border colour to be changed at all.

Default Colour Setting

The VDU 20 command performs two distinct actions:

Most EGA cards do not emulate the (peculiar) CGA mode 0 characteristics and the VDU 20 command acts in an apparently unusual manner in this mode if an EGA or VGA is used. This is because the EGA/VGA default palette for mode 0 is cyan for logical colour 1 and white for logical colour 0.

Some EGA cards come with a software utility which improves their CGA emulation.


Drawing on The Screen

Introduction

This sub-section describes the statements and functions available for drawing on the graphics screen and discovering the colour of any pixel (picture element) on the screen.

Screen Dimensions

As in the case of the BBC Micro, there are a number of display modes available with differing graphics resolution. In order to bring some semblance of order to this potentially chaotic situation, 'logical' screen coordinates are used.

Because of the facilities provided by the hardware, it has not been possible to retain the same vertical graphics coordinates as the BBC Micro. It would have been possible to scale the vertical coordinates if only graphics had been involved, but it is not possible to scale characters.

The Graphics Area

BBCBASIC(86) has a logical graphics area (or 'internal' screen) with a size of +32767 to -32768 in both the X and Y axis. The graphics window, the graphics origin and the current graphics cursor position may be anywhere within this graphics area.

The physical screen is a window on the graphics area. Its maximum 'logical' size depends upon the mode selected and it is much smaller then the graphics area.

By default, the graphics window is the full size of the screen and the graphics origin is at the bottom left-hand corner of the screen. You may change the size of the graphics window with the VDU 24 command and the graphics origin with the VDU 29 command. The action of these commands is described later in the Windows sub-section.

You can move or draw to any point which is within the graphics area whether or not this point is outside the current graphics window . If you draw a line to a point outside the graphics window, the line is not displayed beyond the boundary of the window.

DRAW

You can use the DRAW statement to draw a straight line on the screen in any one of the graphics modes (modes 0, 1, 2, 4, 5, 8, 9, 10, 12, 13, 15, 16 and 18). The statement is followed by the X and Y coordinates of the end of the line.

The start of the line is the current graphics cursor position. This is either the end of the last line drawn or a point specified by a MOVE statement.

The line is drawn in the current graphics foreground colour. This colour can be changed using the GCOL statement (see earlier).

DRAW x,y

MOVE 200,300
DRAW 640,800
The DRAW statement is identical to PLOT 5.

MOVE

You can move the graphics cursor to an absolute position without drawing a line with the MOVE statement.
MOVE X,Y
MOVE 124,327
The MOVE statement is identical to PLOT 4.

PLOT

PLOT is a multi-purpose drawing statement. Three numbers follow the PLOT statement: the first specifies the type of point, line or shape to be drawn; the second and third give the X and Y coordinates to be used.
PLOT mode,X,Y
Lines are drawn from the current graphics cursor position (the last point 'visited') to the specified X,Y coordinates.

As previously described, the two most commonly used statements, PLOT 4 and PLOT 5, have the duplicate keywords MOVE and DRAW.

The available PLOT modes are listed on the following pages.

Basic Modes

 Mode Action
0 Move relative to the last point.
1 Draw a line, in the current graphics foreground colour, relative to the last point.
2 Draw a line, in the logical inverse colour, relative to the last point.
3 Draw a line, in the background colour, relative to the last point.
4 Move to the absolute position.
5 Draw a line, in the current foreground colour, to the absolute coordinates specified by X and Y.
6 Draw a line, in the logical inverse colour, to the absolute coordinates specified by X and Y.
7 Draw a line, in the current background colour, to the absolute coordinates specified by X and Y.

Enhanced Modes

Modes 8 to 71

 Mode Action
8-15 As 0-7, except that the last point is plotted twice.
16-31 As 0-15, but the line is drawn dotted.
32-47 As 0-15, but the line is drawn dashed.
48-63 As 0-15, but the line is drawn broken.
64-71 As 0-7, but only a single point is plotted.

Horizontal Line Fill to Non-background

Modes 72 to 79

The graphics cursor first moves to the specified coordinate (relative or absolute). Next it moves left until the first non-background pixel is encountered. Then it moves right until the first non-background pixel is encountered. Finally, a line is drawn between these two points

If the PLOT number is 73 or 77, the line is drawn in the current foreground colour. If the PLOT number is 72 or 76, the cursor movements are made, but no line is drawn.

Triangle Plot and Fill

Modes 80 to 87

As 0-7, but plot and fill a triangle. The triangle is formed from the given X,Y coordinates and the previous two points 'visited', however they were specified.

The following example plots and fills the triangle illustrated in the current graphics foreground colour. triangle

MOVE 150,200
MOVE 400,300
PLOT 85,500,150

If the PLOT number is 81 or 85, the triangle is drawn and filled in the current foreground colour.

Horizontal Line Fill to Background Right

Modes 88 to 95

The graphics cursor moves to the specified coordinate. It then moves to the right until the first background coloured pixel is encountered. Finally, a line is drawn between these two points.

If the PLOT number is 91 or 95, the line will be drawn in the current background colour. If the PLOT number is 88 or 92, the cursor movements are made, but no line is drawn.

Rectangle Plot and Fill

Modes 96 to 103

Plot and fill an axis-aligned rectangle. The opposite corners are at the point plotted and the point last 'visited', however it was specified.

The following example plots and fills the rectangle illustrated in the current graphics foreground colour. rectangle

MOVE 150,200
PLOT 101,500,300

If the PLOT number is 97 or 101, the rectangle will be drawn and filled in the current foreground colour.

Horizontal Line Fill to Foreground

Modes 104 to 111

The graphics cursor moves to the specified coordinate. It then moves to the right until the first foreground coloured pixel is encountered. It then moves left until the first foreground coloured pixel is encountered. Finally, a line is drawn between these last two points.

If the PLOT number is 107 or 111, the line will be drawn in the current background colour. If the PLOT number is 104 or 108, the cursor movements are made, but no line is drawn.

Parallelogram Plot and Fill

Modes 112 to 119

Plot and fill a parallelogram whose vertices are defined by the previous two points visited and the point specified. For reference purposes, call the previous two points visited point1 and point2 in order, and the point specified in the PLOT command, point3. The x and y coordinates of the fourth point are calculated by:
point3-point2+point1
The order in which the points are visited is important.

The following example plots and fills the parallelogram illustrated in the current graphics foreground colour. parallelogram

MOVE 150,200
MOVE 250,350
PLOT 117,500,300

If the PLOT number is 113 or 117, the parallelogram will be drawn and filled in the current foreground colour.

Horizontal Line Fill to Non-foreground Right

Modes 120 to 127

The graphics cursor moves to the specified coordinate. It then moves to the right until the first non-foreground coloured pixel is encountered. Finally, a line is drawn between these two points.

If the PLOT number is 123 or 127, the line will be drawn in the current background colour. If the PLOT number is 120 or 124, the cursor movements are made, but no line is drawn.

Flood Fill to Non-background

Modes 128 to 135

Flood fill starting at the given point and continuing until non-background pixels are found. This may fail with a 'No room' error if the area to fill is too complex or the colour being used to fill can itself be filled.

Flood Fill to Foreground

Modes 136 to 143

Flood fill starting at the given point and continuing until foreground pixels are found. This may fail with a 'No room' error if the area to fill is too complex or the colour being used to fill can itself be filled.

Draw Circle

Modes 144-151

Draw a circle on the screen with the origin at the current graphics cursor position. A point on the circumference or the radius of the circle may be specified.

Point on Circumference

If the 'absolute' plot codes (148 to 151) are used the point specified will be on the circumference of the circle. For example,
MOVE x1,y1
PLOT 149,x2,y2
will draw a circle centred on x1,y1 with the point x2,y2 in its circumference.

Radius

If the 'relative' plot codes (144 to 147) are used either of the parameters may be used to specify the radius. For example, either
MOVE x,y
PLOT 145,R,0
or
MOVE x,y
PLOT 145,0,R
will draw a circle of radius R centred about the point x,y.

The shape is drawn 'circular' in terms of graphics units. As previously explained, the shape will be elliptical in modes 15 and 16. The adjustment of the monitor (height, width and linearity) will also affect the shape displayed.

Draw Solid Disc

Modes 152-159

Draw a disc on the screen with its origin at the current graphics cursor position. A point on the circumference or the radius of the disc may be specified in a similar manner to a circle.

If plot codes 156 to 159 are used, the point specified will be on the circumference of the disc. If plot codes 152 to 155 are used, the non-zero parameter is interpreted as the radius of the disc.

Draw Relative

The 'draw relative' commands act relative to the last point plotted. Suppose, for example, the current X and Y coordinates were 200, 300. The command
PLOT 1,0,150
would draw a line in the current graphics foreground colour from 200, 300 to 200,450.

Logical Inverse Colour

Two Colour Modes

 Logical  Inverse 
01
10

Four Colour Modes

 Logical  Inverse 
03
12
21
30

Sixteen Colour Modes

 Logical  Inverse 
015
114
213
312
etc.
123
132
141
150

POINT

The POINT function returns a number giving the logical colour of the screen at the coordinates specified. If the point is outside the graphics window, then -1 is returned.

There must not be a space between POINT and the opening bracket.

colour=POINT(X,Y)
IF POINT(X,Y)=3 THEN 300
You can use POINT to find out the colour of the screen at the specified point and take action accordingly. In an adventure game, for example, the swamps may be marked in green. If the explorer ventured into a green area he must be in the swamp and 'swamp type demons' would be activated.


Windows

Introduction

BBCBASIC(86) writes text to the text window and graphics to the graphics window. The text and graphics windows can overlap. By default, the text and graphics windows are the full size of the screen, but the size and position of the windows may be changed.

The text and graphics windows may be restored to their default state with the VDU 26 command.

The CLS command clears the text window to the current text background colour. The CLG command clears the graphics window to the current graphics background colour with the current graphics background plotting action (set by GCOL). If the text and graphics windows overlap, the background colour of the overlapping area will be set by the last clear command issued.

Text Window

The text origin is the top left-hand corner of the current text window. The reference point for defining a text window is also the top left-hand corner of the screen.

Define Text Window

VDU 28

The VDU 28 command defines a text window. The four bytes following VDU 28 define the X & Y coordinates of the bottom left corner of the window and the X & Y coordinates of the top right corner of the window, in that order. The coordinates are with respect to the screen text origin and are measured in 'character positions'.

If the text cursor is outside the new window, it is moved to the new home position (top left of the window). If it is inside the new window, it is not moved.

If any of the edges of the new text window would be off the screen, the command is ignored.

The following example defines a text window with the bottom left corner at 0,15 (X across, Y down) and the top right corner at 30,3 (X across, Y down).

VDU 28,0,15,30,3

Clear Text Window

The CLS (or VDU 12) command clears the text window to the current text background colour. If you subsequently change the text background colour, the background of each character cell will be set to the new background colour as the character is printed on the screen. When the screen scrolls, the 'empty' line scrolled onto the screen will have the new background colour.

Graphics Window

The graphics origin is initially the bottom left-hand corner of the screen. A graphics window is defined with reference to the current graphics origin. The graphics origin may be set with the VDU 29 command as described later.

Define Graphics Window

VDU 24

In the graphics modes, the VDU 24 command defines a graphics window. The four words (pairs of bytes) following the VDU 24 command are the X & Y coordinates of the bottom left corner of the window and the X & Y coordinates of the top right corner of the window, in that order. The coordinates are with respect to the current graphics origin.

If any of the edges of the new graphics window would be off the screen, the command is ignored. It is particularly easy to select invalid window limits if the graphics origin has been moved. It is advisable, therefore, to precede a VDU 24 command with a VDU 26 command to reset the windows and the graphics origin.

The following example defines a graphics window with the bottom left corner at 200,100 (X,Y) and the top right corner at 500,300 (X,Y).

VDU 24,200;100;500;300;
Note the use of semicolons in this VDU command. Their significance is explained under VDU in the Keywords section.

Clear Graphics Window

The CLG (or VDU 16) command clears the graphics window to the current graphics background colour using the current background plotting action (set by GCOL). If you change the graphics background colour, you will probably not notice a change in the graphics background colour until you next clear the graphics window. However, some of the PLOT modes use the current background colour.

Changing the Graphics Origin

In the graphics modes, VDU 29 moves the graphics origin to the coordinates specified by the following two words (pairs of bytes). The first word specifies the X coordinate of the new origin and the second specifies the Y coordinate. Subsequent graphics commands operate with respect to this origin.

The following example sets the graphics origin to the centre of the screen (except for modes 16 and 18).

VDU 29,640;400;
Note the use of semicolons in this VDU command. Their significance is explained under VDU in the Keywords section.

Resetting Text and Graphics Windows

VDU 26 resets the text and graphics windows to their default positions (filling the whole screen), homes the text cursor to the top left of the screen (0,0), resets the graphics origin to the bottom left of the screen (0,0) and homes the graphics cursor to the graphics origin.

Positioning The Cursor

Text Cursor

The text cursor may be positioned within the text window with the TAB(X,Y) command. For example;
PRINT TAB(10,15)"Fred"
will print the word 'Fred' starting at column 15 of row 10. The top left hand corner of the text window is 0,0.

Graphics Cursor

Within the graphics window, the graphics cursor is positioned by the MOVE, DRAW or PLOT commands.

When printing characters at the graphics cursor position, the top left-hand corner of the character cell is positioned at the graphics cursor position.

Homing The Cursor

In VDU 4 mode, VDU 30 homes the text cursor to the top left corner of the text window. In VDU 5 mode, VDU 30 homes the graphics cursor to the top left corner of the graphics window.


User Defined Characters

Defining a Character

Characters from &80 to &FF (128 to 255) may be programmed using the VDU 23 command. The programmable characters are only available in the graphics modes (0, 1, 2, 4, 5, 8, 9, 10, 12, 13, 15, 16 and 18).

In the EGA and VGA modes (8, 9, 10, 12, 13, 15, 16 and 18), user defined characters programmed with VDU 23 are active only in the VDU 5 mode (plot character at graphics cursor position). In VDU 4 mode, the standard ROM font is used for characters 128 to 255.

The format of the VDU 23 command is;

VDU 23,char_no,r1,r2,r3,r4,r5,r6,r7,r8
'Char_no' is the character number to be programmed and 'r1' to 'r8' are the decimal values of the bytes which define the character, top to bottom. For example, the character illustrated below is defined as character 130 by the following VDU 23 command.
VDU 23,130,24,36,66,255,24,24,24,255

. . . * * . . .		r1 = 24
. . * . . * . .		r2 = 36
. * . . . . * .		r3 = 66
* * * * * * * *		r4 = 255
. . . * * . . .		r5 = 24
. . . * * . . .		r6 = 24
. . . * * . . .		r7 = 24
* * * * * * * *		r8 = 255
Because of hardware limitations, characters up to &7F (127) are not re-programmable.

Since user defined characters occupy a 'cell' which is 8 pixels by 8 pixels, the number of rows of 'VDU 5 mode' text which may be displayed on the screen depends upon the vertical resolution of the display mode in use.

In all modes other than modes 16 and 18, 25 lines of 'VDU 5' text may be displayed. In mode 16, 44 lines of 'VDU 5' text may be displayed. In mode 18, 60 lines of 'VDU 5' text and 30 lines of 'normal' text may be displayed.

Character Dot Pattern

BBCBASIC(86) emulates the BBC Micro OSWORD call which reads the 'dot pattern' of a character. The pattern of both standard and user defined characters may be read using this call.

In order to use the OSWORD call, you need to define a 9 byte area of memory in which the character code is passed and the dot pattern is returned. As with the BBC Micro, the OSWORD function number is passed in A% and the address of the parameter block is passed in X% and Y%. The least significant byte is passed in X% and the most significant in Y%

The following program segment:

  DIM pattern 8
  ?pattern=character
  A%=&A
  X%=pattern MOD 256:Y%=pattern DIV 256
  CALL &FFF1
The character dot pattern is returned in the 8 bytes 'pattern?1' to 'pattern?8'.

The 'Get Character Pattern' function is the only OSWORD call currently available and it is not, therefore, strictly necessary to set A% to the function number. However, doing so makes the program compatible with any future enhancements of BBCBASIC(86).

Double Height Characters

The heart of the following demonstration program is a procedure which accepts a character string and writes it in double height characters to the screen.

The procedure uses the 'Get Character Pattern' OSWORD function to read the dot pattern of each character in the string. This pattern is used to generate two user defined characters; one for the top half of the double height character and the other for the bottom. These two characters are then written to the screen, one below the other.

  10 REM DOUBLE.BBC
  20 :
  30 REM DJM 28 Mar 87
  40 :
  50 REM Prints double height characters in CGA graphics modes
  60 :
Reserve 9 bytes of memory for the parameter block.
  70 DIM ptn 8
  80 :
  90 CLS
 100 :
 110 PRINT TAB(10,5)"This is a test"
 120 PRINT TAB(10,7);
 130 PROC_double("This is a test")
 140 END
 150 :
 160 :
Print the passed string parameter starting at the current text cursor position.
 170 DEF PROC_double(p$)
 180 LOCAL x,y
 190 x=POS:y=VPOS
Set up the OSWORD function number and the address of the parameter block
 200 A%=&A
 210 X%=ptn MOD 256
 220 Y%=ptn DIV 256
For each character in the string
 230 FOR i=1 TO LEN(p$)
Load byte 0 of the parameter block with the ASCII code of the character and call OSWORD.
 240   ?ptn=ASC(MID$(p$,i,1))
 250   CALL &FFF1
Define two double height characters, one for the top half of the character and one for the bottom.
 260   VDU 23,128,ptn?1,ptn?1,ptn?2,ptn?2,ptn?3,ptn?3,ptn?4,ptn?4
 270   VDU 23,129,ptn?5,ptn?5,ptn?6,ptn?6,ptn?7,ptn?7,ptn?8,ptn?8
Print the two characters one below the other.
 280   PRINT TAB(x,y);CHR$(128)
 290   PRINT TAB(x,y+1);CHR$(129)
 300   x=x+1
 310 NEXT

Text Positioning

In any of the graphics modes, text may be written at the text or graphics cursor position.

Text at Graphics Cursor

VDU 5 causes text to be written at the graphics cursor position. It works only in the graphics modes.

As mentioned earlier, if an EGA or VGA mode is selected (mode > 7) user defined characters may only be written at the graphics cursor position. If a CGA mode is selected, user defined characters may be written at either the graphics or text cursor position.

The characters have a 'transparent' background and they are plotted according to the current foreground GCOL rules and colour. VDU 127 (DEL) is an exception; it backspaces and deletes just as it does in the normal text mode using the current background GCOL colour and action.

In the graphics modes, characters may be positioned at any graphics coordinate within the graphics window. The top left of the character cell is the reference point. Characters are clipped to the limits of the graphics window if necessary. No scrolling takes place.

Text at Text Cursor

VDU 4 causes text to be written at the text cursor position in the normal way. This is the default mode

The characters are 'opaque' and they can be positioned only at text coordinates within the text window. The text within the window scrolls as necessary.

User defined characters may only be written at the text cursor position if a CGA mode (mode < 8) is selected.

Current Character

BBCBASIC(86) emulates the BBC Micro OSBYTE call which reads the ASCII code of the character at the current text cursor position.

The ASCII code of the character at the current text cursor position is returned and assigned to a variable called 'char' by the following program segment.

A%=&87
char=(USR(&FFF4) AND &FF00) DIV 256
The 'Read Character' function is the only OSBYTE function currently available and it is not, therefore, strictly necessary to set A% to the function number. However, doing so makes the program compatible with any future enhancements of BBCBASIC(86).

Left CONTENTS

CONTINUE Right


Best viewed with Any Browser Valid HTML 3.2!
© Doug Mounter and Richard Russell