Integrated Tashtari Machine: Floppy Drive Emulator

Tashtari

PIC Whisperer
I've given this a lot of thought over the past week, and I came up with a rough design that supports the necessary features to emulate the majority of copy protection schemes (synchronized sectors, weak/fake bits) while playing back WOZ or MOOF images on the Mac, but with some caveats: only GCR disks (no MFM), only bitstreams (no flux timings), and only reads (no writes). Plus, it'd require some pre-computation, so a Mac/PC-side client application would be necessary. It feels kind of clunky and compromised. I'm not ruling it out, but I think more people's needs would be better met by something that has the same feature set as the Floppy Emu on the Mac, so I'm going to concentrate on that first, at least...
 

Tashtari

PIC Whisperer
Hope I didn't open Pandora's Box for you there!
Nah, even if I don't end up supporting copy protection, I learned a lot, particularly about the Superdrive. Better to learn sooner rather than later, given that even seemingly small details can lead to big redesigns.
 

Tashtari

PIC Whisperer
I've been working on a floppy emulator on and off for at least a year now and the project has gone through more redesigns than I care to count, but I think I'm making progress. Here's an somewhat-rambling update.

In the current design, the "Super Tashtari Integrated Machine" (STIM, in a nod to the SWIM) is a firmware for the PIC12F1840 (same chip as I used for TashTalk), the function of which is to do bitbanging, which is my favorite thing to design and arguably the hardest part to handle in a larger embedded system, in order to be a counterpart of sorts to the SWIM/IWM chips. It handles bidirectional communication in the dual languages of GCR (400 and 800 KB disks) and MFM (720 KB and 1.44 MB disks), translating to and from an easy-to-understand 8-bit UART protocol.

On the receive side, it handles well-behaved disk writes, intelligently interpreting address and data marks and doing de-nibblizing as appropriate for GCR and translating both mark and data bytes into 8-bit bytes for MFM. On the send side, it handles well-behaved disk reads, intelligently interpreting address and data marks and doing nibblizing as appropriate for GCR and intelligently detecting and translating mark bytes for MFM. On the send side, there's also a mode to send a raw GCR bitstream and inject random noise into large gaps, in imitation of the behavior of a real disk drive; this mode can be used to imitate some types of copy protection.

The design using STIM is something of a departure from my past designs where I was trying to put all components of the interface into a single chip and separate that from a chip which behaved exclusively as the frontend. I'm moving away from that and instead separating the MCI into three logical components:
  1. Reception and transmission of magnetic flux transitions
  2. Multiplexing of signals on the RD line in response to CA2, CA1, CA0, and SEL
  3. Reception of commands on CA2, CA1, CA0, and SEL when CA3 is pulsed
Component 1 is STIM. Component 2 must be handled by logic of some kind, whether it's an SPLD, a simple multiplexer, or one of these interesting GreenPAK mixed-signal ICs (the SLG46824). Component 3 is probably best handled by the larger embedded system that's also communicating with STIM.

STIM is basically complete. I'd still like to give it the capability to handle DCD signals so that a device using it could imitate the Floppy Emu and emulate DCD devices, but this is a lower priority given that TashTwenty already does an excellent job of this on its own. Other components are still in flux (ha).

Anyway, nobody pays attention to wordy posts on their own, so have a picture of the other thing I've been working on, the "body" of TashFloppy:

tashfloppybody.jpg

It's a sandwich of two PCBs, easy to manufacture, easy to assemble, and in a Floppy Emu-like form factor. Cute, no?
 

Tashtari

PIC Whisperer
Well, it's been almost two years since I last posted on this project, and over three years since I started trying to spear the white whale that is a full-featured open-source Mac floppy drive emulator. Here's what's been going on and where things stand now.

By way of background, one of the most challenging aspects of the Macintosh MCI (Microfloppy Control Interface) is the way it multiplexes signals. Nearly all of the lines on the floppy controller are outputs from the Macintosh to the drive. Only one, the "read" line, is an input from the drive to the Macintosh, and the MCI repurposes the "phase" lines on the floppy controller, originally intended to control stepper motors, as selector lines for one of sixteen possible one-bit registers maintained by the drive. As a result, some kind of programmable logic is basically necessary to make a floppy drive emulator for the Macintosh.

TashTwenty, thanks to a bit of luck in how the drive controller is used, is able to emulate the register set using a single CLC (Configurable Logic Cell) peripheral, a relatively simple and somewhat unconventional programmable logic device that lives within the PIC. However, the number of CLCs in a single PIC is too few by far to emulate the more complex register set used to communicate with the floppy drive and something more sophisticated is necessary. This threw me for a long time.

