0.0 About this book
0.1 The two models of the BBC Microcomputer
0.2 Loading, saving and joining programs
0.3 Activities
0.4 Discussion of activities
This book enters the fascinating area of computer graphics! It is written with special reference to the BBC Microcomputer and it teaches how to use the BBC Microcomputer to produce such displays as pictures, shapes, graphs, histograms, pie charts, etc. Yet the book is much more than a teaching book. We have written it assuming that you may want to use it for any of the following three reasons, and we have made provision for all three,
i. You may want to see what the BBC Microcomputer can do in the way of colour graphics, and not want to develop a graphics display for any specific purpose. If so, since the displays are opposite or next to the programs which produce them, you can simply choose the display you like, type in the program and run it to get an identical display.
ii. You may be looking for a graphics display to help you with a particular job or problem. If so, you simply flip through the book to find the display which most nearly suits your purposes. Then you read our hints and advice on how to modify it.
iii. You may want to make your own graphics programs. With this in mind, we describe and explain the necessary BBC BASIC instructions and show how to use them. We also provide various routines to save you time when you program sophisticated graphics displays, and we show you how to use them.
In iii, we mentioned routines to save you time when you program graphics displays. Let us explain. Whenever you program graphics, you will find that you keep needing routines to do certain jobs, like scaling data so that the display fits the screen, or like drawing and graduating axes of a graph. We do not just teach you how to program these for yourself. We actually supply them as procedures for you! They are listed in Appendix I for you to type in and save, although you can also buy them ready-recorded on cassette tape. You merely call on the procedure which you happen to want for a particular job, without having to program it yourself. You do not even have to understand how it works - although we do explain in Appendix 2. So, in effect, these routines extend BBC BASIC! They enormously simplify your graphics programming, so that you can immediately get on with the exciting tasks of producing your own unique displays.
You will get the most out of this book if you have a BBC Microcomputer and a colour television or monitor. This is for two reasons. Firstly, the BBC Microcomputer is particularly renowned for its colour graphics facilities, and this book exploits them to the full. Secondly, the book presents the material in such a way that you will learn by doing, as well as by reading. We assume that you are sitting at or near the computer as you read, and will want to break every few minutes to try some of the activities which we suggest.
We also assume that you are already familiar with the essentials of programming in BBC BASIC. If you are not, you should first work through our previous book BASIC Programming on the BBC Microcomputer, which is also published by Prentice Hall.
In this book, our way of working is to give you some information, and then to follow it with an Activities section, in which we ask you to do something for yourself to consolidate. Consequently you learn by doing. We now continue this chapter with a few short sections to illustrate this way of working. First we give information. We tell you about the BBC Microcomputer, as a computer for programming graphics and then we, explain how to save, load and join programs. We think it is important for you to become proficient at this quite early on. Although we do not specifically ask you to do it until some way into the book, we are quite sure that you will want to save, load and join the routines that you develop yourself as you go through the book. Afterwards we give a short section of Activities where you might like to do something yourself.
The BBC Microcomputer is available in two models, Model A and Model B. The memory of the Model B is greater than that of Model A (32K of RAM compared with l6K). You can upgrade a Model A by adding more memory. This makes it equivalent to a Model B for all programming purposes.
The greater memory of the Model B gives the advantages of a larger number of display modes, a greater choice of colour and more detail (resolution] on the screen. Also, as graphics programs tend to be rather long, especially when they call on a number of our graphics procedures, a Model A may run out of memory. A further advantage of Model B is concerned with saving and retrieving programs. Both models allow you to save and retrieve using cassette tape and an ordinary tape recorder, but Model B allows you to add a disk system. The disk drives are not cheap but they give speed and reliability.
We have not lost sight of the fact that you may be using a Model A for your graphics programming. Although you will not have as many facilities as Model B owners, you do, nevertheless, have sufficient to make it worthwhile to program graphics. In particular we provide some very useful routines which allow most of the graphics to operate in the Teletext mode, mode 7. This offers the full range of colours and requires only 1K of memory! With a Model B and with long programs which require a large amount of memory for data storage, you will also find these routines valuable. In Appendix 2 we explain how to estimate whether or not a program will fit into the memory of your model of computer, depending on which of our procedures it calls.
In this section, we explain how to save, toad and join programs. As we mentioned earlier, we expect that you wilt want to become proficient at this in order to save, load and join routines that you develop yourself as a result of working through this book.
There is another reason why you will want to save, load and join programs. As we also mentioned, a feature of this book is that we provide various routines to do those jobs which you are likely to keep needing for programming graphics. After the first few chapters, we repeatedly refer to these routines throughout the text and we supply them as procedures, listed in Appendix I. To use them, you will either have to buy the cassette on which they are ready-recorded, or you will have to type them into your computer and save them, ready to join them to your existing program.
We have adopted the approach of saving all of our routines in what is called the *EXEC format, and we advise you to do the same. Using this format, the routines can be retrieved from tape or disk, just as if you had typed them in from the keyboard. Since the lines of our routines have numbers over 9000, they will not overwrite your existing program. They simply join onto whatever program is already in memory. This is in contrast to loading using the LOAD command, which irretrievably removes all trace of any previous program.
To save any program on tape in the *EXEC format, first type the following where NAME may be up to ten characters long:
*SPOOL "NAME"
Enter this by pressing RETURN.
The computer responds with the following message:
RECORD then RETURN
So set the tape recorder to record and then press the RETURN key. The prompt and flashing cursor appear.
Next enter:
LIST
This causes the program listing to appear on the screen. It also sends the listing to a buffer inside the computer, ready for recording onto the tape.
When the listing is complete, enter:
*SPOOL
This completes the saving process and sends any remaining program from the buffer to the tape recorder.
To load anything which has been saved in the *EXEC format, rewind the tape, and then simply type the following and set the tape recorder to play:
*EXEC "NAME"
Once you have pressed RETURN, you will see the lines of the program appearing very rapidly on the screen, just as if a phantom typist were typing them. Any program already in the computer is unaffected, as long as it does not have the same line numbers. Then the incoming lines would overwrite the existing ones, just as if you were typing them in yourself.
If you have a disk system, you will clearly want to transfer the programs to disk - but you will have to be more careful in choosing names because a name can only be up to seven characters long. The cassette tape available with this book can be read into a BBC Microcomputer with the disk operating system, by first switching to the tape file system by issuing the command:
*TAPE
Programs and procedures, etc. can then be loaded as already described. Once the program lines are in the computer, the following command switches back to the disk file system, ready for saving:
*DISK
For complete programs, it is more usual to save and reload using the following commands, respectively:
SAVE "NAME"
and
LOAD "NAME"
Using LOAD and SAVE is much faster than using *EXEC and *SPOOL.
These activities illustrate the saving and joining of programs using *SPOOL and *EXEC.
i. Start by entering the following two lines of program so that you have something to save:
10 PROCtrial
20 END
ii. Now save these lines under the name MAIN-PROG using the *SPOOL command, as described in the previous section.
iii. Enter NEW. This is to remove these lines from memory and so convince you, when you see them again, that you have really retrieved them from tape.
iv. Now, using the *SPOOL command, save the following lines under the name TRIAL. They define the procedure PROCtrial which was called in line l0 of the MAIN-PROG:
100 DEF PROCtrial
110 PRINT "This is proc trial"
120 ENDPROC
v. You should now have two blocks of data saved: under the names MAIN-PROG and TRIAL. Enter NEW to clear the existing lines of procedure and then retrieve MAIN-PROG using the *EXEC command. You will have to wind the tape back to the start and set the tape recorder to play. You will now see the lines of the first program rapidly typed up on the screen preceded by the message:
>>LIST
Syntax error
and followed by the message:
>> *SPOOL
Syntax error
>
We discuss these error messages in Section 0.4.
vi. List the program lines recovered so far. This should confirm that only the first set of lines, up to line 20 have reappeared. Try entering RUN. Does this produce the following error message?
No such FN/PROC at line 10
vii. Now similarly retrieve "TRIAL" using the *EXEC commend. Do the set of tines which define the procedure appear?
viii. Enter LIST tm confirm that the two sets of lines have been joined to give a complete program. Does the program run now?
Activity 0.3v: You may ignore the Syntax error messages. They always arise at the start and end of loading of a program using *SPOOL, and arise because the > sign which precedes the *SPOOL is a mechanism by which the system is prevented from responding to recorded commands.