COMMENT @----------------------------------------------------------------------

	Copyright (c) GeoWorks 1991 -- All Rights Reserved

PROJECT:	PC GEOS
MODULE:		CD-ROM Interface
FILE:		cdrom.def

REVISION HISTORY
	Name	Date		Description
	----	----		-----------
	Fred	3/91		Initial version

DESCRIPTION
	This file contains the equates and the data structures for calls
	to the CD-ROM driver. From the MSCDEX CD-ROM Extensions Version
	2.10 document.

	$Id: cdrom.def,v 1.1 97/04/04 14:23:55 newdeal Exp $
-------------------------------------------------------------------------------@

StartLibrary cdrom

;------------------------------------------------------------------------------
;		Definitions
;------------------------------------------------------------------------------
; Access to the CD-ROM functions in MSCDEX is done through interrupt 2fh.
; AH contains 15h which is the entry into the MSCDEX routines. AL
; contains code of the function.
 
;
CDRomFunction	etype	word, 1500h
    CD_GET_DRIVE_NUMBER	enum	CDRomFunction	; Get # of CD-ROM drive letters
    CD_GET_DRIVE_LIST	enum	CDRomFunction	; Get CD-ROM drive list
    CD_GET_COPYRIGHT	enum	CDRomFunction	; Get copyright file name
    CD_GET_ABSTRACT	enum	CDRomFunction	; Get abstract file name
    CD_GET_BIBLIOGRAPHY	enum	CDRomFunction	; Get bibliograph doc file name
    CD_READ_VTOC	enum	CDRomFunction		; Read VTOC
    CD_DISK_READ	enum	CDRomFunction, 1508h	; Absolute disk read
    CD_DISK_WRITE	enum	CDRomFunction		; Absolute disk write
    CD_DRIVE_CHECK	enum	CDRomFunction, 150bh	; CD-ROM drive check
    CD_MSCDEX_VERSION	enum	CDRomFunction		; MSCDEX version
    CD_DRIVE_LETTERS	enum	CDRomFunction	; Get CD-ROM drive letters
    CD_VOLUME_DESCRIPTORS enum  CDRomFunction	; Get/Set Volume descriptor
    CD_DIRECTORY_ENTRY	enum	CDRomFunction	; Get directory entry
    CD_SEND_REQUEST	enum	CDRomFunction	; Send device request



; Command codes for CD_SEND_REQUEST
CDSendRequestCode	etype	byte
    CDSR_INIT		enum	CDSendRequestCode, 0	; Initialize cd drive
    CDSR_IOCTL_INPUT	enum	CDSendRequestCode, 3		;
    CDSR_INPUT_FLUSH	enum	CDSendRequestCode, 7
    CDSR_OUTPUT_FLUSH	enum	CDSendRequestCode, 11
    CDSR_IOCTL_OUTPUT	enum	CDSendRequestCode, 12
    CDSR_DEVICE_OPEN	enum	CDSendRequestCode, 13
    CDSR_DEVICE_CLOSE	enum	CDSendRequestCode, 14
    CDSR_READ_LONG	enum	CDSendRequestCode, 128
    CDSR_READ_LONG_PRE	enum	CDSendRequestCode, 130
    CDSR_SEEK		enum	CDSendRequestCode, 131
    CDSR_PLAY_AUDIO	enum	CDSendRequestCode, 132
    CDSR_STOP_AUDIO	enum	CDSendRequestCode, 133
    CDSR_WRITE_LONG	enum	CDSendRequestCode, 134
    CDSR_WRITE_LONG_VERIFY enum	CDSendRequestCode, 135
    CDSR_RESUME_AUDIO	enum	CDSendRequestCode, 136

; Addressing modes
CDAddressType	etype	byte, 0
    HSG_MODE		enum	CDAddressType
    RED_BOOK_MODE	enum	CDAddressType

; Disk Types
CDDiskType	etype	byte, 0
    DISK_NOT_AUDIO	enum	CDDiskType
    DISK_AUDIO		enum	CDDiskType 

