X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libpcsxcore%2Fppf.c;h=6a88e0536c71d46c2a290228987ffe9569d90cdc;hb=refs%2Fremotes%2Fgithub%2Flibretro;hp=2ce1a9d9a1df2d93cb84f0571879a62a2c9a6836;hpb=92e2ce8532309ab0dfa2f82122855b6b06311539;p=pcsx_rearmed.git diff --git a/libpcsxcore/ppf.c b/libpcsxcore/ppf.c index 2ce1a9d9..6a88e053 100644 --- a/libpcsxcore/ppf.c +++ b/libpcsxcore/ppf.c @@ -21,6 +21,7 @@ #include "psxcommon.h" #include "ppf.h" +#include "misc.h" #include "cdrom.h" typedef struct tagPPF_DATA { @@ -180,7 +181,7 @@ static void AddToPPF(s32 ladr, s32 pos, s32 anz, unsigned char *ppfmem) { } } -void BuildPPFCache() { +void BuildPPFCache(const char *fname) { FILE *ppffile; char buffer[12]; char method, undo = 0, blockcheck = 0; @@ -195,23 +196,25 @@ void BuildPPFCache() { if (CdromId[0] == '\0') return; - // Generate filename in the format of SLUS_123.45 - buffer[0] = toupper(CdromId[0]); - buffer[1] = toupper(CdromId[1]); - buffer[2] = toupper(CdromId[2]); - buffer[3] = toupper(CdromId[3]); - buffer[4] = '_'; - buffer[5] = CdromId[4]; - buffer[6] = CdromId[5]; - buffer[7] = CdromId[6]; - buffer[8] = '.'; - buffer[9] = CdromId[7]; - buffer[10] = CdromId[8]; - buffer[11] = '\0'; - - sprintf(szPPF, "%s%s", Config.PatchesDir, buffer); - - ppffile = fopen(szPPF, "rb"); + if (!fname) { + // Generate filename in the format of SLUS_123.45 + buffer[0] = toupper(CdromId[0]); + buffer[1] = toupper(CdromId[1]); + buffer[2] = toupper(CdromId[2]); + buffer[3] = toupper(CdromId[3]); + buffer[4] = '_'; + buffer[5] = CdromId[4]; + buffer[6] = CdromId[5]; + buffer[7] = CdromId[6]; + buffer[8] = '.'; + buffer[9] = CdromId[7]; + buffer[10] = CdromId[8]; + buffer[11] = '\0'; + + sprintf(szPPF, "%s%s", Config.PatchesDir, buffer); + fname = szPPF; + } + ppffile = fopen(fname, "rb"); if (ppffile == NULL) return; memset(buffer, 0, 5); @@ -219,7 +222,7 @@ void BuildPPFCache() { goto fail_io; if (strcmp(buffer, "PPF") != 0) { - SysPrintf(_("Invalid PPF patch: %s.\n"), szPPF); + SysPrintf(_("Invalid PPF patch: %s.\n"), fname); fclose(ppffile); return; } @@ -345,7 +348,8 @@ void BuildPPFCache() { FillPPFCache(); // build address array - SysPrintf(_("Loaded PPF %d.0 patch: %s.\n"), method + 1, szPPF); + SysPrintf(_("Loaded PPF %d.0 patch: %s.\n"), method + 1, fname); + return; fail_io: #ifndef NDEBUG @@ -356,6 +360,7 @@ fail_io: // redump.org SBI files, slightly different handling from PCSX-Reloaded unsigned char *sbi_sectors; +int sbi_len; int LoadSBI(const char *fname, int sector_count) { int good_sectors = 0; @@ -369,7 +374,8 @@ int LoadSBI(const char *fname, int sector_count) { if (sbihandle == NULL) return -1; - sbi_sectors = calloc(1, sector_count / 8); + sbi_len = (sector_count + 7) / 8; + sbi_sectors = calloc(1, sbi_len); if (sbi_sectors == NULL) goto end; @@ -413,15 +419,13 @@ int LoadSBI(const char *fname, int sector_count) { break; } - fclose(sbihandle); - return 0; - end: if (!clean_eof) SysPrintf(_("SBI: parse failure at 0x%lx\n"), ftell(sbihandle)); if (!good_sectors) { free(sbi_sectors); sbi_sectors = NULL; + sbi_len = 0; } fclose(sbihandle); return sbi_sectors ? 0 : -1; @@ -431,5 +435,6 @@ void UnloadSBI(void) { if (sbi_sectors) { free(sbi_sectors); sbi_sectors = NULL; + sbi_len = 0; } }