# Validation ladder **Where it stands, 2026-11-13:** | Rung | Judge | State | |---|---|---| | 0 | the contract with the board | passes (12 tests) | | 1 | digital values published from real chips | passes (64 tests) | | 2 | the manufacturers' documents | passes (71 tests) | | 3 | recordings from real consoles | not analysed | | 4 | community statements checked on hardware | passes (18 tests) | | 5 | ymfm run as a detector | not run (it is read, as S21) | | 6 | Nuked-OPN2 as a closed box | run; nine differences, all open (below) | | 7 | probes on a real console with the discrete YM2612 | empty: no probes have been run | | 8 | the board | megadrive-python uses the core; its comparisons are its own | Plus 21 tests pinning the provisional decisions. `validation/faults.py`: 28 faults, every one caught (rung 0 catches 2, rung 1 19, rung 2 12, rung 4 12, the provisional record 8), about 70 seconds. Not yet done: rung 3; rung 5 (its harness needs ymfm's `ymfm_adpcm.*` and `ymfm_ssg.*` fetched and pinned at `81aec25`); streams that break Yamaha's waits; the ladder fit against Aly James's recording. CPython 3.11 has not been tried. The rungs below were written on 2026-11-12, before the code, and are kept as written; the closed box's results are added under rung 6. They are ordered by how far their judge can be trusted, the best first. A lower rung never overrules a higher one. Source IDs are [phase0.md](phase0.md)'s; section, C and U numbers are [spec.md](spec.md)'s. Two things hold for every rung: - **Each check names its source in the test itself**: the document and page, or the post number. - **Each rung must be able to fail.** Before a rung is called passed, break the model on purpose in ways that rung should catch and see it fail. A starting list: drop the 17-bit wrap after detune; apply a high F-number byte at once; use the manual's timer formula of S1; make CSM act on mode 01; change the SSG-EG factor to 6; invert with an exclusive-or of $1FF instead of `$200 − x`; clamp decay to the sustain level; sum carriers before cutting to 9 bits; let the accumulator wrap; move a detune table entry; shift the envelope step pattern by one; make the attack curve linear. The count of faults caught goes in the README beside the rung. What the ladder cannot do is in the last section. ## Rung 0: the contract with the board Not a judge of the chip; it keeps the core usable. - The names and calls of the API in [api.md](api.md) exist and behave as it says: one output frame per 144 master clocks. - `run(a)` then `run(b)` gives the same samples, status and timer flags as `run(a + b)`, for any split. - State is plain attributes; a state copied out and back continues identically. - An instance, and each operator and channel record, has fewer than 80 attributes (PyPy turns a larger one into a dict). **Exit**: all pass on PyPy 3.11 and CPython 3.11 (PyPy only so far). ## Rung 1: digital values published from real chips The strongest judge in hand: numbers that were read out of a chip through its test register, or seen on an oscilloscope at its pin, and printed in a post. Each is a single fact, so this rung is a list of exact unit tests. - **Tables as data** (settles U18 first): the log-sine and exponent tables generated from S9's formulas, from S22's formulas and from S19's formulas (which are for the OPL family) are compared entry by entry with each other and with S21's printed tables. Any entry that differs is listed in the README; S9 wins, because it was read from this chip. - Phase increments (p6177): F-number $7FF, block 7 → $1FFC0; block 0 → $3FF; F-number $100, block 5, detune 3 → $100B; detune 7 → $FF5; F-number 0 with detune −1 → $1FFFF; F-number $1FF, block 4, multiple 8 → $7FC0; multiple 0 → $7FC; $1FFFF × 15 keeps 20 bits ($DFFF1). Block 0 loses the F-number's low bit. - F-number latch (p5621): the three writes $A6 = $1E, $A2 = $FF, $A6 = $24 leave the channel at $1E/$FF. - Operator range (p11876): one operator at full level spans −8168 to +8168; 8168 cut to 9 bits is +255 and −8168 is −256. - Envelope (p7967): from $3FF an attack at increment 8 reaches 0 in 10 updates; an attack rate of 62 or 63 at key-on gives attenuation 0 in the same sample; switching to 62 during an attack freezes it; a decay step that passes the sustain level is not cut back; a sustain-level write after decay has ended does nothing. - SSG-EG (p7967): inversion examples $001 → $1FF, $110 → $0F0, $250 → $3B0; with attack rate below 31 a looping pattern rests at $200 and the first attack step takes it to $1DF (p8037). (Two values listed here in the first draft, "$001F and not $1FE8" and "$0021 straight to 0", were struck by the provenance audit: they appear in no post's prose.) - Timers (p5680, p5687): the reload rules, one by one; Timer A at $3FF overflows every sample. - CSM (p7967): mode 10 only; one overflow gives a one-sample key-on; overflow every sample holds the key; a key held through $28 survives; leaving mode 10 releases. - Accumulator (p11876): carriers are cut to 9 bits before summing; two carriers at full level limit and do not wrap. - Output order (p7516): slot order 1, 5, 3, 2, 6, 4, if the core exposes slots. - BUSY (p31026, p31154): set by a data write only; clear 192 master clocks later. - Absent registers (p5680): $29, $2D to $2F and part II's $2x have no effect. **Proves**: the core reproduces every digital value its sources print. **Does not prove**: the many values nobody printed; in particular the full envelope step table and the LFO have only spot checks here. **Exit**: every listed value passes; each fault in the list above that touches this rung is caught. ## Rung 2: the manufacturers' documents Every check is a row of a printed table or a sentence, cited by document and page. - Register map, both parts, every field (S1, S2 pages 9 to 16). - Operator order 1, 3, 2, 4 in the register addresses; channel 3's extra frequency registers (S2 table 2.1, S4 table 2-2). - F-number formula: the twelve notes of S2's table at 8 MHz (page 24: 277.2 Hz → 654.0 ... 523.3 Hz → 1234.6) reproduce to the printed decimal; a played F-number gives the frequency back within the counter's resolution. - Key code: the manual's five sample rows of N3 and all 2,048 F-numbers against the formula. - Detune: all 96 non-zero entries of S2's table (page 25), in hertz at 7.9872 MHz, from the model's phase increments. - Multiple: 16 rows (S2 table 2.3). - Rate = 2R + Rks, R = 0 gives 0, limit 63, release doubling (S2 page 28); the key-scaling table's 128 entries (S2 table 2.6). - Total level 0.75 dB a step and sustain level 3 dB a step, as steady-state amplitude ratios (S2 tables; p11876's "8 steps halve" is the same check). - The eight algorithms: carriers and modulators (S2 figure 2.2), by silencing one operator at a time. - Feedback levels π/16 to 4π (S2 table 2.2): the peak modulation index of operator 1 on itself, measured from the model's phase input. - LFO: the eight rates within the tolerance that C14 leaves (the test states which divider the model uses and both expected values); tremolo depths 1.4, 5.9, 11.8 dB and vibrato depths ±3.4 to ±80 cents as peak deviations (S2 page 31). This settles U16 and U17 as far as documents can. - SSG-EG: the eight shapes of S2 figure 2.4 with the attack rate at 31, as envelope traces classified by shape. - Timers: S2's formulas and worked figures (18 µs to 18,432 µs; 288 µs units), not S1's (C1). - Status byte layout; BUSY in bit 7 (S1, S2). - DAC channel: offset binary, replaces channel 6, 8 bits (S2 page 15). - Total-level advice of S2 page 42: algorithms 0 to 3 at total level 0 never reach the limit; algorithm 7 with all four at 0 does. **Proves**: the model does what Yamaha told programmers it does. **Does not prove**: what the manuals leave out, which is everything about exact arithmetic. **Exit**: every row passes; where S1 and S2 disagree the test names the one followed and why. ## Rung 3: recordings from real consoles, in hand Audio that passed through a console's filter and amplifier at unknown gain. It can judge shape, timing and pitch, not level. The analysis scripts live in `validation/`; the recordings stay out of git and are named by hash. - **Nemesis's SSG-EG recording** (S13, `ssg-eg md1600.wav`, 96 kHz, PAL console): the model plays the same register sequence. Two ways to get the sequence, in order of preference: write it from the test's description in p5716 (eight patterns in turn); or log the writes of `ym2612ssg-eg.bin` running on megadrive-python (the ROM is data to a board, not source read here). Compare per pattern: the envelope's shape, the period of each repetition to the sample, the phase restart on patterns 08 and 0C. - **The attack-and-release recording** (S13, 180 MB, not yet unpacked): the same, for SSG-EG with an attack rate below 31. This is where spec 7.6.6 is tested against the thing itself: the burst between repetitions and its length. - **The CSM recording** (S13): pitch and repetition rate of the "fading, repeating A6 tone". - **Aly James's ladder recording** (S14): a tone walked down in level. The discrete variant must show a floor that stops falling and then cuts to silence; the YM3438 variant must not. This recording is what the provisional ladder constants are tuned against, with the tuning written down as a fit, not a measurement. - **MDFourier's FM blocks** (S16), on one board with the discrete chip and one with the ASIC: block-by-block spectra, after removing each board's frequency response as megadrive-python's fit already does. Judges gross errors in any of the 96 FM blocks and the discrete-versus-ASIC difference in quiet blocks. **Proves**: that envelope timing, SSG-EG and the presence of the ladder floor match real consoles within what a filtered recording shows. **Does not prove**: sample values, or anything about the console of rung 7. **Exit**: each comparison has a number and a tolerance written before the run; the README states each result and says "one recording, one console" beside it. ## Rung 4: community statements checked on hardware Prose rules without a printed value: each becomes a test that pins the rule. - The 9-bit address-and-part latch and either data port (p7673). - Key-on does not reset the attenuation (p7999); frequency, total level, detune, multiple, feedback and rates take effect at once (p5655, p5720, p7967). - Tremolo still applied with the LFO off, at its maximum (p7490, p16436). - Vibrato applied to the F-number before the block (p8905). - Modulation input is the output shifted right once; two feedback stores (p18814). - The delayed modulation paths of spec 9.6 (die reading). - Channel 6 keeps running under the DAC (p14109); $2C bit 3 is the ninth bit (p26996). - Write waits: a board-level statement; the core exports the three numbers. - The discrete variant has a mid-scale step and the YM3438 does not (S12, p12981): with the GManiac test of p12980 (one operator, total level $40 and $3F) the YM3438 variant gives the level sequences −1, 0 and −2 to +1. **Proves**: agreement with the best public accounts. **Exit**: all pass; each test's docstring gives the tier. ## Rung 5: permissive emulators, run and read ymfm (S21) and ares (S22) may be both read and run. They are emulators: a difference is a question, not a verdict. - A small C++ harness in `validation/` builds ymfm's YM2612 and YM3438 classes from the pinned files and feeds them the register streams of rung 6. ares's component is tied to its own framework; reading it against a failing case is enough. - Compare per-sample left and right outputs after undoing each side's output stage (ymfm averages six channels and scales; its ladder constants are its own). - Expected and acceptable differences, to be confirmed one by one: the delayed modulation paths (C11), the F-number latch (C12), vibrato precision (C16), sustain level 15 (C9), status addresses, data written through the other part's port (C13). **Proves**: that two independently written sample-level models agree wherever the spec gives them the same rule. **Exit**: every difference is traced to a numbered C or U item or fixed. ## Rung 6: Nuked-OPN2 as a closed-box detector Under restart.md rule 8. **Nothing was fetched or built in Phase 0.** A model here is a detector: a difference says where to look and proves nothing by itself. ### The harness - `scripts/fetch_references.py` gains pins for the model's repository at one commit: its licence file, its README, its one public header and its one `.c` file. The script's docstring says which files may be opened (licence, README, header) and that the `.c` file is compiled and never opened, searched or quoted, including when a comparison fails. Those pins were removed on 2026-11-24: the source is not fetched here any more (Aubrey, 2026-11-24), and the model is built only in emu-tools-gpl. - `nuked_harness.c`, written here (kept outside this repository since 2026-11-22 as a GPL tool; since 2026-11-24 nuked-harness's `opn2-stream` (built in emu-tools-gpl, run at `$EMU_TOOLS_GPL/tools/nuked/build/opn2-stream`)), includes the header and calls only what the header declares: create or reset a chip, select the chip type (the header is said to offer a discrete YM2612 mode and a YM3438 mode), write a byte to one of four ports, read a port, and advance by one clock, receiving the output of that clock. The harness is the only code that touches the model. Nothing built from the model is committed or shipped. - **Input**: a text stream of `(master clock, port, value)` writes and `(master clock, port)` reads. Three kinds: one synthetic stream per behaviour of spec sections 5 to 14 (written by hand, small); the write sequences of rung 3; and, later, streams exported from megadrive-python playing real music (`validation/streams/`, derived from ROMs and never committed). - **Write spacing**: every stream keeps Yamaha's waits (17, 83, 47 master clocks, spec 2.7) and places each data write early in a sample, so that the difference between a clock-level model and a sample-level core is not the first thing seen. A second pass deliberately breaks the waits, to map U1; its differences are recorded, not chased. - **Output**: the model produces a value per internal clock. The harness sums each channel slot's value over the 24 clocks of a sample, giving one left and right figure per sample, and also dumps the six slot values. Our core is asked for the same: the six 9-bit channel values per sample before its output stage, and the output after it. - **Alignment**: the two outputs are aligned once per stream by the first non-zero sample; a fixed offset of a sample or two between a clock-level and a sample-level model is expected and is stated, not hidden. ### What is compared, in order 1. The six channel values per sample, YM3438 mode against our YM3438 variant: the digital path with no ladder. Reported per stream as the count of samples equal, differing by one step, and differing by more. 2. Status reads: BUSY's length and the timer flags' timing. 3. The discrete mode against our YM2612 variant: the output stage. This is where the provisional ladder constants are confronted with a second opinion (U12). 4. The test registers, if decision T8 goes beyond $2C bit 3. ### When they differ The answer is sought in spec.md's sources, in the recordings, and in further measurements of the model's *outputs* (shorter streams, one register at a time, the slot dump). The model's source stays closed. If nothing settles it, the difference is written into spec.md as an open item naming the stream that shows it. A rule may not enter the core on the sole ground that it makes this rung pass: it needs a source from phase0.md, or the word "provisional" and the tier "closed-box observation". Rule 8 allows that last case, marked as a closed-box measurement: fitting a constant to a closed box is weaker than copying its code and stronger than having no number at all. For the ladder effect it may be the only number available until rung 7 exists. No constant in the core has been fitted this way. **Proves**: nothing by itself. **Shows**: where a clock-level, die-derived model and this core part ways. **Exit**: every stream has a result line in the README; every difference is either explained from an allowed source, fixed, or listed as open. ### Results, 2026-11-13 Run: Nuked-OPN2 (Nuke.YKT, LGPL-2.1-or-later), pinned as at `335747d78cb0abbc3b55b004e62dad9763140115` (not fetched into this repository since 2026-11-24, Aubrey; built in emu-tools-gpl at the same pin); its `ym3438.c` was compiled and not opened, and the state structure in its header was hidden when the header was read. `python validation/closed_box.py` and `--probes`, about 10 seconds. **Nothing in the core was changed because of this rung, and no constant was fitted to it.** How the harness turned out against the plan above (its docstring has the detail): one `OPN2_Clock` call is one internal clock, 24 to a sample, six slots of four; which slot is which channel was found by keying one channel at a time; a slot's four clocks summed and divided by three give a value comparable with the core's after its output stage; each channel of each stream is aligned by a whole number of samples (-2 to +8) chosen to give the most equal samples, and the lag is printed. **Two tables.** Table 1 gives both the same writes. Table 2 feeds the *core* each $28 write in two halves, operator 1's key bit one sample after the others, because the model hears operator 1's key one sample after operators 2 to 4 (probe 1). That changes the core's input, not the core, so that the rest of the digital path can be compared. It is labelled and not counted as evidence ([provenance.md](provenance.md), "The closed box and the core"). - Table 1: 9 of 55 streams identical on every channel; 276,578 of 388,113 channel samples equal. - Table 2: 12 of 55 identical; 361,827 of 388,113 equal. - Status reads: 154 of 160 equal in value and IRQ; BUSY set for 32 reads after a data write in both. | Stream | Channel samples | Equal, same writes | Equal, operator 1 keyed late | |---|---:|---:|---:| | dac | 47 | 47 | 47 | | tone | 2017 | 2017 | 2017 | | tone-channel-5 | 2017 | 2017 | 2017 | | total-levels | 2428 | 2407 | 2407 | | frequencies | 1906 | 1850 | 1850 | | detune-multiple | 5423 | 5050 | 5050 | | algorithm-0 | 1518 | 77 | 1515 | | algorithm-1 | 1518 | 47 | 1515 | | algorithm-2 | 1518 | 56 | 1516 | | algorithm-3 | 1518 | 51 | 1515 | | algorithm-4 | 1518 | 526 | 1517 | | algorithm-5 | 1518 | 266 | 1517 | | algorithm-6 | 1518 | 756 | 1518 | | algorithm-7 | 1518 | 708 | 1518 | | feedback | 3367 | 2650 | 2794 | | envelope-slow | 6118 | 6117 | 6117 | | envelope-fast | 6118 | 5874 | 5874 | | envelope-key-scale | 6118 | 5814 | 5814 | | envelope-sustain-15 | 6118 | 6117 | 6117 | | rate-changes | 2120 | 1314 | 1314 | | ssg-eg-0 | 6217 | 4882 | 4882 | | ssg-eg-1 | 6217 | 6217 | 6217 | | ssg-eg-2 | 6217 | 6214 | 6214 | | ssg-eg-3 | 6217 | 6216 | 6216 | | ssg-eg-4 | 6217 | 4830 | 4830 | | ssg-eg-5 | 6217 | 6217 | 6217 | | ssg-eg-6 | 6217 | 6214 | 6214 | | ssg-eg-7 | 6217 | 6216 | 6216 | | ssg-eg-0-slow-attack | 6217 | 6150 | 6150 | | ssg-eg-2-slow-attack | 6217 | 6003 | 6003 | | ssg-eg-6-slow-attack | 6217 | 6003 | 6003 | | tremolo-depth-3-rate-7 | 1287 | 58 | 58 | | tremolo-depth-1-rate-6 | 1671 | 234 | 234 | | tremolo-depth-2-rate-3 | 6019 | 1329 | 1329 | | tremolo-lfo-off | 1221 | 1212 | 1212 | | vibrato-depth-7-rate-7 | 1287 | 87 | 87 | | vibrato-depth-3-rate-6 | 1671 | 425 | 425 | | vibrato-depth-5-rate-2 | 6019 | 774 | 774 | | channel-3-mode-01 | 1223 | 267 | 1116 | | channel-3-mode-11 | 1223 | 267 | 1116 | | csm-3f0 | 2019 | 1892 | 1892 | | csm-3ff | 2019 | 2019 | 2019 | | f-number-latch | 831 | 828 | 828 | | other-data-port | 418 | 417 | 417 | | clip | 1516 | 1269 | 1516 | | pan | 1021 | 1013 | 1013 | | quiet-sine | 3016 | 3016 | 3016 | | mixed-1 | 48804 | 28940 | 48383 | | mixed-2 | 45390 | 25889 | 44730 | | mixed-3 | 51720 | 32369 | 48158 | | ym2612-dac | 282 | 279 | 279 | | ym2612-tone | 12102 | 12102 | 12102 | | ym2612-quiet-sine | 18096 | 18096 | 18096 | | ym2612-pan | 6126 | 5933 | 5933 | | ym2612-mixed-1 | 48804 | 28940 | 48383 | **Probes** (measurements of the model's output only): 1. Write timing (U1): the model hears a key-on 5, 4, 4, 4 samples after the core (operators 1 to 4), a total-level write 2, 2, 2, 1, a multiple write 3, 3, 3, 2. 2. LFO (C14): the six LFO streams run with the core's divider table swapped, in the harness process only, for the set one fewer (S21's and S22's). Equal samples rise on five of six (for example 58 to 632 of 1,287); vibrato depth 5 at rate 2 does not improve. **The core stays at the manual's dividers.** The manual's dividers follow from a document by arithmetic, and a closed-box measurement does not overrule a document (rule 8); this probe is labelled and not counted as evidence. 3. Fast envelope (U4): 244 differing samples in 110 runs of 1 to 9 samples, at envelope steps. **The nine differences, all OPEN** (none is settled by an allowed source): 1. **Write timing (U1).** The probe-1 delays. They explain most of table 1's differences and the few samples around every mid-note write. 2. **Accumulator (C8, U27).** With four carriers at different frequencies the model's peaks are lower than the core's clipped +255 (`channel-3-mode-01`, 107 of 1,223 samples). Consistent with limiting after each addition in the order 1, 3, 2, 4; the core sums, then limits. A change to follow the detector was considered and not made; the core is unchanged. 3. **Phase restart (U28).** At a CSM re-key over a sounding note, and in SSG-EG patterns 0 and 4, the model's waveform is one sample later than the core's relative to the envelope. The core follows Nemesis's note that the phase generator "effectively outputs the phase increment value" with the counter held at 0. 4. **CSM start (U29).** In `csm-3f0` the model's first key-on comes about a timer period before the core's. Not characterised. 5. **LFO dividers (C14).** Probe 2. 6. **Envelope steps (U3, U4).** `envelope-fast`: 244 of 6,118 differ, in short runs at envelope steps. 7. **The ladder (U12).** The model's slot is value + 4 or value - 3, as the core's (ymfm's) provisional constants: observed, not fitted. A muted slot in the model is +4 or -4 by the channel's sign; the core's is +4 always. On the DAC channel a sign change between consecutive samples differs by 2 steps for one sample. 8. **BUSY (U10).** The model's read at the write's own clock is not BUSY; the core's is. 9. **Not looked into:** `feedback` (573 of 3,367 differ), `rate-changes` (806 of 2,120), `mixed-3` channel 1 (3,394 of 8,620). ## Rung 7: new measurements from a real console (empty) No probes have been run on a console. On an early Mega Drive or Genesis with the discrete YM2612 and a flash cartridge, one probe program would settle more than everything else in this document, because the chip can report its own digital values: with $21 bit 6 set, a status read returns the operator's 14-bit output ($21 bit 7 choosing the byte), and with $2C bit 4 the 9-bit channel output (spec 17). A program can freeze the phase generator ($21 bit 3) to read the envelope alone, as Nemesis did. No audio equipment is needed for the digital probes: the program stores what it reads in the cartridge's save memory. | Probe | Settles | |---|---| | Envelope read-out at every rate, 0 to 63, for a few thousand updates | U15, U3, U4: the whole step table at tier 1, independent of any emulator's lineage (decision P2) | | LFO: tremolo read-out at each rate and depth | C14, U16, C15 | | Vibrato: phase read-out with F-numbers that have one bit set | C16, U17 | | Two-carrier and feedback patches, operator read-out per sample | C11, U7, C8 | | High byte for one channel, low byte for another | C12 | | Address through one part, data through the other, for a $2x and a $3x register | C13 | | Status read at all four addresses after a write, in a counted loop | C4, U10, BUSY's length on this chip | | Writes at stepped delays after an address, per register group | U1 | | Key-off and key-on one sample apart at attenuation 0 | U5 | | /IC cannot be driven by a program; a reset-button press during a held note, then read-out | part of U14 | | The DAC channel stepped through all 512 values ($2A with $2C bit 3), recorded from the line output at 96 kHz or better, with $2C bit 5 as a louder second pass | U12: the ladder as numbers, for this console | | A channel panned off, others silent, recorded | spec 14.4, 15.2.4 | The read-out results would be files of numbers with a hash, kept in `validation/`; spec.md's marks change from "unsettled" to "measured here" with the file named. The probe cartridge is a separate project; the analysis belongs here. **Proves**: one discrete YM2612, at tier 1, digitally. **Does not prove**: the YM3438 or the ASIC (no such console is available), or analogue levels beyond one console. ## Rung 8: emulators at board level megadrive-python's own comparisons (MAME, others): the board's job. What the board says about its FM output should be what these rungs measured, not sample-for-sample agreement with a die model. ## What this ladder cannot do - It cannot show the core equal to a chip at every clock. No allowed source describes the chip at that grain, and the core is not built at that grain. - Rungs 1, 2 and 4 check that the core follows its sources, not that the sources are right. Most of rung 1 rests on one researcher and one chip. - Rung 3 is filtered audio from consoles other than the one rung 7 would use. - Rungs 5 and 6 are emulators. Agreement with them is evidence only in proportion to their own sources, which for rung 6 this project may not inspect. - Until rung 7 exists, the discrete chip's output stage is a fit to one short recording and, if rule 8's measuring use is taken up, to a closed box. The claim rungs 0 to 4 support, and no larger one: *the core does what Yamaha's manuals and the published hardware measurements say, value for value where they print values, and its envelopes match three recordings of one PAL Mega Drive in shape and timing.*