Yesterday I finished The Making of Prince of Persia — Journals 1985–1993 by Jordan Mechner. It was an awesome read and I whipped through it in no time. I don’t know what I expected, but the book was much more to me than just a developer’s journal. Maybe it’s because Jordan’s 1980s self was as old as I am today. The book made me think about career choices, free time, family, and friendship.

Fancy words, I know. Also, this post is not about that.

Screenshot of level 12 of the Prince of Persia game on an IBM PC with VGA graphics. The prince just jumped through a mirror and thus brought his evil counterpart to life.
The Prince and his evil doppelgänger, the Shadow Man (IBM PC version with VGA graphics)

It is rather about a neat little yet ingenious technical thing that I am trying to reproduce. A retro experiment, if you will. I caught myself smiling when I stumbled upon this line in the book:

I was explaining to her why there are no enemies in Prince of Persia. The animations for the player’s character are so elaborate, there’s not enough memory left to add another character.
—Jordan Mechner

Sure, these worries are part of the old game development days that are long gone. But it makes me appreciate games from back then even more. I mean, where is the challenge in game programming today? Sometimes I wish for the romantic of computer technology in the eighties, to be frank.

Back to my little experiment. Jordan found a solution for his dilemma:

I started to explain: ‘This is the Apple II…’ and then it hit me: What if I exclusive-OR each frame with itself, bit-shifted one pixel over? I visualized a ghostly, shimmering outline-figure, black, with white face and arms, running and leaping, pursuing you. I described it to Tomi. ‘Shadow Man!’ she exclaimed.
—Jordan Mechner

It is ridiculous how his idea is simple and brilliant at the same time. Use XOR and everything is going to be fine, no big deal. I wanted to try it out anyways. Say ‘Hi’ to the Prince and his 1-pixel-shifted friend!

The original and copy of the prince where the latter wasw shifted by 1 pixel.

I used imagemagick and Seashore to do exactly what Jordan suggested: I took the two images and XORed them together. The result looks magically familiar:

The outcome of xor-ing the both princes images toegther: the Shadow Man.

You may say the outcome has been obvious all along. However, I felt great as I witnessed the Shadow Man coming to life on my computer—25 years after his first appearance!

The in-game Shadow Man in fight action on a DOS machine.
A fighting Shadow Man (DOS version)

Shadow Man might be a bit misleading, since the Prince’s antagonist is really his own reflection in the mirror. Spoiler: Before you approach Jaffar, the final opponent who captured the princess, you reunite with your evil twin to regain your full strength.

It doesn’t matter… From now on I will always refer to him as Shadow Man. Simply because I can picture Tomi Pierce, who coined this name, with eyes wide open, a huge smile on her face, and all filled up with excitement.

Just like me, when my dad introduced me to Prince of Persia.

Notes

  1. I do find the rise of computer games fascinating and stunning. But I also think that they are stagnating. Fortunately, I have the feeling that HTML5 games might have set the stage for some true innovations and new pioneers. 
  2. The characters in this article are from the DOS version of the game. Here you can find a nice screenshot collection of the different versions. 
  3. This is a perfect analogy for the underlying math: Iff a xor b = c, then c xor b = a (the last equation is also true if you switch a and b). Beautiful! 
  4. Shit… When I googled for her last name, I found out that she died of ALS 4 years ago. Based on Jordan’s obituary, it seems Tomi was a wonderful person. May she never be forgotten!