FIXING the ENTIRE SM64 Source Code (INSANE N64 performance)

Kaze Emanuar7 HN recommenders · 2022–2025
3.2M views · explainer · evergreen · Uploaded 2022-04-09

Kaze Emanuar explains how he rewrote and optimized the Super Mario 64 source code so it runs far faster on real N64 hardware. He covers performance bottlenecks and fixes in detail for his ROM hacks.

HN loves the deep, hands-on look at N64 hardware quirks such as bus contention and the surprisingly large wins from low-hanging optimizations.

Watch on YouTube

19 comments from Hacker News

@prophesi2022 · in “Overhauling Mario 64's code to reach 30 FPS and render 6x faster on N64 [video]”

I think the main thing is that Nintendo had splitscreen multiplayer planned, but performance prevented it. Edit: Got farther into the video and he talks about this at 14:50 ( [VIDEO] )

@Thaxll2022 · in “Quake on the Game Boy Advance [video]”

Are modern compiler good enough / have good optimization on old hardware so that you don't need to write ASM? I remember that impressive opti on Mario64 and it's using C / GCC: [VIDEO]

@psychphysic2022 · in “Ask HN: Publish old projects even though the source code embarrasses you by now?”

Just open source it. No one will judge you by 15 year old code if you have recently produced good code. That's what people will look at. Just look at the face palms at Nintendo HQ despite the amazing game they made [VIDEO]

CriticalView on HN
@MarioMan2023 · in “Nintendo 64 Java”

On a related note, Kaze has done a deep dive into optimizing the Super Mario 64 source code for his ROM hacks. Here’s one of his more popular videos on the subject: [VIDEO]

RecommendsView on HN
@psychphysic2023 · in “The model for the coins in Super Mario Odyssey is 65% simpler than in SM Galaxy”

If you like this stuff Kaze Emanuar does loads of neat work with the super mario 64 decompiled code. [VIDEO] Loads of interesting quirks of the N64 to do with slow bus.

RecommendsView on HN
@kibwen2023 · in “Finding the best sine function for Nintendo 64”

Kaze has already done so, and picking the low-hanging fruit results in much greater improvements than the optimizations shown here (which frees up less than one millisecond per frame). Here's the previous video with explanations and video demonstration of their improvements: [VIDEO]

@phire2023 · in “Finding the best sine function for Nintendo 64”

In one of Kaze's older videos [1] , he tracks both CPU and RCP time over various optimisations. The numbers make it pretty apparent that you can get significant RDP performance gains by reducing the amount of CPU bandwidth and/or improving it's access locality. The N64 is a unified memory system, and memory stalls triggered by the CPU will slow RDP down. The N64's memory controller appears to be very simple. As I understand it, if one sub-component attempts to access a DRAM row that is closed (DRAM rows are 2KB long), then the entire memory controller stalls for ~100ns as the RDRAM chip closes the previous row (writing out any dirty changes) and opens the new row. The controller doesn't appear to do any reordering to optimise access patterns. If multiple components are accessing the same 1MB bank simultaneously, you can hit pathological bad cases were the entire system slows down, as the memory controller is continually stalling for 100ns at a time while the memory chips close and reopen rows. Which is why some games can enable a high resolution mode when the memory expansion pack is present. They often don't need the extra 4MB of ram, but simply being able to strategically spread their data across eight different banks instead of four banks can massively improve performance. [1] [VIDEO]

@psychphysic2023 · in “Leaked Wipeout source code leads to near-total rewrite and remaster”

Excellent..more of this please. Super Mario 64 has also had stupendous rewrites from decompiled code I believe. [VIDEO] His videos on the Sine function in sm64 is a fun watch as the limitations make nearly all optimizations justifiable.

RecommendsView on HN
@rdlw2023 · in “The Worlds First FPGA N64”

If anyone is interested in new projects for N64 hardware, Kaze Emanuar has an amazing series about optimizing Super Mario 64 to run incredibly complex romhacks on original hardware. Interestingly, SM64 is usually throttled by memory speed. This means that using 'inline' is detrimental to performance, since making the program larger can cause another read from memory. Here's an overview video, he has many more specific videos about specific topics: [VIDEO]

RecommendsView on HN
@dharmab2023 · in “Ask HN: What's your "it's not stupid if it works" story?”

