VDU Emulator

Introduction

On the BBC Microcomputer and Acorn Archimedes the VDU commands perform a number of important actions, primarily involving the screen display and graphics. Although not strictly part of BASIC, most of these commands have been emulated in the TI-83+ port of BBC BASIC (Z80).

The VDU statement takes a list of numeric arguments (constants or variables) and sends their least significant bytes as characters to the currently selected output stream.

A 16 bit value (word) can be sent if the value is followed by a semi-colon. It is sent as a pair of characters, the least significant byte first.

VDU Commands

VDU 0

VDU 0 does absolutely nothing. In other words, it is ignored.

VDU 4

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

Characters can be positioned only at text coordinates within the text viewport; the text viewport scrolls as necessary. Characters are written using the current text foreground colour on an opaque background of the current text background colour (see COLOUR).

VDU 5

VDU 5 causes text to be written at the graphics cursor position.

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

Characters are plotted using the current graphics foreground colour and in the current graphics foreground plotting mode (see GCOL).

The character background is 'transparent', i.e. it does not change what was previously displayed underneath. VDU 127 (DEL) is an exception; it backspaces and deletes just as it does in the normal text mode, using the current background GCOL rules and colour.

VDU 8

VDU 8 moves the text cursor left one character. If the cursor moves outside the text viewport it is moved back to the rightmost column and up a line.

VDU 9

VDU 9 moves the text cursor right one character. If the cursor moves outside the text viewport it is moved back to the leftmost column and down a line.

VDU 10

VDU 10 moves the text cursor down one line. By default, if the cursor was on the bottom line of the text viewport, the viewport scrolls up (except in VDU 5 mode). The cursor is constrained to remain within the text viewport.

VDU 11

VDU 11 moves the text cursor up one line. If the cursor was on the top line of the text viewport, the viewport scrolls down (except in VDU 5 mode). The cursor is constrained to remain within the text viewport.

VDU 12

VDU 12 clears the text viewport to the current text background colour and moves the text cursor the top-left corner of the text viewport; it is identical to CLS.

VDU 13

VDU 13 moves the text cursor to the the left edge of the text viewport.

VDU 14

VDU 14 enables auto-paging mode. In this mode outputting to the console is paused once the text viewport has been filled until the 2nd key is pressed.

VDU 15

VDU 15 disables auto-paging mode. This is the default condition.

VDU 16

VDU 16 clears the graphics viewport using the current background GCOL colour. It does not move the graphics cursor. VDU 16 is identical to CLG.

VDU 17

VDU 17 is identical to COLOUR. The next byte determines the text foreground or background colour.

VDU 18

VDU 18 is identical to GCOL. It takes the next two characters as the plotting mode and graphics colour respectively.

VDU 20

VDU 20 sets the text and graphics foreground and background to their default logical colours and plotting modes. This action is the same as issuing the commands:

COLOUR 0
COLOUR 255
GCOL 0,0
GCOL 0,255

VDU 22

VDU 22 is identical to MODE, except that MODE zeros the value of COUNT whereas VDU 22 does not. The mode is set according to the value of the byte following the VDU 22 command. The example below sets mode 3.

VDU 22,3

VDU 22 also resets all the screen driver variables (colour, palette, viewports, cursor position, graphics origin, etc). In particular, VDU 22 performs the actions of VDU 4, VDU 12, VDU 20 and VDU 26.

See the MODE keyword for further details.

VDU 23

Changing the appearance of the letter 'O'.

VDU 23 can be used to create user-defined characters, show or hide the text cursor or scroll the display.

User-defined characters

Characters from &20 to &FF (32 to 255) may be programmed using the VDU 23 command. User-defined characters can only be used in modes using 8×8 pixel characters - see the MODE statement for more information.

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 values of the bytes which define the character, top to bottom.

You can calculate the eight bytes of data that define the character using a grid similar to the one shown above. For each row in the character, take any pixel that is "on" (black), and add up the corresponding values taken from the column headers. For example, the first, fifth, sixth, seventh and eigth pixel are set in the third row of the ball image above. Adding up the column headers &80+&08+&04+&02+&01 yields a value of &8F for that row.

VDU 23,ASC"O",&3C,&5E,&8F,&DF,&FF,&FF,&7E,&3C

You can reset characters to their original value with the *RESETCHR command.

Text cursor control

The text cursor (caret) may be disabled and enabled using the VDU 23 command as shown below.

VDU 23,1,0;0;0;0; : REM Disable cursor
VDU 23,1,1;0;0;0; : REM Enable cursor

The text cursor is disabled in VDU 5 and is automatically re-enabled when changing MODE.

Scrolling the window

The contents of BASIC's output window (or just the current text viewport) can be scrolled, by one character width or height, using VDU 23,7:

VDU 23,7,m,d,0;0;0;

where m and d are as follows:

The cursor is not repositioned after the screen has been scrolled.

VDU 24

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

It is particularly easy to select invalid viewport limits if the graphics origin has been moved. It is advisable, therefore, to precede a VDU 24 command with a VDU 29,0;0; command to reset the graphics origin.

The following example defines a graphics viewport with the bottom left corner at 100,50 and the top right corner at 250,150.

VDU 24,100;50;250;150;
VDU 24,left;bottom;right;top;

Be very careful not to omit the final semicolon.

VDU 25

VDU 25 is identical to the PLOT statement. See the Graphics section or the keyword PLOT for more details.

VDU 25,mode,x_coord;y_coord;

The following example draws a line in the current foreground colour to the point 35,52:

VDU 25,5,35;52;

VDU 26

VDU 26 resets the text and graphics viewports 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 top-left of the screen (0,0) and moves the 'current point' to the graphics origin.

VDU 27

VDU 27 sends the next byte to the screen without interpreting it as a control character. It allows graphics characters corresponding to VDU 0 to VDU 31 and VDU 127 to be displayed.

VDU 28

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

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

The following example defines a text viewport with the bottom-left corner at X=0, Y=5 and the top-right corner at X=20, Y=3.

VDU 28,0,5,20,3
VDU 28,left,bottom,right,top

VDU 29

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 (48,32):

VDU 29,48;32;

VDU 30

In VDU 4 mode, VDU 30 homes the text cursor to column 0, row 0 (the top-left corner of the text viewport). In VDU 5 mode, VDU 30 homes the graphics cursor to the top-left corner of the graphics viewport.

VDU 31

VDU 31 is identical to PRINT TAB(x,y). It positions the text cursor according to the following two bytes, the first determining the column number and the second the row number. The example below positions the text cursor in column 5 and row 3.

VDU 31,5,3

See the keyword TAB for further details.

VDU 31,col,row

VDU 127

VDU 127 deletes the character to the left of the cursor and backspaces the cursor to this position.