Extracted Mac resource files (PoP 1 and 2)

About PR usage and development, and about the POP format.
Post Reply
Falcury
Calif
Calif
Posts: 565
Joined: June 25th, 2009, 10:01 pm

Extracted Mac resource files (PoP 1 and 2)

Post by Falcury »

The Mac resources are mostly stored in resource forks.
These resources are a bit difficult to get at, because there is no easy/obvious way to extract them.
Apple published a utility for editing the resources, but that program can't extract them.
I managed to extract them using rezycle, which runs on Mac OS X.

For PoP1, the main file "Prince of Persia" contains: the code and data segments, menus/error messages/prompts, icons, fonts, levels, color palettes, sounds and music, plus some other stuff that I cannot identify.
The graphical data has three separate variants: black/white, grayscale and color.

For PoP2, the data is spread out over many more separate files.
The main file "Prince of Persia 2" contains: the code and data segments, menus/error messages/prompts, icons, fonts, levels, music instruments and MIDI driver stuff, and yet more things that I cannot identify.
Interestingly, the PoP2 code segments retain a lot of symbol information.
The "Data" subdirectory of PoP2 for Mac contains the rest of the data files.
There are four files with a .dat extension: DigiSnd.dat, MIDISnd.dat, NISDIGI.dat, and NISMIDI.dat.
The .dat files do not have any resources hidden away in a 'resource fork'. However, all the other files (those with a .rsrc extension) do.
The .rsrc files mostly match the DOS DAT equivalents. Although there seems to be no equivalent for SEQUENCE.DAT (I guess that is the sequence table).

In the attached zip files, I only included the extracted resource forks.

Edit:
It would be nice to somehow get all of those code segments into a disassembly database.
Unfortunately, IDA Freeware does not support m68k code. Maybe there are alternatives.
Attachments
PoP1MacResources.zip
(528.56 KiB) Downloaded 232 times
PoP2MacResources_1.zip
(4.32 MiB) Downloaded 202 times
PoP2MacResources_2.zip
(2.47 MiB) Downloaded 211 times
David
The Prince of Persia
The Prince of Persia
Posts: 2848
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Extracted Mac resource files (PoP 1 and 2)

Post by David »

I'm wondering where are you going with this...

It probably won't surprise some people that I have already looked into the files of PoP1 and 2 for the Mac, some many years ago.
Maybe it's time to post my findings on our wiki or otherwise?
Falcury wrote: April 19th, 2018, 11:06 pm The Mac resources are mostly stored in resource forks.
These resources are a bit difficult to get at, because there is no easy/obvious way to extract them.
Apple published a utility for editing the resources, but that program can't extract them.
I managed to extract them using rezycle, which runs on Mac OS X.
Well, you can run that; I had to make my own extractor from scratch and without any documentation on the format of the resource fork.
Although later I found this: https://developer.apple.com/legacy/libr ... ox-99.html
Falcury wrote: April 19th, 2018, 11:06 pm The graphical data has three separate variants: black/white, grayscale and color.
Note that PoP1 graphics is stored in the *data* fork of the files, the resource fork includes only pointers into that data.
Also, you can find the extracted PoP1 Mac graphics here: viewtopic.php?p=17961#p17961
Falcury wrote: April 19th, 2018, 11:06 pm Interestingly, the PoP2 code segments retain a lot of symbol information.
I briefly mentioned that here: viewtopic.php?p=19625#p19625
Falcury wrote: April 19th, 2018, 11:06 pm The "Data" subdirectory of PoP2 for Mac contains the rest of the data files.
There are four files with a .dat extension: DigiSnd.dat, MIDISnd.dat, NISDIGI.dat, and NISMIDI.dat.
The .dat files do not have any resources hidden away in a 'resource fork'.
Those files contain sounds and music.
I have recently posted a tool that can extract them: viewtopic.php?p=19618#p19618
Falcury wrote: April 19th, 2018, 11:06 pm However, all the other files (those with a .rsrc extension) do.
The .rsrc files mostly match the DOS DAT equivalents.
Someone has posted the Mac PoP2 sprites here: viewtopic.php?f=64&t=3439
On a related note, I have an old unreleased program called PrDatView which can display Mac PoP2 images (and also DOS PoP1&2 images).
Falcury wrote: April 19th, 2018, 11:06 pm Although there seems to be no equivalent for SEQUENCE.DAT (I guess that is the sequence table).
Those are in Prince.rsrc, in SEQS.
Falcury wrote: April 19th, 2018, 11:06 pm Edit:
It would be nice to somehow get all of those code segments into a disassembly database.
Unfortunately, IDA Freeware does not support m68k code. Maybe there are alternatives.
Dunno; I have found dasm68 back then, but it's a "dumb" disassembler, i.e. it can't even skip those parts that are not machine code.
So I made my own disassembler, like I did with PoP1 SNES, that follows the flow of the code and can add annotations to the disassembly from an external file.
I didn't post it anywhere yet, though.
Falcury
Calif
Calif
Posts: 565
Joined: June 25th, 2009, 10:01 pm

