VDU

From BeebWiki
Revision as of 15:34, 30 July 2010 by Jgharston (talk) (Added BASIC I/O category.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

VDU is a BASIC statement to send characters to the screen, printer, serial port or other output device. It is usually used to generate VDU sequences that control the display.

VDU
Availability Present in all original versions of BBC BASIC.
Syntax BASIC I-III VDU <numeric>{,|;<numeric>}[;]
BASIC IV-V VDU<numeric>{,|;||<numeric>} [;||]
Token (hex) BASIC I-V EF (statement)
Description BASIC I-V Sends the <numeric> arguments as little-endian character pairs (if followed by ;) or single characters (otherwise) to OSWRCH, thereby printing them.
In BASIC V, a <numeric> followed by a vertical bar | prints the character followed by nine NULs.
Associated keywords CHR$

Description

VDU is a versatile statement to control features of the BBC Micro's display that do not have their own BASIC keywords -- and a few that do. It can also be used to send binary data to the printer, serial port, *SPOOL file or any other device attached to the output stream.

A VDU statement is equivalent to PRINTing a string of CHR$ functions. The only exception is that PRINT increases COUNT whereas VDU does not.

All the facilities of VDU are available to machine code programs as it is just a veneer for the MOS routine, OSWRCH.

VDU interprets each of the <numeric> values following the keyword as an ASCII value. Any value between 0 and 255 inclusive is accepted, and maps to a unique character. If the <numeric> is followed by a semicolon ; then the value is a little-endian word from 0 to 65535 inclusive. It is broken down into two ASCII values; first the word value MOD 256, then its value DIV 256. This word syntax is useful for graphics coordinates or for crunching BASIC programs.

In BASIC IV onwards, if the <numeric> is followed by a vertical bar | then the <numeric> is treated as a single ASCII value, followed by nine ASCII values of zero. This ensures that the current VDU sequence is completed as the longest sequence length is nine characters. It is a useful shorthand to fill in the trailing zeroes of VDU 23 commands.

In each case, the ASCII value or values are sent to OSWRCH one at a time. From there they are delivered to the output device or devices. Beware as certain characters are blocked from going to the printer. See VDUCHR and OSBYTE &06.

VDU commands

The commands in the list below are provided by the MOS, not by BASIC. They are only of interest to VDUCHR, the screen driver routine that is part of OSWRCH. The attached printer or serial device may have its own meanings for these commands, although VDUCHR may still be listening and can affect the flow of characters to the printer.

VDUCHR parses the incoming characters looking for these commands. When it finds one it opens a VDU sequence or VDU queue to collect the required number of extra bytes (if any), then executes the command it forms. While a VDU queue is open, all incoming characters go into the queue and do not have their usual effect on the screen.

The table is based on the B+ User Guide:

VDU commands
Hex Decimal CTRL ASCII abreviation Bytes extra Meaning
&00 0 @ NUL 0 Does nothing
&01 1 A SOH 1 Send next character to printer only
&02 2 B STX 0 Start print job
&03 3 C ETX 0 End print job
&04 4 D EOT 0 Write text at text cursor
&05 5 E ENQ 0 Write text at graphics cursor
&06 6 F ACK 0 Enable VDU drivers
&07 7 G BEL 0 Make a short beep
&08 8 H BS 0 Backspace cursor one character
&09 9 I HT 0 Advance cursor one character
&0A 10 J LF 0 Move cursor down one line
&0B 11 K VT 0 Move cursor up one line
&0C 12 L FF 0 Clear text area (CLS)
&0D 13 M CR 0 Move cursor to start of current line
&0E 14 N SO 0 Page mode on
&0F 15 O SI 0 Page mode off
&10 16 P DLE 0 Clear graphics area (CLG)
&11 17 Q DC1 1 Define text colour (COLOUR n)
&12 18 R DC2 2 Define graphics colour (GCOL a,n)
&13 19 S DC3 4 Define logical colour (COLOUR l,p and COLOUR l,r,g,b)
&14 20 T DC4 0 Restore default logical colours
&15 21 U NAK 0 Disable VDU drivers or delete current line
&16 22 V SYN 1 Select screen mode (MODE)
&17 23 W ETB 9 Define display character and other commands (used by ON and OFF)
&18 24 X CAN 8 Define graphics window
&19 25 Y EM 5 PLOT K,x,y (used by MOVE, DRAW and other statements)
&1A 26 Z SUB 0 Restore default windows
&1B 27 [ ESC 0 Does nothing
&1C 28 \ FS 4 Define text window
&1D 29 ] GS 4 Define graphics origin (ORIGIN)
&1E 30 ^ RS 0 Home text cursor to top left
&1F 31 _ US 2 Move text cursor to x,y (PRINT TAB(x,y);)
&7F 127 n/a DEL 0 Backspace and delete