Skip to content

Commit 0bd8cef

Browse files
committed
Port save relocation setting to soft-reset process
1 parent 24c0a92 commit 0bd8cef

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed

retail/bootloaderi/source/arm7/hook_arm7.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#define b_isDlp BIT(21)
6060
#define b_useColorLut BIT(22)
6161
#define b_clearRamOnReset BIT(23)
62+
#define b_saveRelocation BIT(24)
6263
#define b_i2cBricked BIT(30)
6364
#define b_scfgLocked BIT(31)
6465

@@ -443,6 +444,10 @@ int hookNdsRetailArm7(
443444
if (strncmp(romTid, "A5F", 3) == 0 || strncmp(romTid, "C5F", 3) == 0) { // Professor Layton and the Curious Village
444445
ce7->valueBits |= b_clearRamOnReset;
445446
}
447+
extern bool saveRelocationApplied;
448+
if (saveRelocationApplied) {
449+
ce7->valueBits |= b_saveRelocation;
450+
}
446451
if (REG_SCFG_EXT == 0) {
447452
ce7->valueBits |= b_scfgLocked;
448453
}

retail/bootloaderi/source/arm7/patch_arm7.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ u32 vAddrOfRelocSrc = 0;
154154
u32 relocDestAtSharedMem = 0;
155155
u32 newSwiHaltAddr = 0;
156156
// bool swiHaltPatched = false;
157+
bool saveRelocationApplied = false;
157158

158159
static void patchSwiHalt(const cardengineArm7* ce7, const tNDSHeader* ndsHeader, const module_params_t* moduleParams) {
159160
extern bool pkmnGen5;
@@ -854,7 +855,9 @@ u32 patchCardNdsArm7(
854855
}
855856
}
856857
}
857-
if (!saveResult) {
858+
if (saveResult) {
859+
saveRelocationApplied = true;
860+
} else {
858861
patchOffsetCache.savePatchType = 0;
859862
} /*else if (strncmp(romTid, "AMH", 3) == 0) {
860863
aFile* savFile = (aFile*)(dsiSD ? SAV_FILE_LOCATION : SAV_FILE_LOCATION_ALT);

retail/cardenginei/arm7/source/patcher/hook_arm9.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "nds_header.h"
1010
#include "cardengine_header_arm9.h"
1111

12+
#define pingIpc BIT(3)
1213
#define isSdk5_9 BIT(5)
1314
#define isSdk5_7 BIT(13)
1415
#define b_isDlp BIT(15)
@@ -124,7 +125,13 @@ int hookNdsRetailArm9(
124125
//nocashMessage("hookNdsRetailArm9");
125126

126127
extern u32 iUncompressedSize;
128+
extern u32 newSwiHaltAddr;
127129

130+
if (newSwiHaltAddr == 0) {
131+
ce9->valueBits |= pingIpc;
132+
} else {
133+
ce9->valueBits &= ~pingIpc;
134+
}
128135
if (valueBits & isSdk5_7) {
129136
ce9->valueBits |= isSdk5_9;
130137
} else {

retail/cardenginei/arm7/source/patcher/patch_arm7.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define dsiMode BIT(4)
1818
#define hasVramWifiBinary BIT(14)
1919
#define sleepMode BIT(17)
20+
#define saveRelocation BIT(24)
2021

2122
extern u32 valueBits;
2223
extern u16 scfgRomBak;
@@ -41,7 +42,7 @@ const u16* generateA7InstrThumb(int arg1, int arg2) {
4142
u32 offset = (u32)(arg2 - arg1 - 4);
4243
//dbg_printf("generateA7InstrThumb offset\n");
4344
//dbg_hexa(offset);
44-
45+
4546
// 1st instruction contains the upper 11 bit of the offset
4647
instrs[0] = ((offset >> 12) & 0x7FF) | 0xF000;
4748

@@ -70,6 +71,8 @@ static void patchSwiHalt(const cardengineArm7* ce7, const tNDSHeader* ndsHeader,
7071
if (swiHaltOffset) {
7172
// Patch
7273
if (a7IsThumb) {
74+
if (newSwiHaltAddr == 0) return;
75+
7376
tonccpy((u16*)newSwiHaltAddr, ce7->patches->newSwiHaltThumb, 0x18);
7477
u32 srcAddr = (u32)swiHaltOffset - vAddrOfRelocSrc + 0x37F8000;
7578
u32 dstAddr = (u32)newSwiHaltAddr - vAddrOfRelocSrc + 0x37F8000;
@@ -82,6 +85,7 @@ static void patchSwiHalt(const cardengineArm7* ce7, const tNDSHeader* ndsHeader,
8285
} else {
8386
u32* swiHaltPatch = ce7->patches->j_newSwiHalt;
8487
tonccpy(swiHaltOffset, swiHaltPatch, 0xC);
88+
newSwiHaltAddr = 1; // Let ce9 know not to ping arm7 IPC
8589
}
8690
// swiHaltPatched = true;
8791
// dbg_printf("swiHalt hooked\n");
@@ -381,19 +385,21 @@ u32 patchCardNdsArm7(
381385
patchMirrorCheck(ndsHeader, moduleParams);
382386
patchVramWifiBinaryLoad(ndsHeader, moduleParams);
383387
u32 saveResult = 0;
384-
385-
if (ndsHeader->arm7binarySize==0x2352C || ndsHeader->arm7binarySize==0x235DC || ndsHeader->arm7binarySize==0x23CAC || ndsHeader->arm7binarySize==0x245C0 || ndsHeader->arm7binarySize==0x245C4) {
386-
saveResult = savePatchInvertedThumb(ce7, ndsHeader, moduleParams);
387-
} else if (moduleParams->sdk_version > 0x5000000) {
388-
// SDK 5
389-
saveResult = savePatchV5(ce7, ndsHeader);
390-
} else {
391-
saveResult = savePatchV1(ce7, ndsHeader, moduleParams);
392-
if (!saveResult) {
393-
saveResult = savePatchV2(ce7, ndsHeader, moduleParams);
394-
}
395-
if (!saveResult) {
396-
saveResult = savePatchUniversal(ce7, ndsHeader, moduleParams);
388+
389+
if (valueBits & saveRelocation) {
390+
if (ndsHeader->arm7binarySize==0x2352C || ndsHeader->arm7binarySize==0x235DC || ndsHeader->arm7binarySize==0x23CAC || ndsHeader->arm7binarySize==0x245C0 || ndsHeader->arm7binarySize==0x245C4) {
391+
saveResult = savePatchInvertedThumb(ce7, ndsHeader, moduleParams);
392+
} else if (moduleParams->sdk_version > 0x5000000) {
393+
// SDK 5
394+
saveResult = savePatchV5(ce7, ndsHeader);
395+
} else {
396+
saveResult = savePatchV1(ce7, ndsHeader, moduleParams);
397+
if (!saveResult) {
398+
saveResult = savePatchV2(ce7, ndsHeader, moduleParams);
399+
}
400+
if (!saveResult) {
401+
saveResult = savePatchUniversal(ce7, ndsHeader, moduleParams);
402+
}
397403
}
398404
}
399405
}

retail/common/include/cardengine_header_arm7.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ typedef struct cardengineArm7 {
105105
21: isDlp
106106
22: useColorLut
107107
23: clearRamOnReset
108+
24: saveRelocation
108109
30: i2cBricked
109110
31: scfgLocked
110111
*/

0 commit comments

Comments
 (0)