From 2a0ca1b236004dcf4914c377a5eaba12630902da Mon Sep 17 00:00:00 2001 From: sanni Date: Fri, 15 Sep 2017 17:51:41 +0200 Subject: [PATCH] V28D: Simplify GBA Logo Check --- Cart_Reader/Cart_Reader.ino | 6 +++--- Cart_Reader/GBA.ino | 35 ++++++----------------------------- 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino index 7f1bc29..dc45c18 100644 --- a/Cart_Reader/Cart_Reader.ino +++ b/Cart_Reader/Cart_Reader.ino @@ -2,8 +2,8 @@ Cartridge Reader for Arduino Mega2560 Author: sanni - Date: 2017-09-14 - Version: V28C + Date: 2017-09-15 + Version: V28D SD lib: https://github.com/greiman/SdFat LCD lib: https://github.com/adafruit/Adafruit_SSD1306 @@ -34,7 +34,7 @@ YamaArashi - GBA flashrom bank switch command **********************************************************************************/ -char ver[5] = "V28C"; +char ver[5] = "V28D"; /****************************************** Define Output diff --git a/Cart_Reader/GBA.ino b/Cart_Reader/GBA.ino index 6438a3a..145e300 100644 --- a/Cart_Reader/GBA.ino +++ b/Cart_Reader/GBA.ino @@ -8,19 +8,6 @@ char calcChecksumStr[5]; boolean readType; -static const int nintendoLogo[] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, 0x24, 0xFF, 0xAE, 0x51, 0x69, 0x9A, 0xA2, 0x21, 0x3D, 0x84, 0x82, 0x0A, - 0x84, 0xE4, 0x09, 0xAD, 0x11, 0x24, 0x8B, 0x98, 0xC0, 0x81, 0x7F, 0x21, 0xA3, 0x52, 0xBE, 0x19, - 0x93, 0x09, 0xCE, 0x20, 0x10, 0x46, 0x4A, 0x4A, 0xF8, 0x27, 0x31, 0xEC, 0x58, 0xC7, 0xE8, 0x33, - 0x82, 0xE3, 0xCE, 0xBF, 0x85, 0xF4, 0xDF, 0x94, 0xCE, 0x4B, 0x09, 0xC1, 0x94, 0x56, 0x8A, 0xC0, - 0x13, 0x72, 0xA7, 0xFC, 0x9F, 0x84, 0x4D, 0x73, 0xA3, 0xCA, 0x9A, 0x61, 0x58, 0x97, 0xA3, 0x27, - 0xFC, 0x03, 0x98, 0x76, 0x23, 0x1D, 0xC7, 0x61, 0x03, 0x04, 0xAE, 0x56, 0xBF, 0x38, 0x84, 0x00, - 0x40, 0xA7, 0x0E, 0xFD, 0xFF, 0x52, 0xFE, 0x03, 0x6F, 0x95, 0x30, 0xF1, 0x97, 0xFB, 0xC0, 0x85, - 0x60, 0xD6, 0x80, 0x25, 0xA9, 0x63, 0xBE, 0x03, 0x01, 0x4E, 0x38, 0xE2, 0xF9, 0xA2, 0x34, 0xFF, - 0xBB, 0x3E, 0x03, 0x44, 0x78, 0x00, 0x90, 0xCB, 0x88, 0x11, 0x3A, 0x94, 0x65, 0xC0, 0x7C, 0x63, - 0x87, 0xF0, 0x3C, 0xAF, 0xD6, 0x25, 0xE4, 0x8B, 0x38, 0x0A, 0xAC, 0x72, 0x21, 0xD4, 0xF8, 0x07 -}; - /****************************************** Menu *****************************************/ @@ -750,8 +737,8 @@ void writeByte_GBA(unsigned long myAddress, byte myData) { /****************************************** GBA ROM Functions *****************************************/ -// Test known Nintendo header for errors and sets read method to either sequential or random access -int testHeader() { +// Read info out of rom header +void getCartInfo_GBA() { // Read Header into array for (int currWord = 0; currWord < 192; currWord += 2) { word tempWord = readWord_GBA(currWord); @@ -760,24 +747,14 @@ int testHeader() { sdBuffer[currWord + 1] = (tempWord >> 8) & 0xFF; } - // Compare Nintendo logo, 156 bytes starting at 0x04 - int errors = 0; + // Compare Nintendo logo against known checksum, 156 bytes starting at 0x04 + byte logoChecksum = 0; for (int currByte = 0x4; currByte < 0xA0; currByte++) { - if (pgm_read_byte(&nintendoLogo[currByte]) != sdBuffer[currByte]) { - errors++; - } + logoChecksum += sdBuffer[currByte]; } - return errors; -} -// Read info out of rom header -void getCartInfo_GBA() { - // Test rom header for errors - int logoErrors = testHeader(); - - if (logoErrors != 0) { + if (logoChecksum != 0x1B) { print_Error(F("CARTRIDGE ERROR"), false); - cartSize = 32; strcpy(romName, "ERROR"); println_Msg(F("")); println_Msg(F(""));