First Steps in Programming
RISC OS Computers
Martyn Fox

Appendix 2 : VDU codes

The VDU command sends the numbers or values of variables which follow it to the screen. Numbers between 32 and 126 are ASCII codes for characters which are printed on the screen. Code 127 is backspace and delete. Numbers above 127 also produce characters on the screen.

VDU codes below 32 have various control functions and are explained in this appendix.

VDU   Purpose
0   Does nothing
1   Sends the next character to the printer only
2   Turns on printer
3   Turns off printer
4   Selects text cursor for text printing
5   Selects graphics cursor for text printing
6   Turns on the VDU drivers
7   Produces a beep
8   Moves cursor back one space
9   Moves cursor forwards one space
10   Moves cursor down one line
11   Moves cursor up one line
12   Clears the screen or text window
13   Moves the cursor to the start of the line
14   Selects paged mode
15   Turns off paged mode
16   Clears the graphics window
17   Sets the text colour
18   Sets the graphics colour
19   Redefines logical colour 1
20   Resets default colours
21   Turns off VDU drivers
22   Changes screen mode
23   Miscellaneous VDU commands
24   Sets the graphics window
25   PLOT command
26   Resets text and graphics window to cover the entire screen
27   Does nothing
28   Sets the text window
29   Moves the graphics origin
30   Moves the text cursor to its home position
31   Moves the text cursor

VDU 0

Does nothing.

VDU 1

The next VDU character is sent to the printer only and not to the screen. The printer must have already been turned on with VDU 2.

Printers frequently use sequences of codes beginning with an escape character, which is sent as number 27. If these numbers were also sent to the screen, VDU 27 would do nothing but the following characters may cause havoc.

A printer may, for example, use a sequence consisting of Esc E, meaning 'Set emphasised mode'. This would be sent as 27, followed by 69 which, if sent to the screen, would display an unwanted 'E'. This may be prevented by using:

    VDU 1,27,1,69

VDU 2

Turns on the printer. Anything sent to the screen will also be sent to the printer.

VDU 3

Turns off the printer, cancelling the effect of VDU 2.

VDU 4

Text is printed at the text cursor position with the text foreground colour. This is the usual situation. This call cancels the effect of VDU 5.

VDU 5

Text is printed at the graphics cursor position using the graphics foreground colour which is set by GCOL. The text position is set with a MOVE command, not a TAB command.

VDU 6

Turns on output to the screen. This cancels the effect of VDU 21.

VDU 7

Produces a beep.

VDU 8

Moves the cursor back one space. This does not delete the previous character, but positions the cursor under it.

VDU 9

Moves the cursor forwards one space.

VDU 10

Line Feed. Moves the cursor down one line.

VDU 11

Moves the cursor up one line.

VDU 12

