mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-25 07:10:00 -06:00
NDSCart : Abstract out common code in LoadROM()
Signed-off-by: Madhav Kanbur <abcdjdj@gmail.com>
This commit is contained in:
@ -885,46 +885,15 @@ void DecryptSecureArea(u8* out)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool LoadROM(const char* path, const char* sram, bool direct)
|
||||
static bool LoadROMCommon(u32 filelength, const char *sram, bool direct)
|
||||
{
|
||||
// TODO: streaming mode? for really big ROMs or systems with limited RAM
|
||||
// for now we're lazy
|
||||
// also TODO: validate what we're loading!!
|
||||
|
||||
FILE* f = Platform::OpenFile(path, "rb");
|
||||
if (!f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
NDS::Reset();
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
u32 len = (u32)ftell(f);
|
||||
|
||||
CartROMSize = 0x200;
|
||||
while (CartROMSize < len)
|
||||
CartROMSize <<= 1;
|
||||
|
||||
u32 gamecode;
|
||||
fseek(f, 0x0C, SEEK_SET);
|
||||
fread(&gamecode, 4, 1, f);
|
||||
memcpy(&gamecode, CartROM + 0x0C, 4);
|
||||
printf("Game code: %c%c%c%c\n", gamecode&0xFF, (gamecode>>8)&0xFF, (gamecode>>16)&0xFF, gamecode>>24);
|
||||
|
||||
u8 unitcode;
|
||||
fseek(f, 0x12, SEEK_SET);
|
||||
fread(&unitcode, 1, 1, f);
|
||||
u8 unitcode = CartROM[0x12];
|
||||
CartIsDSi = (unitcode & 0x02) != 0;
|
||||
|
||||
CartROM = new u8[CartROMSize];
|
||||
memset(CartROM, 0, CartROMSize);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
fread(CartROM, 1, len, f);
|
||||
|
||||
fclose(f);
|
||||
//CartROM = f;
|
||||
|
||||
ROMListEntry romparams;
|
||||
if (!ReadROMParams(gamecode, &romparams))
|
||||
{
|
||||
@ -941,7 +910,7 @@ bool LoadROM(const char* path, const char* sram, bool direct)
|
||||
else
|
||||
printf("ROM entry: %08X %08X\n", romparams.ROMSize, romparams.SaveMemType);
|
||||
|
||||
if (romparams.ROMSize != len) printf("!! bad ROM size %d (expected %d) rounded to %d\n", len, romparams.ROMSize, CartROMSize);
|
||||
if (romparams.ROMSize != filelength) printf("!! bad ROM size %d (expected %d) rounded to %d\n", filelength, romparams.ROMSize, CartROMSize);
|
||||
|
||||
// generate a ROM ID
|
||||
// note: most games don't check the actual value
|
||||
@ -1026,6 +995,37 @@ bool LoadROM(const char* path, const char* sram, bool direct)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LoadROM(const char* path, const char* sram, bool direct)
|
||||
{
|
||||
// TODO: streaming mode? for really big ROMs or systems with limited RAM
|
||||
// for now we're lazy
|
||||
// also TODO: validate what we're loading!!
|
||||
|
||||
FILE* f = Platform::OpenFile(path, "rb");
|
||||
if (!f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
NDS::Reset();
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
u32 len = (u32)ftell(f);
|
||||
|
||||
CartROMSize = 0x200;
|
||||
while (CartROMSize < len)
|
||||
CartROMSize <<= 1;
|
||||
|
||||
CartROM = new u8[CartROMSize];
|
||||
memset(CartROM, 0, CartROMSize);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
fread(CartROM, 1, len, f);
|
||||
|
||||
fclose(f);
|
||||
|
||||
return LoadROMCommon(len, sram, direct);
|
||||
}
|
||||
|
||||
void RelocateSave(const char* path, bool write)
|
||||
{
|
||||
// herp derp
|
||||
|
Reference in New Issue
Block a user