home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga MA Magazine 1998 #6
/
amigamamagazinepolishissue1998.iso
/
datatypes
/
fp_adpcm
/
cdripper
/
source
/
cdripper.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-10-09
|
23KB
|
889 lines
/* RIP TRACKS FROM A CD AND SAVE AS 2 OR 3 BIT ADPCM SAMPLE */
/* Written in 1995 by Christian Buchner. This is Public Domain. */
/* Note: TAB SIZE = 4 */
/* History:
added version string (still V1.0)
V1.1: added NumTracks, maximizing and boost factor
*/
/* Includes */
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <clib/alib_stdio_protos.h>
#include <libraries/dos.h>
#include <intuition/intuition.h>
#include <exec/io.h>
#include <exec/memory.h>
#include <devices/scsidisk.h>
#include <string.h>
#include <stdarg.h>
/* Version string */
UBYTE Version[]="$VER: CDRipper 1.1 "__AMIGADATE__" by Christian Buchner";
/* CDDA constants */
#define CDDA_BLOCKSIZE 2352 /* size of one CDDA block */
#define ONE_SECOND 75 /* blocks per second (75) */
/* Buffer size */
#define BUFBLOCKS 64
/*******************************************************************************/
BOOL OpenSCSI(UBYTE *Device, ULONG Unit);
void CloseSCSI(void);
ULONG DoSCSI(struct IOStdReq *IORequest, APTR Command, ULONG CommandLength, APTR Buffer, ULONG Length, ULONG Flags, BOOL Asynchronous, UBYTE *ActivityName);
void RipTrack(ULONG Track, ULONG NumTracks, UBYTE *ToFile, ULONG Bits, BOOL Maximize, LONG Boost);
void __stdargs Message(UBYTE *Msg,...);
extern __asm ULONG CompressADPCM2( register __a0 UBYTE *Source,
register __d0 ULONG Length,
register __a1 UBYTE *Destination,
register __d1 ULONG JoinCode );
extern __asm ULONG CompressADPCM3( register __a0 UBYTE *Source,
register __d0 ULONG Length,
register __a1 UBYTE *Destination,
register __d1 ULONG JoinCode );
/*******************************************************************************/
/* Library bases */
struct DosLibrary *DOSBase;
struct IntuitionBase *IntuitionBase;
/* Synchronous SCSI IO */
LONG SyncSigBit= -1;
struct MsgPort SyncReplyPort;
struct IOStdReq SyncSCSI_IO;
struct SCSICmd SyncSCSICmd;
/* SCSI command and mode structures */
struct Read12
{
UBYTE cmd; /* READ(12) SCSI command 0xA8 */
UBYTE pad_a; /* Bits 7-5 Logical Unit Number | Bits 4-1 Reserved | Bit 0 EVPD */
ULONG lba; /* logical block address MSB, , ,LSB */
ULONG lbn; /* number of blocks to transfer MSB, , ,LSB */
UBYTE subcode; /* special sub code selector (only for SONY!)
* 0: normal 2352
* 1: 2368
* 2: 2448
* 3: 96 bytes */
UBYTE cntrl; /* Control */
};
struct ModeSense
{
UBYTE cmd;
UBYTE pad_a;
UBYTE page;
UBYTE reserved;
UBYTE alloclen;
UBYTE cntrl;
};
struct ModeSelect
{
UBYTE cmd;
UBYTE pageformat;
UBYTE reserved_a;
UBYTE reserved_b;
UBYTE plistlen;
UBYTE cntrl;
};
struct ModeData
{
/* 4 Byte Mode Parameter Header (Table 7-61) */
UBYTE mode_data_length;
UBYTE medium_type;
UBYTE device_specific_parameter;
UBYTE block_descriptor_length;
/* 8 Byte Mode Parameter Block Descriptor (Table 7-63) */
UBYTE density;
UBYTE num_blocks_H;
UBYTE num_blocks_M;
UBYTE num_blocks_L;
ULONG block_length;
};
struct Inquiry
{
UBYTE cmd;
UBYTE pad_a;
UBYTE page;
UBYTE reserved;
UBYTE alloclen;
UBYTE cntrl;
};
struct InquiryData
{
UBYTE pdevtype;
UBYTE rmb_devtypmod;
UBYTE versions;
UBYTE rdformat;
UBYTE addlength;
UBYTE reserved_a;
UBYTE reserved_b;
UBYTE lotsofbits;
UBYTE vendor[8];
UBYTE prod_id[16];
UBYTE revision[4];
UBYTE specific[20];
UBYTE reserved[40];
};
struct ReadTOC
{
UBYTE cmd;
UBYTE misc;
ULONG reserved;
UBYTE starttrack;
UBYTE alloclenHI;
UBYTE alloclenLO;
UBYTE control;
};
struct TrackDesc
{
UBYTE reserved;
UBYTE adrctrl;
UBYTE trackno;
UBYTE reserved2;
ULONG lba;
};
struct TOCData
{
UWORD length;
UBYTE lowtrack;
UBYTE hightrack;
struct TrackDesc desc[100];
};
struct SenseData
{
UBYTE errcode;
UBYTE segnum;
UBYTE sensekey;
UBYTE information[4];
UBYTE addlength;
UBYTE specificinfo[4];
UWORD additionalsense;
UBYTE unitcode;
UBYTE sensekeyspec[3];
UBYTE space[20];
};
/* SCSI command and data bytes (somewhat pre-initialized) */
struct SenseData SyncSenseData;
struct Read12 Read12= { 0xA8, 0x00, 0, 0, 0, 0 };
struct InquiryData InquiryData;
struct Inquiry Inquiry={0x12, 0x00, 0, 0, sizeof(InquiryData), 0};
struct ModeData OldModePage;
struct ModeData NewModePage={0,0,0,8, 0x82,0,0,0,CDDA_BLOCKSIZE};
struct ModeSense ModeSense ={0x1A, 0, 1, 0, sizeof(OldModePage), 0};
struct ModeSelect ModeSelect={0x15, 0x10, 0, 0, sizeof(NewModePage), 0};
struct TOCData TOCData;
struct ReadTOC ReadTOC={0x43, 0, 0, 0, sizeof(TOCData)>>8, sizeof(TOCData)&0xff, 0};
UBYTE *Template="TRACK/N/A,NUMTRACKS/K/N,TO/K/A,BITS/K/N,DEVICE/K,UNIT/K/N,MAXIMIZE/S,BOOST/K/N";
struct ArgArray
{
ULONG *aa_Track;
ULONG *aa_NumTracks;
UBYTE *aa_To;
ULONG *aa_Bits;
UBYTE *aa_Device;
ULONG *aa_Unit;
ULONG aa_Maximize;
ULONG *aa_Boost;
};
struct ArgArray AA;
struct RDArgs *RDArgs;
UBYTE ProgName[60];
UBYTE *ReadBuffer;
UBYTE *StreamBuffer;
UBYTE *ADPCMBuffer;
/*******************************************************************************/
/* void __saveds main() */
LONG __saveds main()
{
UBYTE *DeviceName="scsi.device";
ULONG DeviceUnit=3;
ULONG Bits=2;
ULONG NumTracks=1;
LONG Boost=100;
if (DOSBase=(struct DosLibrary*)OpenLibrary("dos.library",37))
{
if (!GetProgramName(ProgName,sizeof(ProgName))) strcpy(ProgName,"CDRipper");
if (!(RDArgs=ReadArgs(Template,(LONG *)&AA,0)))
{
PrintFault(IoErr(),ProgName);
}
else
{
if (AA.aa_NumTracks) NumTracks= *AA.aa_NumTracks;
if (AA.aa_Device) DeviceName=AA.aa_Device;
if (AA.aa_Unit) DeviceUnit= *AA.aa_Unit;
if (AA.aa_Bits) Bits= *AA.aa_Bits;
if (AA.aa_Boost) Boost= *AA.aa_Boost;
if (Bits != 2 && Bits != 3)
{
Printf("Illegal bit number. Use 2 for ADPCM2 and 3 for ADPCM3.\n");
}
else
{
if (OpenSCSI(DeviceName, DeviceUnit))
{
RipTrack(*AA.aa_Track, NumTracks, AA.aa_To, Bits, (BOOL)AA.aa_Maximize, Boost);
CloseSCSI();
}
}
FreeArgs(RDArgs);
}
CloseLibrary(DOSBase);
}
}
/* Rip CD audio data */
void RipTrack(ULONG Track, ULONG NumTracks, UBYTE *ToFile, ULONG Bits, BOOL Maximize, LONG Boost)
{
BPTR File;
ULONG LBA;
ULONG StartLBA;
ULONG EndLBA;
ULONG StreamLen;
ULONG ADPCMLen;
ULONG JoinCode=0;
BOOL Break=FALSE;
LONG MaxVal=32768;
LONG ScaleFact=Boost*1024/100;
/* Calculate stream sizes based on buffer size */
StreamLen=BUFBLOCKS*CDDA_BLOCKSIZE/8;
if (Bits==2) ADPCMLen=(StreamLen+3)/4;
if (Bits==3) ADPCMLen=(StreamLen+7)/8*3;
StartLBA=TOCData.desc[Track-1].lba;
EndLBA=TOCData.desc[Track-1+NumTracks].lba-1;
if (!(File=Open(ToFile,MODE_NEWFILE)))
{
Printf("Error cannot open '%s'.\n",ToFile);
}
else
{
ULONG Frequency=22050;
if (Bits==2) Write(File,"ADPCM2", 6);
if (Bits==3) Write(File,"ADPCM3", 6);
Write(File,&Frequency, sizeof(Frequency));
if (ReadBuffer=AllocVec(BUFBLOCKS*CDDA_BLOCKSIZE,MEMF_CLEAR))
{
if (StreamBuffer=AllocVec(StreamLen,MEMF_CLEAR))
{
if (ADPCMBuffer=AllocVec(ADPCMLen,MEMF_CLEAR))
{
if (Maximize)
{
MaxVal=0;
for (LBA=StartLBA; LBA<EndLBA; )
{
UBYTE *ptr;
ULONG Left=EndLBA-LBA;
ULONG NumBlocks = Left < BUFBLOCKS ? Left : BUFBLOCKS;
UWORD i;
Printf("\rMaximize run (%02ld%%)",100*(LBA-StartLBA)/(EndLBA-StartLBA));
/* Calculate stream sizes based on read blocks */
StreamLen=NumBlocks*CDDA_BLOCKSIZE/8;
/* Init LBA and LBN */
Read12.lba=LBA;
Read12.lbn=NumBlocks;
/* start synchronous reading */
DoSCSI( &SyncSCSI_IO,
&Read12, sizeof(Read12),
ReadBuffer, NumBlocks*CDDA_BLOCKSIZE,
SCSIF_READ, FALSE, "reading CD-DA block");
ptr=ReadBuffer;
for(i=0 ; i<StreamLen ; i++ , ptr+=8)
{
LONG sample=( (WORD)(*(ptr+1)<<8) | *(ptr+0)) +
( (WORD)(*(ptr+3)<<8) | *(ptr+2)) +
( (WORD)(*(ptr+5)<<8) | *(ptr+4)) +
( (WORD)(*(ptr+7)<<8) | *(ptr+6)) ;
sample=sample>>2;
if (sample<0) sample= -sample;
if (sample>MaxVal) MaxVal=sample;
}
LBA+=NumBlocks;
if (CheckSignal(SIGBREAKF_CTRL_C))
{
PrintFault(ERROR_BREAK,NULL);
Break=TRUE;
break;
}
}
}
if (!Break)
{
if (MaxVal!=32768)
{
Printf("\rMaximizing by %ld%%.\n",(ULONG)100*32768/MaxVal);
}
for (LBA=StartLBA; LBA<EndLBA; )
{
UBYTE *ptr;
BYTE *dest;
ULONG Left=EndLBA-LBA;
ULONG NumBlocks = Left < BUFBLOCKS ? Left : BUFBLOCKS;
UWORD i;
Printf("\rLoading/compressing (%02ld%%)",100*(LBA-StartLBA)/(EndLBA-StartLBA));
/* Calculate stream sizes based on read blocks */
StreamLen=NumBlocks*CDDA_BLOCKSIZE/8;
if (Bits==2) ADPCMLen=(StreamLen+3)/4;
if (Bits==3) ADPCMLen=(StreamLen+7)/8*3;
/* Init LBA and LBN */
Read12.lba=LBA;
Read12.lbn=NumBlocks;
/* start synchronous reading */
DoSCSI( &SyncSCSI_IO,
&Read12, sizeof(Read12),
ReadBuffer, NumBlocks*CDDA_BLOCKSIZE,
SCSIF_READ, FALSE, "reading CD-DA block");
ptr=ReadBuffer;
dest=StreamBuffer;
for(i=0 ; i<StreamLen ; i++ , ptr+=8)
{
LONG sample=( (WORD)(*(ptr+1)<<8) | *(ptr+0)) +
( (WORD)(*(ptr+3)<<8) | *(ptr+2)) +
( (WORD)(*(ptr+5)<<8) | *(ptr+4)) +
( (WORD)(*(ptr+7)<<8) | *(ptr+6)) ;
sample=sample>>2;
if (MaxVal!=32768)
{
sample=(sample<<15)/MaxVal;
}
if (ScaleFact!=1024)
{
sample=(sample*ScaleFact)>>10;
}
sample=sample>>8;
if (sample>127) sample= 127;
if (sample<-128) sample= -128;
*dest++=sample;
}
if (Bits==2) JoinCode=CompressADPCM2(StreamBuffer, StreamLen, ADPCMBuffer, JoinCode);
if (Bits==3) JoinCode=CompressADPCM3(StreamBuffer, StreamLen, ADPCMBuffer, JoinCode);
Write(File,ADPCMBuffer,ADPCMLen);
LBA+=NumBlocks;
if (CheckSignal(SIGBREAKF_CTRL_C))
{
PrintFault(ERROR_BREAK,NULL);
Break=TRUE;
break;
}
}
}
Printf("\rLoading/compressing finished\n");
}
FreeVec(StreamBuffer);
}
FreeVec(ReadBuffer);
}
Close(File);
}
}
/* Open and initialize CDRom */
BOOL OpenSCSI(UBYTE *Device, ULONG Unit)
{
BOOL Success=FALSE;
/* Init synchronous SCSI IO */
SyncReplyPort.mp_Node.ln_Type=NT_MSGPORT;
SyncReplyPort.mp_Flags=PA_SIGNAL;
SyncReplyPort.mp_SigTask=FindTask(NULL);
NewList(&SyncReplyPort.mp_MsgList);
if ((SyncSigBit=SyncReplyPort.mp_SigBit=AllocSignal(-1))!=-1)
{
SyncSCSI_IO.io_Message.mn_Node.ln_Type=NT_MESSAGE;
SyncSCSI_IO.io_Message.mn_Length=sizeof(struct IOStdReq);
SyncSCSI_IO.io_Message.mn_ReplyPort= &SyncReplyPort;
SyncSCSI_IO.io_Data= &SyncSCSICmd;
SyncSCSICmd.scsi_SenseData=(UBYTE*)&SyncSenseData;
SyncSCSICmd.scsi_SenseLength=sizeof(SyncSenseData);
if (OpenDevice(Device,Unit,(struct IORequest*)&SyncSCSI_IO,0))
{
Message("Cannot open '%s' unit %ld.",Device,Unit);
}
else
{
if (DoSCSI(&SyncSCSI_IO, &Inquiry, sizeof(Inquiry), &InquiryData, sizeof(InquiryData), SCSIF_READ, FALSE, "reading inquiry data"))
{
if (InquiryData.pdevtype != 5)
{
Message("'%s' unit %ld is not a CDRom!",Device,Unit);
}
else
{
/* Read Table of Contents */
if (!(DoSCSI(&SyncSCSI_IO, &ReadTOC, sizeof(ReadTOC), &TOCData, sizeof(TOCData), SCSIF_READ, FALSE, "reading table of contents")))
{
Message("Cannot read Table of Contents!");
}
else
{
/* Prepare CDRom for CDDA data transfer */
DoSCSI(&SyncSCSI_IO, &ModeSense, sizeof(ModeSense), &OldModePage, sizeof(OldModePage), SCSIF_READ, FALSE, "reading mode page");
DoSCSI(&SyncSCSI_IO, &ModeSelect, sizeof(ModeSelect), &NewModePage, sizeof(NewModePage), SCSIF_WRITE, FALSE, "selecting CD-DA data format");
Success=TRUE;
}
}
}
}
}
if (!Success) CloseSCSI();
return(Success);
}
/*******************************************************************************/
/* Reset and close CDRom */
void CloseSCSI(void)
{
if (SyncSCSI_IO.io_Device)
{
/* Reset CDRom transfer mode */
if (OldModePage.mode_data_length>0)
{
OldModePage.mode_data_length=0;
DoSCSI(&SyncSCSI_IO, &ModeSelect, sizeof(ModeSelect), &OldModePage, sizeof(OldModePage), SCSIF_WRITE, FALSE, "resetting data format");
}
CloseDevice((struct IORequest*)&SyncSCSI_IO);
SyncSCSI_IO.io_Device=NULL;
}
if (SyncSigBit!=-1)
{
FreeSignal(SyncSigBit);
SyncSigBit= -1;
}
}
/* Execute a SCSI command (synchronous or asynchronous) */
UBYTE* SenseKeys[]=
{
"NO SENSE",
"RECOVERED ERROR",
"NOT READY",
"MEDIUM ERROR",
"HARDWARE ERRROR",
"ILLEGAL REQUEST",
"UNIT ATTENTION",
"DATA PROTECT",
"BLANK CHECK",
"VENDOR-SPECIFIC",
"COPY ABORTED",
"ABORTED COMMAND",
"EQUAL",
"VOLUME OVERFLOW",
"MISCOMPARE",
"RESERVED"
};
struct ErrorDefinition
{
UWORD ErrorCode;
UBYTE *ErrorName;
};
struct ErrorDefinition ErrorTable[]=
{
0x1300,"ADDRESS MARK NOT FOUND FOR DATA FIELD",
0x1200,"ADDRESS MARK NOT FOUND FOR ID FIELD",
0x0011,"AUDIO PLAY OPERATION IN PROGRESS",
0x0012,"AUDIO PLAY OPERATION PAUSED",
0x0014,"AUDIO PLAY OPERATION STOPPED DUE TO ERROR",
0x0013,"AUDIO PLAY OPERATION SUCCESSFULLY COMPLETED",
0x0004,"BEGINNING-OF-PARTITION/MEDIUM DETECTED",
0x1404,"BLOCK SEQUENCE ERROR",
0x3002,"CANNOT READ MEDIUM - INCOMPATIBLE FORMAT",
0x3001,"CANNOT READ MEDIUM - UNKNOWN FORMAT",
0x5200,"CARTRIDGE FAULT",
0x3F02,"CHANGED OPERATING DEFINITION",
0x1106,"CIRC UNRECOVERED ERROR",
0x3003,"CLEANING CARTRIDGE INSTALLED",
0x4A00,"COMMAND PHASE ERROR",
0x2C00,"COMMAND SEQUENCE ERROR",
0x2F00,"COMMANDS CLEARED BY ANOTHER INITIATOR",
0x2B00,"COPY CANNOT EXECUTE SINCE HOST CANNOT DISCONNECT",
0x4100,"DATA PATH FAILURE",
0x4B00,"DATA PHASE ERROR",
0x1107,"DATA RESYCHRONIZATION ERROR",
0x1600,"DATA SYNCHRONIZATION MARK ERROR",
0x1900,"DEFECT LIST ERROR",
0x1903,"DEFECT LIST ERROR IN GROWN LIST",
0x1902,"DEFECT LIST ERROR IN PRIMARY LIST",
0x1901,"DEFECT LIST NOT AVAILABLE",
0x1C00,"DEFECT LIST NOT FOUND",
0x3201,"DEFECT LIST UPDATE FAILURE",
0x6300,"END OF USER AREA ENCOUNTERED ON THIS TRACK",
0x0005,"END-OF-DATA DETECTED",
0x1403,"END-OF-DATA NOT FOUND",
0x0002,"END-OF-PARTITION/MEDIUM DETECTED",
0x5100,"ERASE FAILURE",
0x0A00,"ERROR LOG OVERFLOW",
0x1102,"ERROR TOO LONG TO CORRECT",
0x0302,"EXCESSIVE WRITE ERRORS",
0x3B07,"FAILED TO SENSE BOTTOM-OF-FORM",
0x3B06,"FAILED TO SENSE TOP-OF-FORM",
0x0001,"FILEMARK DETECTED",
0x1402,"FILEMARK OR SETMARK NOT FOUND",
0x0902,"FOCUS SERVO FAILURE",
0x3101,"FORMAT COMMAND FAILED",
0x5800,"GENERATION DOES NOT EXIST",
0x1C02,"GROWN DEFECT LIST NOT FOUND",
0x0006,"I/O PROCESS TERMINATED",
0x1000,"ID CRC OR ECC ERROR",
0x2200,"ILLEGAL FUNCTION",
0x6400,"ILLEGAL MODE FOR THIS TRACK",
0x2801,"IMPORT OR EXPORT ELEMENT ACCESSED",
0x3000,"INCOMPATIBLE MEDIUM INSTALLED",
0x1108,"INCOMPLETE BLOCK READ",
0x4800,"INITIATOR DETECTED ERROR MESSAGE RECEIVED",
0x3F03,"INQUIRY DATA HAS CHANGED",
0x4400,"INTERNAL TARGET FAILURE",
0x3D00,"INVALID BITS IN IDENTIFY MESSAGE",
0x2C02,"INVALID COMBINATION OF WINDOWS SPECIFIED",
0x2000,"INVALID COMMAND OPERATION CODE",
0x2101,"INVALID ELEMENT ADDRESS",
0x2400,"INVALID FIELD IN CDB",
0x2600,"INVALID FIELD IN PARAMETER LIST",
0x4900,"INVALID MESSAGE ERROR",
0x1105,"L-EC UNCORRECTABLE ERROR",
0x6000,"LAMP FAILURE",
0x5B02,"LOG COUNTER AT MAXIMUM",
0x5B00,"LOG EXCEPTION",
0x5B03,"LOG LIST CODES EXHAUSTED",
0x2A02,"LOG PARAMETERS CHANGED",
0x2100,"LOGICAL BLOCK ADDRESS OUT OF RANGE",
0x0800,"LOGICAL UNIT COMMUNICATION FAILURE",
0x0802,"LOGICAL UNIT COMMUNICATION PARITY ERROR",
0x0801,"LOGICAL UNIT COMMUNICATION TIME-OUT",
0x0500,"LOGICAL UNIT DOES NOT RESPOND TO SELECTION",
0x4C00,"LOGICAL UNIT FAILED SELF-CONFIGURATION",
0x3E00,"LOGICAL UNIT HAS NOT SELF-CONFIGURED YET",
0x0401,"LOGICAL UNIT IS IN PROCESS OF BECOMING READY",
0x0400,"LOGICAL UNIT NOT READY, CAUSE NOT REPORTABLE",
0x0404,"LOGICAL UNIT NOT READY, FORMAT IN PROGRESS",
0x0402,"LOGICAL UNIT NOT READY, INITIALIZING COMMAND REQUIRED",
0x0403,"LOGICAL UNIT NOT READY, MANUAL INTERVENTION REQUIRED",
0x2500,"LOGICAL UNIT NOT SUPPORTED",
0x1501,"MECHANICAL POSITIONING ERROR",
0x5300,"MEDIA LOAD OR EJECT FAILED",
0x3B0D,"MEDIUM DESTINATION ELEMENT FULL",
0x3100,"MEDIUM FORMAT CORRUPTED",
0x3A00,"MEDIUM NOT PRESENT",
0x5302,"MEDIUM REMOVAL PREVENTED",
0x3B0E,"MEDIUM SOURCE ELEMENT EMPTY",
0x4300,"MESSAGE ERROR",
0x3F01,"MICROCODE HAS BEEN CHANGED",
0x1D00,"MISCOMPARE DURING VERIFY OPERATION",
0x110A,"MISCORRECTED ERROR",
0x2A01,"MODE PARAMETERS CHANGED",
0x0700,"MULTIPLE PERIPHERAL DEVICES SELECTED",
0x1103,"MULTIPLE READ ERRORS",
0x0000,"NO ADDITIONAL SENSE INFORMATION",
0x0015,"NO CURRENT AUDIO STATUS TO RETURN",
0x3200,"NO DEFECT SPARE LOCATION AVAILABLE",
0x1109,"NO GAP FOUND",
0x0100,"NO INDEX/SECTOR SIGNAL",
0x0600,"NO REFERENCE POSITION FOUND",
0x0200,"NO SEEK COMPLETE",
0x0301,"NO WRITE CURRENT",
0x2800,"NOT READY TO READY TRANSITION (MEDIUM MAY HAVE CHANGED)",
0x5A01,"OPERATOR MEDIUM REMOVAL REQUEST",
0x5A00,"OPERATOR REQUEST OR STATE CHANGE INPUT (UNSPECIFIED)",
0x5A03,"OPERATOR SELECTED WRITE PERMIT",
0x5A02,"OPERATOR SELECTED WRITE PROTECT",
0x6102,"OUT OF FOCUS",
0x4E00,"OVERLAPPED COMMANDS ATTEMPTED",
0x2D00,"OVERWRITE ERROR ON UPDATE IN PLACE",
0x3B05,"PAPER JAM",
0x1A00,"PARAMETER LIST LENGTH ERROR",
0x2601,"PARAMETER NOT SUPPORTED",
0x2602,"PARAMETER VALUE INVALID",
0x2A00,"PARAMETERS CHANGED",
0x0300,"PERIPHERAL DEVICE WRITE FAULT",
0x5002,"POSITION ERROR RELATED TO TIMING",
0x3B0C,"POSITION PAST BEGINNING OF MEDIUM",
0x3B0B,"POSITION PAST END OF MEDIUM",
0x1502,"POSITIONING ERROR DETECTED BY READ OF MEDIUM",
0x2900,"POWER ON, RESET, OR BUS DEVICE RESET OCCURRED",
0x4200,"POWER-ON OR SELF-TEST FAILURE",
0x1C01,"PRIMARY DEFECT LIST NOT FOUND",
0x4000,"RAM FAILURE",
0x1500,"RANDOM POSITIONING ERROR",
0x3B0A,"READ PAST BEGINNING OF MEDIUM",
0x3B09,"READ PAST END OF MEDIUM",
0x1101,"READ RETRIES EXHAUSTED",
0x1401,"RECORD NOT FOUND",
0x1400,"RECORDED ENTITY NOT FOUND",
0x1802,"RECOVERED DATA - DATA AUTO-REALLOCATED",
0x1805,"RECOVERED DATA - RECOMMEND REASSIGNMENT",
0x1705,"RECOVERED DATA USING PREVIOUS SECTOR ID",
0x1803,"RECOVERED DATA WITH CIRC",
0x1801,"RECOVERED DATA WITH ERROR CORRECTION AND RETRIES APPLIED",
0x1800,"RECOVERED DATA WITH ERROR CORRECTION APPLIED",
0x1804,"RECOVERED DATA WITH LEC",
0x1703,"RECOVERED DATA WITH NEGATIVE HEAD OFFSET",
0x1700,"RECOVERED DATA WITH NO ERROR CORRECTION APPLIED",
0x1702,"RECOVERED DATA WITH POSITIVE HEAD OFFSET",
0x1701,"RECOVERED DATA WITH RETRIES",
0x1704,"RECOVERED DATA WITH RETRIES AND/OR CIRC APPLIED",
0x1706,"RECOVERED DATA WITHOUT ECC - DATA AUTO-REALLOCATED",
0x1707,"RECOVERED DATA WITHOUT ECC - RECOMMEND REASSIGNMENT",
0x1E00,"RECOVERED ID WITH ECC CORRECTION",
0x3B08,"REPOSITION ERROR",
0x3600,"RIBBON, INK, OR TONER FAILURE",
0x3700,"ROUNDED PARAMETER",
0x5C00,"RPL STATUS CHANGE",
0x3900,"SAVING PARAMETERS NOT SUPPORTED",
0x6200,"SCAN HEAD POSITIONING ERROR",
0x4700,"SCSI PARITY ERROR",
0x5400,"SCSI TO HOST SYSTEM INTERFACE FAILURE",
0x4500,"SELECT OR RESELECT FAILURE",
0x3B00,"SEQUENTIAL POSITIONING ERROR",
0x0003,"SETMARK DETECTED",
0x3B04,"SLEW FAILURE",
0x0903,"SPINDLE SERVO FAILURE",
0x5C02,"SPINDLES NOT SYNCHRONIZED",
0x5C01,"SPINDLES SYNCHRONIZED",
0x1B00,"SYNCHRONOUS DATA TRANSFER ERROR",
0x5500,"SYSTEM RESOURCE FAILURE",
0x3300,"TAPE LENGTH ERROR",
0x3B03,"TAPE OR ELECTRONIC VERTICAL FORMS UNIT NOT READY",
0x3B01,"TAPE POSITION ERROR AT BEGINNING-OF-MEDIUM",
0x3B02,"TAPE POSITION ERROR AT END-OF-MEDIUM",
0x3F00,"TARGET OPERATING CONDITIONS HAVE CHANGED",
0x5B01,"THRESHOLD CONDITION MET",
0x2603,"THRESHOLD PARAMETERS NOT SUPPORTED",
0x2C01,"TOO MANY WINDOWS SPECIFIED",
0x0900,"TRACK FOLLOWING ERROR",
0x0901,"TRACKING SERVO FAILURE",
0x6101,"UNABLE TO ACQUIRE VIDEO",
0x5700,"UNABLE TO RECOVER TABLE-OF-CONTENTS",
0x5301,"UNLOAD TAPE FAILURE",
0x1100,"UNRECOVERED READ ERROR",
0x1104,"UNRECOVERED READ ERROR - AUTO REALLOCATE FAILED",
0x110B,"UNRECOVERED READ ERROR - RECOMMEND REASSIGNMENT",
0x110C,"UNRECOVERED READ ERROR - RECOMMEND REWRITE THE DATA",
0x4600,"UNSUCCESSFUL SOFT RESET",
0x5900,"UPDATED BLOCK READ",
0x6100,"VIDEO ACQUISITION ERROR",
0x5000,"WRITE APPEND ERROR",
0x5001,"WRITE APPEND POSITION ERROR",
0x0C00,"WRITE ERROR",
0x0C02,"WRITE ERROR - AUTO REALLOCATION FAILED",
0x0C01,"WRITE ERROR RECOVERED WITH AUTO REALLOCATION",
0x2700,"WRITE PROTECTED",
0xFFFF,"UNKNOWN ERROR CODE"
};
ULONG DoSCSI(struct IOStdReq *IORequest, APTR Command, ULONG CommandLength, APTR Buffer, ULONG Length, ULONG Flags, BOOL Asynchronous, UBYTE *ActivityName)
{
struct SCSICmd *Cmd=(struct SCSICmd*)IORequest->io_Data;
/* loop forever */
for (;;)
{
Cmd->scsi_Command=Command;
Cmd->scsi_CmdLength=CommandLength;
Cmd->scsi_Data=Buffer;
Cmd->scsi_Length=Length;
Cmd->scsi_Flags=Flags;
Cmd->scsi_Actual=
Cmd->scsi_CmdActual=
Cmd->scsi_SenseActual=0;
if (Cmd->scsi_SenseData)
{
Cmd->scsi_Flags |= SCSIF_AUTOSENSE;
}
IORequest->io_Flags=0;
IORequest->io_Length=sizeof(struct SCSICmd);
IORequest->io_Command=HD_SCSICMD;
if (Asynchronous)
{
BeginIO(IORequest);
break;
}
else
{
DoIO(IORequest);
if (Cmd->scsi_SenseActual)
{
struct EasyStruct Req={ sizeof (struct EasyStruct),
0,
"SCSI error",
"SCSI unit reports error while %s\n%s: %s",
"Retry|Cancel"};
struct SenseData *SD;
if (SD=(struct SenseData*)Cmd->scsi_SenseData)
{
BOOL OpenIntui=FALSE;
UBYTE *KeyName=SenseKeys[SD->sensekey&0xf];
UBYTE *AddName="NO ADDITIONAL ERROR CODE";
if (SD->addlength>=6)
{
struct ErrorDefinition *ED;
for(ED=ErrorTable;ED->ErrorCode!=0xffff;ED++)
{
if (ED->ErrorCode==SD->additionalsense) break;
}
AddName=ED->ErrorName;
}
if (!IntuitionBase)
{
IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library",37);
OpenIntui=TRUE;
}
if (IntuitionBase)
{
if (!EasyRequest(NULL, &Req, NULL, ActivityName, KeyName, AddName))
{
break;
}
}
if (IntuitionBase && OpenIntui)
{
CloseLibrary((struct Library*)IntuitionBase);
IntuitionBase=NULL;
}
}
}
else break;
}
}
return(Cmd->scsi_Actual);
}
/*******************************************************************************/
/* Show a message to the user */
void __stdargs Message(UBYTE *Msg,...)
{
va_list Arg;
struct EasyStruct Req={sizeof(struct EasyStruct),0,"CDRipper message",0,"Okay"};
Req.es_TextFormat=Msg;
va_start(Arg,Msg);
if (IntuitionBase)
{
EasyRequestArgs(NULL,&Req,0,Arg);
}
else
{
VPrintf(Msg,Arg);
Printf("\n");
}
va_end(Arg);
}