/* Copyright 2012 Fredrik Wikstrom. All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1. Redistributions of source code must retain the above copyright
**    notice, this list of conditions and the following disclaimer.
**
** 2. Redistributions in binary form must reproduce the above copyright
**    notice, this list of conditions and the following disclaimer in the
**    documentation and/or other materials provided with the distribution.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
** POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef CDDAPATCH_H
#define CDDAPATCH_H

#include <exec/exec.h>
#include <dos/dos.h>
#include <devices/trackdisk.h>
#include <devices/scsidisk.h>
#include <libraries/commodities.h>
#include <libraries/cdplayer.h>

#define PROGNAME "CDDAPatch"

/* command codes */
#define SCSICMD_READ_SUBCHANNEL 0x42
#define SCSICMD_PLAY_AUDIO      0x45
#define SCSICMD_PLAY_AUDIO_MSF  0x47
#define SCSICMD_PAUSE_RESUME    0x4b
#define SCSICMD_STOP_PLAY_SCAN  0x4e
#define SCSICMD_PLAY_AUDIO_12   0xa5
#define SCSICMD_START_STOP_UNIT 0x1b
#define SCSICMD_MODE_SENSE      0x1a
#define SCSICMD_MODE_SELECT     0x15

/* status codes */
#define SCSI_Good							0x00
#define SCSI_CheckCondition					0x02
#define SCSI_ConditionMet					0x04
#define SCSI_Busy							0x08
#define SCSI_Intermediate					0x10
#define SCSI_Intermediate_ConditionMet		0x14
#define SCSI_ReservationConflict			0x18
#define SCSI_CommandTerminated				0x22
#define SCSI_TaskSetFull					0x28
#define SCSI_ACAActive						0x30

/* sense key codes */
#define SENSEKEY_NoSense					0x0
#define SENSEKEY_RecoveredError				0x1
#define SENSEKEY_NotReady					0x2
#define SENSEKEY_MediumError				0x3
#define SENSEKEY_HardwareError				0x4
#define SENSEKEY_IllegalRequest				0x5
#define SENSEKEY_UnitAttention				0x6
#define SENSEKEY_DataProtect				0x7
#define SENSEKEY_BlankCheck					0x8
#define SENSEKEY_VendorSpecific				0x9
#define SENSEKEY_CopyAborted				0xA
#define SENSEKEY_AbortedCommand				0xB
#define SENSEKEY_VolumeOverflow				0xD
#define SENSEKEY_Miscompare					0xE

#define ADDR2MSF(x,m,s,f) do { \
	m = ((x) / 75UL) / 60UL; \
	s = ((x) / 75UL) % 60UL; \
	f = (x) % 75UL; \
	} while (0)
#define MSF2ADDR(m,s,f) (((uint32)(m) * (75UL*60UL)) \
	+ ((uint32)(s) * 75UL) + (uint32)(f))

/* main.c */
extern struct DiskObject *Icon;
int main (int argc, STRPTR *argv);

/* cxbroker.c */
extern struct MsgPort *BrokerPort;
extern CxObj *Broker;
BOOL RegisterCxBroker (void);
void UnregisterCxBroker (void);

/* trimstr.c */
STRPTR TrimStr (STRPTR str);

/* amiupdate.c */
void SetAmiUpdateENVVariable (const char *varname);

/* tooltypes.c */
BOOL TTBoolean (struct DiskObject *icon, CONST_STRPTR name);
int32 TTInteger (struct DiskObject *icon, CONST_STRPTR name, int32 def_value);
STRPTR TTString (struct DiskObject *icon, CONST_STRPTR name, STRPTR def_value);

/* checklib.c */
BOOL CheckLib (struct Library *lib, uint32 ver, uint32 rev);

/* asprintfpooled.c */
VARARGS68K STRPTR ASPrintfPooled (APTR pool, CONST_STRPTR fmt, ...);
STRPTR VASPrintfPooled (APTR pool, CONST_STRPTR fmt, CONST_APTR args);

#endif
