Skip to content

Commit

Permalink
Try to fix crashing in Gen 5 Pokemon in DSi mode on DSi (by shrinking…
Browse files Browse the repository at this point in the history
… heap 2MB further)
  • Loading branch information
RocketRobz committed Nov 25, 2024
1 parent ec87158 commit 0ae5e0e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 14 deletions.
17 changes: 13 additions & 4 deletions retail/bootloaderi/source/arm7/hook_arm9.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,25 @@ int hookNdsRetailArm9(
extern u32 cheatSizeTotal;
const bool cheatsEnabled = (cheatSizeTotal > 4 && cheatSizeTotal <= 0x8000);
const bool specialTitle = (strncmp(romTid, "V2G", 3) == 0 || strncmp(romTid, "DD3", 3) == 0);
const bool pkmnTitle = (strncmp(romTid, "IRB", 3) == 0 || strncmp(romTid, "IRA", 3) == 0 || strncmp(romTid, "IRE", 3) == 0 || strncmp(romTid, "IRD", 3) == 0);
extern u8 gameOnFlashcard;

ce9->cacheAddress = (consoleModel > 0 ? dev_CACHE_ADRESS_START_TWLSDK : (cheatsEnabled ? retail_CACHE_ADRESS_START_TWLSDK_CHEAT : retail_CACHE_ADRESS_START_TWLSDK));
if (consoleModel == 0 && !gameOnFlashcard && specialTitle) {
ce9->cacheAddress = (cheatsEnabled ? retail_CACHE_ADRESS_START_TWLSDK_SMALL_CHEAT : retail_CACHE_ADRESS_START_TWLSDK_SMALL);
if (consoleModel == 0 && !gameOnFlashcard) {
if (pkmnTitle) {
ce9->cacheAddress = (cheatsEnabled ? retail_CACHE_ADRESS_START_TWLSDK_LARGE_CHEAT : retail_CACHE_ADRESS_START_TWLSDK_LARGE);
} else if (specialTitle) {
ce9->cacheAddress = (cheatsEnabled ? retail_CACHE_ADRESS_START_TWLSDK_SMALL_CHEAT : retail_CACHE_ADRESS_START_TWLSDK_SMALL);
}
}
ce9->romLocation = ce9->cacheAddress;
ce9->cacheSlots = (consoleModel > 0 ? (cheatsEnabled ? dev_CACHE_ADRESS_SIZE_TWLSDK_CHEAT : dev_CACHE_ADRESS_SIZE_TWLSDK) : (cheatsEnabled ? retail_CACHE_ADRESS_SIZE_TWLSDK_CHEAT : retail_CACHE_ADRESS_SIZE_TWLSDK))/cacheBlockSize;
if (consoleModel == 0 && !gameOnFlashcard && specialTitle) {
ce9->cacheSlots = (cheatsEnabled ? retail_CACHE_ADRESS_SIZE_TWLSDK_SMALL_CHEAT : retail_CACHE_ADRESS_SIZE_TWLSDK_SMALL)/cacheBlockSize;
if (consoleModel == 0 && !gameOnFlashcard) {
if (pkmnTitle) {
ce9->cacheSlots = (cheatsEnabled ? retail_CACHE_ADRESS_SIZE_TWLSDK_LARGE_CHEAT : retail_CACHE_ADRESS_SIZE_TWLSDK_LARGE)/cacheBlockSize;
} else if (specialTitle) {
ce9->cacheSlots = (cheatsEnabled ? retail_CACHE_ADRESS_SIZE_TWLSDK_SMALL_CHEAT : retail_CACHE_ADRESS_SIZE_TWLSDK_SMALL)/cacheBlockSize;
}
}
} else {
if (strncmp(romTid, "UBR", 3) == 0) {
Expand Down
8 changes: 6 additions & 2 deletions retail/bootloaderi/source/arm7/main.arm7.c
Original file line number Diff line number Diff line change
Expand Up @@ -2117,8 +2117,12 @@ int arm7_main(void) {
}
if (ROMsupportsDsiMode(ndsHeader) && dsiModeConfirmed) {
cheatEngineOffset = (consoleModel > 0) ? CHEAT_ENGINE_TWLSDK_LOCATION_3DS : CHEAT_ENGINE_TWLSDK_SMALL_LOCATION;
if (consoleModel == 0 && !gameOnFlashcard && strncmp(romTid, "V2G", 3) != 0 && strncmp(romTid, "DD3", 3) != 0) {
cheatEngineOffset = CHEAT_ENGINE_TWLSDK_LOCATION;
if (consoleModel == 0 && !gameOnFlashcard) {
if (strncmp(romTid, "IRB", 3) == 0 || strncmp(romTid, "IRA", 3) == 0 || strncmp(romTid, "IRE", 3) == 0 || strncmp(romTid, "IRD", 3) == 0) {
cheatEngineOffset = CHEAT_ENGINE_TWLSDK_LARGE_LOCATION;
} else if (strncmp(romTid, "V2G", 3) != 0 && strncmp(romTid, "DD3", 3) != 0) {
cheatEngineOffset = CHEAT_ENGINE_TWLSDK_LOCATION;
}
}
} else {
cheatEngineOffset = (ce7Location == CARDENGINEI_ARM7_LOCATION_ALT) ? CHEAT_ENGINE_LOCATION_ALT : CHEAT_ENGINE_LOCATION;
Expand Down
19 changes: 16 additions & 3 deletions retail/bootloaderi/source/arm7/patch_arm9.c
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,20 @@ void patchHiHeapPointer(const module_params_t* moduleParams, const tNDSHeader* n
}
} else { */
// DSi mode title loaded on DSi from SD card, or DSi/3DS with external DSi BIOS files loaded
if (!gameOnFlashcard && strncmp(romTid, "V2G", 3) != 0 && strncmp(romTid, "DD3", 3) != 0) {
if (!gameOnFlashcard && (strncmp(romTid, "IRB", 3) == 0 || strncmp(romTid, "IRA", 3) == 0 || strncmp(romTid, "IRE", 3) == 0 || strncmp(romTid, "IRD", 3) == 0)) {
// Pokemon Black & White 1&2
switch (*heapPointer) {
case 0x13A007BE:
*heapPointer = (u32)0x13A0062D; // MOVNE R0, #0x2D00000
break;
case 0xE3A007BE:
*heapPointer = (u32)0xE3A0062D; // MOV R0, #0x2D00000
break;
case 0x048020BE:
*heapPointer = (u32)0x048020B4; // MOVS R0, #0x2D00000
break;
}
} else if (!gameOnFlashcard && strncmp(romTid, "V2G", 3) != 0 && strncmp(romTid, "DD3", 3) != 0) {
switch (*heapPointer) {
case 0x13A007BE:
*heapPointer = (u32)0x13A0062F; // MOVNE R0, #0x2F00000
Expand Down Expand Up @@ -2005,7 +2018,7 @@ void codeCopy(u32* dst, u32* src, u32 len) {
}
}

void relocate_ce9(u32 default_location, u32 current_location, u32 size) {
/* void relocate_ce9(u32 default_location, u32 current_location, u32 size) {
dbg_printf("relocate_ce9\n");
u32 location_sig[1] = {default_location};
Expand Down Expand Up @@ -2245,7 +2258,7 @@ void relocate_ce9(u32 default_location, u32 current_location, u32 size) {
ce9->thumbPatches->cardEndReadDmaRef = (u32*)((u32)ce9->thumbPatches->cardEndReadDmaRef - default_location + current_location);
ce9->thumbPatches->sleepRef = (u32*)((u32)ce9->thumbPatches->sleepRef - default_location + current_location);
ce9->thumbPatches->reset_arm9 = (u32*)((u32)ce9->thumbPatches->reset_arm9 - default_location + current_location);
}
} */

static void randomPatch(const tNDSHeader* ndsHeader, const module_params_t* moduleParams) {
const char* romTid = getRomTid(ndsHeader);
Expand Down
4 changes: 2 additions & 2 deletions retail/cardenginei/arm9/source/cardengine.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@ void sleepMs(int ms) {
}
}*/

/* #ifdef TWLSDK
#ifdef TWLSDK
void resetSlots(void) {
for (int i = 0; i < ce9->cacheSlots; i++) {
cacheDescriptor[i] = 0;
cacheCounter[i] = 0;
}
accessCounter = 0;
}
#endif */
#endif

int allocateCacheSlot(void) {
int slot = 0;
Expand Down
6 changes: 3 additions & 3 deletions retail/cardenginei/arm9/source/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,11 @@ void reset(u32 param, u32 tid2) {
VRAM_I_CR = 0;
}

/* #ifndef DLDI
if (ce9->consoleModel == 0) {
#ifndef DLDI
if (ce9->cacheAddress < 0x02F00000) {
resetSlots();
}
#endif */
#endif

while (sharedAddr[0] != 0x44414F4C) { // 'LOAD'
while (REG_VCOUNT != 191);
Expand Down
5 changes: 5 additions & 0 deletions retail/common/include/locations.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
#define CHEAT_ENGINE_LOCATION_ALT 0x03000000
#define CHEAT_ENGINE_TWLSDK_SMALL_LOCATION 0x02F60000
#define CHEAT_ENGINE_TWLSDK_LOCATION 0x02F00000
#define CHEAT_ENGINE_TWLSDK_LARGE_LOCATION 0x02D00000
#define CHEAT_ENGINE_TWLSDK_LOCATION_3DS 0x0DFF7C00
#define CHEAT_ENGINE_DSIWARE_LOCATION 0x02FD9400
#define CHEAT_ENGINE_DSIWARE_LOCATION3 0x02F80C00
Expand Down Expand Up @@ -129,6 +130,8 @@
#define retail_CACHE_ADRESS_START_TWLSDK_SMALL_CHEAT 0x02F68400
#define retail_CACHE_ADRESS_START_TWLSDK 0x02F00000
#define retail_CACHE_ADRESS_START_TWLSDK_CHEAT 0x02F08400
#define retail_CACHE_ADRESS_START_TWLSDK_LARGE 0x02D00000
#define retail_CACHE_ADRESS_START_TWLSDK_LARGE_CHEAT 0x02D08400

#define retail_CACHE_ADRESS_SIZE 0xBC0000
#define retail_CACHE_ADRESS_SIZE_DSIMODE 0x7FF000
Expand All @@ -137,6 +140,8 @@
#define retail_CACHE_ADRESS_SIZE_TWLSDK_SMALL_CHEAT 0x17C00
#define retail_CACHE_ADRESS_SIZE_TWLSDK 0x80000
#define retail_CACHE_ADRESS_SIZE_TWLSDK_CHEAT 0x77C00
#define retail_CACHE_ADRESS_SIZE_TWLSDK_LARGE 0x280000
#define retail_CACHE_ADRESS_SIZE_TWLSDK_LARGE_CHEAT 0x277C00

#define dev_CACHE_ADRESS_START_TWLSDK 0x0D000000

Expand Down

0 comments on commit 0ae5e0e

Please sign in to comment.