24

Is there a way, such a specific interface adapter, which would allow me to connect a PS/2 keyboard to an original ZX Spectrum?

I expect the keyboard to work similarly to the ZX Spectrum itself -- in other words, pressing P would trigger send the same interrupt to the CPU as the rubber keyboard.

It should be doable since some joystick interfaces, such as the Sinclair Interface 2, did map joystick events to key presses.

25

I did such interface long time ago. It was(is) an internal interface designed to fit in a place near the right side of the board when using the Plus case.

Technical details here: http://www.zxprojects.com/index.php/ps2-adapter

This is the board Interface circuit board

Designed to fit here: Spectrum with interface fitted

Schematic. Very simple. One microcontroller does all the work. Circuit Diagram

Upon booting, the uC resets the keyboard and checks for scan 3 capability. If it's not present, then default to scan 2 mode. After then, the uC sends a command to the keyboard to leave the NumLock led on. That means that the keyboard is ready to use.

Features new in the firmware version (v1.3b) or changed from previous releases:

  • Spanish and US-english keyboards supported (download and install the relevant update for your keyboard)
  • All the Spectrum keystrokes are supported, even those that needs to switch to E-Mode for a while (Velesoft request).
  • The Tab key has changed: now it maps to CAPS SHIFT+8, to help identing while working in GENS 3. Shift+Tab maps to CAPS SHIFT+5.
  • Trigger key on Sinclair mode has changed to the left Alt key. The "0" key can also be used.
  • The "Application" key toggles E-MODE on/off.
  • The pound sign has been mapped to the key that shows the grave accent (both symbols have the same ASCII code).
  • Spanish keyboard: the Ç key is mapped to the (C) sign.
  • Macros are stored in flash. They are not erased when the computer turns off. A update procedure doesn't erase the current stored macros.
  • HOME and END keys also work as Begin Macro Recording (F3), and End Macro Recording (F4).
  • The PAUSE key pauses a macro recording, so a key typed after PAUSE is not recorded. Recording is resumed pressing PAUSE again. While in macro playback mode, the PAUSE key toggles current macro playing on/off.

ISSUES RESOLVED:

  • Phantom keys appearing while the user types another key, or key combination does not happen anymore (hopefully). This was causes by the old way to give keytrokes to the ULA. From version 1.3, this method has radically changed. Now, the microcontroller polls the Z80A for IO requests to the ULA port. If there's a IO read request, the microcontroller answer it with theright value. For this reason, a hardware change is needed for the PS/2 adapter, internal version, to work correctly with the newer firmware versions.
  • A little issue with Ctrl-Alt-Del not working correctly on powerup has been fixed.

Features present in the firmware version (v1.2):

  • All alphanumeric keys are mapped to the Spectrum, as well as symbol keys and their shifter forms.
  • Shifted alphabetic keys give the upper case version, as expected. Shifted numbers give the corresponding symbol.
  • Current keyboard mapping is for the spanish standard 101/102-keys layout keyboard.
  • Cursor block maps to the Spectrum cursor keys (i.e. "down" key is mapped to CAPS SHIF+6)
  • ESC is mapped to the BREAK Spectrum key (CAPS SHIFT+SPACE)
  • Caps Lock key is mapped to CAPS SHIFT + 2
  • AltGr key maps to CAPS SHIFT + 9
  • The F2 key (which is used mainly to edit the current filename in Windows Explorer and some other applications) maps to the EDIT key (CAPS SHIFT + 1).
  • The Tab key maps to the EXTMODE key (CAPS SHIFT + SYMBOL SHIFT).
  • The Backspace key is mapped to DELETE key (CAPS SHIFT + 0).
  • Left Control key is mapped to CAPS SHIFT, and right Control key, to SYMBOL SHIFT.
  • The separate numeric block behaves as if NumLock were always on (in fact, it is).
  • The ScrollLock key toggles the cursor key mapping between normal use (editing mode) and Sinclair joystick mode. The later is signaled with ScrollLock led on. In Sinclair joystick mode, cursor keys are mapped to the same keys used by the Sinclair port 2 joystick (6,7,8, and 9). Trigger (0 key) is mapped to both Control keys (recalling the standard MAME layout for controls).
  • If the reset pin is connected from the keyboard adapter PCB to the Spectrum, everytime the user presses Crtl-Alt-Del, a low pulse is sent to the reset pin at the Z80, hence enabling the user to reset the machine with the classic three-finger-salute.
  • The adapter has a bult-in mechanism for helping the user to diagnose a malfunction. Upon booting, if Alt+F12 is pressed, a series of keys are "typed-in" automatically. Assuming the K-mode, the sequence typed is:

    REM 12345qwertasdfgZXCV67890yuiophjkl*,.

  • There's another, more sophisticated, built-in test, designed to test the compatibility of a specific keyboard. Some of them doesn't allow more than a number of keys being pressed at the same time, or even more than one. This is very important, for example if you want to use the Sinclair joystick mode feature and want to press UP+RIGHT for instance. The test is entered by pressing Alt+F1. Prior to do this, it's better to reset the Spectrum.

