                         MSCDEX   ver. 2.20
                            / part two /

- Audio Track Info

TnoInfoDB11; Control block code
DB?; Track number
DD?; Starting point of the track
DB?; Track control information

This function takes a binary track number, from within the range
specified by the lowest and highest track number given by the Audio
Disk Info command, and returns the Red Book address for the starting
point of the track and the track control information for that track.
The track control information byte corresponds to the byte in the TOC 
in the lead-in track containing the two 4-bit fields for CONTROL and
ADR in the entry for that track. The CONTROL information is in the
most significant 4 bits and the ADR information is in the lower 4
bits. The track control information is encoded as follows:

00x00000- 2 audio channels without pre-emphasis
00x10000- 2 audio channels with pre-emphasis
10x00000- 4 audio channels without pre-emphasis
10x10000- 4 audio channels with pre-emphasis
01x00000- data track
01x10000- reserved
11xx0000- reserved
xx0x0000- digital copy prohibited
xx1x0000- digital copy permitted

- Audio Q-Channel Info

QInfoDB12; Control block code
DB?; CONTROL and ADR byte
DB?; Track number (TNO)
DB?; (POINT) or Index (X)
; Running time within a track
DB?; (MIN)
DB?; (SEC)
DB?; (FRAME)
DB?; (ZERO)
; Running time on the disk
DB?; (AMIN) or (PMIN)
DB?; (ASEC) or (PSEC)
DB?; (AFRAME) or (PFRAME)

This function reads and returns the most up to date Q-channel address 
presently available. It must not interrupt the present status of the
drive as one of its intended purposes is to monitor the location of
the read head while playing audio tracks. This function should return 
valid information even when no audio tracks are being played and the
head is stationary. The fields returned correspond to the data that
is stored in the Q-channel as described in the Red Book. The values
in MIN-SEC-FRAME, AMIN-ASEC-AFRAME and PMIN-PSEC-PFRAME are converted 
by the driver from BCD to binary so that minutes range from 0 to 59+, 
seconds from 0 to 59, and frames from 0 to 74. The Control and ADR
byte, TNO, and POINT/Index bytes are always passed through as they
appear on the disc and are not converted. If the drive returns
Q-channel information when ADR is not equal to 1, then when ADR is
not equal to 1 all ten bytes of information are passed through
unmodified to the caller. 

Audio Sub-Channel Info

SubChanInfoDB13; Control block code
DD?; Starting sector address
DD?; Transfer address
DD?; Number of sectors to read

This function takes a Red Book address of a particular sector (also
known as a block or frame) and copies the sub-channel information for 
each sector requested to the transfer address.  If multiple sectors
are requested, they are copied sequentially.  Each sector contains 96 
bytes of sub-channel information. These bytes do not include the two
sync patterns (S0 and S1) that head the subcoding block.  They
contain only the subcoding symbols--each with one bit of information
for the eight different channels (P-W) that follow them. In this
byte, the 2 most significant bits that represent channels P and Q are 
undefined, the next most significant bit (bit 6) represents channel
R, and the least significant bit (bit 1) represents channel W.

For the sub-channel data to be generally useful it must be provided
during an AUDIO PLAY operation without interrupting it.  Therefore,
when the requested sectors lie within the current play request they
should be provided in real-time.  This requires data buffering (in
the drive or by the driver) for at least one sector of sub-channel
information.  This is because an application using sub-channel
information will send an AUDIO PLAY command, follow it up with
successive and contiguous sub-channel information commands, and
expect to get that data starting with the first sector of the play
request.  It is recommended that the buffer handle up to 32 sectors,
to give an application time to process sub-channel data between
requests.

Since implementation of this command is optional, bit 12 in the
device status long word should indicate whether sub-channel support
is available.  The driver will return an error code of Unknown
Command if it is not supported.

The method of data error detection and correction for R-W channels is 
specified in the Red Book standard, and if not implemented by the
drive, must be provided in the driver software.

