CPCKey Release 1.0:

README    Version 1.0
Schematic Version 1.0
PCB       Version 1.2
Firmware  Version 1.0

Copyright (C) 1998 by Soeren Gust, sgust@ithh.informationstheater.de

With CPCKey it is possible to connect a MF-2 keyboard to a computer of the
Amstrad CPC series. It contains a small Z80 system to translate the MF-2
keyboard codes to the CPC keyboard matrix. Its main purpose is to solve the
keyboard problem if you want to put your CPC into a bigger case.

WARNING: This is not a project for beginners. You need to make your own
double-sided pcb, you need an EPROM-burner to build it and you have to
de-solder the original keyboard connector in the CPC.

******************************************************************
* This text is distributed in the hope that it will be useful,   *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  *
* GNU General Public License for more details.                   *
******************************************************************

This text is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

How does it work:
-----------------
The core of the CPCKey is a Z80 with 2K RAM and 8K EPROM. EPROM is at
$0000-$7fff, RAM at $8000-$ffff. Both are mirrored several times. IC9-IC18
(all HCT574) simulate the CPC keyboard. When scanning the keyboard the CPC
sets one row to 0 via PORT C bit 0-3 of the builtin 8255. There is a
LS145 connected to PORT C generating the 10 row signals for the keyboard
at CP102. Because of the LS145 only one row is 0 every time. If there is a
key pressed on the original keyboard in the active row this 0 is connected
to one bit of the sound chip where it is read by the CPC at CP101. Instead
of the keyboard the CPCKey uses the 10 HCT574 8 bit buffers with output
enable.  The rows are connected to the output enables and the outputs are
connected to the sound chip, so the CPC sees the contents of all the HCT574
one after the other when scanning the keyboard. The contents of the HCT574
are controlled by the Z80 by writing to I/O ports 0-9. The ports are decoded
by IC2, HCT154 and are mirrored several times. Since the joysticks are part
of the keyboard the original joystick connectors can't be used any more,
they would produce short circuits. The first joystick is simple, it is
connected to IC9 bit 2-7, everytime the value for IC9 is written the
joystick state is latched.  The second joystick is originally connected
parallel to the keyboard, this can't be done without extra logic any more,
so it is connected to bit 1-6 at IC7 (HCT541) forming an input port to the
Z80. This port is mirrored into the whole address space. It is the job of
the firmware to read this port, mix it with the matching keys and write it
to the matching buffer. The firmware has to rewrite the contents of IC9
too, because thats the only way to feed data from the first joystick to the
CPC. Bit 0 and 7 on IC7 are used to read data from the MF2 keyboard. The
firmware understands 11 bit AT scan codes in code-set 2. Since it can't
send any commands to the keyboard only keyboards which default to this can
be used. I have tried several keyboards, the only one which did not work
was built in 1987, had problems with any PC newer than my 386sx and uses a
strange keyboard layout. (AT layout, but with extra cursor keys, ESC and
several lock keys still on the numeric keypad) On Win95 keyboards the extra
keys are mapped to COPY.

Tips to build it:
-----------------
Although it is possible to wire-wrap the circuit I suggest you build your
own pcb using my layout. I have included files in eps and png (at 300dpi)
format. If you need another format contact me.

Use sockets which you can solder on both sides so you don't need to plate
through the holes. Some of the capacitors and resistors have to be soldered
on the component side, too.  There are 19 single vias, don't forget them.

Burn the atkey.obj file into the 27(C)64 EPROM. I have used asl under linux
to assemble it. Other assemblers may need some minor changes, especially
CPC ones. (untested)

If you can't get the SIP6+1 resistor network simply use an SIP8+1 and
ignore 2 pins.

To connect the joysticks you can use press on connectors, the pins will be
connected correctly. You can even buy the connections ready made, they are
used for serial ports in PCs, but be careful, don't get the version which
connects pins with the same number, they are wrong, use the ones which
connect the matching pin positions.

To connect the circuit to the CPC you have to de-solder the foil-connectors
inside the CPC. I have soldered 2 10 pin IC socket strips into my CPC. This
description is for a German CPC 6128, please check yourself if this matches
your CPC. On one of the keyboard connectors only the 8 middle pins are
used.  To connect to the CPCKey I use 2 flat cables with a double pin strip
on each end. If you look at the CPCKey with the Z80 at the bottom connect
the left connector (8 middle pins) to the right connector on the CPC
(CP101).  Connect the right connector (all 10 pins) to the left connector
on the CPC (CP102). Pin 1 is on the top of all connectors. Keep the
connection as short as possible.

To connect the keyboard use the 4 pins on the bottom left. On the normal 5
pin DIN plug VCC is pin 5, GND is pin 4, CLK is pin 1 and DATA is pin 2.
The RESET connector can be used to connect an extra reset switch to the
CPCKey to be able to reset it if it crashed. This should not happen in
normal cases, it is useful if you want to extend the firmware.
The CPCKey needs a 5V power supply. I used the CPCKey to put my CPC into a
PC case so I could use the PC supply for the CPC and for CPCKey. The
original supply build into the monitor may not be strong enough for the
CPC and CPCKey and the keyboard.

Hints:
------
Some power supplies need a longer time to stabilise the power, so the power
on reset circuit on the CPCKey generates a too short reset. In that case
the CPCKey works if you reset it again by hand. To avoid this increase the
value of C2.  Although both joysticks have a real GND it is still not
possible to connect auto fire joysticks, those get their power from the line
used as fire 2 by the CPC.

If the cables from the CPCKey to the CPC are too long and you can't make
them any shorter try soldering a 1K*8 pull up resistor array to the input
lines on the CPC sound chip, on my CPC there was already a position for it.

Porting to other systems:
-------------------------
The CPCKey can be used for all systems which activate only 1 row at once
when scanning the keyboard. The only systems I know of which do this are
the CPCs, but there must be others. The VIC-20, C64, C16, C116 and plus/4
from Commodore are incompatible with CPCKey, they activate all rows at once
to see if there is any key pressed.

Future development:
-------------------
Implement keyboard macros.

Component list:
---------------

IC1       Z80A processor
IC2       74HCT154 4-to-16 decoder
IC3       6116 2K RAM
IC4       27(C)64 8K EPROM
IC5       74LS14 6 inverting schmitt-triggers
IC6       74HCT32 4 or gates
IC7       74HCT541 8 bit bus driver
IC8       74HCT541 8 bit bus driver
IC9-IC18  74HCT574 8 bit buffer
OSC       4 MHz oscillator
C1        47uF/16V capacitor
C2        10uF/16V capacitor
CB1-CB12  100nf capacitor
R1-R4     1K resistor
RN1-RN2   resistor network 1K*8 SIP 8+1
RN3       resistor network 1K*6 SIP 6+1
JOY1·JOY2 2*5 pin connector
RESET     2 pin connector
CPCKEY    2*10 pin connector
VCC       1 pin connector
GND       1 pin connector
VCCKEY    1 pin connector
GNDKEY    1 pin connector
CLK       1 pin connector
DATA      1 pin connector
misc      connectors on the CPC side