mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-24 14:49:53 -06:00
GBACart : Abstract out common code in LoadROM()
Signed-off-by: Madhav Kanbur <abcdjdj@gmail.com>
This commit is contained in:
@ -620,6 +620,32 @@ void DoSavestate(Savestate* file)
|
||||
if (HasSolarSensor) GBACart_SolarSensor::DoSavestate(file);
|
||||
}
|
||||
|
||||
static void LoadROMCommon(const char *sram)
|
||||
{
|
||||
char gamecode[5] = { '\0' };
|
||||
memcpy(&gamecode, CartROM + 0xAC, 4);
|
||||
printf("Game code: %s\n", gamecode);
|
||||
|
||||
for (int i = 0; i < sizeof(SOLAR_SENSOR_GAMECODES)/sizeof(SOLAR_SENSOR_GAMECODES[0]); i++)
|
||||
{
|
||||
if (strcmp(gamecode, SOLAR_SENSOR_GAMECODES[i]) == 0) HasSolarSensor = true;
|
||||
}
|
||||
|
||||
if (HasSolarSensor)
|
||||
{
|
||||
printf("GBA solar sensor support detected!\n");
|
||||
}
|
||||
|
||||
CartCRC = CRC32(CartROM, CartROMSize);
|
||||
printf("ROM CRC32: %08X\n", CartCRC);
|
||||
|
||||
CartInserted = true;
|
||||
|
||||
// save
|
||||
printf("Save file: %s\n", sram);
|
||||
GBACart_SRAM::LoadSave(sram);
|
||||
}
|
||||
|
||||
bool LoadROM(const char* path, const char* sram)
|
||||
{
|
||||
FILE* f = Platform::OpenFile(path, "rb");
|
||||
@ -640,36 +666,13 @@ bool LoadROM(const char* path, const char* sram)
|
||||
while (CartROMSize < len)
|
||||
CartROMSize <<= 1;
|
||||
|
||||
char gamecode[5] = { '\0' };
|
||||
fseek(f, 0xAC, SEEK_SET);
|
||||
fread(&gamecode, 1, 4, f);
|
||||
printf("Game code: %s\n", gamecode);
|
||||
|
||||
for (int i = 0; i < sizeof(SOLAR_SENSOR_GAMECODES)/sizeof(SOLAR_SENSOR_GAMECODES[0]); i++)
|
||||
{
|
||||
if (strcmp(gamecode, SOLAR_SENSOR_GAMECODES[i]) == 0) HasSolarSensor = true;
|
||||
}
|
||||
|
||||
if (HasSolarSensor)
|
||||
{
|
||||
printf("GBA solar sensor support detected!\n");
|
||||
}
|
||||
|
||||
CartROM = new u8[CartROMSize];
|
||||
memset(CartROM, 0, CartROMSize);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
fread(CartROM, 1, len, f);
|
||||
|
||||
fclose(f);
|
||||
|
||||
CartCRC = CRC32(CartROM, CartROMSize);
|
||||
printf("ROM CRC32: %08X\n", CartCRC);
|
||||
|
||||
CartInserted = true;
|
||||
|
||||
// save
|
||||
printf("Save file: %s\n", sram);
|
||||
GBACart_SRAM::LoadSave(sram);
|
||||
LoadROMCommon(sram);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user