- UPC Code

UPCCodeDB14; Control block code
DB?; CONTROL and ADR byte
DB7 dup (?); UPC/EAN code
; (last 4 bits are zero; the low-order nibble of byte 7)
DB?; Zero
DB?; Aframe

This function returns the UPC/EAN (Universal Product Code - BAR
coding) for the disc. This information is stored as a mode-2 (ADR=2)
Q-channel entry. The UPC code is 13 successive BCD digits (4 bits
each) followed by 12 bits of zero. The last byte is the continuation
of FRAME in mode-1 though in the lead-in track (TNO=0) this byte is
zero. If the CONTROL/ADR byte is zero or if the 13 digits of UPC code 
are all zero, then either no catalog number was encoded on the disc
or it was missed by the device driver. If the command is supported
but the disc does not have a UPC Code recorded, then the driver will
return an error code of Sector not Found. If the command is not
supported, then the driver will return an error code of Unknown
Command.

- Audio Status Info

AudStatDB15; Control block code
DW?; Audio status bits
; Bit 0 is Audio Paused bit
; Bits 1-15 are reserved
DD?; Starting location of last Play or for next Resume
DD?; Ending location for last Play or for next Resume

The Audio Paused bit and Starting and Ending locations are those
referred to in the RESUME command. These are recorded in Red Book
addressing mode.

WRITE (IOCTL OUTPUT)

Command code = 12
ES:BX = IOCTLO

IOCTLODB13 dup (0); Request header
DB0; Media descriptor byte from BPB
DD?; Transfer address
DW?; Number of bytes to transfer
DW0; Starting sector number 
DD0; DWORD ptr to requested vol 
; ID if error 0FH
The media descriptor byte, starting sector number, and volume ID
fields are all 0.

The transfer address points to a control block that is used to
communicate with the device driver. The first byte of the control
block determines the request that is being made. The Length of Block
is the number of bytes to transfer. With the exception of Reset Drive 
and Write Device Control String, the action of these request may be
verified with the READ IOCTL Audio Channel Info or Device Status
functions.   

CodeLength of BlockFunction
01Eject Disk
12Lock/Unlock Door
21Reset Drive
39Audio Channel Control
4?Write Device Control String
51Close Tray
6-255?Reserved

- Eject Disk

EjectDB0; Control block code

The device driver will unlock the drive and eject the CD-ROM disk
from the drive unit.  The door will report as being open until the
user has inserted a disk  into the drive unit and closed the door.
The status bit for door open can be monitored to determine when a
disk has been reinserted.

- Lock/Unlock Door

LockDoorDB1; Control block code
DB?; Lock function

When this function is received, the device driver will ask the CD-ROM 
drive to unlock or lock the door. If lock function is 0, the device
driver will unlock the door. If lock function is 1, it will lock the
door.

- Reset Drive

ResetDrvDB2; Control block code

This function directs the device driver to reset and reinitialize the 
drive.


- Audio Channel Control

AudInfoDB3; Control block code
DB?; Input channel (0, 1, 2, or 3) for output channel 0
DB?; Volume control (0 - 0xff) for output channel 0
DB?; Input channel (0, 1, 2, or 3) for output channel 1
DB?; Volume control (0 - 0xff) for output channel 1
DB?; Input channel (0, 1, 2, or 3) for output channel 2
DB?; Volume control (0 - 0xff) for output channel 2
DB?; Input channel (0, 1, 2, or 3) for output channel 3
DB?; Volume control (0 - 0xff) for output channel 3
This function is intended to provide playback control of audio
information on the disk. It allows input channels on the CD-ROM to be 
assigned to specific output speaker connections. The purpose of this
function is to allow two independent channels to be recorded - in
different languages for example - and to play back only one of them
at a time or to be able to manipulate an audio signal so that the
source appears to move - to make a sound seem to move from left to
right for example.

