PiTubeDirect

By David Crookes. Posted

The creators of Raspberry Pi owe much to the BBC Micro – the first computer owned by Raspberry Pi Foundation founder Eben Upton and the one that taught children to code in schools across the UK.

The 1980s gem inspired the affordable microcomputer we've come to know and love, so we adore how this project brings both together, using Raspberry Pi to enhance the BBC Micro by allowing another external CPU to be added.

This idea is not new. BBC Micro maker Acorn included a port called Tube for this very purpose and it released a range of second processors to expand a machine with limited RAM. But Acorn's original set of second processors can be expensive and tricky to find, so PiTubeDirect recreates them on Raspberry Pi.

As such, BBC Micro enthusiasts can enhance their computers by adding a second 6502 or they can add external Z80, 32016 and ARM1 second processors – the latter used to develop the Archimedes range.

“The second processors would take responsibility for running the current language and the user's programs, leaving the BBC Micro host responsible for the keyboard, screen, and file system,” says project originator David Banks. “The Tube architecture was unique and very innovative at the time.”

Timing it right

 David Banks originally created a 6502 second processor using a field-programmable gate array. Raspberry Pi reduced the cost, and this was the first prototype

To enhance a BBC Micro in this way, users need a level-shifter HAT connected to Raspberry Pi’s GPIO interface which, in turn, is hooked to the BBC Micro's Tube port using a 40-pin IDC cable. After installing the PiTubeDirect software to a microSD card, you simply plug and play.

Yet getting to this point has been a challenge. “We were brainstorming what it would take to connect Raspberry Pi Zero to the Tube port with the absolute minimal amount of hardware,” recalls David, who began tinkering with the BBC Micro again in 2013 after discovering people were preserving the computer and developing new hardware and software.

“The BBC Micro's Tube interface is just an extension of the 6502 microprocessor bus and it uses 5V signal levels. Raspberry Pi uses more modern 3.3V signal levels, so the minimum hardware is just a couple of off-the-shelf level-shifter chips. 

“But such a solution is only feasible if Raspberry Pi, in software, can do everything else, including responding to Tube requests in real time.” Achieving that was tricky.

To the bare metal

The original BBC Micro Model B had 32kB, but Acorn’s originally released 6502 second processor included a 50 percent faster 3MHz 65C02 CPU, as well as 64kB of RAM

The wizardry used to interface the BBC Micro to a second processor was originally encapsulated in the Tube ULA custom chip. “Every second processor that Acorn produced contained one, providing a set of four bidirectional FIFOs that allow the ‘host’ and ‘parasite’ processors to communicate via a series of well defined messages, called the Tube Protocol,” explains David.

Emulating this entailed using software running on Raspberry Pi and it needed to meet the hard real-time constraints of the 2MHz Tube interface.

“We knew running a conventional operating system like Raspberry Pi OS would not yield the required guaranteed response time,” David says. “So, we dispensed with the operating system and engaged in 'Bare Metal' programming, developing software by directly accessing the hardware of Raspberry Pi Zero.”

To further resolve time-related problems, Dominic Plunkett joined the team and suggested moving the Tube ULA emulation code on to the GPU. Dominic also optimised the emulation speed of the 6502 to 292MHz, thus making it 150 times the speed of the original 2MHz BBC Micro. 

One thing's for sure, it's been an education. “One of the more satisfying aspects of developing PiTubeDirect has been learning about programming at the lowest bare metal level,” notes David. “And that's very much in the same manner that we would really get to know machines back in the 1980s.”

From The MagPi store

Subscribe

Subscribe to the newsletter

Get every issue delivered directly to your inbox and keep up to date with the latest news, offers, events, and more.