Beginners Series Part 10

After investigating GET$ we begin our in-depth exploration of the BBC Micro's modes.

Volume 1

Number 12

February 1984

Get yourself in the right mode

Which of the BBC MICRO'S eight modes is the best one for your program?

THIS month we're going to look at the features the different modes on the BBC Micro provide.

However, before we do so, we'll cover a useful command we've neglected so far - GET$.

10 REM *** PROGRAM I ***
20 MODE 6
30 PRINT'' "When you are ready, press a letter
40 string$=GET$
50 PRINT'' "You pressed " string$

Look at Program I. Line 40 is:

40 string$=GET$

When the computer reaches this line it waits for a key to be pressed. As soon as you press a key, the micro continues with the next line of the program.

The variable string$ now contains the character whose key you pressed. For instance, if you'd hit the letter "A", PRINT string$ would print out the character "A".

Run Program I and you'll soon see what happens.

Notice two points:

Unlike INPUT, you do not have to press Return.

Again, unlike INPUT, the variable used for storage only contains one character.

As well as GET$, there is GET. Notice that this has no "$" symbol on the end. This is because GET returns a number, which must be stored in a. numeric variable, unlike GET$.

On encountering GET, the micro waits until a key is pressed, then continues. The actual value that GET obtains from the keyboard is the Ascii code of the key pressed.

10 REM *** PROGRAM II ***
20 MODE 6
30 PRINT''' "When you are ready, press a letter ";
40 ascii=GET
50 PRINT''' "The character had Ascii code ";ascii
60 PRINT'' 'This means it was "CHR$(ascii)

Look at Program II. Line 40 reads:

40 ascii=GET

When it reaches it the program waits for a key to be pressed, at which it continues.

If you pressed "A", the variable ascii would contain the value 65, which you'll remember, if you cast your mind back, is the code for "A".

Run Program II to see how it all works. Line 50 prints out the Ascii code of the character you inputted and line 60 uses CHR$ to translate it into a character. Don't leave a space between CHR$ and (.

10 REM *** PROGRAM III ***
20 CLS
40 PRINT''"Next Mode?";
50 mode%=GET-48
60 MODE mode%
70 FOR loop%=l TO 20
90 NEXT loop%

Program III, which we're going to use to examine the BBC Micro's modes, uses GET to input the mode you want to look at (line 50).

Notice how I label the GET statement in line 40. It's bad practice not to tell people that you want them to enter something from the keyboard.

Line 60 then changes mode, and 70 to 90 consist of a FOR . . . NEXT loop printing out "THIS IS A DEMO" 20 times.

The whole affair is wrapped up in a REPEAT . . . UNTIL FALSE loop, so that you are repeatedly asked which mode you wish to view.

Once you understand it, try looking at the various modes with Program III.

The size of the letters varies in each mode. In Modes 2 and 5, you can have only 20 characters across the screen.

Modes 1, 4, 6 and 7 allow 40 characters fit into the width of the display, while Modes 3 and 0 have 80 characters across.

At first all this diversity may seem a little confusing. However, it's all fairly simple and logical if we take it step by step.

You see the more characters you have to cram across the screen the more memory your micro has to set aside to remember what's happening on the display.

The more memory the micro reserves for the screen the less it has to store the program in. So it is often a trade-off between program size and the number of characters in the display.

It still might seem a little odd that we have more than one mode with the same number of characters in a row. For instance, Modes 1,4,6 and 7 all have 40 character rows.

Each of these modes, however, has characteristics that differ.

First, let's put Mode 7 to one side. This is the Teletext mode, the one the Electron hasn't got, and it works very differently to the others.

So that leaves us with Modes 1,4 and 6 that have 40 characters to the row.

Try running Program III entering Mode 6 first, the one in which we've done almost all our work. Then try it for Mode 4, then Mode 1. '

You should notice that in Mode 6 you get far fewer lines on the screen than you do in Modes 4 and 1. This is because Mode 6 puts more space between the lines.

You see, Mode 6 is a text only mode intended for word processing, and the extra spacing is designed for clarity.

In fact Modes 4 and 1 allow you 32 rows of 40 characters, while Mode 6 allows you only 25 rows of 40 characters.

We still haven't distinguished between Modes 4 and 1 though. After all, they both have the same number of characters, so why bother with two of them?

The answer is colour, a subject that we have so far avoided.

Mode 1 allows you four colours on the screen at the same time, whereas Mode 4 allows only two.

So why not opt for Mode 1 all the time? The answer is memory. Mode 1 has to use exactly twice as much memory as Mode 4 to obtain the extra colours, and sometimes this is a bit too profligate.

In fact, on Model A computers you cannot even use Mode 1 because there isn't enough memory.

If you now use Program III to experiment with Modes 5 and 2 you will see that both give you 32 lines of 20 rather chunky characters.

However, as you probably suspect by now, Mode 2 allows you more colours than Mode 5 16 as opposed to 4.

Using Program III with Modes 0 and 3 shows that, while both give you 80 character rows, Mode 0 gives you 32 rows while Mode 3 gives you only 25 rows, leaving gaps between for clarity, as did Mode 6.

Mode 3 is for text only, as was Mode 6. Text-only means that the mode can't support graphics. It cannot draw the multicoloured lines and triangles associated with the BBC Micro's graphics modes.

However we're getting ahead of ourselves. Next month we'll look at colour on the BBC Micro. Then, armed with some useful Basic commands, we'll cover graphics.

Meanwhile, here are the answers to the problems I set you last month.

Programs VIIa and VIIb show alternative ways of inverting the triangle of asterisks we showed in last month's Figure IIIb.

10 REM *** PROGRAM VIIa ***
20 REM *** JANUARY ***
30 MODE 6
40 FOR loop%=0 TO 10
50 asterisk$=asterisk$+"*"
60 PRINT TAB(10-loop%,10-loop%) asterisk$
70 NEXT loop%

10 REM *** PROGRAM VIIb ***
20 REM *** JANUARY ***
30 MODE 6
40 FOR loop%=10 TO 0 STEP -1
50 asterisk$"asterisk$+"*"
60 PRINT TAB(loop%,loop%) asterisk$
70 NEXT loop%

As you can see, you can either tinker with the effect of the loop variable by providing a new offset, or you can rejig the whole loop by altering the step (Programs IV and V).

I also asked you to invert the triangle of asterisks produced by last month's Program VIII. Programs VIIIa and VIIIb show two ways of doing this, again by altering either the offset or the loop parameter.

I'd be very happy to hear from readers who've found alternative solutions.

10 REM *** PROGRAM VIIIa ***
20 REM *** JANUARY ***
30 MODE 6
40 asterisk$="*"
50 FOR loop%=0 TO 10
60 PRINT TAB(10-loop%,10-loop%) asterisk$
70 asterisk$=asterisk$+"**"
80 NEXT loop%

10 REM *** PROGRAM VIIIb ***
20 REM *** JANUARY ***
30 MODE 6
40 asterisk$"*"
50 FOR loop%=10 TO 1 STEP -1
60 PRINT TAB(loop%,loop%) asterisk$
70 asterisk$=asterisk$+"**"
80 NEXT loop%