Prince Of Persia Code Review: Part 3 (POP Bootloader explained)
Now that we have all the knowledge necessary, we can read the source and
understand where each files are located in the incredible mess that is the Apple II
RAM layout.
You can also find an heavily commented version of the source code on GitHub.
Part I : Introduction
Part II : Bootloader
Part III : Code explained
Here is a drawing of the infamous RAM that will be updated as we read on :
BOOT.S
BOOT.S
start by outputting $01
to the instruction stream (line:21). This will trigger the Apple firmware to automatically
load one sector from track:0 to the RAM at $800
and branch there :
After setting up a few soft-switches, BOOT.S
uses RWTS16 to load a bunch of sectors to RAM using skewing table table (line:79). It turns out those sectors contains the rest of BOOT.S
and RWTS18 routines :
After moving RWTS18 routines to an other bank at $D000
(so it can be used easily), it uses RWTS18 to load the entire track 1 to
$E000
(line:136) and jump to a mysterious $ee00
.
HIRES.S
We have no idea what was on track 1 and what is supposed to be at $ee00
.
But we can use grep to find out:
fabiensanglard$ find . -name "*.S" -exec grep -H "org = \$ee00" {} \; ./01 POP Source/Source/HIRES.S:org = $ee00 ./01 POP Source/Source/MOVER.S:org = $ee00
After a bit of exploration, it turns out we are interested in HIRES.S
.
HIRES.S
features a jump table at the beginning...that takes us to an other mysterious location: $f880
(line:13).
MASTER.S
Again, we have no idea what is supposed to be at $f880
.
But we can use grep to find out:
fabiensanglard$ find . -name "*.S" -exec grep -H "org = \$f880" {} \; ./01 POP Source/Source/MASTER.S:org = $f880 ./04 Support/MakeDisk/S/MASTER.S:org = $f880 ./04 Support/MakeDisk/S/MASTER525.S:org = $f880
So at $f880
is the content of MASTER.S
. We can edit the memory map:
The content of MASTER.S
is as follow :
jmp FIRSTBOOT jmp LOADLEVEL jmp RELOAD jmp LoadStage2 jmp RELOAD jmp ATTRACTMODE jmp CUTPRINCESS jmp SAVEGAME jmp LOADGAME jmp DOSTARTGAME jmp EPILOG jmp LOADALTSET
At this point the game engine has been loaded in RAM and it is about to load the legendary DOUBLE-HIGH intro screen :
Next
That is it for now. I am unsure people are really interested in more POP Code Review. Let me know.