Replacing an Apple 2e Clone's keyboard controller with an Arduino

2017-10-19

This is about my vintage Apple 2e clone. It's a bit of a turd but I love it. I picked it up in a junk store in the mid 90s for something like $20.

When you boot it up, instead of saying APPLE ][, it says, simply, COMPUTER.

Upon firing it up for the first time in 20 years I discovered the keyboard was not working, and quickly deduced the keyboard decoder chip was burned out. This is an article about how I reverse engineered the keyboard decoder circuit enough to replace it with an Arduino. I would have just replaced the actual chip but it is ridiculously obscure and there was not one shred of information on it on the internet on it, arguably till now!

The old, dead chip was labelled C35224E, and had 40 pins.

The keyboard decoder chip scans an 8 by 10 matrix keyboard, and serially outputs the keypresses as ASCII. This is different to a genuine apple where the decoder chip outputs the keypresses as parallel data. This is a good time to have a quick look at Mike Willegal's write ups about Apple keyboards. http://www.willegal.net/appleii/early-a2-keyboards.htm. Short version is that genuine Apple 2 keyboards have the decoder chip as part of the keyboard assembly, while this had it on the main board.

Arduino as replacement


The replacement Arduino scans the keyboard matrix (using a 74hc595, so we only need 3 ouput pins) and sends the decoded keypresses, serially in ASCII, back to the Apple clone via a single output pin (37). There is also an output clock/shift pin (36) and 3rd output pin that acts as like a "key press available" or "latch enable" or something (35).

I built this up permanantly as a daughterboard that plugs into the old keyboard decoder chip socket.

As a bonus feature, the Arduino can not only decode the keyboard but also you can upload text directly into the Apple as if you typed it in. This is achieved through serial communication from your PC to the Arduino: the Arduino is listening for serial data and any that it receives it converts into keypresses and pipes it into the Apple. This means that you can cut and paste basic programs directly off the internet and upload them into the apple as if you typed it in on the actual keyboard!




Addendum: CAPS lock, pin 6 in the keyboard decoder chip socket, is wired to A6 on the arduino.

On the RE process

I've never really done this before but the short version was this

  1. physically look at the PCB and see where traces went to draw a circuit
  2. as above but with continuity tester
  3. using CRO determine that the old decoder chip looked to be scanning ok (noting pulses out) but not decoding and sending decoded signals
  4. deduce approximate directions of signals: ie scan out, scan result in, and encoded keyboard data fed into data bus

After having a rough idea about most of the 40 pins function, I found 4 pins that looked to be data out from keyboard decoder chip to the rest of the computer. So I rigged up an Arduino and started sending signals on these 4 inputs to try and see what letters came up on screen. 4 bits is not enough to provide parallel data for 60 odd keys but that didn't stop me barking up the parallel tree and writing bit numbers 0-15 on the 4 pins, to no effect.

What was interesting however was when I turned the Arduino off but leaving it connected to the apple keyboard socket: streams of junk appeared on screen as if the keyboard was being mashed. It soon dawned on me that it was probably some sort of serial communication. I guessed that one line was data and another was a clock. So I carefully traced the PCB and sure enough they went, via 2 sets of inverters, to a shift register. There was a 3rd line I started tracing, but it was more difficult, and I sorta gave up, because I already had a strong scent. The 4th line, interestingly, went nowhere.

So I started sending bits to the 2 lines that operated connected to the shift register. I took a wild guess and pulsed the 3rd line after the 8 bits were sent - and lo and behold a letter appeared on screen. So 1st line was data, 2nd was clock and 3rd was latch enable, or data ready, whatever.

Didn't take long, through experimentation, to figure out the order of bits to send, and that I simply had to send ASCII codes as letters! The rest was elementary.

More on the rest of the clone

CPU is a 65c02 (currently running a plain old 6502). There are 2 EPROMS. I manged to dump both: first, a 27c128, who's image seems sensible. .. and there is another, a 27c32 (24 pins) but the image does not make sense: there are no strings in it, no obvious 6502 code and the bytes are very repetitive. I wonder what it is? (edit: it's a character rom.) It sits in an 28pin socket awith 2764 written next to it. So for fun I burned the 2732 image onto a 27c64 and plugged it in, and the computer works, not that I tested it extensively.

There are four 41464 ram chips - 64Kx4 each - giving this a total of 128KB ram. I think only the first 64k works because I've had to switch the ram ICs around to get the thing to boot. Upon further testing I think one of the 4 ram chips is burned out, but it is sitting in the upper 128k doing nothing anyway.

The other chips of note are:

  1. STK 65301
  2. STK 65371

which according to this forum post

http://www.vcfed.org/forum/showthread.php?56444-Apple-IIe-clone-ASIC-STK-chips-help-required

are found in a lot of Apple 2 clones, but who the hell knows what they do! IOU / MMU functional equivalents? Anyway if they burn out this thing might as well be scrap. Reverse engineering a keyboard decoder is one thing but I can't imagine RE those.

On the PSU, it was such a piece of junk that I spent hours figuring out why it was putting out 25/12/-12/-25v instead of 12/5/-5/-12v ... turns out it needed a load to get the correct voltages. If you ran it unloaded the output voltage was double and it started smoking. I replaced it with a ATX PSU, but that has it's own weird smell.

Anyway, you can plug in a genuine FDC and load disks. I also have a dual EPSON floppy that works. Here's a screen shot of it playing Ultima 1.

ROM dumps

  1. ROM 1
  2. ROM 2

Arduino sources

  1. Arduino sketch

Back to index