# Hand-off brief: building the core For the session that writes the code. Written 2026-11-12 at the end of Phase 0. ## Read first, in this order 1. [restart.md](restart.md): the rules. They bind you as they bound Phase 0. 2. [api.md](api.md): what the boards call. 3. [phase0.md](phase0.md): the sources, what was read and how, what was not. 4. [spec.md](spec.md): the behaviour, statement by statement, with C and U numbers. 5. [validation.md](validation.md): the ladder. 6. `seed/psg.py` and `seed/test_psg.py`. Then run `python scripts/fetch_references.py --local`. It fetches the pinned references into the git-ignored `reference/` and checks the files cited in place from sms-python and megadrive-python. Add `--large` only if decision D2 allows the die photograph. ## What is not to be opened Unchanged from Phase 0: `/data/backup/nuked-derived/`; any Nuked source wherever a copy sits; Genesis Plus GX, Gearsystem, openMSX, BlastEm, jt89; megadrive-python's `src` audio and PSG code; descriptions of chip internals in megadrive-python's and sms-python's documents. Two more, until the owner decides: the netlist files of emu-russia's SEGAChips (D1) and the annotated die photograph (D2). When a comparison against a model fails, the model's source stays closed (rule 8). ## Scope A pure-Python model of four variants (spec.md section 1), exact to the tick (one level per 16 input clocks), offering the API in api.md. Analogue behaviour after the mixer (filters, sag, a console's flattened volume steps, the Game Gear's mono speaker) is the boards'. READY stalls on the SG-1000 are the board's; the core can export the 32-clock figure. Not in scope: the other TI and clone parts (SN76489 without the A, SN76494, SN76496 as a discrete part, NCR 8496, T6W28). The variant record should not make them hard to add, and nothing more. ## Package shape - Repository `sn76489-python`, package `sn76489_python`, under `src/`. - One module for the chip, one for the variant table, tests under `tests/`. No subclass per variant: a variant is a frozen dataclass value, as in the seed. - Exports exactly what api.md lists: `SN76489`, `PSGVariant`, `CLOCKS_PER_SAMPLE`, `SN76489AN`, `SEGA_VDP_PSG`, `GAME_GEAR_PSG`, `YM7101_PSG`. - State as plain attributes (numbers, lists); sms-python's save states walk them. Keep an instance under 80 attributes for PyPy. - Python floor 3.11, the newest PyPy supports. CI, if any, PyPy only. - MIT. The README says which documents each behaviour comes from, which reference models were run, and that their code was not read. If any line of S19 or S20 is ever ported, its notice comes with it; Phase 0 ported nothing. - `validation/` holds the harness for rung 5 and the analysis for rung 4. `validation/streams/` and `reference/` stay out of git. The variant record needs at least: shift register length; white-noise taps; whether there is a stereo register; whether the part is reset at power-on and to what; what a tone value of 0 means; whether the test override exists. Each field's docstring names its source and its standing (documented, measured, unsettled). ## What to take from the seed Take the write protocol, the variant-as-data shape, the counter and shift-register logic, the volume table and the stereo routing; spec.md section 14 lists where it already agrees. Change the seven things listed there under "Where the seed differs", and give every item under "What the seed does that no source supports" either a source or the word "choice". Keep the seed's tests, moved to the new package and re-anchored: the noise test should name Kortink's capture (S9) as its judge. `seed/` stays as it is until the new package passes everything the seed's tests check; then it can go, by a commit that says so. ## The ladder | Rung | Judge | State today | |---|---|---| | 0 | The API contract | to write | | 1 | Kortink's capture of a BBC Micro's chip (S9) | data in hand | | 2 | TI's and Sega's manuals (S1 to S5) | documents in hand | | 3 | Maxim's page and the other community accounts (S6, S7, S10, S15) | documents in hand | | 4 | Recordings from a real console | **none exist**: D8 | | 5 | Reference models run as closed boxes | nothing fetched: D1, D9 | | 6 | Emulators at board level | the boards' job | Rungs 0 to 3 can be built and passed with what is in hand. They support this claim and no larger one: *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.* ## Unknowns and contradictions In full in spec.md sections 12 and 13. The ones that change what a player hears: - **U1, C1, C2**: tone values 0 and 1 on Sega's parts. Decides how loud sampled speech and drums are beside ordinary tones (a factor of two). - **U2, C3**: tone value 0 on the discrete chip. - **U3, C9**: Sega's white-noise sequence has no capture in hand. - **C4**: noise at rate 11 clocked from tone 2's output, not from a counter of its own. The steady sound is the same; the phase against tone 2 is not. - **U4**: no measured volume curve for any Sega part. - **U13**: the discrete chip's sound at a cold start. The ones a player will not hear but a test will see: U5 to U12, U14, U15. Build every unsettled behaviour as variant data or a clearly named switch, so that a measurement later changes a value and not the structure. ## Open decisions for Aubrey **D1. The traced netlist of the Mega Drive's PSG (emu-russia SEGAChips, CC0).** The licence allows reading it. It was not opened: its topology page credits the cell map to the author of the Nuked models, whose view of AI use is not known here, and a netlist of this exact circuit is as close to a blueprint as a source gets. Options: read it as a tier-1 document; run it in a Verilog simulator as a closed box under rule 8's conditions; leave it alone. *Recommendation*: run it, do not read it. It would be the strongest detector for the Mega Drive variant, and the core stays written from prose. If the author's wishes can be learned, revisit. **D2. The annotated SN76489A die photograph (gchiasso), marked CC BY-NC.** One reduced view was seen while looking for its licence. It would bear on the discrete chip's register length, counter reload and reset. *Recommendation*: treat non-commercial as restart.md treats Genesis Plus GX and leave it unread, unless you rule that a photograph with labels is a measurement and not a work to be licensed. The spec does not need it today. **D3. Tone values 0 and 1 on Sega's parts until a recording exists (C1, C2).** *Recommendation*: value 1 toggles every tick (Sega's manual says n = 1 is the top note). Value 0 behaves as value 1, as MAME's hardware-tested note has it. Both are variant data. This halves the level of sample playback against the seed and against Maxim's "constant +1"; say so in the README and settle it by D8. **D4. Tone value 0 on the discrete chip (C3, sms-python open item 3).** *Recommendation*: 1,024, marked "tier 5, consistent with TI's description of the counter", in place of the seed's constant. **D5. The discrete chip at power-on.** It is not reset (S10). MAME's rendering is all four channels at full volume with a period of 1,024, a low beep until the program writes. *Recommendation*: model that as the variant's power-on state, with a board option to start silent. An SG-1000 that beeps for a moment at switch-on is what the hardware did. **D6. The register latched at power-on on Sega's parts (C8).** Maxim's 2003 text says tone 0; MAME says the second tone channel's attenuation, crediting a hardware test. *Recommendation*: tone 0, as the seed has it, marked unsettled. Neither source publishes its test, the two MAME comments disagree with each other about which register is meant, and no known program depends on it. D8 can settle it in one probe. **D7. `write_test` for the Mega Drive.** The only source is one paragraph on Plutiedev (spec.md section 11). *Recommendation*: keep the method, implement that paragraph literally (bit 9 enables, bits 11-10 choose the channel whose attenuation level replaces all four outputs), mark it tier 3 and untested, and make it exist only on `YM7101_PSG`. **D8. Recordings from the early Genesis.** Rung 4 is empty, and one afternoon with the Genesis, the flash cartridge and a line input would settle U1, U3, U4, U6, U7, U11, U12, U14 and U15 for the Mega Drive's part at tier 1 (validation.md lists the probes). Another session owns the console suite. *Recommendation*: yes. Ask that session to add a PSG probe program; the analysis script belongs here. Nothing else available can raise the Sega variants above tier 3. **D9. Which models to run in rung 5.** *Recommendation*: Nuked-PSG (run only), MAME's device, and SEGAChips' netlist if D1 allows. Not Genesis Plus GX: rule 8 names GPL and LGPL models, and that one is non-commercial. Say if rule 8 should cover it. **D10. Sega's Game Gear manual is stamped "CONFIDENTIAL" and "PROPERTY OF SEGA".** It is the best manufacturer source for Sega's part (16-stage noise, n = 1, stereo, power-on) and already sits in sms-python's references, from SMS Power. *Recommendation*: keep citing it and quoting single sentences; do not copy its tables or pages into this repository. The tests carry the numbers they check, with the page named. **D11. Per-console volume curves.** *Recommendation*: the core ships the ideal 2 dB table only. A console's measured curve, when one exists, is a table the board passes in. No numbers are in hand. **D12. The noise files on SMS Power are mislabelled (C9).** Both downloads are Kortink's BBC Micro data; none is Sega's. *Recommendation*: you decide whether to tell Maxim, and in whose voice. SMS Power's stance on AI-written posts was not checked. **D13. The live SMS Power page was not reachable** (a time-out, then HTTP 503), so the snapshot in sms-python was not compared with the current page. *Recommendation*: the build session tries again before relying on S6. ## Decisions taken (2026-11-12) The owner does not rule on chip-level questions; where a source cannot settle one, the builder takes the recommendation above, marks the behaviour **provisional** in the code and in the spec with the source's tier, and keeps it as variant data so a later measurement changes one value. As decided: | | Decision | | --- | --- | | D1 | The traced netlist may be **run** as a closed box under rule 8, never read. Not needed for the first build. | | D2 | The non-commercial die photograph stays unread. | | D3 | Sega parts: tone value 1 toggles every tick; value 0 behaves as value 1. Provisional. | | D4 | Discrete chip: tone value 0 is a period of 1,024. Provisional (emulator tier). | | D5 | Discrete chip: not reset at power-on; the variant powers up as the sources describe, and a board may ask for a silent start. Provisional. | | D6 | Sega parts latch tone 0 at power-on. Provisional. | | D7 | `write_test` exists only on the Mega Drive variant and follows the one published paragraph. Provisional, untested. | | D8 | **Deferred.** The owner's Genesis has a broken controller port; no recordings until it is repaired. Rung 4 stays empty and the README says so. | | D9 | Models run as detectors: Nuked-PSG (run only) and MAME's device. Genesis Plus GX is not run. | | D10 | Sega's manuals are cited and quoted a sentence at a time; no tables or pages are copied. | | D11 | The core ships the ideal 2 dB table; a measured curve is a table a board passes in. | | D12 | Nothing is posted to SMS Power for now. | | D13 | The build session tries the live SMS Power page again before relying on the snapshot. | D3 changes what is heard: sample playback through the PSG is quieter than with the seed. The README states it as provisional.