# Sound DS p. 41-44 (tier 2); OBSERVED behaviour of the firmware in MAME. MAME models the output as an "8-Bit R-2R DAC" and two "4-Bit R-2R DAC"s (`-listxml`): a model, not evidence. ## The generator (DS p. 41) - **SG0, SG1**: arbitrary waveforms, 32 steps of 4 bits each, stored in SG0W0-15 / SG1W0-15 (0060-007F) as two steps per byte, **low step in bits 7-4** ("In order of Low and High": STEP0 in the high nibble of SGxW0, STEP1 in the low nibble: DS Fig. 20). Each 4-bit value is signed, -8 to +7. The waveform registers can be read or written only while the channel is disabled. - **SG2**: noise ("random rectangular waveform"), its rate from a 12-bit time constant. - **Time constants**: 12 bits (SGxTH bits 3-0 : SGxTL), "must be written by MOVW", must not be 0 or 1. DS's formula for one step's period is printed "Period = fCK(n-1)", which is not dimensionally a time (**C3**): (n + 1)/fCK or (n - 1)/fCK is meant; which one is **U11**. - **Output levels** SG0L, SG1L, SG2L: 5 bits, attenuation 0, 1/32 ... 31/32. - **Mixer**: each channel's 4-bit value is "expanded to sixteen times" (x16), attenuated, and the three are added; DS warns the sum must not overflow the mixer (overflow behaviour **U12**). - **SGDA** (004E, write only): an 8-bit value sent straight to the D/A when SG0-2 are disabled and both SONDOUT (SGC bit 7) and DIROUT (SGC bit 3) are set. - SGC (0040): bit 7 sound output enable, bit 3 D/A direct, bits 2-0 SG2/SG1/SG0 enables. - The D/A's output is 0-5 V; software makes the mute level and ramps (DS Fig. 21). ## What the firmware uses (OBSERVED, MAME, 300 frames) SGC = 88h (output on, direct D/A) 258 times, and **SGDA written 31,384 times** in about 5 s (~6,250 a second): the firmware plays sampled sound by writing the D/A from software, timed by Timer 1 (TM1C 80h/81h, TM1D 18h/D0h, IE1 = 50h: Timer 1 and clock interrupts). The waveform registers were each written once (initialisation). Cartridge games were not traced (mame-oracle.md). ## Model level The D/A value over time is the board's output. SGDA writes land at CPU-cycle times; SG0-2 step on fCK dividers. Cycle-exact is cheap (a few counters); the host resamples.