It’s been close to the bottom of my ToDo list for years, but I’ve finally added preliminary support for loading from tape. It was painless in the end too, largely thanks to Philip Kendall’s libspectrum library, which does all the hard work. It supports TZX, TAP and CSW tape images, which between them can represent the content of any SAM tape.
I first had to build libspectrum for Win32, which isn’t an officially supported target platform. Building with Cygwin did work, but the stand-alone DLL was over 600K! A few code tweaks later I managed to build it as a Visual Studio 6 project, resulting in a much more respectable 49K DLL (UPX-compressed).
The SimCoupe side of the implementation is only a couple of hundred lines of code. The libspectrum library supplies t-state timing information on when the next ear pulse is due, which is scheduled as a SimCoupe CPU event in the same way as interrupts. When the event fires I toggle the ear bit of port #FE, ready to be picked up by the loader edge detection. The timings do need an cycle-accurate machine emulation to work correctly, but we’ve had that for some time. The rest of the implementation is just tape image management, so the user can insert/eject images.
I’ve had a run through the dozen or so tape SAM tape images I’ve had on my HDD for years, and most work fine. The working ones include a couple of titles not yet available on World of Sam, which I’ll upload soon. The non-working ones are simply bad dumps, converted from poor quality VOC samples — I’ll redump these from my own tapes. I’ll also post a sam-users list request for other tape images, or for people to create images from any undumped titles.
The tape support is still pretty basic, with insert/eject/play/stop functions, and auto-play if the tape is inserted at the startup screen (exactly like auto-boot for disks, but pressing F7 instead of F9). I’ll add a tape block browser soon, so you can select where to play the tape from on compilation images. There’s probably not much demand/use for save support, so that will be completed last.
I’ve not looked at accelerated loading yet, but most (if not all) loaders call the edge routines in uncontended ROM, so a single solution should fit almost every SAM title. In the meantime you can use SimCoupe’s turbo feature to zip through the slow loaders (unless you’re like me and enjoy watching them!).
Perhaps a bigger reason to add tape support is the mass of Spectrum software that exists in the format. SimCoupe has no problem using Spectrum tape images, but I’m a little worried at how well they’ll work. If you were a SAM owner in early 1990s you’ll remember the problem of loading Spectrum titles on the SAM. Even if the timing values in the loaders were adjusted for the CPU speed difference, the fully contended RAM would break most custom loaders, with turbo loaders suffering most.
The Spectrum Emulator utility on the original SAM demo tape/disk was able to handle a selection of specific Spectrum loading schemes, and that should work just as well in SimCoupe. I’m also hoping that the exact timings on the tape images will give more reliable loading than using a cheap tape recorder back in 1990, to improve reliability. There’s also some scope for applying a compatibility scaling to the t-state tape timings, to better match SAM CPU speed.
I’m considering adding support for native loading of Spectrum snapshots (z80/sna/szx/etc.), as libspectrum provides support for those too. Unlike the old Spectrum support in SimCoupe, it would be done in a 100% faithful SAM way without pretending to be a Spectrum emulator. This would probably involve loading a Spectrum or skeleton ROM at address 65536, with the 48K snapshot following it, and resuming it using the CALL MODE 1 mechanism.
Just for fun, here are a few screenshots of the loading in action:
Defenders of the Earth is a mammoth 21 minutes and 51 seconds long, which certainly makes you appreciate the disk version! 🙂