• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
Retro Game Coders

Retro Game Coders

Retro computer/console game + dev community

  • About
    • Retro Computer Collection
    • Contact
  • Blog
  • Retro Resources
    • Retro Gaming Timeline
    • Online Retro IDE
    • Retro Pixel Art Editor
    • Dungeon Loom Map Editor
    • 6502 Programmer’s Reference
    • Emulators
      • Acorn Electron
      • Amstrad CPC Emulator
      • Online BBC Micro Emulator
      • Commodore PET Emulator
      • Browser C64 Emulator
      • DOSBox/DOS PC emulator
      • Tandy CoCo/Dragon
    • Best Retro YouTube Channels
    • New Retro Books
    • Raspberry Pi Amiga Emulation
    • MiSTer FPGA Tutorial
    • BMC64 C64 Pi
  • Community

Home » Retro Game Coders Blog » Hardware, Refurbs and Builds

Reading C64 Joysticks and Analog Signals (Programming Electronics with the Commodore 64 Part 3)

In Part 1 we blinked an LED using the Commodore 64 User Port, and in Part 2 we read binary (on or off) input also using the User Port. In this part we will use the Control Ports to read Joystick input and also analog signals.

The Two C64 Control Ports

Join Retro Game Coders Community
Join the Retro Game Coders Community

The Commodore 64 Control/Joystick Port

The C64 has two Joystick ports, but you will notice they are labelled Control Port 1 and Control Port 2. This is because, as you might infer, they are not just joystick ports!

In fact there are pins for an Atari-style joystick, paddles, mouse, and even a light pen.

The paddle pins are in fact able to not just read digital, on/off signals, but values from 0 to 255, because they are each connected to an analog to digital converter on the SID chip.


You can now follow the tutorials and edit the code right in your web browser with the Online Retro IDE

– No downloads, configuration, etc necessary, and it is free!

Control/Joystick Port Pins

C64 Control Port Pin Diagram
1Up
2Down
3Left / Paddle Fire
4Right / Paddle Fire
5Paddle Y / Potentiometer
6Fire / Light Pen
75v
8Ground
9Paddle X / Potentiometer
Control Port Pinout

Basic Joystick Reading

There are two addresses to read joystick values, one for each control port. Joystick 1 is read at address 56321, and joystick 2 with 56320.

Due to the way port 1 conflicts with keyboard input on the CIA chip, most programmers have traditionally favoured port 2.

Basic reading joystick in port 2
Result

💬 Questions or comments? Head over to the community to discuss!

Reading Both Joysticks

10 j1=not(peek(56321)):j2=not(peek(56320))
20 print "{clear}"
30 if j1=-255 then print "j1   ";
40 if j2=-127 then print "j2   ";
50 if (j1 and 1) then print "j1 ^ ";
60 if (j2 and 1) then print "j2 ^ ";
70 if (j1 and 2) then print "j1 v ";
80 if (j2 and 2) then print "j2 v ";
90 if (j1 and 4) then print "j1 {arrow left} ";
100 if (j2 and 4) then print "j2 {arrow left} ";
110 if (j1 and 8) then print "j1 > ";
120 if (j2 and 8) then print "j2 > ";
130 if (j1 and 16)then print "j1 Q ";
140 if (j2 and 16)then print "j2 Q ";
150 goto 10

To read both joysticks you just need to grab the values of the two ports using PEEK and then interpret the results appropriately.

When the Commodore 128 came out they added a JOY command to replace having to PEEK memory addresses. It works a little differently in terms of the values returned but it is a much more convenient approach.

Strangely, even though there were sufficient pins available, the C64 seemingly standardized on a single fire button during the entire production run outside of a few outliers, even when other systems were innovating with different controllers and inputs.

Reading Analog Signals

Atari Paddle
Atari Paddle

Speaking of different input controllers, we should talk about Paddles.

For those not around during the Pong heyday of the paddle, unlike joysticks and d-pad controllers that use switches and buttons, they are an analog type of input device. This means that rather than return a direction, the paddle returns a position between 0 and 255.

Really this means each paddle contains a “pot” (potentiometer), something found in a lot of electronics projects, and are used for dials, sliders, analog joysticks, etc.

This ability to provide an analog input also comes in handy for things like, say, reading the temperature.

The most simple project for people interested in retro games programming is obviously the analog joystick, so here we have the most basic stripped-down version:

Reading Analog Signals
Reading Analog Signals (using a joystick port extension cable for convenience)

As you can see, this analog stick takes pins for Ground, 5v, the X and Y, plus a switch.

On the control port these are reflected thusly:

As always, but especially here, be careful how you wire things up because it is easy to zap your computer by applying voltage where it shouldn’t go!

Output appears as a value between 0 and 255

C64 Electronics Series

Part 1: The Commodore User Port

Part 2: Digital Input

Part 3: Joysticks and Analog Signals

Part 4: Commodore 64 + Arduino

Category: Hardware, Refurbs and BuildsTag: basic programming, Commodore 64 (C64), commodore pet, electronics, vic20
Previous Post:C64 “Security System” / Digital Input (Programming Electronics with the Commodore 64 Part 2)
Next Post:Commodore 64 + Arduino (C64 Electronics Part 4)c64-arduino

Retro Game Coders

Retro computer/console game + dev programming community by Chris Garrett

  • Bluesky
  • Threads
  • Facebook
  • Instagram
  • YouTube
  • Mastodon

Maker Hacks ・ D6Combat・chrisg.com

© Copyright 2026 Chris Garrett

Privacy ﹒ Terms of Service

Return to top