# 6502 Illegal-Opcode Completion — Campaign Plan Status: approved, not yet launched Written: 2026-08-29 ## Objective Take the existing, working `F:\storage-dev\6502-python` core from 151/256 to **256/256 opcodes** so it can be published as a complete NMOS 6502 reference implementation. This is a **brownfield continuation of a green codebase**, not a fresh build. It deliberately inverts every property that made attempts r2–17 fail. ## Verified starting state (measured 2026-08-29, not assumed) | Fact | Value | | --- | --- | | Full suite | 514 passed, 105 xfailed (457s / 8m35s; reconfirmed 515s) | | Non-vector suite alone | 358 passed, 291s | | Oracle sweep portion | ~166s for 151 full + 105 fail-fast | | Product size | 34 `.py` files, 5,015 lines | | Oracle corpus | 256 JSON files, 1,031 MB, `tests/6502_test_vectors/6502/v1/` | | Corpus shape | one file per opcode, `00.json` … `FF.json` | | Baseline commit | `b267508` | | Interpreter | no project `.venv` yet — see Prerequisite 1 | ## Definition of done There is exactly **one** xfail site in the whole repository — `tests/test_6502_vectors.py`, in `_file_case()`: ```python if opcode not in OFFICIAL_OPCODES: return pytest.param(path, id=file_id, marks=pytest.mark.xfail(...)) ``` **Done = that branch is deleted and all 256 vector files pass.** The acceptance criterion is mechanical, externally defined by the SingleStepTests oracle, and cannot be satisfied by the agent writing its own tests. This is the single most important property of this plan. ## The 105 missing opcodes (derived from `OFFICIAL_OPCODES`, not from memory) | Family | Count | Opcodes | | --- | --- | --- | | NOP | 27 | 04 0C 14 1A 1C 34 3A 3C 44 54 5A 5C 64 74 7A 7C 80 82 89 C2 D4 DA DC E2 F4 FA FC | | JAM | 12 | 02 12 22 32 42 52 62 72 92 B2 D2 F2 | | SLO | 7 | 03 07 0F 13 17 1B 1F | | RLA | 7 | 23 27 2F 33 37 3B 3F | | SRE | 7 | 43 47 4F 53 57 5B 5F | | RRA | 7 | 63 67 6F 73 77 7B 7F | | SAX | 4 | 83 87 8F 97 | | LAX | 6 | A3 A7 AF B3 B7 BF | | DCP | 7 | C3 C7 CF D3 D7 DB DF | | ISC | 7 | E3 E7 EF F3 F7 FB FF | | ANC | 2 | 0B 2B | | ALR / ARR / SBX / USBC | 4 | 4B 6B CB EB | | ANE / LXA / TAS / LAS | 4 | 8B AB 9B BB | | SHA / SHX / SHY | 4 | 93 9F 9E 9C | ## Phases (easy first, hardest last) Ordered so the loop proves itself on cheap work before reaching the opcodes that genuinely need iteration. 1. **NOP + JAM — 39 opcodes.** No ALU behavior. NOPs are decode, dummy reads, and cycle counts; JAMs halt. Mostly a decode-table and harness-semantics exercise. Good warm-up that proves the pipeline end to end. 2. **SLO / RLA / SRE / RRA — 28 opcodes.** Read-modify-write composed with an ALU op already implemented. Highly regular. 3. **SAX / LAX / DCP / ISC — 24 opcodes.** Load/store/compare combinations, same regular shape. 4. **ANC / ALR / ARR / SBX / USBC — 6 opcodes.** Stable immediate-mode oddities. ARR's decimal-mode behavior is the one real trap here. 5. **ANE / LXA / TAS / LAS / SHA / SHX / SHY — 8 opcodes.** The unstable ones (magic-constant and RDY/high-byte-dependent behavior). Expect the most iteration. The oracle defines truth, so they are tractable — but they are correctly last. 6. **Close out.** Delete the xfail branch, run the full 256-file sweep, update `README.md` to state complete coverage, and record the provenance pin. Total: 39 + 28 + 24 + 6 + 8 = 105. ## Prerequisites 1. **Create a project-local `.venv`.** The core currently only passes against system Python — a prior AFK run's `pip install -e .` landed in system user site-packages. Do `python -m venv .venv; .venv\Scripts\python.exe -m pip install -e ".[dev]"` and point the campaign's target interpreter at it, so the deliverable is verifiable in isolation. 2. **Timeouts — done 2026-08-29.** `worker.max_shell_timeout` 600 → 1800. Roles that execute shell commands raised above that ceiling: `coder` 900 → 2700, `researcher`/`validator` 900 → 2400. `route.timeout` is the hard deadline on the *entire* agent turn including its shell commands, so a shell ceiling above a session deadline is self-contradictory. 3. **AFK bug fixes — done 2026-08-29 (`71d9a63`).** Read-only tasks no longer fail or loop on an inherited baseline; read-only failures now consume retries and escalate; campaign locks survive PID reuse. ## Runtime expectation Oracle time scales roughly 256/151 once the 105 stop failing fast, so the full suite should land near 570–620s — comfortably inside the new 1800s ceiling but well over the old 600s one. Prefer scoped, task-owned pytest during routine review and reserve the full 256-file sweep for phase 6. ## Governance rules for this run Carried over deliberately from the attempts 05–17 post-mortem: - **Run it as a normal campaign that is allowed to finish.** Not a canary. - **Do not auto-cancel on the first control deviation.** Log deviations as findings in the closing report. A run that stops at its first imperfection cannot produce a reference core — that is precisely what produced fourteen empty targets in one day. - **Do not start a fresh target per attempt.** Product must accumulate in `6502-python` on real branches. - **No new governance surface.** If something misbehaves, record it and keep going; fix it afterward with a plain unit test. - Independently read the generated source and run it against the oracle before declaring success. A "Review PASSED" self-report has previously masked a real production bug in this repo. ## Explicitly out of scope Host memory map, peripherals, video, audio, cartridge, OS, or a complete machine. This stays an embeddable instruction core.