Super Mario 64's source code has been decompiled and officially released

supermario64.png

After having been decompiled back in July, the source code for Super Mario 64 has been completely reverse-engineered, and is now publicly available. Available on GitHub is a full decompilation of the beloved 3D platformer, Super Mario 64. The decompilation works for the NTSC-U and NTSC-J builds of the game, with (E) ROM support coming soon. To keep things legal, you will need to provide your own copy of the game, in order to compile the data, with the exact process being detailed, below. If you've ever wanted to see some of the magic that went into creating such an iconic game, you can now finally see into all of the finer details.

Linux
  1. For each version (jp/us/eu) that you want to build a ROM for, put an existing ROM at ./baserom.<version>.z64 for asset extraction.

  2. Install the following packages:
Debian / Ubuntu

  • git
  • binutils-mips-linux-gnu / mips64-elf (>= 2.27)
  • python3 (>= 3.7)
  • build-essential
  • pkg-config
  • zlib1g-dev
  • libaudiofile-dev
Arch Linux

  1. Install qemu-irix
3.a Options: 1. Clone https://github.com/n64decomp/qemu-irix to somewhere and follow its install instructions in the README. 2. Optionally, grab the prebuilt qemu-irix from the Releases section. 3. (Arch) Use AUR package qemu-irix-git

3.b (For options 1 or 2), copy executable qemu-irix from irix-linux-user to somewhere convenient with a relatively short path.

mkdir -p /opt/qemu-irix/bin
cp irix-linux-user/qemu-irix /opt/qemu-irix/bin

3.c Define QEMU_IRIX environment variable in your ~/.bashrc to point to this qemu-irix executable.

export QEMU_IRIX=/opt/qemu-irix/bin/qemu-irix

  1. Run make to build the ROM (defaults to us version). Make sure your path to the repo is not too long or else this process will error, as the emulated IDO compiler cannot handle paths longer than 255 characters. Build examples:
make VERSION=jp -j4 # build (J) version instead with 4 jobs
make VERSION=eu COMPARE=0 # non-matching EU version still WIP

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

:arrow: Source
 

Ecchi95

Well-Known Member
Member
Joined
Jul 7, 2019
Messages
121
Trophies
0
Age
29
XP
890
Country
United States
guys, gals, and whatever you are: now is the time to aswer one of the greatest questions ever

was luigi in mario64?
Nintendo already confirmed Luigi was in Super Mario 64 in an Iwata Asks interview. It was 2-player. And pieces of that code are still there.
 
  • Like
Reactions: Manana

Ecchi95

Well-Known Member
Member
Joined
Jul 7, 2019
Messages
121
Trophies
0
Age
29
XP
890
Country
United States
http://iwataasks.nintendo.com/interviews/#/wiiu/super-mario-3d-world/0/6

Iwata
Regrets?

Koizumi
One goes all the way back to Super Mario 64. When we made the first prototype, Mario and Luigi were on a flat field.

Iwata
Both of them.

Koizumi
Yes. We ran it that way, but when we made the landforms, because of hardware limitations we had a choice between cutting Luigi or making more elaborate landforms. Then, in tears, we had to ask Luigi to leave.


Iwata
Oh, is that so?

Koizumi
And at that time, I talked with Miyamoto-san about having Luigi appear alongside Mario sometime in a multiplayer 3D Super Mario game. I've thought that for 15 years.
 
  • Like
Reactions: zfreeman
D

Deleted User

Guest
But what about the DS enhanced port stuff?
Another long journey likely. I mean, I don't know how close sm64ds runs (source code wise) to sm64. I mean sm64ds had a shit ton of improvements from sm64. But if it's a lot different (point that it no longer even looks like the original source code) then well... another decompilation journey.
 
Last edited by ,

Ecchi95

Well-Known Member
Member
Joined
Jul 7, 2019
Messages
121
Trophies
0
Age
29
XP
890
Country
United States
Another long journey likely. I mean, I don't know how close sm64ds runs (source code wise) to sm64. I mean sm64ds had a shit ton of improvements from sm64. But if it's a lot different (point that it no longer even looks like the original source code) then well... another decompilation journey.
The DS version looks more like Ocarina of Time. It uses relocatable binaries for everything like Ocarina of Time.
 

Spazzery

Well-Known Member
Newcomer
Joined
Jun 30, 2019
Messages
85
Trophies
0
Age
23
XP
1,350
Country
Estonia
this is phenomenal! I can't wait to see what amazing things people can do with this! :yaysp::yaynds::yay3ds::yaywii::yayu::yayswitch::yaypsp::yayps3::yayone::gba:

Now that I think, a 3DS port would be super awesome! :yaynds:
 

