Beebug


Newcomers Start Here: Some Experiments In Mode 7

 
Published in Beebug Volume 2 Number 1

Newcomers Start Here: Some Experiments In Mode 7

We have received requests from some members for articles for absolute newcomers to computing. Here is an offering from David Graham in which he assumes very little previous knowledge. The article covers the use of PRINT and TAB statements, and some control codes in mode 7.

The BBC micro has 8 possible display modes, they differ in the size of printed characters, the number of colours available, and the so-called graphics 'resolution' - this is just the degree of fineness or chunkiness of the graphics picture. The modes which give the most colours and the highest resolution are generally those which use up the most memory. Mode 7, which has a very low resolution picture capability but offers 7 colours, uses up only about 1000 units (or bytes) of memory, whereas mode 1 takes up over 20,008 (and leaves precious little memory for any programs to reside in).

Because it uses so little memory in a machine where memory space is at a premium, Mode 7 is a particularly important one for BBC users. It is also called the Teletext mode. This is because it uses all the same conventions as Teletext systems such as Prestel or Oracle; and it is by using mode 7 that it is possible to dial into Prestel with a small add-on to your Beeb.

Mode 7 is different from graphics modes such as 1, 2, 4 and 5 in an important respect; you cannot use commands like PLOT and DRAW to draw lines or to fill triangles. Instead everything must be put on to the screen using the ordinary PRINT statement or equivalent. Do not however think that Mode 7 is an uninteresting one; quite the reverse.

Getting Into Mode 7

When you turn on your machine (or hit the BREAK key at any time) the machine automatically defaults to mode 7. If you are in another mode, you can change to mode 7 by typing MODE 7 (RETURN) (where RETURN means press the key marked RETURN). There is an abbreviation for this command. It is MO. 7 (RETURN). Most keywords in BBC Basic have abbreviations. A full list is given on pages 483 and 484 of the User Guide (or on the Beebug Reference Card).

TAB

There is a TAB statement in BBC Basic, rather like a typewriter tab. It allows you to place your printed text anywhere on a line or anywhere on the whole screen in fact. Try typing:

PRINT TAB(10)"HELLO" (RETURN)

You should see that the text will be indented by 10 characters. If you wish to specify which line the text is to appear on, you can do this as follows:

PRINT TAB(15,4)"TEST"

This places the word TEST fifteen characters along on the fourth line down the screen. If there happens to be something on the screen in that position, it will be overwritten.

40 x 25 Screen

In each mode, there is a fixed number of character positions available for printing. In Mode 7 there are 25 lines on which text may be placed (labelled @ to 24), and each line can accommodate up to 40 characters (the positions being numbered from 0 to 39). If you try to print further along than character 39, the text will automatically spill over on to the next line. If the screen is full, it will scroll upwards to leave space below.

Colours

There are 7 possible colours in Mode 7 if you include white, and each has associated with it a code number. These are listed below.

Code Colour
129 Red
130 Green
131 Yellow
132 Blue
133 Magenta
134 Cyan
135 White

To get a line of coloured text, you must insert an invisible colour code character before the text. One way to do this is with the CHR$ command. Try the following:

PRINT CHR$(130);"GREEN TEXT" (RETURN)

The text will be printed in green (providing you are in Mode 7). The code telling the computer to put the text in green is printed invisibly in the character position immediately to the left of the word GREEN, as the computer has printed it. You can test this by using the (up arrow) and COPY cursors to copy the line of green text. Unless you start copying at the space before the word GREEN, the text will copy over as white. You can experiment with the other colour codes; and they may be used in combination. Try:

PRINT CHR$ (129);"RED TEXT";CHR$ (133);"MAGENTA TEXT" (RETURN)

Coloured Background

It is possible to alter the background colour on any line from natural black to one of the 7 colours. To do this you use code 157. This means "change background colour to the current text colour". Thus:

PRINT CHR$(129);CHR$(157);CHR$(132);"BLUE TEXT ON RED BACKGROUND" (RETURN)

will give a background band of red with the text in blue. This is because the code preceding the "set background code" is 129 - the code for red - and this is followed by the code that sets the foreground. Some quite striking effects can be achieved in this way.

VDU Commands

It is possible to abbreviate the sequence of CHR$ commands on the BBC micro using a single "VDU" command. This is used outside a print statement. The above example can now be replaced with the shortened, version:

VDU129,157,132:PRINT"BLUE TEXT ON RED BACKGROUND" (RETURN)

Other Effects

A number of other effects are possible in Mode 7, all achieved by the interplay of control codes. For example there is one for flashing characters (code 136 = Flash On, 137 = Flash off), and another for double height characters. With the latter you must print the same line of text twice, as you can see if you type:

PRINT CHR$(141) "DOUBLE HEIGHT" (RETURN)

You need to enter it twice, as follows

PRINT CHR$(141);"DOUBLE HEIGHT":PRINT CHRS$ (141);"DOUBLE HEIGHT" (RETURN)

With a 1little ingenuity, you should be able to produce flashing double height text on a coloured background.

Use Within A Program

The ideas suggested above may easily be incorporated into programs of your own design. If you have not written a program before, it is done by preceding statements with a number - usually increasing in steps of 14. For example enter the following:

10 MODE 7 (RETURN)
20 PRINT TAB(10,10);CHRS$(129);CHR$(157);CHR$(132);"BLUE TEXT ON a red background" (RETURN)

Each time you type RUN (RETURN), the sequence will be executed in line number order. The command LIST (RETURN) (or L. (RETURN)) will list the program. It may be saved on a cassette with SAVE"COLOURS" (RETURN), and loaded back in with LOAD"COLOURS" (RETURN), or just LO."" (RETURN).

For more ideas on mode 7 see Beebug vol. 1 no. 4 p.7 and the User Guide p. 150.

David Graham