Skip to content

Commit 072c9a9

Browse files
committed
[libretro] Detect SG-1000 roms based on file extension. Fix #103
1 parent 22e0493 commit 072c9a9

File tree

5 files changed

+41
-30
lines changed

5 files changed

+41
-30
lines changed

platforms/libretro/libretro.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ bool retro_load_game(const struct retro_game_info *info)
556556

557557
log_cb(RETRO_LOG_INFO, "Loading game: %s\n", retro_game_path);
558558

559-
if (!core->LoadROMFromBuffer(reinterpret_cast<const u8*>(info->data), info->size, &config))
559+
if (!core->LoadROMFromBuffer(reinterpret_cast<const u8*>(info->data), info->size, &config, retro_game_path))
560560
{
561561
log_cb(RETRO_LOG_ERROR, "Invalid or corrupted ROM.\n");
562562
return false;

src/Cartridge.cpp

+35-25
Original file line numberDiff line numberDiff line change
@@ -307,30 +307,7 @@ bool Cartridge::LoadFromFile(const char* path)
307307

308308
Reset();
309309

310-
strcpy(m_szFilePath, path);
311-
312-
std::string pathstr(path);
313-
std::string filename;
314-
315-
size_t pos = pathstr.find_last_of("\\");
316-
if (pos != std::string::npos)
317-
{
318-
filename.assign(pathstr.begin() + pos + 1, pathstr.end());
319-
}
320-
else
321-
{
322-
pos = pathstr.find_last_of("/");
323-
if (pos != std::string::npos)
324-
{
325-
filename.assign(pathstr.begin() + pos + 1, pathstr.end());
326-
}
327-
else
328-
{
329-
filename = pathstr;
330-
}
331-
}
332-
333-
strcpy(m_szFileName, filename.c_str());
310+
SetROMPath(path);
334311

335312
ifstream file(path, ios::in | ios::binary | ios::ate);
336313

@@ -383,10 +360,12 @@ bool Cartridge::LoadFromFile(const char* path)
383360
return m_bReady;
384361
}
385362

386-
bool Cartridge::LoadFromBuffer(const u8* buffer, int size)
363+
bool Cartridge::LoadFromBuffer(const u8* buffer, int size, const char* path)
387364
{
388365
if (IsValidPointer(buffer))
389366
{
367+
SetROMPath(path);
368+
390369
Log("Loading from buffer... Size: %d", size);
391370
// Some ROMs have 512 Byte File Headers
392371
if ((size % 1024) == 512)
@@ -432,6 +411,37 @@ bool Cartridge::TestValidROM(u16 location)
432411
return (strcmp(tmrsega, "TMR SEGA") == 0);
433412
}
434413

414+
void Cartridge::SetROMPath(const char* path)
415+
{
416+
if (!IsValidPointer(path))
417+
return;
418+
419+
strcpy(m_szFilePath, path);
420+
421+
std::string pathstr(path);
422+
std::string filename;
423+
424+
size_t pos = pathstr.find_last_of("\\");
425+
if (pos != std::string::npos)
426+
{
427+
filename.assign(pathstr.begin() + pos + 1, pathstr.end());
428+
}
429+
else
430+
{
431+
pos = pathstr.find_last_of("/");
432+
if (pos != std::string::npos)
433+
{
434+
filename.assign(pathstr.begin() + pos + 1, pathstr.end());
435+
}
436+
else
437+
{
438+
filename = pathstr;
439+
}
440+
}
441+
442+
strcpy(m_szFileName, filename.c_str());
443+
}
444+
435445
bool Cartridge::GatherMetadata(u32 crc)
436446
{
437447
m_bPAL = false;

src/Cartridge.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class Cartridge
9292
const char* GetFileName() const;
9393
u8* GetROM() const;
9494
bool LoadFromFile(const char* path);
95-
bool LoadFromBuffer(const u8* buffer, int size);
95+
bool LoadFromBuffer(const u8* buffer, int size, const char* path = NULL);
9696
void SetGameGenieCheat(const char* szCheat);
9797
void ClearGameGenieCheats();
9898

@@ -101,6 +101,7 @@ class Cartridge
101101
void GetInfoFromDB(u32 crc);
102102
bool LoadFromZipFile(const u8* buffer, int size);
103103
bool TestValidROM(u16 location);
104+
void SetROMPath(const char* path);
104105

105106
private:
106107
u8* m_pROM;

src/GearsystemCore.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ bool GearsystemCore::LoadROM(const char* szFilePath, Cartridge::ForceConfigurati
169169
return false;
170170
}
171171

172-
bool GearsystemCore::LoadROMFromBuffer(const u8* buffer, int size, Cartridge::ForceConfiguration* config)
172+
bool GearsystemCore::LoadROMFromBuffer(const u8* buffer, int size, Cartridge::ForceConfiguration* config, const char* szFilePath)
173173
{
174-
if (m_pCartridge->LoadFromBuffer(buffer, size))
174+
if (m_pCartridge->LoadFromBuffer(buffer, size, szFilePath))
175175
{
176176
if (IsValidPointer(config))
177177
m_pCartridge->ForceConfig(*config);

src/GearsystemCore.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class GearsystemCore
5656
void Init(GS_Color_Format pixelFormat = GS_PIXEL_RGB888);
5757
bool RunToVBlank(u8* pFrameBuffer, s16* pSampleBuffer, int* pSampleCount, bool step = false, bool stopOnBreakpoints = false);
5858
bool LoadROM(const char* szFilePath, Cartridge::ForceConfiguration* config = NULL);
59-
bool LoadROMFromBuffer(const u8* buffer, int size, Cartridge::ForceConfiguration* config = NULL);
59+
bool LoadROMFromBuffer(const u8* buffer, int size, Cartridge::ForceConfiguration* config = NULL, const char* szFilePath = NULL);
6060
void SaveMemoryDump();
6161
void SaveDisassembledROM();
6262
bool GetRuntimeInfo(GS_RuntimeInfo& runtime_info);

0 commit comments

Comments
 (0)