Output channel 0 is the left channel, 1 is right, 2 is left prime,
and 3 is right prime. The Red Book specification allows for 4 audio
channels. The two "prime" channels (2 and 3) extend stereo to
quadrophonic stereo.

An audio volume setting of 0 means off. Drives that don't support 4
output audio channels may ignore output to channels 2 and 3.
Assignment of input channels 2 and 3 to output channels 0 and 1 may
be treated as though the volume control for that channel is 0.

Drives that do not support variable audio control will treat a
setting of 0 as off and 1-0xff as on. Drives that support less than
256 volume settings will do their best to break up the 256 settings
among the settings they can support. E.g. if there are 16 settings
supported, then the first setting will cover 0x01-0x10, the second
0x11-0x20...the sixteenth 0xf1-0xff. Drives that can't play a single
channel in both must play only that one channel and try to suppress
the other if possible. Drives that can't swap channels should play
the channel that was moved in its normal channel.

- Write Device Control String

DrvBytesDB4; Control block code
DBN dup (?); Write buffer

This function is provided to allow programs to talk directly to the
CD-ROM drive. All remaining bytes are sent uninterpreted to the drive 
unit.

The function and content of these bytes are entirely device and
device driver dependent. This function is provided to allow access to 
device-specific features that are not addressed under any other
portion of the device driver spec.

- Close Tray

CloseTrayDB5; Control block code

This command is the logical complement to the Eject Disk command.
This command will instruct drives that can do so to close the door or 
tray.

READ LONG

Command code = 128
ES:BX = ReadL

ReadLDB13 dup (0); Request header
DB?; Addressing mode
DD?; Transfer address
DW?; Number of sectors to read
DD?; Starting sector number
DB?; Data read mode
DB?; Interleave size
DB?; Interleave skip factor

The request block is different from a normal character device READ to 
accommodate the larger size and different characteristics of CD-ROM
devices.

The media descriptor byte, which has no meaning for character
devices, is now the addressing mode field. The following values are
recognized addressing modes:

0HSG addressing mode
1Red Book addressing mode
2-255Reserved

The default addressing mode is the HSG addressing mode. Long (DWORD)
address values are treated as logical block numbers, as defined by
the High Sierra proposal. When Red Book addressing mode is on, all
disk addresses are interpreted as Minute/Second/Frame addresses,
according to the Philips/Sony Red Book standard. Each of these fields 
is 1 byte. The frame byte is the least significant byte of the
address field, the "second" byte the next most significant, the
minute byte the next, and the most significant byte of the 4-byte
field is unused. These values are represented in binary rather than
in BCD format. For example, if we are referencing the sector
addressed by minute 36, second 24, frame 12, the hex long value for
this would be 0x0024180C. This 4 byte value is recorded in the
starting sector number field with the least significant byte first
and most significant byte last.

The relationship between High Sierra sectors and Red Book frames is
described by the equation:

Sector = Minute * 60 * 75 + Second * 75 + Frame - 150

The byte/sector count field becomes the number of sectors to read and 
the starting sector number expands from one word to two, which  means 
we can address up to 4 giga-sectors (over 8 terabytes). The DWORD ptr 
for requested volume ID is eliminated and MSCDEX.EXE will keep track
of what volume is needed.

MSCDEX.EXE handles buffering requests, but performance may be
improved if the device driver reads ahead or uses a sector caching
scheme, given the slow seek times of CD-ROM drives. The operating
system will use the prefetch function when it can to give hints to
the driver.

The data read mode field will be one of the following:

0Cooked mode
1Raw mode
2-255Reserved

Cooked mode is the default mode in which the hardware typically
handles the EDC/ECC and the device driver returns 2048 bytes of data
per sector read. When raw mode is set, the driver will return all
2352 bytes of user data, including any EDC/ECC present independent of 
the actual sector mode (Mode 2 Form 1 vs. Mode 2 Form 2). User
programs will have to consider this and allow enough room for buffer
space when reading in raw mode as each sector returned will take up
2352 bytes of space. Drives that cannot return all 2352 bytes will
return what they can and leave blank what they cannot. For example,
drives that can return all 2336 bytes except the 16 byte header will
leave a space in the first 16 bytes where the header would go so that 
the sectors align on 2352 byte boundaries. Drivers should do what
they can to return as much of the user data per sector as possible.