At first, I tried using ATF16V8 SPLDs, but those were too simple; I also tried using ATF22V10s but ran into trouble programming the chips, besides the fact that my design using them cut some corners, so I abandoned SPLDs. The next candidate I looked at was a series of devices called GreenPAKs, neat little chips able to run at 5V with a whole mess of logic blocks that can be connected together in myriad ways. These got tantalizingly close to working, but again fell short of what I needed. CPLDs and FPGAs would certainly have enough logic to do what I need, but add complexities that I don't want to deal with - low voltage levels, inconvenient packages, staggeringly bloated software packages. Yuck.

Honestly, if I were a better electrical/computer engineer, I'd probably have given up my unconventional paths in favor of using a more sophisticated microcontroller paired with a CPLD or FPGA. But I make no claim to be electrical or computer engineer, much less a conventional one. What I am is a PIC whisperer - it says so right underneath my forum user icon - and that informs my latest approach. Here's the code:


A trio of PIC16F1704s, pooling their CPU cores, their memories, their peripherals, and most importantly, their CLCs, to work as one to handle all aspects of communicating with the Macintosh MCI - from register multiplexing to handling commands, to bitbanging both GCR and MFM. It does for the MCI what TashTalk does for LocalTalk - it allows just about any embedded system with a UART to emulate a floppy drive, taking as much of the load off as it can. Just supply it with a prompt and steady stream of data and you're off to the races.

It is the backend to any type of floppy emulator frontend a person might want to create, be it a brick-on-a-leash like Floppy Emu, a smart network interface like FujiNet, or - and this is what I dream of - something that replaces the floppy drive in a Macintosh both functionally and aesthetically.

So what's the status of this project as defined above? I believe it to be functionally complete and operational. I have, however, run into a major snag in proving it out.

I wrote a prototype frontend that connected to a SPI PSRAM chip, downloaded an image to it, and supplied data to TashFloppy from the PSRAM. Unfortunately, I couldn't get the PSRAM to work properly - it kept having massive numbers of bit errors. It doesn't appear to be the PIC firmware's fault, either the chips I got were faulty or my skills at soldering SOICs are so poor that I damaged them in the course of attaching them to SOIC-to-DIP adapters. I don't know.

My next step, I think, is to find an appropriate larger-scale embedded system to perform the same function. The safest option would be to find one with enough RAM to hold a whole disk image. It is certainly possible to hold the image in flash or on an SD card - this is what Floppy Emu does, after all - but for purposes of testing the backend, I want the frontend to be as simple as possible. I'd like to find one that supports MicroPython, which someone suggested to me over on the TashRouter thread, ideally.

The other thing I could work on in the meantime is DCD/HD20 support. I haven't written this yet, but I have a place in the firmware where it's planned to go. If all goes to plan, a single device using this backend will be able to emulate a full chain of devices - multiple DCDs and a floppy drive - all at the same time.

So that's where things stand. If anyone's got any suggestions for a MicroPython-supported board with a lot of RAM, or wants to work with me on creating a frontend of some kind, or just thinks this is cool and wants to know more, I'm all ears. =)
 

Iesca

Well-known member
For what it's worth, I really like my Tash20, and I'm glad I was able to assist in bringing low-capacity SD card compatibility to the project. Glad to see you're still chipping away at it! :)
 

saybur

