# Timers, flags, /IRQ, BUSY, CT pins, test register, /IC Citation forms: [start-here.md](start-here.md). Line numbers are IKAOPM 08a5b40's. Times are in input clocks (fM) unless "cycles" (internal cycles, two input clocks each) or "samples" (32 cycles) is said. The register bits are in [registers.md](registers.md). ## Clock | Rule | Evidence | | --- | --- | | fM 3.0-4.0 MHz (3.58 typical); the chip runs at fM / 2, and the phi1 pin outputs that clock for the D/A converter | DOC (DS p.3, p.6; AM p.24) | | IRQ, CT1, CT2, SO, SH1 and SH2 change when phi1 falls | DOC (DS p.3; AM p.24) | | 32 internal cycles per sample (one per slot); sample rate fM / 64 | DOC (AM p.6); DIE (IKAOPM_timinggen.v:219-232) | ## Timers and flags | Rule | Evidence | | --- | --- | | Timer A: 10-bit, period 64 (1024 - NA) / fM; timer B: 8-bit, period 1024 (256 - NB) / fM | DOC (AM p.13-14) | | Timer A counts once per sample while running; it loads NA when started (LOAD 0 -> 1) and at each overflow; stopping it clears it | DIE (IKAOPM_timer.v:46-66) | | Timer B counts once per 16 samples, from a 4-bit prescaler that runs freely (only /IC resets it), so the first period after a start is shorter by up to 15 samples | DIE (IKAOPM_timer.v:70-104) | | An overflow sets the timer's flag only if its IRQ EN bit is 1; while IRQ EN is 0 the flag is held at 0 | DOC (AM p.14: IRQ EN "inhibit the flag register"); DIE (IKAOPM_timer.v:112-127) | | F RESET (0x14 bits 4, 5) clears a flag at that write; writing 0x14 with LOAD and IRQ EN unchanged is the usual acknowledge | DOC (AM p.14); DIE (IKAOPM_reg.v:451-452) | | /IRQ (open drain) is low while either flag is set | DOC (DS p.3; AM p.14-15); DIE (IKAOPM_timer.v:129) | | Test bit 2 makes both timers count every cycle | DIE (IKAOPM_timer.v:53, :93) | Closed box (OBSERVED, Nuked-OPM f209e6e, `reference/referee-probe.txt`; data write before cycle 400): timer A NA 1023 flags 49 cycles after the LOAD write, NA 1022 81 cycles, NA 1000 785 cycles, and /IRQ follows one cycle later; free-running NA 1000 flags every 768 cycles (24 samples, as the formula says). Timer B NB 255 flags after 81 cycles and NB 254 after 593 (512 cycles per count, the free prescaler setting the first period). The first-period offset (17 cycles past the formula for timer A) is the write path plus pipeline; the die reading has the same structure, and the exact cycle is a rung 2 gate against the referee. **CSM.** Timer A loading keys every slot on for one round (32 cycles). DOC (AM p.15: "a key-on in all sound source slots when Timer A generates an overflow"). The die also loads timer A, and so keys on, at the write that starts it (IKAOPM_timer.v:54, :66; IKAOPM_reg.v:520). The closed box agrees: with CSM set, a carrier never keyed by KON sounds 6 samples after the LOAD write, long before the first overflow (1,024 samples); without CSM it stays silent. OBSERVED (Nuked-OPM f209e6e, `scripts/referee_survey.py`). ## BUSY (C2) | Source | Says | | --- | --- | | Manual | "From the time the write command is received until the write is completed, a period of fM 68 bits is required" (68 input clocks). DOC (AM p.6) | | IKAOPM | BUSY is set when the data write leaves the input synchronizer (a couple of cycles after the strobe) and cleared by a 5-bit counter: 32 cycles = 64 input clocks after that, so about 68 input clocks from the strobe. DIE (IKAOPM_reg.v:120-167, :749-767) | | Closed box | BUSY reads 1 from the cycle after the data write, for exactly 32 cycles (64 input clocks), at every write phase tried. OBSERVED (Nuked-OPM f209e6e, `reference/referee-probe.txt`) | | MAME 0.285 (ymfm) | Clears BUSY 64 input clocks after the write, 4 earlier than the referee in the `ddragon` replay ([mame-oracle.md](mame-oracle.md)) | The manual and the die reading agree on about 68 input clocks from the strobe; the closed box shows 64 counted from the cycle after the write. The difference is where the count starts (the synchronizer delay, U2), not the counter. The core takes the die structure (DIE, consistent with DOC); the referee comparison at rung 2 will show a constant offset of the BUSY edges, which is written down, not fixed. ## CT pins (C1) | Source | Says | | --- | --- | | Manual | register 0x1B bits D6 and D7 "correspond to output terminals CT1 and CT2" (D6 -> CT1). DOC (AM p.6) | | Data sheet | pin 8 is CT1, pin 9 is CT2. DOC (DS p.2; AM p.23) | | IKAOPM | traced on the die: bit 7 drives pin 8, bit 6 drives pin 9; "there are datasheets that have CT2 and CT1 reversed". DIE (IKAOPM README; IKAOPM.v:33-34) | | Closed box | YM2151 mode: bit 6 -> the line its header calls CT1, bit 7 -> CT2; YM2164 mode: swapped. OBSERVED (Nuked-OPM f209e6e, `referee-probe.txt`; names only, no pin numbers) | Read together, the two Yamaha documents put bit 6 on pin 8; the die reading puts bit 7 on pin 8. Decision 8 sidesteps the names: the core exposes a 2-bit `ct` by register bit, with the pin question in its docstring. With test bit 3 set, the bit-6 output carries the LFO clock instead. DIE (IKAOPM_reg.v:441-444). The CT outputs are 0 after /IC. DOC (DS p.3). ## Test register (0x01) "A TEST-use signal; entering level 1 data in a place other than the designated bit will cause the device to go into the test mode." DOC (AM p.13). The manual documents bit 1 (LFO reset) only. IKAOPM implements every bit (README: "All LSI test bits are implemented"): | Bit | Effect in the die reading | Evidence | | --- | --- | --- | | 0 | envelope steps every sample | DIE (IKAOPM_eg.v:77) | | 1 | LFO held in reset | DOC (AM p.13); DIE (IKAOPM_lfo.v:251-279) | | 2 | LFO and both timers clock every cycle | DIE (IKAOPM_lfo.v:215; IKAOPM_timer.v:53, :93) | | 3 | LFO counter every cycle; all phases held at 0; LFO clock on the bit-6 CT pin | DIE (IKAOPM_lfo.v:140; IKAOPM_pg.v:689; IKAOPM_reg.v:442) | | 4 | operator output sign path altered | DIE (IKAOPM_op.v:253, :308) | | 5 | final attenuation forced to 0 (loudest) | DIE (IKAOPM_eg.v:720, :787) | | 6 | status read replaced by operator output bits | DIE (IKAOPM_reg.v:778) | | 7 | with bit 6: phase / attenuation probe bits in the read | DIE (IKAOPM_reg.v:777) | Only bit 1 has been checked on the closed box. Bits 0 and 2-7 are DIE-only (U4). ## /IC | Rule | Evidence | | --- | --- | | /IC low initializes the registers and circuits; CT pins 0 | DOC (DS p.3; AM p.6) | | The falling edge of /IC realigns the phi1 phase; IKAOPM needs /IC held at least 64 input clocks to flush all pipelines | DIE (IKAOPM_timinggen.v:59-116, :183-186; README `FAST_RESET`) | | While /IC is low the slot counter is held at 0 and SH1/SH2 are held low | DIE (IKAOPM_timinggen.v:223-232, :293-294) | | After /IC: every slot in release at level 1023, phases 0, timers stopped, flags 0 | DIE (IKAOPM_eg.v:263-264; IKAOPM_pg.v:540, :725; IKAOPM_timer.v:113, :121) | | The output accumulators are not reset on the chip (IKAOPM resets them only as an FPGA convenience) | DIE (IKAOPM_acc.v:82) |