# Memory map: the CUS117 space and each CPU's view Everything on this page is **OBSERVED** unless tagged otherwise: MAME 0.285's address maps as its running binary builds them for `pacmania`, printed by `scripts/mame_maps.lua` (the Lua `address_space.map` entries: range, mirror, handler kind, share name, region). MAME names many handlers only "delegate", so this page gives ranges and kinds, and marks every function it cannot see as HYPOTHESIS. The source that would name them is MAME's `namcos1.cpp`, `c117.cpp` and friends, which are BSD-3-Clause by their `license:` lines but closed for this Phase 0 (open decision 1). Run it again with: ```sh mame pacmania -rompath "$MAME_ROMPATH" -video none -sound none -nothrottle -noreadconfig \ -skip_gameinfo -seconds_to_run 1 -autoboot_script scripts/mame_maps.lua | grep '^MAP' ``` ## The CUS117 "virtual" space (23 bits, $000000-$7FFFFF) MAME models the CUS117 as a device with its own 23-bit program space; the main and sub 6809s see all of $0000-$FFFF as one handler (a "delegate") that goes through it. A 23-bit space for "a pair of M6809 CPUs" is also how MAME's `c117.cpp` header describes the chip (seen only as a web-search summary of that file, not opened; the map below shows the same width directly). | Range (23-bit) | Size | Kind | MAME share/region | Function | | --- | --- | --- | --- | --- | | $2C0000-$2C1FFF | 8 KB | write only | - | HYPOTHESIS: a control or key-related write port; unnamed | | $2E0000-$2E7FFF | 32 KB | read/write handler | - | HYPOTHESIS: the C116 palette (the size of 3 x 8-bit colour RAMs plus registers) | | $2F0000-$2F7FFF | 32 KB | read/write handler | - | HYPOTHESIS: C123 tilemap RAM | | $2F8000-$2F9FFF | 8 KB | read/write handler | - | HYPOTHESIS: the per-game key custom ([keys-and-protection.md](keys-and-protection.md)) | | $2FC000-$2FC7FF | 2 KB | RAM | `scratchpad` | work RAM | | $2FC800-$2FCFFF | 2 KB | RAM, write handler | `spriteram` | sprite list (writes trapped: HYPOTHESIS, a sprite-DMA trigger) | | $2FD000-$2FD01F (mirror $FE0) | 32 B | handler | - | HYPOTHESIS: video control registers | | $2FE000-$2FE3FF (mirror $C00) | 1 KB | handler | - | the CUS30's registers and wave RAM, also seen by the sound CPU at $5000 (same size and mirror) | | $2FF000-$2FF7FF (mirror $800) | 2 KB | RAM | **`triram`** | the three-port RAM: also the sound CPU's $7000 and the MCU's $C000 | | $300000-$307FFF | 32 KB | RAM | - | main RAM | | $400000-$7FFFFF | 4 MB | ROM | `mainrom` | the game's program ROMs | How a 6809's 64 KB is cut into windows of this space (bank size, bank registers, which CPU owns which register, the interrupt and reset registers) is **not visible in the map**: U1 in the brief. The 2 s trace in [mame-oracle.md](mame-oracle.md) shows the sub CPU, sound CPU and MCU all restarting at frame 110 of Pac-Mania (their cycle counters drop to 0 and their PCs return to the reset entry), consistent with the main CPU releasing or re-asserting their resets through the CUS117 (the chip MAME's header calls "the reset generator for the entire system"): HYPOTHESIS, to be confirmed by a watchpoint run. ## Sound CPU (MC6809E) | Range | Kind | Function | | --- | --- | --- | | $0000-$3FFF | bank `soundbank` (read) | banked sound program ROM | | $4000-$4001 | handler | YM2151 (address, data): HYPOTHESIS from the chip list and the pair of addresses | | $5000-$53FF (mirror $C00) | handler | CUS30 (shared with the C117 space's $2FE000) | | $7000-$77FF (mirror $800) | RAM `triram` | the three-port RAM | | $8000-$9FFF | RAM | sound work RAM | | $A000 | read nop | | | $C000-$C001, $D001, $E000 | write handlers | HYPOTHESIS: bank select, watchdog, interrupt acknowledge | | $C000-$FFFF | ROM (read) | fixed sound program ROM (reads; the writes above overlay it) | ## MCU (HD63701V0, the CUS64) | Range | Kind | Function | | --- | --- | --- | | $0000-$0014 | handlers | the HD6301's on-chip registers (ports, timer, SCI; DOC: Hitachi U07) | | $0080-$00FF | RAM `internal_ram` | 128 bytes on-chip RAM (DOC: U07, "128 Bytes of RAM") | | $1000-$1003 | read handlers | HYPOTHESIS: DIP switches and inputs | | $1400, $1401 | ports `CONTROL0`, `CONTROL1` | player controls (MAME's port names) | | $4000-$BFFF | bank `mcubank` (read) | the voice (sample) ROMs, banked | | $C000-$C7FF | RAM `triram` | the three-port RAM | | $C800-$CFFF | RAM `nvram` | battery-backed RAM (high scores, settings) | | $D000, $D400, $D800, $F000 | write handlers | HYPOTHESIS: the two DACs, the voice-ROM bank, and one more control | | $F000-$FFFF | ROM | the 4 KB internal program (`cus64-64a1.mcu`, one image for all 40 sets) | ## Channels this map implies The **triram** is the meeting point of three CPUs (the main/sub pair through the CUS117, the sound 6809, the MCU), and the CUS30 is visible from both the main side and the sound CPU. These are the channels [domains-and-speed.md](domains-and-speed.md) builds on.