Similarly, a modder recently found that unrolling loops _hurt_ performance on the N64 because of RAM bus contention: [VIDEO]

@Wolfbeta2024 · in “Super Mario 64 on the Web”

I've recently been enjoying watching this young modder on YouTube optimize all of the original SM64 source code, doubling frame rate, and modding his own Return To Yoshi's Island [VIDEO]

RecommendsView on HN
@CSMastermind2024 · in “Decompilation of Paper Mario for N64”

There's an amazing video about refactoring Mario 64 to reach 30 FPS and render 6x faster on N64: [VIDEO] The changes were much more extensive than just removing the debug flags. They were also able to get local coop and a 4 player split screen working which were features originally intended for the game but cut for performance reasons.

Strongly recommendsView on HN
@alpaca1282024 · in “How video games use lookup tables”

Not always, though it might depend on what platform you mean with retro. Kaze Emanuar on YT does a lot of development for the N64 and it feels like half the time he talks about how the memory bus affects all kinds of optimizations. In Mario 64 he replaced the original lookup table for the sine function because an approximation was faster and accurate enough (or rather two approximations for two different purposes). I love that channel, he reworked the entire Mario 64 code [0] to make it run at stable 60FPS...because he wanted his mods to run faster. [0] [VIDEO]

Strongly recommendsView on HN
@echelon2024 · in “VR Powered by N64 [video]”

This is what James Lambert does as a follow up when Valve shuts down [1] his "Portal in N64" project [2]. James is like Kaze [3] and builds incredible N64 demos [4] and technical videos about them. [1] [LINK] [2] [LINK] [3] [VIDEO] [4] [LINK]

@Apofis2024 · in “I ported thousands of apps to Windows 95 [video]”

If you found the video on Super Mario 64 being published with debug symbols interesting, check this out: After finding out about the debug symbols, a developer took a deeper dive through the codebase and optimized the ever living hell out of to get 60fps+. FIXING the ENTIRE SM64 Source Code (INSANE N64 performance) [VIDEO]

RecommendsView on HN
@Manuel_D2024 · in “Programming the C64 with Visual Studio Code”

Retro game coders achieve some pretty astounding results sometimes. One of my favorite examples is one who optimized super Mario 64 to such a degree that it runs with much better framerate on the original hardware. Also, multiplayer was added: [VIDEO]

@01HNNWZ0MV43FF2025 · in “RT64: N64 graphics renderer in emulators and native ports”

For those who haven't heard, Kaze is the guy who optimized Mario 64's code, fixed some physics bugs, etc., claims roughly 6x speedup, so that he can make a mod / ROM-hack that runs smoother despite having better graphics: [VIDEO]

@phire2025 · in “Palette lighting tricks on the Nintendo 64”

Both use a unified memory architecture, where the GPU and CPU share the same pool of memory. On the N64, the CPU always ends up bottlenecked by memory latency. The RAM latency is quite high to start with, your CPU is sitting idle for ~40 cycles if it ever misses the cache, assuming RCP is idle. If RCP is not idle, contention with can sometimes push that well over 150 cycles. Kaze Emanuar has a bunch of videos (like this one [VIDEO] ) going into detail about this flaw. The gamecube fixed this flaw in multiple ways. They picked a CPU with a much better cache subsystem. The PowerPC 750 had Multi-way caches instead of a direct mapped, and a quite large L2 cache. Their customisations added special instructions to stream graphics commands without polluting the caches, resulting in way less cache misses. And when it did cache miss, the latency to main memory is under 20 cycles (despite the Gamecube's CPU running at 5x the clock speed). The engineers picked main memory that was super low latency. To fix the issue of bus contention, they created a complex bus arbitration scheme and gave CPU reads the highest priority. The gamecube also has much less traffic on the bus to start with, because many components were moved out of the unified memory. --------------------------- The N64 famously had only 4KB of TMEM (texture memory). Textures had to fit in just 4KB, and to enable mipmapping, they had to fit in half that. This lead to most games on the N64 using very small textures stretched o

@haiku20772025 · in “I Ported SAP to a 1976 CPU. It Wasn't That Slow”

> Lookup tables are always faster than calculation - is that true? I know it's not always true on the Nintendo 64, because it shared a single bus between the RAM and "GPU": [VIDEO] , [LINK]