From 3fcd1a808d29258c8718c470ab2e6800665b6c8e Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Fri, 21 Oct 2022 13:59:06 +0000 Subject: [PATCH 01/24] https://github.com/sanni/cartreader/issues/574#issuecomment-1286956251 --- Cart_Reader/COLV.ino | 46 +++++------ Cart_Reader/Cart_Reader.ino | 126 ++++++++++++++++++++++++------ Cart_Reader/FLASH.ino | 110 +++++++++++++------------- Cart_Reader/GB.ino | 82 ++++++++++--------- Cart_Reader/GBA.ino | 103 +++++++++++++----------- Cart_Reader/GBM.ino | 20 +++-- Cart_Reader/GBS.ino | 35 +++++---- Cart_Reader/INTV.ino | 67 ++++++++-------- Cart_Reader/MD.ino | 74 +++++++++--------- Cart_Reader/N64.ino | 152 +++++++++++++++++++----------------- Cart_Reader/NES.ino | 137 +++++++++++++++++--------------- Cart_Reader/NGP.ino | 16 ++-- Cart_Reader/PCE.ino | 23 +++--- Cart_Reader/PCW.ino | 37 +++++---- Cart_Reader/SFM.ino | 47 ++++++----- Cart_Reader/SMS.ino | 25 +++--- Cart_Reader/SNES.ino | 50 ++++++------ Cart_Reader/SV.ino | 14 ++-- Cart_Reader/VBOY.ino | 34 ++++---- Cart_Reader/WS.ino | 38 ++++----- Cart_Reader/WSV.ino | 43 +++++----- 21 files changed, 720 insertions(+), 559 deletions(-) diff --git a/Cart_Reader/COLV.ino b/Cart_Reader/COLV.ino index 3937e51..9f16d84 100644 --- a/Cart_Reader/COLV.ino +++ b/Cart_Reader/COLV.ino @@ -51,8 +51,8 @@ byte newcolsize; static const char colMenuItem1[] PROGMEM = "Select Cart"; static const char colMenuItem2[] PROGMEM = "Read ROM"; static const char colMenuItem3[] PROGMEM = "Set Size"; -static const char colMenuItem4[] PROGMEM = "Reset"; -static const char* const menuOptionsCOL[] PROGMEM = { colMenuItem1, colMenuItem2, colMenuItem3, colMenuItem4 }; +//static const char colMenuItem4[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsCOL[] PROGMEM = { colMenuItem1, colMenuItem2, colMenuItem3, string_reset2 }; void setup_COL() { // Set Address Pins to Output @@ -175,14 +175,14 @@ void readROM_COL() { sd.chdir(folder); display_Clear(); - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); // open file on sdcard if (!myFile.open(fileName, O_RDWR | O_CREAT)) - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); // write new folder number back to EEPROM foldern++; @@ -216,7 +216,8 @@ void readROM_COL() { compareCRC("colv.txt", 0, 1, 0); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } @@ -239,11 +240,11 @@ void setROMSize_COL() { println_Msg(COL[i]); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to Change")); - println_Msg(F("and right to Select")); + print_STR(press_to_change_STR, 1); + print_STR(right_to_select_STR, 1); #elif defined(enable_LCD) - println_Msg(F("Rotate to Change")); - println_Msg(F("Press to Select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #endif display_Update(); @@ -261,11 +262,11 @@ void setROMSize_COL() { println_Msg(COL[i]); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to Change")); - println_Msg(F("and right to Select")); + print_STR(press_to_change_STR, 1); + print_STR(right_to_select_STR, 1); #elif defined(enable_LCD) - println_Msg(F("Rotate to Change")); - println_Msg(F("Press to Select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #endif display_Update(); } @@ -281,11 +282,11 @@ void setROMSize_COL() { println_Msg(COL[i]); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to Change")); - println_Msg(F("and right to Select")); + print_STR(press_to_change_STR, 1); + print_STR(right_to_select_STR, 1); #elif defined(enable_LCD) - println_Msg(F("Rotate to Change")); - println_Msg(F("Press to Select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #endif display_Update(); } @@ -349,7 +350,8 @@ void checkStatus_COL() { print_Msg(COL[colsize]); println_Msg(F("K")); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); #else @@ -460,11 +462,11 @@ void setCart_COL() { println_Msg(F("KB")); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to Change")); - println_Msg(F("and right to Select")); + print_STR(press_to_change_STR, 1); + print_STR(right_to_select_STR, 1); #elif defined(enable_LCD) - println_Msg(F("Rotate to Change")); - println_Msg(F("Press to Select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #elif defined(SERIAL_MONITOR) println_Msg(F("U/D to Change")); println_Msg(F("Space to Select")); diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index 7bf8f56..72b05d0 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -56,7 +56,7 @@ **********************************************************************************/ -char ver[5] = "10.3"; +char ver[5] = "10.4"; //****************************************** // !!! CHOOSE HARDWARE VERSION !!! @@ -263,6 +263,57 @@ bool i2c_found; #include "FreqCount.h" #endif +/****************************************** + Common Strings + *****************************************/ +#define press_button_STR 0 +#define sd_error_STR 1 +#define reset_STR 2 +#define did_not_verify_STR 3 +#define _bytes_STR 4 +#define error_STR 5 +#define create_file_STR 6 +#define open_file_STR 7 +#define file_too_big_STR 8 +#define done_STR 9 +#define saving_to_STR 10 +#define verifying_STR 11 +#define flashing_file_STR 12 +#define press_to_change_STR 13 +#define right_to_select_STR 14 +#define rotate_to_change_STR 15 +#define press_to_select_STR 16 + +// This arrays holds the most often uses strings +static const char string_press_button0[] PROGMEM = "Press Button..."; +static const char string_sd_error1[] PROGMEM = "SD Error"; +static const char string_reset2[] PROGMEM = "Reset"; +static const char string_did_not_verify3[] PROGMEM = "did not verify"; +static const char string_bytes4[] PROGMEM = " bytes "; +static const char string_error5[] PROGMEM = "Error: "; +static const char string_create_file6[] PROGMEM = "Can't create file"; +static const char string_open_file7[] PROGMEM = "Can't open file"; +static const char string_file_too_big8[] PROGMEM = "File too big"; +static const char string_done9[] PROGMEM = "Done"; +static const char string_saving_to10[] PROGMEM = "Saving to "; +static const char string_verifying11[] PROGMEM = "Verifying..."; +static const char string_flashing_file12[] PROGMEM = "Flashing file "; +static const char string_press_to_change13[] PROGMEM = "Press left to Change"; +static const char string_right_to_select14[] PROGMEM = "and right to Select"; +static const char string_rotate_to_change15[] PROGMEM = "Rotate to Change"; +static const char string_press_to_select16[] PROGMEM = "Press to Select"; + +static const char* const string_table[] PROGMEM = { string_press_button0, string_sd_error1, string_reset2, string_did_not_verify3, string_bytes4, string_error5, string_create_file6, string_open_file7, string_file_too_big8, string_done9, string_saving_to10, string_verifying11, string_flashing_file12, string_press_to_change13, string_right_to_select14, string_rotate_to_change15, string_press_to_select16 }; + +void print_STR(byte string_number, boolean newline) { + char string_buffer[22]; + strcpy_P(string_buffer, (char*)pgm_read_word(&(string_table[string_number]))); + if (newline) + println_Msg(string_buffer); + else + print_Msg(string_buffer); +} + /****************************************** Defines *****************************************/ @@ -629,7 +680,7 @@ boolean compareCRC(char* database, char* crcString, boolean renamerom, int offse // Write iNES header sd.chdir(folder); if (!myFile.open(fileName, O_RDWR)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } for (byte z = 0; z < 16; z++) { myFile.write(iNES_HEADER[z]); @@ -973,15 +1024,15 @@ static const char modeItem4[] PROGMEM = "Nintendo 64(3V EEP)"; #endif static const char modeItem5[] PROGMEM = "Game Boy"; static const char modeItem6[] PROGMEM = "About"; -static const char modeItem7[] PROGMEM = "Reset"; -static const char* const modeOptions[] PROGMEM = { modeItem1, modeItem2, modeItem3, modeItem4, modeItem5, modeItem6, modeItem7 }; +// static const char modeItem7[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const modeOptions[] PROGMEM = { modeItem1, modeItem2, modeItem3, modeItem4, modeItem5, modeItem6, string_reset2 }; // Add-ons submenu static const char addonsItem1[] PROGMEM = "Consoles"; static const char addonsItem2[] PROGMEM = "Handhelds"; static const char addonsItem3[] PROGMEM = "Flashrom Programmer"; -static const char addonsItem4[] PROGMEM = "Reset"; -static const char* const addonsOptions[] PROGMEM = { addonsItem1, addonsItem2, addonsItem3, addonsItem4 }; +//static const char addonsItem4[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const addonsOptions[] PROGMEM = { addonsItem1, addonsItem2, addonsItem3, string_reset2 }; // Consoles submenu static const char consolesItem1[] PROGMEM = "NES/Famicom"; @@ -989,8 +1040,8 @@ static const char consolesItem2[] PROGMEM = "PC Engine/TG16"; static const char consolesItem3[] PROGMEM = "SMS/GG/MIII/SG-1000"; static const char consolesItem4[] PROGMEM = "Intellivision"; static const char consolesItem5[] PROGMEM = "Colecovision"; -static const char consolesItem6[] PROGMEM = "Reset"; -static const char* const consolesOptions[] PROGMEM = { consolesItem1, consolesItem2, consolesItem3, consolesItem4, consolesItem5, consolesItem6 }; +//static const char consolesItem6[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const consolesOptions[] PROGMEM = { consolesItem1, consolesItem2, consolesItem3, consolesItem4, consolesItem5, string_reset2 }; // Handhelds submenu static const char handheldsItem1[] PROGMEM = "Virtual Boy"; @@ -998,8 +1049,8 @@ static const char handheldsItem2[] PROGMEM = "WonderSwan"; static const char handheldsItem3[] PROGMEM = "NeoGeo Pocket"; static const char handheldsItem4[] PROGMEM = "Watara Supervision"; static const char handheldsItem5[] PROGMEM = "Pocket Challenge W"; -static const char handheldsItem6[] PROGMEM = "Reset"; -static const char* const handheldsOptions[] PROGMEM = { handheldsItem1, handheldsItem2, handheldsItem3, handheldsItem4, handheldsItem5, handheldsItem6 }; +//static const char handheldsItem6[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const handheldsOptions[] PROGMEM = { handheldsItem1, handheldsItem2, handheldsItem3, handheldsItem4, handheldsItem5, string_reset2 }; // All included slots void mainMenu() { @@ -1227,7 +1278,8 @@ void aboutScreen() { println_Msg(F("")); println_Msg(F("")); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); while (1) { @@ -1539,14 +1591,14 @@ void savetofile() { delay(2000); if (!myFile.open("/snes_clk.txt", O_WRITE | O_CREAT | O_TRUNC)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } // Write calibration factor to file myFile.print(cal_factor); // Close the file: myFile.close(); - println_Msg(F("Done")); + print_STR(done_STR, 1); display_Update(); delay(1000); resetArduino(); @@ -1726,12 +1778,12 @@ void setup() { // Init SD card if (!sd.begin(SS)) { display_Clear(); - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } #ifdef global_log if (!myLog.open("OSCR_LOG.txt", O_RDWR | O_CREAT | O_APPEND)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } println_Msg(F("")); #if defined(HW1) @@ -1849,6 +1901,32 @@ void print_Error(const __FlashStringHelper* errorMessage, boolean forceReset) { } } +void print_Error(byte errorMessage, boolean forceReset) { + errorLvl = 1; + setColor_RGB(255, 0, 0); + print_STR(errorMessage, 1); + display_Update(); + + if (forceReset) { + println_Msg(F("")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); + display_Update(); + wait(); + if (ignoreError == 0) { + resetArduino(); + } else { + ignoreError = 0; + display_Clear(); + println_Msg(F("")); + println_Msg(F("Error Overwrite")); + println_Msg(F("")); + display_Update(); + delay(2000); + } + } +} + void wait() { // Switch status LED off statusLED(false); @@ -1916,7 +1994,7 @@ void save_log() { strcpy(fileName, romName); strcat(fileName, ".txt"); if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } while (myLog.available()) { @@ -2310,7 +2388,7 @@ byte questionBox_Serial(const __FlashStringHelper* question, char answers[7][20] EEPROM_readAnything(0, foldern); sprintf(fileName, "IMPORT/%d.bin", foldern); if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); } // Read file from serial @@ -2577,7 +2655,7 @@ void wait_serial() { myFile.close(); } else { - print_Error(F("Can't open file"), true); + print_Error(open_file_STR, true); } }*/ } @@ -2915,7 +2993,7 @@ browserstart: // Open filepath directory if (!myDir.open(filePath)) { display_Clear(); - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } // Count files in directory @@ -2973,7 +3051,8 @@ page: println_Msg(F("Too many files")); display_Update(); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } @@ -2981,7 +3060,7 @@ page: // Open filepath directory if (!myDir.open(filePath)) { display_Clear(); - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } int countFile = 0; @@ -3231,7 +3310,8 @@ void loop() { print_Msg(F("Mode = ")); print_Msg(mode); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); resetArduino(); @@ -3240,4 +3320,4 @@ void loop() { //****************************************** // End of File -//****************************************** \ No newline at end of file +//****************************************** diff --git a/Cart_Reader/FLASH.ino b/Cart_Reader/FLASH.ino index 7e815f6..79697ab 100644 --- a/Cart_Reader/FLASH.ino +++ b/Cart_Reader/FLASH.ino @@ -27,16 +27,16 @@ static const char flash8MenuItem3[] PROGMEM = "Read"; static const char flash8MenuItem4[] PROGMEM = "Write"; static const char flash8MenuItem5[] PROGMEM = "ID"; static const char flash8MenuItem6[] PROGMEM = "Print"; -static const char flash8MenuItem7[] PROGMEM = "Reset"; -static const char* const menuOptionsFLASH8[] PROGMEM = { flash8MenuItem1, flash8MenuItem2, flash8MenuItem3, flash8MenuItem4, flash8MenuItem5, flash8MenuItem6, flash8MenuItem7 }; +//static const char flash8MenuItem7[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsFLASH8[] PROGMEM = { flash8MenuItem1, flash8MenuItem2, flash8MenuItem3, flash8MenuItem4, flash8MenuItem5, flash8MenuItem6, string_reset2 }; #ifdef enable_FLASH16 // Flash start menu static const char flashMenuItem1[] PROGMEM = "8bit Flash adapter"; static const char flashMenuItem2[] PROGMEM = "Eprom adapter"; static const char flashMenuItem3[] PROGMEM = "MX26L6420 adapter"; -static const char flashMenuItem4[] PROGMEM = "Reset"; -static const char* const menuOptionsFlash[] PROGMEM = { flashMenuItem1, flashMenuItem2, flashMenuItem3, flashMenuItem4 }; +// static const char flashMenuItem4[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsFlash[] PROGMEM = { flashMenuItem1, flashMenuItem2, flashMenuItem3, string_reset2 }; // 16bit Flash menu items static const char flash16MenuItem1[] PROGMEM = "Blankcheck"; @@ -45,8 +45,8 @@ static const char flash16MenuItem3[] PROGMEM = "Read"; static const char flash16MenuItem4[] PROGMEM = "Write"; static const char flash16MenuItem5[] PROGMEM = "ID"; static const char flash16MenuItem6[] PROGMEM = "Print"; -static const char flash16MenuItem7[] PROGMEM = "Reset"; -static const char* const menuOptionsFLASH16[] PROGMEM = { flash16MenuItem1, flash16MenuItem2, flash16MenuItem3, flash16MenuItem4, flash16MenuItem5, flash16MenuItem6, flash16MenuItem7 }; +//static const char flash16MenuItem7[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsFLASH16[] PROGMEM = { flash16MenuItem1, flash16MenuItem2, flash16MenuItem3, flash16MenuItem4, flash16MenuItem5, flash16MenuItem6, string_reset2 }; // Eprom menu items static const char epromMenuItem1[] PROGMEM = "Blankcheck"; @@ -54,8 +54,8 @@ static const char epromMenuItem2[] PROGMEM = "Read"; static const char epromMenuItem3[] PROGMEM = "Write"; static const char epromMenuItem4[] PROGMEM = "Verify"; static const char epromMenuItem5[] PROGMEM = "Print"; -static const char epromMenuItem6[] PROGMEM = "Reset"; -static const char* const menuOptionsEprom[] PROGMEM = { epromMenuItem1, epromMenuItem2, epromMenuItem3, epromMenuItem4, epromMenuItem5, epromMenuItem6 }; +// static const char epromMenuItem6[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsEprom[] PROGMEM = { epromMenuItem1, epromMenuItem2, epromMenuItem3, epromMenuItem4, epromMenuItem5, string_reset2 }; void flashMenu() { // create menu with title and 3 options to choose from @@ -222,7 +222,8 @@ void flashromMenu8() { println_Msg(F("s")); display_Update(); } - print_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 0); display_Update(); wait(); } @@ -555,7 +556,8 @@ idtheflash: println_Msg(""); println_Msg(F("UNKNOWN FLASHROM")); println_Msg(""); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); @@ -570,7 +572,8 @@ idtheflash: print_Error(F("Press Button to reset"), true); } println_Msg(""); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); resetFlash8(); @@ -625,7 +628,8 @@ void id_Flash16() { println_Msg(""); } println_Msg(""); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); } #endif @@ -1038,7 +1042,7 @@ void eraseFlash29F032() { void writeFlash29F032() { // Create filepath sprintf(filePath, "%s/%s", filePath, fileName); - print_Msg(F("Flashing file ")); + print_STR(flashing_file_STR, 0); print_Msg(filePath); println_Msg(F("...")); display_Update(); @@ -1048,7 +1052,7 @@ void writeFlash29F032() { // Get rom size from file fileSize = myFile.fileSize(); if (fileSize > flashSize) - print_Error(F("File size exceeds flash size."), true); + print_Error(file_too_big_STR, true); // Set data pins to output dataOut(); @@ -1113,7 +1117,7 @@ void writeFlash29F032() { // Close the file: myFile.close(); } else { - println_Msg(F("Can't open file")); + print_STR(open_file_STR, 1); display_Update(); } } @@ -1179,7 +1183,7 @@ void resetFlash29F1610() { void writeFlash29F1610() { // Create filepath sprintf(filePath, "%s/%s", filePath, fileName); - println_Msg(F("Flashing file ")); + print_STR(flashing_file_STR, 1); println_Msg(filePath); display_Update(); @@ -1188,7 +1192,7 @@ void writeFlash29F1610() { // Get rom size from file fileSize = myFile.fileSize(); if (fileSize > flashSize) - print_Error(F("File size exceeds flash size."), true); + print_Error(file_too_big_STR, true); // Set data pins to output dataOut(); @@ -1225,7 +1229,7 @@ void writeFlash29F1610() { // Close the file: myFile.close(); } else { - println_Msg(F("Can't open file on SD")); + print_STR(open_file_STR, 1); display_Update(); } } @@ -1233,7 +1237,7 @@ void writeFlash29F1610() { void writeFlash29F1601() { // Create filepath sprintf(filePath, "%s/%s", filePath, fileName); - println_Msg(F("Flashing file ")); + print_STR(flashing_file_STR, 1); println_Msg(filePath); display_Update(); @@ -1242,7 +1246,7 @@ void writeFlash29F1601() { // Get rom size from file fileSize = myFile.fileSize(); if (fileSize > flashSize) - print_Error(F("File size exceeds flash size."), true); + print_Error(file_too_big_STR, true); // Set data pins to output dataOut(); @@ -1284,7 +1288,7 @@ void writeFlash29F1601() { // Close the file: myFile.close(); } else { - println_Msg(F("Can't open file on SD")); + print_STR(open_file_STR, 1); display_Update(); } } @@ -1376,7 +1380,7 @@ void busyCheck29LV640(unsigned long myAddress, byte myData) { void writeFlash29LV640() { // Create filepath sprintf(filePath, "%s/%s", filePath, fileName); - println_Msg(F("Flashing file ")); + print_STR(flashing_file_STR, 1); println_Msg(filePath); display_Update(); @@ -1385,7 +1389,7 @@ void writeFlash29LV640() { // Get rom size from file fileSize = myFile.fileSize(); if (fileSize > flashSize) - print_Error(F("File size exceeds flash size."), true); + print_Error(file_too_big_STR, true); // Set data pins to output dataOut(); @@ -1412,7 +1416,7 @@ void writeFlash29LV640() { // Close the file: myFile.close(); } else { - println_Msg(F("Can't open file on SD")); + print_STR(open_file_STR, 1); display_Update(); } } @@ -1423,7 +1427,7 @@ void writeFlash29LV640() { void writeFlash29GL(unsigned long sectorSize, byte bufferSize) { // Create filepath sprintf(filePath, "%s/%s", filePath, fileName); - println_Msg(F("Flashing file ")); + print_STR(flashing_file_STR, 1); println_Msg(filePath); display_Update(); @@ -1432,7 +1436,7 @@ void writeFlash29GL(unsigned long sectorSize, byte bufferSize) { // Get rom size from file fileSize = myFile.fileSize(); if (fileSize > flashSize) - print_Error(F("File size exceeds flash size."), true); + print_Error(file_too_big_STR, true); // Set data pins to output dataOut(); @@ -1479,7 +1483,7 @@ void writeFlash29GL(unsigned long sectorSize, byte bufferSize) { // Close the file: myFile.close(); } else { - println_Msg(F("Can't open file on SD")); + print_STR(open_file_STR, 1); display_Update(); } } @@ -1490,7 +1494,7 @@ void writeFlash29GL(unsigned long sectorSize, byte bufferSize) { void writeFlash29F800() { // Create filepath sprintf(filePath, "%s/%s", filePath, fileName); - println_Msg(F("Flashing file ")); + print_STR(flashing_file_STR, 1); println_Msg(filePath); display_Update(); @@ -1499,7 +1503,7 @@ void writeFlash29F800() { // Get rom size from file fileSize = myFile.fileSize(); if (fileSize > flashSize) - print_Error(F("File size exceeds flash size."), true); + print_Error(file_too_big_STR, true); // Set data pins to output dataOut(); @@ -1528,7 +1532,7 @@ void writeFlash29F800() { // Close the file: myFile.close(); } else { - println_Msg(F("Can't open file on SD")); + print_STR(open_file_STR, 1); display_Update(); } } @@ -1580,7 +1584,7 @@ void eraseFlash28FXXX() { void writeFlash28FXXX() { sprintf(filePath, "%s/%s", filePath, fileName); - print_Msg(F("Flashing file ")); + print_STR(flashing_file_STR, 0); println_Msg(filePath); display_Update(); @@ -1594,7 +1598,7 @@ void writeFlash28FXXX() { myFile.close(); } else { - println_Msg(F("Can't open file on SD")); + print_STR(open_file_STR, 1); display_Update(); } } @@ -1602,7 +1606,7 @@ void writeFlash28FXXX() { void writeFlashE28FXXXJ3A() { fileSize = myFile.fileSize(); if (fileSize > flashSize) { - print_Error(F("File size exceeds flash size."), false); + print_Error(file_too_big_STR, false); return; } @@ -1653,7 +1657,7 @@ void writeFlashE28FXXXJ3A() { void writeFlashLH28F0XX() { fileSize = myFile.fileSize(); if (fileSize > flashSize) { - print_Error(F("File size exceeds flash size."), false); + print_Error(file_too_big_STR, false); return; } @@ -1713,7 +1717,7 @@ void blankcheck_Flash() { } void verifyFlash() { - println_Msg(F("Verifying...")); + print_STR(verifying_STR, 1); display_Update(); // Open file on sd card @@ -1721,7 +1725,7 @@ void verifyFlash() { // Get rom size from file fileSize = myFile.fileSize(); if (fileSize > flashSize) - print_Error(F("File size exceeds flash size."), true); + print_Error(file_too_big_STR, true); blank = 0; for (unsigned long currByte = 0; currByte < fileSize; currByte += 512) { @@ -1737,15 +1741,15 @@ void verifyFlash() { println_Msg(F("Flashrom verified OK")); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(blank); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } // Close the file: myFile.close(); } else { - println_Msg(F("Can't open file on SD")); + print_STR(open_file_STR, 1); display_Update(); } } @@ -1772,7 +1776,7 @@ void readFlash() { // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); } for (unsigned long currByte = 0; currByte < flashSize; currByte += 512) { for (int c = 0; c < 512; c++) { @@ -1834,7 +1838,7 @@ void resetFlash16() { void writeFlash16() { // Create filepath sprintf(filePath, "%s/%s", filePath, fileName); - println_Msg(F("Flashing file ")); + print_STR(flashing_file_STR, 1); println_Msg(filePath); display_Update(); @@ -1843,7 +1847,7 @@ void writeFlash16() { // Get rom size from file fileSize = myFile.fileSize(); if (fileSize > flashSize) - print_Error(F("File size exceeds flash size."), true); + print_Error(file_too_big_STR, true); // Set data pins to output dataOut16(); @@ -1892,7 +1896,7 @@ void writeFlash16() { void writeFlash16_29F1601() { // Create filepath sprintf(filePath, "%s/%s", filePath, fileName); - println_Msg(F("Flashing file ")); + print_STR(flashing_file_STR, 1); println_Msg(filePath); display_Update(); @@ -1901,7 +1905,7 @@ void writeFlash16_29F1601() { // Get rom size from file fileSize = myFile.fileSize(); if (fileSize > flashSize) - print_Error(F("File size exceeds flash size."), true); + print_Error(file_too_big_STR, true); // Set data pins to output dataOut16(); @@ -2024,7 +2028,7 @@ void blankcheck16() { } void verifyFlash16() { - println_Msg(F("Verifying...")); + print_STR(verifying_STR, 1); display_Update(); // Open file on sd card @@ -2032,7 +2036,7 @@ void verifyFlash16() { // Get rom size from file fileSize = myFile.fileSize(); if (fileSize > flashSize) { - print_Error(F("File size exceeds flash size."), true); + print_Error(file_too_big_STR, true); } blank = 0; @@ -2190,7 +2194,7 @@ void busyCheck16_29LV640(unsigned long myAddress, word myData) { void writeFlash16_29LV640() { // Create filepath sprintf(filePath, "%s/%s", filePath, fileName); - println_Msg(F("Flashing file ")); + print_STR(flashing_file_STR, 1); println_Msg(filePath); display_Update(); @@ -2199,7 +2203,7 @@ void writeFlash16_29LV640() { // Get rom size from file fileSize = myFile.fileSize(); if (fileSize > flashSize) - print_Error(F("File size exceeds flash size."), true); + print_Error(file_too_big_STR, true); // Set data pins to output dataOut16(); @@ -2417,7 +2421,7 @@ void read_Eprom() { void write_Eprom() { // Create filepath sprintf(filePath, "%s/%s", filePath, fileName); - println_Msg(F("Flashing file ")); + print_STR(flashing_file_STR, 1); println_Msg(filePath); display_Update(); @@ -2426,7 +2430,7 @@ void write_Eprom() { // Get rom size from file fileSize = myFile.fileSize(); if (fileSize > flashSize) - print_Error(F("File size exceeds flash size."), true); + print_Error(file_too_big_STR, true); // Switch VPP/OE(PH5) to HIGH PORTH |= (1 << 5); @@ -2477,7 +2481,7 @@ void write_Eprom() { } void verify_Eprom() { - println_Msg(F("Verifying...")); + print_STR(verifying_STR, 1); display_Update(); // Open file on sd card @@ -2485,7 +2489,7 @@ void verify_Eprom() { // Get rom size from file fileSize = myFile.fileSize(); if (fileSize > flashSize) { - print_Error(F("File size exceeds flash size."), true); + print_Error(file_too_big_STR, true); } blank = 0; diff --git a/Cart_Reader/GB.ino b/Cart_Reader/GB.ino index c4445bc..c4cc36d 100644 --- a/Cart_Reader/GB.ino +++ b/Cart_Reader/GB.ino @@ -19,15 +19,15 @@ static const char gbxMenuItem1[] PROGMEM = "Game Boy (Color)"; static const char gbxMenuItem2[] PROGMEM = "GB Advance (3V)"; static const char gbxMenuItem3[] PROGMEM = "Flash GBC Cart"; static const char gbxMenuItem4[] PROGMEM = "NPower GB Memory"; -static const char gbxMenuItem5[] PROGMEM = "Reset"; -static const char* const menuOptionsGBx[] PROGMEM = { gbxMenuItem1, gbxMenuItem2, gbxMenuItem3, gbxMenuItem4, gbxMenuItem5 }; +//static const char gbxMenuItem5[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsGBx[] PROGMEM = { gbxMenuItem1, gbxMenuItem2, gbxMenuItem3, gbxMenuItem4, string_reset2 }; // GB menu items static const char GBMenuItem1[] PROGMEM = "Read ROM"; static const char GBMenuItem2[] PROGMEM = "Read Save"; static const char GBMenuItem3[] PROGMEM = "Write Save"; -static const char GBMenuItem4[] PROGMEM = "Reset"; -static const char* const menuOptionsGB[] PROGMEM = { GBMenuItem1, GBMenuItem2, GBMenuItem3, GBMenuItem4 }; +//static const char GBMenuItem4[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsGB[] PROGMEM = { GBMenuItem1, GBMenuItem2, GBMenuItem3, string_reset2 }; // GB Flash items static const char GBFlashItem1[] PROGMEM = "29F Cart (MBC3)"; @@ -36,8 +36,8 @@ static const char GBFlashItem3[] PROGMEM = "29F Cart (CAM)"; static const char GBFlashItem4[] PROGMEM = "CFI Cart"; static const char GBFlashItem5[] PROGMEM = "CFI Cart and Save"; static const char GBFlashItem6[] PROGMEM = "GB Smart"; -static const char GBFlashItem7[] PROGMEM = "Reset"; -static const char* const menuOptionsGBFlash[] PROGMEM = { GBFlashItem1, GBFlashItem2, GBFlashItem3, GBFlashItem4, GBFlashItem5, GBFlashItem6, GBFlashItem7 }; +//static const char GBFlashItem7[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsGBFlash[] PROGMEM = { GBFlashItem1, GBFlashItem2, GBFlashItem3, GBFlashItem4, GBFlashItem5, GBFlashItem6, string_reset2 }; // Start menu for both GB and GBA void gbxMenu() { @@ -84,7 +84,8 @@ void gbxMenu() { //MBC3 writeFlash29F_GB(3, 1); // Reset - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); resetArduino(); @@ -102,7 +103,8 @@ void gbxMenu() { //MBC5 writeFlash29F_GB(5, 1); // Reset - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); resetArduino(); @@ -120,7 +122,8 @@ void gbxMenu() { sd.chdir("/"); //MBC3 writeFlash29F_GB(3, 1); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); @@ -131,7 +134,8 @@ void gbxMenu() { println_Msg(F("if you want to flash")); println_Msg(F("a second game")); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); @@ -143,7 +147,8 @@ void gbxMenu() { // Reset println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); resetArduino(); @@ -167,7 +172,8 @@ void gbxMenu() { if (!writeCFI_GB()) { display_Clear(); println_Msg(F("Flashing failed, time out!")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } @@ -194,7 +200,8 @@ void gbxMenu() { if (!writeCFI_GB()) { display_Clear(); println_Msg(F("Flashing failed, time out!")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); resetArduino(); @@ -230,10 +237,10 @@ void gbxMenu() { println_Msg(F("Verified OK")); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(wrErrors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } break; } @@ -333,10 +340,10 @@ void gbMenu() { println_Msg(F("Verified OK")); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(wrErrors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } } } else { @@ -349,7 +356,8 @@ void gbMenu() { resetArduino(); break; } - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } @@ -534,7 +542,8 @@ void showCartInfo_GB() { // Wait for user input println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } else { @@ -938,7 +947,7 @@ void readROM_GB() { sd.chdir(folder); display_Clear(); - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); @@ -949,7 +958,7 @@ void readROM_GB() { //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); } int endAddress = 0x7FFF; @@ -1158,7 +1167,7 @@ void readSRAM_GB() { //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } // MBC2 Fix @@ -1289,7 +1298,7 @@ unsigned long verifySRAM_GB() { myFile.close(); return writeErrors; } else { - print_Error(F("Can't open file"), true); + print_Error(open_file_STR, true); } } @@ -1306,7 +1315,7 @@ void readSRAMFLASH_MBC6_GB() { sd.chdir(folder); display_Clear(); - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); @@ -1317,7 +1326,7 @@ void readSRAMFLASH_MBC6_GB() { //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } //Initialize progress bar @@ -1788,7 +1797,7 @@ void writeFlash29F_GB(byte MBC, boolean flashErase) { } } - print_Msg(F("Verifying...")); + print_STR(verifying_STR, 0); display_Update(); // Go back to file beginning @@ -1837,11 +1846,11 @@ void writeFlash29F_GB(byte MBC, boolean flashErase) { } else { println_Msg(F("Error")); print_Msg(writeErrors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), true); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, true); } } else { - println_Msg(F("Can't open file")); + print_STR(open_file_STR, 1); display_Update(); } } @@ -2018,7 +2027,8 @@ bool writeCFI_GB() { print_Msg(F("but needs ")); print_Msg(romBanks); println_Msg(F(".")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); resetArduino(); @@ -2194,13 +2204,13 @@ bool writeCFI_GB() { println_Msg(F("OK")); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(writeErrors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } } else { - println_Msg(F("Can't open file")); + print_STR(open_file_STR, 1); display_Update(); } return true; diff --git a/Cart_Reader/GBA.ino b/Cart_Reader/GBA.ino index e8352ad..78d216f 100644 --- a/Cart_Reader/GBA.ino +++ b/Cart_Reader/GBA.ino @@ -18,8 +18,8 @@ static const char GBAMenuItem2[] PROGMEM = "Read Save"; static const char GBAMenuItem3[] PROGMEM = "Write Save"; static const char GBAMenuItem4[] PROGMEM = "Force Savetype"; static const char GBAMenuItem5[] PROGMEM = "Flash Repro"; -static const char GBAMenuItem6[] PROGMEM = "Reset"; -static const char* const menuOptionsGBA[] PROGMEM = { GBAMenuItem1, GBAMenuItem2, GBAMenuItem3, GBAMenuItem4, GBAMenuItem5, GBAMenuItem6 }; +//static const char GBAMenuItem6[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsGBA[] PROGMEM = { GBAMenuItem1, GBAMenuItem2, GBAMenuItem3, GBAMenuItem4, GBAMenuItem5, string_reset2 }; // Rom menu static const char GBARomItem1[] PROGMEM = "1 MB"; @@ -129,7 +129,8 @@ void gbaMenu() { #ifdef global_log save_log(); #endif - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); break; @@ -231,7 +232,8 @@ void gbaMenu() { break; } println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); break; @@ -289,10 +291,10 @@ void gbaMenu() { println_Msg(F("Verified OK")); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(writeErrors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } setROM_GBA(); break; @@ -307,10 +309,10 @@ void gbaMenu() { println_Msg(F("Verified OK")); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(writeErrors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } setROM_GBA(); break; @@ -326,10 +328,10 @@ void gbaMenu() { println_Msg(F("Verified OK")); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(writeErrors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } setROM_GBA(); break; @@ -358,7 +360,8 @@ void gbaMenu() { //print_Error(F(""), true); } println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); display_Clear(); @@ -399,7 +402,8 @@ void gbaMenu() { //print_Error(F(""), true); } println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); display_Clear(); @@ -437,16 +441,17 @@ void gbaMenu() { println_Msg(F("Verified OK")); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(writeErrors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } setROM_GBA(); break; } println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); break; @@ -498,7 +503,8 @@ void gbaMenu() { display_Clear(); flashRepro_GBA(); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); resetArduino(); @@ -565,7 +571,8 @@ void setup_GBA() { // Wait for user input println_Msg(""); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } @@ -942,12 +949,12 @@ void getCartInfo_GBA() { println_Msg(saveTypeStr); #if defined(enable_OLED) - println_Msg(F("Press left to Change")); - println_Msg(F("and right to Select")); + print_STR(press_to_change_STR, 1); + print_STR(right_to_select_STR, 1); #elif defined(enable_LCD) println_Msg(F("")); - println_Msg(F("Rotate to Change")); - println_Msg(F("Press to Select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #elif defined(SERIAL_MONITOR) println_Msg(F("")); println_Msg(F("U/D to Change")); @@ -1056,7 +1063,8 @@ void getCartInfo_GBA() { println_Msg(calcChecksumStr); print_Error(F("Checksum Error"), false); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } @@ -1127,7 +1135,7 @@ void readROM_GBA() { //clear the screen display_Clear(); - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); @@ -1138,7 +1146,7 @@ void readROM_GBA() { //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); } //Initialize progress bar @@ -1234,7 +1242,7 @@ void readSRAM_GBA(boolean browseFile, unsigned long sramSize, uint32_t pos) { sd.chdir(folder); // Save location - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); @@ -1245,7 +1253,7 @@ void readSRAM_GBA(boolean browseFile, unsigned long sramSize, uint32_t pos) { //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } // Seek to a new position in the file @@ -1265,7 +1273,7 @@ void readSRAM_GBA(boolean browseFile, unsigned long sramSize, uint32_t pos) { myFile.close(); // Signal end of process - println_Msg(F("Done")); + print_STR(done_STR, 1); display_Update(); } @@ -1363,7 +1371,7 @@ void readFRAM_GBA(unsigned long framSize) { sd.chdir(folder); // Save location - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); @@ -1373,7 +1381,7 @@ void readFRAM_GBA(unsigned long framSize) { //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } for (unsigned long currAddress = 0; currAddress < framSize; currAddress += 512) { for (int c = 0; c < 512; c++) { @@ -1407,7 +1415,7 @@ void readFRAM_GBA(unsigned long framSize) { myFile.close(); // Signal end of process - println_Msg(F("Done")); + print_STR(done_STR, 1); display_Update(); } @@ -1790,7 +1798,7 @@ void readFLASH_GBA(boolean browseFile, unsigned long flashSize, uint32_t pos) { sd.chdir(folder); // Save location - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); @@ -1802,7 +1810,7 @@ void readFLASH_GBA(boolean browseFile, unsigned long flashSize, uint32_t pos) { //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } // Seek to a new position in the file @@ -1829,7 +1837,7 @@ void readFLASH_GBA(boolean browseFile, unsigned long flashSize, uint32_t pos) { PORTH |= (1 << 0); // Signal end of process - println_Msg(F("Done")); + print_STR(done_STR, 1); display_Update(); } @@ -1915,7 +1923,7 @@ void writeFLASH_GBA(boolean browseFile, unsigned long flashSize, uint32_t pos, b // Close the file: myFile.close(); - println_Msg(F("done")); + print_STR(done_STR, 1); display_Update(); } else { @@ -1947,7 +1955,7 @@ void verifyFLASH_GBA(unsigned long flashSize, uint32_t pos) { //open file on sd card if (!myFile.open(filePath, O_READ)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } // Seek to a new position in the file @@ -2010,7 +2018,7 @@ void writeEeprom_GBA(word eepSize) { // Close the file: myFile.close(); - println_Msg(F("done")); + print_STR(done_STR, 1); display_Update(); } else { println_Msg(F("Error")); @@ -2032,7 +2040,7 @@ void readEeprom_GBA(word eepSize) { sd.chdir(folder); // Save location - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); @@ -2043,7 +2051,7 @@ void readEeprom_GBA(word eepSize) { //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } // Each block contains 8 Bytes, so for a 8KB eeprom 1024 blocks need to be read @@ -2285,7 +2293,7 @@ unsigned long verifyEEP_GBA(word eepSize) { //open file on sd card if (!myFile.open(filePath, O_READ)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } // Fill sd Buffer @@ -2779,7 +2787,7 @@ boolean verifyFlashrom_GBA() { return 0; } } else { - print_Error(F("Can't open file"), true); + print_Error(open_file_STR, true); return 9999; } } @@ -2824,7 +2832,8 @@ void flashRepro_GBA() { println_Msg(F("Repro Cartridge.")); println_Msg(F("")); println_Msg(""); - println_Msg(F("Press Button")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); @@ -2903,7 +2912,7 @@ void flashRepro_GBA() { myFile.close(); // Verify - print_Msg(F("Verifying...")); + print_STR(verifying_STR, 0); display_Update(); if (strcmp(flashid, "8802") == 0) { // Don't know the correct size so just take some guesses @@ -2935,7 +2944,7 @@ void flashRepro_GBA() { } */ } else { - print_Error(F("Can't open file"), true); + print_Error(open_file_STR, true); } } else { println_Msg(F("Error")); diff --git a/Cart_Reader/GBM.ino b/Cart_Reader/GBM.ino index 7e388b6..1463059 100644 --- a/Cart_Reader/GBM.ino +++ b/Cart_Reader/GBM.ino @@ -42,7 +42,8 @@ void gbmMenu() { println_Msg(F("cartreader directly")); println_Msg(F("before reading")); println_Msg(""); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); // Clear screen @@ -71,7 +72,8 @@ void gbmMenu() { println_Msg(F("NP Cartridge.")); println_Msg(""); println_Msg(""); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); // Clear screen @@ -131,7 +133,8 @@ void gbmMenu() { println_Msg(F("NP Cartridge's")); println_Msg(F("mapping data")); println_Msg(""); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); @@ -171,7 +174,8 @@ void gbmMenu() { break; } println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } @@ -333,7 +337,7 @@ void readROM_GBM(word numBanks) { // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); } else { // Read rom word currAddress = 0; @@ -677,7 +681,7 @@ void writeFlash_GBM() { } // Close the file: myFile.close(); - println_Msg(F("Done")); + print_STR(done_STR, 1); } else { print_Error(F("Can't open file"), false); } @@ -716,7 +720,7 @@ void readMapping_GBM() { // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); } else { for (byte currByte = 0; currByte < 128; currByte++) { sdBuffer[currByte] = readByte_GBM(currByte); @@ -891,7 +895,7 @@ void writeMapping_GBM() { // Close the file: myFile.close(); - println_Msg(F("Done")); + print_STR(done_STR, 1); } else { print_Error(F("Can't open file"), false); } diff --git a/Cart_Reader/GBS.ino b/Cart_Reader/GBS.ino index 0c4aedd..403304e 100644 --- a/Cart_Reader/GBS.ino +++ b/Cart_Reader/GBS.ino @@ -11,8 +11,8 @@ // GB Smart menu items static const char gbSmartMenuItem1[] PROGMEM = "Game Menu"; static const char gbSmartMenuItem2[] PROGMEM = "Flash Menu"; -static const char gbSmartMenuItem3[] PROGMEM = "Reset"; -static const char* const menuOptionsGBSmart[] PROGMEM = { gbSmartMenuItem1, gbSmartMenuItem2, gbSmartMenuItem3 }; +//static const char gbSmartMenuItem3[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsGBSmart[] PROGMEM = { gbSmartMenuItem1, gbSmartMenuItem2, string_reset2 }; static const char gbSmartFlashMenuItem1[] PROGMEM = "Read Flash"; static const char gbSmartFlashMenuItem2[] PROGMEM = "Write Flash"; @@ -23,8 +23,8 @@ static const char gbSmartGameMenuItem1[] PROGMEM = "Read Game"; static const char gbSmartGameMenuItem2[] PROGMEM = "Read SRAM"; static const char gbSmartGameMenuItem3[] PROGMEM = "Write SRAM"; static const char gbSmartGameMenuItem4[] PROGMEM = "Switch Game"; -static const char gbSmartGameMenuItem5[] PROGMEM = "Reset"; -static const char* const menuOptionsGBSmartGame[] PROGMEM = { gbSmartGameMenuItem1, gbSmartGameMenuItem2, gbSmartGameMenuItem3, gbSmartGameMenuItem4, gbSmartGameMenuItem5 }; +//static const char gbSmartGameMenuItem5[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsGBSmartGame[] PROGMEM = { gbSmartGameMenuItem1, gbSmartGameMenuItem2, gbSmartGameMenuItem3, gbSmartGameMenuItem4, string_reset2 }; typedef struct { @@ -216,10 +216,10 @@ void gbSmartGameOptions() { println_Msg(F("Verified OK")); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(wrErrors); println_Msg(F(" bytes")); - print_Error(F("did not verify."), false); + print_Error(did_not_verify_STR, false); } break; } @@ -238,7 +238,8 @@ void gbSmartGameOptions() { if (gameSubMenu != 3) { println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } @@ -310,7 +311,8 @@ void gbSmartFlashMenu() { println_Msg(F("This will erase your")); println_Msg(F("GB Smart Cartridge.")); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); @@ -331,7 +333,8 @@ void gbSmartFlashMenu() { } println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } @@ -419,7 +422,7 @@ void gbSmartReadFlash() { display_Update(); if (!myFile.open(fileName, O_RDWR | O_CREAT)) - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); // reset flash to read array state for (int i = 0x00; i < gbSmartBanks; i += gbSmartBanksPerFlashChip) @@ -470,7 +473,7 @@ void gbSmartWriteFlash() { gbSmartEraseFlash(bank); gbSmartResetFlash(bank); - println_Msg(F("Done")); + print_STR(done_STR, 1); print_Msg(F("Blankcheck...")); display_Update(); @@ -487,7 +490,7 @@ void gbSmartWriteFlash() { gbSmartWriteFlashByte(0x0000, 0xff); } - print_Msg(F("Verifying...")); + print_STR(verifying_STR, 0); display_Update(); writeErrors = gbSmartVerifyFlash(); @@ -495,16 +498,16 @@ void gbSmartWriteFlash() { println_Msg(F("OK")); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(writeErrors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), true); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, true); } } void gbSmartWriteFlash(uint32_t start_bank) { if (!myFile.open(filePath, O_READ)) - print_Error(F("Can't open file on SD"), true); + print_Error(open_file_STR, true); // switch to flash base bank gbSmartRemapStartBank(start_bank, gbSmartFlashSizeGB, gbSmartSramSizeGB); diff --git a/Cart_Reader/INTV.ino b/Cart_Reader/INTV.ino index 1c9c335..2792239 100644 --- a/Cart_Reader/INTV.ino +++ b/Cart_Reader/INTV.ino @@ -95,8 +95,8 @@ byte newintvsize; static const char intvMenuItem1[] PROGMEM = "Select Cart"; static const char intvMenuItem2[] PROGMEM = "Read ROM"; static const char intvMenuItem3[] PROGMEM = "Set Mapper + Size"; -static const char intvMenuItem4[] PROGMEM = "Reset"; -static const char* const menuOptionsINTV[] PROGMEM = { intvMenuItem1, intvMenuItem2, intvMenuItem3, intvMenuItem4 }; +//static const char intvMenuItem4[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsINTV[] PROGMEM = { intvMenuItem1, intvMenuItem2, intvMenuItem3, string_reset2 }; void setup_INTV() { // Set Address Pins to Output (UNUSED) @@ -316,14 +316,14 @@ void readROM_INTV() { sd.chdir(folder); display_Clear(); - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); // open file on sdcard if (!myFile.open(fileName, O_RDWR | O_CREAT)) - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); // write new folder number back to EEPROM foldern++; @@ -423,7 +423,8 @@ void readROM_INTV() { compareCRC("intv.txt", 0, 1, 0); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } @@ -528,11 +529,11 @@ void setMapper_INTV() { println_Msg(intvmapselect); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to Change")); - println_Msg(F("and right to Select")); + print_STR(press_to_change_STR, 1); + print_STR(right_to_select_STR, 1); #elif defined(enable_LCD) - println_Msg(F("Rotate to Change")); - println_Msg(F("Press to Select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #endif display_Update(); @@ -553,11 +554,11 @@ void setMapper_INTV() { println_Msg(intvmapselect); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to Change")); - println_Msg(F("and right to Select")); + print_STR(press_to_change_STR, 1); + print_STR(right_to_select_STR, 1); #elif defined(enable_LCD) - println_Msg(F("Rotate to Change")); - println_Msg(F("Press to Select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #endif display_Update(); } @@ -575,11 +576,11 @@ void setMapper_INTV() { println_Msg(intvmapselect); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to Change")); - println_Msg(F("and right to Select")); + print_STR(press_to_change_STR, 1); + print_STR(right_to_select_STR, 1); #elif defined(enable_LCD) - println_Msg(F("Rotate to Change")); - println_Msg(F("Press to Select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #endif display_Update(); } @@ -647,11 +648,11 @@ void setROMSize_INTV() { println_Msg(INTV[i]); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to Change")); - println_Msg(F("and right to Select")); + print_STR(press_to_change_STR, 1); + print_STR(right_to_select_STR, 1); #elif defined(enable_LCD) - println_Msg(F("Rotate to Change")); - println_Msg(F("Press to Select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #endif display_Update(); @@ -669,11 +670,11 @@ void setROMSize_INTV() { println_Msg(INTV[i]); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to Change")); - println_Msg(F("and right to Select")); + print_STR(press_to_change_STR, 1); + print_STR(right_to_select_STR, 1); #elif defined(enable_LCD) - println_Msg(F("Rotate to Change")); - println_Msg(F("Press to Select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #endif display_Update(); } @@ -688,11 +689,11 @@ void setROMSize_INTV() { println_Msg(INTV[i]); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to Change")); - println_Msg(F("and right to Select")); + print_STR(press_to_change_STR, 1); + print_STR(right_to_select_STR, 1); #elif defined(enable_LCD) - println_Msg(F("Rotate to Change")); - println_Msg(F("Press to Select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #endif display_Update(); } @@ -887,11 +888,11 @@ void setCart_INTV() { print_Msg(F("Mapper: ")); println_Msg(intvmapper); #if defined(enable_OLED) - println_Msg(F("Press left to Change")); - println_Msg(F("and right to Select")); + print_STR(press_to_change_STR, 1); + print_STR(right_to_select_STR, 1); #elif defined(enable_LCD) - println_Msg(F("Rotate to Change")); - println_Msg(F("Press to Select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #elif defined(SERIAL_MONITOR) println_Msg(F("U/D to Change")); println_Msg(F("Space to Select")); diff --git a/Cart_Reader/MD.ino b/Cart_Reader/MD.ino index 82464f1..43bc439 100644 --- a/Cart_Reader/MD.ino +++ b/Cart_Reader/MD.ino @@ -192,8 +192,8 @@ void mdLoadConf() { static const char MDMenuItem1[] PROGMEM = "Game Cartridge"; static const char MDMenuItem2[] PROGMEM = "SegaCD RamCart"; static const char MDMenuItem3[] PROGMEM = "Flash Repro"; -static const char MDMenuItem4[] PROGMEM = "Reset"; -static const char* const menuOptionsMD[] PROGMEM = { MDMenuItem1, MDMenuItem2, MDMenuItem3, MDMenuItem4 }; +//static const char MDMenuItem4[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsMD[] PROGMEM = { MDMenuItem1, MDMenuItem2, MDMenuItem3, string_reset2 }; // Cart menu items static const char MDCartMenuItem1[] PROGMEM = "Read Rom"; @@ -202,14 +202,14 @@ static const char MDCartMenuItem3[] PROGMEM = "Write Sram"; static const char MDCartMenuItem4[] PROGMEM = "Read EEPROM"; static const char MDCartMenuItem5[] PROGMEM = "Write EEPROM"; static const char MDCartMenuItem6[] PROGMEM = "Cycle cart"; -static const char MDCartMenuItem7[] PROGMEM = "Reset"; -static const char* const menuOptionsMDCart[] PROGMEM = { MDCartMenuItem1, MDCartMenuItem2, MDCartMenuItem3, MDCartMenuItem4, MDCartMenuItem5, MDCartMenuItem6, MDCartMenuItem7 }; +//static const char MDCartMenuItem7[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsMDCart[] PROGMEM = { MDCartMenuItem1, MDCartMenuItem2, MDCartMenuItem3, MDCartMenuItem4, MDCartMenuItem5, MDCartMenuItem6, string_reset2 }; // Sega CD Ram Backup Cartridge menu items static const char SCDMenuItem1[] PROGMEM = "Read Backup RAM"; static const char SCDMenuItem2[] PROGMEM = "Write Backup RAM"; -static const char SCDMenuItem3[] PROGMEM = "Reset"; -static const char* const menuOptionsSCD[] PROGMEM = { SCDMenuItem1, SCDMenuItem2, SCDMenuItem3 }; +//static const char SCDMenuItem3[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsSCD[] PROGMEM = { SCDMenuItem1, SCDMenuItem2, string_reset2 }; // Sega start menu void mdMenu() { @@ -275,7 +275,8 @@ void mdMenu() { // Set CS(PH3) HIGH PORTH |= (1 << 3); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); break; @@ -350,10 +351,10 @@ void mdCartMenu() { println_Msg(F("Sram verified OK")); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(writeErrors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } } else { print_Error(F("Cart has no Sram"), false); @@ -400,7 +401,8 @@ void mdCartMenu() { resetArduino(); break; } - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } @@ -441,7 +443,8 @@ void segaCDMenu() { break; } println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } @@ -1082,7 +1085,8 @@ void getCartInfo_MD() { // Wait for user input #if (defined(enable_LCD) || defined(enable_OLED)) - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); #endif @@ -1155,7 +1159,7 @@ void readROM_MD() { sd.chdir(folder); display_Clear(); - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); @@ -1166,7 +1170,7 @@ void readROM_MD() { // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } byte buffer[1024] = { 0 }; @@ -1489,10 +1493,10 @@ void writeSram_MD() { // Close the file: myFile.close(); - println_Msg(F("Done")); + print_STR(done_STR, 1); display_Update(); } else { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } dataIn_MD(); } @@ -1517,7 +1521,7 @@ void readSram_MD() { // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } for (unsigned long currBuffer = sramBase; currBuffer < sramBase + sramSize; currBuffer += 256) { @@ -1611,7 +1615,7 @@ unsigned long verifySram_MD() { // Close the file: myFile.close(); } else { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } // Return 0 if verified ok, or number of errors return writeErrors; @@ -1637,7 +1641,7 @@ void resetFlash_MD() { void write29F1610_MD() { // Create filepath sprintf(filePath, "%s/%s", filePath, fileName); - print_Msg(F("Flashing file ")); + print_STR(flashing_file_STR, 0); print_Msg(filePath); println_Msg(F("...")); display_Update(); @@ -1647,7 +1651,7 @@ void write29F1610_MD() { // Get rom size from file fileSize = myFile.fileSize(); if (fileSize > flashSize) { - print_Error(F("File size exceeds flash size."), true); + print_Error(file_too_big_STR, true); } // Set data pins to output dataOut_MD(); @@ -1686,7 +1690,7 @@ void write29F1610_MD() { // Close the file: myFile.close(); } else { - println_Msg(F("Can't open file")); + print_STR(open_file_STR, 1); display_Update(); } } @@ -1764,7 +1768,7 @@ void verifyFlash_MD() { // Get rom size from file fileSize = myFile.fileSize(); if (fileSize > flashSize) { - print_Error(F("File size exceeds flash size."), true); + print_Error(file_too_big_STR, true); } blank = 0; @@ -1789,15 +1793,15 @@ void verifyFlash_MD() { println_Msg(F("Flashrom verified OK")); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(blank); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } // Close the file: myFile.close(); } else { - println_Msg(F("Can't open file")); + print_STR(open_file_STR, 1); display_Update(); } } @@ -2382,7 +2386,7 @@ void readEEP_MD() { // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } if (eepSize > 0x100) { // 24C04+ for (word currByte = 0; currByte < eepSize; currByte += 256) { @@ -2448,10 +2452,10 @@ void writeEEP_MD() { myFile.close(); println_Msg(F("")); display_Clear(); - println_Msg(F("Done")); + print_STR(done_STR, 1); display_Update(); } else { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } dataIn_MD(); } @@ -2481,7 +2485,7 @@ void readBram_MD() { // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } for (unsigned long currByte = 0; currByte < bramSize; currByte += 512) { @@ -2527,10 +2531,10 @@ void writeBram_MD() { myFile.close(); println_Msg(F("")); display_Clear(); - println_Msg(F("Done")); + print_STR(done_STR, 1); display_Update(); } else { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } dataIn_MD(); } @@ -2568,7 +2572,7 @@ void readRealtec_MD() { sd.chdir(folder); display_Clear(); - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); @@ -2579,7 +2583,7 @@ void readRealtec_MD() { // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } // Realtec Registers diff --git a/Cart_Reader/N64.ino b/Cart_Reader/N64.ino index 4d09619..8b6ee62 100644 --- a/Cart_Reader/N64.ino +++ b/Cart_Reader/N64.ino @@ -58,30 +58,30 @@ static const char n64MenuItem1[] PROGMEM = "Game Cartridge"; static const char n64MenuItem2[] PROGMEM = "Controller"; static const char n64MenuItem3[] PROGMEM = "Flash Repro"; static const char n64MenuItem4[] PROGMEM = "Flash Gameshark"; -static const char n64MenuItem5[] PROGMEM = "Reset"; -static const char* const menuOptionsN64[] PROGMEM = { n64MenuItem1, n64MenuItem2, n64MenuItem3, n64MenuItem4, n64MenuItem5 }; +//static const char n64MenuItem5[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsN64[] PROGMEM = { n64MenuItem1, n64MenuItem2, n64MenuItem3, n64MenuItem4, string_reset2 }; // N64 controller menu items static const char N64ContMenuItem1[] PROGMEM = "Test Controller"; static const char N64ContMenuItem2[] PROGMEM = "Read ControllerPak"; static const char N64ContMenuItem3[] PROGMEM = "Write ControllerPak"; -static const char N64ContMenuItem4[] PROGMEM = "Reset"; -static const char* const menuOptionsN64Controller[] PROGMEM = { N64ContMenuItem1, N64ContMenuItem2, N64ContMenuItem3, N64ContMenuItem4 }; +//static const char N64ContMenuItem4[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsN64Controller[] PROGMEM = { N64ContMenuItem1, N64ContMenuItem2, N64ContMenuItem3, string_reset2 }; // N64 cart menu items static const char N64CartMenuItem1[] PROGMEM = "Read ROM"; static const char N64CartMenuItem2[] PROGMEM = "Read Save"; static const char N64CartMenuItem3[] PROGMEM = "Write Save"; static const char N64CartMenuItem4[] PROGMEM = "Force Savetype"; -static const char N64CartMenuItem5[] PROGMEM = "Reset"; -static const char* const menuOptionsN64Cart[] PROGMEM = { N64CartMenuItem1, N64CartMenuItem2, N64CartMenuItem3, N64CartMenuItem4, N64CartMenuItem5 }; +//static const char N64CartMenuItem5[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsN64Cart[] PROGMEM = { N64CartMenuItem1, N64CartMenuItem2, N64CartMenuItem3, N64CartMenuItem4, string_reset2 }; // N64 CRC32 error menu items static const char N64CRCMenuItem1[] PROGMEM = "No"; static const char N64CRCMenuItem2[] PROGMEM = "Yes and keep old"; static const char N64CRCMenuItem3[] PROGMEM = "Yes and delete old"; -static const char N64CRCMenuItem4[] PROGMEM = "Reset"; -static const char* const menuOptionsN64CRC[] PROGMEM = { N64CRCMenuItem1, N64CRCMenuItem2, N64CRCMenuItem3, N64CRCMenuItem4 }; +//static const char N64CRCMenuItem4[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsN64CRC[] PROGMEM = { N64CRCMenuItem1, N64CRCMenuItem2, N64CRCMenuItem3, string_reset2 }; // Rom menu static const char N64RomItem1[] PROGMEM = "4 MB"; @@ -194,7 +194,8 @@ void n64ControllerMenu() { verifyCRC(); validateMPK(); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); break; @@ -215,7 +216,8 @@ void n64ControllerMenu() { delay(500); verifyMPK(); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); break; @@ -266,7 +268,8 @@ void n64CartMenu() { print_Error(F("Savetype Error"), false); } println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); break; @@ -285,10 +288,10 @@ void n64CartMenu() { println_Msg(F("SRAM verified OK")); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(writeErrors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } } else if (saveType == 4) { // Launch file browser @@ -296,7 +299,7 @@ void n64CartMenu() { display_Clear(); getFramType(); writeFram(flashramType); - print_Msg(F("Verifying...")); + print_STR(verifying_STR, 0); display_Update(); writeErrors = verifyFram(flashramType); if (writeErrors == 0) { @@ -304,10 +307,10 @@ void n64CartMenu() { display_Update(); } else { println_Msg(""); - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(writeErrors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } } else if ((saveType == 5) || (saveType == 6)) { // Launch file browser @@ -326,16 +329,17 @@ void n64CartMenu() { println_Msg(F("EEPROM verified OK")); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(writeErrors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } } else { display_Clear(); print_Error(F("Save Type Error"), false); } - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); break; @@ -1611,12 +1615,12 @@ void readMPK() { strcat(filePath, ".crc"); FsFile crcFile; if (!crcFile.open(filePath, O_RDWR | O_CREAT)) { - print_Error(F("Can't open file on SD"), true); + print_Error(open_file_STR, true); } //open mpk file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("Can't open file on SD"), true); + print_Error(open_file_STR, true); } print_Msg(F("Saving N64/MPK/")); @@ -1669,18 +1673,18 @@ void readMPK() { void verifyCRC() { writeErrors = 0; - println_Msg(F("Verifying...")); + print_STR(verifying_STR, 1); display_Update(); //open CRC file on sd card FsFile crcFile; if (!crcFile.open(filePath, O_READ)) { - print_Error(F("Can't open file on SD"), true); + print_Error(open_file_STR, true); } //open MPK file on sd card if (!myFile.open(fileName, O_READ)) { - print_Error(F("Can't open file on SD"), true); + print_Error(open_file_STR, true); } //Initialize progress bar @@ -1715,10 +1719,10 @@ void verifyCRC() { sd.remove(filePath); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(writeErrors); println_Msg(F(" blocks ")); - print_Error(F("did not verify."), false); + print_Error(did_not_verify_STR, false); } } @@ -1743,7 +1747,7 @@ boolean checkHeader(byte startAddress) { void validateMPK() { //open file on sd card if (!myFile.open(fileName, O_READ)) { - print_Error(F("Can't open file"), true); + print_Error(open_file_STR, true); } // Read first 256 byte which contains the header including checksum and reverse checksum and three copies of it @@ -1856,7 +1860,7 @@ void writeMPK() { // Close the file: myFile.close(); } else { - print_Error(F("Can't open file on SD"), true); + print_Error(open_file_STR, true); } } @@ -1864,12 +1868,12 @@ void writeMPK() { void verifyMPK() { writeErrors = 0; - println_Msg(F("Verifying...")); + print_STR(verifying_STR, 1); display_Update(); //open file on sd card if (!myFile.open(filePath, O_READ)) { - print_Error(F("Can't open file on SD"), true); + print_Error(open_file_STR, true); } //Initialize progress bar @@ -1911,10 +1915,10 @@ void verifyMPK() { println_Msg(F("Written successfully")); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(writeErrors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } } @@ -1963,7 +1967,8 @@ void printCartInfo_N64() { // Wait for user input println_Msg(F(" ")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } else { @@ -1982,7 +1987,8 @@ void printCartInfo_N64() { strcpy(romName, "GPERROR"); print_Error(F("Cartridge unknown"), false); println_Msg(""); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); @@ -2344,11 +2350,11 @@ void writeEeprom_CLK() { // Close the file: myFile.close(); - println_Msg(F("Done")); + print_STR(done_STR, 1); display_Update(); delay(600); } else { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } } else { print_Error(F("Savetype Error"), true); @@ -2378,7 +2384,7 @@ void readEeprom_CLK() { // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); } for (byte i = 0; i < (eepPages / 64); i++) { @@ -2481,7 +2487,7 @@ unsigned long verifyEeprom_CLK() { } else { // SD Error writeErrors = 999999; - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } // Return 0 if verified ok, or number of errors return writeErrors; @@ -2713,11 +2719,11 @@ void writeEeprom() { // Close the file: myFile.close(); - println_Msg(F("Done")); + print_STR(done_STR, 1); display_Update(); delay(600); } else { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } } else { print_Error(F("Savetype Error"), true); @@ -2743,7 +2749,7 @@ void readEeprom() { // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); } for (byte i = 0; i < (eepPages / 64); i++) { @@ -2847,7 +2853,7 @@ unsigned long verifyEeprom() { } else { // SD Error writeErrors = 999999; - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } // Return 0 if verified ok, or number of errors return writeErrors; @@ -2888,10 +2894,10 @@ void writeSram(unsigned long sramSize) { } // Close the file: myFile.close(); - println_Msg(F("Done")); + print_STR(done_STR, 1); display_Update(); } else { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } } else { @@ -2931,7 +2937,7 @@ void readSram(unsigned long sramSize, byte flashramType) { // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } for (unsigned long currByte = sramBase; currByte < (sramBase + (sramSize / flashramType)); currByte += offset) { @@ -2994,7 +3000,7 @@ unsigned long verifySram(unsigned long sramSize, byte flashramType) { // Close the file: myFile.close(); } else { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } // Return 0 if verified ok, or number of errors return writeErrors; @@ -3100,7 +3106,7 @@ void writeFram(byte flashramType) { // Close the file: myFile.close(); } else { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } } else { print_Error(F("Savetype Error"), true); @@ -3327,7 +3333,7 @@ redumpnewfolder: sd.chdir(folder); display_Clear(); - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); @@ -3339,7 +3345,7 @@ redumpnewfolder: redumpsamefolder: // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } // dumping rom slow @@ -3478,7 +3484,8 @@ redumpsamefolder: print_Msg(timeElapsed); // include elapsed time println_Msg(F("s)")); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); // This saves a tt file with rom info next to the dumped rom #ifdef savesummarytotxt @@ -3493,7 +3500,8 @@ redumpsamefolder: errorLvl = 1; setColor_RGB(255, 0, 0); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); // This saves a tt file with rom info next to the dumped rom #ifdef savesummarytotxt @@ -3528,7 +3536,7 @@ redumpsamefolder: sd.chdir(folder); // Delete old file if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } if (!myFile.remove()) { print_Error(F("Delete Error"), true); @@ -3554,7 +3562,7 @@ redumpsamefolder: void savesummary_N64(boolean checkfound, char crcStr[9], unsigned long timeElapsed) { // Open file on sd card if (!myFile.open("N64/ROM/n64log.txt", O_RDWR | O_CREAT | O_APPEND)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } //Write the info @@ -3675,7 +3683,8 @@ void flashRepro_N64() { println_Msg(F("Repro Cartridge.")); println_Msg(F("Attention: Use 3.3V!")); println_Msg(""); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } else { @@ -3821,7 +3830,7 @@ void flashRepro_N64() { // Compare file size to flashrom size if ((fileSize / 1048576) > cartSize) { - print_Error(F("File too big"), true); + print_Error(file_too_big_STR, true); } // Erase needed sectors @@ -3879,7 +3888,7 @@ void flashRepro_N64() { myFile.close(); // Verify - print_Msg(F("Verifying...")); + print_STR(verifying_STR, 0); display_Update(); writeErrors = verifyFlashrom_N64(); if (writeErrors == 0) { @@ -3888,7 +3897,7 @@ void flashRepro_N64() { } else { print_Msg(writeErrors); print_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_Error(did_not_verify_STR, false); } } else { // Close the file @@ -3899,7 +3908,8 @@ void flashRepro_N64() { print_Error(F("Can't open file"), false); } - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); display_Clear(); @@ -4598,7 +4608,7 @@ unsigned long verifyFlashrom_N64() { myFile.close(); return writeErrors; } else { - println_Msg(F("Can't open file")); + print_STR(open_file_STR, 1); display_Update(); return 9999; } @@ -4627,7 +4637,8 @@ void flashGameshark_N64() { println_Msg(F("Gameshark cartridge")); println_Msg(F("Attention: Use 3.3V!")); println_Msg(F("Power OFF if Unsure!")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); @@ -4652,7 +4663,7 @@ void flashGameshark_N64() { // Compare file size to flashrom size if (fileSize > 262144) { - print_Error(F("File too big"), true); + print_Error(file_too_big_STR, true); } // SST 29LE010, chip erase not needed as this eeprom automaticly erases during the write cycle @@ -4668,7 +4679,7 @@ void flashGameshark_N64() { myFile.close(); // Verify - print_Msg(F("Verifying...")); + print_STR(verifying_STR, 0); display_Update(); writeErrors = verifyGameshark_N64(); @@ -4682,7 +4693,7 @@ void flashGameshark_N64() { } else { print_Msg(writeErrors); print_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_Error(did_not_verify_STR, false); } } else { print_Error(F("Can't open file"), false); @@ -4695,7 +4706,8 @@ void flashGameshark_N64() { print_Error(F("Unknown flashrom"), false); } - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); display_Clear(); @@ -4755,7 +4767,7 @@ void backupGameshark_N64() { // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } for (unsigned long currByte = romBase + 0xC00000; currByte < (romBase + 0xC00000 + 262144); currByte += 512) { @@ -4865,7 +4877,7 @@ unsigned long verifyGameshark_N64() { myFile.close(); return writeErrors; } else { - println_Msg(F("Can't open file")); + print_STR(open_file_STR, 1); display_Update(); return 9999; } diff --git a/Cart_Reader/NES.ino b/Cart_Reader/NES.ino index 51dd343..d559ce6 100644 --- a/Cart_Reader/NES.ino +++ b/Cart_Reader/NES.ino @@ -227,8 +227,8 @@ static const char nesMenuItem3[] PROGMEM = "Read Sram"; static const char nesMenuItem4[] PROGMEM = "Write Sram"; static const char nesMenuItem5[] PROGMEM = "Change Mapper"; static const char nesMenuItem6[] PROGMEM = "Flash NESMaker"; -static const char nesMenuItem7[] PROGMEM = "Reset"; -static const char* const menuOptionsNES[] PROGMEM = { nesMenuItem1, nesMenuItem2, nesMenuItem3, nesMenuItem4, nesMenuItem5, nesMenuItem6, nesMenuItem7 }; +//static const char nesMenuItem7[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsNES[] PROGMEM = { nesMenuItem1, nesMenuItem2, nesMenuItem3, nesMenuItem4, nesMenuItem5, nesMenuItem6, string_reset2 }; // NES chips menu #ifndef nointro @@ -269,7 +269,8 @@ void nesMenu() { sd.chdir("/"); readRom_NES(); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); #ifdef global_log save_log(); #endif @@ -289,7 +290,8 @@ void nesMenu() { readRAM(); resetROM(); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); break; @@ -299,7 +301,8 @@ void nesMenu() { writeRAM(); resetROM(); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); break; @@ -329,7 +332,8 @@ void nesMenu() { println_Msg(F("Error:")); println_Msg(F("Can't write to this cartridge")); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); } wait(); @@ -361,14 +365,16 @@ void nesChipMenu() { resetROM(); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); #else display_Clear(); // Change working dir to root sd.chdir("/"); readRaw_NES(); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); #ifdef global_log save_log(); #endif @@ -383,7 +389,8 @@ void nesChipMenu() { readPRG(false); resetROM(); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); break; @@ -394,7 +401,8 @@ void nesChipMenu() { readCHR(false); resetROM(); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); break; @@ -717,11 +725,11 @@ boolean getMapping() { println_Msg(F("K")); } #if defined(enable_OLED) - println_Msg(F("Press left to Change")); - println_Msg(F("and right to Select")); + print_STR(press_to_change_STR, 1); + print_STR(right_to_select_STR, 1); #elif defined(enable_LCD) - println_Msg(F("Rotate to Change")); - println_Msg(F("Press to Select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #elif defined(SERIAL_MONITOR) println_Msg(F("U/D to Change")); println_Msg(F("Space to Select")); @@ -1005,11 +1013,11 @@ void selectMapping() { println_Msg(F("K")); } #if defined(enable_OLED) - println_Msg(F("Press left to Change")); - println_Msg(F("and right to Select")); + print_STR(press_to_change_STR, 1); + print_STR(right_to_select_STR, 1); #elif defined(enable_LCD) - println_Msg(F("Rotate to Change")); - println_Msg(F("Press to Select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #elif defined(SERIAL_MONITOR) println_Msg(F("U/D to Change")); println_Msg(F("Space to Select")); @@ -1101,7 +1109,7 @@ void readRom_NES() { sd.chdir(folder); display_Clear(); - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); @@ -1112,7 +1120,7 @@ void readRom_NES() { // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } //Initialize progress bar @@ -1160,7 +1168,7 @@ void readRaw_NES() { sd.chdir(folder); display_Clear(); - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); @@ -1171,7 +1179,7 @@ void readRaw_NES() { // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } //Initialize progress bar @@ -1530,7 +1538,7 @@ void CreatePRGFileInSD() { display_Clear(); println_Msg(F("PRG FILE FAILED!")); display_Update(); - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); LED_RED_OFF; } @@ -1555,7 +1563,7 @@ void CreateCHRFileInSD() { display_Clear(); println_Msg(F("CHR FILE FAILED!")); display_Update(); - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); LED_RED_OFF; } @@ -1580,7 +1588,7 @@ void CreateRAMFileInSD() { display_Clear(); println_Msg(F("RAM FILE FAILED!")); display_Update(); - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); LED_RED_OFF; } @@ -1682,7 +1690,7 @@ void outputNES() { display_Clear(); println_Msg(F("PRG FILE FAILED!")); display_Update(); - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } if (has_header) { @@ -1702,7 +1710,7 @@ void outputNES() { display_Clear(); println_Msg(F("NES FILE FAILED!")); display_Update(); - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } if (has_header) { @@ -1726,7 +1734,7 @@ void outputNES() { display_Clear(); println_Msg(F("CHR FILE FAILED!")); display_Update(); - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } while ((n = myFile.read(sdBuffer, sizeof(sdBuffer))) > 0) { nesFile.write(sdBuffer, n); @@ -2065,7 +2073,7 @@ chooseMapper: println_Msg(""); println_Msg(""); println_Msg(""); - println_Msg(F("Press left to change")); + print_STR(press_to_change_STR, 1); println_Msg(F("Press right to select")); if (digit == 0) { @@ -2185,8 +2193,8 @@ chooseMapper: print_Msg(F("Mapper: ")); println_Msg(mapselect); println_Msg(F("")); - println_Msg(F("Rotate to change")); - println_Msg(F("Press to select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); display_Update(); while (1) { @@ -2203,8 +2211,8 @@ chooseMapper: print_Msg(F("Mapper: ")); println_Msg(mapselect); println_Msg(F("")); - println_Msg(F("Rotate to change")); - println_Msg(F("Press to select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); display_Update(); } @@ -2219,8 +2227,8 @@ chooseMapper: print_Msg(F("Mapper: ")); println_Msg(mapselect); println_Msg(F("")); - println_Msg(F("Rotate to change")); - println_Msg(F("Press to select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); display_Update(); } @@ -2321,11 +2329,11 @@ void setPRGSize() { println_Msg(PRG[i]); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to change")); + print_STR(press_to_change_STR, 1); println_Msg(F("Press right to select")); #elif defined(enable_LCD) - println_Msg(F("Rotate to change")); - println_Msg(F("Press to select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #endif display_Update(); @@ -2343,11 +2351,11 @@ void setPRGSize() { println_Msg(PRG[i]); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to change")); + print_STR(press_to_change_STR, 1); println_Msg(F("Press right to select")); #elif defined(enable_LCD) - println_Msg(F("Rotate to change")); - println_Msg(F("Press to select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #endif display_Update(); } @@ -2362,11 +2370,11 @@ void setPRGSize() { println_Msg(PRG[i]); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to change")); + print_STR(press_to_change_STR, 1); println_Msg(F("Press right to select")); #elif defined(enable_LCD) - println_Msg(F("Rotate to change")); - println_Msg(F("Press to select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #endif display_Update(); } @@ -2441,11 +2449,11 @@ void setCHRSize() { println_Msg(CHR[i]); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to change")); + print_STR(press_to_change_STR, 1); println_Msg(F("Press right to select")); #elif defined(enable_LCD) - println_Msg(F("Rotate to change")); - println_Msg(F("Press to select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #endif display_Update(); @@ -2463,11 +2471,11 @@ void setCHRSize() { println_Msg(CHR[i]); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to change")); + print_STR(press_to_change_STR, 1); println_Msg(F("Press right to select")); #elif defined(enable_LCD) - println_Msg(F("Rotate to change")); - println_Msg(F("Press to select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #endif display_Update(); } @@ -2483,11 +2491,11 @@ void setCHRSize() { println_Msg(CHR[i]); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to change")); + print_STR(press_to_change_STR, 1); println_Msg(F("Press right to select")); #elif defined(enable_LCD) - println_Msg(F("Rotate to change")); - println_Msg(F("Press to select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #endif display_Update(); } @@ -2576,11 +2584,11 @@ void setRAMSize() { println_Msg(RAM[i]); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to change")); + print_STR(press_to_change_STR, 1); println_Msg(F("Press right to select")); #elif defined(enable_LCD) - println_Msg(F("Rotate to change")); - println_Msg(F("Press to select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #endif display_Update(); @@ -2612,11 +2620,11 @@ void setRAMSize() { println_Msg(RAM[i]); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to change")); + print_STR(press_to_change_STR, 1); println_Msg(F("Press right to select")); #elif defined(enable_LCD) - println_Msg(F("Rotate to change")); - println_Msg(F("Press to select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #endif display_Update(); } @@ -2646,11 +2654,11 @@ void setRAMSize() { println_Msg(RAM[i]); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to change")); + print_STR(press_to_change_STR, 1); println_Msg(F("Press right to select")); #elif defined(enable_LCD) - println_Msg(F("Rotate to change")); - println_Msg(F("Press to select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #endif display_Update(); } @@ -2859,7 +2867,8 @@ void checkStatus_NES() { println_Msg(F("K")); } println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } @@ -4808,7 +4817,7 @@ void writeRAM() { display_Update(); } else { - print_Error(F("SD ERROR"), true); + print_Error(sd_error_STR, true); } } diff --git a/Cart_Reader/NGP.ino b/Cart_Reader/NGP.ino index 79386f3..cad21aa 100644 --- a/Cart_Reader/NGP.ino +++ b/Cart_Reader/NGP.ino @@ -5,8 +5,8 @@ static const char ngpMenuItem1[] PROGMEM = "Read Rom"; static const char ngpMenuItem2[] PROGMEM = "Read chip info"; -static const char ngpMenuItemReset[] PROGMEM = "Reset"; -static const char* const menuOptionsNGP[] PROGMEM = { ngpMenuItem1, ngpMenuItem2, ngpMenuItemReset }; +//static const char ngpMenuItemReset[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsNGP[] PROGMEM = { ngpMenuItem1, ngpMenuItem2, string_reset2 }; static const char ngpRomItem1[] PROGMEM = "4 Mbits / 512 KB"; static const char ngpRomItem2[] PROGMEM = "8 Mbits / 1 MB"; @@ -73,7 +73,8 @@ void ngpMenu() { } println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } @@ -169,7 +170,8 @@ void printCartInfo_NGP() { println_Msg(F(" Mbits")); } - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } @@ -206,14 +208,14 @@ void readROM_NGP(char* outPathBuf, size_t bufferSize) { snprintf(outPathBuf, bufferSize, "%s/%s", folder, fileName); display_Clear(); - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); // open file on sdcard if (!myFile.open(fileName, O_RDWR | O_CREAT)) - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); // write new folder number back to EEPROM foldern++; @@ -264,7 +266,7 @@ void scanChip_NGP() { // open file on sdcard if (!myFile.open(fileName, O_RDWR | O_CREAT)) - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); // write new folder number back to EEPROM foldern++; diff --git a/Cart_Reader/PCE.ino b/Cart_Reader/PCE.ino index 5c44f5a..0366a78 100644 --- a/Cart_Reader/PCE.ino +++ b/Cart_Reader/PCE.ino @@ -54,14 +54,14 @@ uint8_t tennokoe_bank_index = 0; static const char pceMenuItem1[] PROGMEM = "HuCARD (swapped)"; static const char pceMenuItem2[] PROGMEM = "HuCARD(not swapped)"; static const char pceMenuItem3[] PROGMEM = "Turbochip"; -static const char pceMenuItem4[] PROGMEM = "Reset"; -static const char *const menuOptionspce[] PROGMEM = { pceMenuItem1, pceMenuItem2, pceMenuItem3, pceMenuItem4 }; +//static const char pceMenuItem4[] PROGMEM = "Reset"; (stored in common strings array) +static const char *const menuOptionspce[] PROGMEM = { pceMenuItem1, pceMenuItem2, pceMenuItem3, string_reset2 }; // PCE card menu items static const char pceCartMenuItem1[] = "Read ROM"; static char pceCartMenuItem2[20]; static char pceCartMenuItem3[20]; -static const char pceCartMenuItem4[] = "Reset"; +//static const char pceCartMenuItem4[] = "Reset"; (stored in common strings array) static const char pceCartMenuItem5[] = "Inc Bank Number"; static const char pceCartMenuItem6[] = "Dec Bank Number"; static char pceCartMenuItem7[20]; @@ -69,8 +69,8 @@ static char menuOptionspceCart[7][20]; // Turbochip menu items static const char pceTCMenuItem1[] PROGMEM = "Read ROM"; -static const char pceTCMenuItem2[] PROGMEM = "Reset"; -static const char *const menuOptionspceTC[] PROGMEM = { pceTCMenuItem1, pceTCMenuItem2 }; +//static const char pceTCMenuItem2[] PROGMEM = "Reset"; (stored in common strings array) +static const char *const menuOptionspceTC[] PROGMEM = { pceTCMenuItem1, string_reset2 }; // PCE start menu void pcsMenu(void) { @@ -549,7 +549,7 @@ void read_tennokoe_bank_PCE(int bank_index) { //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); } pin_read_write_PCE(); @@ -688,8 +688,8 @@ void write_tennokoe_bank_PCE(int bank_index) { } else { println_Msg(F("Verify failed...")); print_Msg(diffcnt); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } pin_init_PCE(); @@ -743,7 +743,7 @@ void read_rom_PCE(void) { //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); } pin_read_write_PCE(); @@ -800,7 +800,7 @@ void pceMenu() { strcpy(menuOptionspceCart[0], pceCartMenuItem1); strcpy(menuOptionspceCart[1], pceCartMenuItem2); strcpy(menuOptionspceCart[2], pceCartMenuItem3); - strcpy(menuOptionspceCart[3], pceCartMenuItem4); + strcpy(menuOptionspceCart[3], string_reset2); // (stored in common strings array) strcpy(menuOptionspceCart[4], pceCartMenuItem5); strcpy(menuOptionspceCart[5], pceCartMenuItem6); if (pce_force_rom_size > 0) { @@ -865,7 +865,8 @@ void pceMenu() { } println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } diff --git a/Cart_Reader/PCW.ino b/Cart_Reader/PCW.ino index f0f0122..53d36c0 100644 --- a/Cart_Reader/PCW.ino +++ b/Cart_Reader/PCW.ino @@ -137,8 +137,8 @@ void setup_PCW() { static const char pcwmenuItem1[] PROGMEM = "Read ROM"; static const char pcwmenuItem2[] PROGMEM = "Read SRAM"; static const char pcwmenuItem3[] PROGMEM = "Write SRAM"; -static const char pcwmenuItem4[] PROGMEM = "Reset"; -static const char* const menuOptionsPCW[] PROGMEM = { pcwmenuItem1, pcwmenuItem2, pcwmenuItem3, pcwmenuItem4 }; +//static const char pcwmenuItem4[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsPCW[] PROGMEM = { pcwmenuItem1, pcwmenuItem2, pcwmenuItem3, string_reset2 }; void pcwMenu() { convertPgm(menuOptionsPCW, 4); @@ -164,7 +164,8 @@ void pcwMenu() { readSRAM_PCW(); sd.chdir("/"); // Wait for user input - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); break; @@ -181,10 +182,10 @@ void pcwMenu() { println_Msg(F("SRAM verified OK")); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(writeErrors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } break; @@ -468,7 +469,7 @@ void readROM_PCW() { sd.chdir(folder); display_Clear(); - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); @@ -477,7 +478,7 @@ void readROM_PCW() { EEPROM_writeAnything(0, foldern); if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } read_setup_PCW(); for (unsigned long address = 0; address < 0x400000; address += 512) { // 4MB @@ -495,7 +496,8 @@ void readROM_PCW() { // Wait for user input println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } @@ -510,7 +512,7 @@ void readMultiROM_PCW() { sd.chdir(folder); display_Clear(); - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); @@ -519,7 +521,7 @@ void readMultiROM_PCW() { EEPROM_writeAnything(0, foldern); if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } display_Clear(); println_Msg(F("READING MULTI-PACK")); @@ -554,7 +556,8 @@ void readMultiROM_PCW() { // Wait for user input println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } @@ -576,7 +579,7 @@ void readSRAM_PCW() { // readSRAM_1A() EEPROM_writeAnything(0, foldern); if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } display_Clear(); read_setup_PCW(); @@ -620,13 +623,13 @@ void writeSRAM_PCW() { } } myFile.close(); - println_Msg(F("Done")); + print_STR(done_STR, 1); display_Update(); } else { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } } else { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } display_Clear(); } @@ -649,7 +652,7 @@ unsigned long verifySRAM_PCW() { } myFile.close(); } else { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } return writeErrors; diff --git a/Cart_Reader/SFM.ino b/Cart_Reader/SFM.ino index 709ef8f..dcca1d7 100644 --- a/Cart_Reader/SFM.ino +++ b/Cart_Reader/SFM.ino @@ -34,8 +34,8 @@ boolean hirom[8]; // SFM menu items static const char sfmMenuItem1[] PROGMEM = "Game Menu"; static const char sfmMenuItem2[] PROGMEM = "Flash Menu"; -static const char sfmMenuItem3[] PROGMEM = "Reset"; -static const char* const menuOptionsSFM[] PROGMEM = { sfmMenuItem1, sfmMenuItem2, sfmMenuItem3 }; +//static const char sfmMenuItem3[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsSFM[] PROGMEM = { sfmMenuItem1, sfmMenuItem2, string_reset2 }; // SFM flash menu items static const char sfmFlashMenuItem1[] PROGMEM = "Read Flash"; @@ -51,8 +51,8 @@ static const char sfmGameMenuItem1[] PROGMEM = "Read Sram"; static const char sfmGameMenuItem2[] PROGMEM = "Read Game"; static const char sfmGameMenuItem3[] PROGMEM = "Write Sram"; static const char sfmGameMenuItem4[] PROGMEM = "Switch Game"; -static const char sfmGameMenuItem5[] PROGMEM = "Reset"; -static const char* const menuOptionsSFMGame[] PROGMEM = { sfmGameMenuItem1, sfmGameMenuItem2, sfmGameMenuItem3, sfmGameMenuItem4, sfmGameMenuItem5 }; +//static const char sfmGameMenuItem5[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsSFMGame[] PROGMEM = { sfmGameMenuItem1, sfmGameMenuItem2, sfmGameMenuItem3, sfmGameMenuItem4, string_reset2 }; void sfmMenu() { // create menu with title and 3 options to choose from @@ -182,10 +182,10 @@ void sfmGameOptions() { println_Msg(F("Verified OK")); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(wrErrors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } break; @@ -201,7 +201,8 @@ void sfmGameOptions() { } if (gameSubMenu != 3) { println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } @@ -267,7 +268,8 @@ void sfmFlashMenu() { println_Msg(F("This will erase your")); println_Msg(F("NP Cartridge.")); println_Msg(""); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); @@ -379,7 +381,8 @@ void sfmFlashMenu() { println_Msg(F("This will erase your")); println_Msg(F("NP Cartridge.")); println_Msg(""); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); @@ -429,7 +432,8 @@ void sfmFlashMenu() { } if (flashSubMenu != 5) { println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } @@ -784,7 +788,8 @@ void getCartInfo_SFM() { print_Msg(F("Sram: ")); print_Msg(sramSize); println_Msg(F("Kbit")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); // Wait for user input wait(); @@ -927,7 +932,7 @@ void readROM_SFM() { //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); } // Check if LoROM or HiROM... @@ -1098,7 +1103,7 @@ void writeFlash_SFM(int startBank, uint32_t pos) { myFile.close(); println_Msg(""); } else { - print_Error(F("Can't open file on SD"), true); + print_Error(open_file_STR, true); } } @@ -1261,7 +1266,7 @@ void readFlash_SFM() { // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); } if (romType) { for (int currBank = 0xC0; currBank < 0xC0 + numBanks; currBank++) { @@ -1405,7 +1410,7 @@ void readMapping() { //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } // Read the mapping info out of the 1st chip @@ -1730,7 +1735,7 @@ void write_SFM(int startBank, uint32_t pos) { display_Update(); eraseFlash_SFM(startBank); resetFlash_SFM(startBank); - println_Msg(F("Done")); + print_STR(done_STR, 1); print_Msg(F("Blankcheck...")); display_Update(); if (blankcheck_SFM(startBank)) { @@ -1747,17 +1752,17 @@ void write_SFM(int startBank, uint32_t pos) { resetFlash_SFM(startBank); // Checking for errors - print_Msg(F("Verifying...")); + print_STR(verifying_STR, 0); display_Update(); writeErrors = verifyFlash_SFM(startBank, pos); if (writeErrors == 0) { println_Msg(F("OK")); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(writeErrors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), true); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, true); } } else { print_Error(F("Error: Wrong Flash ID"), true); diff --git a/Cart_Reader/SMS.ino b/Cart_Reader/SMS.ino index 052e60a..1020ed0 100644 --- a/Cart_Reader/SMS.ino +++ b/Cart_Reader/SMS.ino @@ -18,9 +18,9 @@ static const char* const menuAdapterSMS[] PROGMEM = { SMSAdapterItem1, SMSAdapte static const char SMSMenuItem1[] PROGMEM = "Read Rom"; static const char SMSMenuItem2[] PROGMEM = "Read from SRAM"; static const char SMSMenuItem3[] PROGMEM = "Write to SRAM"; -static const char SMSMenuItem4[] PROGMEM = "Reset"; +//static const char SMSMenuItem4[] PROGMEM = "Reset"; (stored in common strings array) static const char SMSMenuItem5[] PROGMEM = "Change Retrode Mode"; -static const char* const menuOptionsSMS[] PROGMEM = { SMSMenuItem1, SMSMenuItem2, SMSMenuItem3, SMSMenuItem4, SMSMenuItem5 }; +static const char* const menuOptionsSMS[] PROGMEM = { SMSMenuItem1, SMSMenuItem2, SMSMenuItem3, string_reset2, SMSMenuItem5 }; // Rom Size menu static const char SMSRomItem1[] PROGMEM = "8KB"; @@ -114,10 +114,12 @@ void _smsMenu() { } if (retrode_mode) { println_Msg(retrode_mode ? (retrode_mode_sms ? F("Retrode Mode SMS") : F("Retrode Mode GG")) : F("Retrode Mode Off")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); } else { println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); } display_Update(); wait(); @@ -550,7 +552,8 @@ void getCartInfo_SMS() { // Wait for user input #if (defined(enable_LCD) || defined(enable_OLED)) - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); #endif @@ -579,7 +582,7 @@ void readROM_SMS() { sd.chdir(folder); display_Clear(); - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); @@ -590,7 +593,7 @@ void readROM_SMS() { // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } // set default bank size to 16KB @@ -664,7 +667,7 @@ void readSRAM_SMS() { sd.chdir(folder); display_Clear(); - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); @@ -675,7 +678,7 @@ void readSRAM_SMS() { // Open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } // Write the whole 32KB // When there is only 8KB of SRAM, the contents should be duplicated @@ -742,10 +745,10 @@ void writeSRAM_SMS() { blinkLED(); println_Msg(F("")); - println_Msg(F("DONE")); + print_STR(done_STR, 1); display_Update(); } else { - print_Error(F("SD ERROR"), true); + print_Error(sd_error_STR, true); } } diff --git a/Cart_Reader/SNES.ino b/Cart_Reader/SNES.ino index b312747..5f4953b 100644 --- a/Cart_Reader/SNES.ino +++ b/Cart_Reader/SNES.ino @@ -35,11 +35,11 @@ static const char snsMenuItem3[] PROGMEM = "Satellaview BS-X"; static const char snsMenuItem4[] PROGMEM = "Flash repro"; #ifdef clockgen_calibration static const char snsMenuItem5[] PROGMEM = "Calibrate Clock"; -static const char snsMenuItem6[] PROGMEM = "Reset"; -static const char* const menuOptionsSNS[] PROGMEM = { snsMenuItem1, snsMenuItem2, snsMenuItem3, snsMenuItem4, snsMenuItem5, snsMenuItem6 }; +//static const char snsMenuItem6[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsSNS[] PROGMEM = { snsMenuItem1, snsMenuItem2, snsMenuItem3, snsMenuItem4, snsMenuItem5, string_reset2 }; #else -static const char snsMenuItem5[] PROGMEM = "Reset"; -static const char* const menuOptionsSNS[] PROGMEM = { snsMenuItem1, snsMenuItem2, snsMenuItem3, snsMenuItem4, snsMenuItem5 }; +//static const char snsMenuItem5[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsSNS[] PROGMEM = { snsMenuItem1, snsMenuItem2, snsMenuItem3, snsMenuItem4, string_reset2 }; #endif // SNES menu items @@ -49,24 +49,24 @@ static const char SnesMenuItem3[] PROGMEM = "Write Save"; static const char SnesMenuItem4[] PROGMEM = "Test SRAM"; static const char SnesMenuItem5[] PROGMEM = "Cycle cart"; static const char SnesMenuItem6[] PROGMEM = "Force cart type"; -static const char SnesMenuItem7[] PROGMEM = "Reset"; -static const char* const menuOptionsSNES[] PROGMEM = { SnesMenuItem1, SnesMenuItem2, SnesMenuItem3, SnesMenuItem4, SnesMenuItem5, SnesMenuItem6, SnesMenuItem7 }; +//static const char SnesMenuItem7[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsSNES[] PROGMEM = { SnesMenuItem1, SnesMenuItem2, SnesMenuItem3, SnesMenuItem4, SnesMenuItem5, SnesMenuItem6, string_reset2 }; // Manual config menu items static const char confMenuItem1[] PROGMEM = "Use header info"; static const char confMenuItem2[] PROGMEM = "4MB LoROM 256K SRAM"; static const char confMenuItem3[] PROGMEM = "4MB HiROM 64K SRAM"; static const char confMenuItem4[] PROGMEM = "6MB ExROM 256K SRAM"; -static const char confMenuItem5[] PROGMEM = "Reset"; -static const char* const menuOptionsConfManual[] PROGMEM = { confMenuItem1, confMenuItem2, confMenuItem3, confMenuItem4, confMenuItem5 }; +//static const char confMenuItem5[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsConfManual[] PROGMEM = { confMenuItem1, confMenuItem2, confMenuItem3, confMenuItem4, string_reset2 }; // Repro menu items static const char reproMenuItem1[] PROGMEM = "LoROM (P0)"; static const char reproMenuItem2[] PROGMEM = "HiROM (P0)"; static const char reproMenuItem3[] PROGMEM = "ExLoROM (P1)"; static const char reproMenuItem4[] PROGMEM = "ExHiROM (P1)"; -static const char reproMenuItem5[] PROGMEM = "Reset"; -static const char* const menuOptionsRepro[] PROGMEM = { reproMenuItem1, reproMenuItem2, reproMenuItem3, reproMenuItem4, reproMenuItem5 }; +//static const char reproMenuItem5[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsRepro[] PROGMEM = { reproMenuItem1, reproMenuItem2, reproMenuItem3, reproMenuItem4, string_reset2 }; // SNES repro menu void reproMenu() { @@ -247,10 +247,10 @@ void snesMenu() { println_Msg(F("Verified OK")); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(wrErrors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } } else { display_Clear(); @@ -282,10 +282,10 @@ void snesMenu() { println_Msg(F("Restored OK")); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(wrErrors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } } else { display_Clear(); @@ -323,7 +323,8 @@ void snesMenu() { break; } //println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } @@ -840,7 +841,8 @@ void getCartInfo_SNES() { // Wait for user input #if (defined(enable_LCD) || defined(enable_OLED)) - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); #endif @@ -1314,7 +1316,7 @@ void readROM_SNES() { //clear the screen display_Clear(); - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); @@ -1325,7 +1327,7 @@ void readROM_SNES() { //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); } //Dump Derby Stallion '96 (Japan) Actual Size is 24Mb @@ -1678,7 +1680,7 @@ void readSRAM() { //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } int sramBanks = 0; if (romType == LO) { @@ -1951,10 +1953,10 @@ unsigned long verifySRAM() { if (writeErrors == 0) { println_Msg(F("Verified OK")); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(writeErrors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } display_Update(); wait(); diff --git a/Cart_Reader/SV.ino b/Cart_Reader/SV.ino index dafad9a..6ad69ff 100644 --- a/Cart_Reader/SV.ino +++ b/Cart_Reader/SV.ino @@ -82,10 +82,10 @@ void svMenu() { println_Msg(F("Verified OK")); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(wrErrors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } wait(); break; @@ -300,7 +300,7 @@ void readSRAM_SV() { //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } int sramBanks = 0; @@ -435,7 +435,7 @@ void readROM_SV() { //clear the screen display_Clear(); - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); @@ -446,7 +446,7 @@ void readROM_SV() { //open file on sd card if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); } // Read Banks @@ -559,7 +559,7 @@ void writeROM_SV(void) { dataIn(); //Set pins to input controlIn_SNES(); myFile.seekSet(0); // Go back to file beginning - println_Msg(F("Verifying...")); + print_STR(verifying_STR, 1); display_Update(); for (int currBank = 0xC0; currBank < 0xD0; currBank++) { draw_progressbar(((currBank - 0xC0) * 0x10000), 0x100000); diff --git a/Cart_Reader/VBOY.ino b/Cart_Reader/VBOY.ino index 36ef1e2..709f360 100644 --- a/Cart_Reader/VBOY.ino +++ b/Cart_Reader/VBOY.ino @@ -97,8 +97,8 @@ void setup_VBOY() { static const char vboyMenuItem1[] PROGMEM = "Read ROM"; static const char vboyMenuItem2[] PROGMEM = "Read SRAM"; static const char vboyMenuItem3[] PROGMEM = "Write SRAM"; -static const char vboyMenuItem4[] PROGMEM = "Reset"; -static const char* const menuOptionsVBOY[] PROGMEM = { vboyMenuItem1, vboyMenuItem2, vboyMenuItem3, vboyMenuItem4 }; +//static const char vboyMenuItem4[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsVBOY[] PROGMEM = { vboyMenuItem1, vboyMenuItem2, vboyMenuItem3, string_reset2 }; void vboyMenu() { convertPgm(menuOptionsVBOY, 4); @@ -126,7 +126,8 @@ void vboyMenu() { } #if (defined(enable_OLED) || defined(enable_LCD)) // Wait for user input - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); #endif @@ -145,17 +146,18 @@ void vboyMenu() { println_Msg(F("SRAM verified OK")); display_Update(); } else { - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(writeErrors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } } else { print_Error(F("Cart has no SRAM"), false); } #if (defined(enable_OLED) || defined(enable_LCD)) // Wait for user input - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); #endif @@ -395,7 +397,8 @@ void getCartInfo_VB() { #if (defined(enable_OLED) || defined(enable_LCD)) // Wait for user input - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); #endif @@ -417,7 +420,7 @@ void readROM_VB() { sd.chdir(folder); display_Clear(); - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); @@ -426,7 +429,7 @@ void readROM_VB() { EEPROM_writeAnything(0, foldern); if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } word d = 0; @@ -469,7 +472,8 @@ void readROM_VB() { #if (defined(enable_OLED) || defined(enable_LCD)) // Wait for user input println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); #endif @@ -493,10 +497,10 @@ void writeSRAM_VB() { writeByte_VB(currByte, (myFile.read())); } myFile.close(); - println_Msg(F("Done")); + print_STR(done_STR, 1); display_Update(); } else { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } dataIn_VB(); } @@ -516,7 +520,7 @@ void readSRAM_VB() { EEPROM_writeAnything(0, foldern); if (!myFile.open(fileName, O_RDWR | O_CREAT)) { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } for (unsigned long currBuffer = 0; currBuffer < sramSize; currBuffer += 512) { for (int currByte = 0; currByte < 512; currByte++) { @@ -550,7 +554,7 @@ unsigned long verifySRAM_VB() { } myFile.close(); } else { - print_Error(F("SD Error"), true); + print_Error(sd_error_STR, true); } return writeErrors; diff --git a/Cart_Reader/WS.ino b/Cart_Reader/WS.ino index 5be2800..40e8273 100644 --- a/Cart_Reader/WS.ino +++ b/Cart_Reader/WS.ino @@ -35,9 +35,9 @@ static const char wsMenuItem1[] PROGMEM = "Read Rom"; static const char wsMenuItem2[] PROGMEM = "Read Save"; static const char wsMenuItem3[] PROGMEM = "Write Save"; -static const char wsMenuItem4[] PROGMEM = "Reset"; +//static const char wsMenuItem4[] PROGMEM = "Reset"; (stored in common strings array) static const char wsMenuItem5[] PROGMEM = "Write WitchOS"; -static const char *const menuOptionsWS[] PROGMEM = { wsMenuItem1, wsMenuItem2, wsMenuItem3, wsMenuItem4, wsMenuItem5 }; +static const char *const menuOptionsWS[] PROGMEM = { wsMenuItem1, wsMenuItem2, wsMenuItem3, string_reset2, wsMenuItem5 }; static const uint8_t wwLaunchCode[] PROGMEM = { 0xea, 0x00, 0x00, 0x00, 0xe0, 0x00, 0xff, 0xff }; @@ -184,7 +184,8 @@ void wsMenu() { } println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); @@ -404,7 +405,8 @@ void showCartInfo_WS() { print_Msg(F("Checksum: ")); println_Msg(checksumStr); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } @@ -487,14 +489,14 @@ void readROM_WS(char *outPathBuf, size_t bufferSize) { snprintf(outPathBuf, bufferSize, "%s/%s", folder, fileName); display_Clear(); - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); // open file on sdcard if (!myFile.open(fileName, O_RDWR | O_CREAT)) - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); // write new folder number back to EEPROM foldern++; @@ -561,7 +563,7 @@ void readSRAM_WS() { EEPROM_writeAnything(0, foldern); if (!myFile.open(fileName, O_RDWR | O_CREAT)) - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); uint32_t bank_size = (sramSize << 7); uint16_t end_bank = (bank_size >> 16); // 64KB per bank @@ -591,7 +593,7 @@ void readSRAM_WS() { myFile.close(); - println_Msg(F("Done")); + print_STR(done_STR, 1); display_Update(); } @@ -630,10 +632,10 @@ void verifySRAM_WS() { println_Msg(F("passed")); } else { println_Msg(F("failed")); - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(write_errors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } } else { print_Error(F("File doesn't exist"), false); @@ -706,7 +708,7 @@ void readEEPROM_WS() { EEPROM_writeAnything(0, foldern); if (!myFile.open(fileName, O_RDWR | O_CREAT)) - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); uint32_t eepromSize = (sramSize << 7); uint32_t bufSize = (eepromSize < 512 ? eepromSize : 512); @@ -738,7 +740,7 @@ void readEEPROM_WS() { myFile.close(); - println_Msg(F("Done")); + print_STR(done_STR, 1); } void verifyEEPROM_WS() { @@ -784,10 +786,10 @@ void verifyEEPROM_WS() { println_Msg(F("passed")); } else { println_Msg(F("failed")); - print_Msg(F("Error: ")); + print_STR(error_STR, 0); print_Msg(write_errors); - println_Msg(F(" bytes ")); - print_Error(F("did not verify."), false); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); } } else { print_Error(F("File doesn't exist"), false); @@ -839,7 +841,7 @@ void writeEEPROM_WS() { myFile.close(); - println_Msg(F("Done")); + print_STR(done_STR, 1); } else { print_Error(F("File doesn't exist"), false); } @@ -928,7 +930,7 @@ void writeWitchOS_WS() { myFile.close(); - println_Msg(F("Done")); + print_STR(done_STR, 1); } else { print_Error(F("File doesn't exist"), false); } diff --git a/Cart_Reader/WSV.ino b/Cart_Reader/WSV.ino index d7ed265..c3a70a5 100644 --- a/Cart_Reader/WSV.ino +++ b/Cart_Reader/WSV.ino @@ -102,8 +102,8 @@ void setup_WSV() { static const char wsvMenuItem1[] PROGMEM = "Select Cart"; static const char wsvMenuItem2[] PROGMEM = "Read ROM"; static const char wsvMenuItem3[] PROGMEM = "Set Size"; -static const char wsvMenuItem4[] PROGMEM = "Reset"; -static const char* const menuOptionsSV[] PROGMEM = { wsvMenuItem1, wsvMenuItem2, wsvMenuItem3, wsvMenuItem4 }; +//static const char wsvMenuItem4[] PROGMEM = "Reset"; (stored in common strings array) +static const char* const menuOptionsSV[] PROGMEM = { wsvMenuItem1, wsvMenuItem2, wsvMenuItem3, string_reset2 }; void wsvMenu() { convertPgm(menuOptionsSV, 4); @@ -198,14 +198,14 @@ void readROM_WSV() { sd.chdir(folder); display_Clear(); - print_Msg(F("Saving to ")); + print_STR(saving_to_STR, 0); print_Msg(folder); println_Msg(F("/...")); display_Update(); // open file on sdcard if (!myFile.open(fileName, O_RDWR | O_CREAT)) - print_Error(F("Can't create file on SD"), true); + print_Error(create_file_STR, true); // write new folder number back to EEPROM foldern++; @@ -233,7 +233,8 @@ void readROM_WSV() { compareCRC("wsv.txt", 0, 1, 0); println_Msg(F("")); - println_Msg(F("Press Button...")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); display_Update(); wait(); } @@ -256,11 +257,11 @@ void setROMSize_WSV() { println_Msg(WSV[i]); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to Change")); - println_Msg(F("and right to Select")); + print_STR(press_to_change_STR, 1); + print_STR(right_to_select_STR, 1); #elif defined(enable_LCD) - println_Msg(F("Rotate to Change")); - println_Msg(F("Press to Select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #endif display_Update(); @@ -278,11 +279,11 @@ void setROMSize_WSV() { println_Msg(WSV[i]); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to Change")); - println_Msg(F("and right to Select")); + print_STR(press_to_change_STR, 1); + print_STR(right_to_select_STR, 1); #elif defined(enable_LCD) - println_Msg(F("Rotate to Change")); - println_Msg(F("Press to Select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #endif display_Update(); } @@ -298,11 +299,11 @@ void setROMSize_WSV() { println_Msg(WSV[i]); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to Change")); - println_Msg(F("and right to Select")); + print_STR(press_to_change_STR, 1); + print_STR(right_to_select_STR, 1); #elif defined(enable_LCD) - println_Msg(F("Rotate to Change")); - println_Msg(F("Press to Select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #endif display_Update(); } @@ -478,11 +479,11 @@ void setCart_WSV() { println_Msg(F("KB")); println_Msg(F("")); #if defined(enable_OLED) - println_Msg(F("Press left to Change")); - println_Msg(F("and right to Select")); + print_STR(press_to_change_STR, 1); + print_STR(right_to_select_STR, 1); #elif defined(enable_LCD) - println_Msg(F("Rotate to Change")); - println_Msg(F("Press to Select")); + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); #elif defined(SERIAL_MONITOR) println_Msg(F("U/D to Change")); println_Msg(F("Space to Select")); From e7ef7fd4bd971d7a59e31b4725243751d2039c70 Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Sat, 22 Oct 2022 00:47:50 +0000 Subject: [PATCH 02/24] All: Make flashid an integer flashid (almost) always contains the hexadecimal representation of two bytes, which then means it gets compares with strcmp, which in turn need another string argument. Instead, make it an integer, removing the need to call strcmp. Add a separate string representation for printing purposes (maybe this can be avoided by having the print function format it when needed ?). The only apparent case where flashid is not an hexadecimal representation of a pair of bytes is when N64 clears it to "CONF". Set flashid to zero this case. This saves about 500 bytes of program space and 200 bytes of ram. --- Cart_Reader/Cart_Reader.ino | 3 +- Cart_Reader/FLASH.ino | 102 +++++++++++++++++++----------------- Cart_Reader/GB.ino | 16 +++--- Cart_Reader/GBA.ino | 63 ++++++++++++---------- Cart_Reader/GBM.ino | 10 ++-- Cart_Reader/MD.ino | 8 +-- Cart_Reader/N64.ino | 83 +++++++++++++++-------------- Cart_Reader/NES.ino | 10 ++-- Cart_Reader/SFM.ino | 24 +++++---- 9 files changed, 174 insertions(+), 145 deletions(-) diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index 72b05d0..5475f88 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -431,7 +431,8 @@ bool errorLvl = 0; byte romVersion = 0; char cartID[5]; unsigned long cartSize; -char flashid[5]; +unsigned int flashid; +char flashid_str[5]; char vendorID[5]; unsigned long fileSize; unsigned long sramBase; diff --git a/Cart_Reader/FLASH.ino b/Cart_Reader/FLASH.ino index 79697ab..cca8646 100644 --- a/Cart_Reader/FLASH.ino +++ b/Cart_Reader/FLASH.ino @@ -153,16 +153,16 @@ void flashromMenu8() { writeFlash29F032(); break; case 2: - if (strcmp(flashid, "C2F3") == 0) + if (flashid == 0xC2F3) writeFlash29F1601(); - else if ((strcmp(flashid, "C2F1") == 0) || (strcmp(flashid, "C2F9") == 0)) + else if ((flashid == 0xC2F1) || (flashid == 0xC2F9)) writeFlash29F1610(); - else if ((strcmp(flashid, "C2C4") == 0) || (strcmp(flashid, "C249") == 0) || (strcmp(flashid, "C2A7") == 0) || (strcmp(flashid, "C2A8") == 0) || (strcmp(flashid, "C2C9") == 0) || (strcmp(flashid, "C2CB") == 0)) + else if ((flashid == 0xC2C4) || (flashid == 0xC249) || (flashid == 0xC2A7) || (flashid == 0xC2A8) || (flashid == 0xC2C9) || (flashid == 0xC2CB)) writeFlash29LV640(); - else if (strcmp(flashid, "017E") == 0) { + else if (flashid == 0x017E) { // sector size, write buffer size writeFlash29GL(sectorSize, bufferSize); - } else if ((strcmp(flashid, "0458") == 0) || (strcmp(flashid, "0158") == 0) || (strcmp(flashid, "01AB") == 0)) + } else if ((flashid == 0x0458) || (flashid == 0x0158) || (flashid == 0x01AB)) writeFlash29F800(); break; @@ -271,9 +271,9 @@ void flashromMenu16() { fileBrowser(F("Select file")); display_Clear(); time = millis(); - if (strcmp(flashid, "C2F3") == 0) { + if (flashid == 0xC2F3) { writeFlash16_29F1601(); - } else if ((strcmp(flashid, "C2C4") == 0) || (strcmp(flashid, "C249") == 0) || (strcmp(flashid, "C2A7") == 0) || (strcmp(flashid, "C2A8") == 0) || (strcmp(flashid, "C2C9") == 0) || (strcmp(flashid, "C2CB") == 0) || (strcmp(flashid, "C2FC") == 0)) { + } else if ((flashid == 0xC2C4) || (flashid == 0xC249) || (flashid == 0xC2A7) || (flashid == 0xC2A8) || (flashid == 0xC2C9) || (flashid == 0xC2CB) || (flashid == 0xC2FC)) { writeFlash16_29LV640(); } else { writeFlash16(); @@ -404,77 +404,77 @@ idtheflash: println_Msg(""); println_Msg(""); print_Msg(F("Flash ID: ")); - println_Msg(flashid); + println_Msg(flashid_str); - if (strcmp(flashid, "C2F1") == 0) { + if (flashid == 0xC2F1) { println_Msg(F("MX29F1610 detected")); flashSize = 2097152; flashromType = 2; - } else if (strcmp(flashid, "C2F3") == 0) { + } else if (flashid == 0xC2F3) { println_Msg(F("MX29F1601 detected")); flashSize = 2097152; flashromType = 2; - } else if (strcmp(flashid, "C2F9") == 0) { + } else if (flashid == 0xC2F9) { println_Msg(F("MX29L3211 detected")); println_Msg(F("ATTENTION 3.3V")); flashSize = 4194304; flashromType = 2; - } else if ((strcmp(flashid, "C2C4") == 0) || (strcmp(flashid, "C249") == 0)) { + } else if ((flashid == 0xC2C4) || (flashid == 0xC249)) { println_Msg(F("MX29LV160 detected")); println_Msg(F("ATTENTION 3.3V")); flashSize = 2097152; flashromType = 2; - } else if ((strcmp(flashid, "C2A7") == 0) || (strcmp(flashid, "C2A8") == 0)) { + } else if ((flashid == 0xC2A7) || (flashid == 0xC2A8)) { println_Msg(F("MX29LV320 detected")); println_Msg(F("ATTENTION 3.3V")); flashSize = 4194304; flashromType = 2; - } else if ((strcmp(flashid, "C2C9") == 0) || (strcmp(flashid, "C2CB") == 0)) { + } else if ((flashid == 0xC2C9) || (flashid == 0xC2CB)) { println_Msg(F("MX29LV640 detected")); println_Msg(F("ATTENTION 3.3V")); flashSize = 8388608; flashromType = 2; - } else if (strcmp(flashid, "0141") == 0) { + } else if (flashid == 0x0141) { println_Msg(F("AM29F032B detected")); flashSize = 4194304; flashromType = 1; - } else if (strcmp(flashid, "01AD") == 0) { + } else if (flashid == 0x01AD) { println_Msg(F("AM29F016B detected")); flashSize = 2097152; flashromType = 1; - } else if (strcmp(flashid, "20AD") == 0) { + } else if (flashid == 0x20AD) { println_Msg(F("AM29F016D detected")); flashSize = 2097152; flashromType = 1; - } else if (strcmp(flashid, "04AD") == 0) { + } else if (flashid == 0x04AD) { println_Msg(F("AM29F016D detected")); flashSize = 2097152; flashromType = 1; - } else if (strcmp(flashid, "04D4") == 0) { + } else if (flashid == 0x04D4) { println_Msg(F("MBM29F033C detected")); flashSize = 4194304; flashromType = 1; - } else if (strcmp(flashid, "04D5") == 0) { + } else if (flashid == 0x04D5) { println_Msg(F("MBM29F080C detected")); flashSize = 1048576; flashromType = 1; - } else if (strcmp(flashid, "0458") == 0) { + } else if (flashid == 0x0458) { println_Msg(F("MBM29F800BA detected")); flashSize = 1048576; flashromType = 2; - } else if (strcmp(flashid, "01AB") == 0) { + } else if (flashid == 0x01AB) { println_Msg(F("AM29F400AB detected")); flashSize = 131072 * 4; flashromType = 2; - } else if (strcmp(flashid, "0158") == 0) { + } else if (flashid == 0x0158) { println_Msg(F("AM29F800BB detected")); flashSize = 1048576; flashromType = 2; - } else if (strcmp(flashid, "01A3") == 0) { + } else if (flashid == 0x01A3) { println_Msg(F("AM29LV033C detected")); flashSize = 131072 * 32; flashromType = 1; - } else if (strcmp(flashid, "017E") == 0) { + } else if (flashid == 0x017E) { // S29GL032M if (readByte_Flash(28) == 0x1A) { println_Msg(F("S29GL032M detected")); @@ -498,7 +498,7 @@ idtheflash: } println_Msg(F("ATTENTION 3.3V")); flashromType = 2; - } else if (strcmp(flashid, "B088") == 0) { + } else if (flashid == 0xB088) { // LH28F016SUT println_Msg(F("LH28F016SUT detected")); println_Msg(F("ATTENTION 3/5 setting")); @@ -506,20 +506,20 @@ idtheflash: sectorSize = 65536; bufferSize = 256; flashromType = 3; - } else if ((strcmp(flashid, "8916") == 0) || (strcmp(flashid, "8917") == 0) || (strcmp(flashid, "8918") == 0)) { + } else if ((flashid == 0x8916) || (flashid == 0x8917) || (flashid == 0x8918)) { // E28FXXXJ3A print_Msg(F("E28F")); - switch (flashid[3]) { - case '6': + switch (flashid & 0x00f0) { + case 0x60: flashSize = 131072 * 32; print_Msg(F("320")); break; - case '7': + case 0x70: flashSize = 131072 * 64; print_Msg(F("640")); break; - case '8': + case 0x80: flashSize = 131072 * 128; print_Msg(F("128")); break; @@ -537,7 +537,7 @@ idtheflash: goto idtheflash; } else if (secondID == 2) { // Backup first ID read-out - strncpy(vendorID, flashid, 5); + strncpy(vendorID, flashid_str, 5); // Read ID a third time using a different command (type 2 flashrom) resetFlash8(); @@ -552,7 +552,7 @@ idtheflash: print_Msg(F("ID Type 1: ")); println_Msg(vendorID); print_Msg(F("ID Type 2: ")); - println_Msg(flashid); + println_Msg(flashid_str); println_Msg(""); println_Msg(F("UNKNOWN FLASHROM")); println_Msg(""); @@ -588,37 +588,37 @@ void id_Flash16() { println_Msg(F("Flashrom Writer 16bit")); println_Msg(""); print_Msg(F("Flash ID: ")); - println_Msg(flashid); - if (strcmp(flashid, "C2F1") == 0) { + println_Msg(flashid_str); + if (flashid == 0xC2F1) { println_Msg(F("MX29F1610 detected")); println_Msg(""); flashSize = 2097152; flashromType = 2; - } else if (strcmp(flashid, "C2F3") == 0) { + } else if (flashid == 0xC2F3) { println_Msg(F("MX29F1601 detected")); flashSize = 2097152; flashromType = 2; - } else if (strcmp(flashid, "C2F9") == 0) { + } else if (flashid == 0xC2F9) { println_Msg(F("MX29L3211 detected")); println_Msg(F("ATTENTION 3.3V")); flashSize = 4194304; flashromType = 2; - } else if ((strcmp(flashid, "C2C4") == 0) || (strcmp(flashid, "C249") == 0)) { + } else if ((flashid == 0xC2C4) || (flashid == 0xC249)) { println_Msg(F("MX29LV160 detected")); println_Msg(F("ATTENTION 3.3V")); flashSize = 2097152; flashromType = 2; - } else if ((strcmp(flashid, "C2A7") == 0) || (strcmp(flashid, "C2A8") == 0)) { + } else if ((flashid == 0xC2A7) || (flashid == 0xC2A8)) { println_Msg(F("MX29LV320 detected")); println_Msg(F("ATTENTION 3.3V")); flashSize = 4194304; flashromType = 2; - } else if ((strcmp(flashid, "C2C9") == 0) || (strcmp(flashid, "C2CB") == 0)) { + } else if ((flashid == 0xC2C9) || (flashid == 0xC2CB)) { println_Msg(F("MX29LV640 detected")); println_Msg(F("ATTENTION 3.3V")); flashSize = 8388608; flashromType = 2; - } else if (strcmp(flashid, "C2FC") == 0) { + } else if (flashid == 0xC2FC) { println_Msg(F("MX26L6420 detected")); println_Msg(F("ATTENTION 3.3V")); flashSize = 8388608; @@ -1008,7 +1008,9 @@ void idFlash29F032() { dataIn8(); // Read the two id bytes into a string - sprintf(flashid, "%02X%02X", readByte_Flash(0), readByte_Flash(1)); + flashid = readByte_Flash(0) << 8; + flashid |= readByte_Flash(1); + sprintf(flashid_str, "%04X", flashid); } void eraseFlash29F032() { @@ -1306,7 +1308,9 @@ void idFlash29F1610() { dataIn8(); // Read the two id bytes into a string - sprintf(flashid, "%02X%02X", readByte_Flash(0), readByte_Flash(2)); + flashid = readByte_Flash(0) << 8; + flashid |= readByte_Flash(2); + sprintf(flashid_str, "%04X", flashid); } byte readStatusReg() { @@ -1547,7 +1551,9 @@ void idFlash28FXXX() { dataIn8(); // Read the two id bytes into a string - sprintf(flashid, "%02X%02X", readByte_Flash(0), readByte_Flash(1)); + flashid = readByte_Flash(0) << 8; + flashid |= readByte_Flash(1); + sprintf(flashid_str, "%04X", flashid); } void resetFlash28FXXX() { @@ -1590,9 +1596,9 @@ void writeFlash28FXXX() { // Open file on sd card if (myFile.open(filePath, O_READ)) { - if ((strcmp(flashid, "B088") == 0)) + if ((flashid == 0xB088)) writeFlashLH28F0XX(); - else if ((strcmp(flashid, "8916") == 0) || (strcmp(flashid, "8917") == 0) || (strcmp(flashid, "8918") == 0)) { + else if ((flashid == 0x8916) || (flashid == 0x8917) || (flashid == 0x8918)) { writeFlashE28FXXXJ3A(); } @@ -1969,7 +1975,9 @@ void idFlash16() { dataIn16(); // Read the two id bytes into a string - sprintf(flashid, "%02X%02X", readWord_Flash(0) & 0xFF, readWord_Flash(1) & 0xFF); + flashid = (readWord_Flash(0) & 0xFF) << 8; + flashid |= readWord_Flash(1) & 0xFF; + sprintf(flashid_str, "%04X", flashid); } byte readStatusReg16() { diff --git a/Cart_Reader/GB.ino b/Cart_Reader/GB.ino index c4cc36d..c0e9f1c 100644 --- a/Cart_Reader/GB.ino +++ b/Cart_Reader/GB.ino @@ -1608,33 +1608,34 @@ void writeFlash29F_GB(byte MBC, boolean flashErase) { writeByte_GB(0x555, 0x90); // Read the two id bytes into a string - sprintf(flashid, "%02X%02X", readByte_GB(0), readByte_GB(1)); + flashid = readByte_GB(0) << 8; + flashid |= readByte_GB(1); - if (strcmp(flashid, "04D4") == 0) { + if (flashid == 0x04D4) { println_Msg(F("MBM29F033C")); print_Msg(F("Banks: ")); print_Msg(romBanks); println_Msg(F("/256")); display_Update(); - } else if (strcmp(flashid, "0141") == 0) { + } else if (flashid == 0x0141) { println_Msg(F("AM29F032B")); print_Msg(F("Banks: ")); print_Msg(romBanks); println_Msg(F("/256")); display_Update(); - } else if (strcmp(flashid, "01AD") == 0) { + } else if (flashid == 0x01AD) { println_Msg(F("AM29F016B")); print_Msg(F("Banks: ")); print_Msg(romBanks); println_Msg(F("/128")); display_Update(); - } else if (strcmp(flashid, "04AD") == 0) { + } else if (flashid == 0x04AD) { println_Msg(F("AM29F016D")); print_Msg(F("Banks: ")); print_Msg(romBanks); println_Msg(F("/128")); display_Update(); - } else if (strcmp(flashid, "01D5") == 0) { + } else if (flashid == 0x01D5) { println_Msg(F("AM29F080B")); print_Msg(F("Banks: ")); print_Msg(romBanks); @@ -1642,7 +1643,8 @@ void writeFlash29F_GB(byte MBC, boolean flashErase) { display_Update(); } else { print_Msg(F("Flash ID: ")); - println_Msg(flashid); + sprintf(flashid_str, "%04X", flashid); + println_Msg(flashid_str); display_Update(); print_Error(F("Unknown flashrom"), true); } diff --git a/Cart_Reader/GBA.ino b/Cart_Reader/GBA.ino index 78d216f..21ff4f4 100644 --- a/Cart_Reader/GBA.ino +++ b/Cart_Reader/GBA.ino @@ -344,16 +344,16 @@ void gbaMenu() { resetFLASH_GBA(); print_Msg(F("FLASH ID: ")); - println_Msg(flashid); + println_Msg(flashid_str); println_Msg(F("")); println_Msg(F("FLASH Type: ")); - if (strcmp(flashid, "1F3D") == 0) { + if (flashid == 0x1F3D) { println_Msg(F("Atmel AT29LV512")); - } else if (strcmp(flashid, "BFD4") == 0) { + } else if (flashid == 0xBFD4) { println_Msg(F("SST 39VF512")); - } else if (strcmp(flashid, "C21C") == 0) { + } else if (flashid == 0xC21C) { println_Msg(F("Macronix MX29L512")); - } else if (strcmp(flashid, "321B") == 0) { + } else if (flashid == 0x321B) { println_Msg(F("Panasonic MN63F805MNP")); } else { println_Msg(F("Unknown")); @@ -367,7 +367,7 @@ void gbaMenu() { display_Clear(); display_Update(); - if (strcmp(flashid, "1F3D") == 0) { // Atmel + if (flashid == 0x1F3D) { // Atmel writeFLASH_GBA(1, 65536, 0, 1); verifyFLASH_GBA(65536, 0); } else { @@ -390,12 +390,12 @@ void gbaMenu() { resetFLASH_GBA(); print_Msg(F("Flashrom ID: ")); - println_Msg(flashid); + println_Msg(flashid_str); println_Msg(F("")); println_Msg(F("Flashrom Type: ")); - if (strcmp(flashid, "C209") == 0) { + if (flashid == 0xC209) { println_Msg(F("Macronix MX29L010")); - } else if (strcmp(flashid, "6213") == 0) { + } else if (flashid == 0x6213) { println_Msg(F("SANYO LE26FV10N1TS")); } else { println_Msg(F("Unknown")); @@ -1584,7 +1584,9 @@ void idFlash_GBA() { "nop\n\t"); // Read the two id bytes into a string - sprintf(flashid, "%02X%02X", readByteFlash_GBA(0), readByteFlash_GBA(1)); + flashid = readByteFlash_GBA(0) << 8; + flashid |= readByteFlash_GBA(1); + sprintf(flashid_str, "%04X", flashid); // Set CS_FLASH(PH0) high PORTH |= (1 << 0); @@ -2354,10 +2356,12 @@ void idFlashrom_GBA() { "nop\n\t"); // Read flashrom ID - sprintf(flashid, "%02X%02X", ((readWord_GBA(0x2) >> 8) & 0xFF), (readWord_GBA(0x4) & 0xFF)); + flashid = readWord_GBA(0x2) & 0xFF00; + flashid |= readWord_GBA(0x4) & 0xFF; + sprintf(flashid_str, "%04X", flashid); // Intel Strataflash - if (strcmp(flashid, "8802") == 0 || (strcmp(flashid, "8816") == 0)) { + if (flashid == 0x8802 || (flashid == 0x8816)) { cartSize = 0x2000000; } else { // Send swapped MX29GL128E/MSP55LV128 ID command to flashrom @@ -2374,10 +2378,11 @@ void idFlashrom_GBA() { "nop\n\t"); // Read flashrom ID - sprintf(flashid, "%02X%02X", ((readWord_GAB(0x2) >> 8) & 0xFF), (readWord_GAB(0x2) & 0xFF)); + flashid = readWord_GAB(0x2); + sprintf(flashid_str, "%04X", flashid); // MX29GL128E or MSP55LV128 - if (strcmp(flashid, "227E") == 0) { + if (flashid == 0x227E) { // MX is 0xC2 and MSP is 0x4 or 0x1 romType = (readWord_GAB(0x0) & 0xFF); cartSize = 0x1000000; @@ -2387,7 +2392,7 @@ void idFlashrom_GBA() { println_Msg(F("")); println_Msg(F("Unknown Flash")); print_Msg(F("Flash ID: ")); - println_Msg(flashid); + println_Msg(flashid_str); println_Msg(F("")); print_Error(F("Check voltage"), true); } @@ -2796,14 +2801,14 @@ void flashRepro_GBA() { // Check flashrom ID's idFlashrom_GBA(); - if ((strcmp(flashid, "8802") == 0) || (strcmp(flashid, "8816") == 0) || (strcmp(flashid, "227E") == 0)) { + if ((flashid == 0x8802) || (flashid == 0x8816) || (flashid == 0x227E)) { print_Msg(F("ID: ")); - print_Msg(flashid); + print_Msg(flashid_str); print_Msg(F(" Size: ")); print_Msg(cartSize / 0x100000); println_Msg(F("MB")); // MX29GL128E or MSP55LV128(N) - if (strcmp(flashid, "227E") == 0) { + if (flashid == 0x227E) { // MX is 0xC2 and MSP55LV128 is 0x4 and MSP55LV128N 0x1 if (romType == 0xC2) { println_Msg(F("Macronix MX29GL128E")); @@ -2820,11 +2825,11 @@ void flashRepro_GBA() { } } // Intel 4000L0YBQ0 - else if (strcmp(flashid, "8802") == 0) { + else if (flashid == 0x8802) { println_Msg(F("Intel 4000L0YBQ0")); } // Intel 4400L0ZDQ0 - else if (strcmp(flashid, "8816") == 0) { + else if (flashid == 0x8816) { println_Msg(F("Intel 4400L0ZDQ0")); } println_Msg(""); @@ -2857,17 +2862,17 @@ void flashRepro_GBA() { display_Update(); // Erase needed sectors - if (strcmp(flashid, "8802") == 0) { + if (flashid == 0x8802) { println_Msg(F("Erasing...")); display_Update(); eraseIntel4000_GBA(); resetIntel_GBA(0x200000); - } else if (strcmp(flashid, "8816") == 0) { + } else if (flashid == 0x8816) { println_Msg(F("Erasing...")); display_Update(); eraseIntel4400_GBA(); resetIntel_GBA(0x200000); - } else if (strcmp(flashid, "227E") == 0) { + } else if (flashid == 0x227E) { //if (sectorCheckMX29GL128E_GBA()) { //print_Error(F("Sector Protected"), true); //} @@ -2895,9 +2900,9 @@ void flashRepro_GBA() { print_Msg(F("Writing ")); println_Msg(filePath); display_Update(); - if ((strcmp(flashid, "8802") == 0) || (strcmp(flashid, "8816") == 0)) { + if ((flashid == 0x8802) || (flashid == 0x8816)) { writeIntel4000_GBA(); - } else if (strcmp(flashid, "227E") == 0) { + } else if (flashid == 0x227E) { if ((romType == 0xC2) || (romType == 0x89) || (romType == 0x20)) { //MX29GL128E (0xC2) //PC28F256M29 (0x89) @@ -2914,7 +2919,7 @@ void flashRepro_GBA() { // Verify print_STR(verifying_STR, 0); display_Update(); - if (strcmp(flashid, "8802") == 0) { + if (flashid == 0x8802) { // Don't know the correct size so just take some guesses resetIntel_GBA(0x8000); delay(1000); @@ -2922,12 +2927,12 @@ void flashRepro_GBA() { delay(1000); resetIntel_GBA(0x200000); delay(1000); - } else if (strcmp(flashid, "8816") == 0) { + } else if (flashid == 0x8816) { resetIntel_GBA(0x200000); delay(1000); } - else if (strcmp(flashid, "227E") == 0) { + else if (flashid == 0x227E) { resetMX29GL128E_GBA(); delay(1000); } @@ -2951,7 +2956,7 @@ void flashRepro_GBA() { println_Msg(F("")); println_Msg(F("Unknown Flash")); print_Msg(F("Flash ID: ")); - println_Msg(flashid); + println_Msg(flashid_str); println_Msg(F("")); print_Error(F("Check voltage"), true); } diff --git a/Cart_Reader/GBM.ino b/Cart_Reader/GBM.ino index 1463059..53e5db8 100644 --- a/Cart_Reader/GBM.ino +++ b/Cart_Reader/GBM.ino @@ -496,16 +496,18 @@ boolean readFlashID_GBM() { send_GBM(0x0F, 0x5555, 0x90); // Read the two id bytes into a string - sprintf(flashid, "%02X%02X", readByte_GBM(0), readByte_GBM(1)); - if (strcmp(flashid, "C289") == 0) { + flashid = readByte_GBM(0) << 8; + flashid |= readByte_GBM(1); + sprintf(flashid_str, "%04X", flashid); + if (flashid == 0xC289) { print_Msg(F("Flash ID: ")); - println_Msg(flashid); + println_Msg(flashid_str); display_Update(); resetFlash_GBM(); return 1; } else { print_Msg(F("Flash ID: ")); - println_Msg(flashid); + println_Msg(flashid_str); print_Error(F("Unknown Flash ID"), true); resetFlash_GBM(); return 0; diff --git a/Cart_Reader/MD.ino b/Cart_Reader/MD.ino index 43bc439..07f239c 100644 --- a/Cart_Reader/MD.ino +++ b/Cart_Reader/MD.ino @@ -254,8 +254,8 @@ void mdMenu() { idFlash_MD(); resetFlash_MD(); print_Msg(F("Flash ID: ")); - println_Msg(flashid); - if (strcmp(flashid, "C2F1") == 0) { + println_Msg(flashid_str); + if (flashid == 0xC2F1) { println_Msg(F("MX29F1610 detected")); flashSize = 2097152; } else { @@ -1708,7 +1708,9 @@ void idFlash_MD() { dataIn_MD(); // Read the two id bytes into a string - sprintf(flashid, "%02X%02X", readFlash_MD(0) & 0xFF, readFlash_MD(1) & 0xFF); + flashid = (readFlash_MD(0) & 0xFF) << 8; + flashid |= readFlash_MD(1) & 0xFF; + sprintf(flashid_str, "%04X", flashid); } byte readStatusReg_MD() { diff --git a/Cart_Reader/N64.ino b/Cart_Reader/N64.ino index 8b6ee62..e2d97ec 100644 --- a/Cart_Reader/N64.ino +++ b/Cart_Reader/N64.ino @@ -3647,34 +3647,34 @@ void flashRepro_N64() { // If the ID is known continue if (cartSize != 0) { // Print flashrom name - if ((strcmp(flashid, "227E") == 0) && (strcmp(cartID, "2201") == 0)) { + if ((flashid == 0x227E) && (strcmp(cartID, "2201") == 0)) { print_Msg(F("Spansion S29GL256N")); if (cartSize == 64) println_Msg(F(" x2")); else println_Msg(""); - } else if ((strcmp(flashid, "227E") == 0) && (strcmp(cartID, "2101") == 0)) { + } else if ((flashid == 0x227E) && (strcmp(cartID, "2101") == 0)) { print_Msg(F("Spansion S29GL128N")); - } else if ((strcmp(flashid, "227E") == 0) && (strcmp(cartID, "2100") == 0)) { + } else if ((flashid == 0x227E) && (strcmp(cartID, "2100") == 0)) { print_Msg(F("ST M29W128GL")); - } else if ((strcmp(flashid, "22C9") == 0) || (strcmp(flashid, "22CB") == 0)) { + } else if ((flashid == 0x22C9) || (flashid == 0x22CB)) { print_Msg(F("Macronix MX29LV640")); if (cartSize == 16) println_Msg(F(" x2")); else println_Msg(""); - } else if (strcmp(flashid, "8816") == 0) + } else if (flashid == 0x8816) println_Msg(F("Intel 4400L0ZDQ0")); - else if (strcmp(flashid, "7E7E") == 0) + else if (flashid == 0x7E7E) println_Msg(F("Fujitsu MSP55LV100S")); - else if ((strcmp(flashid, "227E") == 0) && (strcmp(cartID, "2301") == 0)) + else if ((flashid == 0x227E) && (strcmp(cartID, "2301") == 0)) println_Msg(F("Fujitsu MSP55LV512")); - else if ((strcmp(flashid, "227E") == 0) && (strcmp(cartID, "3901") == 0)) + else if ((flashid == 0x227E) && (strcmp(cartID, "3901") == 0)) println_Msg(F("Intel 512M29EW")); // Print info print_Msg(F("ID: ")); - print_Msg(flashid); + print_Msg(flashid_str); print_Msg(F(" Size: ")); print_Msg(cartSize); println_Msg(F("MB")); @@ -3692,7 +3692,7 @@ void flashRepro_N64() { print_Msg(F("ID: ")); print_Msg(vendorID); print_Msg(F(" ")); - print_Msg(flashid); + print_Msg(flashid_str); print_Msg(F(" ")); println_Msg(cartID); println_Msg(F(" ")); @@ -3706,7 +3706,8 @@ void flashRepro_N64() { // clear IDs sprintf(vendorID, "%s", "CONF"); - sprintf(flashid, "%s", "CONF"); + flashid = 0; + sprintf(flashid_str, "%s", "CONF"); sprintf(cartID, "%s", "CONF"); @@ -3834,17 +3835,17 @@ void flashRepro_N64() { } // Erase needed sectors - if (strcmp(flashid, "227E") == 0) { + if (flashid == 0x227E) { // Spansion S29GL256N or Fujitsu MSP55LV512 with 0x20000 sector size and 32 byte buffer eraseSector_N64(0x20000); - } else if (strcmp(flashid, "7E7E") == 0) { + } else if (flashid == 0x7E7E) { // Fujitsu MSP55LV100S eraseMSP55LV100_N64(); - } else if ((strcmp(flashid, "8813") == 0) || (strcmp(flashid, "8816") == 0)) { + } else if ((flashid == 0x8813) || (flashid == 0x8816)) { // Intel 4400L0ZDQ0 eraseIntel4400_N64(); resetIntel4400_N64(); - } else if ((strcmp(flashid, "22C9") == 0) || (strcmp(flashid, "22CB") == 0)) { + } else if ((flashid == 0x22C9) || (flashid == 0x22CB)) { // Macronix MX29LV640, C9 is top boot and CB is bottom boot block eraseSector_N64(0x8000); } else { @@ -3859,22 +3860,22 @@ void flashRepro_N64() { println_Msg(filePath); display_Update(); - if ((strcmp(cartID, "3901") == 0) && (strcmp(flashid, "227E") == 0)) { + if ((strcmp(cartID, "3901") == 0) && (flashid == 0x227E)) { // Intel 512M29EW(64MB) with 0x20000 sector size and 128 byte buffer writeFlashBuffer_N64(0x20000, 128); - } else if ((strcmp(cartID, "2100") == 0) && (strcmp(flashid, "227E") == 0)) { + } else if ((strcmp(cartID, "2100") == 0) && (flashid == 0x227E)) { // ST M29W128GH(16MB) with 0x20000 sector size and 64 byte buffer writeFlashBuffer_N64(0x20000, 64); - } else if (strcmp(flashid, "227E") == 0) { + } else if (flashid == 0x227E) { // Spansion S29GL128N/S29GL256N or Fujitsu MSP55LV512 with 0x20000 sector size and 32 byte buffer writeFlashBuffer_N64(0x20000, 32); - } else if (strcmp(flashid, "7E7E") == 0) { + } else if (flashid == 0x7E7E) { //Fujitsu MSP55LV100S writeMSP55LV100_N64(0x20000); - } else if ((strcmp(flashid, "22C9") == 0) || (strcmp(flashid, "22CB") == 0)) { + } else if ((flashid == 0x22C9) || (flashid == 0x22CB)) { // Macronix MX29LV640 without buffer and 0x8000 sector size writeFlashrom_N64(0x8000); - } else if ((strcmp(flashid, "8813") == 0) || (strcmp(flashid, "8816") == 0)) { + } else if ((flashid == 0x8813) || (flashid == 0x8816)) { // Intel 4400L0ZDQ0 writeIntel4400_N64(); resetIntel4400_N64(); @@ -3956,13 +3957,14 @@ void idFlashrom_N64() { setAddress_N64(romBase); sprintf(vendorID, "%02X", readWord_N64()); // Read 2 bytes flashrom ID - sprintf(flashid, "%04X", readWord_N64()); + flashid = readWord_N64(); + sprintf(flashid_str, "%04X", flashid); // Read 2 bytes secondary flashrom ID setAddress_N64(romBase + 0x1C); sprintf(cartID, "%04X", ((readWord_N64() << 8) | (readWord_N64() & 0xFF))); // Spansion S29GL256N(32MB/64MB) with either one or two flashrom chips - if ((strcmp(cartID, "2201") == 0) && (strcmp(flashid, "227E") == 0)) { + if ((strcmp(cartID, "2201") == 0) && (flashid == 0x227E)) { cartSize = 32; // Reset flashrom @@ -3991,7 +3993,7 @@ void idFlashrom_N64() { } // Macronix MX29LV640(8MB/16MB) with either one or two flashrom chips - else if ((strcmp(flashid, "22C9") == 0) || (strcmp(flashid, "22CB") == 0)) { + else if ((flashid == 0x22C9) || (flashid == 0x22CB)) { cartSize = 8; resetFlashrom_N64(romBase + 0x800000); @@ -4019,7 +4021,7 @@ void idFlashrom_N64() { } // Intel 4400L0ZDQ0 (64MB) - else if (strcmp(flashid, "8816") == 0) { + else if (flashid == 0x8816) { // Found first flashrom chip, set to 32MB cartSize = 32; resetIntel4400_N64(); @@ -4039,7 +4041,8 @@ void idFlashrom_N64() { sprintf(cartID, "%04X", readWord_N64()); if (strcmp(cartID, "8813") == 0) { cartSize = 64; - strncpy(flashid, cartID, 5); + flashid = 0x8813; + strncpy(flashid_str, cartID, 5); } resetIntel4400_N64(); // Empty cartID string @@ -4047,35 +4050,35 @@ void idFlashrom_N64() { } //Fujitsu MSP55LV512/Spansion S29GL512N (64MB) - else if ((strcmp(cartID, "2301") == 0) && (strcmp(flashid, "227E") == 0)) { + else if ((strcmp(cartID, "2301") == 0) && (flashid == 0x227E)) { cartSize = 64; // Reset flashrom resetFlashrom_N64(romBase); } // Spansion S29GL128N(16MB) with one flashrom chip - else if ((strcmp(cartID, "2101") == 0) && (strcmp(flashid, "227E") == 0)) { + else if ((strcmp(cartID, "2101") == 0) && (flashid == 0x227E)) { cartSize = 16; // Reset flashrom resetFlashrom_N64(romBase); } // ST M29W128GL(16MB) with one flashrom chip - else if ((strcmp(cartID, "2100") == 0) && (strcmp(flashid, "227E") == 0)) { + else if ((strcmp(cartID, "2100") == 0) && (flashid == 0x227E)) { cartSize = 16; // Reset flashrom resetFlashrom_N64(romBase); } // Intel 512M29EW(64MB) with one flashrom chip - else if ((strcmp(cartID, "3901") == 0) && (strcmp(flashid, "227E") == 0)) { + else if ((strcmp(cartID, "3901") == 0) && (flashid == 0x227E)) { cartSize = 64; // Reset flashrom resetFlashrom_N64(romBase); } // Unknown 227E type - else if (strcmp(flashid, "227E") == 0) { + else if (flashid == 0x227E) { cartSize = 0; // Reset flashrom resetFlashrom_N64(romBase); @@ -4100,10 +4103,11 @@ void idFlashrom_N64() { if (strcmp(cartID, "7E7E") == 0) { resetMSP55LV100_N64(romBase); cartSize = 64; - strncpy(flashid, cartID, 5); + flashid = 0x7E7E; + strncpy(flashid_str, cartID, 5); } } - if ((strcmp(flashid, "1240") == 0) && (strcmp(cartID, "1240") == 0)) { + if ((flashid == 0x1240) && (strcmp(cartID, "1240") == 0)) { print_Error(F("Please reseat cartridge"), true); } } @@ -4308,12 +4312,12 @@ void eraseSector_N64(unsigned long sectorSize) { blinkLED(); // Spansion S29GL256N(32MB/64MB) with two flashrom chips - if ((currSector == 0x2000000) && (strcmp(cartID, "2201") == 0) && (strcmp(flashid, "227E") == 0)) { + if ((currSector == 0x2000000) && (strcmp(cartID, "2201") == 0) && (flashid == 0x227E)) { // Change to second chip flashBase = romBase + 0x2000000; } // Macronix MX29LV640(8MB/16MB) with two flashrom chips - else if ((currSector == 0x800000) && ((strcmp(flashid, "22C9") == 0) || (strcmp(flashid, "22CB") == 0))) { + else if ((currSector == 0x800000) && ((flashid == 0x22C9) || (flashid == 0x22CB))) { flashBase = romBase + 0x800000; } @@ -4630,7 +4634,7 @@ void flashGameshark_N64() { // !!!! SST 29EE010 may have a 5V requirement for writing however dumping works at 3V. As such it is not !!!! // !!!! advised to write to a cart with this chip until further testing can be completed. !!!! - if (strcmp(flashid, "0808") == 0 || strcmp(flashid, "0404") == 0 || strcmp(flashid, "3535") == 0 || strcmp(flashid, "0707") == 0) { + if (flashid == 0x0808 || flashid == 0x0404 || flashid == 0x3535 || flashid == 0x0707) { backupGameshark_N64(); println_Msg(""); println_Msg(F("This will erase your")); @@ -4702,7 +4706,7 @@ void flashGameshark_N64() { // If the ID is unknown show error message else { print_Msg(F("ID: ")); - println_Msg(flashid); + println_Msg(flashid_str); print_Error(F("Unknown flashrom"), false); } @@ -4729,7 +4733,8 @@ void idGameshark_N64() { // Read 1 byte vendor ID readWord_N64(); // Read 2 bytes flashrom ID - sprintf(flashid, "%04X", readWord_N64()); + flashid = readWord_N64(); + sprintf(flashid_str, "%04X", flashid); // Reset flashrom resetGameshark_N64(); } @@ -4864,7 +4869,7 @@ unsigned long verifyGameshark_N64() { setAddress_N64(romBase + 0xC00000 + currSector + currSdBuffer + currByte); // Compare both if (readWord_N64() != currWord) { - if ((strcmp(flashid, "0808") == 0) && (currSector + currSdBuffer + currByte > 0x3F) && (currSector + currSdBuffer + currByte < 0x1080)) { + if ((flashid == 0x0808) && (currSector + currSdBuffer + currByte > 0x3F) && (currSector + currSdBuffer + currByte < 0x1080)) { // Gameshark maps this area to the bootcode of the plugged in cartridge } else { writeErrors++; diff --git a/Cart_Reader/NES.ino b/Cart_Reader/NES.ino index d559ce6..de72358 100644 --- a/Cart_Reader/NES.ino +++ b/Cart_Reader/NES.ino @@ -5035,16 +5035,16 @@ void NESmaker_ID() { // Read Flash ID write_prg_byte(0xAAAA, 0x55); write_prg_byte(0xC000, 0x01); write_prg_byte(0x9555, 0x90); // Software ID Entry - unsigned char ID1 = read_prg_byte(0x8000); - unsigned char ID2 = read_prg_byte(0x8001); - sprintf(flashid, "%02X%02X", ID1, ID2); + flashid = read_prg_byte(0x8000) << 8; + flashid |= read_prg_byte(0x8001); + sprintf(flashid_str, "%04X", flashid); write_prg_byte(0xC000, 0x01); write_prg_byte(0x9555, 0xAA); write_prg_byte(0xC000, 0x00); write_prg_byte(0xAAAA, 0x55); write_prg_byte(0xC000, 0x01); write_prg_byte(0x9555, 0xF0); // Software ID Exit - if (strcmp(flashid, "BFB7") == 0) // SST 39SF040 + if (flashid == 0xBFB7) // SST 39SF040 flashfound = 1; } @@ -5098,7 +5098,7 @@ void writeFLASH() { display_Update(); } else { print_Msg(F("Flash ID: ")); - println_Msg(flashid); + println_Msg(flashid_str); println_Msg(F("")); println_Msg(F("NESmaker Flash Found")); println_Msg(F("")); diff --git a/Cart_Reader/SFM.ino b/Cart_Reader/SFM.ino index dcca1d7..7a7095b 100644 --- a/Cart_Reader/SFM.ino +++ b/Cart_Reader/SFM.ino @@ -311,9 +311,9 @@ void sfmFlashMenu() { println_Msg(F("OK")); display_Update(); idFlash_SFM(0xC0); - if (strcmp(flashid, "c2f3") == 0) { + if (flashid == 0xc2f3) { idFlash_SFM(0xE0); - if (strcmp(flashid, "c2f3") == 0) { + if (flashid == 0xc2f3) { // Reset flash resetFlash_SFM(0xC0); resetFlash_SFM(0xE0); @@ -350,9 +350,9 @@ void sfmFlashMenu() { println_Msg(F("OK")); display_Update(); idFlash_SFM(0xC0); - if (strcmp(flashid, "c2f3") == 0) { + if (flashid == 0xc2f3) { idFlash_SFM(0xE0); - if (strcmp(flashid, "c2f3") == 0) { + if (flashid == 0xc2f3) { // Reset flash resetFlash_SFM(0xC0); resetFlash_SFM(0xE0); @@ -1014,7 +1014,9 @@ void idFlash_SFM(int startBank) { controlIn_SFM(); // Read the two id bytes into a string - sprintf(flashid, "%x%x", readBank_SFM(startBank, 0x00), readBank_SFM(startBank, 0x02)); + flashid = readBank_SFM(startBank, 0x00) << 8; + flashid |= readBank_SFM(startBank, 0x02); + sprintf(flashid_str, "%04x", flashid); } else { writeBank_SFM(1, 0x8000 + 0x1555L * 2, 0xaa); writeBank_SFM(0, 0x8000 + 0x2AAAL * 2, 0x55); @@ -1026,7 +1028,9 @@ void idFlash_SFM(int startBank) { controlIn_SFM(); // Read the two id bytes into a string - sprintf(flashid, "%x%x", readBank_SFM(0, 0x8000), readBank_SFM(0, 0x8000 + 0x02)); + flashid = readBank_SFM(0, 0x8000) << 8; + flashid |= readBank_SFM(0, 0x8000 + 0x02); + sprintf(flashid_str, "%04x", flashid); } } @@ -1473,7 +1477,7 @@ void eraseMapping(byte startBank) { if (unlockHirom()) { // Get ID idFlash_SFM(startBank); - if (strcmp(flashid, "c2f3") == 0) { + if (flashid == 0xc2f3) { resetFlash_SFM(startBank); // Switch to write @@ -1583,7 +1587,7 @@ void writeMapping_SFM(byte startBank, uint32_t pos) { if (unlockHirom()) { // Get ID idFlash_SFM(startBank); - if (strcmp(flashid, "c2f3") == 0) { + if (flashid == 0xc2f3) { resetFlash_SFM(startBank); // Switch to write @@ -1716,9 +1720,9 @@ void write_SFM(int startBank, uint32_t pos) { if (unlockHirom()) { // Get ID idFlash_SFM(startBank); - if (strcmp(flashid, "c2f3") == 0) { + if (flashid == 0xc2f3) { print_Msg(F("Flash ID: ")); - println_Msg(flashid); + println_Msg(flashid_str); display_Update(); resetFlash_SFM(startBank); delay(1000); From ae2e90a6cd73c962b5c42c19d529751bc09bae33 Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Sat, 22 Oct 2022 01:34:13 +0000 Subject: [PATCH 03/24] PCE.ino: Skip strcpy to menuOptionspceCart Values can be directly composed/initialised in menuOptionspceCart, avoiding the need to strcpy to it. This saves about 100 bytes of ram by dropping a few global char arrays. Re-duplicates "Reset" string initialiser, but this should not be a big deal. --- Cart_Reader/PCE.ino | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/Cart_Reader/PCE.ino b/Cart_Reader/PCE.ino index 0366a78..9bb0e58 100644 --- a/Cart_Reader/PCE.ino +++ b/Cart_Reader/PCE.ino @@ -58,14 +58,15 @@ static const char pceMenuItem3[] PROGMEM = "Turbochip"; static const char *const menuOptionspce[] PROGMEM = { pceMenuItem1, pceMenuItem2, pceMenuItem3, string_reset2 }; // PCE card menu items -static const char pceCartMenuItem1[] = "Read ROM"; -static char pceCartMenuItem2[20]; -static char pceCartMenuItem3[20]; -//static const char pceCartMenuItem4[] = "Reset"; (stored in common strings array) -static const char pceCartMenuItem5[] = "Inc Bank Number"; -static const char pceCartMenuItem6[] = "Dec Bank Number"; -static char pceCartMenuItem7[20]; -static char menuOptionspceCart[7][20]; +static char menuOptionspceCart[7][20] = { + "Read ROM", + "", // Read RAM Bank %d + "", //Write RAM Bank %d + "Reset", + "Inc Bank Number", + "Dec Bank Number", + "" // ROM size now %dK / Force ROM size +}; // Turbochip menu items static const char pceTCMenuItem1[] PROGMEM = "Read ROM"; @@ -795,20 +796,13 @@ void pceMenu() { unsigned char mainMenu; if (pce_internal_mode == HUCARD || pce_internal_mode == HUCARD_NOSWAP) { - sprintf(pceCartMenuItem2, "Read RAM Bank %d", tennokoe_bank_index + 1); - sprintf(pceCartMenuItem3, "Write RAM Bank %d", tennokoe_bank_index + 1); - strcpy(menuOptionspceCart[0], pceCartMenuItem1); - strcpy(menuOptionspceCart[1], pceCartMenuItem2); - strcpy(menuOptionspceCart[2], pceCartMenuItem3); - strcpy(menuOptionspceCart[3], string_reset2); // (stored in common strings array) - strcpy(menuOptionspceCart[4], pceCartMenuItem5); - strcpy(menuOptionspceCart[5], pceCartMenuItem6); + sprintf(menuOptionspceCart[1], "Read RAM Bank %d", tennokoe_bank_index + 1); + sprintf(menuOptionspceCart[2], "Write RAM Bank %d", tennokoe_bank_index + 1); if (pce_force_rom_size > 0) { - sprintf(pceCartMenuItem7, "ROM size now %dK", pce_force_rom_size); + sprintf(menuOptionspceCart[6], "ROM size now %dK", pce_force_rom_size); } else { - sprintf(pceCartMenuItem7, "Force ROM size"); + sprintf(menuOptionspceCart[6], "Force ROM size"); } - strcpy(menuOptionspceCart[6], pceCartMenuItem7); mainMenu = question_box(F("PCE HuCARD menu"), menuOptionspceCart, 7, 0); // wait for user choice to come back from the question box menu From b3eb3dd92890d7ca33453112c868d07e26424df4 Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Mon, 24 Oct 2022 03:22:04 +0000 Subject: [PATCH 04/24] GBS.ino: Move gbSmartGames from globals to a local. Saves 120 bytes of global ram space. Also, factorise code reading a single entry. This saves about 60 bytes of code space. --- Cart_Reader/GBS.ino | 89 +++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 55 deletions(-) diff --git a/Cart_Reader/GBS.ino b/Cart_Reader/GBS.ino index 403304e..bdc5b35 100644 --- a/Cart_Reader/GBS.ino +++ b/Cart_Reader/GBS.ino @@ -26,14 +26,14 @@ static const char gbSmartGameMenuItem4[] PROGMEM = "Switch Game"; //static const char gbSmartGameMenuItem5[] PROGMEM = "Reset"; (stored in common strings array) static const char* const menuOptionsGBSmartGame[] PROGMEM = { gbSmartGameMenuItem1, gbSmartGameMenuItem2, gbSmartGameMenuItem3, gbSmartGameMenuItem4, string_reset2 }; -typedef struct +struct GBSmartGameInfo { uint8_t start_bank; uint8_t rom_type; uint8_t rom_size; uint8_t sram_size; char title[16]; -} GBSmartGameInfo; +}; uint32_t gbSmartSize = 32 * 131072; uint16_t gbSmartBanks = 256; @@ -46,19 +46,9 @@ uint8_t gbSmartRomSizeGB = 0x07; uint8_t gbSmartSramSizeGB = 0x04; uint8_t gbSmartFlashSizeGB = 0x06; -GBSmartGameInfo gbSmartGames[GB_SMART_GAMES_PER_PAGE]; - byte signature[48]; uint16_t gameMenuStartBank; -#ifdef enable_SFM -extern boolean hasMenu; -extern byte numGames; -#else -boolean hasMenu; -byte numGames; -#endif - // Compare checksum boolean compare_checksum_GBS() { println_Msg(F("Calculating Checksum")); @@ -150,8 +140,6 @@ void setup_GBSmart() { signature[i] = readByte_GBS(0x0104 + i); gameMenuStartBank = 0x02; - hasMenu = true; - numGames = 0; display_Clear(); display_Update(); @@ -246,12 +234,15 @@ void gbSmartGameOptions() { } void gbSmartGameMenu() { + boolean hasMenu; + byte numGames; + struct GBSmartGameInfo gbSmartGames[GB_SMART_GAMES_PER_PAGE]; uint8_t gameSubMenu = 0; gb_smart_load_more_games: if (gameMenuStartBank > 0xfe) gameMenuStartBank = 0x02; - gbSmartGetGames(); + gbSmartGetGames(gbSmartGames, &hasMenu, &numGames); if (hasMenu) { char menuOptionsGBSmartGames[7][20]; @@ -339,29 +330,44 @@ void gbSmartFlashMenu() { wait(); } -void gbSmartGetGames() { +void gbSmartGetOneGame(struct GBSmartGameInfo *gbSmartGames, byte bank, word base) { + uint8_t myByte, myLength = 0; + word title_address = base + 0x0134; + + for (uint8_t j = 0; j < 15; j++) { + myByte = readByte_GBS(title_address++); + + if (((myByte >= '0' && myByte <= '9') || (myByte >= 'A' && myByte <= 'z'))) + gbSmartGames->title[myLength++] = myByte; + } + + gbSmartGames->title[myLength] = 0x00; + gbSmartGames->start_bank = bank; + gbSmartGames->rom_type = readByte_GBS(base + 0x0147); + gbSmartGames->rom_size = readByte_GBS(base + 0x0148); + gbSmartGames->sram_size = readByte_GBS(base + 0x0149); +} + +void gbSmartGetGames(struct GBSmartGameInfo *gbSmartGames, boolean *hasMenu, byte *numGames) { static const byte menu_title[] = { 0x47, 0x42, 0x31, 0x36, 0x4d }; // reset remap setting gbSmartRemapStartBank(0x00, gbSmartRomSizeGB, gbSmartSramSizeGB); uint16_t i; - uint8_t myByte, myLength; // check if contain menu - hasMenu = true; + *hasMenu = true; dataIn(); for (i = 0; i < 5; i++) { if (readByte_GBS(0x0134 + i) != menu_title[i]) { - hasMenu = false; + *hasMenu = false; break; } } - if (hasMenu) { - for (i = gameMenuStartBank, numGames = 0; i < gbSmartBanks && numGames < GB_SMART_GAMES_PER_PAGE;) { - myLength = 0; - + if (*hasMenu) { + for (i = gameMenuStartBank, *numGames = 0; i < gbSmartBanks && *numGames < GB_SMART_GAMES_PER_PAGE;) { // switch bank dataOut(); writeByte_GB(0x2100, i); @@ -371,46 +377,19 @@ void gbSmartGetGames() { for (uint8_t j = 0x00; j < 0x30; j++) { if (readByte_GBS(0x4104 + j) != signature[j]) { i += 0x02; - goto gb_smart_get_game_loop_end; + continue; } } - - for (uint8_t j = 0; j < 15; j++) { - myByte = readByte_GBS(0x4134 + j); - - if (((char(myByte) >= 0x30 && char(myByte) <= 0x39) || (char(myByte) >= 0x41 && char(myByte) <= 0x7a))) - gbSmartGames[numGames].title[myLength++] = char(myByte); - } - - gbSmartGames[numGames].title[myLength] = 0x00; - gbSmartGames[numGames].start_bank = i; - gbSmartGames[numGames].rom_type = readByte_GBS(0x4147); - gbSmartGames[numGames].rom_size = readByte_GBS(0x4148); - gbSmartGames[numGames].sram_size = readByte_GBS(0x4149); - - myByte = (2 << gbSmartGames[numGames].rom_size); - i += myByte; - numGames++; -gb_smart_get_game_loop_end:; + gbSmartGetOneGame(&gbSmartGames[*numGames], i, 0x4000); + i += (2 << gbSmartGames[(*numGames)++].rom_size); } gameMenuStartBank = i; } else { dataIn(); - for (uint8_t j = 0; j < 15; j++) { - myByte = readByte_GBS(0x0134 + j); + gbSmartGetOneGame(&gbSmartGames[0], 0, 0); - if (((char(myByte) >= 0x30 && char(myByte) <= 0x39) || (char(myByte) >= 0x41 && char(myByte) <= 0x7a))) - gbSmartGames[0].title[myLength++] = char(myByte); - } - - gbSmartGames[0].title[myLength] = 0x00; - gbSmartGames[0].start_bank = 0x00; - gbSmartGames[0].rom_type = readByte_GBS(0x0147); - gbSmartGames[0].rom_size = readByte_GBS(0x0148); - gbSmartGames[0].sram_size = readByte_GBS(0x0149); - - numGames = 1; + *numGames = 1; gameMenuStartBank = 0xfe; } } From d7bbc59607d4b831098290bfef8eae9a983065c8 Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Sat, 22 Oct 2022 06:07:10 +0000 Subject: [PATCH 05/24] N64.ino: Remove unused function This does not save any space as the linker noticed it wasn't used. Also, point the (commented-out) only caller to the equivalent libc function. --- Cart_Reader/N64.ino | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/Cart_Reader/N64.ino b/Cart_Reader/N64.ino index e2d97ec..aa5feb7 100644 --- a/Cart_Reader/N64.ino +++ b/Cart_Reader/N64.ino @@ -2033,15 +2033,6 @@ void printCartInfo_N64() { } } -// improved strcmp function that ignores case to prevent checksum comparison issues -int strcicmp(char const* a, char const* b) { - for (;; a++, b++) { - int d = tolower((unsigned char)*a) - tolower((unsigned char)*b); - if (d != 0 || !*a) - return d; - } -} - /* look-up the calculated crc in the file n64.txt on sd card boolean searchCRC(char crcStr[9]) { boolean result = 0; @@ -2063,7 +2054,7 @@ int strcicmp(char const* a, char const* b) { } // Check if string is a match - if (strcicmp(tempStr1, crcStr) == 0) { + if (strcasecmp(tempStr1, crcStr) == 0) { // Skip the , in the file myFile.seekSet(myFile.curPosition() + 1); From dc9ee3b01e39d1b2bbd3400af7b68cd924717a13 Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Sat, 22 Oct 2022 03:01:50 +0000 Subject: [PATCH 06/24] Cart_Reader.ino: make myDir a variable local to fileBrowser. It is not used anywhere else. --- Cart_Reader/Cart_Reader.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index 5475f88..f55304f 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -176,7 +176,6 @@ char ver[5] = "10.4"; // SD Card #include "SdFat.h" SdFs sd; -FsFile myDir; FsFile myFile; #ifdef global_log FsFile myLog; @@ -2972,6 +2971,8 @@ void wait_encoder() { void fileBrowser(const __FlashStringHelper* browserTitle) { char fileNames[7][FILENAME_LENGTH]; int currFile; + FsFile myDir; + filebrowse = 1; // Root From dc391541b4fbe5c4262628277717afe3f886a33a Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Sat, 22 Oct 2022 08:18:46 +0000 Subject: [PATCH 07/24] Cart_Reader.ino: Simplify fileBrowser pagination. Also, this resolves a warning about `count` being potentially used uninitialised: when landing in the "Too many files" codepath. With this simplification, the limit on the number of files is removed. It is unclear whether that was intentional (maybe this was gating other issues ?)? --- Cart_Reader/Cart_Reader.ino | 50 ++++--------------------------------- 1 file changed, 5 insertions(+), 45 deletions(-) diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index f55304f..cb89193 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -2972,6 +2972,7 @@ void fileBrowser(const __FlashStringHelper* browserTitle) { char fileNames[7][FILENAME_LENGTH]; int currFile; FsFile myDir; + div_t page_layout; filebrowse = 1; @@ -3000,32 +3001,15 @@ browserstart: // Count files in directory while (myFile.openNext(&myDir, O_READ)) { - // Ignore if hidden - if (myFile.isHidden()) { - } - // Indicate a directory. - else if (myFile.isDir()) { - currFile++; - } - // It's just a file - else if (myFile.isFile()) { + if (!myFile.isHidden() && (myFile.isDir() || myFile.isFile())) { currFile++; } myFile.close(); } myDir.close(); - // "Calculate number of needed pages" - if (currFile < 8) - numPages = 1; - else if (currFile < 15) - numPages = 2; - else if (currFile < 22) - numPages = 3; - else if (currFile < 29) - numPages = 4; - else if (currFile < 36) - numPages = 5; + page_layout = div(currFile, 7); + numPages = page_layout.quot + 1; // Fill the array "answers" with 7 options to choose from in the file browser char answers[7][20]; @@ -3033,31 +3017,7 @@ browserstart: page: // If there are less than 7 entries, set count to that number so no empty options appear - byte count; - if (currFile < 8) - count = currFile; - else if (currPage == 1) - count = 7; - else if (currFile < 15) - count = currFile - 7; - else if (currPage == 2) - count = 7; - else if (currFile < 22) - count = currFile - 14; - else if (currPage == 3) - count = 7; - else if (currFile < 29) - count = currFile - 21; - else { - display_Clear(); - println_Msg(F("Too many files")); - display_Update(); - println_Msg(F("")); - // Prints string out of the common strings array either with or without newline - print_STR(press_button_STR, 1); - display_Update(); - wait(); - } + byte count = currPage == numPages ? page_layout.rem : 7; // Open filepath directory if (!myDir.open(filePath)) { From 92f86266871e37fc363a07f13842c3a47861d012 Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Sat, 22 Oct 2022 08:21:24 +0000 Subject: [PATCH 08/24] Cart_Reader.ino: Drop convertPgm(const char* const [], byte, byte) This avoids code duplication between it and convertPgm(const char* const [], byte) for just 3 callers, when the callers can be easily updated to call the latter. --- Cart_Reader/Cart_Reader.ino | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index cb89193..67d7f68 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -853,17 +853,17 @@ void mainMenu() { while (1) { if (currPage == 1) { // Copy menuOptions out of progmem - convertPgm(modeOptions, 0, 7); + convertPgm(modeOptions + 0, 7); modeMenu = question_box(F("OPEN SOURCE CART READER"), menuOptions, 7, 0); } if (currPage == 2) { // Copy menuOptions out of progmem - convertPgm(modeOptions, 7, 7); + convertPgm(modeOptions + 7, 7); modeMenu = question_box(F("OPEN SOURCE CART READER"), menuOptions, 7, 0); } if (currPage == 3) { // Copy menuOptions out of progmem - convertPgm(modeOptions, 14, 2); + convertPgm(modeOptions + 14, 2); modeMenu = question_box(F("OPEN SOURCE CART READER"), menuOptions, 2, 0); } if (numPages == 0) { @@ -1862,13 +1862,6 @@ void setColor_RGB(byte r, byte g, byte b) { #endif } -// Converts a progmem array into a ram array -void convertPgm(const char* const pgmOptions[], byte startArray, byte numArrays) { - for (int i = 0; i < numArrays; i++) { - strlcpy_P(menuOptions[i], (char*)pgm_read_word(&(pgmOptions[i + startArray])), 20); - } -} - // Converts a progmem array into a ram array void convertPgm(const char* const pgmOptions[], byte numArrays) { for (int i = 0; i < numArrays; i++) { From 264d83f383549cc9f6321530ca01eb2d3209b809 Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Sat, 22 Oct 2022 08:22:37 +0000 Subject: [PATCH 09/24] Cart_Reader.ino: Drop redundant initialisation. `i` is initialised on the previous line, along with its declaration. --- Cart_Reader/Cart_Reader.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index 67d7f68..371006e 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -1998,7 +1998,7 @@ void save_log() { myFile.write(sdBuffer, 512); } else { word i = 0; - for (i = 0; i < myLog.available(); i++) { + for (; i < myLog.available(); i++) { sdBuffer[i] = myLog.read(); } myFile.write(sdBuffer, i); From 50da6b9da7930fe378ed64ee9fa4a40de9510d6f Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Tue, 25 Oct 2022 15:31:25 +0000 Subject: [PATCH 10/24] Cart_Reader.ino: Assorted cosmetic changes to compareCRC. Shorten gamename to the number of bytes actually used in the code, more sizeof() use. --- Cart_Reader/Cart_Reader.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index 371006e..0ad5bb4 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -636,7 +636,7 @@ boolean compareCRC(char* database, char* crcString, boolean renamerom, int offse display_Update(); //Search for CRC32 in file - char gamename[100]; + char gamename[96]; char crc_search[9]; //go to root @@ -645,8 +645,8 @@ boolean compareCRC(char* database, char* crcString, boolean renamerom, int offse //Search for same CRC in list while (myFile.available()) { //Read 2 lines (game name and CRC) - get_line(gamename, &myFile, 96); - get_line(crc_search, &myFile, 9); + get_line(gamename, &myFile, sizeof(gamename)); + get_line(crc_search, &myFile, sizeof(crc_search)); skip_line(&myFile); //Skip every 3rd line //if checksum search successful, rename the file and end search From daec1f3e35517471f3935fb5290900db44e7ba79 Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Tue, 25 Oct 2022 15:09:08 +0000 Subject: [PATCH 11/24] Card_Reader.ino: Optimise get_line for speed Do fewer calls to readfile->read, especially if the buffer is large enough to fit an entire line, resulting in less call/return overhead. --- Cart_Reader/Cart_Reader.ino | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index 0ad5bb4..aa21e2c 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -590,28 +590,29 @@ void skip_line(FsFile* readfile) { //Get line from file void get_line(char* str_buf, FsFile* readfile, uint8_t maxi) { + int read_len; + // Status LED on statusLED(true); - int i = 0; - - while (readfile->available()) { - //If line size is more than maximum array, limit it. - if (i >= maxi) { - i = maxi - 1; - } - - //Read 1 byte from file - str_buf[i] = readfile->read(); + read_len = readfile->read(str_buf, maxi - 1); + for (int i = 0; i < read_len; i++) { //if end of file or newline found, execute command if (str_buf[i] == '\r') { - str_buf[i] = '\0'; - readfile->read(); //dispose \n because \r\n + str_buf[i] = 0; + readfile->seekCur(i - read_len + 2); // +2 to skip over \n because \r\n + return; + } + } + str_buf[maxi - 1] = 0; + // EOL was not found, keep looking (slower) + while (readfile->available()) { + if (readfile->read() == '\r') { + readfile->read(); // read \n because \r\n break; } - i++; - } //End while + } } // Calculate CRC32 if needed and compare it to CRC read from database From b84f63d1dc81cbdf196a4b58064f391396bce595 Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Tue, 25 Oct 2022 15:15:19 +0000 Subject: [PATCH 12/24] Cart_Reader.ino: Drop redundant display_Update call. In this codepath, there will be a second call just after displaying the CRC, making this call redundant. For completeness: In the alternate codepath, the next operation does a lot of IO, so it makes sense to refresh the screen before printing the CRC. --- Cart_Reader/Cart_Reader.ino | 1 - 1 file changed, 1 deletion(-) diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index aa21e2c..e3f9fc9 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -629,7 +629,6 @@ boolean compareCRC(char* database, char* crcString, boolean renamerom, int offse } else { // Use precalculated crc print_Msg(F("CRC32... ")); - display_Update(); strcpy(crcStr, crcString); } // Print checksum From d81f2c0509e001a77c572200219ceb03563d1b61 Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Sat, 22 Oct 2022 03:00:59 +0000 Subject: [PATCH 13/24] NES.ino: Simplify CRC functions. It seems crc32EEP only exists because the actual number of bytes read from file were not checked, hence falling back to smaller reads. Instead, always read up to the full available buffer, adding to the CRC only as many bytes as were actually read. Also, move some related variables to local scope. Overall, this saves about 50 bytes of code and 80 bytes of global ram. --- Cart_Reader/NES.ino | 60 ++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 42 deletions(-) diff --git a/Cart_Reader/NES.ino b/Cart_Reader/NES.ino index de72358..bb3e697 100644 --- a/Cart_Reader/NES.ino +++ b/Cart_Reader/NES.ino @@ -1458,45 +1458,21 @@ int int_pow(int base, int exp) { // Power for int /****************************************** CRC Functions *****************************************/ -FsFile crcFile; -char tempCRC[9]; -uint32_t crc32(FsFile& file, uint32_t& charcnt) { - uint32_t oldcrc32 = 0xFFFFFFFF; - charcnt = 0; - while (file.available()) { - crcFile.read(sdBuffer, 512); - for (int x = 0; x < 512; x++) { - uint8_t c = sdBuffer[x]; - charcnt++; - oldcrc32 = updateCRC(c, oldcrc32); - } - } - return ~oldcrc32; -} - -uint32_t crc32EEP(FsFile& file, uint32_t& charcnt) { - uint32_t oldcrc32 = 0xFFFFFFFF; - charcnt = 0; - while (file.available()) { - crcFile.read(sdBuffer, 128); - for (int x = 0; x < 128; x++) { - uint8_t c = sdBuffer[x]; - charcnt++; - oldcrc32 = updateCRC(c, oldcrc32); - } - } - return ~oldcrc32; -} - -void calcCRC(char* checkFile, unsigned long filesize, uint32_t* crcCopy, unsigned long offset) { - uint32_t crc; - crcFile = sd.open(checkFile); +void calcCRC(char* checkFile, uint32_t* crcCopy, unsigned long offset) { + uint32_t crc = 0xFFFFFFFF; + char tempCRC[9]; + int byte_count; + FsFile crcFile = sd.open(checkFile); crcFile.seek(offset); - if (filesize < 1024) - crc = crc32EEP(crcFile, filesize); - else - crc = crc32(crcFile, filesize); + while (crcFile.available()) { + byte_count = crcFile.read(sdBuffer, sizeof(sdBuffer)); + for (int x = 0; x < byte_count; x++) { + uint8_t c = sdBuffer[x]; + crc = updateCRC(c, crc); + } + } + crc = ~crc; crcFile.close(); sprintf(tempCRC, "%08lX", crc); @@ -1753,7 +1729,7 @@ void outputNES() { println_Msg(F("")); display_Update(); - calcCRC(outputFile, (prg + chr) * 1024, NULL, crcOffset); + calcCRC(outputFile, NULL, crcOffset); LED_RED_OFF; LED_GREEN_OFF; LED_BLUE_OFF; @@ -3671,7 +3647,7 @@ void readPRG(boolean readrom) { println_Msg(F("")); display_Update(); #ifndef nointro - calcCRC(fileName, prg * 1024, &prg_crc32, 0); + calcCRC(fileName, &prg_crc32, 0); #endif } } @@ -4396,7 +4372,7 @@ void readCHR(boolean readrom) { println_Msg(F("")); display_Update(); #ifndef nointro - calcCRC(fileName, chr * 1024, &chr_crc32, 0); + calcCRC(fileName, &chr_crc32, 0); #endif } } @@ -4585,9 +4561,9 @@ void readRAM() { display_Update(); if ((mapper == 16) || (mapper == 159)) - calcCRC(fileName, eepsize, NULL, 0); + calcCRC(fileName, NULL, 0); else - calcCRC(fileName, ram * 1024, NULL, 0); + calcCRC(fileName, NULL, 0); } } set_address(0); From a555f2117f54ca50fb57b46f1bda7732a8eed18f Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Sat, 22 Oct 2022 08:25:37 +0000 Subject: [PATCH 14/24] All: Resolve all compiler and linker warnings No functional change intended. --- Cart_Reader/Cart_Reader.ino | 33 +++++++------ Cart_Reader/FLASH.ino | 10 ++-- Cart_Reader/GB.ino | 51 ++++++++++++++------ Cart_Reader/GBA.ino | 2 + Cart_Reader/GBM.ino | 2 +- Cart_Reader/GBS.ino | 6 +-- Cart_Reader/INTV.ino | 2 +- Cart_Reader/MD.ino | 8 ++-- Cart_Reader/N64.ino | 41 ++++++++-------- Cart_Reader/NES.ino | 96 +++++++------------------------------ Cart_Reader/NGP.ino | 1 - Cart_Reader/PCE.ino | 7 +-- Cart_Reader/PCW.ino | 5 ++ Cart_Reader/SFM.ino | 24 +++++----- Cart_Reader/SNES.ino | 42 +++------------- Cart_Reader/SV.ino | 10 +--- Cart_Reader/WS.ino | 12 ++--- 17 files changed, 139 insertions(+), 213 deletions(-) diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index e3f9fc9..7ddf943 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -564,6 +564,7 @@ uint32_t calculateCRC(char* fileName, char* folder, int offset) { //print_Msg(F("/")); //print_Msg(fileName); print_Error(F(" not found"), true); + return 0; } } @@ -616,7 +617,7 @@ void get_line(char* str_buf, FsFile* readfile, uint8_t maxi) { } // Calculate CRC32 if needed and compare it to CRC read from database -boolean compareCRC(char* database, char* crcString, boolean renamerom, int offset) { +boolean compareCRC(const char* database, char* crcString, boolean renamerom, int offset) { #ifdef nointro char crcStr[9]; if (crcString == 0) { @@ -661,15 +662,15 @@ boolean compareCRC(char* database, char* crcString, boolean renamerom, int offse get_line(iNES_STR, &myFile, 33); // Convert "4E4553" to (0x4E, 0x45, 0x53) - byte iNES_BUF[2]; + unsigned int iNES_BUF; for (byte j = 0; j < 16; j++) { - sscanf(iNES_STR + j * 2, "%2X", iNES_BUF); - iNES_HEADER[j] = iNES_BUF[0]; + sscanf(iNES_STR + j * 2, "%2X", &iNES_BUF); + iNES_HEADER[j] = iNES_BUF; } //Skip CRLF myFile.seekSet(myFile.curPosition() + 4); } -#endif +#endif // enable_NES // Close the file: myFile.close(); @@ -687,7 +688,7 @@ boolean compareCRC(char* database, char* crcString, boolean renamerom, int offse } myFile.close(); } -#endif +#endif // enable_NES print_Msg(F(" -> ")); display_Update(); @@ -718,9 +719,10 @@ boolean compareCRC(char* database, char* crcString, boolean renamerom, int offse println_Msg(F("Database missing")); return 0; } -#else +#else // nointro println_Msg(""); -#endif +#endif // !nointro + return 0; } byte starting_letter() { @@ -1877,7 +1879,7 @@ void print_Error(const __FlashStringHelper* errorMessage, boolean forceReset) { if (forceReset) { println_Msg(F("")); - println_Msg(F("Press Button...")); + print_STR(press_button_STR, 1); display_Update(); wait(); if (ignoreError == 0) { @@ -1997,7 +1999,7 @@ void save_log() { } myFile.write(sdBuffer, 512); } else { - word i = 0; + int i = 0; for (; i < myLog.available(); i++) { sdBuffer[i] = myLog.read(); } @@ -2031,7 +2033,7 @@ void print_Msg(const char myString[]) { #if (defined(enable_LCD) || defined(enable_OLED)) // test for word wrap if ((display.tx + strlen(myString) * 6) > 128) { - int strPos = 0; + unsigned int strPos = 0; // Print until end of display while (display.tx < 122) { display.print(myString[strPos]); @@ -2174,7 +2176,7 @@ void println_Msg(const char myString[]) { #if (defined(enable_LCD) || defined(enable_OLED)) // test for word wrap if ((display.tx + strlen(myString) * 6) > 128) { - int strPos = 0; + unsigned int strPos = 0; // Print until end of display while ((display.tx < 122) && (myString[strPos] != '\0')) { display.print(myString[strPos]); @@ -2305,8 +2307,8 @@ void blinkLED() { #endif } -void statusLED(boolean on) { #if defined(HW5) +void statusLED(boolean on) { if (!on) PORTD |= (1 << 7); else @@ -2334,8 +2336,11 @@ void statusLED(boolean on) { PORTB &= ~(1 << 7); } */ -#endif } +#else +void statusLED(boolean on __attribute__ ((unused))) { +} +#endif /****************************************** Menu system diff --git a/Cart_Reader/FLASH.ino b/Cart_Reader/FLASH.ino index cca8646..50b6a0b 100644 --- a/Cart_Reader/FLASH.ino +++ b/Cart_Reader/FLASH.ino @@ -1803,7 +1803,7 @@ void printFlash(int numBytes) { for (int currByte = 0; currByte < numBytes; currByte += 10) { for (int c = 0; c < 10; c++) { itoa(readByte_Flash(currByte + c), myBuffer, 16); - for (int i = 0; i < 2 - strlen(myBuffer); i++) { + for (size_t i = 0; i < 2 - strlen(myBuffer); i++) { print_Msg(F("0")); } // Now print the significant bits @@ -2147,14 +2147,14 @@ void printFlash16(int numBytes) { sprintf(buf, "%x", left_byte); - for (int i = 0; i < 2 - strlen(buf); i++) { + for (size_t i = 0; i < 2 - strlen(buf); i++) { print_Msg(F("0")); } // Now print the significant bits print_Msg(buf); sprintf(buf, "%x", right_byte); - for (int i = 0; i < 2 - strlen(buf); i++) { + for (size_t i = 0; i < 2 - strlen(buf); i++) { print_Msg(F("0")); } // Now print the significant bits @@ -2546,14 +2546,14 @@ void print_Eprom(int numBytes) { sprintf(buf, "%x", left_byte); - for (int i = 0; i < 2 - strlen(buf); i++) { + for (size_t i = 0; i < 2 - strlen(buf); i++) { print_Msg(F("0")); } // Now print the significant bits print_Msg(buf); sprintf(buf, "%x", right_byte); - for (int i = 0; i < 2 - strlen(buf); i++) { + for (size_t i = 0; i < 2 - strlen(buf); i++) { print_Msg(F("0")); } // Now print the significant bits diff --git a/Cart_Reader/GB.ino b/Cart_Reader/GB.ino index c0e9f1c..18a86f6 100644 --- a/Cart_Reader/GB.ino +++ b/Cart_Reader/GB.ino @@ -7,8 +7,8 @@ Variables *****************************************/ // Game Boy -int sramBanks; -int romBanks; +word sramBanks; +word romBanks; word lastByte = 0; /****************************************** @@ -911,19 +911,41 @@ void getCartInfo_GB() { } // M161 (Mani 4 in 1) - if ((strncmp(romName, "TETRIS SET", 10) == 0) && (sdBuffer[0x14D] == 0x3F)) { + if (strncmp(romName, "TETRIS SET", 10) == 0 && sdBuffer[0x14D] == 0x3F) { romType = 0x104; } // MMM01 (Mani 4 in 1) if ( - (strncmp(romName, "BOUKENJIMA2 SET", 15) == 0) && (sdBuffer[0x14D] == 0) || (strncmp(romName, "BUBBLEBOBBLE SET", 16) == 0) && (sdBuffer[0x14D] == 0xC6) || (strncmp(romName, "GANBARUGA SET", 13) == 0) && (sdBuffer[0x14D] == 0x90) || (strncmp(romName, "RTYPE 2 SET", 11) == 0) && (sdBuffer[0x14D] == 0x32)) { + ( + strncmp(romName, "BOUKENJIMA2 SET", 15) == 0 && sdBuffer[0x14D] == 0 + ) || ( + strncmp(romName, "BUBBLEBOBBLE SET", 16) == 0 && sdBuffer[0x14D] == 0xC6 + ) || ( + strncmp(romName, "GANBARUGA SET", 13) == 0 && sdBuffer[0x14D] == 0x90 + ) || ( + strncmp(romName, "RTYPE 2 SET", 11) == 0 && sdBuffer[0x14D] == 0x32 + ) + ) { romType = 0x0B; } // MBC1M if ( - (strncmp(romName, "MOMOCOL", 7) == 0) && (sdBuffer[0x14D] == 0x28) || (strncmp(romName, "BOMCOL", 6) == 0) && (sdBuffer[0x14D] == 0x86) || (strncmp(romName, "GENCOL", 6) == 0) && (sdBuffer[0x14D] == 0x8A) || (strncmp(romName, "SUPERCHINESE 123", 16) == 0) && (sdBuffer[0x14D] == 0xE4) || (strncmp(romName, "MORTALKOMBATI&II", 16) == 0) && (sdBuffer[0x14D] == 0xB9) || (strncmp(romName, "MORTALKOMBAT DUO", 16) == 0) && (sdBuffer[0x14D] == 0xA7)) { + ( + strncmp(romName, "MOMOCOL", 7) == 0 && sdBuffer[0x14D] == 0x28 + ) || ( + strncmp(romName, "BOMCOL", 6) == 0 && sdBuffer[0x14D] == 0x86 + ) || ( + strncmp(romName, "GENCOL", 6) == 0 && sdBuffer[0x14D] == 0x8A + ) || ( + strncmp(romName, "SUPERCHINESE 123", 16) == 0 && sdBuffer[0x14D] == 0xE4 + ) || ( + strncmp(romName, "MORTALKOMBATI&II", 16) == 0 && sdBuffer[0x14D] == 0xB9 + ) || ( + strncmp(romName, "MORTALKOMBAT DUO", 16) == 0 && sdBuffer[0x14D] == 0xA7 + ) + ) { romType += 0x100; } @@ -961,7 +983,7 @@ void readROM_GB() { print_Error(create_file_STR, true); } - int endAddress = 0x7FFF; + word endAddress = 0x7FFF; word romAddress = 0; word startBank = 1; @@ -1082,7 +1104,7 @@ void readROM_GB() { } // Calculate checksum -unsigned int calc_checksum_GB(char* fileName, char* folder) { +unsigned int calc_checksum_GB(char* fileName) { unsigned int calcChecksum = 0; // int calcFilesize = 0; // unused unsigned long i = 0; @@ -1126,7 +1148,7 @@ void compare_checksums_GB() { // Internal ROM checksum char calcsumStr[5]; - sprintf(calcsumStr, "%04X", calc_checksum_GB(fileName, folder)); + sprintf(calcsumStr, "%04X", calc_checksum_GB(fileName)); print_Msg(F("Checksum: ")); print_Msg(calcsumStr); @@ -1299,6 +1321,7 @@ unsigned long verifySRAM_GB() { return writeErrors; } else { print_Error(open_file_STR, true); + return 1; } } @@ -1679,7 +1702,7 @@ void writeFlash29F_GB(byte MBC, boolean flashErase) { display_Update(); // Read x number of banks - for (int currBank = 0; currBank < romBanks; currBank++) { + for (word currBank = 0; currBank < romBanks; currBank++) { // Blink led blinkLED(); @@ -1713,7 +1736,7 @@ void writeFlash29F_GB(byte MBC, boolean flashErase) { uint32_t totalProgressBar = (uint32_t)(romBanks)*16384; draw_progressbar(0, totalProgressBar); - for (int currBank = 0; currBank < romBanks; currBank++) { + for (word currBank = 0; currBank < romBanks; currBank++) { // Blink led blinkLED(); @@ -1763,7 +1786,7 @@ void writeFlash29F_GB(byte MBC, boolean flashErase) { uint32_t totalProgressBar = (uint32_t)(romBanks)*16384; draw_progressbar(0, totalProgressBar); - for (int currBank = 0; currBank < romBanks; currBank++) { + for (word currBank = 0; currBank < romBanks; currBank++) { // Blink led blinkLED(); @@ -1885,7 +1908,7 @@ byte readByteCompensated(int address) { . address needs to be the x8 mode address of the flash register that should be read. */ -byte writeByteCompensated(int address, byte data) { +void writeByteCompensated(int address, byte data) { if (flashSwitchLastBits) { data = (data & 0b11111100) | ((data << 1) & 0b10) | ((data >> 1) & 0b01); } @@ -2078,7 +2101,7 @@ bool writeCFI_GB() { display_Update(); // Read x number of banks - for (int currBank = 0; currBank < romBanks; currBank++) { + for (word currBank = 0; currBank < romBanks; currBank++) { // Blink led blinkLED(); @@ -2105,7 +2128,7 @@ bool writeCFI_GB() { word currAddr = 0; word endAddr = 0x3FFF; - for (int currBank = 0; currBank < romBanks; currBank++) { + for (word currBank = 0; currBank < romBanks; currBank++) { // Blink led blinkLED(); diff --git a/Cart_Reader/GBA.ino b/Cart_Reader/GBA.ino index 21ff4f4..e435946 100644 --- a/Cart_Reader/GBA.ino +++ b/Cart_Reader/GBA.ino @@ -1339,6 +1339,7 @@ unsigned long verifySRAM_GBA(unsigned long sramSize, uint32_t pos) { return writeErrors; } else { print_Error(F("Can't open file"), false); + return 1; } } @@ -1546,6 +1547,7 @@ unsigned long verifyFRAM_GBA(unsigned long framSize) { return writeErrors; } else { print_Error(F("Can't open file"), false); + return 1; } } diff --git a/Cart_Reader/GBM.ino b/Cart_Reader/GBM.ino index 53e5db8..dc2ff50 100644 --- a/Cart_Reader/GBM.ino +++ b/Cart_Reader/GBM.ino @@ -308,7 +308,7 @@ void writeByte_GBM(word myAddress, byte myData) { HELPER FUNCTIONS **********************/ void printSdBuffer(word startByte, word numBytes) { - for (int currByte = 0; currByte < numBytes; currByte += 10) { + for (word currByte = 0; currByte < numBytes; currByte += 10) { for (byte c = 0; c < 10; c++) { // Convert to char array so we don't lose leading zeros char currByteStr[2]; diff --git a/Cart_Reader/GBS.ino b/Cart_Reader/GBS.ino index bdc5b35..bebd73b 100644 --- a/Cart_Reader/GBS.ino +++ b/Cart_Reader/GBS.ino @@ -62,7 +62,7 @@ boolean compare_checksum_GBS() { sprintf(folder, "GB/ROM/%s/%d", romName, foldern - 1); char calcsumStr[5]; - sprintf(calcsumStr, "%04X", calc_checksum_GB(fileName, folder)); + sprintf(calcsumStr, "%04X", calc_checksum_GB(fileName)); if (strcmp(calcsumStr, checksumStr) == 0) { print_Msg(F("Result: ")); @@ -404,7 +404,7 @@ void gbSmartReadFlash() { print_Error(create_file_STR, true); // reset flash to read array state - for (int i = 0x00; i < gbSmartBanks; i += gbSmartBanksPerFlashChip) + for (uint16_t i = 0x00; i < gbSmartBanks; i += gbSmartBanksPerFlashChip) gbSmartResetFlash(i); // remaps mmc to full access @@ -443,7 +443,7 @@ void gbSmartReadFlash() { } void gbSmartWriteFlash() { - for (int bank = 0x00; bank < gbSmartBanks; bank += gbSmartBanksPerFlashChip) { + for (uint16_t bank = 0x00; bank < gbSmartBanks; bank += gbSmartBanksPerFlashChip) { display_Clear(); print_Msg(F("Erasing...")); diff --git a/Cart_Reader/INTV.ino b/Cart_Reader/INTV.ino index 2792239..3fd7590 100644 --- a/Cart_Reader/INTV.ino +++ b/Cart_Reader/INTV.ino @@ -871,7 +871,7 @@ void setCart_INTV() { myFile.seekSet(myFile.curPosition() + 1); // Read SRAM size - byte sramSize = myFile.read() - 48; + byte sramSize __attribute__ ((unused)) = myFile.read() - 48; // Skip rest of line myFile.seekSet(myFile.curPosition() + 2); diff --git a/Cart_Reader/MD.ino b/Cart_Reader/MD.ino index 07f239c..cb7021c 100644 --- a/Cart_Reader/MD.ino +++ b/Cart_Reader/MD.ino @@ -8,7 +8,7 @@ Variables *****************************************/ unsigned long sramEnd; -int eepSize; +word eepSize; word addrhi; word addrlo; word chksum; @@ -1176,10 +1176,10 @@ void readROM_MD() { byte buffer[1024] = { 0 }; // get current time - unsigned long startTime = millis(); + // unsigned long startTime = millis(); // Phantasy Star/Beyond Oasis with 74HC74 and 74HC139 switch ROM/SRAM at address 0x200000 - if (0x200000 < cartSize < 0x400000) { + if (0x200000 < cartSize && cartSize < 0x400000) { enableSram_MD(0); } @@ -1561,7 +1561,7 @@ void readSram_MD() { } unsigned long padsize = (1UL << 16) - (sramSize << 1); unsigned long padblockcount = padsize >> 9; // number of 512 byte blocks - for (int i = 0; i < padblockcount; i++) { + for (unsigned long i = 0; i < padblockcount; i++) { myFile.write(sdBuffer, 512); } } diff --git a/Cart_Reader/N64.ino b/Cart_Reader/N64.ino index aa5feb7..2e1e51c 100644 --- a/Cart_Reader/N64.ino +++ b/Cart_Reader/N64.ino @@ -981,7 +981,6 @@ void controllerTest_Display() { // Graph int xax = 24; // midpoint x int yax = 24; // midpoint y - int zax = 24; // size // variables to display test data of different sticks int upx = 0; @@ -1727,20 +1726,16 @@ void verifyCRC() { } // Calculates the checksum of the header -boolean checkHeader(byte startAddress) { +boolean checkHeader(byte *buf) { word sum = 0; + word buf_sum = (buf[28] << 8) + buf[29]; // first 28 bytes are the header, then comes the checksum(word) followed by the reverse checksum(0xFFF2 - checksum) - for (int i = 0; i < 28; i += 2) { - word tempword = (((sdBuffer[startAddress + i] & 0xFF) << 8) | (sdBuffer[startAddress + i + 1] & 0xFF)); - sum += tempword; + for (byte i = 0; i < 28; i += 2) { + sum += (buf[i] << 8) + buf[i + 1]; } - if ((((sdBuffer[startAddress + 28] & 0xFF) << 8) | (sdBuffer[startAddress + 29] & 0xFF)) != (sum & 0xFFFF)) { - return 0; - } else { - return 1; - } + return sum == buf_sum; } // verifies if Controller Pak holds valid header data @@ -1755,13 +1750,13 @@ void validateMPK() { //Check all four header copies writeErrors = 0; - if (!checkHeader(0x20)) + if (!checkHeader(&sdBuffer[0x20])) writeErrors++; - if (!checkHeader(0x60)) + if (!checkHeader(&sdBuffer[0x60])) writeErrors++; - if (!checkHeader(0x80)) + if (!checkHeader(&sdBuffer[0x80])) writeErrors++; - if (!checkHeader(0xC0)) + if (!checkHeader(&sdBuffer[0xC0])) writeErrors++; print_Msg(F("HDR: ")); @@ -2484,6 +2479,7 @@ unsigned long verifyEeprom_CLK() { return writeErrors; } else { print_Error(F("Savetype Error"), true); + return 1; } } @@ -2850,6 +2846,7 @@ unsigned long verifyEeprom() { return writeErrors; } else { print_Error(F("Savetype Error"), true); + return 1; } } @@ -3630,8 +3627,8 @@ void savesummary_N64(boolean checkfound, char crcStr[9], unsigned long timeElaps N64 Repro Flashrom Functions *****************************************/ void flashRepro_N64() { - unsigned long sectorSize; - byte bufferSize; + unsigned long sectorSize = 0; + byte bufferSize = 0; // Check flashrom ID's idFlashrom_N64(); @@ -3870,10 +3867,14 @@ void flashRepro_N64() { // Intel 4400L0ZDQ0 writeIntel4400_N64(); resetIntel4400_N64(); - } else if (bufferSize == 0) { - writeFlashrom_N64(sectorSize); + } else if (sectorSize) { + if (bufferSize) { + writeFlashBuffer_N64(sectorSize, bufferSize); + } else { + writeFlashrom_N64(sectorSize); + } } else { - writeFlashBuffer_N64(sectorSize, bufferSize); + print_Error(F("sectorSize not set"), true); } // Close the file: @@ -4498,7 +4499,7 @@ void writeFlashBuffer_N64(unsigned long sectorSize, byte bufferSize) { writeWord_N64((bufferSize / 2) - 1); // Define variable before loop so we can use it later when reading the status register - word currWord; + word currWord = 0; for (byte currByte = 0; currByte < bufferSize; currByte += 2) { // Join two bytes into one word diff --git a/Cart_Reader/NES.ino b/Cart_Reader/NES.ino index bb3e697..da43208 100644 --- a/Cart_Reader/NES.ino +++ b/Cart_Reader/NES.ino @@ -186,7 +186,7 @@ byte prgchk1; boolean mmc6 = false; byte prgchk2; byte prgchk3; -int eepsize; +word eepsize; byte bytecheck; byte firstbyte; boolean flashfound = false; // NESmaker 39SF040 Flash Cart @@ -206,7 +206,6 @@ char fileBIN[] = "CART.bin"; // Cartridge Config byte mapper; -byte newmapper; byte prgsize; byte newprgsize; byte chrsize; @@ -632,10 +631,10 @@ boolean getMapping() { skip_line(&myFile); // Convert "4E4553" to (0x4E, 0x45, 0x53) - byte iNES_BUF[2]; + unsigned int iNES_BUF; for (byte j = 0; j < 16; j++) { - sscanf(iNES_STR + j * 2, "%2X", iNES_BUF); - iNES_HEADER[j] = iNES_BUF[0]; + sscanf(iNES_STR + j * 2, "%2X", &iNES_BUF); + iNES_HEADER[j] = iNES_BUF; } // Convert iNES garbage to useful info (thx to fceux) @@ -925,10 +924,10 @@ void selectMapping() { skip_line(&myFile); // Convert "4E4553" to (0x4E, 0x45, 0x53) - byte iNES_BUF[2]; + unsigned int iNES_BUF; for (byte j = 0; j < 16; j++) { - sscanf(iNES_STR + j * 2, "%2X", iNES_BUF); - iNES_HEADER[j] = iNES_BUF[0]; + sscanf(iNES_STR + j * 2, "%2X", &iNES_BUF); + iNES_HEADER[j] = iNES_BUF; } // Convert iNES garbage to useful info (thx to fceux) @@ -1212,17 +1211,6 @@ void readRaw_NES() { /****************************************** Low Level Functions *****************************************/ -static void phi2_init() { - int i = 0x80; - unsigned char h = PORTF |= (1 << 0); - unsigned char l = PORTF &= ~(1 << 0); - while (i != 0) { - PORTL = l; - PORTL = h; - i--; - } -} - static void set_address(unsigned int address) { unsigned char l = address & 0xFF; unsigned char h = address >> 8; @@ -1295,60 +1283,6 @@ static void write_prg_byte(unsigned int address, uint8_t data) { // _delay_us(1); } -static void write_chr_byte(unsigned int address, uint8_t data) { - PHI2_LOW; - ROMSEL_HI; - MODE_WRITE; - PORTK = data; - - set_address(address); // PHI2 low, ROMSEL always HIGH - //_delay_us(10); - CHR_WRITE_LOW; - _delay_us(1); // WRITING - //_delay_ms(1); // WRITING - CHR_WRITE_HI; - //_delay_us(1); - MODE_READ; - set_address(0); - PHI2_HI; - //_delay_us(1); -} - -static void write_prg(unsigned int address, unsigned int len, uint8_t* data) { - LED_RED_ON; - while (len > 0) { - write_prg_byte(address, *data); - address++; - len--; - data++; - } - //_delay_ms(1); - LED_RED_OFF; -} - -static void write_chr(unsigned int address, unsigned int len, uint8_t* data) { - LED_RED_ON; - while (len > 0) { - write_chr_byte(address, *data); - address++; - len--; - data++; - } - //_delay_ms(1); - LED_RED_OFF; -} - -static void reset_phi2() { - LED_RED_ON; - LED_GREEN_ON; - PHI2_LOW; - ROMSEL_HI; - _delay_ms(100); - PHI2_HI; - LED_RED_OFF; - LED_GREEN_OFF; -} - void resetROM() { set_address(0); PHI2_HI; @@ -2017,6 +1951,7 @@ unsigned char* getNES20HeaderBytesFromDatabaseRow(const char* crctest) { Config Functions *****************************************/ void setMapper() { + byte newmapper; #ifdef global_log // Disable log to prevent unnecessary logging println_Log(F("Set Mapper manually")); @@ -2028,7 +1963,7 @@ void setMapper() { chooseMapper: // Read stored mapper EEPROM_readAnything(7, newmapper); - if ((newmapper > 220) || (newmapper < 0)) + if (newmapper > 220) newmapper = 0; // Split into digits byte hundreds = newmapper / 100; @@ -2920,7 +2855,7 @@ void readPRG(boolean readrom) { case 87: // 16K/32K case 184: // 32K case 185: // 16K/32K - for (word address = 0; address < ((prgsize * 0x4000) + 0x4000); address += 512) { // 16K or 32K + for (word address = 0; address < (((word) prgsize) * 0x4000) + 0x4000; address += 512) { // 16K or 32K dumpPRG(base, address); } break; @@ -2948,7 +2883,7 @@ void readPRG(boolean readrom) { case 2: // 128K/256K for (int i = 0; i < 8; i++) { // 128K/256K write_prg_byte(0x8000, i); - for (word address = 0x0; address < (((prgsize - 3) * 0x4000) + 0x4000); address += 512) { + for (word address = 0x0; address < (((word) prgsize - 3) * 0x4000) + 0x4000; address += 512) { dumpPRG(base, address); } } @@ -5113,11 +5048,11 @@ void writeFLASH() { myFile.read(sdBuffer, 512); for (int x = 0; x < 512; x++) { word location = base + sector + addr + x; - NESmaker_ByteProgram(i, base + sector + addr + x, sdBuffer[x]); + NESmaker_ByteProgram(i, location, sdBuffer[x]); delayMicroseconds(14); // Typical 14us for (byte k = 0; k < 2; k++) { // Confirm write twice do { - bytecheck = read_prg_byte(base + sector + addr + x); + bytecheck = read_prg_byte(location); delayMicroseconds(14); } while (bytecheck != sdBuffer[x]); } @@ -5152,6 +5087,11 @@ void writeFLASH() { sd.chdir(); // root filePath[0] = '\0'; // Reset filePath } + +// avoid warnings +#undef MODE_READ +#undef MODE_WRITE + #endif //****************************************** // End of File diff --git a/Cart_Reader/NGP.ino b/Cart_Reader/NGP.ino index cad21aa..288800a 100644 --- a/Cart_Reader/NGP.ino +++ b/Cart_Reader/NGP.ino @@ -248,7 +248,6 @@ void readROM_NGP(char* outPathBuf, size_t bufferSize) { void scanChip_NGP() { display_Clear(); - uint32_t block_addr = 0; // generate name of report file snprintf(fileName, FILENAME_LENGTH, "%s.txt", romName); diff --git a/Cart_Reader/PCE.ino b/Cart_Reader/PCE.ino index 9bb0e58..fae4fbd 100644 --- a/Cart_Reader/PCE.ino +++ b/Cart_Reader/PCE.ino @@ -440,9 +440,8 @@ uint32_t calculate_crc32(int n, unsigned char c[], uint32_t r) { return r; } -void crc_search(char *file_p, char *folder_p, uint32_t rom_size, uint32_t crc) { +void crc_search(char *file_p, char *folder_p, uint32_t rom_size __attribute__ ((unused)), uint32_t crc) { FsFile rom, script; - uint32_t r, processedsize; char gamename[100]; char crc_file[9], crc_search[9]; uint8_t flag; @@ -519,10 +518,6 @@ void lock_tennokoe_bank_RAM() { } void read_tennokoe_bank_PCE(int bank_index) { - uint32_t processed_size = 0; - uint32_t verify_loop; - uint8_t verify_flag = 1; - //clear the screen display_Clear(); diff --git a/Cart_Reader/PCW.ino b/Cart_Reader/PCW.ino index 53d36c0..3d47830 100644 --- a/Cart_Reader/PCW.ino +++ b/Cart_Reader/PCW.ino @@ -657,6 +657,11 @@ unsigned long verifySRAM_PCW() { return writeErrors; } + +// avoid warnings +#undef MODE_READ +#undef MODE_WRITE + #endif //****************************************** // End of File diff --git a/Cart_Reader/SFM.ino b/Cart_Reader/SFM.ino index 7a7095b..535a36b 100644 --- a/Cart_Reader/SFM.ino +++ b/Cart_Reader/SFM.ino @@ -941,7 +941,7 @@ void readROM_SFM() { display_Update(); // Read up to 96 banks starting at bank 0×00. - for (int currBank = 0; currBank < numBanks; currBank++) { + for (byte currBank = 0; currBank < numBanks; currBank++) { // Dump the bytes to SD 512B at a time for (long currByte = 32768; currByte < 65536; currByte += 512) { for (int c = 0; c < 512; c++) { @@ -956,7 +956,7 @@ void readROM_SFM() { println_Msg(F("Dumping HiRom...")); display_Update(); - for (int currBank = 192; currBank < (numBanks + 192); currBank++) { + for (byte currBank = 192; currBank < (numBanks + 192); currBank++) { for (long currByte = 0; currByte < 65536; currByte += 512) { for (int c = 0; c < 512; c++) { sdBuffer[c] = readBank_SFM(currBank, currByte + c); @@ -1056,7 +1056,7 @@ void writeFlash_SFM(int startBank, uint32_t pos) { if (romType) { // Write hirom - for (int currBank = startBank; currBank < startBank + numBanks; currBank++) { + for (byte currBank = startBank; currBank < startBank + numBanks; currBank++) { // Fill SDBuffer with 1 page at a time then write it repeat until all bytes are written for (unsigned long currByte = 0; currByte < 0x10000; currByte += 128) { myFile.read(sdBuffer, 128); @@ -1081,7 +1081,7 @@ void writeFlash_SFM(int startBank, uint32_t pos) { } } else { // Write lorom - for (int currBank = 0; currBank < numBanks; currBank++) { + for (byte currBank = 0; currBank < numBanks; currBank++) { for (unsigned long currByte = 0x8000; currByte < 0x10000; currByte += 128) { myFile.read(sdBuffer, 128); // Write command sequence @@ -1184,7 +1184,7 @@ byte blankcheck_SFM(int startBank) { byte blank = 1; if (romType) { - for (int currBank = startBank; currBank < startBank + numBanks; currBank++) { + for (byte currBank = startBank; currBank < startBank + numBanks; currBank++) { for (unsigned long currByte = 0; currByte < 0x10000; currByte++) { if (readBank_SFM(currBank, currByte) != 0xFF) { currBank = startBank + numBanks; @@ -1193,7 +1193,7 @@ byte blankcheck_SFM(int startBank) { } } } else { - for (int currBank = 0; currBank < numBanks; currBank++) { + for (byte currBank = 0; currBank < numBanks; currBank++) { for (unsigned long currByte = 0x8000; currByte < 0x10000; currByte++) { if (readBank_SFM(currBank, currByte) != 0xFF) { currBank = numBanks; @@ -1221,7 +1221,7 @@ unsigned long verifyFlash_SFM(int startBank, uint32_t pos) { controlIn_SFM(); if (romType) { - for (int currBank = startBank; currBank < startBank + numBanks; currBank++) { + for (byte currBank = startBank; currBank < startBank + numBanks; currBank++) { for (unsigned long currByte = 0; currByte < 0x10000; currByte += 512) { // Fill SDBuffer myFile.read(sdBuffer, 512); @@ -1233,7 +1233,7 @@ unsigned long verifyFlash_SFM(int startBank, uint32_t pos) { } } } else { - for (int currBank = 0; currBank < numBanks; currBank++) { + for (byte currBank = 0; currBank < numBanks; currBank++) { for (unsigned long currByte = 0x8000; currByte < 0x10000; currByte += 512) { // Fill SDBuffer myFile.read(sdBuffer, 512); @@ -1273,7 +1273,7 @@ void readFlash_SFM() { print_Error(create_file_STR, true); } if (romType) { - for (int currBank = 0xC0; currBank < 0xC0 + numBanks; currBank++) { + for (byte currBank = 0xC0; currBank < 0xC0 + numBanks; currBank++) { for (unsigned long currByte = 0; currByte < 0x10000; currByte += 512) { for (int c = 0; c < 512; c++) { sdBuffer[c] = readBank_SFM(currBank, currByte + c); @@ -1282,7 +1282,7 @@ void readFlash_SFM() { } } } else { - for (int currBank = 0; currBank < numBanks; currBank++) { + for (byte currBank = 0; currBank < numBanks; currBank++) { for (unsigned long currByte = 0x8000; currByte < 0x10000; currByte += 512) { for (int c = 0; c < 512; c++) { sdBuffer[c] = readBank_SFM(currBank, currByte + c); @@ -1348,10 +1348,10 @@ void printMapping() { // Read the mapping out of the first chip char buffer[3]; - for (int currByte = 0xFF00; currByte < 0xFF50; currByte += 10) { + for (unsigned int currByte = 0xFF00; currByte < 0xFF50; currByte += 10) { for (int c = 0; c < 10; c++) { itoa(readBank_SFM(0xC0, currByte + c), buffer, 16); - for (int i = 0; i < 2 - strlen(buffer); i++) { + for (size_t i = 0; i < 2 - strlen(buffer); i++) { print_Msg(F("0")); } // Now print the significant bits diff --git a/Cart_Reader/SNES.ino b/Cart_Reader/SNES.ino index 5f4953b..5a0c8d8 100644 --- a/Cart_Reader/SNES.ino +++ b/Cart_Reader/SNES.ino @@ -204,8 +204,6 @@ void snesMenu() { display_Clear(); // Change working dir to root sd.chdir("/"); - // get current time - unsigned long startTime = millis(); // start reading from cart readROM_SNES(); // Internal Checksum @@ -604,7 +602,7 @@ void readLoRomBanks(unsigned int start, unsigned int total, FsFile* file) { uint32_t totalProgressBar = (uint32_t)(total - start) * 1024; draw_progressbar(0, totalProgressBar); - for (int currBank = start; currBank < total; currBank++) { + for (byte currBank = start; currBank < total; currBank++) { PORTL = currBank; // Blink led @@ -655,7 +653,7 @@ void readHiRomBanks(unsigned int start, unsigned int total, FsFile* file) { uint32_t totalProgressBar = (uint32_t)(total - start) * 1024; draw_progressbar(0, totalProgressBar); - for (int currBank = start; currBank < total; currBank++) { + for (byte currBank = start; currBank < total; currBank++) { PORTL = currBank; // Blink led @@ -701,31 +699,6 @@ void readHiRomBanks(unsigned int start, unsigned int total, FsFile* file) { void getCartInfo_SNES() { boolean manualConfig = 0; - //Prime SA1 cartridge - uint16_t c = 0; - uint16_t currByte = 0; - byte buffer[1024] = { 0 }; - PORTL = 192; - while (c < 1024) { - PORTF = (currByte & 0xFF); - PORTK = ((currByte >> 8) & 0xFF); - - // Wait for the Byte to appear on the data bus - // Arduino running at 16Mhz -> one nop = 62.5ns - // slowRom is good for 200ns, fastRom is <= 120ns; S-CPU best case read speed: 3.57MHz / 280ns - // let's be conservative and use 6 x 62.5 = 375ns - NOP; - NOP; - NOP; - NOP; - NOP; - NOP; - - buffer[c] = PINC; - c++; - currByte++; - } - // Print start page if (checkcart_SNES() == 0) { // Checksum either corrupt or 0000 @@ -953,12 +926,10 @@ boolean checkcart_SNES() { // set control to read dataIn(); - uint16_t c = 0; uint16_t headerStart = 0xFFB0; - uint16_t currByte = headerStart; - byte snesHeader[80] = { 0 }; + byte snesHeader[80]; PORTL = 0; - while (c < 80) { + for (uint16_t c = 0, currByte = headerStart; c < 80; c++, currByte++) { PORTF = (currByte & 0xFF); PORTK = ((currByte >> 8) & 0xFF); @@ -976,8 +947,6 @@ boolean checkcart_SNES() { NOP; snesHeader[c] = PINC; - c++; - currByte++; } // Calculate CRC32 of header @@ -1396,7 +1365,7 @@ void readROM_SNES() { controlIn_SNES(); byte initialSOMap = readBank_SNES(0, 18439); - for (int currMemmap = 0; currMemmap < (numBanks / 16); currMemmap++) { + for (byte currMemmap = 0; currMemmap < (numBanks / 16); currMemmap++) { dataOut(); controlOut_SNES(); @@ -1974,6 +1943,7 @@ unsigned long verifySRAM() { return writeErrors; } else { print_Error(F("Can't open file"), false); + return 1; } } diff --git a/Cart_Reader/SV.ino b/Cart_Reader/SV.ino index 6ad69ff..ba61252 100644 --- a/Cart_Reader/SV.ino +++ b/Cart_Reader/SV.ino @@ -302,11 +302,8 @@ void readSRAM_SV() { if (!myFile.open(fileName, O_RDWR | O_CREAT)) { print_Error(sd_error_STR, true); } - int sramBanks = 0; readBank_SV(0x10, 0); // Preconfigure to fix corrupt 1st byte - // Sram size - long lastByte = (long(sramSize) * 0x80); //startBank = 0x10; endBank = 0x17; CS low for (byte BSBank = 0x10; BSBank < 0x18; BSBank++) { @@ -347,8 +344,6 @@ void writeSRAM_SV() { // Set RST RD WR to High and CS to Low controlOut_SNES(); - long lastByte = (long(sramSize) * 0x80); - println_Msg(F("Writing sram...")); display_Update(); @@ -390,10 +385,6 @@ unsigned long verifySRAM_SV() { // Set control controlIn_SNES(); - int sramBanks = 0; - // Sram size - long lastByte = (long(sramSize) * 0x80); - //startBank = 0x10; endBank = 0x17; CS low for (byte BSBank = 0x10; BSBank < 0x18; BSBank++) { //startAddr = 0x5000 @@ -412,6 +403,7 @@ unsigned long verifySRAM_SV() { return writeErrors; } else { print_Error(F("Can't open file"), false); + return 1; } } diff --git a/Cart_Reader/WS.ino b/Cart_Reader/WS.ino index 40e8273..727f239 100644 --- a/Cart_Reader/WS.ino +++ b/Cart_Reader/WS.ino @@ -981,7 +981,7 @@ boolean compareChecksum_WS(const char *wsFilePath) { } uint32_t calLength = myFile.fileSize() - 512; - uint32_t checksum = 0; + uint16_t checksum = 0; if (wsWitch) { // only calcuate last 128Kbytes for wonderwitch (OS and BIOS region) @@ -1003,18 +1003,12 @@ boolean compareChecksum_WS(const char *wsFilePath) { myFile.close(); - checksum &= 0x0000ffff; - calLength = wsGameChecksum; - - // don't know why formating string "%04X(%04X)" always output "xxxx(0000)" - // so split into two snprintf char result[11]; - snprintf(result, 5, "%04X", calLength); - snprintf(result + 4, 11 - 4, "(%04X)", checksum); + snprintf(result, 11, "%04X(%04X)", wsGameChecksum, checksum); print_Msg(F("Result: ")); println_Msg(result); - if (checksum == calLength) { + if (checksum == wsGameChecksum) { println_Msg(F("Checksum matches")); display_Update(); return 1; From 0a627e5bd4010e36c32877a916da02d2213a2c1b Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Sun, 23 Oct 2022 05:01:59 +0000 Subject: [PATCH 15/24] All: Use f.seekCur(x) instead of f.seekSet(f.curPosition() + x) Saves 450 bytes of program space. --- Cart_Reader/COLV.ino | 18 +++++++++--------- Cart_Reader/Cart_Reader.ino | 4 ++-- Cart_Reader/GBA.ino | 20 ++++++++++---------- Cart_Reader/INTV.ino | 22 +++++++++++----------- Cart_Reader/N64.ino | 12 ++++++------ Cart_Reader/NES.ino | 36 ++++++++++++++++++------------------ Cart_Reader/SNES.ino | 10 +++++----- Cart_Reader/WSV.ino | 18 +++++++++--------- 8 files changed, 70 insertions(+), 70 deletions(-) diff --git a/Cart_Reader/COLV.ino b/Cart_Reader/COLV.ino index 9f16d84..4ea817e 100644 --- a/Cart_Reader/COLV.ino +++ b/Cart_Reader/COLV.ino @@ -399,15 +399,15 @@ void setCart_COL() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); } // Display database @@ -425,7 +425,7 @@ void setCart_COL() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read CRC32 of first 512 bytes sprintf(crc_search, "%c", myFile.read()); @@ -435,7 +435,7 @@ void setCart_COL() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read rom size // Read the next ascii character and subtract 48 to convert to decimal @@ -449,7 +449,7 @@ void setCart_COL() { } // Skip rest of line - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); // Skip every 3rd line skip_line(&myFile); @@ -490,15 +490,15 @@ void setCart_COL() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); break; } diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index 7ddf943..6415943 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -655,7 +655,7 @@ boolean compareCRC(const char* database, char* crcString, boolean renamerom, int #ifdef enable_NES if ((mode == mode_NES) && (offset != 0)) { // Rewind to iNES Header - myFile.seekSet(myFile.curPosition() - 36); + myFile.seekCur(-36); char iNES_STR[33]; // Read iNES header @@ -668,7 +668,7 @@ boolean compareCRC(const char* database, char* crcString, boolean renamerom, int iNES_HEADER[j] = iNES_BUF; } //Skip CRLF - myFile.seekSet(myFile.curPosition() + 4); + myFile.seekCur(4); } #endif // enable_NES diff --git a/Cart_Reader/GBA.ino b/Cart_Reader/GBA.ino index e435946..5b1054b 100644 --- a/Cart_Reader/GBA.ino +++ b/Cart_Reader/GBA.ino @@ -873,7 +873,7 @@ void getCartInfo_GBA() { skip_line(&myFile); // Skip over the CRC checksum - myFile.seekSet(myFile.curPosition() + 9); + myFile.seekCur(9); // Read 4 bytes into String, do it one at a time so byte order doesn't get mixed up sprintf(tempStr, "%c", myFile.read()); @@ -890,15 +890,15 @@ void getCartInfo_GBA() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); // Display database while (myFile.available()) { @@ -908,7 +908,7 @@ void getCartInfo_GBA() { get_line(gamename, &myFile, 96); // Skip over the CRC checksum - myFile.seekSet(myFile.curPosition() + 9); + myFile.seekCur(9); // Read 4 bytes into String, do it one at a time so byte order doesn't get mixed up sprintf(tempStr, "%c", myFile.read()); @@ -918,7 +918,7 @@ void getCartInfo_GBA() { } // Skip the , in the file - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read the next ascii character and subtract 48 to convert to decimal cartSize = myFile.read() - 48; @@ -930,7 +930,7 @@ void getCartInfo_GBA() { } // Skip the , in the file - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read save type into string get_line(saveTypeStr, &myFile, 14); @@ -980,15 +980,15 @@ void getCartInfo_GBA() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); break; } diff --git a/Cart_Reader/INTV.ino b/Cart_Reader/INTV.ino index 3fd7590..4acc8f9 100644 --- a/Cart_Reader/INTV.ino +++ b/Cart_Reader/INTV.ino @@ -812,15 +812,15 @@ void setCart_INTV() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); } // Display database @@ -838,7 +838,7 @@ void setCart_INTV() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read CRC32 of first 512 bytes sprintf(crc_search, "%c", myFile.read()); @@ -848,13 +848,13 @@ void setCart_INTV() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read mapper intvmapper = myFile.read() - 48; // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read rom size // Read the next ascii character and subtract 48 to convert to decimal @@ -868,13 +868,13 @@ void setCart_INTV() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read SRAM size byte sramSize __attribute__ ((unused)) = myFile.read() - 48; // Skip rest of line - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); // Skip every 3rd line skip_line(&myFile); @@ -916,15 +916,15 @@ void setCart_INTV() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); break; } diff --git a/Cart_Reader/N64.ino b/Cart_Reader/N64.ino index 2e1e51c..2456603 100644 --- a/Cart_Reader/N64.ino +++ b/Cart_Reader/N64.ino @@ -2051,7 +2051,7 @@ void printCartInfo_N64() { // Check if string is a match if (strcasecmp(tempStr1, crcStr) == 0) { // Skip the , in the file - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read 4 bytes into String, do it one at a time so byte order doesn't get mixed up sprintf(tempStr, "%c", myFile.read()); @@ -2071,7 +2071,7 @@ void printCartInfo_N64() { } // If no match, empty string, advance by 12 and try again else { - myFile.seekSet(myFile.curPosition() + 12); + myFile.seekCur(12); } } // Close the file: @@ -2106,7 +2106,7 @@ void getCartInfo_N64() { skip_line(&myFile); // Skip over the CRC32 checksum - myFile.seekSet(myFile.curPosition() + 9); + myFile.seekCur(9); // Read 8 bytes into String, do it one at a time so byte order doesn't get mixed up sprintf(tempStr, "%c", myFile.read()); @@ -2118,7 +2118,7 @@ void getCartInfo_N64() { // Check if string is a match if (strcmp(tempStr, checksumStr) == 0) { // Skip the , in the file - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read the next ascii character and subtract 48 to convert to decimal cartSize = myFile.read() - 48; @@ -2130,7 +2130,7 @@ void getCartInfo_N64() { } // Skip the , in the file - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read the next ascii character and subtract 48 to convert to decimal saveType = myFile.read() - 48; @@ -2141,7 +2141,7 @@ void getCartInfo_N64() { // If no match skip to next entry else { // skip rest of line - myFile.seekSet(myFile.curPosition() + 7); + myFile.seekCur(7); // skip third empty line skip_line(&myFile); } diff --git a/Cart_Reader/NES.ino b/Cart_Reader/NES.ino index da43208..301e3b7 100644 --- a/Cart_Reader/NES.ino +++ b/Cart_Reader/NES.ino @@ -559,7 +559,7 @@ boolean getMapping() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read CRC32 of first 512 bytes sprintf(crc_search, "%c", myFile.read()); @@ -569,7 +569,7 @@ boolean getMapping() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read iNES header get_line(iNES_STR, &myFile, 33); @@ -586,15 +586,15 @@ boolean getMapping() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); // Display database @@ -612,7 +612,7 @@ boolean getMapping() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read CRC32 of first 512 bytes sprintf(crc_search, "%c", myFile.read()); @@ -622,7 +622,7 @@ boolean getMapping() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read iNES header get_line(iNES_STR, &myFile, 33); @@ -756,15 +756,15 @@ boolean getMapping() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); break; } @@ -879,15 +879,15 @@ void selectMapping() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); } // Display database @@ -905,7 +905,7 @@ void selectMapping() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read CRC32 of first 512 bytes sprintf(crc_search, "%c", myFile.read()); @@ -915,7 +915,7 @@ void selectMapping() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read iNES header get_line(iNES_STR, &myFile, 33); @@ -1040,15 +1040,15 @@ void selectMapping() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); break; } diff --git a/Cart_Reader/SNES.ino b/Cart_Reader/SNES.ino index 5a0c8d8..c4383a7 100644 --- a/Cart_Reader/SNES.ino +++ b/Cart_Reader/SNES.ino @@ -847,7 +847,7 @@ void checkAltConf(char crcStr[9]) { skip_line(&myFile); // Skip over the CRC checksum - myFile.seekSet(myFile.curPosition() + 9); + myFile.seekCur(9); // Get internal ROM checksum as string for (byte j = 0; j < 4; j++) { @@ -862,7 +862,7 @@ void checkAltConf(char crcStr[9]) { display_Update(); // Skip the , in the file - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read the CRC32 of the SNES header out of database for (byte k = 0; k < 8; k++) { @@ -871,13 +871,13 @@ void checkAltConf(char crcStr[9]) { tempStr3[8] = '\0'; // Skip the , in the file - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read file size byte romSize2 = (myFile.read() - 48) * 10 + (myFile.read() - 48); // Skip the , in the file - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read number of banks byte numBanks2 = (myFile.read() - 48) * 100 + (myFile.read() - 48) * 10 + (myFile.read() - 48); @@ -911,7 +911,7 @@ void checkAltConf(char crcStr[9]) { // If no match go to next entry else { // skip rest of line - myFile.seekSet(myFile.curPosition() + 18); + myFile.seekCur(18); // skip third empty line skip_line(&myFile); } diff --git a/Cart_Reader/WSV.ino b/Cart_Reader/WSV.ino index c3a70a5..da409b6 100644 --- a/Cart_Reader/WSV.ino +++ b/Cart_Reader/WSV.ino @@ -413,15 +413,15 @@ void setCart_WSV() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); } // Display database @@ -439,7 +439,7 @@ void setCart_WSV() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read CRC32 of first 512 bytes sprintf(crc_search, "%c", myFile.read()); @@ -449,7 +449,7 @@ void setCart_WSV() { } // Skip over semicolon - myFile.seekSet(myFile.curPosition() + 1); + myFile.seekCur(1); // Read rom size // Read the next ascii character and subtract 48 to convert to decimal @@ -463,7 +463,7 @@ void setCart_WSV() { } // Skip rest of line - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); // Skip every 3rd line skip_line(&myFile); @@ -507,15 +507,15 @@ void setCart_WSV() { if (myFile.curPosition() == 0) { break; } else if (myFile.peek() == '\n') { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); break; } else { - myFile.seekSet(myFile.curPosition() - 1); + myFile.seekCur(-1); } } } if (myFile.curPosition() != 0) - myFile.seekSet(myFile.curPosition() + 2); + myFile.seekCur(2); break; } From 27baa2b1646e60270ea9576dcf826c4ea2858c27 Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Sun, 23 Oct 2022 02:54:59 +0000 Subject: [PATCH 16/24] All: Factorise code seeking a file back N lines This saves 890 bytes of program space. --- Cart_Reader/COLV.ino | 30 ++----------------- Cart_Reader/Cart_Reader.ino | 14 +++++++++ Cart_Reader/GBA.ino | 30 ++----------------- Cart_Reader/INTV.ino | 30 ++----------------- Cart_Reader/NES.ino | 60 +++---------------------------------- Cart_Reader/WSV.ino | 30 ++----------------- 6 files changed, 26 insertions(+), 168 deletions(-) diff --git a/Cart_Reader/COLV.ino b/Cart_Reader/COLV.ino index 4ea817e..070186b 100644 --- a/Cart_Reader/COLV.ino +++ b/Cart_Reader/COLV.ino @@ -394,20 +394,7 @@ void setCart_COL() { } // Rewind one line - for (byte count_newline = 0; count_newline < 2; count_newline++) { - while (1) { - if (myFile.curPosition() == 0) { - break; - } else if (myFile.peek() == '\n') { - myFile.seekCur(-1); - break; - } else { - myFile.seekCur(-1); - } - } - } - if (myFile.curPosition() != 0) - myFile.seekCur(2); + rewind_line(myFile); } // Display database @@ -485,20 +472,7 @@ void setCart_COL() { // Previous else if (b == 2) { - for (byte count_newline = 0; count_newline < 7; count_newline++) { - while (1) { - if (myFile.curPosition() == 0) { - break; - } else if (myFile.peek() == '\n') { - myFile.seekCur(-1); - break; - } else { - myFile.seekCur(-1); - } - } - } - if (myFile.curPosition() != 0) - myFile.seekCur(2); + rewind_line(myFile, 6); break; } diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index 6415943..d5dd208 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -616,6 +616,20 @@ void get_line(char* str_buf, FsFile* readfile, uint8_t maxi) { } } +void rewind_line(FsFile &readfile, byte count=1) { + uint32_t position = readfile.curPosition(); + count++; + for (byte count_newline = 0; count_newline < count; count_newline++) { + while (position--) { + readfile.seekCur(-1); + if (readfile.peek() == '\n') + break; + } + } + if (position) + readfile.seekCur(1); +} + // Calculate CRC32 if needed and compare it to CRC read from database boolean compareCRC(const char* database, char* crcString, boolean renamerom, int offset) { #ifdef nointro diff --git a/Cart_Reader/GBA.ino b/Cart_Reader/GBA.ino index 5b1054b..b010921 100644 --- a/Cart_Reader/GBA.ino +++ b/Cart_Reader/GBA.ino @@ -885,20 +885,7 @@ void getCartInfo_GBA() { // Check if string is a match if (strcmp(tempStr, cartID) == 0) { // Rewind to start of entry - for (byte count_newline = 0; count_newline < 2; count_newline++) { - while (1) { - if (myFile.curPosition() == 0) { - break; - } else if (myFile.peek() == '\n') { - myFile.seekCur(-1); - break; - } else { - myFile.seekCur(-1); - } - } - } - if (myFile.curPosition() != 0) - myFile.seekCur(2); + rewind_line(myFile); // Display database while (myFile.available()) { @@ -975,20 +962,7 @@ void getCartInfo_GBA() { // Previous else if (b == 2) { - for (byte count_newline = 0; count_newline < 7; count_newline++) { - while (1) { - if (myFile.curPosition() == 0) { - break; - } else if (myFile.peek() == '\n') { - myFile.seekCur(-1); - break; - } else { - myFile.seekCur(-1); - } - } - } - if (myFile.curPosition() != 0) - myFile.seekCur(2); + rewind_line(myFile, 6); break; } diff --git a/Cart_Reader/INTV.ino b/Cart_Reader/INTV.ino index 4acc8f9..549ff29 100644 --- a/Cart_Reader/INTV.ino +++ b/Cart_Reader/INTV.ino @@ -807,20 +807,7 @@ void setCart_INTV() { } // Rewind one line - for (byte count_newline = 0; count_newline < 2; count_newline++) { - while (1) { - if (myFile.curPosition() == 0) { - break; - } else if (myFile.peek() == '\n') { - myFile.seekCur(-1); - break; - } else { - myFile.seekCur(-1); - } - } - } - if (myFile.curPosition() != 0) - myFile.seekCur(2); + rewind_line(myFile); } // Display database @@ -911,20 +898,7 @@ void setCart_INTV() { // Previous else if (b == 2) { - for (byte count_newline = 0; count_newline < 7; count_newline++) { - while (1) { - if (myFile.curPosition() == 0) { - break; - } else if (myFile.peek() == '\n') { - myFile.seekCur(-1); - break; - } else { - myFile.seekCur(-1); - } - } - } - if (myFile.curPosition() != 0) - myFile.seekCur(2); + rewind_line(myFile, 6); break; } diff --git a/Cart_Reader/NES.ino b/Cart_Reader/NES.ino index 301e3b7..5a8b313 100644 --- a/Cart_Reader/NES.ino +++ b/Cart_Reader/NES.ino @@ -581,20 +581,7 @@ boolean getMapping() { if (((strcmp(crc_search, crcStr) == 0) || (strcmp(crc_search, crcStrMMC3) == 0)) && (strcmp(crc_search, "BD7BC39F") != 0)) { // Rewind to start of entry - for (byte count_newline = 0; count_newline < 4; count_newline++) { - while (1) { - if (myFile.curPosition() == 0) { - break; - } else if (myFile.peek() == '\n') { - myFile.seekCur(-1); - break; - } else { - myFile.seekCur(-1); - } - } - } - if (myFile.curPosition() != 0) - myFile.seekCur(2); + rewind_line(myFile, 3); // Display database @@ -751,20 +738,7 @@ boolean getMapping() { // Previous else if (b == 2) { - for (byte count_newline = 0; count_newline < 7; count_newline++) { - while (1) { - if (myFile.curPosition() == 0) { - break; - } else if (myFile.peek() == '\n') { - myFile.seekCur(-1); - break; - } else { - myFile.seekCur(-1); - } - } - } - if (myFile.curPosition() != 0) - myFile.seekCur(2); + rewind_line(myFile, 6); break; } @@ -874,20 +848,7 @@ void selectMapping() { } // Rewind one line - for (byte count_newline = 0; count_newline < 2; count_newline++) { - while (1) { - if (myFile.curPosition() == 0) { - break; - } else if (myFile.peek() == '\n') { - myFile.seekCur(-1); - break; - } else { - myFile.seekCur(-1); - } - } - } - if (myFile.curPosition() != 0) - myFile.seekCur(2); + rewind_line(myFile); } // Display database @@ -1035,20 +996,7 @@ void selectMapping() { // Previous else if (b == 2) { - for (byte count_newline = 0; count_newline < 7; count_newline++) { - while (1) { - if (myFile.curPosition() == 0) { - break; - } else if (myFile.peek() == '\n') { - myFile.seekCur(-1); - break; - } else { - myFile.seekCur(-1); - } - } - } - if (myFile.curPosition() != 0) - myFile.seekCur(2); + rewind_line(myFile, 6); break; } diff --git a/Cart_Reader/WSV.ino b/Cart_Reader/WSV.ino index da409b6..080b19a 100644 --- a/Cart_Reader/WSV.ino +++ b/Cart_Reader/WSV.ino @@ -408,20 +408,7 @@ void setCart_WSV() { } // Rewind one line - for (byte count_newline = 0; count_newline < 2; count_newline++) { - while (1) { - if (myFile.curPosition() == 0) { - break; - } else if (myFile.peek() == '\n') { - myFile.seekCur(-1); - break; - } else { - myFile.seekCur(-1); - } - } - } - if (myFile.curPosition() != 0) - myFile.seekCur(2); + rewind_line(myFile); } // Display database @@ -502,20 +489,7 @@ void setCart_WSV() { // Previous else if (b == 2) { - for (byte count_newline = 0; count_newline < 7; count_newline++) { - while (1) { - if (myFile.curPosition() == 0) { - break; - } else if (myFile.peek() == '\n') { - myFile.seekCur(-1); - break; - } else { - myFile.seekCur(-1); - } - } - } - if (myFile.curPosition() != 0) - myFile.seekCur(2); + rewind_line(myFile, 6); break; } From e4e09c7bf8e3d13484538f890908b68b6b20232d Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Sat, 22 Oct 2022 11:58:39 +0000 Subject: [PATCH 17/24] GBA.ino: Reduce gbaMenu size. Replace switch blocks which produce one output with const tables. Use functions instead of repeating code. Move common initial and final statements outside of blocks. Also, do not erase/flash second bank on dual-bank chips when the first one had failures. This saves about 520 bytes of code and increases ram use by 12 bytes. --- Cart_Reader/GBA.ino | 405 +++++++++++--------------------------------- 1 file changed, 95 insertions(+), 310 deletions(-) diff --git a/Cart_Reader/GBA.ino b/Cart_Reader/GBA.ino index b010921..27d5b6c 100644 --- a/Cart_Reader/GBA.ino +++ b/Cart_Reader/GBA.ino @@ -50,73 +50,18 @@ void gbaMenu() { switch (mainMenu) { case 0: // Read rom - switch (cartSize) { - case 0: - // create submenu with title and 4 options to choose from - unsigned char GBARomMenu; - // Copy menuOptions out of progmem - convertPgm(romOptionsGBA, 6); - GBARomMenu = question_box(F("Select ROM size"), menuOptions, 6, 0); + if (cartSize == 0) { + const byte romOptionsGBASize[] = {1, 2, 4, 8, 16, 32}; + // create submenu with title and 4 options to choose from + unsigned char GBARomMenu; + // Copy menuOptions out of progmem + convertPgm(romOptionsGBA, 6); + GBARomMenu = question_box(F("Select ROM size"), menuOptions, 6, 0); - // wait for user choice to come back from the question box menu - switch (GBARomMenu) { - case 0: - // 1MB - cartSize = 0x100000; - break; - - case 1: - // 2MB - cartSize = 0x200000; - break; - - case 2: - // 4MB - cartSize = 0x400000; - break; - - case 3: - // 8MB - cartSize = 0x800000; - break; - - case 4: - // 16MB - cartSize = 0x1000000; - break; - - case 5: - // 32MB - cartSize = 0x2000000; - break; - } - break; - - case 1: - // 1MB - cartSize = 0x100000; - break; - - case 4: - // 4MB - cartSize = 0x400000; - break; - - case 8: - // 8MB - cartSize = 0x800000; - break; - - case 16: - // 16MB - cartSize = 0x1000000; - break; - - case 32: - // 32MB - cartSize = 0x2000000; - break; + // wait for user choice to come back from the question box menu + cartSize = romOptionsGBASize[GBARomMenu]; } + cartSize *= 0x100000; display_Clear(); // Change working dir to root sd.chdir("/"); @@ -137,82 +82,30 @@ void gbaMenu() { case 1: // Read save - if (saveType == 0) { - // create submenu with title and 6 options to choose from - unsigned char GBASaveMenu; - // Copy menuOptions out of progmem - convertPgm(saveOptionsGBA, 6); - GBASaveMenu = question_box(F("Select save type"), menuOptions, 6, 0); - - // wait for user choice to come back from the question box menu - switch (GBASaveMenu) { - case 0: - // 4K EEPROM - saveType = 1; - break; - - case 1: - // 64K EEPROM - saveType = 2; - break; - - case 2: - // 256K SRAM/FRAM - saveType = 3; - break; - - case 3: - // 512K SRAM/FRAM - saveType = 6; - break; - - case 4: - // 512K FLASH - saveType = 4; - break; - - case 5: - // 1M FLASH - saveType = 5; - break; - } - } - switch (saveType) { + display_Clear(); + sd.chdir("/"); + switch (getSaveType()) { case 1: - display_Clear(); - sd.chdir("/"); // 4K EEPROM readEeprom_GBA(4); - setROM_GBA(); break; case 2: - display_Clear(); - sd.chdir("/"); // 64K EEPROM readEeprom_GBA(64); - setROM_GBA(); break; case 3: - display_Clear(); - sd.chdir("/"); // 256K SRAM/FRAM readSRAM_GBA(1, 32768, 0); - setROM_GBA(); break; case 4: - display_Clear(); - sd.chdir("/"); // 512K FLASH readFLASH_GBA(1, 65536, 0); - setROM_GBA(); break; case 5: - display_Clear(); - sd.chdir("/"); // 1M FLASH (divided into two banks) switchBank_GBA(0x0); setROM_GBA(); @@ -220,17 +113,14 @@ void gbaMenu() { switchBank_GBA(0x1); setROM_GBA(); readFLASH_GBA(0, 65536, 65536); - setROM_GBA(); break; case 6: - display_Clear(); - sd.chdir("/"); // 512K SRAM/FRAM readSRAM_GBA(1, 65536, 0); - setROM_GBA(); break; } + setROM_GBA(); println_Msg(F("")); // Prints string out of the common strings array either with or without newline print_STR(press_button_STR, 1); @@ -240,132 +130,45 @@ void gbaMenu() { case 2: // Write save - if (saveType == 0) { - // create submenu with title and 6 options to choose from - unsigned char GBASavesMenu; - // Copy menuOptions out of progmem - convertPgm(saveOptionsGBA, 6); - GBASavesMenu = question_box(F("Select save type"), menuOptions, 6, 0); - // wait for user choice to come back from the question box menu - switch (GBASavesMenu) { - case 0: - // 4K EEPROM - saveType = 1; - break; - - case 1: - // 64K EEPROM - saveType = 2; - break; - - case 2: - // 256K SRAM/FRAM - saveType = 3; - break; - - case 3: - // 512K SRAM/FRAM - saveType = 6; - break; - - case 4: - // 512K FLASH - saveType = 4; - break; - - case 5: - // 1M FLASH - saveType = 5; - break; - } - } - - switch (saveType) { + display_Clear(); + sd.chdir("/"); + switch (getSaveType()) { case 1: - display_Clear(); - sd.chdir("/"); // 4K EEPROM writeEeprom_GBA(4); - writeErrors = verifyEEP_GBA(4); - if (writeErrors == 0) { - println_Msg(F("Verified OK")); - display_Update(); - } else { - print_STR(error_STR, 0); - print_Msg(writeErrors); - print_STR(_bytes_STR, 1); - print_Error(did_not_verify_STR, false); - } + verifyEEP_GBA(4); setROM_GBA(); break; case 2: - display_Clear(); - sd.chdir("/"); // 64K EEPROM writeEeprom_GBA(64); - writeErrors = verifyEEP_GBA(64); - if (writeErrors == 0) { - println_Msg(F("Verified OK")); - display_Update(); - } else { - print_STR(error_STR, 0); - print_Msg(writeErrors); - print_STR(_bytes_STR, 1); - print_Error(did_not_verify_STR, false); - } - setROM_GBA(); + verifyEEP_GBA(64); break; case 3: - display_Clear(); - // Change working dir to root - sd.chdir("/"); // 256K SRAM/FRAM writeSRAM_GBA(1, 32768, 0); - writeErrors = verifySRAM_GBA(32768, 0); - if (writeErrors == 0) { - println_Msg(F("Verified OK")); - display_Update(); - } else { - print_STR(error_STR, 0); - print_Msg(writeErrors); - print_STR(_bytes_STR, 1); - print_Error(did_not_verify_STR, false); - } - setROM_GBA(); + verifySRAM_GBA(32768, 0); break; case 4: - display_Clear(); - sd.chdir("/"); // 512K FLASH idFlash_GBA(); resetFLASH_GBA(); - print_Msg(F("FLASH ID: ")); - println_Msg(flashid_str); - println_Msg(F("")); - println_Msg(F("FLASH Type: ")); if (flashid == 0x1F3D) { - println_Msg(F("Atmel AT29LV512")); + printFlashTypeAndWait(F("Atmel AT29LV512")); } else if (flashid == 0xBFD4) { - println_Msg(F("SST 39VF512")); + printFlashTypeAndWait(F("SST 39VF512")); } else if (flashid == 0xC21C) { - println_Msg(F("Macronix MX29L512")); + printFlashTypeAndWait(F("Macronix MX29L512")); } else if (flashid == 0x321B) { - println_Msg(F("Panasonic MN63F805MNP")); + printFlashTypeAndWait(F("Panasonic MN63F805MNP")); } else { - println_Msg(F("Unknown")); + printFlashTypeAndWait(F("Unknown")); //print_Error(F(""), true); } - println_Msg(F("")); - // Prints string out of the common strings array either with or without newline - print_STR(press_button_STR, 1); - display_Update(); - wait(); - display_Clear(); - display_Update(); if (flashid == 0x1F3D) { // Atmel writeFLASH_GBA(1, 65536, 0, 1); @@ -375,80 +178,44 @@ void gbaMenu() { if (blankcheckFLASH_GBA(65536)) { writeFLASH_GBA(1, 65536, 0, 0); verifyFLASH_GBA(65536, 0); - } else { - print_Error(F("Erase failed"), false); } } - setROM_GBA(); break; case 5: - display_Clear(); - sd.chdir("/"); // 1M FLASH idFlash_GBA(); resetFLASH_GBA(); - print_Msg(F("Flashrom ID: ")); - println_Msg(flashid_str); - println_Msg(F("")); - println_Msg(F("Flashrom Type: ")); if (flashid == 0xC209) { - println_Msg(F("Macronix MX29L010")); + printFlashTypeAndWait(F("Macronix MX29L010")); } else if (flashid == 0x6213) { - println_Msg(F("SANYO LE26FV10N1TS")); + printFlashTypeAndWait(F("SANYO LE26FV10N1TS")); } else { - println_Msg(F("Unknown")); + printFlashTypeAndWait(F("Unknown")); //print_Error(F(""), true); } - println_Msg(F("")); - // Prints string out of the common strings array either with or without newline - print_STR(press_button_STR, 1); - display_Update(); - wait(); - display_Clear(); - display_Update(); eraseFLASH_GBA(); // 131072 bytes are divided into two 65536 byte banks - switchBank_GBA(0x0); - setROM_GBA(); - if (blankcheckFLASH_GBA(65536)) { - writeFLASH_GBA(1, 65536, 0, 0); - verifyFLASH_GBA(65536, 0); - } else { - print_Error(F("Erase failed"), false); + for (byte bank = 0; bank < 2; bank++) { + switchBank_GBA(bank); + setROM_GBA(); + if (!blankcheckFLASH_GBA(65536)) + break; + writeFLASH_GBA(!bank, 65536, bank ? 65536 : 0, 0); + if (verifyFLASH_GBA(65536, bank ? 65536 : 0)) + break; } - switchBank_GBA(0x1); - setROM_GBA(); - if (blankcheckFLASH_GBA(65536)) { - writeFLASH_GBA(0, 65536, 65536, 0); - verifyFLASH_GBA(65536, 65536); - } else { - print_Error(F("Erase failed"), false); - } - setROM_GBA(); break; case 6: - display_Clear(); - // Change working dir to root - sd.chdir("/"); // 512K SRAM/FRAM writeSRAM_GBA(1, 65536, 0); - writeErrors = verifySRAM_GBA(65536, 0); - if (writeErrors == 0) { - println_Msg(F("Verified OK")); - display_Update(); - } else { - print_STR(error_STR, 0); - print_Msg(writeErrors); - print_STR(_bytes_STR, 1); - print_Error(did_not_verify_STR, false); - } - setROM_GBA(); + verifySRAM_GBA(65536, 0); break; } + setROM_GBA(); println_Msg(F("")); // Prints string out of the common strings array either with or without newline print_STR(press_button_STR, 1); @@ -458,44 +225,8 @@ void gbaMenu() { case 3: display_Clear(); - // create submenu with title and 7 options to choose from - unsigned char GBASaveMenu; - // Copy menuOptions out of progmem - convertPgm(saveOptionsGBA, 6); - GBASaveMenu = question_box(F("Select save type"), menuOptions, 6, 0); - - // wait for user choice to come back from the question box menu - switch (GBASaveMenu) { - case 0: - // 4K EEPROM - saveType = 1; - break; - - case 1: - // 64K EEPROM - saveType = 2; - break; - - case 2: - // 256K SRAM/FRAM - saveType = 3; - break; - - case 3: - // 512K SRAM/FRAM - saveType = 6; - break; - - case 4: - // 512K FLASH - saveType = 4; - break; - - case 5: - // 1M FLASH - saveType = 5; - break; - } + saveType = 0; + saveType = getSaveType(); display_Clear(); break; @@ -580,6 +311,35 @@ void setup_GBA() { /****************************************** Low level functions *****************************************/ +static byte getSaveType() { + if (saveType == 0) { + const byte saveOptionsGBAType[] = {1, 2, 3, 6, 4, 5}; + // create submenu with title and 6 options to choose from + unsigned char GBASaveMenu; + // Copy menuOptions out of progmem + convertPgm(saveOptionsGBA, 6); + GBASaveMenu = question_box(F("Select save type"), menuOptions, 6, 0); + // wait for user choice to come back from the question box menu + saveType = saveOptionsGBAType[GBASaveMenu]; + } + return saveType; +} + +static void printFlashTypeAndWait(const __FlashStringHelper* caption) { + print_Msg(F("FLASH ID: ")); + println_Msg(flashid_str); + println_Msg(F("")); + println_Msg(F("FLASH Type: ")); + println_Msg(caption); + println_Msg(F("")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); + display_Update(); + wait(); + display_Clear(); + display_Update(); +} + void setROM_GBA() { // CS_SRAM(PH0) DDRH |= (1 << 0); @@ -1310,6 +1070,17 @@ unsigned long verifySRAM_GBA(unsigned long sramSize, uint32_t pos) { } // Close the file: myFile.close(); + + if (writeErrors == 0) { + println_Msg(F("Verified OK")); + display_Update(); + } else { + print_STR(error_STR, 0); + print_Msg(writeErrors); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); + } + return writeErrors; } else { print_Error(F("Can't open file"), false); @@ -1711,6 +1482,7 @@ boolean blankcheckFLASH_GBA(unsigned long flashSize) { // Check buffer for (unsigned long currByte = 0; currByte < 512; currByte++) { if (sdBuffer[currByte] != 0xFF) { + print_Error(F("Erase failed"), false); currByte = 512; currAddress = flashSize; blank = 0; @@ -1911,7 +1683,7 @@ void writeFLASH_GBA(boolean browseFile, unsigned long flashSize, uint32_t pos, b } // Check if the Flashrom was written without any error -void verifyFLASH_GBA(unsigned long flashSize, uint32_t pos) { +unsigned long verifyFLASH_GBA(unsigned long flashSize, uint32_t pos) { // Output a HIGH signal on CS_ROM(PH3) WE_FLASH(PH5) PORTH |= (1 << 3) | (1 << 5); @@ -1961,6 +1733,8 @@ void verifyFLASH_GBA(unsigned long flashSize, uint32_t pos) { print_Msg(wrError); print_Error(F(" Errors"), false); } + + return wrError; } /****************************************** @@ -2289,6 +2063,17 @@ unsigned long verifyEEP_GBA(word eepSize) { } } myFile.close(); + + if (wrError == 0) { + println_Msg(F("Verified OK")); + display_Update(); + } else { + print_STR(error_STR, 0); + print_Msg(wrError); + print_STR(_bytes_STR, 1); + print_Error(did_not_verify_STR, false); + } + return wrError; } From 337ef94b07a65818aa6de0345e6da27c4b769d47 Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Sun, 23 Oct 2022 10:01:09 +0000 Subject: [PATCH 18/24] NES.ino: Factorise code. Mainly, this removes a lot of the logic from selectMapping by reusing the copy already present in getMapping. As a result, selectMapping is not expected to be accessed from outside this module anymore. Also, this factorises several smaller chunks of code found throughout the module. Also, get rid of a few easy globals along the way. Also, move a bit more of NES-specific initialisation and menu display to the NES.ino module. This saves about 1490 bytes of code. --- Cart_Reader/Cart_Reader.ino | 10 - Cart_Reader/NES.ino | 780 ++++++++++++------------------------ 2 files changed, 249 insertions(+), 541 deletions(-) diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index d5dd208..ac643d6 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -906,11 +906,6 @@ void mainMenu() { display_Clear(); display_Update(); setup_NES(); -#ifdef nointro - if (getMapping() == 0) { - selectMapping(); - } -#endif checkStatus_NES(); nesMenu(); break; @@ -1170,11 +1165,6 @@ void consoleMenu() { display_Clear(); display_Update(); setup_NES(); -#ifdef nointro - if (getMapping() == 0) { - selectMapping(); - } -#endif checkStatus_NES(); nesMenu(); break; diff --git a/Cart_Reader/NES.ino b/Cart_Reader/NES.ino index 5a8b313..02f6cd9 100644 --- a/Cart_Reader/NES.ino +++ b/Cart_Reader/NES.ino @@ -161,7 +161,6 @@ static const byte PROGMEM mapsize[] = { *****************************************/ // Mapper byte mapcount = (sizeof(mapsize) / sizeof(mapsize[0])) / 7; -boolean mapfound = false; byte mapselect; int PRG[] = { 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 }; @@ -213,9 +212,6 @@ byte newchrsize; byte ramsize; byte newramsize; -// Button -int b = 0; - /****************************************** Menus *****************************************/ @@ -242,9 +238,11 @@ static const char* const menuOptionsNESChips[] PROGMEM = { nesChipsMenuItem1, ne // NES start menu void nesMenu() { + unsigned char answer; + // create menu with title "NES CART READER" and 7 options to choose from convertPgm(menuOptionsNES, 7); - unsigned char answer = question_box(F("NES CART READER"), menuOptions, 7, 0); + answer = question_box(F("NES CART READER"), menuOptions, 7, 0); // wait for user choice to come back from the question box menu switch (answer) { @@ -308,11 +306,7 @@ void nesMenu() { // Change Mapper case 4: - romName[0] = 'C'; - romName[1] = 'A'; - romName[2] = 'R'; - romName[3] = 'T'; - romName[4] = '\0'; + setDefaultRomName(); setMapper(); checkMapperSize(); setPRGSize(); @@ -460,6 +454,15 @@ uint32_t uppow2(uint32_t n) { return n; } +struct database_entry { + char filename[128]; + char crc_str[8 + 1 + 8 + 1 + 32 + 1]; + uint32_t crc; + char *crc512_str; + uint32_t crc512; + char *iNES_str; +}; + void printPRG(unsigned long myOffset) { display_Clear(); print_Msg(F("Printing PRG at ")); @@ -482,336 +485,245 @@ void printPRG(unsigned long myOffset) { display_Update(); } -boolean getMapping() { - display_Clear(); - println_Msg(F("Searching database")); - display_Update(); +void setDefaultRomName() { + romName[0] = 'C'; + romName[1] = 'A'; + romName[2] = 'R'; + romName[3] = 'T'; + romName[4] = '\0'; +} - // Read first 512 bytes of PRG ROM - for (int x = 0; x < 512; x++) { - sdBuffer[x] = read_prg_byte(0x8000 + x); +void setRomnameFromString(const char *input) { + byte myLength = 0; + for (byte i = 0; i < 20 && myLength < 15; i++) { + // Stop at first "(" to remove "(Country)" + if (input[i] == '(') { + break; + } + if ( + (input[i] >= '0' && input[i] <= '9') || + (input[i] >= 'A' && input[i] <= 'Z') || + (input[i] >= 'a' && input[i] <= 'z') + ) { + romName[myLength++] = input[i]; + } } - // Calculate CRC32 + // If name consists out of all japanese characters use CART as name + if (myLength == 0) { + setDefaultRomName(); + } +} + +void getMapping() { + FsFile database; uint32_t oldcrc32 = 0xFFFFFFFF; - for (int c = 0; c < 512; c++) { - oldcrc32 = updateCRC(sdBuffer[c], oldcrc32); - } + uint32_t oldcrc32MMC3 = 0xFFFFFFFF; char crcStr[9]; - char tempStr2[2]; - char iNES_STR[33]; - sprintf(crcStr, "%08lX", ~oldcrc32); - //MMC3 maps the last 8KB block of PRG ROM to 0xE000 while 0x8000 can contain random data after bootup - char crcStrMMC3[9]; - // Read first 512 bytes of last block of PRG ROM - for (int x = 0; x < 512; x++) { - sdBuffer[x] = read_prg_byte(0xE000 + x); + display_Clear(); + + sd.chdir(); + if (!database.open("nes.txt", O_READ)) { + print_Error(F("Database file not found"), true); + // never reached } - // Calculate CRC32 - oldcrc32 = 0xFFFFFFFF; + + // Read first 512 bytes of first and last block of PRG ROM and compute CRC32 + // MMC3 maps the last 8KB block of PRG ROM to 0xE000 while 0x8000 can contain random data after bootup for (int c = 0; c < 512; c++) { - oldcrc32 = updateCRC(sdBuffer[c], oldcrc32); + oldcrc32 = updateCRC(read_prg_byte(0x8000 + c), oldcrc32); + oldcrc32MMC3 = updateCRC(read_prg_byte(0xE000 + c), oldcrc32MMC3); } - sprintf(crcStrMMC3, "%08lX", ~oldcrc32); - - print_Msg(F("for ")); - print_Msg(crcStr); - if (strcmp(crcStrMMC3, crcStr) != 0) { - print_Msg(F(" or ")); - print_Msg(crcStrMMC3); - } - println_Msg(F("...")); - display_Update(); + oldcrc32 = ~oldcrc32; + oldcrc32MMC3 = ~oldcrc32MMC3; // Filter out all 0xFF checksums at 0x8000 and 0xE000 - if ((strcmp(crcStr, "BD7BC39F") == 0) && (strcmp(crcStrMMC3, "BD7BC39F") == 0)) { + if (oldcrc32 == 0xBD7BC39F && oldcrc32MMC3 == 0xBD7BC39F) { delay(200); println_Msg(F("")); println_Msg(F("No data found.")); println_Msg(F("Using manual selection")); display_Update(); delay(500); - romName[0] = 'C'; - romName[1] = 'A'; - romName[2] = 'R'; - romName[3] = 'T'; - romName[4] = '\0'; - return 0; + setDefaultRomName(); + selectMapping(database); } else { - //Search for CRC32 in file - char gamename[100]; - char crc_search[9]; + println_Msg(F("Searching database")); + print_Msg(F("for ")); + sprintf(crcStr, "%08lX", oldcrc32); + print_Msg(crcStr); + if (oldcrc32 != oldcrc32MMC3) { + char crcStrMMC3[9]; + print_Msg(F(" or ")); + sprintf(crcStrMMC3, "%08lX", oldcrc32MMC3); + print_Msg(crcStrMMC3); + } + println_Msg(F("...")); + display_Update(); + while (database.available()) { + struct database_entry entry; - //go to root - sd.chdir(); - if (myFile.open("nes.txt", O_READ)) { - //Search for same CRC in list - while (myFile.available()) { - // Read game name - get_line(gamename, &myFile, 96); - - // Read CRC32 checksum - sprintf(checksumStr, "%c", myFile.read()); - for (byte i = 0; i < 7; i++) { - sprintf(tempStr2, "%c", myFile.read()); - strcat(checksumStr, tempStr2); - } - - // Skip over semicolon - myFile.seekCur(1); - - // Read CRC32 of first 512 bytes - sprintf(crc_search, "%c", myFile.read()); - for (byte i = 0; i < 7; i++) { - sprintf(tempStr2, "%c", myFile.read()); - strcat(crc_search, tempStr2); - } - - // Skip over semicolon - myFile.seekCur(1); - - // Read iNES header - get_line(iNES_STR, &myFile, 33); - - //Skip every 3rd line - skip_line(&myFile); - - //if checksum search was successful set mapper and end search, also filter out 0xFF checksum - if (((strcmp(crc_search, crcStr) == 0) || (strcmp(crc_search, crcStrMMC3) == 0)) && (strcmp(crc_search, "BD7BC39F") != 0)) { - - // Rewind to start of entry - rewind_line(myFile, 3); - - - // Display database - while (myFile.available()) { - display_Clear(); - - // Read game name - get_line(gamename, &myFile, 96); - - // Read CRC32 checksum - sprintf(checksumStr, "%c", myFile.read()); - for (byte i = 0; i < 7; i++) { - sprintf(tempStr2, "%c", myFile.read()); - strcat(checksumStr, tempStr2); - } - - // Skip over semicolon - myFile.seekCur(1); - - // Read CRC32 of first 512 bytes - sprintf(crc_search, "%c", myFile.read()); - for (byte i = 0; i < 7; i++) { - sprintf(tempStr2, "%c", myFile.read()); - strcat(crc_search, tempStr2); - } - - // Skip over semicolon - myFile.seekCur(1); - - // Read iNES header - get_line(iNES_STR, &myFile, 33); - - // Skip every 3rd line - skip_line(&myFile); - - // Convert "4E4553" to (0x4E, 0x45, 0x53) - unsigned int iNES_BUF; - for (byte j = 0; j < 16; j++) { - sscanf(iNES_STR + j * 2, "%2X", &iNES_BUF); - iNES_HEADER[j] = iNES_BUF; - } - - // Convert iNES garbage to useful info (thx to fceux) - mapper = (iNES_HEADER[6] >> 4); - mapper |= (iNES_HEADER[7] & 0xF0); - mapper |= ((iNES_HEADER[8] & 0x0F) << 8); - - // PRG size - if ((iNES_HEADER[9] & 0x0F) != 0x0F) { - // simple notation - prgsize = (iNES_HEADER[4] | ((iNES_HEADER[9] & 0x0F) << 8)); //*16 - } else { - // exponent-multiplier notation - prgsize = (((1 << (iNES_HEADER[4] >> 2)) * ((iNES_HEADER[4] & 0b11) * 2 + 1)) >> 14); //*16 - } - if (prgsize != 0) - prgsize = (int(log(prgsize) / log(2))); - - // CHR size - if ((iNES_HEADER[9] & 0xF0) != 0xF0) { - // simple notation - chrsize = (uppow2(iNES_HEADER[5] | ((iNES_HEADER[9] & 0xF0) << 4))) * 2; //*4 - } else { - chrsize = (((1 << (iNES_HEADER[5] >> 2)) * ((iNES_HEADER[5] & 0b11) * 2 + 1)) >> 13) * 2; //*4 - } - if (chrsize != 0) - chrsize = (int(log(chrsize) / log(2))); - - // RAM size - ramsize = ((iNES_HEADER[10] & 0xF0) ? (64 << ((iNES_HEADER[10] & 0xF0) >> 4)) : 0) / 4096; //*4 - if (ramsize != 0) - ramsize = (int(log(ramsize) / log(2))); - - prg = (int_pow(2, prgsize)) * 16; - if (chrsize == 0) - chr = 0; // 0K - else - chr = (int_pow(2, chrsize)) * 4; - if (ramsize == 0) - ram = 0; // 0K - else if (mapper == 82) - ram = 5; // 5K - else - ram = (int_pow(2, ramsize)) * 4; - - // Mapper Variants - // Identify variant for use across multiple functions - if (mapper == 4) { // Check for MMC6/MMC3 - checkMMC6(); - if (mmc6) - ram = 1; // 1K - } - -#ifdef global_log - // Disable log to prevent unnecessary logging - println_Log(F("Get Mapping from List")); - dont_log = true; -#endif - println_Msg(gamename); - print_Msg(F("MAPPER: ")); - println_Msg(mapper); - print_Msg(F("PRG SIZE: ")); - print_Msg(prg); - println_Msg(F("K")); - print_Msg(F("CHR SIZE: ")); - print_Msg(chr); - println_Msg(F("K")); - print_Msg(F("RAM SIZE: ")); - if (mapper == 0) { - print_Msg(ram / 4); - println_Msg(F("K")); - } else if ((mapper == 16) || (mapper == 80) || (mapper == 159)) { - if (mapper == 16) - print_Msg(ram * 32); - else - print_Msg(ram * 16); - println_Msg(F("B")); - } else if (mapper == 19) { - if (ramsize == 2) - println_Msg(F("128B")); - else { - print_Msg(ram); - println_Msg(F("K")); - } - } else { - print_Msg(ram); - println_Msg(F("K")); - } -#if defined(enable_OLED) - print_STR(press_to_change_STR, 1); - print_STR(right_to_select_STR, 1); -#elif defined(enable_LCD) - print_STR(rotate_to_change_STR, 1); - print_STR(press_to_select_STR, 1); -#elif defined(SERIAL_MONITOR) - println_Msg(F("U/D to Change")); - println_Msg(F("Space to Select")); -#endif - display_Update(); - -#ifdef global_log - // Enable log again - dont_log = false; -#endif - int b = 0; - while (1) { - // Check button input - b = checkButton(); - - // Next - if (b == 1) { - break; - } - - // Previous - else if (b == 2) { - rewind_line(myFile, 6); - break; - } - - // Selection - else if (b == 3) { - // Get name - byte myLength = 0; - for (unsigned int i = 0; i < 20; i++) { - // Stop at first "(" to remove "(Country)" - if (char(gamename[i]) == 40) { - break; - } - if (((char(gamename[i]) >= 48 && char(gamename[i]) <= 57) || (char(gamename[i]) >= 65 && char(gamename[i]) <= 90) || (char(gamename[i]) >= 97 && char(gamename[i]) <= 122)) && (myLength < 15)) { - romName[myLength] = char(gamename[i]); - myLength++; - } - } - - // If name consists out of all japanese characters use CART as name - if (myLength == 0) { - romName[0] = 'C'; - romName[1] = 'A'; - romName[2] = 'R'; - romName[3] = 'T'; - romName[4] = '\0'; - } - - // Save Mapper - EEPROM_writeAnything(7, mapper); - EEPROM_writeAnything(8, prgsize); - EEPROM_writeAnything(9, chrsize); - EEPROM_writeAnything(10, ramsize); - myFile.close(); - return 1; - break; - } - } - } - } + readDatabaseEntry(database, &entry); + //if checksum search was successful set mapper and end search, also filter out 0xFF checksum + if ( + entry.crc512 != 0xBD7BC39F && ( + entry.crc512 == oldcrc32 || entry.crc512 == oldcrc32MMC3 + ) + ) { + // Rewind to start of entry + rewind_line(database, 3); + break; } + } + if (!database.available()) { // File searched until end but nothing found println_Msg(F("")); println_Msg(F("CRC not found in database")); println_Msg(F("Using manual selection")); display_Update(); - delay(1000); + delay(500); // Print debug printPRG(0x8000); printPRG(0xE000); // Change ROM name to CART - romName[0] = 'C'; - romName[1] = 'A'; - romName[2] = 'R'; - romName[3] = 'T'; - romName[4] = '\0'; - return 0; - } else { - println_Msg(F("Database file not found")); - return 0; + setDefaultRomName(); + selectMapping(database); } } + + // Display database + while (database.available()) { + byte iNES[16]; + byte *output; + char *input; + + struct database_entry entry; + + display_Clear(); + readDatabaseEntry(database, &entry); + + input = entry.iNES_str; + output = iNES; + for (byte i = 0; i < sizeof(iNES); i++) { + unsigned int buf; + + sscanf(input, "%2X", &buf); + *(output++) = buf; + input += 2; + } + + mapper = (iNES[6] >> 4) | (iNES[7] & 0xF0) | (iNES[8] & 0x0F); + + if ((iNES[9] & 0x0F) != 0x0F) { + // simple notation + prgsize = (iNES[4] | ((iNES[9] & 0x0F) << 8)); //*16 + } else { + // exponent-multiplier notation + prgsize = (((1 << (iNES[4] >> 2)) * ((iNES[4] & 0b11) * 2 + 1)) >> 14); //*16 + } + if (prgsize != 0) + prgsize = (int(log(prgsize) / log(2))); + + if ((iNES[9] & 0xF0) != 0xF0) { + // simple notation + chrsize = (uppow2(iNES[5] | ((iNES[9] & 0xF0) << 4))) * 2; //*4 + } else { + // exponent-multiplier notation + chrsize = (((1 << (iNES[5] >> 2)) * ((iNES[5] & 0b11) * 2 + 1)) >> 13) * 2; //*4 + } + if (chrsize != 0) + chrsize = (int(log(chrsize) / log(2))); + + ramsize = ((iNES[10] & 0xF0) ? (64 << ((iNES[10] & 0xF0) >> 4)) : 0) / 4096; //*4 + if (ramsize != 0) + ramsize = (int(log(ramsize) / log(2))); + + prg = (int_pow(2, prgsize)) * 16; + if (chrsize == 0) + chr = 0; // 0K + else + chr = (int_pow(2, chrsize)) * 4; + if (ramsize == 0) + ram = 0; // 0K + else if (mapper == 82) + ram = 5; // 5K + else + ram = (int_pow(2, ramsize)) * 4; + + // Mapper Variants + // Identify variant for use across multiple functions + if (mapper == 4) { // Check for MMC6/MMC3 + checkMMC6(); + if (mmc6) + ram = 1; // 1K + } + +#ifdef global_log + // Disable log to prevent unnecessary logging + println_Log(F("Get Mapping from List")); + dont_log = true; +#endif + println_Msg(entry.filename); + printNESSettings(); +#if defined(enable_OLED) + print_STR(press_to_change_STR, 1); + print_STR(right_to_select_STR, 1); +#elif defined(enable_LCD) + print_STR(rotate_to_change_STR, 1); + print_STR(press_to_select_STR, 1); +#elif defined(SERIAL_MONITOR) + println_Msg(F("U/D to Change")); + println_Msg(F("Space to Select")); +#endif + display_Update(); + +#ifdef global_log + // Enable log again + dont_log = false; +#endif + int b = 0; + do { + b = checkButton(); + } while (b == 0); + + if (b == 1) + // 1: Next record + continue; + if (b == 2) { + // 2: Previous record + rewind_line(database, 6); + continue; + } + // anything else: select current record + setRomnameFromString(entry.filename); + // Save Mapper + EEPROM_writeAnything(7, mapper); + EEPROM_writeAnything(8, prgsize); + EEPROM_writeAnything(9, chrsize); + EEPROM_writeAnything(10, ramsize); + break; + } + database.close(); } -void selectMapping() { - char gamename[100]; - char tempStr2[2]; - char iNES_STR[33]; - char crc_search[9]; +static void readDatabaseEntry(FsFile &database, struct database_entry *entry) { + get_line(entry->filename, &database, sizeof(entry->filename)); + get_line(entry->crc_str, &database, sizeof(entry->crc_str)); + skip_line(&database); - //go to root - sd.chdir(); + entry->crc_str[8] = 0; + entry->crc512_str = &entry->crc_str[8 + 1]; + entry->crc512_str[8] = 0; + entry->iNES_str = &entry->crc_str[8 + 1 + 8 + 1]; + memcpy(iNES_HEADER, entry->iNES_str, sizeof(iNES_HEADER)); + entry->crc = strtoul(entry->crc_str, NULL, 16); + entry->crc512 = strtoul(entry->crc512_str, NULL, 16); +} + +static void selectMapping(FsFile &database) { // Select starting letter byte myLetter = starting_letter(); @@ -823,224 +735,26 @@ void selectMapping() { setCHRSize(); setRAMSize(); } else { - // Open database - if (myFile.open("nes.txt", O_READ)) { - #ifdef global_log - // Disable log to prevent unnecessary logging - println_Log(F("Select Mapping from List")); - dont_log = true; + // Disable log to prevent unnecessary logging + println_Log(F("Select Mapping from List")); + dont_log = true; #endif - - // Skip ahead to selected starting letter - if ((myLetter > 0) && (myLetter <= 26)) { - while (myFile.available()) { - // Read current name - get_line(gamename, &myFile, 96); - - // Compare selected letter with first letter of current name until match - while (gamename[0] != 64 + myLetter) { - skip_line(&myFile); - skip_line(&myFile); - get_line(gamename, &myFile, 96); - } - break; - } - - // Rewind one line - rewind_line(myFile); - } - - // Display database - while (myFile.available()) { - display_Clear(); - - // Read game name - get_line(gamename, &myFile, 96); - - // Read CRC32 checksum - sprintf(checksumStr, "%c", myFile.read()); - for (byte i = 0; i < 7; i++) { - sprintf(tempStr2, "%c", myFile.read()); - strcat(checksumStr, tempStr2); - } - - // Skip over semicolon - myFile.seekCur(1); - - // Read CRC32 of first 512 bytes - sprintf(crc_search, "%c", myFile.read()); - for (byte i = 0; i < 7; i++) { - sprintf(tempStr2, "%c", myFile.read()); - strcat(crc_search, tempStr2); - } - - // Skip over semicolon - myFile.seekCur(1); - - // Read iNES header - get_line(iNES_STR, &myFile, 33); - - // Skip every 3rd line - skip_line(&myFile); - - // Convert "4E4553" to (0x4E, 0x45, 0x53) - unsigned int iNES_BUF; - for (byte j = 0; j < 16; j++) { - sscanf(iNES_STR + j * 2, "%2X", &iNES_BUF); - iNES_HEADER[j] = iNES_BUF; - } - - // Convert iNES garbage to useful info (thx to fceux) - mapper = (iNES_HEADER[6] >> 4); - mapper |= (iNES_HEADER[7] & 0xF0); - mapper |= ((iNES_HEADER[8] & 0x0F) << 8); - - // PRG size - if ((iNES_HEADER[9] & 0x0F) != 0x0F) { - // simple notation - prgsize = (iNES_HEADER[4] | ((iNES_HEADER[9] & 0x0F) << 8)); //*16 - } else { - // exponent-multiplier notation - prgsize = (((1 << (iNES_HEADER[4] >> 2)) * ((iNES_HEADER[4] & 0b11) * 2 + 1)) >> 14); //*16 - } - if (prgsize != 0) - prgsize = (int(log(prgsize) / log(2))); - - // CHR size - if ((iNES_HEADER[9] & 0xF0) != 0xF0) { - // simple notation - chrsize = (uppow2(iNES_HEADER[5] | ((iNES_HEADER[9] & 0xF0) << 4))) * 2; //*4 - } else { - chrsize = (((1 << (iNES_HEADER[5] >> 2)) * ((iNES_HEADER[5] & 0b11) * 2 + 1)) >> 13) * 2; //*4 - } - if (chrsize != 0) - chrsize = (int(log(chrsize) / log(2))); - - // RAM size - ramsize = ((iNES_HEADER[10] & 0xF0) ? (64 << ((iNES_HEADER[10] & 0xF0) >> 4)) : 0) / 4096; //*4 - if (ramsize != 0) - ramsize = (int(log(ramsize) / log(2))); - - prg = (int_pow(2, prgsize)) * 16; - if (chrsize == 0) - chr = 0; // 0K - else - chr = (int_pow(2, chrsize)) * 4; - if (ramsize == 0) - ram = 0; // 0K - else if (mapper == 82) - ram = 5; // 5K - else - ram = (int_pow(2, ramsize)) * 4; - - // Mapper Variants - // Identify variant for use across multiple functions - if (mapper == 4) { // Check for MMC6/MMC3 - checkMMC6(); - if (mmc6) - ram = 1; // 1K - } - - println_Msg(gamename); - print_Msg(F("MAPPER: ")); - println_Msg(mapper); - print_Msg(F("PRG SIZE: ")); - print_Msg(prg); - println_Msg(F("K")); - print_Msg(F("CHR SIZE: ")); - print_Msg(chr); - println_Msg(F("K")); - print_Msg(F("RAM SIZE: ")); - if (mapper == 0) { - print_Msg(ram / 4); - println_Msg(F("K")); - } else if ((mapper == 16) || (mapper == 80) || (mapper == 159)) { - if (mapper == 16) - print_Msg(ram * 32); - else - print_Msg(ram * 16); - println_Msg(F("B")); - } else if (mapper == 19) { - if (ramsize == 2) - println_Msg(F("128B")); - else { - print_Msg(ram); - println_Msg(F("K")); - } - } else { - print_Msg(ram); - println_Msg(F("K")); - } -#if defined(enable_OLED) - print_STR(press_to_change_STR, 1); - print_STR(right_to_select_STR, 1); -#elif defined(enable_LCD) - print_STR(rotate_to_change_STR, 1); - print_STR(press_to_select_STR, 1); -#elif defined(SERIAL_MONITOR) - println_Msg(F("U/D to Change")); - println_Msg(F("Space to Select")); -#endif - display_Update(); - - int b = 0; - while (1) { - // Check button input - b = checkButton(); - - // Next - if (b == 1) { - break; - } - - // Previous - else if (b == 2) { - rewind_line(myFile, 6); - break; - } - - // Selection - else if (b == 3) { - // Get name - byte myLength = 0; - for (unsigned int i = 0; i < 20; i++) { - // Stop at first "(" to remove "(Country)" - if (char(gamename[i]) == 40) { - break; - } - if (((char(gamename[i]) >= 48 && char(gamename[i]) <= 57) || (char(gamename[i]) >= 65 && char(gamename[i]) <= 90) || (char(gamename[i]) >= 97 && char(gamename[i]) <= 122)) && (myLength < 15)) { - romName[myLength] = char(gamename[i]); - myLength++; - } - } - - // If name consists out of all japanese characters use CART as name - if (myLength == 0) { - romName[0] = 'C'; - romName[1] = 'A'; - romName[2] = 'R'; - romName[3] = 'T'; - romName[4] = '\0'; - } - - // Save Mapper - EEPROM_writeAnything(7, mapper); - EEPROM_writeAnything(8, prgsize); - EEPROM_writeAnything(9, chrsize); - EEPROM_writeAnything(10, ramsize); - myFile.close(); - break; - } - } - } -#ifdef global_log - // Enable log again - dont_log = false; -#endif - } else { - print_Error(F("Database file not found"), true); + database.rewind(); + // Skip ahead to selected starting letter + if ((myLetter > 0) && (myLetter <= 26)) { + myLetter += 'A' - 1; + struct database_entry entry; + // Read current name + do { + readDatabaseEntry(database, &entry); + } while (database.available() && entry.filename[0] != myLetter); + rewind_line(database, 3); } +#ifdef global_log + // Enable log again + dont_log = false; +#endif } } @@ -2108,7 +1822,7 @@ chooseMapper: #elif defined(enable_serial) setmapper: String newmap; - mapfound = false; + boolean mapfound = false; Serial.println(F("SUPPORTED MAPPERS:")); for (int i = 0; i < mapcount; i++) { int index = i * 7; @@ -2180,7 +1894,6 @@ void setPRGSize() { if (prglo == prghi) newprgsize = prglo; else { - b = 0; int i = prglo; display_Clear(); @@ -2197,7 +1910,7 @@ void setPRGSize() { display_Update(); while (1) { - b = checkButton(); + int b = checkButton(); if (b == doubleclick) { // Previous if (i == prglo) @@ -2300,7 +2013,6 @@ void setCHRSize() { if (chrlo == chrhi) newchrsize = chrlo; else { - b = 0; int i = chrlo; display_Clear(); @@ -2317,7 +2029,7 @@ void setCHRSize() { display_Update(); while (1) { - b = checkButton(); + int b = checkButton(); if (b == doubleclick) { // Previous if (i == chrlo) @@ -2421,7 +2133,6 @@ void setRAMSize() { if (ramlo == ramhi) newramsize = ramlo; else { - b = 0; int i = 0; display_Clear(); @@ -2452,7 +2163,7 @@ void setRAMSize() { display_Update(); while (1) { - b = checkButton(); + int b = checkButton(); if (b == doubleclick) { // Previous Mapper if (i == 0) @@ -2666,6 +2377,9 @@ void checkMMC6() { // Detect MMC6 Carts - read PRG 0x3E00A ("START } void checkStatus_NES() { +#ifdef nointro + getMapping(); +#endif EEPROM_readAnything(7, mapper); EEPROM_readAnything(8, prgsize); EEPROM_readAnything(9, chrsize); @@ -2696,6 +2410,15 @@ void checkStatus_NES() { println_Msg(F("")); println_Msg(F("CURRENT SETTINGS")); println_Msg(F("")); + printNESSettings(); + println_Msg(F("")); + // Prints string out of the common strings array either with or without newline + print_STR(press_button_STR, 1); + display_Update(); + wait(); +} + +static void printNESSettings(void) { print_Msg(F("MAPPER: ")); println_Msg(mapper); print_Msg(F("PRG SIZE: ")); @@ -2725,11 +2448,6 @@ void checkStatus_NES() { print_Msg(ram); println_Msg(F("K")); } - println_Msg(F("")); - // Prints string out of the common strings array either with or without newline - print_STR(press_button_STR, 1); - display_Update(); - wait(); } /****************************************** From 84738038e180510c6eb13afa13689e123e7c47fa Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Sun, 23 Oct 2022 13:44:31 +0000 Subject: [PATCH 19/24] NES.ino: Give more time to read "No data found" message. --- Cart_Reader/NES.ino | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Cart_Reader/NES.ino b/Cart_Reader/NES.ino index 02f6cd9..e0d2f2e 100644 --- a/Cart_Reader/NES.ino +++ b/Cart_Reader/NES.ino @@ -540,12 +540,11 @@ void getMapping() { // Filter out all 0xFF checksums at 0x8000 and 0xE000 if (oldcrc32 == 0xBD7BC39F && oldcrc32MMC3 == 0xBD7BC39F) { - delay(200); println_Msg(F("")); println_Msg(F("No data found.")); println_Msg(F("Using manual selection")); display_Update(); - delay(500); + delay(1000); setDefaultRomName(); selectMapping(database); } else { From 3b05046ee9e40cc508b8c69c70dd05a88bc41302 Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Sun, 23 Oct 2022 12:26:40 +0000 Subject: [PATCH 20/24] All: Factorise CRC functions. This saves 370 bytes of program space. --- Cart_Reader/Cart_Reader.ino | 58 +++++++++++++++++++++++-------------- Cart_Reader/N64.ino | 18 +++--------- Cart_Reader/NES.ino | 32 ++++++++------------ Cart_Reader/SFM.ino | 6 +--- Cart_Reader/SNES.ino | 6 +--- 5 files changed, 55 insertions(+), 65 deletions(-) diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index ac643d6..1c6eb14 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -531,32 +531,48 @@ static const uint32_t crc_32_tab[] PROGMEM = { /* CRC polynomial 0xedb88320 */ 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; -inline uint32_t updateCRC(uint8_t ch, uint32_t crc) { - uint32_t idx = ((crc) ^ (ch)) & 0xff; - uint32_t tab_value = pgm_read_dword(crc_32_tab + idx); - return tab_value ^ ((crc) >> 8); +// Defined as a macros, as compiler disregards inlining requests and these are +// performance-critical functions. +#define UPDATE_CRC(crc, ch) do { \ + uint8_t idx = ((crc) ^ (ch)) & 0xff; \ + uint32_t tab_value = pgm_read_dword(crc_32_tab + idx); \ + (crc) = tab_value ^ ((crc) >> 8); \ +} while (0) + +uint32_t updateCRC(const byte *buffer, size_t length, uint32_t crc) { + for (size_t c = 0; c < length; c++) { + UPDATE_CRC(crc, buffer[c]); + } + return crc; +} + +uint32_t calculateCRC(const byte *buffer, size_t length) { + uint32_t crc = 0xFFFFFFFF; + updateCRC(buffer, length, crc); + return ~crc; +} + +uint32_t calculateCRC(FsFile &infile) { + uint32_t byte_count; + uint32_t crc = 0xFFFFFFFF; + + while((byte_count = infile.read(sdBuffer, sizeof(sdBuffer))) != 0) { + updateCRC(sdBuffer, byte_count, crc); + } + return ~crc; } // Calculate rom's CRC32 from SD uint32_t calculateCRC(char* fileName, char* folder, int offset) { - // Open folder + FsFile infile; + uint32_t result; + sd.chdir(folder); - // Open file - if (myFile.open(fileName, O_READ)) { - uint32_t oldcrc32 = 0xFFFFFFFF; - - // Skip iNES header - myFile.seek(offset); - - for (unsigned long currByte = 0; currByte < ((myFile.fileSize() - offset) / 512); currByte++) { - myFile.read(sdBuffer, 512); - for (int c = 0; c < 512; c++) { - oldcrc32 = updateCRC(sdBuffer[c], oldcrc32); - } - } - // Close the file: - myFile.close(); - return ~oldcrc32; + if (infile.open(fileName, O_READ)) { + infile.seek(offset); + result = calculateCRC(infile); + infile.close(); + return result; } else { display_Clear(); print_Msg(F("File ")); diff --git a/Cart_Reader/N64.ino b/Cart_Reader/N64.ino index 2456603..2e44c2f 100644 --- a/Cart_Reader/N64.ino +++ b/Cart_Reader/N64.ino @@ -3379,8 +3379,6 @@ redumpsamefolder: // prepare crc32 uint32_t oldcrc32 = 0xFFFFFFFF; - uint32_t tab_value = 0; - uint8_t idx = 0; // run combined dumper + crc32 routine for better performance, as N64 ROMs are quite large for an 8bit micro // currently dumps + checksums a 32MB cart in 170 seconds (down from 347 seconds) @@ -3412,12 +3410,8 @@ redumpsamefolder: PORTH |= (1 << 6); // crc32 update - idx = ((oldcrc32) ^ (buffer[c])); - tab_value = pgm_read_dword(crc_32_tab + idx); - oldcrc32 = tab_value ^ ((oldcrc32) >> 8); - idx = ((oldcrc32) ^ (buffer[c + 1])); - tab_value = pgm_read_dword(crc_32_tab + idx); - oldcrc32 = tab_value ^ ((oldcrc32) >> 8); + UPDATE_CRC(oldcrc32, buffer[c]); + UPDATE_CRC(oldcrc32, buffer[c + 1]); } // Set the address for the next 512 bytes to dump @@ -3443,12 +3437,8 @@ redumpsamefolder: PORTH |= (1 << 6); // crc32 update - idx = ((oldcrc32) ^ (buffer[c])) & 0xff; - tab_value = pgm_read_dword(crc_32_tab + idx); - oldcrc32 = tab_value ^ ((oldcrc32) >> 8); - idx = ((oldcrc32) ^ (buffer[c + 1])) & 0xff; - tab_value = pgm_read_dword(crc_32_tab + idx); - oldcrc32 = tab_value ^ ((oldcrc32) >> 8); + UPDATE_CRC(oldcrc32, buffer[c]); + UPDATE_CRC(oldcrc32, buffer[c + 1]); } processedProgressBar += 1024; diff --git a/Cart_Reader/NES.ino b/Cart_Reader/NES.ino index e0d2f2e..f549a08 100644 --- a/Cart_Reader/NES.ino +++ b/Cart_Reader/NES.ino @@ -532,8 +532,8 @@ void getMapping() { // Read first 512 bytes of first and last block of PRG ROM and compute CRC32 // MMC3 maps the last 8KB block of PRG ROM to 0xE000 while 0x8000 can contain random data after bootup for (int c = 0; c < 512; c++) { - oldcrc32 = updateCRC(read_prg_byte(0x8000 + c), oldcrc32); - oldcrc32MMC3 = updateCRC(read_prg_byte(0xE000 + c), oldcrc32MMC3); + UPDATE_CRC(oldcrc32, read_prg_byte(0x8000 + c)); + UPDATE_CRC(oldcrc32MMC3, read_prg_byte(0xE000 + c)); } oldcrc32 = ~oldcrc32; oldcrc32MMC3 = ~oldcrc32MMC3; @@ -1054,27 +1054,19 @@ int int_pow(int base, int exp) { // Power for int CRC Functions *****************************************/ -void calcCRC(char* checkFile, uint32_t* crcCopy, unsigned long offset) { - uint32_t crc = 0xFFFFFFFF; +void printCRC(char* checkFile, uint32_t* crcCopy, unsigned long offset) { + uint32_t crc; char tempCRC[9]; - int byte_count; FsFile crcFile = sd.open(checkFile); + crcFile.seek(offset); - while (crcFile.available()) { - byte_count = crcFile.read(sdBuffer, sizeof(sdBuffer)); - for (int x = 0; x < byte_count; x++) { - uint8_t c = sdBuffer[x]; - crc = updateCRC(c, crc); - } - } - crc = ~crc; + crc = calculateCRC(crcFile); crcFile.close(); - sprintf(tempCRC, "%08lX", crc); if (crcCopy != NULL) { *crcCopy = crc; } - + sprintf(tempCRC, "%08lX", crc); print_Msg(F("CRC: ")); println_Msg(tempCRC); display_Update(); @@ -1324,7 +1316,7 @@ void outputNES() { println_Msg(F("")); display_Update(); - calcCRC(outputFile, NULL, crcOffset); + printCRC(outputFile, NULL, crcOffset); LED_RED_OFF; LED_GREEN_OFF; LED_BLUE_OFF; @@ -3247,7 +3239,7 @@ void readPRG(boolean readrom) { println_Msg(F("")); display_Update(); #ifndef nointro - calcCRC(fileName, &prg_crc32, 0); + printCRC(fileName, &prg_crc32, 0); #endif } } @@ -3972,7 +3964,7 @@ void readCHR(boolean readrom) { println_Msg(F("")); display_Update(); #ifndef nointro - calcCRC(fileName, &chr_crc32, 0); + printCRC(fileName, &chr_crc32, 0); #endif } } @@ -4161,9 +4153,9 @@ void readRAM() { display_Update(); if ((mapper == 16) || (mapper == 159)) - calcCRC(fileName, NULL, 0); + printCRC(fileName, NULL, 0); else - calcCRC(fileName, NULL, 0); + printCRC(fileName, NULL, 0); } } set_address(0); diff --git a/Cart_Reader/SFM.ino b/Cart_Reader/SFM.ino index 535a36b..4bf5087 100644 --- a/Cart_Reader/SFM.ino +++ b/Cart_Reader/SFM.ino @@ -807,12 +807,8 @@ boolean checkcart_SFM() { } // Calculate CRC32 of header - uint32_t oldcrc32 = 0xFFFFFFFF; - for (int c = 0; c < 80; c++) { - oldcrc32 = updateCRC(snesHeader[c], oldcrc32); - } char crcStr[9]; - sprintf(crcStr, "%08lX", ~oldcrc32); + sprintf(crcStr, "%08lX", calculateCRC(snesHeader, 80)); // Get Checksum as string sprintf(checksumStr, "%02X%02X", readBank_SFM(0, 65503), readBank_SFM(0, 65502)); diff --git a/Cart_Reader/SNES.ino b/Cart_Reader/SNES.ino index c4383a7..96162d6 100644 --- a/Cart_Reader/SNES.ino +++ b/Cart_Reader/SNES.ino @@ -950,12 +950,8 @@ boolean checkcart_SNES() { } // Calculate CRC32 of header - uint32_t oldcrc32 = 0xFFFFFFFF; - for (int c = 0; c < 80; c++) { - oldcrc32 = updateCRC(snesHeader[c], oldcrc32); - } char crcStr[9]; - sprintf(crcStr, "%08lX", ~oldcrc32); + sprintf(crcStr, "%08lX", calculateCRC(snesHeader, 80)); // Get Checksum as string sprintf(checksumStr, "%02X%02X", snesHeader[0xFFDF - headerStart], snesHeader[0xFFDE - headerStart]); From 67b54a690b74fc33bc727d92804d9449a70fa310 Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Sun, 23 Oct 2022 15:49:38 +0000 Subject: [PATCH 21/24] All: Factorise title generation from cart. Fix out-of-bound access when first byte is not an ascii printable character. Reduces program space use by 480 bytes. --- Cart_Reader/Cart_Reader.ino | 26 ++++++++++++++++++++++++++ Cart_Reader/GB.ino | 16 ++++++++-------- Cart_Reader/GBA.ino | 20 +------------------- Cart_Reader/N64.ino | 30 +++--------------------------- Cart_Reader/SNES.ino | 25 ++++--------------------- 5 files changed, 42 insertions(+), 75 deletions(-) diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index 1c6eb14..d7b38d8 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -1884,6 +1884,32 @@ void setColor_RGB(byte r, byte g, byte b) { #endif } +// Extract ASCII printable characters from input, collapsing underscores and spaces. +// Use when extracting titles from cartridges, to build a rom title. +byte buildRomName(char *output, const byte *input, byte length) { + byte input_char; + byte output_len = 0; + for (unsigned int i = 0; i < length; i++) { + input_char = input[i]; + if (isprint(input_char) && input_char != '<' && input_char != '>' && input_char != ':' && input_char != '"' && input_char != '/' && input_char != '\\' && input_char != '|' && input_char != '?' && input_char != '*') { + output[output_len++] = input_char; + } else { + if (output_len == 0 || output[output_len - 1] != '_') { + output[output_len++] = '_'; + } + } + } + while ( + output_len && ( + output[output_len - 1] == '_' || output[output_len - 1] == ' ' + ) + ) { + output_len--; + } + output[output_len] = 0; + return output_len; +} + // Converts a progmem array into a ram array void convertPgm(const char* const pgmOptions[], byte numArrays) { for (int i = 0; i < numArrays; i++) { diff --git a/Cart_Reader/GB.ino b/Cart_Reader/GB.ino index 18a86f6..5f30796 100644 --- a/Cart_Reader/GB.ino +++ b/Cart_Reader/GB.ino @@ -882,12 +882,10 @@ void getCartInfo_GB() { for (int addr = 0x0134; addr <= 0x0143 - x; addr++) { myByte = sdBuffer[addr]; if (isprint(myByte) && myByte != '<' && myByte != '>' && myByte != ':' && myByte != '"' && myByte != '/' && myByte != '\\' && myByte != '|' && myByte != '?' && myByte != '*') { - romName[myLength] = char(myByte); - } else { - if (romName[myLength - 1] == 0x5F) myLength--; - romName[myLength] = 0x5F; + romName[myLength++] = char(myByte); + } else if (myLength == 0 || romName[myLength - 1] != '_') { + romName[myLength++] = '_'; } - myLength++; } // Find Game Serial @@ -904,11 +902,13 @@ void getCartInfo_GB() { } // Strip trailing white space - for (unsigned int i = myLength - 1; i > 0; i--) { - if ((romName[i] != 0x5F) && (romName[i] != 0x20)) break; - romName[i] = 0x00; + while ( + myLength && + (romName[myLength - 1] == '_' || romName[myLength - 1] == ' ') + ) { myLength--; } + romName[myLength] = 0; // M161 (Mani 4 in 1) if (strncmp(romName, "TETRIS SET", 10) == 0 && sdBuffer[0x14D] == 0x3F) { diff --git a/Cart_Reader/GBA.ino b/Cart_Reader/GBA.ino index 27d5b6c..a01ab68 100644 --- a/Cart_Reader/GBA.ino +++ b/Cart_Reader/GBA.ino @@ -755,25 +755,7 @@ void getCartInfo_GBA() { } // Get name - byte myByte = 0; - byte myLength = 0; - for (int addr = 0xA0; addr <= 0xAB; addr++) { - myByte = sdBuffer[addr]; - if (isprint(myByte) && myByte != '<' && myByte != '>' && myByte != ':' && myByte != '"' && myByte != '/' && myByte != '\\' && myByte != '|' && myByte != '?' && myByte != '*') { - romName[myLength] = char(myByte); - } else { - if (romName[myLength - 1] == 0x5F) myLength--; - romName[myLength] = 0x5F; - } - myLength++; - } - - // Strip trailing white space - for (unsigned int i = myLength - 1; i > 0; i--) { - if ((romName[i] != 0x5F) && (romName[i] != 0x20)) break; - romName[i] = 0x00; - myLength--; - } + buildRomName(romName, &sdBuffer[0xA0], 11); // Get ROM version romVersion = sdBuffer[0xBC]; diff --git a/Cart_Reader/N64.ino b/Cart_Reader/N64.ino index 2e44c2f..0efc1fd 100644 --- a/Cart_Reader/N64.ino +++ b/Cart_Reader/N64.ino @@ -2181,33 +2181,9 @@ void idCart() { // Get rom version romVersion = sdBuffer[0x3F]; - // Get name - byte myByte = 0; - byte myLength = 0; - for (unsigned int i = 0; i < 20; i++) { - myByte = sdBuffer[0x20 + i]; - if (isprint(myByte) && myByte != '<' && myByte != '>' && myByte != ':' && myByte != '"' && myByte != '/' && myByte != '\\' && myByte != '|' && myByte != '?' && myByte != '*') { - romName[myLength] = char(myByte); - } else { - if (romName[myLength - 1] == 0x5F) myLength--; - romName[myLength] = 0x5F; - } - myLength++; - } - - // Strip trailing white space - for (unsigned int i = myLength - 1; i > 0; i--) { - if ((romName[i] != 0x5F) && (romName[i] != 0x20)) break; - romName[i] = 0x00; - myLength--; - } - // If name consists out of all japanese characters use cart id - if (myLength == 0) { - romName[0] = sdBuffer[0x3B]; - romName[1] = sdBuffer[0x3C]; - romName[2] = sdBuffer[0x3D]; - romName[3] = sdBuffer[0x3E]; + if (buildRomName(romName, &sdBuffer[0x20], 20) == 0) { + strcpy(romName, cartID); } #ifdef savesummarytotxt @@ -4874,4 +4850,4 @@ unsigned long verifyGameshark_N64() { //****************************************** // End of File -//****************************************** \ No newline at end of file +//****************************************** diff --git a/Cart_Reader/SNES.ino b/Cart_Reader/SNES.ino index 96162d6..95aa756 100644 --- a/Cart_Reader/SNES.ino +++ b/Cart_Reader/SNES.ino @@ -1016,25 +1016,7 @@ boolean checkcart_SNES() { } // Get name - byte myByte = 0; - byte myLength = 0; - for (unsigned int i = 0xFFC0; i < 0xFFD5; i++) { - myByte = snesHeader[i - headerStart]; - if (isprint(myByte) && myByte != '<' && myByte != '>' && myByte != ':' && myByte != '"' && myByte != '/' && myByte != '\\' && myByte != '|' && myByte != '?' && myByte != '*') { - romName[myLength] = char(myByte); - } else { - if (romName[myLength - 1] == 0x5F) myLength--; - romName[myLength] = 0x5F; - } - myLength++; - } - - // Strip trailing white space - for (unsigned int i = myLength - 1; i > 0; i--) { - if ((romName[i] != 0x5F) && (romName[i] != 0x20)) break; - romName[i] = 0x00; - myLength--; - } + byte myLength = buildRomName(romName, &snesHeader[headerStart], 21); // If name consists out of all japanese characters use game code if (myLength == 0) { @@ -1045,9 +1027,10 @@ boolean checkcart_SNES() { romName[3] = 'C'; romName[4] = '-'; for (unsigned int i = 0; i < 4; i++) { + byte myByte; myByte = snesHeader[0xFFB2 + i - headerStart]; - if (((char(myByte) >= 48 && char(myByte) <= 57) || (char(myByte) >= 65 && char(myByte) <= 122)) && myLength < 4) { - romName[myLength + 5] = char(myByte); + if (((myByte >= '0' && myByte <= '9') || (myByte >= 'A' && myByte <= 'z')) && myLength < 4) { + romName[myLength + 5] = myByte; myLength++; } } From 3632b069805e558823c37f5e200eea6e764aff3b Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Mon, 24 Oct 2022 04:38:56 +0000 Subject: [PATCH 22/24] SFM.ino: Factorise single-game gamecode retrieval. Frees 220 bytes of code and 16 bytes of ram. --- Cart_Reader/SFM.ino | 54 ++++++++++++++------------------------------- 1 file changed, 17 insertions(+), 37 deletions(-) diff --git a/Cart_Reader/SFM.ino b/Cart_Reader/SFM.ino index 4bf5087..16baaa2 100644 --- a/Cart_Reader/SFM.ino +++ b/Cart_Reader/SFM.ino @@ -490,8 +490,8 @@ void getGames() { for (int j = 0; j < 9; j++) { myByte = readBank_SFM(0xC6, i * 0x2000 + 0x07 + j); // Remove funny characters - if (((char(myByte) >= 44 && char(myByte) <= 57) || (char(myByte) >= 65 && char(myByte) <= 122)) && myLength < 9) { - gameCode[i][myLength] = char(myByte); + if (((myByte >= ',' && myByte <= '9') || (myByte >= 'A' && myByte <= 'z')) && myLength < 9) { + gameCode[i][myLength] = myByte; myLength++; } } @@ -499,48 +499,28 @@ void getGames() { gameCode[i][myLength] = '\0'; } } else { + word base; //check if hirom if (readBank_SFM(0xC0, 0xFFD5) == 0x31) { hirom[0] = true; + base = 0xFF00; } else { hirom[0] = false; + base = 0x7F00; } - if (hirom[0]) { - gameVersion[0] = readBank_SFM(0xC0, 0xFFDB); - gameCode[0][0] = 'G'; - gameCode[0][1] = 'A'; - gameCode[0][2] = 'M'; - gameCode[0][3] = 'E'; - gameCode[0][4] = '-'; - gameCode[0][5] = char(readBank_SFM(0xC0, 0xFFB2)); - gameCode[0][6] = char(readBank_SFM(0xC0, 0xFFB3)); - gameCode[0][7] = char(readBank_SFM(0xC0, 0xFFB4)); - gameCode[0][8] = char(readBank_SFM(0xC0, 0xFFB5)); - gameCode[0][9] = '\0'; - - byte romSizeExp = readBank_SFM(0xC0, 0xFFD7) - 7; - gameSize[0] = 1; - while (romSizeExp--) - gameSize[0] *= 2; - } else { - gameVersion[0] = readBank_SFM(0xC0, 0x7FDB); - gameCode[0][0] = 'G'; - gameCode[0][1] = 'A'; - gameCode[0][2] = 'M'; - gameCode[0][3] = 'E'; - gameCode[0][4] = '-'; - gameCode[0][5] = char(readBank_SFM(0xC0, 0x7FB2)); - gameCode[0][6] = char(readBank_SFM(0xC0, 0x7FB3)); - gameCode[0][7] = char(readBank_SFM(0xC0, 0x7FB4)); - gameCode[0][8] = char(readBank_SFM(0xC0, 0x7FB5)); - gameCode[0][9] = '\0'; - - byte romSizeExp = readBank_SFM(0xC0, 0x7FD7) - 7; - gameSize[0] = 1; - while (romSizeExp--) - gameSize[0] *= 2; - } + gameVersion[0] = readBank_SFM(0xC0, base + 0xDB); + gameCode[0][0] = 'G'; + gameCode[0][1] = 'A'; + gameCode[0][2] = 'M'; + gameCode[0][3] = 'E'; + gameCode[0][4] = '-'; + gameCode[0][5] = readBank_SFM(0xC0, base + 0xB2); + gameCode[0][6] = readBank_SFM(0xC0, base + 0xB3); + gameCode[0][7] = readBank_SFM(0xC0, base + 0xB4); + gameCode[0][8] = readBank_SFM(0xC0, base + 0xB5); + gameCode[0][9] = '\0'; + gameSize[0] = 1 << (readBank_SFM(0xC0, base + 0xD7) - 7); } } From 3c3b399d6a6551c719415b83a89aadb1e22d730a Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Mon, 24 Oct 2022 06:16:04 +0000 Subject: [PATCH 23/24] SFM.ino: Move all menu variables from globals to locals. Saves about 100 bytes of program memory and 80 bytes of global ram. --- Cart_Reader/SFM.ino | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/Cart_Reader/SFM.ino b/Cart_Reader/SFM.ino index 16baaa2..0ae22aa 100644 --- a/Cart_Reader/SFM.ino +++ b/Cart_Reader/SFM.ino @@ -16,16 +16,11 @@ // SF Memory status byte sfmReady = 0; -// SF Memory Menu -boolean hasMenu = true; -byte numGames = 0; - // Arrays that hold game info int gameSize[8]; int saveSize[8]; byte gameAddress[8]; byte gameVersion[8]; -char gameCode[8][10]; boolean hirom[8]; /****************************************** @@ -79,20 +74,17 @@ void sfmMenu() { } void sfmGameMenu() { + char menuOptionsSFMGames[8][20]; + byte numGames; + boolean hasMenu; // Switch to hirom all if (send_SFM(0x04) == 0x2A) { delay(300); // Fill arrays with data - getGames(); + getGames(menuOptionsSFMGames, &hasMenu, &numGames); if (hasMenu) { - // Create submenu options - char menuOptionsSFMGames[8][20]; - for (int i = 0; i < (numGames); i++) { - strncpy(menuOptionsSFMGames[i], gameCode[i], 10); - } - // Create menu with title and numGames options to choose from unsigned char gameSubMenu; // wait for user choice to come back from the question box menu @@ -121,7 +113,7 @@ void sfmGameMenu() { } } // Copy gameCode to romName in case of japanese chars in romName - strcpy(romName, gameCode[gameSubMenu + 1]); + strcpy(romName, menuOptionsSFMGames[gameSubMenu + 1]); // Print info getCartInfo_SFM(); @@ -133,7 +125,7 @@ void sfmGameMenu() { delay(200); // Copy gameCode to romName in case of japanese chars in romName - strcpy(romName, gameCode[0]); + strcpy(romName, menuOptionsSFMGames[0]); // Print info getCartInfo_SFM(); @@ -441,29 +433,31 @@ void sfmFlashMenu() { #endif // Read the games from the menu area -void getGames() { +void getGames(char gameCode[8][20], boolean *hasMenu, byte *numGames) { // Set data pins to input dataIn(); // Set control pins to input controlIn_SFM(); // Check if menu is present + *hasMenu = true; byte menuString[] = { 0x4D, 0x45, 0x4E, 0x55, 0x20, 0x50, 0x52, 0x4F, 0x47, 0x52, 0x41, 0x4D }; for (int i = 0; i < 12; i++) { if (menuString[i] != readBank_SFM(0xC0, 0x7FC0 + i)) { - hasMenu = false; + *hasMenu = false; } } - if (hasMenu) { + if (*hasMenu) { + *numGames = 0; // Count number of games for (word i = 0x0000; i < 0xE000; i += 0x2000) { - if (readBank_SFM(0xC6, i) == numGames) - numGames++; + if (readBank_SFM(0xC6, i) == *numGames) + (*numGames)++; } // Get game info - for (int i = 0; i < numGames; i++) { + for (int i = 0; i < *numGames; i++) { // Read starting address and size gameAddress[i] = 0xC0 + readBank_SFM(0xC6, i * 0x2000 + 0x01) * 0x8; gameSize[i] = readBank_SFM(0xC6, i * 0x2000 + 0x03) * 128; @@ -500,6 +494,7 @@ void getGames() { } } else { word base; + *numGames = 1; //check if hirom if (readBank_SFM(0xC0, 0xFFD5) == 0x31) { hirom[0] = true; @@ -1756,4 +1751,4 @@ void write_SFM(int startBank, uint32_t pos) { //****************************************** // End of File -//****************************************** \ No newline at end of file +//****************************************** From 10061beaf511303934036ca9f6e1c670d256f439 Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Mon, 24 Oct 2022 06:51:06 +0000 Subject: [PATCH 24/24] MD.ino: Move some globals to getCartInfo_MD locals. Also, bypass sdBuffer when it was the directory copied to another buffer. Also, factorise yet another pair of loops copying rom name. This frees 59 bytes of global ram space. --- Cart_Reader/MD.ino | 62 ++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/Cart_Reader/MD.ino b/Cart_Reader/MD.ino index cb7021c..bc3df7e 100644 --- a/Cart_Reader/MD.ino +++ b/Cart_Reader/MD.ino @@ -103,10 +103,6 @@ static unsigned long cartSizeLockon; static unsigned long cartSizeSonic2 = 262144; static word chksumLockon; static word chksumSonic2 = 0x0635; -static char romNameLockon[12]; -static char id[15]; -static char idLockon[15]; -static char labelLockon[17]; /****************************************** Configuration @@ -671,6 +667,23 @@ void dataIn_MD() { /****************************************** MEGA DRIVE functions *****************************************/ +byte copyToRomName_MD(char *output, const byte *input, byte length) { + byte myLength = 0; + + for (byte i = 0; i < 48; i++) { + if ( + ( + (input[i] >= '0' && input[i] <= '9') || + (input[i] >= 'A' && input[i] <= 'z') + ) && myLength < length + ) { + output[myLength++] = input[i]; + } + } + + return myLength; +} + void getCartInfo_MD() { // Set control dataIn_MD(); @@ -709,6 +722,7 @@ void getCartInfo_MD() { // Sonic & Knuckles Check SnKmode = 0; if (chksum == 0xDFB3) { + char id[15]; // Get ID for (byte c = 0; c < 14; c += 2) { @@ -718,15 +732,13 @@ void getCartInfo_MD() { byte hiByte = myWord >> 8; // write to buffer - sdBuffer[c] = hiByte; - sdBuffer[c + 1] = loByte; - } - for (int i = 0; i < 14; i++) { - id[i] = char(sdBuffer[i]); + id[c] = hiByte; + id[c + 1] = loByte; } //Sonic & Knuckles ID:GM MK-1563 -00 if (!strcmp("GM MK-1563 -00", id)) { + char labelLockon[17]; // Get labelLockon for (byte c = 0; c < 16; c += 2) { @@ -736,15 +748,13 @@ void getCartInfo_MD() { byte hiByte = myWord >> 8; // write to buffer - sdBuffer[c] = hiByte; - sdBuffer[c + 1] = loByte; - } - for (int i = 0; i < 16; i++) { - labelLockon[i] = char(sdBuffer[i]); + labelLockon[c] = hiByte; + labelLockon[c + 1] = loByte; } // check Lock-on game presence if (!(strcmp("SEGA MEGA DRIVE ", labelLockon) & strcmp("SEGA GENESIS ", labelLockon))) { + char idLockon[15]; // Lock-on cart checksum chksumLockon = readWord_MD(0x1000C7); @@ -759,11 +769,8 @@ void getCartInfo_MD() { byte hiByte = myWord >> 8; // write to buffer - sdBuffer[c] = hiByte; - sdBuffer[c + 1] = loByte; - } - for (int i = 0; i < 14; i++) { - idLockon[i] = char(sdBuffer[i]); + idLockon[c] = hiByte; + idLockon[c + 1] = loByte; } if (!(strncmp("GM 00001009-0", idLockon, 13) & strncmp("GM 00004049-0", idLockon, 13))) { @@ -968,16 +975,11 @@ void getCartInfo_MD() { sdBuffer[c] = hiByte; sdBuffer[c + 1] = loByte; } - byte myLength = 0; - for (unsigned int i = 0; i < 48; i++) { - if (((char(sdBuffer[i]) >= 48 && char(sdBuffer[i]) <= 57) || (char(sdBuffer[i]) >= 65 && char(sdBuffer[i]) <= 122)) && myLength < 15) { - romName[myLength] = char(sdBuffer[i]); - myLength++; - } - } + romName[copyToRomName_MD(romName, sdBuffer, sizeof(romName) - 1)] = 0; //Get Lock-on cart name if (SnKmode >= 2) { + char romNameLockon[12]; //Change romName strcpy(romName, "SnK_"); @@ -992,13 +994,7 @@ void getCartInfo_MD() { sdBuffer[c] = hiByte; sdBuffer[c + 1] = loByte; } - byte myLength = 0; - for (unsigned int i = 0; i < 48; i++) { - if (((char(sdBuffer[i]) >= 48 && char(sdBuffer[i]) <= 57) || (char(sdBuffer[i]) >= 65 && char(sdBuffer[i]) <= 122)) && myLength < 11) { - romNameLockon[myLength] = char(sdBuffer[i]); - myLength++; - } - } + romNameLockon[copyToRomName_MD(romNameLockon, sdBuffer, sizeof(romNameLockon) - 1)] = 0; switch (SnKmode) { case 2: strcat(romName, "SONIC1"); break;