New static recompiler tool N64Recomp aims to seamlessly modernize N64 games

zelda.png

As each year passes, retro games become harder and harder to play, as the physical media begins to fall apart and becomes more difficult and expensive to obtain. The onward marching of time and evolution of technology also means that video games that were once landmark titles in their day, are now thought of as clunky, awkward, or just not viable by today's standards.

These reasons are why so many individuals have dedicated years of their lives to reverse engineering beloved video games, combining their efforts to create decompilations that allow for classic games to be experienced in new ways, on new technology, with new features and improvements that were never possible on original hardware or through emulation. These decompilation projects take massive amounts of effort, however; for example, one such undertaking for The Legend of Zelda: Majora's Mask, has been worked on since early 2021, and after years of steady, painstaking progress, is still not yet ready for release.

A new piece of software might be a big game-changer in that department, though. A modder by the name of Mr-Wiseguy quietly released two projects--one of which is titled Zelda 64: Recompiled, which can play The Legend of Zelda: Majora's Mask with numerous modern-day features, including support for autosaves, ultrawide resolutions, high framerates, gyro aiming, custom textures, and more. All of this can be utilized by downloading his release of Zelda 64: Recompiled, and providing your own legal cart dump of Majora's Mask.



According to Mr-Wiseguy, the project was made using a tool he created: N64 Recomp. It is a static recompiler for Nintendo 64 games that can turn N64 binaries into C code, and then be compiled into a platform of your choosing. By using N64 Recomp, the modder was able to create "recompilations" of Nintendo 64 games that lack decompilations, such as Rocket Robot on Wheels, Banjo-Kazooie, and Superman 64.

A highly-detailed breakdown of the process is explained below.

The recompiler works by accepting a list of symbols and metadata alongside the binary with the goal of splitting the input binary into functions that are each individually recompiled into a C function, named according to the metadata.

Instructions are processed one-by-one and corresponding C code is emitted as each one gets processed. This translation is very literal in order to keep complexity low. For example, the instruction addiu $r4, $r4, 0x20, which adds 0x20 to the 32-bit value in the low bytes of register $r4 and stores the sign extended 64-bit result in $r4, gets recompiled into ctx->r4 = ADD32(ctx->r4, 0X20); The jal (jump-and-link) instruction is recompiled directly into a function call, and j or b instructions (unconditional jumps and branches) that can be identified as tail-call optimizations are also recompiled into function calls as well. Branch delay slots are handled by duplicating instructions as necessary. There are other specific behaviors for certain instructions, such as the recompiler attempting to turn a jr instruction into a switch-case statement if it can tell that it's being used with a jump table. The recompiler has mostly been tested on binaries built with old MIPS compilers (e.g. mips gcc 2.7.2 and IDO) as well as modern clang targeting mips. Modern mips gcc may trip up the recompiler due to certain optimizations it can do, but those cases can probably be avoided by setting specific compilation flags.

Every output function created by the recompiler is currently emitted into its own file. An option may be provided in the future to group functions together into output files, which should help improve build times of the recompiler output by reducing file I/O in the build process.

Recompiler output can be compiled with any C compiler (tested with msvc, gcc and clang). The output is expected to be used with a runtime that can provide the necessary functionality and macro implementations to run it. An example of most of the required macro implementations can be found in the Zelda 64: Recompiled project here, with the project also containing accompanying code for implementing the rest of the required runtime.

Additionally, a collaborative video between Mr-Wiseguy and YouTuber Narrel was released, which goes into further technical explanation on how the tool works, and what it can be capable of. It also showcases demos of recompiled games running.



Zelda 64: Recompiled currently supports The Legend of Zelda: Majora's Mask, with plans to support Ocarina of Time soon. A release on GitHub is linked below. N64 Recomp is not publically available yet, though you can browse the GitHub page for the project below as well, so that you can keep up to date on any new updates as they happen.

:arrow: Source: Zelda 64 Recompiled GitHub
:arrow: Source: N64Recomp GitHub
 

Rune

