What and Why Are Super Mario Bros. Frame Rules?

Not a damnable Youtube video this time, but an honest-to-frog text post I’m linking to! A 2021 post from the blog Brandon’s Thoughts explains what you might be wondering if you watched such events like AGDQ 2025’s Super Mario Bros. race. Well, okay, I’ll give you a video (33 minutes), but it’s not the point of the post this time:

The analogy often given is to think of a bus that leaves every 21 frames, and levels can only end by getting on that bus, and so other than in the last level (which has no new level to load at the end of it), improvements in Super Mario Bros. can only happen in 21 frame increments. If you save a frame or two in a level, but it’s not enough to make the previous frame rule, it’s not enough to take the previous bus, you’ll just end up waiting for it to happen anyway.

But what a weird thing to have! Lots of games don’t have frame rules like this, so why does Super Mario Bros? What advantage did it give the game’s code to be implemented this way? Why did the game’s programmers, according to MobyGames Toshihiko Nakago or Kazuaki Morita, do it?

I’m not completely sure, but Brandon explains why they happen in his blog post. I can summarize the the details here, and give a theory.

Super Mario Bros. uses a bunch of timers in its code. Quite sensibly, they’re laid out in a region of memory so they can all be updated by the same bit of code, a loop that cycles through them and counts them all down, one per frame, until they reach zero. It doesn’t do anything itself when they reach zero; the timers are each checked in other places by the code that needs to know if enough time has elapsed, and which then resets the timer so the countdown can continue on the next frame.

Many of these timers are short, like the code that determines when Mario emits a bubble in an underwater area. But all of these timers are single bytes, so the longest they can last are 255 frames, which at 60 fps is just a few seconds.

In order to track longer periods of time, but keep the same mechanism, there’s a subset of these timers that don’t count down every second. These timers are only checked and decremented every 21 frames, which is triggered when a special extra timer goes off. The intent was probably every 20 frames, but it uses BMI, Branch if result MInus, for the check instead of BEQ, Branch if EQual to zero, meaning it takes an extra frame.

Long timers are a bit less precise than short ones. When a long timer is set, the inner timer, the one that decides when long timers count down, could be at any point in its cycle.

This timer exists to determine when the second set, of longer timers, counts down. So, those timers’ lengths are around 21 times longer than the other timers. This is the source of the frame rule. After a level has finished, the game displays a black status screen with text announcing the number of the next level (“WORLD 1-2”) and the number of lives Mario has left. This code uses a long timer to keep the message on screen for longer than 255 frames. But it has the side effect that levels can only begin at 21-frame intervals.

Other periods of time tracked by long timers, such as Mario’s invulnerability time after taking damage and and duration of invincibility powerups, are also framerule based, and can vary by around a third of a second in length.

Super Mario Bros.’ ROM space is a bit cramped, and the timers are probably implemented in this way for space efficiency. Brandon points to evidence that the game had been optimized to save space to as to squeeze in more level data. In most cases it doesn’t matter that long times vary slightly in length. Gross duration matters more than precision here, but the implication is that framerules exist. Funny, that.

Super Mario Bros. Frame Rules (brskari.com)

Ocarina of Time-r Bug

Here is a very short video from Seedy, only a minute long, explaining an interesting bug in The Legend of Zelda: Ocarina of Time.

OoT handles fiery environments without the Red Tunic, and being held underwater by wearing Iron Boots without the Blue Tunic, in an unusual away. You might expect them to return Link to the last safe place he had been, like when falling into a void, or else maybe kill him instantly, or at least cause periodic damage. Instead, for whatever reason, the designers chose a unique way to implement the danger Link is in.

While in hot places or stuck underwater without the proper tunic, the game starts a timer, with time relative to the amount of health that Link has. If Link leaves the area or puts on the right tunic before time runs out, the timer goes away and Link takes no damage regardless of how much time was left on it. However, if the timer expires before Link reaches safety, he just dies instantly, “getting a game over” in the clumsy parlance of video games. You’d think it’d be better just to inflict some damage on Link every few seconds, but that’s not how they chose to do it.

Link gets eight seconds on the clock for every full heart he has. Fractions of a heart grant proportional time. While the game only displays health in quarter-hearts, Ocarina of Time actually tracks hearts in 16ths (each full heart is effectively 16 hit points), and each 8th of a heart grants Link one second on the timer.

So, what happens if Link has exactly 1/16th of a heart? The display rounds up, so it looks like Link has a quarter of a heart left, but he’s considerably closer to kicking the bucket than that. He has less health than what’s needed to get a one-second timer. How does the game cope with that?

It does it by just not starting a timer at all! If Link is almost dead, paradoxically, he becomes immune to fire and drowning timers. He’s still in great danger, for any attack on him in this state will kill him immediately, but it makes tunic-less challenge runs a bit more interesting.

Break Timers With Low Health (Youtube, 1 minute)