; Error codes produced by Int 2f calls. These are the DOS error codes
Int2fError	etype	byte, 0
    WRITE_PROTECT	enum	Int2fError
    UNKNOWN_UNIT	enum	Int2fError
    DRIVE_NOT_READY	enum	Int2fError
    UNKNOWN_COMMAND	enum	Int2fError
    CRC_ERROR		enum	Int2fError
    ERR_		enum	Int2fError
    SEEK_ERROR		enum	Int2fError
    UNKNOWN_MEDIA	enum	Int2fError
    SECTOR_NOT_FOUND	enum	Int2fError
    PRINTER_OUT		enum	Int2fError
    WRITE_FAULT		enum	Int2fError
    READ_FAULT		enum	Int2fError
    GENERAL_FAILURE	enum	Int2fError
    BAD_DISK_CHANGE	enum	Int2fError, 0fh

CDRomAudioStatus	etype	byte, 0
	CAS_INVALID	enum	CDRomAudioStatus
	CAS_STOPPED	enum	CDRomAudioStatus
	CAS_PAUSED	enum	CDRomAudioStatus
	CAS_PLAYING	enum	CDRomAudioStatus

;------------------------------------------------------------------------------
;			Structures
;------------------------------------------------------------------------------
;	Request header format

CDRequestHeader	struct
    CD_addressHeader	byte		; Length in bytes of address header
    CD_subunit		byte		; Subunit code for minor devices
    CD_code		byte		; Command code field
    CD_status		word		; Status
    CD_Reserved		byte	8 dup (?) ; Reserved
CDRequestHeader	ends


CDStatus	record			; Definition of status word
    CDS_ERROR:1				;Bit 15		- Error bit
    :5					;Bit 14-10	- Reserved
    CDS_BUSY:1				;Bit 9		- Busy
    CDS_DONE:1				;Bit 8		- Done
    CDS_ERROR_CODE	Int2fError:8	;Bit 7-0	- Error code (bit 15 on)
CDStatus	end

;------------------------------------------------------------------------------

InitStruct	struct
	I_Header	CDRequestHeader	; CDRequest Header
	InitUnits	byte		; Number of units (=0)
	EndAddress	fptr		; End address
    	BPBPointer	fptr		; Ptr to BPB array
	BlockNumber	byte		; Block device number
InitStruct	ends

FlushI	struct
	IF_Header	CDRequestHeader
FlushI	ends

FlushO	struct
	OF_Header	CDRequestHeader
FlushO	ends

DevOpen	struct
	DO_Header	CDRequestHeader
DevOpen	ends

DevClose	struct
	DC_Header	CDRequestHeader
DevClose	ends

;------------------------------------------------------------------------------
; IOCTLI transfer address points to a control block that is used
; to communicate with the device driver. The following structs are
; the control blocks for IOCTLI
IOCTLI	struct
	IOI_Header	CDRequestHeader	; Request Header
	IOI_MediaType	byte		; Media descriptor byte from BPB
	IOI_transfer	fptr		; Transfer address
	IOI_numBytes	word		; Number of bytes to transfer
	IOI_startSector	word		; Starting sector number
	IOI_errorPtr	fptr		; DWORD ptr to requested vol
					; ID if error 0Fh
IOCTLI	ends

; Equates for IOCTLI call
CDInputEquate	etype	word, 0
CDI_RETURN_ADDRESS_DEVICE_HEADER enum	CDInputEquate
CDI_HEAD_LOCATION		enum	CDInputEquate
CDI_AUDIO_CHANNEL_INFO		enum	CDInputEquate,	4
CDI_READ_DRIVE_BYTES		enum	CDInputEquate
CDI_DEVICE_STATUS		enum	CDInputEquate
CDI_RETURN_SECTOR_SIZE		enum	CDInputEquate
CDI_RETURN_VOLUME_SIZE		enum	CDInputEquate
CDI_MEDIA_CHANGED		enum	CDInputEquate
CDI_AUDIO_DISK_INFO		enum	CDInputEquate
CDI_AUDIO_TRACK_INFO		enum	CDInputEquate
CDI_AUDIO_QCHANNEL_INFO		enum	CDInputEquate
CDI_AUDIO_SUBCHANNEL_INFO	enum	CDInputEquate
CDI_UPC_CODE			enum	CDInputEquate
CDI_AUDIO_STATUS_INFO		enum	CDInputEquate

