opensourceprojects.dev

A broadsheet for software that doesn't ask for your email

Statically recompile N64 binaries into portable C with this tool
GitHub RepoImpressions2

Project Description

View on GitHub

Breathing New Life into N64 Games: Static Recompilation with n64recomp

You've probably seen the painstaking work that goes into decompiling classic games—teams spending years matching original compiler output byte-for-byte just to get a portable C codebase. But what if you didn't need to fully understand a game's code to port it? What if you could take the raw binary and mechanically translate it into C that runs anywhere? That's exactly the problem n64recomp tackles, and it does so with a surprisingly straightforward approach.

What It Does

N64: Recompiled is a tool that statically recompiles N64 binaries into C code you can compile for any platform. Unlike dynamic recompilation (which translates code at runtime) or interpretation (which simulates each instruction), static recompilation analyzes the binary upfront and produces standalone C source files.

The workflow is simple: you feed the tool a binary along with a list of symbols and metadata. It splits the binary into individual functions, then processes each MIPS instruction one-by-one, emitting corresponding C code as it goes. The translation is deliberately literal to keep complexity low. For example, the instruction addiu $r4, $r4, 0x20 becomes ctx->r4 = ADD32(ctx->r4, 0X20);—no clever optimizations, just a direct mapping that preserves behavior.

The recompiler has been tested primarily with old MIPS compilers like gcc 2.7.2 and IDO (the SGI compiler used for many N64 titles), as well as modern clang targeting MIPS. It can also handle both statically linked and relocatable overlays, emitting function lookups for indirect jumps that a runtime can resolve dynamically.

Why It's Cool

The elegance here is in how the project sidesteps the hardest part of N64 preservation. Instead of reverse-engineering a game's logic to write clean C from scratch, you get working C that's mechanically derived from the original binary. That's a fundamentally different trade-off, and it opens up some interesting possibilities.

  • It's not decompilation, and that's fine. Decompilation projects aim for human-readable, maintainable code that matches the original. n64recomp aims for runnable code. The output is ugly—full of ctx->rN register references and macro calls—but it compiles and runs correctly. Sometimes that's all you need.

  • Performance without the interpreter tax. The README notes this can simulate behaviors significantly faster than interpreters or dynamic recompilers. Since you're compiling straight to native code, you skip the overhead of instruction dispatch and translation caches entirely.

  • It follows a proven lineage. The project takes inspiration from IDO static recompilation, which recompiles the SGI IDO compiler itself to run on modern systems. That project enabled matching decompilation of N64 games by making the original toolchain available again. n64recomp applies the same idea to game binaries themselves.

  • Clever handling of tricky control flow. Branch delay slots (a quirk of MIPS architecture where the instruction after a branch always executes) are handled by duplicating instructions as needed. The recompiler even attempts to convert jr instructions into switch-case statements when it detects jump table usage—which is how C compilers implement switch statements on MIPS.

  • It pairs with a real runtime. The output isn't meant to run standalone. You're expected to use it with N64ModernRuntime, which provides the macro implementations and hardware abstraction needed to actually execute the recompiled code. That runtime powers Zelda 64: Recompiled, a real project that gets Majora's Mask running on PC this way.

How to Try It

If you want to experiment with this, you'll need to build the tool from source. The repository doesn't ship prebuilt binaries, so you'll be compiling it yourself. Head over to the n64recomp GitHub repository and check the Building section in the README for the specific dependencies and commands.

Once built, you'll need three things to actually recompile a binary:

  1. An N64 binary (a ROM or extracted executable)
  2. A symbol list and metadata file describing the functions you want to extract
  3. A runtime implementation to actually run the output

The tool currently outputs each recompiled function into its own C file, which can make build times slow due to file I/O. The README notes that grouping functions into fewer files is a possible future enhancement.

If you're curious about seeing this in action, look at the Zelda 64: Recompiled project—it's the most complete demonstration of what this approach can achieve.

Final Thoughts

n64recomp isn't for everyone. If you're doing clean-room reverse engineering or aiming for fully decompiled, human-readable source code, this isn't the tool for you. But if you want to get N64 code running on modern platforms without years of manual analysis, it's a genuinely clever shortcut. The literal translation approach means the output won't win any beauty contests, but it works—and it's already proven itself with at least one major title.

The project is honest about its limitations too. Modern MIPS GCC optimizations can trip it up, and you'll need to pick specific compilation flags to avoid those cases. But for old compilers and clang targeting MIPS, it handles things well. For anyone interested in N64 preservation, tooling, or just the sheer audacity of mechanically translating assembly to C, this is worth a look.

Follow @githubprojects for more developer tools and open source projects.

Back to Projects
Project ID: a118c447-ed2d-4870-80b2-12f74c3cb588Last updated: September 6, 2026 at 02:43 AM