How does the −1 bug work in Super Mario Bros

Original author: MagicScrumpy
  • Transfer


World −1 in the original Super Mario Bros. - one of the most famous bugs on NES. If you enter the transition zone (Warp Zone) in a special way, the game is buggy, and when you enter the pipe, you find yourself in a strange world.

You can get into world −1 by almost passing level 1-2 and standing on the pipe leading to the earth’s surface, to the flagpole and the end of the level. Then you need to move to the left edge of the pipe, bend down and bounce to the right, so that going down Mario is almost under the ceiling. It may take several attempts, but as a result it will get to the desired point and automatically pass through the pipe, and then through the wall into the room with the transition zone. If at least one pixel of the pipe is not visible, Mario will be trapped and the player will have to wait until the time runs out.

Another way to get into the world −1: break two brick blocks on the ceiling, leaving the rightmost one. Then you need to go to the left end of the pipe and jump to the right. It is not necessary to bend down in this case, because Mario may try to hit (without actually destroying it). In this case, the game will crash, and Mario will be able to go through the pipe and wall. But this method is more complicated and long. If everything is done correctly, the player will see in front of him three pipes of the transition zone. If you climb into the left or right pipe, Mario will fall into the world −1. If you go down to the middle pipe, he will go to level 5-1. In case the right wall of the transition zone becomes visible, the bug ceases to work.

But this is not the whole story of why this bug works. Some say that this happens because the world number is not displayed on the screen of the transition zone above the pipe when you enter it. But this is not true, and those who have an understanding of the mechanics of the game will never believe such an explanation. After reading this article, you can tell the dreamers what is really happening. In this article, we will analyze and reveal in detail the secrets of the “world minus one” bug.

How transition zones work


To understand how we get into −1, we first need to figure out how the Warp Zone works. There are three such zones in the game: one at the end of the world 1-2 (to go to worlds 2, 3 or 4), the second at the end of 4-2 (moves to world 5), and the third can be reached through a vine in world 4- 2 (and choose world 6, 7 or 8). Let's see how the game finds out which worlds the transition zone should lead to.


Figure 1.

The zone numbers are stored starting from the offset $ 87F2 of the running program, the data is as follows: 04 03 02 00 24 05 24 00 08 07 06 00(00 separate the zones from each other). The first 4 bytes belong to the zone in the world 1-2, the next 4 bytes to the underground zone of the world 4-2, and the last 4 bytes to the aboveground zone of the world 4-2. We can prove it by hacking the game. I used the HEX editor to change the value of 04 to 08, and see what happened:



Using memory editing, you can also get to other worlds-bugs, for example, to world 0.



The next part of the data (red in Figure 1) refers to the underground zone in world 4-2, and consists of 24 05 24. This corresponds to the transition to the world of $ 24 (36) through the left pipe, to world 5 through the middle pipe and again to the world $ 24 (36) through the right pipe. But the left and right pipes do not exist, so we can only get into the world 5. What does 24 mean in the transition zone? Numbers $ 24 at Super Mario Bros. empty spaces are indicated. They are needed because the offset $ 87F2 indicates not only WHERE the pipes move, but WHAT to write on them. The transition zone object should always draw three tiles corresponding to the zone pipes, but since there is only one pipe in the second zone, the game draws empty spaces on the left and right. We can show a hack that changes these values ​​on the left and on the right to render the values ​​we don’t need.



These transitions technically work anyway, we just can't use them without a pipe. I inserted another pipe in a hack to show you what happens when you enter a pipe that transfers to world 36. As a pipe with number 5 takes us to world 5, so a pipe without a number takes us to world _, that is, to level −1 .



Since technically $ 24 means 36, we are actually transported to the world 36. But the game denotes this number as an empty place, so it seems that we are in the world _. Actually, this is the world 36. But wait, there are 24 values ​​only in the second zone. How do we get into this world from level 1-2?

How the world −1 bug works


In fact, all transition zones are the same object. The game determines which zone to load based on the value at $ 06D6. By default, this value is 00, that is, it does not correspond to any zone. But this is normal, because most of the time we are not near the transition zones. However, near the end of level 1-2 we create a scrolling lock object.



