Reading Time: 3 minutes

After digging through Fire Ant's machine code in an emulator, the natural next step is playing it the way it was meant to be played: on a real Commodore 64, from the sofa. Original joysticks are wonderful and mostly worn out, and a long cable across the living room is nobody's idea of fun. This project is a small adapter that lets modern Bluetooth game controllers pretend to be a 1980s joystick.

Where the project is today: design stage. This post covers the complete design: electrical interface, parts, wiring, software and test plan. Nothing has been built and tested yet, and the code is a design sketch.

Credit where it is due: Ricardo Quesada's open-source Unijoysticle adapters already do this brilliantly, built on his Bluepad32 library. This design uses Bluepad32 too. The point of building my own is to understand every part of it, and to write it up in detail.

5signal lines per joystick port
0 Vmeans pressed; open means released
10 Hzoptional auto-fire
~£35rough parts cost
SCORE 0420port 2ESP32BT → DE-9Bluepad32 on an ESP32any supported modern padBluetooth
A modern pad steering a sprite on a C64 through the adapter (animated illustration).

How a C64 joystick actually works

There is no protocol at all. An Atari-style joystick, the kind the C64 uses, is just five switches. Each one connects a signal line to ground when you push that direction or press fire. Inside the computer, each line is pulled up to 5 V and read by one of the two 6526 CIA chips, so a released switch reads as 1 and a pressed one as 0.

DE-9 pinSignalUsed here
1Upyes
2Downyes
3Leftyes
4Rightyes
5Paddle Y (POT)no
6Fireyes
7+5 V (max 50 mA)never
8Groundyes
9Paddle X (POT)no

That simplicity is what makes the adapter possible. To "press" a direction it only has to connect the line to ground, and to release it, it lets go. Pin 7's 5 V supply is far too feeble for an ESP32 with its radio running, so the adapter has its own USB power and shares only ground with the computer.

The one part that matters: open collector

It is tempting to wire ESP32 pins straight to the joystick lines. Don't. The C64 pulls those lines up to 5 V, and the ESP32's pins are 3.3 V parts that are not 5 V tolerant. Even a pin set to "off" would have 5 V pushed into it through the pull-up.

The answer is an open-collector stage on each line: a small NPN transistor whose collector connects to the joystick line and whose emitter goes to ground. When the ESP32 drives the base high, the transistor switches on and pulls the line to about 0 V, which is a press. When the base is low, the transistor is off and the C64's own pull-up holds the line at 5 V, exactly like a released switch. The ESP32 never sees 5 V.

Inside the C64ESP32GPIO16 · 3.3 V logicR1 4.7 kΩR2 100 kΩQ1 2N3904+5 Vpull-upCIA 6526$DC00 bit 0DE-9 pin 1 (Up)Common ground · DE-9 pin 85 V: releasedGPIO16 LOW → transistor off → the C64 pull-up holds the line at 5 V → reads 1 (released)≈0 V: pressedGPIO16 HIGH → transistor on → line pulled to ≈0 V → reads 0 (pressed)
One of ten identical channels. The animation alternates between released (5 V) and pressed (about 0 V).

The 100 kΩ resistor holds each transistor firmly off while the ESP32 is booting or unpowered, so the C64 never sees phantom presses. A tidier alternative to ten transistors is a pair of SN74LVC07A chips: hex buffers whose open-drain outputs tolerate 5 V while running from 3.3 V. The catch is that they only come in surface-mount packages.

The hardware

PartWhy this oneApprox. £
ESP32-WROOM-32 development boardThe original ESP32 has Classic Bluetooth as well as BLE, which many game controllers need. The newer S3 and C3 are BLE-only.6–10
10 × 2N3904 NPN transistorsOne open-collector stage per line: two ports × five lines.1–2
10 × 4.7 kΩ and 10 × 100 kΩ resistorsBase resistor and base pull-down for each stage.1–2
2 × DE-9 female connector and 9-core cableOr cut up two cheap joystick extension leads.6–12
Stripboard or a small two-layer PCBStripboard is fine for the first one.3–10
LED and 330 Ω resistorPairing and port status.<1
5 V USB supplyThe joystick port cannot power the ESP32.~5
3D-printed enclosurePETG, with strain relief for both cables.2–4

All in, roughly £25 to £45.

Wiring

Each ESP32 pin drives one transistor stage, and each stage's collector goes to one pin of a DE-9 socket. The pins chosen avoid the ESP32's strapping pins (0, 2, 5, 12 and 15), the flash pins (6 to 11) and the serial pins that chatter during boot. On WROVER modules, GPIO16 and 17 are used by the PSRAM, so this layout assumes a WROOM.

