Click Here To Go To The Your Computer Archive

Written By Chris Melville

Cover Art
Click Here To Enlarge Loading Screen

Loading Screen
Click Here To Enlarge Opening Screen

Opening Screen
Click Here To Enlarge Screenshot

Game Screenshot

Pixel Plotter

Chunky pixels and coloured backgrounds: Chris Melville presents some mode 7 ideas to chew over

Mode 7 provides a full eight colours although at first sight its graphic capabilities may seem a litde limited. However, it does have a character set which includes block graphic characters. Sensible use of these can help to realise pseudo low- resolution graphics such as the use of "chunky" pixels for plotting and drawing figures. Also, we can make use of the windowing capabilities of the BBC - which still exist in mode 7 - to emulate foregound and background colouring done permanently in other modes with VDU19,Colour and GCOL,so that Ctrl L,CLS and scrolling do not change the colour scheme.

In order to produce a coloured character on a Mode 7 screen we must precede it with one of the graphic control codes somewhere along the line. Suppose then, that we wanted to have a foreground colour of yellow and background colour of blue over the whole screen. It is easily done by writing the necessary control characters; these are 132, 157, 134 for Alpha-blue, Background, Alpha-cyan respectively to the first three character positions on every line.

This still has two drawbacks. First, as soon as the screen scrolls or you print on a new line, list the program or clear the screen the effect will be lost and you will have to re-write all the control characters again. We can stop this from happening by creating a text window which envelopes the whole screen apart from the left-most three columns. Thus both you and the machine are prevented from interfering with the control codes that have been placed in these columns, unless you change mode or re-define the window.

Second, three character positions on each line are lost. This cannot be prevented, although use of the window will insure that statements such as PRINTTAB(0,2) print at the apparent beginning of line and not over the control codes.

Different Strokes

Of course, there is no reason why different sections cannot have different foreground and background colours, it just depends on the control codes - you could have half the screen in double-height flashing graphics, red if required. Listing 1 shows the code which will do the job in the form of a procedure. The parameters to be given to the procedure are, in order: PROCscreencoll, start line number, finish line number, foreground colour and background colour.

It is necessary that PROCinit1 gets called once before PROCscreencoll is ever used since this defines the colour names, amongst other things. This means that you can refer to the colour using names. Prefix the name of the colour in lower case with either G for choosing a graphics colour-foreground only or A for an alphanumeric colour: and use it in the procedure call.

The one exception is black which is referred to as "dark" and can only be used as a background parameter. The action of the procedure is very simple: it checks the parameters and exits without doing anything if erroneous; cancels out any existing window; puts the correct control codes in the correct place; and re-defines the text window as required. The procedure is in Basic and therefore not very useful as part of, say, a games program using continuous foregroundlbackground colour changing since one can see the colour changing "flowing" down the screen. A much faster assembly language version is provided, which also serves as a good example of operating system calls. This time the parameters are passed as follows.

There are four bytes in memory named y-start, y-end, frontcol, backcol - names are defined in the initialising procedure. These should be set up as required before the subroutine is called.

Demo Program

PROCinit2 must be called once only as before - see listing 2. The actual routine is now called by:

CALL screencol2

from Basic or

JSR screencol2

from assembly. Try the following demo program:

 1 PROCinit2:FOR I%=0 TO 4
 2 READ S%,E%,F%,B%
 3 ?y-start=%:?y=end=E%:?frontcol=F%:?backcol=B%
 4 CALL screencol2
 5 NEXT I%
 6 DATA 0,5,Acyan,Ablue,6,11,Ablue,Ayellow,12,17,Gmagenta,Awhite,18,21,Ayell
 7 END

Now list the program and try and read it. Some colour combinations more easy on the eye include: cyan and blue; yellow and blue; magenta and white; yellow and red and green and white.

In Mode 7 we have 40 characters across the screen and 25 down it. We also have graphics shapes, each the size of a character, which are split into squares of which there are two across and three up. This gives an effective screen resolution of 80 across and 75 up which, although small by comparison to other modes, is sufficient for bat-and-ball-type games and static displays as used by Ceefax. Suppose we say the x axis goes from 0 to 79 and the 7 axis from 0 to 74 - relative to botton left-hand side of screen - and we wish to plot the pixel with co-ordinates (x,y)

Work out which character square the pixel lies in. This is given by:

c.p. = (xDIV2,24-yDIV3)

Make a note of the ASCII code of any character that is already inside this character square. Some of the available pixels within this square may already be filled and of course they must remain filled when we choose the new graphic character.

Work out the displacement of the pixel within the calculated r character square:

DISP(X) = xmod2, DISP(y) = ymod3

and decide which of the teletext graphics characters - see back of manual - fills only this pixel.

This can be done using a predefined look-up table in the form of an array containing the relevant ASCII codes.

Now determine, by means of a logical OR, the ASCII code of the character which fills up both the selected pixel and those that were originally filled. Print the selected character at the Tab position that you first calculated. I have provided an assembly language subroutine - see listing 3 - which performs these steps for you. It can be used from either Basic by

CALL pix

or assembler by

JSR pix

For Basic, the point whose co-ordinates are X%,Y% will be plotted according to whether A%=1 or A%=0 respectively. For assembler, the co-ordinates are in the x and y registers and the plot/unplot flag in the accumulator. In both cases the parameters are unchanged on exit. Also, the respective initialising procedures must have previously been called once. This subroutine can be used in the construction of line, circle or triangle drawing¬filling routines.

For an example of Mode 7 pixel plotting see the Breakout/Breakthrough game in the May issue of Your Computer and note the smooth movement of the ball which could not be achieved in Basic or using a character-size ball.

The final listing - listing 4 - is a complete utility for use when your aim is to create a picture on the screen. It can be used as an easy alternative to the usual method of drawing your picture on divided-up graph paper and then leafing through the back of the manual to see which character is needed for each square on the screen. It is in Basic but uses the previous assembly routine to do any plotting-unplotting.

There are two stages to building up a picture in mode 7: first plotting pixels at the correct points, second putting the colour control codes at the correct places to give the desired colour layout. Thus the program has two mutually interchangeable modes: Pixel Mode - entered by pressing P: here you can move a flashing pixel cursor round the screen using the arrowed keys. If you want to fill in a pixel you press Copy, to rub one out you press D.

You can draw or undraw lines by moving the cursor while keeping Ctrl pressed or Shift pressed.

Colour Mode

The other mode is colour mode - entered by pressing C. You can move a flashing cursor around the screen using the arrow keys. To enter a colour control simply press the function key which when shifted or controlled - would normally generate that colour code.

A select number of other features, for example, flashing, can be obtained by pressing the relevant key on the keyboard. These are given on request in the program itself.

Note that you will have to append the two procedures from Pix to the program. Other commands include Save Screen - pressing S will at any time save the contents of the screen on to tape with the file name "Telepic". It can then be loaded back at a later date by either running the Telepic program and pressing L or by doing a *LOAD.