Joystick interface for C-16, C-116 and Plus/4
© 1999, 2000 Levente Hársfalvi
Abstract
Do you have a C-16? A C-116? ...A Plus/4? ...Are you a proud owner
of a CBM 264 or 364 prototype ;-) ? ...Then I suppose you know those pretty
8 pin mini DIN sockets on your computer with Joy 1 and Joy 2 label. I'd
say it's just another blunder of Commodore (whoever on Earth knows what
did motivate these lots of bad decisions?) not equipping these computers
with a more or less 'standard' joystick connector. One could say anyway,
that's just another small nuance of the features that make these computers
not to fit into the series of other micros of Commodore. All in all - the
joystick port of the Plus/4 differs from the 'standard' (Marko said: 'Atari
VCS style') joystick port both in its shape and its inners.
In this document I'll explain some possibilities on interfacing
standard 9-pin digital joysticks to the Plus/4 and also some practical
tips.
This is V1.1 of this document; some re-writing was done, and
correcting a mistake in the theory that I made in the first version.
Table of contents
Copyright
This article is © 1999, 2000 Levente
Hársfalvi and this document is published under the General
Public License by the Free Software Foundation. (Since GPL was designed
for software, applying it to an article or hardware stuff is not as clear
as applying it for a program; however, I'd like to publish this document
with the spirit of this license.) All this is distributed in the hope that
it will be useful, but WITHOUT WARRANTY and with all the usual disclaimer
stuff. If you make an attempt to build an interface for your computer,
or use anything from here for your own design, you do it at your own risk.
Should anything here prove defective, all consequences are with you. For
more, read GPL.
You can have this document in a zipfile together with all graphics here.
Credits
The article is based on the original User's Guides by Commodore and some
practical experience. Schematics were drawn with CirCad
3.5 for DOS by Holophase Inc., converted
with Image Alchemy V1.7.5 by Handmade Software and customized with Adobe
Photoshop 4.01 (Win95). The HTML document was written in Arachnophilia
3.9 (Paul Lutus) (V1.1 was edited in Netscape
Composer). Thanks for all creators of these programs.
Review
On figure 1. you can see both computers joystick ports.
Figure 1.
C64
The socket is a male Canon Sub-D 9. There are two identical connectors
(joy 1 and joy 2) on the computer. You can also find the same sockets and
pin-outs on the VIC-20, the C-128 and the Amiga, and more or less the same
on a lot of other computers. There are 9 lines, of which one is common
ground (GND), one is supply voltage for the paddles and occassional external
devices (like joysticks equipped with autofire) (+5v), four + one direction
lines (left, right, up, down, fire) and two analogue potmeter lines for
paddles (POTX, POTY).
The joysticks contain small micro switches, connected between
GND and the appropriate direction line. When pushing the joystick towards
a direction, a switch shorts the appropriate direction line to ground.
The scanning of the state is realised in several different ways in different
computers; in the C64, the direction lines are connected parallel with
the keyboard scanning lines and can be queried with a simple procedure
through the CIA1 ports. Since there are two joystick ports on the C64,
scanning them independently needs them to be connected to different CIA
input lines (as it is seen in the C64's schematics).
The POTX and POTY lines are for querying the paddles (the popular
game devices of the early 80's - does anyone still have such gadgets?!).
The paddles are in fact potentiometers inside (variable resistors). One
end of the potmeter is connected to +5v while the other to the POTX or
POTY line (the paddles used to appear in pairs wired to one common joystick
port plug). In the computer, these input lines go to a simple integrating
analogue to digital converter (counter type). By measuring the time needed
to charge a capacitor by the current going from +5v through the paddle
potentiometer, one can deduct where the wheel is currently positioned.
In most computers, the position is measured with 8-bit precision.
Plus/4
First of all, as you probably noticed (at least if you're rather
a Commodore hacker and not a Plus/4 fanatic in particular), I refer to
these computers as 'Plus/4' or 'Plus/4 line'. Well
this is wrong. But I'm not gonna call them '264 line of computers', because
even if it was the 'official' name of this line, it never made it to the
common sense - and anyway this line has not much to do with the 'C-64'
as '264' would suggest. As I'm a longtime Plus/4 and C-16 user I rather
decide with the 'wrong' but otherwise more sensible term. By the way, the
members of this series are the same in the subject of this document.
Commodore decided to equip these computers with new joystick ports.
(Just to mention, only the Serial,the Video and the RF connectors are identical
to the ones found on other Commodore computers). For the tape and joystick
ports, Commodore introduced Mini DIN plugs. The reason, well - I guess
it's out of the scope of this document. They probably wanted to lower their
prices, and thus decided to use cheaper connectors. Or they were in lack
of free place on their new model (the Plus/4 is relatively small; there
is simply no free place on the rear of the computer, even if the sockets
are mini DIN's and the RF modulator appears on the left side). The rest
is history; they also introduced their own joysticks with the computer,
but seems like it didn't help much. Joysticks were always a problem ever
since the Plus/4 existed.
Speaking of the specialities of the joystick port, at first we
notice that no POTX and POTY lines can be found. It's not possible to hook
a paddle (as easily as to the C64) to the Plus/4. We find the usual GND,
+5v and the direction lines. There is one more line which was not present
on the C64s joystick port, this is the Select' line.
Going deeper to the inners of the port, the Plus/4 hardware schematics
tell us some differences. In the Plus/4, the joystick lines are also connected
parallel to the keyboard scanning lines, the same way as it is found in
the C64. However, both joysticks are connected parallel to the same
keyport scanning lines (except fire buttons, whose keyport lines are unique
for each ports). Thinking it over, it would mean, that we cannot differentiate
between the two joysticks from the computers side, since they're both free
to pull the same keyboard line in the same moment.
Now, the problem is solved by the last line named Select' which
is unique for each joystick ports. The Plus/4 joysticks direction switches
must be connected between the appropriate direction line and Select' (instead
of GND). In the scanning process, the software on the computer can make
each Select' line to go low in a particular moment, independently from
each other, thus making possible to scan the state of just one joystick
instead of both. (One more advantage of this method is, that it's also
possible to prevent the keyboard scanning process from getting false keyboard
data by the joystick, just by inhibiting both Select' outputs, which was
anyway not possible on C64).
In a more deep point of view, the Select' line comes from a standard
LS-TTL gate output from the computer, whose input is hardwired to one dataline
of the processor data bus (D2 for joy1 and D1 for joy2). One would suspect
a static, well programmable selector line in such a subject, but this design
seems to rather result in a heuristic 'oscillation' on the Select' line
(as the computers databus changes cycle to cycle). Still, it is suitable
for this task, because of the way it is used for the selection. The answer
is in the TED, the TEDs keyport input latch which is sampled in a certain
minute.
The TED's keyboard port is available at $FF08. When the processor
writes to this register, the TED samples the actual states of the keyboard
lines (this value can then be read out next, reading from $ff08), right
after receiving the writing statement. If we want the state of one joystick,
we need first to make the appropriate Select' line to go low, making the
joystick able to pull the keyport lines to low. Because of the above mentioned
wiring of the Select' lines in the Plus/4, this is only possible if a certain
data is found on the data bus when (or rather, shortly before) this sampling
happens. Luckily, the 6502 architecture of the processor helps that it
can be done. For getting a joysticks state, one must write to $FF08 a value
whose 1st or 2nd bit is 0. Since the writing statements (for example, an
STA $FF08) 'last' transferred byte on the data bus is just the value to
be written, in the right minute the lines of the databus will reflect the
bits of the data written to $FF08 - thus driving low the respective D,
thus Select' line. The TED samples its inputs before the next cycle, so
when the program reads the sampled value from $FF08, the register will
reflect the state of the input lines when the joystick selection happened.
There is one more difference that I haven't realised for a long
time; it is indeed a really stupid overlook anyway, I don't know how did
I miss it since it is also in the above facts. The Select' lines come from
a standard LS-TTL gate output (a totem pole output). This means,
it is either GND or (something less than) +5v but nevertheless both levels
are active. It would mean, that the joystick can indeed pull an input line
high in some moments (to be precise, whenever it is moved and it is not
selected). And this fact makes sure that the series diodes on the joystick
input lines, seen in the schematics of the Plus/4 must indeed be present
in _all Plus/4 (else, the joysticks, if some direction switches are shorted,
would interfere with the keyboard scanning process). As a consequence,
this makes sure that it doesn't hurt if one drives the inputs to active
high, as I previously suspected - since the original design does it so.
How to...
Some conlusions that may help in designing a joystick interface:
-
Seems like, it's not very neccessary, to put simply, to try hooking paddles
to the Plus/4. You can do it however, but it's at least not supported by
any software; and dealing with it needs a lot of extra electronics (not
even such counter with capture option is available in the Plus/4s hardware).
However, you can see an excellent design having Solders (Christian Schäffner)
SID card that has a full featured C64-like joystick port on the rear.
-
The different architectures may cause troubles. There is no problem with
bare joysticks, because they simply act as a bunch of switches. The only
difference is, the different common point. That's the way BTW that common
C64 to Plus/4 joystick interfaces are wired. Troubles come in, when the
joystick, or whatever external unit needs supply voltage for its operation.
-
Because of this pretty dirty operation of the Plus/4 joystick port, one
doesn't have to keep in mind not driving the input lines to high. Going
to the joystick port directly from a a totem pole output is legal and violate
no rules.
-
Since the Select' lines change so fast, the interfacing circuitry, if any,
should be fast too.
-
There is another quirk that should also be kept in mind. The input latch,
which is responsible for sampling the state of the scanlines, is integrated
into the TED chip. It won't make problems anyway, but the TED is not well
protected against peaks and high currents. A very common situation is when
this latch 'goes to the moon'. Luckily, this failure doesn't mean that
one must obtain another TED, nevertheless some problems still come in.
The input keyboard scanlines will appear going to the keyport read register
($FF08) directly, instead of the 'in a certain minute' sampled behaviour.
Once again, this doesn't result in unability to work. Since the other port
- which is responsible for the keyboard scan (the keyport output latch)
- is a simple 6529B, the selecting lines are static, it's no matter that
reading $FF08 happens in one or another minute (one probably gets still
the same result from the keyboard if reading the lines later by few microseconds;
anyway, few programs like Laser Squad sense no keys on a defect TED machine-
maybe they change $FD30, the keyport output latch after they wrote but
before read $FF08). In opposition to this, the joystick read process is
heavily dependent on the above sampling. With a defect TED, one most probably
gets no answer from a properly interfaced (or even original Commodore)
joystick. Why? The selection depends on the state of datalines in the sampling
cycle. Now, when the real 'sampling' occurs, it's the very same cycle when
reading from $FF08. In this moment, there is $FF on the databus, the last
byte of the cells address to be read. Thus all data lines are high - no
joysticks are selected.
A simple interface
With this interface, you can use your C64 joystick with the Plus/4. This
is just a pin-to-pin interface and thus it will be suitable for bare joysticks.
Joysticks with autofire function may or may not work occassionally, depending
on their construction.
You'll need...
-
A Sub-D 9 connector (male), with the plug housing.
-
A Mini-DIN 8 connector (male). You may have troubles finding this part,
but resellers like Konrad, RET or Radio Shack in the US can surely ship
it.
-
A short 7 wire cable. You can also substitute this by a piece of ribbon
cable.
-
A soldering iron, solder, some solvents (if needed...) and a good amount
of patience... Whatever soldering iron will do (if you're good in this
process...) but I'd suggest a Weller or similar termostate one, especially
with sharp soldering pin.
To create this interface, cut a short (about 10 cm) cable. Blank the wires
at the end (about 1.5 - 2 cm from the cover, and about 1-2mm on the wires
each). It makes sense to apply a few solder to these ends before trying
to mount them on the connector pins (especially the mini-DIN). Take the
mini-DIN plug. Solder wires to pins 1-6, 8. (You will notice that it is
the most difficult stage in the process, because of the small pins and
place). When finished, take the Sub-D plug ( DON'T FORGET TO PUT the cover
of the mini-DIN plug to the cable before this!) Solder the appropriate
wires to the Sub-D plug (DIN #1-4, 6 --> Sub-D #1-4, 6 (directions+fire),
DIN #5 --> Sub-D #7 (+5v), DIN #7 --> Sub-D #8 (Select').
You can verify the routes on Figure 1. All lines go straightforward
to their equivalents. The only exception is the Select' line: this is connected
to the joysticks GND pin. +5v is connected because some autofire circuits
will still work if it's present, even if the 'GND' level is present just
occassionally. Note that POTX and POTY (Sub-D #5,9) are unconnected.
After soldering everything, check if there are no loose wires,
shorts on the connectors. Then assemble the plugs together.
You'll most probably have to adjust the mini-DINs cover, because
there's so small place around the Plus/4's connectors that these replacement
plugs don't always fit to the computer (the original, cable manufactured
ones do, but they can't really be obtained).
Try your work out. Connect the interface, the joystick and the
computer together. Switch the computer on. Try to move the joystick. If
you see 'A', '4', '3', 'W' characters on the screen (joy2) or '5', 'R',
'6', 'D', 'T' (joy1), your interface is perfect. If you see '2', 'Q' or
the cursor jumps to 'HOME', you'd most probably connected the GND lines
together instead of connecting Select'.
When you notice no effect, first check the cabling, the wires,
the joystick etc. If nothing works, your Plus/4's TED is most probably
broken. This interface doesn't work for you.
-
Take a new TED. ...This may be impossible. No TEDs were manufactured since
1990 or so.
-
Design a small board (or just circuit, piggy backing the chips in the Plus/4)
that captures the TEDs input lines right (or rather after a short time)
when $FF08 is written. This may be difficult, since it implies a lot of
decoding logic. But it's possible.
-
Disassemble your interface (the mini-DIN plug), remove the wire from pin
#8 (Select') and connect it to pin #7 (GND). This will mean that your Plus/4
won't be able to differentiate between joy1 and joy2. But the joystick
will somehow work. If you experience strange behaviour when using certain
programs, it should be because both joystick ports are selected statically
from the point of the Plus/4.
I don't really know, how and why TED's input latches get burnt. It
may well either be an effect of high current or static electricity. Would
suspect the first. If you use the joystick port, your computer is also
subject to this risk. I know, heavy shocks on the joystick input lines
surely do - once I also did burn mine, about ten years ago :-( (I obtained
a new TED since that). Don't make an attempt to solder something inside
with an instant ('pistol...') soldering iron. Since Commodore's original
joysticks contain keyboard-like rubber+charcoal bell sensors, whose resistance
is relatively high, you can also put some resistors (of about 100 ohms)
series to the direction lines (they fit into the Sub-D connector housing).
A full featured interface
This interface is capable of faking a C64 joyport on the joysticks
side (except POTX and POTY), and being able to forward the line-states
to the Plus/4 in sampling times. Because of the nature of the Plus/4 joyport,
this implies some gating logic.
My interface is built around a 74LS244, a dual quad tristate bus-driver
chip. But you can use several other chips too. In fact, five OR gates would
do the trick (but unfortunately, simple OR chips contain only 4 gates).
Here's the schematic diagram.
Figure 2.
It looks like spaghetti. However, the connections are simple, and this
'spaghetti' look is the consequence of drawing the schematic from the ready
interface. All direction lines go to the bus driver chips inputs. The chips
gate inputs are connected to the Plus/4 joystick ports Select' line. The
gate inputs are low-active, so when Select' goes low, the chips outputs
will reflect the respective inputs. Else, the outputs are in high impedance
state - say, they don't even exist from the point of the Plus/4 joystick
port. In theory, the joystick side would need 5 pull-up resistors of about
2-3K ohm each on the direction lines; I left them, since the TTL inputs
are on a weak high state as default thus it works with or without those
pull-ups. A bypass capacitor of 100 nF (between pin 10 and pin 20 of the
chip) won't hurt either, but there was no place in the housing for one
more ceramic capacitor. The series resistors limit current, as the original
Commodore joystick does with its sensors.
(If you built my previous interface design with the diodes, don't worry
- applying the diodes or using an open collector bus driver doesn't appear
to be hurting, just more than neccessary.)
What you'll need is...
-
A Sub-D 9 plug (male), with cable-end housing
-
A mini-DIN 8 plug (male)
-
A short 8-wire cable
-
74LS244 chip. This is one of the most common chips ever used in digital
electronics. If you have some old wrecks, I bet you have a lot of them.
But if not, any part resellers can ship it. You can also use any other
family (74F244, 74S244). I'd avoid, however, using standard, C, HC (maybe
even HCT) parts because of logical level incompatibilities. You can substitute
the '244 by a 74LS757, which is almost the same component but has open
collector outputs.
-
5 pieces of about 100 ohm resistors. Limits currents (fakes Commodore joysticks).
-
A lot of short wires, to connect the chips pins to the Sub-D 9 connector.
-
A small amount of epoxy resin
-
A screwdriver, pliers, solvents (or resin) and your favourite soldering
iron. You may use instant soldering iron, because this TTL chip is not
much sensitive to peaks; but you'll be at least hard on soldering in small
places.
Since I found no sense in creating a board for such a small circuit, I
made everything fit into the Sub-D 9 housing. First take the 74LS244, bend
all pins horizontally (or at least, 15-20 degrees from the horizontal state)
:-O. Cut pins 8, 9, 12, 13 (you may even smooth the side of the chip).
Cut all pins short, so you can still solder to them but they're much shorter
than originally. Try if the chip fits into the housing, with its 'head'
towards the connector and the 4 cut pins between the two screw-holes that
keep the house halfs together. If fits, O.K.
Here is the chip with its pin-out. The red arrows indicate the
connections and data directions inside the chip
Figure 3.
-
Cut some short wires which will connect the Sub-D 9 pins to the chip. Now
you know what is seated where; then you can approximate the lengths. Blank
the wire ends.
-
Take the 8-wire cable and blank it's ends.
-
Take the resistors, and cut their ends 'short' (as needed). Bend them like
they forms 'U's with the resistor body on one arm and just wire on the
other - it will be the easiest to solder them this way to the chips pins,
so you can still solder the wires to the other ends.
-
Take a short, naked wire. Connect pins 1 and 19 under the chip together,
solder the wire and cut the ends. Make sure that the wire doesn't come
off the pins when you'll solder to them.
-
Take the 8 wire cable. Solder one wire to pin 19 of the chip (Select').
Take a short wire together a with a wire of the cable, and solder to pin
7 of the Sub-D connector. Do the same with pin 8 of the Sub-D. Solder the
other end of the short wires to pin 20 and pin 10 of the chip. (+5v and
GND)
-
Connect all appropriate Sub-D direction pins to the chip's inputs (see
figure, which to which).
-
Pick up one resistor, and solder it to one output pin of the chip. This
may be difficult. You may want to use some solvents or resin (it makes
soldering much easier). Repeat it with the other resistors.
At the end, you'll get a complex that can be seated into the bottom of
the Sub-D housing. Try it if it fits. Hopefully, it does. Take special
care to the front of the chip, where it's really low on room. As final
step, connect all remaining wires of the 8-wire cable to the resistors.
-
Put the plastic cover of the mini-DIN plug to the cable. Solder all wires
to the appropriate pins (see figure).
When you think you're ready, once again verify all connections. Now it's
time to try your work out. Connect the mini-DIN to the joystick port, and
connect a joystick to the interface Sub-D connector. Then turn your computer
on (turning the display on first seem to be reasonable, to be on the action
right from the minute when you turn the computer on). The expectations
are the same: when moving the joystick, you should see '3', 'W', '4', 'A'
(joy2) or '5', 'R', '6', 'D', 'T' (joy1) characters on the screen. If it
doesn't work, you should suspect...
-
Loose connection somewhere.
-
Defect 74LS244
-
Defect joystick
-
Defect TED
First you have to make sure that your Plus/4 is good. Try connecting, for
example, the Select' and the Up line together on the joystick port, then
switch the computer on. If it acts like constantly pressing '3' or '5'
then the computer itselves is perfect. If not, the TED input latch is dead
(as described above). If this is the case, for possible solutions see above.
-
Finally, I'd suggest to make it secure. Mount the cable fastener part of
the Sub-D connector to the cable. Now the Sub-D should be quite compact
inside, with a lot of wires and simply no space. Take the epoxy glue, mix
a small amount and fill the Sub-D 9 housing around the chip and the wires.
When done, put the two sides together and fix the screws in the connector
housing. The glue solidifies in few hours.
Hope you did all good. Seems like nothing will prevent your interface from
surviving a few centuries ;-)
Contact
For contact, write to Levente@Terrasoft.Hu.
Bug reports, improvements and comments are welcome.