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
 

NinStar

Ny'hrarr ♂
Member
Joined
Apr 3, 2017
Messages
579
Trophies
0
Age
23
Location
Rio de Janeiro
Website
ninstar.carrd.co
XP
2,153
Country
Brazil
Wonder how hard it will be to develop such a recompilation tool for other consoles beyond just n64
To be honest, I'm more surprised that they managed to do it for N64 to begin with, emulating it has always been hard because of games that uses their own microcode
 
  • Like
Reactions: Starwarsfan2099

shadow1w2

Still here.
Member
Joined
Mar 16, 2004
Messages
1,715
Trophies
2
XP
1,826
Country
United States
Oh it would be great to see sone obscure n64 games get aome improvements.
Combined with an emulator as a plugin shoukd be really neat.

Looking forward to trying some really obscure games.
Hope we get a group together to start projects on every odd game that could use the improvements.

Heck extreme g2 has a pc port already (get it for the included series soundtrack well worth it) but, a recompile of the N64 version with splitscreen multiplayer intact, rumble, analog controls intact and the PC version audio added in could be quite the improvement for instance.
Very exciting.
 

MadMakuFuuma

Well-Known Member
Member
Joined
Jun 23, 2018
Messages
193
Trophies
0
Age
40
XP
1,338
Country
Brazil
i saw the video other day and this is in fact awesome news, but it begs the question: we'll se more projects like that for other consoles too? imagine play a game with improvements without being emulator restricted.
 

Psi-hate

GBATemp's Official Psi-Hater
Member
Joined
Dec 14, 2014
Messages
1,750
Trophies
1
XP
3,438
Country
United States
for this to work, you need to locate all of the code and fixup pseudo-c mistakes not covered in the video, but basically any code that is loaded after runtime needs to be considered when using this tool. it generates compilable c code and hopes that it behaves correctly. this is different from the pseudo-c code that is generated by m2c because it's compilable, and not meant to be highly accurate, it's basically high level emulation but very automated, very targeted (at the specific game,) with extra steps. also hilariously subject to compiler mistakes, if you look at the github you can see a lot of the small stuff they had to work on to get this working. very cool but also obviously not as magically easy as Nerrel suggested
 

MikaDubbz

Well-Known Member
Member
Joined
Dec 12, 2017
Messages
3,878
Trophies
1
Age
36
XP
7,368
Country
United States
you'll be limited by hardware if you wanted it to play on original hardware. I suppose the benefit of using this sort of software over a romhack would be more control and flexibility over the final result.

a manual decompilation approach lets you label what does what in the code, and this more just converts stuff based on a template you provide (from my poor understanding). i wonder if you can comment and use plain english for stuff based on templates/metadata...either way, I'd imagine it can help speed decompilation up? I'm still iffy on the details. but decompilation projects are still the ultimate goal.

and as long as you're cool with it not being on original hardware, you'd only be limited by whatever your target device can handle. I don't actually have experience with things like that, so this tool will definitely help me learn. I'd imagine you'd be able to compile for new platforms with this if all done correctly and you knew what you were doing.

these are all the words of an inexperienced beginner, so take it with a grain of salt.
Curious why you responded this to my point about what Zelda games are gonna get HD remasters/remakes and when.
 
  • Haha
Reactions: osaka35

Coolsonickirby

Well-Known Member
Member
Joined
Dec 6, 2015
Messages
333
Trophies
0
Age
23
Website
coolsonickirby.com
XP
2,565
Country
United States
It's funny seeing everyone here calling this a "decomp" when its a "recomp" instead. A decomp takes the original code and "decomps" it to human readable stuff, while the "recomp" takes the code and does exactly what it says for modern platforms.

You aren't gonna get the decompiled code for the game, you'll just have it recompiled for modern PCs (which is still super damn impressive and amazing.)
 
  • Like
Reactions: osaka35

osaka35

Instructional Designer
Global Moderator
Joined
Nov 20, 2009
Messages
3,757
Trophies
2
Location
Silent Hill
XP
6,003
Country
United States
for this to work, you need to locate all of the code and fixup pseudo-c mistakes not covered in the video, but basically any code that is loaded after runtime needs to be considered when using this tool. it generates compilable c code and hopes that it behaves correctly. this is different from the pseudo-c code that is generated by m2c because it's compilable, and not meant to be highly accurate, it's basically high level emulation but very automated, very targeted (at the specific game,) with extra steps. also hilariously subject to compiler mistakes, if you look at the github you can see a lot of the small stuff they had to work on to get this working. very cool but also obviously not as magically easy as Nerrel suggested
thank you, i was scratching my head about where the magic sauce was. this makes perfect sense to me.



