Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Platform:Super Nintendo Entertainment System

From ReverseEngineering.wiki
Platform
Developer Nintendo
Versions SNES / Super Famicom (1990), SNES Jr. / SNS-101 (1997)
Endianness little
On this wiki Facts · Code · Notes · Topics

Nintendo's 16-bit home console (1990 JP, 1991 NA). A 65C816-based CPU (Ricoh 5A22), a Sony SPC700 sound CPU with its own 64 KB RAM, and a two-chip PPU with 64 KB VRAM, 512-byte CGRAM (256 BGR555 colours) and 544-byte OAM (128 sprites). Graphics are planar 2/4/8 bpp 8x8 tiles; the palette is chosen per tilemap entry or sprite, not stored in the tile.

Overview

  • CPU: Ricoh 5A22, a WDC 65C816 core plus DMA/HDMA, multiply/divide and joypad units. Clock 3.58, 2.68 or 1.79 MHz depending on the memory region accessed.
  • Sound: Sony SPC700 CPU + S-DSP, 64 KB ARAM, 8 BRR-compressed sample voices. Talks to the main CPU only through four I/O ports (0x2140–0x2143).
  • Video: PPU1 (5C77) + PPU2 (5C78). 256x224 (or 256x239 overscan) per field; 512-pixel hires in modes 5/6 and with pseudo-hires; optional interlace.
  • PPU memories (accessed only through ports, never mapped in the CPU address space):
    • VRAM: 64 KB, addressed in 16-bit words (0x0000–0x7FFF). All base-address registers count in words. Ports: VMAIN 0x2115, VMADD 0x2116/7, VMDATA 0x2118/9.
    • CGRAM: 512 bytes = 256 colours. Ports: CGADD 0x2121, CGDATA 0x2122 (written twice, low byte then high byte).
    • OAM: 544 bytes = 512-byte low table + 32-byte high table. Ports: OAMADD 0x2102/3, OAMDATA 0x2104.

Colour format (CGRAM)

Each entry is 15-bit BGR555, little endian: 0bbbbbgg gggrrrrr — bits 0–4 red, 5–9 green, 10–14 blue, bit 15 unused. To convert to 8-bit RGB, use (c << 3) | (c >> 2) per channel.

Colour 0 of every palette is transparent for BGs and sprites; CGRAM entry 0 is also the backdrop colour.

Final brightness is applied after palette lookup by INIDISP 0x2100 (bits 0–3 = brightness 0–15, bit 7 = forced blank). Fades are usually done with this register, so CGRAM keeps the original colours during a fade.

Tile (character) format

Tiles are 8x8 pixels, planar, stored as pairs of bitplanes interleaved per row. In each byte, bit 7 is the leftmost pixel.

Depth Size Layout (r = row 0–7)
2 bpp 16 bytes byte 2r = plane 0, 2r+1 = plane 1
4 bpp 32 bytes bytes 0x00–0x0F: planes 0/1 as in 2 bpp; bytes 0x10–0x1F: planes 2/3 (0x10+2r, 0x11+2r)
8 bpp 64 bytes planes 0/1, 2/3, 4/5, 6/7 in four 16-byte blocks

Pixel value at (x, r) = Σ over planes p of ((plane_p_byte >> (7 - x)) & 1) << p.

A tile stores only colour indices (0–3, 0–15 or 0–255). Which palette is used comes from the tilemap entry or the OAM entry, so the same tile data is routinely drawn with several palettes. A tile ripper or graphics replacer that wants to recognise graphics independently of palette swaps should key on the tile bytes alone.

Mode 7 uses a different, linear format (see below).

