Minor refactor to .msu1 pack hotpatching

This commit is contained in:
qwertymodo 2017-09-09 17:02:52 -07:00
parent 158b509bbb
commit 7455501db8
3 changed files with 20 additions and 30 deletions

View File

@ -4754,34 +4754,19 @@ void CMemory::CheckForAnyPatch (const char *rom_filename, bool8 header, int32 &r
#ifdef UNZIP_SUPPORT
// Mercurial Magic (MSU-1 distribution pack)
if (strcasecmp(ext, "msu1") && strcasecmp(ext, ".msu1"))
if (strcasecmp(ext, "msu1") && strcasecmp(ext, ".msu1")) // ROM was *NOT* loaded from a .msu1 pack
{
_makepath(fname, drive, dir, name, "msu1");
unzFile msu1file = unzOpen(fname);
if (!msu1file)
Stream *s = S9xMSU1OpenFile("patch.bps", TRUE);
if (s)
{
_snprintf(fname, sizeof(fname), "%s" SLASH_STR "%s%s",
S9xGetDirectory(IPS_DIR), name, ".msu1");
msu1file = unzOpen(fname);
}
printf("Using BPS patch %s.msu1", name);
ret = ReadBPSPatch(s, offset, rom_size);
s->closeStream();
if (msu1file)
{
int port = unzFindExtension(msu1file, "bps");
if (port == UNZ_OK)
{
printf(" in %s", fname);
Stream *s = new unzStream(msu1file);
ret = ReadBPSPatch(s, offset, rom_size);
s->closeStream();
if (ret)
printf("!\n");
else
printf(" failed!\n");
}
if (ret)
printf("!\n");
else
printf(" failed!\n");
}
}
#endif

View File

@ -240,12 +240,17 @@ static int unzFindExtension(unzFile &file, const char *ext, bool restart = TRUE,
}
#endif
STREAM S9xMSU1OpenFile(char *msu_ext)
STREAM S9xMSU1OpenFile(char *msu_ext, bool skip_unpacked)
{
const char *filename = S9xGetFilename(msu_ext, ROMFILENAME_DIR);
STREAM file = OPEN_STREAM(filename, "rb");
if (file)
printf("Using msu file %s.\n", filename);
STREAM file = 0;
if (!skip_unpacked)
{
file = OPEN_STREAM(filename, "rb");
if (file)
printf("Using msu file %s.\n", filename);
}
#ifdef UNZIP_SUPPORT
// look for msu1 pack file in the rom or patch dir if msu data file not found in rom dir

2
msu1.h
View File

@ -229,7 +229,7 @@ extern struct SMSU1 MSU1;
void S9xResetMSU(void);
void S9xMSU1Init(void);
bool S9xMSU1ROMExists(void);
STREAM S9xMSU1OpenFile(char *msu_ext);
STREAM S9xMSU1OpenFile(char *msu_ext, bool skip_unpacked = FALSE);
void S9xMSU1Init(void);
void S9xMSU1Generate(size_t sample_count);
uint8 S9xMSU1ReadPort(uint8 port);