A IBM PC to C-64 Keyboard Converter By Joel Kolstad April, 1991 After years of use of my Commodore 64, its keyboard started to become unresponsive and not at all very useable. I tried all the usual remedies -- cleaning the key pads, buffing the contacts, etc., but found that sooner or later the keyboard would start exhibiting the same problems once again. I got so fed up with not having a decent keyboard, I finally decided to take a drastic step -- interface an IBM PC keyboard to the C-64. Note that when I say "IBM PC keyboard," I _mean_ IBM PC or IBM XT keyboard. NOT IBM AT or PS/2 keyboard. The IBM AT and PS/2 keyboards use somewhat different methods of sending keycodes than the PC/XT keyboards, and will not work with my converter. Although you probably won't harm anything in trying, you certainly won't accomplish anything useful either. Note also that there are some so-called "universal" keyboards out there that are supposed to adapt themselves to the computer in use. I know little about these, and haven't tried any of them, so I cannot say if they work or not. I would presume they would, though. Luckily for most of us, PC/XT keyboards are the kind most commonly found at surplus stores and swap meets. They also tend to be quite inexpensive -- $20-$40 is not at all uncommon. PC/XT keyboards are so cheap because they're quite dumb; all they know how to do is send key scan codes. This is fine for my application. The converter I built is based on an Intel 8748 microcontroller, and a Dallas Semiconductors DS1277 8x8 crosspoint switch. The Intel 8748 microcontroller is a now-ancient (about 10 years old, I believe) chip containing a CPU, a 1K EPROM, 32 bytes of RAM, a timer/counter, some interrupt sources, and some I/O. An interesting bit of trivia is that many PC/XT keyboards use an 8748 (or close derivitive) microcontroller themselves! This basically leaves us with some mechanical switches talking to an 8748, talking to an 8748, talking to a DS1277 being read by the 6526 in the C-64. The DS1277 is a newly introduced chip that contains an 8x8 bank of analog switches -- a "crosspoint switch." This 8x8 bank of switches happens to be exactly how the Commodore 64 keyboard is laid out, and therefore proved quite useful in designing this circuit. The DS1277 replaces at least 8 conventional TTL chips. It utilizes a simple serial interface, and even contains provision for battery backup of the switch setting (not used here, for obvious reasons :-) ). In making the 8748 software, I attempted to create a program that allowed as complete of a keyboard emulation as possible, without setting me back a few years on my college education (ok, just kidding... it really only took a week to write and another or so to get working...). The emulation is very good -- caps lock and num lock modes are supported, cursor keys do what they do, and hitting shifted keys enters what's labeled on the PC keyboard (as opposed to the C-64 keyboard!). Here's how it works... Normally you type away... To enter caps lock mode, hit caps lock. YOU CANNOT BE PRESSING A-Z WHILE HITTING CAPS LOCK (Why would you?), OR IT WILL BE IGNORED. Unless the caps lock is ignored, a caps lock indicator lights on the PC keyboard is indicative of the caps lock mode. If the caps lock is ignored, you'll have to hit caps lock twice to engage it -- once to turn off the caps lock indicator light, and again to turn it back on. Num lock is quite similar to caps lock. You cannot be pressing 0-9 or @. while entering the num lock mode, or it will be ignored in the same vein as caps lock. When not in caps lock mode, cursor keys automatically have shifts added when needed -- that is, if you hit the left arrow key, the C-64 will actually "see" the right arrow key and a shift. To enter shifted symbols (the ones above 0-9, the brackets, etc.), you hit Shift and the key with the symbol on it. Duh. But seriously, what's important here is that you hit Shift first, like your high school typing teaher taught you. For instance, hitting Shift-2 will let the C-64 keyboard "see" an @ sign (an unshifted key of C-64 keyboards). However, if you hit 2 and _then_ shift, C-64 will "see" a shifted 2 on the C-64 keyboard... which it may decide is a double quote. Likewise, you should release the character key before the shift key, or you may run into the small problem as above. So just remember: Shift-Hit character-Release character-Unshift. But that's how you type anyway, right? Just like Mr. Relph taught you in high school... Trying to decide what to do with "non-standard" characters was a little tricky... since what key creates these characters is completely up to the programmer. However, I've tried to be as consistent as possible with as many programs as I have that use these characters, and this is what I came up with: ` --> ' ~ --> pi (Sh. up arrow) _ --> Shift @ \ --> British pound key | --> Shift Brit. Lb. { --> Shift + } --> Shift - Tab, Pg Up and Pg Down don't do a darn thing, at the moment. Back space and delete are synonymous. Insert is still shifted delete... F1-F8 are still F1-F8. Even numbers add a shift. F9 and F10 are _both_ defined as STOP. Alt is defined as the Commodore (C=) key. Scroll Lock is now Restore. Really. So now you hit F10-Scroll Lock. :-) Apologies to those who might be annoyed by scroll light indicator lights -- they latch, Restore doesn't. But I couldn't find any other good keys... Finally, as a token of appreciation to the MS-DOS world that gives us these keyboards to begin with, Ctrl-Alt-Delete will reset the microcontroller and keyboard. But no, it won't help a runaway C-64 program. :-) By now you might be wondering how to build the thing. If you asked for them, you got a schematic of the circuit and the machine language program that runs the 8748. You can build the circuit just about anyway you want -- nothing is really critical. Keep the .1uf close to the power leads, though. You might have a hard time getting the 8748 programmed -- many places have standard EPROM programmers, but nowhere near as many have 8748 programmers. Actually, since the circuit doesn't use the BUS lines of the 8748, you could use an 8048 (EPROMless 8748) and an EPROM to run the code. This arrangement also requires an address latch to work. It does save all of about $2 on parts cost, but personally I don't think it's worth it given the considerable extra wiring to two more chips. And besides, a two chip circuit that does something vaguely useful is kind of slick. However, if you really want to take this route, I refer you to the Intel "Embedded Controller Systems Handbook." Intel can be reached at 1-800-548-4725. If you want to get an 8748 programmed and can't do it locally, I can do it for you for a nominal fee. In fact, I keep all the parts for something this simple around most of the time, and can sell them to you if need be. This whole project is supposed to be more or less in the "public domain," though, so I'd feel a little guilty if I didn't tell you where to get the parts yourself: --> 8748: Many places. I like JDR Microdevices ($7.95). 1-800-538-5000 (ask for a catalog). Digikey (1-800-DIGI-KEY) and JameCo (1-415-592-8097) have them too. --> DS1277: Dallas Semiconductors. Calling Dallas directly at 1-800-336-6933 is the easiest way to get one, and they're perfectly happy shipping you one for $4.85 plus postage. Otherwise, _well stocked_ Dallas distributors should have them. --> 11MHz crystal: Digikey has these. A buck or so. --> Connectors: If you want to get a female 20 pin connector that plugs into a circuit board, you might have a hard time finding out. Allied (1-800-433-5700) and Newark (various phone numbers nation wide) sell them, but they unfortunately have $25 and $50 minimum orders, respectively. Otherwise, Digikey sells lots of Waldhom "header connectors" -- I used a pair of 10 pin female-female connectors going to (2) 10 pin male headers on the circuit board. Also, a simple "pass through" for all 20 pins will let you use an IBM PC keyboard and the Commodore keyboard together. This means that you can still use your original C-64 keyboard just like you could before (the C-64 will see the union of true C-64 keys and IBM PC keys, in this case). If you ever take your C-64 somewhere without a PC keyboard, you won't notice a thing. --> Miscellaneous capacitors, etc: Mouser (1-800-34-MOUSER) or Digikey. Well, that should be everything you'll ever need to know about the IBM PC/XT to C-64 keyboard converter. Should you have any questions, comments, etc., you can e-mail me at: kolstad@jomby.cs.wisc.edu, or kolstad@cae.wisc.edu. Unless you have a close to death C-64 keyboard like I did, this hack is more of a gimmick than anything else. :-) However, it works well, and I think it's better than the original keyboard itself. ---Joel Kolstad NOTE #1: As of April 17th, 1991, my prototype is using an 8749 instead of an 8748. An 8749 is an 8748 with a 2K EPROM and 64 bytes of RAM. Unless there's a bug somewhere in the program, this makes _no difference whatsoever_ -- the two devices are completely code compatible, of course. However, I cannot promise an 8748 will work until I get some to try. I do have some on order -- they should be here within a week. If I do find any problems, I'll send out a new version of the software. NOTE #2: For awhile, I had turned the Dallas part number 1277 into 1127. Oops. I believe I've gotten rid of all of those references, but if you do see anything referring to a "DS1127", IGNORE IT. The right part number is DS1277. Sorry about that. @EOF set `sum $sumopt c64.kybd.info2 <<'@EOF' @From kolstad%jomby.cs.wisc.edu@cs.wisc.edu Sat Apr 20 08:07 MDT 1991 Received: from hpgrla.gr.hp.com by hpgrea.gr.hp.com with SMTP (15.11/15.5+IOS 3.20) id AA02004; Sat, 20 Apr 91 08:07:54 mdt Return-Path: Received: from relay.hp.com by hpgrla.gr.hp.com with SMTP (15.11/15.5+IOS 3.20+OM) id AA14267; Sat, 20 Apr 91 08:13:34 mdt Received: from jomby.cs.wisc.edu by relay.hp.com with SMTP (16.5/15.5+IOS 3.13) id AA05304; Sat, 20 Apr 91 07:12:16 -0700 Date: Sat, 20 Apr 91 09:10:59 -0500 @From: kolstad%jomby.cs.wisc.edu@cs.wisc.edu (Joel Kolstad) Message-Id: <9104201410.AA14521@jomby.cs.wisc.edu> Received: by jomby.cs.wisc.edu; Sat, 20 Apr 91 09:10:59 -0500 To: markp@hpgrla.gr.hp.com This file contains the 8748 machine code for the IBM PC to C-64 keyboard interface. It is uuencoded. If you're on a U*IX box and don't know about UUencoded files, just save this file as "foo3" and enter the command "uudecode foo3" You'll be left with a file called "keyfer.bin" -- the machine code program. As you can see from the bottom quarter or so of this file, not all of the 8748's EPROM is used. Of the 1024 bytes of EPROM availiable, a little over 3/4 is used. If anybody has suggestions for what to do with the rest of the ROM, I'd be glad to hear them. Keep in mind that I only have a byte or two left of RAM, though, and that an 8748 is a far cry from a 68000. :-) -->IMPORTANT NOTE: As pointed out in the main documentation, my own prototype actually uses an 8749, since the 8748s are still "in the mail." Unless there's some devious bug in my program, though, this should make no difference whatsoever. But if there is... :-) You've been warned. I will be verifying 8748 operation as soon as one arrives, and at that time will remove this silly notice. ---Joel Kolstad kolstad@jomby.cs.wisc.edu or kolstad@cae.wisc.edu @EOF set `sum $sumopt c64.kybd.info3 <<'@EOF' @From kolstad@jomby.cs.wisc.edu Fri Apr 26 18:11:54 1991 Relay-Version: version Notes 2.8.4 1990/05/09; site hpgrla.gr.hp.com @From: kolstad@jomby.cs.wisc.edu (Joel Kolstad) Date: Sat, 27 Apr 1991 00:11:54 GMT Date-Received: Wed, 1 May 1991 22:53:38 GMT Subject: IBM PC/XT to C-64 keyboard converter update Message-ID: <1991Apr27.001154.10657@spool.cs.wisc.edu> Organization: U of Wisconsin CS Dept Path: hpgrla!hpfcso!hplabs!hp-pcd!sdd.hp.com!caen!uwm.edu!uwvax!jomby.cs.wisc.edu!kolstad Newsgroups: comp.sys.cbm Sender: news@spool.cs.wisc.edu (The News) Lines: 32 Originator: kolstad@jomby.cs.wisc.edu After the initial release of my plans for an IBM PC/XT to C-64 keyboard converter a few weeks ago, I've been sending out schematics and instructions as the requests come in. The requests have just about died off, and now that I have a little feedback from potential users, I'm posting this little addendum. First: The instuction text fails to mention that ESC is mapped to the back arrow key. Second: MANY OF THE NUMEROUS VARIETIES OF 8748/9s REQUIRE PIN 26 TIED TO Vcc (pin 40). In fact, everybody ought to make this change to their schematic. If you happen to have one of the 8748/9s that needs this pin tied high and you haven't done so, your 8748/9 will sit there like a dead duck. :-) Third: Seems that the original code was bug free. Haha. 8748s work fine. (I finally got some to try the code out on). Fourth: At a user's request, I mapped TAB into Ctrl-I. This ought to be helpful for terminal programs. If you'd like the updated program, send me mail. Fifth: Several people have asked about kits for the thing. At this time, I can make everything except a printed circuit board availiable. I don't yet have enough interested people to make making circuit boards worthwhile. If you're interested, send me mail. That's about it. I hope you're all enjoying the circuit. :-) ---Joel Kolstad kolstad@jomby.cs.wisc.edu @EOF set `sum $sumopt keyfer.bin.uue <<'@EOF' begin 777 keyfer.bin M)%< !+X 2V_P$ D6!C4)*3E)66EYAP_P9A9E%6048Q-B&;G'$"8F5254)% M,C4BF9J09Q!D5U1'1#P<'_/V'B(DCA(6&((&" M@X"*,P #8&-04T!#,"1X_W?_>O]R$W___NRJ M_X/5N""P #7%D]6ON"#PEM(FS; ((_AB)8;-_\63!Z C^&*7)MNGN2'Q9Z&J M\);--;DC^J')L?\$S;H(JU,!0P(Y0P0Y4P,Y^W?J\(,C CDCN13N(P 4[B/P M%.Z\"+@D\!3N&.P4(P Y@ZP4HJO\1U,' R2H@S0>\-N@@S0>\%N#N#GZ4PB6 M/1CZ!**L%**N_'=W=U,/ RRH\(.X+B.5O 0$J",".K@8N2BP !CI7B,#.B, M.39I504T ;@BN2/PQG.P /%3?P.L]G/Q%**J\5. QHGZJ_$T15K;EF_PVJ"X M/?#&I;@LO0OPEF\8[9TD5_$#K9:^(QTT0%[&OB,X-$!>QKZX/;#_)&_Q%)RM M%\9O W_FRT0ON#?P4P*6U$0;\5,_ _#FT@/VYN%$!_NJQNZ7;@W\%,!ECZZ:/U3?VH4H*U$&P/[ MYNH#\_:L PVJ^Y:-(RHT0%[&;"-G-"HT-:D8&-"@R,CY1(,C-C1 7L9Y(Q0T M*D2!(X!J%*"M1!LT-="@(W-J%*"M1!LT-:E0QGGXK0,"J/E0QJ/PV: C9T2E M(Q0T*OVH^42# Z&6UON6ZKDWN#0CF;P#%*C&Q?'3!*$D;_%3!,;0\5/[H21O M\=,!H21O _[&W$3]^Y;JN3keyferhpgl.uue <<'@EOF' begin 777 KeyferHPGL.Z M'YV-&UPDP1%CQXX8-W0$='(PAPX%2:# 8#$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