naomi: close cart and free resources properly

This commit is contained in:
Flyinghead 2019-03-13 19:59:59 +01:00
parent f4568ace3c
commit 7369e81af5
3 changed files with 29 additions and 51 deletions

View File

@ -359,11 +359,7 @@ bool naomi_cart_LoadRom(char* file)
{ {
printf("\nnullDC-Naomi rom loader v1.2\n"); printf("\nnullDC-Naomi rom loader v1.2\n");
if (CurrentCartridge != NULL) naomi_cart_Close();
{
delete CurrentCartridge;
CurrentCartridge = NULL;
}
size_t folder_pos = strlen(file) - 1; size_t folder_pos = strlen(file) - 1;
while (folder_pos>1 && (file[folder_pos] != '\\' && file[folder_pos] != '/')) while (folder_pos>1 && (file[folder_pos] != '\\' && file[folder_pos] != '/'))
@ -613,28 +609,30 @@ bool naomi_cart_LoadRom(char* file)
return true; return true;
} }
bool naomi_cart_SelectFile(void* handle) void naomi_cart_Close()
{
if (CurrentCartridge != NULL)
{
delete CurrentCartridge;
CurrentCartridge = NULL;
}
if (RomCacheMap != NULL)
{
for (int i = 0; i < RomCacheMapCount; i++)
if (RomCacheMap[i] != INVALID_FD)
CloseFile(RomCacheMap[i]);
RomCacheMapCount = 0;
delete[] RomCacheMap;
RomCacheMap = NULL;
}
}
bool naomi_cart_SelectFile()
{ {
char SelectedFile[512]; char SelectedFile[512];
cfgLoadStr("config", "image", SelectedFile, "null"); cfgLoadStr("config", "image", SelectedFile, "null");
#if HOST_OS == OS_WINDOWS
if (strcmp(SelectedFile, "null") == 0) {
OPENFILENAME ofn = { 0 };
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hInstance = (HINSTANCE)GetModuleHandle(0);
ofn.lpstrFile = SelectedFile;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = "*.lst\0*.lst\0*.bin\0*.bin\0*.dat\0*.dat\0\0";
ofn.nFilterIndex = 0;
ofn.hwndOwner = (HWND)handle;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
if (GetOpenFileName(&ofn) <= 0)
return true;
}
#endif
if (!naomi_cart_LoadRom(SelectedFile)) if (!naomi_cart_LoadRom(SelectedFile))
{ {
printf("Cannot load %s: error %d\n", SelectedFile, errno); printf("Cannot load %s: error %d\n", SelectedFile, errno);

View File

@ -78,7 +78,8 @@ private:
u8 naomi_cart_ram[64 * 1024]; u8 naomi_cart_ram[64 * 1024];
}; };
bool naomi_cart_SelectFile(void* handle); bool naomi_cart_SelectFile();
void naomi_cart_Close();
extern char naomi_game_id[]; extern char naomi_game_id[];
extern u8 *naomi_default_eeprom; extern u8 *naomi_default_eeprom;

View File

@ -80,33 +80,9 @@ int64_t get_time_usec(void)
int GetFile(char *szFileName, char *szParse /* = 0 */, u32 flags /* = 0 */) int GetFile(char *szFileName, char *szParse /* = 0 */, u32 flags /* = 0 */)
{ {
cfgLoadStr("config","image",szFileName,"null"); cfgLoadStr("config", "image", szFileName, "");
if (strcmp(szFileName,"null")==0)
{
#if HOST_OS==OS_WINDOWS
OPENFILENAME ofn;
ZeroMemory( &ofn , sizeof( ofn));
ofn.lStructSize = sizeof ( ofn );
ofn.hwndOwner = NULL ;
ofn.lpstrFile = szFileName ;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = "All\0*.*\0\0";
ofn.nFilterIndex =1;
ofn.lpstrFileTitle = NULL ;
ofn.nMaxFileTitle = 0 ;
ofn.lpstrInitialDir=NULL ;
ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST ;
if (GetOpenFileNameA(&ofn)) return szFileName[0] != '\0' ? 1 : 0;
{
//already there
//strcpy(szFileName,ofn.lpstrFile);
}
#endif
}
return 1;
} }
@ -121,7 +97,7 @@ s32 plugins_Init()
return rv; return rv;
#endif #endif
#if DC_PLATFORM == DC_PLATFORM_NAOMI || DC_PLATFORM == DC_PLATFORM_ATOMISWAVE #if DC_PLATFORM == DC_PLATFORM_NAOMI || DC_PLATFORM == DC_PLATFORM_ATOMISWAVE
if (!naomi_cart_SelectFile(libPvr_GetRenderTarget())) if (!naomi_cart_SelectFile())
return rv_serror; return rv_serror;
#endif #endif
@ -333,7 +309,7 @@ int dc_start_game(const char *path)
LoadCustom(); LoadCustom();
#elif DC_PLATFORM == DC_PLATFORM_NAOMI || DC_PLATFORM == DC_PLATFORM_ATOMISWAVE #elif DC_PLATFORM == DC_PLATFORM_NAOMI || DC_PLATFORM == DC_PLATFORM_ATOMISWAVE
LoadRomFiles(get_readonly_data_path(DATA_PATH)); LoadRomFiles(get_readonly_data_path(DATA_PATH));
if (!naomi_cart_SelectFile(libPvr_GetRenderTarget())) if (!naomi_cart_SelectFile())
return -6; return -6;
LoadCustom(); LoadCustom();
#if DC_PLATFORM == DC_PLATFORM_NAOMI #if DC_PLATFORM == DC_PLATFORM_NAOMI
@ -443,6 +419,9 @@ void* dc_run(void*)
void dc_term() void dc_term()
{ {
sh4_cpu.Term(); sh4_cpu.Term();
#if DC_PLATFORM != DC_PLATFORM_DREAMCAST
naomi_cart_Close();
#endif
plugins_Term(); plugins_Term();
_vmem_release(); _vmem_release();