Skip to content

Commit

Permalink
Merge pull request #88 from Robz8/master
Browse files Browse the repository at this point in the history
Add donor SDK version for increased ROM hack compatibility
  • Loading branch information
shutterbug2000 authored Jun 23, 2017
2 parents d960cc6 + 9f19b5b commit 12881d1
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 18 deletions.
12 changes: 6 additions & 6 deletions arm9/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void dopause() {
scanKeys();
}

void runFile(string filename, string savPath, string arm7DonorPath, u32 patchMpuRegion, u32 patchMpuSize) {
void runFile(string filename, string savPath, string arm7DonorPath, u32 donorSdkVer, u32 patchMpuRegion, u32 patchMpuSize) {
vector<char*> argarray;

if(debug) dopause();
Expand Down Expand Up @@ -98,7 +98,7 @@ void runFile(string filename, string savPath, string arm7DonorPath, u32 patchMpu
dbg_printf("no nds file specified\n");
} else {
dbg_printf("Running %s with %d parameters\n", argarray[0], argarray.size());
int err = runNdsFile (argarray[0], strdup(savPath.c_str()), strdup(arm7DonorPath.c_str()), patchMpuRegion, patchMpuSize, argarray.size(), (const char **)&argarray[0]);
int err = runNdsFile (argarray[0], strdup(savPath.c_str()), strdup(arm7DonorPath.c_str()), donorSdkVer, patchMpuRegion, patchMpuSize, argarray.size(), (const char **)&argarray[0]);
dbg_printf("Start failed. Error %i\n", err);

}
Expand Down Expand Up @@ -235,14 +235,14 @@ int main( int argc, char **argv) {
fifoSendValue32(FIFO_USER_08, 1);
}
*/

// Options from INI file set. Now tell Arm7 to check to apply changes if any were requested.
fifoSendValue32(FIFO_USER_06, 1);

initMBK();

dbg_printf("Running %s\n", ndsPath.c_str());
runFile(ndsPath.c_str(), savPath.c_str(), arm7DonorPath.c_str(), patchMpuRegion, patchMpuSize);
runFile(ndsPath.c_str(), savPath.c_str(), arm7DonorPath.c_str(), bootstrapini.GetInt( "NDS-BOOTSTRAP", "DONOR_SDK_VER", 0), patchMpuRegion, patchMpuSize);
} else {
consoleDemoInit();
printf("SD init failed!\n");
Expand Down
12 changes: 7 additions & 5 deletions arm9/source/nds_loader_arm9.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@
#define HAVE_DSISD_OFFSET 28
#define SAV_OFFSET 32
#define DONOR_OFFSET 36
#define PUR_OFFSET 40
#define PUS_OFFSET 44
#define DONORSDK_OFFSET 40
#define PUR_OFFSET 44
#define PUS_OFFSET 48

typedef signed int addr_t;
typedef unsigned char data_t;
Expand Down Expand Up @@ -265,7 +266,7 @@ static bool dldiPatchLoader (data_t *binData, u32 binSize, bool clearBSS)
return true;
}

int runNds (const void* loader, u32 loaderSize, u32 cluster, u32 saveCluster, u32 donorCluster, u32 patchMpuRegion, u32 patchMpuSize, bool initDisc, bool dldiPatchNds, int argc, const char** argv)
int runNds (const void* loader, u32 loaderSize, u32 cluster, u32 saveCluster, u32 donorCluster, u32 donorSdkVer, u32 patchMpuRegion, u32 patchMpuSize, bool initDisc, bool dldiPatchNds, int argc, const char** argv)
{
char* argStart;
u16* argData;
Expand Down Expand Up @@ -327,6 +328,7 @@ int runNds (const void* loader, u32 loaderSize, u32 cluster, u32 saveCluster, u3

writeAddr ((data_t*) LCDC_BANK_C, SAV_OFFSET, saveCluster);
writeAddr ((data_t*) LCDC_BANK_C, DONOR_OFFSET, donorCluster);
writeAddr ((data_t*) LCDC_BANK_C, DONORSDK_OFFSET, donorSdkVer);
writeAddr ((data_t*) LCDC_BANK_C, PUR_OFFSET, patchMpuRegion);
writeAddr ((data_t*) LCDC_BANK_C, PUS_OFFSET, patchMpuSize);

Expand Down Expand Up @@ -366,7 +368,7 @@ int runNds (const void* loader, u32 loaderSize, u32 cluster, u32 saveCluster, u3
return true;
}

int runNdsFile (const char* filename, const char* savename, const char* arm7DonorPath, int patchMpuRegion, int patchMpuSize, int argc, const char** argv) {
int runNdsFile (const char* filename, const char* savename, const char* arm7DonorPath, int donorSdkVer, int patchMpuRegion, int patchMpuSize, int argc, const char** argv) {
struct stat st;
struct stat stSav;
struct stat stDonor;
Expand Down Expand Up @@ -404,6 +406,6 @@ int runNdsFile (const char* filename, const char* savename, const char* arm7Don

if(argv[0][0]=='s' && argv[0][1]=='d') havedsiSD = true;

return runNds (load_bin, load_bin_size, st.st_ino, clusterSav, clusterDonor, patchMpuRegion, patchMpuSize, true, true, argc, argv);
return runNds (load_bin, load_bin_size, st.st_ino, clusterSav, clusterDonor, donorSdkVer, patchMpuRegion, patchMpuSize, true, true, argc, argv);
}

4 changes: 2 additions & 2 deletions arm9/source/nds_loader_arm9.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ extern "C" {

#define LOAD_DEFAULT_NDS 0

int runNds (const void* loader, u32 loaderSize, u32 cluster, u32 saveCluster, u32 donorCluster, u32 patchMpuRegion, u32 patchMpuSize, bool initDisc, bool dldiPatchNds, int argc, const char** argv);
int runNds (const void* loader, u32 loaderSize, u32 cluster, u32 saveCluster, u32 donorCluster, u32 donorSdkVer, u32 patchMpuRegion, u32 patchMpuSize, bool initDisc, bool dldiPatchNds, int argc, const char** argv);

int runNdsFile (const char* filename, const char* savename, const char* arm7DonorPath, int patchMpuRegion, int patchMpuSize, int argc, const char** argv);
int runNdsFile (const char* filename, const char* savename, const char* arm7DonorPath, int donorSdkVer, int patchMpuRegion, int patchMpuSize, int argc, const char** argv);

#ifdef __cplusplus
}
Expand Down
3 changes: 2 additions & 1 deletion bootloader/source/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ extern unsigned long argSize;
extern unsigned long dsiSD;
extern unsigned long saveFileCluster;
extern unsigned long donorFileCluster;
extern unsigned long donorSdkVer;
extern unsigned long patchMpuRegion;
extern unsigned long patchMpuSize;

Expand Down Expand Up @@ -386,7 +387,7 @@ int main (void) {
copyLoop (ENGINE_LOCATION_ARM7, (u32*)cardengine_arm7_bin, cardengine_arm7_bin_size);
copyLoop (ENGINE_LOCATION_ARM9, (u32*)cardengine_arm9_bin, cardengine_arm9_bin_size);

module_params_t* params = findModuleParams(NDS_HEAD);
module_params_t* params = findModuleParams(NDS_HEAD, donorSdkVer);
if(params)
{
ensureArm9Decompressed(NDS_HEAD, params);
Expand Down
26 changes: 23 additions & 3 deletions bootloader/source/card_patcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,37 @@ u32 generateA7Instr(int arg1, int arg2) {
return (((u32)(arg2 - arg1 - 8) >> 2) & 0xFFFFFF) | 0xEB000000;
}

module_params_t* findModuleParams(const tNDSHeader* ndsHeader)
module_params_t* findModuleParams(const tNDSHeader* ndsHeader, u32 donorSdkVer)
{
dbg_printf("Looking for moduleparams\n");
uint32_t moduleparams = getOffset((u32*)ndsHeader->arm9destination, ndsHeader->arm9binarySize, (u32*)moduleParamsSignature, 2, 1);
if(!moduleparams)
{
dbg_printf("No moduleparams?\n");
moduleparams = malloc(0x100);
memset(moduleparams,0,0x100);
((module_params_t*)(moduleparams - 0x1C))->compressed_static_end = 0;
dbg_printf("No moduleparams?\n");
return (module_params_t*)(moduleparams - 0x1C);
switch(donorSdkVer) {
case 0:
default:
break;
case 1:
((module_params_t*)(moduleparams - 0x1C))->sdk_version = 0x1000500;
break;
case 2:
((module_params_t*)(moduleparams - 0x1C))->sdk_version = 0x2001000;
break;
case 3:
((module_params_t*)(moduleparams - 0x1C))->sdk_version = 0x3002001;
break;
case 4:
((module_params_t*)(moduleparams - 0x1C))->sdk_version = 0x4002001;
break;
case 5:
((module_params_t*)(moduleparams - 0x1C))->sdk_version = 0x5003001;
break;
}
return (module_params_t*)(moduleparams - 0x1C);
}
return (module_params_t*)(moduleparams - 0x1C);
}
Expand Down
2 changes: 1 addition & 1 deletion bootloader/source/card_patcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ typedef struct
} module_params_t;


module_params_t* findModuleParams(const tNDSHeader* ndsHeader);
module_params_t* findModuleParams(const tNDSHeader* ndsHeader, u32 donorSdkVer);
void ensureArm9Decompressed(const tNDSHeader* ndsHeader, module_params_t* moduleParams);
/*-------------------------------------------------------------------------
arm7_hookGame
Expand Down
3 changes: 3 additions & 0 deletions bootloader/source/load_crt0.s
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
.global dsiSD
.global saveFileCluster
.global donorFileCluster
.global donorSdkVer
.global patchMpuRegion
.global patchMpuSize
@---------------------------------------------------------------------------------
Expand Down Expand Up @@ -60,6 +61,8 @@ saveFileCluster:
.word 0x00000000 @ .sav file
donorFileCluster:
.word 0x00000000 @ donor .nds file
donorSdkVer:
.word 0x00000000 @ donor SDK version
patchMpuRegion:
.word 0x00000000
patchMpuSize:
Expand Down

0 comments on commit 12881d1

Please sign in to comment.