Using an RP2040 to Load Programs from a SD Card into a ZX81 Microcomputer

This was a fun project, putting together my old and new hobbies. Back in the 80s, cheap personal computers used K7 tape to store programs. I still got a few of these old computers, but tape is pretty rare these days and my K7 players are breaking apart. You can find a lot of ZX81 software in the internet, as files for emulators. How about using an RP2040 to generate the necessary audio signals from these files?

The final assembly


How the ZX81 Loads and Stores Programs

The ZX81 microcomputer was as frugal as it comes. Using only 4 chips (a Z80 microcontroller, an 8K ROM, a 1K RAM and a custom chip known as "ULA"), it can be connected to a TV and includes a very quirky BASIC interpreter.

With cycles and ROM bytes at a premium, saving and loading was done by small loops in the BASIC interpreter (written in assembly). At the lower level, 0 and 1 bits are coded as sequences of pulses (4 pulses for a 0, 9 pulses for a 1), followed by a short period of silence. There is no special mark between bytes or signaling the start of a byte. What is saved? First there is the program name, with the last character with the high bit at 1. Then a dump of most of the memory, including some system variables, the screen, the BASIC program, and the BASIC variables (so a loaded program could just resume operation from where it was when a SAVE command was executed).

Testing using a Brazilian ZX81 clone


The usual format for the program files on the internet (.P files) is just the memory dump (sometimes with garbage at the end).

The Hardware

In the final assembly I used an RP2040 Zero from Waveshare, during developing I used a Raspberry Pi Pico (for easy access to the debugging pins). An LCD display and a rotary encoder is used for user interaction and an SD module is used for reading the SD card.

A single NPN transistor is used to interface the RP2040's signal to the tape input in the ZX81.

The Software

Here is where the fun comes! I used an existing library ( "no-OS-FatFS-SD-SDIO-SPI-RPi-Pico") is used to read the files from the SD card. I already had code for the display and rotary encoder.

That leaves the pulse generation. For a first test, I just used delay calls to timing, but I could not resist using the PIO for this task. Using the PIO I just load bytes into the PIO FIFO and it takes care of shifting the bits and generating the pulses. This eases the time constrains on my code and allows to show the progress on the LCD.

In the end, I used three PIO programs: one for the pulse generation, one for reading the rotary encoder, and one for controlling the RGB LED on the RP2040 Zero.


The full project is available at https://github.com/dquadros/PicoK7










Comments

Popular posts from this blog