Language…
9 users online: Batata Douce, crocodileman94, DimeR, DixyNL, Dzing,  icrawfish,  Nanako, temsuper1, TheXander - Guests: 267 - Bots: 303
Users: 64,795 (2,377 active)
Latest user: mathew

Enabling brick blocks to collect coins above them when shattered like the other Mario games (solved)

Link Thread Closed
In most Mario games when you break a brick with a coin on top of it, it collects the coin. I made a video illustrating this here:

Link to video.

My question is how I'd enable that behavior in a custom brick block in SMW, namely the one included here as it doesn't seem to be enabled by default (as seen in the video).

Edit: solved
maybe it's caused by the block's bounce sprite, because iirc, that collects the coin.
Hi, I'm a signature!
Hack Thread
Hack Testing Status: Available.
Layout by Koopster.
IIRC the base game was specifically coded to collect coins above blocks (though was bugged, obviously), but I apparently forgot to include that with my custom bounce patch. It's been a long while so I don't remember what needs to be done to restore the behavior.


It's because of the code at $029347, where the game jumps to a subroutine for creating an invisible solid block (tile 152, which gets placed behind blocks while the bounce sprite is showing). Likely the routine originally created a non-solid block and Nintendo just never fixed the code.

Anyway, long story short, the easiest way to fix it is to just do this:

Code
org $029342
	autoclean JSL GetEmpty
	JSR $91BA
	NOP

freecode
GetEmpty:
	SBC #$00
	STA.w $16A9,X
	LDA #$01
	RTL


Professional frame-by-frame time wizard. YouTube - Twitter - SMW Glitch List - SMW Randomizer
Originally posted by Kaijyuu
IIRC the base game was specifically coded to collect coins above blocks (though was bugged, obviously), but I apparently forgot to include that with my custom bounce patch. It's been a long while so I don't remember what needs to be done to restore the behavior.


The custom bounce patch I linked to in the original post collects the coin when it's hit from below as small Mario, just not when it's broken, so maybe you can use that as a reference. Even though yours lacks that I still like it since has more options. Someone should combine the two (as well as fixing it so it collects the coin when the brick is broken obviously).

Originally posted by Thomas
It's because of the code at $029347, where the game jumps to a subroutine for creating an invisible solid block (tile 152, which gets placed behind blocks while the bounce sprite is showing). Likely the routine originally created a non-solid block and Nintendo just never fixed the code.

Anyway, long story short, the easiest way to fix it is to just do this:

Code
org $029342
	autoclean JSL GetEmpty
	JSR $91BA
	NOP

freecode
GetEmpty:
	SBC #$00
	STA.w $16A9,X
	LDA #$01
	RTL


The only difference I could tell using that code is that it fixes the glitch that happens when the bounce sprite collects the coin, which someone already posted a fix for in another thread. I want to enable the coin to get collected when the brick below it is broken like in the other Mario games.
I updated the original post to clarify my question and explain it in a simpler way.
Made another video illustrating this concept. Should be clear now.

Interestingly, out of all the games I tested, Super Mario Land 2 was the only game that doesn't do this (doesn't collect the coin when the brick is hit by small Mario either, unlike Bounce Block Sprite & Tile Generation Unrestrictor v0.91).
I realize I'm one of the few who could reasonably help with this, being the author of the original bounce blocks patch, but it's been so long since I've hacked that I honestly don't remember.

I do recall including an optional fix to invisible solid block problem when collecting coins. You could check the address that it hijacks to trace the subroutines. I imagine the solution will be a simple subroutine call.
Originally posted by Kaijyuu
I realize I'm one of the few who could reasonably help with this, being the author of the original bounce blocks patch, but it's been so long since I've hacked that I honestly don't remember.

I do recall including an optional fix to invisible solid block problem when collecting coins. You could check the address that it hijacks to trace the subroutines. I imagine the solution will be a simple subroutine call.

Specifically, address $029265 does this thing.

If you want to use the code, use this snipped:
Code
PHK
PEA .JSL2RTSreturn-1
PEA $8070
JML $029265
.JSL2RTSreturn

(The code has to be placed in the bounce block, specifically in the init code.)

Edit: Fixed the RTL address.

Edit²: And added some information

Edit³: Wait, it crashes. I'll fix it later.

Edit4: Forget Edit³. That was on my end.
I can't check now, but if that's another fix for the invisible block glitch, that's unnecessary since Thomas posted another way to do that (and someone else in another thread as I said before). What I still can't figure out is how to make Mario collect the coin when the brick is broken from below.
Originally posted by smwln
but if that's another fix for the invisible block glitch

