|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
ZX Spectrum Nunchuck Joystick Interface
This is my Nunchuck Interface for the ZX Spectrum. This is quite a popular device and I try to keep a few in stock for people to buy. If you're interested, you can buy directly from me, as described here. Alternatively, search eBay for the (slightly more expensive) listing.
A Nunchuck controller, for the uninitiated, is a one-handed joystick controller popularised by Nintendo. It's a slim unit that fits in one hand.
It has a small joystick (a "thumbstick") under the thumb and a fire button on the tip which is operated by the index finger. Thus you get joystick direction control and a fire button in one hand, leaving the other hand free. On Nintendo the other hand operates a different type of controller; on the Spectrum the other hand would more typically be operating other game features using the keyboard.
My controller interface has two compatibility modes, one being Kempston, the other being Sinclair keys (6,7,8,9,0). This means it will work with any game which has Kempston or Sinclair compatibility, or redefinable keys. It also has autofire, with 4 fire speeds. That's toggled on and off by the small button next to the fire button. Holding that small button cycles the autofire speeds: 4Hz, 7.5Hz, 10Hz and 20Hz. It turns out that 7.5Hz is the sweet spot for most games I tried.
I'm using an AliExpress Nintendo-compatible Nunchuck. The official Nintendo ones are 5x the cost! Under the cover the interface has a beefy microcontroller, programmed to respond to Kempston or Sinclair joystick standards. It's not easy to make a video showing Specchums how to use a joystick, but I made one anyway: (VIDEO PLACEHOLDER) This sort of controller really benefits games with relatively complex controls, where the joystick is complimented with keypresses for bombs and powerups and the like. Things like combat flight simulators are significantly easier to play because you can switch weapons and use other controls while simultaneously retaining joystick control. Design
The Nunchuck interface is almost all implemented in software on a microcontroller:
The microcontroller board is an RP2350B based board from Olimex. It exposes all 48 GPIOs on the RP, which is required for this project so the microcontroller can decode all 16 bits of the Z80's address bus. That's not necessary for a Kempston compatible device (which uses an 8-bit port number, 0x1F), but it is required for a keyboard port on the Spectrum's ULA (which uses the full 16 bit width). The Nunchuck device was implemented by Nintendo as an I2C slave. These AliExpress Nunchucks have the markings ground off the chips they use, but everything has been reverse engineered so it's simple enough to have the microcontroller repeatedly query the controller over an I2C bus. From there, I just work out what the Nunchuck is saying the joystick and buttons are doing and convert that information to Kempston or Sinclair joystick protocol before putting it on the Z80's data bus when the Z80 asks for it. The Nunchuck has a motion sensor in it, and that works as well. Only, the Spectrum was conceived long before such technologies were invented, and there's no way I can think of to use the motion controller's data. I suppose it could be made available to the Spectrum as a curio? I can't really see a point though, no games could use it. My initial implementation used one of the RP2350's cores to track the Z80 control bus and the other core to query the Nunchuck over I2C. That worked fine at 150MHz, but once I started thinking about handling the button press to change modes, or the autofire, or changing the autofire speed, it became clear that I had no resources left and I needed help from the PIOs. I therefore moved the code which places the joystick data on the Z80's data bus as a PIO program. Two PIO programs actually, one for Kempston mode, the other for Sinclair mode. Pressing the mode toggle button stops one PIO program and starts the other. The PIO programs both work the same way. They watch the Z80's address bus, plus the IORQ and RD lines, watching for an IN instruction on the relevant port. Once that scenario is detected they pull, via DMA, the latest Nunchuck status byte from the core which is doing the I2C transactions. PIOs are really nice like that: you set them running and forget about them, they just keep singing along doing their task while the cores do the more complex things. Derek Fountain, August 2026 |
||||||||||||||||||||||
|
Site and content Copyright 2023 Derek Fountain - All Rights Reserved |
|||||||||||||||||||||||