Prince of Persia: the Apple II source

It’s been a good few months for the 8 bit versions of Prince of Persia. Last October saw the release of a C64 version. Yesterday the original source code for the Apple II version was uploaded to github! Read about how Jason Scott recovered that source code from 20 year old disks (similar to what I did recently!)

The game was originally written in assembler so the source code was already out there. How? Machine code is the language a machine understands and assembler is a human representation of that machine code. For example, the machine code “A9 00 8D 20 D0″ is actually this more readable assembler: (that inserts the value 0 into the memory location $D020)
[code lang=”plain”]LDA #00
STA $D020[/code]

The assembler code released yesterday goes one step further. It uses labels, variables and comments. See BOOT.S as a good example. Variables are defined at the top and labels are used throughout making it a lot easier to deal with moving and adding code around. Look for the text “skewtbl” where you’ll find a simple loop that reads in data from memory and inserts it into 2 registers.

[code lang=”plain”]:0 ldy sector
lda skewtbl,y
sta $3d
lda sectaddr,y
beq :1
sta $27
:rdsect jsr $005c
:1 dec sector
bne :0

lda SLOT
jmp $900

skewtbl hex 00,0d,0b,09,07,05,03,01
hex 0e,0c,0a,08,06,04,02,0f

sectaddr hex 00,09,00,00,00,00,00,00
hex 30,31,32,33,34,00,00,00[/code]

Jordan Mechner puts it more poetically:

Non-programming analogy: Video game source code is a bit like the sheet music to a piano sonata that’s already been performed and recorded. One might reasonably ask: If you have the recording, what do you need the sheet music for?
You don’t, if all you want is to listen and enjoy the music. But to a pianist performing the piece, or a composer who wants to study it or arrange it for different instruments, the original score is valuable.

Props to this Slashdot post for the extra links. Also worth a look is the development diary of the C64 version and there are videos showing how the game was made back in 1985!

Author: Donncha

Donncha Ó Caoimh is a software developer at Automattic and WordPress plugin developer. He posts photos at In Photos and can also be found on Google+ and Twitter.

1 thought on “Prince of Persia: the Apple II source”

  1. Bet having access to the comments etc. in there would have made things a bit easier for Mr Sid when doing the C64 conversion! I must play it now since Ultimate 1541 cart can now handle the format.

Leave a Reply