mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-25 23:29:55 -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)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool LoadROMCommon(u32 filelength, const char *sram, bool direct)
|
||||||
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;
|
|
||||||
|
|
||||||
u32 gamecode;
|
u32 gamecode;
|
||||||
fseek(f, 0x0C, SEEK_SET);
|
memcpy(&gamecode, CartROM + 0x0C, 4);
|
||||||
fread(&gamecode, 4, 1, f);
|
|
||||||
printf("Game code: %c%c%c%c\n", gamecode&0xFF, (gamecode>>8)&0xFF, (gamecode>>16)&0xFF, gamecode>>24);
|
printf("Game code: %c%c%c%c\n", gamecode&0xFF, (gamecode>>8)&0xFF, (gamecode>>16)&0xFF, gamecode>>24);
|
||||||
|
|
||||||
u8 unitcode;
|
u8 unitcode = CartROM[0x12];
|
||||||
fseek(f, 0x12, SEEK_SET);
|
|
||||||
fread(&unitcode, 1, 1, f);
|
|
||||||
CartIsDSi = (unitcode & 0x02) != 0;
|
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;
|
ROMListEntry romparams;
|
||||||
if (!ReadROMParams(gamecode, &romparams))
|
if (!ReadROMParams(gamecode, &romparams))
|
||||||
{
|
{
|
||||||
@ -941,7 +910,7 @@ bool LoadROM(const char* path, const char* sram, bool direct)
|
|||||||
else
|
else
|
||||||
printf("ROM entry: %08X %08X\n", romparams.ROMSize, romparams.SaveMemType);
|
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
|
// generate a ROM ID
|
||||||
// note: most games don't check the actual value
|
// 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;
|
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)
|
void RelocateSave(const char* path, bool write)
|
||||||
{
|
{
|
||||||
// herp derp
|
// herp derp
|
||||||
|
Reference in New Issue
Block a user