Wednesday, December 27, 2017

Building Joysticks

Now that the bitstream is working fairly well at 800x600 (at least well enough to cause our children to squabble about whose turn it is to play Boulder Dash next), I am beginning to turn my attention back to finishing testing the physical ports on the first revision of the MEGA65 PCB, and then get as many of those ports working as possible.

The keyboard is already working, thanks to the overhaul of the keyboard input code.  The joystick ports also used to work. The past tense being employed there, because the overhaul of the keyboard input broke it.  I have since fixed that (it was just that I hadn't fed the real joystick pins into the combined joystick input code), and am synthesising the resulting bitstream for testing later today. 

For those with an interest in VHDL, here is the logic that is used to update the joystick state:

      for n in 0 to 4 loop
        joya(n) <= '1' and (joya_physkey(n) or joykey_disable)
                   and (joya_widget(n) or widget_disable)
                   and (joya_real(n) or joyreal_disable)
                   and (joya_ps2(n) or ps2_disable);
        joyb(n) <= '1' and (joyb_physkey(n) or joykey_disable)
                   and (joyb_widget(n) or widget_disable)
                   and (joyb_real(n) or joyreal_disable)
                   and (joyb_ps2(n) or ps2_disable);
      end loop;

Basically for each line on both joysticks, we consider all the possible input sources, and merge them together, these are USB/PS2 keyboard using dedicated keys mapped to the joystick, the MEGA65 Widget Board that can be connected to a Nexys4 FPGA development board to allow use of a real keyboard and joysticks on that, and apparently the USB/PS2 keyboard a second time (I just noticed this, and will have to investigate why on earth I have it twice).

However, getting to the point of being able to test joysticks has led me to a long term problem I have had: I don't have any properly working C64 joysticks left. I have a Quick Fire 2, with its lead in very poor condition, with loops of wires on the outside holding it in strange kinks that cause it to sometimes work.  I could have fixed that, but the quality of the switches and everything would mean that it would soon die again.  Also, it wouldn't solve the above-mentioned problem of both of our children wanting to play games at the same time.

Thus I finally got around to doing what I had intended to do for the last 20 years, and build up a couple of proper arcade joysticks.  There is something about the feel of a fully free and well constructed arcade joystick controller, as well as the fact that they are much, much more durable than commodity joysticks, and also much more serviceable. The TAC2 is about the closest C64 joystick I have found, and even those are not as durable, and to me at least, don't quite have the same feel.

Anyway, this adventure in making arcade joysticks was made easier by the fact that Jaycar now stock the joystick assemblies and buttons, as well as cheap plastic boxes in which to put everything.  I had previously bodged one up about 20 years ago with parts from a pinball rental company, but Jaycar is much, much cheaper, and the quality of the mechanisms seem to be pretty good.

Wiring up a C64 joystick is really simple: There are dedicated lines for up, down, left, right and fire, and these get connected through the switches to ground.  If you want any electronics in there, e.g., an auto-fire function, there is also 5V available.  There are also two lines for the analog inputs, but we are not using those.

The arcade joysticks have spade connectors, so I got some nice black 7-core cable and put spade connectors on one end, and the correctly wired DB9 on the other end.  I did try to get all clever-pants, and bought the cable as DB9 serial null-modem cables, with the female DB9 on the end, however, they didn't have all nine pins connected, so I had to go for the hand-soldered and screw-box cover. Here is the joystick wired up with spade-connectors and a soldered ground-loop, so that if I have messed up the joystick directions in the wiring, I can easily fix it.

If I were building an arcade game for public use, I would have used spades for the ground-loop as well, so that the micro-switches could be more easily replaced as they wear out. However, for home use, that is unlikely to ever happen, and a bit of remedial soldering doesn't scare me. The spade connectors also mean I can switch one of them to being "left-handed" (button on right), if my daughter's fears about not being able to use a "right-handed" joystick prove to be genuine.  I should say that I am also left-handed, but don't have trouble using a right-handed joystick, so we will see how we go.

Anyway, here is one of the finished units. Total cost per unit, about AU$45 (ca. 30€).

They are quite big, which is partly necessitated by the rather large joystick mechanisms, and also because I like a big solid joystick, so that you can whack the stick around as you need, and thump the button with impunity.

The arcade buttons from Jaycar have an LED in them, so you can make the button illuminate, which I decided to do on one of them. The other was already sealed up, so I didn't make the modification to that one, but I might another day. For now, it means that I have an easy way to tell them apart.

I'm pretty happy with the result. They are unlikely to ever appear in an Ikea catalog or anywhere else where styling is important, however, they are solid, should last the next 20 years, and have that nice arcade game feel to them.  Now I just need to wait for the FPGA synthesis to finally finish, so I can give it a try...


  1. Hey Paul, nice work so far, but can't you provide a way to using a 3 button + Start, Sega MegaDrive compatible joystick on the C65? I mean, it could open the door for more complex games running on it...

    1. Hello,

      I am happy to explore adding support for MEgadrive and Amiga CD32 multi-button controllers. However, I don't own any. If someone were to send me one off each, I will happily look at adding support for them. Now is a good time to do this, as we have a small window of opportunity to adjust the wiring of the joysticks.


  2. Megadrive controllers are sold new on Aliexpress, for example:

    However, supporting them won't be easy: They expect +5V on pin 5, while the Commodore control ports provide 5V on pin 7. Pin 7 is used by the Megadrive controller to select beween the direction signals on pin 1-4 and 4 of the buttons. The remaining buttons are connected to pin 6 and 9.

    Supporting the button/direction selection on pin 7 might be doable by switching on-off the normal 5V supply, allthough this might be somewhat dangerous as you can no longer safely connect that line to GND.

    Supplying 5V on pin 5, the POTY line, looks difficult to me. The active component in such a joystick is a 74HC157, which probably does not draw a lot of power, so you don't need to offer a lot of current. However, probably still difficult and perhaps only achievable with mechanical switches?

    But, I do think the fact that you can buy these devices brand new anno 2017 at affordable prices makes a strong case to get them supported. Perhaps worth looking if there is a viable solution to the 5V problem.

    Technical data on the Megadrive/Genesis joystick available here:

    1. Hello,

      I think the solution is to have a megadrive joystick adapter you plug into the joystick ports on the MEGA65, and which contains an arduino or similar that talks the protocol to the megadrive controllers, and then has a high-speed protocol to the MEGA65. That way, we don't need to change the pinout at all. This seems to me the most practical path, if we still want mouse and paddles to work. Speaking of which, we need to work out the correct circuit to have in the MEGA65 to listen to the pot lines. This is one of the things I want to address once I have the IEC serial bus working.


  3. Hi Paul, nice post...thanks for sharing! :)
    Do you have a link to the box on Jaycar you used as well?


    1. Hi Paul,

      Here are the ones we used:

      They are only marginally deep enough, depending on how you route the joystick cable. If I were doing it again, I would do this more carefully, and probably have the cable come out very low on the box, instead of half-way up as I did.

      If you decide to make your own, please send me a photo or two, and I will post them here.