# Handoff: the Mega Duck as a machine of the Game Boy specification ## Context you are inheriting The Mega Duck is a Game Boy with its I/O registers moved and partly re-wired, a headerless cartridge with its own bank latches, and no boot ROM (relation-to-gameboy.md). The family already has its CPU (`../sm83-python`, `40c387f`), its APU (`../gb-apu-python`, `d886019`), and the DMG specification around them (`../gameboy-python`, `ff3c643`), with Rust tiers and a browser player. **Recommended (decision 1): build the Duck as a `megaduck` row inside gameboy-python**, in a session working in gameboy-python under its own rules and gates; this repository is the research behind it. Rules: Python >= 3.11, CPython and PyPy; MIT; nothing read from GPL or unlicensed code (MiSTer's core, the SameDuck forks until checked, MAME's bodies by this brief's closed-box rule); no cartridge or firmware bytes in any repository; `NO_INTRO_DIR`, `MAME_ROMPATH`; local git only; no sweeps over the library; **gameboy-python's author-respect work (furrtek lineage set aside, 2026-11-26) stays as it is**, and the row adds no source from that lineage. ### Read in this order README.md; docs/start-here.md; relation-to-gameboy.md; registers.md; memory-map.md; cartridges.md; cpu.md; census.md; domains.md; validation.md; mame-oracle.md; provenance.md; then MDI itself (`reference/src/megaduck-info/README.md`, after `python -I scripts/fetch_references.py`; 21 KB) and HWINC's `TARGET_MEGADUCK` blocks; then gameboy-python's `machines.py`, `board.py` (`_io_read`, `_io_write`, `_skip_boot`) and `cartridge/`. ## Scope In: the `megaduck` machine row; the I/O decode table and data permutations; MD1 and MD2 cartridges with a SHA-1 table; power-on without a boot ROM. Later: the laptop row (Super Quique system ROM, MD0 with RAM, the serial-port peripherals) once decision 5 is taken. Out: any change to DMG behaviour; the SM83 and APU cores (unchanged); the Cougar Boy as a separate row (it is the same console under another name: MAME's manufacturer list, SR); hosts and sites (play-gb picks the row up later). ## Proposed names (inside gameboy-python) - `MACHINES["megaduck"] = Machine("Mega Duck", "megaduck", "-", boot_rom=None, ...)` with the DMG-B quirk flags and `certified=False`; a new field `io_map` (default identity). - `gameboy_python/megaduck.py`: the decode table (Duck low byte -> DMG low byte, data permutation id) and the eight-bit LCDC move, the nybble swap and the NR32 code, each with MDI's section in its docstring (DOC) and its inverse for reads (HYPOTHESIS U5). - `cartridge/megaduck.py`: `MD1` (`$B000`, D0, 32 KB), `MD2` (`$0001`, 16 KB at `$4000`, 0 -> 1), `DUCK_CARTS` (SHA-1 -> mapper, the 25 NI images from census.md). - Socket: the serial port's peripheral socket for the laptops (later). ## Import boundary Unchanged: gameboy-python imports `sm83_python` and `gb_apu_python`; the cores import nothing. The Duck row touches only the board's I/O dispatch, cartridge loading and power-on. ## Unknowns (U) and contradictions (C) - U1 whether the Duck's SoC behaves as a DMG-CPU (CPU quirks, PPU timing, APU details): no test ROM has been reported run on a unit; everything rests on this HYPOTHESIS. - U2 the crystal's real frequency (MAME 4,194,304 Hz; no measurement). - U3 (closed) the interrupt vectors: the 25 games' code agrees with the DMG's. - U4 STAT's bits and the PPU's other registers' bit layouts (only LCDC is listed as permuted). - U5 whether reads of the permuted registers come back permuted (MDI says so; no probe). - U6 the unlisted I/O addresses (`$FF03`, `$FF08-$FF0E`, `$FF1C-$FF1F`, `$FF26`, `$FF2F`, `$FF47-$FF7F`) and `$E000-$FDFF`: what they read and whether DMG registers alias there. - U7 power-on register, RAM and VRAM contents ("random, affinity to FFFF/0000"). - U8 the MD0 bank switch's ~41 M-cycle delay in the laptop ROM: needed or habit. - U9 MD2's bank 0 on write: SR (via MESS) says 0 selects 1; no hardware statement. - U10 the laptops' serial peripheral protocol and the undumped `81x00.bin`. - C1 SR's traced latch decodes any write with A14 = 0 and latches D0 only (one bit, two banks: an MD1-like design), while MDI places MD1 at `$B000` and MD2 at `$0001` with 3 bits: both are consistent if MD2 boards latch more bits from a wider decode; the build decodes narrowly (the register addresses the games use) and records SR's wider decode as a HYPOTHESIS to test with a write elsewhere in `$0000-$3FFF` (no game in the census does). - C2 SR's bank lines are MESS's, not his measurement: they are tier 5, not a second witness. - C3 MAME's list marks MD1 games (Puppet Knight, Suleiman's Treasure) `fixedbank` like the MD2 ones; what the flag means is in MAME's unopened source. ## Milestones (exit tests in validation.md) M1 the row, power-on, flat carts (rung 0); M2 the decode table and permutations (1); M3 MD1, MD2 and the SHA-1 table (2); M4 MAME lockstep and pictures, detector only (3, 4); M5 Duck-linked test ROMs (5); M6 seeded faults (6); then carry down to gameboy-rust and -fast under their lockstep gates (the DMG rows' traces must stay identical); M7 the laptop row (7). ## Domains and speed (domains.md) - **Domains and channels:** one domain on one 4,194,304 Hz clock, gameboy-python's order of record; channels to the outside only: the cartridge port, the joypad, the serial port (the laptops' peripherals sit on it). - **Instructions per second:** ceiling 4,194,304 / 4 = 1.05 M/s (one-M-cycle instructions); MAME observed 1,119,253 in 3 s of Armour Force = 0.37 M/s (2.82 M-cycles each). - **No-JIT path:** the Duck row runs on the existing tiers; gameboy-rust-fast as wasm measured 5.9-8.7x real time under Node and 3.0 ms per 16.74 ms frame in Chromium (play-gb). Real time on desktop, phone and browser with `recompile: none`; an A55-class handheld ~1.1-1.7x (HYPOTHESIS scaling). No Duck-specific `-fast`, turbo, threads or recompiler. ## Open decisions for Aubrey 1. **The Mega Duck is a machine row of gameboy-python (`megaduck`), not its own board.** Recommended: every known difference is wiring (addresses, data lines, cartridge latch, no boot ROM); a row keeps one DMG specification, so fixes land once upstream and flow to gameboy-rust, -fast and play-gb by the usual merges. The cost is an I/O decode table in gameboy-python's board, kept only if it does not slow the DMG rows (measured), and a gate run downstream. The alternative (its own board pinning gameboy-python) would need gameboy-python to publish its PPU and timer as an interface or code to be copied. 2. **This repository stays as the Duck's research record (docs, pins, census, MAME recipe), with no board code**; its brief is executed in gameboy-python. Recommended; the alternative is folding these docs into gameboy-python's docs and archiving the repo. 3. **Mapper selection by a SHA-1 table plus an explicit `mapper=` argument**, not by extension or by emulating MD1 and MD2 at once. Recommended: no cartridge holds both latches; the census table covers all 25 NI images. 4. **Power-on state: zeros by default, a seeded "random" fill as an option**, both marked HYPOTHESIS (U7). Recommended: deterministic by default for traces and gates. 5. **The laptops (Super Quique, Super Junior Computer) wait for a later milestone**, with the Spanish system ROM by SHA-1 (`fbf86dff...`, in MAME's set) and the serial peripheral protocol read from bbbbbr's prose notes (not the disassembly, which is an unlicensed firmware transcription). Recommended: the handheld is the product; 25 games. 6. **MAME's Game Boy and Mega Duck files are BSD-3-Clause; they stay a closed box for now.** Recommended (provisional): keep the brief's rule; if a fact is ever needed from them (e.g. C3's `fixedbank`), Aubrey may open them as the family opens other BSD MAME files, with the notice. The SameDuck forks stay unfetched until their per-file licences are checked. 7. **Queue three probes for the day a Duck and a flash cart exist** (PROBE-QUEUE.md is Aubrey's to edit): Duck-linked blargg `cpu_instrs` over serial (U1, CPU), dmg-acid2 (U1, PPU, U4), and a register read-back ROM (U5, U6). Recommended: they turn U1 from a hypothesis into a judged claim; no hardware is on hand today (emulation only).