It isn't. SMW only has got one routine to collect a coin from a bounce block (it would be otherwise very unnecessary). The only way to fix this glitch is such hijack the place where SMW places the block when the bonce block collects a coin (i.e. Thoma's code).

Originally posted by smwln
What I still can't figure out is how to make Mario collect the coin when the brick is broken from below.

As such, my code isn't a fix to the invisible coin glitch but it's the solution to your problem, to make a bounce block collect a coin above it.
That's not my problem, though. This bounce block already collects the coin when it's hit by small Mario as seen in this video that I made. What I was asking specifically is the coin getting collected when the brick underneath is broken which doesn't involve a bounce sprite, AFAIK.
Okay, now I get this. The question was quite ambigious anyway. The fact that others has confused this question with bounce blocks instead of the shatter didn't help.

Anyway, I know the reason why the brick block collects the coin when creating a bounce block but not when shattering the block: Bounce block unrestrictor's bounce blocks are literally SMW's blocks (up to running the same of the bounce block's code) but with custom graphics and a different tile changing routine. This means, they have got the same properties as most of SMW's bounce blocks including collecting coin.
In contrast are the custom bounce block patch (not the bounce block unrestrictor which you use): None of the custom bounce blocks collect coins automatically and you have to add the code manually.

The solution to your problem (your actual problem, not the one which we confused to) is to download this modified block. I haven't tested the block whether it works but the code to collect the coin itself works (I have used a different brick block to test the code, btw).
What I have done is to check whether the block above the brick is a coin (which includes munchers, brown block and p-switch coins). If it is, it collects it, else it won't.

Edit: Fixed some stuff.
The game crashes whenever the inserted block is shattered. I also tried a clean ROM (aside from bounceunrestrictor.asm also being applied), same result.

I also tried adding your code (the "CollectCoin:" part and everything after, I'm assuming) to Kaijyuu's bounce block, which seemed to have no effect.

Edit: It probably had no effect because another part of the code is supposed to call the CollectCoin section, as I found out when making the post below, lol.
Amazingly, I somehow got it to work, despite having barely any ASM skills, just by randomly adding and removing lines. I just changed this part:

Code
		LDA.b #!ShatterType
		PHY
		PHX
		JSL $028663
		LDA $98
		PHA
		LDA $99
		PLA
		JSR CollectCoin
		PLA
		STA $99
		PLA
		STA $98
		PLX
		PLY
		PLB
		RTS


To this:

Code
		LDA.b #!ShatterType
		PHY
		JSL $028663
		JSR CollectCoin
		PLY
		PLB
		RTS
Alternatively (even more recommend), you could have changed
Code
		LDA $98
		PHA
		LDA $99
		PLA
		JSR CollectCoin
		PLA
		STA $99
		PLA
		STA $98

to
Code
		LDA $98
		PHA
		LDA $99
		PHA
		JSR CollectCoin
		PLA
		STA $99
		PLA
		STA $98

The reason I put these is because my routine modifies these values and the game use them later in the block. Removing pushes isn't generally a good idea.
And why the block crashed before: The code was supposed push A twice and then pull it back. But I unfortunatelly had written for the second "PHA" "PLA" instead which means the CPU had pulled two values too much, thus messing up some return addresses and causing the crash. Of course, removing them "works" too but as mentioned above, it might mess up some stuff when the block use $98 and $99 afterwards.
I will do what you suggested. Like I said, I was just randomly adding and removing lines until it seemingly worked, and I only tested it for a bit. I wouldn't want it to mess something else up.

This is pretty much solved now, but I have one more quick question: How would you make it so it can be shattered from above with a spin jump like in Kaijyuu's SMB3 brick? Looking at the code, it seems they're coded pretty differently so I can't just copy and paste that part to the other block.

Edit: I noticed another issue as well. I just made a new thread so I'll mark this as solved.
I would love it if you can make RussianMan‘s coin sprites stunt on top when the bricks broke. Only sprites (enemies) on top of the brick block stunt when it’s broken not block tiles (coins).


You should avoid bumping old threads; if you have a new question, make a new thread. Or more specifically, since you have a request, make a post for it in the requests thread.

Professional frame-by-frame time wizard. YouTube - Twitter - SMW Glitch List - SMW Randomizer
Link Thread Closed