• Published on | Aug 04, 2013 | by Chris Osborn

Video demo of the Pi acting as a disk drive

I've made some more progress on my software that allows the Raspberry Pi to act as a Commodore 64 disk drive. I was amazed at how much more of the IEC protocol was missing from the documents I have. One of the things that I found a little strange about the IEC protocol was there was no way to specify how much of the data you want. Once you say go, the sender is just going to send it all. It turns out that when ATN is asserted it doesn't mean abort, it just means pause.

Took quite a bit of doing to not miss any signaling that was happening when the Raspberry Pi was in the middle of sending data. It was tricky because I had to disable interrupts for timing issues during sending bytes, and of course that caused me to miss the ATN and CLK signals that the C64 wanted to send. I've got it worked out now, and things seem to be working quite reliably.

Other improvements are directory listings and wildcard matching now work. You can get a list of all the files, file sizes, it handles conversion of some filename extensions, and see free blocks. Of course free blocks is probably always going to be 65535 since the Pi has far more free space than a puny little floppy disk. Wild cards can be used so that you don't have to type out long names, plus a few of the programs I've been running seem to have wildcard naming built-in for loading their files.

I think the next thing to work on is .d64 support, at least for reading.

As before, the source is available on Github.

Join The Discussion

+1  Posted by Phil • Aug.06.2013 at 16:33 • Reply

This is just epic. I remember that the C64 had a "fastload" mode (either through a cartridge or a pre-loaded piece of software) that dramatically sped up the disk drive. See, for example: http://en.wikipedia.org/wiki/Epyx_Fast_Load. There was also some super optimized copy software like http://en.wikipedia.org/wiki/Fast_Hack%27em. which could copy 170k from drive to drive in just 35 seconds. Did any of these do anything clever with the I2C bus to step up the speed?

+1  Posted by Wild Bill • Aug.08.2013 at 05:21 • Reply

ISTR that many of those utilities actually deployed code do the drive controller (also a 6502?). I imagine there was other cleverness as well.

+1  Posted by plexxer • Aug.08.2013 at 08:00 • Reply

You know, I bet the RPi would be fast enough to run a full 1541 emulator with a virtual 6502 to allow that. That would be an awesome project...

+1  Posted by Richard • Aug.07.2013 at 14:29 • Reply

Did you port a 1541 emulator to the Raspberry Pi or write IEC emulation code from scratch?

+1  Posted by Chris Osborn • Aug.07.2013 at 14:32 • Reply

I wrote the code from scratch. I needed something that was interrupt based and would work as a Linux Kernel Module.

+1  Posted by Franky • Aug.08.2013 at 11:03 • Reply

Very cool indeed. Would it be too much to hope for JiffyDOS support in the future?

+1  Posted by pcollins • Aug.28.2013 at 06:09 • Reply

Is there SEQ/REL/USR Support?

And do you know XD2031 (http://xd2031.petsd.net/)
It works fine at the Raspberry Pi, too.

+1  Posted by Holger Morgen • Aug.31.2013 at 01:50 • Reply

Very cool! I have been thing of building something like this (using Microchip PIC), but never thought of using the Raspberry. Definitive the way to go. A few questions:
Why not use the SPI interface to send Bytes? Could that make 'mucking around with kernel modules' obsolete?
Is there a link to schmatics? (other than VoltageDivider.png, which looks wrong? :-)
Any plans for a PCB?

+1  Posted by Holger Morgen • Aug.31.2013 at 05:36 • Reply

Sorry - forget SPI: only master and min. clk frq is >100khz @ 1Ghz... a bit over the 535Bytes/s ...

+1  Posted by Alan Page • Nov.04.2013 at 16:23 • Reply

See my blog post http://virtualfloppy.blogspot.ca/2013/09/spi-key-to-project.html about misusing SPI to emulate floppy disk format. Largest divider for SPI is 0 which is interpreted as 65536 which gives a clock rate of 250Mhz/65536 or about 3,814 clocks per second, though it's a bit more complicated because the clock rate is the bit rate and there's a gap between bytes.

+1  Posted by Chris Osborn • Aug.31.2013 at 07:45 • Reply

The voltage divider is correct, and that's the only circuitry I'm using to interface to the IEC bus. You just need 3 of those. It's really that simple.

The SPI protocol is not the same as the IEC protocol and it can't be used.

+1  Posted by Jim Steichen • Sep.28.2013 at 13:15 • Reply

There is no '/dev/iec8' in my raspberryPi '/dev' directory. Care to explain how you created it?

+1  Posted by Jim Steichen • Sep.28.2013 at 14:03 • Reply

Also, where can <iec/iec.h> be found?

+1  Posted by Chris Osborn • Sep.28.2013 at 14:21 • Reply

It's all in the source. You need to compile the kernel module and load it for iec8 to appear.

+1  Posted by Jim Steichen • Sep.28.2013 at 18:54 • Reply

I did find the iec/iec.h & iec.c source files. Are they what is used to compile the kernel module? Also, I'm guessing that mknod wants to create /dev/iec8 as a block device. What are the other magic numbers for mknod?

+1  Posted by Chris Osborn • Sep.28.2013 at 19:01 • Reply

Yes the stuff in the iec folder is the kernel module. mknod isn't used, when the module is loaded it will automatically create the /dev/iec8 entry.

You'll need to compile a kernel from source in order to build the module. It can't be done directly on the Raspberry Pi, it doesn't have enough resources. You have to setup a cross development environment under QEMU with an ARM emulator.

+1  Posted by Jim Steichen • Sep.29.2013 at 09:03 • Reply

You need to read http://kernelnewbies.org/KernelHeaders concerning your Makefile. I did get iec.c to compile (ONCE!), but there is something wrong with the Makefile, because it does NOT know where to find liunx/init.h (for example)

+1  Posted by Chris Osborn • Sep.29.2013 at 09:31 • Reply

You have to build it against a kernel source directory that has been compiled for the Raspberry Pi, located in /usr/src/linux. If you put the linux kernel source somewhere else you will need to adjust the Makefile.

+1  Posted by Juan Castro • Oct.23.2013 at 20:56 • Reply

Have you seen this? Maybe it can help with the IEC stuff you haven't got yet? http://www.c64-wiki.com/index.php/sd2iec_%28firmware%29