Commodore joystick ports

From: Jim Brain (
Date: 2004-10-21 07:43:45

I have been playing around with interfacing with the Commodore joystick 
ports.  Obviously the digital inputs are easy, but the analog inputs 
were tough, and doing anything else on the controller while handling 
them posed definite challenges.

I used some ideas from this cbm-hackers thread:

*Subject*: PS/2 mouse as 1351?*
From:* Maciej Witkowiak (/*
Date:* 2003-09-16 23:51:08

And the serial mouse interface information presented on funet.  The 
controller is an 8MHz Atmel ATmega16.

Tonight, I think I have some working code.

I noticed a few things:

I am using a 10K resistor to feed the POT lines, with POTY going 
straight to an INT line (INT1).  Since my intended interface was as a 
joystick/paddle, I tried to run the entire range.  I can;t seem to the 
POT line to 5V.  The reading is 10 at the lowest (255 being ground, 0 
being 5V).  I thought I would just start the charging earlier, but that 
does not work, as the SID internally shorts out the line until 256 
clocks into the cycle.  Any ideas? 

When sampling, I noticed +-5 jitter as I got up to 255 (less voltage 
applied).  I thought that was excessive, but it appears a regular paddle 
has +-4 jitter. 

Although not really needed for a paddle emulation, I was thinking I 
could detect PAL or NTSC by measuring a couple intervals between 
triggers, and calibrating. to get maximum resolution.

In another vein, I am trying to think of a way to utilize the 5 bit 
joystick interface to transfer raw interface data to the 64/128, say in 
the case you wanted raw PS2 mouse data back or you needed to talk to the 
controller.  My idea was to transfer it in nybbles, using the fire 
button as a clock generated by the 64/128.  I am pretty sure that will 
work fine, but the question is how to detect that the 64/128 wants to 
switch into this alternate mode.  When no buttons are pressed on the 
controller, I can set the pins to input and watch for activity, but what 

My initial idea is to look for a bit-pattern like 01010 and then 10101 
and then 01010, as that should never occur in the keyscan routine, If I 
see 01010, wait for 10101 for x uS.  If found, wait for 01010 for x uS.  
If found, switch into raw mode.  Wait for clock (FIRE) to go hi, dump 
low nybble onto "bus", then wait for clock to go low, then hi, repeat 
for high nybble, rinse, latther, repeat until done sending packet, then 
switch "bus" to inputs to await comand from 64 (0000 would be nop, 1111 
would be switch back into normal mode, etc.).  What are everyone's thoughts?

As always, code is GPL, so anyone that has a ATmega8/16/32 is welcome to 
have.  Eventually target is MLF-32 package ATmega8.  I tried to fit the 
functionality into a ATtiny28, but it is lacking some required items.  I 
found the ATmega8 is the smallest controller that can support the SPI 
interface and >1 IRQ.  My idea is to design a PCB that fits in a DB9 
shell, but bring all the pins need used by the joystick interface 
portion to solder pads.  That way, folks could modify the code and 
re-use the boards to build different interfaces/adapters.


Jim Brain, Brain Innovations                      
Dabbling in WWW, Embedded Systems, Old CBM computers, and Good Times!

       Message was sent through the cbm-hackers mailing list

Archive generated by hypermail pre-2.1.8.