MSU1 - Development Guide
Readable registers
$2000: status port
d7 = data port busy
d6 = audio port busy
d5 = audio repeating
d4 = audio playing
d3-d0 = MSU1 chip revision (always 1)
This register tells you the current status of the MSU1.
Note that on some implementations, especially hardware, the choice of media storage may add latency. Although no delay is necessary for an emulator, nor for hardware that utilizes parallel NOR flash memory, certain storage mediums are not as fast. For instance, imagine a DVD-ROM based version. When seeking to a certain location to read from, the disc drive must seek to that position, and perform some basic buffering.
As such, you must not access certain registers while their respective busy flags are set; or your implementation may not work on real hardware. Use a wait loop as shown below to wait for the device to be ready first.
; wait for data port to be ready for reading -; bit $002000; bmi - ; wait for audio port to be ready for playback -; bit $002000; bvs -
The revision value is reserved for possible future expansion.
$2001: stream port
accessible only when $2007.d7 = 0
Reads one byte from the 4GB data storage device. It will read from the current offset, and then increment the offset by one.
Attempting to read from this register while the data port busy flag is set is forbidden. Doing so will not increment the read offset, nor will it return valid data.
$2002-2007: identification
Returns the chip identification string, "S-MSU1" ('1' is at $2007.) Use this to detect the presence of the S-MSU1 coprocessor.
Note that for certain uses, such as enhanced audio, a non-MSU1 fallback option can be implemented for greater compatibility.
Writable registers
$2000-2003: data port address (32-bit)
$2000 = data port lo
$2001 = data port hi
$2002 = data port bank lo
$2003 = data port bank hi
These registers set the data port address.
Strictly speaking, there is both the internal read offset, and the register port values. The internal read offset is only updated and seeked to once $2003 is written.
Note that after writing to $2003, you must wait for the data port busy flag to be cleared before you can begin reading from the stream port.
$2004-2005: audio track number (16-bit)
$2004 = audio track lo
$2005 = audio track hi
These registers set the audio track number.
Like the data port address, there is the internal playing track number, and the register port values. The track number is only changed upon writes to $2005.
Note that writing to $2005 will immediately stop the currently playing track (with no fade out on the audio volume). You must also wait for the audio port busy flag to be cleared, before you can begin playing the new track number.
$2006: audio volume
This register will set the audio playback volume. This operates on a linear scale, where 0 = 0% (muted), 127 = ~50% (half volume), 255 = 100% (full volume.)
You can change this register even while audio is playing. With a timed loop, you can use this register to do audio fade-ins and fade-outs at arbitrary points. It is recommended you do this prior to changing a track number or pausing to prevent audio popping.
$2007: audio state
accessible only when $2007.d6 = 0
d7-d2 = unusued (must be zero for compatibility with future revisions)
d1 = repeat
d0 = play
This register controls the audio state of the MSU1.
If the repeat flag is set, the audio track will loop forever. This will effectively keep the playing flag always set. If the repeat flag is not set, the song will stop after it has finished playing.
The play flag, when set, will begin playing music. Clearing the flag is equivalent to pausing the audio. Setting the flag again will resume playback where it previously left off.
Attempting to write to this register while the audio port busy flag is set will have no effect. It will not start playing audio, and it will not change the repeat flag's state internally.
PCM file format
MSU1 audio files are stored as 44.1KHz 16-bit signed stereo files, with optional loop point.
The first four bytes of the file are the signature string "MSU1" (the first byte is thusly 'M'.)
The next four bytes are a little-endian value that represents an optional loop position, for tracks played with the repeat flag set. After the file has played completely, it will skip to this sample number. This can be used to create songs that seemingly never stop playing. As this is a sample index, and not a byte index, the exact file offset is 8 + loop_offset * 4. You can set this value to zero to repeat as ordinary audio tracks do.
The rest of the file consists of 16-bit signed stereo samples, to be played back at 44.1KHz (redbook audio specification.) Each sample is stored as a 4-byte little-endian value. The high 16-bits represent the right sample, and the low 16-bits represent the left sample.