mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-23 06:10:03 -06:00
fail gracefully when ROM loading fails
This commit is contained in:
10
src/NDS.cpp
10
src/NDS.cpp
@ -352,14 +352,18 @@ void Stop()
|
|||||||
SPU::Stop();
|
SPU::Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadROM(const char* path, bool direct)
|
bool LoadROM(const char* path, bool direct)
|
||||||
{
|
{
|
||||||
Reset();
|
|
||||||
|
|
||||||
if (NDSCart::LoadROM(path, direct))
|
if (NDSCart::LoadROM(path, direct))
|
||||||
|
{
|
||||||
Running = true;
|
Running = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
printf("Failed to load ROM %s\n", path);
|
printf("Failed to load ROM %s\n", path);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadBIOS()
|
void LoadBIOS()
|
||||||
|
@ -106,7 +106,7 @@ void DeInit();
|
|||||||
void Reset();
|
void Reset();
|
||||||
void Stop();
|
void Stop();
|
||||||
|
|
||||||
void LoadROM(const char* path, bool direct);
|
bool LoadROM(const char* path, bool direct);
|
||||||
void LoadBIOS();
|
void LoadBIOS();
|
||||||
void SetupDirectBoot();
|
void SetupDirectBoot();
|
||||||
|
|
||||||
|
@ -817,15 +817,14 @@ bool LoadROM(const char* path, bool direct)
|
|||||||
// TODO: streaming mode? for really big ROMs or systems with limited RAM
|
// TODO: streaming mode? for really big ROMs or systems with limited RAM
|
||||||
// for now we're lazy
|
// for now we're lazy
|
||||||
|
|
||||||
if (CartROM) delete[] CartROM;
|
|
||||||
|
|
||||||
FILE* f = fopen(path, "rb");
|
FILE* f = fopen(path, "rb");
|
||||||
if (!f)
|
if (!f)
|
||||||
{
|
{
|
||||||
printf("Failed to open ROM file %s\n", path);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NDS::Reset();
|
||||||
|
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
u32 len = (u32)ftell(f);
|
u32 len = (u32)ftell(f);
|
||||||
|
|
||||||
@ -845,6 +844,11 @@ bool LoadROM(const char* path, bool direct)
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
//CartROM = f;
|
//CartROM = f;
|
||||||
|
|
||||||
|
// generate a ROM ID
|
||||||
|
// note: most games don't check the actual value
|
||||||
|
// it just has to stay the same throughout gameplay
|
||||||
|
CartID = 0x00001FC2;
|
||||||
|
|
||||||
if (direct)
|
if (direct)
|
||||||
{
|
{
|
||||||
NDS::SetupDirectBoot();
|
NDS::SetupDirectBoot();
|
||||||
@ -853,11 +857,6 @@ bool LoadROM(const char* path, bool direct)
|
|||||||
|
|
||||||
CartInserted = true;
|
CartInserted = true;
|
||||||
|
|
||||||
// generate a ROM ID
|
|
||||||
// note: most games don't check the actual value
|
|
||||||
// it just has to stay the same throughout gameplay
|
|
||||||
CartID = 0x00001FC2;
|
|
||||||
|
|
||||||
u32 arm9base = *(u32*)&CartROM[0x20];
|
u32 arm9base = *(u32*)&CartROM[0x20];
|
||||||
if (arm9base < 0x8000)
|
if (arm9base < 0x8000)
|
||||||
{
|
{
|
||||||
|
@ -400,6 +400,27 @@ void Stop(bool internal)
|
|||||||
uiAreaQueueRedrawAll(MainDrawArea);
|
uiAreaQueueRedrawAll(MainDrawArea);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TryLoadROM(char* file, int prevstatus)
|
||||||
|
{
|
||||||
|
char oldpath[1024];
|
||||||
|
strncpy(oldpath, ROMPath, 1024);
|
||||||
|
|
||||||
|
strncpy(ROMPath, file, 1023);
|
||||||
|
ROMPath[1023] = '\0';
|
||||||
|
|
||||||
|
if (NDS::LoadROM(ROMPath, Config::DirectBoot))
|
||||||
|
Run();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uiMsgBoxError(MainWindow,
|
||||||
|
"Failed to load the ROM",
|
||||||
|
"Make sure the file can be accessed and isn't opened in another application.");
|
||||||
|
|
||||||
|
strncpy(ROMPath, oldpath, 1024);
|
||||||
|
EmuRunning = prevstatus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int OnCloseWindow(uiWindow* window, void* blarg)
|
int OnCloseWindow(uiWindow* window, void* blarg)
|
||||||
{
|
{
|
||||||
@ -410,6 +431,7 @@ int OnCloseWindow(uiWindow* window, void* blarg)
|
|||||||
void OnDropFile(uiWindow* window, char* file, void* blarg)
|
void OnDropFile(uiWindow* window, char* file, void* blarg)
|
||||||
{
|
{
|
||||||
char* ext = &file[strlen(file)-3];
|
char* ext = &file[strlen(file)-3];
|
||||||
|
int prevstatus = EmuRunning;
|
||||||
|
|
||||||
if (!strcasecmp(ext, "nds") || !strcasecmp(ext, "srl"))
|
if (!strcasecmp(ext, "nds") || !strcasecmp(ext, "srl"))
|
||||||
{
|
{
|
||||||
@ -419,11 +441,7 @@ void OnDropFile(uiWindow* window, char* file, void* blarg)
|
|||||||
while (EmuStatus != 2);
|
while (EmuStatus != 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(ROMPath, file, 1023);
|
TryLoadROM(file, prevstatus);
|
||||||
ROMPath[1023] = '\0';
|
|
||||||
|
|
||||||
NDS::LoadROM(ROMPath, Config::DirectBoot);
|
|
||||||
Run();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -456,14 +474,8 @@ void OnOpenFile(uiMenuItem* item, uiWindow* window, void* blarg)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(ROMPath, file, 1023);
|
TryLoadROM(file, prevstatus);
|
||||||
ROMPath[1023] = '\0';
|
|
||||||
uiFreeText(file);
|
uiFreeText(file);
|
||||||
// TODO: change libui to store strings in stack-allocated buffers?
|
|
||||||
// so we don't have to free it after use
|
|
||||||
|
|
||||||
NDS::LoadROM(ROMPath, Config::DirectBoot);
|
|
||||||
Run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnRun(uiMenuItem* item, uiWindow* window, void* blarg)
|
void OnRun(uiMenuItem* item, uiWindow* window, void* blarg)
|
||||||
@ -685,8 +697,8 @@ int main(int argc, char** argv)
|
|||||||
strncpy(ROMPath, file, 1023);
|
strncpy(ROMPath, file, 1023);
|
||||||
ROMPath[1023] = '\0';
|
ROMPath[1023] = '\0';
|
||||||
|
|
||||||
NDS::LoadROM(ROMPath, Config::DirectBoot);
|
if (NDS::LoadROM(ROMPath, Config::DirectBoot))
|
||||||
Run();
|
Run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user