TomDDG / ZXPicoMD

Raspberry Pico ZX Spectrum Microdrive Hardware Emulator
GNU General Public License v2.0
54 stars 4 forks source link

ZXPicoMD

image

Raspberry Pico ZX Spectrum Microdrive Hardware Emulator (https://en.wikipedia.org/wiki/ZX_Microdrive)

Hardware emulation of 8 microdrives for the ZX Spectrum only (no plans to adapt for the QL, if you want a Microdrive emulator for the QL see http://oqtadrive.org/). Main features are:

Load up the SD card with all your favourite games and programs and enjoy hours of nostalgia with the blistering 15kB/sec transfer rate. Yes you can now load a game in a few seconds!

[!TIP] I highly recommend you use a modern regulated PSU with your Spectrum. Older unregulated PSUs, which will now be 40yrs old, could push voltage spikes through to the ZXPicoMD as it is connected directly to the 9v input. The Traco used in the design should filter out most but if you also use the barrel jack to switch your computer on and off (pull out and back in) something called barrel bounce could happen which results in very large spikes, too large for the Traco to filter out. This could damage the ZXPicoMD, and possibly other devices connected if they use 9v input. In this situation the Traco is fine but the Raspberry Pico wouldn't be. If you insist on using an original PSU then I highly recommend additional filter capacitors on the input and output of the Traco (22uF 50V capacitor on ouput to ground & 10uF 50v on the input to ground).

How to Get One

Installation

If you are building your own start at step 1, for pre-built jump to step 5

  1. Download the correct UF2 from the UF2 folder (_w for Pico W)
  2. Flash the Pico with the UF2 (see 3.2 https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf)
  3. Build the circuit (see below) - best to use the PCB (https://www.pcbway.com/project/shareproject/Raspberry_Pi_Pico_ZX_Spectrum_Microdrive_Hardware_Emulator_37750e81.html)
  4. Print a nice case to house the device (optional)
  5. Format a blank Micro SD Card (recommend exFAT) and insert into the SD Card reader
  6. Connect to the IF1 using an appropriate cable
  7. Turn on the Spectrum and you should see the splash screen if all working

Version History

First Usage

First you need to format your micro SD card using a PC/MAC, I recommend exFAT but FAT32 is also fine. Using the same PC/MAC you can also create a folder for your files and copy games or programs into these directories. You don't need any files for the device to work so this is just if you want to use it to load games etc... Insert the micro SD Card into the device while it is powered off and then turn on the Spectrum with the device connected. If all ok you will see a Splash Screen followed by a screen saying it is setting up the SD Card. Just wait for this to complete and once the screen goes blank and the blue LED comes on you are good to go.

Usage

The device is very simple to use, upon booting the Spectrum you will see a Splash Screen which will disappear after a couple of seconds. The screen will then stay blank (OLED is off to prevent burn-in) and the blue LED (or whatever colour you picked) will light up on the side to indicate the device is ready for input, either from the IF1 or by the user pressing a button. You can now use all the normal commands on the Spectrum to control the drive such as RUN, LOAD *"m";1;"aaa" or FORMAT "m";5;"blank".

When the blue LED is on so the unit is input ready you can enter the Menu to select new cartridges etc... for full list of menu items see the chart below. To enter the menu press the enter key which is 3rd from left. You should now see the Cartridge 1 icon. Pressing enter again takes you to the cartridge sub-menu, showing a folder icon. Pressing again and you will enter the file explorer where you can navigate the listings to pick a new cartridge or snapshot to convert.

The buttons are (from the left): Previous; Next; Enter; Back; Reset

image

Previous & Next are used to go left/right or up/down in the menu or file explorer. Enter is used to select an option or file (also to enter the menu in the first place). Back goes up one level in the menu or when using the file explorer moves up one directory. Reset reboots the Pico if all else fails (also useful when flashing the Pico). If you hold down the buttons it also behaves differently in certain scenarios, for example holding down Next in the file explorer goes down one page of file entries rather than just one file entry.

The LEDs show certain activity:

  1. The top LED (furthest from the buttons) is Drive and Write for when the Microdrive is being accessed. Drive will come on when the simulated motor is on (if you installed a buzzer you will also hear it). Write will come on (replacing Drive) when the ZXPicoMD is receiving a WRITE signal.
  2. The other LED is for SD Card access and Input ready. SD Card is simply to show when the SD card is being accessed (don't turn off). Input ready is to show when the drive is idling and therefore ready for a command or input.

image

Development

Built from the ground up using the the Pico C SDK (https://raspberrypi.github.io/pico-sdk-doxygen/). Uses Pico multicore to separate the time critical emulation components (core 1) to the interrupt driven IO (core 0). For more details on how I built the code please see the code section

Big thanks to Alex from OqtaDrive fame (https://codeberg.org/xelalexv/oqtadrive) for help with understanding the Microdrive hardware & troubleshooting.

Some additional references:

Code makes extensive use of the excellent Pico SD Card Library by carlk3 (https://github.com/carlk3/no-OS-FatFS-SD-SPI-RPi-Pico). This gives full access to the also excellent small embedded systems FatFS (http://elm-chan.org/fsw/ff/00index_e.html).

Design Decisions

Outside of basing this around the easily obtainable Raspberry Pico I also made the following design decisions:

Connected to a ZX Spectrum

Following image shows everything connected. The ZXPicoMD is fully compatible with the Multiface 1 and 128 (shown in the photo).

image

The IF1 Cable

To connect the ZXPicoMD to an Interface 1 you need the correct ribbon cable. All IF1s came with this but they can be easily replaced if yours has gone missing. There are plenty on eBay (just search microdrive cable) or you can build your own. To do this you will need:

Cut the ribbon cable to around 15-20cm length and on the two IDC connectors remove the 3rd pin in from the top & bottom, these should just pull through. In the resultant gap insert some plastic to create a key for the PCB notch, I 3D print these (see ExpansionPin https://www.thingiverse.com/thing:5908920). The cable needs the notch on the same side so lay the connectors back to back with the missing pin on the same side on both (see photo). Now insert the ribbon cable and crimp using a vice or similar.

image

Warning If using with a real h/w Microdrive you must use the correct Connection Block between the ZX PicoMD and the Microdrive, not this ribbon cable. A connection block passes the pins straight through, whereas the cable will flip the pins top to bottom resulting in 9v being passed to the wrong pin which could damage your Microdrive. I've created a design so you can make your own (https://www.thingiverse.com/thing:5908920), or you can find them on eBay now and again. v1.3 of the PCB prevents the connection of the ribbon cable on the wrong side, as per the original Microdrive design.

The GUI

Main Menu

Microdrive Sub-Menu

The file explorer will only show compatible files, those with extension MDR, TAP, Z80 & SNA and directories.

image

image

Quick Swap

Firmware v1.3 added quick swap functionality to drive 1 allowing the user to quickly swap between 4 pre-loaded cartridges. This was only added to drive 1 as this drive number is often hardcoded into programs so being able to quickly flip between cartridges is an advantage.

To use Quick Swap on drive 1 you have to first turn it on. To do this go into the menu (enter button), select drive 1 and scroll one right of the folder icon. You should see an icon with a swap symbol. Click on this and you will get a message that it is setting up Quick Swap for Drive 1. This takes a few seconds as it is creating 4 new cartridges, copying the contents of the current drive 1 cartridge to A, and creating 3 blank cartridges B,C & D. Once done it goes back to idle (blue light) and is ready to use.

To quickly swap the cartridges just press the PREV or NEXT buttons and a selector will pop up showing cartridges 1A to 1D. Just pick the one you want, press enter and it will complete the swap. Simple as that.

If you want to put a new image into a certain quick swap cartridge just first select the one you want, say 1D, and then just use the normal menu options to load a Z80 or format it etc... If you turn off quick swap (using the same icon), the cartridge currently selected remains in drive 1 and the others are lost, so recommend you save them first if needed.

TAP copy

Selecting a TAP file from the file explorer will copy the contents to a blank cartridge. It works with headerless files as well as normal and also removes the autorun from basic files so they can be edited. As headerless files have no file type or start address these are simply set as a code block starting at memory end minus length.

Note this is a simple file copy so if you are wanting to run a loader, usually for a game, off the cartridge you will need to adjust said loader to use Microdrive commands. Unfortunately this isn't always possible as a lot of games use machine code loaders but some are and the following details how to do this for the classic Manic Miner.

Once the copy has complete CAT the drive and you will see

image

Now Load the (Info) file:

image

This will show details of the files copied from the TAP in REM statements. Write down the filenames mm1 (the loading screen) & MM2 (the main code) for later.

image

Now load the main basic loader ManicMiner:

image

and LIST

image

Now edit the loader with the correct Microdrive syntax *"m";1; and filenames you wrote down earlier:

image

Save this as RUN with autorun LINE 1 added so you can use the shortcut on reboot:

image

The game will now load using RUN:

image

Working with Real H/W Microdrives

image

Note If using with a real h/w Microdrive you must use the correct Connection Block (shown below) between the ZX PicoMD and the Microdrive not the cable you use to connect to the IF1.

image

As of release v1 beta you can now put real h/w Microdrives downstream of the ZXPicoMD. Please note these only work downstream (ZXPicoMD closest to the Spectrum) as the ZXPicoMD needs to control the COMMs shift register in order to mix virtual/emulated drives and real h/w drives. Any drive combination can be used with the only restriction being a lower numbered drive will be activated first, example, if you pick drive 2 & 4 as real h/w drives the lower number, 2, will be the one next to the ZXPicoMD and 4 the one after.

The following diagram shows how to select drive 1 as real h/w.

image

and how to add drive 3 as real h/w.

image

With drive 1 & 3 set to real h/w, CAT 1 will access the first real drive connected to the ZXPicoMD. CAT 3 will access the second real drive, the one connected to the first real drive. All other drive selections will access a virtual/emulated drive.

To flip back to virtual/emulated drive just select the drive in the menu.

Using the Filename Selector

When saving a cartridge to the SD card you can specify a filename by using a simple character selector as show below:

image

Use the previous and next buttons to pick the character you want and press enter to select the character, note unless you are on the last character the enter is used to select the character not to complete the name. To complete the name before the last character there is a complete name option towards the beginning of the selector (see list below). To delete an entered character you use a remove character option at the beginning of the selector. The selector only allows you to enter alphanumeric characters i.e. no specials and maximum length is 12. The order of the characters is:

You can't pick anything before 0 (zero) for the first character. If you press back it will exit the selector and if you either pick the complete name option or enter 12 characters it will ask if you want to save or not. Pressing enter again saves the cartridge to the root of the SD Card.

v1.2 Circuit (the one without BOB)

The following circuit does not include the level shifter which is no longer required due to the IF1 accepting the lower voltage output of the Pico ~3V. For the old circuit please click here. v1.3 of the PCB simply adds the ability to swap the GND & VCC pins of the OLED using a couple of jumpers, rest of the circuit remains the same.

image

v1.1 PCB Hardware Mod for Real H/W Support

Unfortunately during testing it became apparent that the BOB level shifter interferes with the data output of the real Microdrive and lacks the OE pin which would put it into high impedance mode. During initial testing everything worked fine with a vDrive, in place of real h/w, as its signal strength is much stronger and therefore wasn't affected by the BOB.

Luckily this is extremely simple to fix and doesn't need any complex re-routing or code changes, in fact all you need to do to get the v1.1 PCB working with real hardware is to replace the BOB-12009 level shifter with 3 diodes as shown in the image below (note the cathode line at the top HV side). I've tested this with standard 1N4148 and BAT43 Schottky diodes. The BAT diodes have a better voltage drop, measuring I show 3.0V for the 1N4148 and 3.2V with the BAT. Recommend to use BATs although 1N4148 seem to work fine.

image

BoM

Note V1.3 of the PCB now includes the values of the components instead of their names as I found it easier to build this way. The silkscreen shows the footprint of which component is required, resistor or diode for example, but if you are still in doubt please refer to the v1.2 PCB image as the components are in the same place and labelled as per the BoM.

PCB

I have designed a PCB to house everything and you can purchase v1.3 on PCBWay (https://www.pcbway.com/project/shareproject/Raspberry_Pi_Pico_ZX_Spectrum_Microdrive_Hardware_Emulator_37750e81.html).

As of v1.3 the Gerbers are also now available to download from the GitHub site so you can get them made at your preferred PCBFab.

image image

Older v1.2 PCB for reference image

Case

The PCB was originally designed to fit in a real Microdrive case as it is based on my Oqtadrive PCB. As such the screw holes etc... line up perfectly, however, the addition of the buttons and OLED mean, although it will fit, you won't be able to use it without cutting the case. As such I designed a custom 3D case (https://www.thingiverse.com/thing:5569842) to match the Spectrum + models such as the 128k Toastrack. There have been a few designs, with recent improvements coming about as I purchased a new Bambu P1S multi-colour printer and used it to print a rainbox badge and Sinclair logo. I've also adapted the case to accomodate a larger OLED screen as these have now become cheaper to buy. The latest design has a 1.54" OLED which is a lot easier to read than the original 0.96" OLED.

image

With the smaller 0.96" OLED

image

Original case design

image

Adam Kay has also created a design which looks nearly identical to the original Microdrive case, this uses a 1.54" OLED. This has a few other improvements over the original case such as front mounted SD Card slot which helps if you attach a real h/w Mircrodrive.

image

Andrew Potter has also adapted my original case to fit an even larger 2.42" OLED. This photo shows the 3 difference sizes, left to right, 2.42", 1.54" and 0.96". I think 1.54" is the sweet spot but guess it depends on how good your eyesight is.

image

Importance of Adding Feet

I recommend adding some rubber feet to the case. If you can get hold of them the original feet are fine, however, I recommend the smaller 3M Black Bumpons (SJ5076) which lift the case to the correct height (by ~2.8mm). This height adjustment is a requirement if you plan to connect this to a real Microdrive using the connector block. Without the feet the edge connector will be at the wrong height and won't fit together very well. If you don't plan on using this with a real Microdrive the feet are not needed although I still recommend them for anti-slip.

Building with Case

This guide is based on v1.2 of the PCB which is the same as v1.3 minus the OLED GND/VCC selection pins. It also applies to v1.1 with the diodes placed where the BOB was.

First solder in the diodes, resistors, buttons, buzzer, transistor & TSR 1-2450 as per the silk screen, being mindful of the orientation of the diodes. I recommend you use BAT42/43 Schottky diodes for Data 1 [D1(D)], Data 2 [D1(D)] & Comms Out [CO(D)] as these are small signal outputs which may benefit from the lower voltage drop.

Follow this with the header sockets for the Pico (20-pin) and Micro SD Card reader (9-pin). Ensure these are straight before fully soldering with the best way being to solder one leg check it is straight and then soldering the rest. For the Pico header I'd recommend plugging in the Pico first, use a bit of blue tack to hold in place, and then solder ensuring it all aligns.

Now solder in the bi-colour LEDs. Mount these so the bulb is slightly above the top of header socket, this gives enough height to bend into place later.

After this you should have the following set-up (blue diodes are BATs, red are 1N4148s):

image

The OLED socket needs to be raised off the PCB in order for the screen to fit in the top of the case, these longer legs sockets are often referred to as stackable pin header sockets. The best way to get this at the correct height is to first mount the OLED into the top case, plug the header socket in, and then put the PCB on top (bottom up). Ensure the PCB is straight and then solder in place. It should now look like this:

image

For v1.3 PCB you also need to either add a 2x2 pin header and jumpers or use solder bridges to route VCC & GND to the correct pins. The layout is as follows, note this is with pin 1 at the right hand side i.e. the OLED is upside down:

image

You can now fit the Pico & Micro SD-Card socket and mount into the bottom part of the case by sliding in the front buttons first and then securing with a small screw. Be careful when bending the LED legs to fit the side holes and ensure the Micro SD card slot is flush to the side of the case as shown in the photo.

image

with a 1.54" SSD1309 OLED instead of the smaller SSD1306:

image

Pop the top of case on but remember the OLED screen pins need to fit in the raised socket. This can take a couple of goes. A final touch is to add a rainbow sticker to match the original case. I've created a PDF sticker sheet if you want to print your own

image

Latest case design with the two OLED sizes (0.96" vs. 1.54"). Printed using a Bambu P1S with AMS, including the rainbow badge.

image

Testing the ZX PicoMD

Once built I run the device through a series of tests. The main one is a test cartridge by Martin Smith, you can download this by clicking the link or from the TestCarts folder. This utility was initially designed to test emulators so works great for making sure everything is ok with the ZX PicoMD. There is also the test routine that comes with the official service manual which I've also put in the TestCarts folder.

Another test I run is making sure the write protect circuit is ok by toggling it on and trying to format a cartridge, this should fail with a write protect message, toggling it back off and it should work again.

image

In addition I've also uploaded two IF1 ROM version check cartridges, one based on a CRC check routine by Blaze and another which looks for the location of a HOOK routine in the shadow ROM written by Andy Pennell for Your Spectrum (Issue 20, page 13). These both determine the ROM version of the IF1 you are using which is useful for debugging as I've only been able to test ZX PicoMD with a v2 ROM.

image

FAQ

image