Sunday 23 December 2018

Commodore 64 Joystick interferes with keyboard

I have been contacted a few times to fixes a particular fault on a Commodore 64. A fault that isn't a fault, but a 'feature' of the design.
The fault report usually goes along the lines of 'when I move the joystick, it also presses some keys'.
This can be seen if you plug a joystick into port 1 and wiggle it around, you will see a variety of keys pressed. Ignore the POKE 53281,0 - that is just to set the background colour to black. We have hit the limit of my photography skills, my camera just doesn't get on with the light blue on dark blue of the default colour scheme and merges them into one.
The phantom keypresses aren't actually a fault, they are caused by the joystick ports sharing the same pins used by the keyboard. Here you can see that part of the schematic in isolation.
The joystick ports are connected to the lower 5 bits of each of the 8 bit ports used to scan the keyboard. The joystick is just a series of switches connecting the up / down / left / right / fire lines to ground, and this is read by making those ports both into inputs and activating internal pullup resistors in the 6256 Complex Input Adapter. Any inputs which read 0 mean that lines from the joystick is active. The others read as 1 due to the pullups.
When the keyboard is read, the rows (port A of the CIA) are set as outputs, with each row pulled low in turn. The columns (port B of the CIA) are read in, any that are low indicate a key on the currently scanning row is held down. If there is a joystick in use in controller port 1, that can cause false readings as that also make one or more of those rows low when the joystick is moved or fire is pressed, giving the false readings above.
That's normally as much as needs to be said as that explains the extra characters on the screen. However, one repair request came in recently which initially looked like this, but proved to be a little more complicated. What was happening here was keys were stopping working after the joystick had been moved, and were staying disabled until the power was cycled.
Here I have typed 1234567890 several times, and after moving the joystick down, you can see that 3 and 4 stop registering. The keys W, A, shift, Z, S, and E also stoped, you can see from the matrix that these are all on the same row.
Those keys remain unresponsive, and when the joystick is moved left, more keys go, this time 7 and 8 (and also Y, G, V, B, H and U).
Again, a full row, and the row that corresponds to the pin on the controller port 1 pin that would have been pulled low by the joystick.
I know the joystick is fine, but I tested in anyway, and also tried several other joysticks including my 'joystick emulators', and the same effect was observed.
There was only one likely culprit here, U1, the 6526 CIA that connects to the keyboard and both controller ports.
The chip was soldered in, so just to make sure, I did try the Commodore 64 Diagnostics with loopback connectors. That initially confused things by saying that both CIAs were at fault, but detected that on the user port test.
That, however, turned out to be down to a bad connection on the edge connector, so I gave that a good clean and got it nice and shinny.
With the cleaned, it passed all tests, and did not detect the keyboard fault, I presume it was testing in the default state after power on when it works, rather than after the inputs had latched up (if that is what had happened).
I still thought the keyboard CIA was faulty, so I replaced it, the ran the diagnostics again to check everything was still OK. That passed OK, and back in BASIC, the fault was gone, no keys were being blocked after moving the controller in port 2.
I suspect that fault could have been caused by swapping the joystick ports when powered, or by static getting to the pins on the port from a carpet. I don't know for sure, just be careful with your controller ports.

If you want to support this blog, you can donate via Patreon or Paypal, or buy something from my store.