
#ifndef _CDPLAY_H
#define _CDPLAY_H

/*
**  cdplay.h
**
**  © 1995, 96 by Patrick Hess, all rights reserved.
**  $VER: cdplay.h 1.0 (20.09.1996)
**
*/

#ifndef EXEC_TYPES_H
#include <exec/types.h>
#endif

#define CDPLAYNAME		"cdplay.library"
#define CDPLAYVERSION		37L

/* macros */

#define base2min(val)	((val)/75/60)
#define base2sec(val)	(((val)/75)%60)

#define btst(n,m)	(n & m)
#define bchg(n,m)	(n = (n & m) ? (n & (~m)) : ( n | m))
#define bset(n,m)	(n = n | m)

/* special cd request */

struct CDRequest
{
	struct	IOStdReq	*cdr_Request;
	struct	MsgPort		*cdr_MsgPort;
	struct	CDCapacity	*cdr_Capacity;
	struct	CDInquiry	*cdr_Inquiry;
	struct	CDPTOC		*cdr_TOC;
	struct	CDTime		*cdr_Time;
	struct	CDVolume	*cdr_Volume;

	UBYTE	cdr_ID[20];
	UBYTE	cdr_Active;
	UBYTE	cdr_CurrentTrack;
	ULONG 	cdr_CurrentAddress;

	/* internal buffers, hands off! */

	UBYTE	*cdr_SCSISense;
	UBYTE	*cdr_SCSIData;
	UBYTE	*cdr_TOCBuf;
};

/* capacity of the cd */

struct CDCapacity
{
	ULONG	cdc_MaxSector;		/* max sector */
	ULONG	cdc_SectorSize;	/* size of a sector */
	ULONG	cdc_Capacity;		/* capacity of the cd */
};

/* devicetypes */

#define	DEVTYPE_DIRECT_ACCESS		0x00	/* Direct-access device (e.g., magnetic disk) */
#define DEVTYPE_SEQUENTIAL_ACCESS	0x01	/* Sequential-access device (e.g., magnetic tape) */
#define DEVTYPE_PRINTER			0x02	/* Printer device */
#define DEVTYPE_PROCESSOR		0x03	/* Processor device */
#define DEVTYPE_WRITE_ONCE		0x04	/* Write-once device (e.g., some optical disks) */
#define DEVTYPE_CDROM			0x05	/* CD-ROM device */
#define DEVTYPE_SCANNER			0x06	/* Scanner device */
#define DEVTYPE_OPTICAL			0x07	/* Optical memory device (e.g., some optical disks) */
#define DEVTYPE_MEDIUM_CHANGER		0x08	/* Medium Changer device (e.g., jukeboxes) */
#define DEVTYPE_COMMUNICATIONS		0x09	/* Communications device */
#define DEVTYPE_ASC_IT8_1		0x0A	/* Defined by ASC IT8 (Graphic Arts Pre-Press Devices) */
#define DEVTYPE_ASC_IT8_2		0x0B	/* Defined by ASC IT8 (Graphic Arts Pre-Press Devices) */
#define DEVTYPE_UNKNOWN			  -1	/* Reserved, unknown or no device type */

/* ansiversion */

#define ANSI_NONE			0x00
#define ANSI_SCSI_1			0x01
#define ANSI_SCSI_2			0x02

/* response format */

#define RESP_SCSI_1			0x00
#define RESP_CCS			0x01
#define RESP_SCSI_2			0x02

/* inquiry flags */

#define IFLAG_REMOVABLE			(1 << 0)
#define IFLAG_AENC			(1 << 1)
#define IFLAG_REL_ADDRESS		(1 << 2)
#define IFLAG_16WIDE_DATA		(1 << 3)
#define IFLAG_32WIDE_DATA		(1 << 4)
#define IFLAG_SYNC			(1 << 5)
#define IFLAG_LINKED			(1 << 6)
#define IFLAG_CMDQUE			(1 << 7)
#define IFLAG_SOFTRESET			(1 << 8)
#define IFLAG_TRMIOP			(1 << 9)

/* inquiry */

struct CDInquiry
{
	ULONG	cdi_Flags;
	UBYTE	cdi_DeviceType;
	UBYTE	cdi_ANSIVersion;
	UBYTE	cdi_ResponseFormat;
	UBYTE	cdi_ISOVersion;
	UBYTE	cdi_ECMAVersion;
	UBYTE	cdi_VendorID[9];
	UBYTE	cdi_ProductID[17];
	UBYTE	cdi_RevisionLevel[5];
	UBYTE	cdi_VendorSpecific[21];
	UBYTE	cdi_Reserved[36];
};

/* toc: sub-channel Q */

#define TOC_SUBCHAN_NOT_AVAIL				0x00	/* Sub-channel Q mode information not supplied. */
#define TOC_SUBCHAN_CURRENT_POS				0x01	/* Sub-channel Q encodes current position data. */
#define TOC_SUBCHAN_MEDIA_CATALOG_NUM			0x02	/* Sub-channel Q encodes media catalog number. */
#define TOC_SUBCHAN_ISRC				0x03	/* Sub-channel Q encodes ISRC. */
#define TOC_SUBCHAN_RESERVED				  -1	/* Reserved */

/* toc: track flags */

#define IFLAG_PRE_EMPHASIS				(1 << 0)
#define IFLAG_COPY_PROHIBITED				(1 << 1)
#define IFLAG_AUDIO_TRACK				(1 << 2)
#define IFLAG_2_CHAN					(1 << 3)

/* toc: simple track */

struct CDTrack
{
	ULONG	tr_Position;
	ULONG	tr_Flags;
	UBYTE	tr_SubChan;
};

/* table of contents */

struct CDPTOC
{
	ULONG	cdptoc_TOCSize;
	UBYTE	cdptoc_FirstTrack;
	UBYTE	cdptoc_LastTrack;

	struct	CDTrack cdptoc_Track[100];
};

/* time of the current track, values must be converted with base2min() and  */
/* base2sec() macros */

struct CDTime
{
	ULONG	cdt_TrackCurBase;	/* address: current position (Track) */
	ULONG	cdt_TrackRemainBase;	/* address: remaining time (Track) */
	ULONG	cdt_TrackCompleteBase;	/* address: complete time (Track) */
	ULONG	cdt_AllCurBase;		/* address: current position (CD) */
	ULONG	cdt_AllRemainBase;	/* address: remaining time (CD) */
	ULONG	cdt_AllCompleteBase;	/* address: complete time (CD) */
};

/* volume */

struct CDVolume
{
	UBYTE cdv_Output[4];
	UBYTE cdv_Volume[4];
};

/* results of CDActive() */

#define SCSI_STAT_NO_DISK               0       /* no cd in the drive */
#define SCSI_STAT_PLAYING               1       /* audio playing */
#define SCSI_STAT_STOPPED               2       /* drive motor stopped */
#define SCSI_STAT_PAUSED                3       /* audio paused */

#endif	/* _CDPLAY_H */

