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);