Run a BBC Micro
Les Pounder reminisces about that one time when he caused a core meltdown in a nuclear reactor, then flew away in a spaceship.
Les Pounder remembers the time when he caused a core meltdown in a nuclear reactor, then flew away in a spaceship.
The BBC Micro was a popular fixture in 1980s classrooms in the UK. It was developed by Acorn Computers after successfully winning the interest of the British Broadcasting Corporation’s (BBC) Computer Literacy project with its hastily created Acorn Proton computer. This catapulted Acorn’s fortunes and saw the BBC Micro become a popular, if expensive choice for home computing enthusiasts.
The BBC Micro was also quickly adopted by educational bodies, and children (including us!) learnt programming via this machine. One of this author’s first encounters with a BBC Micro was controlling a simulated nuclear reactor that may have gone critical due to a careless mistake.
The BBC Micro was powered by a MOS Technology 6502/6512 processor running at 2MHZ. It came with a plethora of ports, some providing access to a GPIO of sorts: a 15-pin analogue port typically used in science experiments, and a user port which has a digital interface that can be used to control basic electronics.
Initially, the BBC Micro had two “main” models: the 16KB Model A and the 32KB Model B. But future releases saw further models: the B+, Master and Plus 32. All of these models saw expanded memory options as well as additional ports and functionality while retaining compatibility with the core machines. Fans of the Raspberry Pi will recognise the “Model” names because the Raspberry Pi was directly influenced by the
BBC Micro. Yet the legacy of the BBC Micro isn’t just limited to this. The BBC Micro was also used as the test bed for the ARM CPU architecture – a CPU architecture present in the myriad of portable devices that are now a massive part of our everyday lives.
The BBC Micro lasted from 1981 to 1994, but its legacy has lived on and right now it’s enjoying a resurgence of interest, especially its fantastic BBC BASIC which is stored in ROM ready for use. Based upon the earlier Atom BASIC, BBC BASIC was developed by Sophie Wilson and colleagues at Cambridge University. BBC BASIC is simple to use, and “friendlier” to new users than many others of the era.
The best way to learn more about this great machine is to get hands on, and in this tutorial we shall do just that. We’ll learn how to load games in an emulator, and write code in a dedicated BBC Micro code editor.
Emulating a BBC Micro
To write code for our BBC Micro we chose to use BBC
BASIC for SDL, available from www.bbcbasic.co.uk/ bbcsdl. We installed the version for 64-bit Linux on our test machine running Ubuntu 18.04.
To install, download the BBC SDL archive and extract the contents to your computer.
For Linux we need to install a few dependencies. Open a terminal and run the following commands:
$ sudo apt install libsdl2-2.0-0
$ sudo apt install libsdl2-ttf-2.0-0
$ sudo apt install libsdl2-net-2.0-0
Navigate via the terminal to the directory where the files were extracted. In the directory will be a file, bbcsdl,
which we need to make executable. In the terminal use the chmod command to set the file as executable:
$ chmod +x bbcsdl
We can now run the application by typing the following command:
$ ./bbcsdl
On start, BBCSDL will ask which editor we would like to use. We chose BBCEDIT for this tutorial, but both
BBCEDIT and SDLIDE are equal in our opinion.
Writing an application
BBC BASIC is well known to have started the careers of many coders. The language is similar to other BASIC variants of the era, but it extends the standard BASIC with extra keywords for procedures and functions, REPEAT UNTIL loops and IF THEN and ELSE structures. BBC BASIC is where many 1980s UK school children cut their teeth with coding. From simple “Hello World” loops, to complex code for the GPIO, BBC BASIC was a capable and easy-to-use language. So let’s take a stroll through memory lane and use BBC BASIC to write a simple calculator application that will employ many elements of the language.
Building the calculator
We start building the calculator code by first introducing the name of the project, and then provide instructions to the user. The calculator works by asking for two numbers; these can be either integers or floats. Then we ask the user to press a key to perform a specific action:
10 PRINT “LXF BBC Basic Calculator”
15 PRINT “Enter two numbers to be used in the calculation, press Enter after each number. Then...” 20 PRINT “Press A for Addition”
30 PRINT “Press S for Subtraction”
40 PRINT “Press M for Multiplication”
50 PRINT “Press D for Division”
How do we get the users numbers and store them for later use? For this we use the INPUT command, which will store the two numbers as variables, X and Y:
56 INPUT X,Y
Lines 60 to 90 use variables for addition, subtraction, multiplication, and division (A, S, M and D) and each letter stores an integer that corresponds to the value returned for pressing each key.
60 A=65
70 S=83
80 M=77
90 D=68
Line 100, here we GET the key being pressed, and save that value to a variable, KEY% .
100 KEY% = GET
We now move into a series of conditional statements. These check to see if the value stored in KEY% , the keypress, is the same as the values stored in the variables A,S,M and D. If there’s a matching value, a GOTO will then direct the code to the appropriate line number, effectively branching the code:
110 IF KEY%=A GOTO 200
120 IF KEY%=S GOTO 250
130 IF KEY%=M GOTO 300
140 IF KEY%=D GOTO 350 150 ELSE GOTO 400
155 ENDIF
If the user chooses to add the two numbers together, then we go to line 200. We print that the user has chosen to add the numbers, then on line 205 we add them together after a short print statement. Line 210 sees our code go to line 400, the end of the project.
200 PRINT “Addition”
255 PRINT “The answer is ",X + Y
210 GOTO 400
Lines 250 to 260 repeat the same process, but this time the numbers are subtracted:
250 PRINT “Subtraction”
255 PRINT “The answer is ",X - Y
260 GOTO 400
Lines 300 to 360 handle multiplying and dividing the two numbers:
300 PRINT “Multiplication”
305 PRINT “The answer is ",X * Y
310 GOTO 400
350 PRINT “Division”
355 PRINT “The answer is ",X / Y
360 GOTO 400
Lines 400 is the end point for every branch in the code. It prints a message to the user before moving to line 410 to END the calculator: