Do not clear time, except for GBA ROM dumping

This commit is contained in:
RocketRobz 2020-02-04 00:56:47 -07:00
parent e60993ec3e
commit 35583045b2
3 changed files with 257 additions and 187 deletions

View File

@ -6,6 +6,7 @@
#include <fstream>
#include "auxspi.h"
#include "date.h"
#include "driveOperations.h"
#include "ndsheaderbanner.h"
#include "read_card.h"
@ -48,208 +49,225 @@ void ndsCardSaveDump(const char* filename) {
void ndsCardDump(void) {
int pressed = 0;
printf ("\x1b[0;27H");
printf ("\x1B[42m"); // Print green color
printf ("_____"); // Clear time
consoleSelect(&bottomConsole);
consoleClear();
printf ("\x1B[47m"); // Print foreground white color
printf("Dump NDS card ROM to\n");
printf("\"%s:/gm9i/out\"?\n", (sdMounted ? "sd" : "fat"));
printf("(<A> yes, <Y> trim, <B> no)");
while (true) {
// Power saving loop. Only poll the keys once per frame and sleep the CPU if there is nothing else to do
do {
scanKeys();
pressed = keysDownRepeat();
swiWaitForVBlank();
} while (!(pressed & KEY_A) && !(pressed & KEY_Y) && !(pressed & KEY_B));
if ((pressed & KEY_A) || (pressed & KEY_Y)) {
consoleClear();
char folderPath[2][256];
sprintf(folderPath[0], "%s:/gm9i", (sdMounted ? "sd" : "fat"));
sprintf(folderPath[1], "%s:/gm9i/out", (sdMounted ? "sd" : "fat"));
if (access(folderPath[0], F_OK) != 0) {
printf("Creating directory...");
mkdir(folderPath[0], 0777);
consoleSelect(&topConsole);
printf ("\x1B[42m"); // Print green color
// Power saving loop. Only poll the keys once per frame and sleep the CPU if there is nothing else to do
do {
// Move to right side of screen
printf ("\x1b[0;26H");
// Print time
printf ("_%s" ,RetTime().c_str());
scanKeys();
pressed = keysDownRepeat();
swiWaitForVBlank();
} while (!(pressed & KEY_A) && !(pressed & KEY_Y) && !(pressed & KEY_B));
consoleSelect(&bottomConsole);
printf ("\x1B[47m"); // Print foreground white color
if ((pressed & KEY_A) || (pressed & KEY_Y)) {
consoleClear();
char folderPath[2][256];
sprintf(folderPath[0], "%s:/gm9i", (sdMounted ? "sd" : "fat"));
sprintf(folderPath[1], "%s:/gm9i/out", (sdMounted ? "sd" : "fat"));
if (access(folderPath[0], F_OK) != 0) {
printf("Creating directory...");
mkdir(folderPath[0], 0777);
}
if (access(folderPath[1], F_OK) != 0) {
printf ("\x1b[0;0H");
printf("Creating directory...");
mkdir(folderPath[1], 0777);
}
consoleClear();
// Read header
sNDSHeaderExt* ndsCardHeader = (sNDSHeaderExt*)malloc(0x1000);
if (cardInit (ndsCardHeader) == 0) {
printf("Dumping...\n");
printf("Do not remove the NDS card.\n");
} else {
printf("Unable to dump the ROM.\n");
for (int i = 0; i < 60*2; i++) {
swiWaitForVBlank();
}
if (access(folderPath[1], F_OK) != 0) {
printf ("\x1b[0;0H");
printf("Creating directory...");
mkdir(folderPath[1], 0777);
}
consoleClear();
// Read header
sNDSHeaderExt* ndsCardHeader = (sNDSHeaderExt*)malloc(0x1000);
if (cardInit (ndsCardHeader) == 0) {
printf("Dumping...\n");
printf("Do not remove the NDS card.\n");
} else {
printf("Unable to dump the ROM.\n");
for (int i = 0; i < 60*2; i++) {
swiWaitForVBlank();
}
free(ndsCardHeader);
return;
}
char gameTitle[13] = {0};
tonccpy(gameTitle, ndsCardHeader->gameTitle, 12);
char gameCode[7] = {0};
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" : ""));
char destSavPath[256];
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) {
case 0x00:
romSize = 0x20000;
break;
case 0x01:
romSize = 0x40000;
break;
case 0x02:
romSize = 0x80000;
break;
case 0x03:
romSize = 0x100000;
break;
case 0x04:
romSize = 0x200000;
break;
case 0x05:
romSize = 0x400000;
break;
case 0x06:
romSize = 0x800000;
break;
case 0x07:
romSize = 0x1000000;
break;
case 0x08:
romSize = 0x2000000;
break;
case 0x09:
romSize = 0x4000000;
break;
case 0x0A:
romSize = 0x8000000;
break;
case 0x0B:
romSize = 0x10000000;
break;
case 0x0C:
romSize = 0x20000000;
break;
}
// Dump!
remove(destPath);
FILE* destinationFile = fopen(destPath, "wb");
for (u32 src = 0; src < romSize; src += 0x200) {
printf ("\x1b[8;0H");
printf ("Progress:\n");
printf ("%i/%i Bytes ", (int)src, (int)romSize);
cardRead (src, romBuffer);
fwrite(romBuffer, 1, 0x200, destinationFile);
}
fclose(destinationFile);
ndsCardSaveDump(destSavPath);
free(ndsCardHeader);
break;
return;
}
if (pressed & KEY_B) {
break;
char gameTitle[13] = {0};
tonccpy(gameTitle, ndsCardHeader->gameTitle, 12);
char gameCode[7] = {0};
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" : ""));
char destSavPath[256];
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) {
case 0x00:
romSize = 0x20000;
break;
case 0x01:
romSize = 0x40000;
break;
case 0x02:
romSize = 0x80000;
break;
case 0x03:
romSize = 0x100000;
break;
case 0x04:
romSize = 0x200000;
break;
case 0x05:
romSize = 0x400000;
break;
case 0x06:
romSize = 0x800000;
break;
case 0x07:
romSize = 0x1000000;
break;
case 0x08:
romSize = 0x2000000;
break;
case 0x09:
romSize = 0x4000000;
break;
case 0x0A:
romSize = 0x8000000;
break;
case 0x0B:
romSize = 0x10000000;
break;
case 0x0C:
romSize = 0x20000000;
break;
}
// Dump!
remove(destPath);
FILE* destinationFile = fopen(destPath, "wb");
for (u32 src = 0; src < romSize; src += 0x200) {
consoleSelect(&topConsole);
printf ("\x1B[42m"); // Print green color
// Move to right side of screen
printf ("\x1b[0;26H");
// Print time
printf ("_%s" ,RetTime().c_str());
printf ("\x1b[8;0H");
printf ("Progress:\n");
printf ("%i/%i Bytes ", (int)src, (int)romSize);
cardRead (src, romBuffer);
fwrite(romBuffer, 1, 0x200, destinationFile);
}
fclose(destinationFile);
ndsCardSaveDump(destSavPath);
free(ndsCardHeader);
}
}
void gbaCartDump(void) {
int pressed = 0;
printf ("\x1b[0;27H");
printf ("\x1B[42m"); // Print green color
printf ("_____"); // Clear time
consoleSelect(&bottomConsole);
consoleClear();
printf ("\x1B[47m"); // Print foreground white color
printf("Dump GBA cart ROM to\n");
printf("\"fat:/gm9i/out\"?\n");
printf("(<A> yes, <B> no)");
while (true) {
// Power saving loop. Only poll the keys once per frame and sleep the CPU if there is nothing else to do
do {
scanKeys();
pressed = keysDownRepeat();
swiWaitForVBlank();
} while (!(pressed & KEY_A) && !(pressed & KEY_B));
if (pressed & KEY_A) {
consoleClear();
if (access("fat:/gm9i", F_OK) != 0) {
printf("Creating directory...");
mkdir("fat:/gm9i", 0777);
}
if (access("fat:/gm9i/out", F_OK) != 0) {
printf ("\x1b[0;0H");
printf("Creating directory...");
mkdir("fat:/gm9i/out", 0777);
}
char gbaHeaderGameTitle[13] = "\0";
char gbaHeaderGameCode[5] = "\0";
char gbaHeaderMakerCode[3] = "\0";
for (int i = 0; i < 12; i++) {
gbaHeaderGameTitle[i] = *(char*)(0x080000A0+i);
if (*(u8*)(0x080000A0+i) == 0) {
break;
}
}
for (int i = 0; i < 4; i++) {
gbaHeaderGameCode[i] = *(char*)(0x080000AC+i);
if (*(u8*)(0x080000AC+i) == 0) {
break;
}
}
for (int i = 0; i < 2; i++) {
gbaHeaderMakerCode[i] = *(char*)(0x080000B0+i);
}
u8 gbaHeaderSoftwareVersion = *(u8*)(0x080000BC);
char destPath[256];
char destSavPath[256];
snprintf(destPath, sizeof(destPath), "fat:/gm9i/out/%s_%s%s_%x.gba", gbaHeaderGameTitle, gbaHeaderGameCode, gbaHeaderMakerCode, gbaHeaderSoftwareVersion);
snprintf(destSavPath, sizeof(destSavPath), "fat:/gm9i/out/%s_%s%s_%x.sav", gbaHeaderGameTitle, gbaHeaderGameCode, gbaHeaderMakerCode, gbaHeaderSoftwareVersion);
consoleClear();
printf("Dumping...\n");
printf("Do not remove the GBA cart.\n");
// Determine ROM size
u32 romSize = 0x02000000;
for (u32 i = 0x09FE0000; i > 0x08000000; i -= 0x20000) {
if (*(u32*)(i) == 0xFFFE0000) {
romSize -= 0x20000;
} else {
break;
}
}
// Dump!
remove(destPath);
FILE* destinationFile = fopen(destPath, "wb");
fwrite((void*)0x08000000, 1, romSize, destinationFile);
fclose(destinationFile);
// Save file
remove(destSavPath);
destinationFile = fopen(destSavPath, "wb");
fwrite((void*)0x0A000000, 1, 0x10000, destinationFile);
fclose(destinationFile);
break;
consoleSelect(&topConsole);
printf ("\x1B[42m"); // Print green color
// Power saving loop. Only poll the keys once per frame and sleep the CPU if there is nothing else to do
do {
// Move to right side of screen
printf ("\x1b[0;26H");
// Print time
printf ("_%s" ,RetTime().c_str());
scanKeys();
pressed = keysDownRepeat();
swiWaitForVBlank();
} while (!(pressed & KEY_A) && !(pressed & KEY_B));
if (pressed & KEY_A) {
printf ("\x1b[0;27H");
printf ("\x1B[42m"); // Print green color
printf ("_____"); // Clear time
}
consoleSelect(&bottomConsole);
printf ("\x1B[47m"); // Print foreground white color
if (pressed & KEY_A) {
consoleClear();
if (access("fat:/gm9i", F_OK) != 0) {
printf("Creating directory...");
mkdir("fat:/gm9i", 0777);
}
if (pressed & KEY_B) {
break;
if (access("fat:/gm9i/out", F_OK) != 0) {
printf ("\x1b[0;0H");
printf("Creating directory...");
mkdir("fat:/gm9i/out", 0777);
}
char gbaHeaderGameTitle[13] = "\0";
char gbaHeaderGameCode[5] = "\0";
char gbaHeaderMakerCode[3] = "\0";
for (int i = 0; i < 12; i++) {
gbaHeaderGameTitle[i] = *(char*)(0x080000A0+i);
if (*(u8*)(0x080000A0+i) == 0) {
break;
}
}
for (int i = 0; i < 4; i++) {
gbaHeaderGameCode[i] = *(char*)(0x080000AC+i);
if (*(u8*)(0x080000AC+i) == 0) {
break;
}
}
for (int i = 0; i < 2; i++) {
gbaHeaderMakerCode[i] = *(char*)(0x080000B0+i);
}
u8 gbaHeaderSoftwareVersion = *(u8*)(0x080000BC);
char destPath[256];
char destSavPath[256];
snprintf(destPath, sizeof(destPath), "fat:/gm9i/out/%s_%s%s_%x.gba", gbaHeaderGameTitle, gbaHeaderGameCode, gbaHeaderMakerCode, gbaHeaderSoftwareVersion);
snprintf(destSavPath, sizeof(destSavPath), "fat:/gm9i/out/%s_%s%s_%x.sav", gbaHeaderGameTitle, gbaHeaderGameCode, gbaHeaderMakerCode, gbaHeaderSoftwareVersion);
consoleClear();
printf("Dumping...\n");
printf("Do not remove the GBA cart.\n");
// Determine ROM size
u32 romSize = 0x02000000;
for (u32 i = 0x09FE0000; i > 0x08000000; i -= 0x20000) {
if (*(u32*)(i) == 0xFFFE0000) {
romSize -= 0x20000;
} else {
break;
}
}
// Dump!
remove(destPath);
FILE* destinationFile = fopen(destPath, "wb");
fwrite((void*)0x08000000, 1, romSize, destinationFile);
fclose(destinationFile);
// Save file
remove(destSavPath);
destinationFile = fopen(destSavPath, "wb");
fwrite((void*)0x0A000000, 1, 0x10000, destinationFile);
fclose(destinationFile);
}
}

View File

@ -5,6 +5,7 @@
#include <dirent.h>
#include <vector>
#include "date.h"
#include "file_browse.h"
using namespace std;
@ -13,6 +14,8 @@ using namespace std;
u32 copyBuf[copyBufSize];
extern PrintConsole topConsole, bottomConsole;
char clipboard[256];
char clipboardFilename[256];
bool clipboardFolder = false;
@ -121,6 +124,15 @@ int fcopy(const char *sourcePath, const char *destinationPath)
return -1;
break;
}
consoleSelect(&topConsole);
printf ("\x1B[42m"); // Print green color
// Move to right side of screen
printf ("\x1b[0;26H");
// Print time
printf ("_%s" ,RetTime().c_str());
consoleSelect(&bottomConsole);
printf ("\x1B[47m"); // Print foreground white color
printf ("\x1b[16;0H");
printf ("Progress:\n");
printf ("%i/%i Bytes ", (int)offset, (int)fsize);
@ -182,6 +194,8 @@ void changeFileAttribs(DirEntry* entry) {
printf ("\x1b[%i;0H", 9+cursorScreenPos);
printf ("(UDRL to change attributes)");
while (1) {
consoleSelect(&bottomConsole);
printf ("\x1B[47m"); // Print foreground white color
printf ("\x1b[%i;1H", 5+cursorScreenPos);
printf ((newAttribs & ATTR_READONLY) ? "X" : " ");
printf ("\x1b[%i;18H", 5+cursorScreenPos);
@ -193,8 +207,15 @@ void changeFileAttribs(DirEntry* entry) {
printf ("\x1b[%i;0H", 11+cursorScreenPos);
printf ((currentAttribs==newAttribs) ? "(<A> to continue) " : "(<A> to apply, <B> to cancel)");
consoleSelect(&topConsole);
printf ("\x1B[42m"); // Print green color
// Power saving loop. Only poll the keys once per frame and sleep the CPU if there is nothing else to do
do {
// Move to right side of screen
printf ("\x1b[0;26H");
// Print time
printf ("_%s" ,RetTime().c_str());
scanKeys();
pressed = keysDown();
swiWaitForVBlank();

View File

@ -184,9 +184,6 @@ int fileBrowse_A(DirEntry* entry, char path[PATH_MAX]) {
int cursorScreenPos = 0;
int maxCursors = -1;
printf ("\x1b[0;27H");
printf ("\x1B[42m"); // Print green color
printf ("_____"); // Clear time
consoleSelect(&bottomConsole);
consoleClear();
printf ("\x1B[47m"); // Print foreground white color
@ -232,6 +229,8 @@ int fileBrowse_A(DirEntry* entry, char path[PATH_MAX]) {
}
printf("\n");
printf("(<A> select, <B> cancel)");
consoleSelect(&bottomConsole);
printf ("\x1B[47m"); // Print foreground white color
while (true) {
// Clear old cursors
for (int i = OPTIONS_ENTRIES_START_ROW+cursorScreenPos; i < (maxCursors+1) + OPTIONS_ENTRIES_START_ROW+cursorScreenPos; i++) {
@ -240,14 +239,24 @@ int fileBrowse_A(DirEntry* entry, char path[PATH_MAX]) {
// Show cursor
iprintf ("\x1b[%d;0H->", optionOffset + OPTIONS_ENTRIES_START_ROW+cursorScreenPos);
consoleSelect(&topConsole);
printf ("\x1B[42m"); // Print green color for time text
// Power saving loop. Only poll the keys once per frame and sleep the CPU if there is nothing else to do
do {
// Move to right side of screen
printf ("\x1b[0;26H");
// Print time
printf ("_%s" ,RetTime().c_str());
scanKeys();
pressed = keysDownRepeat();
swiWaitForVBlank();
} while (!(pressed & KEY_UP) && !(pressed & KEY_DOWN)
&& !(pressed & KEY_A) && !(pressed & KEY_B));
consoleSelect(&bottomConsole);
printf ("\x1B[47m"); // Print foreground white color
if (pressed & KEY_UP) optionOffset -= 1;
if (pressed & KEY_DOWN) optionOffset += 1;
@ -317,9 +326,6 @@ bool fileBrowse_paste(char destPath[256]) {
consoleClear();
printf ("\x1b[0;27H");
printf ("\x1B[42m"); // Print green color
printf ("_____"); // Clear time
consoleSelect(&bottomConsole);
printf ("\x1B[47m"); // Print foreground white color
printf(clipboardFolder ? "Paste folder here?" : "Paste file here?");
@ -333,6 +339,8 @@ bool fileBrowse_paste(char destPath[256]) {
}
printf("\n");
printf("(<A> select, <B> cancel)");
consoleSelect(&bottomConsole);
printf ("\x1B[47m"); // Print foreground white color
while (true) {
// Clear old cursors
for (int i = OPTIONS_ENTRIES_START_ROW; i < (maxCursors+1) + OPTIONS_ENTRIES_START_ROW; i++) {
@ -341,14 +349,24 @@ bool fileBrowse_paste(char destPath[256]) {
// Show cursor
iprintf ("\x1b[%d;0H->", optionOffset + OPTIONS_ENTRIES_START_ROW);
consoleSelect(&topConsole);
printf ("\x1B[42m"); // Print green color for time text
// Power saving loop. Only poll the keys once per frame and sleep the CPU if there is nothing else to do
do {
// Move to right side of screen
printf ("\x1b[0;26H");
// Print time
printf ("_%s" ,RetTime().c_str());
scanKeys();
pressed = keysDownRepeat();
swiWaitForVBlank();
} while (!(pressed & KEY_UP) && !(pressed & KEY_DOWN)
&& !(pressed & KEY_A) && !(pressed & KEY_B));
consoleSelect(&bottomConsole);
printf ("\x1B[47m"); // Print foreground white color
if (pressed & KEY_UP) optionOffset -= 1;
if (pressed & KEY_DOWN) optionOffset += 1;
@ -461,7 +479,7 @@ string browseForFile (void) {
printf ("\x1b[0;26H");
// Print time
printf ("_%s" ,RetTime().c_str());
scanKeys();
pressed = keysDownRepeat();
held = keysHeld();
@ -611,20 +629,26 @@ string browseForFile (void) {
// Delete file/folder
if ((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
consoleSelect(&bottomConsole);
consoleClear();
printf ("\x1B[47m"); // Print foreground white color
iprintf("Delete \"%s\"?\n", entry->name.c_str());
printf ("(<A> yes, <B> no)");
consoleSelect(&topConsole);
printf ("\x1B[42m"); // Print green color for time text
while (true) {
// Move to right side of screen
printf ("\x1b[0;26H");
// Print time
printf ("_%s" ,RetTime().c_str());
scanKeys();
pressed = keysDownRepeat();
swiWaitForVBlank();
if (pressed & KEY_A) {
consoleSelect(&bottomConsole);
consoleClear();
printf ("\x1B[47m"); // Print foreground white color
if (FAT_getAttr(entry->name.c_str()) & ATTR_READONLY) {
printf ("Failed deleting:\n");
printf (entry->name.c_str());
@ -632,7 +656,14 @@ string browseForFile (void) {
printf ("\n");
printf ("(<A> to continue)");
pressed = 0;
consoleSelect(&topConsole);
printf ("\x1B[42m"); // Print green color for time text
while (!(pressed & KEY_A)) {
// Move to right side of screen
printf ("\x1b[0;26H");
// Print time
printf ("_%s" ,RetTime().c_str());
scanKeys();
pressed = keysDown();
swiWaitForVBlank();