
Super Mario 64 has been decompiled - sjuut
https://github.com/n64decomp/sm64/blob/master/README.md
======
bri3d
As an amusing side-effect, the team working on this effort also implemented
IRIX userland support for QEMU since the original N64 toolchain ran on IRIX on
the SGI Indy, and they need the original compilers to verify functional
equivalence of their source: [https://github.com/n64decomp/qemu-
irix](https://github.com/n64decomp/qemu-irix) .

~~~
gdubs
I wrote to SGI in high school asking for some info on their computers and they
sent back a stack of beautifully printed, full-color brochures. The Indy had a
webcam, which was very rare in those days. Also included was a brochure on the
Indigo workstation, which Industrial Light and Magic used for Jurassic Park,
etc.

Nintendo is a little mysterious when it comes to what their actual tooling
was, but I remember Donkey Kong Country being the first time I read they were
using SGIs (or at least the studio "Rare" was).

It's somewhat surprising they used the Indy for developing Mario 64 – I always
got the sense that it was somewhat lightweight in performance compared to the
Indigo, but a very cool machine either way.

~~~
segmondy
I have an SGI rotting in my garage, what's amazing about them is the quality
of the monitor. For CRT displays, the best damn monitor I ever experienced,
just CRISP.

The Nintendo 64 had a MIPS R4300 chip, the SGI Indigio also used the MIPS
Rchip, the early one had R4000/R4400 chip, the later ones R8000+ chips. I can
only speculate that by using SGI, you could run some of your non specific N64
code locally and debug faster.

Original PSX had a R3000 chip, but Sony opted for BSD, their devkit ran on
FreeBSD PCs and you built the code and ran on actual PSX device. Cheaper...

~~~
IntelMiner
Can you link more info about Sony's devkits using FreeBSD?

BSD would've been a strange choice as the Playstation 1 debuted on December
3rd, 1994. "FreeBSD 1" came out just 13 months earlier

The Playstation 2 "TOOL" machines ran Red Hat for some of them, which was a
bit more mature by 2001

The Playstation 3 and 4 though both run Net and FreeBSD under the hood
internally though

~~~
primis
The Playstation 1 "TOOL" actually ran windows [1]. A large success of the the
PS1 however was the the "twin ISA" card dev kit, which could be plugged into
any PC-Compatible for PS1 development, which drastically lowered the cost of
development for the PS1.

Also BSD != FreeBSD, BSD 4.3 Net/1 (the first BSD released under the BSD
license instead of containing AT&T code) was released in 1989.

[1][https://www.retroreversing.com/official-playStation-
devkit](https://www.retroreversing.com/official-playStation-devkit)

------
derefr
One thing I've always been curious about: is there any sort of clear
continuity of architecture or design patterns between the games in the Super
Mario series? Yes, they're probably all from-scratch rewrites of the engine,
but could each successive engine be said to be a "descendant" of a previous
one, on a design level?

One thing I know (and can be seen in this repo) is that SM64 emulates a
version of the NES/SNES "Object Attribute Memory", as a pure-software ring-
buffer. (I'd love to know whether that carries on to later titles like Galaxy,
3D World, NSMB(U), Mario Maker, etc.)

~~~
chc4
Super Paper Mario uses an extremely similar engine as Paper Mario: The
Thousand Year Door, which uses a slightly modified version of the Paper Mario
64 engine.

~~~
derefr
Intelligent Systems seems to have a good head on their shoulders for code
reuse. Enough so that I would suspect that their _Fire Emblem_ and _Advance
Wars_ series—when they were releasing concurrently—were the same engine
underneath.

(Side-note: I've always wondered how the mini-games in IS's _WarioWare_ series
work—whether each game is entirely custom code, or whether they've come up
with some sort of DSL for specifying reflex games. If the latter, I would bet
that that has a decent genealogy too.)

~~~
Andrex
Well, they made a game where you can make your own microgames (D.I.Y.), and I
believe an Iwata Asks revealed it was basically a dumbed down version of the
internal tools they had been using, at least for the earlier DS WarioWare game
(Touched.) Not sure if that quite answers your question, but I would bet it's
some kind of DSL interpreted by a microgame engine.

------
euske
This is cool and illegal. What makes me envy of the West (or countries other
than Japan in general) is that this kind of attempt is somewhat condoned and
praised, while in Japan there would be a vocal outcry and finger-pointing
campaign (with some media exposure) to the point where the author would be
forced to shut down the project. It's a blessing that people can pursue things
like this, and it's a huge shame that Japan is such an anal when it comes to a
marginally illegal activity in an open space. (I'm sure some people do it
underground though.)

~~~
sdrothrock
> It's a blessing that people can pursue things like this, and it's a huge
> shame that Japan is such an anal when it comes to a marginally illegal
> activity in an open space.

I've noticed spillover effects into Japanese gamers as well -- people being
suspicious of or derisive about mods, even when they're perfectly legal and
the game has built-in mod support (looking at you Monster Hunter World).

My (Japanese) girlfriend is on the very conservative side of the spectrum
there and absolutely hates it when I bring up any kind of modding, and so do
her friends -- the culture of "authorial intent is king" is very strangely
strong for a culture that also appreciates and enjoys doujin.

~~~
triodan
Doujin works are made with the awareness that they are parodies of the
original work. It does not alter the body of the original work in any way and,
as the term itself means, self-published. It is made without any direct
affilation in regards to the original work.

------
ortusdux
I am looking forward to the mods that this will enable. I highly recommend
trying mario 64 on dolphin EMU at 1080P with a texture pack. A HD mod that
added a few more polygons would really round out the experience.

~~~
urda
Is a raspberry pi a good-enough platform to run N64 1080P games on?

~~~
bluedino
The question is now, would it be possible for someone to make a port of Mario
64 that runs on the Pi, instead of trying to emulate it?

Usually after you get source releases to games, you get people that port them
to different platforms. Like how we had Doom on iPods and Kodak digital
cameras.

~~~
hugg
There's still a lot of assembly code

------
dooglius
Previous discussion:
[https://news.ycombinator.com/item?id=20418577](https://news.ycombinator.com/item?id=20418577)

~~~
Mathnerd314
This is the "official" release, where someone from the team that was working
on the decompilation is making it public rather than just a random person on
the Discord.

But not much has changed, I guess it's hard to make progress in a month.

------
laurent123456
It's interesting there are bits of code that don't have a purpose, and may
have been there to support a second player. For example here:

    
    
        > This is evidence of a removed second player, likely Luigi.
        > This variable lies in memory just after the gMarioObject and
        > has the same type of shadow that Mario does. The `isLuigi`
        > variable is never 1 in the game. Note that since this was a
        > switch-case, not an if-statement, the programmers possibly
        > intended there to be even more than 2 characters.
    

[https://github.com/n64decomp/sm64/blob/4b46247686fd0e1ee691b...](https://github.com/n64decomp/sm64/blob/4b46247686fd0e1ee691bf0f09201cfeeeb1d9f1/src/game/shadow.c#L530)

And more results when searching for "luigi":

[https://github.com/n64decomp/sm64/search?q=luigi&unscoped_q=...](https://github.com/n64decomp/sm64/search?q=luigi&unscoped_q=luigi)

~~~
Wowfunhappy
I vaguely recall reading that the multiple characters in SM64DS were a feature
that was cut from the original game. Am I hallucinating or did Nintendo say
that somewhere?

(The additional characters in the DS remake were horribly unbalanced, so I
wonder if the earlier implementation would have been better...)

------
DiseasedBadger
"For Windows, install WSL and a distro of your choice and follow the Linux
guide."

I love these instructions!

Also, I'd love to see this converted to a native executable. I wish Nintendo
would actually allow that, although I'm sure they wouldn't.

~~~
sigotirandolas
If I remember correctly, some time ago I saw a video from someone who managed
to build a substantial part of SM64 as a native executable and was able to
verify that tool-assisted runs ran perfectly on in it (hence it being
accurate). The video displayed the game as a wireframe and had no audio, since
those parts are surely tied to the N64 hardware.

I can not figure out the right keywords to find it again, but you may be able
to if you are interested.

EDIT: Even though I can't find the video anywhere (I promise it existed!),
from
[https://warosu.org/vr/thread/5644072](https://warosu.org/vr/thread/5644072)

"To answer your questions, yes: This is a full source code which can be
recompiled with modern toolchains (gcc: ive done this already) and even target
other platforms (PC) with quite a bit of work. There already exists some proof
of concept wireframe stuff."

~~~
alexhaber
[https://www.youtube.com/watch?v=7VbTe7U-bo4](https://www.youtube.com/watch?v=7VbTe7U-bo4)

------
vSanjo
Always a little humbling to remember the developers are just like you and I.

[https://github.com/n64decomp/sm64/blob/master/src/game/camer...](https://github.com/n64decomp/sm64/blob/master/src/game/camera.h#L379)

[https://github.com/n64decomp/sm64/blob/4b46247686fd0e1ee691b...](https://github.com/n64decomp/sm64/blob/4b46247686fd0e1ee691bf0f09201cfeeeb1d9f1/src/game/level_select_menu.c#L111)

[https://github.com/n64decomp/sm64/blob/4b46247686fd0e1ee691b...](https://github.com/n64decomp/sm64/blob/4b46247686fd0e1ee691bf0f09201cfeeeb1d9f1/src/game/behaviors/spiny.inc.c#L59)

[https://github.com/n64decomp/sm64/blob/4b46247686fd0e1ee691b...](https://github.com/n64decomp/sm64/blob/4b46247686fd0e1ee691bf0f09201cfeeeb1d9f1/src/game/debug.c#L181)

[https://github.com/n64decomp/sm64/blob/4b46247686fd0e1ee691b...](https://github.com/n64decomp/sm64/blob/4b46247686fd0e1ee691bf0f09201cfeeeb1d9f1/src/game/mario_misc.c#L33)

~~~
NikkiA
It's a decompiled result, it's _incredibly_ unlikely the comments are from the
original code, rather they'll have been placed there by the people doing the
decompile.

~~~
vSanjo
Ah, I wasn't aware of that. I thought it might include those.

That's a shame!

------
bla3
Nintendo will request a takedown the second they see this, no?

~~~
derefr
What for? There's no copyrighted material in this repo.

~~~
lostgame
The models and sounds aren't copyrighted? Because they are totally within the
GitHub, there...

~~~
kelnos
I didn't look through the repo, but given that the linked README talks about
needing an original version of the ROM in order to extract assets, I would
guess they're not in there?

~~~
lostgame
The models certainly are. Don't think the textures are.

~~~
duskwuff
A number of assets, including textures, audio, and prerecorded demos, have
been stripped out of this release.

------
diveanon
Is there a usb compatible n64 controller?

Part of what makes this game such a watershed moment for 3d gaming is how the
controller was designed to maximize it's potential.

To this day Mario 64 is one of the best games ever made.

~~~
andimm
8bitdo once hat an N64 controller, but seems like it's not available anymore,
maybe you find a used one somewhere.

Also there are "Controller Converter" N64->USB available on i.e. Amazon and
iNNEXT has an Retro 64-Bit N64 Controller on Amazon as well.

Don't know if any of these will work for you, at least the iNNEXT is mentioned
in the retropie wiki[0].

[0]
[https://retropie.org.uk/docs/Nintendo-64/](https://retropie.org.uk/docs/Nintendo-64/)

------
lame88
What an awesome project. I would love to mess with random stuff like whirlpool
strength and see what it does to the game. Efforts like this to make the
decompiler output intelligible e.g. meaningful variable names make this much
more approachable for a technical person like me without much of the niche
platform-specific reverse engineering skills. In fact there are countless
games I'd love to dive into like this.

~~~
thanatropism
Train a ML system on a range of parameters (whirlpool strength) until you have
a decent port of the game to a neural network and/or tree-based algo. Then try
to optimize the game based on people’s enjoyment.

~~~
im3w1l
I think it would be much easier to use change the parameters directly in the
original program. Just have to use a gradient-free optimizer.

~~~
thanatropism
Yours is a better technical approach to the vague dream I had described.

Am I being downvoted because I don't have an optimal solution to some problem?

------
kbumsik
I don't know much about reverse engineering field, but more than 70% code is
assembly. Is extracting assembly still considered decompiled?

~~~
holmium
Outside of a few audio and PAL routines (see asm/non_matchings), everything
that was written in C has been decompiled back into C. There are a few
routines written in ASM, like the boot code and some of the SDK code.

Most of the other "assembly" files are for data, like the level scripts. It's
not assembly of machine code.

You could try to put those into C, but you're not gaining much--assuming that
it's even something that can be represented in C without a bunch of fancy
compiler specific tricks. You'd be better off creating a DSL or a custom
program suite, which is probably what Nintendo was doing 25 years ago.

------
person_of_color
So how do people do this?

Manual inspection?

~~~
aeneasmackenzie
They got the original compiler running and made source that compiles to the
same ROM.

~~~
person_of_color
How does that work? They still manually reversed the disassembly right?

------
segmondy
It's amazing the level of effort and work that has gone into this and here I'm
trying to finish a 100 line side project. :-]

~~~
WilliamEdward
You can get a lot more done with a team of people who are also getting paid.

~~~
breakingcups
Who was funding this decompilation? Was it from the speedrunning community?

------
mrpippy
Once the inevitable native ports start appearing, I’d love to see an OpenGL 1
graphical backend so it can run natively on IRIX

------
JohnSmith13345
pannenkoek2012 would probably find more glitches, assuming this doesn’t get
taken down by Nintendo given their aggressive stance on copyright

------
ryan-allen
They wrote it in assembly, nuts!

~~~
o-__-o
Binary executables are machine code. One step from machine code is assembly.
It’s easy to translate machine code to ASM (because you are just reversing the
op code and adding data structures) from there it gets hard because compilers
do all sorts of tricks to create performant assembly and throws away hints
about code structure (e.g a simple overloaded function may become an ASM
routine with 30 parameters depending on how it’s called. Or vice versa.. it’s
like trying to recreate HD video from mpeg-1, entropy has been thrown away).
So decompiled code is usually left in assembly. Sometimes an effort is made to
create the C equivalent but that’s a maddening effort.

More than likely SM64 was written in c with some critical performance parts in
ASM (like mode7 and some of the OAM stuff other threads talk about).

------
codesushi42
It would be great if this could be done for games where the source code was
lost.

Like Panzer Dragoon Saga.

~~~
mburns
This decompile was done without the original source code, just the released
game, which is effectively the same as being ‘lost’.

~~~
codesushi42
I meant where the source code does not exist anymore, anywhere.

Nintendo still has the source to SM64.

~~~
mburns
Maybe I misunderstood you.

I’m saying this same decompile process could indeed be done to any released
game where the source code is lost, because that is effectively what happened
in this case.

~~~
filoleg
I think you misunderstood what the parent was saying.

On the technical level, you are correct in that in both scenarios the end
result would be the same, as you are going from compiled code to decompiled
code.

What I believe the parent is saying, is that applying this to Panzer Dragoon
accomplishes more (on the human level), because devs of that game don't have
the original source code anymore, while Super Mario 64 devs do.

~~~
jolmg
Maybe the confusion could have been avoided if instead of:

> It would be great if this could be done...

codesushi42 would have said (emphasis mine):

> It would be great if this _would_ be done...

Not that I think it was incorrect as it was, just a little ambiguous, I guess.

~~~
filoleg
Not a native english speaker, but this seems like a nitpicky non-issue to me.
How is it not the same as "could you please pass me a glass of water" vs.
"would you please pass me a glass of water"? Both indicate a request rather
than talking about actual physical ability to perform the action.

Also, I would agree more with your point if the parent said "It could be great
if this could be done..." instead of "It would be great if this could be
done". The first "would" seems to indicate to me pretty clearly that the
parent was talking about a request rather than ability.

~~~
sigstoat
> Not a native english speaker, but this seems like a nitpicky non-issue to
> me. How is it not the same as "could you please pass me a glass of water"
> vs. "would you please pass me a glass of water"? Both indicate a request
> rather than talking about actual physical ability to perform the action.

in the case of something like the glass of water, "could" makes the sentence
more indirect, and more polite.

the original post is "it would be great if [huge task undertaken by
unspecified persons] could be done". this native speaker would not attempt to
polite-ify a request for something like that (and i don't think other native
speakers would either), so the original post can't be making a request. it is
expressing a hope that the thing is possible. mburns (reasonably) then
explains that it is possible. then codesushi42 sort of goes on the rails, and
i can't figure out what they're attempting to convey at this point.

~~~
codesushi42
Huh? I wasn't making an appeal to anyone, so your point is moot.

Context is important. Why bother decompiling a game if you have the source
already? Of course I meant decompiling games for which there is no source code
available on any machine. Nintendo has the source for SM64.

What a ridiculous load of pedantry.

~~~
torstenvl
It isn't pedantry. Expressing a wish that something "could" be done is
ambiguous. "Could" is both used as you originally intended _and_ as an
expression of ability. It's not pedantry to misunderstand, and it's not
pedantry for GP to explain why the misunderstanding occurred.

A misunderstanding occurred. The misunderstanding was clarified, acknowledged,
and explained. I'm not sure it contributes anything to make accusations of
pedantry.

~~~
Pizzaputer
Yes, this thread right here officer.

------
crtlaltdel
lol i love seeing all the replies to comments on this that start with "No."

