# Z80 Memory Map Three Z80s, each at **3.072 MHz** (18.432 MHz crystal ÷ 6; `MASTER_CLOCK` and the three `Z80(config, ...)` lines in `galaga_state::galaga` in MAME `src/mame/namco/galaga.cpp`). MAME names them `maincpu`, `sub` and `sub2`; the driver header calls them MAIN, SUB (motion) and SOUND. All three run the **same address map**, `galaga_state::galaga_map`, and every range from `0x6800` upward is one shared bus — a write by any CPU is seen by the others. Only `0x0000`-`0x3fff` differs per CPU: each Z80 has its own program ROM there. Sources: `galaga.cpp` (`galaga_map`, the Galaga decode table in the file header, the handler bodies, `galaga_state::galaga` machine config, `ROM_START( galaga )`), `galaga.h`, `galaga_v.cpp` (`draw_sprites`, `galaga_videoram_w`), MAME `src/devices/sound/namco.cpp` (`pacman_sound_w` and its register comment), `src/mame/namco/namco06.cpp`, `src/devices/machine/74259.cpp`, `src/emu/romload.cpp`, `src/emu/emumem_aspace.cpp`. ## Per-CPU program ROM (`ROM_START( galaga )`, `galaga_map`) | CPU | Populated | ROMs (see [rom-manifest.md](rom-manifest.md)) | `0x1000`-`0x3fff` | |---|---|---|---| | main | `0x0000`-`0x3fff` (16 KB) | gg1_1b.3p, gg1_2b.3m, gg1_3.2m, gg1_4b.2l, 4 KB each | ROM | | sub | `0x0000`-`0x0fff` (4 KB) | gg1_5b.3f | not connected (header decode table) | | sub2 | `0x0000`-`0x0fff` (4 KB) | gg1_7b.2c | not connected (header decode table) | `galaga_map` declares `0x0000`-`0x3fff` as ROM with writes discarded for all three CPUs (`.rom().nopw()`). For sub/sub2, `0x1000`-`0x3fff` therefore reads the unloaded part of a 64 KB ROM region; `romload.cpp` zero-fills regions ≤ 4 MB that have no erase flag, so MAME returns **`0x00`** there. Real boards have nothing on the bus at those addresses `[unverified what the bus floats to]`. ## Full map (`galaga_state::galaga_map` unless noted) | Range | Size | Device | R/W | Notes | |---|---|---|---|---| | `0x0000`-`0x3fff` | 16 KB | program ROM | R (W ignored) | per-CPU, see above | | `0x4000`-`0x67ff` | — | nothing | — | header decode table: `0x4000`-`0x67ff` not connected | | `0x6800`-`0x6807` | 8 | DIP switches | R | `bosco_dsw_r`; 2 bits per address, see below | | `0x6800`-`0x681f` | 32 | WSG sound registers (RAM 2A/2B, 4-bit) | W | `namco_wsg_device::pacman_sound_w`; low nibble only | | `0x6808`-`0x681f` | 24 | nothing | R | unmapped; header table marks the read side n.c. | | `0x6820`-`0x6827` | 8 | LS259 "misclatch" (3C, CPU board) | W | `ls259_device::write_d0`: bit 0 of data, address selects bit; see latch table | | `0x6830` | 1 | watchdog | W | `watchdog_timer_device::reset_w`; must be written within 8 vblanks (`set_vblank_count(m_screen, 8)`) or MAME resets the machine. Safe to ignore in an emulator, as in galemu | | `0x7000`-`0x70ff` | 256 | 06XX data window | R/W | `namco_06xx_device::data_r`/`data_w`; all 256 addresses hit the same port | | `0x7100` | 1 | 06XX control | R/W | `namco_06xx_device::ctrl_r`/`ctrl_w`; see 06XX section | | `0x7101`-`0x7fff` | — | nothing | — | unmapped (hardware decode implies mirrors, see below) | | `0x8000`-`0x87ff` | 2 KB | video RAM (RAM 1K) | R/W | `galaga_videoram_w`; tile index is `offset & 0x3ff`, so the two 1 KB halves address the same 1024 cells (code / attribute — see [video-hardware.md](video-hardware.md)) | | `0x8800`-`0x8bff` | 1 KB | work RAM 1 (RAM 3E/3F) | R/W | share `galaga_ram1`; top 128 bytes are sprite bytes | | `0x8c00`-`0x8fff` | — | nothing | — | not declared by MAME; hardware decode implies a mirror of RAM 1 | | `0x9000`-`0x93ff` | 1 KB | work RAM 2 (RAM 3K/3L) | R/W | share `galaga_ram2`; top 128 bytes are sprite bytes | | `0x9800`-`0x9bff` | 1 KB | work RAM 3 (RAM 3H/3J) | R/W | share `galaga_ram3`; top 128 bytes are sprite bytes | | `0xa000`-`0xa007` | 8 | LS259 "videolatch" (5K, video board) | W | `ls259_device::write_d0`; starfield control + flip, see below | | `0xa008`-`0xffff` | — | nothing | — | unmapped | Inputs are **not** memory-mapped: IN0/IN1 (joystick, fire, start, coin, service) are read by the 51XX custom through the 06XX window (`n51xx.input_callback<0..3>` in the machine config). Only the DIP switches sit directly on the bus. **Unmapped reads** return `0x00` in MAME: `address_space` initialises its unmapped value to 0 (`emumem_aspace.cpp`) and `galaga.cpp` never calls `unmap_value_high()`. **Mirrors.** `galaga_map` declares none (no `.mirror()` in the map). The decode table in the driver header, however, shows that hardware leaves several address lines undecoded: `0x6800`-`0x683f` repeat every `0x40` through `0x6fff`; the 06XX data/control select is A8 only, so data repeats at `0x7000`-`0x70ff`, `0x7200`-`0x72ff`, … and control at `0x7100`-`0x71ff`, `0x7300`-`0x73ff`, … through `0x77ff`; each 1 KB work RAM ignores A10 (`0x8800`≡`0x8c00`, `0x9000`≡`0x9400`, `0x9800`≡`0x9c00`); the video latch repeats every 8 bytes through `0xa7ff`. Treat these as `[unverified]` against schematics; the parent ROMs run in MAME without them. ## Write latch `0x6820`-`0x6827` (misclatch, LS259 at 3C) Writing to `0x6820 + n` sets latch bit n to data bit 0 (`write_d0`). Callback wiring is in `galaga_state::galaga`; the driver's names come from the header decode table. | Address | Bit | Name | Effect (`galaga.cpp`) | Reset state | |---|---|---|---|---| | `0x6820` | Q0 | IRQ1 | `irq1_clear_w`: 1 = main CPU vblank IRQ enabled; writing 0 also drops a pending IRQ | 0 (disabled) | | `0x6821` | Q1 | IRQ2 | `irq2_clear_w`: same for the sub CPU | 0 (disabled) | | `0x6822` | Q2 | NMION | `nmion_w`: sub2 NMI mask = NOT Q2, i.e. **0 = NMI on, 1 = NMI off** | see note | | `0x6823` | Q3 | RESET | inverted to the RESET line of sub and sub2, and reset of 51XX and 54XX: **0 = held in reset, 1 = running** | see note | | `0x6824` | Q4 | n.c. | no callback | 0 | | `0x6825`-`0x6827` | Q5-Q7 | MOD 0-2 | header calls them "unused?"; no callback | 0 | Reset note. `addressable_latch_device::device_reset` clears all Q to 0, but `clear_outputs` only invokes callbacks for bits that *change*, and Q already starts at 0, so no callback runs. The driver's `m_main_irq_mask`, `m_sub_irq_mask` and `m_sub2_nmi_mask` all start at 0 (`galaga.h` constructor) and the sub CPUs are **not** held in reset by MAME at power-on. That leaves `m_sub2_nmi_mask` (0, NMI off) inconsistent with Q2 (0, would mean NMI on) until the game first writes 1 then 0 to `0x6822`; `update_bit` likewise ignores writes that do not change a bit. Whether real hardware ties the LS259 /CLR to system reset is `[unverified]`. Interrupt sources: `vblank_irq` asserts IRQ (Z80 maskable, mode-dependent) on main and sub at the start of vblank when the respective enable is set. `cpu3_interrupt_callback` pulses NMI on sub2 at scanlines 64 and 192 (period 128 lines, wrapping at 272 back to 64; first one scheduled for line 64 by `machine_reset`) while the NMI mask is set. ## Video latch `0xa000`-`0xa007` (videolatch, LS259 at 5K) Bit use is from `galaga_state::screen_vblank_galaga` in `galaga_v.cpp` and the header table; semantics belong to [video-hardware.md](video-hardware.md). | Address | Bit | Use | Reset | |---|---|---|---| | `0xa000`-`0xa002` | Q0-Q2 | 05XX starfield X-scroll speed index (Q0 = bit 0) | 0 | | `0xa003`-`0xa004` | Q3-Q4 | 05XX active starfield set select (`set_active_starfield_sets(q3, q4 \| 2)`) | 0 | | `0xa005` | Q5 | 05XX starfield enable (STARCLR); header: "unknown" | 0 (stars off) | | `0xa006` | Q6 | n.c. | 0 | | `0xa007` | Q7 | FLIP: `flip_screen_set`, 1 = flipped | 0 | ## DIP switch read `0x6800`-`0x6807` (`bosco_dsw_r`) Reading `0x6800 + n` (n = 0..7) returns bit n of one bank in **bit 0** and bit n of the other bank in **bit 1**; bits 2-7 are 0. Bit 0 carries MAME port `DSWB`, bit 1 carries MAME port `DSWA`. Per `INPUT_PORTS_START( galaga )` `PORT_DIPLOCATION`, MAME's `DSWB` is the physical switch block **SWA** (coinage bits 0-2, bonus life 3-5, lives 6-7) and `DSWA` is physical **SWB** (difficulty 0-1, demo sounds 3, freeze 4, rack test 5, cabinet 7). The header decode table labels bit 0 "dip switch B" and bit 1 "dip switch A" — that follows MAME's port names, not the silkscreen; this document follows the `PORT_DIPLOCATION` labels because they are what the game's option tables are tested against. All switches are active-low. ## WSG sound registers `0x6800`-`0x681f` (`pacman_sound_w` register comment, `namco.cpp`) Write-only, 4-bit (data is masked to `0x0f`). Voice clock 18.432 MHz ÷ 6 ÷ 32 = 96 kHz (`NAMCO_WSG(config, ...)`). Detail in [sound-hardware.md](sound-hardware.md). | Address | Voice | Register | |---|---|---| | `0x6805` / `0x680a` / `0x680f` | 0 / 1 / 2 | waveform select (bits 0-2) | | `0x6810` | 0 only | frequency bits 0-3 (voice 0 has 20-bit frequency; others 16-bit) | | `0x6811`-`0x6814` | 0 | frequency bits 4-7, 8-11, 12-15, 16-19 | | `0x6815` | 0 | volume | | `0x6816`-`0x6819` / `0x681a` | 1 | frequency (as above, nibble order low to high) / volume | | `0x681b`-`0x681e` / `0x681f` | 2 | frequency / volume | | all other offsets | — | stored, no effect | ## Sprite bytes in the work RAMs (`draw_sprites`, `galaga_v.cpp`) The last 128 bytes of each work RAM (offset `0x380`-`0x3ff`) hold 64 two-byte sprite records, and each RAM holds a different pair of bytes for the same sprite index i (0..63): | RAM | Addresses | Byte 0 (`+2i`) | Byte 1 (`+2i+1`) | |---|---|---|---| | RAM 1 | `0x8b80`-`0x8bff` | sprite code, bits 0-6 | colour, bits 0-5 | | RAM 2 | `0x9380`-`0x93ff` | Y position | X position, low 8 bits | | RAM 3 | `0x9b80`-`0x9bff` | bit 0 flip X, bit 1 flip Y, bit 2 double width, bit 3 double height | X position, bits 8-9 (bits 0-1) | The header decode table confirms the same `-111xxxxxxx` sub-range in all three RAMs. ## 06XX window (`namco06.cpp`) `0x7100` control byte: bits 0-3 select the 06XX sub-device (on Galaga bit 0 = 51XX I/O, bit 3 = 54XX explosion sound, bits 1-2 unconnected per the interface table), bit 4 = direction (1 = read, 0 = write), bits 5-7 = transfer-clock divider (0 stops the transfer and the NMI to the main CPU). `0x7000` reads AND together the selected devices' data (starting from `0xff`) and writes broadcast to every selected device. The 06XX clock is 18.432 MHz ÷ 6 ÷ 64 = 48 kHz; its NMI goes to the main CPU (`set_maincpu(m_maincpu)`). Control resets to 0 (`device_reset`).