Add support for .msu1 pack files

This commit is contained in:
qwertymodo 2017-08-16 18:56:57 -07:00
parent 4a3f7dcc2b
commit f8da152441
2 changed files with 57 additions and 17 deletions

View File

@ -4257,6 +4257,28 @@ void CMemory::CheckForAnyPatch (const char *rom_filename, bool8 header, int32 &r
} }
#ifdef UNZIP_SUPPORT #ifdef UNZIP_SUPPORT
// Mercurial Magic (MSU-1 distribution pack)
_makepath(fname, drive, dir, name, "msu1");
unzFile msu1file = unzOpen(fname);
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 (!strcasecmp(ext, "zip") || !strcasecmp(ext, ".zip")) if (!strcasecmp(ext, "zip") || !strcasecmp(ext, ".zip"))
{ {
unzFile file = unzOpen(rom_filename); unzFile file = unzOpen(rom_filename);

View File

@ -224,7 +224,7 @@ static int unzFindExtension(unzFile &file, const char *ext, bool restart = TRUE,
unzGetCurrentFileInfo(file, &info, name, 128, NULL, 0, NULL, 0); unzGetCurrentFileInfo(file, &info, name, 128, NULL, 0, NULL, 0);
len = strlen(name); len = strlen(name);
if (len >= l + 1 && strcasecmp(name + len - l, ext) == 0 && unzOpenCurrentFile(file) == UNZ_OK) if (len >= l && strcasecmp(name + len - l, ext) == 0 && unzOpenCurrentFile(file) == UNZ_OK)
{ {
if (print) if (print)
printf("Using msu file %s", name); printf("Using msu file %s", name);
@ -247,24 +247,28 @@ STREAM S9xMSU1OpenFile(char *msu_ext)
printf("Using msu file %s.\n", filename); printf("Using msu file %s.\n", filename);
#ifdef UNZIP_SUPPORT #ifdef UNZIP_SUPPORT
// look for msu file in .msu.zip if not found in rom dir // look for msu file in .msu1 (Mercurial Magic pack) or .msu.zip if not found in rom dir
if (!file) if (!file)
{ {
const char *zip_filename = S9xGetFilename(".msu.zip", ROMFILENAME_DIR); const char *zip_filename = S9xGetFilename(".msu.zip", ROMFILENAME_DIR);
if (zip_filename) unzFile unzFile = unzOpen(zip_filename);
if (!unzFile)
{
zip_filename = S9xGetFilename(".msu1", ROMFILENAME_DIR);
unzFile = unzOpen(zip_filename);
}
if (unzFile)
{ {
unzFile unzFile = unzOpen(zip_filename); int port = unzFindExtension(unzFile, msu_ext);
if (unzFile) if (port == UNZ_OK)
{ {
int port = unzFindExtension(unzFile, msu_ext); printf(" in %s.\n", zip_filename);
if (port == UNZ_OK) file = new unzStream(unzFile);
{
printf(" in %s.\n", zip_filename);
file = new unzStream(unzFile);
}
else
unzCloseCurrentFile(unzFile);
} }
else
unzCloseCurrentFile(unzFile);
} }
} }
#endif #endif
@ -321,6 +325,10 @@ bool DataOpen()
} }
dataStream = S9xMSU1OpenFile(".msu"); dataStream = S9xMSU1OpenFile(".msu");
if(!dataStream)
dataStream = S9xMSU1OpenFile("msu1.rom");
return dataStream != NULL; return dataStream != NULL;
} }
@ -368,10 +376,20 @@ bool S9xMSU1ROMExists(void)
{ {
struct stat buf; struct stat buf;
STREAM s = S9xMSU1OpenFile(".msu"); STREAM s = S9xMSU1OpenFile(".msu");
bool8 exists = (s != NULL); if (s)
if(s) {
CLOSE_STREAM(s); CLOSE_STREAM(s);
return exists; return true;
}
s = S9xMSU1OpenFile("msu1.rom");
if (s)
{
CLOSE_STREAM(s);
return true;
}
return false;
} }
void S9xMSU1Generate(size_t sample_count) void S9xMSU1Generate(size_t sample_count)