Making a Raspberry Pi into a unified retro peripheral
If you've been following along here or on Twitter or Google+ you've no doubt seen the experimenting I've been doing with interfacing a Raspberry Pi in various ways with several retro computers like the Atari 800 and Commodore 64. My first project was using the Raspberry Pi to act as a converter for a USB gamepad to turn it into an Atari 2600 style joystick.
After discovering Eric Nelson on Twitter and seeing all the games he was playing on the Commodore 64, I really wanted to try it myself. The first step though was finding a good game controller. Even though I grew up during the Atari 2600 era, I always hated those joysticks. Genuine Atari 2600 joysticks are absolutely awful, and the Sega Master and Genesis gamepads aren't a lot better. Modern gamepads are more responsive and comfortable, but they aren't going to talk to a Commodore or Atari. The first thing I needed to do if I was going to play old games was find a way to use a USB gamepad on these old computers.
After getting that to work (see my original article) the next thing on the list was dealing with the disk drives. I happen to have a big stack of Commodore 1541 floppy drives, but having to master real 5.25" disks and then sneakernet them around was just way too old school and tedious. After discovering that there was a program that would emulate Atari 800 disk drives and trying it out, it was clear that a floppy disk jukebox was the way to go.
All of the software that was written to allow modern computers to speak the Commodore IEC protocol either relied on DOS because they needed full control of the processor for timing issues, or used an external microcontroller to handle it. I felt that the Raspberry Pi should be able to do the IEC protocol directly without additional microcontrollers.
The best way to deal with the timing was to write a Linux Kernel Module which could handle interrupts when the IEC bus was signaling, and briefly disable interrupts to deal with the microsecond timing involved. The biggest setback was the documentation I found about the IEC protocol was wrong. Wrong in a lot of places. But I did get it figured out.
I've now got both the joystick conversion working and very simple file IO working over the IEC bus. The joystick support only works with one joystick and supports a single fire button. The CBM DOS emulation is limited to reading and writing .PRG files, it doesn't know anything about .d64 disk images. There's not even any directory listing or wildcard support.
I'm releasing it now though even though the functionality is somewhat limited. I think the kernel module source may be useful for people to look at to see how to handle GPIO interrupts on the Raspberry Pi. I also have a small gpio.h file which implements the GPIO basics all in macros, no functions.
The source code is being released as Open Source under GPL v2+, and it's available on github.