Recovering the code of Prince of Persia


Filed under Game trail, History, Mainstream coverage, People;
3 comments.

Jordan Mechner, rockstar programmer responsible for Prince of Persia and Karateka and keynote speaker of next week’s PAX East convention, published a comprehensive journal of the making of Prince of Persia. In the book and on Mechner’s Web site are notes, sketches, concept art, demo videos, and more — a wealth of information he preserved from decades ago.

Yet for all that time, there was one vital piece of data he was missing: the original source code. Whether it had been overwritten, lent or donated, mistakenly or purposely trashed, or simply lost remained unknown to Mechner, despite his best efforts.

This week, that long-lost treasure fell in his lap when his father mailed him a box of assorted unidentified floppies. Contained therein was Prince of Persia in its rawest form.

It never occurred to me that Mechner didn’t already have PoP’s source code. Given that PoP has appeared on platforms as recent as the Xbox 360, I wonder what version or fork they were basing that port on. It makes even more recent independent ports all the more impressive.

Source Code

Jake Gyllenhaal followed his role as Mechner's Prince of Persia
with the lead in
Source Code... coincidence?!

Mechner’s next task is to verify the integrity of the floppies and migrate the data off them. New hardware like the FC5025 and Kyroflux are miracle workers in our ability to access vintage media via a modern operating system, but the fact remains that the floppy disk is a magnetic medium whose charge is dying. I started (but did not finish) my own floppy migration two years ago. It’s easy to dismiss it as a low-priority project compared to ongoing and more demanding tasks, but it will be all too soon that I’ll have put it off too long.

Once the code is recovered, I wonder what Mechner will do with it? It’s still copyrighted material, so will he continue to keep it a secret — or will he publish it under Creative Commons, allowing a variety of variations and ports?

All this reminds me: David X. Cohen, co-creator of the television show Futurama, reported almost five years ago that he too had programmed an Apple II game that needed rescuing from floppies. I wonder what ever came of that?

UPDATE (Mar 30): Jason Scott tells me, "You’ll be delighted to know I am leading this expedition."

(Hat tip to Sean Fahey)

  1. Well, the raw binary 6502 machine code from the Apple II version is what MrSid disassembled to create the recent C64 version, of course with heavy adaptions and essentially rewriting much of the code. 6502 machine code has a very limited instruction set, hence rather easy to decode. The trick lies in figuring out where the data is and in what structure it is, as well as giving things labels (variables and jumps) to make it easy to read. So in a sense the “source code” of most 8bit games are never truly lost, it just takes a bit of effort to make them a bit more readable.

    I suggest reading MrSid’s blog for when he did the porting, just search for “Prince of Persia C64 blog”, it should be easy to find.

  2. Thanks, John! I blogged about Mr. SID’s work back in October; my point was that the port would’ve been easier with the original source code.

    I wonder what variance there is between the code he derived through disassembly, and what Mechner now has?

  3. Indeed, Jordan must have been thrilled to see the source of his old masterpiece again. :) – Since he made some documents public about the format of data files they gave enough clues to make it easier to interpret the 6502 machine code. Very few assemblers at the time used any heavy macro stuff with pre processing so the source is probably very much like the disassembly, but of course with meaningful labels. For PoP, the grunt of the work must have been the graphical assets and those are rather easy to extract as well from most games binaries.