Module adpcm

Module adpcm 

Source
Expand description

The ADPCM unit: 64 KiB of RAM, its pointers, the MSM5205 decoder and the audio source (adpcm.py).

Tiers (the base board’s docs/validation.md): [hw: pcetech 8] MacDonald, tier 2, names the registers and a few bit meanings and says the rest is “currently trying to document”; [mfr: Hudson BIOS manual and System Card ROM] tier 3, the BIOS source (AD_STAT, AD_PLAY, ad_*_addr_set in Super CD-ROM2 System V3.00 (J).ASM) shows how the registers are driven; [emu] Mesen2 PceAdpcm.cpp, Geargrafx adpcm*.cpp, Mednafen pcecd.cpp and MAME pce_cd.cpp are tier 5 detectors: where a behaviour comes only from them it is a field of AdpcmSwitches (a named switch) with a U/C entry in the reference’s docs/m8-record.md.

Registers (offsets from $1800):

regwriteread
$08/$09the 16-bit address latch (low / high)($08 reads the CD data bus: the unit)
$0Athe byte for the write pointer, which then stepsthe read buffer; next fetch starts
$0BDMA control (bit 1 requests CD-to-ADPCM DMA; bit 0 follows a waiting block)the same
$0C–bit 7 read busy, bit 3 playing, bit 2 write busy, bit 0 end reached
$0Dcontrol (below)the last value written
$0Erate: playback at 32 / (16 - n) kHz, n = value & $0Fthe same

Control $0D: bit 7 reset (pointers and length to zero, flags cleared, the read buffer is kept), bit 6 stop at length zero (clear: keep playing), bit 5 play, bit 4 latch the length from the address latch (a length of zero then means 64 KiB), bit 3 copy the latch to the read pointer on a rising edge (bit 2 set: as it is; clear: one less, so the first read fetch lands on it), bit 1 the same for the write pointer (bit 0). [hw: pcetech 8; mfr: the BIOS routines ad_read_addr_set, ad_write_addr_set, ad_length_set]

Flags: the half flag (IRQ2 source $04, $1803 bit 2) is set while less than half of the length is left and the end flag (source $08, $180C bit 0) when the length has run out. [hw: pcetech 8 $1803 bit 2; mfr: AD_STAT reads $180C bit 0 then $1803 bit 2, and $180C bit 3 for busy]

Decoder (MSM5205, 4-bit): a 12-bit signal and a step index 0-48. A nibble is a sign bit and three magnitude bits; the signal moves by step/8 + step/4*b0 + step/2*b1 + step*b2 (integer divisions of step = floor(16 * 1.1 ** index)), the index by -1 -1 -1 -1 +2 +4 +6 +8 clamped to 0..48. Each byte holds two samples, the high nibble first. The audio is the signal held between samples (the AudioSource below).

Differences forced by Rust:

  • Adpcm is its own audio source: the reference’s AdpcmSource (an object that holds the unit) is the origin, taken and held fields and the AudioSource impl here; the fader it asks the audio player for is the shared Fader (cdda.rs). The reference’s source first catches the unit up to the mixer’s clock; the board has always done that already (it runs the port device at every advance), and this source cannot reach the unit.
  • on_irq (the reference’s callback into the unit) is the list irq_changes, applied by the unit after each call.
  • The step table is the 49 integers floor(16 * 1.1 ** index) written out, so that it does not depend on a platform’s pow (wasm).

Structs§

Adpcm
RAM, pointers, flags and the decoder. Time comes from the unit (run(mclk) and the now of each register access); the unit calls run for every event from next_event.
AdpcmSwitches
Switches: behaviours only tier 5 gives, or undecidable between sources (the reference’s docs/m8-record.md; its Adpcm class attributes, with its defaults).

Constants§

ADPCM_RAM_BYTES
DELTA
DELTA[index * 8 + magnitude], the signal change for a 3-bit magnitude [MSM5205 data sheet as modelled by MAME msm5205.cpp, Mednafen okiadpcm.cpp, Geargrafx: tier 3/5].
INDEX_STEP
IRQ_END
IRQ_HALF
LENGTH_MASK
[emu: Mesen2, Geargrafx] 17 bits: a length of 64 KiB needs the 17th
OUTPUT_HZ
STEPS
floor(16 * 1.1 ** index) for index 0..48.