# Clocks, timers and the serial output Citations as in [registers.md](registers.md). ## Clocks - Master clock phi M 8 MHz (7.5-8.5 MHz). [DOC AM §5, §6.4] Every YM2610 in MAME 0.285 runs at 8 MHz. [census, [users-and-census.md](users-and-census.md)] - One output sample every **144** phi M clocks (55.56 kHz at 8 MHz): SH1 rises every 144 clocks. [OBSERVED lle:clock] ymfm's YM2610 sample rate is clock/144. [DOC ymfm ymfm_opn.h:674-675] The OPNA's FM rate at its default prescaler (1/6) is the same phi M/144 (Table 2-1's 1/6 with 24 operator slots). [DOC OPNA p. 19; ymfm ymfm_opn.h:280-283] - The YM2610 has no prescaler registers ($2D-$2F): the manual's register map lists none. [DOC AM "Write Data (FM)"] (The OPNA has them. [DOC OPNA p. 19]) - phi S, the DAC's bit clock, is an output of one clock high in three: phi M / 3, 48 bits per sample. [OBSERVED lle:clock] (The manual's pin list marks phi S, SH1, SH2 and OPO "(I)"; they are outputs. [DOC AM §5] ) ## The serial word (OPO, SH1, SH2) Seen from the closed box, counting bit 0 as the first phi S rise after the clock on which SH1 rises [OBSERVED lle:clock, lle:fm]: | phi S bits | SH1 | SH2 | OPO | | --- | --- | --- | --- | | 0-7 | high | low | bits 0-6: the R word's bits 9-15 | | 8-23 | low | low | bits 15-23: the L word's bits 0-8 | | 24-31 | low | high | bits 24-30: the L word's bits 9-15 | | 32-47 | low | low | bits 39-47: the R word's bits 0-8 | - Each word is **16 bits, LSB first, offset binary**: $8000 is zero (silence sends a single 1, the MSB). [OBSERVED lle:clock] The L word is the one bit 7 of $B4-$B6 selects, the R word bit 6. [OBSERVED lle:fm, pan $80] - This fits the YM3016: a 2-channel serial DAC with "16-bit binary or 2's complement input", the choice made by its FORM pin, its floating conversion (10-bit mantissa, 7-step exponent) done **inside the DAC**. [DOC YM3016 p. 32] That the Neo Geo ties FORM to VCC is [HYPOTHESIS: was NGD *YM3016*]; it needs new evidence (a board schematic or a photograph of the trace). Which level of FORM means binary is not on the sheet's readable pages: **U9**. - Each word completes while the other channel's SH line is high, and the DAC presumably latches it on that line's fall (L by SH2, R by SH1). [HYPOTHESIS; settle with the YM3016 sheet's timing figure, unreadable in this scan, or a scope on a Neo Geo] - What the word holds: the sum of the FM channels and both ADPCM parts, clamped to 16 bits. One FM carrier at TL 0 swings +-4084; ADPCM-A at full level adds up to about +-15,000; ADPCM-B up to +-16,320. [OBSERVED lle:fm, lle:adpcma, lle:adpcmb] ymfm: FM scaled down one bit ("OPNB is 13-bit with no intermediate clipping"), then ADPCM-A and B added, then a 16-bit clamp. [DOC ymfm ymfm_opn.cpp:2180-2186] Clamping, not wrapping, of the final sum is ymfm's and was not tested past one source at a time: **U10**. - The SSG is not in the word: it has its own analogue pin. [DOC AM §3(b), §5] ## Timers - Timer A, 10 bits ($24 = bits 9-2, $25 = bits 1-0); timer B, 8 bits ($26); $27: D7-D6 mode, D5/D4 reset B/A flag, D3/D2 enable B/A flag (and /IRQ), D1/D0 load (run) B/A. [DOC AM "Write Data (FM)"; OPNA pp. 35-36] - Periods in phi M clocks: **timer A 144 x (1024 - NA)**, **timer B 2304 x (256 - NB)**; the flag is set again each period (the timer reloads). [OBSERVED lle:timers: NA 1023, 1020, 1000 give 144, 576, 3456; NB 255, 254, 250 give 2304, 4608, 13824] - ymfm: (1024 - NA) x 24 x 6 and 16 x (256 - NB) x 24 x 6. [DOC ymfm ymfm_fm.ipp:1480-1486] - The OPNA manual: tA = 72 x (1024 - NA) / phi M (9 us minimum at 8 MHz) and tB = 1152 x (256 - NB) / phi M. [DOC OPNA p. 35] Half the closed box's: these look like the YM2203's figures at its own clock carried into the OPNA manual. Contradiction **C1**; the core follows the closed box and ymfm. [HYPOTHESIS for the reason] - The flag reset (D5/D4) clears the flag within 2 clocks of /WR's rise. [OBSERVED lle:timers] D2/D3 clear: the counter runs, no flag, /IRQ released. [OBSERVED lle:timers; DOC OPNA p. 36] - That writing 1 to load copies the load value only when the counter is at zero, and writing 0 resets the counters, is [HYPOTHESIS: was NGD *YM2610 timers*], not measured; ymfm starts timer B with a small negative adjustment (`-(m_total_clocks & 15)`). [DOC ymfm ymfm_fm.ipp:1584-1587] Load timing: **U8**. - CSM: timer A's overflow keys channel 2's operators when $27 D7-D6 selects it. [DOC OPNA p. 36; ymfm ymfm_fm.ipp:1515] Not measured: **U8**. ## The ROM buses - ADPCM-A: RAD0-7 multiplexed address/data, RA8-9, RA20-23, RMPX (address latch strobe), /ROE. ADPCM-B: PAD0-7, PA8-11, PMPX, /POE. [DOC AM §5] - The bit mapping (on RMPX's rise RAD0-7, RA8-9 carry address bits 0-9; on its fall bits 10-19 and RA20-23 bits 20-23; PMPX likewise with 12 + 12 bits; one ADPCM-A read in 6 periods of 1.5 us, the channels in turn; one ADPCM-B read in 6 periods of 250 ns) is [HYPOTHESIS: was NGD *YM2610 ADPCM bus*]; only RMPX's 72-clock period has other evidence (below). - The closed box: RMPX rises every **72 clocks**, so each of the six ADPCM-A channels is read once per 432 clocks (3 samples). [OBSERVED lle:adpcma] The rest (channel order, the address on the pins, /ROE's timing, every ADPCM-B bus signal) was not measured: the probe uses only the pins it carried over (docs/validation.md), and the other pins' names are in a header this restart did not open. **U4**. - The core's interface is decision 3: byte callbacks with 24-bit addresses, called on the clock the chip latches each byte; the multiplexed pins only as a debug trace. [docs/decisions.md] ## The SSG's pin See [ssg.md](ssg.md). The analogue mix of SSG with the DAC's output is the board's (decision 4).