RTR logo

BBC BASIC for Windows

BBC BASIC for SDL 2.0

MODE 7 - Teletext



Introduction to MODE 7

MODE 7 is unique amongst the modes provided by BBC BASIC, as it was on the original BBC Microcomputer. MODE 7 is a text-only mode (although low-resolution block graphics are available) and has 25 rows each of 40 characters. Each of these characters can be a conventional alphanumeric symbol or a 'control code'; control codes (usually) display as spaces but affect the attributes (e.g. colour) of subsequent characters on the row.

MODE 7 is compatible with the Videotex (Viewdata) and Teletext formats, and uses the same control codes. The only difference is that the 'start box' and 'end box' control codes, which in the case of a Teletext display allow text to be superimposed on a television picture, are not implemented.

Implementation

On the BBC Micro, MODE 7 was implemented in hardware using the SAA5050 chip. PC compatibles have no comparable hardware, so BBC BASIC emulates the SAA5050 chip in software. With the exception of the 'start box' and 'end box' control codes, all the Videotex display features are implemented, as specified in the Broadcast Teletext Specification (September 1976). These include colour, graphics (contiguous and separated), background colour, flashing, double-height (text and graphics) and held-graphics.

Character set (MODE 7)

The full Videotex (UK) character set is supported. Those characters not having an equivalent in the ASCII set are obtained from the keys listed below. Note particularly that the code normally corresponding to backslash (and used by Windows™ as a directory delimiter) displays as the fraction ½:
SymbolKey
left arrow[
right arrow]
up arrow^
½\
¼{
¾}
_ (underscore)
÷~ (tilde)
£` or £
|||
small blockCTRL-backspace

As with the BBC Micro, the codes for # (hash) £ (pound) and _ (underscore) are 'shuffled' so as to display as expected, rather than using the Videotex codes. To force use of the standard Videotex codes (such as would be required for displaying a Teletext page) set bit 7 of the stored characters, i.e. add 128 to their normal ASCII values.

Control codes

Control codes can be written to the screen using PRINT CHR$ or VDU in the usual way, but an alternative is to incorporate them in a constant (quoted) string. To enter a control code into a constant string hold down the Alt key and type a four digit decimal value on the numeric keypad. For example, to enter the code for yellow text hold down Alt, type 0131 on the numeric keypad, then release Alt.

So to write some yellow text you could do any of the following:

MODE 7
PRINT CHR$131;"Yellow text"
VDU 131 : PRINT "Yellow text"
PRINT "•Yellow text"
where the symbol corresponds to that obtained by entering Alt-0-1-3-1.

Normally control codes display as a space (in the current background colour) but see the Held graphics section for exceptions. Control codes affect subsequent characters in the row; all rows start off as steady, single-height alphanumeric white characters on a black background.

Control codes summary

CodeAttribute
129alphanumeric red
130alphanumeric green
131alphanumeric yellow
132alphanumeric blue
133alphanumeric magenta
134alphanumeric cyan
135alphanumeric white
136flash
137steady
140normal height
141double height
145graphics red
146graphics green
147graphics yellow
148graphics blue
149graphics magenta
150graphics cyan
151graphics white
152conceal
153contiguous graphics
154separated graphics
156black background
157new background
158hold graphics
159release graphics
BBC BASIC for Windows v6.14a or later, or BBCSDL, only:
128alphanumeric black
144graphics black
155toggle between character sets
Codes 128, 144 and 155 must be enabled using VDU 23,18,3,1;0;0;0; (and disabled using VDU 23,18,3,0,0;0;0;). See the MODE7LIB library for details of how to change the character sets; every row starts in the primary character set.

Coloured text (MODE 7)

By default text displays as white characters on a black background. You can change the text colour by using one of the following control codes:
128black text (only if enabled with VDU 23,18,3,1;0;0;0;)
129red text
130green text
131yellow text
132blue text
133magenta text
134cyan text
135  white text
MODE 7
PRINT CHR$130;"Green text"

Background colour (MODE 7)

The background colour is normally black. To change the background colour you must first select the required colour as the current text (or graphics) colour, then insert the new background control code 157.

For example to select a blue background you can insert code 132 followed by code 157 (which will together occupy two consecutive character positions on the screen). Remember to change the text colour back to something different, since blue text on a blue background isn't very useful!

MODE 7
PRINT CHR$132;CHR$157;CHR$131"Yellow text on blue background"
To switch back to a black background insert control code 156.

Block graphics

The graphics capability in MODE 7 is limited to low-resolution block graphics, where each character cell is occupied by six small blocks in an arrangement of two columns by three rows. For obvious reasons these blocks are sometimes referred to as sixels. To select a graphics mode insert one of the following control codes:
144black graphics (only if enabled with VDU 23,18,3,1;0;0;0;)
145red graphics
146green graphics
147yellow graphics
148blue graphics
149magenta graphics
150cyan graphics
151  white graphics
Once a graphics mode is selected each of the 64 possible patterns of sixels corresponds to an alphanumeric character code. The following table shows the correspondence between each code and the displayed graphic:

160 161 162 163 164 165 166 167
168 169 170 171 172 173 174 175
176 177 178 179 180 181 182 183
184 185 186 187 188 189 190 191
224 225 226 227 228 229 230 231
232 233 234 235 236 237 238 239
240 241 242 243 244 245 246 247
248 249 250 251 252 253 254 255

As with control codes, these character codes can be entered with PRINT CHR$, VDU or by holding down Alt and typing a four digit decimal value on the numeric keypad.

MODE 7
PRINT "A red box:"CHR$145;CHR$247;CHR$251

Blast-through text

Capital letters display as text even when in a graphics mode. This is handy as it allows you to incorporate text without the overhead (and wasted space) of switching from graphics mode to text mode and back again. This is called blast-through text.

Separated graphics

Normally graphics characters display as contiguous blocks as shown in the table above (in other words, there are no gaps between the sixels). By inserting control code 154 you can switch to the separated graphics mode; in this mode the graphics blocks are smaller and are separated by small gaps. This can give a shaded appearance and improve the subjective quality of certain types of graphics.

To switch back to contiguous graphics on the same row, insert the control code 153.

Held graphics

Generally all control codes are displayed as spaces, in the current background colour. In the held graphics mode, which can be selected by inserting control code 158, control codes are displayed as a copy of the most recently displayed graphics symbol. This permits a limited range of abrupt display colour changes.

The held graphics character is displayed in the same contiguous/separated mode as when it was first displayed. If there has been a change in the text/graphics mode or the normal/double-height mode since the last graphics character was displayed, the held graphics character is cleared and control codes once again display as spaces.

To switch held graphics mode off, on the same row, insert control code 159.

Flashing

Text or graphics may be made to flash by inserting control code 136; the characters alternate between the selected colour and the current background colour. To switch back to steady characters, on the same row, insert control code 137.

All rows begin as steady, single-height, white alphanumeric characters on a black background.

MODE 7
PRINT CHR$136"Some flashing text"

Double height

Text or graphics may be displayed in double-height, where one row contains the top halves of the characters and the next row contains the bottom halves. To select double-height, insert control code 141; to switch back to single-height, on the same row, insert control code 140. Wherever you have single-height characters the second row of the pair will contain spaces (in the current background colour).

The characters in the first row of a double-height pair are not automatically duplicated in the second row (as would be the case for a conventional hardware implementation) so you must arrange for two consecutive display rows to contain identical data. The BBC Micro had the same requirement and it is what BBC BASIC programs expect. It has the advantage of allowing special effects such as the top and bottom halves of double-height characters being in different colours. Software drivers for Viewdata or Teletext emulations must take account of this feature and carry out the duplication themselves.

There is no need to, nor can you, specify which row should contain the top halves of the characters and which the bottom; this is worked out automatically by the MODE 7 display driver. The consequence of this is that if you delete all the double-height control codes (141) in the first row of the pair, the characters in the 'second' row will instantly change from bottom halves to top halves.

MODE 7
PRINT CHR$141"Double-height text"
PRINT CHR$141"Double-height text"

Reveal/conceal

The conceal control code (152) causes subsequent text in the row to be hidden (displayed as spaces in the current background colour) until the next text colour or graphics colour control code is encountered. To reveal the hidden text, an applications program must change all the conceal characters to something innocuous (e.g. the escape character, control code 155, which does nothing).

The two procedures below are taken from the demonstration program 'MODE7DEM.BBC'. The first procedure converts all conceal characters (&98) to escape characters (&9B). The second converts all escape characters back to conceal characters.

DEF PROCreveal
LOCAL N%,X%,Y%
X%=POS:Y%=VPOS:VDU 30
FOR N%=1 TO 24*40
  IF (&FF00 AND USR&FFF4)DIV256=&98 VDU &9B ELSE VDU 9
NEXT
PRINTTAB(X%,Y%);
ENDPROC

DEF PROCconceal
LOCAL N%,X%,Y%
X%=POS:Y%=VPOS:VDU 30
FOR N%=1 TO 24*40
  IF (&FF00 AND USR&FFF4)DIV256=&9B VDU &98 ELSE VDU 9
NEXT
PRINTTAB(X%,Y%);
ENDPROC

Left CONTENTS

CONTINUE Right


Best viewed with Any Browser Valid HTML 3.2!
© Richard Russell 2021