The 2 bpp layout is byte-for-byte the Game Boy tile format (Platform:Game Boy#Graphics), so Game Boy tile viewers and rippers decode SNES 2 bpp graphics unchanged.

Background modes

Selected by BGMODE 0x2105 bits 0–2. Bit 3 = BG3 high priority (mode 1). Bits 4–7 = 16x16 tile size for BG1–BG4.

Mode BG1 BG2 BG3 BG4 Notes
0 2 bpp 2 bpp 2 bpp 2 bpp each BG has its own 32-colour block: BG1 0–31, BG2 32–63, BG3 64–95, BG4 96–127
1 4 bpp 4 bpp 2 bpp — the most common mode
2 4 bpp 4 bpp (offset-per-tile) — BG3 tilemap holds per-column scroll offsets
3 8 bpp 4 bpp — — 8 bpp may use direct colour
4 8 bpp 2 bpp (offset-per-tile) —
5 4 bpp 2 bpp — — hires 512 wide; BG tiles always 16 pixels wide
6 4 bpp — (offset-per-tile) — hires 512 wide
7 8 bpp (EXTBG) — — affine rotation/scaling, one 1024x1024 layer

Palette selection outside mode 0: a 2 bpp BG picks one of 8 four-colour palettes in CGRAM 0–31; a 4 bpp BG picks one of 8 sixteen-colour palettes in CGRAM 0–127; an 8 bpp BG uses all 256 colours (or direct colour, CGWSEL 0x2130 bit 0, where the index itself encodes BGR 2:3:3 plus palette bits).

Tilemaps

BGnSC 0x2107–0x210A: bits 2–7 = tilemap base in 0x400-word units; bits 0–1 = size (0 = 32x32, 1 = 64x32, 2 = 32x64, 3 = 64x64 entries, each 32x32 screen being 0x400 words).

BG12NBA 0x210B / BG34NBA 0x210C: character (tile data) base for each BG in 0x1000-word (8 KB) units (low nibble = BG1/BG3, high nibble = BG2/BG4).

Each tilemap entry is one 16-bit word: vhopppcc cccccccc.

Bits Meaning
0–9 tile number (relative to the BG character base, in units of one tile of that BG's depth)
10–12 palette 0–7
13 priority
14 horizontal flip
15 vertical flip

With 16x16 BG tiles, entry N draws tiles N, N+1 (right), N+16 (below), N+17. Flips swap the sub-tiles as well as flipping each one.

Sprites (OBJ)

Sprites are always 4 bpp and use palettes 0–7 at CGRAM 128–255 (sprite palette p = colours 128 + 16p … 143 + 16p). Only sprite palettes 4–7 take part in colour math.

OBSEL 0x2101: bits 0–2 = sprite tile base in 0x2000-word units; bits 3–4 = gap to the second name table (base + (n+1) * 0x1000 words); bits 5–7 = size pair:

Value Small Large
0 8x8 16x16
1 8x8 32x32
2 8x8 64x64
3 16x16 32x32
4 16x16 64x64
5 32x32 64x64
6 16x32 32x64 (undocumented)
7 16x32 32x32 (undocumented)

OAM low table, 4 bytes per sprite (128 sprites):

Offset Size Name Notes
0x00 1 X low 8 bits of X
0x01 1 Y
0x02 1 tile low 8 bits of tile number
0x03 1 attr bit 0 = name table select (tile bit 8), bits 1–3 = palette, bits 4–5 = priority, bit 6 = h-flip, bit 7 = v-flip

High table (OAM 0x200–0x21F): 2 bits per sprite, sprite 0 in the low bits of byte 0x200. Bit 0 = X bit 8 (sign), bit 1 = large size.

Sprite tiles are laid out as a 16x16-tile grid in each name table: the low 4 bits of the tile number are the column, the high 4 bits the row. A sprite larger than 8x8 using tile N draws the tile to its right as column+1 and the tile below as row+1 (N+16); column and row each wrap independently inside their 4 bits, so a sprite never spills into the other name table. The tile address is (OBJ base + tile * 16 + (name table bit ? gap : 0)) & 0x7FFF words.

Flipping. For square sizes, flipping mirrors the whole sprite, not each 8x8 tile in place: with h-flip, displayed column x reads source column width - 1 - x; with v-flip, displayed row y reads source row width - 1 - y.

Rectangular sizes (OBSEL 6/7, 16x32 and 32x64) flip vertically per square half. The v-flip formula uses the sprite width, not its height: for displayed row y < width the source row is width - 1 - y, otherwise 3 * width - 1 - y. The top and bottom squares are each mirrored in place and do not swap positions. H-flip is unaffected. A tool that rebuilds sprite images from OAM + VRAM and flips the full rectangle will not match the screen for these sizes.

OBJ interlace (SETINI 0x2133 bit 1): the sprite row fetched on a scanline is ((scanline - Y) << 1) | field, where field is the odd/even frame bit. Sprites appear at half height and alternate source rows between fields; the visibility test uses the halved height. Applies independently of BG interlace (bit 0). A ripper that maps screen rows to sprite rows 1:1 will read the wrong rows while this bit is set.

Limits per scanline: 32 sprites ("range over") and 34 8-pixel sprite slivers ("time over"); excess is dropped and flagged in STAT77 0x213E.

Mode 7

VRAM is split by byte: the low byte of words 0x0000–0x3FFF is a 128x128 tilemap (one byte per entry, tile number only — no palette, flip or priority bits), and the high byte of words 0x0000–0x3FFF holds 256 tiles of 8x8 linear 8 bpp pixels (64 bytes per tile, one byte per pixel, row-major). The layer is transformed by the 2x2 matrix M7A–M7D (0x211B–0x211E, 8.8 fixed point) around centre M7X/M7Y (0x211F/0x2120); games often change the matrix per scanline with HDMA for perspective effects. With EXTBG (SETINI 0x2133 bit 6), BG2 reuses the same data as 7 bpp with bit 7 as a per-pixel priority.

Other effects relevant to graphics tools

  • Mosaic (MOSAIC 0x2106): bits 0–3 enable BG1–BG4, bits 4–7 = block size − 1. Each block shows its top-left pixel.
  • Windows and colour math (0x2123–0x2133): two windows mask layers; colour math adds or subtracts the sub screen or a fixed colour, optionally halved. Used for transparency, shadows and lighting.
  • Interlace / pseudo-hires (SETINI 0x2133): bit 0 interlace, bit 1 OBJ interlace (half-height sprites, see Sprites (OBJ) above), bit 3 pseudo-hires. In hires output each 256-wide pixel becomes two: the sub screen pixel on the even (left) half, the main screen pixel on the odd (right) half.
  • HDMA changes PPU registers per scanline (gradients, wavy scrolling, mode 7 perspective), so a single frame cannot always be described by one set of register values.

How to verify

Any debugging emulator with a tile/tilemap/OAM viewer (e.g. Mesen, bsnes-plus) shows VRAM, CGRAM and OAM live; decoding a VRAM dump with the formulas above must reproduce what the viewer shows. The sprite tile wrapping and the hires sub/main pixel order match the PPU renderer of the open-source Mesen emulator (Core/SNES/SnesPpu.cpp). The register descriptions match the public fullsnes and SNESdev wiki documentation.

Code & repositories

  • https://github.com/SourMesen/Mesen2 @ b9fa69ddc6d0a331fb103fdb5eef6904305703c2 · license: GPL-3.0-only (declared by the contributor for the files used; GitHub reports GPL-3.0 for the repository)
    SNES header scoring and coprocessor detection (Core/SNES/BaseCartridge.cpp, CartTypes.h)
    Tested on: source read, not run: source read, not run · checked 2026-10-18; archived; last activity 2026-06-04; Note: the latest release ships binaries; the wiki links only the source, never the binaries