
Prince of Persia source code released (Apple II assembly) - andrewf
https://github.com/jmechner/Prince-of-Persia-Apple-II
======
snprbob86
I'll have to find some time to settle down in a deep leather chair with my
smoking jacket and a snifter of brandy for a fine evening of reading through
someone else's code.

Sounds like fun!

~~~
Trufa
I really hope the YC comment section doesn't become the reddit.

~~~
snprbob86
My apologies. Jeff Atwood made me a guest blogger without asking me first,
then added some boilerplate that I didn't agree with. I'd have given him
permission, had he asked, and I appreciate the inbound traffic, so I didn't
complain. However, this seemed like the perfect opportunity for some humor
while clarifying my position :-)

------
jasonlotito
And, just as a reminder, there is a wonderful book. It's from the journal
Jordan Mechner kept at the time. It's an excellent read.

<http://jordanmechner.com/ebook/>

~~~
talmand
I agree, it is quite interesting to read his thoughts as he was going through
the process of developing the game and what the industry was like at the time.

------
sehugg
This is a very interesting thought exercise on "what if you could send modern
programming languages back to the 1980s?" <http://prog21.dadgum.com/6.html>

It would be interesting to analyze early Apple ][ game images and see which
_didn't_ use assembly. Wizardry was a notable example for using USCD Pascal,
essentially running in a VM. Infocom games of course used Z-code. Applesoft
BASIC was fine for some text adventures (Eamon for example).

There were also programs like Microsoft's TASC that compiled Applesoft to
binary, much of the speedup gained by converting floating point values to
integer.

The SWEET16 interpreter was also built-in to ROM, but I don't know if any
titles used it.

But almost every game relied on some kind of special graphics technique to wow
the player, and that usually meant at least one neato routine hand-optimized
in assembly. Drawing a sprite to the Apple's frame buffer was actually much
more complex than blasting RGB values like we do today.

~~~
nevster
Thanks for that link. I never knew Marble Madness was written in C!

~~~
rbanffy
Aztec-C's performance on the II at least was terrible. A colleague explored it
for a project and gave up - the program ended up being developed in GraFORTH.

 _Very_ fast.

------
st3fan
My first patch [https://github.com/st3fan/Prince-of-Persia-Apple-
II/commit/d...](https://github.com/st3fan/Prince-of-Persia-Apple-
II/commit/d232cb1e279e295ee4396f22d84c84ef7c493925)

------
jcromartie
I never did assembly on those old machines, just BASIC and Logo in elementary
school, and some Turbo C by the time we had a 386.

I had heard of assembly and thought it was inherently "scary" and obtuse. But
this PoP code is pretty easy to follow, and I probably should have taken the
plunge way earlier.

Neat.

~~~
pmjordan
I recently thought about how I started programming and to my dismay I probably
held myself back by 6 years or so by lack of confidence:

1\. not having the confidence to talk to the 3 or 4 older kids at school who
clearly knew about this stuff. 16 & 17-year olds were _terrifying_ to my
10-year-old self. They of course graduated secondary school soon after, so
there was a small window and I missed it.

2\. I _really_ wish I hadn't believed any adults claiming this stuff was
"hard" or "scary". None of them did any real programming, so how would they
know? I should have just pestered my parents to find me an x86 instruction and
architecture reference - I'm sure I could have worked everything out from
there, after all I had enough spare time. I started with BASICA on an 8088 and
eventually was given a 486 after my parents got fed up with me hogging their
computer; alas, it took _years_ before I picked up C & C++ and assembly
language shortly after. As a 10-year old in rural Austria, my possibilities
for obtaining this kind of information myself were pretty limited, and
everyone (parents, teachers) was constantly encouraging me to focus on science
(physics) instead of programming.

Still, I shouldn't harp on too much about #2. I was into electronics before I
heard about programming and was obsessed with wanting to build my own
computer, and tried to get hold of information on doing so, only to be told it
was "impossible". (a 6502 plus some manuals would almost certainly have done
the trick, and in 1993 couldn't have been _that_ expensive - but I guess by
that point the "kit" computers were long dead) So clearly being more assertive
about wanting programming information would not have helped much either.

I hope I don't fuck this part up if I have kids of my own.

~~~
sliverstorm
_I hope I don't fuck this part up if I have kids of my own._

The hard part is the "thing to learn" may not be computers and programming, it
may be something entirely new. That's why your elders seem like they were out
of touch- tech was so new and all. It looks like a great choice from 2012, but
from 1990 it was more of an unknown, and there will be similar developments in
the future in other fields that challenge new parents to allow their kids to
explore fledgeling prospects.

~~~
dpeck
Hmm, not sure I believe that. I think anyone with any foresight in 1990
realized that computing was going to change the world. They may not have
realized the scale, or the details of it though. I think those of us who's
parents acted on that are really blessed with the jumpart we got on the world
to come

------
DanBC
See also this (<http://news.ycombinator.com/item?id=961713>) discussion about
the source code documentation.

------
abuzzooz
I didn't know it was all written in Assembly. Is there any documentation to
help with reading the code?

Thanks for the code btw. PoP is a landmark in the history of computer games.

~~~
thirdhaf
Of course, you need only go to the horse's mouth. [1]

It's been posted before but Jordan, the creator of both Karateka and Prince of
Persia, has a wonderful series of journals documenting his travails with video
games and the movie industry. [2] As part of this he has a detailed
description of his trek out to California and a lot of details on technical
obstacles that make you thankful to live in the second decade of the third
millennium.

[1] [http://jordanmechner.com/wp-
content/uploads/1989/10/popsourc...](http://jordanmechner.com/wp-
content/uploads/1989/10/popsource009.pdf)

[2] <http://jordanmechner.com/>

------
vessenes
Cue DCPU-16 port in 3..2..

------
schiffern
Wow, and the day after the 35th anniversary of the first public showing of the
Apple II: [http://techland.time.com/2012/04/16/apple-ii-
forever-a-35th-...](http://techland.time.com/2012/04/16/apple-ii-
forever-a-35th-anniversary-tribute-to-apples-first-iconic-product/)

------
binarycrusader
No license or copyright stated. Doh!

(Which technically means we don't have permission to do anything with the
source at all, though I doubt that's what Jordan intended.)

~~~
eru
You can trade patches. Isn't that how Linux got started, as patches to Minix?

~~~
gumbo72
No, it started as a Minix clone by Linus.

~~~
plaes
Nope, it was initially a terminal emulator, which he used to access the large
UNIX servers of the university. Initial development was done on Minix.

------
albertzeyer
I wonder, how was this ported to PC? Completely rewritten from scratch? Or was
there some AppleII -> x86 translator?

~~~
famousactress
Effectively, yes. It sounds like it was basically a rewrite. The book of
journals for the game development that lots of other folks have led to talked
about the process of finding a programmer to do the work in a fair bit of
detail. Like everyone else has said, the journals are well worth reading. Best
money I've spent on an e-book this year for sure.

------
acomjean
Loved that game when I was a kid.

love the sound code. Having to write your own "tone" routines to tweak a sound
out of the speaker...

------
rbanffy
I love the 6502. One day I'll finally get to learn VHDL and build myself a
64-bit 6564. x86 is no fun.

~~~
joezydeco
You can use the OpenCore 6502 as a start. Cut-and-paste!

<http://opencores.org/project,6502vhdl>

------
pooyak
wait! no "megahit" in source? this can't be real...

~~~
wladimir
Maybe that cheat was only in the PC version?

I wonder how the PC version (which I've played and fondly remember) and Apple
2 version differ.

~~~
jipumarino
Jordan, regarding the PC version, 01/26/1990:

 _This is going to be the definitive version of Prince of Persia. With VGA and
a sound card, on a fast machine, it'll blow the Apple away. (In contrast, none
of the Karateka conversions was as good as the Apple original)_

------
chris_wot
Anyone got any good Apple Assembly manuals? :-)

~~~
vidarh
Depends. The CPU is "just" a 6502, so there's plenty:

* <http://www.6502.org/>

* Most of the machine code books here: <http://www.bombjack.org/commodore/books-generic.htm>

As for Apple-II specific details (graphics chipset etc.) someone else will
need to chip in - never even saw an Apple-II during my childhood, Norway like
much of Europe was Commodore dominated.

~~~
krevis
This made me laugh. The words "Apple II" and "graphics chipset" don't belong
in the same sentence! The Apple II graphics were a fantastic, and
fantastically weird, low-hardware hack.

[http://en.wikipedia.org/wiki/Apple_II_graphics#Video_output_...](http://en.wikipedia.org/wiki/Apple_II_graphics#Video_output_on_the_machines)

~~~
vidarh
That does sound rather strange. But fascinating...

Stuff like that seems like it might explain some of the mutual disdain that
Chuck Peddle and Woz seems to have ended up with after their early encounters
(when Peddle was on his 6502 "sales tours"; though maybe interviews and books
have exaggerated it).

I can totally see this being the type of hack that would excite someone like
Woz to pull off but that would make Peddle's straight laced inner formal
engineer rage... Combine Commodore / MOS engineerings early problems getting a
decent color graphics chip together but cultural refusal to go for something
more hacky (the did plenty hacky stuff but only when Tramiel put jobs on the
line) to get out the door quicker, with plenty of blame being put allocated to
Peddle on a regular basis, and I can see lots of ego getting caught up in it..

~~~
Someone
I think you will be interested in the design of the Macintosh video/audio
hardware, too, then;
[http://www.folklore.org/StoryView.py?story=Sound_By_Monday.t...](http://www.folklore.org/StoryView.py?story=Sound_By_Monday.txt)
gives some details.

IIRC, things were even better. There were two (740 byte, IIRC) buffers from
which samples were taken at every horizontal refresh.

The sound driver used one to get samples to send to the speaker; the disk
driver used the other to control the rotation speed of the disk drive (using
pulse-width modulation).

------
_pferreir_
I had no idea it had been written in assembly. I am amazed. The awesomeness of
this thread is unprecedented.

~~~
eru
To give you another example: Transport Tycoon was also written in assembly.

~~~
octotoad
Almost all of Rollercoaster Tycoon as well. Blew my mind when I found out.

~~~
_pferreir_
Can't they publish the source code for those as well? I'm sure many of the
original developers of early games that are now abandonware still have a
backup of the source code lying around.

~~~
cdmoyer
I think this part of the README is relevant:

    
    
      Thanks to Jason Scott and Tony Diaz for successfully   
      extracting the source code from a 22-year-old 3.5" floppy 
      disk archive, a task that took most of a long day and 
      night, and would have taken much longer if not for Tony's 
      incredible expertise, perseverence, and well-maintained 
      collection of vintage Apple hardware.
    

From this we learn that the code, today, only existed in an out-dated medium,
readable on vintage hardware, and even meeting those prerequisites, still
involved a fair amount of human expertise and time to extract.

I'm sure they could, but unless they also have a book to promote, it's
probably not worth their time. Well, I think it would be, simply as a
contribution to the history/record of the era... but they likely aren't going
to recoup the time or effort other than in goodwill. (I also suspect there's
probably legal, copyright, and ownership issues involved as well.)

------
wildtype
I can't find the Makefile :D

------
cfontes
Now just wait 10 minutes to get a port to DCPU-16.

