www.jupiter-ace.co.uk

Hardware articles index > Ace Keyboard Interface from ETI magazine, November 1983.


ETI Magazine November 1983 page 20
ACE INTERFACE
Game playing and typing in should be fast and furious on the Jupiter Ace because of the use of FORTH. But with a membrane keyboard? Doug Bollen shows how to get round the rubber.

It is strange that something as simple as a set of keys and a joystick should pose such a problem for both makers and users of low cost computers. Beneath that intractable rubber keyboard, in an unassuming plastic box, lies many a good computer, spoilt by the lack of a real human interface. Of course, the reason for this is a price differential of at least twenty-five quid.
  A typewriter-style keyboard can reduce frustration, and more than double program and test entering speed if the key-scan plus display routine in the computer ROM is fast enough to cope with fleeting fingers. Old mini and mainframe keyboards can be picked up now
and then quite cheaply, and some of them have excellent magnetic switches. Alternatively, a good low-cost keyboard may be built with readily available switches mounted on a piece of Veroboard.
  Video games are great fun, but can you imagine piloting an airliner or spacecraft with four keypresses? There is no standard for games software direction keys so a programmable joystick is an absolute necessity for the dedicated games-player.
  Once you've acquired a keyboard and a joystick, you need an interface to connect them to the computer. At this rate of expenditure you could have bought a 'Flash MK IIB' computer, but
never mind, it is all part of the learning process, and those plug-in-add-ons can be very versatile.
  The Jupiter Ace has a fast key-scan routine which is capable of electric typewriter performance. The space key is a trifle slower than normal, but all other keys respond well, particularly when aided by a software or hardware key beep. If the relatively large user memory (51 K expanded) of this compact language machine is taken into account along with its other features, an Ace with full-travel keyboard is capable of serious work in areas of text and data handling, as well as super-speed gaming.
  This project allows a full-travel keyboard and a joystick, acting on
HOW IT WORKS
- INTERFACE
The Ace rubber keyboard uses an input port which occupies eight addresses, but all even addresses (A0 low) are reserved for internal use. Data lines D0-D4, and address lines A8-A15 are used for key-scan, while D5 is reserved for tape load. The remaining three data bits may be ignored here. Because the five Ace data lines are up with no keypress, and the Ace TTL keyboard buffers have a relatively high output impedance for logic 1, it is possible to pull down the data lines externally during keyscan, and this saves on hardware and software.
  Ace keys are positioned in a matrix of 5 data lines by 8 address lines. In normal inputting key-scan mode, no keypress and multiple keypresses (other than shifts) return a zero; this is also the case with IN KEY. If the keyboard is read by 'address IN' (refer to Fig. 3), a combination of any five keys on each matrix line Y0-Y7 will give a multiple keypress code. For example, F7FE IN (keys 1-5) is binary 111111 with no keypress, five keys at once 100000, key '1' on X0 111110, and key '5' on X4 101111. The MSB is the tape port which toggles between 1 and 0 only when you input a tape signal.
  There is nothing very mysterious about the interface circuit of Fig. 1, it is merely a six-hit input port running in tandem with the Ace's own keyboard port, and addressed by A0 low. Two three input NORs (IC1) are configured to give an active low enable to buffer/driver IC2 during an input request. Diodes D1-D8 serve to isolate each address line. Spare input T is the alternative WAD port. X0-X4 and Y0-Y7 form the interface input lines.

Fig. 1 Circuit diagram of the interface.

ETI Magazine November 1983 page 21

Fig. 2 (a) Overlay diagram of the PCB.                                           (b) detail of assembly of edge connector.

any pre-selected group of five
keys, to be plugged into the back of the Ace, which will not invalidate the manufacturer's guarantee or require additional software. The interface circuit mimics the Ace's internal hardware so that dual keyboards and joystick effectively operate in parallel and simultaneously. An additional input provides DC access to the internal tape-load port of the Ace for experimental purposes.
  The ability to simulate key-press with a switch (without a mess of wires soldered to the computer mainboard) can provide a range of useful facilities. Allowing for shift functions and unprintable codes, there are 106 individual codes which may be obtained using INKEY during program execution, and each represents a discrete input channel. Multiple key-presses of up to forty keys are also possible with the IN word, or a compact machine code routine, and this will yield 255 key combinations or channels.
  A three-octave monophonic music keyboard, fitted with suitable contacts, can make use of the ready-made and debounced key-scan routine in Ace ROM, and leave 70 additional channels free for other functions. Multi-key-press offers three octave polyphonic operation.   A small panel of insulated material, with forty 3.5mm jack sockets, will serve as a general purpose patch-panel for switch interfacing, and is handy for quick, softwareless joystick programming. With the switch combinations available, and an equal number of possible computer responses, many other applications should spring to mind.


