Raspberry Pi as Virtual Floppy Disk

14 posts
by alpage » Mon Feb 18, 2013 12:10 am
Inspired by several similar projects using Arduino and other micro-controllers, I decided to try creating a virtual floppy disk emulator using the Pi. The advantage being that the Pi has a full operating system, lots of memory and a lot of GPIO pins.

After several weeks of work I succeeded in getting my ancient TRS-80 to boot from my Raspberry Pi. The interface board between the Pi and the floppy disk edge connector only requires 3 ICs and some termination resistors. The operating system was RiscOS but I think it could also work under one of the Linux distributions with a bit of work. An album of images is at http://s766.beta.photobucket.com/user/alpage57/library/TRS80%20Virtual%20Floppy.

Two main challenges were generating the raw floppy disk clock and data signals and detecting the very short 8 μS 'step' signals. The clock and data signals are 1 μS pulses separated by 3 μS gaps. They look something like C___D___C___D___ where C is a clock bit and D is a data bit (which is absent for a '0'). I initially thought to use a 1 μS timer interrupt but quickly discarded that idea as not feasible. Instead I tried the SPI output and set a 1 for a clock or data pulse and 0 for the gaps between pulses. That meant that each bit of floppy disk data would be transmitted as a byte by the SPI hardware. A single-density track using FM modulation contains approx. 3,125 bytes including CRC, padding and other overhead. This would be transformed into 25,000 bytes encoded for SPI transmission.

But when I looked at the actual signal I realized that each SPI byte was separated by a 1 μS gap equal to one clock cycle which slowed down the timing and made the gap between the clock and data bits less than ideal. But, surprisingly, it still works because the floppy disk controller is fairly tolerant about the location of the data bit as long as the clock signal is reliable. So I sped up the SPI clock slightly so that the 8 bits of data plus the gap between bytes took 8 μS so the speed of the virtual disk would be very close to the 300 rpm of an actual drive. Every clock pulse would be exactly 8 μS apart even though the data pulse would show up slightly before the ideal time. Data and clock pulses would be a bit shorter than 1 μS, but well within tolerance.

The Pi SPI fifo needs to be fed a byte every 8 μS using my data rate, but since the fifo can store up to 64 bytes, we have up to 512 μS before the fifo is empty. To play it safe I use a timer interrupt every 200 μS to fill the transmit fifo and empty the receive fifo. The timer interrupt also generates the 4 millisecond index pulse signal at the start of every track.

The second challenge was to pick up the 8 μS step pulse used by the floppy disk controller to step the virtual floppy drive head in and out. Here's where the GPIO rising edge detection made it easy. Setting a rising edge detection on the GPIO pin corresponding to the step signal allowed the BCM2835 do all the hard work of detecting the pulse. All I had to do was check the pulse detection bit every few milliseconds and switch to the desired track.

Currently it is read-only, meaning the computer cannot write to the floppy disk. I may be able to use the SPI slave data input to read the write signal from the floppy disk controller, but I would probably need to double or even quadruple the SPI data rate as the SPI clock and the floppy disk clock would not be synchronized so I would have to sub-sample the input and try to figure out the actual data and clock bits. I probably need to switch to DMA to get the higher data rate reliably as sometimes other interrupts are long enough to cause a gap in the SPI data though the floppy disk controller and operating system are robust enough to automatically detect and recover from such errors.

Details of hardware and software available on request.

Alan Page
Posts: 7
Joined: Sun Feb 17, 2013 11:13 pm
by rpdom » Mon Feb 18, 2013 5:46 am
Um, can I just say "Wow!"?

An impressive feat. If I still had my old Beebs I'd consider using one of my "A" Pis to do this - they cost a quarter of what I paid for a 5.25" floppy drive back then and would be able to hold thousands of floppy images on a 2GB SD card even with the OS :-)
User avatar
Posts: 11021
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK
by Burngate » Mon Feb 18, 2013 10:38 am
Wow also
User avatar
Posts: 4826
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK
by RaTTuS » Mon Feb 18, 2013 11:05 am
3rd Wow
and from a 1st post....
I got rid of my TRS80 a couple of years back ..
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

