BEEBUG'S STARTER PACK - ELECTRON is a First Rate introduction to your computer
A Comprehensive Manual
7 Explanatory Articles
25 Hints and Tips
5 Function Key Strips
Screen Planning Sheets
A Character Planner
A Cassette containing: 5 Utility Programs and 7 Games Programs
This is the ideal companion for anyone new to computing or learning about the Electron. The pack has been compiled by Beebug (the User Group for the BBC Micro) and draws on their experience with the machines and the feedback from over 25,000 members.
Separate packs are available for the Electron and BBC Micro, and each includes a cassette or disc containing 5 handy utility programs. Also included are 7 games, chosen not only because they are fun to play, but also to highlight the speed, sound and graphics capabilities of your computer.
A comprehensive manual introduces you to various aspects of computing and how to program in a series of carefully explained articles. 25 of our most useful hints and tips are also detailed in the manual, which is accompanied by a number of handy function key strips.
The articles include:
How a computer works
Simple BASIC programming
Use of function keys
Getting going with computer graphics
An introduction to Teletext
How to use sound and envelopes
Reviews of useful books
5 Utility programs:
Function key editor
Multiple character designer
Bad program recovery
Utility search and replace editor
7 Interesting games:
Four In A Row
This starter pack consists of programs, information and assorted items useful to the new user of the BBC Microcomputer or the Electron. Both computers are powerful machines so some basic knowledge of their capabilities and features is essential before the new user can begin to use the machine to its full capabilities. This booklet contains some of this information, and if necessary the User Guide supplied with the computer should be referred to for additional details. The programs on the accompanying cassette or disc include demonstrations of many individual features such as the sound and graphics capabilities, together with some games and utilities. These programs are explained later in the booklet.
1.1 Getting Started
The programs and text supplied in this starter pack require a standard Electron or Model B BBC computer, with a television (or monitor) and a cassette recorder or disc drive. A UHF lead (suitable for a television) is supplied with the computer. Details of connecting your computer and cassette recorder/disc drive are given in the User Guide. It is assumed that you will be familiar with the keyboard and program editing system. These are explained in the first few chapters of the User Guide. A 1.00 operating system (or later) is required for BBC users; to find which operating system is in the machine type:
which will display the version number of the operating system (OS) resident in your machine. If you have a BBC 0.1 operating system you should have it upgraded; consult a dealer for details. If your machine was purchased recently then it will certainly have the 1.20 version of the operating system which is fitted to the vast majority of machines now. Electron owners will have a 1.00 system which is equivalent to the BBC 1.20 version.
1.2 Running The Programs
Most of the programs can be run be rewinding the tape to the start and typing:
CHAIN "" (RETURN)
and then pressing the letter corresponding to the program required when the menu appears. Pressing ESCAPE whilst any program is running will stop the program and allow you to list and examine it.
Disc users can execute the programs by inserting the STARTER PACK disc in drive 0 and holding down the SHIFT key and pressing the BREAK key. You must be careful to release the BREAK key before releasing SHIFT.
1.3 BEEBUG and ELBUG
It is well worth subscribing to a magazine dedicated to your computer. Although some of the articles contained in such magazines will not be of interest initially, they do contain useful information, programs, articles and hints. This booklet is produced by BEEBUG Publications who also produce the BEEBUG (BBC) and ELBUG (Electron) magazines 10 times a
year. For further details write to:
BEEBUG/ELBUG P.O. Box 109 High Wycombe BUCKS HP10 8HQ
The programs supplied in this package are taken from past issues of BEEBUG and ELBUG magazines. The authors of the programs are:
M. J. Taylor
D. J. Pilling
L. P. Baxter
FOUR IN A ROW
FUNCTION KEY EDITOR
D. Fell & A. Webster
P. Otto, T. Burgess & A. Calcraft
The explanations are based on articles written by David Graham, Sheridan Williams, Mike Williams and Rob Pickering. This package has been compiled by Michael Beasley and Matthew Rapier.
2. The Games
The games programs on the cassette (or disc) can all be run from the menu. These games have been carefully selected to show the range of effects that can be achieved with the sound and graphics capabilities. Almost all of the programs are written entirely in BASIC.
In this game you control a man trapped in a series of caverns from which he must try to escape whilst being bombarded by blocks dropped from above by a very mobile gantry. As the blocks fall towards him, you must make him dodge them in order to stay alive, but the only way for him to escape is to climb onto the blocks, and to continue until he reaches the height of the walls. At this point a ladder extends from one of the walls and the man escapes, only to be thrown into a still deeper cavern.
The man is controlled by the left and right cursor keys, and he will also climb over any blocks in his way, provided he does not have to step up or down by more than one block at a time. The driver of the gantry tries to drop the blocks where you are standing. This can lead to some delicate manoeuvring as the crane is persuaded to drop the blocks into advantageous positions, but make one false move and he is trapped between two columns of bricks, helplessly awaiting the coup de grace.
This is based on the board game for two players commonly known as Othello, and is normally played on a conventional draughts board. This version can be played either by one player against the computer at one of two skill levels, or by two players with the machine merely keeping the score and displaying the board.
In this implementation of Reversi the first two moves are automatically made for you, these simply set up the starting positions. When playing the computer you have the choice of colour and whether to do first or second. For a move to be valid your counter must be placed in such a position that a line of the opponent's counters has one of your counters
at either end. This line may be vertical, horizontal or diagonal, but must be straight and have no bends. All the surrounded counters are now reversed so that they change to the colour of your own pieces. There is of course no reason why more than one line cannot be captured at any one time. It is part of the rules that any move must result in at least one of your opponent's pieces changing colour. If you are unable to do this then you must pass. A little practice will show how it should be played. Thinking ahead is the only way to beat the computer.
To enter a move when prompted, type the letter corresponding to the column of the square required, followed by the number of the relevant row. If at any point you are unable to make a valid move just press P to pass and your go will be skipped. There is no time limit for any move. The game ends when neither player may make a move, and the winner is the player with the most counters on the board. A list of the current scores is kept on the board throughout the game.
The principles of this game are relatively easy to understand; it is simply a shooting game. A massed force of Galactic Invaders appears at the top of the screen. One by one they peel off and come swooping down on your base with unpredictable but purposeful paths. The object of course is to shoot the aliens. Shooting them in the air is more difficult but does score extra points. The base is controlled by Z and X for left and right with full-stop for fire. The game ends when the base has been destroyed three times. The scores for the aliens vary, and a table of the relevant values is displayed at the start of the game. The points for shooting the highest scoring aliens vary randomly.
Life if a mathematical simulation played ona grid. It was developed by Professor John Conway at the University of Cambridge. You set an initial state for each of the cells on a large grid, then the rules given below decide whether any particular element of the grid survives to the next generation. Each cell of the grid may be either live or dead and has a maximum of eight neighbours around it.
If a live cell has two or three live neighbours it will survive to the next generation
If a dead cell has exactly three neighbours it will be born in the next generation
If a cell has no neighbours or only one it will die of loneliness
If a cell has four or more neighbours it will die of overcrowding
Instructions on how to define a position on the screen are given in the program. The following diagrams provide some interesting patterns you might like to try. The most interesting are usually fairly symmetrical. You may care to experiment with lines, squares, etc. A great deal has been written about Life and you will find references in magazines such as BYTE and Scientific American.
X X X
XXX X X X XXXXX
X XXXXX X X
X X X X X X X
X X X XXX
Some Starting Patterns For LIFE
FOUR IN A ROW
This is an implementation of the commercially available game "Connect 4" and the objective is simply to get four counters in a row vertically, horizontally or diagonally on a 6 x 7 board. It is a two player game, but as REVERSI you may either play the computer or another person. The two opponents each play one counter alternately, and may decide in which column this piece is played. The row of any particular piece cannot be chosen directly; the counters just pile up from the bottom. This is a particularly frustrating game as the computer plays a very hard game.
This is an implementation of the classis LUNAR RESCUE game. You are in control of a spaceship that has to land on a landing pad on the Mars surface. To make things more difficult the sky is filled with meteors which you must steer around and the ground is rather rough. You can choose a level of difficulty which makes the controls more sensitive and increases the number of meteors as well as making the ground even more craggy.
Z - Left, X - Right, RETURN - Thrust
This is a simple football game played against the computer. Both sides have two players which move left and right across the pitch. The ball bounces off the players' feet. The aim is to score as many goals as possible in the 90 second play period. You are the United team in chequered shirts playing City in stripes. When the program starts you are prompted for the attack position. This is the row where your forward player will be put on the screen. Type a number between 26 and 7, 7 is next to the computer's goalie, 26 is next to yours. The next prompt is for a rather unusual feature in football, you can choose how well the other side plays. Small values (say 0) give a very easy game, but larger numbers (say 100) make the game almost unbeatable.
Z - Left, X - Right, / - Allows ball to pass through player
This is an implementation of another classic computer game, ZOMBIES. You control a man who is chased by a number of robots. You must dodge the robots, and at the same time lure them into variously placed mines which explode destroying the robot. You must also keep well clear of the swift and purposeful Marvin. From time to time he will burst through the bars
of his cage to pursue you - but you do get a warning - the cage bars and screen-surround will flash if this is imminent. If two robots collide then they are transported through hyperspace to appear elsewhere on the screen.
Z - Left, X - Right, : - Up, / - Down, SPACE - Hyperspace
3. The Utilities
This section gives brief information on how to use the various utilities on the cassette or disc supplied with this pack.
This program is designed to make full use of the function keys at the top of the keyboard. On the Electron the function keys are accessed by pressing the FUNC key in conjunction with the numeric keys. These keys may be used to contain often used commands or text and are set up using the *KEY command. Normally it is difficult to edit the definition of a function key without re-typing it entirely. However, this editor allows them to be listed and altered with great ease.
The program, which is very easy to use, works by directly modifying the function key buffer. This is an area of memory that is used by the computer to store the key definitions. Note that this program will not work with the 6502 second processor, which must be switched off before loading it. The program also assumes that the cursor keys and COPY are being used as function keys, numbered from 11 to 15. You will not normally change these definitions, but you can use these keys as function keys by typing *FX 4,2.
When the program is run the menu is displayed, type the number of the option required, without pressing RETURN.
LIST KEYS - This simply displays all the key definitions that have been entered.
EDIT KEY - This lists out the function key in exactly the same format as was used to enter it. The definition can be changed by using the normal editing function with the cursor keys and COPY. This new definition is entered when you press the RETURN key.
DELETE - To make a function key empty use this option. It allows a range of keys to be cleared. Enter the same number to both requests if you only wish to clear one.
COMPACT TO TOKENS - Basic stores commands and keywords internally with special token values. There is only a limited amount of memory space to hold function key definitions so it is useful for a function key to contain these token values rather than whole key words. It is usually rather difficult to do this as the control characters corresponding to each keyword must be calculated by hand. The program contains an automatic translation facility that will take complete unabbreviated keywords and convert them into the compact tokenised format.
SPACE LEFT - The space used to store function keys is fairly limited. This option shows how much space is left with all the keys stored in the buffer. Press the SHIFT key to continue the display when it pauses.
EXPAND KEYS - If keywords have been compacted as above it becomes very difficult to understand the resulting key definition. This option expands the tokens stored in the function key into the full Basic keywords.
UPDATE DEFINITIONS - When this program is used to alter the function keys the contents of the keys are kept by the program. The original definitions stored in the computer's buffer are left untouched until this option is used. This has the effect of copying the program's key definitions to the main buffer. This means that if you make a mistake editing a key you can exit from the program and try again without damaging the original definitions which are still present. This updating process is also automatically used by options 4, 5 and 6. So if one of these is used then any edited change is permanently stored in memory at this point.
EXIT - This leaves the program. Note that you should use option 7 to update the key definitions before using this option if the definitions held by the program are to be used.
MEMORY DISPLAY UTILITY
It is useful for many reasons to be able to look at the contents of the machine's memory. This program not only reads the contents of blocks of memory, but displays them in four different forms: namely decimal, hexadecimal, binary and ASCII. Each form has its uses, and to show the use of the ASCII form, try inspecting memory from &8000 for example.
To do this, run the program, and it will prompt for two pieces of data: a start address, and the number of locations to be inspected. Both values may be entered either in decimal or in hex (preceding the hex value with an ampersand '&'). If you enter &8000 for the start address, and say, 1000 for the number of locations to be inspected, you will see the start of the Basic interpreter that is held in ROM (see section 13 for an explanation of the Basic ROM). When the screen is full of
information, press SHIFT to continue scrolling.
Other interesting areas of memory to look at are:
The Operating System ROM
Memory the BASIC program is stored in (Tape users)
Memory the BASIC program is stored in (Disc users)
When writing your own programs you will often need to define one of the user defined characters. Without a program to help you, this is a tedious and frustrating task. This program is very easy to use, all the necessary instructions are displayed when the program is RUN. It is often the case that a few characters are needed to make a large object. This program allows you to define many characters together so that a large shape can be made occupying several characters. When all the shapes have been entered as desired, pressing RETURN will list out all the character definitions needed to incorporate in your own programs. Either send these to the printer or write them down, you must then include the series of VDU statements in your program. The characters are then accessed by character numbers.
This program is used to recover corrupted Basic programs in memory. Occassionally a bug in a program, a glitch in the power supply, or a minor hardware fault will leave a program in memory slightly modified. This usually results in the message "Bad Program" being displayed. This can also occur when a program is loaded from cassette with *OPT 2 set
to ignore cassette errors. Provided the program is only slightly damaged it is possible to recover from the "Bad Program" message and restore the program to a usable form. To do this, another program must be loaded which will operate on the program in memory and try to restore it. This program is the Rescue program. You will only need to use this if disaster strikes, and it appears to do nothing if used on a correctly stored program.
Using the program is slightly tricky as this program must be loaded into memory somewhere other than the space occupied by the corrupted program. To load and use the program use the following series of commands:
On the BBC...
On the Electron...
The program will now operate, showing line numbers and where they were found. Wait until the prompt re-appears. Your original program should now be ready to list. You should now save the program that has been recovered before doing anything else. When you list the program you may find spurious line numbers and strange characters in the listing. You will have to edit or re-type lines containing these. It is possible to have line numbers listed out of order. This is rather difficult to fix. The RENUMBER command may cure the problem. If this does not work then you can use the following sequence to re-type the whole program.
This prints out a listing of the program to cassette or disc and then re-enters it with the *EXEC command. This will ensure that all the lines are in the correct order in memory so that strange line numbers can be edited or deleted as normal. Any control characters that were found in the program are replaced with the ' ' symbol, so you will need to
replace any of these you find. If using cassette, make sure you have a cassette in the player ready for saving the program. Rewind the cassette first before pressing RETURN.
This program gives you global searching facilities for Basic programs. When writing a long program it is easy to forget where a particular procedure is defined or used. Rather than tediously search through the listing looking for it, you can use this program to perform the task for you. In addition the program can be used to replace one string with another throughout the program. This is often useful for changing variable names.
To use the program:
On the BBC...
On the Electron...
This assumes that you have already loaded in the program that you wish to edit at the normal PAGE setting. Options 3, 4 and 5 are self-explanatory. 3 and 4 both list all occurrences of DEFPROC and DEFFN respectively.
Option 1 will look through your program for a certain string. It can be used for strings in print statements, variable names, procedure names etc. It can also be used to look for a Basic keyword eg. PRINT, IF, GOTO, FOR etc. The keywords must be searched for separately as each keyword is stored as a single byte of the program. The program will only allow one keyword to be looked for at a time, but this can be with preceding or following text e.g.
/PRINT/ "HELLO" will look for PRINT "HELLO"
If the program cannot find the keyword enclosed in '/' marks then the message Invalid Keyword will be displayed.
This short program is designed to make experimenting with sound easier. It basically consists of standard definitions of 8 envelopes together with a simple mechanism for calling them. If you are trying to design a program with sound effects then you can take out one of the envelope definitions from the program and put it in your own. When you press ESCAPE to leave the program it tells you which line to list to display the envelope that you were last using. Some sounds you might like to try are:
4. Writing A Starter Package BASIC Program
This section is designed to show how a simple program can be built up in easy stages. To do this a specific example has been chosen, a simple reaction tester. This illustrates the use of procedures, integer variables, long variable names, INKEY, GET and the REPEAT UNTIL structure. A full listing of the program is given at the end of this section; you may find it helpful to refer to this as the program is developed.
The logic involved in a primitive reaction tester is quite straightforward, and the problem of creating a concept to perform this function provides an ideal testbed for introducing a range of concepts from BBC BASIC. In essence the program to be discussed will generate a prompt on the screen, and then start a timer which will run until the user presses
the Space bar. The reaction time will then be calculated and displayed on the screen.
4.2 The Program
BBC owners begin with the following lines:
10 REM REACTION TESTER
20 MODE 7
If you are using an Electron line 20 should enter Mode 6 not Mode 7, so use the following:
10 REM REACTION TESTER
20 MODE 6
All programs should start by telling you briefly what they do, and by setting up the machine to be in the correct mode for their operation. We have chosen a text only mode for this program as this leaves plenty of memory free.
The next task of the program is to wait for a few seconds, and then flash the prompt onto the screen. Try adding:
80 TIME=0:REPEAT UNTIL TIME >=500
100 PRINT TAB(18,13)"TEST"
Lines 30 to 70 and 90 have been missed out because they will be used in later development. Line 100 simply prints the word TEST approximately in the centre of the screen. Line 80 of the program uses two features of BBC BASIC to effect a time delay. First it sets the internal user clock to zero, then it uses the REPEAT UNTIL structure to wait until the clock reads 500 units or greater. Since the clock counts in hundredths of a second this gives a five second time delay. The TIME variable is an unusual one in that it will change in the background without you specifically assigning a value to it. Try running the program in this form.
4.3 Introducting Procedures
The time delay will be needed elsewhere in the program, so we would like to make this same piece of code available to other parts of the program, as yet unwritten. To do this we will use a procedure. Procedures are extremely useful and help you to program in a concise and structured manner and allow sections of code to be called from different places within a program. The code is placed at the end of the program, given a name and defined as a procdure (See later in this booklet). It may then be called from the program whenever it is needed with the PROC command. We will now do this with the five second time delay. Enter the following lines:
1000 DEF PROCwait
1020 REPEAT UNTIL TIME>=500
Note that running the program will have the same effect as before, but the time delay works by calling the wait routine at line 1000 and then returning to the main program and continuing. The END statement has been put in to stop the program attempting to execute the DEFPROC statement at line 1000.
In this particular case the procedure we have defined is so short that we did not really need to define a procedure to perform this task. However it makes the program easier to read if the main body contains the command PROCwait rather than a short piece of code whose meaning is not immediately obvious. The ideal structure to make your program readable is to have a short main control program that calls a number of procedures, each of which carries out a specific task. We could
structure the problem even further by having PROCprintprompt to print out the word TEST. This is however a little ridiculous as it is obvious what the line does in its current form, and we are unlikely to need the routine elsewhere.
Line 100 of the program now puts the word TEST on the screen. This is the cue for the user to hit the Space bar as quickly as possible. We want to know how long they take to do this so we must use the TIME variable again.
Line 110 sets the timer to zero. Line 120 waits for the user to press a key, the character typed will then be stored in the string variable A$. Whilst the program is waiting for the user to press a key the computer is automatically updating TIME continuously in the background. When the key is pressed the program flows on to line 130 where the current value of TIME is stored away. We must do this immediately as TIME is continuously being updated. If several lines of code are executed before TIME is checked it will have increased to a larger value. The number is divided by 100 to give a time in seconds as TIME is in centi-seconds. Note that a long variable name has been used to make its function clearer.
4.4 Checking For A Particular Key Press
We have now developed a working program. It is however rather unsatisfactory as it is very easy to cheat and it will respond to any key being pressed. In the original specification it was to be the Space bar that would stop the timer. To make it only respond to the Space bar is very easy.
120 REPEAT UNTIL GET$=" "
This is a slightly odd line as the REPEAT UNTIL loop contains no instructions. All the work is performed by the test at the end. When this line is encountered the computer waits for a character to be typed for the GET$ function. If this character is not a space then control flows back to the REPEAT statement. If it was a space then the loop is finished and control passes to the next statement, on the following line. We used a similar structure in line 1020 to control the time
This game was mentioned in the following articles: