Friday, January 5, 2018

1351 Mouse and paddles now work on the MEGA65 rev1 PCB

I had previously written about how I had figured out to drive the mouse.  I have now merged those changes into the MEGA65 source code, and synthesised a bit-stream that happily works with it, as you can see in this video:

This proved not too hard to do, especially since I had already proven it to work in my VHDL test harness. The main complications I faced were in plumbing the signals through to the SIDs, and getting the CIA multiplexing of the POT lines working correctly.  With two SIDs, the MEGA65 lets you use all four POT lines without fiddling with the multiplexor: Two on each SID. The CIA multiplexor lines just switch which SID handles the POT lines from which joystick port.

The only known caveat at the moment, is if you use external SIDs, then the POT lines won't work, because the POT lines are read through the VHDL SIDs.  There are a couple of ways around this at the moment:

1. Have some kind of crazy adaptor on any external SID cartridge, to route the lines. This might require joystick pass-through adapters, similar to what I am using on this rev1 PCB.

2. Patch software to use the MEGA65 direct POT registers at $D620-$D623, which allow all four POT lines to be read, without involving the SIDs.

However, we recognise that this is not ideal, and I will have a look at having an option to have SIDs external, but still making the POT lines be read from the internal VHDL-SIDs. That way, things like the MSSIAH cartridge combined with an external SID cartridge would still be able to work, which we see as a potential use-case for some folks, and that we would like to support.

Otherwise, the only remaining thing to fix on the POT lines is to try out the 1.0nF capacitors, to see if that gets us full range of movement on the paddles working correctly.  I had a couple of errands to run this morning, so I pedalled past Jaycar on the way and invested the necessary $0.70 in the two capacitors, and also a few dollars for an HDMI cable, so that I can begin working on HDMI output.

After replacing the capacitors, the mouse still works, and I even didn't accidentally exchange the X and Y axes when I had the appropriate wires de-soldered, which I was very happy about :)

Also, changing the capacitors fixed the jumping problem in the mouse test program, as the values being presented by the mouse are now in the correct range expected from a real mouse. However, the paddles are still not perfect: They only cover the range from $00 to about $C0 (range of 192).  So it might be that we need a slightly larger value capacitor, perhaps a 1.2nF in order to get full range. However, that said, real C64 paddles typically have a similar usable range, but not identical.  So, the best solution: Test it! The easiest option open to me was to simply plug in Pinball Spectacular, and try to see if I could get full travel on the game. This worked totally fine, with ample spare travel at each end.

So, I think that wraps up the POT lines on the MEGA65 for now.  I can now work through the other tasks on my list.


  1. Nice work, all in all it has become a clean and elegant implementation. The copy of the registers at $D620 looks like a good idea for people who are interrested in "legacy free" programming.

    Getting the capacitor value right is indeed a bit of a trial and error process. But no need to worry that much, as neither the C64 is perfect: I did another experiment this morning with a C64 with real paddles: I am able to get the full range, but the point where you reach 255 is already at 290 kiloohm. The conclusion is that the capacitors inside the C64 are also significantly oversized and it is not much of a problem in practise at all: It doesn't hurt in games if you can turn the paddle a bit more if the bat on the screen is already against the wall. With 1.2nF or perhaps 1.47 nF you might do better than the original C64.

    All in all I kind of like the 1351: Yes, it is a bit of a hack to abuse the POT-lines this way, but works just fine and it's kind of ironic that modern USB mice send their position at about 100 Hz, high-end gaming mice 300Hz, but the 30 year old 1351 humiliates them with 2 KHz :) Considering that it runs at 1MHz, it would be logical that it updates its 6-bit counters every clock cycle, so there is near zero latency beween mouse movement and transmission.

    And so... the Mega65 might become a good computer for high-end gaming mice... unique selling point :)

    1. Yes, while it is a bit of a hack, it is a very nice solution in the end. And as you say, the very high update rate of the 1351, gives much better response than even a modern high-end gaming mouse. This issue of poor latency on modern computers is one that someone explored recently: They basically concluded that old computers like Apple ][ and CBM PET etc all did much better than modern ones. The only thing that worked against them is their long key travel. Give a MEGA65 short-travel keyboard and scan the keyboard at ~1KHz, and you could get response rates averaging 15ms or so. It could be interesting to make some fast response game for MEGA65 and also have a PC client, and show that it is basically impossible to beat someone who is playing on the MEGA65 if you are on a PC.