Recomp #02
0 Lines of Code
I'm now several hours into developing Recomp and have successfully written 0 lines of code. I do know more about CDs than I ever thought I would though. It turns out that extracting (and verifying) the contents of a 30-year-old CD was a little more involved than I anticipated.
Since the goal of this project is to eventually incorporate formal verification, I needed to make sure that the data I was working with was correct from the start. I probably could've downloaded a copy of Crash Bandicoot from somewhere online, but that feels like cheating.
Dumping the Disc
I picked up a copy of Crash Bandicoot from CeX this morning. It turned out to be an Australian Platinum release of the game, with the serial SCES-00344.

I'm using an ASUS SDRW-08D2S-U external optical drive alongside a piece of software called Redumper to create a raw image of the disc.
The first attempt to dump the disc produced a huge number of errors. I was initially worried that the disc hadn't survived 30 years - I don't have a PS1 to check it runs normally - but thankfully some trial and error got things working.
The original PlayStation uses the CD-ROM XA format, in which each raw sector contains 2,352 bytes. In a typical Mode 2 Form 1 sector, only 2,048 of these bytes contain user data, with the remainder dedicated to synchronisation, headers, error detection and error correction.
When reading a sector, the optical drive can also return 96 bytes of subchannel data, which contains additional info such as track positioning and timing, as well as C2 error pointers which indicate potentially erroneous bytes.
The first issue I came across was that Redumper was expecting this information to be returned as DATA_C2_SUB, with the C2 errors in the middle. However, my drive was actually returning DATA_SUB_C2, causing Redumper to interpret subchannel information as error pointers, producing hundreds of read errors that didn't actually exist. Correcting this removed C2 errors entirely.
Unfortunately, the issues don't end there. Redumper was still failing when attempting to produce the final disc image, leading to another concept: CD sector scrambling.
Data sectors on a CD are scrambled using a predictable sequence before being recorded as a means of improving the recording characteristics of the disc. Redumper normally attempts to retrieve data sectors using audio-sector reads to obtain the scrambled data. However, not all drives handle this in the same way and it is not straightforward to find out how my specific drive does it. Using the flag --force-unscrambled Redumper is able to read the data sectors normally.
On the fourth attempt, I finally had a usable disc image.
Verification
Redumper was initially developed for a project called Redump, a disc preservation project. They maintain a database of metadata and checksums for optical media. This made it easy to establish whether the data from my disc was correct and had been read correctly.
My Crash Bandicoot disc image had the following properties:
| Property | Value |
|---|---|
| Format | MODE2/2352 |
| Tracks | 1 |
| Sectors | 267,697 |
| Size | 629,623,344 bytes |
| CRC32 | fd11eb1e |
| MD5 | c50abf968e9c2edff47ad8235d84c04a |
| SHA-1 | e95b3dd1deebf32f33a7194535353cc8f2d7cab5 |
All three checksums match the Redump entry. A single changed bit would most likely produce a completely different SHA-1 hash, so I can be confident that I have an accurate copy of the main data track. I have also generated a SHA-256 for future verification use.
Extracting the Files
Using IsoBuster, I was then able to extract the files within the ISO:
S0/
S1/
S2/
S3/
SCES_003.44
SYSTEM.CNF
ZBSPTREE.WAD
SCES_003.44 is the executable file and SYSTEM.CNF contains the boot configuration used by the PlayStation. The SHA-256 checksums of these two files have been compared against the original disc.
At this point, even I was starting to wonder why I went through so much effort to get files that were readily available in File Explorer. I've spent close to three hours fiddling with optical drive settings to extract the same files I could've just copied from the disc.
However, this process wasn't technically just to retrieve these files. On the original hardware, the PlayStation's CD-ROM controller allows games to read data directly from specific sectors on the disc. The extracted files themselves wouldn't necessarily preserve all the information needed to reproduce this behaviour. For the initial stages of this project, the copied files would've worked fine, but eventually I'll be reproducing the behaviour of that CD-ROM controller, so I'm starting as I mean to continue.
What's Next?
I've spent some time trying to understand the PlayStation architecture using this analysis by Rodrigo Copetti as well as manually looking through the executable in a hex editor to try and understand the structure of the PS-X EXE format and MIPS instructions.
The first piece of actual Rust code will be a parser for PS-X EXE, allowing me to retrieve the information required to load the executable. From there, I'll be working on decoding the instructions themselves.
A lot of work for no code, but at least now I'm an expert in reading CDs.
- Jack