# Handoff brief: pico-python For the session that builds the board. Read [start-here.md](start-here.md) and [shape.md](shape.md) first; this brief assumes both. ## Scope A readable, pure-Python Sega Pico: the 68000, the VDP and its PSG reused from the family, the Pico's own I/O block, pen, buttons and page sensors, the 315-5641 ADPCM path, the interrupt merge, the storyware cartridge, and a window that shows the drawing pad and the open page. Rows `pico`, `picou`, `picoj`, `picok`, and later `copera`. Not in scope: the Beena (a separate board later), the Keyboard Pico and other accessories until a source describes them. ## Names - Repository `pico-python`, package `pico_python` (family rule: x-python imports as x_python). - `machine.py`: `PicoMachine` (frozen dataclass: name, pal, version bits, PCM clock, cartridge kind) and `MACHINES` with `pico`, `picou`, `picoj`, `picok`, `copera`. - `board.py`: `PicoBoard`, the 68000's map; implements megadrive-python's `VDPHost`. - `io.py`: `PicoIO` (the $800000-$80001F block), `Pen`, `Buttons`, `PageSensors`. - `pcm.py`: `Pcm5641`, the FIFO, control and interrupt wrapper around an ADPCM core behind `PcmSocket`. - `cartridge.py`: `Storyware` (plain ROM; a hook for a cartridge-side device). - `system.py`: `PicoSystem`, the 68000-led scheduler, with no Z80. - `frontend.py`: the window (pad and page panels, page images from `$PICO_PAGES_DIR`). ## The import boundary | Owner | What | | --- | --- | | m68000-python (pinned at the commit megadrive-python pins) | the CPU: instructions, exceptions, `set_ipl`, autovectors, the access clock | | megadrive-python (pinned) | `VDP` and `Renderer`, through the `VDPHost` protocol and a VDP-only config (its items 1-3 in [shape.md](shape.md)) | | sn76489-python | the PSG (`SEGA_VDP_PSG`), reached through the VDP as on the Mega Drive | | upd7759-python (proposed, open decision 3) | the ADPCM decoder and the uPD7759's slave-mode handshake | | pico-python | the map, the I/O block, the pen/page/button state, the FIFO and its interrupt, the IPL merge, the cartridge, the mixer, the scheduler, the machines, the frontend | Never copy code from megadrive-python: import it by pin. A VDP behaviour the Pico shows differently is raised on megadrive-python (or the extracted VDP core), not patched here. ## Sockets (board-internal Protocols) | Socket | Filled by | Empty means | | --- | --- | --- | | `PcmSocket` | `Pcm5641` over upd7759-python | silence; $800010 reads a fixed free count, $800012 not busy | | `CartridgeDevice` | the Keyboard Pico's cartridge, later | plain ROM | | `CoperaExtras` | nothing yet (U17) | the Copera runs as a Pico with a 640 kHz PCM | | `PageImages` (host side) | `$PICO_PAGES_DIR//` | numbered placeholders | ## Unknowns - U1. What $400000-$7FFFFF and $800020-$BFFFFF return (open bus, a mirror, or a hang). - U2. VDP and work-RAM mirrors (PICODOC: "may be mirrored elsewhere"). - U3. The 315-5769's role ("possibly I/O controller", JSK). - U4. What drives IPL levels 2, 3 and 5, and how it merges with the VDP's levels 4 and 6. - U5. The 315-5641's clock: its own resonator or MCLK/42; MAME's 1.28 MHz. - U6. $800003 bits 5-6 (PICODOC "unused?"; MAME returns 0). - U7. $80000F (read once by a Copera title). - U8. $800017 (written $40 at start-up by Sonic's Gameworld). - U9. Bus timing: the cartridge-refresh stall, I/O wait states, DMA from ROM, any MC68HC000 difference that software can see. - U10. The pen's value when lifted or out of range; hover against touch. - U11. The 315-5640's scan rate and whether X and Y can be read from different scans. - U12. Each storyware's printed margins against the coordinate band (page-image calibration). - U13. Keyboard Pico, PC link kit, the early units' expansion and EXT ports. - U14. What the 315-5641 is (a uPD7759 inside?), its FIFO depth, its control bits. - U15. The ADPCM decoder itself (no NEC document gives it; system16-python's U11). - U16. Korean version bits; whether any cartridge refuses a region. - U17. The Copera: its cartridges' boot (no header, SP=0, PC=$400) and its extra hardware. - U18. The Beena's AP2010 instruction set. - U19. Three Japanese dumps whose reset vectors cannot start a 68000. - U20. Whether the "SEGA" writes to $800019-$80001F gate anything (a TMSS-like lock). ## Contradictions - C1. NEC's uPD7759 runs at 630-650 kHz and samples at 5, 6 or 8 kHz (DS7759 pp. 1, 6); MAME clocks the Pico's 315-5641 at 1.28 MHz and PICODOC guesses "16kHz variants". Either the 315-5641 is not a plain uPD7759, or it runs one at twice NEC's clock (pcm.md). - C2. The page register: PICODOC's thermometer code $00-$3F, against MAME's idle $92 (Pico rows) and $33 (Copera). Bits 6-7 at least carry something PICODOC does not name, or MAME is wrong. - C3. PICODOC: a read of $800012 with bit 15 clear means busy, and games "wait for it to become 1". Under MAME, Sonic's Gameworld writes $8000 itself before and after its data; whether bit 15 is a status, a command, or both is open. - C4. Button colours: PICODOC's blue against purple on JSK's and UMFR's units (by model; harmless to software). ## Milestones (each with its exit test) | | Milestone | Exit test | | --- | --- | --- | | M0 | In megadrive-python, behind its gate: the `VDPHost` protocol, the VDP-only config, the refresh hooks the host's (shape.md items 1-3); pin it here | megadrive-python's gate moves 0 rows; a test there hosts the VDP from a minimal non-Mega-Drive host | | M1 | `PicoBoard` + `PicoSystem`: 68000, VDP, RAM, cartridge, the I/O block answering idle values, the "SEGA" bytes, IPL from the VDP only | 10 storyware (Magic Crayons, Sonic's Gameworld, Tails and the Music Maker among them) reach their title screens; a 68000 lockstep against MAME with MAME's I/O reads replayed: every instruction of 2 emulated seconds identical on 3 cartridges, or each difference named | | M2 | Pen, buttons, pages from scripted inputs | Magic Crayons draws along a scripted pen path; stepping the page changes activity in 3 titles (the game's own behaviour is the judge; MAME with the same script is a detector) | | M3 | Sound: the PSG through the VDP | a WAV; the PSG write log identical to MAME's for the same run | | M4 | upd7759-python's slave mode and decoder (decision 3), `Pcm5641` with its FIFO and the level-3 interrupt (labelled HYPOTHESIS) | speech in Sonic's Gameworld is intelligible; the core's handshake rung passes against DS7759's slave-mode timing; every 315-5641 choice cites its evidence | | M5 | The window: pad and page panels, page images, page controls; save states in megadrive-python's form | a person plays one storyware through; 20 save/load round trips continue identically | | M6 | Rows: `pico`, `picou`, `picoj`, `picok`, `copera` | a curated smoke group (20 titles, including the 3 with MAME page scans, 2 Korean, 2 Copera) boots on the right row; no full sweep until the smoke group passes | ## Domains and speed Summarised from [domains-and-speed.md](domains-and-speed.md): - **Domains**: D1 the main bus on MCLK (68000, VDP and PSG, I/O registers, cartridge); D2 the 315-5641 on its own clock (1.28 MHz per MAME); D3 the tablet, sensors and buttons as latched host inputs. **Channels**: $800010 writes (FIFO), $800010/$800012 reads (free count, busy), $800012 writes (control), IPL level 3, the audio samples, and the input registers at $800003-$80000D. Order of record: 68000-led, the PCM caught up before any access to its registers and before IPL is sampled. - **Instructions a second**: 68000 at 7,670,453 Hz; measured 2,047,512 instructions in 120 NTSC frames under MAME = 1.02 M a second (ceiling 1.92 M at 4 clocks each). VDP: 262 x 3,420 MCLK x 59.92 = MCLK; 3.4-4.3 M visible pixels a second. PSG 224 k steps a second; PCM at most 16 k samples a second. No Z80, no YM2612: a strict subset of the Mega Drive's work. - **No-JIT path**: `recompile: none`. Desktop Python close to real time (megadrive-python makes 40-55 fps with more work); desktop Rust 4-6x real time (megadrive-rust with Z80 and FM); phone and browser real time on the evidence of play-md (about 4.3 ms a frame in Chromium, played on an iPhone). No `-fast`, cached interpreter or threads needed on this evidence. ## Open decisions for Aubrey 1. **Shape.** A separate `pico-python` board that reuses megadrive-python's VDP by pin (option C), rather than a machine row or a socket device on megadrive-python (options A and B in shape.md). **Recommend option C**: the Pico removes four Mega Drive parts and adds an interrupt source the sockets deliberately left out. 2. **The VDP's interface and extraction.** megadrive-python gains a `VDPHost` protocol and a VDP-only config (M0) now; the chip rule then points to extracting the VDP into its own core (`ym7101-python`, say) with history, pinned by megadrive-python, pico-python and later system16-python's System 18 row. **Recommend**: M0 now; extract when the second host reaches its video milestone, so the interface is proven before it moves. 3. **A shared `upd7759-python` core** with system16-python (System 16B), the decoder's provenance decided once for both (system16-python's open decision 3: whether MAME's BSD-3 `upd7759.cpp` may be read for facts with its notice). **Recommend**: create the core when the first of the two boards reaches its sound milestone; keep the 315-5641's FIFO and interrupt in pico-python until a source puts them on the same die. 4. **MAME's BSD-3 `segapico.cpp`.** The brief keeps it closed; its `license:` line says BSD-3-Clause. **Recommend**: keep it closed through M1-M3 (PICODOC and the games' behaviour suffice); revisit at M4 only if the 315-5641 cannot be pinned down otherwise, reading it then for facts with its notice kept, as pcenginecd-python did with `msm5205.cpp`. 5. **The Beena.** **Recommend** a separate `beena-python` board after its own Phase 0 (ARM-class SoC, its own firmware, nothing shared with the Mega Drive), on arm7tdmi-python if the AP2010 proves to be an ARM7TDMI; listed here only as the later row of the Pico line. 6. **The Copera.** **Recommend** a `copera` row in pico-python at M6 with an empty `CoperaExtras` socket, until a respect-clean source describes its extra hardware (the only description met is on vgmrips.net, set aside). 7. **Storyware page images.** **Recommend** a host-side `$PICO_PAGES_DIR//` of the player's own scans, never shipped or fetched, with numbered placeholders when absent. 8. **Rust tiers.** **Recommend** none until M5; then `pico-rust` pinning megadrive-rust for the VDP, and no `-fast` unless a measured target needs it. 9. **smspower.org and the other blocked sites.** smspower.org's robots.txt now disallows ClaudeBot (as do tcrf.net, consolemods.org and sonicretro.org), and sms-python cites its wiki pages. **Recommend**: record them as set aside (site's wishes) in the family's sources.md; facts sms-python already holds stay cited as they are, nothing new is fetched, and you decide whether those citations need a second source.