G-Mode Technical Details

From A complete guide to Super Metroid speedrunning
Revision as of 02:12, 19 March 2025 by Maddo (talk | contribs) (Clarify boss room exceptions)
Jump to: navigation, search

When starting to use X-Ray by pressing dash with X-Ray selected, the following things happen as part of the X-Ray setup process:

  • time-is-frozen flag ($0A78) is set to 1 (at $91E21A, also again at $91CAFE).
  • enemy projectile flag ($198D) is cleared to 0 (at $91E231).
  • PLM flag ($1C23) is cleared to 0 (at $91E235).
  • animated tiles flag ($1EF1) is cleared to 0 (at $91E239).
  • palette FX flag ($1E79) is cleared to 0 (at $91E23D).
  • an X-Ray HDMA object is created (at $91CAEE) which handles the control of the X-Ray beam, along with its deactivation once dash is released.

During normal usage of X-Ray, these changes create the intended effect that time has stopped, allowing the playing to inspect the room with X-Ray without having to worry about dodging enemies, their projectiles, or other hazards. Note that the game state ($0998) remains in "main gameplay" ($08) the whole time; just the modifications to the flags affect the behavior of the game.

Normally, all of these changes are undone during the X-Ray deactivation routine ($91E2AD). However, if an auto-reserve trigger finishes while X-Ray is active, then this restores the time-is-frozen flag ($0A78) to 0 (at $82DC18), which prevents the X-Ray deactivation from completing, as it checks (at $888A26) that time is frozen as a condition for the deactivation to proceed. This leaves the game in the "G-mode" state, where processing of PLMS, enemy projectiles, animated tiles, and palette FX remain disabled. The X-ray HDMA object also remains, and as a result, every frame it continues to check the time-is-frozen flag to see if it should proceed with the X-Ray deactivation cleanup; if auto-reserves are triggered again, this will happen, resulting in Samus being forced to stand up ("R-mode forced stand-up") and an end to the G-mode effects. The forced standup occurs because part of the X-Ray deactivation involves putting Samus into a standing pose (at $888A5A).

While in G-mode, if X-Ray is used again, a second X-Ray HDMA object will be created; when X-Ray deactivates, this second X-Ray HDMA object will be deleted, and the enemy projectile, PLM, animated tiles, and palette FX flags will all return to normal, ending G-mode. However, the first X-Ray HDMA object will still remain, meaning the "R-mode forced standup" is still possible. So "R-mode" is simply the result of entering G-mode and then using X-Ray again. Normally this is done by continuing to hold X-Ray through to the end of the auto-reserve trigger, which buffers a second use of X-Ray after the reserve trigger finishes; however, in terms of the resulting game state, there is no difference between doing this vs. entering "G-mode" and then using X-Ray at a later time in the same room.

When leaving the room in G-mode, the X-Ray HDMA object will get cleaned up (at $82E2FA), ending the "R-mode" effects, but the enemy projectile, PLM, animated tiles, and palette FX flags will remain disabled, preserving the G-mode effects.

Effects of each components

The various effects of G-mode, R-mode, and related states can be explained by the individual flags/components affected:

Time-is-frozen flag ($0A78)

The time-is-frozen flag has many effects, including preventing Samus' movement, preventing enemy processing (including enemy movement), and preventing earthquake shaking. It is normally only active during an auto-reserve trigger, while using X-ray, or during the death sequence. Because the time-is-frozen flag is cleared at the end of the reserve trigger, its effects do not apply to either G-mode or R-mode. One unusual scenario where its effects can be seen is by triggering auto-reserves when entering the Toilet; Samus will continue to pass through the Toilet during the refill, and if enough energy is in reserves to reach the transition on the other side before it completes, then Samus will enter the next room with time frozen. This will be a soft-lock as Samus will not be able to move, though some actions are still possible such as walking in-place or turning around in-place.

Enemy projectile flag ($198D)

When this flag is cleared, processing of enemy projectiles will be skipped. This means that enemy projectiles will not be drawn and will not move. However, though they are invisible, they can still spawn and can still damage Samus. The game has space for a maximum of 18 projectiles, so after that amount have spawned, no more will spawn, in which case we say that enemy projectiles are overloaded. If X-ray or a reserve trigger is used to exit G-mode, then the processing of enemy projectiles will resume, meaning all the spawned projectiles will become visible and begin moving (if applicable). Drops from enemies (energy and ammo) are a type of enemy projectile. If a player wants to use G-mode to pass through a heated room, and is relying on drops (and pause abuse) from an enemy near the door in order to escape the room after exiting G-mode, then the player must be careful to avoid letting enemy projectiles become overloaded, since in that case no drops will spawn.

PLM flag ($1C23)

When this flag is cleared, processing of PLMs will be skipped. During normal usage of X-Ray, this means, for example, that if a door is in the middle of being opened, or a shot block or bomb block is in the middle of being destroyed, it will stay how it is rather than continuing to progress through its animation, as long as X-Ray is in use. In G-mode this has many implications, and the effects vary depending on the specific type of PLMs and blocks involved.

Some types of PLMs spawn when the room loads, including door locks, items, and gates (blue and green). When entering the room with a reserve trigger to enter G-mode, these PLMs will still be processed for 1 frame (at $82E53C) before G-mode is entered; therefore, door locks, items, and gates still spawn in this case (direct G-mode). However, if leaving the room while still in G-mode (indirect G-mode), the PLMs in the new room will not process at all, until G-mode is exited. This means that in indirect G-mode, door locks, items, and gates do not spawn.

