cdrom: give up on cdda subq support
authornotaz <notasas@gmail.com>
Mon, 31 Dec 2012 23:38:52 +0000 (01:38 +0200)
committernotaz <notasas@gmail.com>
Wed, 2 Jan 2013 23:06:43 +0000 (01:06 +0200)
this just won't currently work because atleast of:
- reads racing with cdda thread
- hw cdrom plugins
- broken/unknown format .sub files

libpcsxcore/cdrom.c

index fdb38ba..f227b1b 100644 (file)
@@ -45,7 +45,6 @@
 
 cdrStruct cdr;
 static unsigned char *pTransfer;
-static int subq_broken;
 
 /* CD-ROM magic numbers */
 #define CdlSync        0
@@ -395,10 +394,58 @@ static void Find_CurTrack(const u8 *time)
        }
 }
 
-static void ReadTrack(const u8 *time, int after_seek) {
+static void generate_subq(const u8 *time)
+{
+       unsigned char start[3], next[3];
+       unsigned int this_s, start_s, next_s, pregap;
+       int relative_s;
+
+       CDR_getTD(cdr.CurTrack, start);
+       if (cdr.CurTrack + 1 <= cdr.ResultTN[1]) {
+               pregap = 150;
+               CDR_getTD(cdr.CurTrack + 1, next);
+       }
+       else {
+               // last track - cd size
+               pregap = 0;
+               next[0] = cdr.SetSectorEnd[2];
+               next[1] = cdr.SetSectorEnd[1];
+               next[2] = cdr.SetSectorEnd[0];
+       }
+
+       this_s = msf2sec(time);
+       start_s = fsm2sec(start);
+       next_s = fsm2sec(next);
+
+       cdr.TrackChanged = FALSE;
+
+       if (next_s - this_s < pregap) {
+               cdr.TrackChanged = TRUE;
+               cdr.CurTrack++;
+               start_s = next_s;
+       }
+
+       cdr.subq.Index = 1;
+
+       relative_s = this_s - start_s;
+       if (relative_s < 0) {
+               cdr.subq.Index = 0;
+               relative_s = -relative_s;
+       }
+       sec2msf(relative_s, cdr.subq.Relative);
+
+       cdr.subq.Track = itob(cdr.CurTrack);
+       cdr.subq.Relative[0] = itob(cdr.subq.Relative[0]);
+       cdr.subq.Relative[1] = itob(cdr.subq.Relative[1]);
+       cdr.subq.Relative[2] = itob(cdr.subq.Relative[2]);
+       cdr.subq.Absolute[0] = itob(time[0]);
+       cdr.subq.Absolute[1] = itob(time[1]);
+       cdr.subq.Absolute[2] = itob(time[2]);
+}
+
+static void ReadTrack(const u8 *time) {
        unsigned char tmp[3];
        struct SubQ *subq;
-       int track, old_track;
        u16 crc;
 
        tmp[0] = itob(time[0]);
@@ -413,81 +460,25 @@ static void ReadTrack(const u8 *time, int after_seek) {
        cdr.RErr = CDR_readTrack(tmp);
        memcpy(cdr.Prev, tmp, 3);
 
-       cdr.TrackChanged = FALSE;
-
        if (CheckSBI(time))
                return;
 
        subq = (struct SubQ *)CDR_getBufferSub();
-       if (subq != NULL && !subq_broken) {
+       if (subq != NULL && cdr.CurTrack == 1) {
                crc = calcCrc((u8 *)subq + 12, 10);
-               old_track = btoi(cdr.subq.Track);
-               track = btoi(subq->TrackNumber);
-
-               // track checks are probably wrong, but deals with corrupted
-               // subq + good checksum
-               // (how does the real thing handle that?)
-               if (crc == (((u16)subq->CRC[0] << 8) | subq->CRC[1])
-                   && (after_seek || track == old_track || track == old_track + 1)) {
+               if (crc == (((u16)subq->CRC[0] << 8) | subq->CRC[1])) {
                        cdr.subq.Track = subq->TrackNumber;
                        cdr.subq.Index = subq->IndexNumber;
                        memcpy(cdr.subq.Relative, subq->TrackRelativeAddress, 3);
                        memcpy(cdr.subq.Absolute, subq->AbsoluteAddress, 3);
-
-                       if (track == cdr.CurTrack + 1) {
-                               cdr.CurTrack++;
-                               cdr.TrackChanged = TRUE;
-                       }
                }
                else {
-                       CDR_LOG_I("ignore subq @%02x:%02x:%02x\n",
+                       CDR_LOG_I("subq bad crc @%02x:%02x:%02x\n",
                                tmp[0], tmp[1], tmp[2]);
                }
        }
        else {
-               unsigned char start[3], next[3];
-               unsigned int this_s, start_s, next_s, pregap;
-               int relative_s;
-
-               CDR_getTD(cdr.CurTrack, start);
-               if (cdr.CurTrack + 1 <= cdr.ResultTN[1]) {
-                       pregap = 150;
-                       CDR_getTD(cdr.CurTrack + 1, next);
-               }
-               else {
-                       // last track - cd size
-                       pregap = 0;
-                       next[0] = cdr.SetSectorEnd[2];
-                       next[1] = cdr.SetSectorEnd[1];
-                       next[2] = cdr.SetSectorEnd[0];
-               }
-
-               this_s = msf2sec(time);
-               start_s = fsm2sec(start);
-               next_s = fsm2sec(next);
-
-               if (next_s - this_s < pregap) {
-                       cdr.TrackChanged = TRUE;
-                       cdr.CurTrack++;
-                       start_s = next_s;
-               }
-
-               cdr.subq.Index = 1;
-
-               relative_s = this_s - start_s;
-               if (relative_s < 0) {
-                       cdr.subq.Index = 0;
-                       relative_s = -relative_s;
-               }
-               sec2msf(relative_s, cdr.subq.Relative);
-
-               cdr.subq.Track = itob(cdr.CurTrack);
-               cdr.subq.Relative[0] = itob(cdr.subq.Relative[0]);
-               cdr.subq.Relative[1] = itob(cdr.subq.Relative[1]);
-               cdr.subq.Relative[2] = itob(cdr.subq.Relative[2]);
-               cdr.subq.Absolute[0] = tmp[0];
-               cdr.subq.Absolute[1] = tmp[1];
-               cdr.subq.Absolute[2] = tmp[2];
+               generate_subq(time);
        }
 
        CDR_LOG(" -> %02x,%02x %02x:%02x:%02x %02x:%02x:%02x\n",
@@ -572,7 +563,7 @@ void cdrPlayInterrupt()
 
                memcpy(cdr.SetSectorPlay, cdr.SetSector, 4);
                Find_CurTrack(cdr.SetSectorPlay);
-               ReadTrack(cdr.SetSectorPlay, 1);
+               ReadTrack(cdr.SetSectorPlay);
                cdr.TrackChanged = FALSE;
        }
 
@@ -604,7 +595,7 @@ void cdrPlayInterrupt()
        CDRMISC_INT(cdReadTime);
 
        // update for CdlGetlocP/autopause
-       ReadTrack(cdr.SetSectorPlay, 0);
+       generate_subq(cdr.SetSectorPlay);
 }
 
 void cdrInterrupt() {
@@ -686,7 +677,7 @@ void cdrInterrupt() {
                        - plays tracks without retry play
                        */
                        Find_CurTrack(cdr.SetSectorPlay);
-                       ReadTrack(cdr.SetSectorPlay, 1);
+                       ReadTrack(cdr.SetSectorPlay);
                        cdr.TrackChanged = FALSE;
 
                        if (!Config.Cdda)
@@ -1025,8 +1016,8 @@ void cdrInterrupt() {
 
                        // Fighting Force 2 - update subq time immediately
                        // - fixes new game
-                       cdr.CurTrack = 1;
-                       ReadTrack(cdr.SetSector, 1);
+                       Find_CurTrack(cdr.SetSector);
+                       ReadTrack(cdr.SetSector);
 
 
                        // Crusaders of Might and Magic - update getlocl now
@@ -1104,7 +1095,7 @@ void cdrReadInterrupt() {
        cdr.Result[0] = cdr.StatP;
        cdr.Seeked = SEEK_DONE;
 
-       ReadTrack(cdr.SetSector, 0);
+       ReadTrack(cdr.SetSector);
 
        buf = CDR_getBuffer();
        if (buf == NULL)
@@ -1197,7 +1188,7 @@ void cdrReadInterrupt() {
        }
 
        // update for CdlGetlocP
-       ReadTrack(cdr.SetSector, 0);
+       ReadTrack(cdr.SetSector);
 
        Check_Shell(0);
 }
@@ -1626,9 +1617,6 @@ void cdrDmaInterrupt()
 
 static void getCdInfo(void)
 {
-       unsigned int i, j, sector;
-       struct SubQ *subq;
-       u8 tmpp[3];
        u8 tmp;
 
        CDR_getTN(cdr.ResultTN);
@@ -1636,26 +1624,6 @@ static void getCdInfo(void)
        tmp = cdr.SetSectorEnd[0];
        cdr.SetSectorEnd[0] = cdr.SetSectorEnd[2];
        cdr.SetSectorEnd[2] = tmp;
-
-       subq_broken = 0;
-       subq = (struct SubQ *)CDR_getBufferSub();
-       if (subq != NULL && cdr.ResultTN[1] >= 2) {
-               CDR_getTD(cdr.ResultTN[1], tmpp);
-               sector = fsm2sec(tmpp) - 33;
-               for (i = 0; i < 5; i++, sector += 2) {
-                       sec2msf(sector, tmpp);
-                       for (j = 0; j < 3; j++)
-                               tmpp[j] = itob(tmpp[j]);
-                       CDR_readTrack(tmpp);
-                       subq = (struct SubQ *)CDR_getBufferSub();
-                       if (subq->IndexNumber == 0)
-                               break;
-               }
-               if (i == 5) {
-                       SysPrintf("cdrom: subchannel data looks broken, not using it\n");
-                       subq_broken = 1;
-               }
-       }
 }
 
 void cdrReset() {
@@ -1699,7 +1667,7 @@ int cdrFreeze(void *f, int Mode) {
                // read right sub data
                memcpy(tmpp, cdr.Prev, 3);
                cdr.Prev[0]++;
-               ReadTrack(tmpp, 1);
+               ReadTrack(tmpp);
 
                if (cdr.Play) {
                        Find_CurTrack(cdr.SetSectorPlay);