The two interleave parameters are for drivers that support
interleaved reading. If the driver does not support interleaving,
these fields are both ignored. If it does, interleave size is the
number of consecutive logical blocks or sectors that are stored
sequentially, and the interleave skip factor is the number of
consecutive logical blocks or sectors that separate portions of the
interleaved file.

READ LONG PREFETCH

Command code = 130
ES:BX = ReadLPre

ReadLPreDB13 dup (0); Request header
DB?; Addressing mode
DD0; Transfer address
DW?; Number of sectors to read
DD?; Starting sector number
DB?; Read mode
DB?; Interleave size
DB?; Interleave skip factor

This function is similar in form to READ LONG, but control returns
immediately to the requesting process. The device driver is not
obligated to read in the requested sectors but can instead consider
the request for these sectors as hints from the operating system that 
they are likely to be needed. It is recommended that at a minimum,
the driver seek to the location provided. The attribute in the device 
status for prefetching is used to distinguish drivers that do more
than just seek to the given location. The requests are low priority
and preemptible by other requests for service. A READ LONG PREFETCH
with 0 number of sectors to read should be treated as an advisory
seek, and the driver can, if it is not busy, move the head to the
starting sector. Since prefetching requests are advisory, there will
be no functional difference between a device driver that supports
prefetching from one that does not, except in terms of performance.
The transfer address is not applicable for this call as the driver is 
not meant to transfer any data into the user address space. 

SEEK

Command code = 131
ES:BX = SeekReq

SeekReqDB13 dup (0); Request header
DB?; Addressing mode
DD0; Transfer address
DW0; Number of sectors to read
DD?; Starting sector number

Control returns immediately to the caller without blocking and
waiting for the seek to be completed. The number of sectors to be
read and the transfer address are ignored. SEEK is used to relocate
the head in order to begin playing audio or video tracks, or in
anticipation of reading in a particular region on the disk. Further
requests for disk activity will wait until the given SEEK is
completed. This seek is not advisory and the head must move to the
desired location.

PLAY AUDIO

Command code = 132
ES:BX = PlayReq

PlayReqDB13 dup (0); Request header
DB?; Addressing mode
DD?; Starting sector number
DD?; Number of sectors to read

This function will cause the driver to play the selected audio tracks 
until the requested sectors have been exhausted or until play is
interrupted with an AUDIO STOP request. Control returns immediately
to the caller.  The busy bit in the status word will indicate if the
drive is presently playing audio and when the play request is
completed.  The busy bit in the status word of the request header, as 
well as the paused bit and starting and ending locations returned by
the Audio Status Info IOCTL, will be updated.  If the drive does not
support playing audio this request is ignored.


STOP AUDIO

Command code = 133
ES:BX = StopPlayReq

StopPlayReqDB13 dup (0); Request header

This function is included to pause the drive unit when it is
currently in play mode, or to reset the starting and ending locations 
when in paused mode.  If applicable, at the next stopping point it
reaches the drive will discontinue playing, and process the next
request.  The busy bit in the status word of the request header, as
well as the paused bit and starting location returned by the Audio
Status Info IOCTL, will be updated.  If the drive does not support
playing audio this request is ignored.

RESUME AUDIO

Command code = 136
ES:BX = ResumeReq

ResumeReqDB13 dup (0); Request header

This function is used to resume playing audio tracks when  a previous 
PLAY AUDIO call has been paused with a STOP AUDIO command.   It will
resume playing from the starting location indicated by the Audio
Status Info IOCTL.  It will modify the Audio Paused bit returned by
the Audio Status Info IOCTL, and the busy bit in the status word of
the request header.  If the drive does not support playing audio this 
request is ignored.

