# Start here: the HG51B169 (Cx4) as a core author needs it The **Capcom Cx4** in *Mega Man X2* and *Mega Man X3* (*Rockman X2/X3*) is a **Hitachi HG51B169** ("CAPCOM CX4 DL-2427, BS169FB" on the package; "a Hitachi HG51B169 as confirmed by decapping", fullsnes "SNES Cart Capcom CX4"): an 80-pin 24-bit DSP-style CPU with 16-bit instructions, a 24-bit accumulator, a 24 x 24 multiplier, sixteen 24-bit general registers, a 3 KiB data RAM, a 3 KiB data ROM of math tables, and **no program ROM of its own**: it fetches its program from the cartridge ROM into a two-page instruction cache. It sits *between* the SNES and the cartridge ROM (pins 1-24 and 61-80 are the SNES bus, pins 25-60 the ROM/SRAM bus with `/ROM1`, `/ROM2`, `/SRAM`; fullsnes "SNES Pinouts CX4 Chip"), so every S-CPU ROM read passes through it. **Hitachi published nothing on the HG51B169 that anyone has found** (searched 2026-11-06; validation.md "What does not exist"). Everything below is research tier (fullsnes, from the program and probing), emulator tier (byuu's model as published in ares, ISC) or OBSERVED (Mesen2 run as a closed box), and each statement says which. This repository builds the chip: CPU, cache, DMA, bus port, data RAM, data ROM and its SNES-side register file. The board (snes-python, milestone 7) owns the clock relation, the cartridge ROM bytes, and the S-CPU connector. [The boundary](handoff-brief.md#the-core-boundary) and the [open decisions](handoff-brief.md#open-decisions-for-aubrey) are in the brief. Sources and their short names (pinned in `scripts/pinned_*.json`; tiers in [validation.md](validation.md); what each may be used for in docs/provenance.md): - **fullsnes**: `reference/docs/fullsnes.txt` lines 8468-8766 ("SNES Cart Capcom CX4" and its I/O Ports, Opcodes, Functions sections), 22773 (oscillator), 24115-24140 (pinout). - **ares** `ares/component/processor/hg51b/` (the CPU) + `ares/sfc/coprocessor/hitachidsp/` (the SNES-side glue): byuu's model, ISC ("Copyright (c) 2004-2025 ares team, Near et al", NOTICE). bsnes carries the same core but is GPL-3: a closed box, never opened. - **Mesen2** (GPL-3): a closed box. Its library is driven by the GPL tool mesen2-runner, `$EMU_TOOLS_GPL/tools/mesen2/run.py --machine snes-cx4` in emu-tools-gpl (trace logger, host stream; run as a separate program) and `scripts/cx4_probe.py` (homebrew probe cartridges); what it does is OBSERVED, cited to the run. Earlier text here described its source; that reading is withdrawn (docs/provenance.md, Wave 2). - **MiSTer** Cx4 (no licence): not opened, not runnable here; not a source. - **MAME** 0.285 (`snescx4.cpp` GPL-2.0+), **snes9x**: the old high-level emulation (command results, no instructions); closed boxes. MAME's software list `hash/snes.xml` (CC0) gives the data ROM's hash. - **the program**: the 4,096 words at cartridge 02:8000-9FFF, read in place from the No-Intro set (BYOR) by `scripts/survey_program.py`. GPL and unlicensed sources (bsnes, Mesen2, snes9x, MAME's `snescx4.cpp`, MiSTer) are closed boxes only: run, never read. Line numbers below are of the pinned ares revision. ## Registers (ares `hg51b.hpp` l.104-137; fullsnes "Opcodes" lower-8-bit table) | Register | Width | Operand code | Notes | | --- | --- | --- | --- | | A | 24 | 00h | accumulator; every ALU result lands here | | MUL (MH:ML) | 48 | MH 01h, ML 02h | signed product of the last MUL; MH = bits 47-24, ML = bits 23-0 (fullsnes: "MSBs are sign-expanded") | | MDR | 24 | 03h | bus memory data register (fullsnes `ext_dta`); receives a bus read | | ROM | 24 | 08h | data ROM buffer (fullsnes `rom_dta`), set by RDROM | | RAM | 24 | 0Ch | data RAM buffer (fullsnes `ram_dta`), three byte lanes | | MAR | 24 | 13h | bus memory address register (fullsnes `ext_ptr`): a 24-bit SNES-style address | | DPR | 24 | 1Ch | data RAM pointer (fullsnes `ram_ptr`); RDRAM/WRRAM imm use DPR + imm | | PC | 8 | 20h | word within the current 256-word cache page | | P | 15 | 28h | page register (fullsnes `prg_page`): the page a far jump or a fall-through loads | | bus port | | 2Eh, 2Fh | reading or writing it starts an external access at MAR (U10): 2Eh with the ROM wait, 2Fh with the RAM wait; reads return 0 | | constants | 24 | 50h-5Fh | 000000, FFFFFF, 00FF00, FF0000, 00FFFF, FFFF00, 800000, 7FFFFF, 008000, 007FFF, FF7FFF, FFFF7F, 010000, FEFFFF, 000100, 00FEFF (fullsnes, ares `registers.cpp` l.26-41: identical) | | R0-R15 | 24 | 60h-6Fh (and 70h-7Fh, U5) | general registers; also the S-CPU's $7F80-$7FAF | | PB | 15 | | program bank: the page the cache holds for the running code | | stack | 8 entries | | return addresses (C4: what an entry holds and what overflow does) | | N, Z, C, V | 1 each | | flags (U9); V only from ADD/SUB (C10) | | other operand codes | | | read 0 (ares `registers.cpp` l.62; provisional, U5), writes ignored | Internal memories: **data RAM** 3,072 bytes (12-bit byte address; U3), **data ROM** 1,024 x 24 bits (U4, U21), **instruction cache** 2 pages x 256 words (U2), **vectors** 32 bytes ($7F60-$7F7F, U16). ## Instruction encoding (ares `instruction.cpp`; fullsnes "CX4 Opcodes") Every instruction is one 16-bit little-endian word (fullsnes "All values are little-endian"). Bits 15-10 select the operation, bits 9-8 a sub-field, bits 7-0 an operand: a register code (bit 7 ignored), an 8-bit immediate, a jump target within a page, or a 5-bit shift count. The shift sub-field `ss` gives A, A<<1, A<<8, A<<16 (fullsnes A*2/A*100h/A*10000h). | Bits 15-8 | ares name | fullsnes | Operation | | --- | --- | --- | --- | | 00-07 | NOP, ??? | nop, - | none | | 08-0B (f = bit 9) | JMP imm | jmp | PC = imm; far: PB = P | | 0C-0F, 10-13, 14-17 | JMP EQ/GE/MI | jz/jc/js | the same if Z / C / N | | 18-1B | JMP VS | - | if V (C10) | | 1C-1F | WAIT | finish ext_dta | wait for the bus access to finish (U10) | | 20-23 | ??? | - | none | | 24-27 | SKIP V/C/Z/N | skip ?/c/z/s | bits 9-8 select the flag; bit 0 = the value that skips; skips one word (C10 for flag 0) | | 28-3B | JSR, JSR EQ/GE/MI/VS | call/callz/callc/calls/- | push, then as JMP | | 3C-3F | RTS | ret | pull | | 40-43 | INC MAR | inc ext_ptr | MAR + 1 | | 48-4B, 4C-4F | CMPR A<