Construction
  Ace edge connectors are not widely available, but you can use a cut-down ZX Spectrum con-nector, a modified ZX81 connector,
or one cut from a long block. Make sure that the edge connector wire length is at least 14mm. Some, but not all, ZX81 connectors can be modified by carefully pushing out two contacts at the end of each block with a small pair of pliers and reinserting them in the ZX blanking key position, then fitting the blanking key at the end of the row to suit the Ace.
  Insert the edge connector half-way into the plain side of the PCB with the blanking key to the right.
PARTS LIST
CAPACITOR
C1            10uF 10V tubular
                electrolytic

SEMICONDUCTORS
IC1          74LS27
IC2          74LS367
D1-D8      1N4148

MISCELLANEOUS
Double sided 23-way edge connector (see text); 14-way PCB mounting screw terminals (see text); 14-pin IC socket; 16-pin IC socket; PCB (see Buylines); keyboard; joystick (see text).

Fig. 3 The coding of the keyboard matrix.

ETI Magazine November 1983 page 22

Fig. 4 Different Joystick configurations: a. a microswitch joystick rewired for the Ace and multipress on any six keys; b. pot switch joystick (Voitmace) shown for multi-press on keys 1 to 5; c. diaphragm switch joystick (Spectrovideo Quickshot) shown for multipress on keys 1 to 5; d. use of isolating diodes to avoid ghosting.




Lay a pencil along the top row of wires, on the foil side of the PCB, and apply pressure to the pencil to bend the wires inwards (see Fig. 2). Now bend the remaining row of wires inwards and adjust until the a suitable male edge connector strip into position between the wires, making sure that there is plenty of contact area free for the Rampack, and solder the wires to the strip. Position the edge connector parallel
to the PCB in all planes, 6mm away from the board, and solder to the PCB.
  Now check all solder joints with a magnifying glass (even if you do have good eyesight!) and look for whiskers or blobs of solder which may cause a short between adjacent strips. Clean minute blobs of flux from the extender strip with a brass wire brush. Plug the interface into the   Ace and remove it, with power supplies OFF, several times, to remove oxidisation from the compute board. If you have a Rampack, push it on and off the interface rear extender strip too. Now switch on and check that the Ace behaves normally. With clean contacts, it should be possible to rock the Rampack slightly without crashing. Look for dry joints or dirty contacts if there is malfunctioning.
  Insert the remaining components and link wires on the PCB, but leave out the longest link for the time being. Observe capacitor and diode polarities and DIL socket orientation. The screw terminal block can he made up of 8 + 4 + 2, 8 + 3 + 3, or 4 + 4 + 4 + 2 assemblies. It may be necessary to sandpaper the end of the blocks for a good fit on the PCB. You can insert and solder the long link wire . after the diodes have been soldered.
  Before inserting the ICs, check that the Ace works normally with the interface in position. Switch off, insert ICs the correct way up, and test again. The interface should have no effect on the Ace. Just to make sure, try a LOAD from a trusty tape and check all key-presses on the rubber keyboard.
  Wire up the underside of your add-on keyboard according to the keyboard layout in Fig. 3, and fit optional shift lock switches if required. Try to keep switch interconnecting wiring as short as possible, to minimise circuit strays.
  Your keyboard can be wired straight to the PCB terminal block, with about ½ metre of ribbon cable, and all key-presses then tested. If some keys work erratically, or are slow on repeat, try earthing the computer via the negative side of the power supply jack plug. A joystick can also be wired to the PCB terminal block, but cannot be reconfigured without switching the computer off because of edge connector wobble. It is a good idea to run a flexible length of ribbon cable from the PCB to two 2 A terminal blocks for the joystick, which can then be reconfigured while the computer is running.
  Joysticks


  There are many weird and wonderful joysticks now on the market. Analogue joysticks with pots are not suitable for this

: LEFT
  ." left"
;
 
: UP
  ." up"
;

: DOWN
  ." down"
;

: RIGHT
  ." right"
;  

: FIRE
  ." fire"
;