; Lengths for IOCTLI call
LENGTH_RETURN_ADDRESS		equ	5
LENGTH_HEAD_LOCATION		equ	6
LENGTH_AUDIO_INFO		equ	9
LENGTH_READ_DRIVE		equ	130
LENGTH_DEVICE_STATUS		equ	5
LENGTH_SECTOR_SIZE		equ	4
LENGTH_VOLUME_SIZE		equ	5
LENGTH_MEDIA_CHANGED		equ	2
LENGTH_AUDIO_DISK		equ	7
LENGTH_AUDIO_TRACK		equ	7
LENGTH_Q_CHANNEL		equ	11
LENGTH_SUB_CHANNEL		equ	13
LENGTH_UPC_CODE			equ	11
LENGTH_AUDIO_STATUS		equ	11

; Return address of Device Header
; Number of bytes to transfer 

Raddr	struct
	ReturnCode	byte	?
	HeaderAddress	dword	?	; returned address of device header
Raddr	ends

; Location of head
LocHead	struct
	LocCode	byte	?
	AddrMode	byte	?	; Addressing mode
	HeadPosition	dword	?	; returned location of drive head
LocHead	ends


InputChannel	etype	byte, 0
	CHANNEL0	enum	InputChannel
	CHANNEL1	enum	InputChannel
	CHANNEL2	enum	InputChannel
	CHANNEL3	enum	InputChannel


; Audio Channel Info
AudInfo	struct
	AudInfoCode	byte	?
	InputChan0	InputChannel	; Input channel for out ch 0
	Volume0		byte	?	; Volume (0-0xff) for out channel 0
	InputChan1	InputChannel	; Input channel for out ch 1 
	Volume1		byte 	?	; Volume (0-0xff) for out channel 1
	InputChan2	InputChannel	; Input channel for out ch 2 
	Volume2		byte 	?	; Volume (0-0xff) for out channel 2
	InputChan3	InputChannel	; Input channel for out ch 3 
	Volume3		byte 	?	; Volume (0-0xff) for out channel 3
AudInfo	ends

; Read Drive Bytes
RDrvBytes	struct
	RDrvCode	byte	?
			byte	?		; number of bytes read
	Buffer		byte	128 dup (?)	; Read buffer
RDrvBytes	ends

; Device Status
DevStat struct
	DevCode		byte	?
	Parameters	dword	?	; Device parameters
DevStat	ends

; This call returns a 32 bit value


; Status masks

DevTypeStatus	record
	DTS_DISK_ABSENT:1	; Bit 11: 0 Disk is present in drive
				;	  1 No disk present in drive
	:1			; Bit 10: Reserved
	DTS_HSG_REDBOOK:1	; Bit 9: 0 Supports HSG addressing mode
				;	 1 Supports HSG & Red Book mode
				;        HSG = High Sierra Mode
				;	 Red Book mode = CD-DA(digital audio)
	DTS_MANIPULATION:1	; Bit 8: 0 No audio channel manipulation
				;	 1 Supports audio channel manipulation
	DTS_PREFETCH:1		; Bit 7: 0 No prefetching
				;	 1 Supports prefetching request
	:1			; Bit 6:   Reserved
	DTS_INTERLEAVE:1	; Bit 5: 0 No interleaving
				; 	 1 Interleave by ISO9660 rules
	DTS_DATA_AUDIO:1		; Bit 4: 0 Data read only
				; 	 1 Data read and audio/video
	DTS_READ_WRITE:1		; Bit 3: 0 Read only
				;	 1 Read/Write
	DTS_RAW_COOKED:1		; Bit 2: 0 supports only cooked read
				;	 1 supports cooked & raw read
	DTS_DOOR_LOCKED:1	; Bit 1: 0 door locked
				;	 1 door unlocked
	DTS_DOOR_OPEN:1		; Bit 0: 0 drive door closed
				; 	 1 drive door open
DevTypeStatus	end

SectSize struct
	SectCode	byte	?
	SS_readMode	byte	?	; Read mode
	SS_sectorSize	word	?	; Sector size
SectSize ends

VolSize struct
	VolCode		byte	?
	VolumeSize	word	?	; Volume size
