Pokémon Red and Blue use various memory regions for different purposes. Understanding this layout is crucial for comprehending how the game manages its state.
$0000-$00FF: RST vectors and interrupt handlers$0100-$014F: ROM header$0150-$3FFF: Home bank (Bank 0)$4000-$7FFF: Switchable ROM banks (1-44)$8000-$97FF: Tile data (blocks 0-2)$9800-$9BFF: Background tile map 0$9C00-$9FFF: Background tile map 1$A000-$BFFF: External cartridge RAM$C000-$C0FF: Audio RAM$C100-$C1FF: Sprite state data$C200-$C2A0: Shadow OAM$C2A0-$C3FF: Tilemap and overworld data$C400-$CFFF: Main work RAM$D000-$DFFF: Party, bag, and game state$E000-$FDFF: Echo of $C000-$DDFF (unusable)$FE00-$FE9F: OAM (Object Attribute Memory)$FF00-$FF7F: I/O registers$FF80-$FFFE: High RAM (HRAM)$FFFF: Interrupt enable register
RST (restart) vectors are special single-byte call instructions that save space. For example, RST $38 is equivalent to CALL $0038 but uses only 1 byte instead of 3.
SECTION "Party Data", WRAM0wPartyCount:: db ; Number of Pokémon in party (1-6)wPartySpecies:: ds PARTY_LENGTH + 1 ; Species list + $FF terminatorwPartyMons:: ; 6 × 44 bytes = 264 bytes; Each party_struct contains:; Species (1); HP (2); Box level (1); Status (1); Types (2); Catch rate/held item (1); Moves (4); OT ID (2); Experience (3); HP EV (2); Attack EV (2); Defense EV (2); Speed EV (2); Special EV (2); DVs (2); Move PP (4); Level (1); Max HP (2); Attack (2); Defense (2); Speed (2); Special (2)wPartyMonOT:: ; 6 × 11 bytes = 66 bytes; Original trainer nameswPartyMonNicks:: ; 6 × 11 bytes = 66 bytes; Pokémon nicknames
wCurMap:: db ; Current map IDwYCoord:: db ; Player Y coordinatewXCoord:: db ; Player X coordinatewYBlockCoord:: db ; Y in 2×2 blockswXBlockCoord:: db ; X in 2×2 blockswCurMapHeader:: ; Map header datawCurMapTileset:: dbwCurMapHeight:: dbwCurMapWidth:: dbwCurMapDataPtr:: dwwCurMapTextPtr:: dwwCurMapScriptPtr:: dwwCurMapConnections:: dbwSpriteSet:: ds SPRITE_SET_LENGTH ; 11 sprite IDswSpriteSetID:: db
The cartridge battery-backed RAM stores saved games:
SRAM $0 ; Bank 0: Sprite buffers "Sprite Buffers"SRAM $1 ; Bank 1: Main save data "Save Data" ; Contains copy of: ; - Player name and ID ; - Badges and progress flags ; - Party Pokémon ; - Current box Pokémon ; - Pokédex ; - Items and money ; - Rival name ; - Current map and positionSRAM $2 ; Bank 2: Box 1-6 data "Saved Boxes 1"SRAM $3 ; Bank 3: Box 7-12 data "Saved Boxes 2"
HRAM ($FF80-$FFFE) is fast-access RAM used for critical variables:
SECTION "HRAM", HRAMhSoftReset:: db ; Soft reset counter; Multiplication/division (overlapped)hMultiplicand:: ds 3hMultiplier:: dbhProduct:: ds 4hDividend:: ds 4hDivisor:: dbhQuotient:: ds 4hRemainder:: db; Joypad statehJoyHeld:: db ; Currently held buttonshJoyPressed:: db ; Newly pressed buttonshJoyReleased:: db ; Newly released buttons; ROM bankinghLoadedROMBank:: db ; Current ROM bankhSavedROMBank:: db ; Saved bank for restoration; Video synchronizationhSCX:: db ; Scroll X (copied to rSCX)hSCY:: db ; Scroll Y (copied to rSCY)hWY:: db ; Window Y (copied to rWY)hVBlankOccurred:: db ; VBlank flag; DMA and transfershAutoBGTransferEnabled:: db ; Auto-transfer flaghAutoBGTransferDest:: dw ; Destination addresshVBlankCopyBGSource:: dw ; Source for BG copy
HRAM is accessible even during OAM DMA, making it ideal for the DMA routine itself.