aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/NDSCart.cpp66
-rw-r--r--src/NDSCart.h1
-rw-r--r--src/melonDLDI.h2
3 files changed, 34 insertions, 35 deletions
diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp
index fe359a6..497c0f6 100644
--- a/src/NDSCart.cpp
+++ b/src/NDSCart.cpp
@@ -1291,40 +1291,8 @@ void CartHomebrew::ROMCommandFinish(u8* cmd, u8* data, u32 len)
}
}
-void CartHomebrew::ApplyDLDIPatch(const u8* patch, u32 patchlen, bool readonly)
+void CartHomebrew::ApplyDLDIPatchAt(u8* binary, u32 dldioffset, const u8* patch, u32 patchlen, bool readonly)
{
- u32 offset = *(u32*)&ROM[0x20];
- u32 size = *(u32*)&ROM[0x2C];
-
- u8* binary = &ROM[offset];
- u32 dldioffset = 0;
-
- for (u32 i = 0; i < size; i++)
- {
- if (*(u32*)&binary[i ] == 0xBF8DA5ED &&
- *(u32*)&binary[i+4] == 0x69684320 &&
- *(u32*)&binary[i+8] == 0x006D6873)
- {
- dldioffset = i;
- break;
- }
- }
-
- if (!dldioffset)
- {
- return;
- }
-
- printf("DLDI structure found at %08X (%08X)\n", dldioffset, offset+dldioffset);
-
- if (*(u32*)&patch[0] != 0xBF8DA5ED ||
- *(u32*)&patch[4] != 0x69684320 ||
- *(u32*)&patch[8] != 0x006D6873)
- {
- printf("bad DLDI patch\n");
- return;
- }
-
if (patch[0x0D] > binary[dldioffset+0x0F])
{
printf("DLDI driver ain't gonna fit, sorry\n");
@@ -1421,7 +1389,37 @@ void CartHomebrew::ApplyDLDIPatch(const u8* patch, u32 patchlen, bool readonly)
*(u32*)&binary[writesec_addr+0x04] = 0xE12FFF1E; // bx lr
}
- printf("applied DLDI patch\n");
+ printf("applied DLDI patch at %08X\n", dldioffset);
+}
+
+void CartHomebrew::ApplyDLDIPatch(const u8* patch, u32 patchlen, bool readonly)
+{
+ if (*(u32*)&patch[0] != 0xBF8DA5ED ||
+ *(u32*)&patch[4] != 0x69684320 ||
+ *(u32*)&patch[8] != 0x006D6873)
+ {
+ printf("bad DLDI patch\n");
+ return;
+ }
+
+ u32 offset = *(u32*)&ROM[0x20];
+ u32 size = *(u32*)&ROM[0x2C];
+
+ u8* binary = &ROM[offset];
+
+ for (u32 i = 0; i < size; )
+ {
+ if (*(u32*)&binary[i ] == 0xBF8DA5ED &&
+ *(u32*)&binary[i+4] == 0x69684320 &&
+ *(u32*)&binary[i+8] == 0x006D6873)
+ {
+ printf("DLDI structure found at %08X (%08X)\n", i, offset+i);
+ ApplyDLDIPatchAt(binary, i, patch, patchlen, readonly);
+ i += patchlen;
+ }
+ else
+ i++;
+ }
}
void CartHomebrew::ReadROM_B7(u32 addr, u32 len, u8* data, u32 offset)
diff --git a/src/NDSCart.h b/src/NDSCart.h
index 358b138..bbeb2ff 100644
--- a/src/NDSCart.h
+++ b/src/NDSCart.h
@@ -188,6 +188,7 @@ public:
void ROMCommandFinish(u8* cmd, u8* data, u32 len) override;
private:
+ void ApplyDLDIPatchAt(u8* binary, u32 dldioffset, const u8* patch, u32 patchlen, bool readonly);
void ApplyDLDIPatch(const u8* patch, u32 patchlen, bool readonly);
void ReadROM_B7(u32 addr, u32 len, u8* data, u32 offset);
diff --git a/src/melonDLDI.h b/src/melonDLDI.h
index 202e092..351bc15 100644
--- a/src/melonDLDI.h
+++ b/src/melonDLDI.h
@@ -21,7 +21,7 @@
const u8 melonDLDI[] =
{
- 0xED, 0xA5, 0x8D, 0xBF, 0x20, 0x43, 0x68, 0x69, 0x73, 0x68, 0x6D, 0x00, 0x01, 0x01, 0x00, 0x00,
+ 0xED, 0xA5, 0x8D, 0xBF, 0x20, 0x43, 0x68, 0x69, 0x73, 0x68, 0x6D, 0x00, 0x01, 0x09, 0x00, 0x00,
0x6D, 0x65, 0x6C, 0x6F, 0x6E, 0x44, 0x53, 0x20, 0x44, 0x4C, 0x44, 0x49, 0x20, 0x64, 0x72, 0x69,
0x76, 0x65, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,