mirror of https://github.com/snes9xgit/snes9x.git
Merge branch 'msu1-zip'
This commit is contained in:
commit
158b509bbb
20
apu/apu.cpp
20
apu/apu.cpp
|
@ -245,6 +245,8 @@ namespace msu
|
|||
static int buffer_size;
|
||||
static uint8 *landing_buffer = NULL;
|
||||
static Resampler *resampler = NULL;
|
||||
static int resample_buffer_size = -1;
|
||||
static uint8 *resample_buffer = NULL;
|
||||
}
|
||||
|
||||
static void EightBitize (uint8 *, int);
|
||||
|
@ -314,6 +316,13 @@ bool8 S9xMixSamples (uint8 *buffer, int sample_count)
|
|||
else
|
||||
dest = buffer;
|
||||
|
||||
if (Settings.MSU1 && msu::resample_buffer_size < (sample_count << 1))
|
||||
{
|
||||
delete[] msu::resample_buffer;
|
||||
msu::resample_buffer = new uint8[sample_count << 1];
|
||||
msu::resample_buffer_size = sample_count << 1;
|
||||
}
|
||||
|
||||
if (Settings.Mute)
|
||||
{
|
||||
memset(dest, 0, sample_count << 1);
|
||||
|
@ -336,10 +345,9 @@ bool8 S9xMixSamples (uint8 *buffer, int sample_count)
|
|||
{
|
||||
if (msu::resampler->avail() >= sample_count)
|
||||
{
|
||||
uint8 *msu_sample = new uint8[sample_count * 2];
|
||||
msu::resampler->read((short *)msu_sample, sample_count);
|
||||
msu::resampler->read((short *)msu::resample_buffer, sample_count);
|
||||
for (uint32 i = 0; i < sample_count; ++i)
|
||||
*((int16*)(dest+(i * 2))) += *((int16*)(msu_sample+(i * 2)));
|
||||
*((int16*)(dest+(i * 2))) += *((int16*)(msu::resample_buffer +(i * 2)));
|
||||
}
|
||||
else // should never occur
|
||||
assert(0);
|
||||
|
@ -614,6 +622,12 @@ void S9xDeinitAPU (void)
|
|||
delete[] msu::landing_buffer;
|
||||
msu::landing_buffer = NULL;
|
||||
}
|
||||
|
||||
if (msu::resample_buffer)
|
||||
{
|
||||
delete[] msu::resample_buffer;
|
||||
msu::resample_buffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static inline int S9xAPUGetClock (int32 cpucycles)
|
||||
|
|
13
loadzip.cpp
13
loadzip.cpp
|
@ -209,7 +209,7 @@ bool8 LoadZip (const char *zipname, uint32 *TotalFileSize, uint8 *buffer)
|
|||
if (file == NULL)
|
||||
return (FALSE);
|
||||
|
||||
// find largest file in zip file (under MAX_ROM_SIZE) or a file with extension .1
|
||||
// find largest file in zip file (under MAX_ROM_SIZE) or a file with extension .1, or a file named program.rom
|
||||
char filename[132];
|
||||
uint32 filesize = 0;
|
||||
int port = unzGoToFirstFile(file);
|
||||
|
@ -241,10 +241,19 @@ bool8 LoadZip (const char *zipname, uint32 *TotalFileSize, uint8 *buffer)
|
|||
break;
|
||||
}
|
||||
|
||||
if (strncasecmp(name, "program.rom", 11) == 0)
|
||||
{
|
||||
strcpy(filename, name);
|
||||
filesize = info.uncompressed_size;
|
||||
break;
|
||||
}
|
||||
|
||||
port = unzGoToNextFile(file);
|
||||
}
|
||||
|
||||
if (!(port == UNZ_END_OF_LIST_OF_FILE || port == UNZ_OK) || filesize == 0)
|
||||
int len = strlen(zipname);
|
||||
if (!(port == UNZ_END_OF_LIST_OF_FILE || port == UNZ_OK) || filesize == 0 ||
|
||||
(len > 5 && strcasecmp(zipname + len - 5, ".msu1") == 0 && strcasecmp(filename, "program.rom") != 0))
|
||||
{
|
||||
assert(unzClose(file) == UNZ_OK);
|
||||
return (FALSE);
|
||||
|
|
44
memmap.cpp
44
memmap.cpp
|
@ -967,7 +967,7 @@ static bool8 ReadUPSPatch (Stream *, long, int32 &);
|
|||
static long ReadInt (Stream *, unsigned);
|
||||
static bool8 ReadIPSPatch (Stream *, long, int32 &);
|
||||
#ifdef UNZIP_SUPPORT
|
||||
static int unzFindExtension (unzFile &, const char *, bool restart = TRUE, bool print = TRUE);
|
||||
static int unzFindExtension (unzFile &, const char *, bool restart = TRUE, bool print = TRUE, bool allowExact = FALSE);
|
||||
#endif
|
||||
|
||||
// deinterleave
|
||||
|
@ -1439,7 +1439,7 @@ uint32 CMemory::FileLoader (uint8 *buffer, const char *filename, uint32 maxsize)
|
|||
_makepath(fname, drive, dir, name, exts);
|
||||
|
||||
int nFormat = FILE_DEFAULT;
|
||||
if (strcasecmp(ext, "zip") == 0)
|
||||
if (strcasecmp(ext, "zip") == 0 || strcasecmp(ext, "msu1") == 0)
|
||||
nFormat = FILE_ZIP;
|
||||
else
|
||||
if (strcasecmp(ext, "jma") == 0)
|
||||
|
@ -4188,10 +4188,10 @@ static bool8 ReadIPSPatch (Stream *r, long offset, int32 &rom_size)
|
|||
}
|
||||
|
||||
#ifdef UNZIP_SUPPORT
|
||||
static int unzFindExtension (unzFile &file, const char *ext, bool restart, bool print)
|
||||
static int unzFindExtension (unzFile &file, const char *ext, bool restart, bool print, bool allowExact)
|
||||
{
|
||||
unz_file_info info;
|
||||
int port, l = strlen(ext);
|
||||
int port, l = strlen(ext), e = allowExact ? 0 : 1;
|
||||
|
||||
if (restart)
|
||||
port = unzGoToFirstFile(file);
|
||||
|
@ -4206,7 +4206,7 @@ static int unzFindExtension (unzFile &file, const char *ext, bool restart, bool
|
|||
unzGetCurrentFileInfo(file, &info, name, 128, NULL, 0, NULL, 0);
|
||||
len = strlen(name);
|
||||
|
||||
if (len >= l + 1 && name[len - l - 1] == '.' && strcasecmp(name + len - l, ext) == 0 && unzOpenCurrentFile(file) == UNZ_OK)
|
||||
if (len >= l + e && name[len - l - 1] == '.' && strcasecmp(name + len - l, ext) == 0 && unzOpenCurrentFile(file) == UNZ_OK)
|
||||
{
|
||||
if (print)
|
||||
printf("Using patch %s", name);
|
||||
|
@ -4751,4 +4751,38 @@ void CMemory::CheckForAnyPatch (const char *rom_filename, bool8 header, int32 &r
|
|||
if (flag)
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef UNZIP_SUPPORT
|
||||
// Mercurial Magic (MSU-1 distribution pack)
|
||||
if (strcasecmp(ext, "msu1") && strcasecmp(ext, ".msu1"))
|
||||
{
|
||||
_makepath(fname, drive, dir, name, "msu1");
|
||||
unzFile msu1file = unzOpen(fname);
|
||||
|
||||
if (!msu1file)
|
||||
{
|
||||
_snprintf(fname, sizeof(fname), "%s" SLASH_STR "%s%s",
|
||||
S9xGetDirectory(IPS_DIR), name, ".msu1");
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
69
msu1.cpp
69
msu1.cpp
|
@ -191,6 +191,7 @@
|
|||
***********************************************************************************/
|
||||
|
||||
#include "snes9x.h"
|
||||
#include "memmap.h"
|
||||
#include "display.h"
|
||||
#include "msu1.h"
|
||||
#include "apu/bapu/dsp/blargg_endian.h"
|
||||
|
@ -206,10 +207,10 @@ size_t partial_samples;
|
|||
int16 *bufPos, *bufBegin, *bufEnd;
|
||||
|
||||
#ifdef UNZIP_SUPPORT
|
||||
static int unzFindExtension(unzFile &file, const char *ext, bool restart = TRUE, bool print = TRUE)
|
||||
static int unzFindExtension(unzFile &file, const char *ext, bool restart = TRUE, bool print = TRUE, bool allowExact = FALSE)
|
||||
{
|
||||
unz_file_info info;
|
||||
int port, l = strlen(ext);
|
||||
int port, l = strlen(ext), e = allowExact ? 0 : 1;
|
||||
|
||||
if (restart)
|
||||
port = unzGoToFirstFile(file);
|
||||
|
@ -224,7 +225,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 + e && strcasecmp(name + len - l, ext) == 0 && unzOpenCurrentFile(file) == UNZ_OK)
|
||||
{
|
||||
if (print)
|
||||
printf("Using msu file %s", name);
|
||||
|
@ -247,24 +248,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 msu1 pack file in the rom or patch dir if msu data file not found in rom dir
|
||||
if (!file)
|
||||
{
|
||||
const char *zip_filename = S9xGetFilename(".msu.zip", ROMFILENAME_DIR);
|
||||
if (zip_filename)
|
||||
const char *zip_filename = S9xGetFilename(".msu1", ROMFILENAME_DIR);
|
||||
unzFile unzFile = unzOpen(zip_filename);
|
||||
|
||||
if (!unzFile)
|
||||
{
|
||||
zip_filename = S9xGetFilename(".msu1", IPS_DIR);
|
||||
unzFile = unzOpen(zip_filename);
|
||||
}
|
||||
|
||||
if (unzFile)
|
||||
{
|
||||
unzFile unzFile = unzOpen(zip_filename);
|
||||
if (unzFile)
|
||||
int port = unzFindExtension(unzFile, msu_ext, true, true, true);
|
||||
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 +326,10 @@ bool DataOpen()
|
|||
}
|
||||
|
||||
dataStream = S9xMSU1OpenFile(".msu");
|
||||
|
||||
if(!dataStream)
|
||||
dataStream = S9xMSU1OpenFile("msu1.rom");
|
||||
|
||||
return dataStream != NULL;
|
||||
}
|
||||
|
||||
|
@ -366,12 +375,30 @@ void S9xMSU1Init(void)
|
|||
|
||||
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;
|
||||
}
|
||||
#ifdef UNZIP_SUPPORT
|
||||
char ext[_MAX_EXT + 1];
|
||||
_splitpath(Memory.ROMFilename, nullptr, nullptr, nullptr, ext);
|
||||
if (!strcasecmp(ext, ".msu1"))
|
||||
return true;
|
||||
|
||||
unzFile unzFile = unzOpen(S9xGetFilename(".msu1", ROMFILENAME_DIR));
|
||||
|
||||
if(!unzFile)
|
||||
unzFile = unzOpen(S9xGetFilename(".msu1", IPS_DIR));
|
||||
|
||||
if (unzFile)
|
||||
{
|
||||
unzCloseCurrentFile(unzFile);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
void S9xMSU1Generate(size_t sample_count)
|
||||
|
|
|
@ -7063,10 +7063,17 @@ void MakeExtFile(void)
|
|||
ofstream out;
|
||||
out.open("Valid.Ext");
|
||||
|
||||
out<<"smcN"<<endl<<"zipY"<<endl<<"gzY" <<endl<<"swcN"<<endl<<"figN"<<endl;
|
||||
out<<"smcN"<<endl;
|
||||
#ifdef UNZIP_SUPPORT
|
||||
out<<"zipY"<<endl;
|
||||
out<<"msu1Y"<<endl;
|
||||
#endif
|
||||
out<<"gzY"<<endl;
|
||||
out<<"swcN"<<endl;
|
||||
out<<"figN"<<endl;
|
||||
out<<"sfcN"<<endl;
|
||||
out<<"bsN"<<endl;
|
||||
out<<"jmaY";
|
||||
out<<"jmaY"<<endl;
|
||||
out.close();
|
||||
SetFileAttributes(TEXT("Valid.Ext"), FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue