# Graphics Bitplane Specification Sources: `galaga.cpp` (`charlayout_2bpp`, `spritelayout_galaga`, `gfx_galaga`, `ROM_START(galaga)`), `galaga_v.cpp` (`galaga_palette`, `draw_sprites`), and MAME's decoder convention in `src/emu/drawgfx.cpp` (`gfx_element::decode`, `readbit`). ## ROMs | Region | ROM | Bytes | CRC32 / SHA1 | Holds | |---|---|---|---|---| | gfx1 `0x0000` | `gg1_9.4l` | 4,096 | `58b2f47c` / `62f1279a784ab2f8218c4137c7accda00e6a3490` | 256 characters x 16 bytes | | gfx2 `0x0000` | `gg1_11.4d` | 4,096 | `ad447c80` / `e697c180178cabd1d32483c5d8889a40633f7857` | sprites 0-63 x 64 bytes | | gfx2 `0x1000` | `gg1_10.4f` | 4,096 | `dd6f1afc` / `c340ed8c25e0979629a9a1730edc762bd72d0cff` | sprites 64-127 x 64 bytes | Characters 0-127 are the set addressed by the tile code byte (bits 0-6); characters 128-255 are X-mirrored copies the hardware selects in flipped-screen mode (`get_tile_info`). Sprite codes are 0-127 (bits 0-6 of the sprite byte). ## Bit convention Both layouts are 2 bpp with plane offsets 0 and 4 bits: the two planes of a 4-pixel group share one byte. MAME reads bits most-significant first (`readbit`) and gives plane 0 the pixel's high bit (`decode`), so for local column k (0-3) within the group: $$ p = 2\cdot\big((\text{byte} \gg (7-k)) \mathbin{\&} 1\big) + \big((\text{byte} \gg (3-k)) \mathbin{\&} 1\big) $$ So the high nibble supplies the pixel's bit 1 (MAME plane 0) and the low nibble its bit 0 (MAME plane 1); the most significant bit of each nibble is the leftmost pixel of the group. ## Characters (8x8, `charlayout_2bpp`) Character c occupies bytes $16c$ to $16c+15$. Bytes 0-7 hold rows 0-7 of the **right** half (x = 4-7); bytes 8-15 hold rows 0-7 of the **left** half (x = 0-3). For pixel (x, y): $$ \text{offset} = 16c + y + 8\,(1 - \lfloor x/4 \rfloor),\qquad k = x \bmod 4 $$ ## Sprites (16x16, `spritelayout_galaga`) Sprite s occupies bytes $64s$ to $64s+63$. Bytes 0-31 are rows 0-7 and bytes 32-63 rows 8-15; each 32-byte half is four 8-byte strips holding x = 0-3, 4-7, 8-11, 12-15 in that order, one byte per row. For pixel (x, y): $$ \text{offset} = 64s + 32\lfloor y/8 \rfloor + 8\lfloor x/4 \rfloor + (y \bmod 8),\qquad k = x \bmod 4 $$ Note the strip order differs from characters: sprites store the leftmost 4-pixel strip first, characters store it second. Double-width or double-height sprites (`draw_sprites`) use consecutive codes `c, c+1, c+2, c+3` for the top-left, top-right, bottom-left, bottom-right cells. ## From pixel value to color With pixel value $p$ (0-3) and 6-bit color attribute $a$ (0-63): 1. Lookup PROM index = $4a + p$ (256 entries). Characters use `prom-4.2n`, sprites `prom-3.1c`; only the low nibble $n$ of the byte is used (`galaga_palette`). 2. Palette entry = $16 + n$ for characters, $n$ for sprites. Nibble value `0xf` (palette entry 31 for characters, 15 for sprites) is transparent; nibble 0 is an opaque color. 3. The entry selects one byte of `prom-5.5n`; its RGB decode is tabulated in `video-hardware.md`.