From 7455501db8f6966b5d9e97d4c6ef783286f954e5 Mon Sep 17 00:00:00 2001 From: qwertymodo Date: Sat, 9 Sep 2017 17:02:52 -0700 Subject: [PATCH] Minor refactor to .msu1 pack hotpatching --- memmap.cpp | 35 ++++++++++------------------------- msu1.cpp | 13 +++++++++---- msu1.h | 2 +- 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/memmap.cpp b/memmap.cpp index c9927c43..60d38986 100644 --- a/memmap.cpp +++ b/memmap.cpp @@ -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 diff --git a/msu1.cpp b/msu1.cpp index 9e8c8901..bf0a96a1 100644 --- a/msu1.cpp +++ b/msu1.cpp @@ -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 diff --git a/msu1.h b/msu1.h index a9cf8d68..e51739b0 100644 --- a/msu1.h +++ b/msu1.h @@ -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);