add redump.org SBI support
authornotaz <notasas@gmail.com>
Tue, 15 Feb 2011 12:14:00 +0000 (14:14 +0200)
committernotaz <notasas@gmail.com>
Tue, 15 Feb 2011 12:14:00 +0000 (14:14 +0200)
This is based on PCSX-Reloaded (as usual) but done a bit different,
loaded as .sub file instead of as ppf patch.

libpcsxcore/cdriso.c
libpcsxcore/cdrom.c
libpcsxcore/ppf.c
libpcsxcore/ppf.h

index 1e9aded..2d371dd 100644 (file)
@@ -22,6 +22,7 @@
 #include "plugins.h"
 #include "cdrom.h"
 #include "cdriso.h"
 #include "plugins.h"
 #include "cdrom.h"
 #include "cdriso.h"
+#include "ppf.h"
 
 #ifdef _WIN32
 #include <process.h>
 
 #ifdef _WIN32
 #include <process.h>
@@ -685,6 +686,25 @@ static int opensubfile(const char *isoname) {
        return 0;
 }
 
        return 0;
 }
 
+static int opensbifile(const char *isoname) {
+       char            sbiname[MAXPATHLEN];
+       int             s;
+
+       strncpy(sbiname, isoname, sizeof(sbiname));
+       sbiname[MAXPATHLEN - 1] = '\0';
+       if (strlen(sbiname) >= 4) {
+               strcpy(sbiname + strlen(sbiname) - 4, ".sbi");
+       }
+       else {
+               return -1;
+       }
+
+       fseek(cdHandle, 0, SEEK_END);
+       s = ftell(cdHandle) / 2352;
+
+       return LoadSBI(sbiname, s);
+}
+
 static void PrintTracks(void) {
        int i;
 
 static void PrintTracks(void) {
        int i;
 
@@ -730,6 +750,9 @@ static long CALLBACK ISOopen(void) {
        if (!subChanMixed && opensubfile(GetIsoFile()) == 0) {
                SysPrintf("[+sub]");
        }
        if (!subChanMixed && opensubfile(GetIsoFile()) == 0) {
                SysPrintf("[+sub]");
        }
+       if (opensbifile(GetIsoFile()) == 0) {
+               SysPrintf("[+sbi]");
+       }
 
        SysPrintf(".\n");
 
 
        SysPrintf(".\n");
 
@@ -765,6 +788,7 @@ static long CALLBACK ISOclose(void) {
                }
        }
        numtracks = 0;
                }
        }
        numtracks = 0;
+       UnloadSBI();
 
        return 0;
 }
 
        return 0;
 }
index 0de7ecc..ee74835 100644 (file)
@@ -988,10 +988,9 @@ void cdrInterrupt() {
                        }
 
                        // redump.org - wipe time
                        }
 
                        // redump.org - wipe time
-                       /*if( !cdr.Play && CheckSBI(cdr.Result+5) ) {
+                       if( !cdr.Play && CheckSBI(cdr.Result+5) ) {
                                memset( cdr.Result+2, 0, 6 );
                        }
                                memset( cdr.Result+2, 0, 6 );
                        }
-                       */
 
                        cdr.Stat = Acknowledge;
                        break;
 
                        cdr.Stat = Acknowledge;
                        break;
index 45c8733..268ed1c 100644 (file)
@@ -330,3 +330,46 @@ void BuildPPFCache() {
 
        SysPrintf(_("Loaded PPF %d.0 patch: %s.\n"), method + 1, szPPF);
 }
 
        SysPrintf(_("Loaded PPF %d.0 patch: %s.\n"), method + 1, szPPF);
 }
+
+// redump.org SBI files, slightly different handling from PCSX-Reloaded
+unsigned char *sbi_sectors;
+
+int LoadSBI(const char *fname, int sector_count) {
+       char buffer[16], sbifile[MAXPATHLEN];
+       FILE *sbihandle;
+       u8 sbitime[3];
+       int s;
+
+       sbihandle = fopen(fname, "rb");
+       if (sbihandle == NULL)
+               return -1;
+
+if (sbi_sectors != NULL) printf("sbi_sectors?\n");
+       sbi_sectors = calloc(1, sector_count / 8);
+       if (sbi_sectors == NULL)
+               return -1;
+
+       // 4-byte SBI header
+       fread(buffer, 1, 4, sbihandle);
+       while (!feof(sbihandle)) {
+               fread(sbitime, 1, 3, sbihandle);
+               fread(buffer, 1, 11, sbihandle);
+
+               s = MSF2SECT(btoi(sbitime[0]), btoi(sbitime[1]), btoi(sbitime[2]));
+               if (s < sector_count)
+                       sbi_sectors[s >> 3] |= 1 << (s&7);
+               else
+                       SysPrintf(_("SBI sector %d >= %d?\n"), s, sector_count);
+       }
+
+       fclose(sbihandle);
+
+       return 0;
+}
+
+void UnloadSBI(void) {
+       if (sbi_sectors) {
+               free(sbi_sectors);
+               sbi_sectors = NULL;
+       }
+}
index f578028..fdb11eb 100644 (file)
@@ -27,6 +27,21 @@ void BuildPPFCache();
 void FreePPFCache();
 void CheckPPFCache(unsigned char *pB, unsigned char m, unsigned char s, unsigned char f);
 
 void FreePPFCache();
 void CheckPPFCache(unsigned char *pB, unsigned char m, unsigned char s, unsigned char f);
 
+int LoadSBI(const char *fname, int sector_count);
+void UnloadSBI(void);
+
+extern unsigned char *sbi_sectors;
+
+static inline int CheckSBI(const u8 *t)
+{
+       int s;
+       if (sbi_sectors == NULL)
+               return 0;
+
+       s = MSF2SECT(btoi(t[0]), btoi(t[1]), btoi(t[2]));
+       return (sbi_sectors[s >> 3] >> (s & 7)) & 1;
+}
+
 #ifdef __cplusplus
 }
 #endif
 #ifdef __cplusplus
 }
 #endif