# Handoff: build `amiga-python`, the Amiga 500 (OCS) board ## Context you are inheriting The family's shape: chips are cores, boards compose cores; CPUs always get their own core; a non-CPU chip used by one machine stays in its board; never copy a file between repositories, pin the sibling by commit. Read the charter first (emulator-lineage `docs/charter.md`), then [start-here.md](start-here.md). The Amiga is era 2 in spirit (a 68000 with cycle-lockstep custom chips, like the Mega Drive) with one locked clock: the chips meet on every chip-RAM slot, so the board is one domain plus a drive and a keyboard. Boards to model this one on: **megadrive-python** (an m68000-python host with a video chip that stalls the CPU), **sms-python** (machine rows), **a2600-python** (a chip whose every slot is observable). Core it embeds: **m68000-python** (public v0.1.0; read its README's "Reference-core boundary" and docs/claims.md first). Read in order before writing code: 1. [README.md](../README.md), [start-here.md](start-here.md), [machines.md](machines.md). 2. The chips: [agnus.md](agnus.md) (the heart: the slot table), [denise.md](denise.md), [paula.md](paula.md), [cia.md](cia.md), [floppy.md](floppy.md), [kickstart-aros.md](kickstart-aros.md). 3. [cpu-cores.md](cpu-cores.md), [domains-and-speed.md](domains-and-speed.md). 4. [sources.md](sources.md), [validation.md](validation.md), [mame-oracle.md](mame-oracle.md), [census.md](census.md), [provenance.md](provenance.md). Then `python -I scripts/fetch_references.py` (5 documents, about 107 MB, the HRM3 scan being 86 MB of it; 2 repositories; `--verify` to check). Text copies of the PDFs land in `reference/text/` for grepping (the 8520 data sheet has no text layer: use the TRM's 8520 chapter, pdf213-). ## Decided by Aubrey (standing rules that apply here) - Name `amiga-python`, package `amiga_python` (the x-python naming rule). - Local, no remote, until he says otherwise. Bring your own Kickstart and disks; nothing of Commodore's in the repository; firmware identified by SHA-1. - Python floor = PyPy's (3.11); PyPy must work; under ~80 attributes a class; modern over compat; reference boards are correct, not fast; sound may be less exact than pictures; smoke lists before sweeps. - GPL/LGPL/MPL/non-commercial source never enters this repository: WinUAE, FS-UAE, vAmiga, Minimig and the SPS library are closed boxes (sources.md). - Technical choices are made, marked provisional and reported; policy waits for him. ## Proposed by this Phase 0 - **PAL A500, Kickstart 1.3, OCS** first (`a500-pal`), `a500-ntsc` a row from M1; ECS rows (A500+, A600) after the OCS gate; AGA only with a 68020 core and an AGA document. - **One timeline in 7M clocks** (the 68000's clock): a CCK slot is 2, a CPU bus cycle 4, an E cycle 10, a lores pixel 1, a hires pixel 1/2 (Denise works in half-clocks inside a slot). - **The slot table is the specification's spine**: one function decides each slot's owner from the registers latched for that line; every slot is a row of the per-cycle trace the Rust tiers must match. - **The CPU stalls through m68000-python's existing callable contract** (step_clocks + host stalls, Agnus caught up inside each chip-bus callable): no core change needed to start (cpu-cores.md). - **Kickstart 1.3 to its insert-disk screen** is the M1-M3 lockstep and picture case; vAmigaTS is the tier-3 judge from M2 on. - **ADF first, our own IPF reader second** (every library disk is IPF; the SPS decoder is non-commercial). - **A functional keyboard** first; the 6500/1 MCU on 6502-python later if needed. ## Package and classes (proposed) ``` amiga_python/ machine.py # machine rows: chip-set revision, Agnus/Denise IDs, clocks, RAM sizes, Kickstart SHA-1s console.py # build(machine, kickstart=..., disks=[...]) -> Amiga bus.py # the A500 map (Gary's decode): chip RAM, slow RAM, ROM + overlay, CIA, custom regs, open bus agnus.py # Agnus: beam counters, DMACON, the slot table and arbiter, refresh, bitplane/sprite fetch copper.py # Copper (inside Agnus's slots; own file for size) blitter.py # Blitter: channels, minterms, shifts, masks, fill, line mode, its slot sequence denise.py # Denise: shift registers, playfields, HAM/EHB, sprites, priority, collisions, pixels paula.py # Paula: INTENA/INTREQ -> IPL, audio state machines x4, disk DMA, UART, pots cia.py # Cia8520: ports, timers, TOD, serial, ICR (two instances) drive.py # FloppyDrive: motor, head, rotation, index, status lines, the bit-cell track source adf.py, ipf.py # disk image readers producing bit-cell tracks keyboard.py # KeyboardHle: the serial protocol into CIA-A (MCU later) video.py # frame assembly and the picture producer interface audio.py # the DAC and the fixed and LED filters (good-enough) sockets.py # socket Protocols (drive, keyboard, expansion) and test fakes savestate.py # whole-machine states naming Kickstart and disks by hash ``` ## What the board needs from its cores (the embedding contracts) From **m68000-python** (one instance): 1. Byte/word bus callables with `step_clocks` readable inside them (have). 2. `acknowledge(level)` -> `AUTOVECTOR` for Paula's IPL levels 1-6 (have; the E-clock acknowledge wait is modelled from the host's running clock). 3. `reset_devices()` for Kickstart's RESET instruction (have). 4. `tas_write` (have; TAS forbidden on the Amiga, U5). 5. **Request 1 (raise upstream with a repro before M1 closes):** a documented helper or hook for VPA data cycles, so CIA accesses use the same E-clock wait rule as the autovector acknowledge instead of the board duplicating it. 6. Bus-error frame contents stay outside its contract; no A500 source of BERR is known (U30). From **6502-python** (only by open decision 6): a 6502 core under a 6500/1 wrapper. ## The gate (defined at M1, before any add-on) The board's lockstep case against MAME (Kickstart 1.3, the 68000's PC stream and the register-write stream with clocks, `0 unexplained`), its unit tests of documented facts (each citing an HRM3 page), and from M2 the vAmigaTS screenshot rows. With no disk and no expansion, the base board must not move these when a later row lands. ## Milestones | # | Milestone | Judge (tier) | Exit | | --- | --- | --- | --- | | M1 | **Bus and map, the overlay, chip RAM, Kickstart ROM by SHA-1 (doubled images accepted), both CIAs (ports, timers, ICR, TOD), Paula's interrupts, Agnus's beam counters and DMACON with the slot table's refresh slots and CPU stalls, the register file for every custom register (writes logged), the sockets and fakes** | HRM3, TRM (2); MAME (5) as detector | Kickstart 1.3 runs from reset to its first register writes (frame 16) and on through 40 frames with the PC stream and the 8 register writes equal to MAME's, or a named reason for each difference; CIA and register-map facts as unit tests | | M2 | **Bitplane DMA and Denise playfields** (lores/hires, 1-6 planes, dual playfield, HAM, EHB, DIW/DDF, scroll), the **Copper**, colour registers, the frame | vAmigaTS Agnus/DDF, DIW, Copper, Denise/DIW, Modes (3); HRM3 (2) | the Kickstart 1.3 screen draws (without the pointer) and matches MAME's snapshot, every pixel difference triaged; every vAmigaTS case in those folders run, results tabled | | M3 | **Sprites** (DMA, manual, attached, priority), **collisions**, the **Blitter** (all modes, fill, line) with its slot sequence; blitter-nasty | vAmigaTS Denise/Sprites, Agnus/Blitter (3) | the insert-disk screen complete (the hand is drawn by the blitter's line and fill modes); vAmigaTS sprite and blitter rows; the per-channel blitter slot sequence written as one table with each row's evidence | | M4 | **Paula audio** (state machines, DMA, attach, interrupts), the analogue filters | HRM3 ch. 5 (2); vAmigaTS Paula/Audio (3) | vAmigaTS audio cases; audio compared with detectors, differences named; the good-enough rule | | M5 | **The floppy drive and disk DMA**, ADF, the keyboard (functional), the UART, pots/buttons | HRM3 ch. 8 (2); vAmigaTS Paula/Drive, CIA, Mainboard (3); Amiga Test Kit (3 where readings from real units exist) | a vAmigaTS ADF boots from the drive model on Kickstart 1.3 (the first boot from a disk); Amiga Test Kit's menus run; keyboard and mouse input work | | M6 | **The IPF reader** (our own) and the drive's per-cell density and weak bits | the files' CRCs and sector checksums | all 5,753 library IPFs parse with no CRC failure; 5 games of a smoke list (problem titles and well-behaved ones) reach their title screens | | M7 | **Save states, NTSC row, the smoke list grown from failures**; AROS boots | the programs | a save state loads into a fresh machine and continues identically; AROS reaches its first screen | | M8 | **ECS rows** (8372A/8375 Agnus, 8373 Denise: BEAMCON0, super-hires, DENISEID, 1-2 MB chip RAM) with Kickstart 2.04 | HRM3 appendix C (2); vAmigaTS ECS screenshots (3) | Kickstart 2.04 on an A500+ row to its first screen; the OCS gate unchanged | Full library sweeps only when the board might be ready (Aubrey's smoke-sweep rule). ## The chip rule | Chip | Users in or near the family | Proposal | | --- | --- | --- | | MC68000 | Mega Drive, System 16, Sega CD, Neo Geo, Saturn sound, ... | the existing core, m68000-python | | 6500/1 keyboard MCU | Amiga keyboards only | 6502-python + an in-board wrapper, if run at all (decision 6) | | 68EC020/030/040 | AGA and big-box rows only | a future CPU core (decision 8) | | Agnus, Denise, Paula, Gary | Amiga machines and MAME's Amiga-based arcade boards, all of which would pin this board | stay in the board | | 8520 CIA | no other family board (a C64 would want the 6526) | stays in the board behind a pin-shaped class | | floppy drive, IPF reader | Amiga (an Atari ST board would want IPF too) | board; extract the IPF reader when a second board needs it | ## Unknowns (U) and conflicts (C) **Unknowns** (the best source available for each): | # | Unknown | Best source now | Status | | --- | --- | --- | --- | | U1 | PAL line length (227 CCKs: consistent with the clocks, domains-and-speed.md) and NTSC long/short line alternation | HRM3 pdf209 (NTSC 227.5 only) | 227 PAL provisional; vAmigaTS | | U2 | **exact slot numbers of every DMA channel** | HRM3 figure 6-9 ("adjusted") | vAmigaTS Agnus/DDF, DIW | | U3 | trapdoor slow RAM: on the chip bus, contended like chip RAM, reachable by no DMA? | TRM (Gary) | read TRM pdf82-94 at M1 | | U4 | what "unsatisfied for three consecutive memory cycles" counts (blitter-nasty off) | HRM3 pdf213 | vAmigaTS Blitter | | U5 | TAS on chip RAM: is the write lost? | HRM3 pdf211 forbids it | HYPOTHESIS; detectors | | U6 | the Copper danger bit's range, OCS versus ECS | HRM3 ch. 2, appendix C | read at M2 | | U7 | Copper wake-up slot; WAITs in the blank or past the line's end | HRM3 pdf35 (counts only) | vAmigaTS Copper | | U8 | **the blitter's per-channel slot sequence and idle cycles** | HRM3 pdf208 (totals only) | vAmigaTS Blitter; the biggest gap | | U9 | chip RAM wrap above the Agnus's reach, per revision | none | detectors | | U10 | reads of write-only and undecoded custom registers | none | vAmigaTS Registers | | U11 | Denise pipeline delay from BPL1DAT to the first pixel, with scroll | HRM3 pdf210 ("five clocks") | vAmigaTS Denise | | U12 | EHB on early A1000 Denise | none read | A1000 row only | | U13 | DIW outside normal ranges | HRM3 ch. 3 | vAmigaTS DIW | | U14 | sprite arming and comparator rules; sprites starting in the blank | HRM3 ch. 4 | vAmigaTS Sprites | | U15 | collisions in the border and blank; attached and disabled sprites | HRM3 tables 7-3, 7-4 | vAmigaTS | | U16 | DENISEID read on OCS Denise | HRM3 pdf314 (ECS only) | detectors | | U17 | where AROS's extension ROM is mapped; which AROS build targets a 68000 OCS A500 | AROS docs (facts only) | M7 | | U18 | **AGA registers: no Commodore AGA document found** | none pinned | before any AGA row | | U19 | INTREQ/INTENA -> IPL -> 68000 sampling latency | none | vAmigaTS Interrupts | | U20 | audio periods below 124: what is heard | HRM3 pdf156 | detectors; good enough | | U21 | audio DMA request-to-data timing per state | HRM3 figure 5-8 | vAmigaTS Audio | | U22 | analogue filter curves (fixed and LED), per board revision | HRM3 pdf172 (existence) | good-enough rule | | U23 | an access selecting both CIAs: what a read returns | HRM3 appendix F | detectors | | U24 | 8520 one-cycle corners: timer load/read, ICR, interrupt delay, TOD latch | data sheet (2) | vAmigaTS CIA/TOD, Amiga Test Kit | | U25 | the drive ID shift on DSKRDY* | HRM3 pdf259 (mentions it) | HRM3 ch. 8 at M5 | | U26 | head over-step past track 79; step timing | HRM3 (specifications) | FITTED; Amiga Test Kit readings | | U27 | Paula's data separator: how cells are sampled from a drive on its own clock | none | modelling decision at M5 | | U28 | which chips the RESET instruction resets, and to what | TRM | M1 | | U29 | trackdisk's DMA length per Kickstart version | the ROM's behaviour (observe, do not read the ROM) | MAME trace at M5 | | U30 | any bus-error source on an A500 | none | HYPOTHESIS: none | | U31 | ROM wait states and Gary's mirrors | TRM | M1 | **Conflicts** (sources disagree): | # | Conflict | Sides | Proposal | | --- | --- | --- | --- | | C1 | which chip-RAM cycles the 68000 uses | HRM3 pdf211: "only the even-numbered memory access cycles"; HRM3 pdf35: audio, disk, refresh, sprites use "only the even-numbered memory cycles" and the Copper the odd ones | model a free-slot arbiter with no fixed parity for the CPU; let vAmigaTS decide; keep both readings in agnus.md | | C2 | figure 6-9 as a slot table | the figure's own notes: "adjusted" to match hardware requirements; cycle 0 "appears to exclude one of the memory refresh cycles. This is not the case" | treat the figure as a drawing; the slot table is U2 | | C3 | Copper cost in figure 6-9 vs ch. 2 | figure: MOVE "4 slots", WAIT "6 slots"; pdf35: MOVE two memory cycles (four cycle times), WAIT three memory cycles (six cycle times) | the same facts in different units; the table states memory cycles and slots explicitly | | C4 | blitter cycle cost | HRM3 pdf208's per-channel summary (4-8 clocks a cycle) vs the observed per-channel sequences that emulators use (not read) | HRM3's totals as unit tests; the sequence from vAmigaTS (U8) | | C5 | MAME's `beamy` vs Agnus's line counter | MAME counts 625 half-lines (vtotal); VPOSR/VHPOSR count lines | map before comparing (mame-oracle.md) | | C6 | the A3000 ROM 390629-02 | MAME: "Kickstart 2.0 (36.16)"; No-Intro: "v1.4 Rev 36.016" | identify by SHA-1 only; A3000 is not a planned row | | C7 | A3000 Kickstart 2.04 halves | MAME and No-Intro give swapped part numbers (390629-03 / 390630-03) for the same SHA-1s | identify by SHA-1 only | | C8 | Kickstart file names | the loose `kick20.rom` holds 2.04 (37.175); `kick13.rom` and `kick10.rom` hold doubled 256 KB images | SHA-1 of the 256 KB or 512 KB image, never the name | ## Domains and speed Full page: [domains-and-speed.md](domains-and-speed.md). - **Domains:** M (68000, Agnus, Denise, Paula, CIAs, chip RAM: one locked clock, every chip-bus slot observable), D (the floppy drive: its own rotation), K (the keyboard: functional, or its 6500/1 on 6502-python). Producers beside M from `-fast` on: picture (Denise register log; CLXDAT reads are the catch) and sound (channel logs). - **Channels:** disk data and index (D -> M through Paula and CIA-B FLAG), drive status and control (CIA-A PA2-5, CIA-B PB0-7), keyboard serial and handshake (CIA-A SP/CNT), the picture and sound logs. - **Instructions per second, PAL A500:** the 68000 at 7,093,790 clocks a second and a typical 8-12 clocks an instruction: **0.6-0.9 M instructions** (ceiling 1.77 M). The custom chips: **3.55 M slot decisions** (227 CCKs x 15,625 lines), **4-14 M pixel operations** (14.19 M hires pixel times; 8.2 M visible in a hires picture), audio event-driven at <= 28,900 sample events a channel, disk 0.5 M cells while the motor runs, CIAs 1.42 M E ticks if stepped naively. The CPU is a small share; the chips' per-slot and per-pixel work is the cost. - **The no-JIT path:** amiga-python on PyPy about 1/3-1/6 of real time (by analogy with megadrive-python's 10-20 fps), enough for every gate; amiga-rust about 4-6x real time native (megadrive-rust: 4.1-6.3x, unoptimised), about half that as WebAssembly; amiga-rust-fast with D, K and sound on threads about 6-10x native and 3-6x in a desktop browser; phones at roughly 2-5x native and 1-3x in the browser at `-fast`, with `-turbo`'s whole-line Denise and slot-run paths for run-ahead. **Real time without a JIT on desktop, browser and phone; `recompile: none` everywhere**; no cached interpreter needed for the 68000. All of these figures are estimates by analogy, to be replaced by the board's own measurements. ## Open decisions for Aubrey (each with a recommendation) 1. **Scope and first machine.** Recommend the PAL A500 with Kickstart 1.3 (OCS) first, NTSC as a row from M1, ECS (A500+, A600) after the OCS gate at M8, A1000/A2000 as rows when wanted; AGA and CD32/CDTV later, each needing more than this board (a 68020 core, an AGA document, a CD-ROM side). 2. **The IPF reader.** Every library disk is IPF and SPS's decoder is non-commercial. Recommend our own MIT IPF reader in this board (M6), written from disk-utilities' Unlicense description of the container and from the files, checked by their own CRCs; the SPS library, if wanted as a detector, built only in a tool repository whose terms allow it (a new `emu-tools-noncommercial`? or not at all). Extract the reader when an Atari ST board needs it. 3. **vAmigaTS (GPL-3.0) as the tier-3 judge.** Its test programs and real-Amiga screenshots are the best evidence for the custom chips. Running a GPL program and comparing with its published images does not touch our licence, but the brief says no GPL source is fetched into an MIT repository. Recommend fetching and pinning it in **emu-tools-gpl** (a `tools/vamigats/` folder: the ADFs, the screenshots, a runner that boots each ADF on our board and reports per-case pixel differences), with amiga-python reading only its results through `EMU_TOOLS_GPL`; never opening the test sources while writing board code beyond what the screenshots and the suite's own case names show. 4. **vAmiga's MPL-2.0 core.** Recommend closed box only, like the GPL emulators (never read while writing the board), even though MPL would allow reading: transcription would bring MPL file-level copyleft into MIT files, and keeping it closed avoids any doubt. Moira (vAmiga's MIT 68000 core) is separately a candidate fourth lineage for m68000-python, to raise there. 5. **WinUAE as a whole-machine detector.** Recommend yes, later (M3+), built in emu-tools-gpl2 beside the existing cputest tool, as a second detector after MAME for chip-set timing (never a judge, never read). 6. **The keyboard.** Recommend a functional keyboard (the serial protocol into CIA-A) first; run the 6570-036 MCU on 6502-python only if a program depends on its timing. 7. **AROS in CI.** Recommend pinning one AROS m68k ROM release by SHA-256 into `reference/` (never committed) at M7 so CI has a redistributable boot program, since no Kickstart can be fetched; its APL/LGPL terms recorded beside the pin. 8. **AGA and the 68020.** Recommend deferring: an AGA row needs a `m68020-python` core (its own Phase 0; the 68EC020's cache and 32-bit bus) and an AGA register document we have not found (U18). 9. **Amiga Test Kit readings.** Its tests print measured values; they become tier-3 evidence only with readings from real units. Recommend asking whether Aubrey knows anyone with an A500 who could run its CIA, floppy and video tests once (a probe batch, per his probe-batching habit), or accepting it as a program to run. 10. **Request to m68000-python:** a documented VPA/E-clock helper for data cycles (cpu-cores.md, request 1). Recommend raising it with a repro before M1 closes, as fixes start upstream. 11. **sources.md rows:** the nine proposed rows in [sources.md](sources.md) ("Proposed rows"), for Aubrey or a lineage pass to add.