Language…
5 users online: anoMaly666,  Atari2.0, BabaYegha, sinseiga, Tsquare07 - Guests: 247 - Bots: 334
Users: 64,795 (2,375 active)
Latest user: mathew

?-Blocks in the switch Palace FG/BG-setting

Not sure if this is the right place for this topic, as this isn't exactly important or anything, but I was wondering about that ?-Block-bonus game where you could potentionally get a 1-up when you hit three blocks in the right order.

I still remember somewhat when I attempted to try to make some use of it way time back in 2002 and of course it didn't really worked too well. I guess everyone who tried it probably also encountered these used blocks popping out of nowhere when they placed the blocks into their level.

And I dunno, since then I was always kind of curious how they work, so... I figured it couldn't hurt to ask:
Did anyone ever looked into it in regards to how they actually work? I assume it's some kind of strict x/y-position-kind of thing?

I have a feeling it must be something very limited considering that even Nintendo never bothered to create more than one setup for these blocks, they just re-used the same room over and over in SMW. #ab{<_<}

Made use of them myself once

I'm pretty sure they're both related to strict x-position (if you lose the game, one block must know the position of the other two to change them) and y-position (as seen in the video, winning the game once in one specific y-position makes all blocks in said position give lives, so the game probably keeps track of games won by y-position; not to mention the disposition on the screen varies per y-position, and I don't believe any positions are specified/work, just a few, which would explain why I had to repeat it for the 2 last games).
It's easily the best thing I've done
So why the empty numb?
I have looked at the routine once so I can tell you what it does and what shenanigans can appear (though the explaination is a bit difficult for me to describe without a flowchart): The routine at $00F1F9 handes the ?-coin blocks for the switch palace tileset. The first thing it does is to get the group i.e. the level is split vertically into groups with a height of four blocks where the first four blocks make up group 0, the next four group 1, etc. It spans over two subscreens so group 8 is identical to group 0 and so on. It then takes the horizontal position within subscreen and use that as an index to $00F0EC which is a list which blocks will change in case you are unlucky. That value is always kept track in $13F3,x (where X is the group ID).

Now we get to the part where jank appears: Only blocks at a certain column are effected as seen by the table $00F0F8:
Code
$40,$50,$00,$70,$80,$00,$A0,$B0

Basically, only the columns where the ?-coin blocks are normally located but also the leftmost block of the screen are effected while no other block can be affected.

How does the game know which blocks to affect and why it never happens when the blocks are placed as intended? With the table of $00F0EC, of course. $00F0EC contains a list of values which tells you which blocks still can be activated on that current group and which one can't. That works bitwise where bit set means no block can be activated in that group while bit clear means there still are blocks which can be hit. This is dependent on the block's X position but it does result in jank if the posions aren't as expected:
Code
$08,$01,$02,$04,$ED,$F6,$00,$7D,$BE,$00,$6F,$B7,$40,$50,$00,$70

Usually, only two bits are clear (so only two blocks get affected at most). However, only positions 4, 5, 7, 8, 10 and 11 are valid (the bold values), while 0 - 3 and 12 - 15 will load garbage values and 6 and 9 are set to $00 which may result in more blocks getting activated than expected.

To see the maths in action:
Code
$ED = %11101101

$01,$01,$01,$00,$01,$01,$00,$01	; Bitmask
$40,$50,$00,$70,$80,$00,$A0,$B0	; Positions
$00,$00,$00,$70,$00,$00,$A0,$00	; Affected positions


But what if the position is invalid? Then this happens:
Code
$50 = %01010000

$00,$01,$00,$01,$00,$00,$00,$00 ; Bitmask
$40,$50,$00,$70,$80,$00,$A0,$B0	; Positions
$40,$50,$00,$70,$00,$00,$A0,$B0 ; Affected positions

As you can see, now five blocks are changed instead of the intended two (plus the block at that position)!

There is some further jank: When you activate the block, the X position's value is OR'd together with $13F3,x (after all, the game will need to always give you a 1-up if you timed the ?-blocks correctly twice which happens when no block is set to be unactivated). This allows you to create further jank where only selected positions will cause a used block (though as a side effect, this will stop most glitches as well).

Interestingly, if you look up what $13F3, you'll notice why Mario may get suddenly inflated if he hits a ?-coin block at the Switch Palace tileset: The coin block table is actually kept track at $13F4 meaning only groups 1 - 5 are valid while group 0 (aka the topmost four blocks) points to $13F3 which is the inflated Mario state (this causing the infinite P-Balloon glitch if you enable a coin block at the first four blocks of a level save for two positions), group 6 points to $13F9 which puts Mario behind the foreground (but only temporarily) while group 7 points to $13FA which allows Mario to jump out of water (no effect practical effect).
@Koopster: It's definitely great to see them at work in a hack, and I say you used an interesting setup - the last row is especially nicely done, because you make it look like it was intentional that they would give just lives in this particular case.

@MarioFanGamer: Wow, thanks for that thorough and insightful response - it's definitely answered a lot of things I wondered about for a long time. :) Very interesting for sure!