Starting with firmware version 1.1, there is a macro feature, which can be considered in beta state. The user can record up to 6 macros of 512 key strokes each one (a key depressed and released counts as two key strokes).

  • F3 enters macro recording. After F3, the user has to press the F-key he wants to assign to the macro. Then, CapsLock led goes on, signaling that a macro is being recorded.
  • From this moment, the user can type anything he wants. If he reaches the keystroke limit, the recording is automatically ended.
  • To stop a macro recording, press F4. CapsLock led goes off.
  • To play the macro, simply press the F-key assigned to it. Caps Lock led goes on to signal macro play. A macro cannot be stopped unless Ctrl-Alt-Del is pressed. If the user resets the Spectrum using the lateral switch, macro playing won't stop.
  • 1
    Ben Veersted (from bytedelight.com) did an external version based upon my design. I don't know if he is still selling it. – mcleod_ideafix Apr 19 '16 at 23:32
  • 1
    Of course you have to take into account that any keyboard or joystick interface that maps itself to the keboard won't work in a +2A/+3, as these computers have a strong data bus coupling between the gate array and the Z80, making impossible for a external device to override the data put by the gate array from the internal keyboard. Earlier models had resistors between the ULA and the Z80 data busses allowing for a external interface to override the keyboard if needed. – mcleod_ideafix Apr 19 '16 at 23:35
  • Isn't there an IORQGE signal that just invented to fix this kind of problems? – lvd Sep 21 '17 at 12:57
  • 1
    +2A computers don´t have IORQGE signal. And even if they had it, disabling the internal ULA (actually, gate array) to be able to read the keyboard from an external device would disable the EAR input as well, making the computer unable to load programs through audio while the external keyboard interface is used. The solution would be to modify ULA data pins so they are open collector outputs, like in the original Ferranti ULA, or maybe just adding 8 small (220 ohm) resistors to make them weaker than a data value coming from the expansion bus. – mcleod_ideafix Sep 21 '17 at 15:13
  • Wow, it's stuff like this that makes me believe Retro enthusiants have too much time on their hands :-) Kudos for the effort. – user6464 Nov 24 '18 at 0:58
5

In case you are looking for something that can be bought off-the-shelf:

if1Bis (https://sites.google.com/site/interface1bis/) has, amongst numerous other goodies also a ps/2 port supporting keyboards and a mouse.

The device mimicks an IF/1 and supports USB connection to a PC as well as a nice IF/1 file system replica on SD card. I have one myself (don't use the PS/2 keyboard, though) and can thoroughly recommend it.

  • Another vote here for the Interface1bis. And I have used a PS/2 keyboard connected to it like this (and furthermore, you can also use the keyboard of the PC that the IF1bis is connected to, and 'send down' keystrokes - if you have a lot of text typing to do, that works surprisingly well). – robsoft Jul 28 '16 at 19:08
3

Not really an answer but I feel some things needed to be clarified.

Pressing a key on ZX does not trigger any interrupts ... The interrupt is triggered by ULA itself with screen refresh rate and the ISR is scanning keyboard ports in matrix manner.

The PC keyboards Do this whole stuff internally usually by integrated i8048 MCU chip (yes i8048 not i8051). That alone brings up some restrictions in reflection to ZX which was major disappointment for gamers coming from ZX to PC world. The ZX can handle any number of Key pressed at any time the PC (most keyboards) can not. That is because the i8048 has a very little of RAM only between 64 to 256 Byte depending on the chip. This memory is used for registers (4*8 Byte are just for global purpose register banks of r0..r7 ...), stack and variables. So you can imagine there is not much space for key scan tables. So only last few keystrokes are stored instead. That means once you press more than a certain number of keys in a single line or row in the keyboard matrix any next keystorkes are not registered until you release at least one of the first keys. That is the major reason why there are very few split screen games for more than one player on single PC because certain keys (especially extended scan codes like numeric pad) lead to very small number of keys triggering this (like 3-4) so when you're fighting with a friend and suddenly your fire button does not work ... because it has less priority the fun starts :)

Now back to your question To connect PC keyboard you need to emulate the keyboard matrix. So basically you need a computer (MCU) which reads the serial input from PS/2 and emulates the states on the keyboard matrix ports. If you got basic MCU coding experience then it is not that hard to do but the connected keyboard will never perform as well as the original one due to above restrictions.

  • 1
    Upvoted for correcting the cause/effect relationship on interrupts, but I feel like the real Spectrum was far from ideal, suffering from key shadowing? Well, maybe not the original, but when we used to play North & South on a +3 (so: two people at once, on the same keyboard), there were definitely combinations of keys that did not work together. Could be only the Amstrad models though. – Tommy Sep 20 '17 at 13:38
  • 1
    @Tommy on ZX clones we where playing the N&S we have no such experience. But as comment on above answer suggest the +2A/+3 models had stronger pull ups meaning the keyboard matrix would need to provide(sink) more current to override them. And in case of too many rows/vs columns switched on at once could lead in some circumstances to not sufficient current due to branching. But that is just my speculations as I do not came in contact with those models... – Spektre Sep 20 '17 at 13:44
  • 1
    Yes, sorry, to be clear for other readers, it's definitely something like that: an analogue or other manufacturing effect. The CPC has something similar that's well documented, though clearly both it and the Spectrum's hardware allows any key independently to be queried for current state. So there's no digital-side reason that every key can't be entirely independent and it's not surprising that clones made them so. The genuine Sinclair machines might have done as well, for all I know. – Tommy Sep 20 '17 at 13:54
  • The number of keys that can be detected simultaneously by any particular keyboard is down to how the keyboard matrix is wired, not what microcontroller is in use. If the keyboard uses capacitative sensing (like the original IBM Model F) or has a diode on each key (like the Toshiba 3100e laptop) then there's no limit to how many simultaneous keypresses it can detect. – john_e Sep 21 '17 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.