Sunday, 10 June 2018

ZXBaremulator - Bare metal ZX Spectrum emulator for Raspberry Pi

ZXBaremulator is a bare metal ZX Spectrum emulator for the Raspberry Pi by José Luis Sánchez , and something I have been meaning to look at for a while.
This runs directly on the Raspberry Pi, using it as a single board computer, rather than a linux box (in a similar way to the RISC OS Pico I used with the Acorn Electron). Without any operating system in the way, it boots within a few seconds of powering on, and you are greeted with the familiar copyright notice.
From here, you can type away and run BASIC programs.
Press ALT+K to see a cheat sheet of all the keys available.
As nice as that is, you're probably going to want more. Press F1 and you get a menu that allows you to select tap or tzx images (but not z80 it seems).
Once one is selected, you press F1 to go back to the Spectrum, and type LOAD "" as usual.
The tape image then loads as normal (although it is speeded up a bit).
After a short while, the game is loaded and you can play to your hearts content.
CTRL+break resets the Spectrum, and you can then go and select another game.
You can also select 48K, 128K and +2A using ALT+F2, F3 and F4,
I have been running these for a while, through all my usual test titles and it seems to be running well.
Even passes all the diagnostics tests in 48K and 128K mode.
The only issues I found were the top and bottom of the screen, on power on, the top line appears to have a small section missing in the top left.
After selecting a program to load, the gap at the top is gone, but there is now a thin blue line along the bottom of the screen.
The other issue I had was lack of sound, I think that is because I was using version 2.0 of the software. V3.0 apparently has sound, but doesn't work on the Pi Zero.
One of the reasons I wanted to look at this was to check compatibility with my ZX Spectrum USB keyboard kits. I have been using these for many years, mainly with the Fuse emulator, so I expected it to work.
All seemed fine, until I tried to type LOAD "". It seems that symbol shift wasn't being recognised. I had seen a similar issue with an unusual emulator for older Macs that used the right alt key for symbol shift, rather than either control key, as most other emulators use. However, I had been using ctrl+p on a standard USB keyboard during testing.
After further investigation, it turned out that when my Spectrum USB keyboards are switched into emulator mode, I was only sending keypress codes for the shift keys. This isn't an issue normally, and was required by another unusual emulator someone was using. When I set it to send the key as both a keypress and a modifier, it started working.
The ZX Spectrum USB keyboards come with a button on the back to change between modes. In the 'normal' or 'desktop' mode, the keys are remapped to be most useful. Caps lock + keys on the top row give some extra functions, which are handy for starting and selecting games in an emulator for example.
I have produced a revised version of this which includes keys used by ZXBaremulator, F1 to load the menu, Alt+F2/3/4 to select a machine, F8 to stop and start the tape. I've used caps shift+enter to show the keyboard shortcuts, and caps shift+space to reset the Spectrum. Those are all available in the normal mode, press the button on the back to enter emulator mode, where all the keys are passed directly to the Spectrum, and press the button again return to the alternate layout and use the extra keys.
I have build many versions of the 'Raspberry Pi inside a ZX Spectrum' over the years.
These often involved extra power boards and cables, and with the Pi zero, usually a USB hub.
Today, however, I went for a more basic approach. There are many ways to mount a Pi zero, but you could just use a sticky foam pad.
There is an option to use the 4 pin header to wire up the USB keyboard, but you can just use a right angled cable.
The ZX Spectrum USB keyboard kits are available from my Tindie store.

If you want to support this blog, you can donate via Patreon or Paypal, or buy something from my store.