# Handoff: build `gamecom-python`, the Tiger Game.com board ## Context you are inheriting The CPU core is `sm8521-python` (`../sm8521-python`, Phase 0 done alongside this one; its brief proposes the bus contract and the core/board line this board implements). Every other part of the SM8521 (LCDC/DMA, sound generator, timers, watchdog, ports, MMU, UART, IE/IR) is used by no other family machine, so by the chip rule it stays in this board, behind pin-shaped interfaces. Nearest models in the family: `gameboy-python` (a handheld whose LCD controller and DMA live in the board, with a firmware boot ROM the player supplies), `supervision-python` (Phase 0 tonight: another single-domain LCD handheld), `pcengine-python` (a board whose CPU chip carries peripherals). Rules: Python >= 3.11, CPython and PyPy; MIT; MAME's BSD-3 Game.com files closed unless decision 4 changes; no firmware, cartridge bytes or Tiger artwork in the repository; `NO_INTRO_DIR`, `MAME_ROMPATH`; local git only; no sweeps. ### Read in this order README.md; docs/start-here.md; memory-and-cartridges.md; lcd-dma.md; sound.md; io.md; census.md; domains.md; validation.md; mame-oracle.md; provenance.md; then sm8521-python's handoff brief and DS pages 18-50. ## Scope In: the map and MMU (the MMU0 switch and its prefetch rule), firmware loading by SHA-1, the LCDC (timing, interrupt, V-blank, pages, gradation), the DMA (four modes, palette, flips, banks, the HALT start), the sound generator and direct D/A, timers, clock timer, watchdog, IE/IR, ports, buttons, the touchscreen, the two cartridge slots; later the UART and modem cartridges. Out: the SM85CPU (sm8521-python); the picture's rotation and grey palette (host); the modem's far end. ## Proposed names - Package **`gamecom_python`**; `gamecom_python.GameCom` (the board), built with the two firmware images (bytes the player supplies, checked by SHA-1) and up to two cartridges. - Modules: `bus.py` (map, register file 0010-007F dispatch, extend RAM), `mmu.py`, `lcdc.py`, `dma.py`, `sound.py`, `timers.py` (TM0, TM1, CLKT, WDT, prescalers), `irq.py` (IE0/IE1/IR0/IR1 to the core's request lines), `ports.py`, `touch.py`, `pad.py`, `cart.py` (slots and their selection, U3), `uart.py` (late), `firmware.py` (SHA-1 table), `machine.py`. - Sockets: the CPU (sm8521-python's bus callbacks, `step()`, request lines, HALT/STOP and wake), the cartridge slots (`Cartridge` protocol), the touchscreen and pad (an input protocol: stylus x, y, pressed; buttons), the serial port (`SerialDevice`). ## Import boundary The board imports `sm8521_python` and nothing else of the family's. The board keeps time in fCK periods: it scales the core's cycles by CKC's divider and steps the LCDC, DMA, sound and timers on their own dividers. ## Unknowns (U) and contradictions (C) - U1 extend RAM size at E000-FFFF; U2 the touchscreen (resolution, scanning); U3 how the kernel ROM and two slots share the 2 MB space; U4 CPU reads of VRAM; U5 the cartridge header. - U6 when the LCDC interrupt fires; U7 DMA speed; U8 DMA without HALT; U9 LCD refresh during DMA; U10 overlapping VRAM-to-VRAM order. - U11 the sound step-period formula; U12 mixer overflow. - U13 prescaler phases; U14 each port pin's function; U15 IR bits cleared by hardware? - U16 other firmware revisions; U17 starting a cartridge headless in MAME (stylus input). - C1 LCV's V-blank width: bits 4-0 (text) vs bits 3-0 (diagram). - C2 the firmware's LCD settings give 83.48 Hz by DS's formula; MAME shows 59.732155 Hz. - C3 "Period = fCK(n-1)" is not a time. - C4 WDTC "read only" yet with writable bits. - C5 UART baud: Timer 0 output / 32 (text) vs a divide-by-16 (Fig. 25). ## Milestones (exit tests in validation.md) M1 map, MMU, firmware to its first STOP (rung 0); M2 LCDC (1); M3 DMA and the splash screen (2); M4 timers and interrupts (3); M5 sound (4); M6 ports, buttons, touchscreen, slots: the menu starts a cartridge (5); M7 MAME comparison (6); M8 seeded faults (7); M9 UART and modem cartridges (8). ## Domains and speed (domains.md) - **Domains and channels:** one domain on fCK = 11.0592 MHz; the 32.768 kHz clock timer stepped inside it at the exact ratio 337.5; channels to the outside only (UART, buttons and touchscreen, slots). - **Instructions per second:** ceiling 5,529,600 / 2 = 2.76 M/s; MAME observed 0.71 M/s (firmware, 7.86 cycles per instruction). - **No-JIT path:** `gamecom-rust` (a plain transcription, estimated 30-60 M/s native) reaches real time on desktop (10-20x), phone (9-17x), iPhone browser (5-10x) and an A55 handheld (2-4x); no `-fast`, cached interpreter, threads or recompilation needed. `recompile: none`. Python is a specification at up to about real time on firmware-like code. ## Open decisions for Aubrey 1. **The board is specified from DS plus the firmware's observed behaviour, with the board-level wiring (slots, touchscreen, ports) recorded as OBSERVED from traces of real code, not from MAME's source.** Recommended: it is the only respect-clean, licence-clean path that leaves each fact's chain visible. 2. **LCD frame timing from DS's formula (83.48 Hz for the firmware's settings), C2 recorded, MAME's 59.73 Hz kept as a detector.** Recommended, provisional: DS is tier 2; a measurement on a unit would settle it (queued for the probe list, no unit on hand). 3. **The DMA as a transaction with a FITTED busy time** until a speed is known (U7). Recommended. 4. **MAME's BSD-3 Game.com files stay closed.** Recommended as the brief asked; reading them (code OK with notice) would answer U2, U3, U14 quickly, and Aubrey may prefer that: if so, files that take from them carry `MIT AND BSD-3-Clause` and a NOTICE.md crediting Wilbert Pol and Robbbert. 5. **Firmware required, no high-level replacement.** Recommended: the kernel ROM is the console's menu and system calls (GameComHDK documents "system calls" into it); a replacement would be a functional model with nothing to judge it against except the real ROM. 6. **The modem and UART as a late milestone.** Recommended: two cartridges use them, and the far end (Tiger's service) no longer exists. 7. **One Rust tier (`gamecom-rust`), no `-fast`.** Recommended (domains.md).