Professor Oak's lab tilemap corruption glitch

From Glitch City Wiki
Jump to navigationJump to search
PRAMA Initiative a également une page sur Professor Oak's lab tilemap corruption glitch.
Tile corruption caused by the glitch.

Professor Oak's lab tilemap corruption glitch, also known as Professor Oak's lab leaving glitch is a natural glitch which occurs in Pokémon Red and Blue.

This glitch can occur very rarely when repeatedly trying to leave Professor Oak's Lab without picking a Pokémon at the beginning of the game. It causes the player character to become invisible and unable to move. Depending on the horizontal position of the player when triggering this glitch, some other sprites will become invisible too. Opening the start menu will show tilemap corruption (including vertical "a" lines, ":Q", ":I", "eQ") in the overworld, and closing the start menu will fix the glitch.


The cause of the glitch is related to the number of sprites on the screen. The GameBoy OAM can hold 40 tiles, and each sprite in Pokémon Red and Blue consists of 4 tiles, so only 10 visible sprites are allowed on the same screen. In this scene, there are 11 sprites in total: the player, the rival, three Poké Balls, Prof. Oak, two Pokédexes, and three of Professor Oak's aides. In normal cases, either the two male aides on the bottom of the screen are invisible, or the two Pokédexes on the top of the screen are invisible, limiting the number of visible sprites to 9.

Trying to leave Oak's Lab without picking a Pokémon makes the game transition between those two states. In particular, when the game forces the player to walk back up, on the frame the move animation is done, the game marks the two Pokédexes as visible, and then the two male aides as invisible, in the same round of sprite update. If this round of sprite update takes too long to complete, the V-Blank interrupt (during which the OAM buffer is prepared) may occur before it is finished, at which point all 11 sprites are considered visible.

When this happens, the eleventh sprite overflows the OAM buffer and is written into the tilemap buffer, which is immediately after the OAM buffer in the WRAM layout. Furthermore, after populating the OAM buffer, a loop clears the unused portion of the OAM buffer, which runs from the last OAM entry written to the first address with the lower byte $a0. With an OAM overflow, this would not be $c3a0 as intended, but $c4a0, meaning that the corruption extends to the first 256 bytes of the tilemap buffer. The vertical "a" lines come from changing the first byte of every 4-byte block to hex A0, which is the recommended way to remove tiles from the GameBoy OAM (by putting them below the screen).

Normally in the overworld, the tilemap buffer is not copied to the VRAM every frame (the VRAM is updated only as needed), so the tilemap corruption is not directly visible. However, its immediate effect is that any sprite standing on a corrupted tile with ID value >= hex 60 is now invisible. The game thinks that those corrupted tiles are text box tiles, rather than map tiles, and since text boxes should be drawn on top of sprites, those sprites are hidden. For the player sprite, this means that walking is also disabled.

When using the start menu, the tilemap buffer is copied every frame, so opening the start menu shows the corruption directly. And when the start menu is closed, the entire tilemap buffer is rebuilt from the map, fixing the glitch.

YouTube video by Sanqui