# Provenance Audited 2026-11-13 (provenance audit, wave 1) against the family's licence rules (emulator-lineage `docs/charter.md`, "Licences and provenance"). Method: every comment and docstring in `src/`, the tests, scripts and docs; the whole git history (12 commits, including the gameboy-python commits the APU was extracted with); gameboy-python's records of how the APU was written (`docs/validation.md`, milestones 4 and 7, "Copyleft clean-up"); and `provenance_check.py` (pcengine-python) run against **SameBoy's `Core/`** only, because SameBoy is Expat-licensed and reading it is gameboy-python's documented practice: python3 -I pcengine-python/scripts/provenance_check.py --repo gb-apu-python \ --reference gameboy-python/reference/src/SameBoy/Core It reported `apu.c` (7 code runs, 2 tables): the NR43 clock-select glitch (our lines on `old_bit`/`glitch_bit`/`new_bit` against `apu.c` around line 1388) and the read-mask table. No GPL source (Gambatte, NanoBoyAdvance, mooneye-gb, giibiiadvance) and no MPL source (mGBA) was opened for this audit. Verdicts: **clean** (own work from facts or permissive sources, cited), **cite** (clean, but a source must be named or a notice kept), **rewrite** (derived from code we may not take), **unclear** (what would settle it is said). ## The code | Piece | Where its behaviour came from | Source licence | Verdict | | --- | --- | --- | --- | | Register map, `READ_MASKS`, `DUTY`, `NOISE_DIVISORS`, NR52, PCM12/34 | Pan Docs `Audio_Registers.md` (the read masks match SameBoy's table too: they are the hardware's) | CC0 | clean | | DMG channels: lengths and the extra length clock, the DMG sweep (`_trigger_sweep`, `_clock_sweep`, the negate-then-clear rule), the DMG noise LFSR, the wave channel, the frame sequencer steps | Pan Docs `Audio_details.md` / Obscure Behaviour, held by blargg `dmg_sound` 12/12 (hardware-verified) | CC0; blargg's ROMs run as tests | clean | | `WAVE_TRIGGER_DELAY`, `WAVE_WINDOW`, `CORRUPT_LO/HI` | FITTED to blargg `dmg_sound` 09, 10, 12, and labelled so | (measurement) | clean | | DMG wave-trigger corruption (`_trigger_wave_corruption`) | Pan Docs' description; the age window fitted | CC0 | clean | | `HPF_CHARGE` and the high-pass | Pan Docs `Audio_details.md` (0.999958, quoted as a number) | CC0 | clean | | The mixer (`_mix`, `_sample`) | own labelled fit (DAC mapping, NR50/NR51) | own | clean | | `skip_boot` register values | Pan Docs `Power_Up_Sequence.md` table | CC0 | clean | | CGB register differences (length counters on power-off, wave RAM while playing, no trigger corruption) | blargg `cgb_sound` 08-12 verdicts, Pan Docs | CC0 / tests | clean | | `Envelope` (3-bit countdown, secondary-edge reload, lock) and its NRx2 "zombie" write glitches, DMG and CGB forms | **SameBoy `Core/apu.c`** (`GB_envelope_clock_t`, `_nrx2_glitch`, `nrx2_glitch`): same names (`should_lock`, `locked`), same structure, translated; measured by SameSuite | Expat (MIT) | **cite**: Expat notice now kept in the module header (added 2026-11-13) | | Pulse channels in 2 MHz ticks (`lf_div`, `delay`, `suppressed`, `did_tick`, `just_reloaded`, the CGB D/E phantom step, the NRx4 frequency-change undo) | **SameBoy `apu.c`** (`GB_apu_run`, NRx4 write), translated; SameSuite 63/63 | Expat | **cite** (as above) | | CGB sweep (`_sweep_calculation`, `_sweep_done`, `_sweep_restart`, `_write_nr10`, `_run_sweep`, `restart_hold`, `unshifted`) | **SameBoy `apu.c`**, translated | Expat | **cite** (as above) | | CGB noise (14-bit counter, `_noise_start` alignment table, `background_active`, `_write_nr43` glitch) | **SameBoy `apu.c`**, translated (provenance_check code hit); only the deterministic variants kept | Expat | **cite** (as above) | | `WAVE_POWER_ON` (16 bytes, "84 40 43 AA ...") | cites "Pan Docs; the board's skip-boot state", but **Pan Docs does not hold these bytes** (checked: not in `pandocs/src`, not in SameBoy's `Core/`), and nothing in gameboy-python's records names the source. It arrived in gameboy-python b696e68 (milestone 4, 2026-10-09) | unknown | **unclear**: settle by finding a hardware read-out (a DMG unit's power-on wave RAM, published in prose) or replace with a value from a permissive source; power-on wave RAM is per-unit noise, so any recorded unit's bytes would do | | AGB row (`wave_banks`, `_shift_wave`, `_other_bank`, the 75 % force, `READ_MASKS_AGB`) | GBATEK "GBA Sound Channel 3" (prose, quoted in gba-python); followed where mGBA and NanoBoyAdvance differ | GBATEK: free to read (facts) | **unclear**: docs/contract.md describes mGBA's `src/gb/audio.c` (MPL-2.0) and NanoBoyAdvance's (GPL-3.0) behaviour in detail, so both sources were open during the work (commit 25a3891, 2026-11-11). The code follows GBATEK against both on the one point where they differ, and is a few lines of ring rotation, so nothing points to copying; but the rule is that GPL source is not open while writing the code it informs. Settle by a short clean-room rewrite of these four pieces from GBATEK alone, compared against the current code and the seam tests | | `audible()` | the Gambatte test suite's `_outaudio0/1` file-name convention; gameboy-python's record says it is "my reading of Gambatte's audio criterion ... not the testrunner's code" | test ROMs GPL-2, run closed-box | **cite**: reword the docstring to cite the test suite's naming convention and the 76/87 verdicts it is held by, not "Gambatte's criterion" (gameboy-python had `testrunner.cpp` open in that period, see its "Copyleft clean-up"; the predicate is four lines of generic logic) | ## Tests, scripts, data | Item | Verdict | | --- | --- | | `tests/test_apu.py`, `scripts/mutation.py`, `scripts/export_board_streams.py` | clean (own) | | `tests/streams/*.json.gz`: the calls gameboy-python's board made into the APU while running blargg `dmg_sound`/`cgb_sound` (no licence file) and SameSuite `apu/` (X11). Register traffic, digital outputs and sample hashes, no ROM bytes | clean (an I/O trace of a closed-box run, not the ROMs' code); note blargg's tests carry no licence | ## History Nothing from a GPL source appears in or was removed from this repository's history (searched every commit for Gambatte, mGBA, NanoBoyAdvance, higan/bsnes, giibiiadvance, "copied", "transcribed"). The only Gambatte mentions are the `audible()` docstring and the `_outaudio` validation row. The SameBoy translation entered at gameboy-python 5b5e154 (2026-10-21) and is in the public history without the Expat notice until 2026-11-13; the notice is now kept, which is what Expat asks of current copies. ## Owed - SPDX headers (family-wide pass): `src/gb_apu_python/__init__.py` should read `SPDX-License-Identifier: MIT` with the SameBoy Expat notice beside it (already there). - The two **unclear** items above, and the `audible()` docstring rewording. - The README "Credits" already names SameBoy; it could say "translated from SameBoy's `apu.c` (Expat)" rather than "SameBoy's model". ## Re-audit of 2026-11-25 (the pass families.md names as owed) **Method.** The audit above, repeated on `main` at f573f32 (= GitHub's `main`) by the method of emulator-lineage `docs/provenance-audit-2026-11.md`: every outside source the code and docs cite or fetch, checked against emulator-lineage `docs/sources.md`; the history of every ref (13 commits; messages, added and deleted paths, licence texts, file-and-line citations); the LICENSE file, SPDX headers and notices. No GPL or MPL source was opened, and SameBoy's source was not re-read: judged from this repository's own code, docs and history. **Sources against sources.md.** | Source | Use here | sources.md | Verdict | | --- | --- | --- | --- | | SameBoy `Core/apu.c` (Lior Halphon) at `c458e7c` | the CGB-family timing, translated | Expat, code OK (with notice) | **cite**: notice in the module header since 2026-11-13; SPDX line now `MIT AND Expat` with the source named on the next line; NOTICE.md (new) | | Pan Docs | registers, masks, DMG rules, the high-pass constant, skip-boot values | CC0, code OK | **clean** | | blargg `dmg_sound`, `cgb_sound` | judges (through gameboy-python), register traffic in `tests/streams/` | free to use, fetched as evidence, not shipped | **clean** (I/O traces, no ROM bytes) | | SameSuite (LIJI) | judges, as above | the Game Boy suites' row (mostly MIT; SameSuite X11 per the 2026-11-13 audit) | **clean** | | Gambatte test suite (`_outaudio` ROMs) | judges through gameboy-python; `audible()` reads their file-name convention | Gambatte GPL-2.0, closed box only; its test ROMs' names and pictures are the judge | **clean**: the docstring now cites the suite's file-name convention, not "Gambatte's criterion" (owed by the audit above, done 2026-11-25) | | GBATEK ("GBA Sound Channel 3") | the AGB row | facts only | **clean** as a source; the AGB row stays **unclear** (below) | | mGBA (MPL-2.0), NanoBoyAdvance (GPL-3.0) | `docs/contract.md` and the README described what each does on the AGB's wave banks, read in their source when the row was written (25a3891's session, 2026-11-11) | both closed box only | **cite (fixed 2026-11-25)**: the description of their internals (a source file and identifier of mGBA's, how each keeps the bank) taken out of contract.md and the README; the account stays here. validation.md's line on gba-python comparing whole sound output with NanoBoyAdvance is a closed-box comparison and stays | **Code verdicts now.** As in the table above, with the `audible()` docstring done: clean 9 (plus the two rows of tests and data), cite 4 (the four SameBoy-translated pieces, notice in place), rewrite 0, **unclear 2**: - `WAVE_POWER_ON`: still no source. Its comment no longer cites Pan Docs, which does not hold the bytes; it says the source is unknown (HYPOTHESIS as to source). The value is unchanged. - The AGB row (`wave_banks`, `_shift_wave`, `_other_bank`, the 75 % force, `READ_MASKS_AGB`): written from GBATEK while mGBA's (MPL-2.0) and NanoBoyAdvance's (GPL-3.0) sources were open. Unchanged; see the findings. **History.** One branch (`main`), 13 commits, the first seven gameboy-python's (the APU's extraction, 2026-10-07..11-06). No third-party file, GPL or MPL licence text, or file-and-line citation of GPL code was ever added or deleted; the surname clean-up (wave D, 2026-11-22) is in place. Two things the public history keeps, both prose, not code: the SameBoy translation without its notice before f573f32 (recorded above; the notice is what Expat asks of current copies), and the description of mGBA's and NanoBoyAdvance's AGB wave-bank internals in `docs/contract.md` and the README from 9c0cb8e to f573f32 (a file path and an identifier of mGBA's and one sentence on each; no quoted code). **Licence files and headers.** LICENSE (MIT) present. SPDX headers added 2026-11-25 to all six code, test, script and CI files (0 missing now): `MIT` on five; `MIT AND Expat` on `src/gb_apu_python/__init__.py`, the form methodology.md gives for a file holding permissively licensed code, with the source and its notice named on the second line. NOTICE.md added (SameBoy's notice; credits). **Findings for Aubrey:** 1. **The AGB row is behaviour written with MPL and GPL source open** (the pattern of the audit's section 2, "re-establish, then restate"). Nothing points to copying (a few lines of ring rotation; the code follows GBATEK against both where they differ), but by the charter it wants a short clean-room rewrite of the four pieces from GBATEK alone, by a session that sees neither source nor the current code, compared against the seam tests and the seeded faults. Proposed, not done: it is a code change in a public specification with Rust tiers below it (gb-apu-rust, gb-apu-rust-fast) and gba-python as a user. 2. **`WAVE_POWER_ON`** wants a source: a published read-out of a real DMG's power-on wave RAM, or a permissive source's bytes with its notice. Power-on wave RAM differs per unit, so any recorded unit would do; until then it is a value of unknown origin. 3. **The SPDX form `MIT AND Expat`.** SPDX's licence list has no `Expat` identifier (Expat is SPDX `MIT`), so tools reading the first line may not parse it. methodology.md names this form, so it is used; the alternative is `MIT` with the second line, or `LicenseRef-Expat`. A policy call. 4. The public history's AGB description (above): prose about other emulators' internals, no code. A filter-repo pass for it alone seems out of proportion; recorded, Aubrey's call. 5. Downstream: gb-apu-rust and gb-apu-rust-fast transcribe these comments; the docstring and comment changes here (no behaviour change) travel down at their next repin. gb-apu-rust's `src/lib.rs` has the Expat notice but no SPDX line (not audited in this pass). ## Clean-room rewrite of the AGB row (2026-11-25, branch `cleanroom-agb-wave`) Aubrey approved the rewrite the re-audit proposed (finding 1). It replaces the AGB row written in 25a3891 (2026-11-11; 9c0cb8e on `main` after the history rewrite), with mGBA's and NanoBoyAdvance's sources open, by `src/gb_apu_python/agb.py`, written from GBATEK alone. **Source.** GBATEK, Martin Korth, "Extracted from no$gba version 3.06", fetched 2026-11-25 from problemkaputt.de into the git-ignored `reference/gbatek/` (`gbatek.txt` sha256 `ba503864b2201973db4fbeb4d98b4394b19417820a6e6b9f6014fa73ce52845c`, the same file as gba-python's `reference/docs/gbatek.txt`; `gbatek.htm` sha256 `919ca0deac2fe11ecc4eda95fd95157772dd72e2ad69fff61bdbaa9fb53121c8`). Sections read: "GBA Sound Controller", "GBA Sound Channel 3 - Wave Output" (SOUND3CNT_L, SOUND3CNT_H, SOUND3CNT_X, WAVE_RAM), "GBA Sound Control Registers" (SOUNDCNT_X), "GBA Comparison of CGB and GBA Sound". sources.md: facts only, cite section and version; done in agb.py's comments (DOC tags). **What the writer read.** The rest of this repository: the module with every AGB-specific line and block blanked by a script before it was shown (the `_other_bank` and `_shift_wave` bodies, each `if self.wave_banks` block, the AGB comments, `READ_MASKS_AGB`'s comment), the README, validation.md, contract.md outside "The AGB row", the names of the tests and of the seeded faults. `grep -n` for the AGB names showed their call sites, and with them a few lines whole: the `Model` field and the `AGB` row, `self._read_masks = READ_MASKS_AGB if ...`, the docstring fragments of `_other_bank`, `_shift_wave`, `wave_quarters`, `wave_digit`, `volumes`, the `APUState.wave_ram` comment, `self.wave_digits = bytearray(64)`, and the one-line `READ_MASKS_AGB` definition (`0x1F, 0xFF, 0x1F` for NR30-NR32). The masks in `agb_read_masks` were then derived from GBATEK's bit tables, and come out the same. Later, after agb.py was written and while gb-apu-rust was being prepared, a `grep -n` there for the same names printed five body lines of gb-apu-rust's transcription of the old code (its `read_wave`/`write_wave` AGB branches index a 64-entry digit array from `other_bank()`, and `shift_wave` opens with a borrow of it); the Python design was settled by then, and the Rust carries agb.py down. **What the writer did not read.** The bodies of `_other_bank`, `_shift_wave` and the AGB branches in `_read_wave`, `_write_wave`, `_tick_wave`, `wave_quarters` and `_wave_bytes`; the diff of 25a3891 / 9c0cb8e; the old "The AGB row" section of contract.md; the AGB seeded faults' texts; gb-apu-rust's and gb-apu-rust-fast's AGB code; mGBA and NanoBoyAdvance in any form. The old code was replaced by line number, by a script checked against the visible lines around each block, so its text was never printed. The AGB seam tests' bodies were read only after agb.py was written, when one of them failed. **Black-box comparison.** The old module, run unread from `main`, and the new one on the same probes (power-on contents, play order in each NR30 mode, the CPU's view after 1-65 digits, writes while playing, restarts, bank and dimension changes while playing, NR30 bit 7 off and on, NR52 off, every NR32 volume, every register's read-back): the same play order in every mode, the same 32-digit behaviour, volumes, force bit, read masks and power-on zeros. They differ in one model choice and what follows from it: - **64-digit mode.** The old row shifted both banks as one 64-digit ring, so the bank the CPU reaches moved while the other one played. The new one keeps a ring per bank, and only the playing bank moves: DOC, GBATEK "GBA Sound Channel 3", WAVE_RAM: "the entire 128 bits are shifted", which is one bank (32 x 4 bits). GBATEK does not describe the two banks as one register; that a bank not playing stands still is HYPOTHESIS. - **What follows.** After a restart (NR34 bit 7, or NR30 bit 7 off and on) part way through 64-digit mode, the new row plays the selected bank's own digits first (DOC: "output will start by replaying the currently selected bank"); the old one carried on from where its ring stood, in the other bank's digits. Turning NR30 bit 5 on or off while the channel plays, and the CPU's view after NR52 is turned off part way, differ the same way. The play order is what music hears, and it agrees; the differences are what a program sees reading wave RAM in 64-digit mode, and what a restart part way through plays. No hardware test settles either reading. **Tests.** `test_agb_wave_ram_is_a_shift_register_the_cpu_sees_move` held the old 64-digit reading in its first three asserts and failed on the new code; GBATEK does not give that behaviour, so the asserts were rewritten to the new reading, with the old one named in a comment. The rest of it, and the other six AGB tests, pass unchanged: they agree with the GBATEK reading independently (one-bank play from the selected bank's first digit, 64-digit order, the CPU reaching the bank not selected, the force bit and its read-back, NR30's bits). Added: `test_agb_a_restart_plays_the_selected_bank_again`. The nine AGB seeded faults, whose texts named the old code, are replaced by ten against agb.py (`scripts/mutation.py` now takes a file per mutant). Results on the branch: seam tests 25 of 25 (24 before, all passing then too; one of them rewritten as above, one added); board streams 94 of 94 (as before: they are DMG and CGB); the ten AGB faults and the four wave-channel faults beside them 14 of 14 caught (one-stream gate; the full 31-fault run was not repeated, to spare a shared machine). The AGB branch of `_tick_wave` shares the channel's period loop, so the "wave period at 1 MHz" fault reaches it too. **Verdict now.** The AGB row: **clean** (own work from GBATEK, cited, HYPOTHESIS where GBATEK is silent). The old code stays in the history (9c0cb8e..7805b5a), as the charter's "re-establish, then restate" allows.