『第
15 楼』:
好久没有来了, 想不到还有不少人关注
分享一下源码....
/***************************************************************************
name: atapiEject
action: loads or ejects CD-ROM
returns:whatever atapiCmd() returns
****************************************************************************/
static int atapiEject(driveinfo *Drive, bool Load)
{
u8 Pkt[12]={ATAPI_CMD_START_STOP, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
drivecmd Cmd;
printf("atapiEject:");
memset(&Cmd, 0, sizeof(Cmd));
Pkt[4]= (Load ? 3 : 2);
return(atapiCmd(Drive, &Cmd, Pkt));
}
/***************************************************************************
name: atapiGetEventStatus
action: Get Disc is present && Tray opend or Closed
returns: whatever atapiCmd() returns
****************************************************************************/
static int atapiGetEventStatus(driveinfo *Drive, u8 *Buffer, unsigned Count)
{
u8 Pkt[12]={ATAPI_CMD_GET_EVENT, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
drivecmd Cmd;
printf("atapiGetEventStatus:");
memset(&Cmd, 0, sizeof(Cmd));
Cmd.Count=Count;
Cmd.Data=Buffer;
Pkt[1]=1;
Pkt[4]=0x10;
Pkt[8]=Count;
return(atapiCmd(Drive, &Cmd, Pkt));
}
/***************************************************************************
name: atapiChkTrayIsOpen
action: check cd-rom tray opened or closed
returns: 1 is opend , 0 is closed and -1 is Error
****************************************************************************/
static int atapiChkTrayIsOpen(driveinfo *Drive)
{
u8 Buffer[8];
int Temp;
Temp=atapiGetEventStatus(Drive, Buffer, 6);
if (Temp != 0)
{
return(-1);
}
return(Buffer[5]&0x01); // Bit 0 is Tray Status, See SFF-8090 v6R7 P362
}
/***************************************************************************
name: atapiTOCEnt
action: reads one or more table-of-contents entries from audio CD
returns:whatever atapiCmd() returns
****************************************************************************/
static int atapiTOCEnt(driveinfo *Drive, u8 *Buffer, unsigned Count)
{
u8 Pkt[12]={ATAPI_CMD_READTOC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
drivecmd Cmd;
printf("atapiTOCEnt:");
memset(&Cmd, 0, sizeof(Cmd));
Cmd.Count=Count;
Cmd.Data=Buffer;
Pkt[1]=2;
Pkt[7]=Count >> 8;
Pkt[8]=Count;
return(atapiCmd(Drive, &Cmd, Pkt));
}
/***************************************************************************
name: atapiTOC
action: reads table of contents of audio CD and prints starting
time of each track
returns:whatever atapiCmd() returns
****************************************************************************/
static int atapiTOC(driveinfo *Drive)
{
u8 *Entry, Buffer[4 + 8 * (MAX_TRACKS+1)];
int TOCEnt, Temp;
printf("atapiTOC:\n");
// 16-bit TOC length, 8-bit first track, 8-bit last track
TOCEnt = 4;
#ifdef DEBUG
printf(" calling atapiTOCEnt with Count=%u\n", TOCEnt);
#endif
// Read TOC
Temp=atapiTOCEnt(Drive, Buffer, TOCEnt);
if(Temp != 0)
{
return(Temp);
}
// NumTracks = LastTrack - FristTrack + 1
NumTracks=Buffer[3] - Buffer[2] + 1;
// Check NumTracks(must in range 1~99)
if(NumTracks <= 0 || NumTracks > 99)
{
printf(" error: bad number of tracks %d\n", NumTracks);
return(-1);
}
// Check MAX_TRACKS handle
if(NumTracks > MAX_TRACKS)
{
printf(" warning: too many tracks(%u); reducing to %u.\n",NumTracks, MAX_TRACKS);
NumTracks=MAX_TRACKS;
}
// read 4-byte header and 8-byte table-of-contents entries
TOCEnt = 4 + 8 * (NumTracks+1);
#ifdef DEBUG
printf(" calling atapiTOCEnt with Count=%u\n", TOCEnt);
#endif
// Read TOC
Temp=atapiTOCEnt(Drive, Buffer, TOCEnt);
if(Temp != 0)
{
return(Temp);
}
// point to first TOC entry
Entry=Buffer + 4;
// read NumTracks+1 entries the last entry is for the disk lead-out
for(Temp=0; Temp < NumTracks + 1; Temp++)
{
Track[Temp].Min=Entry[5];
Track[Temp].Sec=Entry[6];
Track[Temp].Frame=Entry[7];
printf("%02u:%02u:%02u ", Track[Temp].Min, Track[Temp].Sec, Track[Temp].Frame);
// advance to next entry
Entry += 8;
}
printf("\n");
return(0);
}
/***************************************************************************
name: atapiPlay
action: plays audio from time index Start to End (units of 1/75 sec)
returns:whatever atapiCmd() returns
****************************************************************************/
static int atapiPlay(driveinfo *Drive, atapimsf *Start, atapimsf *End)
{
u8 Pkt[12]={ATAPI_CMD_PLAY, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
drivecmd Cmd;
printf("atapiPlay:");
memset(&Cmd, 0, sizeof(Cmd));
Pkt[3]=Start->Min;
Pkt[4]=Start->Sec;
Pkt[5]=Start->Frame;
Pkt[6]=End->Min;
Pkt[7]=End->Sec;
Pkt[8]=End->Frame;
return(atapiCmd(Drive, &Cmd, Pkt));
}
/***************************************************************************
name: atapiPause
action: pauses or continues audio CD
returns:whatever atapiCmd() returns
****************************************************************************/
static int atapiPause(driveinfo *Drive, bool Continue)
{
u8 Pkt[12]={ATAPI_CMD_PAUSE,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
drivecmd Cmd;
printf("atapiPause:");
memset(&Cmd, 0, sizeof(Cmd));
Pkt[8]=Continue ? 1 : 0;
return(atapiCmd(Drive, &Cmd, Pkt));
}
/***************************************************************************
name: atapiStop
action: stop audio play or scan
return: whatever atapiCmd() returns
****************************************************************************/
static int atapiStop(driveinfo *Drive)
{
u8 Pkt[12]={ATAPI_CMD_STOP,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
drivecmd Cmd;
printf("atapiStop:");
memset(&Cmd, 0, sizeof(Cmd));
return(atapiCmd(Drive, &Cmd, Pkt));
}
|