This project was among the more crazy that I have ever done: I created an implementation of the German three rotor enigma machine, complete with plugboard that would run on an Atari 2600.
As I sit down to try to document this project, I find myself in the awkward position of trying to justify a project which to most people on the planet must seem like complete lunacy. Brave people have asked me "what possessed you to try to write a simulator for a sixty year old German WWII code machine on a primitive, thirty year old game machine?" Some just give me a quizzical look, and ask "what is it good for?" Hopefully by reading this page, you'll get answers to both questions.
First of all, what is an Enigma machine? You can get some details from Wikipedia, but simply put, the Enigma is a family of mechanical cipher machines that were used by Germany during the second World War. It was a small, portable machine, looking very much like a typewriter. As the code clerk typed the plain text on the keyboard, the encrypted letters would light up on the display above, or, during decryption, the reverse. Internally, it consists of a number of rotors. On each keystroke, the rotors advance like a cars odometer. The mapping between the key pressed and the lamp lit is a function of the position of each of these rotors, so there are at least 263 individual cipher alphabets defined by each collection of three rotors. This number is expanded considerably by a number of complications: you can pick any three of five fixed rotors, each rotor has a ring setting which changes the position where the "odometer" rolls over, and a "plugboard" further scrambles some letters on input and output.
The breaking of the Enigma code by the Allied powers is one of the most interesting and amazing stories in the history of military intelligence. While I've read a number of books on the subject, I'm no expert, so I'll simply toss you back to the excellent Wikipedia page on the subject. I first became interested in the cryptanalysis of the Enigma when I read Simon Singh's The Code Book and decided to participate in his Cipher Challenge. I managed to crack seven out of ten ciphers in the challenge, including a challenge which was based upon cracking an Enigma enciphered text.
So, why the interest in the Atari?
As I write this, I'm 41 years old, which is a pretty unique age. This means that I was young enough to remember a time before microcomputers were available to the public. When I was 14 I bought my first computer, an Atari 400 and learned to program. I also later had an Atari 2600 video game which I got as they were being liquidated, and picked up many game cartridges for $1 or $2 a piece. I carried it through college, and would occasionally play it in the dorms with some friends of mine.
The funny thing was, the Atari 400 was the last computer that I really understood. It was simple enough that with some study, you actually could understand everything about it: the hardware, the software, the operating system. Now, computers are thousands of times more complex (and, thankfully, faster) and you just don't have the opportunity to really get down to the bare metal.
So, I decided that I would by teaching myself how to program the Atari 2600. The Enigma simulator idea just came to me one day, and stuck long enough to make it to completion. It's a really boring cartridge to have made, but it's uniquely mine.
How do I make my own cartridge?
Thanks to the Internet there is a large amount of information about programming games for the Atari 2600. At a minimum, I'd advise surfing over to Atari Age, they have a good forum for programmers and can answer many of the questions that you might have. You'll need to know how to program in 6502 assembly code as well, lucky for me, that was the first machine that I ever programmed on. If you didn't ever bother to learn how to program this quirky little 8-bit machine, try 6502.org for tutorials, primers and information. You'll need a 6502 assembler. Lots of different ones exist, but I used P65, an assembler written entirely in Perl, which makes it very portable and convenient. (There is a new version written in Python, but I already had perl on my Windows laptop, so that's what I stuck with). It's not a macro assembler, so I found gnu m4 to be useful to code up some simple macros (which I used to unwind most of the encryption functions). I used vim to edit the files, assembled them, and then ran them with Stella, a cross platform emulator for the Atari 2600. This is the most important thing you need: an emulator means that you can run your code on your regular computer, with all its conveniences, and not be burdened with burning new EPROMS just try try out a fix or two. Stella is a very good emulator: I had no difficulty running the code that I developed with it on the real Atari hardware. To make a real cartridge for a real Atari 2600, you need to burn an eprom with your code on it: I ordered a $50 unit from MCU mall, and got some EEPROMS that were compatible from digikey. Atari Age sells circuit boards which you can plug the chips into, and I scavenged an old Super Breakout Cartridge to provide a case. I then printed up a nice label for it, stuck it on, and voila! A real cartridge which worked the first time!
Addendum: I made a single sheet writeup of some of this information so that I could hand it out at the Maker's Faire.
Addendum2: Click here to download the source and compiled ROM file, suitable for execution with Stella.
Addendum3: A few more comments:
On the right you can see the simulator actually running on real Atari hardware. Under the section labelled "ROTORS" are the three rotor settings: you can select any of the five available rotors for each position. Below that, you can set the "ring settings", which help control how the carry works as the rotors increment their position. Below that, is the key: a three letter key, indicating the initial position of each rotor. Below that are six plug settings: these modify characters before and after they are sent through the encrypting rotors. Below that is the INPUT section. You can position the cursor around with the joystick, and select a key by hitting the fire button. The enigma machine then encrypts the character, and displays it in the scrolling display below the OUTPUT section.
To make this all works was actually moderately tricky, given the limitations of the base machine. To describe precisely why is a bit complicated, but here's the short description: the machine only has 128 bytes RAM. That's not very much. In particular, it isn't enough to create a frame buffer: the normal technique for bitmapped raster graphics. Instead of poking bytes into memory, and having a display controller converting these values into the appropriate signal for your TV, you are expected to do most of the timing yourself, and directly control the video stream in real time. Considering that the machine has a 1.19 Mhz 6507 processor, that gives you very little time to do anything at all: executing even the most basic instruction takes long enough for the electron gun in your tv to travel several pixels. Nevertheless, the Atari designers were quite clever, and managed to insert some nifty stuff that actually allows you to get individual control of 48 pixels on a single scanline. This allows you to put six characters on a line, which is why the interface looks like it does.
Anyway, it makes programming it a puzzle in and of itself, one that the original creators of Collosus might have appreciated.
I haven't got any pictures of the completed cartridge (I'll have to dig it out sometime, but here is the label design I made.