ndmckinney|net

In the Army now

Pocket PDP-8

without comments

A few months back, I purchased an Arduino Duemilanove prototyping board. The platform is fun, simple, and very flexible. After spending some time with the gizmo, I started to wonder just how powerful is the ATmega168 controller that drives my little Arduino. I needed a challenge. One of my secret joys in life is old computers. Call me crazy, but there is nothing more satisfying than exploring the simplicity of an piece of hardware. One day, while performing research for a book I’m writing, I realized that the amount of processing power contained in my micro-controller is greater than many popular old computers. Being a sucker for DEC hardware, I new I had found my goal: to create an Arduino-based device that runs PDP-8 code. To be clear, I’m not an expert on embedded programming. I’ve got some coding experience, having been a CS major and all, but I never was very good at low-level programming. The Arduino certainly poses a number of challenges for someone with my background experience, especially in light of the limited capacities of the ATmega168. My experiences have all revolved around object-oriented programming, mainly in Java and Objective-C, on platforms that are infinitely more powerful that the ’168. That, combined with C programming skills that were at least a decade old, and I had my work cut out for me.

Background on the PDP-8

The PDP-8 was created by the Digital Electronic Corporation (DEC) and first sold in 1965. It is regarded as the first widely-sold general purpose computer, due in large part to the machine’s low purchase price and customizability. The basic PDP-8 uses four 12-bit registers and has 4,096 words of memory. Later models had options for additional memory — up to 32K words.

Preliminary Decisions

As I began the project, it became clear to me that the goal of a 100% pure replica was not going to happen. For starters, the number of GPIOs available was vastly insufficient to accommodate the shear number of switches found on the front panel of the PDP-8, plus the lights and dials on the front panel. Because my implementation was software, not hardware, the solution was not simply to solder lights onto CPU leads. I decided that the best way to approach the problem was to put an LCD display on the front, relegate my panel to a few LEDs and switches for easy access and push everything else to a serial console, which I decided to call the Virtual Front Panel (VFP). After all, acronyms are quick common in this era of computing, and I wanted to have one of my own. Another early decision was how elaborate to make the PDP-8. I wanted a system that not only was a proof-of-concept (PDP emulation) but ultimately one that could run OS/8, DECs PDP-8 operating system. Hardware implementation was certainly going to be a challenge. Even the most basic PDP-8 has 4K words, far more space than is available internally on an ATmega 168. After some thought, I realized I had a couple 32Kb EEPROM chips around, and two would suffice in replicating the PDP-8′s memory space.

Writing the Emulator

The overall prospect of writing a CPU emulator that ran on the Arduino was a very daunting challenge for me, but one which I found to be very exciting. Like all great works, the hardest part is starting. I decided to start by writing the basic instructions. Since the PDP-8 only has 8 instructions, writing the code seemed fairly straightforward. Of course, these functions all deal with memory addressing and such, concepts of which I did not have a fresh understanding. After spending several hours studying PDP-8 manuals and playing around on other emulators, I had coded the instructions. The time then came to write some sort of I/O to interact with my Pocket PDP-8. I decided that I would take a stab at writing a basic command interpreter to act as a “virtual front panel.” While not as nostalgic as having a ton of lights, it was functional and quick. If I get so inspired later, I may replace this with a more authentic system. Oh no, my board is resetting after each command? What’s wrong? As it turns out, I think I found one of the first limitations of the Arduino. My initial code structure looked something like this:

...global variables...
void setup() { ... }
void loop() {
    if (halt_flag) run_prompt();
    else run_command();
}

It seems that running the code this way was causing two problems. First, two of my global variables, which represented CPU signals, were not accessible from inside the main emulator. This, of course, is a problem. Second, and more critical, both the emulator and VFP functions were somehow consuming too much memory, causing the Arduino to reset before the end of the loop was reached. After some rearrangement of code, I was back to work. I found a simple “Welcome to PDP-8″ program that prints a simple message then quits. It seems to run a number of extraneous commands, perfect for debugging my emulator. Of course, debugging is the key: I’ve got a number of them to squash as of now, largely related to the I/O functions.

First Run

April 3, 2009. I successfully ran my first program on my PDP-8 emulator: a simple “hello, world” program that prints 40×5 characters. Along the way, I was able to successfully debug:

  • TAD (Two’s complement ADd)
  • SNA & SZA (Skip on Nonzero Accumulator & Skip on Zero Accumulator)
  • SKP (SKiP Always) [still broken, actually]
  • Indirect Addressing

I’ve downloaded a number of papertape files from pdp-8.org, so I’ve got a number of other programs to test. My next goal is to figure out a system for quickly uploading these files to my PDP-8. Copy/paste (at least through OS X’s Terminal.app) glitches too often. Also coming down the pipe: stand-alone hardware implementation. Here’s a hint:

Altoids, the ultimate project box

Altoids, the ultimate project box. Photo Credit: Tojosan (via Flickr)

Share and Enjoy:
  • Print
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Twitter
  • Yahoo! Bookmarks
  • Identi.ca
  • Netvibes
  • Slashdot
  • StumbleUpon
  • MySpace
  • NewsVine
  • Reddit

Written by Nick

April 3rd, 2009 at 11:02 pm

Posted in

Tagged with