# ym2612-python The Yamaha YM2612 and YM3438 (OPN2) FM sound chip as a readable pure-Python core for megadrive-python. No runtime dependencies. PyPy 3.11 is the supported interpreter. ```python from ym2612_python import YM2612, YM2612_DISCRETE fm = YM2612(YM2612_DISCRETE) # the model 1's discrete chip; YM3438_ASIC for later boards fm.write(0, 0x22) # address, part I fm.write(1, 0x00) # data fm.run(7_670_453) # one second of the chip's clock pin (NTSC) frames = fm.take_samples() # one (left, right) pair per 144 clocks ``` [docs/api.md](docs/api.md) is the whole surface; [docs/adoption.md](docs/adoption.md) says what megadrive-python must change to use it. ## Status (2026-11-13) **A restart, built from documents.** An earlier core under this name was a translation of a GPL/LGPL model and was withdrawn; [docs/restart.md](docs/restart.md) has the rules this one is written under. The code is written from [docs/spec.md](docs/spec.md), which is written from the sources in [docs/phase0.md](docs/phase0.md); [docs/provenance-audit.md](docs/provenance-audit.md) checked each statement against its source's prose before any code. Every rule in the code names its spec section, or says CHOICE or PROVISIONAL. What it supports, and no more: *the core does what Yamaha's and Sega's manuals say and what Nemesis and others report reading out of real chips; it steps once per sample and takes writes at sample boundaries.* **No measurement was made for it, and nothing is claimed exact to a console or to any other model.** The discrete chip's output stage (the "ladder") uses provisional constants. [docs/claims.md](docs/claims.md) lists each claim with its evidence; [docs/validation.md](docs/validation.md) says what was run and what it showed. - 186 tests pass on PyPy 3.11: the contract (12), published read-outs of real chips (64), the manuals (71), community statements checked on hardware (18), and the provisional decisions (21). - `validation/faults.py` breaks the core in 28 ways; every fault is noticed. - Nuked-OPN2 was run as a closed box and **its source was not read** (`validation/closed_box.py`). 9 of 55 streams agree on every channel with the same writes; the differences are written down as open, chiefly when a write is heard, and nothing was tuned to it. - About 9 times real time on PyPy with six channels sounding. - Local only: not pushed, not on PyPI, not adopted by the board yet. Yamaha's YM2612 application manual (S1) is a leaked confidential document; it is cited a sentence at a time and nothing from it is copied here. ## What is known, and how *documented*: a manual says so (tier 2). *measured*: someone read it out of a real chip or saw it at a pin, and said so in prose (tier 1). *community*: an author who tested on hardware (tier 3). *provisional*: no source above an emulator settles it; the value is a decision, labelled in the code and pinned by a test. Spec section numbers in brackets. | Behaviour | Standing | |---|---| | Register map, addressing, the address latch [2, 3] | documented; the shared latch measured | | Phase generator: detune, multiple, 17- and 20-bit wraps, key-on reset [5] | measured (Nemesis) and documented | | Operator: log-sine and exponent tables, output range, total level [6] | measured (the OPL read-outs, Nemesis) | | Envelope: rates, the every-third-sample clock, attack curve, SSG-EG [7] | measured; the step table and attack formula **provisional**, ymfm's (U21, U22) | | LFO: rates and depths [8] | documented; divider length and vibrato precision **provisional** (C14, C16) | | Algorithms, feedback, modulation paths [9] | documented; the delayed paths from a die reading, **provisional** (T4) | | Channel 3 special mode, CSM [10] | measured | | Timers, status, BUSY [11, 12] | measured; status addresses **provisional** (T3) | | DAC channel [13] | documented and measured | | Accumulator and panning [14] | measured; the upper limit **provisional** (T5) | | Output stage of the discrete chip [15] | the shape measured; the constants **provisional**, ymfm's (T10, U12) | | State after reset, test registers [16, 17] | **provisional** (T14, T8) | | When inside a sample a write lands [2.8, U1] | not modelled: writes are heard from the next sample (T9) | ## Layout - `src/ym2612_python/`: `chip.py`, `operator.py`, `tables.py`, `variant.py`. - `tests/`: `test_contract.py` (rung 0), `test_measured.py` (rung 1), `test_manuals.py` (rung 2), `test_community.py` (rung 4), `test_provisional.py`. - `validation/`: `faults.py`, `closed_box.py` and `nuked_harness.c` (rung 6). - `scripts/fetch_references.py`: the pinned references, into the git-ignored `reference/`. Nuked-OPN2 is fetched for the closed box only; its `.c` file is compiled and never opened. - `docs/build-status.md`: where the work stands, what was not read, and every slip from the rules. ```sh python -m pytest # all rungs python validation/faults.py # can each rung fail? python validation/closed_box.py # the closed-box comparison (needs a C compiler) ``` ## Licence MIT.