# Validation ladder (proposed) Written 2026-11-12 for the build that follows Phase 0. The rungs 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; 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**, as the seed's tests do. - **Each rung must be able to fail.** Before a rung is called passed, break the model on purpose in ways that rung should catch (swap the noise taps, change the register length, drop the reset on a noise write, shift the volume table one step, ignore a data byte) and see it fail. The count of faults caught goes in the README beside the rung. What the ladder cannot do is in the last section. Read it before claiming anything. ## Rung 0: the contract with the boards Not a judge of the chip; it keeps the core usable. - The names and calls in [api.md](api.md) exist and behave as it says: one `(left, right)` pair per `CLOCKS_PER_SAMPLE` input clocks, levels 0.0 to 4.0. - `run(a)` then `run(b)` gives the same samples as `run(a + b)`, for any split. - State is plain attributes; a state copied out and back continues identically. - An instance has fewer than 80 attributes (PyPy turns a larger one into a dict). **Exit**: all pass on CPython and PyPy 3.11. ## Rung 1: captures from hardware that are in hand There is exactly one: John Kortink's white-noise sequence from a BBC Micro (S9, `reference/kortink/white_noise.bin`, 32,767 bits), with his account of how he took it. - `SN76489AN` white noise, run from a noise-register write for 32,767 shifts, equals the capture as a rotation, in one polarity. State in the test which rotation and which polarity matched: the capture cannot fix either (U5, U7). - The wiki's two files (S8) are the same data and add nothing, but the seed's test on them can stay as a cross-check that the pinned files are what Phase 0 analysed. **Proves**: the discrete variant's register length, taps and sequence, against a real TI chip. **Does not prove**: anything about Sega's parts, the reset alignment, or that an SG-1000's SN76489AN matches a BBC Micro's chip. **Exit**: 32,767 of 32,767 bits. ## Rung 2: the manufacturers' documents Every check is a row of a printed table or a sentence, cited by document and page. - Register address field, all eight codes (S1 Table 4, S4 section 3). - Two-byte tone load and one-byte attenuation and noise loads (S1 section 6, S3). - The latched register persists across data bytes (S1 section 4). - f = N / (32 n): all 51 rows of the Game Gear manual's note table (S4 `psg-6`), to the three decimals printed; the 440 Hz worked example (S4 `psg-2`: n = 254, 440.397 Hz). - n = 1 gives N / 32 (S4 `psg-7`: "Maximum frequency is n = 1"). - 50 % duty on tones (S4 section 4). - Attenuation: 16 rows, 0 to 28 dB and OFF (S3, S4 `psg-3`); the weights 2, 4, 8, 16 add (S1 Table 1). - Noise shift rates N/512, N/1024, N/2048 (S1 Table 3 as corrected by S2; S4). - Noise rate 11 follows tone 2's output: one shift per full cycle (S1 block diagram, S4 `psg-4`). - Sega variants, synchronous noise: one pulse in 16, 6.25 % duty; all 33 rows of the manual's synchronous-noise table (S4 `psg-8`), for example n = 428, 16.335 Hz. - A noise-register write clears the shift register (S1, S4). - Game Gear stereo: each of the eight bits routes the channel and side S4 `main-4` names; $FF after power-on; no effect on the other variants. - Game Gear silent after power-on (S4 `psg-1`). **Proves**: the model does what TI and Sega told programmers it does. **Does not prove**: anything the manuals leave out, which is most of what is contested. **Exit**: every row passes; each listed fault is caught. ## Rung 3: community documents checked on hardware - S6's four worked write sequences and its table of Tone0 after each byte. - A data byte reaches the attenuation register and the noise register on Sega's parts (S6, with the two games it names as the symptom). - Tone registers take effect on the latch byte alone (S6). - Sega white noise: 16 stages, taps 0 and 3, reset to the top bit; period 57,337 (S6's rule; the period is arithmetic on that rule, not a measurement). - Every noise write restarts the register, even an unchanged value (S6, S24). - The discrete chip is not silent at power-on (S10), in whatever form decision D5 takes. - The Mega Drive's test override (S15), in whatever form decision D7 takes. **Proves**: agreement with the best public account of Sega's part. **Does not prove**: that account. Its captures are unpublished and its one published "Sega" file is not Sega's (C9). **Exit**: all pass, and each test's docstring says "tier 3". ## Rung 4: recordings from a real console (none exist yet) This is the rung that would turn most of the unknowns into measurements. It is empty today. Nothing in hand is a recording of any Sega PSG. What exists: S13 and S23 are test ROMs made for exactly this comparison, but they show no verdict and nobody's recording of them is in hand. The owner has an early Genesis with a flash cartridge; its PSG is the `YM7101_PSG` variant, and by S6's account its noise matches the Master System's. No Master System, Game Gear or SG-1000 is available. The proposed method is Kortink's (S9), which needs only a line input: play the thing under test with a second channel as a visible clock, record, threshold, and read the bits or levels off against the clock. A probe program for the Genesis would play, each after a spoken-length gap and a sync burst: | Probe | Settles | |---|---| | White noise at rate 11 over tone 2 at a low, steady value, tone 2 audible | U3 (the sequence), U6 (which edge) | | The same after noise writes placed at stepped delays | U7 | | Periodic noise the same way | 16 stages on this part, at tier 1 | | One tone at each of the 16 attenuations | U4 for this console | | A channel at full volume with tone value 0, then 1, then 2, then a low tone | U1, C1 (levels and any ultrasonic leak) | | First write after power-on is a data byte, then each attenuation raised in turn | U14 | | Nothing written for two seconds after power-on | U12 | | A tone rewritten at stepped delays within its cycle | U11 | | The test override on, for each source channel | U15 | The analysis script and the recordings' hashes would live in `validation/`; the recordings themselves stay out of git. **Proves**: behaviour of one Mega Drive's PSG, at tier 1. **Does not prove**: the discrete chip (U2, U8, U13 need an SG-1000, SC-3000 or a bare SN76489AN), absolute polarity (U5), or sub-tick write timing (U9). **Exit**: each probe's result is written into spec.md as "measured", with the recording's hash; the model matches each, or the difference is listed as open. ## Rung 5: reference models as closed-box detectors Under restart.md rule 8. A model here is a **detector**: a difference says where to look and proves nothing by itself. Nothing is fetched or built in Phase 0. ### Candidate models | Model | Licence | Variants it claims | May its source be read? | |---|---|---|---| | Nuked-PSG | GPL or LGPL (restart.md rule 1; confirm from its licence file when fetched) | The Mega Drive VDP's PSG | **No.** Run only | | MAME `sn76496` device | BSD-3-Clause (S19, header read) | SN76489, SN76489A, Sega PSG, Game Gear PSG and others | Yes: it is permissive and was read in Phase 0 | | emu76489 | MIT (S20, licence read) | Sega's part | Yes; it follows S6 and MAME, so it is a weak, dependent witness | | emu-russia SEGAChips `PSG.v`, simulated | CC0-1.0 (S16) | The Mega Drive VDP's PSG, traced from the die | Waits on decision D1. It can be *run* under rule 8's conditions without being read | | Gearsystem, BlastEm (their PSG parts) | GPL-3 as restart.md lists them | Sega's part | **No.** Run only, and only if the first three leave a question open | Genesis Plus GX is not proposed: restart.md rule 8 covers GPL and LGPL models, and that one is under a non-commercial licence. See decision D9. ### The harness - Lives in `validation/`. It is the only code that touches a model. Nothing built from a model is committed or shipped. - For a model whose source may not be read, it is written from the model's public header alone: the calls to create the chip, clock it, write a byte and read the output. The model's `.c` files are not opened, searched or quoted, by a person or by a tool, including when a comparison fails. - **What it feeds**: a *stream*, a list of `(input-clock time, port, byte)`. Two kinds: 1. Synthetic streams written here, one per spec statement: every register code; every attenuation; tone values 0, 1, 2, 3, $3FF; each noise mode and rate; noise rate 11 across tone 2 values 0, 1, 2 and a large one; a noise write at each of 256 consecutive clock offsets; a tone rewrite at each offset within a cycle; a data byte as the first write after reset; every stereo mask. 2. Streams exported from the boards while real games run, kept in the git-ignored `validation/streams/`. - **What it compares**: the output level at every tick (every 16 input clocks), ours against the model's, after two normalisations stated in the report: scale (each model's full-volume single channel is called 1.0) and polarity. Where a model exposes per-channel outputs through its header those are compared separately, which localises a difference to a channel. - **What it reports**: for each stream, the first tick that differs, the registers at that moment, and how many ticks differ in all. For the offset sweeps, a table of offset against delay, which characterises U7, U9 and U11 as that model sees them. - **What happens on a difference**: look for the answer in phase0.md's documents and in rung 4's recordings, and in more measurements of the model's *outputs*. If nothing above tier 5 settles it, write it into spec.md as open, with what each model does. Two models agreeing is not a source. **Proves**: where our model and others part ways. **Does not prove**: who is right. **Exit**: every stream either matches or has a written entry in spec.md; the README names each model that was run and says its code was not read. ## Rung 6: emulators at the board level MAME running the same ROM as the board, audio compared by ear or by spectrum, as sms-python and megadrive-python already do for other things. The coarsest check and the last. **Exit**: no difference a listener can point to in the boards' smoke lists, or each one traced to a numbered unknown. ## What this ladder cannot establish - With rung 4 empty, **every statement about Sega's parts rests on tier 2 documents that leave out the contested points, and on tier 3 accounts whose data is not public**. The README must say so. No claim of exactness to a console is supported. - Sub-tick timing (U9) and power-on internals (U10) are not observable through a sound card, and a closed-box model's answer to them is only that model's opinion. - The discrete chip has one capture, from a BBC Micro. Nothing here is measured on an SG-1000 or SC-3000. --- # What was run (2026-11-12, the first build) Everything above is the plan as Phase 0 wrote it. This is what the build did, on PyPy 3.11, and what each run showed. Nothing here was run on CPython. ## Rungs 0 to 3: `python -m pytest -q`, 233 passed | Rung | File | Tests | Faults it notices, of 22 | |---|---|---|---| | 0 | `tests/test_contract.py` | 26 | 5 | | 1 | `tests/test_capture.py` | 4 | 5 | | 2 | `tests/test_manuals.py` | 126 | 13 | | 3 | `tests/test_community.py` | 41 | 13 | | provisional and chosen behaviours | `tests/test_provisional.py` | 36 | 16 | `validation/faults.py` makes 22 copies of the package, each with one thing broken, and runs the suite against each. All 22 are noticed by at least one file. Four are noticed only by `test_provisional.py`: the discrete chip's tone value 0, the register latched at power-on, a new tone value restarting the count, and the test override being ignored. That is as it should be: no document above tier 5 speaks to those, so no rung can judge them. ### Rung 1, as found `SN76489AN` white noise, from a noise write, for 32,767 shifts: **32,767 of 32,767 bits equal Kortink's capture**, with two things the capture cannot fix and the test therefore states rather than proves: - **Polarity**: the capture is the inverse of the model's bit, as Kortink's own rule says ("the inverse of new_value[0]"). - **Rotation**: the model's first bit after the write's first shift falls at index 20,863 of the capture, counting from 0. Kortink gives the skew as 20,862. The other polarity matches at no rotation. The comparison runs in two forms: by the capture's SHA-256 (always) and bit for bit against the file (when fetched). The wiki's two files (S8) were checked as well: the one labelled "Sega VDP" is the model's discrete sequence rotated by one place, the other the same inverted and rotated. ### Rung 2, one finding **The Game Gear manual's note table was computed from 3,579,550 Hz**, not from the 3.579545 MHz the manual states. With 3,579,550 the formula reproduces 50 of the 51 printed values on rounding (the 51st, n = 170, is 658.0055 printed as 658.005); with 3,579,545 only 17. The plan above said "to the three decimals printed", which cannot hold at the stated clock. The test checks what the model owes the manual, the division itself (a cycle of exactly 32n clocks, for all 51 rows), then that the frequency is within 0.004 Hz of print at the stated clock and within 0.00055 Hz at 3,579,550. The 33 rows of the synchronous-noise table agree to three decimals at either clock. ### The seed's tests | Seed test | Here | Standing | |---|---|---| | `test_white_noise_periods` | `test_capture.py` (32,767), `test_community.py` (57,337) | kept, split by judge | | `test_periodic_noise_is_the_register_width` | `test_manuals.py`, `test_community.py` | kept, read off the output | | `test_discrete_noise_matches_the_wikis_bit_pattern` | `test_capture.py` | kept as a cross-check; **corrected** by one place of rotation, because this core gives the stage at the output end after the shift (spec 6.2.5, 6.4.3) where the seed gave the bit shifted out. Its judge is now Kortink's file | | `test_tone_latch_then_data_byte` | `test_manuals.py` | kept | | `test_data_byte_after_a_volume_latch_sets_the_volume` | `test_community.py` | kept | | `test_data_byte_after_a_noise_latch_is_not_ignored` | `test_community.py` | kept | | `test_power_up_is_silent_with_zeroed_registers` | `test_community.py` | kept for Sega's parts; the discrete chip now powers on sounding (spec 10.4) | | `test_volume_table_is_two_decibels_per_step_and_fifteen_is_silent` | `test_manuals.py` | kept | | `test_tone_register_0x0fe_is_440_hz` | `test_manuals.py` | kept, widened to the manual's 51 rows | | `test_tone_register_zero_or_one_holds_the_output_high` | `test_manuals.py` (value 1), `test_provisional.py` (value 0) | **corrected**: value 1 is a square wave (spec 5.5, Sega's manual); value 0 behaves as 1 on Sega's parts (D3) and is 1,024 on the discrete chip (D4) | | `test_noise_rate_three_follows_tone_two` | `test_manuals.py` | rate kept; **corrected** to the third tone's output as the clock (spec 6.1.4), not a counter of its own | | `test_stereo_register_only_exists_on_the_game_gear` | `test_manuals.py` | kept | | `test_game_gear_stereo_routes_each_channel` | `test_manuals.py` | kept, widened to all eight bits; levels are now 0.0 to 4.0 | | `test_one_second_gives_the_sample_rate` | `test_contract.py` | **replaced**: the core gives one level per 16 clocks and the boards resample (spec 4.3) | | `test_samples_write_as_a_stereo_wav` | none | **dropped**: it tested sms-python's WAV writer, not the chip | ## Rung 4: not run No recording of a Sega console exists here. Decision D8 is deferred: the owner's Genesis has a broken controller port. The probe table above stands as written. ## Rung 5: Nuked-PSG as a closed box `python validation/closed_box.py --sweeps` (about 30 seconds). Nuked-PSG at commit `d15a168`, GPL-2.0-or-later, "Yamaha YM7101 PSG emulator" by its README. It is compared with `YM7101_PSG` only. **Its source was not read.** The harness was written from the declarations in `ympsg.h`. That header also declares the model's state structure, so the names of its fields were seen; the harness does not use them and no part of the core was shaped by them. When comparisons failed, the answers below were found by feeding the model more streams and looking at its output. Every statement about "the model" here is an observation of its output. Normalisations, all measured from the output: one `YMPSG_Clock` call is one input clock; the model is run 7 clocks before each stream so that its tone edges fall on the core's tick boundaries (it also ignores writes in its first 5 clocks, and one of two writes with no clock between them); the model's sixteen levels are given to the core as its volume table so that waveforms can be compared. **51 streams. 19 are identical at every tick.** 24 more are identical once three timing behaviours are applied to the core (`validation/as_observed.py`, a stand-in used only for this measurement). 8 are left over: the four test-override streams, and four random streams that contain one transition the stand-in does not follow. ### Where the core and the model agree All of these at every tick of their streams: - Silent at power-on, nothing written (4,000 ticks). - A data byte as the first write goes to the first tone value: the model agrees with `power_on_latch = 0` (D6, U14), against MAME's register 3. - Tone values 0, 1, 2, 3, 4 and $3FF. **Value 0 behaves as value 1, toggling every tick**: the model agrees with D3 (U1), against Maxim's constant +1. - Every attenuation on each tone channel (as waveform; the levels differ, below). - Noise controls 000, 001, 010, 100, 101, 110 for 30,000 ticks each: the fixed rates, 16 stages, the white-noise sequence of taps 0 and 3, periodic noise, and the set bit reaching the output 15 shifts after a noise write (C5: a plain register). This is agreement with a model whose author may have used the same community account; it is not a capture of a console. - Data bytes to an attenuation register. - The starting phase of the tone flip-flops and of the noise divider, **after the core's starting state was changed to the seed's** (flip-flops set) on seeing that the first comparison was inverted. It is a choice with no source (U10), and the claim is only that the two start alike. ### Where they differ | | Difference | Size | Do the documents explain it? | |---|---|---|---| | 1 | **Volume curve.** The model's levels for attenuations 0 to 15 are 1, 0.772, 0.622, 0.485, 0.382, 0.290, 0.229, 0.174, 0.132, 0.096, 0.072, 0.051, 0.034, 0.019, 0.009, 0: steps that grow from 2.2 dB to 6.5 dB, 40.9 dB down at step 14 where the ideal curve is 28 dB down | up to 13 dB at the quiet end | No. Sega's manuals print 2 dB steps; S12 says the Mega Drive shows "the proper 2dB step gapping", without numbers. Open: U4. The core keeps the ideal table (D11) and the model's numbers are not shipped | | 2 | **A tone value governs the half-cycle in progress** in the model: the half-cycle ends when the ticks it has lasted reach the value in force, at once if they already have. The core finishes the half-cycle on the old value | Rewriting 47 to 33 at 36 ticks in: the half-cycle lasts 47 ticks in the core, 37 in the model. 33 to 47: 33 against 47 | No. Maxim's wording is a down counter reloaded at zero (spec 5.1, 5.4), and so is TI's for its own chip. No source tests it. Open: U11 | | 3 | **A write to a tone value or to the noise control reaches the model's generators one tick later** than the core applies it. After a noise write the model's output keeps its old bit for one more tick, and a shift on that tick is lost to the restart | one tick (16 clocks) | No source speaks to it. Open: U7, U9 | | 4 | **At noise rate 3 the model shifts one tick after the third tone rises**; the core shifts on the tick it rises. Both shift on the rising edge, so the core's choice for U6 agrees | one tick | No. The manuals say the tone's output is the clock, not when within a tick. Open: U6 | | 5 | The fixed-rate noise divider behaves as in difference 2 when the rate changes | up to one divider period | As 2 | | 6 | **Leaving noise rate 3 for a fixed rate**: the model's first shifts afterwards fall at a different phase from the core's and from the stand-in's. Seventeen accounts of what the divider does during rate 3 were tried against the output; the best fitted 29 of 60 trials | within one divider period, once per transition | Not characterised. The core's own rule here (the divider stands still during rate 3) is a choice. Open | | 7 | **Test override.** With bit 9 of its test input set the model's output is a held level: the chosen channel's volume level minus 3.177 (in units where one channel at full volume is 1.0). The core gives four times the chosen channel's level. Both are constant, follow the chosen channel's attenuation and ignore the square waves; bits 11-10 choose the channel in both, and no other bit of the 16 changes the model's output | a factor of four in the size of the level steps, and an offset | Partly. Plutiedev's paragraph gives the bits and "replaced with the volume level of one of them"; it does not say whether one level or four are heard. Open: U15. The core keeps the literal reading (D7) | | 8 | **Sub-tick write timing.** Over 64 consecutive clocks: an attenuation write in the last clock of the core's tick, or a noise write in its last five, can count for the tick after in the model. Tone writes showed no such window | under one tick | No source. Open: U9 | Differences 2 to 5 together account for every tick of every stream outside the test bits and transition 6: the stand-in with those behaviours equals the model on 43 streams, including four random streams of up to 400 writes each (about 75,000 ticks apiece). **The core was not changed to match the model** in any of these. Two things were taken from running it, both said above: the starting phase (a choice either way), and the confidence that D3 and D6 are at least not contradicted by it. ## MAME's `sn76496` device: read, not run Two attempts to run `mame sg1000` headless with a hand-made cartridge of PSG writes stopped before emulation on a slot error ("Unknown slot option"), and the attempt was dropped: the device cannot be driven outside a machine without more work than a short run. Its source is BSD-3-Clause and was read (S19). From the source, the core differs from it in these ways: | | MAME | The core | Spec | |---|---|---|---| | Register latched at power-on, Sega parts | 3 | 0 | C8, U14 (D6) | | Noise rate 3 | a counter of its own, period twice the tone value | clocked by the third tone's output | C4 | | Noise bit after a noise write | keeps the old bit until the first shift | the register's last stage: 0 at once | U7 | | Discrete chip (its SN76489A), bit arrival after a noise write | two shifts later than a plain register | plain register | C5 | | Discrete chip at power-on, noise | shifts every tick until the register is written | rate 0 | U13 | | Starting flip-flops | clear, rising on the first tick | set, falling on the first tick | U10 | | Polarity | negated for Sega's parts | unsigned levels | C7, U5 | It agrees with the core on the write protocol, tone values 0 and 1 on Sega's parts, 1,024 on TI's, the taps and lengths, the reset on every noise write, a new tone value waiting for the next reload, the 2 dB table, the stereo bits and the 32-clock READY time. ## Rung 6: not run Board-level comparison is the boards' job, after adoption. ## What can be claimed after this build Exactly the sentence the hand-off allowed: the core does what the manufacturers' manuals and SMS Power's research say, and its discrete-chip noise matches one capture from a BBC Micro. In addition, as observations and not as proof: a closed-box model of the Mega Drive's part agrees with it on steady tones and fixed-rate noise and differs in the eight ways listed.