[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PC to Apple 2 Keyboard Conversion



In article <Pine.LNX.4.10.10103161920110.28110-100000@Gloria.CAM.ORG>,
Michael Black  <blackm00@Gloria.CAM.ORG> wrote:
 
> On Fri, 16 Mar 2001, Rubywand wrote:
> 
>> Edward Ho writes ...
>> 
>>> I have several Apple II Plus system board still functioning, but do not have
>>> any working keyboard to go with them. Is it possible to convert a PC
>>> keyboard to work with an Apple II? If yes, please describe in detail.
 
................
 
> This isn't going to be a simple project.  The Apple keyboard just outputs
> ASCII characters in parallel format.  An IBM-compatible keyboard is not
> only serial, and if I remember isn't exactly the same format usually
> seen when sending serial, but it is not ASCII.  Press a key on an IBM
> keyboard, and you will get a serial code that denotes that key, and I
> think a different code is sent when you let go of the key.
 
True -- these codes are known as "scan codes" and the scan codes only
tells you the physical location of the key.  Note that ALL keys emit
these scan codes, including the shift, ctrl and alt keys.
 
The reason scan codes are emitted when the key is released as well as
when it's pressed is that this enables the keyboard driver to sense
the shift/ctrl/alt states, and also enables the keyboard driver to
implement auto-repeat if the key is pressed long enough.
 
Also: there are many different national keyboard layouts in the PC
world, and switching from one to another is implemented in the keyboard
driver and requires no change in the physical keyboard (unless you
also want the national characters to appear on the keys - in that case
some of the keys need to be exchanged).
 
> The conversion
> to ASCII is done in the IBM.  ON the original and XT, there is a TTL
> shift register, I think it was the 74LS595, that converted the serial
> input to parallel, and then code in ROM does the actual converstion to
> ASCII.  On the AT and later, there is a separate microcomputer to do
> the serial to parallel conversion, and some or all of the conversion to
> ASCII.
 
The conversion to ASCII isn't done in the AT keyboard either.  But the
AT keyboard has its own micro-controller (a micro-controller is a
microprocessor with some RAM, some ROM/EEPROM and some I/O on-chip),
and also a slightly different serial format - therefore an AT keyboard
cannot successfully be run on an XT, and vice versa.  The AT keyboard
is in addition able to send a RESET signal to the computer.
 
> If it was just a serial to parallel conversion problem, one would do
> better to use a UART intended for standalone use.  They were common
> in the early days of small computers and you can still buy them;
> the were programmed not by software like the 8251, but by hardwiring
> the pins.  Or you might be able to get by with a simple logic based
> serial to parallel shift register like the 74LS595.
> 
> But it won't be that simple.  You either have to do the conversion
> externally, most likely by using a dedicated microprocessor, or
> fix the ROM inside the Apple II to do the conversion.
 
The latter wouldn't work, for two reasons:
 
1. It would require the Apple II program to do all keyboard input
through some appropriate monitor routine; however many real-world
Apple II programs read the keyboard by accessing the I/O-mapped
addresses $C000 and $C010 directly.
 
2. The table and the code to translate from scan codes to ASCII would
require some space, perhaps a few hundred bytes.  Where would you find
enough free RAM never used by any other Apple software?  Perhaps in
the usually unused bank of the Language Card....
 
3. Different drivers would be needed by different OS'es.  Only Apple
DOS and ProDOS use the monitor routines a lot; other OS'es such as
Apple Pascal and Apple CP/M bypass them.
 
> The former has been done, there is/was such a unit available for the
> Radio Shack CoCo, while the latter is going to require a lot of work
> and fitting into place.
 
The former is probably the best route to go even today.  Yes, it requires
some extra hardware, but microcontrollers are much more capable today.
SInce microcontrollers rarely have parallell I/O, one would have to
do it with serial I/O and add a UART afterwards:
 
                 ___________________       ________
           scan  |                 | ASCII |      |====== Apple II
 PC keybd -------| Microcontroller |-------| UART |====== ASCII
           codes |_________________| codes |______|====== kbd input
                         |    |__________________________ RESET signal
                         |_______________________________ Kbd strobe
 
The microcontroller should read the scan codes from the PC,
translating them to ASCII when appropriate, and also keeping track of
the states of the Shift, Ctrl and Alt keys (the Alt key could be
ignored, or it could be given the functionality of the RESET key,
e.g. pressing Alt-R could be interpreted as equivalent to pressing
RESET - this would require one 1-bit output from the microcontroller
to be reserved for the RESET signal).
 
Optionally the code in the microcontroller could implement auto-repeat,
but this isn't necessary since the original Apple II keyboard didn't
have any auto-repeat function.
 
Perhaps this could be done with the common and cheap PIC microcontroller?
A circuit diagram plus a HEX file with the PIC software could then be
posted on suitable Apple II archives, enabling anyone who wanted to
connect a PC keyboard to the Apple to do so.
                
> There was a time when you would either buy a keyboard that was unencoded,
> and add an encoder, or buy a keyboard with a built in ASCII encoder.
 
I have one of the latter: it looks much like an early PC keyboard,
but it connects to an Apple II, not a PC!  It even have function
keys, where pressing a function key simply sends a short ASCII string
to the Apple - these strings are common Apple II commands (CATALOG,
BRUN, etc).  They are hardcoded and cannot be changed.
 
> Those were once plentiful, new and on the surplus market.  The original
> Apple counted on you being able to buy such a thing.  Nowadays,
> it seems either everyone uses an IBM compatible keyboard, or some
> other similar type that puts out a non-standard code.
> 
> I don't think someone will find much success in rewiring an IBM keyboard,
> because it seems like a lot of them use capacitance switches that require
> proper interface.  If they were actually micro-switch type keys, one
> could cut traces on the board and wire the keys into a matrix that would
> match an ASCII encoder.  This is still doable, if one could find a source
> of unencoded keyboards that actually used old-style switches.  You used
> to be able to buy ASCII encoder ICs, but if those are hard to find,
> one could make such an encoder with common TTL or CMOS logic ICs;  Don
> Lancaster shows some in his "TV Typewriter Cookbook" and his "CMOS
> Cookbook".
> 
> Ironically, the simplest solution is to use another computer.  Youcan find
> all kinds of all in one units, like Commodore 64s and Radio Shack
> Color Computers that have a keyboard and BASIC in ROM.  You'd need
> a parallel output port, ie a parallel printer port, and then just
> write a line of code that takes from the keyboard and outputs the 
> character to the printer port.  Connect that to where the keyboard
> connects on an Apple II, and you've got your ASCII keyboard, albeit
> bulky.
 
Note that "another computer" could also be a microcontroller.  A
microcontroller is nothing but a physically small computer: it has
CPU, ROM/EEPROM, RAM and some I/O on-chip.  Useful devices can be
made with just a microcontroller (properly programmed of course),
a few resistors and a power supply (which could be a battery in
a low-power application).
 
The task of connecting a PC keyboard to an Apple II would be very
suitable for a microcontroller.  Microcontrollers often have serial
I/O on-chip, i.e. they'll be able to directly read the serial stream
form a PC keyboard.  And if you choose a microcontroller with enough
output pins, you could make the microcontroller directly generate
the parallell ASCII data required bu the Apple II keyboard input,
eliminating the need for that UART as well!
 
Where would that microcontroller be placed, physically?  Basically
we have three options:
 
1. A stand-alone unit with connectors to the PC keyboard, the Apple II
keyboard input, and some power supply.  This is the easiest to build,
and should be chosen during the development stage.  Since that "extra
box" would be pretty small, it could be considered the permanent
solution as well.
 
2. Built into the PC keboard -- this would "convert" the PC keoboard
to an Apple II keyboard.  The connector from the keyboard would then
also need to be replaced.  The keyboard as well as the
microcontroller would get its power from the Apple.
 
3. Built onto a prototype card inserted into one of the Apple II
slots - this would give the Apple II a connector to PC keyboards.
That protptype board would also need a wire to a connector to the
Apple II keyboard input.
 
-- 
----------------------------------------------------------------
Paul Schlyter,  Swedish Amateur Astronomer's Society (SAAF)
Grev Turegatan 40,  S-114 38 Stockholm,  SWEDEN
e-mail:  pausch at saaf dot se   or    paul.schlyter at ausys dot se
WWW:     http://hotel04.ausys.se/pausch    http://welcome.to/pausch