diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index 7dde98b..42f42cf 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -4,7 +4,7 @@ This project represents a community-driven effort to provide an easy to build and easy to modify cartridge dumper. - Date: 14.06.2022 + Date: 16.06.2022 Version: 8.5 BETA SD lib: https://github.com/greiman/SdFat @@ -907,7 +907,87 @@ void wait() { #endif } -void print_Msg(const __FlashStringHelper *string) { +#ifdef global_log +// Copies the last part of the current log file to the dump folder +void save_log() { + // Last found position + uint64_t lastPosition = 0; + + // Go to first line of log + myLog.rewind(); + + // Find location of OSCR string to determine start of current log + char tempStr[5]; + while (myLog.available()) { + // Read first 4 chars of line + tempStr[0] = myLog.read(); + + // Check if it's an empty line + if (tempStr[0] == '\r') { + // skip \n + myLog.read(); + } + else { + // Read more lines + tempStr[1] = myLog.read(); + tempStr[2] = myLog.read(); + tempStr[3] = myLog.read(); + tempStr[4] = '\0'; + char str_buf; + + // Skip rest of line + while (myLog.available()) { + str_buf = myLog.read(); + + //break out of loop if CRLF is found + if (str_buf == '\r') + { + myLog.read(); //dispose \n because \r\n + break; + } + } + + // If string is OSCR remember position in file and test if it's the lastest log entry + if (strncmp(tempStr, "OSCR", 4) == 0) { + // Check if current position is newer as old position + if (myLog.position() > lastPosition) { + lastPosition = myLog.position(); + } + } + } + } + // Go to position of last log entry + myLog.seek(lastPosition - 16); + + // Copy log from there to dump dir + sd.chdir(folder); + strcpy(fileName, romName); + strcat(fileName, ".txt"); + if (!myFile.open(fileName, O_RDWR | O_CREAT)) { + print_Error(F("SD Error"), true); + } + + while (myLog.available()) { + if (myLog.available() >= 512) { + for (word i = 0; i < 512; i++) { + sdBuffer[i] = myLog.read(); + } + myFile.write(sdBuffer, 512); + } + else { + word i = 0; + for (i = 0; i < myLog.available(); i++) { + sdBuffer[i] = myLog.read(); + } + myFile.write(sdBuffer, i); + } + } + // Close the file: + myFile.close(); +} +#endif + +void print_Msg(const __FlashStringHelper * string) { #ifdef enable_LCD display.print(string); #endif @@ -1082,7 +1162,7 @@ void println_Msg(const char myString[]) { #endif } -void println_Msg(const __FlashStringHelper *string) { +void println_Msg(const __FlashStringHelper * string) { #ifdef enable_LCD display.print(string); display.setCursor(0, display.ty + 8); @@ -1147,7 +1227,7 @@ void display_Clear() { #endif } -unsigned char question_box(const __FlashStringHelper* question, char answers[7][20], int num_answers, int default_choice) { +unsigned char question_box(const __FlashStringHelper * question, char answers[7][20], int num_answers, int default_choice) { #ifdef enable_LCD return questionBox_LCD(question, answers, num_answers, default_choice); #endif @@ -1206,7 +1286,7 @@ void wait_serial() { }*/ } -byte questionBox_Serial(const __FlashStringHelper* question, char answers[7][20], int num_answers, int default_choice) { +byte questionBox_Serial(const __FlashStringHelper * question, char answers[7][20], int num_answers, int default_choice) { // Print menu to serial monitor //Serial.println(question); Serial.println(""); diff --git a/Cart_Reader/GB.ino b/Cart_Reader/GB.ino index 0b4625a..bede440 100644 --- a/Cart_Reader/GB.ino +++ b/Cart_Reader/GB.ino @@ -300,6 +300,9 @@ void gbMenu() { sd.chdir("/"); readROM_GB(); compare_checksums_GB(); +#ifdef global_log + save_log(); +#endif break; case 1: @@ -997,7 +1000,7 @@ void compare_checksums_GB() { } } else { - println_Msg("gb.txt not found"); + println_Msg(" -> gb.txt not found"); } #else println_Msg(""); diff --git a/Cart_Reader/GBA.ino b/Cart_Reader/GBA.ino index 4230727..41dfdaa 100644 --- a/Cart_Reader/GBA.ino +++ b/Cart_Reader/GBA.ino @@ -128,6 +128,9 @@ void gbaMenu() { readROM_GBA(); sd.chdir("/"); compare_checksum_GBA(); +#ifdef global_log + save_log(); +#endif println_Msg(F("")); println_Msg(F("Press Button...")); display_Update(); diff --git a/Cart_Reader/MD.ino b/Cart_Reader/MD.ino index f3625bf..7b61626 100644 --- a/Cart_Reader/MD.ino +++ b/Cart_Reader/MD.ino @@ -311,6 +311,9 @@ void mdCartMenu() { else readROM_MD(); //compare_checksum_MD(); +#ifdef global_log + save_log(); +#endif } else { print_Error(F("Cart has no ROM"), false); diff --git a/Cart_Reader/N64.ino b/Cart_Reader/N64.ino index bdcae07..e833f65 100644 --- a/Cart_Reader/N64.ino +++ b/Cart_Reader/N64.ino @@ -3575,6 +3575,9 @@ redumpsamefolder: // This saves a tt file with rom info next to the dumped rom #ifdef savesummarytotxt savesummary_N64(1, crcStr, timeElapsed); +#endif +#ifdef global_log + save_log(); #endif wait(); } diff --git a/Cart_Reader/NES.ino b/Cart_Reader/NES.ino index d07e1f0..11f82bb 100644 --- a/Cart_Reader/NES.ino +++ b/Cart_Reader/NES.ino @@ -246,6 +246,9 @@ void nesMenu() { delay(2000); resetROM(); CartFinish(); +#ifdef global_log + save_log(); +#endif break; // Read single chip diff --git a/Cart_Reader/SMS.ino b/Cart_Reader/SMS.ino index 30abd8c..e4b9480 100644 --- a/Cart_Reader/SMS.ino +++ b/Cart_Reader/SMS.ino @@ -68,6 +68,9 @@ void _smsMenu() { // Change working dir to root sd.chdir("/"); readROM_SMS(); +#ifdef global_log + save_log(); +#endif break; case 1: diff --git a/Cart_Reader/SNES.ino b/Cart_Reader/SNES.ino index 3858ed3..19e3a27 100644 --- a/Cart_Reader/SNES.ino +++ b/Cart_Reader/SNES.ino @@ -216,10 +216,14 @@ void snesMenu() { // start reading from cart readROM_SNES(); compare_checksum(); + // print elapsed time print_Msg(F("Time elapsed: ")); print_Msg((millis() - startTime) / 1000); println_Msg(F("s")); +#ifdef global_log + save_log(); +#endif display_Update(); } else {