: MULTIPRESS
  0 IN 31 AND ( get keypress and 
 mask off unwanted bits)
  DUP 1 AND 0=
  IF
   ( is D0 low?)
   LEFT
  THEN
   DUP 2 AND 0=
  IF
   ( is D1 low?)
   UP
  THEN
   DUP 4 AND 0=
   IF
   ( is D2 low?)
   DOWN
  THEN
   DUP 8 AND 0=
   IF
    ( is D3 low?)
    RIGHT
  THEN
   DUP 16 AND 0=
   IF
   ( is D4 low?)
   FIRE
  THEN
   DROP ( discard keypress)
;
 
 
: TEST
  BEGIN
   CLS MULTIPRESS 500 0
   DO
    ( slow routine down for 
  display)
  LOOP 
   0
  UNTIL
;


Fig 5 Five-key FORTH multi-press
routine.

ETI Magazine November 1983 page 23
HOW IT WORKS
— MULTIPLE
KEY ROUTINE

READ is a table containing a 5 x 8 byte array of ASCII codes relating directly to the logical layout of the Ace keyboard. At the end of this table is an 8 byte array, which is a table of keyboard port ad-dresses (high byte only).
  The word KEY picks up from the I stack the start address of the READ table and the ASCII key value to be tested. It searches the table until it finds a match ' to the key value. If there is no match the routine is aborted with ERROR 6 as an invalid key code has been used.
  By the time a valid match is found, the Z80's B and D registers contain an indirect pointer to the relevant port address for the key which is to be tested (B register), and the key's position within that port as a data bit (D register). If the bit is reset ( = 0), then the key is being pressed and a 1 is placed on the stack, otherwise a 0 is stacked, thus giving a I true or false flag for testing with IF....THEN.

interface. There are 'floppy-stick' joysticks which do not 'click' but use switches which look like pots. Then there are diaphragm switch joysticks, and microswitch joysticks which 'click'. Leaving aside personal styling preferences and magnetic switch joysticks, the microswitch type is preferred for this interface, but diaphragm switch joysticks (Atari, Quickshot) will work over a limited range of keys and can he rewired (with some difficulty) for all keys.

  If you can find or make a microswitch joystick it should be wired as in Fig. 4a. The pot type switch (Fig. 4b) cannot be rewired for all key positions, but will multipress a five key row. The diaphragm switch joystick, Fig. 4c, can be rewired for all keys by cutting the tracks on the switch PCB and rewiring as in Fig. 4a, but make sure there are no solder joints under the switch actuator plastic ring. Unmodified, the diaphragm switch type will multipress five keys as in Fig. 4b.
  If you rewire the joystick according to Fig. 4a, use pairs of twisted insulated wire about metre long. If you are also making a patch panel (which has a socket for each key), the joystick pairs can be terminated with 3.5 mm insulated jack plugs. To configure the joystick for a program, merely insert the appropriate plug in the socket position corresponding to the keypress, or clamp the wire pairs in the terminal blocks by following the key/matrix diagram of Fig. 3.

  Certain key combinations of diagonal plus fire button could
conceivably produce unwanted responses with a few examples of commercial software. To avoid keypress 'ghosting', place an isolating diode in each joystick 'x' wire, as in Fig 4d.

  Programming For The
  Interface

   Good games software must be responsive and easy to control, not to be confused with difficult to play. There is nothing worse than a
CREATE READ 48 ALLOT

:  IN
  16 BASE C! 48 0
  DO
   RETYPE NUMBER DROP 
   OVER I
   + C!
  LOOP
  DECIMAL
;

: HEX
 16 BASE C!
;

READ IN

43 53 7A 78 63 61 73 64
66 67 71 77 65 72 74 31
32 33 34 35 30 39 38 37
36 70 6F 69 25 79 D  6C
6B 6A 68 20 6D 6E 62 76 
FE FD FB F7 EF DF BF 7F

DEFINER MC
 VIS CR ." BITES:"
 RETYPE NUMBER DROP
 CR BASE 
 C@ HEX SWAP ." ENTER"
 0
 DO
  RETYPE NUMBER DROP C,
 LOOP
 CR BASE C!
DOES>
 CALL
;

REDEFINE IN

MC KEY (NOTE:on bytes
prompt enter 52)

DF D5 DF El E5 6 8 E
5 16 1 7E BB 28 B CB
22 D 23 20 F6 10 F0 El
E7 0 3E 8 90 El 1 28
0 9 85 6F 46 E FE ED
78 2F A2 11 0 0 28 1
13 D7 FD E9

DEFINER MC
DOES>
 CALL