Re: Extracted Mac resource files (PoP 1 and 2)

Post by Falcury »

David wrote: April 21st, 2018, 4:26 pm I'm wondering where are you going with this...
Well, it's mostly curiosity... but aside from that I was also wondering how the drawing code of the Mac version compares to the DOS drawing code. I was thinking, if we can figure out the differences from the disassemblies, then maybe we could also port those differences over to SDLPoP, in order to support the Mac graphics. Of course, you have already made a lot of progress toward that goal, which you posted in this thread: viewtopic.php?f=126&t=3810

And I am also interested in seeing if we can use the Mac version's MIDI instrument definitions.
David wrote: April 21st, 2018, 4:26 pm It probably won't surprise some people that I have already looked into the files of PoP1 and 2 for the Mac, some many years ago.
Maybe it's time to post my findings on our wiki or otherwise?
David wrote: April 21st, 2018, 4:26 pmI had to make my own extractor from scratch
David wrote: April 21st, 2018, 4:26 pmI have an old unreleased program called PrDatView which can display Mac PoP2 images (and also DOS PoP1&2 images).
David wrote: April 21st, 2018, 4:26 pmI made my own disassembler, like I did with PoP1 SNES, that follows the flow of the code and can add annotations to the disassembly from an external file.
I didn't post it anywhere yet, though.
Wow, I would definitely be interested in all of the above!
David
The Prince of Persia
The Prince of Persia
Posts: 2848
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Extracted Mac resource files (PoP 1 and 2)

Post by David »

Falcury wrote: April 21st, 2018, 5:49 pm Wow, I would definitely be interested in all of the above!
Here is "PrDatView" for a start.
Beware, it's very old; I think I started it in 2006. The source is messy, and the GUI is in Hungarian only.
But at least the hotkeys in the menu give some hints on what each menu item does.
Attachments
PrDatView.zip
(338.97 KiB) Downloaded 182 times
David
The Prince of Persia
The Prince of Persia
Posts: 2848
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Extracted Mac resource files (PoP 1 and 2)

Post by David »

Next up, here are the disassemblies of Mac PoP1 and 2.
I also included my custom diassembler (written in PHP).
Attachments
PoP_mac_disasm.zip
(1.88 MiB) Downloaded 190 times
David
The Prince of Persia
The Prince of Persia
Posts: 2848
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Extracted Mac resource files (PoP 1 and 2)

Post by David »

Here is the program that extracts PoP1 Mac graphics (written in PHP).
You can find the graphics themselves here: viewtopic.php?p=17961#p17961
Attachments
PoP1_mac_graphics.zip
(4.01 KiB) Downloaded 193 times
David
The Prince of Persia
The Prince of Persia
Posts: 2848
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Extracted Mac resource files (PoP 1 and 2)

Post by David »

