# Handoff: build `x68000-python`, the Sharp X68000 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 and is extracted only when a second family project needs it; 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 X68000 is era 2 in the charter's table in all but name: one 16-bit CPU at 10-16 MHz with a DMA controller on its bus, custom video, FM and ADPCM sound, floppy and hard disk; cycle-lockstep is affordable; `-fast` needed for phones; threads optional (video). Boards to model this one on: **megadrive-python** (an m68000-python core on a board bus, DMA that stops the 68000, sockets, save states), **amiga-python**'s Phase 0 (another 68000 computer with DMA and floppies; its decision 8 names the future 68020 core), **zxspectrum-python** and **sms-python** (the uPD765 family), **saturn-python** (a boot ROM as the first test program, the brief's structure). Cores it embeds, read and not touched by this phase: **m68000-python** (pin its main; read at `55d3d60`) and **ym2151-python** (still Phase 0, no core: read at `3207328`). Read in order before writing code: 1. [README.md](../README.md), [start-here.md](start-here.md), [memory-map.md](memory-map.md). 2. The chips: [video.md](video.md), [dmac.md](dmac.md), [mfp-keyboard-mouse.md](mfp-keyboard-mouse.md), [fdc.md](fdc.md), [scsi-sasi.md](scsi-sasi.md), [sound.md](sound.md), [firmware.md](firmware.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). Then `python -I scripts/fetch_references.py` (13 files, about 130 MB; `--verify` to check). Text versions of every PDF land in `reference/text/` for grepping; check any fact that rests on a table or figure against the page image (`pdftoppm`), as this phase did for the DMAC's register map and the uPD72065's Version answer. ## Decided by Aubrey (standing rules that apply here) - Name `x68000-python`, package `x68000_python` (the x-python naming rule). - Local, no remote, until he says otherwise. Bring your own IPL ROM, CGROM and disks; nothing of Sharp's, Hudson's or any publisher's in the repository; firmware by SHA-1. - Python floor = PyPy's (3.11), PyPy must work; modern over compat; reference boards are correct, not fast; sound may be less exact than pictures; smoke lists before sweeps. - Technical choices are made, marked provisional and reported; policy waits for him. - MAME's x68k driver is a closed box (this Phase 0's brief), whatever its BSD headers say, until decision 8 is taken. ## Proposed by this Phase 0 - **The original X68000 first** (row `x68000`), with the IPL ROM V1.0 87/05/07 (in MAME and TOSEC) and the CZ-600CE V1.0 (MAME's default) both accepted by SHA-1; ACE, EXPERT and PRO as rows (RAM size, internal SASI disk); SUPER, XVI and Compact later (SCSI, 16 MHz, 3.5" drives); X68030 deferred (decision 2). - **The IPL ROM is the first test program**: run it, trace its bus, compare with MAME's trace; **never disassemble it** (firmware.md: the free release's "no analysis" clause, decision 7). - **Domains** C (CPU, DMAC, MFP and the rest of the bus), V (video), S (sound), D (disk), K (serial devices), R (clock), with the channels of [domains-and-speed.md](domains-and-speed.md) first-class from milestone 1. - **DMA arbitration at instruction boundaries first** (provisional; decision 3). - **The keyboard and mouse functional** at their serial lines (their MCUs are not dumped). - **The mouse on the SCC's channel B**, not the MFP (OBSERVED; C1). ## Package and classes (proposed) ``` x68000_python/ machine.py # machine rows: model, CPU clock, RAM size, disk interface, IPL/CGROM/SCSI ROM SHA-1s console.py # build(machine, disks=(), hd=None, firmware_dir=...) -> X68000 bus.py # the 24-bit map, wait states, BERR for absent RAM and boards, the area set, function codes ioc.py # the I/O controller (FDC, FDD, HD, printer interrupts; vector base) sysport.py # E8E000 system port; SRAM lock sram.py # 16 KB battery SRAM with a documented default image (never a copied one) mfp.py # Mfp (MC68901): GPIP, 16 channels, timers A-D, USART dmac.py # Dmac (HD63450): 4 channels, chaining, cycle steal, NIV/EIV crtc.py # Crtc (VINAS): R00-R24, timing, raster interrupt, raster copy, fast clear videoctl.py # VideoController (VSOP/VICON): R0-R2, priority, half-tone; palettes sprites.py # Cynthia: 128 sprites, BG0/BG1, PCG compose.py # the planes: text, graphics pages, sprites, BG -> one line of pixels scc.py # Scc (Z8530): register side; line side to K rtc.py # Rp5c15 ppi.py # Ppi8255: joysticks, ADPCM rate and pan keyboard.py # functional keyboard MCU at the USART line mouse.py # functional mouse at SCC channel B fdc.py # wraps upd765_python (decision 4) as the uPD72065; drive control ports floppy.py # drives and images: DIM, XDF, D88, HDM; later flux (KryoFlux raw, HFE, SCP) sasi.py # SASI interface and target; spc.py: MB89352 (SUPER and later) msm6258.py # Msm6258: MPU interface, ADPCM decode, DMA-fed sound.py # SoundDomain: the ym2151_python socket + Msm6258 + mixing sockets.py # the socket Protocols and their test-only fakes savestate.py # whole-machine states naming firmware and disks by hash ``` ## What the board needs from its cores (the embedding contracts) From **m68000-python** (cpu-cores.md has the table): 1. Bus callbacks with function codes (exists), the board adding wait states (the core models none). 2. Vectored interrupt acknowledge (exists) for the MFP, SCC, DMAC and I/O controller; NMI autovectored. 3. Bus errors from the host on every access to absent RAM or boards (exists; the frame's open edge against WinUAE is the corner to watch: raise any IPL/Human68k difference upstream with a repro). 4. A way to let the DMAC take the bus: provisional at instruction boundaries using `step_clocks`; a bus-cycle stall is the upstream request if tests demand it (decision 3). From **ym2151-python** (when its core exists): any input clock, /IRQ as a live line, the CT outputs readable on every change (its users.md lists all three for the X68000). From a future **upd765-python** (decision 4): the uPD72065 as a part variant (Version 80H, Software Reset, Set/Reset Standby, 255-track Recalibrate, the non-B overrun and DRQ quirks), a DMA socket (DRQ out, DACK and TC in), four drives, drive READY as an input the board drives (here from the OPM's CT1). ## The gate (defined at milestone 1) The board's lockstep cases (the IPL ROM's instruction stream and its I/O access sequence against MAME's trace, `0 unexplained` over a fixed number of frames, or a named reason per difference), unit tests of each data-sheet fact (MFP prescalers and vectors, DMAC register map, uPD72065 Version, MSM6258 dividers), and later picture rows against the detectors. Seeded faults: validation.md's list. ## Milestones | # | Milestone | Judge (tier) | Exit | | --- | --- | --- | --- | | M1 | **Bus, 68000, IPL ROM and CGROM by SHA-1, SRAM, area set, system port, I/O controller, interrupts and bus errors; MFP complete (timers, USART at byte level); CRTC timing skeleton (V-DISP, H-SYNC, CIRQ edges); register files for the video controller, CYNTHIA, DMAC, FDC (no drives), SCC, RTC, PPI; OPM and ADPCM stubs; the sockets and fakes** | MFP (2); MAME trace (5) as detector | the IPL (V1.0 87/05/07 and CZ-600CE) runs 60 frames with its instruction stream and I/O accesses equal to MAME's, or a named reason for each difference; MFP data-sheet facts as unit tests | | M2 | **The text plane, palettes and the CGROM**: the IPL's "cannot boot from disk" screen | video: none above tier 5 (U1) | the screen drawn; every pixel difference with MAME's snapshot triaged | | M3 | **DMAC transfers** (cycle steal, chaining), the keyboard and mouse functional | DMAC-H/M/AN (2) | the IPL's key handling (e.g. its boot-menu keys) works; DMAC unit tests of each mode from the data sheet's examples | | M4 | **Graphics planes, sprites, BG, video-controller priority and half-tone** | detectors (5) | a curated set of title screens (smoke list from the software list's names) drawn; differences triaged; U9-U11 cases logged | | M5 | **Floppies**: upd765-python as the uPD72065 (or in-board, by decision 4), DMA channel 0, drives, DIM/XDF/D88/HDM | FDC72065, FDC765 (2) | Human68k 3.02 (the player's own disk, by SHA-1 from TOSEC's set) boots to its prompt; DIR and COPY between two drives work | | M6 | **Sound**: ym2151-python pinned, the MSM6258 with DMA channel 3, the PPI and CT2 controls | ym2151-python's ladder; ADPCM (2) | a game's music and voice play; compared with detectors' audio, differences named (good-enough rule) | | M7 | **The smoke list** (problem titles and well-behaved ones: MAME's 51 partial and 64 unsupported entries are candidates) grown from failures | programs | the smoke list reaches gameplay | | M8 | **Hard disks and the later models**: SASI with a blank image formatted by Human68k's FORMAT; SUPER and XVI rows with the MB89352 and their SCSI ROMs; 16 MHz | SASI, SPC (2) | Human68k installs to and boots from a SASI image and a SCSI image | | M9 | **Flux images and save states**: KryoFlux raw (the No-Intro TwinBee), HFE, SCP; whole-machine states | programs | the flux TwinBee boots; a save state loads into a fresh machine and continues identically | | M10 | **X68030** (only by decision 2) | the 68030 core's ladder | the IPL V1.3 reaches its screen on the 68EC030 | Full TOSEC sweeps only when the board might be ready (the smoke-sweep rule). ## Unknowns (U) and conflicts (C) | # | Unknown | Best source now | Status | | --- | --- | --- | --- | | U1 | Register meanings of the Sharp custom chips (CRTC, video controller, CYNTHIA) and the X68000-specific ports | none usable in hand (*Inside X68000*, Sharp's technical documents: decision 11) | HYPOTHESIS; detectors | | U2 | MFP GPIP wiring beyond GPIP 3 | community; MAME | HYPOTHESIS | | U3 | DMAC channel wiring (channel 3 = ADPCM partly OBSERVED) | the IPL's set-up | HYPOTHESIS | | U4 | Bus errors in normal boot (memory and board sizing) | none read | HYPOTHESIS; watch the trace | | U5 | DMA arbitration latency and granularity on this board | DMAC timing diagrams | provisional (decision 3) | | U6 | Wait states per region, per model (10/16 MHz) | none | FITTED | | U7 | The USART's clock: Timer B's output (2,404 bit/s by arithmetic) | the IPL's values | HYPOTHESIS | | U8 | The keyboard's protocol and command set | MAME's log lines | HYPOTHESIS | | U9 | Sprites per line, sprite/BG fetch timing, CYNTHIA's timing registers against the CRTC | community | detectors | | U10 | Raster copy and fast clear: duration, what the CPU sees | none | detectors | | U11 | Half-tone and special-priority arithmetic | none | detectors | | U12 | Dot clocks per mode, the 24 kHz modes, the frame rate before the IPL programs the CRTC | MAME's two clocks | HYPOTHESIS | | U13 | RP5C15 against msx-python's RP5C01: how close | the two data sheets | check when either is built | | U14 | System-port and I/O-controller bits | MAME trace values | HYPOTHESIS | | U15 | The SCC's baud clock source; the mouse protocol | the IPL's values; SCC manual | HYPOTHESIS | | U16 | The FDC drive-control ports E94005, E94007 | the IPL's writes | HYPOTHESIS | | U17 | Which uPD72065 revision the models carry (non-B quirks: overrun bit, DRQ reset) | FDC72065 p. 5-54 | open | | U18 | The SASI interface's registers | none | HYPOTHESIS | | U19 | The SASI commands the IPL issues (SPECIFY is vendor-specific) | MAME's log | read from the IPL's traffic | | U20 | MB89352 against MB87030 compatibility | MB87030 manual only | HYPOTHESIS | | U21 | The MSM6258 MPU version's command bits | not in the data book's text layer | read the page images | | U22 | Analogue mixing of OPM and ADPCM | none | FITTED (good-enough rule) | | U23 | SRAM's default contents and layout | none | build from the IPL's behaviour on an empty SRAM | | U24 | The FSHARP terms' primary text; which SHA-1s are the free-release images | XEiJ's summary | ask (decision 7) | | U25 | Crystal relationships between the domains | MAME's clocks | HYPOTHESIS | | U26 | Any hardware-verified X68000 test suite | none found | search again before M4 | | # | Conflict | Sides | Proposal | | --- | --- | --- | --- | | C1 | Where the mouse is | the brief: "keyboard and mouse via the MFP's USART"; the IPL programs the SCC's channel B and MAME has a separate mouse port (OBSERVED) | the keyboard on the MFP USART, the mouse on SCC channel B | | C2 | The X68030's CPU | community: MC68EC030; MAME's device list: "MC68030" | the EC part (no MMU) unless a board photograph or Sharp document says otherwise | | C3 | Frame rate | 55.45 Hz from the IPL's CRTC values and MAME's screen clock; 55.9 Hz average over MAME's first 60 frames | the programmed value; the early frames are U12 | | C4 | MAME's BSD-3-Clause x68k driver | ym2151-python's users.md cites its lines; this brief treats it as a closed box | decision 8 | ## Domains and speed (Full page: [domains-and-speed.md](domains-and-speed.md).) - **Domains**: C (68000, RAM, ROMs, SRAM, DMAC, MFP, I/O controller, system port, PPI, SCC registers), V (CRTC, video controller, CYNTHIA, palettes, VRAMs), S (YM2151, MSM6258), D (FDC and drives; SASI or SPC and targets), K (keyboard, mouse lines), R (RTC). The DMAC and MFP stay in C because they touch the CPU's bus on nearly every cycle (10,444 MFP reads in the IPL's first second). - **Channels**: VRAM and register accesses C -> V; V-DISP, CIRQ, H-SYNC V -> C (MFP); OPM ports and /IRQ; ADPCM DMA requests at fsample/2 and the PPI/CT2 rate controls; OPM CT1 -> FDC ready; FDC and hard-disk registers, DMA requests and interrupts; USART and SCC bytes; RTC and its alarm; NMI. - **Instructions a second**: 10 MHz / (8-12 clocks an instruction) = 0.83-1.25 M for the 10 MHz models (the IPL measured 12.3 clocks an instruction over 875,417 instructions); 16 MHz / (8-12) = 1.33-2.0 M for the XVI and Compact; 5-8 M for the X68030's 68EC030 at 3-5 clocks (HYPOTHESIS). Video: 768 x 512 x 55.45 Hz = 21.8 M pixels a second, up to about 110 M layer-pixel steps at worst. Sound: 62.5 kHz x 32 slots = 2 M slot steps. - **The no-JIT path**: Rust -fast alone reaches real time. m68000-rust-fast runs 112-191 M instructions a second on this desktop (90-150x the need); a phone at a third to a quarter (HYPOTHESIS) still has more than 25x; the browser (wasm, about 112 M under Node against 134 M native, m68000-rust-fast's README) is within 20 % of desktop. Video is the only tight spot, on phones in the heaviest modes: the planned margin is the V domain on its own thread fed by a register-write log. **`recompile: none` on every target**; no cached interpreter or turbo foreseen. The X68030 row, at 5-8 M instructions a second, is within a -fast interpreter's reach (to be measured when its core exists). ## Open decisions for Aubrey (each with a recommendation) 1. **Scope and first machine.** Recommend the original X68000 row first, accepting the IPL V1.0 87/05/07 and the CZ-600CE V1.0 by SHA-1; ACE, EXPERT, PRO as rows from milestone 1 (RAM size, internal SASI); SUPER, XVI, Compact at M8. 2. **The X68030.** Recommend deferring it, and when it comes, one Phase 0 for `m68020-python` (68020/68EC020/68030/68EC030 as variants, the FPU as a coprocessor socket), shared with amiga-python's AGA rows (its decision 8). 3. **DMA arbitration.** Recommend instruction-boundary arbitration first, tagged HYPOTHESIS, and an upstream request to m68000-python for a bus-cycle stall only when a test shows the difference. 4. **The uPD765 extraction.** Recommend extracting `upd765-python` from sms-python with history (zxspectrum-python's decision 3), with the uPD72065 as a part variant and DMA as a socket: five family boards want it. The X68000 needs it at M5, not before. 5. **The MFP.** Recommend it stays in the board behind a pin-shaped class; extract as `mc68901-python` if an Atari ST board ever starts (its second user). 6. **The MSM6258.** Recommend it stays in the board; no shared "OKI ADPCM step" core with msm6295-python and pcenginecd-python's MSM5205 (a dozen lines; the chips differ in everything around it). 7. **Firmware and the FSHARP free release.** Recommend keeping "never ship" unchanged, and adopting as a rule that the board never disassembles or describes the IPL ROM's code (the release's terms, as XEiJ summarises them, forbid analysis), learning only from running it and tracing its bus. If Aubrey has the primary FSHARP text, it settles U24. 8. **MAME's BSD-3-Clause X68000 files.** Their headers allow reading with notice; this brief made them a closed box, as the PlayStation brief did. Recommend keeping them closed for the board (the specification stays independent of MAME's model, which is a detector), and recording that ym2151-python's users.md already cites `x68k.cpp` lines, which is consistent with the licence but not with a closed-box rule; Aubrey to say which rule holds family-wide. 9. **bitsavers.** bitsavers.org answers curl's default agent with 403; this phase fetched the same files from the trailing-edge mirror with curl's own agent. Not an anti-AI rule by its wording, but close to "working around": recommend Aubrey confirm the mirror is acceptable (or fetch the 12 files himself and verify them by the pinned SHA-256s). 10. **`TOSEC_DIR`.** Recommend adding it to the family profile (the directory holding TOSEC's trees), as REDUMP_DIR was added; zxspectrum-python proposed a narrower `SPECTRUM_TOSEC_DIR`, and one variable for TOSEC would serve both. 11. **_Inside X68000_.** The single biggest evidence upgrade for the video chips (tier 5 to tier 2). Recommend asking whether Aubrey owns or will buy a copy (or Sharp's technical documentation); facts only, cited by page, never re-hosted. 12. **sources.md rows** (emulator-lineage; facts may be added by anyone, but this report proposes rather than edits): - "Motorola MC68901 MFP and MC68450 DMAC data sheets; Hitachi HD63450 (1987 peripheral LSI data book) and HD68450 application notes; NEC uPD765 data sheet and AN-08, and the 1989 Intelligent Peripheral Devices data book (uPD72065); OKI 1987 voice synthesis data book (MSM6258); Fujitsu MB87030 SPC manual; Zilog Z8530 SCC manual; Ricoh 1988 data book (RP5C15); Shugart SASI specification rev F: makers' documents, facts only, cited by document and page (bitsavers, trailing-edge mirror)". - "MAME `hash/x68k_flop.xml`: CC0-1.0 (covered by the software-lists row)". - "MAME X68000 files (`sharp/x68k*.cpp`, `mc68901.cpp`, `hd63450.cpp`, `upd765.cpp`, `mb87030.cpp`, `rp5c15.cpp`, `okim6258.cpp`, `x68k_scsiext.cpp`): BSD-3-Clause by their `license:` lines (read 2026-11-26 at `mame0285`); closed box by the X68000 brief, decision pending". - "XEiJ (Makoto Kamada): own licence, free distribution with source: closed box only; its site's documents facts only". - "XM6 / XM6 TypeG / XM6i / XM6 Pro-68k: licence not established: closed box only". - "px68k (kenyahiro, hissorii, sokoide): no licence detected: closed box only; px68k-libretro: GPL-2.0: closed box only". - "MiSTer X68000 core: GPL-3.0: closed box only"; "run68x (kg68k): GPL-2.0: closed box only"; "yosshin4004/x68k_xsp: Apache-2.0: code OK (with notice)". - "datacrystal.tcrf.net and chibiakumas.com: set aside (site's wishes): robots.txt disallows ClaudeBot and anthropic-ai". 13. **Upstream note to m68000-python** (no change requested yet): the X68000 makes bus errors routine at boot. Recommend telling its next session so that any bus-error frame difference found by this board is expected and handled there first.