Check if .nds (or .gba) file is created before dumping

This commit is contained in:
RocketRobz 2021-01-24 14:18:20 -07:00
parent ada2974435
commit edd514aad5

View File

@ -282,6 +282,12 @@ void ndsCardDump(void) {
tonccpy(gameTitle, ndsCardHeader.gameTitle, 12); tonccpy(gameTitle, ndsCardHeader.gameTitle, 12);
char gameCode[7] = {0}; char gameCode[7] = {0};
tonccpy(gameCode, ndsCardHeader.gameCode, 6); tonccpy(gameCode, ndsCardHeader.gameCode, 6);
if (gameTitle[0] == 0 || gameTitle[0] == 0x2E || gameTitle[0] == 0xFF) {
sprintf(gameTitle, "NO-TITLE");
}
if (gameCode[0] == 0 || gameCode[0] == 0x23 || gameCode[0] == 0xFF) {
sprintf(gameCode, "NONE00");
}
bool trimRom = (pressed & KEY_Y); bool trimRom = (pressed & KEY_Y);
char destPath[256]; 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" : ""));
@ -441,26 +447,28 @@ void ndsCardDump(void) {
remove(destPath); remove(destPath);
u32 currentSize = romSize; u32 currentSize = romSize;
FILE* destinationFile = fopen(destPath, "wb"); FILE* destinationFile = fopen(destPath, "wb");
for (u32 src = 0; src < romSize; src += 0x8000) { if (destinationFile) {
consoleSelect(&topConsole); for (u32 src = 0; src < romSize; src += 0x8000) {
printf ("\x1B[30m"); // Print black color consoleSelect(&topConsole);
// Move to right side of screen printf ("\x1B[30m"); // Print black color
printf ("\x1b[0;26H"); // Move to right side of screen
// Print time printf ("\x1b[0;26H");
printf (" %s" ,RetTime().c_str()); // Print time
printf (" %s" ,RetTime().c_str());
consoleSelect(&bottomConsole); consoleSelect(&bottomConsole);
printf ("\x1B[47m"); // Print foreground white color printf ("\x1B[47m"); // Print foreground white color
printf ("\x1b[8;0H"); printf ("\x1b[8;0H");
printf ("Progress:\n"); printf ("Progress:\n");
printf ("%i/%i Bytes", (int)src, (int)romSize); printf ("%i/%i Bytes", (int)src, (int)romSize);
for (u32 i = 0; i < 0x8000; i += 0x200) { for (u32 i = 0; i < 0x8000; i += 0x200) {
cardRead (src+i, copyBuf+i); cardRead (src+i, copyBuf+i);
}
fwrite(copyBuf, 1, (currentSize>=0x8000 ? 0x8000 : currentSize), destinationFile);
currentSize -= 0x8000;
} }
fwrite(copyBuf, 1, (currentSize>=0x8000 ? 0x8000 : currentSize), destinationFile); fclose(destinationFile);
currentSize -= 0x8000;
} }
fclose(destinationFile);
ndsCardSaveDump(destSavPath); ndsCardSaveDump(destSavPath);
//} //}
} }
@ -576,30 +584,32 @@ void gbaCartDump(void) {
}; };
writeChange(rstCmd); writeChange(rstCmd);
FILE* destinationFile = fopen(destPath, "wb"); FILE* destinationFile = fopen(destPath, "wb");
fwrite(GBAROM, 1, romSize, destinationFile); if (destinationFile) {
// Check for 64MB GBA Video ROM fwrite(GBAROM, 1, romSize, destinationFile);
if (strncmp((char*)0x080000AC, "MSAE", 4)==0 // Shark Tale // Check for 64MB GBA Video ROM
|| strncmp((char*)0x080000AC, "MSKE", 4)==0 // Shrek if (strncmp((char*)0x080000AC, "MSAE", 4)==0 // Shark Tale
|| strncmp((char*)0x080000AC, "MSTE", 4)==0 // Shrek & Shark Tale || strncmp((char*)0x080000AC, "MSKE", 4)==0 // Shrek
|| strncmp((char*)0x080000AC, "M2SE", 4)==0 // Shrek 2 || strncmp((char*)0x080000AC, "MSTE", 4)==0 // Shrek & Shark Tale
) { || strncmp((char*)0x080000AC, "M2SE", 4)==0 // Shrek 2
// Dump last 32MB ) {
u32 cmd[4] = { // Dump last 32MB
0x11, // Command u32 cmd[4] = {
0, // ROM address 0x11, // Command
0x08001000, // Virtual address 0, // ROM address
0x8, // Size (in 0x200 byte blocks) 0x08001000, // Virtual address
}; 0x8, // Size (in 0x200 byte blocks)
};
size_t i; size_t i;
for (i = 0x02000000; i < 0x04000000; i += 0x1000) { for (i = 0x02000000; i < 0x04000000; i += 0x1000) {
cmd[1] = i, cmd[1] = i,
writeChange(cmd); writeChange(cmd);
readChange(); readChange();
fwrite(GBAROM + (0x1000 >> 1), 0x1000, 1, destinationFile); fwrite(GBAROM + (0x1000 >> 1), 0x1000, 1, destinationFile);
}
} }
fclose(destinationFile);
} }
fclose(destinationFile);
// Save file // Save file
remove(destSavPath); remove(destSavPath);
destinationFile = fopen(destSavPath, "wb"); destinationFile = fopen(destSavPath, "wb");