From 77c0daeb6ac1e9f581643cc1af68532ccbbab88f Mon Sep 17 00:00:00 2001 From: Lesserkuma Date: Sat, 24 Sep 2022 14:36:13 +0200 Subject: [PATCH] Update to displaying full ROM title on SNES, N64, GB, GBA --- Cart_Reader/GB.ino | 19 ++++++++++++++----- Cart_Reader/GBA.ino | 15 +++++++++++---- Cart_Reader/N64.ino | 18 +++++++++++++++--- Cart_Reader/SNES.ino | 17 ++++++++++++++--- 4 files changed, 54 insertions(+), 15 deletions(-) diff --git a/Cart_Reader/GB.ino b/Cart_Reader/GB.ino index 60de2a3..a00307a 100644 --- a/Cart_Reader/GB.ino +++ b/Cart_Reader/GB.ino @@ -792,19 +792,28 @@ void getCartInfo_GB() { sprintf(checksumStr, "%02X%02X", eepbit[6], eepbit[7]); // Get name + byte myByte = 0; byte myLength = 0; byte x = 0; if (sdBuffer[0x143] == 0x80 || sdBuffer[0x143] == 0xC0) { x++; } for (int addr = 0x0134; addr <= 0x0143-x; addr++) { - if (isprint(sdBuffer[addr]) && sdBuffer[addr] != '<' && sdBuffer[addr] != '>' && sdBuffer[addr] != ':' && sdBuffer[addr] != '"' && sdBuffer[addr] != '/' && sdBuffer[addr] != '\\' && sdBuffer[addr] != '|' && sdBuffer[addr] != '?' && sdBuffer[addr] != '*') { - romName[myLength] = char(sdBuffer[addr]); - myLength++; - } else if (char(sdBuffer[addr]) != 0) { + 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++; } + 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--; } } diff --git a/Cart_Reader/GBA.ino b/Cart_Reader/GBA.ino index 2b95cd4..2cacd24 100644 --- a/Cart_Reader/GBA.ino +++ b/Cart_Reader/GBA.ino @@ -897,13 +897,20 @@ void getCartInfo_GBA() { myByte = sdBuffer[addr]; if (isprint(myByte) && myByte != '<' && myByte != '>' && myByte != ':' && myByte != '"' && myByte != '/' && myByte != '\\' && myByte != '|' && myByte != '?' && myByte != '*') { romName[myLength] = char(myByte); - myLength++; - } else if (char(sdBuffer[addr]) != 0) { + } else { + if (romName[myLength-1] == 0x5F) myLength--; romName[myLength] = 0x5F; - myLength++; } + 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--; + } + // Get ROM version romVersion = sdBuffer[0xBC]; diff --git a/Cart_Reader/N64.ino b/Cart_Reader/N64.ino index 9662102..f0fa9e4 100644 --- a/Cart_Reader/N64.ino +++ b/Cart_Reader/N64.ino @@ -2711,12 +2711,24 @@ void idCart() { romVersion = sdBuffer[0x3F]; // Get name + byte myByte = 0; byte myLength = 0; for (unsigned int i = 0; i < 20; i++) { - if (((char(sdBuffer[0x20 + i]) >= 48 && char(sdBuffer[0x20 + i]) <= 57) || (char(sdBuffer[0x20 + i]) >= 65 && char(sdBuffer[0x20 + i]) <= 90) || (char(sdBuffer[0x20 + i]) >= 97 && char(sdBuffer[0x20 + i]) <= 122)) && (myLength < 15)) { - romName[myLength] = char(sdBuffer[0x20 + i]); - myLength++; + 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 diff --git a/Cart_Reader/SNES.ino b/Cart_Reader/SNES.ino index 8bd268e..a535aee 100644 --- a/Cart_Reader/SNES.ino +++ b/Cart_Reader/SNES.ino @@ -1009,11 +1009,22 @@ boolean checkcart_SNES() { byte myLength = 0; for (unsigned int i = 0xFFC0; i < 0xFFD4; i++) { myByte = snesHeader[i - headerStart]; - if (((char(myByte) >= 48 && char(myByte) <= 57) || (char(myByte) >= 65 && char(myByte) <= 122)) && myLength < 15) { + if (isprint(myByte) && myByte != '<' && myByte != '>' && myByte != ':' && myByte != '"' && myByte != '/' && myByte != '\\' && myByte != '|' && myByte != '?' && myByte != '*') { romName[myLength] = char(myByte); - myLength++; + } 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 game code if (myLength == 0) { // Get rom code @@ -1225,7 +1236,7 @@ unsigned int calc_checksum (char* fileName, char* folder) { } boolean compare_checksum() { - print_Msg(F("Chksum...")); + print_Msg(F("Checksum...")); display_Update(); strcpy(fileName, romName);