Prince Of Persia Code Review: Part 1 (Introduction)

On Apr 17, 2012 Jordan Mechner released the source code of Prince of Persia.



Even though it is the Apple II version written in 6502 assembly language, it was a pleasant experience to dive in the code of that mythical game: As usual there were many fascinating sofware wizardries to discover.



The Apple II apparent poor environment for game programming was actually ground to unmatched innovation and creativity : From self-modifying code, in-house bootloader, clever floppy disc format to skewing lookup tables: Prince Of Persia features engineering treasures in every modules.



Reading the source allowed me not only to learn about the game development process of the 80s but it also renewed my appreciation for things that we take for granted today.



As usual I took numerous notes that I have cleaned up on this page. I hope it will inspire others to read more source code and become better engineers.



Acknowledgment : I would like to thank Miles.J from 6502.org and Roland Gustafsson (author of RWTS18) for patiently sharing their knowledge with me.



Part I : Introduction

Part II : Bootloader

Part III : Code explained



EDIT June 17th, 2013 : Jordan Mechner commented on this article (#32).

EDIT June 17th, 2013 : Andreas Varga (whom reverse engineer POP before the source code release) also commentd (#41) !





Where to start ?

The source code is available in a GitHub repository and can be downloaded with one command:



git clone git://github.com/jmechner/Prince-of-Persia-Apple-II.git

The interesting part is in /Prince-of-Persia-Apple-II/01 POP Source/Source/ which contains the game engine made of numerous .S files.

That is the first thing that programmers back then did not have: High level languages with high quality compilers. To achieve high performances developers had to work down to the metal using 6502 assembly. This is what those .S files are.

According to Jordan Mechner's book: Making of Prince of Persia, POP used Merlin assembler.



One of the good feature of Merlin is the ORG directive which allows to hint the assembler where the instructions will be loaded in RAM: In POP, there is a ORG directive at the top of every files.



Trivia : ORG directives were really just hints. There was no operating system and no linker/loader on Apple II: The developer had to "somehow" manage to transfer the instructions from floppy disc to the intended location.

