Language…
10 users online: Cristian Cardoso, Darolac, howardadam1126, lean4, Oskise, RenkoV2,  Segment1Zone2, Shiki_Makiro, SpacePea, Zavok - Guests: 262 - Bots: 295
Users: 64,795 (2,377 active)
Latest user: mathew

Sprite Memory Shared Between Areas (Patch + Code)

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.
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


Will you submit this to the patches section? If so, what will it's name be? I remember you talking about this on the IRC.
Balloon Party.
At times like this, you need to step back and say, "Where's the Balloon Party?"
I probably won't submit this to the patches section. I'll probably just include it with sprites that use it, since it's completely useless without sprites that use it.

As for a name, I don't know. Maybe something along the lines of "InterLevel Sprite Memory".


There needs to be a "misc" option in the sidebar...
Balloon Party.
At times like this, you need to step back and say, "Where's the Balloon Party?"