Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility regression, arm7 optimisation and arm7 swapping option #39

Merged
merged 5 commits into from
Jan 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arm7/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ LDFLAGS = -specs=../ds_arm7_ram.specs -g $(ARCH) -Wl,--nmagic -Wl,-Map,$(notdir
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -lmm7 -lnds7
LIBS := -lnds7


#---------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions arm7/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ redistribute it freely, subject to the following restrictions:
---------------------------------------------------------------------------------*/
#include <nds.h>

#include <maxmod7.h>
// #include <maxmod7.h>
#include <nds/ndstypes.h>

#include "fifocheck.h"
Expand Down Expand Up @@ -127,11 +127,11 @@ int main(void) {
// Start the RTC tracking IRQ
initClockIRQ();

mmInstall(FIFO_MAXMOD);
// mmInstall(FIFO_MAXMOD);

SetYtrigger(80);

installSoundFIFO();
// installSoundFIFO();
installSystemFIFO();

irqSet(IRQ_VCOUNT, VcountHandler);
Expand Down
2 changes: 1 addition & 1 deletion arm9/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project (order is important)
#---------------------------------------------------------------------------------
LIBS := -lfat -lmm9 -lnds9
LIBS := -lfat -lnds9


#---------------------------------------------------------------------------------
Expand Down
16 changes: 11 additions & 5 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) {
void runFile(string filename, string savPath, string arm7DonorPath, u32 patchMpuRegion, u32 patchMpuSize) {
vector<char*> argarray;

if(debug) dopause();
Expand Down Expand Up @@ -98,7 +98,7 @@ void runFile(string filename, string savPath) {
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()), argarray.size(), (const char **)&argarray[0]);
int err = runNdsFile (argarray[0], strdup(savPath.c_str()), strdup(arm7DonorPath.c_str()), patchMpuRegion, patchMpuSize, argarray.size(), (const char **)&argarray[0]);
dbg_printf("Start failed. Error %i\n", err);

}
Expand Down Expand Up @@ -248,6 +248,12 @@ int main( int argc, char **argv) {
std::string ndsPath = bootstrapini.GetString( "NDS-BOOTSTRAP", "NDS_PATH", "");

std::string savPath = bootstrapini.GetString( "NDS-BOOTSTRAP", "SAV_PATH", "");

std::string arm7DonorPath = bootstrapini.GetString( "NDS-BOOTSTRAP", "ARM7_DONOR_PATH", "");

u32 patchMpuRegion = bootstrapini.GetInt( "NDS-BOOTSTRAP", "PATCH_MPU_REGION", 0);

u32 patchMpuSize = bootstrapini.GetInt( "NDS-BOOTSTRAP", "PATCH__MPU_SIZE", 0);

if(bootstrapini.GetInt("NDS-BOOTSTRAP","BOOST_CPU",0) == 1) {
dbg_printf("CPU boosted\n");
Expand All @@ -273,17 +279,17 @@ int main( int argc, char **argv) {
dbg_printf("RERUN BOOTSTRAP in NTR mode via argv\n");
dbg_printf("Running %s\n", bootstrapPath.c_str());

runFile(bootstrapPath.c_str(), savPath);
runFile(bootstrapPath.c_str(), savPath, arm7DonorPath.c_str(), patchMpuRegion, patchMpuSize);
} else {
dbg_printf("Running %s\n", ndsPath.c_str());

runFile(ndsPath.c_str(), savPath.c_str());
runFile(ndsPath.c_str(), savPath.c_str(), arm7DonorPath.c_str(), patchMpuRegion, patchMpuSize);
}
} else {
dbg_printf("TWL MODE enabled\n");
dbg_printf("Running %s\n", ndsPath.c_str());

runFile(ndsPath.c_str(), savPath.c_str());
runFile(ndsPath.c_str(), savPath.c_str(), arm7DonorPath.c_str(), patchMpuRegion, patchMpuSize);
}
} else {
consoleDemoInit();
Expand Down
18 changes: 15 additions & 3 deletions arm9/source/nds_loader_arm9.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
#define ARG_SIZE_OFFSET 20
#define HAVE_DSISD_OFFSET 28
#define SAV_OFFSET 32
#define DONOR_OFFSET 36
#define PUR_OFFSET 40
#define PUS_OFFSET 44

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

int runNds (const void* loader, u32 loaderSize, u32 cluster, u32 saveCluster, bool initDisc, bool dldiPatchNds, int argc, const char** argv)
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)
{
char* argStart;
u16* argData;
Expand Down Expand Up @@ -332,6 +335,9 @@ int runNds (const void* loader, u32 loaderSize, u32 cluster, u32 saveCluster, bo
writeAddr ((data_t*) LCDC_BANK_C, ARG_SIZE_OFFSET, argSize);

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

if(dldiPatchNds) {
// Patch the loader with a DLDI for the card
Expand Down Expand Up @@ -369,10 +375,12 @@ int runNds (const void* loader, u32 loaderSize, u32 cluster, u32 saveCluster, bo
return true;
}

int runNdsFile (const char* filename, const char* savename, 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) {
struct stat st;
struct stat stSav;
struct stat stDonor;
u32 clusterSav = 0;
u32 clusterDonor = 0;
char filePath[PATH_MAX];
int pathLen;
const char* args[1];
Expand All @@ -385,6 +393,10 @@ int runNdsFile (const char* filename, const char* savename, int argc, const char
if (stat (savename, &stSav) >= 0) {
clusterSav = stSav.st_ino;
}

if (stat (arm7DonorPath, &stDonor) >= 0) {
clusterDonor = stDonor.st_ino;
}

if (argc <= 0 || !argv) {
// Construct a command line if we weren't supplied with one
Expand All @@ -403,7 +415,7 @@ int runNdsFile (const char* filename, const char* savename, int argc, const char

//installBootStub(havedsiSD);

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

/*
Expand Down
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, bool initDisc, bool dldiPatchNds, int argc, const char** argv);
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 runNdsFile (const char* filename, const char* savename, 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);

bool installBootStub(bool havedsiSD);

Expand Down
22 changes: 11 additions & 11 deletions bootloader/source/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ void sdmmc_controller_init();
#define CHEAT_DATA_LOCATION 0x06010000
#define ENGINE_LOCATION_ARM7 0x03780000
#define ENGINE_LOCATION_ARM9 0x03700000
#define MARKER_ADDRESS_1 0x03740000
#define MARKER_ADDRESS_2 0x03746004

const char* bootName = "BOOT.NDS";

Expand All @@ -85,6 +83,9 @@ extern unsigned long argStart;
extern unsigned long argSize;
extern unsigned long dsiSD;
extern unsigned long saveFileCluster;
extern unsigned long donorFileCluster;
extern unsigned long patchMpuRegion;
extern unsigned long patchMpuSize;

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Firmware stuff
Expand Down Expand Up @@ -294,14 +295,17 @@ int main (void) {
_io_dldi.fn_isInserted = sdmmc_inserted;
_io_dldi.fn_startup = sdmmc_startup;
}

aFile file = getFileFromCluster (storedFileCluster);

// Init card
if(!FAT_InitFiles(initDisc))
{
nocashMessage("!FAT_InitFiles");
return -1;
}

aFile file = getFileFromCluster (storedFileCluster);
aFile donorFile = getFileFromCluster (donorFileCluster);

if ((file.firstCluster < CLUSTER_FIRST) || (file.firstCluster >= CLUSTER_EOF)) /* Invalid file cluster specified */
{
file = getBootFileCluster(bootName);
Expand Down Expand Up @@ -354,19 +358,15 @@ int main (void) {
} else {
nocashMessage("dldi Patch Unsuccessful try to patch card");
copyLoop (ENGINE_LOCATION_ARM7, (u32*)cardengine_arm7_bin, cardengine_arm7_bin_size);
copyLoop (ENGINE_LOCATION_ARM9, (u32*)cardengine_arm9_bin, cardengine_arm9_bin_size);

// set a synchronisation marker on the WRAM block
*((vu32*)MARKER_ADDRESS_1) = (vu32)0xDEADBABE;
*((vu32*)MARKER_ADDRESS_2) = (vu32)0xDEADBABE;
copyLoop (ENGINE_LOCATION_ARM9, (u32*)cardengine_arm9_bin, cardengine_arm9_bin_size);

module_params_t* params = findModuleParams(NDS_HEAD);
if(params)
{
ensureArm9Decompressed(NDS_HEAD, params);
}
patchCardNds(NDS_HEAD,ENGINE_LOCATION_ARM7,ENGINE_LOCATION_ARM9,params,saveFileCluster);

patchCardNds(NDS_HEAD,ENGINE_LOCATION_ARM7,ENGINE_LOCATION_ARM9,params,saveFileCluster, patchMpuRegion, patchMpuSize, donorFile);

int error = hookNdsRetail(NDS_HEAD, file, (const u32*)CHEAT_DATA_LOCATION, (u32*)CHEAT_ENGINE_LOCATION, (u32*)ENGINE_LOCATION_ARM7);
if(error == ERR_NONE) {
Expand Down
Loading