Obsolescence Guaranteed
Recommended: Gigatron
a computer w/o a microprocessor
KIM Uno: a DIY clone of the KIM-1
Technical Details
I got introduced to the Arduino this spring. At our local Swiss vintage computer club, Christoph Haberer introduced his CH2 board, which turns the Arduino into a 4-bit computer (see here for details). I joked about his Arduino board being close to the minimal spec of running a KIM-I emulator.
Then I came across a post from Mike Chambers (link) on the Arduino forum. A 6502 emulator running on the Arduino?! I got the KIM-1 ROM, added some ROM call intercepts to the 6502 emulator and got myself a real KIM.
Some background is given in blog posts here, here and here; this page summarises the end result. All source code as well as the Kicad schematics and Gerbers are available as downloads down below on this page.
KIM Uno over the serial port: using Mode 1
(emulation of the onboard 6 digit LED display)
KIM Uno over the serial port: using Mode 2
(using the KIM-1 ROM's serial teleprinter functions)
Original KIM-1 keyboard/display schematic
(click to enlarge)
KIM Uno - PCB layout (click to enlarge)
KIM Uno Expansion connector (click to enlarge)
1. Software
The KIM-1 basically consists of a 6502, two 6530 RIOTs plus 1K RAM. Each 6530 RIOT contains 1K of ROM, 64 bytes of RAM and I/O & Timer ports. Just like I did with the Microchess project, I'm using Mike Chambers' 6502 emulator. I added the KIM-1 ROM code into the CPU emulator's memory map, added two 64-byte RAM spaces and of course 1K of Arduino RAM is used as main memory. The Arduino's built-in EEPROM is used as the second kilobyte of memory, and a write-protect can be switched on or off.
Having done that, I needed to replicate the functionality of the I/O and timer ports on each of the two 6530s. The current version of Kim Uno is a bit lazy. The 6530 timers respond with TimeOut at any time. And the only IO port that works is SAD, which just responds with 0x01 to indicate the KIM's ROM should use the onboard keys/LEDs, or (after pressing [TAB]) with 0x00 to indicate the user wants to use his serial terminal.
Although the above approach to I/O (non)emulation disqualifies me as a proper emulator programmer, the lazyness has very little impact on functionality. The emulator intercepts calls to the screen and keyboard routines in the KIM ROM, and does its own screen/keyboard I/O in a way invisible to the ROM.
Almost 40 years after the original KIM-I, there must be something improved in the KIM Uno? At boot time, a demo program is loaded into 0x200 for immediate gratification purposes. Also, the NMI and RST vectors at 0x17XX are set during startup. You used to have to do that manually every time to make BRK and SST work.
The famous programming utilities disassembler, relocator, movit and branch are added, either as extra ROMs in the KIM's memory space or as preloaded code in RAM. A floating-point library, fltpt65, is also added as a ROM allowing the KIM to become a 6502 programmable calculator. The emulator supports this with a pop-out-of-KIM-emulation "Calculator Mode" in which the KIM's display is briefly extended with an extra digit and decimal points to view floating point numbers comfortably.
Running the emulator on any Arduino (without the KIM Uno board)
Actually, the software will run on any Arduino. Just compile the source code below. Without a physical keyboard and LED display, it will only let you use it over the serial port of course. You can choose between two 'Modes' though. Mode 1: use a terminal program such as puTTY (9600bps) to look at the six digits like they would be present on the physical hardware, or (Mode 2:) just press [TAB] to switch the KIM-1 to its normal serial mode operation. In Mode 2, the KIM-1 ROM operates a bit differently in terms of keystrokes. See the KIM-1 User Manual section (link) for details.
Note that in mode 1, the KIM-1 ROM thinks you're using its on-board hardware, not the serial port. It's the emulator that reroutes the output. The following keystrokes simulate the buttons on the KIM-1 keyboard:
AD - Ctrl A ST - Ctrl T SST on - ]
DA - Ctrl D RS - Ctrl R SST off- [
PC - Ctrl P GO - Ctrl G
In mode 2, you are using the KIM-1's luxury mode. Back in 1976, it was not likely - but possibly you were rich enough to afford a teletype printer or - ooh - even a serial terminal. Comfortable ASCII keystrokes were then used instead of the on-board dedicated keys. And of course the KIM-1 could then print text to the terminal, instead of just flashing the contents of 3 bytes on its LEDs. Hit [TAB] at any time to go back to Mode 1.
Proper credit where it is due
The bulk of the source code consists of Mike Chambers' 6502 emulator, and of course the original KIM-1 ROM.
2. Hardware
The KIM-1 has an ingenious schematic to scan a keyboard with 24 keys, and drive a 6-digit LED display with mostly the same I/O pins, flipping them from input to output mode. There are three groups of I/O pins:
-
7 'column pins' which sense 7 buttons on the keyboard, and then flip over to drive the 7 LED segments that together form a LED digit.
-
4 'row pins', output pins that provide power to a row of 7 buttons each. The KIM just cycles through each of these rows to scan for a button press (a short between that row line and one of the column pins).
-
6 'led pins' that provide power to one of the six LED digits on the display. They are the anode (+ side) of the seven segment LED's that together form one LED digit.
Flash the 6 digits in sequence fast enough, and the human eye will see all six LED digits light up at the same time. Scan the keyboard in-between lighting up each LED, and the keyboard/screen are live!
The original schematic for doing all this is shown to the right (click to expand). It is beautiful in its simplicity, and with the atMega's extra driving power can be simplified even more (by leaving out buffer ICs and driving transistors) to exactly fit the Arduino's I/O space.
The following Arduino pins are used:
-
D2..D8: Column pins used to sense keyboard and to select the LED segments
A5: An extra column pin not found on the original schematic
Note that there are 8, not 7 columns. The eight column was needed to drive the decimal point on the segment LED blocks - which effectively is the 8th LED on the display. At the same time it was also needed to hook up the special keys ST, RS and SST. On the KIM-1, these may look like keys but they are actually switching signals directly to the CPU (RST, NMI). These 3 keys on the KIM Uno, are all on the Column 8 pin of which the KIM-1 emulator of course knows nothing - and needs to know nothing.
-
D9..11: keyboard rows 0,1 and 2
These are identical to the KIM-1 schematic, and serve all of the normal keys. Actually, the KIM-1 had a fourth keyboard row in the schematic which was only used to sense the serial port on/off jumper. That jumper wire had to be soldered on to choose between on-board and serial terminal I/O. It has been replaced by a toggle switch ([TAB]) handled in software. So row 4 is a virtual IO line in the KIM Uno.
-
D12, D13, A0..3: LED digit select lines for the 6 KIM-1 digits
Optionally, A4: LED digit select line for an additional 7th LED digit used in calculator mode.
Expansion Connector:
Adding I2C to the KIM Uno as an option
The above leaves A4 free unless 7-digit calculator mode is used. And A5 is only used for output to a sense line consisting of a row of keys. Nothing gets hurt if another output purpose is fulfilled by A5 when not scanning that row of keys. This is nice, because A4 is the I2C Data line (input/output) and A5 is the I2C clock line (output only). So the KIM Uno can have an I2C expansion interface adding more fun. The current firmware supports a tiny little OLED display that way.
Using SPI is also a possibility. But it will give some of the I/O pins double duty. I.e., you have to stop scanning the keyboard and driving the LEDs to use the SPI port. And periperals on the SPI port will get (unproblematic, I believe) meaningless signals on their lines if the LED or row pins are used for the display/keyboard.
The figure to the left shows the pinout of the expansion connector. The top 3 rows are a standard 6-pin SPI (pins 1-6), I2C is on pins 19+21. The other pins can be used for extra SPI chip selects or whatever, at times when the KIM Uno keyboard/LED display is not used.
Schematic
The above leads to the following schematic (full version in downloads). Fitting in with the minimalist approach, only 11 resistors and 2 four-digit segment LED blocks are needed.
Arduino Pro Mini: everything on a DIP-24 socket
Choice for the Arduino Pro Mini
Part of the fun in this project was to arrive at minimal building costs. To my astonishment, a complete Arduino Pro Mini costs just $2.59 on eBay... less than a single, separate atMega328P DIP chip. Using the el cheapo Pro Mini also eliminates the need for the crystal and capacitors you'd need to bring on board when using a separate atMega328 DIP IC. Nice!
Even better, the Mini Pro has the footprint of a normal 24-pin chip. By putting it on the bottom side of the PCB, underneath the segment LEDs, a lot of PCB board space can be saved, minimising the size and thus cost of the PCB.
Lastly, one other benefit was that the Pro Mini's programming header can double up as serial interface and power supply connector, elegantly (IMHO) at the top right corner of the PBC. All dealt with in one 24-pin DIP footprint for $2.59... amazing really.
​
2020 update: the current version also supports the STM32 'Blue Pill' and esp32 microcontrollers with more features.
Arduino Pro Mini - Connector Pinout
The six-pin connector on the Pro Mini provides the KIM Uno's serial port and 5V/GND power pins. The easiest cable to use is a TTL-to-USB cable, which provides the serial RX and TX connection to your PC as well as a 5V power source. Here is the one I have (link). Provided you keep to the correct pinout, any 5V power supply or TTL serial can be used of course.
Also, note two alternative power options: the expansion port provides pins where a 5V power supply can be connected. 3 AA batteries providing 4.5V are fine too. And on the Pro Mini, the 'RAW' pin accepts any DC power supply between 6.5 and 12V. However, you'd have to solder a wire to the RAW pin yourself.
Downloads
Current version of files can be downloaded here. Note: download links are to Google Drive, meaning you have to select Download to get the ZIP file.
Latest changes:
17 Aug 2020: Big firmware update adding Apple-1 compatibility, using EEPROM as cassette tape storage.
The firmware now also runs on the STM32 and esp32 microcontrollers. And runs on the TTGO 2020 wristwatch...