Emulate a BBC Micro on Raspberry Pi 400

With an optimised version of the B-Em emulator, Raspberry Pi 400 can take us back to the heyday of the British micro that inspired it. It’s #MagPiMonday, so let’s take a look at this tutorial by KG Orphanides from the latest issue of the official Raspberry Pi magazine.

From schools to bedrooms, Acorn Computers’ BBC Micro helped to kick-start a revolution in software and hardware development. Its influence is imprinted on products ranging from the ubiquitous Arm processors to modern gaming blockbusters like Elite Dangerous.

This build works beautifully with our retro joystick projects, but modern controllers work just as well and give you more buttons to assign
This build works beautifully with our retro joystick projects, but modern controllers work just as well and give you more buttons to assign

But emulating the BBC on modest hardware has traditionally been a chore. There are several excellent BBC emulators, and you can run most of them on Raspberry Pi, but only at the cost of major performance issues.

That’s no longer the case, thanks to Raspberry Pi Pico SDK architect Graham ‘kilograham’ Sanderson who’s forked an optimised version of the B-Em emulator that’ll run smoothly on both the Raspberry Pi Pico microcontroller and Raspberry Pi SBCs.

01. Check your graphics settings

When building this B-Em fork for Raspberry Pi, you need to make sure that the compositor is disabled and that you’re not using the legacy video driver. If you’re running a fresh Raspberry Pi OS Bullseye install on Raspberry Pi 400, neither of these should be the case, but it’s worth checking.

To do so, open a Terminal window and type:

sudo raspi-config

Select ‘6 Advanced’, then ‘A3 Compositor’. Make sure this isn’t enabled. If your hardware and OS versions support the legacy video driver, you’ll also find this in the advanced menu. Similarly, make sure it’s disabled. Reboot.

Make sure that the Pico SDK, Pico Extras, and B-Em source code folders are all in the same directory before you compile
Make sure that the Pico SDK, Pico Extras, and B-Em source code folders are all in the same directory before you compile

02. Gather your dependencies

At the Terminal type:

sudo apt install build-essential cmake libdrm-dev libx11-xcb-dev libxcb-dri3-dev libepoxy-dev ruby libasound2-dev

Although we’re building B-Em for Raspberry Pi, we’ll still need the Pico SDK. The Pico SDK, Pico Extras, and B-Em folders all need to be in the same directory. We’ll make a directory called Pico in our home root to put everything in, then put all the software we need in it.

You should substitute the wget URL in the next step with the current release version of the Pico SDK.

03. Build B-Em

Enter the following Terminal commands to download and make the software:

  cd
  mkdir Pico
  wget https://github.com/raspberrypi/pico-sdk/archive/refs/tags/1.4.0.tar.gz
  tar -xzf 1.4.0.tar.gz
  git clone https://github.com/raspberrypi/
pico-extras.git
  git clone https://github.com/kilograham/b-
em.git
  cd b-em
  mkdir pi_build
  cd pi_build
  cmake -DPICO_SDK_PATH=path/to/pico-sdk -DPI_
BUILD=1 -DPICO_PLATFORM=host -DDRM_PRIME=1 
-DX_GUI=1 ..
  make -j4

Following these instructions, the path to Pico SDK will be something like: ~/Pico/pico-sdk-1.4.0.

04. Is this thing on?

B-Em emulators for the BBC Micro (xbeeb) and Master (xmaster) will be built two directories below the pi-build directory we made earlier, in src/pico. Assuming you still have the Terminal open from the previous step:

cd src/pico 
./xbeeb

You should find yourself looking at an emulation of a 32K BBC Micro running Acorn’s 1770 DFS (disk filing system). 

05. Would you like to play a game?

Unlike other BBC emulators, including the fully loaded versions of B-Em, there’s no graphical interface to browse and load disk image files. Fortunately, B-Em for Pico loads a copy of Eben Upton’s port of puzzle game 2048 by default. Not all the keys and characters on Raspberry Pi 400 map tidily to those of a BBC Micro – see Figure 1. In B-Em, type:

*.

…to list the files on the virtual disk, then:

*EXEC !BOOT

…to run the program.

06. Key combinations and commands

In this version of B-Em, F11 opens the menu, navigable using the mouse or arrow keys. Press ENTER to select an option and, if it flashes after selection, to confirm it. Press ESC to exit the menu or opt out of a flashing selection. The pared-down menu gives you sound and graphics settings, access to embedded disks, and a hard reset. To exit B-EM, close the window or press ALT+F4 to terminate the program.

We’ve already seen that *. lists the files on a disk and EXEC executes a program. You can find a helpful lookup sheet for other commands and for BBC BASIC in general here. An HTML version of the BBC Micro User Guide exists here.

This version of B-Em has a stripped-down F11 menu but it includes critical sound and video options, plus embedded disc image handling
This version of B-Em has a stripped-down F11 menu but it includes critical sound and video options, plus embedded disc image handling

07. Loading disk images

Although there’s no disk image browser, you can launch B-Em to run a specific disc image. The .SSD and .DSD formats are supported, these are the most commonly used to distribute modern BBC games. 

Download Infuto’s Guntus shoot-’em-up here (direct download) and save it to your Downloads folder.

To load it, the command with full paths should be:

 ~/Pico/b-em/pi_build/src/pico/xbeeb
~/Downloads/Disc172-Guntus.ssd

We’ll make some shortcuts to tidy that up later. In B-Em list the files by typing *., then load Guntus with:

