Hey folks! This video recently hit 100k views, which is absolutely mind-blowing. This has become a series and I'm getting close to cracking that opening cinematic! Some context and corrections below: What this codebase is: I called it "source code" but it's really not. Here's the deal: First, Nintendo wrote the original C "source code" for Ocarina of Time. To run it on an N64, they compiled it down to "machine code" that the N64 understands, but is tough for humans to read. The ZeldaRET team then analyzed that machine code and reverse-engineered it into C code that compiles back to the original machine code. So, while both codebases create the same game, they aren’t the same code. Mistakes will be made: I hadn’t touched C in over a decade before this, and I record these off-the-cuff to keep it interesting. Minor mistakes are edited out, and future videos will include corrections when possible. My aim here is to share the process of diving into unknown territory and learning along the way. As one viewer put it, this is like exploring the Water Temple for the first time-but in C. Check out the comments: The comments have been an incredible resource for corrections and in-depth explanations. The community here has been awesome. A huge thank you to everyone who's enjoying the series. I'm glad this is as fun for others as it is for me.
Great stuff bro. Thought you had 2-300k subs upon clicking lol. I'm a new creator and get the same comments, so now I understand how they feel ;) Hope you keep growing, you deserve it
If you were alive during OOT it was an experience. Everyday go home play, get stuck goto school and at the lunch table everyone would be trying to help each other get further. It was so fun when you found out something the group didn't know. A time when running to guides was way way less common.
You know what’s insane the same thing happened to breath of the wild for me in school and everyone would ask how to get the master sword… but I love all the old games better
Yeah those days were truly magical. My best friend and I resorted to calling a national "nintendo hotline" with a minute fee, where we'd get guidance on how to get unstuck in the Water Temple
my siblings and I pooled our allowance money to get this gem - probably a monthly wage back then in 1999 Nigeria. Booting it in the N64 was a surreal experience. Good times
I suppose I cannot exactly blame you for misunderstanding the DmaHandler typedef given that your IDE did not actually take you to the definition of s32 for whatever reason, and function pointer syntax in C is miserable In case it is not mentioned later in the video, and in case anyone is curious: 'typedef s32 (*DmaHandler)(args...)' means that we are defining a type named DmaHandler, which can hold pointers to functions which have the arguments (args...) and return a value of type s32. The definition for s32 itself would look something like 'typedef ... s32'. The name of the type comes last usually. EDIT: Some more notes: 13:45 - A double is a 64-bit floating point value. A 'long long' is a generic type defined to hold at least as much as a 'long'. (It is vague because C's standard does not like to give actual bit counts to anything, so as to be more portable, but on most systems you will ever use, a 'long long' will be defined *in the implementation of the standard* as a 64-bit integer.) 17:55 - A short is usually 16 bits
Small correction: the N64 does not run any operating system. The code runs bare metal. The way those processes are created and handled is via interrupts. Each time a "process" has to run, the cpu jumps to the global exception handler and from there it jumps to the appropriate code (the "process" code)
@@SimoneN64 That seems like an OS? It is obviously far simpler than Windows or Linux, but those are not the only kinds of operating systems. I'm slowly confused by what distinction you imagine there is. Even an OS like Windows does not run code in some magical place; it is still on the CPU, just perhaps in a lower privilege level. And, it also uses interrupts to implement its scheduler!
hey mate, randomly got this in my youtube algorithm. i'm a dev from australia, and i thought this was a really great watch. very fun to see old games dissected and the thought patterns behind them
I’m currently studying CS, I really underestimated how hard it is but I find this super interesting. Thanks UA-cam algorithm for recommending this dudes channel, great video dude
do {...} while(0) is a common idiom for C macros to ensure the body of the macro is a single statement that requires a semicolon after it. Basically, it makes the syntax when using macros identical to when calling a function.
OoT started off as an N64DD game originally. So it's interesting that the devs left a lot of that disk drive boot code in the game at the beginning. Also, they were gonna use the storage on the disk to save things like link's footprints in sandy areas etc. It was going to be a persistent open world game, so it's cool to see when they downgraded the game, they left a lot of that ambitious stuff in the code base.
This is my most memorable game I ever played, I think I was around 11 years old when I played it and it took me like 3 months to finish and it was breathtaking all the way through. I did .net and java in university so I could somewhat follow along. What really strikes me is that this was created all by hand, no AI sh*t, nothing, just pure good old fashioned human ingenuity. Loved this video, enjoyed watching every minute of it! Kudos to you mate!
Thanks for posting a video like this. I wondered how programmers often delve into codebases and I wanted to learn from them and you're my first concrete example of how it's done.
I feel like such a dum-dum every time I try to read a big C project like this alone (coming from a higher level background like C#, js etc). It's so cool to get through it with you and see you have the same question I would have along the way, plus it's easier to see in video format, would love to see other things like these !
Instantly subbed. I’ve been wanting someone to explore the codebase of this game for a while. The decomp is wonderful I also started streaming/playing master quest and managed to beat the Demi tree so far. 🤘🤘
Dude thank you for covering this! I'm on a binge of looking at old game source code and trying to mess with it -- please keep it up. I start with doom/wolfenstein, but just as OOT, there are more games out there! Keep it up man
This was super fun to watch! Would be neat to also see how they go about doing some actions like, how does their ledge detection work, or what goes into Links Attack, etc you name it!
i just started my first year as CS undergrad, i may not understand everything just yet but the concept of this video is interesting and this was enjoyable to watch. nice video man
@@benvillalobos thank you, and also if you plan on looking into any other games if its possible to access the codebase for mario 64 or Mario galaxy ill definitely be tuning in 😩
im only 10 minutes in but im really enjoying how you're explaining all this. i've been modding zelda oot since like, 2010, but it was all hex values and very rudimentary programs that could only do so much. ever since the game was decompiled, it's been my understanding its the premiere way to mod oot now, but i've never been able to interpret code quite like this. i don't know if you plan to go further, but i would watch a series of this. its pretty good
Over the years people have explored this game so hard like it’s the video game form of the Da Vinci code haha. I played this game so many times over the years and even did glitch speedruns when I got older that were fun. OOT itself is this weird game to me that feels very biblical in a lot of ways, and I’ve developed a deep personal connection to it after playing it so much, and mastering the different versions. I can’t really explain why though. I think the SRW series gives me that feeling too, but I dunno. It’s just a mindblowingly cool game.
Now you can see why companies hesitate to release super old titles that they haven't touched in ages, as well as why it takes so long. This is the sort of thing I do for a living. Not being able to debug the code while trying to figure out what's happening is a nightmare.
Damn, I didnt even know we have access to a decompiled version of OoT. I need to check out that code asap :D This game is literally what even got me into Programming 11 years ago, bc watching Speedruns of it was so mesmerizing. :)
Just started to dabble in C to learn some programming, this video sure is pretty insightfully for me even though I don't understand too much. Mainly I just wanted to throw in the analogy that watching this is like playing through Water Temple for the first time but in C :P
Wow I love that they were using actual musical notation for the ocarina code. I mean of course they were, but you just never think about it unless you see it in text.
From what I saw here, I would assume newf was the string used to initialize the new save file name, i.e. filling it with blanks for final builds, but for debug builds the string was "ZELDAZ"
fb stands for framebuffer, sp stands for stack pointer. Stack Top gets the element from the top of the stack. Surprised you didn't know that, it's usually tought in Comp Sci
Just found you and really enjoying the video so far. :-) I know it's been two weeks but I think I can add a bit of background to two things in the initial #includes: CIC is Nintendo's copy protection chip. One's on the cartridge, one in the console. N64DD is the Nintendo 64 Disc Drive, a failed addon to the N64. OOT was initially developed as a disc based game for this addon.
Congrats on making a hit video! I found this super interesting. It made a great background video for me while I was studying. It helped me get in the right mindset to try to comprehend the geologic functions of volcanoes. Like coding to understand one thing in geology you need to understand [x] prior functions that make our world turn the way it does. So, thank you for your help! It was fun getting lost in this code of a game I also loved as a kid. When we saw "sword health" I became very curious and personally would've gotten lost down that rabbit hole for awhile, so if you ever figure out what "sword health" is, let me know! Also curious, how many total lines of code the game is, just for funsies. Hope to see more like this from you if you so desire to continue down this rabbit hole. As others have mentioned I'd love to see the likes of FF7, other FF titles, other Zelda titles, and since you seem to like the SuperNin era based on your choice of music, Chrono Trigger would be a neat one.
Oh man I wouldn't be surprised if the entire codebase was in the 100k+ range. Codebases have the habit of becoming jungles over time (or dungeons in this case). I took a note to check on sword health next time I see it. Cheers, and good luck on your studies!
Not a coder, but im interested in it and this was fun to watch you poke through this although I understood very little. Would love to see more poking around if youre up to it!
i wish people would do stuff like this with other games, like for an actual dev to go through some leaked source (wouldn't touch any rockstar stuff with a 6 foot pole tho) and talk about what's good, what's shit, etc
Those kind of markers like the "ZELDAZ" string can be really useful when you have to look at a random piece of binary memory and figure out what is wrong with it.
19:00 i dont know the reason why they coded it like this, but probably the logic goes like this: is doubleMagicAcquired= a flag that is checked at the great fairy that doubles your magic, to see if its should display the cutscene and double it, or if that already happened. yes, you can infer this information from magicLevel, with something like: if magicLevel==16: play the cutscene, multiply magicLevel by 2, recover health to healthCapacity, and recover mana to magicLevel, else recover health to healthCapacity, and recover mana to magicLevel (skip the cutscene)... but that assume that the programer who coded this system already knew the value of the magicLevels that the final game would use, if the beta testers decided that the game is too easy or too hard with the current maximum magicLevel and change it to, lets say 24 (and 48 when doubled), that would have required found this hardcoded reference to the 16 number (if magicLevel==16) and if this value change again and again, the same problem would repeat, so it make sense to have 2 variables, one to see if the magic was already increased and other to register the final value. i dont know why 1 and 2 values were used.
If my understanding of the TriForce% from GDC and my own experience with programming is any help: Overlays aren't menus. Menus are overlays. This game, and probably a lot of other games on the N64, tend to use a design pattern where an instance of an object will usually have its methods (Code for acting on their data structure proper.) copied into RAM and executed there, presumably to maximize performance as at this point ROM chips were definitely a lot slower than consoles. I don't know if we saw any of the actual overlay-loading code, but my guess is most the game states, like other objects, make use of this system.
this is why commenting and documention is more vital than the code itself, this is what alot of ppl don't understand, when we make things we decide what are the limits and most of our intents wich isnt usualy in the code thats why the documentaiton is vital, whats the points, whats the goal what are the limits and then also what are unforseen clashing of certain things
To be clear this is a decompilation of a OoT cartridge. Somebody (probably a whole lot of somebodies) rebuilt this C code out of the disassembled byte code from a cartridge-along with some decompilation tools. The original source code made by Nintendo probably has comments in it, and those comments are probably in Japanese. The people who did the decompiling themselves likely didn’t know the purpose of most of these things and used a lot of guess work to get the repo to where it is. A complete decompilation with thorough documentation for OoT is a huge, huge project
@@Daimondz1239 indeed but I’d also like to add that the naming convention they chose is very good, and probably much more expressive than the original code More than documentation and comments, picking good, explicit names for your functions and variables is what makes code easier or harder to understand. And in the late 1990s, it was pretty common to use short, cryptic names that convey both the content but also the type of the variable (so, stuff like pszBuffer which in just a few characters tells you that it’s a pointer to a zero-ended string). As someone else mentioned, C89 restricts variable names to 31 characters, and I believe there was no namespaces either, so this kind of things was necessary, but it’s more difficult to read in 2024 So, while documentation is lacking, what I see here is honestly one of the best situations I’ve seen in my career, with decent comments and explicit names. Good job to the guys who decompiled it
The preprocessor conditionals are curious because those cannot come from decompilation. One could tediously derive local variable and struct field purposes to name them, but you cannot unwind macros or code that was never in the binary.
// string "ZELDAZ" commonly known as a magic number Also, being reverse engineered code, none of the comments or variable names come from the original source code. The zeldaret team doesn't have access to the original code.
@@lucetubegplusstillsux2678 Yup! Being overly pedantic, that's neither a code comment nor variable name (though, being debug output, it can and does contain either!)
The ZELDAZ string is part of the sanity check for the save data. I think if any character is non-matching, then the save is considered corrupt even if the checksum is correct.
@@mzxrules Correct! Magic numbers are commonly used to identify file formats. If it's not "ZELDAZ", it could be a save file for another game entirely-or some other kind of file that happens to store a checksum in the same place as OOT
@@valshaped under normal circumstances, it is fairly difficult for the save chip embedded into the Ocarina of Time cartridge to hold save data for a completely different game. Rather, the problem is that the checksum algo for saves isn't particularly good for verifying data integrity. It simply treats the Save struct as an array of u16, and adds everything up. This means that a Save struct that was wiped to all 0s (which isn't a valid save), will pass the checksum
@@benvillalobos No reason to not be proud of anything man. You're curious and exploring new stuff. That's awesome. Just because you're on camera doesn't mean you have to be omniscient.
If I remember correctly, the section of code with the unused cutscenes that he looked at is what I call the cutscene exit command control codes. Zelda64 has at least two different cutscene systems, one called OnePointDemo which you might imagine involves focusing the camera on one subject matter (a door unlocking, a chest dropping from the sky), and the other one is a "script" based cutscene system. The "script" based system is just a list of commands which are generally associated with a start and end frame for when the command should be active. One command is the cutscene exit command (decomp calls this CS_DESTINATION), which runs a script that acts as the end of the cutscene because it spawns you in a new destination. To restore them, you can modify an existing CS_DESTINATION to have w/e and it should usually work out of the box.
I think you would absolutely love going through the Super Mario Bros 3 (NES) codebase, decompiled and annotated by Captain Southbird. I've been doing that for many years. It is a true treasure trove.
@@Digitalgems9000 actually no, functions, function names and in fact all code is not the same. A decompiler takes machine instructions and translates it into C code that would compile into the original. So functions you see in this version may not even exist in the original. It's the people working on the decompiled version going through and naming things when they try to figure out what it actually represents. And that is why it's misleading to call this the source code for Ocarina of Time because the original source code will be totally different.
@@rosen8757 because i have a codebase for a game called risk your life 2, by planetwide games. it was a big mmo back in the day, and it even has the comments and the old visual studio build files. server library and client side engine. the whole shebang. it's gigantic. looks like a team or studio had to work on it it's so big.
@@Digitalgems9000 in some cases it can, for example if the N64 architecture has some system calls at specific values and the decompiler knows this it can mark those function calls with a correct name, but for any user code no.
Hey folks! This video recently hit 100k views, which is absolutely mind-blowing. This has become a series and I'm getting close to cracking that opening cinematic! Some context and corrections below:
What this codebase is: I called it "source code" but it's really not. Here's the deal: First, Nintendo wrote the original C "source code" for Ocarina of Time. To run it on an N64, they compiled it down to "machine code" that the N64 understands, but is tough for humans to read. The ZeldaRET team then analyzed that machine code and reverse-engineered it into C code that compiles back to the original machine code. So, while both codebases create the same game, they aren’t the same code.
Mistakes will be made: I hadn’t touched C in over a decade before this, and I record these off-the-cuff to keep it interesting. Minor mistakes are edited out, and future videos will include corrections when possible. My aim here is to share the process of diving into unknown territory and learning along the way. As one viewer put it, this is like exploring the Water Temple for the first time-but in C.
Check out the comments: The comments have been an incredible resource for corrections and in-depth explanations. The community here has been awesome.
A huge thank you to everyone who's enjoying the series. I'm glad this is as fun for others as it is for me.
Great stuff bro. Thought you had 2-300k subs upon clicking lol. I'm a new creator and get the same comments, so now I understand how they feel ;) Hope you keep growing, you deserve it
I wish there was more content like this on the platform. I absolutely love watching breakdown of old games. Impressive C knowledge bro
Thanks for the kind words, more to come soon!
As a Zelda Fan & Coder, it makes me really appreciate looking at this code and being able to understand it.
If you were alive during OOT it was an experience. Everyday go home play, get stuck goto school and at the lunch table everyone would be trying to help each other get further. It was so fun when you found out something the group didn't know. A time when running to guides was way way less common.
I took the day off work to buy it
You know what’s insane the same thing happened to breath of the wild for me in school and everyone would ask how to get the master sword… but I love all the old games better
Yeah those days were truly magical. My best friend and I resorted to calling a national "nintendo hotline" with a minute fee, where we'd get guidance on how to get unstuck in the Water Temple
@@DanielChristensen-mb5qr The water temple was our depression period lmao. No one could figure it out for weeks
my siblings and I pooled our allowance money to get this gem - probably a monthly wage back then in 1999 Nigeria. Booting it in the N64 was a surreal experience. Good times
I suppose I cannot exactly blame you for misunderstanding the DmaHandler typedef given that your IDE did not actually take you to the definition of s32 for whatever reason, and function pointer syntax in C is miserable
In case it is not mentioned later in the video, and in case anyone is curious:
'typedef s32 (*DmaHandler)(args...)' means that we are defining a type named DmaHandler, which can hold pointers to functions which have the arguments (args...) and return a value of type s32.
The definition for s32 itself would look something like 'typedef ... s32'. The name of the type comes last usually.
EDIT: Some more notes:
13:45 - A double is a 64-bit floating point value. A 'long long' is a generic type defined to hold at least as much as a 'long'. (It is vague because C's standard does not like to give actual bit counts to anything, so as to be more portable, but on most systems you will ever use, a 'long long' will be defined *in the implementation of the standard* as a 64-bit integer.)
17:55 - A short is usually 16 bits
Thank you for such a detailed comment! Your explanation on DEFINE_GAMESTATE is extremely helpful, cheers!
That's why I love humans
You're a complete boss :D
Small correction: the N64 does not run any operating system. The code runs bare metal. The way those processes are created and handled is via interrupts. Each time a "process" has to run, the cpu jumps to the global exception handler and from there it jumps to the appropriate code (the "process" code)
@@SimoneN64 That seems like an OS? It is obviously far simpler than Windows or Linux, but those are not the only kinds of operating systems. I'm slowly confused by what distinction you imagine there is. Even an OS like Windows does not run code in some magical place; it is still on the CPU, just perhaps in a lower privilege level. And, it also uses interrupts to implement its scheduler!
hey mate, randomly got this in my youtube algorithm. i'm a dev from australia, and i thought this was a really great watch. very fun to see old games dissected and the thought patterns behind them
This was a total experiment, so I'm glad to see others enjoying it as well!
@@benvillalobos i was similarly blessed by the algo with this. i would totally watch a whole series of this
Same here
I’m currently studying CS, I really underestimated how hard it is but I find this super interesting. Thanks UA-cam algorithm for recommending this dudes channel, great video dude
There's always something to learn, no matter how long you've been at it :) cheers!
do {...} while(0) is a common idiom for C macros to ensure the body of the macro is a single statement that requires a semicolon after it. Basically, it makes the syntax when using macros identical to when calling a function.
do (...) while(x) can also be used as one would use a while loop but ensure the loop runs once before evaluating if it should run again
Yes, but that's a more commonly understood fact because that's the intended use of do-while loops.
OoT started off as an N64DD game originally. So it's interesting that the devs left a lot of that disk drive boot code in the game at the beginning. Also, they were gonna use the storage on the disk to save things like link's footprints in sandy areas etc. It was going to be a persistent open world game, so it's cool to see when they downgraded the game, they left a lot of that ambitious stuff in the code base.
Ocarina of time... What a beautiful memory ❤
This is my most memorable game I ever played, I think I was around 11 years old when I played it and it took me like 3 months to finish and it was breathtaking all the way through. I did .net and java in university so I could somewhat follow along. What really strikes me is that this was created all by hand, no AI sh*t, nothing, just pure good old fashioned human ingenuity. Loved this video, enjoyed watching every minute of it! Kudos to you mate!
Thanks for the extremely kind comment :D
@@benvillalobos You're most welcome, definitly make more content along the lines of this video, I'm sure many will appreciate the content!
Best game man has ever made. Complete game changer in so many ways.
Thanks for posting a video like this. I wondered how programmers often delve into codebases and I wanted to learn from them and you're my first concrete example of how it's done.
I feel like such a dum-dum every time I try to read a big C project like this alone (coming from a higher level background like C#, js etc).
It's so cool to get through it with you and see you have the same question I would have along the way, plus it's easier to see in video format, would love to see other things like these !
This is the equivalent of staring at an absolute breathtaking sunset for me. Video game code is so amazing, I just adore it.
Subscribed!
Never seen your channel, but as a lifelong Zelda fan who recently stumbled into Tech I can say the timing could have never been better
i was ready for this, 20 years ago
lets go
That title song hits so hard for me. It’s just a wash of good nostalgia coming over me.
I never write production C in my life, seeing this, I'm truly is a quiche eater
Man, what a nice and different video, i'm not into the code word, but that breakdown of the game was amazing, make more content like this.
Instantly subbed. I’ve been wanting someone to explore the codebase of this game for a while.
The decomp is wonderful
I also started streaming/playing master quest and managed to beat the Demi tree so far.
🤘🤘
Dude thank you for covering this! I'm on a binge of looking at old game source code and trying to mess with it -- please keep it up. I start with doom/wolfenstein, but just as OOT, there are more games out there! Keep it up man
brb watching more of your series on this
would love to see a whole series of this with Nintendo's N64 games.
This was super fun to watch!
Would be neat to also see how they go about doing some actions like, how does their ledge detection work, or what goes into Links Attack, etc you name it!
Great idea ! And you are right about the music its so good.
i used this as my asmr video to calm myself before sleeping
This video is incredible man. Thank you for this
I didn't know about mermaid, that's really cool! Thanks for making the video, found it fascinating
@3:45 the way you talk about source code,
reminds me of a way to approach sheet music
i just started my first year as CS undergrad, i may not understand everything just yet but the concept of this video is interesting and this was enjoyable to watch. nice video man
Thanks for the kind comment, good luck on the journey!
@@benvillalobos thank you, and also if you plan on looking into any other games if its possible to access the codebase for mario 64 or Mario galaxy ill definitely be tuning in 😩
im only 10 minutes in but im really enjoying how you're explaining all this. i've been modding zelda oot since like, 2010, but it was all hex values and very rudimentary programs that could only do so much. ever since the game was decompiled, it's been my understanding its the premiere way to mod oot now, but i've never been able to interpret code quite like this. i don't know if you plan to go further, but i would watch a series of this. its pretty good
Took me 10 mins to remember I don't understand coding 🤣
Just because you don’t understand decompiled C that came out of Japan doesn’t mean coding is beyond your comprehension
If you ever want to fall down the rabbit hole, check out the free course CS50 by Harvard
Wait this is coding? I thought this was ASMR.
Over the years people have explored this game so hard like it’s the video game form of the Da Vinci code haha. I played this game so many times over the years and even did glitch speedruns when I got older that were fun. OOT itself is this weird game to me that feels very biblical in a lot of ways, and I’ve developed a deep personal connection to it after playing it so much, and mastering the different versions. I can’t really explain why though. I think the SRW series gives me that feeling too, but I dunno. It’s just a mindblowingly cool game.
Now you can see why companies hesitate to release super old titles that they haven't touched in ages, as well as why it takes so long. This is the sort of thing I do for a living. Not being able to debug the code while trying to figure out what's happening is a nightmare.
and also why they usually just emulate it.
Volunteers made a customizable PC version in a matter of months, what are you talking about?
Damn, I didnt even know we have access to a decompiled version of OoT. I need to check out that code asap :D This game is literally what even got me into Programming 11 years ago, bc watching Speedruns of it was so mesmerizing. :)
wow awesome video! Im glad youtube put this in my feed its a super interesting watch
This was pretty fun to watch. Super Mario 64 code is also great to analyze.
How did you link to a ty search like that?
Dis dude's hair is on another level. It's like, 'what if Akira Toriyama designed Max Fischer from Rushmore?'
I would watch 300 hours of this.
Just started to dabble in C to learn some programming, this video sure is pretty insightfully for me even though I don't understand too much.
Mainly I just wanted to throw in the analogy that watching this is like playing through Water Temple for the first time but in C :P
Oh this is incredible, please make more!!
Wow I love that they were using actual musical notation for the ocarina code. I mean of course they were, but you just never think about it unless you see it in text.
I have been blessed by the algorithm - this is awesome thanks.
If you're taking suggestions: Goldeneye please
Please continue doing this z64 video series. Triple Like!
From what I saw here, I would assume newf was the string used to initialize the new save file name, i.e. filling it with blanks for final builds, but for debug builds the string was "ZELDAZ"
fb stands for framebuffer, sp stands for stack pointer. Stack Top gets the element from the top of the stack. Surprised you didn't know that, it's usually tought in Comp Sci
What a time to be alive!
man i wish i can write code like this look so fun
Just found you and really enjoying the video so far. :-) I know it's been two weeks but I think I can add a bit of background to two things in the initial #includes:
CIC is Nintendo's copy protection chip. One's on the cartridge, one in the console.
N64DD is the Nintendo 64 Disc Drive, a failed addon to the N64. OOT was initially developed as a disc based game for this addon.
Congrats on making a hit video!
I found this super interesting. It made a great background video for me while I was studying. It helped me get in the right mindset to try to comprehend the geologic functions of volcanoes. Like coding to understand one thing in geology you need to understand [x] prior functions that make our world turn the way it does. So, thank you for your help!
It was fun getting lost in this code of a game I also loved as a kid. When we saw "sword health" I became very curious and personally would've gotten lost down that rabbit hole for awhile, so if you ever figure out what "sword health" is, let me know!
Also curious, how many total lines of code the game is, just for funsies.
Hope to see more like this from you if you so desire to continue down this rabbit hole. As others have mentioned I'd love to see the likes of FF7, other FF titles, other Zelda titles, and since you seem to like the SuperNin era based on your choice of music, Chrono Trigger would be a neat one.
Oh man I wouldn't be surprised if the entire codebase was in the 100k+ range. Codebases have the habit of becoming jungles over time (or dungeons in this case).
I took a note to check on sword health next time I see it. Cheers, and good luck on your studies!
bro you gotta keep doing these videos! this was so informative!
That blue paint/and/or wallpaper reminds me of a certain Scott that says hey all
Not a coder, but im interested in it and this was fun to watch you poke through this although I understood very little. Would love to see more poking around if youre up to it!
08:45 DKC bangers make me feel some type of way
i wish people would do stuff like this with other games, like for an actual dev to go through some leaked source (wouldn't touch any rockstar stuff with a 6 foot pole tho) and talk about what's good, what's shit, etc
like ive literally been looking for this kinda thing pretty much since the sm64 decomp finished
high quality content you're going places so i'm subbin to follow!
Rode the algorithm all the way here!
17:30 - I imagine that's just the "magic numbers" of a Zelda save file format:
en.m.wikipedia.org/wiki/List_of_file_signatures
Subscribed in hope for more videos like this.
Those kind of markers like the "ZELDAZ" string can be really useful when you have to look at a random piece of binary memory and figure out what is wrong with it.
my childhood game!
ZELDAZ is the equivalent to BM in a .bmp file or JFIF in a jpg file, or MZ in a executable PE/COFF file from Windows.
What a nice video. Thanks
i have no idea what is going on but i enjoyed this anyway
19:00 i dont know the reason why they coded it like this, but probably the logic goes like this:
is doubleMagicAcquired= a flag that is checked at the great fairy that doubles your magic, to see if its should display the cutscene and double it, or if that already happened.
yes, you can infer this information from magicLevel, with something like: if magicLevel==16: play the cutscene, multiply magicLevel by 2, recover health to healthCapacity, and recover mana to magicLevel, else recover health to healthCapacity, and recover mana to magicLevel (skip the cutscene)...
but that assume that the programer who coded this system already knew the value of the magicLevels that the final game would use, if the beta testers decided that the game is too easy or too hard with the current maximum magicLevel and change it to, lets say 24 (and 48 when doubled), that would have required found this hardcoded reference to the 16 number (if magicLevel==16)
and if this value change again and again, the same problem would repeat, so it make sense to have 2 variables, one to see if the magic was already increased and other to register the final value.
i dont know why 1 and 2 values were used.
Thanks for being smart.. making life fun for us all :) I could never lol
13:51 no a double is a floating point, longs are integers. both are still used today as is the language that is made in ~.~
A video on how to compile into a useful rom would be helpful !
Love this
Really cool stuff hope i see more
If my understanding of the TriForce% from GDC and my own experience with programming is any help: Overlays aren't menus. Menus are overlays.
This game, and probably a lot of other games on the N64, tend to use a design pattern where an instance of an object will usually have its methods (Code for acting on their data structure proper.) copied into RAM and executed there, presumably to maximize performance as at this point ROM chips were definitely a lot slower than consoles. I don't know if we saw any of the actual overlay-loading code, but my guess is most the game states, like other objects, make use of this system.
awesome!
This is me trying to review one of my coworkers Pull Requests
this is why commenting and documention is more vital than the code itself, this is what alot of ppl don't understand, when we make things we decide what are the limits and most of our intents wich isnt usualy in the code thats why the documentaiton is vital, whats the points, whats the goal what are the limits and then also what are unforseen clashing of certain things
To be clear this is a decompilation of a OoT cartridge. Somebody (probably a whole lot of somebodies) rebuilt this C code out of the disassembled byte code from a cartridge-along with some decompilation tools. The original source code made by Nintendo probably has comments in it, and those comments are probably in Japanese. The people who did the decompiling themselves likely didn’t know the purpose of most of these things and used a lot of guess work to get the repo to where it is. A complete decompilation with thorough documentation for OoT is a huge, huge project
@@Daimondz1239 indeed but I’d also like to add that the naming convention they chose is very good, and probably much more expressive than the original code
More than documentation and comments, picking good, explicit names for your functions and variables is what makes code easier or harder to understand.
And in the late 1990s, it was pretty common to use short, cryptic names that convey both the content but also the type of the variable (so, stuff like pszBuffer which in just a few characters tells you that it’s a pointer to a zero-ended string). As someone else mentioned, C89 restricts variable names to 31 characters, and I believe there was no namespaces either, so this kind of things was necessary, but it’s more difficult to read in 2024
So, while documentation is lacking, what I see here is honestly one of the best situations I’ve seen in my career, with decent comments and explicit names. Good job to the guys who decompiled it
I feel like an alien reading another alien's language
Interested people are interesting. Keep up the stuff you find intriguing it’s fascinating seeing people walk through thought processes
i love the mysterious bg music to this
Donkey Kong country!
Not going to lie, when I saw the thumbnail I thought it was Dave Grohl playing zelda.
Good shit I can vibe to.
Guessing the ZELDAZ might be an error checker for corrupt saves - ie the bytes need to start with that string to be a zelda save just a guess though
Mario 64 next please. That will be very popular
Not one of mine, but it’s a great game with great music.
The preprocessor conditionals are curious because those cannot come from decompilation. One could tediously derive local variable and struct field purposes to name them, but you cannot unwind macros or code that was never in the binary.
This was fun man, thanks! SNES Drunk background music?
He makes a good mix 👌
this is the future of university right here
How did they get symbols (variable names, function names, files, etc) out of decompiling the ROM?
really cool video, wish i was better with C
Do you have a theme or layout for Visual Studio Code? (it looks like you are using that)
I really like your setup
Nice!
// string "ZELDAZ"
commonly known as a magic number
Also, being reverse engineered code, none of the comments or variable names come from the original source code. The zeldaret team doesn't have access to the original code.
It's a debug rom so *some* of it is, the stuff left printed to the console, which still has some silly comments here and there.
@@lucetubegplusstillsux2678 Yup! Being overly pedantic, that's neither a code comment nor variable name (though, being debug output, it can and does contain either!)
The ZELDAZ string is part of the sanity check for the save data. I think if any character is non-matching, then the save is considered corrupt even if the checksum is correct.
@@mzxrules Correct! Magic numbers are commonly used to identify file formats. If it's not "ZELDAZ", it could be a save file for another game entirely-or some other kind of file that happens to store a checksum in the same place as OOT
@@valshaped under normal circumstances, it is fairly difficult for the save chip embedded into the Ocarina of Time cartridge to hold save data for a completely different game.
Rather, the problem is that the checksum algo for saves isn't particularly good for verifying data integrity. It simply treats the Save struct as an array of u16, and adds everything up. This means that a Save struct that was wiped to all 0s (which isn't a valid save), will pass the checksum
really cool video, an instant subscribe
So, have idea to make more this kinda of videos?
Greetings from Brazil
It's already a series ;) Thanks for the comment!
A long long is not a double. A double is a double precision floating point number. A long long is just a 64 bit integer.
Not proud of that misspeak 😉
@@benvillalobos No reason to not be proud of anything man. You're curious and exploring new stuff. That's awesome. Just because you're on camera doesn't mean you have to be omniscient.
this post made by BIGINT gang
i know everything and i'm a genius
Would be interesting to start going through gameplay logic
Yes
Getting there, slowly but surely!
Very cool video. Is it possible to load the unused cutscenes?
If I remember correctly, the section of code with the unused cutscenes that he looked at is what I call the cutscene exit command control codes. Zelda64 has at least two different cutscene systems, one called OnePointDemo which you might imagine involves focusing the camera on one subject matter (a door unlocking, a chest dropping from the sky), and the other one is a "script" based cutscene system. The "script" based system is just a list of commands which are generally associated with a start and end frame for when the command should be active. One command is the cutscene exit command (decomp calls this CS_DESTINATION), which runs a script that acts as the end of the cutscene because it spawns you in a new destination. To restore them, you can modify an existing CS_DESTINATION to have w/e and it should usually work out of the box.
I think you would absolutely love going through the Super Mario Bros 3 (NES) codebase, decompiled and annotated by Captain Southbird. I've been doing that for many years. It is a true treasure trove.
I'll keep that in mind, cheers!
This is not the source code for ocarina of time, this is a decompiled version
isn't it similar enough though? function names and stuff are the original, correct? maybe just comments are missing?
@@Digitalgems9000 actually no, functions, function names and in fact all code is not the same. A decompiler takes machine instructions and translates it into C code that would compile into the original. So functions you see in this version may not even exist in the original.
It's the people working on the decompiled version going through and naming things when they try to figure out what it actually represents.
And that is why it's misleading to call this the source code for Ocarina of Time because the original source code will be totally different.
@@rosen8757 ohh yeah that makes sense. i agree then, it's not the same at all. i thought a decompiler could xfer the function names and stuff
@@rosen8757 because i have a codebase for a game called risk your life 2, by planetwide games. it was a big mmo back in the day, and it even has the comments and the old visual studio build files. server library and client side engine. the whole shebang. it's gigantic. looks like a team or studio had to work on it it's so big.
@@Digitalgems9000 in some cases it can, for example if the N64 architecture has some system calls at specific values and the decompiler knows this it can mark those function calls with a correct name, but for any user code no.
Would love to see a whole series on this?
Do you plan to do the same for Banjo Kazooie?
One day :)
TIL LInk was 5 in OoT