Well-Known Member
Member
Joined
Feb 15, 2017
Messages
704
Trophies
0
XP
2,482
Country
United Kingdom
I wanna try and combine all the WCW/WWF N64 AKI games into one. Also, play Ogre Battle 64 without awful emulation sound glitches.
This was the first thing I thought about also. The thought of what this could do for No Mercy and all the potential mods for it.
 

Gamemaster1379

Well-Known Member
Member
Joined
May 5, 2008
Messages
839
Trophies
1
Age
29
Location
United States
Website
1379tech.110mb.com
XP
2,278
Country
United States
Are there similarly maintained projects for NES and SNES? Some quick Google searching doesn't turn up as much.

I'd love some (reasonably) ready made tools where I can throw my own ROMs at NES/SNES and the like and make some ready made executables for Windows and Linux for these old games.
 

drasglaf

Member
Newcomer
Joined
Mar 21, 2020
Messages
8
Trophies
0
Age
54
XP
306
Country
Spain
This is amazing! I just tried Majora's Mask and it runs great. I wonder if there'll ever be similar projects for other consoles from that time.
 

regnad

Button Masher
Member
Joined
May 19, 2008
Messages
2,520
Trophies
1
Age
53
XP
3,708
Country
Japan
Feels like I'm getting 10000000 fps. It's weird.

I don't understand how autosave works. It doesn't seem to be autosaving, even though I have it toggled on. Honestly I would like to have save states, especially with this particular game. Or at least something akin to standby/sleep.
 
Last edited by regnad,

urherenow

Well-Known Member
Member
Joined
Mar 8, 2009
Messages
4,811
Trophies
2
Age
48
Location
Japan
XP
3,719
Country
United States
Seems almost too good to be true. When I see Wave Race 64 at 60fps with widescreen and all the bells and whistles I'll be happy.
Really? But why? We have MAME. Games that were designed for the N64 are great and all, but pretty much every single port of an arcade game on it sucks balls. Killer Instinct Gold is a prime example. Not a thing like the Arcade.
 

ciaomao

Well-Known Dude
Member
Joined
Feb 20, 2014
Messages
582
Trophies
1
XP
1,971
Country
Albania
but such a tool is not completely new, even if it now seems to offer much more.
what kind of decompiler tools were there back in the Bung/Dextrose/LaC days? :huh:i remember tinkering with/decompiling roms on my 386 back then. i just couldn't do anything with the resulting code back then.
 
  • Like
Reactions: KiiWii and osaka35

osaka35

Instructional Designer
Global Moderator
Joined
Nov 20, 2009
Messages
3,757
Trophies
2
Location
Silent Hill
XP
6,003
Country
United States
i read through the github, but I'm still not 100% on the extent and limits. I need to play around with this, and the apparent others floating around. maybe i can fix megaman 64...
 

urherenow

Well-Known Member
Member
Joined
Mar 8, 2009
Messages
4,811
Trophies
2
Age
48
Location
Japan
XP
3,719
Country
United States
except it isnt
I stand corrected. It's arguably a copy though. Namco Released Wave Racer in the Arcades in '95. This was released in '96. But there was a '92 GameBoy Wave Race... And then Sega released their Wave Runner also in '96. I think my confusion is justified. :grog:
 

cearp

瓜老外
Developer
Joined
May 26, 2008
Messages
8,737
Trophies
2
XP
8,578
Country
Tuvalu
Very cool but don't think this makes things simple now for non devs.
For example, using this on Mario Kart 64:
It's not going to output variables named "MARIO_SPEED", "LUIGI_SPEED" etc, you're not going to know where the course track data is or what means what when you do find it.

There's still a lot of work that needs to be done after using a tool like this.
This tool turns the game into C code but it doesn't mean the C code is nice!

Not take away from the tool, just trying to clear up misunderstandings, this isn't all you need and it will not magically port the game to vita or add wide-screen support for you!
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    The Real Jdbye @ The Real Jdbye: don't mind me, just liking all of SDIO's posts, they deserve it for...