I thought it was time we made a post detailing "Yoshi-drop swap" glitch, which is a glitch whereby Yoshi despawns on the same frame a new sprite spawns in the same slot and, for some sprites, the sprite will warp to Mario's position and we'll keep Yoshi in the next level/area. For a long time we didn't know why this worked or which sprites it work with. We've known for a while but I don't think the information was made public, so thanks to nathanisbored for his research.
This bug has several advantages.
- The sprite teleports to Mario's position.
- We can change the colour of the Yoshi based on the palette of the new sprite.
- We can ditch Yoshi in unneeded levels and recover him in the next area (useful for flying levels).
Yoshi uses sprite table $7E00C2 to determine his current state. #$00 = not riding, #$01 = riding, #$02 = running away (hurt). The bug occurs when a sprite spawns in Yoshi's (now unused) slot using an initial value of #$01. The game determines that Mario must be riding this sprite and, as such, teleports the new sprite to underneath him. It quickly corrects itself (as there are no Yoshi's present) but the one frame is sufficient to trigger the glitch. This isn't such a technical explanation but I hope it is sufficient.
We can also trick a property of other sprites, sprite table $7E160E. The game uses this table as the ID of the sprite Yoshi is eating, but it is set to -1 (255) when there is no sprite. If Yoshi swallows a sprite on the frame he despawns AND we spawn a new sprite in that slot, that sprite will spawn with -1 in that table. This seems to have no useful effect so far. I've only found that we can turn mushrooms/flowers into berries and despawn goal tapes, which is less than useful :p I'm sure there's more undiscovered bugs regarding this.
Edit: By the way, this is used in CHEESE BRIDGE AREA in our 96-exit run. The reason we get a glitched-looking Yoshi is because the sprite we swap with is tileset-specific, which means it uses the last two graphics pages. Thus, Yoshi loads his graphics from these pages too, which corrupts his image.
Edit 2:
Here are the sprites that will cause the bug. I used a script for this, and as such it may not catch certain edge cases (the list does not contain Mushroom, which will work, but only when stationary). But this list is
mostly complete; I don't want to manually check all...