Quantcast
Channel: JeeLabs
Viewing all articles
Browse latest Browse all 265

TFoC - PDP-8 in 256 lines of C

$
0
0

Always in search of the essential “fabric” of computing, I decided to create yet another PDP-8 emulator. In plain C, and in as few lines of code as possible - without resorting to obfuscated C. It ended up being 256 LOC.

The PDP-8 was kicked into the world in 1965. It’s an atractive target, because its instruction set is minimal, with quite a number of applications available for it.

My goal was to implement enough of the core to support FOCAL-69, a BASIC-like programming language from DEC, which supports interactive editing and floating-point, all in 4K 12-bits words of memory.

A “semi-real” PDP-8 was built in an earlier post. Here’s the new all-software “model”:

$ ./p8 focal.bin
LOAD 0000-7577 CHECK 1153

CONGRATULATIONS!!
YOU HAVE SUCCESSFULLY LOADED 'FOCAL,1969' ON A PDP-8 COMPUTER.

SHALL I RETAIN LOG, EXP, ATN ?:YES

PROCEED.

*T 12.3*45.6,!
=  560.8800
*
QUIT PC 2627
0000: 2667 5403 5403 2603 0004 0013 0100 6400
0010: 3140 0046 1402 3220 7475 6277 0000 3150
0020: 7777 1577 2407 3642 0000 3632 0000 3140
0030: 2030 3217 0003 7774 0000 4617 0000 0000
0040: 7775 0000 0000 0000 0000 7661 0000 0000
0050: 1315 6603 2004 6724 0014 0000 0000 0000
0060: 3217 1500 0000 2676 2666 0001 0215 0231
0070: 0005 0273 0214 0207 0203 0337 0212 0215
0100: 0001 7700 0256 7701 7600 7760 0177 0017
0110: 0277 7776 7477 0260 7540 7522 7563 7775
0120: 7773 7767 0077 0200 4000 2030 2155 5715
0130: 6000 6200 3140 3206 3140 3217 2017 2407
0140: 0521 1565 0477 0534 0554 2274 2502 1314
0150: 0721 2465 2155 2425 0302 2242 2360 0413
0160: 1517 1533 2035 0744 0700 2062 2726 0000
0170: 0000 0000 0000 0000 0000 0000 2741 7610
$

Note that the emulator dumps its “page zero” on exit, all in very 1960’ish octal.

The emulator source code is on GitHub. Some 25% of it deals with loading “paper tape” (i.e. from file) and handling polled keyboard input, so the PDP-8 emulation itself requires less than 200 lines of C code. It’s about as simple as it gets for a usable (and commercially successful) system.

There are many PDP-8 emulators out there. For Mac OSX, there’s a really amazing one by Bernhard Bähr. It emulates not just the CPU, but also paper tape, DECtape, disk drives, and a gorgeous live front panel:

On a modern machine, it will run orders of magnitude faster than a real PDP-8/e …


Viewing all articles
Browse latest Browse all 265

Trending Articles