you may have seen the speedrun of super
mario brothers 3 that completes the game
in just about 11 minutes
the general route is pretty simple
gather two warp whistles from these two
stages in world 1
use them together to go directly to
world 8 then get through that world and
defeat bowser
but even a straight line isn't always
the shortest path
sometimes the shortest path is through a
wormhole
on august 1 2020 zakubi achieved the
seemingly impossible feat of beating the
game in 3 minutes and 2 seconds
this is the super mario brothers 3 any
percent speedrun explained
[Music]
the first 2 minutes are very similar to
the any percent no wrong warp run by
mitch flower power
zakubi gathers p-speed early in this
level and blasts through it with ease
[Music]
[Applause]
[Music]
notice how the hammer brother moves only
once at the end of the stage
this will be the case for all four
hammer brother movements in the run
this optimal pattern which only has a
three percent chance of happening
is required to get such a good time but
the first hammered weather movement was
actually manipulated
this game's random number generation
function runs on every frame and always
goes through the same sequence of
numbers
as a result any random element can be
manipulated by having it happen on a
specific frame
by waiting on the title screen until
this exact time the qb set up the hammer
brother to move by only one tile as long
as he finished 1-1 within a 5-frame
window
after that it becomes too difficult to
finish levels with this kind of accuracy
so the remaining movements are
essentially random
this does bring up the chance of optimal
movements from 3
to 6 assuming the manipulation is done
right
quick side note in my previous video i
made a mistake with the odds of each
direction of a t-shaped intersection
all of the percentages in this video
have been corrected to reflect the
actual odds
[Music]
in this level he does the same strategy
of reaching p-speed on the pipe
then tries to get mario to run down
slopes as much as possible
[Applause]
mario runs about five percent faster
down slopes with a speed of up to 59
compared to 56
on flat ground over the course of the
level running down slopes saves about 3
or 4 frames
[Music]
[Applause]
[Music]
here the strategy is again identical to
the no wrong warp run
zakubi needs a mushroom to get the super
leaf in the next level and he needs to
wait four seconds on this block to reach
the secret exit and get the first warp
whistle
[Music]
now all jakubi needs is the second warp
whistle from this fortress's secret exit
which he flies up to using the super
[Music]
leaf
[Music]
here though he doesn't go into world 8.
instead he goes into world 2
then warps to world 7. why do such a
thing
well let's see what happens
[Music]
me
[Music]
and that's it that's the run so what
happened
in short mario hit a glitched note block
and the game crashed in the perfect way
to make it immediately load the ending
sequence
to help better understand why i
painstakingly recreated the run frame by
frame on emulator
the result very closely matches the
original and will let us analyze all the
variables at play
first mario hit the side of this pipe
and entered it in the wrong direction
with enough speed mario can sometimes
move into solid blocks
he can usually only stay inside of a
block for a single frame after which
he's pushed out
but by clipping inside of the pipe at
this spot he's also standing on a pipe
exit tile
normally because pipe exits are always
connected to a pipe mario can only go in
them from one direction so nothing was
made to specifically prevent mario from
entering them the wrong way
so by pressing down against the top of
the pipe exit tile mario goes down into
it instead of up
when mario's traveling in a pipe he
simply moves along the pipe until he
reaches another exit tile at the other
end
however in this case there's no other
end so mario keeps going down this
glitched pipe until he leaves the bounds
of the level map
so where does he end up well this is
where it gets complicated
the level data is divided into up to 16
screens
ordered from top to bottom in vertical
levels the game uses a table as sort of
a reference sheet
for any given screen the table holds the
memory address of where the level data
for this screen is located
when mario reaches the 17th screen
there's no more level data so the game
starts to look beyond the table to find
the memory address
the address found is garbage data which
is a value used for a completely
unrelated purpose that makes no sense
when used as a memory address for level
data
the game then goes to the wrong place
and finds more garbage data that it
interprets as if it was level data so
the end result is a garbled mess
to make things worse tiles are drawn on
screen through a separate process that
also goes horribly wrong so the garbage
on the screen is different from the
garbage that is actually there
mario keeps going through this mess
until luckily at the top of the 19th
screen the garbage data happens to line
up so that there's a tile that acts like
a pipe exit and frees mario from the
glitched pipe
on the right edge is the culprit for the
whole game crash an invisible note block
the animation when mario bumps a block
is more complicated than it looks
blocks are background tiles which are
generally incapable of being animated in
this way
to get around this limitation the
background tile is removed during the
animation and replaced with a sprite
that removal is what causes the crash
super mario bros 3's rom is 8 times
larger than what the nes can load
instead of loading it all at once the
rom is subdivided into 32 banks that can
be swapped in and out of memory so that
only four of them are loaded at any
given time
the memory address for the 19th screen
happens to point to a location that's
normally used to control which banks
need to be loaded
normally only the middle two are ever
swapped out the first one is always bank
30 and the last one is always bank 31
but when the game attempts to remove the
note block tile for the bumping
animation it swaps out these two banks
instead
replacing the very code it's currently
running for a different part of the rom
this causes one of the key elements of
the nes processor to fail
the stack instructions in the code are
organized into multiple layers of
routines and subroutines so that any
given basic function has its associated
routine that can be called from any
point in the code
when jumping around between subroutines
the processor needs to remember where it
came from so that it can go back there
after it's done
this is what the stack is used for the
stack is essentially a list of return
addresses in reverse chronological order
whenever a subroutine is called the
memory address where the call was made
is added to the stack and when a
subroutine is done the processor returns
to the address at the top of the stack
to go back where it came from
typically the number of return addresses
in the stack matches the number of
layers in the subroutines the processor
is currently in
however in this case because a different
part of the rom was suddenly loaded in
this balance is thrown out of the window
after swapping out the rom banks the
processor starts running code from
inside a subroutine at the end of which
is an instruction called return from
subroutine
so the processor looks at this stack and
finds only one return address so it goes
back to that address clears
it from the stack and resumes executing
code from there
but because the wrong bank was swapped
for a new one the return address no
longer points to where it was supposed
to
instead it points to yet another
subroutine which ends in the same
instruction
returned from subroutine the problem is
there's nothing in the stack to return
to anymore
this is called the stack underflow as it
tries to find the return address the
processor loops back around to the other
end of the stack
super mario brothers 3 doesn't make use
of all 128 entries in the stack so the
last entry is instead used for other
purposes
specifically it's made up of two
variables one for the status bar mode
and one for the level mode
for a vertical stage they take up values
0 0 and 8 0.
this means that 0 0 8 0 is used as a
return address to continue executing
code
this leads directly into these variables
when executed like code they're ordered
in this way
the first byte is a code number for an
instruction and the next two bytes are
parameters given to that instruction
usually a memory address let's look at
this instruction
it's made up of the horizontal position
of enemy slots 3
4 and 5. this is interesting because all
three variables can be manipulated to
any value we want
as long as the right enemies are placed
at the right location
this means that any code instruction can
be executed here
as long as the enemies are in the
correct horizontal position
but surely you can't have three
different enemies move into pixel
perfect positions right
yes you can because that's exactly what
zakubi did
first the enemy slots were manipulated
by killing the piranha plants while
moving up in the level
and loading the enemies in the correct
order so that sloths 3
4 and 5 are taken up by these three
koopas
zakubi kills the koopa in slot 4 on this
block which puts it at position e3
next he flips the koopa in slot 3 and
goes down the pipe when it's at position
2-0
this pipe entry has a two-frame window
for the position to be correct
it's interesting to note that this part
did not go as intended
zukubi turned around slightly too early
here which threw off his usual method of
tiling the pipe entry right
to compensate he didn't turn back to
avoid overshooting the pipe and winged
it for the timing
luckily for him it worked and the shell
was correctly stopped at position 2-0
finally he carries with him the coupon
slot 5 all the way down to the 19th
screen where he throws it to the left
on the frame where its position is at 9
5 zakubi jumps
activating the crash and leading the
code to read the instruction 2 0
e3 8f 2 0 is the code for a jump to
subroutine instruction
this instruction essentially makes
execution jump to the address specified
by the next two bytes
so execution moves to 8f e3 which would
normally be the function that loads the
ending sequence
but remember after the wrong bank was
unintendedly swapped for another
the ending sequence can no longer be
found at 8f e3
except very conveniently for us one of
the things that this instruction does is
to swap the wrong banks back to their
intended positions
which means that the ending sequence is
put back in its place just in time to be
jumped to
so after all of these unintended hoops
and hurdles the game finally jumps to
the end and princess speech is rescued
many things can go wrong though before
reaching the jump instruction
the code runs through other variables so
they need to have values that translate
into code that doesn't crash or derail
execution for example the horizontal
position of this koopa is used as an
instruction as well
in this run zakubi was fast enough so
that the koopa de-loaded with a
horizontal position of 7-4
if he had been 2 frames slower the koopa
would have had a position of 7 2 instead
which translates into an instruction
that instantly stops execution
five of the 11 most common koopa
positions would result in the trick
failing
on top of that the sound engine also
runs into its own issues
in short the sudden jump to the end
sequence deletes the music data that the
sound engine was reading which causes it
to get caught in the loop
depending on where the music was before
the jump the processor can eventually
exit the loop and play this glitched
sound
or it can get stuck for longer and delay
the ending
[Music]
or even worse eventually hit an
instruction that tells it to quit all
execution
here's a quick recap mario clipped
partially inside of this pipe which
allowed him to take it down instead of
up
this glitched pipe has no exit so mario
goes down until he's beyond the bounds
of the level and into garbage data where
a note block can be found
interacting with an out-of-bound snow
block causes the game to go through a
series of unintended jumps in its code
that eventually leads it to read the
horizontal position of enemies as if
they were instructions of game code
through careful manipulation they are
set to values which translate into a
simple instruction that tells the game
to load the end screen so that's what it
does and the game is beaten this way
the run itself is so close to perfect
that with this current strategy even a
301 seems very unlikely
zakubi only lost 11 frames on the
overworld a few frames entering the
secret door in the fortress and a couple
more in 7-1
keep in mind though that improving a
stage by a frame or two most likely
would cause the hammer brother to go the
wrong way
because of that there are only a few
select frames where a stage can be
completed to get optimal patterns making
slide improvements even harder to come
by
the tool assisted speedrun uses a
completely different and faster setup
that makes use of a piranha plant to
replace one of the koopa shells but good
luck replicating that with the
controller
as of right now as close as it is a time
of sub 3 minutes looks to be humanly
impossible to achieve
if you want more in-depth information
about what goes on in the game's code
during the wrong warp
please watch this video by retro game
mechanics explained
although slightly outdated by now it was
the most vital piece of information i
had when making this video and a lot of
the visualizations were based on isoop
frieza's incredible work so i want to
thank him for making it as well as
helping me troubleshoot a few things
also more detailed explanations of the
sound glitch and other internal
mechanics written by cab audio can be
found in the video description
thanks for watching
[Music]
you