# Handoff: build `enterprise-python`, the Enterprise 64/128 board ## Context you are inheriting Chips are cores, boards compose cores; the board pins its cores by commit. This board embeds `../z80-python` (a 4 MHz Z80A) and keeps two custom chips of its own: **Nick**, a display-list video chip that owns video RAM and stretches the Z80's clock, and **Dave**, which pages 4 MB in 16K segments, generates sound, interrupts and wait states, and decodes the I/O strobes. EXDOS (a WD1770 card) is the disk, through the shared `wd177x-python` the other Phase 0 boards proposed. Era 1: one main domain, cycle level. The hard problems: Nick's clock stretch on Z80 video RAM accesses (undocumented in the manufacturer's text beyond its existence), and Nick's per-mode-line programmability (every 16-byte block can change mode, colours and margins). Nearest models: `samcoupe-python` (Phase 0 today: Z80 board with a custom ASIC, same wd177x question), `colecovision-python` (built Z80 board, measured speed), `msx-python` (a Z80 computer with slots, Phase 0). Rules: Python >= 3.11, CPython and PyPy; MIT; ep128emu, Xemu (GPL) and Enterprise_MiSTer (unlicensed) are closed boxes; MAME's Enterprise files are BSD-3 but stay closed until decision 6; no ROM, cartridge, tape or disk in the repository; `MAME_ROMPATH`, `NO_INTRO_DIR`, `REDUMP_DIR`; local git only; no sweeps. ### Read in this order README.md; docs/start-here.md; docs/nick.md; docs/dave.md; docs/cpu-and-reuse.md; docs/exdos-and-expansion.md; docs/firmware.md; docs/domains-and-speed.md; docs/validation.md; docs/mame-oracle.md; docs/census.md; docs/sources.md; docs/provenance.md. Then NICK-PG and DAVE in `reference/docs/` in full, and ETI20's kernel section (pages 1-40, OCR) for the interrupt and memory conventions EXOS sets up. ## Scope In: the EP64 (EXOS 2.0, 64K) and EP128 (EXOS 2.1, 128K) by ROM SHA-1; Dave (paging, decoding, interrupts, wait modes, sound, strobes); Nick (LPT walk, all video and colour modes, margins, VSYNC lines, interlace through VSYNC placement, VINT, FIXBIAS, border, forced reload, clock stretch); keyboard matrix through B5; the cartridge slot (segments 4-7); EXDOS with one or two drives and raw sector images. Out (for now): cassette and the network/serial port (sockets), printer, joysticks beyond the keyboard-matrix ones, Nick's external colour inputs (EC0-EC3, a socket), the 12 MHz input clock option, RAM expansions beyond 128K, the expansion cards in LGB-PORTS, Spectrum emulator card. ## Proposed names - Package **`enterprise_python`**; `enterprise_python.Enterprise(model="EP128", rom=..., cartridge=None, exdos=None)`, `model` in `"EP64"`, `"EP128"`. - Modules: `nick.py` (LPT walker, slot timing, pixel decode per mode, colour byte, VINT, the stretch decision), `dave.py` (paging, decoding, interrupt latches, wait modes, strobes), `dave_sound.py` (tones, polynomial counters, filters, ring modulation, D/A mode), `memory.py` (segments: ROM, cartridge, video RAM FC-FF, extra RAM), `keyboard.py`, `exdos.py` (card register at 18h, wraps the WD177x model), `machine.py`, `savestate.py`. - Sockets: expansion bus (EXDOS first), cartridge, cassette, serial/net, printer, external colour. ## Import boundary The board imports `z80_python` (`Z80CPU`, `timing.instruction_timing`) and, after decision 4, `wd177x_python`. Cores never import the board. The board owns Dave's waits and Nick's stretch: the CPU's callbacks see addresses; the board decides delays from the access table and its kinds. ## Unknowns (U) and contradictions (C) - U1 Nick's clock stretch: cost per video RAM access and its alignment to slots - nick.md. - U2 The crystal and dividers: Z80 4 MHz, Dave and Nick 8 MHz per MAME; 57 slots in "64 us" is not a whole number of 8 MHz cycles a slot - nick.md. - U3 Where the EP128's second 64K sits (F8-FB by common report) and how it is decoded outside Dave - nick.md, dave.md. - U4 What reading Nick's ports returns - nick.md. - U5 Which Dave input (INT1 or INT2) Nick's VIRQ drives - nick.md, dave.md. - U6 The length of one Dave wait state - dave.md. - U7 Dave's clock divisions, polynomial taps and filter behaviour - dave.md. - U8 The bit maps of the B5-B7 latches (keyboard, cassette, printer, serial, joystick) beyond LGB-PORTS; ETI20's pin-out section not yet read - dave.md. - U9 EXDOS's card register at 18h - exdos-and-expansion.md. - U10 EXDOS disk format details (IS-DOS FAT) - exdos-and-expansion.md. - U11 Who holds Intelligent Software's rights now - firmware.md. - U12 Whether Dave's "wait on M1" applies to the interrupt acknowledge's M1 - cpu-and-reuse.md. - U13 EXOS's interrupt mode (IM 1 expected) - cpu-and-reuse.md. - C1 Frame rate: MAME runs at exactly 50.000 Hz; 312 lines of 64 us give 50.08 Hz; a 9-cycle slot at 8 MHz would give 64.125 us lines and 49.98 Hz - nick.md. - C2 ETI20 says a scanline takes "about 64 microseconds"; NICK-PG says lines "will be 64 us long" (the same author's text, two wordings; settle with U2). ## Milestones M1 EXOS 2.1 boots to the ENTERPRISE screen (R0) with paging and decoding (R2) and the interrupt latches (R1). M2 Nick in full (R3). M3 waits and stretch (R4) against the evidence chosen in decision 7. M4 keyboard, and the EP64 row (EXOS 2.0, 64K). M5 Dave sound (R5). M6 EXDOS (R6). M7 seeded faults (R7), save states. ## Domains and speed (docs/domains-and-speed.md in full.) - **Domains:** M main (Z80, Dave's paging/waits/interrupts/strobes, Nick's fetch and stretch, memory, keyboard); S Dave's sound synthesis (channel: A0-AF writes; the tone generators that can clock an interrupt are shared with M, or kept in M); F EXDOS, stepped inside M (channel: ports 10h-1Fh); P Nick's pixel output, a pure producer in the fast tiers. - **Need, with arithmetic:** 4,000,000 T/s; a 312-line frame of 64 us lines is 79,872 T. At 7-10 T per instruction (MAME's boot trace: 34,773 instructions in 239,997 T) that is **0.4-0.57 M instructions/s**; Nick 57 slots x 312 lines x 50 = 889,000 slot steps/s; Dave's counters about 0.4-0.5 M steps/s; the WD1770 31,250 bytes/s while busy. - **No-JIT path:** trivial. A ColecoVision-sized Z80 load: x-python roughly 0.25-0.45 x real time on CPython and 0.5-2 x on PyPy (estimated from colecovision-python's MEASURED band); x-rust and x-rust-fast well above real time on desktop, phone and browser (estimate); `recompile: none`; no threads needed. ## Open decisions for Aubrey 1. **EP128 (EXOS 2.1) first, EP64 as a row.** Recommended: the same chips with 64K more RAM; MAME's ep128 boots cleanly (OBSERVED); EXOS 2.1 is the later firmware. 2. **Waits and stretch from z80-python's access table plus kinds, not a cycle-stepped Z80.** Recommended (cpu-and-reuse.md): M1 is `t == 1` in the table; ask z80-python for interrupt acknowledge and HALT timing (the request samcoupe-python and zxspectrum-python share), and consider merging `read_m1` (Aubrey's call: z80-python is public). 3. **Nick and Dave stay inside the board.** Recommended: chip rule, Enterprise only. 4. **EXDOS's WD1770 through the shared `wd177x-python`.** Recommended: the same proposal as samcoupe-python decision 4 and atarist-python decision 6. 5. **EXOS, IS-BASIC and EXDOS ship nothing.** Recommended: no release statement found; Intelligent Software's 1984 notice forbids reproduction; player-supplied ROMs by SHA-1. 6. **MAME's BSD-3 Enterprise files (`nick.cpp`, `dave.cpp`, `ep64.cpp`, `exdos.cpp`): open them as a facts source, with notice?** Recommended: **yes, for Nick's clock stretch and Dave's dividers only, and only if decision 7 finds nothing better**, since the manufacturer's text does not cover them and ep128emu (the only other detailed model) is GPL. Facts restated with the BSD notice kept in NOTICE.md (charter point 7), tagged as emulator-derived (tier 5), never as hardware. If Aubrey prefers MAME closed (the family's default this week), the stretch stays HYPOTHESIS until decision 7 brings evidence. 7. **Evidence for Nick's stretch.** Recommended: ask Aubrey whether he (not an agent) will look on enterpriseforever.com (set aside for agents) for published measurements or test programs, and whether ep128emu in emu-tools-gpl should be built as the detector; record whatever comes back with its chain. 8. **Software for a smoke list.** Recommended: none is on the mirror (not even the IS-BASIC cartridge); the board's first rungs need only the system ROM; ask Aubrey whether to fetch MAME's software-list sets (`ep64_cart`, `ep64_flop`) into a new `ENTERPRISE_DIR` outside the repository. 9. **Proposed sources.md rows** (docs/sources.md, 9 rows), including enterpriseforever.com as "set aside (site's wishes)".