How Prince of Persia Defeated Apple II's Memory Limitations | War Stories | Ars Technica

Ars Technica

22 min read Original article ↗

[disk drives beeping]

[deep electronic music]

- I developed a storyline for "Shadow Man."

He comes back at predetermined moments through the game.

There's one point where he steals a potion.

Just as you're about to reach it,

Shadow Man comes running in,

drinks it and runs off.

There's another moment where you're about

to get through a gate,

Shadow Man walks up,

steps on the pressure plate,

and closes the gate.

At that point, you fall back down three levels,

and you're gonna have to work your way back up.

These encounters were scripted

to make you hate Shadow Man

and see him as your enemy,

so that by the time you face him with crossed swords

at the end of the game,

you really wanna get this guy

because he's set you back so many times.

It's a way to build an emotional relationship

between the player and an opponent

through the actual gameplay

rather than just telling it in a cinematic.

Hi, I am Jordan Mechner,

creator of Prince of Persia.

This is how I animated myself into a corner

and had to fight my way out.

So I was a kid in New York in the mid '70s.

I was into comics.

I loved movies.

I grew up on "MAD" Magazine,

and if computers hadn't come along when they did,

you know I might have ended up doing comics, animation,

but when the Apple II came in 1978,

I saw this as a machine that I could

first of all use to play games at home

which was never possible before.

Instead of taking rolls of quarters down to the local arcade

I could stay at home and play "Space Invaders"

on the Apple II as much as I wanted.

The computer was also a way that I could

make my own games,

and I became fascinated with that.

This is before the Internet,

so pretty much everybody was self taught.

I subscribed to "Creative Computing" magazine,

and then a little later "Softalk" magazine

which had articles about how to program,

and then I would trade tips

with my friends who were also into computers.

[dramatic music]

So my first games were copies of existing arcade games,

and you always had three lives,

and the goal was to get a high score,

but now I was a freshman in college,

and I wanted to do a game that would tell a story,

so that's when I started programming the game

that would become "Karateka."

[bright synthesizer music]

It was a very simple story.

The princess has been kidnapped by the evil warlord

who has taken her to his castle,

and so as the hero you have to

fight a series of karate battles

with the warriors who are guarding the fortress.

[warrior shouts]

So you're basically running from left to right,

you fight one warrior after another

until you reach the end,

and then you fight the big bad guy

and rescue the princess,

so the computer that I was working on was the Apple II,

and at that time the Apple was actually

the number one game platform,

but it had limitations.

The Apple II's music capabilities weren't that great,

it only had four colors,

the screen was 280×192 pixels,

and everything had to fit into 48K of memory.

That was pretty much a hard limit.

In those days this was before Photoshop,

this was before we had graphics and animation tools,

if you wanted to put a character up on the screen,

you pretty much had to do it pixel by pixel,

so when I tried to do the animation for the character,

I found out pretty quickly that it just looked stiff,

and it didn't just have the lifelike quality

that I was imagining in my head,

so I used a technique called rotoscoping

which actually has a long history.

It goes back to the early days of film animation.

Early Disney animators used film footage

as reference for the animation in the early films.

If you look at "Snow White,"

the human characters like Snow White and the Prince

were actually animated using rotoscoping,

which means that the Disney animators

filmed live actors doing the moves

that they needed to animate onscreen,

and then they would actually project these frames,

and copy or trace them frame-by-frame

to create the animation that we've seen.

So I did that for "Karateka."

I used Super 8 film to film my karate teacher

doing the kicks and punches,

and the movements

that I needed the character to do on screen,

and then I traced each Super 8 film frame

with tracing paper and pencil,

and then translated those into pixels

to get it up on the screen.

That was kind of the rotoscope 1.0.

[synthesized electronic music]

"Karateka" came out in 1984,

and it became a number one bestseller,

so this was really lucky for me

that it happened when it did,

because as I graduated from college

instead of going out and getting a job

I actually had the luxury of thinking,

What do I wanna do next?

And I had an idea to do another game.

One of the inspirations was the first 10 minutes

of the movie "Raiders of the Lost Ark."

[suspenseful orchestra music]

If you remember Indiana Jones in the opening sequence

runs jumps over a pit almost misses,

spikes spring out of the wall,

there's a gate that's closing,

and to me, those actions kind of matched

what I was seeing in platform games,

like "Lode Runner" and "The Castles of Doctor Creep"

where you'd step on the pressure plate,

it would open a gate.

I thought what if we combined that gameplay

with a character who's so human feeling

that you feel like if you miss the jump

and you fall it's really gonna hurt.

Because in the early platform games

characters were kind of weightless.

You know you would jump, and you would make it or not,

but you would float down to the bottom

It didn't feel like you could really get hurt.

So my idea was to kind of combine

the basic platform puzzle type gameplay

