diff options
| author | SND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2009-10-05 09:22:29 +0000 |
|---|---|---|
| committer | SND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2009-10-05 09:22:29 +0000 |
| commit | 714a40b66dedf426eb1b3b8938168b5a34ffcb5f (patch) | |
| tree | 0acc6034027e2954cbbfba8c652e9355ecaac484 /libpcsxcore | |
| parent | b59859784f3d86b70fbf024fcce878c44a92d9e8 (diff) | |
| download | pcsxr-714a40b66dedf426eb1b3b8938168b5a34ffcb5f.tar.gz | |
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@31117 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'libpcsxcore')
| -rw-r--r-- | libpcsxcore/cdriso.c | 264 |
1 files changed, 136 insertions, 128 deletions
diff --git a/libpcsxcore/cdriso.c b/libpcsxcore/cdriso.c index 65493aaf..9c34f229 100644 --- a/libpcsxcore/cdriso.c +++ b/libpcsxcore/cdriso.c @@ -40,8 +40,8 @@ FILE *cdHandle = NULL; FILE *cddaHandle = NULL; -FILE *subHandle = NULL;
-
+FILE *subHandle = NULL; + static char subChanInterleaved = 0; static unsigned char cdbuffer[DATA_SIZE]; @@ -165,24 +165,24 @@ static void *playthread(void *param) t = GetTickCount() + CDDA_FRAMETIME; - if (subChanInterleaved) {
- s = 0;
+ if (subChanInterleaved) { + s = 0; for (i = 0; i < sizeof(sndbuffer) / CD_FRAMESIZE_RAW; i++) { // read one sector d = fread(sndbuffer + CD_FRAMESIZE_RAW * i, 1, CD_FRAMESIZE_RAW, cddaHandle); if (d < CD_FRAMESIZE_RAW) { break; - }
-
- s += d;
-
- // skip the subchannel data
- fseek(cddaHandle, SUB_FRAMESIZE, SEEK_CUR);
+ } + + s += d; + + // skip the subchannel data + fseek(cddaHandle, SUB_FRAMESIZE, SEEK_CUR); } - }
- else {
- s = fread(sndbuffer, 1, sizeof(sndbuffer), cddaHandle);
+ } + else { + s = fread(sndbuffer, 1, sizeof(sndbuffer), cddaHandle); } if (s == 0) { @@ -309,6 +309,10 @@ static int parsetoc(const char *isofile) { strncpy(dummy, linebuf, sizeof(linebuf)); token = strtok(dummy, " "); + if (token == NULL) { + continue; + } + if (!strcmp(token, "TRACK")) { // get type of track token = strtok(NULL, " "); @@ -374,6 +378,10 @@ static int parsecue(const char *isofile) { strncpy(dummy, linebuf, sizeof(linebuf)); token = strtok(dummy, " "); + if (token == NULL) { + continue; + } + if (!strcmp(token, "TRACK")){ numtracks++; @@ -473,105 +481,105 @@ static int parseccd(const char *isofile) { } return 0; -}
-
-// this function tries to get the .mds file of the given .mdf
-// the necessary data is put into the ti (trackinformation)-array
-static int parsemds(const char *isofile) {
- char mdsname[MAXPATHLEN];
- FILE *fi;
- unsigned int offset, extra_offset, l, i;
- unsigned short s;
-
- numtracks = 0;
-
- // copy name of the iso and change extension from .mdf to .mds
- strncpy(mdsname, isofile, sizeof(mdsname));
- mdsname[MAXPATHLEN - 1] = '\0';
- if (strlen(mdsname) >= 4) {
- strcpy(mdsname + strlen(mdsname) - 4, ".mds");
- }
- else {
- return -1;
- }
-
- if ((fi = fopen(mdsname, "rb")) == NULL) {
- return -1;
- }
-
- memset(&ti, 0, sizeof(ti));
-
- // check if it's a valid mds file
- fread(&i, 1, sizeof(unsigned int), fi);
- i = SWAP32(i);
- if (i != 0x4944454D) {
- // not an valid mds file
- fclose(fi);
- return -1;
- }
-
- // get offset to session block
- fseek(fi, 0x50, SEEK_SET);
- fread(&offset, 1, sizeof(unsigned int), fi);
- offset = SWAP32(offset);
-
- // get total number of tracks
- offset += 14;
- fseek(fi, offset, SEEK_SET);
- fread(&s, 1, sizeof(unsigned short), fi);
- s = SWAP16(s);
- numtracks = s;
-
- // get offset to track blocks
- fseek(fi, 4, SEEK_CUR);
- fread(&offset, 1, sizeof(unsigned int), fi);
- offset = SWAP32(offset);
-
- // skip lead-in data
- while (1) {
- fseek(fi, offset + 4, SEEK_SET);
- if (fgetc(fi) < 0xA0) {
- break;
- }
- offset += 0x50;
- }
-
- // check if the image contains interleaved subchannel data
- fseek(fi, offset + 1, SEEK_SET);
- subChanInterleaved = fgetc(fi);
-
- // read track data
- for (i = 1; i <= numtracks; i++) {
- fseek(fi, offset, SEEK_SET);
-
- // get the track type
- ti[i].type = ((fgetc(fi) == 0xA9) ? CDDA : DATA);
- fseek(fi, 8, SEEK_CUR);
-
- // get the track starting point
- ti[i].start[0] = fgetc(fi);
- ti[i].start[1] = fgetc(fi);
- ti[i].start[2] = fgetc(fi);
-
- if (i > 1) {
- l = msf2sec(ti[i].start);
- sec2msf(l - 2 * 75, ti[i].start); // ???
- }
-
- // get the track length
- fread(&extra_offset, 1, sizeof(unsigned int), fi);
- extra_offset = SWAP32(extra_offset);
-
- fseek(fi, extra_offset + 4, SEEK_SET);
- fread(&l, 1, sizeof(unsigned int), fi);
- l = SWAP32(l);
- sec2msf(l, ti[i].length);
-
- offset += 0x50;
- }
-
- fclose(fi);
- return 0;
+} + +// this function tries to get the .mds file of the given .mdf +// the necessary data is put into the ti (trackinformation)-array +static int parsemds(const char *isofile) { + char mdsname[MAXPATHLEN]; + FILE *fi; + unsigned int offset, extra_offset, l, i; + unsigned short s; + + numtracks = 0; + + // copy name of the iso and change extension from .mdf to .mds + strncpy(mdsname, isofile, sizeof(mdsname)); + mdsname[MAXPATHLEN - 1] = '\0'; + if (strlen(mdsname) >= 4) { + strcpy(mdsname + strlen(mdsname) - 4, ".mds"); + } + else { + return -1; + } + + if ((fi = fopen(mdsname, "rb")) == NULL) { + return -1; + } + + memset(&ti, 0, sizeof(ti)); + + // check if it's a valid mds file + fread(&i, 1, sizeof(unsigned int), fi); + i = SWAP32(i); + if (i != 0x4944454D) { + // not an valid mds file + fclose(fi); + return -1; + } + + // get offset to session block + fseek(fi, 0x50, SEEK_SET); + fread(&offset, 1, sizeof(unsigned int), fi); + offset = SWAP32(offset); + + // get total number of tracks + offset += 14; + fseek(fi, offset, SEEK_SET); + fread(&s, 1, sizeof(unsigned short), fi); + s = SWAP16(s); + numtracks = s; + + // get offset to track blocks + fseek(fi, 4, SEEK_CUR); + fread(&offset, 1, sizeof(unsigned int), fi); + offset = SWAP32(offset); + + // skip lead-in data + while (1) { + fseek(fi, offset + 4, SEEK_SET); + if (fgetc(fi) < 0xA0) { + break; + } + offset += 0x50; + } + + // check if the image contains interleaved subchannel data + fseek(fi, offset + 1, SEEK_SET); + subChanInterleaved = fgetc(fi); + + // read track data + for (i = 1; i <= numtracks; i++) { + fseek(fi, offset, SEEK_SET); + + // get the track type + ti[i].type = ((fgetc(fi) == 0xA9) ? CDDA : DATA); + fseek(fi, 8, SEEK_CUR); + + // get the track starting point + ti[i].start[0] = fgetc(fi); + ti[i].start[1] = fgetc(fi); + ti[i].start[2] = fgetc(fi); + + if (i > 1) { + l = msf2sec(ti[i].start); + sec2msf(l - 2 * 75, ti[i].start); // ??? + } + + // get the track length + fread(&extra_offset, 1, sizeof(unsigned int), fi); + extra_offset = SWAP32(extra_offset); + + fseek(fi, extra_offset + 4, SEEK_SET); + fread(&l, 1, sizeof(unsigned int), fi); + l = SWAP32(l); + sec2msf(l, ti[i].length); + + offset += 0x50; + } + + fclose(fi); + return 0; } // this function tries to get the .sub file of the given .img @@ -630,7 +638,7 @@ static long CALLBACK ISOopen(void) { SysPrintf(_("Loaded CD Image: %s"), cdrfilename); - cddaBigEndian = 0;
+ cddaBigEndian = 0; subChanInterleaved = 0; if (parsetoc(cdrfilename) == 0) { @@ -642,9 +650,9 @@ static long CALLBACK ISOopen(void) { } else if (parseccd(cdrfilename) == 0) { SysPrintf("[+ccd]"); - }
- else if (parsemds(cdrfilename) == 0) {
- SysPrintf("[+mds]");
+ } + else if (parsemds(cdrfilename) == 0) { + SysPrintf("[+mds]"); } if (!subChanInterleaved && opensubfile(cdrfilename) == 0) { @@ -713,19 +721,19 @@ static long CALLBACK ISOreadTrack(unsigned char *time) { if (cdHandle == NULL) { return -1; } -
- if (subChanInterleaved) {
- fseek(cdHandle, MSF2SECT(btoi(time[0]), btoi(time[1]), btoi(time[2])) * (CD_FRAMESIZE_RAW + SUB_FRAMESIZE) + 12, SEEK_SET);
- fread(cdbuffer, 1, DATA_SIZE, cdHandle);
- fread(subbuffer, 1, SUB_FRAMESIZE, cdHandle);
- }
+ + if (subChanInterleaved) { + fseek(cdHandle, MSF2SECT(btoi(time[0]), btoi(time[1]), btoi(time[2])) * (CD_FRAMESIZE_RAW + SUB_FRAMESIZE) + 12, SEEK_SET); + fread(cdbuffer, 1, DATA_SIZE, cdHandle); + fread(subbuffer, 1, SUB_FRAMESIZE, cdHandle); + } else { fseek(cdHandle, MSF2SECT(btoi(time[0]), btoi(time[1]), btoi(time[2])) * CD_FRAMESIZE_RAW + 12, SEEK_SET); fread(cdbuffer, 1, DATA_SIZE, cdHandle); if (subHandle != NULL) { fseek(subHandle, MSF2SECT(btoi(time[0]), btoi(time[1]), btoi(time[2])) * SUB_FRAMESIZE, SEEK_SET); - fread(subbuffer, 1, SUB_FRAMESIZE, subHandle);
+ fread(subbuffer, 1, SUB_FRAMESIZE, subHandle); } } @@ -741,12 +749,12 @@ static unsigned char * CALLBACK ISOgetBuffer(void) { // sector: byte 0 - minute; byte 1 - second; byte 2 - frame // does NOT uses bcd format static long CALLBACK ISOplay(unsigned char *time) { - if (SPU_playCDDAchannel != NULL) {
- if (subChanInterleaved) {
- startCDDA(MSF2SECT(time[0], time[1], time[2]) * (CD_FRAMESIZE_RAW + SUB_FRAMESIZE));
- }
+ if (SPU_playCDDAchannel != NULL) { + if (subChanInterleaved) { + startCDDA(MSF2SECT(time[0], time[1], time[2]) * (CD_FRAMESIZE_RAW + SUB_FRAMESIZE)); + } else { - startCDDA(MSF2SECT(time[0], time[1], time[2]) * CD_FRAMESIZE_RAW);
+ startCDDA(MSF2SECT(time[0], time[1], time[2]) * CD_FRAMESIZE_RAW); } } return 0; |
