Contents / Reference section / Previous chapter / Next chapter / Index
The statement VDU X is equivalent to PRINT CHR$(X); and the statement VDU X,Y,Z is equivalent to
PRINT CHR$(X); CHR$(Y); CHR$(Z);.
However the VDU statement finds most common use when generating ASCII control codes and a detailed description of the effect of each control code is given in this chapter. The control codes are interpreted by part of the Machine Operating System called the VDU driver.
Those writing BASIC programs will need to refer to this summary of the VDU drivers if they wish to use some of the more advanced facilities such as definition of graphic and text windows. Those writing other high level languages or machine code programs will also need to refer to this section.
The VDU drivers are part of the "Machine Operating System" (MOS) software. All high level languages (including BASIC) use them to print and draw on the screen. Because they are so extensive and easily accessible to programmers it will be easy to ensure that all high level languages and smaller assembly language programs have access to the same graphics facilities. There is no need for the user to write special routines to handle the screen display.
The BBC Microcomputer is designed so that it can be expanded in many ways. All expansions will be compatible with the current Machine Operating System and it is very important that those writing software use the facilities provided. In a "twin-processor" machine the only access to the screen memory is via the "Tube" and use of these VDU drivers and other Machine Operating System features will ensure that code will work correctly whether executed in the Input/Output processor or in the Language processor.
The VDU drivers interpret all 32 ASCII control character codes. Many of the ASCII control codes are followed by a number of bytes. The number of bytes which follow depends on the function to be performed. The table opposite summarises all the codes and gives the number of bytes which follow the ASCII control code.
Decimal | Hex | CTRL | ASCII abbrev. | Bytes extra | Meaning |
---|---|---|---|---|---|
0 | 0 | @ | NUL | 0 | does nothing |
1 | 1 | A | SOH | 1 | send next character to printer only |
2 | 2 | B | STX | 0 | enable printer |
3 | 3 | C | ETX | 0 | disable printer |
4 | 4 | D | EOT | 0 | write text at text cursor |
5 | 5 | E | ENQ | 0 | write text at graphics cursor |
6 | 6 | F | ACK | 0 | enable VDU drivers |
7 | 7 | G | BEL | 0 | make a short beep |
8 | 8 | H | BS | 0 | backspace cursor one character |
9 | 9 | I | HT | 0 | forwardspace cursor one character |
10 | A | J | LF | 0 | move cursor down one line |
11 | B | K | VT | 0 | move cursor up one line |
12 | C | L | FF | 0 | clear text area |
13 | D | M | CR | 0 | move cursor to start of current line |
14 | E | N | SO | 0 | page mode on |
15 | F | O | SI | 0 | page mode off |
16 | 10 | P | DLE | 0 | clear graphics area |
17 | 11 | Q | DC1 | 1 | define text colour |
18 | 12 | R | DC2 | 2 | define graphics colour |
19 | 13 | S | DC3 | 5 | define logical colour |
20 | 14 | T | DC4 | 0 | restore default logical colours |
21 | 15 | U | NAK | 0 | disable VDU drivers or delete current line |
22 | 16 | V | SYN | 1 | select screen mode |
23 | 17 | W | ETB | 9 | re-program display character |
24 | 18 | X | CAN | 8 | define graphics window |
25 | 19 | Y | EM | 5 | PLOT K,x,y |
26 | 1A | Z | SUB | 0 | restore default windows |
27 | 1B | [ | ESC | 0 | does nothing |
28 | 1C | \ | FS | 4 | define text window |
29 | 1D | ] | GS | 4 | define graphics origin |
30 | 1E | ^ | RS | 0 | home text cursor to top left |
31 | 1F | _ | US | 2 | move text cursor to x,y |
127 | 7F | none | DEL | 0 | Backspace and delete |
The ASCII control codes work as follows:
VDU1,14
or by pressing CTRL A and then CTRL N. This code also enables the "printer ignore" character selected by *FX 6 to be sent to the printer.
/li>PRINT TAB(5,10);
and the graphics cursor is controlled with statements like
MOVE700,450
Once the statement VDU 5 has been given only one cursor is active (the graphics cursor). This enables text characters to be placed at any position on the screen. There are a number of other effects: Text characters overwrite what is already on the screen so that characters can be superimposed; text and graphics can only be written in the graphics window and the colours used for both text and graphics are the graphics colours. In addition the page no longer scrolls up when at the bottom of the page. Note however that POS and VPOS still give you the position of the text cursor. See page 172 for more information.
/li>The first byte specifies the mode of action as follows:
0 | Plot the colour specified |
1 | OR the specified colour with that already there |
2 | AND the specified colour with that already there |
3 | Exclusive-OR the specified colour with that already there |
4 | Invert the colour already there |
The second byte defines the logical colour to be used in future. If the byte is greater than 127 then it defines the graphics background colour (modulo the number of colours available). If the byte is less than 128 then it defines the graphics foreground colour (modulo the number of colours available).
/li>MODE 5
COLOUR 1
will print all text in colour 1 which is red by default. However the addition of
VDU 19,l,4,0,0,0 or VDU 19,l,4;0;
will set logical colour 1 to actual colour 4 (blue). The 3 zeros after the actual colour in the VDU 19 statement are for future expansion.
In MODE 5 there are four colours (0,1,2 and 3). An attempt to set colour 4 will in fact set colour 0 so the statement
VDU 19,4,4,0,0,0 or VDU 19,4,4;0;
is equivalent to
VDU 19,0,4,0,0,0 or VDU 19,0,4;0;
we say that logical colours are reduced modulo the number of colours available in any particular mode.
Note: In the television series 'The Computer Programme', an attractive way of listing programs was produced by using MODE 6 and VDU 19,0,4,0,0,0.
/li>Two colour modes
0 =black
1=white
Four colour modes
0=black
1=red
2= yellow
3= white
Sixteen colour modes
0=black
1=red
2=green
3=yellow
4=blue
5= magenta
6=cyan
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
/li>ASCII codes 0 to 31 are interpreted as VDU control codes - and this chapter is explaining the exact function of each. Thus the full ASCII set consists of all the VDU control codes, all the normal printable characters and a user defined set of characters.
For example if the user wishes to define ASCII code 240 to be a small triangle then the following statement would have to be executed
character to be re-defined |
VDU23, | 240, | 1,3,7,15,31,63,127,255 |
redefine character | 8 numbers giving the contents of each row of dots that makes up the desired character |
Note that you cannot define your own characters in MODE 7.
See page 171 for a more detailed explanation.
As explained above the user may define any ASCII code in the range 224 to 255. To display the resultant shape on the screen the user can type
PRINT CHR$(240) or
VDU 240
In the unlikely event of the user wishing to define more than the 32 characters mentioned above (ASCII 224 to 255) it will be necessary to allocate more RAM for the purpose. This is described on page 427
A second use of VDU 23 is to permit the advanced programmer to alter the contents of the 6845 CRTC circuit. (See page 77 for cursor control.) If the user wishes to place value X in register R this can be done with the command.
VDU 23,0,R,X,0,0,0,0,0,0
The user is cautioned not to do this unless he understands how to program the 6845. Note however that when writing to register 7 (V Sync. Posn.) or register 8 (Interlace) of the 6845, any offset that has been set up with the *TV statement (page 435) will be used to adjust the value sent to R7.
/li>Thus the co-ordinates of A would be approximately 1000,200.
When defining a graphics window four co-ordinates must be given; the left, bottom, right and top edges of the graphics area. Suppose that we wish to confine all graphics to the area shown below.
The left hand edge of the graphics area has an X value of (about) 150. The bottom of the area has a Y value of 300. The right hand side has X=1100 and the top has Y=700. The full statement to set this area is
VDU 24,150;300;1100;700;
Notice that the edges must be given in the order left X, bottom Y, right X, top Y and that when defining graphics windows the numbers must be followed by a semi-colon.
For those who wish to know why trailing semi-colons are used the reason is as follows: X and Y graphic co-ordinates have to be sent to the VDU software as two bytes since the values may well by greater than 255. The semi-colon punctuation in the VDU statement sends the number as a two byte pair with low byte first followed by the high byte.
/li>VDU 25,4,100;500;
would move to absolute position 100,500.
The above is completely equivalent to
VDU 25,4,100,0,244,1
X Y
/li>VDU 28,leftX,bottomY,rightX,topY
where | leftX | sets the left hand edge of the window |
bottomY | sets the bottom edge | |
rightX | sets the right hand edge | |
topY | sets the top edge |
For the example shown the statement would be
VDU 28,5,20,30,12
Note that the units are character positions and the maximum
values will depend on the mode in use. The example above refers to MODE 1 and MODE 4. In MODES 2 and 5 the maximum values would be 19 for X and 31 for Y.
since these modes have only 20 characters per line
/li>To move the origin to the centre of the screen the statement
VDU 29,640;512;
should be executed. Note that the X and Y values should be followed by semi-colons. See the entry for VDU 24 if you require an explanation of the trailing semi-colons. Note also that the graphics cursor is not affected by VDU 29.
/li>Thus to move the text cursor to the centre of the screen in MODE 7 one would execute the statement
VDU 31,20,12
Note that the maximum values of X and Y depend on the mode selected and that both X and Y are measured from the edges of the current text window not the edges of the screen.
The remaining ASCII characters work as follows:
32-126 These codes generate the full set of letters and numbers in the ASCII set. See the ASCII codes on pages 486 to 492. 127 This code moves the text cursor back one character and deletes the character at that position. VDU 127 has exactly the same effect as the DELETE key.
128-223 These characters are normally undefined and will produce random shapes (see pages 384 and 427).
224-255 These characters may be defined by the user using the statement VDU 23. It is thus possible to have 32 user defined shapes such as
§ / VDU 23,224,8,28,28,107,127,107,8,28
¨ / VDU 23,225,8,28,62,127,62,28,8,0 0
© / VDU 23,226,54,127,127,127,62,28,8,0
ª / VDU 23,227,8,28,62,127,127,127,28,62
Note: on machines with operating systems after version 1.0, you can use a *FXcommand which will then allow you to define characters 128 to 159 rather than 224 to 255. This has the advantage that you will then be able to use the new characters easily by holding down the SHIFT key while pressing one of the user definable (red) keys (see page 439). To discover which version of the operating system you have, type
*FX 0 RETURN