in sort of a modular environment

with very smooth visceral running and jumping animation

that would capture the excitement

of the opening minutes of "Raiders of the Lost Ark"

[dramatic orchestral music] [man grunting]

The story of "Prince of Persia" was also simple.

Like "Karateka," it involved rescuing a princess.

And it was really inspired by

the "Thousand and One Nights"

and by movies like the 1940 "The Thief of Bagdad"

in which an evil grand vizier has seized power

and imprisoned the princess.

For "Prince of Persia" I knew

I was gonna need so much more animation

Running, jumping, climbing, falling:

all the movements that the little character

would have to do on screen.

And by the the time I did the animation

for "Prince of Persia" in '85,

a new technology had come along, VHS.

So using one of the early VHS cameras,

I videotaped my brother running and jumping

and doing all those things in the parking lot

across the street from our high school

Go!

Jump!

Action!

Stop!

[both laughs]

Get up get, up get up!

And then the problem was

how to get these videotaped frames into the computer.

After a bit of trial and error,

the technique that I finally settled on

for "Prince of Persia"

was a kind of analog-to-digital to analog-to-digital

and involved several steps.

I took the video tape of my brother

and put that on a TV screen in a darkened room

put a 35mm camera on a tripod

aimed it at the TV screen

and then took a picture,

did a frame advance on the VCR,

took another picture,

frame advance, frame advance, frame advance

then I took that roll of film containing about 35 frames

down to the local Fotomat, the one hour photo

had the film developed

and then got back a sheaf of snapshots

which I then Scotch taped together

and using a Sharpie and Wite-Out

highlighted the outlines of each character

then put that on a Xerox machine

and came out with one clean sheet of paper

with a series of frames of a clean white character

against a black background

so that contrast was sharp enough

that I could then put that piece of paper

on an animation stand,

pointed a video camera at it,

and ran that into the Apple II which had no video in.

This was a special digitizer card

that could get one clean still image.

It couldn't capture motion,

but once I had that sheet of nine or 12 individual frames

of the character,

I could then go in pixel by pixel and cut them out

on screen using my animation tool

and then run those frame in sequence,

and so all of this took weeks of work

to get from that video tape run or jump

to the point where the game was actually playing back

those frames in sequence on screen.

[computer beep]

When I first saw that character running

and jumping on the screen,

it had the rough illusion of life and of weight,

but these were the days of eight-bit graphics.

Each frame of animation in "Prince of Persia"

was a series of bytes that represented

a fixed image on the screen,

and then the next frame of animation

was another set of bytes,

so to do something like jump in place took 12 frames,

to do a running jump might take 15 frames,

and the number of frames made the animation smoother.

[gentle music]

So once you add the jumping, the running, the turning,

the hanging, the swinging, all of these things,

each individual movement took memory.

This is where one difference between computers then

and now became very important

because the Apple II's memory was 48K.

That's less than a normal text email,

so that had to contain everything:

all of the images, all of the backgrounds,

all of the frames of animation,

all of the logic to make it work,

all of the sound effects, all of the music, everything.

So with all of the basic animations

that the character needed to navigate,

through the dungeons, that had filled up

all of the computer's available memory.

[dramatic music]

So it was June of 1988,

and I was two years into making "Prince of Persia"

and at this point I had done most of the heavy lifting

to get the game working.

I had a smoothly animated character

that was running through these dungeons

climbing and falling and stepping on pressure plates

to open gates and jumping over pits

almost falling on spikes.

Everybody who saw the game oohed and ahhed.

It was like a great proof of concept,

but it wasn't that much fun to play,

and I kind of had the sinking feeling as I realized

that I've done almost everything I meant to do,

but it just doesn't have that excitement

that I was hoping for.

Also there was a ticking clock

which is that the Apple II platform was dying.

When I started to make "Price of Persia,"

the Apple II was still the number one games platform.

By 1988, there were new machines that were coming out

that had more colors, higher resolution,

better sound capability,

and I was really at the tail end

of the Apple II's life cycle,

but I felt that switching to a different platform

would have been like starting over,

so the worry was that I could come out with a game

that was great, that was fun,

but nobody would ever play it.

Yeah so it was a problem when you reach a point

in development that makes you question your initial vision.

Sometimes the answer is to say,

you know just believe in the initial vision,

execute it, it's gonna be fine.

But sometimes you discover things along the way

that make you realize

that the initial vision is just a first draft.

From the beginning,

I had the idea that the main character would not fight

that this was a nonviolent character

just trying to survive in a dungeon in a violent world

that is there's spikes that spring out of the floor,

there's you know gates and falling blocks

that can crush you,

but this is not a violent character.

The point is just to get through these traps

and get to the end and rescue the princess,

and I had used all of the resources

that the Apple II offered to try to create this.

