aboutsummaryrefslogtreecommitdiff
path: root/src/NDSCart.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/NDSCart.cpp')
-rw-r--r--src/NDSCart.cpp86
1 files changed, 51 insertions, 35 deletions
diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp
index 0765288..ae051bd 100644
--- a/src/NDSCart.cpp
+++ b/src/NDSCart.cpp
@@ -885,46 +885,15 @@ void DecryptSecureArea(u8* out)
}
}
-
-bool LoadROM(const char* path, const char* sram, bool direct)
+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,53 @@ 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);
+}
+
+bool LoadROM(const u8* romdata, u32 filelength, const char *sram, bool direct)
+{
+ NDS::Reset();
+
+ u32 len = filelength;
+ CartROMSize = 0x200;
+ while (CartROMSize < len)
+ CartROMSize <<= 1;
+
+ CartROM = new u8[CartROMSize];
+ memset(CartROM, 0, CartROMSize);
+ memcpy(CartROM, romdata, filelength);
+
+ return LoadROMCommon(filelength, sram, direct);
+}
+
void RelocateSave(const char* path, bool write)
{
// herp derp