Standard joysticks

The Next has two 9 pin DE-9 ports that standard ‘Atari’ style joysticks can be plugged into. They can have one or two buttons. The original Spectrum didn’t come with any joystick ports and several different interfaces were produced. The Next supports software written for all of them.

  • Kempston

  • Sinclair

  • Cursor

The joysticks themselves were all identical, you didn’t buy a “Kempston” joystick. Instead you bought a joystick and then connected it to a Kempston interface.

As a programmer on the Next it doesn’t matter which interface to use, Z88DK’s joystick API abstracts them all out to the same data structure. What matters is what the user has configured their Next to use.

The first port, which is the one on the left, is a Kempston joystick port by default. The right port is - at least on my Next - configured as the second Sinclair joystick. Original Spectrums didn’t have two ports, so the second port is not standard.

Warning

If you own a joystick like this one with two plugs, you’ll see one of them is light grey.

../../_images/joystick.jpg

Never ever plug that into your Next. It’s wired up differently and you will short out the power supply of the Next if you click one of the buttons. There is no protection on the Next’s ports and releasing the magic smoke from the FPGA would be upsetting.

Reading the Joystick

Communicating with the first joystick is easy no matter what interface has been configured.

Z88DK has code for this and the idea is the routines all report the same data structure which looks like this

Bit

8

7

6

5

4

3

2

1

Value

F1

F2

x

x

R

L

D

U

As programmers we write our games using that data structure, not caring what actual interface is being used.

The intended purpose is to make some sort of table of pointers and index into it based on what stick you actually want to check, and then make all the code work with that returned data structure.

This is explained with sample code on the Z88DK documentation website

https://www.z88dk.org/wiki/doku.php?id=library:input

Communicating with the second stick is equally easy if we know what it has been configured as. Knowing what it has been configured as can be difficult. The best way is to ask the user when they start your game.

The user can configure what the joystick ports do inside the config screen of the Next

Either port can be reconfigured. This is designed so that existing games work with the Next. As a programmer writing a Next game it seems best to stick with Kempston.

Peripheral 1 Register

The peripheral 1 register, which is laid out like this, contains the definition of which interfaces are configured. It can be used to work out what the user has set their Next to.

../../_images/peripheral1.png