Bottom     Previous     Contents

15 Using Teletext graphics

15.0 Introduction

15.1 Writing in colour

15.2 Colouring the background of a single line of text

15.3 Flashing text

15.4 Making double height characters

15.5 Activities

15.6 Block graphics

15.7 Getting continuity when changing colour

15.8 Composite figures

15.9 Activities

15.10 Using the procedures with Teletext

15.11 Error messages with Teletext graphics programming

15.12 Activities

15.13 Discussion of activities

15.0 Introduction

Normally in mode 7, the mode in which the computer first turns on, you can only display black and white text. This chapter explains how to get the full range of eight ordinary colours and eight flashing colours for text and graphics using Teletext facilities. These facilities are only available in mode 7 and are as used by television's Ceefax and Oracle. The method by which the colours are written to the screen is completely different from the other modes, and the amount of memory taken up by the screen display is only 1K. This contrasts with the l0K taken up by modes 4 or 5 and means that more memory is available for sophisticated programs - which is especially important with a Model A BBC Microcomputer.
The appearance of Teletext graphics is somewhat coarser than in Activity l5.9i: The new line appears as block graphics because, at its beginning, there is a code for block graphics. Although this is invisible, it is also copied.t it for dramatic effects, especially as the full range of colours is available,
Teletext facilities have to be turned on a line at a time. As this makes text as well as graphics programming very different from that in other modes, we shall deal with both in this chapter.

15.1 Writing in colour

Mode 7 provides a Teletext screen display of 25 lines with 40 characters to a line. To get colour on any one line, you need to print a character, called a control character, on that line. Each control character occupies one character position on the line but appears blank, ie as the screen's background colour. All the text to the right of the control character is affected by the control character; all the text to the left of the control character is not. The control character affects only the one line on which it is placed.
A control character can be inserted into a line using the PRINT statement. Table 15.1 gives the possible colour control codes for text. For example, suppose you want a display on the screen consisting of the single line:

White Green Blue

Suppose that you also want each word to be in the same colour as its name. The following program achieves this using the appropriate cotour control codes from Table 13.1:

10 MODE 7
20 PRINT "White";CHR$(l30); "Green";CHR$(l32);"Blue"
30 END

The colour code for white, ie 135, is the default control code. So you do not have to give a control code before "White" in the above line 20.

129 red text
130 green text
131 yellow text
132 blue text
133 magenta text
134 cyan text
135 white text

Table 15.1 Colour control codes for Teletext text

15.2 Colouring the background of a single line of text

You can set the background colour for each individual line of text. The instruction is the same as for text, except that you need two control characters, the first to control the colour and the second to specify that it is for the background. The following control characters change the colour of the background.

156 changes the background to black
157 changes the background colour to that for the preceding colour control code

For example, the following instruction sets a green background:

PRINT CHR$(130);CHR$(l57)

15.3 Flashing text

You can get a very dramatic effect by making some of your text characters flash. You need the control code 136 which causes everything following it to flash between the foreground and background colours. You can turn off the flashing with code 137. For example, when the following line is executed, the word 'Flashing' flashes between red and black, while the word 'Steady' is printed in red and does not flash:

100 PRINT CHR$(l36);CHR$(l2 9);"Flashing"; CHR$(137);
"Steady "

15.4 Making double height characters

You can also get dramatic effects by doubling the height of Teletext text. This feature is achieved using two screen lines for every line of text: one for the top half of the text and the other for the bottom half. The doubling is turned on by code 141 and off by code 140. For example the following two lines of program print the message Double Height in characters twice the height of normal characters.

100 PRINT CHR$(141);"Double Height"
110 PRINT CHR$(141);"Double Height"

The following two lines of program produce the message Double Height in large letters next to the message Normal Height in normal sized letters:

100 PRINT CHR$(l4l);"Double Height";CHR$(l40); "Normal
Height"
110 PRINT CHR$(l4l);"Double Height"

15.5 Activities


i. Enter the following and observe what happens:

10 MODE7
20 PRINTT AB(0,4);CHR$l3l;CHR$l4l;5TRING$(5," Hello")
30 F0RI=0TO33
40 PRINTTAB(I,5);CHR$l3l;CHR$l4l;"Hello"
50 FORTT=11TO400:NEXTT
60 NEXTI

ii. Can you explain why the double height HELLO only appears correctly on the screen some of the time? (See Section l5.13.)


145 red graphics
146 green graphics
147 yellow graphics
148 blue graphics
149 magenta graphics
150 cyan graphics
151 white graphics

Table 15.2 Colour control codes for Teletext graphics

15.6 Block graphics

You can get block graphics in a similar way to getting coloured text. You need the codes given in Table 15.2. The blocks of graphics all occupy one of the areas on the screen originally reserved for a letter, but any line starting with a code between 145 and 151 will no longer display lower case letters. In their place graphics characters appear. Although these codes cause lower case (small) letters, numbers and punctuation marks to appear as block graphics characters, upper case (capital) letters are unaffected. For example, in the first of the following two program lines, the code 131 causes yellow numbers to be printed. In the second line of program, the code 147 causes the printing to come out as yellow block graphics.

100 PRINT CHR$(131);"1234567890"
110 PRINT CHR$(147);"1234567B90"

Each graphics character is made up of small blobs, vertically and 2 horizontally. Thus a wide variety of block graphics characters are available, depending on which of the blobs are lit up. Table 15.3 gives the different types of block graphics which are available and their corresponding codes.
While using block graphics, you can get an attractive effect with control code 154, in conjunction with CHR$(l47). This causes each block of graphics to be reduced in size, for example making a continuous line appear as a series of disconnected dots. Code 153 turns off the effect, This is particularly suitable for displaying curves and lines, as they appear less clumsy and of better resolution with the smaller sized blocks.
Double height block graphics can be obtained in the same way as with text, using the code 141.

