Skip to content

Commit

Permalink
Fix Expansion Pak error in DS Browser on 3DS
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketRobz committed Aug 23, 2023
1 parent adb5db2 commit 11b8d26
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
12 changes: 7 additions & 5 deletions retail/bootloaderi/source/arm7/hook_arm9.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ void configureRomMap(cardengineArm9* ce9, const tNDSHeader* ndsHeader, const u32
ce9->romLocation = romLocation;
ce9->romLocation -= romStart;

if (ndsHeader->unitCode > 0 && dsiMode) {
const bool dsBrowser = (strncmp(ndsHeader->gameCode, "UBR", 3) == 0);

if ((ndsHeader->unitCode > 0 && dsiMode) || (consoleModel == 0 && dsBrowser)) {
// ROM map is not used for TWL games in DSi mode
return;
}
Expand All @@ -176,7 +178,7 @@ void configureRomMap(cardengineArm9* ce9, const tNDSHeader* ndsHeader, const u32
romMap[0][0] = romStart;
romMap[0][1] = romLocation;

if (dsiMode) {
if (dsiMode || dsBrowser) {
romMapLines = 1;

if (ce9->valueBits & b_isSdk5) {
Expand Down Expand Up @@ -331,9 +333,9 @@ int hookNdsRetailArm9(
} else {
if (strncmp(romTid, "UBR", 3) == 0) {
runOverlayCheck = false;
ce9->romLocation = CACHE_ADRESS_START_low;
ce9->cacheAddress = ce9->romLocation;
ce9->cacheSlots = retail_CACHE_ADRESS_SIZE_low/cacheBlockSize;
ce9->cacheAddress = CACHE_ADRESS_START;
ce9->romLocation = ce9->romLocation;
ce9->cacheSlots = retail_CACHE_ADRESS_SIZE_BROWSER/cacheBlockSize;
} else {
ce9->cacheAddress = (dsiMode ? CACHE_ADRESS_START_DSIMODE : CACHE_ADRESS_START);
ce9->romLocation = ce9->romLocation;
Expand Down
17 changes: 10 additions & 7 deletions retail/bootloaderi/source/arm7/main.arm7.c
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,9 @@ static module_params_t* loadModuleParams(const tNDSHeader* ndsHeader, bool* foun
}

u32 getRomLocation(const tNDSHeader* ndsHeader, const bool isSdk5) {
if (strncmp(ndsHeader->gameCode, "UBR", 3) == 0) {
return ROM_LOCATION_DSIMODE;
}
if (ndsHeader->unitCode > 0 && dsiModeConfirmed) {
return ROM_LOCATION_TWLSDK;
}
Expand Down Expand Up @@ -1746,13 +1749,13 @@ int arm7_main(void) {
//}
} else {
if (strncmp(romTid, "UBR", 3) == 0) {
toncset((char*)0x0C400000, 0xFF, 0xC0);
toncset((u8*)0x0C4000B2, 0, 3);
toncset((u8*)0x0C4000B5, 0x24, 3);
*(u16*)0x0C4000BE = 0x7FFF;
toncset((char*)0x0C4000C0, 0, 0xE);
*(u16*)0x0C4000CE = 0x7FFF;
toncset((char*)0x0C4000D0, 0, 0x130);
toncset((char*)0x0C3E0000, 0xFF, 0xC0);
toncset((u8*)0x0C3E00B2, 0, 3);
toncset((u8*)0x0C3E00B5, 0x24, 3);
*(u16*)0x0C3E00BE = 0x7FFF;
toncset((char*)0x0C3E00C0, 0, 0xE);
*(u16*)0x0C3E00CE = 0x7FFF;
toncset((char*)0x0C3E00D0, 0, 0x130);
} /*else // GBA file
if (!dsiModeConfirmed && !isSdk5(moduleParams)) {
aFile* gbaFile = (aFile*)(dsiEnhancedMbk ? GBA_FILE_LOCATION_ALT : GBA_FILE_LOCATION);
Expand Down
6 changes: 3 additions & 3 deletions retail/bootloaderi/source/arm7/patch_arm7.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,10 @@ static void patchSdCardReset(const tNDSHeader* ndsHeader, const module_params_t*

static void operaRamPatch(void) {
// Opera RAM patch (ARM7)
*(u32*)0x0238C7BC = 0xC400000;
*(u32*)0x0238C7C0 = 0xC4000CE;
*(u32*)0x0238C7BC = 0xC3E0000;
*(u32*)0x0238C7C0 = 0xC3E00CE;

//*(u32*)0x0238C950 = 0xC400000;
//*(u32*)0x0238C950 = 0xC3E0000;
}

extern void rsetA7Cache(void);
Expand Down
16 changes: 8 additions & 8 deletions retail/bootloaderi/source/arm7/patch_arm9.c
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ static void patchWaitSysCycles(const cardengineArm9* ce9, const tNDSHeader* ndsH
}*/

u32* patchHiHeapPointer(const module_params_t* moduleParams, const tNDSHeader* ndsHeader) {
if (moduleParams->sdk_version < 0x2008000 || !dsiModeConfirmed) {
if (moduleParams->sdk_version < 0x2008000 || !dsiModeConfirmed || strncmp(ndsHeader->gameCode, "UBR", 3) == 0) {
return NULL;
}

Expand Down Expand Up @@ -2375,16 +2375,16 @@ static void operaRamPatch(void) {
extern u8 consoleModel;

// Opera RAM patch (ARM9)
*(u32*)0x02003D48 = 0xC400000;
*(u32*)0x02003D4C = 0xC400004;
*(u32*)0x02003D48 = 0xC3E0000;
*(u32*)0x02003D4C = 0xC3E0004;

*(u32*)0x02010FF0 = 0xC400000;
*(u32*)0x02010FF4 = 0xC4000CE;
*(u32*)0x02010FF0 = 0xC3E0000;
*(u32*)0x02010FF4 = 0xC3E00CE;

*(u32*)0x020112AC = 0xC400080;
*(u32*)0x020112AC = 0xC3E0080;

*(u32*)0x020402BC = 0xC4000C2;
*(u32*)0x020402C0 = 0xC4000C0;
*(u32*)0x020402BC = 0xC3E00C2;
*(u32*)0x020402C0 = 0xC3E00C0;
if (consoleModel > 0) {
*(u32*)0x020402CC = 0xD7FFFFE;
*(u32*)0x020402D0 = 0xD000000;
Expand Down
3 changes: 1 addition & 2 deletions retail/common/include/locations.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,11 @@

#define CACHE_ADRESS_START 0x0C400000
#define CACHE_ADRESS_START_DSIMODE 0x0C800000
#define CACHE_ADRESS_START_low 0x0C480000
#define retail_CACHE_ADRESS_START_TWLSDK 0x02F40000

#define retail_CACHE_ADRESS_SIZE 0xBC0000
#define retail_CACHE_ADRESS_SIZE_DSIMODE 0x800000
#define retail_CACHE_ADRESS_SIZE_low 0x274000
#define retail_CACHE_ADRESS_SIZE_BROWSER 0x3C0000
#define retail_CACHE_ADRESS_SIZE_TWLSDK 0x18000

#define retail_CACHE_SLOTS_16KB 0x200
Expand Down

0 comments on commit 11b8d26

Please sign in to comment.