Possible to detect when joystick is being read?

For experts to discuss very technical stuff and newbies to ask why the Spectrum they bought off ebay doesn't work.
Post Reply
Joefish
Manic Miner
Posts: 581
Joined: Tue Nov 14, 2017 10:26 am

Possible to detect when joystick is being read?

Post by Joefish » Fri Nov 09, 2018 1:16 pm

On a +2 / +2A, is it possible to detect on a joystick port the exact moment the joystick is being read?
Or maybe its possible on the AUDIO out to detect the steady state of the beeper bit (high / low) over the top of the chip sounds?

I ask, as a simple way of triggering an external light, buzzer or rumble motor other than building an I/O interface board...
0 x

User avatar
1024MAK
Manic Miner
Posts: 489
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: Possible to detect when joystick is being read?

Post by 1024MAK » Fri Nov 09, 2018 2:17 pm

The two machines use different circuitry for a start. On the 128k toastrack AND the +2 (grey), a Sinclair designed custom chip is used. There is no way that anything plugged into the joystick ports can tell when the CPU grabs the state of the input lines.

On the +2A/+2B/+3/+3B, the joystick ports are part of the keyboard matrix. You can tell when the CPU scans the matrix, but you cannot tell if the CPU was actually trying to read the joystick port or keyboard. If you look at the way the keyboard works, you will see that it uses the high order address lines. These change state everytime the CPU accesses ANY memory or IO devices... So sorry, it’s a no again.

The best method is to use either the output lines on the “RS232” serial port, or the output lines on the Aux/keypad port. These are latched outputs (from the AY sound chip) routed via a +12v / -12V level shifter chip. So make sure whatever you feed can cope with these voltages.

Mark
0 x

Joefish
Manic Miner
Posts: 581
Joined: Tue Nov 14, 2017 10:26 am

Re: Possible to detect when joystick is being read?

Post by Joefish » Fri Nov 09, 2018 2:27 pm

OK, thanks. The Aux port sounds better, although they are odd connectors. Latched output, drive a transistor (being careful of the voltage) and turn on a buzzer. I'm assuming if I try and put that 12V straight into a relay something's gonna cook!

I fully expected not to be able to tell the joystick and keyboard polling apart. So how would that work as a detector, that the CPU is scanning the keyboard matrix? Would you basically have to have a permanent short from e.g. FIRE to GROUND to detect anything happening? How would the read manifest itself?
0 x

Joefish
Manic Miner
Posts: 581
Joined: Tue Nov 14, 2017 10:26 am

Re: Possible to detect when joystick is being read?

Post by Joefish » Fri Nov 09, 2018 5:26 pm

Hang on - are you saying that the keyboard row lines are being set high and low all the time, randomly, based on the upper 8 bits on the address bus, even when the keyboard is not being read (i.e. an IN with 254 on the lower 8 bits)? Such that from the keyboard circuit, you can't tell when the keyboard IN actually occurs?
0 x

User avatar
1024MAK
Manic Miner
Posts: 489
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: Possible to detect when joystick is being read?

Post by 1024MAK » Fri Nov 09, 2018 7:11 pm

Joefish wrote:
Fri Nov 09, 2018 5:26 pm
Hang on - are you saying that the keyboard row lines are being set high and low all the time, randomly, based on the upper 8 bits on the address bus, even when the keyboard is not being read (i.e. an IN with 254 on the lower 8 bits)? Such that from the keyboard circuit, you can't tell when the keyboard IN actually occurs?
Simple answer = yes!

More complex answer:

It is easier to see on a 48k schematic. All the lines connected to keyboard connector K2 connect to the CPU address lines A8 to A15 via a diode for each line.

On the +2A/+2B/+3/+3B machines, the “COM” lines connected to pins 2 and 8 on each joystick connector are actually connected via a diode to MA3 or MA4 of the 40077 gate array chip. MA3 and MA4 also connect to A3 and A4 of two of the DRAM chips. Note however that these MA lines (there are eight in total) output from the gate array are multiplexed between the lower address lines (A0 to A7) and the higher address lines (A8 to A15) during access to the RAM.

To monitor the “COM” lines, you need to reference to a real 0V/GND on another connector. As there is no 0V/GND pin on the joystick ports.

To use the output from the aux/keyboard port (a 6 way BT telephone plug will fit if you attack it or the socket with a fine metal file), take an output line, feed it via a 2.2k ohm resistor to the base of a NPN transistor. Connect the emitter of the transistor to the 0V/GND of the computer. Wire a 1N4148 signal diode in parallel, that is diode anode (A) to the base of the transistor, diode cathode (K) to the emitter of the transistor. This diode protects the transistor from the -12V that the aux/keyboard port can output.

Feed a separate +12V DC supply to the relay coil (or take the +12V output from the edge-connector, assuming you are using a relay with a 12V coil). The other side of the coil then connects to the collector terminal of the transistor. To protect the transistor from the high voltage spike when the relay coil is turned off, use another 1N4148 diode. Connect it in parallel with the relay coil. Diode anode to the +12V. Diode cathode to the collector of the transistor.

If using an external +12V DC power supply, the 0V/GND of this supply needs to also connect to the emitter of the transistor.

The aux/keyboard outputs can supply about 15 to 20mA, maybe a little more. But they switch between +12V and -12V.

The schematics for the +2A/+2B/+3/+3B machines are at this web site: zxnet.co.uk ;)

Mark
1 x

Joefish
Manic Miner
Posts: 581
Joined: Tue Nov 14, 2017 10:26 am

Re: Possible to detect when joystick is being read?

Post by Joefish » Sun Nov 11, 2018 3:11 pm

Thanks for that - I can use this as a simple output controller, without tying up the main edge connector.
0 x

Post Reply