Today I jammed some wires into the back end of a 30 year old computer to see if it would blow up. (Spoiler: It didn’t blow up).
The early microcomputers were made for hobbyists more than for casual users. The very first ones came as kits that you had to build yourself, and even after that it was expected that a significant number of users would want to experiment with the hardware itself. It’s part of the hobby that has kind of disappeared over the years. Many of us still build our own computers, but these days that’s more like putting together a piece of IKEA furniture than anything that involves real engineering.
The C64 did not come as a kit, of course, but it did come with a user port – a port (really, just the exposed edge of the circuit board) on the back of the machine that you could plug your own electronics projects into. Unlike the cartridge port, which basically just exposes the entire address and data buses of the 6510 CPU, the user port is tied into one of the C64’s two CIA chips. The user port supports several different kinds of I/O including an rs-232 serial connection that’s used by most C64 modems. It also includes an 8 bit parallel port, which is what I’m going to use in this example.
The first problem was figuring out how to physically attach my project to the user port. I certainly didn’t want to solder anything to the C64 motherboard itself. My soldering skills are decidedly mediocre, and the odds of something going horribly wrong are, frankly, pretty high. Luckily, it turns out that the necessary connector is still available from RETRO Innovations.
Here’s a picture of the connector after I soldered some wires onto the pins that I’m using. I didn’t do a very clean job of it, as the melted insulation attests, but the important thing is that the electrical connections are good enough. The other ends of the wires are plugged into a breadboard.
So what’s the user port equivalent of a “Hello, world!” program? Why, blinking LEDs, of course. I knew that the user port used 5v signals, and some of the articles I’d read showed there was enough current to drive the LEDs directly. The resulting circuit is trivial – I connected an LED to each of the 8 parallel lines. The cathodes of the LEDs are attached to a 470Ω resistor (to limit the current), which then goes to one of the user port’s ground pins.
The software side is similarly straightforward. The chip controlling the parallel port is a 6526 Complex Interface Adapter (CIA). Like the other C64 custom chips, it’s controlled by a series of memory-mapped registers. From BASIC, you can peek and poke various memory locations to control it. For example:
20 POKE 56579, 255 30 FOR I = 0 TO 255 40 POKE 56577, I 50 FOR J = 1 TO 150: NEXT J 60 NEXT I 70 GOTO 30
Line 20 sets up the port by telling the CIA to make all 8 parallel port lines outputs, and line 40 turns the individual lines on and off. The register is 8 bits wide, and each bit is connected to one of the output pins. 255 would turn every line on, 0 would turn them all off, and so on. If we send the numbers 0 through 255 in order, the LEDs will turn on and off showing the binary versions of each value.
A word of warning: I wasn’t entirely kidding about blowing up the computer. If you connect the wrong lines together, for example by making a short circuit or plugging the connector in upside down or something, there is a real chance of damaging the C64. In particular, there’s a 9V AC power supply through pins 10 and 11 that could cause a lot of havoc, so be sure to double-check your wiring before turning on the power.
By the way, there was a series of articles about user port projects in Commodore Magazine, starting in the May 1987 issue. If you know how to get hold of those issues, check them out.