I downloaded mikeyk's Yoshi Coin sprite, and I was disappointed at the fact that it re-appears when I exit and re-enter the area after Mario gets it. So... I decided to work on a way to prevent it from re-appearing.
I'm posting this for anyone who would like to use it in their own custom sprites.
This code uses the item memory index just like objects do.
First, patch this to your ROM with XKAS. It sets all the values in the table to zero.
Add this to the very beginning of the sprite (or you can just type the address directly into the following pieces of code)
Add this to the very beginning of the INIT routine, right after 'dcb "INIT"'
and use this code to prevent the sprite from reloading. In mikeyk's Yoshi Coin sprite, add it after "BCC NoContact"
By the way, there might be a little bit of room for optimization in this code.
You can also use the table for other purposes, and you can add extra tables by modifying the patch to zero them out.
Here's an example of a modified patch:
I'm posting this for anyone who would like to use it in their own custom sprites.
This code uses the item memory index just like objects do.
First, patch this to your ROM with XKAS. It sets all the values in the table to zero.
Code
header lorom !Spr_InterLevelTable = $7F8B00 ;0x200 bytes org $0491D8 JSR.w ZeroInterLevel org $04FFB1 ZeroInterLevel: STA.w $0DC2 PHX ; does this even need to be preserved? REP #%00010000 LDX.w #$0000 SprTblLoop: LDA.b #$00 STA.l !Spr_InterLevelTable,x INX CPX.w #$0200 BCC SprTblLoop SEP #%00010000 PLX RTS
Add this to the very beginning of the sprite (or you can just type the address directly into the following pieces of code)
Code
SPR_INTERLEVEL = $7F8B00
Add this to the very beginning of the INIT routine, right after 'dcb "INIT"'
Code
LDA $161A,x STA $00 STZ $01 LDA $13BE REP #%00110000 AND.w #$00FF XBA LSR A CLC ADC $00 PHX TAX SEP #%00100000 LDA SPR_INTERLEVEL,x PLX SEP #%00010000 CMP #$00 BEQ NotDestroyed: STZ $14C8,x RTL NotDestroyed:
and use this code to prevent the sprite from reloading. In mikeyk's Yoshi Coin sprite, add it after "BCC NoContact"
Code
LDA $161A,x STA $00 STZ $01 LDA $13BE REP #%00110000 AND.w #$00FF XBA LSR A CLC ADC $00 PHX TAX SEP #%00100000 LDA #$01 STA SPR_INTERLEVEL,x PLX SEP #%00010000
By the way, there might be a little bit of room for optimization in this code.
You can also use the table for other purposes, and you can add extra tables by modifying the patch to zero them out.
Here's an example of a modified patch:
Code
header lorom !Spr_InterLevelTable = $7F8B00 ;0x200 bytes !Spr_InterLevelTable2 = $7F8D00 ;0x200 bytes org $0491D8 JSR.w ZeroInterLevel org $04FFB1 ZeroInterLevel: STA.w $0DC2 PHX ; does this even need to be preserved? REP #%00010000 LDX.w #$0000 SprTblLoop: LDA.b #$00 STA.l !Spr_InterLevelTable,x STA.l !Spr_InterLevelTable2,x INX CPX.w #$0200 BCC SprTblLoop SEP #%00010000 PLX RTS