# Handoff brief: building ym2610-python For the agent who builds the core. Read [start-here.md](start-here.md) first, then this, then the specification documents it names. The restart's rules ([restart.md](restart.md)) bind every step. ## Scope - The plain **YM2610 (OPNB)**: four keyable FM channels, SSG, ADPCM-A (six channels), ADPCM-B, the bus, status, timers, /IRQ, BUSY and the serial output. A reference core: correct and readable, not fast. - Out of scope: the YM2610B (decision 6: deferred, its model input never driven), the YM3016's floating conversion and the analogue mix (decision 4: the board's), any I/O ports (the chip has none). ## Names and boundary - Repository `ym2610-python`, package `ym2610_python`, MIT. Python at the family's PyPy floor (3.11); standard library only. - No imports from other family cores (`ym2612_python`, `ay8910_python`, `msm6295_python`); decision 1 keeps this core self-contained. - No code from any model: nothing from YM2608-LLE, YM2203-LLE or Nuked-OPN2 is read; the closed box is a judge and a measuring instrument only. - A module holding a table or formula taken from ymfm or Geolith starts with `# SPDX-License-Identifier: MIT AND BSD-3-Clause` and a line naming the source file and pin; NOTICE already carries both notices. - Every rule in the code names its evidence tag and citation, as the specification does. ## Sockets (proposed, provisional) | Socket | Shape | Source | | --- | --- | --- | | clock | `run(clocks)` in phi M clocks; one output sample per 144 | clocking-and-output.md | | bus | `write(port, value)`, `read(port)`, port = A1 A0 (0-3) | registers.md | | ADPCM ROMs | `read_adpcm_a(address) -> byte`, `read_adpcm_b(address) -> byte`, 24-bit addresses, called on the clock the chip latches each byte | decision 3 | | serial output | per sample: L and R as signed 16-bit values (the offset-binary words minus $8000) | clocking-and-output.md | | SSG output | three 5-bit codes per channel; `ssg_mix()` with a replaceable 32-entry table, default the closed box's | ssg.md, decision 5 | | status lines | `irq` (the /IRQ pin pulled), `busy` | registers.md | | debug | the multiplexed ROM-bus pins as an optional trace | decision 3 | | state | save and load of everything above | family rule | | variant | `column0_keyable = False` | decision 6 | ## Board contract The board (neogeo-python first) supplies the 8 MHz clock and the CPU's accesses with their timing; serves the two ROM spaces (on most Neo Geo games the same V ROM, on 13 parents a separate ADPCM-B ROM: [users-and-census.md](users-and-census.md)); honours BUSY or the manual's waits; turns the serial words into sound through its YM3016 model (decision 4) and mixes the SSG pin; wires /IRQ to its CPU. ## Output contract One (L, R) pair per 144 clocks, bit-exact with the closed box except at the listed departures; SSG codes at the SSG's own steps. Anything else the core emits is a debug aid. ## Contradictions (where sources disagree) | | Subject | Sides | Core follows | Doc | | --- | --- | --- | --- | --- | | C1 | timer periods | OPNA 72/1152 x; closed box, ymfm 144/2304 x | closed box | clocking-and-output.md | | C2 | $1C's part | AM, ymfm, Geolith, SNK's driver: part I; closed box: part II | the manual (decision 2); harness translates | registers.md | | C3 | write waits, BUSY | AM 17/83; OPNA 0 for SSG/ADPCM; closed box ~192 for every data write (writes during BUSY land); ymfm 192; writes lost if too soon: HYPOTHESIS, was the wiki's (U1) | closed box, provisional | registers.md | | C4 | ADPCM-A index and delta | Dialogic +2 +4 +6 +8, term-wise; closed box and ymfm +2 +5 +7 +9, single truncation | closed box | adpcm-a.md | | C5 | ADPCM-A $08-$0D at reset | AM and closed box $00; ymfm $DF | AM | registers.md | | C6 | re-key with the end flag set | silent: HYPOTHESIS, was the wiki's (set aside); closed box plays | closed box | adpcm-a.md | | C7 | ADPCM-B rate formula | ajworld "/256"; OPNA, closed box 2^16 | 2^16 | adpcm-b.md | | C8 | ADPCM-B output scaling | ymfm (x level) >> 9; closed box multiples of 4, zero for alternating streams | closed box, via the rung | adpcm-b.md | | C9 | LFO rates | manual and ymfm; closed box ~25 % faster at rate 7 | manual, provisional (U6) | fm.md | | C10 | CH2 mode F-numbers | the wiki (set aside 2026-11-26, no standing source); OPNA and closed box | OPNA | fm.md | | C11 | slot order | AM's table; OPNA, closed box | OPNA | fm.md | | C12 | $27 = $80 | ymfm and OPNA: separate F-numbers; closed box: not | open (U8) | fm.md | A difference from the closed box is written down, not fixed, unless a document or hardware says the core is wrong (rule 6). C2 and C5 are such departures. ## Unknowns | | Unknown | Experiment | | --- | --- | --- | | U1 | real BUSY length; are writes lost while busy | logic analyser on a Neo Geo, or a homebrew test with timed writes and read-back of SSG registers | | U2 | ADPCM-B output rounding, the zero for alternating streams | probe sweep of bytes, levels, delta-N; fit | | U3 | ADPCM-B repeat and RESET | probe with REPEAT set across two ends | | U4 | the ROM buses beyond RMPX's 72 clocks; ADPCM-A latency by phase and channel; re-key while playing | needs the header's pin list (owner's word), then a ROM-serving driver | | U5 | power-on state before /IC; what /IC does to FM and SSG registers | probe: run without /IC, then read SSG and listen to FM | | U6 | LFO periods exactly | finer probe: per-sample envelope of a slow carrier | | U7 | FM envelope increments, attack 62/63, feedback averaging, SSG-EG | FM rung's sweeps against the closed box | | U8 | timer load timing, CSM, $27 = $80 | probe: CSM key-on by timer A; the mode bits one by one | | U9 | which FORM level is binary on the YM3016; which level the Neo Geo ties FORM to (was the wiki's: VCC) | a legible YM3016 sheet hosted elsewhere than the set-aside wiki (the 1990 catalogue's pp. 32-33 do not say); a Neo Geo schematic or board photograph | | U10 | clamping of the full FM + ADPCM sum | probe with all sources at full scale | | U11 | ADPCM flags and /IRQ; ADPCM-B flag cleared by $10; reads of $0E-$FF | probe | | U12 | SSG noise register and rate; all 16 envelope shapes | probe: noise sequence on the analogue pin; shapes | ## Rungs and gates Each rung's gate is a command that can fail; seeded faults prove it (methodology.md, "Gates"). Rung numbers follow the first brief's order. 0. **Tables from documents, ymfm with notice, and closed-box measurement.** The core computes log-sine and exponent from their closed forms, detune from the OPNA manual's Table 2-6, ADPCM-A steps as floor(16 x 1.1^n), ADPCM-B's factors from OPNA Table 5-1; it takes the EG increment table and the ADPCM-A increments from ymfm (with notice; the increments also OBSERVED); the SSG table from the closed box (OBSERVED); the LFO dividers from the manual's rates. Never from a model's lines. Gate: `pytest tests/test_rung0.py` reproducing `validation/check_tables.py`'s equalities from the core's own tables. 1. **Bus, registers, status, timers, BUSY, /IRQ, flag control.** Gate: the core and the closed box fed the same scripted accesses read the same status bytes at the same clocks (timers 144/2304; BUSY's window; $1C with the C2 translation). 2. **FM.** Gate: serial words identical to the closed box for FM-only streams (the sweeps in [siblings.md](siblings.md) step 3), departures listed. 3. **SSG.** Gate: per-channel 5-bit codes identical to the closed box's (inferred from the pin through the decision 5 table) for tone, noise and all envelope shapes. 4. **ADPCM-A and ADPCM-B.** Interim gate: constant-byte streams identical to the closed box (all 256 bytes, the level sweep, delta-N sweep). Full gate, once a ROM-serving driver exists (U4): real sample ROMs through both buses. 5. **Whole chip.** Gate: MAME register taps (`nam1975`, more per [mame-oracle.md](mame-oracle.md)) replayed with the game's ROMs from `MAME_ROMPATH` into core and closed box; serial words identical except at the listed departures. ## The decisions (docs/decisions.md) 1. **Rewritten 2026-11-19, awaiting the owner's confirmation:** self-contained, built from documents and permissive sources with the die model as a closed box (run as judge and instrument, never read); a shared OPN core only when a YM2203 or YM2608 is wanted. (The 2026-11-12 wording, "transcribed from the die-derived model", cannot stand under the GPL; the alternative is a GPL-2.0 core.) **OWNER TO CONFIRM.** 2. $1C: follow the manual, ymfm and SNK's driver (part I); record the departure; the harness translates. 3. ROM buses: byte callbacks with 24-bit addresses on the latching clock; pins as a debug trace. 4. The YM3016's conversion is the board's, from Yamaha's sheet. 5. SSG: the 5-bit codes are the contract; `ssg_mix()`'s default is the closed box's 32 values (OBSERVED, provisional); the catalogue alternative is not in the pinned catalogue. 6. YM2610B deferred; `column0_keyable` kept on the variant. Also carried: package name `ym2610_python`; referees built just before the rung that needs them; outside contacts deferred and sent by Aubrey from a draft; local through Phase 0, public after the first passing rung and a history audit.