Jingle Glitch

There are a lot of jingles in the game, and there are also a lot of glitches, but a particular intersection of these disciplines intrigues many and arouses all.

This is one of a large class of glitches that exists because two actions occurred on the same frame. Naïvely, this might lead one to surmise that something with the shutter doors prevents something with the stairs from happening, but it's actually the opposite. Something with the shutter doors causes something with the stairs to happen twice!

Said thing is triggering the stairs transition. Only two really important things happen when these transitions are triggered: the room ID is updated to the target room, and room data is saved. The former is the issue, because it first saves the current ID to a variable that tracks the previous room. This means that if the update happens twice, the previous room ID and the current room ID will be the same.

Where this breaks is the adjustment that occurs dozens of frames after the trigger. Once the room has faded to black, values for Link's coordinate and the camera and its boundaries are adjusted to a position that will work for the new room. While the hardware can only make sense of the lower 9 bits, the full 16-bit values are used by the software for gameplay calculations. When a room transition occurs, all 16 bits need to be updated, not just the lower order ones.

Despite the simple and straightforward relationship between room ID, coordinates, and camera position, the latter two are always adjusted relatively using the first. The following formulae approximate the code, where R is room ID:

Xnew = Xold + 512 × ((Rnew − Rold) mod 16)
Ynew = Yold + 1024 × (⌊Rnew ÷ 16⌋ − ⌊Rold ÷ 16⌋)

It's much prettier in assembly; I promise!

When the old and new room IDs are the same, such as in the jingle glitch, the adjustments are calculated to be 0. In a sense, it's as if a certain step was skipped, but it did literally happen.

This also explains how the data spoof happens. The room data is saved once when the room ID is correct and again when it's the target room.

While Link's coordinates may be in sync with the camera, sprites' coordinates are not. It's often horribly misstated that the jingle glitch despawns sprites, but that's patently incorrect. Sprites always spawn in the underworld, unless they're dead. What's actually happening is sprites are being displaced. They're just too far off camera to be seen, and their true coordinates are nowhere near Link's. For most sprites, being off-screen also means being inactive; i.e., they won't do anything.

The best way to illustrate is this distinction is with Moldorm. As I have previously explained, everyone's favorite worm is supposed to remain active off-screen. The reason he doesn't is because of an error that occurs when drawing his tail. But! If his tail is never drawn (because he's off-screen), that error won't occur. If you make it to Moldorm 2 in Ganon's Tower with a broken camera—perhaps with a jingle on a certain set of stairs after a certain set of torches that a certain set of the population is all too familiar with—you'll hear Moldorm shuffling. You won't see him, but you will hear him. That's not something we could experience if he were despawned.

That's all clear now, but why does this even happen in the first place? What causes the double trigger?

As mentioned, touching the stairs kicks things off with the room changes, but it also changes the game submodule to whatever relevant stairs module is required. It will only do this while in the default module ($00). Shutter doors are controlled with room tags, which also only occur in the default submodule. Though it sounds like one of these should preclude the other, the funny thing is that these are both under the same submodule check. In fact, the DetectStaircase routine is actually called from inside the HandleRoomTags routine. If stairs are being detected, those shutter doors are already queued up.

As it so happens, shutter doors themselves are animated with a submodule too. Once the animation is complete, the submodule is reset back to the default one. The game makes a pretty fair assumption that shutter doors can only be triggered from the default submodule, so there's no reason to change to anything but when finished.

Interroom stairs are where this assumption doesn't work. On the next frame after the shutters fully close, room tags—and thus staircase detection—will be run again. Movement on stairs is checked for with WALKDIR (at $67), and that says Link is still moving.

Quoth the staircase, "Triggered more."