In the following example the playing flag corresponds to the state
reported by the busy bit in the status word of the request header
when the drive is in audio play mode. The paused flag corresponds to
the Audio Paused bit and last_startloc and last_endloc correspond to
the starting and ending location reported in the Audio Status Info
IOCTL.





// upon RESET,  NEW DISC,  or PLAY/RESUME COMPLETED the state should
be updated: playing = FALSE;
paused = FALSE;  last_startloc = 0;  last_endloc = 0;
PLAY_AUDIO( startloc, endloc ) {
if ( play( startloc, endloc ) != SUCCESSFUL )  return error;
else { playing = TRUE; paused = FALSE; last_startloc = startloc
last_endloc = endloc return no error; }
}
STOP_AUDIO( void ) {
if ( playing ) { last_startloc = present q-channel location playing = 
FALSE; paused = TRUE;
return (  stop() != SUCCESSFUL );
} else { playing = FALSE; paused = FALSE;  last_startloc = 0;
last_endloc = 0;
return no error;
}
}

RESUME_AUDIO() {
if ( paused ) {
if ( play( last_startloc, last_endloc ) != SUCCESSFUL ) return
error;else { playing = TRUE; paused = FALSE; return no error; }
} else return error;
}

WRITE LONG

Command code = 134
ES:BX = WriteL

WriteLDB(dup 13 0); Request header
DB?; Addressing mode
DD?; Transfer address
DW?; Number of sectors to write
DD?; Starting sector number
DB?; Write mode
DB?; Interleave size
DB?; Interleave skip factor

The device will copy the data at the transfer address to the CD RAM
device at the sector indicated. The media must be writable for this
function to work. Data is written sector by sector, depending on the
current write mode and the interleave parameters. The following
values are recognized as valid write modes:

0Mode 0
1Mode 1
2Mode 2 Form 1
3Mode 2 Form 2
4-255Reserved

Writing in Mode 1 is the default and must be supported. If the device 
driver supports the other modes, then they can be used. If Mode 0 is
used, the transfer address is ignored and all sectors are written
with zeroes. If the current write mode is Mode 1 or Mode 2 Form 1,
each sector will consist of 2048 bytes of data located sequentially
at the transfer address. If the write mode is Mode 2 Form 2, the
device driver will expect 2336 bytes of data per sector at the
transfer address. 
WRITE LONG VERIFY

Command code = 135
ES:BX = WriteLV

WriteLVDB(dup 13 0); Request header
DB?; Addressing mode
DD?; Transfer address
DW?; Number of sectors to write
DD?; Starting sector number
DB?; Write mode
DB?; Interleave size
DB?; Interleave skip factor

This function is identical to WRITE LONG, with the addition that the
device driver is responsible for verifying the data written to the
device.

INPUT FLUSH

Command code = 7
ES:BX = FlushI

FlushIDB13 dup (0); Request header

Requests that the device driver free all input buffers and clear any
pending requests.

OUTPUT FLUSH

Command code = 11
ES:BX = FlushO

FlushODB(dup 13 0); Request header

Requests that the device driver write all unwritten buffers to the
disk.

DEVICE OPEN
DEVICE CLOSE

Command code = 13,14
ES:BX = DevOpen, DevClose

DevOpenDB13 dup (0); Request header

Used by the device driver to monitor how many different callers are
currently using the CD-ROM device driver. All new device drivers
should support these calls even if nothing is done with the
information.

MSCDEX - Microsoft MS-DOS CD-ROM Extensions Version 2.20

Device Driver Specification - Copyright (C) Microsoft Corp. 1989,
1990. All rights reserved - page page1

Microsoft MS-DOS CD-ROM Extensions
Hardware-Dependent Device Driver Specification
15 August, 1990

Device Driver Specification - Copyright (C) Microsoft Corp. 1989,
1990. All rights reserved - page page1