ESP32-WROOM-32 DevKitGPIO16 · port 2 upGPIO17 · port 2 downGPIO18 · port 2 leftGPIO19 · port 2 rightGPIO21 · port 2 fireGPIO22 · port 1 upGPIO23 · port 1 downGPIO25 · port 1 leftGPIO26 · port 1 rightGPIO27 · port 1 fireGNDPort 2 DE-9 (via Q1–Q5)1 Up2 Down3 Left4 Right6 Fire8 GNDPort 1 DE-9 (via Q6–Q10)1 Up2 Down3 Left4 Right6 Fire8 GNDEach signal passes through its own transistor stage (see the schematic). Pins 5, 7 and 9 stay unconnected.
Proposed wiring for both joystick ports.

Software

Bluepad32 does the hard part: pairing with and decoding a long list of controllers, including PlayStation DualShock 4 and DualSense, Xbox Wireless pads on recent firmware, Nintendo Switch Pro and 8BitDo controllers. It runs as an Arduino board package or inside an ESP-IDF project, and hands the application a tidy state for each connected controller.

The adapter's own code is short: turn that state into five "pull this line low" decisions per port, many times a second.

// Design sketch - NOT TESTED ON HARDWARE.
struct Pad   { int axisX, axisY; bool up, down, left, right, a, b, turbo; };  // filled from Bluepad32
struct Lines { bool up, down, left, right, fire; };                          // true = pull line to 0 V

constexpr int DEADZONE = 160;   // of roughly +/-512: about 30 %, ignores stick drift

Lines mapPad(const Pad &p, bool jumpOnB, uint32_t now_ms) {
    Lines l{};
    l.left  = p.left  || p.axisX < -DEADZONE;
    l.right = p.right || p.axisX >  DEADZONE;
    l.up    = p.up    || p.axisY < -DEADZONE || (jumpOnB && p.b);   // stick up = negative Y
    l.down  = p.down  || p.axisY >  DEADZONE;
    if (l.left && l.right) l.left = l.right = false;   // a real joystick cannot do both
    if (l.up && l.down)    l.up = l.down = false;
    const bool turboPhase = (now_ms / 50) % 2;          // 10 Hz auto-fire
    l.fire = p.a || (p.turbo && turboPhase);
    return l;
}

void drivePort(const Lines &l, const uint8_t pins[5]) {
    const bool v[5] = { l.up, l.down, l.left, l.right, l.fire };
    for (int i = 0; i < 5; ++i)
        digitalWrite(pins[i], v[i] ? HIGH : LOW);       // HIGH = transistor on = line at 0 V
}

Mapping choices

Controller inputC64 effectDefault
D-pad or left stickUp, down, left and right (8-way)on
A / CrossFireon
B / CircleUp, for games that jump with upoff
X / SquareAuto-fire at 10 Hzoff
Select / ShareSwap port 1 and port 2button
Second controllerPlayer 2 on the other portauto

Opposite directions pressed together are cancelled, because a real joystick physically cannot do that and some games behave strangely if they see it. The stick has a generous dead zone, so a slightly worn thumbstick does not make a character creep across the screen.

Latency

The C64 reads the joystick port whenever the game asks, typically once per frame (50 times a second on a UK PAL machine), and there is no handshake to slow anything down. The only added delay is Bluetooth itself, plus microseconds of transistor switching. That will be measured rather than assumed, by filming the controller and the screen together with a high-frame-rate phone camera.

Testing plan

  1. Bench test with a multimeter. With the adapter powered but not plugged in, fit a 10 kΩ resistor from each line to a 5 V supply to mimic the C64. Released should read 5 V; pressed should read under 0.2 V.
  2. Connect with the C64 switched off. The CIA chips are precious and do not like hot-plugging.
  3. Run a BASIC test. This prints the state of port 2 continuously:
10 PRINT PEEK(56320) AND 31
20 GOTO 10
ActionValue printedBit
Nothing pressed31—
Up300
Down291
Left272
Right233
Fire154

Address 56320 ($DC00) is port 2 and 56321 ($DC01) is port 1. Each direction clears its own bit, so diagonals and fire combine predictably: up and fire together reads 14. After that comes the real test, a long session with a few joystick-heavy favourites.

Risks

  • Port damage: the biggest risk is to the C64, not the adapter. Connect only with the power off, and keep the ground connection solid.
  • Controller quirks: some pads need particular pairing steps or firmware; Bluepad32's documentation lists what is supported.
  • Interference: a crowded 2.4 GHz living room can add latency spikes, so the test plan includes a busy-evening check.

What's next

A stripboard prototype first, checked with the multimeter routine above, then a small PCB that plugs straight onto the side of the machine. Later, the POT lines could carry a second fire button, which a few games support, and the same board could serve an Amiga or an Atari with a different cable.

For more ESP32 design write-ups, see my ESP32-S3 vehicle computer.

← All articles

Related articles