HideoKojima

Well-Known Member
Member
Joined
Jan 17, 2018
Messages
1,107
Trophies
0
Age
26
XP
2,211
Country
United States
It's worth mentioning that this is source code from a decompiled binary, it's missing all of the original commentary and it's "written" as a machine would understand it, not necessarily as a programmer would code it, though the team has clearly made great strides in making it readable for the average Joe. This can make even simple functions quite difficult to wrap your head around, so it will take an experienced group of coders to make any significant use of this. What this does for average users is shedding a better light on the internal workings of the game, which is interesting in and out of itself. Very good, and an almost impossible task to achieve given the complexity of the average video game binary.
Yeah was gonna say that

--------------------- MERGED ---------------------------

We need Mario Party decompiled, so we could merge the best minigames of Mario Party 2 and 3 into 1
And add multi-player too
 
  • Like
Reactions: Ajlr
D

Deleted User

Guest
Yeah was gonna say that

--------------------- MERGED ---------------------------


And add multi-player too
what do you mean by multi-player? Mario party supports local multiplayer. Now if you mean multiplayer like as in wifi or online multiplayer then sure yeah.
 
  • Like
Reactions: Ajlr

Ecchi95

Well-Known Member
Member
Joined
Jul 7, 2019
Messages
121
Trophies
0
Age
29
XP
890
Country
United States
I'll make a new thread about this and other games when I'm further along.

I'm locating functions from Super Mario 64 in Mario Kart 64 (J) (V1.0) [!]. It's clear that it uses the Super Mario 64 engine, but some things are moved around and I don't know if that's the compiler's doing or Nintendo refactoring.

Code:
001050 create_thread              //0C000114
001084 Main                       //not called, jumped to (jr $t2)
0010E0 thread1_idle               //not called, passed as $a2 to create_thread
00125C start_sptask               //0C000197
0017EC dispatch_audio_sptask      //0C0002FB
001820 send_display_list          //0C000308
001888 init_render_image          //0C000322
0018C8 end_master_display_list    //0C000332
00191C clear_frame_buffer         //0C000347
0019E0 sm64_80247ED8              //0C000378
001A94 sm64_80247FAC              //0C0003A5
001B14 display_and_vsync          //0C0003C5
001D38 ?                          //0C00044E dma_read?
001E44 setup_game_memory          //0C000491
002AAC ?                          //0C0007AB render_game?
002B50 interrupt_gfx_sptask       //0C0007D4
002B8C receive_new_tasks          //0C0007E3
002CB8 set_vblank_handler         //0C00082E
002CF8 start_gfx_sptask           //0C00083E
002D48 handle_vblank              //0C000852
002E64 handle_dp_complete         //0C000899
002EBC handle_sp_complete         //0C0008AF
002FC4 thread3_main               //not called, passed as $a2 to create_thread
00335C thread5_game_loop          //not called, passed as $a2 to create_thread
0034C4 thread4_sound              //not called, passed as $a2 to create_thread

004130 profiler_log_thread5_time  //0C000D4C
0041C0 profiler_log_thread4_time  //0C000D70
00423C profiler_log_gfx_time      //0C000D8F
0042CC profiler_log_vblank_time   //0C000DB3

0CD440 osCreateThread             //0C033210
0CD830 osStartThread              //0C03330C
0CE45C osSpTaskLoad               //0C033617
0CE5BC osSpTaskStartGo            //0C03366F
0CF100 osPiStartDma               //0C033940

10DCD8 clear_z_buffer             //0C0A8F06
10DE64 my_rdp_init                //0C0A8F69
10E188 my_rsp_init                //0C0A9032
10E1FC ?                          //0C0A904F display_frame_buffer?
111BC4 set_segment_base_addr      //0C0A9EC1
111BE4 get_segment_base_addr      //0C0A9EC9
111C04 segmented_to_virtual       //0C0A9ED1
111C38 move_segment_table_to_dmem //0C0A9EDE
 
Last edited by Ecchi95,
  • Like
Reactions: _DrBecks_

FAST6191

Techromancer
Editorial Team
Joined
Nov 21, 2005
Messages
36,798
Trophies
3
XP
28,284
Country
United Kingdom
Is that supposed to demonstrate the same engine? Most of those look like basic IO for an early 3d game console such that it would sooner call a common IO library (and both of those were early stage Nintendo in house games)
 

Ecchi95

Well-Known Member
Member
Joined
Jul 7, 2019
Messages
121
Trophies
0
Age
29
XP
890
Country
United States
Is that supposed to demonstrate the same engine? Most of those look like basic IO for an early 3d game console such that it would sooner call a common IO library (and both of those were early stage Nintendo in house games)
The functions that aren't Main, or prefixed with "os" or "thread" are functions that only appear in first-party Nintendo 64 games. They are an engine Nintendo developed. The first game that used it was Super Mario 64, so it's referred to as Super Mario 64's engine.