I didn't have room to put in another character,

so I was sharing an office with friends

who were also working on their own projects.

Robert Cook was working on a game

that became "D/Generation."

Tomi Pierce was creating educational software,

and every time Tomi saw "Prince of Persia" on my screen

as she walked by my desk,

she would say, "Combat, combat, combat.

"You need combat,

"or this game is not going to be fun."

and this frustrated me because I hadn't planned for combat.

"Karateka" was a fighting game.

The whole game was

you meet a guard,

you fight the guard,

and then on to the next battle,

and so I would explain to Tomi,

"I can't do that because there's not enough memory

"in the computer to also have a smoothly animated enemy

"that does everything that I would need an enemy to do."

But when Tomi got an idea,

she wouldn't let it go,

and so I would add a new feature to the game,

I would say, "Now there's torches on my wall.

"Now I've got jaw traps that chomp and add suspense.

"Isn't it better now?"

Tomi would look at the new feature I added and say,

"Combat, combat, combat."

[sighs deeply]

And with frustration I realized that

there was something to what she was saying.

As much as I wish that it was almost done,

it just wasn't that much fun,

so this was the problem:

two years into development,

I'd used up all the memory to get as far as I'd gotten,

but the game was missing that suspense and excitement

and sense of conflict that had made "Karateka"

so simple and so much fun.

What was I gonna do?

[dramatic music]

So I can tell you exactly what happened.

On that day in June 1988,

because I wrote about it in my journal,

it was another day in which

Tomi had come and looked at my screen and said,

"Combat, you need combat."

And again I'd rolled out my usual argument about how

first of all that's not the concept of the game

second of all there's no memory,

and she said, "Well in 'Karateka,'

"you used the same shapes for the hero and the enemy,

"couldn't you do that?"

I said, "No, because the hero looks like a likable

"enduring kind of character.

"The enemy shouldn't look like that."

And she said, "Well,

"what if you made the enemies a different color?"

And then the idea came to me,

what if I exclusive-or'd each byte with itself

shifted one bit over?

[keyboard clacking]

So the Apple II didn't have image processing

in any kind of sense that we understand it now

'cause the graphics were all bitmapped,

but one of the assembly language instructions

was called exclusive-or

which basically means if the the two bits are the same,

you get a zero,

if the two bits are different,

you get a one,

so as I was telling Tomi for the 10th time

why I couldn't draw a character in a different color

than the one I originally created,

I realized that if I used the exclusive-or instruction

shifted one bit over,

this would create kind of a shimmery, ghostly outline

of the main character,

and as soon as I said those words,

the character's name popped into being: Shadow Man.

So with Tomi and Robert looking over my shoulder,

it actually look me all of five minutes

to write the code that would turn the main character

into a shimmery, ghostly version of itself,

and as soon as we saw Shadow Man running, jumping,

and climbing through the dungeon,

it became obvious that this was

this was the opponent that the game needed.

It was Robert who suggested

that Shadow Man could come into being

when you jump through a mirror,

your ghostly self jumps out the other direction

and then once it's loose in the dungeons,

it becomes your enemy,

stealing potions,

closing gates that you wanted open,

and just kind of wreaking all kind of havoc,

so out of necessity was born this character

who ended up becoming one of the best features of the game.

It's a case of where constraints can sometimes push you

to more creative solutions

than you would have found in the beginning

if they had been available.

If memory had not been a constraint,

I probably would have created all kinds of monsters

and enemies in "Prince of Persia" to add a lot of variety,

but because there was no room for any of that,

I was forced to dig deeper and came up with Shadow Man

which ended up actually being kind of deeper

and more satisfying.

At the end of the game when you confront your shadow self,

and you fight him with swords,

every time you hit Shadow Man,

you lose a strength point,

and you realize that if you keep fighting,

you're eventually gonna kill yourself,

so the solution is not to win the sword fight,

but to put away your sword,

and when you put away the sword,

Shadow Man does the same,

and then facing each other,

you run towards Shadow Man,

he runs towards you,

and the two of you merge and are reunited,

and then you get back all the health points

that Shadow Man had stolen from you throughout the game,

and with this restored strength and wholeness,

you're then able to fight the grand vizier,

and win the game.

That's something that I wouldn't have come up with

if I didn't have to.

Once Shadow Man was in the game,

it was obvious that that was the right way to go,

and so I managed to squeeze out of the memory

enough frames to do sword fighting

so that you could fight the shadow version of yourself,

and that was so compelling that it's alright,

whatever it takes,

I've got to find a way to populate this dungeon with guards,

and at this late stage,

I've found a way to take 12K of memory that was hiding

in the auxiliary memory card of the Apple II

to add a guard,

but this presented a new problem.

How do we create the animation for the enemies?

So the model for the animations in "Prince of Persia"

