Bug fixes

This commit is contained in:
RocketRobz 2020-02-04 01:24:08 -07:00
parent 5b3b31f743
commit 9b4876a8e4
3 changed files with 26 additions and 17 deletions

View File

@ -14,6 +14,8 @@
extern PrintConsole topConsole, bottomConsole;
static sNDSHeaderExt ndsCardHeader;
void ndsCardSaveDump(const char* filename) {
std::ofstream output(filename, std::ofstream::binary);
if(output.is_open()) {
@ -88,9 +90,7 @@ void ndsCardDump(void) {
mkdir(folderPath[1], 0777);
}
consoleClear();
// Read header
sNDSHeaderExt* ndsCardHeader = (sNDSHeaderExt*)malloc(0x1000);
if (cardInit (ndsCardHeader) == 0) {
if (cardInit(&ndsCardHeader) == 0) {
printf("Dumping...\n");
printf("Do not remove the NDS card.\n");
} else {
@ -98,25 +98,24 @@ void ndsCardDump(void) {
for (int i = 0; i < 60*2; i++) {
swiWaitForVBlank();
}
free(ndsCardHeader);
return;
}
char gameTitle[13] = {0};
tonccpy(gameTitle, ndsCardHeader->gameTitle, 12);
tonccpy(gameTitle, ndsCardHeader.gameTitle, 12);
char gameCode[7] = {0};
tonccpy(gameCode, ndsCardHeader->gameCode, 6);
tonccpy(gameCode, ndsCardHeader.gameCode, 6);
bool trimRom = (pressed & KEY_Y);
char romBuffer[0x200];
char destPath[256];
sprintf(destPath, "%s:/gm9i/out/%s_%s_%x%s.nds", (sdMounted ? "sd" : "fat"), gameTitle, gameCode, ndsCardHeader->romversion, (trimRom ? "_trim" : ""));
sprintf(destPath, "%s:/gm9i/out/%s_%s_%x%s.nds", (sdMounted ? "sd" : "fat"), gameTitle, gameCode, ndsCardHeader.romversion, (trimRom ? "_trim" : ""));
char destSavPath[256];
sprintf(destSavPath, "%s:/gm9i/out/%s_%s_%x%s.sav", (sdMounted ? "sd" : "fat"), gameTitle, gameCode, ndsCardHeader->romversion, (trimRom ? "_trim" : ""));
sprintf(destSavPath, "%s:/gm9i/out/%s_%s_%x%s.sav", (sdMounted ? "sd" : "fat"), gameTitle, gameCode, ndsCardHeader.romversion, (trimRom ? "_trim" : ""));
// Determine ROM size
u32 romSize = 0;
if (trimRom) {
romSize = ((ndsCardHeader->unitCode != 0) && (ndsCardHeader->twlRomSize > 0))
? ndsCardHeader->twlRomSize : ndsCardHeader->romSize;
} else switch (ndsCardHeader->deviceSize) {
romSize = ((ndsCardHeader.unitCode != 0) && (ndsCardHeader.twlRomSize > 0))
? ndsCardHeader.twlRomSize : ndsCardHeader.romSize;
} else switch (ndsCardHeader.deviceSize) {
case 0x00:
romSize = 0x20000;
break;
@ -168,6 +167,8 @@ void ndsCardDump(void) {
// Print time
printf ("_%s" ,RetTime().c_str());
consoleSelect(&bottomConsole);
printf ("\x1B[47m"); // Print foreground white color
printf ("\x1b[8;0H");
printf ("Progress:\n");
printf ("%i/%i Bytes ", (int)src, (int)romSize);
@ -176,7 +177,6 @@ void ndsCardDump(void) {
}
fclose(destinationFile);
ndsCardSaveDump(destSavPath);
free(ndsCardHeader);
}
}

View File

@ -590,6 +590,9 @@ string browseForFile (void) {
// Rename file/folder
if ((held & KEY_R) && (pressed & KEY_X) && (strcmp (entry->name.c_str(), "..") != 0) && (strncmp (path, "nitro:/", 7) != 0)) {
printf ("\x1b[0;27H");
printf ("\x1B[42m"); // Print green color
printf ("_____"); // Clear time
pressed = 0;
consoleDemoInit();
Keyboard *kbd = keyboardDemoInit();
@ -698,6 +701,9 @@ string browseForFile (void) {
// Create new folder
if ((held & KEY_R) && (pressed & KEY_Y) && (strncmp (path, "nitro:/", 7) != 0)) {
printf ("\x1b[0;27H");
printf ("\x1B[42m"); // Print green color
printf ("_____"); // Clear time
pressed = 0;
consoleDemoInit();
Keyboard *kbd = keyboardDemoInit();

View File

@ -291,6 +291,8 @@ int cardInit (sNDSHeaderExt* ndsHeader)
NULL, 0);
}
toncset(headerData, 0, 0x1000);
u32 iCardId=cardReadID(CARD_CLK_SLOW);
while(REG_ROMCTRL & CARD_BUSY);
//u32 iCheapCard=iCardId&0x80000000;
@ -298,19 +300,22 @@ int cardInit (sNDSHeaderExt* ndsHeader)
// Read the header
cardParamCommand (CARD_CMD_HEADER_READ, 0,
CARD_ACTIVATE | CARD_nRESET | CARD_CLK_SLOW | CARD_BLK_SIZE(1) | CARD_DELAY1(0x1FFF) | CARD_DELAY2(0x3F),
(void*)ndsHeader, 0x200/sizeof(u32));
(void*)headerData, 0x200/sizeof(u32));
tonccpy(ndsHeader, headerData, 0x200);
if ((ndsHeader->unitCode != 0) || (ndsHeader->dsi_flags != 0))
{
// Extended header found
cardParamCommand (CARD_CMD_HEADER_READ, 0,
CARD_ACTIVATE | CARD_nRESET | CARD_CLK_SLOW | CARD_BLK_SIZE(4) | CARD_DELAY1(0x1FFF) | CARD_DELAY2(0x3F),
(void*)ndsHeader, 0x1000/sizeof(u32));
(void*)headerData, 0x1000/sizeof(u32));
if (ndsHeader->dsi1[0]==0xFFFFFFFF && ndsHeader->dsi1[1]==0xFFFFFFFF
&& ndsHeader->dsi1[2]==0xFFFFFFFF && ndsHeader->dsi1[3]==0xFFFFFFFF)
{
toncset((u8*)ndsHeader+0x200, 0, 0xE00);
toncset((u8*)headerData+0x200, 0, 0xE00); // Clear out FFs
}
tonccpy(ndsHeader, headerData, sizeof(sNDSHeaderExt));
}
// Check header CRC
@ -318,8 +323,6 @@ int cardInit (sNDSHeaderExt* ndsHeader)
return ERR_HEAD_CRC;
}
tonccpy(headerData, ndsHeader, 0x1000);
/*
// Check logo CRC
if (ndsHeader->logoCRC16 != 0xCF56) {