# Provenance Where every part of huc6280-python came from, the licence of each source, and a verdict, as audited on 2026-11-13 against local `main` `265df88` (provenance audit, wave 1), with the verdicts updated on 2026-11-19 after the clean rewrite ([restart.md](restart.md)): each row keeps its 2026-11-13 verdict and adds what was done. Verdicts: **clean** (our 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, or a fact whose only source is GPL code that was read), **unclear** (what would settle it is stated). ## How this project used other emulators Phase 0 (2026-10-23) pinned and read the source of MAME 0.285's `h6280` (BSD-3-Clause), ares (ISC), Mesen2 (GPL-3.0), Mednafen 1.32.1 and the two libretro beetle-pce trees (GPL-2.0), Geargrafx (GPL-3.0) and srg320's VHDL in TurboGrafx16_MiSTer (recorded then as GPL-2.0+; unlicensed since Aubrey's verdict of 2026-11-24: no LICENSE file at the pin and no notice on the HUC6280 files, so run only, fetched at the pin and never committed); `scripts/pinned_repos.json` records each with its licence, and the README says "the GPL and LGPL emulators named in these documents are read, cited and run as referees". The family charter (rule 3) now says their source is not opened while writing the code it would inform. So every behaviour below whose only source is a GPL emulator's code is marked for re-establishing by a closed-box run or a permissive or hardware source. Where SingleStepTests huc6280 (MIT; generated by running Mesen) or a MAME replay (closed box) already records the behaviour, that record is the closed-box source and the item is clean once re-cited. `provenance_check.py` was run against each pinned tree. Reading those trees was this project's documented practice; I did not open them myself, only the tool's report. Results: | Reference | Licence | Hits | | --- | --- | --- | | Mesen2 `Core/PCE` | GPL-3.0 | opcode mnemonic rows (facts); **quoted source comments** in `docs/issues/0002`, `tests/test_directed.py`, `docs/timing.md` | | beetle-pce | GPL-2.0 | `tools/mednafen-trace.patch` (now outside, in emu-tools-gpl2) context (expected; GPL tool); a **quoted comment** in `docs/timing.md` | | beetle-pce-fast, Geargrafx | GPL-2.0, GPL-3.0 | none | | TurboGrafx16_MiSTer | GPL-2.0+ as recorded then; unlicensed, run only, since 2026-11-24 | one mnemonic row (fact) | | ares `huc6280` | ISC | mnemonic rows and opcode-number runs (facts) | | MAME `h6280` | BSD-3-Clause | one register-name row (fact) | `src/` has no hit against any tree. ## The core (`src/huc6280/`) | Part | Where its behaviour came from | Verdict | | --- | --- | --- | | Opcode map, bytes, cycle counts (rung 0) | Hudson's HuC6280 software and hardware manuals (`manual_table.py`), checked against SST | clean (facts) | | Registers, MMU, T flag, timer, interrupt priority, block-transfer totals (17 + 6n) | Hudson manuals, MacDonald's pcetech (hardware-tested), SST | clean | | Per-cycle bus shapes (C8) and block-transfer shape (`_block.py`: "Mesen's: 13 cycles of entry ...") | SST huc6280's recorded cycles (closed-box Mesen output, MIT) | **cite** -> **clean** (2026-11-19): `_core.py` and `_block.py` now cite SST's records | | U8 zero-page pointer wrap (`_core.py`) | MAME `program_read16z` (BSD-3) and Mesen `ReadZeroPageWrap` | **cite** -> **clean** (2026-11-19): cites MAME h6280 (BSD-3, Bryan McPhail; NOTICE.md) and SST's 226 cases at `$FF`; the Mesen name dropped | | C3 interrupt entry 8 cycles | SST records, ares (ISC) | **cite** -> **clean** (2026-11-19): ares (ISC); Mesen2's bus observed closed box (the core's order: two reads at PC, pushes, vector, a cycle with no access); Mednafen replays; MAME 7 (BSD-3); the VHDL 9 | | BRK as the interrupt sequence (`_control.py` 254) | comment names srg320's HDL and Mesen2's `ProcessIrq`; SST records BRK | **cite** -> **clean** (2026-11-19): SST's BRK records and the observed entry bus; GPL names dropped | | C6 `TMA` with several mask bits: OR (`_hudson.py`) | Mesen's behaviour, read from source; chosen "by reasoning" | **unclear** -> **clean** (2026-11-19): OBSERVED in all 2,418 multi-bit SST cases (closed-box Mesen); MAME (BSD-3) and Mednafen (closed box) take the highest bit, recorded; default unchanged, provisional | | C7 speed change in the last cycle of `CSL`/`CSH` | Mesen and Mednafen comments (quoted in `docs/timing.md`) | **unclear** -> **clean** (2026-11-19): OBSERVED in the traced Mednafen run (CSH from low 4 + 4 + 1, CSL from high 1 + 1 + 4 units); SST has no timing; quotes removed | | C12 `TSB`/`TRB` Z from the stored result | pcetech, MAME (BSD-3), and "Mesen2's current source", Mednafen | **cite** -> **clean** (2026-11-19): pcetech 2.0 and MAME (BSD-3); Mednafen agrees as a closed box (validation/mednafen_votes.py); GPL sources dropped | | C13 decimal `ADC`/`SBC` (`_alu.py`, `decimal_formula`) | rewritten in `bf20330` "from a description" after the first version transcribed Mednafen's macros and kept Mesen2's formula's shape; `docs/issues/0004` stated both rules in words, read from the GPL source | **unclear** -> **clean** (2026-11-19): the functions were moved aside unread; the two result tables were produced closed box (`scripts/decimal_tables.py`: Mednafen 1.32.1's 262,144 traced operations, SST's 11,346 decimal cases of Mesen's output); the digit rules were written from the tables alone by a writer who had not read the old functions, issue 0004's prose or the test's history; the recorded digests then matched for both formulas and both operations. Issue 0004 now describes the tables. Caveat: the writer is the same agent family that wrote the earlier versions, in a fresh context | | C16 T cleared on interrupt push | "emulator-derived", source not named | **unclear** -> **clean** (2026-11-19): OBSERVED on a timer taken between `SET` and its target: Mesen2 and Mednafen (closed box) run the handler's first `ORA` on A; ares (ISC) clears T; srg320's VHDL (GHDL) dissents, recorded; default unchanged, provisional; test `test_c16_*` added | | C18 `vanished_interrupt = "mesen2"` (default) | Mesen2's `ProcessIrq` and its comment, read from source | **rewrite** -> **clean** (2026-11-19): code moved aside unread and rewritten; behaviour re-established closed box on four probe cards (`validation/vanish_probe.py`): Mesen2 and Mednafen both drop a timer acknowledged in the last cycle and take a VDC interrupt acknowledged then; MAME enters before the site (no CLI delay), recorded; default unchanged | | C18 `"latched"` mode | srg320's VHDL, "read from its source" (`*_INT` registers) | **rewrite** -> **withdrawn** (2026-11-19): the VHDL run as a closed box under GHDL (`validation/vanish_vhdl.py --sweep`) decides on the levels at the end of the last cycle for every source, which is U25 `"last"`, not this mode; `"latched"` now raises `ValueError` | | U25 `irq_poll_cycle = "mednafen"` mode | Mednafen `RunSub`, read from source; the comment quoted the expression | **rewrite** -> **withdrawn** (2026-11-19): not re-established from outside (a timer appearing in the last cycle needs an independent phase measurement; restart.md "Open"); raises `ValueError`. U25 `"last"` kept, now OBSERVED in the VHDL run | | U21, C10, C11, C15 interrupt-flag timing | the 6502 frame's rule (6502-python, own), MAME replay | clean | | `harness.py` HuCard mirroring (384/512/768 KB) | "Mesen2's mirroring (`PceMemoryManager`)" | **unclear** -> **clean** (2026-11-19): ported from MAME 0.285 `bus/pce/pce_slot.cpp` `rom_map_setup` (BSD-3, Fabio Priuli; NOTICE.md and the function's docstring). **Changed**: 512 KB cards now repeat whole and 192 KB images map 0 1 2 2 0 1 2 2 | | Disassembler syntax | PCEAS / MAME `6280dasm` (BSD-3) | clean | | Debugger, trace, state, console | own | clean | ## Tests, tools and fixtures | Part | Source | Verdict | | --- | --- | --- | | SingleStepTests huc6280 and 65x02 Rockwell sets | fetched, pinned, never committed; MIT | clean | | Klaus Dormann's 65C02 extended opcodes test | fetched; `scripts/dormann_to_ca65.py` converts it at build time; GPL-3.0; never committed | clean | | MAME 0.285 replays (`scripts/mame_*`, `tests/mame_replay.py`) | MAME run as a closed box with a Lua tap | clean | | `tools/mednafen-trace.patch` | a patch to Mednafen, labelled GPL-2.0-or-later, outside the package | clean as a GPL tool file (charter rule 6); **moved out 2026-11-21** with the history reset, kept outside the repository; since 2026-11-24 it is GPL-2.0-only by Aubrey's rule of that day and lives at `$EMU_TOOLS_GPL2/tools/mednafen/patches/mednafen-trace.patch`, where `scripts/build_mednafen.py` finds it | | `tests/test_mednafen.py` | SHA-256 digests of the four result tables (facts) | clean | | `tests/huc6280_vhdl/tb_huc6280.vhd` | our testbench for srg320's VHDL; its header described the core's insides | **unclear** -> **clean** (2026-11-19): the header now states the port timing as OBSERVED in simulation (`tb_vanish.vhd` with `late`: data driven 1 ns after the rising edge is misread); both testbenches use only the entity's ports and carry `SPDX-License-Identifier: MIT`. **Moved out 2026-11-21** with `tb_vanish.vhd` and `validation/vanish_probe.py`: a testbench elaborated with a GPL core, and a ctypes driver of Mesen2's C API, are GPL tools as built (the family's rule for harnesses); `scripts/build_referees.py` and `validation/vanish_vhdl.py` find the testbenches at `$EMU_TOOLS_GPL/tools/huc6280-python/huc6280_vhdl/`, and the probe is run by hand from `$EMU_TOOLS_GPL/tools/huc6280-python/vanish_probe.py` (now a shim over mesen2-runner; it finds this checkout through `HUC6280_PYTHON_ROOT`, else the working directory) | | `tests/test_directed.py` lines 753, 765, 771, 877 | quoted Mesen2 comments and Mednafen's code expression | **rewrite** -> **clean** (2026-11-19): comments rewritten as observed behaviour with the closed-box runs named; the two withdrawn modes' tests replaced by refusal tests | | Chris Covell's CPU test ROM | fetched, no licence stated, never committed | clean (closed box) | | Hudson manuals, pcetech, sgxtech, pce_cpu (shu) | fetched into `reference/docs`, never committed | facts only | ## Documents (rewrite: remove quoted GPL source and code fragments) **Done 2026-11-19**: issues 0002 and 0004 rewritten whole; mednafen-oracle.md's votes now come from closed-box runs only (the source-read rows withdrawn); timing.md, undocumented-behavior.md (U6, U8, U10, U15, U21, U23, U25, C1, C3-C10, C12, C13, C15, C16, C18), start-here.md, issues 0001, 0003 and 0005, validation.md, mame-oracle.md and the README reworded without quotes, code or internal names. The list as audited: - `docs/issues/0002`: quotes Mesen2's `ProcessIrq` comment and names `HasIrqSource(TimerIrq)`. - `docs/mednafen-oracle.md` line 80: the expression `IRQlow & IQTIMER & IRQMask` and "else tmpa stays 0"; line 78 `IFlagSample`. - `docs/timing.md` lines 139, 179, 186-187, 224: Mesen/Mednafen function names, a Geargrafx statement (`m_cycles += 8`) and two quoted comments. - `docs/undocumented-behavior.md` U8, U21, C6 (`HUC6280_CPU.vhd` `MPR_OUT`, "read ... not run"), C15, C18; `docs/start-here.md` 130; issues 0003 and 0005: function names read from GPL source. - `docs/issues/0004`: the prose restatement of the Mednafen and Mesen2 code (see C13). - `README.md` lines 97-99 ("read, cited and run as referees") contradicts charter rule 3; reword once the items above are settled. ## History (PUBLIC: `alewman/huc6280-python`) 1. **Mesen2-shaped decimal arithmetic** (GPL-3.0; `bf20330`'s message: the core "kept Mesen2's (GPL-3.0) formula in the same shape"): in `src/huc6280/_alu.py` from `929c9f7` (Rung 1, 2026-10-24) to `9ea9415` (2026-11-12), 24 commits, all on `main`. **Tags `v0.1.0` (`a379416`) and `v0.2.0` (`f31b630`) carry it**, and so do GitHub's automatic source archives of those tags. There are no GitHub releases with assets and no PyPI package. 2. **Mednafen transcription** (GPL-2.0): `d575521` (2026-11-10) transcribed the `ADC`/`SBC` macros into `_alu.py` and repeated them in `tests/test_mednafen.py`; `e8ed549` quoted Mednafen's code in `docs/issues/0004-decimal-adc-sbc-mednafen-formulas.md`; present through `9c47c98` and `9ea9415` (4 commits). No tag carries it: `v0.3.0` points at `bf20330`, the rewrite. 3. **Quoted GPL comments and code fragments** in docs and tests (listed above) since `ee37db5` (2026-10-23) and `5f26ba6` (2026-10-24); they are still at HEAD and in every tag. 4. 28 commits were authored with the owner's full name (2026-10-23/24); the rest `alewman`. 5. No file has ever been deleted; `reference/` (the pinned GPL trees and the Mednafen tarball) is git-ignored and was never committed. A rewrite to remove items 1 and 2 would edit `src/huc6280/_alu.py`, `tests/test_mednafen.py`, `tests/test_directed.py` and issue 0004 in `929c9f7`..`9ea9415` and change every later hash, including tags `v0.1.0`, `v0.2.0`, `v0.3.0` and the pins of huc6280-rust (`v0.3.0`, `265df88`), huc6280-rust-fast and pcengine-python. Local `main` is two commits ahead of `origin/main` (`4c57f5d`, `265df88` "Release 0.4.0", not tagged). ## 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, unless a program with no shipped build is built from it. Pins removed from `scripts/pinned_repos.json`, trees moved aside unopened, out of the repository (not deleted): Mesen2 (https://github.com/SourMesen/Mesen2 @ `b9fa69ddc6d0a331fb103fdb5eef6904305703c2`, GPL-3.0), Beetle PCE (https://github.com/libretro/beetle-pce-libretro @ `b96c11e095b6a40a412d2da02766ae1c3f4fd539`, GPL-2.0), Beetle PCE Fast (https://github.com/libretro/beetle-pce-fast-libretro @ `4eee99c451f85ebe66d1591de88b892015b23059`, GPL-2.0) and Geargrafx (https://github.com/drhelius/Geargrafx @ `57c257dda25f441fff3c63a63bbc4ba7cbb713e3`, GPL-3.0). **Kept, with a question for Aubrey:** TurboGrafx16_MiSTer (`827d45f4`, unlicensed: run only), because `scripts/build_referees.py` analyses its HuC6280 VHDL with GHDL for rung 5; and the Mednafen 1.32.1 tarball with its unpacked tree under `reference/build/` (GPL-2.0), because `scripts/build_mednafen.py` builds the traced detector from it with the emu-tools-gpl2 patch. Neither has a shipped build that would do. Aubrey's answer (decisions page T3, 2026-11-25): both move, one tool at a time. Mednafen moved on 2026-11-25 (below); the VHDL is still here. ### Mednafen's build moved to emu-tools-gpl2 (2026-11-25) Decisions page T3: the traced Mednafen is now built by emu-tools-gpl2's `tools/mednafen` (mednafen-build 0.1.0, GPL-2.0-only: `build.py --machine pce`, the same pinned tarball, SHA-256 `de7eb94a...`, the same patch and configure options), and run from `$EMU_TOOLS_GPL2/tools/mednafen/build/pce/bin/mednafen` (scripts/mednafen_trace.py, through scripts/emu_tools.py; exit status 3 without it). `scripts/build_mednafen.py` now only runs that tool's build as a program. The tarball's pin left `scripts/pinned_files.json`. Moved unopened to a backup outside the repository (not deleted): `reference/build/mednafen-1.32.1.tar.xz`, `reference/build/mednafen-src` (the unpacked, patched tree) and `reference/build/mednafen-bin` (the program, sha1 `e70ac33f`). Identity check, 2026-11-25: `scripts/mednafen_trace.py` on scripts/decimal_tables.py's own 8 KiB card (no commercial ROM), `--count 300000`, with the old program and with the tool's: both traces 600,000 lines, 13,367,056 bytes, sha1 `fb30b743`, byte for byte the same (OBSERVED; pcengine-python's `mednafen_record.py` gave the same file both ways). **For review (a finding, not fixed here):** `scripts/compare_cycles.py`, `scripts/opcode_map.py` and `scripts/manual_table.py` parse tables (cycle counts, opcode sizes, the opcode and addressing-mode tables) out of the Geargrafx, Beetle PCE Fast and Mesen2 sources at run time, and `opcode_map.py`'s `MODE_TEXT` spells Mesen2's addressing-mode names. A program reading GPL source is still reading it (restart.md rule 1). They now stop with a message when the trees are absent; the tables they printed on 2026-10-23 (docs/timing.md) are kept as recorded and marked. Re-establishing them from Hudson's manual, MAME's BSD-3 `h6280.cpp` and SingleStepTests, or retiring the scripts, is Aubrey's call.