# Handoff: build `bbcmicro-python`, the Acorn BBC Micro 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 this repository's [start-here.md](start-here.md). The BBC Micro is era 1 in the charter's table: one clock domain, cycle level everywhere, Python runs the tests, Rust plays. Boards to model this one on: **a2600-python** (a 6502-python board, one domain, a video chip stepped per clock), **famicom-python** (6502-python with its own timing quirks and a large mapper table, like the BBC's paging and machine rows), **sms-python** (sn76489-python embedded). Cores it embeds, read and not touched by this phase: **6502-python**, **w65c02-python**, **sn76489-python**. Read in order before writing code: 1. [README.md](../README.md), [start-here.md](start-here.md), [timing.md](timing.md), [memory-map.md](memory-map.md). 2. The chips: [via6522.md](via6522.md), [crtc6845.md](crtc6845.md), [video-ula.md](video-ula.md), [saa5050.md](saa5050.md), [sound.md](sound.md), [discs.md](discs.md), [adc-serial-tape.md](adc-serial-tape.md). 3. [cpu-and-reuse.md](cpu-and-reuse.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` (21 files, 64 MB to download, 83 MB unpacked, and one blobless sparse repository; `--verify` to check). Text versions of the PDFs and RTFs are in `reference/text/`, OCR of the TIFF data sheets in `reference/text/ocr/` (the fetch script makes the PDF text; the RTF and OCR text were made by hand in this phase: redo with `tesseract` and any RTF-to-text tool if missing). ## Decided by Aubrey (standing rules that apply here) - Name `bbcmicro-python`, package `bbcmicro_python` (the x-python naming rule). - Local, no remote, until he says otherwise. Bring your own ROMs and discs; nothing of Acorn's in the repository. - 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. ## Proposed by this Phase 0 - **Model B first** (`bbc-b`: OS 1.20, BASIC II, optional 8271 + Acorn DFS), with the Model A (16 KB, &3C00 teletext base) as a parameter of the same row; **B+** (`bbc-bplus`, 6512A, shadow RAM, 1770) and **Master 128** (`bbc-master`, G65SC12, ACCCON, CMOS RTC) as later rows. The Electron is a different machine (its own ULA): not a row. - **One timeline in 16 MHz ticks**, one domain, with cycle stretching as a board rule ([timing.md](timing.md)). - **Two new chip cores before the board needs them**: `mos6522-python` (with the Vectrex) and `crtc6845-python` (with the Amstrad CPC): open decisions 1 and 2. - **Firmware and the SAA5050's glyphs supplied by the player**, identified by SHA-1 ([census.md](census.md); open decision 5). ## Package and classes (proposed) ``` bbcmicro_python/ machine.py # machine rows: CPU part, RAM size, ROM sockets and links, FDC fitted, # firmware SHA-1s, the slow-device table, the teletext base console.py # build(machine, roms=..., disc=None, tape=None) -> Bbc clock.py # the 16 MHz timeline: 2 MHz CPU cycles, 1MHzE phase, the stretch rule bus.py # memory map, FRED/JIM/SHEILA decode, open-bus policy (U5) paging.py # ROMSEL (&FE30) and, per row, the B+ PAL (&FE34) and Master ACCCON sysvia.py # the system VIA's wiring: slow data bus, IC32 latch, keyboard, CA1/CB1/CB2 keyboard.py # the matrix, autoscan counter, links (start-up options) video.py # the address path (MA/RA -> RAM, wrap adder, mode 7 map, shadow), DISPEN delay vidula.py # VideoUla: control, palette, serialiser, cursor, flash saa5050.py # Saa5050: control codes, cells, rounding, double height (no BBC names inside) serial.py # SerialUla + the MC6850 (in-board until a second user), tape, RS423 socket adc.py # Upd7002, the analogue port socket fdc8271.py # I8271 (transaction level) + drive model fdc1770.py # Wd1770 (rows 2-3) + drive model disc.py # SSD/DSD sector source, later HFE sockets.py # the socket Protocols (analogue, user port, printer, 1 MHz bus, Tube, # speech, Econet, cartridges) and their test-only fakes savestate.py # whole-machine states naming ROMs and discs by hash ``` Cores from pins: `sixfiveohtwo.MOS6502` (6502-python `828b619`), `w65c02_python.G65SC02` (w65c02-python `fca677f`), `sn76489_python.SN76489` with `SN76489AN` (sn76489-python `1379eff`), and, by decisions 1-2, `mos6522_python` and `crtc6845_python`. ## The import boundary The board owns the clock, the decode, the paging, the wiring of every pin (the latch, the slow bus, the video address path), the machine rows and the sockets. Cores own their chips and know nothing of the BBC: no BBC names, addresses or modes inside a core. The in-board chips (Video ULA, SAA5050, serial ULA, uPD7002, 8271, 1770, MC6850) are written the same way (no `Bbc` import), each with an import-boundary test, so extraction is a move. ## What the board needs from its cores (the embedding contracts) From **6502-python / w65c02-python**: (1) one callback per bus cycle, inside which the board may advance time (exists); (2) host-driven IRQ/NMI/RESET lines, with a stated rule for a line set during a callback (to confirm; judged by `O.VPOLL`, `O.VIA.I1`, `O.VIA.I2`); (3) **SYNC visible in the callback**: w65c02-python has it, 6502-python `828b619` does not, needed for row 2 (open decision 8). From **sn76489-python**: `write(value)` at the latch's falling edge and `run(clocks)` at 4 MHz (exist). From **mos6522-python** (to be built): registers, timers, shift register, CA/CB modes, `tick()` per 1 MHz phi2 edge, pin callbacks, IRQ out; the BBC's two instances wired by the board. From **crtc6845-python** (to be built): `clock()` per character; MA, RA, DISPEN, HSYNC, VSYNC, CURSOR out; LPSTB and the bus side in; variant rows (cpc-python's proposed interface, which this board can use unchanged). ## Sockets Empty at milestone 1, each with a fake for tests: `AnaloguePort` (joysticks), `UserPort`, `PrinterPort`, `OneMhzBus` (FRED/JIM devices), `TubeSocket`, `SpeechSocket`, `EconetSocket`, `Rs423Port`, `TapeDeck`, `DiscDrive` x2, Master `Cartridge` x2. Sideways ROM slots are machine-row data, not sockets. ## The gate (defined at milestone 1, before any socket device) The board's tier-1 output rung (B2T, [validation.md](validation.md)) as soon as BASIC runs; lockstep of the MOS boot's instruction stream and written values against MAME's trace (cycle counts **not** compared across slow accesses: MAME does not stretch); unit tests of every documented fact with its tag; and later picture rows against detectors. With every socket empty the base board must not move these when a socket device lands. ## Milestones | # | Milestone | Judge (tier) | Exit | | --- | --- | --- | --- | | M0 | **The shared chip cores**: `mos6522-python` and `crtc6845-python` reach their own milestone 1 (decisions 1-2) | data sheets (2); B2T VIA outputs (1) run on a bare 6502 + 6522 harness where the test allows; cpc-python's SHAKER photos for the 6845 (1) | each core's own exit; an import-boundary test; seeded faults caught | | M1 | **Clock, decode, paging, system VIA wiring, keyboard, the 6845 and Video ULA register files, a blank picture**: Model B runs OS 1.20 to the BASIC prompt (text not yet drawn) | the firmware (it is the test); MAME trace (5) as detector | the instruction stream and SHEILA writes equal MAME's for 50 frames from reset, or a named reason for each difference; every cycle-count difference at a slow access explained by the stretch rule | | M2 | **Mode 7**: the address path, the SAA5050, the display and cursor delays: the boot screen drawn | SAA, SM 3.3 (2); MAME picture (5) | "BBC Computer 32K / BASIC / >" drawn; pixel differences with MAME triaged (rounding, flash) | | M3 | **Stretching and VIA timing exact**: run B2T drive 0 | **B2T `O.*` outputs from a real Model B (1)** | all 24 drive-0 outputs reproduced byte for byte; U13 and U14 closed and their tags raised from HYPOTHESIS | | M4 | **Modes 0-6**: serialiser, palette, wrap-around, 10-line rows | AUG 18-19, SM 3.3 (2); MAME (5) | each mode's MOS screen drawn; a hardware-scroll program (AUG 18.14) matches its described behaviour; the RA3 blanking rule tagged | | M5 | **Sound**: the latch strobe path into sn76489-python | AUG 23.3 (2); sn76489-python's ladder | `SOUND` and `ENVELOPE` from BASIC produce the documented frequencies (4 MHz / 32N) | | M6 | **Tape and discs**: serial ULA + ACIA with UEF; 8271 + SSD/DSD with Acorn DFS | ACIA, FDC8271 (2); the DFS itself | `*CAT`, `CHAIN` from a disc image and a UEF load work; smoke list (decision 6) of 5 programs reach their title screens | | M7 | **ADC, user VIA ports, save states** | ADC (2) | a save state loads into a fresh machine and continues identically | | M8 | **Row 2, the B+**: 6512A, shadow PAL (needs SYNC: decision 8), paged RAM, 1770 | SMBP (2); B2T drive 3 (1) | the B+ boots to BASIC; drive 3's output reproduced; shadow mode programs work | | M9 | **Row 3, the Master 128**: G65SC12, ACCCON, ANDY/HAZEL/LYNNE, CMOS RTC, cartridges | MRM, MSM (2); w65c02-python's Master captures (1) for the CPU | the Master boots to BASIC from a cleared CMOS; C2 settled | ## The chip rule | Chip | Users in or near the family | Proposal | | --- | --- | --- | | 6502A / 6512A | many | 6502-python | | G65SC12 | BBC Master, Lynx (G65SC02 row) | w65c02-python | | SN76489 | SMS, Mega Drive, SG-1000, ColecoVision, BBC | sn76489-python | | 6522 VIA | **Vectrex (planned in-board), BBC (two)**, Apple II Mockingboard, VIC-20/1541 | `mos6522-python` now (decision 1) | | 6845 CRTC | **Amstrad CPC (Phase 0 tonight), BBC**, IBM CGA/MDA, arcade | `crtc6845-python` now (decision 2) | | WD1770/1772 | BBC B+/Master; Atari ST, Electron, Archimedes (no family boards yet) | board; extract on a second user (decision 7) | | MC6850 | BBC; Atari ST, arcade (no family boards yet) | board; extract on a second user | | Video ULA, serial ULA, SAA5050, 8271, uPD7002, MC146818, latch, PAL | BBC only among family boards | board | | TMS5220 | BBC speech option, TI-99/4A, arcade | socket only (decision 9) | ## Unknowns (U) and conflicts (C) | # | Unknown | Best source now | Status | | --- | --- | --- | --- | | U1 | which makers' 6845s were fitted (Acorn's lists say only "6845") | MAME names the HD6845S | follow HD6845S, variant record | | U2 | the 6845's behaviour when its clock switches between 1 and 2 MHz mid-line | none | detectors; log every case | | U3 | whether a VIA is accessed once or twice in a stretched cycle (AUG 28.5.2's double access) | AUG 28.5.2 (external bus only) | once (HYPOTHESIS); B2T `O.VIA.*` will show | | U4 | how the BBC drives the SAA5050's DEW, GLR, CRS, and its line counter | SAA pin list, SM 3.3 | read the schematic and SAA timing before M2 | | U5 | reads of write-only or absent SHEILA devices and empty ROM slots | none | open bus (HYPOTHESIS), one switchable rule | | U6 | Video ULA write-to-effect latency; whether a Video ULA write on the Model B disturbs the fetch (the B+ inhibits CAS: SMBP 5.4.4) | SMBP 5.4.4 (B+ only) | detectors | | U7 | Video ULA behaviour for inconsistent control values | none | detectors | | U8 | power-on contents of RAM, palette, 6845, Video ULA | none | an option: zeros or a pattern | | U9 | the Master's SHEILA additions (1770 control/registers, cartridge pages) and its ROMSEL/socket matrix in full | MRM, MSM (not yet read in full) | read before M9 | | U10 | NMOS 6522 or CMOS 65C22 in the Master (its parts list offers both) | MSM parts list | NMOS default, CMOS a row option | | U11 | the 8271's internal command, seek and settle timing | FDC8271 (partly) | FITTED, one table | | U12 | the serial ULA's data separator | none | clean tapes first | | U13 | **the stretch rule's phase-to-case mapping** (2 or 3 periods) | SM85-1 figure 1.2, SMBP 5.2 (drawings) | HYPOTHESIS until B2T `O.TIMINGS` (M3) | | U14 | when an IRQ raised inside a stretched cycle counts for the CPU's poll | none at tier 2; B2T `O.VPOLL`, `O.VIA.I1/I2` (1) | settle at M3 with the cores' owners | | U15 | the mechanism blanking lines 8-9 of 10-line rows (modes 3, 6) | the schematic (unread) | HYPOTHESIS (RA3) until read | | U16 | where the keyboard's start-up links sit in the matrix | AUG appendix J, SM 3.7 | read before M1 | | # | Conflict | Sides | Proposal | | --- | --- | --- | --- | | C1 | slow-device cycle counts | SM85-1 figure 1.2 and SMBP 5.2: 1 or 2 extra 2 MHz periods; MAME 0.285: none visible in `totalcycles` | the manuals (tier 2) now, B2T (tier 1) at M3; MAME's cycle counts ignored across slow accesses | | C2 | which Master devices stretch | MRM ch. 2: the 1 MHz bus, the ADC, "the Versatile Interface"; MRM "1MHz Internal I/O": only the system VIA; MSM parts list: 6845 and 6850 are "1MHZ" parts | settle for row 3 from the MSM schematic's decode | | C3 | mode 7's 6845 R8 | AUG appendix F: interlace field 1 (&91); AUG 18.6.1 and OS 1.20's own write: &93 | &93 (the firmware decides what the machine does) | | C4 | mode 7's 6845 R7 | AUG appendix F: &1B; OS 1.20 writes &1C | the firmware's value; the board does not hard-code either | | C5 | the PSG's part number | Acorn's parts lists: SN76489 (SN76489N on the B+); MAME: SN76489A | Acorn's; sn76489-python's `SN76489AN` row covers the discrete TI part | | C6 | the ADC's resolution | NEC: 12-bit conversions; Acorn: "ten-bit" | the chip's 12-bit result register; Acorn's figure is guaranteed accuracy | ## Domains and speed Full page: [domains-and-speed.md](domains-and-speed.md). - **Domains and channels**: one domain (every clock divides from one 16 MHz crystal; CPU and video share RAM on alternate 2 MHz phases). Candidates to schedule apart from `-fast` on: SN76489 synthesis (a pure producer from time-stamped writes), picture output (a producer if the fetched bytes are logged), the disc drive (stepped inside the FDC, the Sega CD precedent); a Tube co-processor would be the first true second domain (later). Sync points: every FRED/JIM/SHEILA access, every IRQ/NMI edge, the end of each stretched cycle; code-invalidating events: RAM writes, every &FE30 write, &FE34/ACCCON writes. - **Instructions per second**: 2,000,000 CPU cycles a second; MAME's boot trace measured 570,564 instructions in 1 s (3.5 cycles each), so about **0.6 M instructions a second**; plus about 2 M 6845 steps, up to 10 M pixel writes, 2 M VIA ticks and 0.25 M PSG steps a second: roughly 6-7 M device steps a second, about twice the Atari 2600's step count. - **The no-JIT path**: PyPy reference below or near real time (not a goal); `-rust` several times real time natively; **`-rust-fast` real time on phone and in the browser expected (HYPOTHESIS by analogy with a2600-rust-fast: about 4x native, 5x as wasm)**. No cached interpreter or threads expected to be needed: **`recompile: none`** on every target. The first measured number comes at M1. ## Open decisions for Aubrey (each with a recommendation) 1. **`mos6522-python` now, shared with the Vectrex.** vectrex-python's Phase 0 planned to extract its in-board VIA "when a second machine (most likely a Commodore or Acorn) needs one"; this is that machine (two VIAs), and B2T gives it a tier-1 judge no other 6522 source matches. *Recommend: create `mos6522-python` before either board writes a VIA, variants as data (NMOS first, CMOS W65C22 later), built by whichever board starts first.* 2. **`crtc6845-python` now, shared with the Amstrad CPC.** cpc-python's Phase 0 keeps the 6845 in-board because no second user existed ("BBC Micro: no repository"); there now is one. *Recommend: one core with variant rows (HD6845S, UM6845, UM6845R, MC6845; the CPC's ASIC types as CPC-only rows), cpc-python's proposed interface, SHAKER photos and the data sheets as judges; the CPC and BBC agents' interfaces reconciled once.* 3. **Scope and first machine.** *Recommend the Model B (OS 1.20, BASIC II, 8271 DFS) first, the Model A as a parameter, the B+ and Master 128 as later rows, the Master Compact after; the Electron is a different board; Tube co-processors, Econet and speech are sockets only.* 4. **Video output level.** *Recommend a pixel grid at the Video ULA's 16 MHz (mode 0's pixel) for modes 0-6 and a 12 MHz half-dot grid for mode 7 (the SAA5050's rounding), scaled by the host; PAL composite colour artefacts out of scope.* (Technical: taken as provisional unless Aubrey objects.) 5. **The SAA5050's character ROM.** It is inside a Mullard chip; MAME's 960-byte dump is in its `saa5050` set; the data sheet draws every glyph. *Recommend treating it as firmware: the player supplies it, identified by SHA-1; the board ships no font.* 6. **A software source for smoke lists.** The mirror has no BBC disc or tape set (MAME's lists name 3,544 entries). *Recommend: Aubrey says whether a BBC software set should be added to the mirror by environment variable (`BBC_SOFTWARE_DIR`, say) and from which source; until then the smoke list is B2T's test volume, BASIC programs written for the tests, and the player's own discs.* 7. **WD1770.** *Recommend in-board until a second family board needs it (an Atari ST or a Spectrum Beta Disk), then `wd177x-python` with an FD179x row.* 8. **Upstream request to 6502-python: expose SYNC** (as w65c02-python's `sync`/`fetch`) for the B+ shadow PAL. *Recommend raising it now with a repro (a shadow-mode access from VDU driver code vs from user code), low priority: needed at M8.* 9. **Speech (TMS5220/TMS6100).** *Recommend a socket only; a TMS5220 sound core only if the TI-99/4A board (tms9900-python's machine) wants one too.* 10. **MAME's BSD-3-Clause BBC files.** Tonight's rule keeps all MAME source closed; the BBC driver and device files carry `license:BSD-3-Clause`. *Recommend keeping them closed for this board (the family has the manuals and B2T), and deciding the general question once for the family (the PSX Phase 0 raised the same).* 11. **stardot.org.uk's AI policy is unverified** (automated reads blocked). Most BBC hardware research is posted there (B2T's tests came from its members). *Recommend that Aubrey checks the forum's rules himself (or allows a browser read), and that nothing from stardot posts is used until then; B2T's files, hosted on GitHub by their author, are used now.* 12. **B2T in an MIT repository's `reference/`.** The test programs are GPL-3.0; they are fetched as evidence and run only, as Dormann's and Hades-Tests are, and b2's emulator source is never downloaded (blobless sparse clone). *Recommend keeping the pin as is; if Aubrey reads tonight's closed-box rule as covering test programs too, move the pin to an emu-tools-gpl `b2-tests` tool and read only the `O.*` outputs from there.* 13. **sources.md rows** (emulator-lineage; Aubrey's file for shape, facts may be added): *recommend adding the six rows listed at the end of [sources.md](sources.md).* 14. **Noticed outside this repository**: vectrex-python's `scripts/pinned_repos.json` pins a sparse MAME source checkout including `src/devices/machine/6522via.*` (MAME tag `mame0285`; the 6522 file is BSD-3-Clause by its `license:` line, the Vectrex driver files to check). *Recommend its owner reviews it against the 2026-11-24 rule (MIT projects do not fetch closed-box source), before `mos6522-python` inherits anything from that Phase 0.*