Release msu data and audio streams on exit, use unzClose when closing file

This commit is contained in:
OV2 2017-10-14 00:08:39 +02:00
parent e014129b12
commit a66b88b276
4 changed files with 36 additions and 25 deletions

View File

@ -624,6 +624,8 @@ void S9xDeinitAPU (void)
delete[] msu::resample_buffer; delete[] msu::resample_buffer;
msu::resample_buffer = NULL; msu::resample_buffer = NULL;
} }
S9xMSU1DeInit();
} }
static inline int S9xAPUGetClock (int32 cpucycles) static inline int S9xAPUGetClock (int32 cpucycles)

View File

@ -274,7 +274,7 @@ STREAM S9xMSU1OpenFile(const char *msu_ext, bool skip_unpacked)
file = new unzStream(unzFile); file = new unzStream(unzFile);
} }
else else
unzCloseCurrentFile(unzFile); unzClose(unzFile);
} }
} }
#endif #endif
@ -285,15 +285,20 @@ STREAM S9xMSU1OpenFile(const char *msu_ext, bool skip_unpacked)
return file; return file;
} }
bool AudioOpen() static void AudioClose()
{
if (audioStream)
{
CLOSE_STREAM(audioStream);
audioStream = NULL;
}
}
static bool AudioOpen()
{ {
MSU1.MSU1_STATUS |= AudioError; MSU1.MSU1_STATUS |= AudioError;
if (audioStream) AudioClose();
{
CLOSE_STREAM(audioStream);
audioStream = NULL;
}
char ext[_MAX_EXT]; char ext[_MAX_EXT];
snprintf(ext, _MAX_EXT, "-%d.pcm", MSU1.MSU1_CURRENT_TRACK); snprintf(ext, _MAX_EXT, "-%d.pcm", MSU1.MSU1_CURRENT_TRACK);
@ -322,13 +327,18 @@ bool AudioOpen()
return false; return false;
} }
bool DataOpen() static void DataClose()
{ {
if (dataStream) if (dataStream)
{ {
CLOSE_STREAM(dataStream); CLOSE_STREAM(dataStream);
dataStream = NULL; dataStream = NULL;
} }
}
static bool DataOpen()
{
DataClose();
dataStream = S9xMSU1OpenFile(".msu"); dataStream = S9xMSU1OpenFile(".msu");
@ -358,17 +368,9 @@ void S9xResetMSU(void)
partial_samples = 0; partial_samples = 0;
if (dataStream) DataClose();
{
CLOSE_STREAM(dataStream);
dataStream = NULL;
}
if (audioStream) AudioClose();
{
CLOSE_STREAM(audioStream);
audioStream = NULL;
}
Settings.MSU1 = S9xMSU1ROMExists(); Settings.MSU1 = S9xMSU1ROMExists();
} }
@ -378,6 +380,12 @@ void S9xMSU1Init(void)
DataOpen(); DataOpen();
} }
void S9xMSU1DeInit(void)
{
DataClose();
AudioClose();
}
bool S9xMSU1ROMExists(void) bool S9xMSU1ROMExists(void)
{ {
STREAM s = S9xMSU1OpenFile(".msu"); STREAM s = S9xMSU1OpenFile(".msu");
@ -399,7 +407,7 @@ bool S9xMSU1ROMExists(void)
if (unzFile) if (unzFile)
{ {
unzCloseCurrentFile(unzFile); unzClose(unzFile);
return true; return true;
} }
#endif #endif

1
msu1.h
View File

@ -229,6 +229,7 @@ extern struct SMSU1 MSU1;
void S9xResetMSU(void); void S9xResetMSU(void);
void S9xMSU1Init(void); void S9xMSU1Init(void);
void S9xMSU1DeInit(void);
bool S9xMSU1ROMExists(void); bool S9xMSU1ROMExists(void);
STREAM S9xMSU1OpenFile(const char *msu_ext, bool skip_unpacked = FALSE); STREAM S9xMSU1OpenFile(const char *msu_ext, bool skip_unpacked = FALSE);
void S9xMSU1Init(void); void S9xMSU1Init(void);

View File

@ -451,7 +451,7 @@ int unzStream::revert (size_t from, size_t offset)
void unzStream::closeStream() void unzStream::closeStream()
{ {
unzCloseCurrentFile(file); unzClose(file);
delete this; delete this;
} }