VolSize ends


MediaChanged	etype	byte
	MEDIA_CHANGED	enum	MediaChanged, -1
	DONT_KNOW	enum	MediaChanged, 0
	MEDIA_NOT_CHANGED	enum	MediaChanged, 1
		
MedChng struct
	MediaCode	byte	?
	CDMedia		MediaChanged
MedChng ends

; Audio disk info
DiskInfo struct
	DiskCode	byte	?
	LowTrackNum	byte	?	; Lowest track number
	HiTrackNum	byte	?	; Highest track number
	LeadOut		dword	?	; Starting point of lead out track
DiskInfo ends

TnoInfo	struct
	TnoCode		byte	?
	TrackNum	byte	?	; Track number
	StartPoint	dword	?	; Starting point of the track 
	TrackControl	byte	?	; Track control information

TnoInfo	ends

; 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
;	11x00000	- reserved
;	xx0x0000	- digital copy prohibited (sure)
;	xx1x0000	- digital copy permitted

; Audio Q-channel information.
Qinfo	struct
	QCode		byte	?
	Q_control	byte	?	; CONTROL and ADR byte
	Q_trackNum	byte	?	; Track number (TNO)
	Q_index		byte	?	; (POINT) or Index (X)
					; Running time within track
	Q_minutes	byte	?	; (MIN)
	Q_seconds	byte	?	; (SEC)
	Q_frame		byte	?	; (FRAME)
	Q_zero		byte	?	; (ZERO)
					; Running time on the disk
	Q_amin		byte	?	; (AMIN) or (PMIN)
	Q_asec		byte	?	; (ASEC) or (PSEC)
	Q_aframe	byte	?	; (AFRAME) or (PFRAME)
Qinfo	ends

; Audio Sub-Channel Info
SubChannelInfo	struct
	SubCode		byte	?
	SBFrame		dword 	?	; Starting Frame address (Red Book)
	SBTransfer	dword 	?	; Transfer address
	SBNumSecs	dword 	?	; Number of sectors to read
SubChannelInfo	ends

UPCCode	struct
	UPC_Code	byte	?
			byte	?	; CONTROL and ADR byte
	UpcString	byte	7 dup (?)	; UPC/EAN code
				; last 4 bits are 0; low order nibble byte 7
			byte	?	; Zero
			byte	?	; Aframe
UPCCode	ends

AudStat	struct
	AudCode		byte	?
	AudStatus	word	?	; Audio status bits
					; Bit 0 is Audio Paused bit
					; Bits 1-15 are reserved
	StartLast	dword	?	; Start location of last play
	EndLast		dword	?	; End location of last play
AudStat	ends

;------------------------------------------------------------------------------
IOCTLO	struct
	IOO_Header	CDRequestHeader	; Request Header
	IOO_mediaType	byte		; Media descriptor byte from BPB
	IOO_transfer	fptr		; Transfer address
	IOO_numberBytes	word		; Number of bytes to transfer
	IOO_startSector	word		; Starting sector number
	IOO_errorPtr	dword		; DWORD ptr to requested vol
					; ID if error 0Fh
IOCTLO	ends

; Control block code equates for IOCTLO

EJECT_DISK		equ	0
LOCK_DOOR		equ	1
RESET_DRIVE		equ	2
AUDIO_CONTROL		equ	3
WRITE_DEVICE_CONTROL	equ	4
CLOSE_TRAY		equ	5

; Lengths for IOCTLO call
LENGTH_EJECT_DISK	equ	1
LENGTH_LOCK_DOOR	equ	2
LENGTH_RESET_DRIVE	equ	1
LENGTH_AUDIO_CONTROL	equ	9
LENGTH_CLOSE_TRAY	equ	1

; IOCTLO transfer address points to a control block that is used
; to communicate with the device driver. The following structs are
; the control blocks for IOCTLO

EjectStruct   struct
	EjectCode	byte	?
			byte 	0
EjectStruct   ends

LockDoor struct
	LockCode	byte	?
	LockDr		byte	?	; 0 to unlock door, 1 lock door
LockDoor ends

ResetDrv struct
	ResetCode	byte	?
			byte 	0
ResetDrv ends