REDEFINE MC
sluggish 'thing' which hesitantly jerks in four directions and freezes (together with the whole scenario) during a zap. It takes all the fun out of what might otherwise be an excellent game.

  Multipress action is not difficult to achieve on the Ace, if INKEY is discarded in favour of IN. Up to five simultaneous keys (those in the vertical groups X0-X4 in Fig. 3 combined with other vertical groups) will give a total of 31 key-press combinations. Apart from the eight directions plus zap, pressing right plus left (or up plus down) could produce a tenth and eleventh response, but this is not possible on a joystick alone.


  In the five key multipress routine Fig. 5, you supply the direction and zap definitions, in place of the demo definitions inside the dot quotes. All five-key groups are operative because MULTIPRESS uses 0 IN. If you want to employ only one group or keys, change number base to HEX, edit MULTIPRESS, and replace 0 with an address from Fig. 3, then redefine


 

3FAE DF       RST 18
3FAF D5       PUSH DE
3FB0 DF       RST 18
3FB1 El       POP HL
3FB2 E5       PUSH HL
3FB3 06 08    LD B,08
3FB5 0E 05    LD C,05
3FB7 16 01    LD D,01
3FB9 7E       LD A,(HL)
3FBA BB       CP E
3FBB 28 0B    JR Z,3FC8
3FBD CB 22    SLA D
3FBF 00       DEC C
3FC0 23       INC HL
3FC1 20 F6    JR NZ,3FB9
3FC3 10 F0    DJNZ 3FB5
3FC5 El       POP HL
3FC6 E7 00    RST 20,00
3FC8 3E 08    LD A,08
3FCA 90       SUB B
3FCB El       POP HL
3FCC 01 28 00 LD BC,0028
3FCF 09       ADD HL,BC
3FD0 85       ADD L
3FD1 6F       LD L,A
3FD2 46       LD B,(HL)
3FD3 0E FE    LD C,FE
3FD5 ED 78    IN A,(C)
3FD7 2F       CPL
3FD8 A2       AND D
3FD9 11 00 00 LD DE,0000
3FDC 28 01    JR Z,3FDF
3FDE 13       INC DE
3FDF D7       RST 10
3FE0 FD E5    JP (IY)



ETI Magazine November 1983 page 24
the MULTIPRESS and return to decimal. The word TEST places MULTIPRESS inside a BEGIN UNTIL loop and slows it down to allow time for a screen display. MULTIPRESS would normally be inside your program loop.


  All Keys Multiple Key
  Read Routine

  Gary Knight has kindly consented to the publication of his own forty key machine code routine.   To use the multiple key read routine you need to place on the stack the ASCII code of the lowercase letter or the number which appears on that key. So, to execute the word LEFT if the 'I' key is being pressed you would use:

ASCII I READ KEY IF LEFT THEN You can test for the ENTER, SPACE, CAPS SHIFT and SYMBOL SHIFT keys by placing on the stack decimal 13, decimal 32, ASCII C or ASCII S (note the last two are in upper-case). See the 'How It Works section for this routine.
  Type in everything in the listing (Fig. 6a) exactly as it stands. There are two tables of numbers (after READ IN and after MC KEY). Type


Fig. 7a. Standard Ace tape input port circuit; b. alternative tape port using spare gate on interface.


each hex number and press ENTER after each.

  Tape Port and Keybeep    The standard Ace tape port input circuit is shown in Fig. 7a. R1 biases the gate input to about 2V, and R2 acts as a tape recorder output load resistor. If the gate is omitted, it is possible to feed straight into the
interface connection from the circuit of Fig. 7a, but gate buffering is desirable.
   A suggested circuit for an alternative tape port is given in Fig. 7b. The spare three input NOR in IC1 is pressed into service (the inverted signal works) and C1 is increased in value to improve sensitivity. A higher value for R2 makes it possible to feed from DIN plugs on some tape recorders. With DC access to the tape port, you can experiment with input filtering, etc.


BUYLINES

The following are available from I.T.M. KJ Interface PCBs £4.45 per set. KJ Interface Kits with PCBs £11.50 each (including full documentation). Assembled and tested KJ Interfaces (un- cased) with applications documentation £14.50 each.
All prices inclusive of VAT and postage. SAE for further details of KJ interfaces, patch boards etc. I.T.M. 119a Culverley Road, Catford, London SE6. (01-698 5351). Long wire ZX81 or Spectrum edge connectors are available from Technomatic (see text). PCB mounting screw terminals (0.2" pitch) and keyboard switches from Maplin or Ambit International (see text). Other components are not difficult to obtain.