Prince of Persia source code released (Apple II assembly)(github.com)
github.com
Prince of Persia source code released (Apple II assembly)
https://github.com/jmechner/Prince-of-Persia-Apple-II
77 comments
Not just text adventures, the original version of Ultima I was written in Applesoft BASIC too.
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-...
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.)
(Which technically means we don't have permission to do anything with the source at all, though I doubt that's what Jordan intended.)
I wonder, how was this ported to PC? Completely rewritten from scratch? Or was there some AppleII -> x86 translator?
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.
In those days it would have been almost certainly rewritten. Although it would maintain a lot of similarities.
I love the 6502. One day I'll finally get to learn VHDL and build myself a 64-bit 6564. x86 is no fun.
You can use the OpenCore 6502 as a start. Cut-and-paste!
http://opencores.org/project,6502vhdl
http://opencores.org/project,6502vhdl
I had no idea it had been written in assembly. I am amazed. The awesomeness of this thread is unprecedented.
To give you another example: Transport Tycoon was also written in assembly.
Almost all of Rollercoaster Tycoon as well. Blew my mind when I found out.
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.
I think this part of the README is relevant:
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.)
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.)
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.
Thanks for the code btw. PoP is a landmark in the history of computer games.
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...
[2] http://jordanmechner.com/
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...
[2] http://jordanmechner.com/
I can't find the Makefile :D
Cue DCPU-16 port in 3..2..
Anyone got any good Apple Assembly manuals? :-)
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.
* 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.
Apple II assembly coder here, and the book I used is in your second link, "Using 6502 Assembly Language" by Randy Hyde. Mine had your link's cover, not the cover shown on Amazon:
http://www.bombjack.org/commodore/books/pdf/A2_Hyde_6502_Asm...
See also http://www.callapple.org/cat/ap0010.htm and http://www.amazon.com/Using-6502-assembly-language-program/d...
For Apple II details, supplemented that with a number of patterns books like Beagle Bros Big Tip Book: http://beagle.applearchives.com/books/big_tip_book_ocrpdf.zi...
http://www.bombjack.org/commodore/books/pdf/A2_Hyde_6502_Asm...
See also http://www.callapple.org/cat/ap0010.htm and http://www.amazon.com/Using-6502-assembly-language-program/d...
For Apple II details, supplemented that with a number of patterns books like Beagle Bros Big Tip Book: http://beagle.applearchives.com/books/big_tip_book_ocrpdf.zi...
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_...
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..
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..
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... 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).
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).
That second link is a treasure trove of 80s-era computer books. I'm surprised at how many of those I owned and/or read.
If you go up a bit it actually has most English language Amiga and Commodore related magazines as well...
wait! no "megahit" in source?
this can't be real...
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.
I wonder how the PC version (which I've played and fondly remember) and Apple 2 version differ.
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)
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)
[deleted](1)
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!
Sounds like fun!
I really hope the YC comment section doesn't become the reddit.
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 :-)
[deleted]
Brilliant!
So many down votes? I liked the reference to the recent item "Learn to read the source, Luke"[1] quite a lot!
[1]: http://news.ycombinator.com/item?id=3849203
[1]: http://news.ycombinator.com/item?id=3849203
I think the reason you were downvoted was that your comment didn't really say anything unique- it just agreed with the parent.
See also this (http://news.ycombinator.com/item?id=961713) discussion about the source code documentation.
Now just wait 10 minutes to get a port to DCPU-16.
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.
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.
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.
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.
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.
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.
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
Yeah, that's my takeaway, too. Offer up a variety of things to try, but encourage whatever they happen to be passionate about, not what I'm passionate about. (and know when I'm out of my depth)
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/
http://jordanmechner.com/ebook/
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.
[deleted]
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...
love the sound code. Having to write your own "tone" routines to tweak a sound out of the speaker...
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.