AudioOutInfo	struct
	AOI_Code	byte	?
	AOI_InputChan0	InputChannel	; Input channel for out ch 0
	AOI_Volume0	byte 	?	; Volume (0-0xff) for out channel 0
	AOI_InputChan1	InputChannel	; Input channel for out ch 1
	AOI_Volume1	byte 	?	; Volume (0-0xff) for out channel 1
	AOI_InputChan2	InputChannel	; Input channel for out ch 2
	AOI_Volume2	byte 	?	; Volume (0-0xff) for out channel 2
	AOI_InputChan3	InputChannel	; Input channel for out ch 3 
	AOI_Volume3	byte 	?	; Volume (0-0xff) for out channel 3
AudioOutInfo	ends

; Write device control string. This function allows any string to be
; written directly to the CD-ROM drive. 

;DrvBytesHeader struct
;			byte		; Control block code
;	CDStringBuffer	label byte  ?	; Write buffer
;DrvBytesHeader ends

;------------------------------------------------------------------------------
ReadLong	struct
	RL_Header	CDRequestHeader	; Request header
	RL_addressMode	byte		; Addressing mode
	RL_transferAddr	dword		; Transfer address
	RL_numSectors	word		; Number of sectors to read
	RL_startSector	dword		; Starting sector number
	RL_errorPtr	dword
ReadLong	ends

ReadLongPre	struct
	RLP_Header	CDRequestHeader	; Request header
	RLP_addressMode	byte		; Addressing mode
	RLP_transferAddr	dword	; Transfer address
	RLP_numSectors	word		; Number of sectors to read
	RLP_startSector	dword		; Starting sector number
	RLP_readMode	byte		; Read mode
	RLP_interleaveSize	byte	; Interleave size
	RLP_skipFactor	byte		; Interleave skip factor
ReadLongPre	ends

SeekReq	struct
	SR_Header	CDRequestHeader	; Request header
	SR_addressMode	byte		; Addressing mode
	SR_transferAddr	dword		; Transfer address
	SR_numSectors	word		; Number of sectors to read
	SR_startSector	DD		; Starting sector number
SeekReq	ends

PlayReq	struct
	PR_Header	CDRequestHeader	; Request header
	PR_addressMode	byte		; Addressing mode
	PR_startSector	dword		; Starting sector number
	PR_numSectors	dword		; Number of sectors to read
PlayReq	ends

StopReq struct
	ST_Header	CDRequestHeader	; Request header
StopReq	ends

ResumeReq	struct
	RES_Header	CDRequestHeader	; Request header
ResumeReq	ends

WriteL	struct
	WL_Header	CDRequestHeader	; Request header
	WL_addressMode	byte		; Addressing mode
	WL_transferAddr	dword		; Transfer address
	WL_numSectors	word		; Number of sectors to write
	WL_startSector	dword		; Starting sector number
	WL_readMode	byte		; Write mode
	WL_interleaveSize	byte	0	; Interleave size
	WL_skipFactor	byte		; Interleave skip factor
WriteL	ends

WriteLV	struct
	WLV_Header	CDRequestHeader	; Request header
	WLV_addressMode	byte		; Addressing mode
	WLV_transferAddr	dword	; Transfer address
	WLV_numSectors	word		; Number of sectors to write
	WLV_startSector	dword		; Starting sector number
	WLV_readMode	byte		; Write mode
	WLV_interleaveSize	byte	; Interleave size
	WLV_skipFactor	byte		; Interleave skip factor
WriteLV	ends

;------------------------------------------------------------------------------
;		Unions
;------------------------------------------------------------------------------


InputUnion union
	RdStruct		Raddr
	HeadStruct	LocHead
	AudStruct	AudInfo
	RDrvStruct	RDrvBytes
	DevStruct	DevStat
	SecStruct	SectSize
	TnoStruct	TnoInfo
	VolStruct	VolSize
	MedStruct	MedChng
	DiskStruct	DiskInfo
	QStruct		Qinfo
	SubStruct	SubChannelInfo
	UPCStruct	UPCCode
	StatStruct	AudStat
InputUnion end

OutputUnion union
	OU_EjectStruct	EjectStruct
	LockStruct	LockDoor
	ResetStruct	ResetDrv
	AudioStruct	AudioOutInfo 
