Thursday, January 23, 2025

The Fauxmodore 64 (A Commodore 64 Emulator in an original Comodore 64 case)

Introduction

I'm not much of a retro computing enthusiast; I like playing classic games, but using an emulator on a PC with a modern controller is perfectly fine with me. I do however like a good embedded project, in particular if I have an excuse to design custom hardware to support it.

Emulating Retro Devices

I recently discovered the excellent VICE emulator that can emulate many Commodore systems. Unlike most other retro systems that I use an emulator for (NES, SNES, etc.), Commodore systems aren't exclusively designed to be gaming systems, and thus have an integrated keyboard. While it is entirely possible to use a modern PC keyboard with the emulator, I found it an unsatisfying experience; one of the great experiences of using these machines is plugging them into a TV and being able to write out some BASIC programs. More so than gaming systems, the experience of having actual hardware that behaves in a similar manner to the prototype adds a lot to the experience. I don't personally have any nostalgic memories of using a Commodore 64; the system was first released a few years before I was born, discontinued while I was in elementary school, and my family never owned one. However, I find the idea of "full" computer that plugs into your TV a fascinating idea that is fun to explore. Unlike some true retro computing enthusiasts, though, I really have no desire to deal with disk drives, composite video, hard to find ICs, slow loading times, etc. so I'm perfectly happy to use an emulator for these conveniences.

Building the Fauxmodore 64

The first step in building the Fauxmodore 64 was to find a suitable enclosure and keyboard. I was able to find an empty case and keyboard for a reasonable price on E-Bay.

After some research, I found that this particular keyboard is actually a VIC-20 style keyboard, which uses rubber caps instead of spring posts (you can tell by the long yellow wires that connect to the Shift Lock key and the placement of the header wires coming off the PCB). Apparently some of the early Commodore 64s shipped with VIC-20 keyboards like this. I was able to build a prototype circuit on breadboard that utilizes an Atmel ATMega88 running V-USB to expose the keyboard as a standard USB keyboard that can be attached to any computer. Thankfully, after cleaning the PCB, all the keys on this keyboard are fully functional, so no repairs were needed.

After prototyping the the USB device on breadboard, I designed a PCB that can do the same purpose and easily mounted inside the case. If you are interested in fabricating your own, the KiCAD design and software are all available in GitHub. The PCB is designed to handle the Commodore 64 keyboard scanning, joystick inputs (compatible with any Atari-style 9 pin joysticks; but no paddles), and 6 "Auxiliary" inputs which will be connected to external buttons to activate functions in VICE, and illuminating the case LED. The controller reports as a standard HID keyboard; each of the keys on the Commodore 64 keyboard are reported as the equivalent positional key in the VICE keymap, while the joysticks are also reported as keyboard keys; Joystick 1 uses the numpad keys defined by VICE, and Joystick 2 just uses other random keys (mostly from the keypad) that otherwise have no meaning in VICE. The reason for doing the joysticks this way is that it's not widely compatible to have a single USB HID device report separate joystick inputs, even though the HID spec allows this (for example, the Linux Kernel HID USB driver will coalesce the reports unless you pass a special flag to the kernel module). Since I wanted this to work "out of the box" and VICE has no problem using keyboard keys as joystick buttons, this was the easiest solution. The resulting HID report generated by this device ends up looking pretty strange because of this; it has a 1 byte report ID, then 16 bits where each bit represents a joystick input (5 bits each + 6 bits of padding), then an array of 4 keyboard keys (like you might see on a normal HID keyboard). This means is is not a "boot compatible" keyboard, but I don't know why you would want to use such a weird keyboard in your BIOS. The reason for this layout is that it allows the joystick button states to always be reported, regardless of how many keys are currently pressed on the keyboard. While 4 keyboard keys might not seem like enough, I'm pretty sure its plenty given that the Commodore 64 keyboard is pretty basic and it's quite difficulty to press more that 2 or 3 keys without the keys ghosting anyway.


 Outside view of the Fauxmodore 64




Inside the Fauxmodore 64