# Registers and the write path Evidence tags and citation forms are in [start-here.md](start-here.md). In short: `DOC (AM p.N)` is page N of the scanned application manual (`reference/docs/yamaha_ym2151_synthesis.pdf`), `DOC (DS p.N)` the printed page of the 1991 catalogue (`YM2151_199112.pdf`), `DIE (IKAOPM 08a5b40, file:line)` the die-derived Verilog, `OBSERVED (Nuked-OPM f209e6e, script)` a closed-box run of the referee. Unknowns are `U` numbers and contradictions `C` numbers, listed in [handoff-brief.md](handoff-brief.md). ## Bus | Rule | Evidence | | --- | --- | | One 8-bit bus, multiplexed: a write with A0 = 0 is an address, with A0 = 1 data | DOC (DS p.3; AM p.23) | | A read with A0 = 1 returns the status byte; with A0 = 0 the chip does not drive the bus (what the CPU sees is the board's business, U3) | DIE (IKAOPM 08a5b40, IKAOPM_reg.v:778-780) | | Status: bit 7 BUSY, bit 1 timer B flag, bit 0 timer A flag, bits 6-2 read 0 | DOC (AM p.6, p.15 "IST"); DIE (IKAOPM_reg.v:778) | | A read has no side effect on flags or BUSY | DIE (IKAOPM_reg.v:777-780: the read path is a multiplexer only) | | Test bit 6 replaces the status byte with internal data (operator output bits; with test bit 7 also one phase bit of channel 6 C2 and one attenuation bit of channel 8 C2) | DIE (IKAOPM_reg.v:777-778, IKAOPM_pg.v:762-770, IKAOPM_eg.v:799-809) | | BUSY is set by a data write only, not by an address write | DIE (IKAOPM_reg.v:765); OBSERVED (Nuked-OPM f209e6e, `reference/referee-probe.txt`: no BUSY after an address write) | BUSY's length is in [timers-and-bus.md](timers-and-bus.md) (C2). ## Address map Writes only; every register reads back as nothing (only the status byte is readable). "Slot" registers are indexed by a 5-bit slot offset (below). | Address | Bits | Field | Evidence | | --- | --- | --- | --- | | 0x01 | 7-0 | TEST; bit 1 resets the LFO (manual); other bits: [timers-and-bus.md](timers-and-bus.md) | DOC (AM p.13); DIE (IKAOPM_reg.v:481) | | 0x08 | 6-3, 2-0 | KON: slot bits (bit 3 M1, bit 4 C1, bit 5 M2, bit 6 C2), channel | DOC (AM p.6); DIE (IKAOPM_reg.v:535-536) | | 0x0F | 7, 4-0 | NE (noise on channel 7 C2), NFRQ | DOC (AM p.11); DIE (IKAOPM_reg.v:485-486) | | 0x10 | 7-0 | CLKA1: timer A value NA bits 9-2 | DOC (AM p.13); DIE (IKAOPM_timer.v:63) | | 0x11 | 1-0 | CLKA2: NA bits 1-0 | DOC (AM p.13); DIE (IKAOPM_timer.v:63) | | 0x12 | 7-0 | CLKB: timer B value NB | DOC (AM p.14) | | 0x14 | 7, 5-4, 3-2, 1-0 | CSM; F RESET B, A; IRQ EN B, A; LOAD B, A | DOC (AM p.14-15); DIE (IKAOPM_reg.v:451-452, :491-494, :503) | | 0x18 | 7-0 | LFRQ | DOC (AM p.12) | | 0x19 | 7, 6-0 | bit 7 = 1: PMD, bit 7 = 0: AMD | DOC (AM p.12); DIE (IKAOPM_reg.v:497-500) | | 0x1B | 7-6, 1-0 | CT (two output pins), W (LFO wave) | DOC (AM p.6, p.12); DIE (IKAOPM_reg.v:483, :501). Pin numbers: C1 | | 0x20 + ch | 7-6, 5-3, 2-0 | RL (bit 7 right, bit 6 left), FL (feedback), CON | DOC (AM p.8, p.15); DIE (IKAOPM_reg.v:590-592, IKAOPM_acc.v:69-70) | | 0x28 + ch | 6-0 | KC: octave bits 6-4, note code bits 3-0 | DOC (AM p.7, Fig. 2.4 p.18) | | 0x30 + ch | 7-2 | KF | DOC (AM p.7); DIE (IKAOPM_reg.v:588) | | 0x38 + ch | 6-4, 1-0 | PMS, AMS | DOC (AM p.8, p.11); DIE (IKAOPM_reg.v:586-587) | | 0x40 + slot | 6-4, 3-0 | DT1, MUL | DOC (AM p.7); DIE (IKAOPM_reg.v:649-650) | | 0x60 + slot | 6-0 | TL | DOC (AM p.10) | | 0x80 + slot | 7-6, 4-0 | KS, AR | DOC (AM p.9-10) | | 0xA0 + slot | 7, 4-0 | AMS-EN, D1R | DOC (AM p.9, p.11); DIE (IKAOPM_reg.v:693: AMS is gated per slot by AMS-EN) | | 0xC0 + slot | 7-6, 4-0 | DT2, D2R | DOC (AM p.8, p.9) | | 0xE0 + slot | 7-4, 3-0 | D1L, RR | DOC (AM p.9-10) | Addresses 0x00, 0x02-0x07, 0x09-0x0E, 0x13, 0x15-0x17, 0x1A and 0x1C-0x1F have no decoder in the die reading: writes there change nothing. DIE (IKAOPM_reg.v:269-317, one decoder per listed address). Whether the YM2164 differs here is open (U5, [ym2164.md](ym2164.md)). **Slot offsets.** The 32 slots are four groups of eight channels in the order M1, M2, C1, C2: offset = 8 x group + channel, so 0x58 is C2 of channel 0. DOC (AM p.17, Fig. 2.2). The die compares the low five address bits with the running slot counter. DIE (IKAOPM_reg.v:414-424). Note that the KON bit order (M1, C1, M2, C2) is not the slot order. **Reset.** /IC clears every register to 0, so the CT pins read 0. DOC (AM p.6; DS p.3); DIE (IKAOPM_reg.v:456-479, :586-592, :648-658). ## How a write lands | Rule | Evidence | | --- | --- | | The bus is latched asynchronously and handed to the internal clock through a short synchronizer, so a write takes effect a couple of internal cycles after the strobe; the exact latency at the pins is not settled (U2) | DIE (IKAOPM_reg.v:120-252; the `FULLY_SYNCHRONOUS` option adds FPGA-only delay, README) | | An address write selects a register; every later data write goes to it until the next address write (no new address is needed to rewrite a register) | DIE (IKAOPM_reg.v:800-807 for 0x00-0x1F; :345-380 for 0x20-0xFF) | | Registers 0x00-0x1F are written at the data write | DIE (IKAOPM_reg.v:454-507) | | Registers 0x20-0xFF go through a holding register and are written when the slot counter reaches their slot, so the new value is in place within 32 internal cycles of the data write; the holding register keeps being applied every round until the next address write | DIE (IKAOPM_reg.v:325-426, :586-691) | | A KON write is staged and copied into the per-slot key state when the slot counter equals its channel, once per 32 cycles; a second KON write before that replaces the first | DIE (IKAOPM_reg.v:514-556) | | Two KON writes 8 cycles apart: the first is lost; 16 or more apart (at the phase tested): both kept | OBSERVED (Nuked-OPM f209e6e, `scripts/referee_measure.py`, KEY-ON latch) | | CSM: a timer A load (overflow, and in the die reading also the start of the timer) keys every slot on for one 32-cycle round, ORed with the KON state | DIE (IKAOPM_reg.v:514-521, :556; IKAOPM_timer.v:54, :66); see [timers-and-bus.md](timers-and-bus.md) (U8) | | Key-on of a slot is the rising edge of its key state against the state 32 cycles earlier | DIE (IKAOPM_eg.v:181-199) | A software rule from the manual: wait for BUSY = 0 before the next data write. DOC (AM p.6). What happens to a data write made while BUSY is set is not described by any document (U2); in the die reading the holding register is simply overwritten.