If VDU 5 mode is not set, this call clears the text window (or whole screen, if it isn't set) to the text background colour (CLS).

If VDU 5 mode is set, the call clears the graphics window (or whole screen, if not set) to the graphics background window (CLG).

VDU 13

Carriage Return. The cursor is moved back to the beginning of the line which it is on. This is usually accompanied by a line feed (VDU 10) to move the cursor down one line.

VDU 14

Puts the screen into page mode, which limits scrolling to less than one screen height. The scrolling action then waits for Shift to be pressed.

VDU 15

Turns off page mode, cancelling VDU 14.

VDU 16

Clears the graphics window (CLG).

VDU 17+1 character

Sets the text colour.

VDU 17,2 is the equivalent of COLOUR 2.

VDU 18+2 characters

Sets the graphics colour and the way graphics appear on the screen.

VDU 18,0,3 is the equivalent of GCOL 0,3.

VDU 19+5 characters

Redefines the colour palette.

This command takes the form VDU 19,col%,action%,red%,green%,blue%.

For action% values between 0 and 15, red%, green% and blue% are not used. Colour col% is redefined as colour action%. This is the equivalent of COLOUR col%,action%.

If action% is 16, colour col% is redefined in terms of red%, green% and blue%. This is the equivalent of COLOUR col%,red%,green%,blue%.

VDU 20

Puts all colours back to normal. This cancels out the effect of VDU 19.

VDU 21

Prevents character output from reaching the screen until VDU 6 is sent.

Characters will still be sent to the printer if it has already been turned on with VDU 2.

VDU 22+1 character

Changes screen mode.

VDU 22,12 is equivalent to MODE 12.

VDU 23+9 characters

Miscellaneous commands. The first byte following VDU 23 determines which action is carried out - the remaining eight bytes carry the necessary data.

Many of these commands are outside the scope of this guide. The following, though, are of interest:

VDU 23,1,action%,0,0,0,0,0,0,0

Controls the appearance of the cursor:

action%   Cursor appearance
0   Cursor turned off
1   Cursor turned on
2   Cursor does not flash
3   Cursor flashes

VDU 23,17,5,0,0,0,0,0,0,0

Exchanges text foreground and background colours. A second call changes them back again.

VDU 23,32 to 255, + 8 characters

Redefines the shapes of characters.

Each text character consists of a rectangle measuring eight pixels in either direction. Any character can be redefined by this call, by changing which pixels have the foreground colour and which have the background.

The number immediately following VDU 23 is the ASCII code for the character to be redefined. Each of the eight numbers following contains the pattern for one row of pixels, from top to bottom. In each number, the least significant bit sets the state of the right-hand pixel and the most significant bit the state of the left-hand pixel.

For example, VDU,23,128,24,60,90,153,24,24,24,24 will redefine the character with ASCII code 128 to be an arrow pointing upwards. VDU 128 will plot it on the screen.

an arrow pointing upwards

This technique was used by earlier Acorn computers such as the BBC Model B to produce user-defined graphics. It has been superseded in 32-bit machines by the use of sprites.

VDU 24+8 characters

Defines the graphics window.

Each coordinate is specified by two bytes - the coordinate MOD 256 followed by the coordinate DIV 256. These may be sent as one number by following it with a semi-colon (;).

For example, VDU 24,300;200;800;600; consists of a total of nine bytes. This call defines a graphics window whose bottom left-hand corner is at (300,200) and whose top right-hand corner is at (800,600).

VDU 25+5 characters

PLOT command.

The first byte after VDU 25 contains the PLOT code. The remaining four specify the x and y coordinates in pairs. Each pair may be given as one number followed by a semi-colon, as in VDU 24.

For example, VDU 25,85,400;500; will plot a filled triangle between (400,500) and the previous two locations of the graphics cursor.

See Appendix 3 for a full list of PLOT codes.

Although VDU 25 may be used for a PLOT command in this way, it is actually much quicker to use Basic's PLOT instruction. The VDU method requires six calls to the operating system - PLOT does it in one call, using a special software interrupt or SWI (see section 14).

VDU 26

Reset both text and graphics windows to cover the entire screen.

This cancels the effect of VDU 24 and VDU 28.

VDU 27

Does nothing.

VDU 28+4 bytes

Redefines the text window.

For example, VDU 28,5,25,45,10 defines the text window as having its bottom left-hand corner five spaces in from the left and 25 rows down from the top, and its top right-hand corner 45 spaces in from the left and 10 rows down from the top.

VDU 29+4 bytes

Changes the position of the graphics origin. The four bytes following VDU 29 contain the x and y coordinates in pairs. Each pair may be given by one number followed by a semi-colon (;) as in VDU 24.

For example, VDU 29,500;400; will redefine the graphics origin (0,0) to be the point on the screen that was originally (500,400).

VDU 30

Moves the text cursor to its 'home' position in the top left-hand corner of the screen. If VDU 5 operation is in force, the graphics cursor is moved to this position instead.

VDU 31+2 bytes

Position the text cursor.

For example, VDU 31,20,10 is the equivalent of TAB(20,10) in a PRINT command and will cause the next text character to be displayed 20 spaces in from the left and 10 rows down from the top.

previousmain indexnext

 
© Martyn & Christine Fox 2003