had been my younger brother who at this point

was 3,000 miles away,

and he wasn't any good at sword fighting anyway,

so my first attempt was to film myself

and my office mate Robert with a sword doing fencing.

Unfortunately, that didn't work.

Finally in desperation, I turned to one of my favorite films

the 1938 "Robin Hood" with Errol Flynn,

and it just happened that in this film,

in his climactic duel with Basil Rathbone,

there's a sequence of about six seconds

where the two characters are perfectly in profile,

fighting each other,

so with a VHS tape of the 1938 "Robin Hood,"

I took photographs of each frame of film,

and extracted the moves that the characters would need to do

in order to do sword fighting,

and once the guards were in there,

the game felt complete.

Now as you move through the dungeons,

you had that feeling of challenge,

of suspense, of fear

that had been such an important part

of what made "Karateka" successful.

[dramatic music]

The lesson, if there is one,

you know the best way that I've been able to formulate it

is that when you have these two voices,

you know two different approaches in your brain,

giving you two different solutions

that are diametrically opposed

to really try to tune into each voice

and think, "Is this the voice you know of the big picture?"

Because sometimes you can have great ideas

that are kind of taking you off the path

of what you originally set out to do,

but sometimes that voice is actually

putting you back on the path.

The reason that Shadow Man was the right thing to do

I think goes back to the original inspiration

of "Prince of Persia."

It's basically the modern version of a swashbuckling movie,

and in those old swashbuckling movies

whether it was Errol Flynn or Douglass Fairbanks

or Indiana Jones, the hero did fight,

so it's completely in line with that spirit.

"Prince of Persia" released at the end of 1989

on the Apple II,

and as I'd feared, I'd lost the race against time.

By then, the Apple II was a dying platform,

and for about a year,

I had the agonizing experience

of feeling that this game that I'd work so hard on

which everybody who played was enjoying,

that this game was going to sink without a trace.

What saved it was the ports to other platforms,

to the PC, to the Mac,

and also to consoles

like Sega and Nintendo

that came out over the next couple of years,

and kind of rescued this game that had been a flop

and made it into a hit,

and that's what actually made it really clear to me

that adding Shadow Man and combat had been

the right thing to do

because on these other platforms,

the memory issues that had been so critical on the Apple II

no longer existed.

Those swashbuckling cinematic roots turned out

to be a key part of you know what made "Prince of Persia"

what it is.

"Prince of Persia" was successful enough on PC

that we did a sequel.

"Prince of Persia 2: The Shadow and the Flame"

and by the time this game came out in 1993,

we had a new generation of PCs that could do sound

and music and color graphics way beyond

what was possible in the late '80s,

and we took advantage of this,

adding more enemies, more characters,

and richer environments, sending the prince on a journey

across a world that got us of the dungeon and palace

of "Prince of Persia 1."

But the basic gameplay,

the formula of traps,

fight and flight, puzzle solving,

and combat and exploration,

was still pretty close to what it had been

in "Prince of Persia 1."

Since the original "Prince of Persia,"

the technology has advanced,

but the basic questions of game design

haven't really changed all that much.

When we did the remake in 2003,

"Prince of Persia: The Sands of Time,"

we were working on

a much later generation of consoles.

The PlayStation 2 generation,

and so for the first time, we had 3D graphics,

the ability to rewind time,

sound, music, you know all these things

that the Apple II couldn't do,

but we still had constraints.

The first draft of the story for "The Sands of Time"

had been much more complicated with kind of

this political intrigue

and you know different factions within the kingdom,

so for the final game,

we ended up stripping all of that out,

and going with a much simpler story

in which everybody in the kingdom has been transformed

into sand monsters,

and that one decision made it possible to design a game

that was actually in sync with what you could do

with a controller in your hands

because everybody that you met was a sand monster,

so your only options really were acrobatics,

combat and running away,

and that was a good fit with what you could do as a player,

even though we had the ability to do dialog

and facial animations and so forth.

Having a large cast of characters would have taken

the game away from its strengths,

so in designing a game story,

you really want to plan choices that emphasize the strengths

rather than emphasizing the weaknesses.

This year is the 30th year anniversary

of the original "Prince of Persia,"

and a lot of what I've told you today

I remember thanks to the fact that I kept a journal,

so we're actually re-releasing these journals as a book

for "Prince of Persia's" 30th anniversary.

They're the journals that I kept at the time

as I was making the games,

so it's got all of the roller coasters,

of all the ups and downs of,

this game is going to be great,

this game is going to be a disaster,

and how do I solve this particular problem?

We've also illustrated the journals with screenshots

of the work in progress and sketches,

so it's been a lot of fun for me on this anniversary

to have a reason to go back

and look at those little journals again

which being in the '80s are mostly on pen and paper.

[soft music]