A sample programming environment that lets coders easily compare the compiled results of their code to the actual game ROM in close to real time.
A sample programming environment that lets coders easily compare the compiled results of their code to the actual game ROM in close to real time.
Even converting a small function of a few assembly instructions in this manner can be a complicated process. But individual N64 functions can run into the thousands of instructions, and a single N64 game can have thousands of such functions (over 15,700 in the case of Ocarina of Time, for one example).
The difficulty can vary by game, as well. For Super Mario 64, Nintendo compiled its source code without any fancy compiler options, meaning the decompiled assembly language is simpler to convert back to C code. For a game like Ocarina of Time, though, Nintendo used optimization flags to generate faster code, making the resulting ROM that much harder to untangle back into its source.
“When there are optimization flags, you have a harder time matching a loop to a ‘for’ vs ‘while’ [statement] etc.,” Kenix said. “You have to try all equivalent patterns of code until you find the one that matches.”
More than just ports
Mario looks great in high-definition thanks to a PC port, but that’s not the main point of decompilation efforts.
While ZRET leadership understands that PC ports are going to be a natural result of their efforts, Kenix said reverse engineers “consider that outside of the scope of what we do. We just decompile the game. Someone else will inevitably pick it up and write the PC port.”
But even with decompiled C code in hand, making a PC port is “not as easy as just [saying] ‘compile it for Windows,’” ZRET member Rozlette noted. “There is a lot of code that deals with talking to N64 hardware. The N64 render pipeline is very different than modern OpenGL, for example.”
The process is “close but not quite” as complex as just writing an N64 emulator in the first place, Kenix said. “It remains quite difficult, especially when considering changes that are considered implicit with a PC target, like being able to change the resolution or framerate,” ZRET member Roman added.
Ports aside, having the source code opens up a potential new world of mods and hacks that would be difficult or impossible by just building on top of the binary ROM. Before Zelda decompiling efforts even began in earnest, for instance, more basic reverse-engineering efforts were key to discovering the amazing method for getting Star Fox 64‘s Arwing into Ocarina of Time.