User avatar
Posts: 9270
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
by alpage » Mon Feb 18, 2013 3:35 pm
Thanks for the compliments. The original project that inspired this is here: http://www.thesvd.com/SVD/. The SVD required 9 ICs and a bunch of other parts and in order to use it you had to plug it into a serial port on your computer and use software to change the floppy images. It had 128K of static RAM on the PCB to hold up to two virtual floppy disks. The SVD software was carefully constructed assembly code with every microsecond of instruction time accounted for to bit-bang data in and out of the data lines.

Developing it on the Pi is so much easier as I can compile and run software on the Pi itself rather than on a development system. And of course I can download new floppy disk images directly from the internet.
Posts: 7
Joined: Sun Feb 17, 2013 11:13 pm
by alexandrefguima » Sun Mar 17, 2013 7:09 am
WoW. It's the most interesting and useful PiProject I even seen.
You'll become a hero to the retrocomputing community worldwide.

When this board will be available?
Will it be sold?
To make it work on other computers like Apple II, Sinclair, etc the changes should be on software, right?

Posts: 1
Joined: Sun Dec 09, 2012 7:00 pm
by alpage » Mon Mar 18, 2013 5:18 am
I don't have any plans to produce a commercial product but I hope to find more people who are interested in helping develop it as open-source hardware/software. I have a TRS-80 Model 4 owner who is working on double-density support. I know how to layout a simple PCB, but a board would be unlikely unless there was more participation.

There would be slight hardware changes for other computers as there may be different termination resistors, different connectors and a few other minor differences.

Someone with moderate soldering/electronic skills could use this https://www.adafruit.com/products/801 to build a board. I found that you could get away with only two ICs and there is room on the end of the board for a 34 pin connector. It's a tight fit, but I did produce a working board myself.
Posts: 7
Joined: Sun Feb 17, 2013 11:13 pm
by jedie » Sun Sep 15, 2013 8:20 pm
Wow, really cool.

Are there more information somewhere?
Posts: 13
Joined: Wed Sep 05, 2012 8:15 am
by alpage » Wed Sep 18, 2013 12:09 am
Have had several people inquire and I did provide some information to one Rasperry Pi/TRS-80 owner. Would be happy to share ideas and information with anyone. Send PM and I will give any interested persons my email address for direct contact.
Posts: 7
Joined: Sun Feb 17, 2013 11:13 pm
by alpage » Tue Sep 24, 2013 1:03 pm
I have started a blog at http://virtualfloppy.blogspot.ca/ for this project. People can ask questions and leave comments there.
Posts: 7
Joined: Sun Feb 17, 2013 11:13 pm
by jedie » Tue Sep 24, 2013 1:05 pm
alpage wrote:I have started a blog at http://virtualfloppy.blogspot.ca/ for this project. People can ask questions and leave comments there.

Great idea!
Posts: 13
Joined: Wed Sep 05, 2012 8:15 am
by alpage » Tue Oct 22, 2013 12:45 am
Just today I implemented functionality to control a floppy disk drive from the Pi and dump the tracks to a file, e.g. .DMK file used by various TRS-80 emulators. Required rewiring one of my prototypes to turn inputs into outputs and vice versa and some code changes. Dumps a 35 track single-sided disk to a file in under 20 seconds.

See latest blog entry at http://virtualfloppy.blogspot.ca/2013/10/using-raspberry-pi-to-read-floppy-disks.html
Posts: 7
Joined: Sun Feb 17, 2013 11:13 pm
by jedie » Tue Oct 22, 2013 7:01 am
Great to hear news!
Posts: 13
Joined: Wed Sep 05, 2012 8:15 am
by mram » Wed Nov 27, 2013 12:13 pm
Hello ! I did a similar work for Amiga and the RPI just rocks!... a bare metal solution... here http://www.raspberrypi.org/phpBB3/viewtopic.php?t=61635&p=459021 you can find my thread.
Posts: 7
Joined: Sun Nov 24, 2013 6:46 am