# Handoff: build `portfolio-python`, the Atari Portfolio board ## Context you are inheriting Chips are cores, boards compose cores; the board pins its cores by commit. The CPU core is `i8086-python` (`../i8086-python`, Phase 0 only at `6dd7152`: the board waits for its 8088 row to pass its own rungs). Everything else is DIP's ASIC and three single-machine chips (HD61830, PCD3311, the cards), used by no other family board, so by the chip rule they stay in this board. Nearest family models: `ibmpc-python` (the same CPU core, a PC board; read its `docs/cpu-8088.md`), `supervision-python` and `gameboy-python` (LCD handhelds). Rules: Python >= 3.11, CPython and PyPy; MIT; nothing read from GPL code; MAME's Portfolio files (BSD-3-Clause) are closed boxes unless decision 2 says otherwise; no firmware or card bytes in the repository; `MAME_ROMPATH` for the ROMs; local git only; no sweeps. ### Read in this order README.md; docs/start-here.md; memory-map.md; cpu.md; lcd.md; sound.md; memory-cards.md; pc-compatibility.md; census.md; domains.md; validation.md; mame-oracle.md; provenance.md; then the TRG's chapters 2 and 3 (`reference/docs/trg.pdf` after `python -I scripts/fetch_references.py`) and the HD61830 sheet (data book pp. 413-442). ## Scope In: the memory map with ROM B / card switching; the ASIC (keyboard matrix and scan codes, tick, interrupt priority and vectors, clock stop and wake, contrast, power states as far as software sees them); the HD61830 and its rendering; the PCD3311; the card slot; the key matrix as the host's input; the expansion port as a socket (PID at 807F, EINT, HOLD). Out: the 80C88 (i8086-python); `pofo2` (a different machine); peripheral models (serial, parallel, memory expander) until a socket exists; LCD persistence or panel greys (host). ## Proposed names - Package **`portfolio_python`**; `portfolio_python.Portfolio(rom_a, rom_b, cg_rom, card=None)`: the two 128 KB DIP ROMs and the character ROM are bytes the player supplies (MAME's `pofo.zip` member names as the documented file names). - Modules: `bus.py` (map, RAM, ROM A/B, card window), `asic.py` (registers, tick, interrupt logic and vectors, clock stop, keyboard scanner), `lcd.py` (HD61830), `tone.py` (PCD3311), `cards.py` (`Card` protocol, RAM/ROM cards), `expansion.py` (the `Peripheral` socket), `machine.py`. - Sockets: the CPU (i8086-python's host callbacks, `set_intr` with the ASIC's vector, `set_nmi` if U20 says the tick or refresh uses NMI), the card (`Card`), the expansion port (`Peripheral`: PID, I/O 8070-807F, EINT, NCC1 external card), the keyboard (a 63-key matrix the host drives). ## Import boundary The board imports `i8086_python` (its 8088 row) and nothing else. The core never imports the board. The board keeps time in CPU clocks; the tick and the controller are events scheduled against them (domains.md). ## Unknowns (U) and contradictions (C) - U1 CMOS 80C88 vs NMOS 8088 corner behaviour (no capture of a CMOS 8088). - U2 the VRAM mirror B1000-BFFFF; U3 **the ASIC register map** (ports 8000-806F: only 8010/8011 identified, by the firmware's HD61830 commands); U4 interrupt vector numbers; U5 ASIC wait states (REDY); U6 what stops the clock (HLT or a register). - U7 HD61830 or HD61830B; U8 the controller's clock, frame rate and busy time; U9 the CG ROM's wiring (32 KB image); U10 contrast register; U11 display RAM size; U12 no photo of a running screen to judge layout. - U13 the PCD3311's interface (parallel or I2C) and port; U14 other speaker sources; U15 the key click. - U16 the card-swap and card-detect registers; U17 paged cards' register; U18 card wait states; U19 software to test with (No-Intro has no set; archive.org has DOS programs). - U20 whether NMI is used (the TRG's Int 61h Fn 1Fh speaks of "Refresh on NMIs"). - C1 the TRG's memory diagram labels the RAM top 3F000 while its text gives 124 KB (1F000) and 636 KB in all (to 9F000): planning reading 1F000. - C2 the Phase 0 brief named a T6A43 LCD controller; the firmware's command stream is HD61830's (lcd.md) and MAME agrees: HD61830. The TRG outranks MAME everywhere it speaks; where it is silent (U3), the firmware's code is the next evidence, MAME a detector. ## Milestones (exit tests in validation.md) M1 map, ROMs, reset, the core wired; the first 570 LCD writes equal MAME's (R0). M2 HD61830 rendering; the banner frame (R1). M3 ASIC keyboard, tick, interrupts, clock stop; the DIP DOS prompt and the built-in applications (R2). M4 lockstep with MAME over boot and a key script (R3). M5 cards (R4). M6 tones (R5). M7 seeded faults (R6). M8 the expansion socket (PID, EINT) with one trivial peripheral. ## Domains and speed (domains.md) - **Domains and channels:** system (CPU + ASIC, 4.9152 MHz, clock stops when idle); tick (32,768 Hz, reaches the system only as an interrupt event); LCD controller (own clock; channel: ports 8010/8011); tone chip (3.58 MHz; channel: its data latch, a pure producer). One serial order of record; no thread needed. - **Instructions per second:** ceiling 4,915,200 / 4 clocks per byte fetch = 1.23 M/s; MAME observed 0.21 M/s (4 s) and 0.26 M/s (10 s) of boot, almost all `LOOP`; planning figure 0.6 M/s busy, near zero while the clock is stopped at the prompt. - **No-JIT path:** portfolio-python on PyPy about 0.5-1.5 x real time while busy (estimate from Z80 siblings, HYPOTHESIS); `portfolio-rust` at about half z80-rust's ~50 M/s gives ~40 x on desktop, ~30 x phone, ~25 x browser, ~8 x on an A55 handheld. `recompile: none`, no threads, no `-fast` needed. Speed: trivial. ## Open decisions for Aubrey 1. **CPU: i8086-python's 8088 row at instruction level, no new core, CMOS 80C88 treated as the 8088 until a capture says otherwise.** Recommended: nothing on the Portfolio is known to depend on bus timing (no DMA, refresh or CRTC), and the 8088 corpus is the only hardware-captured judge. 2. **May the build read MAME's `pofo.cpp` (BSD-3-Clause, Curt Coder per MAME's credits) for the ASIC register map?** sources.md rates MAME's BSD files "code OK (with notice)"; this batch's brief says MAME drivers are closed boxes. Recommended: keep it closed; derive the map from DIP's BIOS code (the player's ROM, read locally, facts only, nothing committed) with MAME traces as the detector, and open `pofo.cpp` only if the BIOS leaves a register unexplained, with its notice and every value tagged OBSERVED. 3. **The LCD controller is modelled as an HD61830 (C2), the T6A43 dropped.** Recommended: the firmware's own command bytes decode exactly as HD61830 commands for this panel. 4. **The HD61830, PCD3311 and ASIC stay inside this board.** Recommended: no other family board uses them (chip rule); revisit if a second HD61830 machine joins. 5. **`pofo2` (MAME's "Portfolio 2", DIP DOS 1.680, 640 x 200, 82C425) is out of scope.** Recommended: a different display system and an unclear product; a row later if wanted. 6. **Software for testing: a small MIT tool that builds a RAM-card image from DOS files (the firmware formats and reads it).** Recommended over hunting card dumps: the library is DOS programs, not cartridges, and No-Intro has no set. 7. **One tier: `portfolio-rust` only; no `-fast`.** Recommended (domains.md: ~8-40 x real time estimated on every target). 8. **pofowiki.de is set aside (site's wishes: robots.txt disallows ClaudeBot and others).** Recommended: leave it; Aubrey may read it himself and bring facts, cited as his. The commercial "Undocumented Atari Portfolio Technical Supplement" e-book likely holds the ASIC map; buying it is Aubrey's call (check its author's wishes first); not needed if decision 2's BIOS route works.