It is created when we are horizontal in this place.

This object executes code upon creation, which also increases the value at the address $ 06D6 by one, creating pipes in the transition zone. Usually we get into the transition zone by running along the top of the screen, and another scrolling blocking object is created, which creates the correct transition zone value.



Here's how it works:

  • First, the game loads the value 04 at the address $ 06D6. This means that the first transition zone will be used.
  • Then she checks at what level the player is. If the player in world is 1, she uses 04 and saves that value to $ 06D6, and then skips all subsequent code.
  • If the player is in another world, it loads the value 05. Then the game checks what level type the player is at. If the player is at the underground, underwater or castle level, then she saves the value 05 in $ 06D6.

As stated above, if we are at level 1-2, this saving is not performed, because the game skips these instructions and the value remains 04. If the player is above ground level, the game writes the value 06 to the address $ 06D6.

As a result, for the zone of level 1-2 the value will be 04, for the underground zone of level 4-2 - 05, and for the aboveground zone - 06. The game displays the message WELCOME TO WARP ZONE if the value at the address $ 06D6 is 04,05 or 06, which is always true when we create transition zones in normal gameplay. When we go through the transition zone creation object, the game creates a transition zone greeting text.

After the text is output, the procedure determines which transition zone to load by subtracting 04 from the value of $ 06D6. So if the value is 04, we get 00, if 05, then 01, and if 06 - 02. But since we created the scrolling lock object and then entered the wall, the value of $ 06D6 is still 01.

This value 01 corresponds to the transition zone of level 4-2, so the game thinks that we are in the zone of level 4-2, not 1-2. We can verify this by going into the second pipe, which takes us to world 5. If we go into the left or right pipe, we go to world 36, or world −1. This explains how we get into the world of −1.

World −1


Why is this world an endlessly looped copy of world 7-2? First, let's see why the world −1 is similar to 7-2. When we go into the pipe, the game runs an algorithm that determines which room Mario needs to be placed in. If the value at the address $ 06D6 is 00, which happens in most cases, the game skips this code and sends Mario to the area specified in the address $ 0650.

This means that when we pass through a curved pipe at level 1-2, the value of $ 06D6 is 00, which is possible only when breaking, we go to where the offset with a value of 25 sends us, which corresponds to the end of the level. This happens when Mario enters a bent pipe. But if the value is not 00 and this is not the case of −1, because the scrolling lock sets the value to 01, then the game uses the world number to search for the corresponding offset of the area in the search table in order to understand what level data needs to be loaded.

If you set $ 24 as the level number, the transition zone code that defines the location for the transition uses $ 24 to offset the world and gets a value of $ 33, which tells the game to look for an offset of $ 33 (51) bytes from the beginning of the lookup table, which has a value of 01, corresponding to the world 7-2. The search table consists of only 34 bytes, because this is usually enough for the game, so an offset of 51 bytes is outside the area of ​​the search table, in the area of ​​the enemy data table. We take this data from a table that the search table should not really have access to. And other worlds bugs also work. So, the game loads what it considers level 36-1, but containing data of level 7-2.



Now let's find out why the levels are looped. This is because the game changes objects in these enemies. Let's see how it works. The scope change object is 3 bytes long. The first byte is the location of the object in the game, the second is the offset of the address of the area, telling the game where to send the player when he goes down the pipe or goes up the vine. The third byte is divided into two parts. The important part is the first three bits: the world number.



The current world number does not match the number in the object. The area offset is not updated, therefore it loads a clone of level 7-2 that is designed to change the area object, but since the area offset is set to $ 25, we move to world 7. When we are actually at level 7-2, the area offset is set to $ 25, because the world number corresponds to the current world number of the object.

However, world −1, which reads data from 7-2, is not in world 7, so the game does not load the offset of the $ 25 region into the offset variable, which would allow us to leave the level. Instead, it still contains the value 01, set at 1-2. Since the displacement never changes, instead of reaching the surface, the level is loaded first. Therefore, the world −1 is infinitely looped.

So we solved the riddle of the −1 bug in Super Mario Bros.! Now we know what world −1 is and how it appears, and most importantly, how we manage to get there. I hope you were interested.

Also popular now: