There's a trick in Super Mario World that allows you to always get every 1up from the small bonus rooms with 3 ? blocks in a row. All you have to do is swing Mario's cape into the left side of each block, and it will always result in a green circle.
It's not just a game of chance any more!
Why on earth would that affect the random result of these blocks? Time to dig into the code.
Here's the block of code responsible for determining whether hitting one of these blocks will give a green circle, or a brown block:
;$00F226: Check if a bonus ? block should
; be a green circle or brown block
CheckBonusBlock:
LDA VisitedBonusGameAlreadyFlag
BNE ProduceBrownBlocks
TXA
BEQ .firstBlockHit
LDA #2
.firstBlockHit:
EOR #%11
AND FrameCounter
BNE ProduceGreenBlock
ProduceBrownBlocks:
;...
The first couple lines detect if you have already visited the bonus room already in this level. This flag gets set when you leave the room, so you can't just go back and reenter the room over and over again to rack up lives. Instead, if you reenter the room, all the blocks will always turn brown.
Then the X register is transferred to the A register. All you need to know at this point is that X will contain zero if no block has been hit in this row yet. If a block has been hit already and this is the second block to be hit, X will be something other than zero. (We'll talk about what exactly another time.) If X had zero, then A gets zero, and is exclusively OR'd with 3 (11 in binary, the lowest 2 bits), which results in 3. Otherwise, A gets 2 before being XOR'd, which results in 1 (01 in binary).
This finally gets AND'd with the game's frame counter to determine the final result. If the result of the AND is zero, then you get a brown block, otherwise you get a green circle. Here's a neat table of all the results that could possibly happen:
| Frame Counter's lower 2 bits | First Block (A = 11) | Second Block (A = 01) |
|---|---|---|
| 00 | 00 ✗ | 00 ✗ |
| 01 | 01 ✓ | 01 ✓ |
| 10 | 10 ✓ | 00 ✗ |
| 11 | 11 ✓ | 01 ✓ |
This means that you have a 3/4 chance of getting the first green circle, then a 1/2 chance of getting the second. This means in total, you have a 3/8 chance of getting the 1up in each row. Your expected number of 1ups per bonus room is then 5 times that (there are 5 rows of blocks), so 15/8, or just under 2 1up mushrooms.
This doesn't explain why the cape trick works though. What here makes the probability go from 37.5% to 100%?
It's pretty simple really. Simulating physics can be pretty resource intensive. Calculating interactions between every object in the level every frame is a lot of work. So some processes are only done every other frame, or every fourth frame.
When Mario spins his cape, the game checks four separate locations for cape-to-block collisions.
Points A and D are at the extent of the cape's range, while points B and C are right next to Mario himself.
Only one of these points is checked each frame. When cape spinning, the cape is on either side of Mario for four frames each. The game also alternates which of the two collision points per side to check. This means that there is an 8 frame pattern that the points are checked: A, B, A, B, C, D, C, D. (Yes, that means that it's not symmetrical--notice that this pattern results in far, near, far, near, near, far, near, far in terms of proximity to Mario.)
This means points A and C are checked when the lowest bits of the frame counter are 00 and 10, while points B and D are checked when the lowest bits are 01 and 11. Let's revisit that table:
| Frame Counter's lower 2 bits | First Block (A = 11) | Second Block (A = 01) | Cape Interaction Points Checked |
|---|---|---|---|
| 00 | 00✗ | 00✗ | A & C |
| 01 | 01✓ | 01✓ | B & D |
| 10 | 10✓ | 00✗ | A & C |
| 11 | 11✓ | 01✓ | B & D |
If you look carefully, that means that if cape interaction points B or D are the points that happen to collide with the ? block, it will always be a green circle.
Point B is hard to isolate--you're pretty much always going to have point A also colliding with the block at the same time. However, point D is easier to isolate since it is on the very tip of Mario's cape when it is on the right side of him. Therefore, just by standing a few pixels away from the left side of each of the ? blocks, we can ensure that cape interaction point D will always be the one to collide with the block (and never point C), and we will always get a green circle every time.
Now your expected number of 1ups to get from these bonus rooms is 5 1up mushrooms!
There's no excuse for not getting all of the 1ups now.
You can support Retro Game Mechanics Explained on Patreon here! Any and all support is greatly appreciated!

