# Handoff: build `konami68k-python`, Konami's TMNT-era boards ## Context you are inheriting Read the family's CLAUDE.md (`../CLAUDE.md`), the family charter and methodology (emulator-lineage `docs/`), then in this repository: [start-here.md](start-here.md), [census.md](census.md), [cpu-cores.md](cpu-cores.md), [memory-map.md](memory-map.md), [tilemaps.md](tilemaps.md), [sprites.md](sprites.md), [mixer-palette.md](mixer-palette.md), [sound.md](sound.md), [eeprom-io.md](eeprom-io.md), [shared-cores.md](shared-cores.md), [domains-and-speed.md](domains-and-speed.md), [validation.md](validation.md), [mame-oracle.md](mame-oracle.md), [sources.md](sources.md), [provenance.md](provenance.md). Then `python -I scripts/fetch_references.py` (5 files, ~17 MB; `--verify` to check). This is an era-2 arcade board: one 68000 (or the KONAMI CPU) plus a Z80, cycle-interleaved; `-fast` is the browser target; threads are optional margin. The custom chips have **no usable hardware-tier oracle** (the die studies are furrtek's and set aside): expect FITTED behaviour, tagged honestly. ## Scope In: the 92 sets of MAME 0.285's `konami/tmnt.cpp`, `tmnt2.cpp`, `xmen.cpp`, `simpsons.cpp`, `aliens.cpp` (15 games), as rows in this order: **tmnt** (TMNT, M.I.A., Cue Brick); **punkshot** (Punk Shot, Thunder Cross II); **tmnt2** (Turtles in Time, Sunset Riders, then Lightning Fighters, Bells & Whistles, Quiz Gakumon); **xmen**; then the KONAMI CPU rows **simpsons** and **aliens** once the CPU mode exists. Later: Golfing Greats and Premier Soccer (K053936 ROZ; MAME preliminary/imperfect). Out: bootlegs' extra hardware (the `tmntucbl` MCU is a nodump), hosts, sites. ## Package and classes (proposed) ``` konami68k_python/ machine.py # row table: set -> CPU kind and clock, sprite generation, mixer kind, # sound chips, EEPROM, protection chip, visible area, rotation romset.py # MAME zips read in place from $MAME_ROMPATH, verified by SHA-1; # factory EEPROM images and PROMs found in the sets, never copied board.py # build(set, rompath) -> Board; the rational-time timeline; save states main.py # MainDomain: CPU socket (m68000-python or the KONAMI mode), map per row, # waits, interrupt levels (autovector), 051550 reset/watchdog, latches io.py # input multiplexers, DIP switches, output latches (coin counters, banks, dim) eeprom.py # Er5911 (128 x 8 here; the data sheet's five instructions) video/ k052109.py # tile RAM, registers, scroll; K051962 pixel path in the same module k051960.py # gen-1 sprites (with K051937) k053245.py # gen-2 sprites (with K053244) k053247.py # gen-3 sprites (with K053246) k053251.py # mixer; prom_mixer.py for tmnt/aliens palette.py # 2,048 x 16-bit RAM, the colour stage (SHAD, BRIT, DIM) sound/ domain.py # SoundDomain: z80-python, ym2151-python, the chip below, the channel k007232.py k053260.py k054539.py k054321.py upd7759.py title_dac.py protection.py # K054000, Sunset Riders' protection (U6) ``` Every chip module is pin-shaped (registers in, pixels or samples out, channels named) so it can be extracted later ([shared-cores.md](shared-cores.md)). ## What the board needs from its cores - **m68000-python** (pin by commit): bus callbacks per access for waits; interrupt levels with autovectored acknowledge; RESET/HALT from the board. All in its claims today. - **z80-python** (pin): IRQ and NMI from the board; nothing new. - **ym2151-python**: a core (it is in Phase 0 now). The sound milestone can start without FM. - **m6809-python with a KONAMI CPU mode** (decision 3): needed only for the simpsons and aliens rows; m6809-python has no core code yet. ## Milestones | # | Milestone | Judge (tier) | Exit | | --- | --- | --- | --- | | M0 | romsets by SHA-1, row table, timeline unit chosen per row (U24) | census | 92/92 load, nothing copied | | M1 | tmnt main domain: map, work RAM, inputs, watchdog, interrupts, K052109/K051960 register and RAM storage (no pixels) | MAME trace (5) | 600 frames of main-CPU lockstep, or each difference named | | M2 | tmnt sound domain and channel (latch, IRQ), Z80, K007232 and uPD7759 register state | MAME trace (5); NEC (2) | Z80 lockstep 600 frames; the channel log equal | | M3 | tmnt pictures: K052109/K051962, K051960/K051937, PROM mixer, palette | MAME pictures (5) | attract loop compared, differences recorded | | M4 | tmnt audio: YM2151 (when ym2151-python lands), K007232, uPD7759, title tune | MAME audio (5), NEC (2) | write streams equal; "good enough" | | M5 | punkshot row: 12 MHz, K053251, K053260 (both halves, ports as the channel) | as M1-M4 | Punk Shot attract loop and a game start | | M6 | tmnt2 row: K053245/K053244, ER5911 (DOC), GX063/064 glue from the schematic (DOC), Sunset Riders' protection | DOC (2) where the schematic covers; MAME (5) | Turtles in Time and Sunset Riders self tests pass, attract loops compared | | M7 | xmen row: K053247/K053246, K054539, K054321 | MAME (5; weak for sound) | X-Men attract and play | | M8 | Thunder Cross II, Lightning Fighters, Bells & Whistles, Quiz Gakumon, Cue Brick, M.I.A. | MAME (5) | each reaches play in a smoke run | | M9 | KONAMI CPU rows: simpsons, aliens (after the CPU mode) | MAME (5) | both reach play | | M10 | save states, run-ahead, full-library smoke | self | identical continuation; all 92 reach play | ## The chip rule | Chip | Family users | Proposal | | --- | --- | --- | | MC68000 | many | m68000-python | | Z80 | many | z80-python | | YM2151 | cps1, namcos1/2, system16 | ym2151-python | | KONAMI CPU | none (13 MAME Konami drivers) | a CPU: mode of m6809-python (decision 3) | | uPD7759 | system16-python (Phase 0) | `upd7759-python` when the second of the two boards reaches sound (decision 4) | | K052109/K051962, sprite pairs, K053251 | none yet (37 MAME parents) | in-board; one `konami-video-python` at the second Konami board (decision 5) | | K007232, K053260, K054539 (+ K054321) | none yet | in-board; extract one by one at their second board (decision 4) | | ER5911 | none; other serial EEPROMs on cps1, jaguar, lynx, cps3, a2600, megadrive | in-board (decision 6) | | K054000, K053936, 051550, 052535 | none | in-board | ## Unknowns (U) and contradictions (C) | # | Unknown | Best source now | | --- | --- | --- | | U1 | schematics for the tmnt, punkshot, xmen, simpsons and aliens boards | none found in a permitted copy; manuals on archive.org were checked for three games | | U2 | which KONAMI CPU part (052001 / 052526 / 053248) is on which board, and whether they differ | board photographs; MAME names one device | | U3 | the KONAMI CPU's opcode map and cycle counts | MAME `konami.cpp` (decision 1), traces | | U4 | (reserved) | | | U5 | the 68000's wait states per region on each row (DTACK is off-sheet on GX063/064) | traces; none | | U6 | Sunset Riders' protection at `1C0400`/`1C0500-1C057F`/`1C0800` | traces, watchpoints | | U7 | punkshot's read at `FFFFFC-FFFFFF` | trace with a watchpoint | | U8 | which source drives which interrupt level on each row | traces of SR and the level | | U9 | DTACK and region timing on GX063/064 | the sheets we lack | | U10-U12 | tilemap scroll latching, board callbacks, raster fetch timing | [tilemaps.md](tilemaps.md) | | U13-U15 | sprite list formats, latch time, shadow path | [sprites.md](sprites.md) | | U16-U18 | 052535 curve, K053251 rules, tmnt PROMs | [mixer-palette.md](mixer-palette.md) | | U19-U22 | TMNT title tune path, K053260 ADPCM, K054539 reverb, K007232 wiring | [sound.md](sound.md) | | U23 | whether xmen's main CPU resets the Z80 through a latch | trace | | U24 | the board timeline's common unit per row | the clocks in [domains-and-speed.md](domains-and-speed.md) | | U25 | whether MAME's Konami chip files carry furrtek-derived facts | only by opening them (not done) or asking their authors | | U26 | the uPD7759 ADPCM step table | NEC 1989 DSP and Speech data book (bitsavers, not yet pinned) | | U27 | if hardware is ever bought: the measurements with most leverage (K053251 priority, 052535 curve, sprite latch timing, KONAMI CPU cycles) | - | | U28 | ER5911 opcode bits as read from an OCR layer | re-read on the data sheet's page image before coding | | # | Contradiction | Sides | Proposal | | --- | --- | --- | --- | | C1 | The Simpsons' CPU | task brief: a "68000 board"; MAME 0.285 `-listxml`: KONAMI CPU at 12 MHz input, 3 MHz of cycles in its trace | a KONAMI CPU row, built after the CPU mode | | C2 | Aliens' CPU | task brief: "a 6309 sibling row"; MAME: KONAMI CPU | KONAMI CPU row; the HD6309 siblings are The Main Event/Devastators and Bottom of the Ninth (decision 2) | | C3 | X-Men's PCM chip | task brief lists the K053260 for the generation; MAME: K054539 + K054321 on X-Men (the K053260 is on Punk Shot, Sunset Riders, The Simpsons) | K054539 in-board for xmen | | C4 | the EEPROM | brief: "the EEPROM" (93C46 is the usual guess); Konami schematic: ER5911 with ORG to ground (128 x 8); MAME: `er5911_8` | ER5911, 128 x 8 (DOC) | | C5 | TMNT's sound | brief lists K007232 only; MAME also has a uPD7759 and a 512 KB title-tune sample ROM | all three in the tmnt row | ## Domains and speed Summary of [domains-and-speed.md](domains-and-speed.md): - **Domains**: main (CPU + video chips + palette + I/O + EEPROM + watchdog) and sound (Z80 + YM2151 + PCM chips + uPD7759). **Channels**: the sound latch and IRQ (tmnt, aliens), the K053260's four ports and IRQ write (punkshot, tmnt2, simpsons), the K054321 (xmen), the sound reset line where one exists, and the picture and audio producers. - **Need** (measured on MAME, frames 60-118): heaviest rows Sunset Riders and X-Men at **~3.0 M instructions a second** (68000 2.15 M + Z80 0.74 M; 1.95 M + 1.04 M) and **24 M clock ticks a second** to interleave (16 + 8 MHz), about 2.1x the Mega Drive's 11.25 M; 6.0 M dots a second (384 x 264 x 59.1856). tmnt: 1.05 M + 0.35 M instructions, 11.6 M ticks. The KONAMI CPU rows: 0.66-0.82 M + 0.52 M instructions, 6.6 M ticks. - **No-JIT path**: plain Rust ~2-3x real time on this desktop (HYPOTHESIS, scaled from megadrive-rust's 4-6x at 11.25 M ticks); `-fast` ~3-4.5x, enough for the desktop browser with run-ahead 1; the cached interpreter is safe (all code in ROM in every trace); threads at the sound channel and a picture producer give phones their margin. **`recompile: none` is expected to meet desktop, phone and browser**; to be measured, not assumed. - **Python**: far from real time; correct, not fast. ## Open decisions for Aubrey (each with a recommendation) 1. **MAME's BSD-3-Clause Konami files.** Every relevant chip and driver file carries `license: BSD-3-Clause` (only `konamiic.txt` has no line: GPL-2.0+). The task brief keeps MAME closed. **Recommend keeping MAME closed for this board** even though the licence would allow facts with notice, because the lineage question U25 (furrtek's findings may have been folded into those files) cannot be answered without opening them; run it as a detector only. If Aubrey prefers to open them for facts, ask their copyright holders first whether furrtek's research is inside. 2. **The 6809-era sibling.** The brief's "6309 sibling" is Aliens, which is a KONAMI CPU board. **Recommend** keeping simpsons and aliens as late rows of this board (they share every video chip and the screen), and treating the HD6309 boards (The Main Event/Devastators, Bottom of the Ninth) as the first candidates for a *second* Konami board, which is what triggers the video-core extraction (decision 5). 3. **The KONAMI CPU core.** **Recommend a mode of `m6809-python`** (as its own docs propose for the HD6309), built after the 6809 core exists; claims stated as tier 5 only. Alternative: its own `konami1-python` repository on m6809-python's frame. 4. **Sound-chip cores.** **Recommend** K007232, K053260 and K054539 in-board now, each extracted at its second family board; **`upd7759-python` as its own core** as soon as either system16-python or this board reaches sound second, since both already need it. 5. **A shared Konami video core.** **Recommend** one `konami-video-python` (K052109/K051962, the three sprite pairs, K053251) extracted when the second Konami board starts, not five separate repositories. 6. **Serial EEPROMs.** **Recommend** the ER5911 in-board now; a serial EEPROM is now on many family boards (93C46-type on cps1/cps2, jaguar and lynx; others on cps3, a2600 and megadrive), so consider one shared serial-EEPROM core for the 93Cxx/ER5911/X24C families at the next board that needs one; the ER5911 differs from the 93C46 in its opcodes and is a variant there. 7. **Lineage reach.** furrtek's die studies cover nearly every custom on this board, and jtcores' Konami cores are built on them. **Recommend** recording jtcores' Konami cores as "set aside (author's wishes: furrtek lineage)" in sources.md (not just "closed box"), and accepting that the customs will be FITTED to MAME. A respect-clean way to raise the tier is a board purchase and our own measurements (U27); Aubrey's call, not needed to start. 8. **Board order.** **Recommend** this board after namcos1/namcos2 (same CPU family, a simpler picture), starting with tmnt; it is cheap (one 8-16 MHz 68000) and a good corner-finder for m68000-python's autovector timing.