Then here are the sounds of PoP1 Mac together with the program that converted them from Mac format to WAV.
It also handles compressed waves (csnd).
(This converter doesn't extract the data from the PoP executable, I did that with PrDatView.)
Attachments
PoP1_mac_sounds.zip
(568.07 KiB) Downloaded 193 times
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5745
Joined: April 9th, 2009, 10:58 pm

Re: Extracted Mac resource files (PoP 1 and 2)

Post by Norbert »

David wrote: April 21st, 2018, 7:21 pmThen here are the sounds of PoP1 Mac
I wonder what those res60* (and res5038.wav) sound effects were used for.
(I've never really played the Mac version.)
David
The Prince of Persia
The Prince of Persia
Posts: 2848
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Extracted Mac resource files (PoP 1 and 2)

Post by David »

Norbert wrote: April 21st, 2018, 9:41 pm I wonder what those res60* (and res5038.wav) sound effects were used for.
(I've never really played the Mac version.)
res60##.wav are the samples of the instruments, for MIDI music.

res5038.wav is, I think, the sound played when the "Press any key to continue" message blinks.
(sound_names.txt calls it "warning".)
At least, in the DOS version (and SDLPoP), sound 38 is used for this purpose: https://github.com/NagyD/SDLPoP/blob/ma ... 000.c#L894
By the way, SDLPoP can't play that sound. See here why: viewtopic.php?p=16433#p16433

Here is also the corresponding part from the PoP1 Mac disassembly. (0x0026 = 38)

Code: Select all

03:01bc: 0c 47 00 03              CMP.W  #0x0003,D7
03:01c0: 66 34                    BNE    B_01F6
03:01c2: 48 6d 96 a0              PEA    (D_96A0,A5) ; "Press any key to continue"
03:01c6: 4e ad 05 42              JSR    (D_0542,A5) ; = Entry 0xa4 = 04:5B6E ; show status text
03:01ca: 3e bc 00 26              MOVE.W #0x0026,(A7)
03:01ce: 4e ad 00 fa              JSR    (D_00FA,A5) ; = Entry 0x1b = 02:2A5A ; play sound (immediately)
03:01d2: 58 8f                    ADDQ   #4,A7
03:01d4: 60 20                    BRA    B_01F6
Falcury
Calif
Calif
Posts: 565
Joined: June 25th, 2009, 10:01 pm

Re: Extracted Mac resource files (PoP 1 and 2)

Post by Falcury »

I find myself once again deeply in awe of your work, David. :)
Falcury
Calif
Calif
Posts: 565
Joined: June 25th, 2009, 10:01 pm

Re: Extracted Mac resource files (PoP 1 and 2)

Post by Falcury »

David wrote: April 22nd, 2018, 11:23 am res60##.wav are the samples of the instruments, for MIDI music.
I wonder if these were used as a fallback method for playing back the MIDI music, on systems that lacked a proper synthesizer chip.
(Sort of like a module file.)

I think I can hear them being used, when I run the game within the SheepShaver emulator. (The music sounds heavily 'compressed', which is understandable if the musical notes are not synthesized, but wave files with a modulated pitch.)
David
The Prince of Persia
The Prince of Persia
Posts: 2848
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Extracted Mac resource files (PoP 1 and 2)

Post by David »

Falcury wrote: April 24th, 2018, 11:12 pm
David wrote: April 22nd, 2018, 11:23 am res60##.wav are the samples of the instruments, for MIDI music.
I wonder if these were used as a fallback method for playing back the MIDI music, on systems that lacked a proper synthesizer chip.
(Sort of like a module file.)
I thought the game always uses these samples for instruments.

Now I tried two things (in BasiliskII):
If I delete the instrument samples, then there will be no music.
If I replace them with another sound (for example "scream"), then that sound will be used for music.

This means that, at least on my (emulated) system, PoP uses these samples.
Falcury
Calif
Calif
Posts: 565
Joined: June 25th, 2009, 10:01 pm

Re: Extracted Mac resource files (PoP 1 and 2)

Post by Falcury »

David wrote: April 28th, 2018, 12:20 pm I thought the game always uses these samples for instruments.

Now I tried two things (in BasiliskII):
If I delete the instrument samples, then there will be no music.
If I replace them with another sound (for example "scream"), then that sound will be used for music.

This means that, at least on my (emulated) system, PoP uses these samples.
I guess you're right.
It looks like the instrument definitions (apparently I can view them in ResEdit!) also support this. They contain references to the wave sounds:
pop1mac_resedit_instruments.png
(By the way, strangely, opening PoP1's 'INST' resources in ResEdit's INST resource editor only seems to work properly after I first open one of the 'INST' resources from PoP2. If I don't do that first, I only get a hex editor view.)
David
The Prince of Persia
The Prince of Persia
Posts: 2848
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Extracted Mac resource files (PoP 1 and 2)

Post by David »

Falcury wrote: April 28th, 2018, 1:09 pm (By the way, strangely, opening PoP1's 'INST' resources in ResEdit's INST resource editor only seems to work properly after I first open one of the 'INST' resources from PoP2. If I don't do that first, I only get a hex editor view.)
That's because PoP2 contains some TMPL resources from with ResEdit can "learn" the format of some of PoP's custom resources.
It looks like ResEdit can use TMPLs from one file (PoP2) for resources from another file (PoP1).
Post Reply