Skip to content

Commit

Permalink
Port recent commits from master
Browse files Browse the repository at this point in the history
Card read DMA commits not included
  • Loading branch information
RocketRobz committed Jun 26, 2019
1 parent 8492898 commit 28fa3b8
Show file tree
Hide file tree
Showing 23 changed files with 358 additions and 578 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,8 @@ build/
#!.vscode/launch.json
#!.vscode/extensions.json
retail/nitrofiles/cardengine_arm7.bin
retail/nitrofiles/cardengine_arm9_dldi.bin
retail/nitrofiles/cardengine_arm9_reloc.bin
retail/nitrofiles/cardengine_arm9_sdk5.bin
retail/nitrofiles/cardengine_arm9_sdk5_dldi.bin
retail/nitrofiles/load.bin
3 changes: 1 addition & 2 deletions retail/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ clean:
@$(MAKE) -C cardengine/arm9 clean
@$(MAKE) -C cardengine/arm9_reloc clean
@$(MAKE) -C cardengine/arm9_sdk5 clean
@$(MAKE) -C cardengine/arm9_sdk5_reloc clean
@$(MAKE) -C cardengine/arm9_sdk5_gsdd clean
@$(MAKE) -C cardengine/arm9_sdk5_dldi clean
@$(MAKE) -C bootloader clean

$(DATA):
Expand Down
7 changes: 3 additions & 4 deletions retail/arm9/include/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ typedef struct configuration {
bool boostVram;
bool gameSoftReset;
bool forceSleepPatch;
bool volumeFix;
bool preciseVolumeControl;
bool soundFix;
bool logging;
bool initDisc;
bool dldiPatchNds;
int argc;
const char** argv; //const char* argv[ARG_MAX];
bool gameOnFlashcard;
bool saveOnFlashcard;
u32 backlightMode;
} configuration;

