# Handoff: build `s2650-python`, the Signetics 2650 core ## Context you are inheriting The family's shape: CPUs always get their own core; boards pin cores by commit; the Python core is the specification, x-rust transcribes it bus cycle for bus cycle. Read the charter (emulator-lineage `docs/charter.md`), then [start-here.md](start-here.md) and [cpu.md](cpu.md). Cores to model this one on: **z80-python** (the callable bus, the interrupt protocol, the oracle tiers in its README), **6502-python** and **m6800-python** (8-bit cores whose bus cycles are the contract), **huc6280-python** (a Phase 0 that became a core). Then `python -I scripts/fetch_references.py` (4 files, ~47 MB; `--verify` to check). ## Decided by Aubrey (standing rules) - Name `s2650-python`, package `s2650_python`. Local, no remote, until he says. - Python floor = PyPy's (3.11), PyPy must work; modern forms over shims. - Technical choices are made, marked provisional and reported. ## Scope The 2650 and 2650A instruction set and bus behaviour from UM and DM83; the 2650B as a variant flag (UF1/UF2) once a source is found (U2). Not in scope: any board's memory map, the PVI/UVI, the FLAG/SENSE wiring (the board's). ## Package and classes (proposed) ``` s2650_python/ cpu.py # S2650(read, write, *, read_port=None, write_port=None, variant="2650A") # step() -> clock periods; registers r0, r1..r3 in two banks, iar, psu, psl, ras[8] _decode.py # the opcode table: one row per UM Table 2 entry: mnemonic, mode, length, cycles _ops.py # one small handler per operation, citing its UM page bus.py # the bus-operation kinds: FETCH, READ, WRITE, IO_C, IO_D, IO_E, INTACK state.py # capture_state / restore_state disasm.py # Signetics mnemonics (the assembler syntax of UM ch. III) ``` ## The embedding contract (what a board gets) 1. `read(address, kind)` / `write(address, value, kind)` with 15-bit addresses, one call per processor cycle's external operation, in UM's order (prefetch in the last cycle). 2. Ports: `read_port(kind, port)` / `write_port(kind, port, value)`, kind C or D (one byte, no address) or E (port on ADR0-7). 3. Pins: `sense` (input, read into PSU.S), `flag` (output, a callback on change, at the last cycle of the changing instruction: UM 41), `intreq` (level), `reset` (level), `pause`. 4. INTACK: the board answers `intack()` with the vector byte; the core performs the jammed ZBSR (UM 43-44). 5. Waits: a board returns extra clock periods for an operation (OPACK late), so the Arcadia's and VC 4000's video DMA contention can be modelled by the board. 6. `step()` returns the clock periods used (3 per processor cycle plus waits). ## Rungs | # | Rung | Judge (tier) | Exit | | --- | --- | --- | --- | | R0 | decode table and disassembler | UM Table 2 (2) | every defined opcode decodes with length and cycles; MAME's disassembly of the three traces agrees mnemonic for mnemonic (detector) | | R1 | every documented instruction, unit tests from UM's pages, both register banks, page wrap per mode, WC/COM/IDC/OVF rules, DAR | UM (2) | all tests pass on CPython and PyPy; seeded faults (carry into ADD with WC clear; compare ignoring COM; page wrap across 1FFF) caught | | R2 | lockstep with MAME on real programs: VC 4000 Golf, Arcadia Escape, Elektor monitor (this phase's traces) and 5 more cartridges | MAME (5), detector | 0 unexplained differences in instruction stream and registers; each explained one cites UM | | R3 | bus-operation order and cycle count per instruction, prefetch, OPACK waits | UM 34-36, 44 (2) | a bus log test per instruction class; x-rust can transcribe it cycle for cycle | | R4 | interrupts and reset: sampling before the last cycle, ZBSR vector and indirect bit, RETE, RESET with INTREQ | UM 43-46 (2) | tests from the text; MAME as detector on a cartridge that uses interrupts | | R5 | undocumented opcodes: a policy (decision 2) | none | the policy implemented and documented | ## Unknowns (U) and conflicts (C) | # | Unknown | Best source now | | --- | --- | --- | | U1 | the page-wrap rule for each addressing mode beyond what UM states | UM 27-28, 44 | | U2 | the 2650B's differences (UF1/UF2 and anything else) | GUIDE only; no Signetics sheet found | | U3 | what opcode 00 (`LODZ R0`) does ("indeterminate results", UM) | none | | U4 | the undefined opcodes | none (GUIDE lists them as unresolved) | | U5 | register, PSW, SP and RAS state after RESET | UM 46 says only that II is cleared and fetch starts at 0 | | U6 | the 2650 / 2650A differences | DM83 sheet vs UM: not compared yet | | U7 | the CC value after DAR ("meaningless", UM note 2) | none; pick, tag HYPOTHESIS | | # | Conflict | Sides | Proposal | | --- | --- | --- | --- | | C1 | pin 35 RUN/WAIT | UM: input; ERR: output | output (ERR; the name and function fit) | ## Domains and speed **Domains and channels.** The CPU is one domain with its board's bus; its channels are the bus (memory-mapped video chips), the one-byte and extended ports, SENSE, FLAG and INTREQ. Threads belong to the boards, not the core. **Instructions a second.** At the consoles' clocks (895 kHz Arcadia, 886.7 kHz VC 4000): this phase's traces average 9.7 clock periods an instruction (Arcadia: 44,745 periods for 4,605 instructions; VC 4000: 53,190 for 5,763 is 9.2), so 895,000 / 9.7 = **~92,000 instructions a second**. The fastest arcade user (Laser Battle, 3.58 MHz) needs ~370,000; the CVS boards run three 2650s (1.78 MHz + 2 x 0.89 MHz): ~370,000 together. **The no-JIT path.** A pure-Python 8-bit core of the z80-python kind runs 2-3 M instructions a second on PyPy: 20-30 x the consoles' need, ~7 x the CVS boards'. A Rust `-fast` core runs hundreds of millions: phone and browser (WASM) reach real time with no cached interpreter and no threads. `recompile: none` on every target. ## Open decisions for Aubrey (each with a recommendation) 1. **Which part is the reference.** Recommend the 2650A (the consoles' part, DM83), with the 2650 as identical until a difference is sourced (U6) and the 2650B as a later variant flag. 2. **Undocumented opcodes.** No hardware source exists. Recommend: execute MAME's behaviour as a marked HYPOTHESIS (so real cartridges that hit them run), log every execution, and list the opcodes in docs/undocumented-behavior.md; no cartridge in this phase's traces executed one. 3. **WinArcadia as a referee.** Its source is published without a licence. Recommend asking James Jacobs (Amigan Software) for a licence or for his test notes; until then, run only, in emu-tools-gpl, never redistributed. 4. **Hardware test programs.** GUIDE says "test programs could be written" to settle the unknowns. Recommend recording U1-U5 as probe candidates in PROBE-QUEUE.md for anyone with a 2650 machine; Aubrey owns no 2650 hardware. 5. **sources.md rows**: proposed in the Phase 0 report (Signetics manuals, Amigan's site, WinArcadia unlicensed, AS2650 Apache-2.0, MAME s2650 BSD-3). 6. **bitsavers.org's 403 to plain curl.** The first downloads used a browser User-Agent (before the new rule); the pins now use the UK Mirror Service. Recommend treating bitsavers.org as "use a listed mirror, never a spoofed agent" in sources.md.