# MCD221 CD-Interface and Audio Processor (CIAP)
The MCD221 CIAP implements a CD drive interface suitable for decoding CD-XA and CD-i
disc sectors and directly supports the corresponding audio functions including
mixing, external audio and decoding ADPCM from CD and from memory.
A technical summary of the CIAP is publicly available ([MCD221ts]) but a
complete data sheet is not. This document is an attempt to describe the CIAP
registers with enough level of detail so that they can be emulated in software.
The information in this document beyond what is described in the technical
summary has been determined by reverse engineering the CD-i CIAP driver
*ciapdriv* used by all CD-i players with a [Mono-III] and [Mono-IV] mainboard
generation. This includes an additional register and all of functions of the
register bits.
Because of this, the exact behaviour of register bits is often unclear. In some
of these cases the emulation used by [CD-i Emulator] is described.
In CD-i players the CIAP is directly connected to the main 68000 CPU as host CPU.
The chip also supports a serial host CPU interface; no information about that option
is included in this document.
## Memory map
The following memory map has mostly been taken from the technical summary but
has been augmented with information from reverse engineering.
All memory addresses are hexadecimal and relative to the base address of
the CIAP. In CD-i players this is always 00300000 so that for example ADPCM
buffer 1 is located at main CPU address 00300900.
The CIAP is a 16-bit wide device and does not have an A0 input pin, therefore all
of the memory addresses below are even and all accesses must use word bus cycles.
The 68000 CPU supports reading bytes, words and long words using such cycles but
all writing must be done with aligned word or long word operations.
Address | Description
--- | ---
0000 - 08FE | ADPCM buffer 0
0900 - 11FE | ADPCM buffer 1
1200 - 1B22 | Mainchannel DATA buffer 0
1B24 - 1B2C | Subchannel Q buffer 0
1B2E - 1B8C | Subchannel R-W buffer 0
1BC2 - 24E4 | Mainchannel DATA buffer 1
24E6 - 24EE | Subchannel Q buffer 1
24F0 - 254E | Subchannel R-W buffer 1
2550 - 257E | Unknown
2580 - 25FE | Register area
2600 - 27FE | Program area 1
2800 - 2FFE | Program area 2
3000 - 3FFF | Program area 3
## Register map
The following register map is based on the technical summary but has been
augmented with information obtained by reverse engineering. Registers not in the
technical summary are marked with a * symbol.
Address | Name | Description
--- | --- | ---
2584 | IER | Interrupt enable register
2586 | ISR | Interrupt status register
2588 | TACS | Temporal audio channel select register
258A | AACS | Actual audio channel select register
258C | TCM1 | Temporal channel mask register
258E | ACM1 | Actual channel mask register 1
2590 | ACM2 | Actual channel mask register 2
2592 | FILE | File selection register
2594 | BMAN | Buffer management register
2596 | CCR | CIAP control register
259A | A_SHDW | ADPCM shadow register
25A0 | AP_Left | Audio processor unit left register
25A2 | AP_Right | Audio processor unit right register
25A4 | AP_Vol | Audio processor unit volume register
25A6 | APCR | Audio processor control register
25A8 | ACONF | Audio configuration register
25AA | ASTAT | Audio processor status register
25C0 | ICR | Interrupt control register
25C2 | DMACTL | DMA control register
25C4 | ID* | Identification register
25FE | DLOAD | Download register
The CD-i CIAP driver uses word read and write operations for all registers. However,
the CD-i low-level tests use byte reads for the ID register.
[CD-i Emulator] does not implement byte access for any register except the ID register.
## Concept of operation
The CIAP sector decoder accepts incoming serial data from a CD drive and uses
the embedded framing information to split this into frames of 1/75th second.
Each frame is then decoded into 2340 bytes of mainchannel data and XXX bytes of
subchannel data, 10 bytes for subchannel Q and 12 bytes each for subchannels R to W.
The mainchannel sector sync bytes and subchannel frame sync bits
are not made available to the host processor and neither are the
subchannel Q CRC bytes.
The mainchannel data part of each sector starts with four bytes of minute,
second, frame, and mode information. For mode 2 sectors this is directly followed
by two four byte sets of file, channel, submode and coding information. The CIAP can
use filtering on the file and channel bytes to select sectors for delivery to
memory and can also optionally send the ADPCM contents of mode 2 audio sectors
in specific channels directly to the CIAP audio processor for decoding.
The CIAP does not implement control functions for CD drives. For CD-i these
functions are implemented by a separate 68HC05 microcontroller called IKAT.
The CIAP is a microcoded device; the CD-i CIAP driver downloads the microcode
from the OS-9 data modules *ciap15_mc0*, *ciap15_mc1* and *ciap15_mc2* into
CIAP Program areas 1 to 3 on device initialization (INIT entry point).
## Register description
Except for most of the register names, all of the information below has been
determined by reverse engineering.
When the function of individual bits is not known this has been indicated with a
question mark ? in the corresponding bit position. For emulation purposes these
bits should be preserved when written but otherwise not used.
#### IER - Interrupt enable register
| 15 | 14 | 13 | 12 |
11 | 10 | 9 | 8 |
7 | 6 | 5 | 4 |
3 | 2 | 1 | 0 |
| ? |
? |
? |
? |
QERROR |
? |
? |
? |
? |
? |
? |
? |
AUDIO |
SUBCODE |
? |
DATA |
The bits of this register specify the conditions for generating interrupts to
the host CPU. If a bit in this register is set, an interrupt will be
generated whenever the corresponding bit in ISR becomes set. See the description
of ISR for a description of the conditions associated with each bit.
#### ISR - Interrupt status register
| 15 | 14 | 13 | 12 |
11 | 10 | 9 | 8 |
7 | 6 | 5 | 4 |
3 | 2 | 1 | 0 |
| ? |
? |
? |
? |
QERROR |
? |
? |
? |
? |
? |
? |
? |
AUDIO |
SUBCODE |
? |
DATA |
The bits of the this register indicate conditions that can generate interrupts
to the host CPU. If the corresponding bit in IER is set, an interrupt
will be generated whenever a bit becomes set.
Reading this register will clear all the bits and any corresponding interrupt.
The DATA bit indicates that new sector data has been read from the CD drive and
is available in the current Mainchannel DATA buffer.
The SUBCODE bit indicates that new subcode data has been read from the CD drive
and is available in the current Subchannel Q and R-W buffers.
The AUDIO bit indicates that an interrupt condition was generated by the audio
decoder.
The QERROR bit indicates that the Subchannel Q buffer is not valid,
probably because it has a bad CRC in the last bytes.
[CD-i Emulator] never sets the QERROR bit.
#### TACS - Temporal audio channel select register
| 15 | 14 | 13 | 12 |
11 | 10 | 9 | 8 |
7 | 6 | 5 | 4 |
3 | 2 | 1 | 0 |
| Ch 15 |
Ch 14 |
Ch 13 |
Ch 12 |
Ch 11 |
Ch 10 |
Ch 9 |
Ch 8 |
Ch 7 |
Ch 6 |
Ch 5 |
Ch 4 |
Ch 3 |
Ch 2 |
Ch 1 |
Ch 0 |
For Mode 2 sectors the bit of this register corresponding to the submode channel byte
must be set for ADPCM data from audio sectors to be directly decoded by the audio processor
without being passed to the host processor.
The CD-i CIAP driver always writes the FILE, TACS, TCM1, ACM2 registers
together and in that order. The AACS and ACM1 registers are never written.
#### AACS - Actual audio channel select register
The CD-i CIAP driver never accesses this register.
#### TCM1 - Temporal channel mask register
| 15 | 14 | 13 | 12 |
11 | 10 | 9 | 8 |
7 | 6 | 5 | 4 |
3 | 2 | 1 | 0 |
| Ch 15 |
Ch 14 |
Ch 13 |
Ch 12 |
Ch 11 |
Ch 10 |
Ch 9 |
Ch 8 |
Ch 7 |
Ch 6 |
Ch 5 |
Ch 4 |
Ch 3 |
Ch 2 |
Ch 1 |
Ch 0 |
For Mode 2 sectors the bit of this register corresponding to the submode channel byte
must be set for sector sectors to be selected for delivery to memory.
The CD-i CIAP driver always writes the FILE, TACS, TCM1, ACM2 registers
together and in that order. The AACS and ACM1 registers are never written.
#### ACM1 - Actual channel mask register 1
The CD-i CIAP driver never accesses this register.
#### ACM2 - Actual channel mask register 2
| 15 | 14 | 13 | 12 |
11 | 10 | 9 | 8 |
7 | 6 | 5 | 4 |
3 | 2 | 1 | 0 |
| Ch 31 |
Ch 30 |
Ch 29 |
Ch 28 |
Ch 27 |
Ch 26 |
Ch 25 |
Ch 24 |
Ch 23 |
Ch 22 |
Ch 21 |
Ch 20 |
Ch 19 |
Ch 18 |
Ch 17 |
Ch 16 |
For Mode 2 sectors the bit of this register corresponding to the submode channel byte
must be set for sector sectors to be selected for delivery to memory.
The CD-i CIAP driver always writes the FILE, TACS, TCM1, ACM2 registers
together and in that order. The AACS and ACM1 registers are never written.
#### FILE - File selection register
| 15 | 14 | 13 | 12 |
11 | 10 | 9 | 8 |
7 | 6 | 5 | 4 |
3 | 2 | 1 | 0 |
| ? |
? |
? |
? |
? |
? |
? |
? |
File number |
For Mode 2 sectors the submode file byte must match the file number in this register
for that sector the be selected for delivery to memory.
The CD-i CIAP driver always writes the FILE, TACS, TCM1, ACM2 registers
together and in that order. The AACS and ACM1 registers are never accessed.
#### BMAN - Buffer management register
| 15 | 14 | 13 | 12 |
11 | 10 | 9 | 8 |
7 | 6 | 5 | 4 |
3 | 2 | 1 | 0 |
| ? |
? |
? |
? |
? |
? |
? |
? |
XXX1? |
XXX0? |
SUBCH1 |
SUBCH0 |
DATA1 |
DATA0 |
ADPCM1 |
ADPCM0 |
This register controls buffer usage during disc reading and audio playback.
Each of the ADPCM*n* bits indicates if ADPCM buffer *n* contains ADPCM audio data
to be decoded by the audio processor.
Each of the DATA*n* bits indicates if Mainchannel DATA buffer *n* contains
sector data that has been decoded from CD.
Each of the SUBCH*n* bits indicates if Subchannel Q buffer *n* contains
subchannel Q data that has been decoded from CD.
Each of the XXX*n* bits indicates if XXX buffer *n* contains XXX.
The XXX buffers are located inside ADPCM buffer 1 at offset 00 and C0,
respectively.
Writing to this register results in the buffer usage bits being XORred
with the bit values written, i.e. writing of a set bit toggles the corresponding
register bit, writing of a clear bit does nothing.
During regular CIAP operation, each bit pair is toggled when the corresponding
buffer has been processed.
#### CCR - CIAP control register
This register accepts control commands for the CIAP.
The following words are written by the CD-i CIAP driver.
Word | Name | Description
--- | --- | ---
0008 | ASEL | Activate selection on next sector
0040 | ??? | ?
0094 | STARTA | Start audio playback (audio track)
00C4 | STARTD | Start data read (data track and lead-in)
0100 | RESET | Reset CIAP
3000 | PREPA | Prepare for audio playback
7000 | PREPD | Prepare for data read
The CD-i CIAP driver always writes PREPx immediately followed by STARTx.
[CD-i Emulator] ignores the PREPx commands and does not distinguish between the STARTx commands.
#### A_SHDW - ADPCM shadow register
| 15 | 14 | 13 | 12 |
11 | 10 | 9 | 8 |
7 | 6 | 5 | 4 |
3 | 2 | 1 | 0 |
| ? |
? |
BITS8 |
FREQ18K9 |
STEREO |
? |
? |
? |
? |
? |
? |
? |
EMPH |
? |
? |
? |
The bits in this register specify the format of the ADPCM data in the ADPCM
buffers. The format information is copied to an internal register for each ADPCM
buffer when the corresponding bit of the BMAN register is set by the host CPU.
The EMPH, STEREO, FREQ18K9 and BITS8 bit correspond directly to bits of the
submode coding byte for audio sectors as follows:
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
--- | --- | --- | --- | --- | --- | --- | ---
0 | EMPH | 0 | BITS8 | 0 | FREQ18K9 | 0 | STEREO
#### AP_Left - Audio processor unit left register
This register controls audio mixing.
The CD-i CIAP driver always writes the AP_Right and AP_Left registers
together and in that order.
[CD-i Emulator] does not currently implement this register.
#### AP_Right - Audio processor unit right register
This register controls audio mixing.
The CD-i CIAP driver always writes the AP_Right and AP_Left registers
together and in that order.
[CD-i Emulator] does not currently implement this register.
#### AP_Vol - Audio processor unit volume register
The CD-i CIAP driver never accesses this register.
#### APCR - Audio processor control register
This register accepts control commands for the audio processor.
The following words are written by the CD-i CIAP driver.
Word | Name | Description
--- | --- | ---
0020 | INTDONE | Generate interrupt when audio playback is done
00A0 | INTNOW | Generate an immediate interrupt
0140 | PLAY0 | Start audio playback with ADPCM buffer 0
#### ACONF - Audio configuration register
The CD-i CIAP driver writes the following words to this register:
Word | Name | Description
--- | --- | ---
0002 | ? | ?
0003 | ? | ?
#### ASTAT - Audio processor status register
| 15 | 14 | 13 | 12 |
11 | 10 | 9 | 8 |
7 | 6 | 5 | 4 |
3 | 2 | 1 | 0 |
| ? |
? |
? |
? |
? |
? |
? |
? |
INT |
? |
? |
? |
? |
? |
? |
? |
The bits in this register indicate the status of the audio processor.
The INT bit indicates that the AUDIO bit in ISR has been set by the audio processor.
It is unclear when this bit should be cleared; [CD-i Emulator] never clears it.
On reset, this register is initialized to hexadecimal 0400.
The CD-i CIAP driver never writes to this register.
#### ICR - Interrupt control register
| 15 | 14 | 13 | 12 |
11 | 10 | 9 | 8 |
7 | 6 | 5 | 4 |
3 | 2 | 1 | 0 |
| ? |
? |
? |
? |
? |
Vector |
Level |
This register controls the CIAP interrupt vector and level.
The CD-i CIAP driver writes this register at device initialization (INIT entry
point) using the values from the device descriptor.
#### ID* - Identification register
| 15 | 14 | 13 | 12 |
11 | 10 | 9 | 8 |
7 | 6 | 5 | 4 |
3 | 2 | 1 | 0 |
| C |
D |
0 |
2 |
The ID register identifies the CIAP version and is read-only.
All read operations will return the hexadecimal value CD02.
Note: The CD-i low level tests use byte operations to read this register.
#### DMACTL - DMA control register
| 15 | 14 | 13 | 12 |
11 | 10 | 9 | 8 |
7 | 6 | 5 | 4 |
3 | 2 | 1 | 0 |
| ? |
START |
DIR |
Word offset |
This register controls DMA transfers.
The word offset specifies the buffer address for DMA access.
This is automatically incremented by one after each transfer.
The DIR bit controls the direction of DMA operation.
Setting the START bit starts DMA operation by setting the REQ output signal.
This will cause the system DMA controller (when appropriately programmed)
to perform back-to-back word DMA transfers.
[CD-i Emulator] never asserts the DONE output signal.
#### DLOAD - Download register
The DLOAD register controls downloading of microcode into Program areas 1 to 3.
The CD-i CIAP driver writes 0001 to this register before downloading the
microcode and writes 0000 after. As configured by the CIAP device descriptor
modules, microcode from OS-9 data modules is downloaded into the CIAP as
follows:
Module | Area
--- | ---
*ciap15_mc0* | Program area 1
*ciap15_mc1* | Program area 2
*ciap15_mc2* | Program area 3
[MCD221ts]: http://www.icdia.co.uk/docs/mcd221tsrev0.zip
[Mono-III]: https://www.cdiemu.org/players/
[Mono-IV]: https://www.cdiemu.org/players/
[CD-i Emulator]: https://www.cdiemu.org/cdiemu/