Expand Down
53 changes: 14 additions & 39 deletions retail/arm9/source/conf_sd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,29 @@ int loadFromSD(configuration* conf, const char *bootstrapPath) {
mkdir("sd:/_nds/nds-bootstrap", 0777);
mkdir("sd:/_nds/nds-bootstrap/patchOffsetCache", 0777);
mkdir("sd:/_nds/nds-bootstrap/fatTable", 0777);
if (conf->ndsPath[0] == 'f' && conf->ndsPath[1] == 'a' && conf->ndsPath[2] == 't') {
conf->dldiPatchNds = true;
if (flashcardFound) {
mkdir("fat:/_nds", 0777);
mkdir("fat:/_nds/nds-bootstrap", 0777);
mkdir("fat:/_nds/nds-bootstrap/patchOffsetCache", 0777);
mkdir("fat:/_nds/nds-bootstrap/fatTable", 0777);
}

nitroFSInit(bootstrapPath);
conf->gameOnFlashcard = (conf->ndsPath[0] == 'f' && conf->ndsPath[1] == 'a' && conf->ndsPath[2] == 't');
conf->saveOnFlashcard = (conf->savPath[0] == 'f' && conf->savPath[1] == 'a' && conf->savPath[2] == 't');

if ((strncmp (bootstrapPath, "sd:/", 4) != 0) && (strncmp (bootstrapPath, "fat:/", 5) != 0)) {
//bootstrapPath = "sd:/_nds/nds-bootstrap-release.nds";
bootstrapPath = "sd:/_nds/nds-bootstrap-nightly.nds";
}
if (!nitroFSInit(bootstrapPath)) {
consoleDemoInit();
printf("nitroFSInit failed!\n");
return -1;
}

// Load ce7 binary
FILE* cebin = fopen("nitro:/cardengine_arm7.bin", "rb");
fread((void*)CARDENGINE_ARM7_BUFFERED_LOCATION, 1, 0x10000, cebin);
fread((void*)CARDENGINE_ARM7_BUFFERED_LOCATION, 1, 0x12000, cebin);
fclose(cebin);

// Load reloc ce9 binary
Expand Down Expand Up @@ -232,41 +242,6 @@ int loadFromSD(configuration* conf, const char *bootstrapPath) {
conf->saveSize = getFileSize(conf->savPath);
conf->cheatSize = getFileSize("sd:/_nds/nds-bootstrap/cheatData.bin");

conf->argc = 0;
conf->argv = (const char**)malloc(ARG_MAX);
if (strcasecmp(conf->ndsPath + strlen(conf->ndsPath) - 5, ".argv") == 0) {
FILE* argfile = fopen(conf->ndsPath, "rb");

char str[PATH_MAX];
char* pstr;
const char* seps = "\n\r\t ";

while (fgets(str, PATH_MAX, argfile)) {
// Find comment and end string there
if ((pstr = strchr(str, '#'))) {
*pstr = '\0';
}

// Tokenize arguments
pstr = strtok(str, seps);

while (pstr != NULL) {
conf->argv[conf->argc] = strdup(pstr);
++conf->argc;

pstr = strtok(NULL, seps);
}
}
fclose(argfile);

free(conf->ndsPath);
conf->ndsPath = strdup(conf->argv[0]);
} else {
conf->argv[0] = strdup(conf->ndsPath);
conf->argc = 1; //++conf->argc;
}
realloc(conf->argv, conf->argc*sizeof(const char*));

// Please wait screen
FILE* bootstrapImage = fopen("nitro:/pleasewait.bmp", "rb");
if (bootstrapImage) {
Expand Down
162 changes: 71 additions & 91 deletions retail/arm9/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ void* load_bin[0x10000];
std::string patchOffsetCacheFilePath;
std::string fatTableFilePath;

/* typedef struct {
typedef struct {
char gameTitle[12]; //!< 12 characters for the game title.
char gameCode[4]; //!< 4 characters for the game code.
} sNDSHeaderTitleCodeOnly; */
} sNDSHeaderTitleCodeOnly;

//extern bool logging;
//bool logging = false;
Expand Down Expand Up @@ -154,9 +154,8 @@ static inline void debugConf(configuration* conf) {
dbg_printf("forceSleepPatch: %s\n", btoa(conf->forceSleepPatch));
dbg_printf("logging: %s\n", btoa(conf->logging));
dbg_printf("initDisc: %s\n", btoa(conf->initDisc));
dbg_printf("dldiPatchNds: %s\n", btoa(conf->dldiPatchNds));
//dbg_printf("argc: %lu\n", conf->argc);
//const char** argv;
dbg_printf("gameOnFlashcard: %s\n", btoa(conf->gameOnFlashcard));
dbg_printf("saveOnFlashcard: %s\n", btoa(conf->saveOnFlashcard));
dbg_printf("backlightMode: %lX\n", conf->backlightMode);
}

Expand Down Expand Up @@ -194,81 +193,78 @@ static int runNdsFile(configuration* conf) {

// adjust TSC[1:26h] and TSC[1:27h]
// for certain gamecodes
/*FILE* f_nds_file = fopen(conf->ndsPath, "rb");
FILE* f_nds_file = fopen(conf->ndsPath, "rb");

char romTid[5];
fseek(f_nds_file, offsetof(sNDSHeaderTitleCodeOnly, gameCode), SEEK_SET);
fread(romTid, 1, 4, f_nds_file);
romTid[4] = 0;
romTid[3] = 0;
//romTid[2] = 0; // SDK 5
//romTid[1] = 0; // SDK 5
fclose(f_nds_file);

// SDK 5
//if (strcmp(romTid, "I") != 0) {
// fifoSendValue32(FIFO_USER_08, 1); // Disable Slot-1 access for games with no built-in infrared port
//}
if (strcmp(romTid, "ABX") == 0 // NTR-ABXE Bomberman Land Touch!
|| strcmp(romTid, "YO9") == 0 // NTR-YO9J Bokura no TV Game Kentei - Pikotto! Udedameshi
|| strcmp(romTid, "ALH") == 0 // NTR-ALHE Flushed Away
|| strcmp(romTid, "ACC") == 0 // NTR-ACCE Cooking Mama
|| strcmp(romTid, "YCQ") == 0 // NTR-YCQE Cooking Mama 2 - Dinner with Friends
|| strcmp(romTid, "YYK") == 0 // NTR-YYKE Trauma Center - Under the Knife 2
|| strcmp(romTid, "AZW") == 0 // NTR-AZWE WarioWare - Touched!
|| strcmp(romTid, "AKA") == 0 // NTR-AKAE Rub Rabbits!, The
|| strcmp(romTid, "AN9") == 0 // NTR-AN9E Little Mermaid - Ariel's Undersea Adventure, The
|| strcmp(romTid, "AKE") == 0 // NTR-AKEJ Keroro Gunsou - Enshuu da Yo! Zenin Shuugou Part 2
|| strcmp(romTid, "YFS") == 0 // NTR-YFSJ Frogman Show - DS Datte, Shouganaijanai, The
|| strcmp(romTid, "YG8") == 0 // NTR-YG8E Yu-Gi-Oh! World Championship 2008
|| strcmp(romTid, "AY7") == 0 // NTR-AY7E Yu-Gi-Oh! World Championship 2007
|| strcmp(romTid, "YON") == 0 // NTR-YONJ Minna no DS Seminar - Kantan Ongakuryoku
|| strcmp(romTid, "A5H") == 0 // NTR-A5HE Interactive Storybook DS - Series 2
|| strcmp(romTid, "A5I") == 0 // NTR-A5IE Interactive Storybook DS - Series 3
|| strcmp(romTid, "AMH") == 0 // NTR-AMHE Metroid Prime Hunters
|| strcmp(romTid, "A3T") == 0 // NTR-A3TE Tak - The Great Juju Challenge
|| strcmp(romTid, "YBO") == 0 // NTR-YBOE Boogie
|| strcmp(romTid, "ADA") == 0 // NTR-ADAE PKMN Diamond
|| strcmp(romTid, "APA") == 0 // NTR-APAE PKMN Pearl
|| strcmp(romTid, "CPU") == 0 // NTR-CPUE PKMN Platinum
|| strcmp(romTid, "APY") == 0 // NTR-APYE Puyo Pop Fever
|| strcmp(romTid, "AWH") == 0 // NTR-AWHE Bubble Bobble Double Shot
|| strcmp(romTid, "AXB") == 0 // NTR-AXBJ Daigassou! Band Brothers DX
|| strcmp(romTid, "A4U") == 0 // NTR-A4UJ Wi-Fi Taiou - Morita Shogi
|| strcmp(romTid, "A8N") == 0 // NTR-A8NE Planet Puzzle League
|| strcmp(romTid, "ABJ") == 0 // NTR-ABJE Harvest Moon DS - Island of Happiness
|| strcmp(romTid, "ABN") == 0 // NTR-ABNE Bomberman Story DS
|| strcmp(romTid, "ACL") == 0 // NTR-ACLE Custom Robo Arena
|| strcmp(romTid, "ART") == 0 // NTR-ARTJ Shin Lucky Star Moe Drill - Tabidachi
|| strcmp(romTid, "AVT") == 0 // NTR-AVTJ Kou Rate Ura Mahjong Retsuden Mukoubuchi - Goburei, Shuuryou desu ne
|| strcmp(romTid, "AWY") == 0 // NTR-AWYJ Wi-Fi Taiou - Gensen Table Game DS
|| strcmp(romTid, "AXJ") == 0 // NTR-AXJE Dungeon Explorer - Warriors of Ancient Arts
|| strcmp(romTid, "AYK") == 0 // NTR-AYKJ Wi-Fi Taiou - Yakuman DS
|| strcmp(romTid, "YB2") == 0 // NTR-YB2E Bomberman Land Touch! 2
|| strcmp(romTid, "YB3") == 0 // NTR-YB3E Harvest Moon DS - Sunshine Islands
|| strcmp(romTid, "YCH") == 0 // NTR-YCHJ Kousoku Card Battle - Card Hero
|| strcmp(romTid, "YFE") == 0 // NTR-YFEE Fire Emblem - Shadow Dragon
|| strcmp(romTid, "YGD") == 0 // NTR-YGDE Diary Girl
|| strcmp(romTid, "YKR") == 0 // NTR-YKRJ Culdcept DS
|| strcmp(romTid, "YRM") == 0 // NTR-YRME My Secret World by Imagine
|| strcmp(romTid, "YW2") == 0 // NTR-YW2E Advance Wars - Days of Ruin
|| strcmp(romTid, "AJU") == 0 // NTR-AJUJ Jump! Ultimate Stars
|| strcmp(romTid, "ACZ") == 0 // NTR-ACZE Cars
|| strcmp(romTid, "AHD") == 0 // NTR-AHDE Jam Sessions
|| strcmp(romTid, "ANR") == 0 // NTR-ANRE Naruto - Saikyou Ninja Daikesshu 3
|| strcmp(romTid, "YT3") == 0 // NTR-YT3E Tamagotchi Connection - Corner Shop 3
|| strcmp(romTid, "AVI") == 0 // NTR-AVIJ Kodomo no Tame no Yomi Kikase - Ehon de Asobou 1-Kan
|| strcmp(romTid, "AV2") == 0 // NTR-AV2J Kodomo no Tame no Yomi Kikase - Ehon de Asobou 2-Kan
|| strcmp(romTid, "AV3") == 0 // NTR-AV3J Kodomo no Tame no Yomi Kikase - Ehon de Asobou 3-Kan
|| strcmp(romTid, "AV4") == 0 // NTR-AV4J Kodomo no Tame no Yomi Kikase - Ehon de Asobou 4-Kan
|| strcmp(romTid, "AV5") == 0 // NTR-AV5J Kodomo no Tame no Yomi Kikase - Ehon de Asobou 5-Kan
|| strcmp(romTid, "AV6") == 0 // NTR-AV6J Kodomo no Tame no Yomi Kikase - Ehon de Asobou 6-Kan
|| strcmp(romTid, "YNZ") == 0 // NTR-YNZE Petz - Dogz Fashion
)
{
fifoSendValue32(FIFO_MAXMOD, 1); // Special setting (when found special gamecode)
}*/
static const char list[][4] = {
"ABX", // NTR-ABXE Bomberman Land Touch!
"YO9", // NTR-YO9J Bokura no TV Game Kentei - Pikotto! Udedameshi
"ALH", // NTR-ALHE Flushed Away
"ACC", // NTR-ACCE Cooking Mama
"YCQ", // NTR-YCQE Cooking Mama 2 - Dinner with Friends
"YYK", // NTR-YYKE Trauma Center - Under the Knife 2
"AZW", // NTR-AZWE WarioWare - Touched!
"AKA", // NTR-AKAE Rub Rabbits!, The
"AN9", // NTR-AN9E Little Mermaid - Ariel's Undersea Adventure, The
"AKE", // NTR-AKEJ Keroro Gunsou - Enshuu da Yo! Zenin Shuugou Part 2
"YFS", // NTR-YFSJ Frogman Show - DS Datte, Shouganaijanai, The
"YG8", // NTR-YG8E Yu-Gi-Oh! World Championship 2008
"AY7", // NTR-AY7E Yu-Gi-Oh! World Championship 2007
"YON", // NTR-YONJ Minna no DS Seminar - Kantan Ongakuryoku
"A5H", // NTR-A5HE Interactive Storybook DS - Series 2
"A5I", // NTR-A5IE Interactive Storybook DS - Series 3
"AMH", // NTR-AMHE Metroid Prime Hunters
"A3T", // NTR-A3TE Tak - The Great Juju Challenge
"YBO", // NTR-YBOE Boogie
"ADA", // NTR-ADAE PKMN Diamond
"APA", // NTR-APAE PKMN Pearl
"CPU", // NTR-CPUE PKMN Platinum
"APY", // NTR-APYE Puyo Pop Fever
"AWH", // NTR-AWHE Bubble Bobble Double Shot
"AXB", // NTR-AXBJ Daigassou! Band Brothers DX
"A4U", // NTR-A4UJ Wi-Fi Taiou - Morita Shogi
"A8N", // NTR-A8NE Planet Puzzle League
"ABJ", // NTR-ABJE Harvest Moon DS - Island of Happiness
"ABN", // NTR-ABNE Bomberman Story DS
"ACL", // NTR-ACLE Custom Robo Arena
"ART", // NTR-ARTJ Shin Lucky Star Moe Drill - Tabidachi
"AVT", // NTR-AVTJ Kou Rate Ura Mahjong Retsuden Mukoubuchi - Goburei, Shuuryou desu ne
"AWY", // NTR-AWYJ Wi-Fi Taiou - Gensen Table Game DS
"AXJ", // NTR-AXJE Dungeon Explorer - Warriors of Ancient Arts
"AYK", // NTR-AYKJ Wi-Fi Taiou - Yakuman DS
"YB2", // NTR-YB2E Bomberman Land Touch! 2
"YB3", // NTR-YB3E Harvest Moon DS - Sunshine Islands
"YCH", // NTR-YCHJ Kousoku Card Battle - Card Hero
"YFE", // NTR-YFEE Fire Emblem - Shadow Dragon
"YGD", // NTR-YGDE Diary Girl
"YKR", // NTR-YKRJ Culdcept DS
"YRM", // NTR-YRME My Secret World by Imagine
"YW2", // NTR-YW2E Advance Wars - Days of Ruin
"AJU", // NTR-AJUJ Jump! Ultimate Stars
"ACZ", // NTR-ACZE Cars
"AHD", // NTR-AHDE Jam Sessions
"ANR", // NTR-ANRE Naruto - Saikyou Ninja Daikesshu 3
"YT3", // NTR-YT3E Tamagotchi Connection - Corner Shop 3
"AVI", // NTR-AVIJ Kodomo no Tame no Yomi Kikase - Ehon de Asobou 1-Kan
"AV2", // NTR-AV2J Kodomo no Tame no Yomi Kikase - Ehon de Asobou 2-Kan
"AV3", // NTR-AV3J Kodomo no Tame no Yomi Kikase - Ehon de Asobou 3-Kan
"AV4", // NTR-AV4J Kodomo no Tame no Yomi Kikase - Ehon de Asobou 4-Kan
"AV5", // NTR-AV5J Kodomo no Tame no Yomi Kikase - Ehon de Asobou 5-Kan
"AV6", // NTR-AV6J Kodomo no Tame no Yomi Kikase - Ehon de Asobou 6-Kan
"YNZ", // NTR-YNZE Petz - Dogz Fashion
};

for (unsigned int i = 0; i < sizeof(list) / sizeof(list[0]); i++) {
if (memcmp(romTid, list[i], 3) == 0) {
// Found a match.
conf->volumeFix = true; // Special setting (when found special gamecode)
break;
}
}

// Boost CPU
if (conf->boostCpu) {
Expand Down Expand Up @@ -307,7 +303,7 @@ static int runNdsFile(configuration* conf) {

debugConf(conf);

if (strcasecmp(conf->ndsPath + strlen(conf->ndsPath) - 4, ".nds") != 0 || conf->argc == 0) {
if (strcasecmp(conf->ndsPath + strlen(conf->ndsPath) - 4, ".nds") != 0) {
dbg_printf("No NDS file specified\n");
if (debug) {
dopause();
Expand Down Expand Up @@ -369,20 +365,6 @@ static int runNdsFile(configuration* conf) {
clusterFatTable = stFatTable.st_ino;
}

if (conf->argc <= 0 || !conf->argv) {
// Construct a command line if we weren't supplied with one
if (!getcwd(filePath, PATH_MAX)) {
return -3;
}
pathLen = strlen(filePath);
strcpy(filePath + pathLen, conf->ndsPath);
//args[0] = filePath;
//conf->argv = args;
memset(conf->argv, 0, conf->argc*sizeof(const char*));
conf->argv[0] = filePath;
conf->argc = 1;
}

//bool havedsiSD = false;
//bool havedsiSD = (argv[0][0] == 's' && argv[0][1] == 'd');

Expand All @@ -402,7 +384,6 @@ static int runNdsFile(configuration* conf) {
int main(int argc, char** argv) {
configuration* conf = (configuration*)malloc(sizeof(configuration));
conf->initDisc = true;
conf->dldiPatchNds = false;

int status = loadFromSD(conf, argv[0]);

Expand All @@ -417,7 +398,6 @@ int main(int argc, char** argv) {
if (status != 0) {
free(conf->ndsPath);
free(conf->savPath);
free(conf->argv);
free(conf);

stop();
Expand Down
Loading

0 comments on commit 28fa3b8

Please sign in to comment.