CHAIN"GUNT-IN"

We could also have used *EXEC !BOOT, as a boot file is present.

There weren’t many consistent standards for game or cursor control layouts in the early 1980s, leading to some creative approaches, demonstrated here by Citadel
There weren’t many consistent standards for game or cursor control layouts in the early 1980s, leading to some creative approaches, demonstrated here by Citadel

08. Embedding disks

You can also embed disk images at build time. By default, B-Em boots with two embedded disks: 2048 and the iconic BBC Welcome disk. You can switch between them in the F11 menu, by going to Disc 0, using the left and right arrow keys to navigate to the option you want, then pressing ENTER.

In our ~/Pico/b-em/src/pico/discs/ directory, you’ll find a file called beeb_discs.txt, alongside several disk images. Add new embedded disks by inserting a line at the bottom formatted thus:

  Your Label For The Disk = /path/to/disk/
image.dsd

Alternatively, you can create a file in the same directory, called beeb_discs_user.txt, with entries formatted in the same way. This will automatically supersede beeb_discs.txt. Labels can have spaces; paths and file names cannot.

Once you’ve added your list of files to embed, repeat the final make -j4 command in the pi_build directory from Step 3.

Figure 1 BBC Micro keyboard map for the UK Raspberry Pi keyboard. BBC keys are marked in red
Figure 1: BBC Micro keyboard map for the UK Raspberry Pi keyboard. BBC keys are marked in red

09. Sticks of joy

Joystick support isn’t built into this version of B-Em, but you can use mapping software to work around this. AntiMicroX can map any recognised joystick, from a Sony DualShock 4 to the Pi Pico-powered DB9 joystick adapter we made in issue 125, or our older GPIO joystick adapter. At the Terminal:

sudo apt install 
antimicroantimicrox

A popular control schema for games used Z to move left, X to move right, : for up, and / for down, with SPACE and RETURN configured as jump and/or action keys. If you only have one joystick button, assign it to whichever you need most often. AntiMicroX supports multiple control profiles, so it’s easy to switch between the most common.

10. A smoother startup

Let’s add some symlinks and shortcuts Open a Terminal and type:

  sudo ln -s ~/Pico/b-em/pi_build/src/pico/
xbeeb /usr/bin/local

You can now launch xbeeb by name at the Terminal, no path required. You’ll still need to provide paths to disc files you wish to launch, though.

We’ll also make a desktop launcher. Create a text file called b-em.desktop on the desktop, or add it to Raspberry Pi OS’s main menu by placing it in ~/.local/share/applications. See the code listing for the full launcher file. If you want to launch from the desktop, embed the disks you use regularly, as there’s no file browser. To ensure that .desktop files are executed by default, in the file manager go to Edit > Preferences and tick ‘don’t ask options on launch executable file’.

Mapping a controller with AntiMicroX is a convenient way of both adding retro joystick support to this version of B-Em, and replacing old-school keyboard layouts with something more familiar
Mapping a controller with AntiMicroX is a convenient way of both adding retro joystick support to this version of B-Em, and replacing old-school keyboard layouts with something more familiar

11. Getting new software

There’s a vibrant homebrew scene for the BBC Micro. The non-commercial section of the Complete BBC Micro Games Archive is home to 29 games released in 2022 alone, plus hundreds of older freeware and public domain titles ranging from the 1980s to the present. New releases are usually announced on the forums of mainline B-Em and BeebEm maintainer group Stardot.

Modern BBC Micro games like Brian Tierney’s Blue Wizard are able to use impressive graphical techniques not readily available to BBC devs in the early 1980s
Modern BBC Micro games like Brian Tierney’s Blue Wizard are able to use impressive graphical techniques not readily available to BBC devs in the early 1980s

12. Learn to program like it’s 1985

Many of Usborne Books’ classic 1980s guides to computer programming are now available for free here. BBC Micro projects feature heavily. 

There are even modern publications that review and analyse software for 8-bit platforms including the BBC Micro, such as The Classic Adventurer, while historians and enthusiasts have archived contemporary magazines and fanzines at sites including the Educational Software Archive for the BBC Micro, 8BS, and The Internet Archive.

4 comments

Bob avatar

10 PRINT “AWESOME”
20 GOTO 10

Would I be right in assuming that if it runs well on a Pico it’ll run well on an original first generation Pi Model B? (Original as in 256MB RAM.)

scruss avatar

If you want a slightly less involved build that doesn’t bring in the extra weight of the Pico SDK and uses a slightly more up to date repo, try these instructions: How to build b-em on Linux — https://github.com/stardot/b-em/wiki/Building-on-Linux

Bob: it would be extremely slow on a Model B. The Linux version runs under X (so bigger, slower) but the Pico version runs bare metal

Adam avatar

Built successfully and able to run discs. However, your comment at the foot of the article about learning to program sparked my interest. Hit a wall almost immediately. It’s only worth doing that if you can save your programs, which, without a blank disc you cannot. So I duplicated the welcome disc renamed it and followed the above to point to it and include it in the f11 list. I attempted to format it using the program on it (*FORM 80 0), and keep getting
Disc Read Only
Bad program.
Any ideas how that read only can be removed? I can’t peel the tape off a virtual disc! I have chmod the disc image to 777 in a cheeky attempt to make sure it wasn’t to do with linux permissions.

Liz Upton avatar

There’s (from memory!) a file menu option to turn off write-protect on whichever drive you’re using. Go have a look and let us know if that works!

Comments are closed