If you mean more specific things like scripts, I haven't found them yet. But what I've found so far are things that only appear in first-party Nintendo games in that exact form.
 

Ecchi95

Well-Known Member
Member
Joined
Jul 7, 2019
Messages
121
Trophies
0
Age
29
XP
890
Country
United States
I wrote a tool now to plug in the symbols I give it for any N64 ROM. Output for Mario Kart 64 (J) (V1.0) [!]'s thread3_main:

Code:
Where? 2fc4
002FC4 27BDFFA0
002FCC v1 = 0x8014DC98
002FDC 25CEF780
002FE0 25EF4F80
002FE4 2718A780
002FE8 AC6E0000
002FEC AC6F0004
002FF0 AC780008
002FFC AFBF0034
003000 AFB50030
003004 AFB4002C
003008 AFB30028
00300C AFB20024
003010 AFB10020
003014 AFB0001C
003018 AFA40060
00301C v0 = 0x80344F80
003020 v1 = 0x8036A780
003024 240A0000
003028 240B0000
00302C 240C0000
003030 240D0000
003034 240E0000
003038 240F0000
00303C v0 = 0x80344FA0
003040 24080000
003044 24090000
003048 AC4FFFFC
00304C AC4EFFF8
003050 AC4DFFF4
003054 AC4CFFF0
003058 AC4BFFEC
00305C AC4AFFE8
003060 AC49FFE4
003064 1443FFEF
003068 AC48FFE0

00306C JAL <setup_mesg_queues>

003074 JAL <setup_game_memory>
003084 26108570
003088 2739A720
003090 24180014
003094 AFB80014
003098 a2 = thread4_sound
00309C AFB90010
0030A0 a0 = gSoundThread
0030A4 a1 = 0x4

0030A8 JAL <create_thread>
0030AC a3 = 0x0

0030B0 JAL <osStartThread>
0030B4 a0 = gSoundThread
0030C0 261063C0
0030C4 25088570
0030CC 2409000A
0030D0 AFA90014
0030D4 a2 = thread5_game_loop
0030D8 AFA80010
0030DC a0 = gGameLoopThread
0030E0 a1 = 0x5

0030E4 JAL <create_thread>
0030E8 a3 = 0x0

0030EC JAL <osStartThread>
0030F0 a0 = gGameLoopThread
0030F8 2610C9A8
0030FC s5 = MESG_START_GFX_SPTASK
003100 s4 = MESG_VI_VBLANK
003104 s3 = MESG_DP_COMPLETE
003108 s2 = MESG_SP_COMPLETE
00310C 27B10054
003110 a0 = gIntrMesgQueue
003114 a1 = 0xFFFFFFF4

003118 JAL <osRecvMesg>
00311C a2 = 0x1
003120 v0 = sp54
003124 (v0)
       case s2: //00315C
00312C (v0)
       case s3: //00316C
003134 (v0)
       case s4: //00314C
00313C (v0)
       case s5: //00317C
003144 break;   //003114
003148 a0 = gIntrMesgQueue

00314C JAL <handle_vblank>
003154 break;   //003114
003158 a0 = gIntrMesgQueue

00315C JAL <handle_sp_complete>
003164 break;   //003114
003168 a0 = gIntrMesgQueue

00316C JAL <handle_dp_complete>
003174 break;   //003114
003178 a0 = gIntrMesgQueue

00317C JAL <start_gfx_sptask>
003184 break;   //003114
003188 a0 = gIntrMesgQueue
003190 ra = sp34
003194 s0 = sp1c
003198 s1 = sp20
00319C s2 = sp24
0031A0 s3 = sp28
0031A4 s4 = sp2c
0031A8 s5 = sp30
0031AC 03E00008
0031B0 27BD0060
Press any key to continue . . .



Mario Kart 64 sets up the game memory on Thread 3 instead of Thread 5 like Super Mario 64.

I found Super Mario 64's orbit_from_positions (envfx_snow) function in Mario Kart 64, which goes unused: (all thanks to stumbling upon the atan2s function originally from Mario 64's math_util)

Code:
Where? 1264c4
1264C4 27BDFFD0
1264C8 AFBF0014
1264CC AFA60038
1264D0 AFA7003C
1264D4 C4860000
1264D8 C4A40000
1264DC C48A0004
1264E0 C4A80004
1264E4 46062001
1264E8 C4860008
1264EC C4A40008
1264F0 460A4081
1264F4 46000402
1264F8 E7A0002C
1264FC 46062381
126500 E7A20028
126504 460E7482
126508 E7AE0024
12650C E7B0001C
126510 46021202
126514 E7B20018
126518 46088280

