From f8da1524414209e4e090c3ec45aee59999c9aaf3 Mon Sep 17 00:00:00 2001 From: qwertymodo Date: Wed, 16 Aug 2017 18:56:57 -0700 Subject: [PATCH] Add support for .msu1 pack files --- memmap.cpp | 22 ++++++++++++++++++++++ msu1.cpp | 52 +++++++++++++++++++++++++++++++++++----------------- 2 files changed, 57 insertions(+), 17 deletions(-) diff --git a/memmap.cpp b/memmap.cpp index 4fc88dd7..01777ac7 100644 --- a/memmap.cpp +++ b/memmap.cpp @@ -4257,6 +4257,28 @@ void CMemory::CheckForAnyPatch (const char *rom_filename, bool8 header, int32 &r } #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")) { unzFile file = unzOpen(rom_filename); diff --git a/msu1.cpp b/msu1.cpp index 1c253244..a13e45bb 100644 --- a/msu1.cpp +++ b/msu1.cpp @@ -224,7 +224,7 @@ static int unzFindExtension(unzFile &file, const char *ext, bool restart = TRUE, unzGetCurrentFileInfo(file, &info, name, 128, NULL, 0, NULL, 0); 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) printf("Using msu file %s", name); @@ -247,24 +247,28 @@ STREAM S9xMSU1OpenFile(char *msu_ext) printf("Using msu file %s.\n", filename); #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) { 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); - if (unzFile) + int port = unzFindExtension(unzFile, msu_ext); + if (port == UNZ_OK) { - int port = unzFindExtension(unzFile, msu_ext); - if (port == UNZ_OK) - { - printf(" in %s.\n", zip_filename); - file = new unzStream(unzFile); - } - else - unzCloseCurrentFile(unzFile); + printf(" in %s.\n", zip_filename); + file = new unzStream(unzFile); } + else + unzCloseCurrentFile(unzFile); } } #endif @@ -321,6 +325,10 @@ bool DataOpen() } dataStream = S9xMSU1OpenFile(".msu"); + + if(!dataStream) + dataStream = S9xMSU1OpenFile("msu1.rom"); + return dataStream != NULL; } @@ -368,10 +376,20 @@ bool S9xMSU1ROMExists(void) { struct stat buf; STREAM s = S9xMSU1OpenFile(".msu"); - bool8 exists = (s != NULL); - if(s) - CLOSE_STREAM(s); - return exists; + if (s) + { + CLOSE_STREAM(s); + return true; + } + + s = S9xMSU1OpenFile("msu1.rom"); + if (s) + { + CLOSE_STREAM(s); + return true; + } + + return false; } void S9xMSU1Generate(size_t sample_count)