Curious why you responded this to my point about what Zelda games are gonna get HD remasters/remakes and when.
oops 🤣 sorry for responding to the wrong one. meant to reply to your response to me.
 

nWo

The Game Master
Member
Joined
Oct 20, 2016
Messages
1,004
Trophies
0
Website
www.facebook.com
XP
2,922
Country
Mexico
Holy shit, these are some great news!!! as a Nintendo player since 1991, and the N64 and Gamecube being my "Golden era" of gaming, this really brings joy to my life. About 40 % of my gaming sessions are N64 games. I just love that platform, so many DAMN GREAT games!!!

I just hope that in the near future, we can enjoy so many, many great projects that take advantage from this tool
 

fvig2001

Well-Known Member
Member
Joined
Aug 21, 2006
Messages
943
Trophies
1
XP
2,965
Country
Philippines
Ooh I wonder if this can be used to fix roms that have issues on the MiSTer FPGA like Conker (random crashes) due to strict timing. Otherwise, I can't wait to see the ports and enhancements that come out
 

beardalaxy

Member
Newcomer
Joined
Mar 9, 2020
Messages
5
Trophies
0
Age
28
Website
twitch.tv
XP
49
Country
United States
My dream of a modernized Star Fox 64 are so close I can practically taste it.
There is at least a decompilation of it going on at the moment, and getting very close. Pretty much all that's left is some really hard stuff. I'm not too privy on how it all works but it seems like they skipped over it to work on other, easier aspects first and now they're onto things that are a lot harder. The whole project got up to 95% within 5 or 6 months. Hopefully, someone will come along once it is decompiled and make a PC port for it, even if it is totally barebones I'd love to see that.

I'm interested in this recompilation for Star Fox 64 as well. It's my favorite game and nothing in the genre comes close. So having it available without emulation on a modern computer would be awesome. Unfortunately I know next to nothing about this kind of stuff, doesn't mean I can't learn but I'd need a good jumping off point. I don't even know how to go about acquiring the ELF file needed for the metadata. I found a code on Github that converts .Z64 into .ELF but I don't know if that's what they're talking about. It does seem to have stuff like the entry point mentioned, so I feel like it's the same thing, I'm just not sure and I don't want to spend an entire week figuring this stuff out if I'm not even doing it correctly to begin with, you know?

But hey, maybe if nobody else is going to do it I can try and stumble my way through to make something somewhat passable. Story of my life.

I kind of hate how easy Nerrel made it sound lol, as if you could just load a ROM up into this tool and it would run the game, and then you could make any fixes you needed to while it was running. I knew it probably wasn't the case that every game would just magically work perfectly, but I didn't think it would be this complex for sure.
 
Last edited by beardalaxy,

vgmoose

Well-Known Member
Member
Joined
Jan 31, 2016
Messages
361
Trophies
1
Website
github.com
XP
3,091
Country
United States
Alright this seems like a good place to ask: to what extent can this be utilized? Like if we wanted to combine all of the Mario Party 1-3 boards and mini games into Mario Party 3, is that feasible or completely out of the question? I mean Ship of Harkinian has successfully combined OoT and Master Quest into a single game, so in theory I'd think what I'm imagining shouldn't be completely impossible.
This should not directly make those kinds of game specific mods easier, as you still don’t get human readable, annotated source code to work with. A well done decomp practically gives you a cleaner version of how the original code might’ve looked.

Whereas the recomp, as the term is being used here, is closer to emulation at compile time (I think) and is more of a blackbox. The machine generated C code it generates should not be as easy to work with.

Buuuut, for less popular games, it could still indirectly help decomp/modding projects, as some C code to reference is still better than none, and also you can use likely use modern PC tools on the compiled binary (like Cheat Engine).
 

HandsomeJack

Well-Known Member
Member
Joined
Dec 24, 2021
Messages
227
Trophies
0
Age
51
XP
1,334
Country
United Kingdom
Quake 2 N64 would be a good candidate for this.

The remastered PC version has annoying-as-fuck gameplay differences. It would be good to get the original running natively on PC.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    BigOnYa @ BigOnYa: It's just a joke..