Skip to content

Commit

Permalink
Potential bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketRobz committed Dec 25, 2023
1 parent a242d0b commit bf68a71
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion retail/bootloader/source/arm7/main.arm7.c
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,7 @@ int arm7_main(void) {
ndsHeader,
moduleParams,
1,
patchMpuSize,
usesCloneboot,
saveFileCluster,
saveSize
);
Expand Down
12 changes: 6 additions & 6 deletions retail/bootloader/source/arm7/patch_arm9.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ static bool patchCardIrqEnable(cardengineArm9* ce9, const tNDSHeader* ndsHeader,
return true;
}

static void patchMpu(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, u32 patchMpuRegion, u32 patchMpuSize) {
static void patchMpu(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, u32 patchMpuRegion) {
if (!extendedMemory || patchMpuRegion == 2 || ndsHeader->unitCode > 0) {
return;
}
Expand Down Expand Up @@ -519,7 +519,7 @@ static void patchMpu(const tNDSHeader* ndsHeader, const module_params_t* moduleP
patchOffsetCache.mpuInitOffset = mpuInitOffset;
}

static void patchMpu2(const tNDSHeader* ndsHeader, const module_params_t* moduleParams) {
static void patchMpu2(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, const bool usesCloneboot) {
if (((moduleParams->sdk_version < 0x2008000) && !extendedMemory) || moduleParams->sdk_version > 0x5000000) {
return;
}
Expand Down Expand Up @@ -588,7 +588,7 @@ static void patchMpu2(const tNDSHeader* ndsHeader, const module_params_t* module
u32 mpuInitOffsetInSrl = (u32)mpuInitOffset;
mpuInitOffsetInSrl -= (u32)ndsHeader->arm9destination;

if (mpuInitOffsetInSrl >= 0 && mpuInitOffsetInSrl < 0x4000) {
if (mpuInitOffsetInSrl >= 0 && mpuInitOffsetInSrl < 0x4000 && usesCloneboot) {
unpatchedFuncs->mpuInitOffset2 = mpuInitOffset;
}
*mpuInitOffset = 0xE1A00000; // nop
Expand Down Expand Up @@ -1938,7 +1938,7 @@ static void setFlushCache(cardengineArm9* ce9, u32 patchMpuRegion, bool usesThum
ce9->patches->needFlushDCCache = (patchMpuRegion == 1);
}

u32 patchCardNdsArm9(cardengineArm9* ce9, const tNDSHeader* ndsHeader, const module_params_t* moduleParams, u32 patchMpuRegion, u32 patchMpuSize) {
u32 patchCardNdsArm9(cardengineArm9* ce9, const tNDSHeader* ndsHeader, const module_params_t* moduleParams, u32 patchMpuRegion, const bool usesCloneboot) {
bool usesThumb;
int readType;
int sdk5ReadType; // SDK 5
Expand Down Expand Up @@ -1987,8 +1987,8 @@ u32 patchCardNdsArm9(cardengineArm9* ce9, const tNDSHeader* ndsHeader, const mod
}
}

patchMpu(ndsHeader, moduleParams, patchMpuRegion, patchMpuSize);
patchMpu2(ndsHeader, moduleParams);
patchMpu(ndsHeader, moduleParams, patchMpuRegion);
patchMpu2(ndsHeader, moduleParams, usesCloneboot);
patchMpuFlagsSet(ndsHeader, moduleParams);
patchMpuChange(ndsHeader, moduleParams);

Expand Down
7 changes: 3 additions & 4 deletions retail/bootloader/source/arm7/patch_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,18 +508,17 @@ u32 patchCardNds(
tNDSHeader* ndsHeader,
const module_params_t* moduleParams,
u32 patchMpuRegion,
u32 patchMpuSize,
const bool usesCloneboot,
u32 saveFileCluster,
u32 saveSize
) {
dbg_printf("patchCardNds\n\n");

bool sdk5 = isSdk5(moduleParams);
if (sdk5) {
if (isSdk5(moduleParams)) {
dbg_printf("[SDK 5]\n\n");
}

u32 errorCodeArm9 = patchCardNdsArm9(ce9, ndsHeader, moduleParams, patchMpuRegion, patchMpuSize);
u32 errorCodeArm9 = patchCardNdsArm9(ce9, ndsHeader, moduleParams, patchMpuRegion, usesCloneboot);

//if (cardReadFound || ndsHeader->fatSize == 0) {
if (errorCodeArm9 == ERR_NONE || ndsHeader->fatSize == 0) {
Expand Down
11 changes: 9 additions & 2 deletions retail/bootloaderi/source/arm7/main.arm7.c
Original file line number Diff line number Diff line change
Expand Up @@ -1706,8 +1706,15 @@ int arm7_main(void) {

//ensureBinaryDecompressed(&dsiHeaderTemp.ndshdr, moduleParams, false);

extern void patchMpu2(const tNDSHeader* ndsHeader, const module_params_t* moduleParams);
patchMpu2(ndsHeader, moduleParams);
u32 clonebootFlag = 0;
fileRead((char*)&clonebootFlag, romFile, ((romSize-4) <= baseRomSize) ? (romSize-4) : baseRomSize, sizeof(u32));
const bool usesCloneboot = (clonebootFlag == 0x16361);
if (usesCloneboot) {
dbg_printf("Cloneboot detected\n");
}

extern void patchMpu2(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, const bool usesCloneboot);
patchMpu2(ndsHeader, moduleParams, usesCloneboot);

patchSharedFontPath((cardengineArm9*)ce9Location, ndsHeader, moduleParams, ltdModuleParams);
dsiWarePatch((cardengineArm9*)ce9Location, ndsHeader);
Expand Down
8 changes: 4 additions & 4 deletions retail/bootloaderi/source/arm7/patch_arm9.c
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ static void patchMpu(const tNDSHeader* ndsHeader, const module_params_t* moduleP
patchOffsetCache.mpuInitOffset = mpuInitOffset;
}

void patchMpu2(const tNDSHeader* ndsHeader, const module_params_t* moduleParams) {
void patchMpu2(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, const bool usesCloneboot) {
if (moduleParams->sdk_version > 0x5000000 && (ndsHeader->unitCode == 0 || !dsiModeConfirmed)) {
return;
}
Expand Down Expand Up @@ -1069,7 +1069,7 @@ void patchMpu2(const tNDSHeader* ndsHeader, const module_params_t* moduleParams)
u32 mpuInitOffsetInSrl = (u32)mpuInitOffset;
mpuInitOffsetInSrl -= (u32)ndsHeader->arm9destination;

if (mpuInitOffsetInSrl >= 0 && mpuInitOffsetInSrl < 0x4000) {
if (mpuInitOffsetInSrl >= 0 && mpuInitOffsetInSrl < 0x4000 && usesCloneboot) {
unpatchedFuncs->mpuInitOffset2 = mpuInitOffset;
}
*mpuInitOffset = 0xE1A00000; // nop
Expand Down Expand Up @@ -2501,7 +2501,7 @@ static void operaRamPatch(void) {
ce9->patches->needFlushDCCache = (patchMpuRegion == 1);
}*/

u32 patchCardNdsArm9(cardengineArm9* ce9, const tNDSHeader* ndsHeader, const module_params_t* moduleParams, const ltd_module_params_t* ltdModuleParams, u32 ROMinRAM, u32 patchMpuRegion, bool usesCloneboot) {
u32 patchCardNdsArm9(cardengineArm9* ce9, const tNDSHeader* ndsHeader, const module_params_t* moduleParams, const ltd_module_params_t* ltdModuleParams, u32 ROMinRAM, u32 patchMpuRegion, const bool usesCloneboot) {

bool usesThumb;
//bool slot2usesThumb = false;
Expand All @@ -2528,7 +2528,7 @@ u32 patchCardNdsArm9(cardengineArm9* ce9, const tNDSHeader* ndsHeader, const mod
dbg_printf("\n\n");

patchMpu(ndsHeader, moduleParams, patchMpuRegion);
patchMpu2(ndsHeader, moduleParams);
patchMpu2(ndsHeader, moduleParams, usesCloneboot);
patchMpuChange(ndsHeader, moduleParams);
patchMpuInitTwl(ndsHeader);

Expand Down
5 changes: 2 additions & 3 deletions retail/bootloaderi/source/arm7/patch_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -16140,15 +16140,14 @@ u32 patchCardNds(
const module_params_t* moduleParams,
const ltd_module_params_t* ltdModuleParams,
u32 patchMpuRegion,
bool usesCloneboot,
const bool usesCloneboot,
u32 ROMinRAM,
u32 saveFileCluster,
u32 saveSize
) {
dbg_printf("patchCardNds\n\n");

bool sdk5 = isSdk5(moduleParams);
if (sdk5) {
if (isSdk5(moduleParams)) {
dbg_printf("[SDK 5]\n\n");
}

Expand Down

0 comments on commit bf68a71

Please sign in to comment.