How PCSX2 grabs metadata from a PlayStation/PlayStation 2 disc

Mohammed Ahmed
3 min readSep 24, 2020

Emulators might seem basic on the outside, but don’t be deceived; they are an absolute mess. Look at PCSX2: The PlayStation 2 emulator that runs on WXWidgets and a lot of C++. As of version 1.6.0, most of the PlayStation 2’s library is deemed as “playable”, meaning that you can play the game from start to finish. As basic as that sounds, there’s a lot of work behind the scenes; one piece of code in particular interests me the most.

First off, the entire catalog of PlayStation and PlayStation 2 games are counted in the thousands. That’s a lot of games! So it’s understandable that Sony needs to catalog them in a database in order to keep track on what’s released. Well… how *do* they keep track?

The Contents of Sly Cooper and the Thevius Raccoonus (2002, Sucker Punch Productions)

Sony has a unique ID System in which it describes the following: The Game’s Region Code (eg. North America, Europe, Australia, Japan[].), and the game’s Catalogue ID (For Sly Cooper, it’s 97198). We’re not done yet, since Sony required games to have a file called “SYSTEM.CNF”. This file directly tells the PlayStation 2 the following: What video-mode the game will run in (eg. NTSC, PAL, NTSC-J), Software Version, and file structure properties (eg. what file to read first, how it should be read.)

“That’s a great explanation, and all, but what about PCSX2? How does that work?” — Don’t worry, I hear ya. PCSX2 has an interesting function that reads SYSTEM.CNF.

Snippet of GetPS2ElfName() [PS1 Disc ==1, PS2 Disc == 2, Unknown Disc == 0]

If this is confusing, don’t worry, we’ll break this down. Let’s start with the top. We initialize a variable called ‘retype’ (of type ‘int’) and set it as 0. We’re gonna use this variable to check whether or not the user has inserted a PlayStation 1 Disc, PlayStation 2 Disc, or something else.

Not all SYSTEM.CNF’s are created equal, so we ignore characters, so long as the main portion of the data is still there.

The first portion of the decision tree checks if there’s any extra characters inside SYSTEM.CNF. The file itself isn’t created equally, as developers might pad the file, or add additional information. We want to ignore that without raising an error, so this checks for Unusual Entries.

The main meat of the function itself, we check for the metadata. [BOOT2 = PS2, BOOT = PS1]

Now, this is where the meat of the function lies. All those if statements will be executed at least once, while the file is still open.

The first if statement looks for what system, the game is supposed to be run on. Since the PlayStation 2 was fully compatible with PlayStation Discs, we check if we’re running a PlayStation game (known as BOOT in SYSTEM.CNF), or a PlayStation 2 game (known as BOOT2 in SYSTEM.CNF). Once we check what system the game is on, we then check what video-mode to run this in (PAL, NTSC, NTSC-J), and Software Version the disc contains.

The last portion of the function is meant for error checking

The last couple of lines in the function is meant for error checking. If we pass a bad FileStream, or the file isn’t found, we return the value of 0. If any of those isn’t true, we just return our ‘retype’ variable.

For such a small function, it really does a lot! How else am I gonna play my copy of Sly Cooper and the Thevius Raccoonus at 4K, while talking to my friends through Discord? The power of emulation, baby!

--

--

Mohammed Ahmed
0 Followers

Transit Enthusiast, and Games Enthusiast