# Handoff: build `ibmpc-python`, the IBM PC 5150 and PC/XT 5160 board ## Context you are inheriting Chips are cores, boards compose cores; the board pins its cores by commit and finds their corners. The CPU core is `i8086-python` (`../i8086-python`, Phase 0 only, `6dd7152`): its brief builds an *instruction* core (8086, then V30) and explicitly leaves out bus-cycle timing and the prefetch queue. This board needs both in 8088 form ([cpu-8088.md](cpu-8088.md)), so the first dependency is a new rung on that core (open decision 1). Era 1 (charter): the whole machine is cheap; Python is the readable specification and runs at a fraction of real time. Nearest models: `cpc-python` and `bbcmicro-python` (a 6845 board whose video owns the CPU's timing, and the CRTC extraction discussion), `a2600-python` (a video chip coupled to the CPU's bus phase), `sms-python` (the in-board 8255 and uPD765 that the extractions start from). Rules: Python >= 3.11, CPython and PyPy; MIT; nothing read from GPL code (86Box, PCem, DOSBox, GLaBIOS's source); MAME's BSD-3 PC files closed too (decision 11); no IBM BIOS, keyboard ROM, card ROM, disk image or IBM artwork in the repository; `MAME_ROMPATH` and the census variables; local git only; no sweeps. ### Read in this order README.md; docs/start-here.md; cpu-8088.md; timers-interrupts-dma.md; ppi-keyboard.md; video.md; fdc.md; machines.md; reuse.md; domains-and-speed.md; validation.md; mame-oracle.md; census.md; provenance.md; then i8086-python's docs (start-here, timing, validation) and the IBM Technical Reference chapters for the milestone at hand (`python3 -I scripts/fetch_references.py`). ## Scope In: the 5150 and 5160 system boards (8253, 8259A, 8237A with DRAM refresh, 8255A, NMI logic, wait-state and DMA-wait logic, speaker, cassette on the 5150), the keyboard interface (and a keyboard model), the MDA and CGA cards (6845, buffers, wait states, snow, RGBI and composite signal), the IBM diskette adapter (uPD765, drives, sector images first), machine rows by BIOS SHA-1. Later rows: the XT hard disk, the EGA, the PCjr, the Tandy 1000. Out: the CPU core (i8086-python); the 8087; hosts, windows, composite-to-RGB decoding (host side), sites. ## Proposed names - Package **`ibmpc_python`**; `ibmpc_python.PC(model="5150", bios=, ram_kb=64, video="cga", drives=2)`; `model` in `{"5150", "5160"}` (later `"pcjr"`, `"tandy1000"`); the BIOS row is chosen by its SHA-1 (census.md) and sets the switch defaults. - Modules: `bus.py` (decode, wait states, the DMA-wait hand-off, I/O CH RDY), `pit.py`, `pic.py`, `dma.py` (8237A + refresh), `ppi.py` (until `i8255-python`), `keyboard.py` (the serial interface; `keyboard_mcu.py` with mcs48-python later), `speaker.py`, `cassette.py`, `cards/mda.py`, `cards/cga.py` (with `crtc.py` until `crtc6845-python`), `cards/fdc.py` (until `upd765-python`), `media.py` (sector images; flux later), `domains.py`, `machine.py`. - Sockets (pin-shaped interfaces, so extraction is a move): the CPU's bus-cycle interface; the ISA slot (a `Card` protocol: memory and I/O decode, READY, DRQ/DACK/TC, IRQ lines); the keyboard connector (clock and data lines); the 8087 socket (empty). ## Import boundary The board imports `i8086_python` (8088 mode) and, by decisions 2-5, `crtc6845_python`, `i8255_python`, `upd765_python`, `mcs48_python`. Cores know nothing of the PC. ## Domains and speed Full arithmetic in [domains-and-speed.md](domains-and-speed.md). - **Domains:** one system domain on the 14.31818 MHz timeline (CPU = 3 ticks, PIT = 12) holding the CPU, bus logic, refresh DMA, PIT, PIC, PPI and the CGA (snow and wait states couple the CGA to the CPU's bus phase); the MDA (own crystal; channel at every access, the CPU waits), the keyboard (two-wire serial channel), the floppy drive (byte FIFO, DRQ2, IRQ6); picture and sound as pure producers. - **Need:** 4.77 M CPU clocks/s, at most 1.19 M bus cycles/s, roughly 0.3-0.6 M instructions/s (HYPOTHESIS), 66,288 refreshes/s, 1.19 M PIT ticks/s, 1.79 M CGA character clocks/s in 80-column text. - **No-JIT path:** x-rust reaches real time on desktop, iPhone app and browser (a ~3 M events/s load against tens of millions per second for the family's Rust cores); x-rust-fast adds run-ahead and rewind headroom. `recompile: none`. Python (PyPy) estimate ~0.1-0.4 x real time: the 640 KB boot to BASIC (50 emulated seconds) takes 2-8 minutes, so Python rungs use small RAM and short windows. ## Unknowns (U) and contradictions (C) - U1 PIT: the clock a written count loads on, readback just after, mode 3 phase after a reload - timers-interrupts-dma.md. - U2 The 8237's clock on the 5150 (MAME: 4.77 MHz; IBM silent) - timers-interrupts-dma.md. - U3 XTCE's hardware results are not in reenigne's tree (generator, emulator, failure lists only) - validation.md. - U4 The demos (8088 MPH, Area 5150, CGADEMO, IntroJr) are not on the mirror and their real-hardware captures were not checked - validation.md, census.md. - U5 Keyboard typematic delay and rate - ppi-keyboard.md. - U6 The speaker's low-pass filter values - ppi-keyboard.md. - U7 PIT gates 0 and 1 wiring - timers-interrupts-dma.md. - U8 Whether a read of the CGA's 3D5 reaches the 6845 (R/W is -IOW) - video.md. - U9 Which makers' 6845s IBM fitted on MDA/CGA - video.md. - U10 The MDA's dot clock (16.257 MHz by arithmetic only) - video.md. - U11 The MDA's ninth-column rule for C0h-DFh (stated only for the EGA) - video.md. - U12 No captures of real CGA snow in hand - video.md. - U13 Which CGA revision reenigne's `circuit_1501981.txt` is (old/new composite) - video.md. - U14 The DOS 2.0 360 KB format's source document - fdc.md. - U15 The uPD765's clock on the IBM adapter - fdc.md. - U16 A permissively licensed PC/XT BIOS (none found) - census.md. - U17 Channel 0's page register, I/O aliasing above 3FFh, the MDA buffer mirror - machines.md. - C1 PIT channels 0 and 1 swapped in the Aug 1981 prose; A83, XT and the BIOS agree on ch0 = time of day, ch1 = refresh. - C2 Refresh cost four clocks (A81 p.20, A83, XT) vs five (A81 p.24, and its "7 %" bandwidth). - C3 CGA status bit 3: "Alpha Dots" (A81) vs vertical retrace (V2, and the BIOS's use). - C4 MAME's default 5150 keyboard is a Keytronic 3270 model (8051), not IBM's 83-key keyboard. ## Milestones (exit tests; oracles in validation.md) | M | Content | Exit test | | --- | --- | --- | | M0 | **The core's 8088 bus rung** (in i8086-python, decision 1): 8088 mode, 4-byte queue, bus-cycle host interface, INTA cycles | SST 8088 v2: all 323 files with registers, RAM and **per-clock bus states** equal (tier 1); count stated | | M1 | Bus, decode, RAM/ROM, PIT, PIC, DMA + refresh, PPI and switches, NMI, CGA register file and text drawing; the keyboard interface answering AAh | 5150 rev 1 and rev 3 BIOS, 64 KB: POST to ROM BASIC; the port-access sequence equals MAME's (OBSERVED log, mame-oracle.md) or each difference is explained from tier 2; same on 5160 rev 1 | | M2 | Timing: the DMA-wait hand-off, I/O wait state, refresh cost (C2), MDA/CGA wait states | XTCE's generated tests with refresh periods 0 and 18 reproduce XTCE's cycle counts (tier 3 detector, tier 1 method); C2 settled with a stated rule | | M3 | CGA: every BIOS mode, snow, the composite signal, mid-frame CRTC writes; the MDA | BIOS mode pictures; snow positions follow the netlist rule for a stated test program; 8088 MPH and Area 5150 effects compared by eye with published real-hardware video (U4) | | M4 | Speaker and PIT edge cases | a PWM sample player's output equals the per-tick logic level; U1 recorded per case | | M5 | Diskette: uPD765 with DMA, two drives, sector images; DOS boot | a DOS 2.x/3.x boot disk (player-supplied) reaches the prompt; smoke list from census (decision 10) reaches title screens | | M6 | Keyboard MCU (XT ROM on mcs48-python) as referee of the interface model; cassette | the interface model's timing equals the MCU model's within a stated bound | | M7 | Save states, seeded faults (validation.md) | a snapshot resumes identically; each seeded fault caught | | later | XT hard disk; EGA; PCjr; Tandy 1000 | own exit tests | ## Open decisions for Aubrey 1. **The 8088 bus-cycle rung belongs in i8086-python, not in the board.** Its brief now says "no bus-cycle timing, no prefetch queue model". *Recommend:* amend its brief (an Aubrey edit: it is another repository's plan) with an 8088 BIU rung after its rung 2, judged by the SST 8088 per-clock data, and a host interface of "run to the next bus cycle, then ask the host for READY": the board owns cycle lengths. Also fix that brief's Python floor (it says 3.12+; the family floor is PyPy's 3.11). 2. **`crtc6845-python`: support the extraction now** (bbcmicro decision 2; the PC is the third user). *Recommend* yes, with the CPC's interface; the PC adds the MC6845 row and needs mid-frame register writes as first-class. 3. **The 8259A stays in-board** until irem-python (uPD71059C) reaches its interrupt milestone, then `i8259-python` is extracted with history. *Recommend.* The 8253 and 8237 stay in-board (no second user). 4. **The keyboard: an interface model first, the XT keyboard's dumped 8048 ROM on mcs48-python as its referee; the 5150 keyboard's own ROM is undumped.** *Recommend;* the interface model's timing tagged HYPOTHESIS until the referee or a measurement settles it. 5. **`upd765-python`: support the extraction from sms-python** (cpc decision 6, zxspectrum, msx, x68000). *Recommend;* the PC asks for DMA/TC pins and two-sided drives in the core interface. 6. **SN76496 as a variant row of `sn76489-python`** when the PCjr/Tandy rows start. *Recommend.* 7. **Tier-1 timing evidence:** reenigne's xtserver (a real 5160 that ran anybody's programs over the web) and MartyPC's author's bench are the only routes to hardware results for U1, U3 and U12; asking either is an outside contact. *Recommend:* note it, decide later; until then the PIT edges and snow carry HYPOTHESIS tags and XTCE stands as a detector. 8. **No HLE BIOS; IBM BIOSes player-supplied by SHA-1; GLaBIOS (GPL-3.0) allowed as a player-supplied ROM for players without a dump, never vendored.** *Recommend.* 9. **New environment variables for the PC collections:** `EXODOS_DIR`, `EXODEMOSCENE_DIR`, `TDC_DIR` (added to the profile by Aubrey). *Recommend;* no No-Intro or TOSEC PC set exists on the mirror. 10. **Smoke list:** ~10 early titles from the Total DOS Collection's 1981-1984 floppy images (sector images first, then one `[kfx]` copy-protected title) plus the CGA demos once obtained. *Recommend;* the list is picked at M5 per the smoke-gate rule. 11. **MAME's BSD-3 PC files stay closed** (licence would allow reading with notice). *Recommend* closed, as psx-python decided: the IBM manuals, the netlists and XTCE suffice, and a closed MAME stays an independent detector. 12. **seasip.info set aside (site's wishes: robots.txt blocks GPTBot).** *Recommend* recording it in sources.md as found; Aubrey may read it himself. 13. **Order:** 5150 with CGA first (the timing corners live there), then MDA, then 5160, then the later rows. *Recommend.*