C64 Keyboard Emulation Over Serial

There’s a lot of reasons you might want to emulate the keyboard on your Commodore 64. The ravages of time and dust may have put the original keyboard out of order, or perhaps you need to type in a long program and don’t fancy pecking away with the less-than-stellar feedback of the standard keys. [podstawek] has come up with the solution: a Commodore 64 keyboard emulator that works over serial.

It’s a simple concept, but one that works well. A Python script accepts incoming keypresses or pre-typed text, then converts them into a 6-bit binary code, which is sent to an Arduino over the serial connection. The Arduino uses the 6-bit code as addresses for an MT8808 crosspoint switch.

MT8808 Functional Diagram from Datasheet

The MT8808 is essentially an 8×8 matrix of controllable switches, which acts as the perfect tool to interface with the C64’s 8×8 keyboard matrix. Hardware wise, this behaves as if someone were actually pressing the keys on the real keyboard. It’s just replacing the original key switches with an electronic version controlled by the Arduino.

[podstawek] already has the setup working on Mac, and it should work on Linux and Windows too. There’s a little more to do yet – modifying the script to allow complex macros and to enable keys to be held – so check out the Github if you want to poke around in the source. Overall it’s a tidy, useful hack to replace the stock keyboard.

The C64 remains a popular platform for hacking — it’s even had a Twitter client since 2009.

14 thoughts on “C64 Keyboard Emulation Over Serial

      1. This could be another approach. However, since I wanted this to be very flexible, and the [any keymap] -> C64 keys mapping is happening on PC side anyway, I didn’t see a reason to put the lower-level mapping (C64 keys -> crosspoint switches) on Arduino. This way I can keep Arduino code very simple and focus on more hardware-level things, e.g. timings which are not perfect yet.

  1. That would require more pins (16 not counting the Restore key) on Arduino side. I wanted to minimize this number (to 9 in current implementation not counting Restore, but 8 is possible too). Also, I must say I found the crosspoint switch an intriguing chip and an elegant idea :)

  2. “[podstawek] has come up with the solution :”.. THE solution that came up every now and then on C64 forums for the last 20 years ??
    While there’s no problem to let know of the pratical use of these “crosspoint” switches for the purpose, Podstawek published another nice tutorial about another “afternoon project for the kids” and put more code on github (which should definitely be renamed “metoohub”)… yes, the truth is less gratifying.

    The real news here may be that he had the good taste to add a “similar projects” section ! :) But the Internet of Wanabees seems to have banished some simple respectful, humble and honest statements like “this well known solution amongst retro-computer hackers” or “here is my take on the classic microcontroller+crosspoint keyboard matrix simulation”…

  3. hackmeimfamous, when I built this, I was covinced it was a first. Probably says a lot about my googling skills, but all I could find were projects whereby people connected physical c64 keyboards to raspberry Pis running vine. After I posted the project on one of the forums you mentioned, I was advised of earlier similar projects. None of them, however, allowed typing on PC or sending key batches — they were all aimed at connecting a USB keyboard to C64. So this, plus putting the bulk of processing on the PC (which will ultimately lead to being able to use a much simpler microcontroller), plus how I handled the Restore key, are I believe still firsts. I have just been made aware of another project, ported from Amiga world, which does this without a matrix switch — I haven’t looked at it yet, but will reference it in my tutorial too when I read more. You are right about adding a “here is my take…” phrase at the beginning to make things clear. Let me do that shortly.

    1. “None of them, however, allowed typing on PC or sending key batches” : serial terminal for debug or to send simple commands are such obvious and classic things that kids and neophytes can discover them by their first Arduino experiments, so doing it is fine, but making the stretch to seriously call it an original feature… could open you up to a job opportunity as an HaD blogger :D

      “I was covinced it was a first.”, “putting the bulk of processing on the PC (…) plus how I handled the Restore key, are I believe still firsts” : processing data (with python or others) sent to an MCU is what everybody, including fresh hobbyists, does everyday on Earth while developing this kind of interface. And simulating the Restore key, with its dedicated line on the C64, seems no different than turning a LED off (as in the “Blink” fisrt Arduino lesson), but this is still unsupported in your code, and you didn’t explained the purpose of your transitor… Anyway, I don’t know how you could possibly believe these are “firsts”, unless you mean “first to shamelessly present such obvious things as special and new”, which sadly isn’t a first either.

      1. mefirst, thanks for pointing out this kind of project is something newbies do on their first days. I’m an electronics newbie indeed and I was sure I’d discovered something new.

        Don’t call this shameless. The tutorial and hackaday post were made in good faith: I was pursuing my own idea, was very proud of “discovering” a cross point switch for this job (naive me), enjoyed it, and thought was doing something good announcing it to C64 community. I have been, and will be, very open about any progress made. I have also, and will, inform of any earlier/similar projects in this area.

        FYI, switching the Restore key is hardly similar to switching a led. Answering your question, the NPN transistor is used as a relay here, and handling it for combination with other key presses / key holds will not be trivial in the software, at least for my neophyte skills. I’ll be updating the tutorial as I make my progress.

        1. You should be able to assert the restore line using the AVR. Simply keep the line tristated (input, no pullup). Then, to assert it, pull it low, wait for a few ms, then tristate it again. That’s exactly what hitting the physical key does. No need for a transistor there.

          I’m also using an mt8808 to control a C64, and incidentally my device also allows typing remotely via USB. In my case that is rather a side effect of allowing any command to be executed remotely, though. The main purpose is to intercept special keyboard combinations on the real keyboard to control other add-on hardware in my C64 (e.g. switch kernals, assert the reset line, etc) or to execute keyboard macros. See http://www.henning-bekel.de/keyman64.

          1. Henning, this is very interesting, thank you — a lot to learn from your project. I’m sure I’ll be back with questions when I’m back at my desk. Also, thanks for pointing out a way to simplify the Restore key handling!

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.