# Sound: the Z80, the latches, and the line between the board and `ym2610-python` The Neo Geo's sound side is a Z80 at 4 MHz (master / 6) with 2 KiB of RAM, its program ROM (SM1 on the board, M1 on the cartridge), a YM2610 at 8 MHz (master / 3) and the cartridge's ADPCM sample ROMs (V ROMs). The 68000 and the Z80 share no memory: they talk through two byte latches. Clocks: [CM:60-71], [MAME `neogeo.h` 32-36]; everything else as cited. `[HYPOTHESIS: was wiki Page]` as defined in [memory-map.md](memory-map.md) (the Neo Geo Development Wiki, set aside 2026-11-26). ## What the board owns and what the core owns Matched to `ym2610-python`'s finished Phase 0 (read-only, `../ym2610-python` at `ed216d0`: `docs/handoff-brief.md`, "The board contract" and "The output contract", and its decisions 3 and 4). | Board (`neogeo`) | Cartridge (in the board's repository, behind the slot) | Core (`ym2610-python`, class `OPNB(YM2610, ...)`) | | --- | --- | --- | | the Z80 instance (`z80-python`) and its memory map | M1 ROM and the Z80 bank windows (NEO-ZMC, NEO-ZMC2) | the chip: FM, SSG, ADPCM-A, ADPCM-B, timers, status, BUSY, the digital mix | | SM1/M1 switch (system latch bit 5) | V ROMs, their demultiplexer (PCM, NEO-PCM2) and PCM2 scrambling/decryption | the ADPCM address counters: it asks for a byte at a 24-bit address | | ports `$00`, `$08`/`$18`, `$0C`, the decode of `$04-$07` | | its /IRQ pin (timer A or B flag) | | the command latch, the reply latch, the NMI gate | | the 16-bit left/right words per sample (what the serial output carries, after the clip) and the SSG's three 5-bit codes | | the clock: it runs the core to the moment of each access | | | | **the YM3016's floating conversion** (the core's decision 4: the board owns it for now, with the formula from Yamaha's sheet cited), which word reaches which speaker, the SSG's level against FM, filters, the AES/MVS output stages | | | The contract, as the core's brief states it: ```python chip = OPNB(YM2610, read_adpcm_a=..., read_adpcm_b=...) # byte callbacks, 24-bit addresses chip.run(clocks) # phiM clocks (8 MHz on the Neo Geo: two per Z80 clock) chip.write(port, value) # port = A1 A0 (the Z80's SDA1-SDA0) value = chip.read(port) # 0 status 0, 1 SSG register, 2 status 1, 3 reads 0 chip.irq() # the /IRQ pin chip.reset() samples = chip.take_samples() # (left, right) every 144 phiM, signed 16-bit codes = chip.ssg_codes() # the SSG's 5-bit codes; ssg_mix() through a table ``` The board brings the chip up to the moment of each Z80 port access with `run()` first (an access is an instant between two phiM clocks), reads `irq()` after each step and wires it to the Z80's maskable interrupt. The two ROM callbacks are **demultiplexed** byte addresses (the core's decision 3); the cartridge object answers both and applies NEO-PCM2 if the set needs it; the board never sees the multiplexed `RMPX/ROE` bus (the core keeps a pin-level trace for its own rungs only). Most cartridges store ADPCM-A and ADPCM-B samples in the same V ROMs (MAME feeds ADPCM-B from the ADPCM-A region unless a set has its own [BUS slot.cpp:60-90]; that the PCM chip is what makes this possible is [HYPOTHESIS: was wiki PCM]); only **13 Neo Geo parents** have their own ADPCM-B region in MAME, all early titles (`ym2610-python/docs/users-and-census.md`). So the cartridge maps both callbacks onto the same bytes unless the set has two regions. ## The 68000 to Z80 path - **Command**: a 68000 byte write to `$320000` latches the byte and raises the Z80's NMI if NMIs are enabled [SNK p12], [MAME 1715] (that the latch is in NEO-C1 is [HYPOTHESIS: was wiki 68k/Z80 communication]). The Z80 reads it at port `$00`, which also acknowledges the NMI; a Z80 **write** to port `$00` clears the latch to `$00` [SNK p12], [MAME 1801]. - **Reply**: a Z80 write to port `$0C` latches a byte the 68000 reads at `$320000`; no interrupt [SNK p12], [MAME 1805]. - **NMI gate**: written `$08` enables, `$18` disables; disabled after reset [SNK p12], [MAME 885-889, 1666]. MAME drives the NMI line as **"command pending AND enabled"** through an input merger [MAME 1955-1960], and the Z80 takes NMI on the line's rising edge, so enabling NMIs with a command already pending raises one at once. No source read here says what the hardware does in that case (U-list). `z80-python` latches an NMI request (`request_non_maskable_interrupt`); the board computes the edge and calls it. - **Z80 IRQ**: the YM2610 /IRQ (timers) to /INT [SNK p12]; that the drivers use IM 1, vector `$0038`, is [HYPOTHESIS: was wiki Z80 interrupts] (the puzzledp sound trace will show it). It is a level: the board calls `request_maskable_interrupt()` while it is low and `clear_maskable_interrupt()` when it rises (`z80-python` `cpu.py`). - **System ROM commands** every sound driver must implement [SNK p78, p216]: `$01` prepare for a slot switch (stop sound, park in RAM with NMI enabled, reply `$01`), `$02` play the eye-catcher music, `$03` reset the sound program within 100 ms. That the MVS self-test shows "Z80 ERROR" and stops if no reply comes in time is [HYPOTHESIS: was wiki 68k/Z80 communication]. These are the first sound milestone's exit test. ## The Z80's view of the cartridge The four bank windows are set by **reading** ports `$08-$0B` with the bank in the address's high byte ([memory-map.md](memory-map.md)). That the banking chip is on the cartridge (NEO-ZMC on early boards, NEO-ZMC2 later, which also serialises sprite data: [cartridges.md](cartridges.md)) is [HYPOTHESIS: was wiki Z80 bankswitching]. An 8-bit bank on 16 KiB windows could reach 4 MiB of M1 through window 3 (MAME masks to 256 KiB, C31). Neo Geo CD has no Z80 banking: MAME's CD comments out the bank read [MAME neogeocd.cpp 967]. The MAME sound trace of `puzzledp` (`scripts/mame_trace.py puzzledp --cpu audiocpu --seconds 1`) starts at `$0000` and logs one unmapped write to port `$01C0` at PC `$0104` (C11). ## Write timing the board must keep Yamaha's YM2610 application manual asks for 17 master clocks after an address write and 83 after a data write [DOC: `ym2610-python` docs/registers.md, "Wait times and BUSY", citing the manual ยง9(a)]; that a write made sooner **is lost** is [HYPOTHESIS: was wiki Z80/YM2610 interface] (the closed box keeps such writes: `ym2610-python`'s U1). **The wait is disputed**: `ym2610-python`'s contradiction C3 (the restarted repository's numbering) sets it against BUSY's 200-205 clocks on the die model run as a closed box, ymfm's 192, SNK's routines' 146 or more ([HYPOTHESIS: was wiki Z80/YM2610 interface]) and a 242-clock smallest gap in SNK's driver (its MAME tap); the core follows the die's BUSY and does not model the 83. The board's part is only to run the core to the exact moment of each port access, so whatever rule the core implements can bite. The Z80's own access timing within an instruction comes from `z80_python.timing.instruction_timing` (added in `z80-python` PR #19, merged as `b62891b`). ## Output path The YM2610 sends FM and ADPCM serially to a YM3016 DAC; the SSG leaves the chip as analogue. The core gives the 16-bit words the serial output carries (it measured the left word under SH2 and the right under SH1 on the die model; the other reading, left on SH1, was the wiki's, recorded only in the archived first ym2610-python, and is not carried) and the SSG codes (`ym2610-python/docs/clocking-and-output.md`, "The serial output"). The board turns the words into levels with the YM3016's floating conversion, and decides which reaches which speaker and how loud the SSG is against FM/ADPCM on AES and MVS: **unknown** today (U14). SNK's AES and MV1F schematics are the sources to read in the sound milestone. Phase 0 found scans only through the wiki's "Audio path schematics" page, set aside 2026-11-26 (no pin); a search that day found no other host for the AES or MV1F drawings. An independent scan of SNK's **MV-4 and MV-4F** (four-slot MVS) schematics exists, made by lithy from paper copies and posted on arcade-projects.com (post 445167, 2024-11-20/22) before the wiki copied it: not fetched, a candidate for the MVS audio path only. Until a schematic is read the mix gains are labelled assumptions.