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 #ifdef UNZIP_SUPPORT
// Mercurial Magic (MSU-1 distribution pack) // 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"); Stream *s = S9xMSU1OpenFile("patch.bps", TRUE);
unzFile msu1file = unzOpen(fname); if (s)
if (!msu1file)
{ {
_snprintf(fname, sizeof(fname), "%s" SLASH_STR "%s%s", printf("Using BPS patch %s.msu1", name);
S9xGetDirectory(IPS_DIR), name, ".msu1"); ret = ReadBPSPatch(s, offset, rom_size);
msu1file = unzOpen(fname); s->closeStream();
}
if (msu1file) if (ret)
{ printf("!\n");
int port = unzFindExtension(msu1file, "bps"); else
if (port == UNZ_OK) printf(" failed!\n");
{
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");
}
} }
} }
#endif #endif

View File

@ -240,12 +240,17 @@ static int unzFindExtension(unzFile &file, const char *ext, bool restart = TRUE,
} }
#endif #endif
STREAM S9xMSU1OpenFile(char *msu_ext) STREAM S9xMSU1OpenFile(char *msu_ext, bool skip_unpacked)
{ {
const char *filename = S9xGetFilename(msu_ext, ROMFILENAME_DIR); const char *filename = S9xGetFilename(msu_ext, ROMFILENAME_DIR);
STREAM file = OPEN_STREAM(filename, "rb"); STREAM file = 0;
if (file)
printf("Using msu file %s.\n", filename); if (!skip_unpacked)
{
file = OPEN_STREAM(filename, "rb");
if (file)
printf("Using msu file %s.\n", filename);
}
#ifdef UNZIP_SUPPORT #ifdef UNZIP_SUPPORT
// look for msu1 pack file in the rom or patch dir if msu data file not found in rom dir // 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 S9xResetMSU(void);
void S9xMSU1Init(void); void S9xMSU1Init(void);
bool S9xMSU1ROMExists(void); bool S9xMSU1ROMExists(void);
STREAM S9xMSU1OpenFile(char *msu_ext); STREAM S9xMSU1OpenFile(char *msu_ext, bool skip_unpacked = FALSE);
void S9xMSU1Init(void); void S9xMSU1Init(void);
void S9xMSU1Generate(size_t sample_count); void S9xMSU1Generate(size_t sample_count);
uint8 S9xMSU1ReadPort(uint8 port); uint8 S9xMSU1ReadPort(uint8 port);