Well-known member
This feels like a perfect match to the new RP2350. The PIO units are flexible and may be able to directly handle the timing sensitive floppy signals, the new chip has PSRAM mapping into the address space, there is some level of 5V tolerance on the GPIOs, and it supports MicroPython. There are even dev boards (https://www.sparkfun.com/news/11526) ready to go.
 

Tashtari

PIC Whisperer
New developments!

MicroPython seems to have one deficiency that keeps it from interfacing with the backend I created, its UART interface can't handle inbound break characters. Frustrating, that would have been a great path to rapid prototyping of a frontend on the Pico or ESP32. It does seem like the ESP32, at least, can handle inbound break characters, but it requires programming at a lower level than MicroPython. Not ruling it out, but there goes the 'rapid' bit of rapid prototyping...

I also found out why the PSRAM wasn't working. Apparently its DRAM refresh circuit is suspended while its chip select line is low, and off in some dusty corner of the datasheet, it specifies that the chip select line can't be low for more than 4 µs at a time. At the speeds I was clocking it, that's not even enough to get the address out before the DRAM array starts to forget data. D'oh.

There is good news, though - apparently, Microchip (yay Microchip!) makes a 512 kB SPI SRAM, and if I gang together three of them, that's enough to hold a 1.44 MB floppy image. With some modifications to my current prototype frontend, I should be able to prove out all the floppy emulation functionality of the backend: GCR, MFM, read-only, and read-write.

...

...

...

Oh, and I substituted a BIOS flash chip for the PSRAM and managed to get a read-only 800 kB floppy disk booting my 512ke! This thing actually works!

Have some photos of the gory development process, while you're here:

photo_2024-08-19_07-25-31.jpgphoto_2024-08-19_07-25-31 (2).jpg

Partially obscured by jumpers in the first picture is the trio of PIC16F1704s that makes up the backend, and below that on the breadboard, the cat5e cable that connects the backend to the frontend, visible in the second picture. (I ended up using a trio of 65HVD08 transceivers on the frontend because they turned out to be the only 3V3 compatible RS422 transceivers I have on hand. Feels wasteful, but if it's stupid and it works, it isn't stupid.)

I don't know for sure what inspired "big mess o' wires", but I'd venture to guess it was a mess not unlike this one...
 
Looks great!

Sorry for a slightly offtopic question that came to my mind when reading the thread title:
From your understanding now of not only the floppy drive interface, but also the inner workings of the IWM:
May I ask for your thoughts on the question if you would say that it could potentially have been easier in retrospect to replicate the whole IWM chip plus floppy drive instead of trying to mimic only the floppy drive? My guess would be that the interface between the IWM and the rest of the system is more "standard" than 1-bit registers and the like, maybe...?
 

Tashtari

PIC Whisperer
May I ask for your thoughts on the question if you would say that it could potentially have been easier in retrospect to replicate the whole IWM chip plus floppy drive instead of trying to mimic only the floppy drive?
The thought has entered my head a few times... it's a definite maybe, with a microcontroller that has a peripheral designed for interfacing with a microprocessor based system like a parallel slave port. Then, though, you have to get a soldering iron involved and you lose the convenience of something that just plugs into the floppy port. In any case, I don't regret the time I've spent learning about the floppy interface; if nothing else, I've helped document it for anyone else who wants to do something like this down the line.
 

zefrenchtoon

Well-known member
I don't know if this may be of any interest for your quest but, in case of, I share it:

 
Hi,
with a microcontroller that has a peripheral designed for interfacing with a microprocessor based system like a parallel slave port
Thanks for confirming that this is indeed a potential route. Would you already have a specific microcontroller in mind for this? Maybe a similar PIC as the one used in the 68k-MBC CP/M board?

Independently, I can definitely see that not everybody would feel like desoldering an IWM chip from a working logic board just for the sake of getting a floppy emulated. On the other hand, I was also thinking more about building clones from scratch and for that it would be handy if one could skip having to source an original IWM chip, I guess. I am not sure about /how/ unobtainable they are as of now though...
 

Tashtari

PIC Whisperer
Looking at the IWM datasheet, I'm starting to feel like one would really need full-on programmable logic to duplicate its functionality to the Mac... it does some rather weird things with the address lines. Maybe the PIOs that I've heard so much about (but haven't yet dug into) could handle it? Whatever the case, it's not a simple beast, and that's just the IWM. If the SWIM (and thus 1.44 MB disks) were to get involved, it'd be more complex still.
 

LaPorta

Well-known member
Well, you were saying that it would be hard to duplicate IWM functions. Can’t we just use the IWMs from all those scrap boards lying around there and put them in place on your board?
 

Tashtari

PIC Whisperer
Well, you were saying that it would be hard to duplicate IWM functions. Can’t we just use the IWMs from all those scrap boards lying around there and put them in place on your board?
Ah, I see. I think there's some confusion here to be cleared up. There are two ways you can connect an emulated floppy interface into a Mac without modifying its software. One, you can use a device that pretends on the MCI (interface) level to be a floppy drive - this is what the Floppy Emu does. Two, you can use a device that pretends on the address/data bus level to be an IWM/SWIM chip and doesn't use the MCI at all - this is what @jonathanschilling was proposing. To require a real IWM and make it part of the floppy emulator would be pointless, as then you get the worst of both worlds - you have to desolder the real IWM and replace it with, effectively, another IWM, then you just have a non-removable version of the Floppy Emu.
 
Top