A Link to the Past
Data Spoofing
Data spoofing is a common transition corruption effect that writes data from one supertile to another.
Layman explanation
Data for rooms is stored in memory as flags that are either on or off. Whenever the room ID changes, this data is written to save RAM. Under normal conditions, data for the next room is then loaded from save RAM and overwrites the old data from the previous room. With certain transition corruptions, the save is performed, but the load is not because it was interrupted by the transition not happening. When this occurs, the old room data is still there but with the current room ID pointing to the new room. Thus, when the room ID is changed again from any sort of transition or glitch, it will write the original room's data into save RAM.
Mechanics
This section goes into very technical detail. The information is presented with the assumption that the reader has at least basic knowledge of hexadecimal, bitwise operations, SNES memory, and/or SNES assembly.
Conflict
The main conflict arises when a transition corruption triggers the game mode change for supertile transitions. The important information to know is two-part:
- These game mode changes are done via incrementation
- The data loading routine is done immediately, from within the default submodule.
The first problem explains why we are able to perform many transition corruptions in the first place. The second problem explains why data spoofing happens when it does. Let's look at a couple of quick examples:
Example 1: YBAs
Using a red YBA on a subtile door, the game mode is corrupted to $0E / $05. Using it on a supertile door, it's corrupted to $0E / $06. The subtile YBA only corrupted the red potion game mode with a subtile transition; ditto for the supertile YBA. Only the supertile YBA will result in a data spoof.
Example 2: STCs
When we perform an STC on a subtile door, the game mode is corrupted to $07 / $03. This is by having the game run the subtile transition set up (+1) followed by the supertile transition set up (+2). When performing an STC on a supertile door, the same game mode happens but from a different order. In those cases, the supertile runs first (+1), then the subtile (+1). In both cases, the same corrupted game mode happens. A supertile setup was touched in both cases, so both STCs will result in data spoofs.
Organization of data
Room flags are stored as bit fields in 3 main addresses in work RAM. When a new room is loaded, these values are transferred to SRAM, creating a new bit field. The base SRAM address is $7EF000 and it's written to with an index determined by multiplying the room ID by 2.
Address $0401 (door flags)
| Bit | Name | Description | Value (as power of 2) | Value in Hexadecimal |
|---|---|---|---|---|
| 7 | D0 | Door 0 opened | 27 | 0x80 |
| 6 | D1 | Door 1 opened | 26 | 0x40 |
| 5 | D2 | Door 2 opened | 25 | 0x20 |
| 4 | D3 | Door 3 opened | 24 | 0x10 |
| 3 | u | Unused | 23 | 0x08 |
| 2 | u | Unused | 22 | 0x04 |
| 1 | u | Unused | 21 | 0x02 |
| 0 | u | Unused | 20 | 0x01 |
Address $0403 (item flags)
| Bit | Name | Description | Value (as power of 2) | Value in Hexadecimal |
|---|---|---|---|---|
| 7 | H | Heart container obtained/Boss killed | 27 | 0x80 |
| 6 | K | Key obtained | 26 | 0x40 |
| 5 | c | Unused 6th chest or 2nd key | 25 | 0x20 |
| 4 | C5 | Chest 5 opened; Rupee tiles grabbed | 24 | 0x10 |
| 3 | C4 | Chest 4 opened | 23 | 0x08 |
| 2 | C3 | Chest 3 opened | 22 | 0x04 |
| 1 | C2 | Chest 2 opened | 21 | 0x02 |
| 0 | C1 | Chest 1 opened | 20 | 0x01 |
Address $0408 (quadrant flags)
| Bit | Name | Description | Value (as power of 2) | Value in Hexadecimal |
|---|---|---|---|---|
| 7 | u | Unused | 27 | 0x80 |
| 6 | u | Unused | 26 | 0x40 |
| 5 | u | Unused | 25 | 0x20 |
| 4 | u | Unused | 24 | 0x10 |
| 3 | Q4 | Northwest quadrant visited | 23 | 0x08 |
| 2 | Q3 | Northeast quadrant visited | 22 | 0x04 |
| 1 | Q2 | Southwest quadrant visited | 21 | 0x02 |
| 0 | Q1 | Southeast quadrant visited | 20 | 0x01 |
Address $7EF000,X (SRAM address)
| Bit | Name | Description | Value (as power of 2) | Value in Hexadecimal |
|---|---|---|---|---|
| 15 | D0 | Door 0 opened | 215 | 0x8000 |
| 14 | D1 | Door 1 opened | 214 | 0x4000 |
| 13 | D2 | Door 2 opened | 213 | 0x2000 |
| 12 | D3 | Door 3 opened | 212 | 0x1000 |
| 11 | H | Heart container obtained/Boss killed | 211 | 0x0800 |
| 10 | K | Key obtained | 210 | 0x0400 |
| 9 | c | Unused 6th chest or 2nd key | 29 | 0x0200 |
| 8 | C5 | Chest 5 opened; Rupee tiles grabbed | 28 | 0x0100 |
| 7 | C4 | Chest 4 opened | 27 | 0x0080 |
| 6 | C3 | Chest 3 opened | 26 | 0x0040 |
| 5 | C2 | Chest 2 opened | 25 | 0x0020 |
| 4 | C1 | Chest 1 opened | 24 | 0x0010 |
| 3 | Q4 | Northwest quadrant visited | 23 | 0x0008 |
| 2 | Q3 | Northeast quadrant visited | 22 | 0x0004 |
| 1 | Q2 | Southwest quadrant visited | 21 | 0x0002 |
| 0 | Q1 | Southeast quadrant visited | 20 | 0x0001 |
Unique uses
Several rooms use the room flags slightly differently:
| ID | Room | Bit | Function |
|---|---|---|---|
0x37 | Hammer peg lever (in Swamp) | C4 | Reuses chest 4 as a flag for whether the room has been flooded |
0x35 | Crystal switch lever (in Swamp) | C4 | Reuses chest 4 as a flag for whether the room has been flooded |
0x66 | Final swamp lever | C4 | Reuses chest 4 as a flag for whether the room has been flooded |
0x65 | Thieves' Town attic | C5 | Reuses chest 5 as a flag for whether or not the attic floor has been bombed |
0x1B | Eye statue room (in PoD) | C4 | Reuses chest 4 as a flag for whether or not the wall has been moved |
0x43 | Desert Palace torches room | C4 | Reuses chest 4 as a flag for whether or not the wall has been moved |
0x97 | Misery Mire torches room | C5 | Reuses chest 5 as a flag for whether or not the wall has been moved |
Dungeon prizes
Crystals and pendants don't set any bit in room data when collected, but they do specifically check for the key bit before they spawn. This is likely vestigial behavior from an earlier point in development, but the consequence of it is that spoofing a collected key into a boss room will prevent its prize from being dropped.
