# Provenance Where each part of this core's behaviour came from, the licence of that source, and a verdict. Written for the family's provenance audit (wave 1, 2026-11-13) against the rules in emulator-lineage's `docs/charter.md` ("Licences and provenance") and `docs/methodology.md` ("Provenance in practice"). 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 material we may not take), **unclear** (what would settle it). This repository has no remote: nothing here is public yet, so every finding below can be fixed in place (a history rewrite before the first push is an option, not a necessity). ## Summary The bus schedule is WDC's datasheet (Table 5-7, read literally), checked at volume against SingleStepTests (MIT). Phase 0 also read emulator sources, under a rule that then allowed reading GPL code "for facts"; the family no longer allows it. The result: one small piece of code taken from bsnes (the same code is published under ISC in ares, by the same authors), one test helper transcribed from MAME's BSD-3 g65816 core, and documentation that quotes GPL source (Mesen2, bsnes's GPL parts, MAME's SNES driver). Counts: 10 clean, 3 cite, 2 rewrite, 1 unclear. **A licence record to correct.** `scripts/pinned_repos.json` (since `1bef472`) and docs/validation.md say bsnes's `processor/` is ISC. bsnes's `LICENSE.txt` puts the whole program under GPL-3.0-or-later and lists only libco, nall, ruby and hiro under ISC. `processor/wdc65816` in bsnes is therefore GPL-3.0; the same component in ares (`ares/component/processor/wdc65816`) is ISC ("Copyright (c) 2004-2025 ares team, Near et al"). ## The core | # | Part | Behaviour from | Source licence | Verdict | | --- | --- | --- | --- | --- | | 1 | `_core.py`: registers, widths, every addressing mode cycle by cycle, emulation-mode wrapping | DS Table 5-7 and notes (WDC W65C816S, 2024-03-13), SST 65816; U3 `(d,x)` quirk from gilyon's cputest (MIT) with emulators as corroboration | manufacturer document; MIT | clean | | 2 | `_alu.py` decimal adder (`add`, `subtract`, 8 and 16 bits) | "the digit-by-digit adder below is bsnes's (`processor/wdc65816/algorithms.cpp`)", generalised into a loop; added in `5a12084` | GPL-3.0 in bsnes; the same algorithm is in ares `algorithms.cpp` under ISC | was **cite** (re-attribute to ares); Aubrey chose the rewrite instead: **clean** since 2026-11-25, written from Clark's *Decimal Mode* (6502.org, DOC) without reading the old body (see "Clean-room rewrite of item 2" below) | | 3 | `_alu.py` binary arithmetic, logic, compares, BIT/TSB/TRB | DS | facts | clean | | 4 | `_block.py` MVN/MVP | DS Table 5-7 rows 9a/9b; SST's 400 whole-move cases | facts; MIT | clean | | 5 | `_control.py`: interrupts, WAI/STP, WDM, ABORT, reset | DS; the 6502-python frame (MIT); two behaviours cited to bsnes's `processor/wdc65816` (WDM's operand is a program read; no poll at the end of an interrupt entry) | GPL-3.0 in bsnes, ISC in ares | **cite**: name ares (ISC) for both, or a non-emulator source | | 6 | `_loads.py`, `_shifts.py` | DS | facts | clean | | 7 | `_dispatch.py` opcode map and cycles | DS Tables 5-4 and 5-7 | facts | clean | | 8 | `cpu.py`, `harness.py`, `state.py`, tooling (`debug`, `console`, `disasm`, `trace`, `__main__`) | own work on 6502-python's frame and tooling hooks | MIT | clean | ## Tests, fixtures and scripts | # | Part | Source | Licence / terms | Verdict | | --- | --- | --- | --- | --- | | 9 | `scripts/datasheet_timing.py`, `tests/datasheet.py` | WDC Tables 5-4/5-7 transcribed | facts | clean | | 10 | SingleStepTests 65816 @ `307c63f5` (fetched, gitignored) | Thomas Harte | MIT | clean (detector) | | 11 | krom's CPU tests (PeterLemon/SNES @ `350b394e`), gilyon's cputest (`snes-tests` @ `5ecdf555`), undisbeliever's hardware tests (`snes-test-roms` @ `ac6ef800`), all fetched, never committed | test ROM authors | none stated (krom: run only); MIT; zlib | clean | | 12 | `tests/p65c816.py`, `tests/p65c816/tb_p65c816.vhd`, `scripts/build_referees.py`, `scripts/run_p65c816.py`: srg320's P65C816 VHDL (SNES_MiSTer @ `23026830`) analysed and simulated under GHDL | srg320 | GPL-3.0 (run only; the GPL units are fetched, never committed) | **unclear** (see Findings) | | 13 | `tests/mame_replay.py` `burst()`: MAME's `bus_5A22_cycle_burst`, added in `eb7831e` | MAME `src/devices/cpu/g65816/g65816.cpp` | BSD-3-Clause, Karl Stenerud | **cite**: done in this audit (notice line added to the docstring) | | 14 | `tests/mame_replay.py` `Replay.__init__`: WRAM filled with `$55`, with a quoted comment from MAME's `snes_m.cpp` (`eb7831e`) | MAME SNES driver | GPL-2.0+ (pin record) | **rewrite** (comment only; see Findings) | | 15 | `scripts/mame_trace.py` `IPL_SOURCE`: a 54-byte S-SMP boot ROM substitute | own SPC700 code written from the documented port protocol (not Nintendo's) | MIT | clean | ## Documentation | # | Part | Verdict | | --- | --- | --- | | 16 | Passages that quote or identify GPL source text: docs/undocumented-behavior.md C4 (a Mesen2 comment, "wrap around to start of previous page instead (cpu bug?)", and a bsnes comment) and U9 (a bsnes comment, quoted from `processor/wdc65816/memory.cpp`); docs/timing.md "Interrupt sampling" (Mesen2 `DetectNmiSignalEdge`, `ProcessCpuCycle`, `CheckForInterrupts` and a quoted comment; bsnes `status.irqLock` from `sfc/cpu`); docs/validation.md (bsnes `sfc/cpu/memory.cpp`, `dmaEdge()`, `timing.cpp` refresh positions; Mesen2 `GetDirectAddressIndirectWordWithPageWrap`; MAME `snes_m.cpp`); docs/start-here.md "The bus" (bsnes `sfc/cpu/memory.cpp`); docs/mame-oracle.md (bsnes `timing.cpp`, Mesen2 `SnesMemoryManager.cpp`). Most were written in `f609b79` and `c7875bb` | **rewrite** (documentation only; see Findings) | ## Findings **2 and 5: code from bsnes's `processor/wdc65816`.** The decimal adder is a restructured translation of bsnes's `algorithmADC8/16` and `SBC8/16`. The audit read ares's ISC copy of `algorithms.cpp` (permissive, allowed) and the algorithm there is the same. Recommended fix: change the citation to ares and keep the ISC notice beside the function: `ares component/processor/wdc65816/algorithms.cpp, ISC, Copyright (c) 2004-2025 ares team, Near et al` plus the ISC permission text. If Aubrey judges that code first taken from the GPL copy cannot be re-licensed by pointing at the ISC copy, rewrite it from the datasheet (which documents N, Z and C for valid BCD) and SingleStepTests' decimal cases, which already fix V and invalid-digit results. The two `_control.py` behaviours are facts (which cycle WDM reads, that an interrupt entry does not poll) checked by SST and gilyon's tests; naming ares or the test that shows them is enough. **12: the P65C816 testbench.** Running the GPL VHDL under GHDL is closed-box use, and the testbench only names the entity's ports. But its header describes the core's insides ("the bus pins are combinational from the core's microcode step, and it latches `D_IN` at the clock edge that ends the cycle"), which suggests the VHDL was read to write it. It is test tooling, never shipped with the core. What would settle it: confirm that knowledge came from simulation waveforms; otherwise state the testbench's licence as GPL-3.0 (a tool may carry the licence it owes, charter rule 6) or move it to a GPL tools directory. **Done 2026-11-22:** moved out (History, below). **14: MAME's power-on WRAM.** The value `$55` is a fact about MAME's behaviour and can be re-established closed box (dump WRAM in MAME's debugger at power-on). Remove the quoted driver comment. **16: documentation quoting GPL source.** No code in the core rests only on these passages: U9 is not implemented (Aubrey's decision: not in the core), C8's sampling point comes from 6502-python's frame (NESdev, visual6502), U3 is set by gilyon's tests, and the 5A22's cycle lengths and DRAM refresh are snes-python's, sourced there from fullsnes and the SNESdev wiki. Rewrite the passages to state each fact in our own words with a non-GPL source (fullsnes, SNESdev *Timing*, ares (ISC), undisbeliever's tests, MAME run as a closed box), and drop the Mesen2 and bsnes-`sfc` identifiers and quotes. Correct the bsnes licence note in `scripts/pinned_repos.json` and docs/validation.md as above. Mesen2's sparse checkout under `reference/src` should not be opened again; it can be removed from the pins. ## Citation fix made in this audit - `tests/mame_replay.py` `burst()`: added "Transcribed from MAME 0.285 `src/devices/cpu/g65816/g65816.cpp` (license: BSD-3-Clause; copyright-holders: Karl Stenerud)". - 2026-11-25: the BSD-3-Clause licence requires its notice, conditions and disclaimer to be kept with the source, which a docstring line does not do. `NOTICE.md` now carries the full text (as 65816-rust's NOTICE.md does for its transcription), and the file's SPDX line is `MIT AND BSD-3-Clause`. MAME's source was not opened for this: the holder and licence are those recorded above. ## How this was checked The repository's comments, docstrings, docs, `scripts/pinned_repos.json`, `pinned_files.json`, fetch and build scripts, and `git log --all -p` (18 commits; no third-party file was ever committed). bsnes's and ares's `LICENSE` files were read for their terms. `provenance_check.py` (pcengine-python) was run on 2026-11-13 with `--repo . --licences scripts/pinned_repos.json` against the permissive trees only: | `--reference` | Licence | Result | | --- | --- | --- | | `reference/src/ares/ares/component/processor/wdc65816` | ISC | 2 pairs: docs/undocumented-behavior.md quotes ares/bsnes comments (lines 102, 185; item 16); `tests/datasheet.py` mnemonic rows vs the disassembler's (alphabet of opcode names, no finding). No code hit; the decimal adder (item 2) is restructured, which this tool does not catch | | `reference/src/mame/src/devices/cpu/g65816` | BSD-3-Clause | 4 pairs: mnemonic lists (no finding); the datasheet quote in C4; the `burst()` table (item 13, now cited) | | `reference/src/CLK` | MIT | 0 | The audit also read ares's `algorithms.cpp` (ISC) to compare item 2. No GPL source was opened. ## Owed (not provenance breaches) - SPDX headers on each source file (charter rule 2). ## History On 2026-11-22 (the family's history clean-up, wave G) `tests/p65c816/tb_p65c816.vhd` left this repository and was removed from every commit with `git filter-repo`; every other change kept its commit. The testbench is elaborated with srg320's P65C816 (SNES_MiSTer, GPL), so by the family's rule of 2026-11-19 it is a GPL tool (finding 12 above). It is kept with the family's other GPL tools (emu-tools-gpl, `tools/65816-python`), and `scripts/build_referees.py p65c816-tb` finds it at its fixed path there, `$EMU_TOOLS_GPL/tools/65816-python/tb_p65c816.vhd` (one variable per tool repository, emu-tools `docs/contract.md` section 5, since 2026-11-24; the old `W65C816_GPL_TOOLS` is retired), and stops with status 3 when `EMU_TOOLS_GPL` is unset. Commit hashes cited from before that date refer to the old history, which is kept privately. ## Closed-box sources removed (2026-11-24) Aubrey's rule of 2026-11-24: an MIT repository does not download or keep the source of anything the family's `sources.md` marks closed box only. `scripts/pinned_repos.json` lost two pins, and their trees were moved aside unopened, out of the repository (not fetched; Aubrey, 2026-11-24), not deleted: - bsnes, https://github.com/bsnes-emu/bsnes @ `78474e5d39f58872dc21aca18cf9eb583b147fe7` (GPL-3.0-or-later, `processor/` included, as found above); - Mesen2, https://github.com/SourMesen/Mesen2 @ `b9fa69ddc6d0a331fb103fdb5eef6904305703c2` (GPL-3.0). Nothing built from either. Item 16's documentation rewrite was done with the move: the bsnes and Mesen2 identifiers, file paths and quoted comments left docs/undocumented-behavior.md, timing.md, start-here.md, mame-oracle.md, handoff-brief.md and validation.md, and each fact that rested only on reading their source is now marked HYPOTHESIS (for review) where it is stated; facts SST, gilyon's tests, ares (ISC) or the datasheet show are cited to those. Item 2 (`_alu.py`'s adder, cited to bsnes's `processor/`) awaits Aubrey's decision as above and is unchanged. **Kept, with a question for Aubrey:** SNES_MiSTer (GPL), pinned because `scripts/build_referees.py p65c816` builds srg320's P65C816 VHDL with GHDL for rung 5 and no shipped build exists. Its source is never opened. Whether that build (and the pin) should move to emu-tools-gpl beside the testbench is open. ## Clean-room rewrite of item 2 (2026-11-25) Aubrey approved rewriting `_alu.py`'s decimal adder on 2026-11-25 rather than re-attributing it to ares. Branch `cleanroom-decimal`. The process: - **Not read:** the bodies of the old `add` and `subtract` (binary and decimal paths alike, since they shared one function), their git history, 65816-rust's `alu.rs` bodies, and bsnes, higan and ares in any form (the fetched ares tree under `reference/src` was not opened). This document's Findings paragraph on items 2 and 5 was skipped too, since it describes the old adder. - **Read:** `_alu.py`'s module docstring, the callers (`_op_adc`, `_op_sbc`) and the rest of `ALUMixin`; `_core.py`'s flag constants and `nz8`/`nz16`; the WDC W65C816S datasheet (Table 7-1, N, V and Z valid in decimal mode); Bruce Clark's *Decimal Mode* (`reference/docs/6502org-decimal_mode.html`, pinned in `scripts/pinned_files.json`; 6502.org documentation, facts only in the family's sources.md), appendix A (Seq. 1 and 2 for ADC, Seq. 3 for the 65816's SBC, the C/N/V/Z table) and appendix C (16-bit as two chained 8-bit operations, Z over 16 bits). - **Written:** `add` and `subtract` dispatch on D; `_binary_add` is the binary path, also rewritten (it shared the old functions); `_decimal_add_byte` and `_decimal_subtract_byte` are Clark's sequences as nibble arithmetic, and `_decimal` chains one or two bytes. The structure (byte operations chained, after Clark's appendix C) is not the old one. - **Judged:** SingleStepTests 65816 (MIT, TEST ROM tier as a detector), all 30 ADC/SBC opcode files, `.e` and `.n`, every case, bucketed by D, width and whether both inputs were valid BCD. Before and after are identical: every case passes. | Bucket | ADC cases | SBC cases | before | after | | --- | --- | --- | --- | --- | | D=1, 8-bit, valid BCD | 17,410 | 17,362 | all pass | all pass | | D=1, 8-bit, invalid BCD | 95,257 | 95,037 | all pass | all pass | | D=1, 16-bit, valid BCD | 904 | 948 | all pass | all pass | | D=1, 16-bit, invalid BCD | 36,615 | 36,517 | all pass | all pass | | D=0, 8-bit | 112,504 | 112,494 | all pass | all pass | | D=0, 16-bit | 37,264 | 37,611 | all pass | all pass | | C4 exclusion (`61`, `e1` (d,x)) | 46 | 31 | excluded | excluded | A closed-box comparison of the old and new functions (called, not read) over every 8-bit (A, M, P) and 2,000,000 random 16-bit inputs per operation found no difference. `tests/test_decimal.py` holds Clark's worked examples (DOC). The quick test loop passed before and after. - **Notices:** none owed. Clark's tutorial is cited as documentation of facts; nothing in the new code came from an emulator, so no ISC or GPL notice applies and the core files are `SPDX-License-Identifier: MIT`.