OutputUnion end


CDUnion	union
	InitStruct	Init
	IOCTLIStruct	IOCTLI
	IOCTLOStruct	IOCTLO
	SeekStruct	SeekReq
	PlayStruct	PlayReq
	StopStruct	StopReq
	ResumeStruct	ResumeReq
	WriteLStruct	WriteL
	WriteLVStruct	WriteLV
CDUnion	end

;------------------------------------------------------------------------------
;		Structures
;------------------------------------------------------------------------------

; Structure for CD request header
CDStrucs struct
	CD_IO	CDUnion
CDStrucs ends

InputStrucs	struct
	inputName InputUnion
InputStrucs	ends

OutputStrucs	struct
	outName OutputUnion
OutputStrucs	ends


; Structure for Red Book data
RBStruct  struct
	Frame	byte
	Second	byte
	Minute	byte
	filler	byte
RBStruct  ends


; Structure for Play Audio command
PStruct  struct
	startSector	dword
	trackLen	dword
PStruct  ends


TableofContStruct struct
	Track		byte
	RBStartSec	RBStruct			; Red Book Address
	AbsTrackLen	dword			; absolute
;	StartHSG	dword
;	TrLenHSG	dword
TableofContStruct ends

COMMENT @---------------------------------------------------------------------@

;------------------------------------------------------------------------------
;		Int 2f Error Codes
;------------------------------------------------------------------------------


global	CDGetDriveNumbers:far
global	CDGetDriveList:far
global	CDGetCopyright:far
global	CDGetAbstract:far
global	CDGetBibliography:far
global	CDGetVTOC:far
global	CDGetDiskRead:far
global	CDGetDiskWrite:far
global	CDGetDriveCheck:far
global	CDGetExtenVersion:far
global	CDGetDriveLetters:far
global	CDGetVolDescriptor:far
global	CDGetDirectoryEntry:far
global	CDInit:far
global	CDInputFlush:far
global  CDOutputFlush:far
global  CDDeviceOpen:far
global  CDDeviceClose:far
global	CDReadAddressDeviceHeader:far
global	CDHeadLocation:far
global	CDAudioChannelInfo:far
global	CDReadDriveBytes:far
global	CDDeviceStatus:far
global	CDSectorSize:far
global	CDVolumeSize:far
global	CDMediaChanged:far
global	CDAudioDiskInfo:far
global	CDAudioTrackInfo:far
global	CDQChannelInfo:far
global	CDSubChannelInfo:far
global	CDUpcCode:far
global	CDAudioStatus:far
global	CDIOCTLInput:far
global	CDIOCTLOutput:far
global	CDEjectDisk:far
global	CDLockDoor:far
global	CDResetDrive:far
global	CDAudioChannelControl:far
global	CDCloseTray:far
global	CDSeek:far
global	CDPlayAudio:far
global	CDStopAudio:far
global	CDResumeAudio:far
global	CDReadLong:far
global	CDReadLongPrefetch:far
global	CDWriteLong:far
global	CDWriteLongVerify:far
global  CDRomEntry:far

global	CDPlayTrack:far
global	ConvertRedBookToAbsolute:far
global	Int2f:far

;--------------------------------------------------------
;	CDRom Class Definitions
;--------------------------------------------------------

CDRomAudioClass		class	MetaClass
	MSG_CDROM_AUDIO_INIT			message
	; Pass:		nothing
	; Return:	ax = CDStatus
	; Destroyed:	nothing

	MSG_CDROM_AUDIO_STOP_AUDIO		message
	; Pass:		nothing
	; Return:	ax = CDStatus
	; Destroyed:	nothing
	;

	MSG_CDROM_AUDIO_PLAY_TRACK		message
	; Pass:		dl = start track
	; 		dh = end track
	; Return: 	ax = CDStatus
	
	CAI_status 		CDRomAudioStatus	CAS_INVALID
	CAI_driveNumber		word			0
	CAI_numDrives		word			0
	CAI_firstTrack		byte			0
	CAI_lastTrack		byte			0
	CAI_leadOut		dword			0

CDRomAudioClass		endc

EndLibrary cdrom
