• Published on | Aug 04, 2013 | by FozzTexx

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 FozzTexx • 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 FozzTexx • 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 FozzTexx • 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 FozzTexx • 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 FozzTexx • 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

+1  Posted by Robert • Nov.16.2014 at 14.03 • Reply

Hello Chris Osborn!

I have a question! I built your circuit with 2 x 74HCT245, but I have troubles with communction with my C64. I guess it's a timing problem, because I always receive different commands for LOAD "$",8 on the Pi. What Linux did you use for your Pi? Did you use a RT patch? I use standard Rasbian, but I have troubles with it. Maybe I have to disable other modues which effect the timing behaviour? regards, Robert

+1  Posted by FozzTexx • Nov.16.2014 at 14.06 • Reply

It sounds like you don't have the wiring correct or your level shifter isn't working.

+1  Posted by porga • Jan.02.2015 at 13.12 • Reply

Why no progress yet? rPI would be better solution than SD2IEC

+1  Posted by FozzTexx • Jan.02.2015 at 13.20 • Reply

What do you mean no progress? Have you looked at the repo?

+1  Posted by smayo • Mar.27.2015 at 22.24 • Reply

Chris, This looks like a great project. Do you have any plans to release a schematic to wire it up?

+1  Posted by FozzTexx • Mar.28.2015 at 07.43 • Reply

There's a basic schematic included in the project.

+1  Posted by Tony • Apr.27.2015 at 19.33 • Reply

This is soo neat. I have my old C-128. Will this work for the 128? I'm gathering the parts needed. can I use a breadboard to make this? My solder skills are bad.

+1  Posted by FozzTexx • Apr.27.2015 at 19.45 • Reply

You can definitely make it on a breadboard, since that's how mine is! There's very few parts needed. It should work with a C128, but there's no support for the fast mode of the C128. It'll still be slow like a 1541.

+1  Posted by Tony • May.29.2015 at 21.16 • Reply

ok, I've built it out on my breadboard. Since I am dumb, I've simply cloned your ninepin package to my pi. I try to do a sudo make and i get this: cc -g -Wall -I/root/Unix//include -dD -o ninepin ninepin.o cbmdos.o joystick.o d64fs.o localfs.o -L/root/Unix//lib -lobjc -lpthread -ldl -lwiringPi -lrt /usr/bin/ld: cannot find -lobjc collect2: ld returned 1 exit status Makefile:63: recipe for target 'ninepin' failed make[1]: *** [ninepin] Error 1 make[1]: Leaving directory '/home/pi/ninepin' Makefile:22: recipe for target 'all' failed make: *** [all] Error 2

I must be missing something. ugh

+1  Posted by FozzTexx • May.29.2015 at 22.36 • Reply

sudo apt-get install gobjc

+1  Posted by Tony • May.30.2015 at 17.26 • Reply

cool. got it to build...but I get unable to open joystick and unable to open IEC device. Must have something wired wrong.

+1  Posted by FozzTexx • May.30.2015 at 18.04 • Reply

You have to load the IEC module before you can use IEC. To use the joystick it has to run as root.

+1  Posted by Tony • May.31.2015 at 13.38 • Reply

ok makes sense :) i've gone to the iec dir and tried to make and it tells me:

make -C /usr/src/linux SUBDIRS=/home/pi/ninepin/iec modules make[1]: *** /usr/src/linux: No such file or directory. Stop. Makefile:9: recipe for target 'default' failed make: *** [default] Error 2

I guess I'm in the correct place. I'm willing to bet I need to setup a cross development environment :( ugh

+1  Posted by FozzTexx • May.31.2015 at 13.42 • Reply

I've got an article on that too: http://www.insentricity.com/a.cl/235

+1  Posted by Tony • May.31.2015 at 17.41 • Reply

ok, wish me luck :) btw. I think I'm a complete moron...for some reason I build my circuit from this diagram:


which is not yours. I have no idea how i got this mixed up. I guess you don't have a diagram for yours :(

+1  Posted by Jim Agla • Sep.01.2015 at 13.45 • Reply

Got my parts in today... Everything is compiled and ready to go. Wish me luck! :)

+1  Posted by Jim Agla • Sep.01.2015 at 20.42 • Reply

Chris, I got everything assembled... I am running my Pi's on the latest OS, compiled the module and user program. Watching kernel messages I am seeing communication to the Pi and back to the C64, but the data seems to be malformed. I do a LOAD"$",8 on the C64 and on the Pi side, I see it trying to open <random char>.PRG file and failing. It seems to repeat the character at times so I created a file it would eventually find. Pi said it sent successfully but on the C64 it came up with a ?LOAD ERROR message.... any ideas? I have not modified the source in any way...

+1  Posted by FozzTexx • Sep.01.2015 at 21.13 • Reply

Sounds like a wiring problem. What are you using for level shifters? How do you have them wired up?

+1  Posted by Jim Agla • Sep.01.2015 at 21.45 • Reply

Just using the diagram from VoltageDivider.png image provided. I have tried both external +5v/GND as well as +5v/GND coming from the Pi. +5v going to the 1k resistor, GND going to the 1.5k resistor and other ends are tied to the GPIO and IEC Signal lines. I am using the 3 wire solution so I have 3 banks of resistors. Here is a pic I took: https://drive.google.com/file/d/0B0qGXfj4d-TgaENTcFZJVnZFcEk/view?usp=sharing

Green wire at bottom is going to Pin 3(ATN), Blue wire is going to Pin 4(CLK) and Brown wire is going to Pin 5(Data)

+1  Posted by FozzTexx • Sep.02.2015 at 07.58 • Reply

Looks like it's wired the same as mine. Do you have anything else plugged into the bus? I always connect the Pi directly to the C64. I did try it once on my Plus/4 and it didn't work at all and figured it might not like the voltage dividers. I need to come back and try it using mosfet level shifters but haven't done it yet.

+1  Posted by Jim Agla • Sep.02.2015 at 09.27 • Reply

Nothing else plugged into the bus... I am going to check the wiring on the C64 side of things. I did not have a 6 Pin DIN connector and I didn't want to butcher a good cable, so I made my own pins and shoved them in the hole. I do have a connector on order...

+1  Posted by Mariusz • Jan.12.2018 at 01.35 • Reply


This is a great project (for sure better than HDD64 - https://www.64hdd.com/64hdd.html - from economical point of wiev).

How it looks support for .d64 currently? Does it work correctly with all versions of Raspberry Pi? Even RPi 1? Could you please give me some advices how to compile your sources to get a working package for Raspbian? Or maybe you could place somewhere in the network?

Thank you and best regards Mariusz