Table 15.3 Teletext block graphics

15.7 Getting continuity when changing colour

If, on one line, while printing a series of the same characters you change the colour, or height or some other characteristic, you normally get a space where the control character goes. This can spoil a graphics display. The problem may be solved by placing control code 158 to the left of the characters. Spaces for control codes will now be occupied with the previous character. This technique allows continuous graphics displays, even where the colours change. Code 159 turns the effect off. For example, the following line causes a display of three red blocks, followed directly by 1 green block. No blank spaces can be seen, even though there is a change of colour caused by the code 146.

100 PRINT CHR$(145);CHR$(255);CHR$(l58); CHR$(146);CHR$(255)

This is in contrast with the effect produced by the following lines which display a single red block followed by a space, where code 146 is stored, followed by a green block:

110 PRINT CHR$(145);CHR$(255);CHR$(146); CHR$(255)

Lines 100 and 110 may be put together to show both continuous and normal graphics on consecutive lines.

15.8 Composite figures

There are no user-definable characters in the Teletext mode. These are confined to the other graphics modes. However you can build up very satisfactory shapes by combining the block graphics shown in Table 15.4. You can place several characters together on a line merely by printing them together. For example, the following line of program produces the printout shown in Figure 15.1:

50 PRINT CHR$(l49);"xyz"

You can make a composite figure on more than one line using the principles described for composite characters in other modes. These are in Section 4.6. Table 4.1 gives the appropriate codes. For your convenience, it is duplicated here as Table 15.4,

Figure 15.1. The result of PRINT CHR$(149)"xyz".

Screen Display 15.1

ASCII code result
08 move backwards one space
09 move forward one space
10 move down one line
11 move up one line

Table 15.4 Cursor control codes

When writing a number of control codes, it is normally easier to use the VDU method whereby any VDU may be followed by as many codes as required. These codes may include character codes. For normal letters and numbers, the codes are the ASCII codes (see Appendix 3).

Figure 15.2 illustrates the sort of composite figure that can be constructed using Teletext graphics.

Figure 15.2. A composite figure consisting of Teletext block graphics.

Screen Display 15.2 (first part)

Screen Display 15.2 (second part)

15.9 Activities


i. Enter the following line:

PRINT CHR$(l49);"xyz"

Do block graphics appear on the screen, with the cursor on the next line? Use the cursor control keys in conjunction with the copy key to make a copy of the line of the block graphics. What do they copy as? Can you see why? We discuss this in Section 15.13.

ii. Use the Teletext graphics shown in Table 15.3 to make a composite figure of more than one line. Print your character on the screen and then try to move it continuously from one side of the screen to the other, as if animated. You will have to remove the old character as well as write up the new one. A space character (ASCII code 32) should help.


15.10 Using the procedures with Teletext

As Teletext facilities offer the full range of colours, and the memory taken up by the screen is only 1K, you will probably want to program various displays in mode 7. With this in mind, we have adapted our procedures for use with Teletext.
The procedures for drawing histograms, pie charts and large, rotated writing proved unsatisfactory in Teletext. Apart from these, ail our procedures are available for use with Teletext. Since normal graphics instructions are not available in mode 7, we have also provided several additional procedures:

Screen Display 15.3a

PROCclg(B,C) clears the screen and sets the foreground and background colours for graphics. B is the colour number for the background and C is the colour number for the foreground. B must be in the range 0 to 7 and C must be in the range I to 7 (see Chapter 2). PROCclg(B,C) must be called before calling any of our other graphics procedures.
PROCdraw(X1,Y1,X2,Y2) draws a line from the point (X1,Y1) to the point (X2,Y2). The range of the co-ordinates is immaterial provided it is within that declared when PROCscale is called. PROCplot(X,Y) plots a single point at the position X,Y. For our own use, we saved all the Teletext procedures as a composite which we called TCOMP.

Screen Display 15.3b


Screen Displays 15.1, 15.2, 15.3, 15.4 and 15.5 show the types of display that you can produce with our Teletext procedures. All are Teletext equivalents of Screen Displays that were given earlier, namely Screen Displays 9.1, 9.2, 9.3, 10.1 and 11.1. By comparing them, you can get a good idea of the advantages and disadvantages of programming graphics in mode 7. You will notice that the coarseness of Teletext graphics makes it impossible to graduate the axes entirely uniformly.

15.11 Error messages with Teletext graphics programming

When you come to program in Teletext, having used PR0Cc[g, your programs become impossible to read because they appear largely in Teletext block graphics, rather than in ordinary characters. Although this looks rather strange, it does not affect how the programs run. The problem is that any error messages become unreadable too! When you think you have an error message, start by entering the following to clear the screen:

MODE7

Next, enter the following to give the error message in readable characters:

REPORT

Finally, enter the following to get the number of the line responsible for the error:

PRINT ERL

Screen Display 15.4

15.12 Activities


i. Experiment with those of our procedures which apply only to Teletext. Do they behave as you expect?

ii. From the earlier chapters, choose one or more of the Screen Displays which rely on the procedures which we provide. Adapt the programs to make them work in Teletext. Do you think that the displays are an improvement?

iii. As Teletext displays can produce more colourful and dramatic displays than those in other modes, you may like to adapt a favourite display of your own for Teletext. Is it an improvement?


15.13 Discussion of activities

Activity 15.5 ii: The two halves of the message are entirely separate. The top half is printed at a fixed position, whereas the lower half moves continuously across the screen.

Activity 15.9i: The new line appears as block graphics beacuse, at its beginning, there is a code for block graphics. Although this is invisible, it is also copied.


Next     Top