Other types of PLMs spawn dynamically as a reaction to interacting with certain types of blocks, e.g. touching sand, an item, or a camera scroll block; grappling to a Grapple block; or bombing a crumble block, Speed block, or bomb block. The PLM flag being cleared does not prevent new PLMs from spawning; it only prevents them from carrying out their instructions that would normally cause them to animate, perform their function, and/or delete themselves when they finish. As a result, in G-mode it is easy for large number of newly spawned PLMs to accumulate. The game has space for a maximum of 40 PLMs, so after that amount have spawned, no more will spawn.

Animated tiles flag ($1EF1)

When this flag is cleared, it prevents animated FX from animating, including lava, acid, rain, and the Pink Brinstar falling spores. So these tiles will remain frozen in their initial state. In indirect G-mode, the animated tiles don't load at all, so they can have a different appearance based on whatever animated tiles were most recently loaded in a previous room.

Palette FX flag ($1E79)

When this flag is cleared, it prevents processing of palette FX, such as the glowing colors in Wrecked Ship, Red Brinstar, and hot Norfair rooms. More significantly, it prevents heat damage, giving the "artificial Varia" effect.

X-Ray HDMA object

The continued presence of the X-Ray HDMA object is what allows for an auto-reserve trigger to cause the R-mode forced stand-up. The X-ray state ($0A7A) ends up stuck with a value of 5, which is the final X-Ray deactivation state. In most cases, this HDMA object also causes the "colour math subscreen backdrop colour" to get overwritten on each frame ($88870C), to the gray color associated with how X-Ray dims the screen. This interferes with the operation of a Crystal Flash, which uses the "color math subscreen backdrop colour" as a sort of counter (at $88A35D). As a result, after using a Crystal Flash in G-mode, usually the Crystal Flash clean-up at $88A317 fails to occur, and this means that the power bomb explosion status ($0592) remains set to $8000 after the Crystal Flash completes, and the two HDMA objects created by the Crystal Flash also remain. This leaves behind a "light orb" which can continue to damage enemies. The game audio will also be silenced (why?).

When the power bomb explosion status ($0592) remains set to $8000, this prevents the use of X-Ray (due to the check at $91E1AA). Leaving the room or triggering auto-reserves will clear the power bomb explosion status ($0592) and allow the use of X-Ray again. Laying another Power Bomb is also an option that can work in some rooms, depending on how many HDMA objects are already occupied by the room's FX (described in some detail below). However, laying another Power Bomb has a side effect of making the foreground (BG1) disappear (why?); in this case, the foreground can be viewed temporarily by using X-Ray, and will be restored permanently by leaving the room.

At $888700, the X-Ray HDMA handler calls a function $91D143, which checks if one of a few special situations applies where the X-Ray HDMA handler will not overwrite the "colour math subscreen backdrop colour", unlike most rooms. These exceptions are the following rooms:

  • Statues Room
  • Glass Tunnel
  • Kraid Room
  • Crocomire's Room
  • Phantoon's Room (only if the room was entered with Phantoon alive)
  • Draygon's Room (only if the room was entered with Draygon alive)
  • Mother Brain Room

Therefore, when Crystal Flash is used in these rooms in G-mode/R-mode, it will clean itself up normally, and not leave behind a light orb or prevent the use of X-Ray. The X-ray handler checks for "Statues Room" and "Glass Tunnel" directly by comparing the room pointer to the two specific values; it checks for boss rooms by comparing the boss ID ($179C) to the 5 specific values. The boss ID is set by enemy initialization for the boss, which in the case of Phantoon and Draygon only happens if the bosses are alive when entering the room (because the room states for these rooms do not include any enemies in the state where the boss is dead). Technically the X-Ray handler also checks for fireflea rooms (by looking at the FX type $196E) and will avoid overwriting the "colour math subscreen backdrop colour" in these rooms as well; however, the fireflea effect itself overwrites these color values, hence the Crystal Flash will still fail to be cleaned up, leaving behind a "light orb" in fireflea rooms the same as in other rooms.

The exception in Mother Brain Room is significant, as the Light Pillar technique would otherwise not be possible (see R-Mode#Light_Pillar_Mother_Brain).

FX-dependent HDMA objects

The game has a total of 6 slots available for HDMA objects. The last slot is essentially always used for handling BG3 scrolling for the HUD (technically it may not be used when initially starting or loading the game in a room without an FX that needs it, but after passing through a door transition it will always be present). The amount of HDMA objects used by room FX (not counting the BG3 scrolling HDMA object) is as follows:

  • Lava and acid use 2.
  • Water uses 1, or 2 if the wavy effect on BG2 is enabled.
  • Fog, rain, and the fireflea effect use 1.
  • Scrolling sky (not itself an FX), adds 1 to whatever FX is used (e.g. rain or water), if any.

In direct G-mode (or R-mode), one of the slots will be occupied by the X-Ray HDMA, and after a Crystal Flash, 2 more will be occupied (except for in the special rooms listed above). Including the slot used by BG3 scrolling for the HUD, if the room has no FX then this leaves 2 free slots, which is just enough for a Power Bomb explosion to happen properly. If the room FX uses 1 slot, then a Power Bomb explosion can still happen and will clear the power bomb explosion status ($0592) and allow the use of X-Ray again; but it will be graphically glitched and will delete the BG3 scrolling HDMA object, resulting in further graphical glitches in the HUD, lasting until leaving the room.

If the room FX uses 2 slots, then it will still be possible to lay a single Power Bomb (after a Crystal Flash), and it can give Samus a boost, but it will fail to explode, and it will still not be possible to use X-Ray afterward, nor to lay additional Power Bombs.