Incoherent ramblings, devlogs, edgy philosophy and other topics of interest

[#49] [Sat, 24 Jul 2019 11:01:51 CST][tech]
■ Super Mario 64 has been accurately decoded

Nintendo apparently left debugging symbols on the production ROM for the original Super Mario 64. On top of that, the ROM was compiled with no compiler optimizations whatsoever. Inevitably, someone took advantage of this and decompiled the ROM, then recompiled the resulting code and surprisingly enough, the hashes of both ROMs match. This means that the decompiled code is an exact reproduction of the original Super Mario 64 source code made back in the early 90s, with the only distinction being the loss of the all variable and function names as the compiler replaced them with its own identifiers. Making the source code a challenge to navigate.

Still, someone actually took the time to decipher all the gibberish, and by the time the team was around 60% done (by their own estimates) someone leaked the project. I was lucky enough to download it just before the sole link I could find was taken down and after a quick peek at the code I can confirm the team did a great job, the code has been restored enough to be mostly readable. The fact that so much has already been decoded means it's only a matter of time before the original SM64 source code is fully restored and released to the public.

Left: renamed code | Right: decode raw output
Games of this era were engineered for old, basic systems leaving little room for bloat. There were no fancy third party engines, no interpreted languages or scripting capabilities, even learning sources were extremely limited.

Super Mario 64 was written in a brutal mix of old school C and MIPS assembly that scares modern programmers, hence the lack of a reaction to the news despite the game's popularity. I found out about the leak about two weeks after it happened, hoping that at least that meant I wouldn't have to try and compile the ROM by myself, since cross compiling for old, very specific CPUs can be a long, tedious process for even the most seasoned veterans. After much fucking around in my main arch installation I finally got it to work by manually compiling build-utils and gcc for the MIPS R4300i architecture, but truth be told, I had to experiment with the dozens of available build parameters until I finally got it to compile. I would later find out that the entire process is unnecessary. Ubuntu 18 LTS actually comes with the entire MIPS build chain in their repos and it just so happens to just werk with the ROMs build process, so if you're interested in compiling your very own Super Mario 64 ROMS all you have to do is:

1. Set up an Ubuntu 18.04 LTS virtual machine (or use your main machine if you're a weenie)

2. Install the build dependencies
sudo apt-get update
sudo apt-get install sudo apt-get install make git binutils-mips-linux-gnu python3 build-essential pkg-config zlib1g-dev libglib2.0-dev libpixman-1-dev libcapstone3

3. Download the qemu-irix binary from here, give it permission to execute and add an environmental variable called "QEMU_IRIX" pointing to it
mv ~/Downloads/qemu-irix ~/Documents/ && chmod +x ~/Documets/qemu-irix
echo "export QEMU_IRIX='~/Documents/qemu-irix'" >> ~/.bashrc

4. Restart the machine.
5. Download the source code from here and compile with make. The ROM can be found in build/us/sm64.u.z64
6. Get sued by Nintendo.
ROM successfully compiled
Freshly compiled ROM running on mupen
Expect some very cool projects in the future.