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)