12651C JAL <sqrtf>
126520 46125300
126524 C7B0001C
126528 C7B20018
12652C t6 = sp38
126530 46128300

126534 JAL <sqrtf>
126538 E5C00000
12653C C7AC0028

126540 JAL <atan2s>
126544 46000386
126548 t7 = sp3c
12654C A5E20000
126550 C7AE0024

126554 JAL <atan2s>
126558 C7AC002C
12655C t8 = sp40
126560 A7020000
126564 ra = sp14
126568 27BD0030
12656C 03E00008
Press any key to continue . . .
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • BigOnYa @ BigOnYa:
    Yea that's what I'm sitting on now- 4.9, and it seems fine, have had no issues at all
  • S @ salazarcosplay:
    I don't know if people play online or such
  • K3Nv2 @ K3Nv2:
    My ps3 short circuited during a deep clean still salty about it after downloading 2tbs worth but SteamDeck okay with emulation still just can't run mgs4 worth shit
  • BigOnYa @ BigOnYa:
    Yea forgot bout trophies. They just silly to me. Just like the xbox achievements. Hey, to each they own tho.
  • K3Nv2 @ K3Nv2:
    It keeps players in touch with the game like a check list of things to do after they beat it
  • S @ salazarcosplay:
    @BigOnYa they ruined the gaming experience for me to be honest
  • S @ salazarcosplay:
    @BigOnYa Im not crazy about getting all of them, i feel like I have something to show for for the time put in
  • S @ salazarcosplay:
    @BigOnYa If you want to do rgh or 360 mod
  • S @ salazarcosplay:
    does it matter if you update your 360 or not before trying is it advisable or not
  • BigOnYa @ BigOnYa:
    Yea I don't pay attention to them really. Or do I try to 100% a game. I just play till story ends/ or I get the girl!
  • K3Nv2 @ K3Nv2:
    Bigonya uses his wiener to mod 360s
    +1
  • Xdqwerty @ Xdqwerty:
    Going to the water park, see ya
  • BigOnYa @ BigOnYa:
    You should update the 360 to newest dash before RGHing it yes. But not a big deal if you don't, you can install new dash/avatar updates after. It's just easier to do it auto online before, instead manual offline after.
  • BigOnYa @ BigOnYa:
    Have fun @Xdqwerty. If you see a chocolate candy bar floating in the water, don't eat it!
  • AncientBoi @ AncientBoi:
    :O:ohnoes: Y didn't U Tell ME that ALSO? @BigOnYa :ohnoes: 🤢🤮
    +1
  • BigOnYa @ BigOnYa:
    Does it taste like... chicken?
    +1
  • S @ salazarcosplay:
    @BigOnYa I wanted to ask you about your experience with seeing south park. Most of the people a bit younger like my younger brother and cousins that are a few younger than me that saw kids found south park funny because of the curse words, kids at school, that seemed like liking the show on a very basic level.

    I could not quite have a in depth discussion of the show.

    How was it for you? As an adult. What did you find the most interesting part about it. Did you relate to the parents of the kids and their situations. Was it satires, the commentary on society. The references on celebrities' and pop culture.
    +1
  • BigOnYa @ BigOnYa:
    I remember seeing the very first episode back in the day, and have watched every episode since. I used to set my VCR to record them even, shows how long ago.
  • BigOnYa @ BigOnYa:
    I just like any comedies really, and cartoons have always been a favorite of mine. Family guy, American Dad, Futurama, Cleveland Show, Simpsons - I like them all.
    +1
  • BigOnYa @ BigOnYa:
    South Park is great cause they always touch on relavent issues going on today, and make something funny out of it.
    +3
  • S @ salazarcosplay:
    @BigOnYa were you always up to date on the current events and issues of the time or were there issues that you first found out thru south park
  • BigOnYa @ BigOnYa:
    Most of the time yea I knew, I watch and read the news regularly, but sometimes the Hollywood BS stuff, like concerning actors slip by me. I don't follow most Hollywood BS (example: the Kardasians)
    +2
  • S @ salazarcosplay:
    @BigOnYa there were relevant issues before south park was made, that's why i think a south park prequel/spinoff would be great. Randy and his friends in their child hood
  • BigOnYa @ BigOnYa:
    Yea, like them running in high school together, getting into stuff, and how they got hitched and had kids. And how the town of South Park was back then compared to now. That would be cool to see.
    BigOnYa @ BigOnYa: Yea, like them running in high school together, getting into stuff, and how they got hitched and...