Skip to content

Commit

Permalink
standalone: some ppf loading
Browse files Browse the repository at this point in the history
mostly for testing, like game.chd.ppf would load game.chd and apply
game.chd.ppf patch
  • Loading branch information
notaz committed Jun 28, 2024
1 parent 77d753f commit e1fbc1a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 24 deletions.
19 changes: 17 additions & 2 deletions frontend/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "../libpcsxcore/cdrom.h"
#include "../libpcsxcore/cdriso.h"
#include "../libpcsxcore/cheat.h"
#include "../libpcsxcore/ppf.h"
#include "../libpcsxcore/new_dynarec/new_dynarec.h"
#include "../plugins/dfsound/spu_config.h"
#include "psemu_plugin_defs.h"
Expand Down Expand Up @@ -740,7 +741,7 @@ static const char *filter_exts[] = {
#ifdef HAVE_CHD
"chd",
#endif
"bz", "znx", "pbp", "cbn", NULL
"bz", "znx", "pbp", "cbn", "ppf", NULL
};

// rrrr rggg gggb bbbb
Expand Down Expand Up @@ -2157,6 +2158,18 @@ static int run_exe(void)
static int run_cd_image(const char *fname)
{
int autoload_state = g_autostateld_opt;
size_t fname_len = strlen(fname);
const char *ppfname = NULL;
char fname2[256];

// simle ppf handling, like game.chd.ppf
if (4 < fname_len && fname_len < sizeof(fname2)
&& strcasecmp(fname + fname_len - 4, ".ppf") == 0) {
memcpy(fname2, fname, fname_len - 4);
fname2[fname_len - 4] = 0;
ppfname = fname;
fname = fname2;
}

ready_to_go = 0;
reload_plugins(fname);
Expand All @@ -2170,6 +2183,8 @@ static int run_cd_image(const char *fname)
menu_update_msg("unsupported/invalid CD image");
return -1;
}
if (ppfname)
BuildPPFCache(ppfname);

SysReset();

Expand All @@ -2185,7 +2200,7 @@ static int run_cd_image(const char *fname)

if (autoload_state) {
unsigned int newest = 0;
int time, slot, newest_slot = -1;
int time = 0, slot, newest_slot = -1;

for (slot = 0; slot < 10; slot++) {
if (emu_check_save_file(slot, &time)) {
Expand Down
2 changes: 1 addition & 1 deletion libpcsxcore/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ int CheckCdrom() {

Apply_Hacks_Cdrom();

BuildPPFCache();
BuildPPFCache(NULL);

return 0;
}
Expand Down
43 changes: 23 additions & 20 deletions libpcsxcore/ppf.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,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;
Expand All @@ -196,31 +196,33 @@ 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);
if (fread(buffer, 1, 3, ppffile) != 3)
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;
}
Expand Down Expand Up @@ -346,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
Expand Down
2 changes: 1 addition & 1 deletion libpcsxcore/ppf.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
extern "C" {
#endif

void BuildPPFCache();
void BuildPPFCache(const char *fname);
void FreePPFCache();
void CheckPPFCache(unsigned char *pB, unsigned char m, unsigned char s, unsigned char f);

Expand Down

0 comments on commit e1fbc1a

Please sign in to comment.