# Galaga RAM Map (for the remix) What the running game keeps where, so that a new renderer can draw the game from RAM and mods can change it. Written to the rules in [STYLE.md](STYLE.md), with two kinds of source: - **measured**: from `galaga-probe` captures of the board in this repository, which reproduces MAME 0.285's reference runs (README). Capture method below. - **disasm**: the community-commented disassembly by Glenn A. Neidermeier et al., https://github.com/hackbar/galaga (commit `5b11485`, 2020-05-22; forked from neiderm/arcade). Its licence permits non-commercial use of the information only. Its facts are restated here with the file named, never copied, and a fact cited only to it is marked `[disasm]`. Where the two disagree, the measurement wins and the difference is noted. Addresses are CPU addresses. Main = main CPU, sub = the "motion" CPU, sound = sub2 (bus names in [memory-map.md](memory-map.md)). ## How it was measured ``` cargo run --release --bin galaga-probe -- --frames 12000 --ppm-every 37 --out target/probe-a python3 tools/... # analysis over target/probe-a/ram.bin (tools/probe_data.py loads it) ``` `galaga-probe` plays the board with a random player (coin and start every 30 s, random stick, random fire) and writes every frame's video RAM and work RAM, periodic screenshots, and an access profile: for every RAM byte, which CPU at which PC read or wrote it and which values were written (`src/galaga/profile.rs`; off unless the probe turns it on, so the oracle runs are unaffected, which `galaga-oracle` confirms). The random player does not clear stage 1, so everything below is measured on stage 1, attract mode and the self-test; later-stage features are `[disasm]` or `[unverified]`. The first ~800 frames are the power-on RAM test, which fills RAM with test patterns. Every statistic here excludes them. ## Coarse layout (measured: the access profile) | Range | Writers / readers | What | |---|---|---| | `0x8800`-`0x887f` | main, sub / main, sub | object status table, 64 slots x 2 bytes | | `0x8a20`-`0x8a4c` | main | top-5 scores and initials `[disasm]` | | `0x8b00`-`0x8b7f` | main, sub / main, sub | sprite code/colour, staging copy | | `0x8b80`-`0x8bff` | main, sub / main | sprite code/colour, live registers | | `0x9100`-`0x91ef` | main, sub / main, sub | motion queue, 12 entries x `0x14` bytes | | `0x9201` | main | game state | | `0x9300`-`0x937f` | main, sub / main, sub | sprite position, staging copy | | `0x9380`-`0x93ff` | main, sub / main | sprite position, live registers | | `0x9820`-`0x984f` | main | active player's state (lives, stage, ...) `[disasm]` for the layout | | `0x9a00`-`0x9aff` | main, sound | sound CPU's variables and trigger flags | | `0x9b00`-`0x9b7f` | main, sub / main, sub | sprite flags and X high bits, staging copy | | `0x9b80`-`0x9bff` | main, sub / main | sprite flags and X high bits, live registers | The hardware draws from the live registers (the top 128 bytes of each work RAM, [memory-map.md](memory-map.md)). The game builds each frame in the staging copies 128 bytes below and the sub CPU copies them up (`f_05BF`) `[disasm: mrw.s, gg1-5.s]`. A renderer reads the live registers: they are what the cabinet shows. ## Objects: 64 slots Slot *n* has a status pair at `0x8800 + 2n` and the sprite registers of the same index. `src/galaga/objects.rs` decodes a slot to a screen-space box; `tests/objects.rs` checks against the video pipeline that every pixel a slot's sprite draws lies inside its decoded box (1,893 visible sprites in the game-2400 run, 2026-09-28). **Screen position.** The video pipeline draws a 288x224 landscape raster and the cabinet shows it rotated: screen (x, y) = (223 - raster y, raster x) (`Video::screen_rgba`). With `P` = `0x9380 + 2n`, `C` = `0x9b80 + 2n`: - raster x = `P[1] + 256 * (C[1] & 3) - 40` - raster y = `((256 - P[0] + 1 - 16 * dh) & 0xff) - 32`, dh = `C[0]` bit 3 - screen box: x = `224 - raster y - w`, y = raster x, w = `16 * (1 + dh)`, h = `16 * (1 + dw)`, dw = `C[0]` bit 2 The video latch's flip bit (`0xa007`) is set only at the end of the power-on test (frames 712-862 after power-on, measured 2026-10-01; an earlier note here said it stayed set in play, from a trace cut off at frame 852); it is clear in attract mode and play. Where it is set, it mirrors the sprite and tile pictures but not sprite positions, so the boxes hold either way. `C[1]` bit 1 adds 512 to raster x, which puts the sprite off screen; the game parks unused sprites that way. **Slot roles.** The game's code indexes objects by byte offset L = 2 x slot (the same L indexes the three sprite register banks). Measured on stage 1 where the column says so; the rest from the disassembly. | Slots | L | Role | Evidence | |---|---|---|---| | `0x00`-`0x03` | `0x00`-`0x06` | captured fighters (red, above their bosses) | `[disasm: task_man.s, gg1-2_fx.s]` | | `0x04`-`0x17` | `0x08`-`0x2e` | the 20 bees | `[disasm: gg1-2_fx.s]` | | `0x18`-`0x1b` | `0x30`-`0x36` | the 4 bosses | measured: the "400" score popups appear in these slots | | `0x1c`-`0x1f` | `0x38`-`0x3e` | transients and bonus-bee clones | `[disasm: gg1-3.s, gg1-5.s]` | | `0x20`-`0x2f` | `0x40`-`0x5e` | the 16 butterflies | `[disasm: gg1-2_fx.s]` | | `0x30` | `0x60` | second fighter of the dual fighter, 15 px right of slot 0x31 | measured 2026-10-01 after a rescue; its status stays 0x80 like the fighter's, 0x08 when it is shot down | | `0x31` | `0x62` | the player's fighter | measured: the only slot drawn on the ship row | | `0x32`-`0x33` | `0x64`-`0x66` | the player's two rockets | measured: move up 6 px per frame | | `0x34`-`0x3b` | `0x68`-`0x76` | eight enemy bombs | measured: 0x34-0x37 seen, down 2-3 px per frame; eight per `[disasm]` and the no-fire bug | The fighter and rockets are live while their position is non-zero, not by their state byte, which stays `0x80` for a live fighter `[disasm: gg1-5.s]`, as measured. **State byte** `0x8800 + L`. The main CPU's dispatcher (`f_23DD`, main 0x23DD) treats any value with bit 7 set as inactive and otherwise jumps on the value; it services half the objects on each odd frame `[disasm: gg1-3.s]`. Measured on stage 1, meaning cross-checked with the disassembly: | Value | Meaning | Measured evidence | |---|---|---| | `0x80` | inactive (also a live fighter or rocket, see above) | the default | | `0x00` | a rescued fighter spinning down to dock `[disasm]` | | | `0x01` | resting in the formation; flap = sprite code bit 0 | two-frame codes 0x16/0x17, 0x1e/0x1f, ... | | `0x07` | spawned by the wave launcher this frame | always `80 -> 07 -> 03` | | `0x03` | flying an entrance path, no home check | `07 -> 03 -> 09` | | `0x09` | diving, or flying home with the home cell tracked | `01 -> 09` is a dive; `03 -> 09` the path's head-home command | | `0x02` | home; rotating back to upright | `09 -> 02 -> 01` | | `0x04` | exploding | codes 0x41-0x44, aux 0x40-0x45 | | `0x05` | score popup (code 0x35 = 400, 0x37 = 800, 0x38 = 1000, 0x3a = 1600 `[disasm]`) | in boss slots after 04 | | `0x06` | rocket or bomb | slots 0x32-0x37 | | `0x08` | fighter exploding (code 0x20 -> 0x2c in steps of 4, double size) | slot 0x31 only | Transitions seen for enemy slots, most common first: `09->02` 77, `80->07` 76, `07->03` 76, `02->01` 76, `03->09` 72, `04->80` 64, `01->04` 42, `01->09` 23, `01->80` 20, `09->04` 14, `03->04` 8. **Aux byte** `0x8801 + L`: while flying (03, 07, 09) the byte offset of the object's motion-queue entry (measured: 0, 0x14, 0x28, ...); while exploding (04) a counter from 0x40 whose value is the tile code, going double size at 0x44 and ending at 0x45; in a popup (05) a countdown from 0x13; while the fighter explodes (08) a countdown from 0x0f `[disasm: gg1-3.s]`. **For the renderer.** An explosion starts when a slot goes `01`/`03`/`09` -> `04` (the colour byte is set to 0x0a); the fighter dies when slot 0x31 goes to `08`; a dive starts at `01 -> 09`. ## Motion queue `0x9100` (12 x `0x14` bytes): the flight paths The sub CPU flies every object that is in state 3, 7 or 9 from one of 12 queue entries (runner `f_08D3`, sub 0x08D3). Entry *k* at `0x9100 + 0x14k` `[disasm: gg1-5.s]`; +0x10 and the entries' use measured: | Offset | Field | |---|---| | `00`-`01` | Y, 9.7 fixed point | | `02`-`03` | X, 9.7 fixed point | | `04`-`05` | heading, 10 bits: 0x100 = 90 degrees, 0x400 = a full turn | | `06`, `07` | target Y and X (bits 8:1): the home cell or a loop point | | `08`-`09` | pointer to the next path token, in **sub CPU ROM** (measured 0x001d-0x045d) | | `0a` / `0b` | speed on odd / even frames | | `0c` | signed turn rate added to the heading each step | | `0d` | frames left in the current segment | | `0e` | bomb-drop countdown | | `0f` | bomb-enable bits, shifted out one per drop | | `10` | the object's L (measured) | | `11`, `12` | home-cell offsets while homing (the formation's breathing) | | `13` | bit 0 active, bit 5 fly until Y = +06, bit 6 homing, bit 7 mirrored | Entries 8-11 were never used on stage 1. **The path language** `[disasm: gg1-5.s, interpreter j_090E at sub 0x090E]`. A path is a byte stream. A token below 0xef starts a three-byte segment `[speeds][turn][frames]`: low nibble of the speed byte to +0a, high to +0b, turn rate to +0c, frame count to +0d. Tokens 0xef-0xff are commands: | Token | Operand | Action | |---|---|---| | `ff` | | end: object inactive, entry freed | | `fe` | 8-byte table | segment length chosen by the fighter's X | | `fd` | pointer | jump | | `fc` | yy | fly on until Y reaches yy | | `fb` | | head home: state 9, heading computed to the home cell | | `fa` | pointer | jump unless continuous bombing is on | | `f9` | | X = the home column | | `f8` | | Y = 0x9c: re-enter from the top of the screen | | `f7` | pointer | jump if the object is a transient | | `f6` | nn | heading = nn x 4; reload the bomb timers | | `f5` | | state 3 | | `f4` | | the capture boss aims its beam at the fighter | | `f3` | 8-byte table | segment length by X distance to the fighter | | `f2` | pointer | split off a bonus-bee clone flying from pointer | | `f1` | | Y = home row origin + 0x20 | | `f0` / `ef` | pointer | jump if a per-stage flag (0x99c8 / 0x99c9) is set | Where the paths are, in sub CPU ROM: bee dive `0x034f`, butterfly dive `0x03a9`, boss `0x0411`, rogue fighter `0x0444`, capture boss `0x0454`, boss carrying a fighter `0x046b`, clone attacks `0x0473`/`0x04ab`/`0x04ea`. Entrance paths are chosen through a 24-word table in main ROM at `0x2a3c` (bits 0-12 the path pointer, bits 13-15 a start position from `0x2a6c`) `[disasm: gg1-3.s]`. **This is the lever for new dive patterns**: the paths are data, and the interpreter already has turns, loops, homing and aiming at the fighter. A mod can serve different bytes for these ROM ranges, or new commands can be added on the Rust side. ## Scalars | Address | What | Evidence | |---|---|---| | `0x9201` | game state: 0 ended, 1 attract, 2 ready, 3 play `[disasm: mrw.s]` | measured 2 and 3 in play | | `0x9820`-`0x983f` | the active player's state; `0x9860` holds the other player's while swapped out `[disasm]` | | | `0x9820` | reserve ships; `0xff` after the last death | measured: 2 at a 3-life start, -1 per death | | `0x9821` | stage number; a challenging stage when (n + 1) % 4 == 0 `[disasm]` | measured: 1 on stage 1 | | `0x9827` | dual fighter: 1 while both ships fly `[disasm]` | measured 2026-10-01: set as the rescued ship docks, back to 0 when either ship is lost; holds attract-demo garbage on the first frame of play | | `0x9828`, `0x9829` | capture boss's (or rescued ship's) L, 1 = none; its queue entry `[disasm]` | measured: 0x32 (boss slot 0x19) during a capture, back to 1 once the captive joins the formation | | `0x9840` | current player, 0 or 1 `[disasm]` | | | `0x9362` | fighter X (staging copy; slot 0x31's position) `[disasm]` | by construction of the slot table | | `0x83f8`-`0x83fd` | 1UP score digits in tile RAM, units first, tile 0x24 = blank | measured: reads 3410, 580, 3000 where the screen does | | `0x83e3`-`0x83e8` | 2UP score digits `[disasm]` | | | `0x83ed`-`0x83f2` | high score digits `[disasm]` | | | `0x928a`-`0x928e` | tractor beam: beam X, step, countdown, capture-boss status, "FIGHTER CAPTURED" `[disasm]` | measured: 0x928a, 0x928b, 0x928d, 0x928e unchanged through 9,000 frames of play in which no capture happened; not yet watched through one | | `0x9288` | challenging-stage hit counter, what "NUMBER OF HITS" shows | measured 2026-10-01: reset about 55 frames into the stage, +1 per hit a frame before the explosion; two rockets meeting one enemy a frame apart count it twice (41 hits, no PERFECT) | | `0x92b0`-`0x92bf` | per-bomb X step, 8 x 2 bytes `[disasm]` | | | `0x920f` | formation breathing counter; bit 7 = contracting `[disasm]` | | | `0x9800`-`0x981f` | formation cell pixel coordinates `[disasm]` | | | `0x92a0`-`0x92a2` | frame counters `[disasm]` | | The tractor beam is not a sprite: the main CPU draws it into tile and colour RAM (`f_2222`, main 0x2222) `[disasm: gg1-3.s]`, so a renderer that keeps the tile layer shows it as is, and one that replaces it can find it from `0x928a`. ## Capture and rescue (measured 2026-10-01) Seen with `galaga-tas --dual` and probes on the remix board: 1. A boss beams the fighter; the captured fighter appears in one of slots 0x00-0x03 (state 0x01 once it sits in the formation above its boss), and only then does the reserve count at `0x9820` drop as the next ship comes in. The fighter does not explode: no state 0x08. 2. Shooting the boss while it dives with the captive frees it; the rescued ship docks and `0x9827` becomes 1, with slot 0x30 flying 15 px right of slot 0x31. 3. With the pair, one press fires one rocket sprite centred between the ships (8 px right of slot 0x31) covering both lanes; there are still two rocket slots, 0x32 and 0x33.