diff options
author | Vincent Pelletier <[email protected]> | 2022-10-23 15:49:38 +0000 |
---|---|---|
committer | Vincent Pelletier <[email protected]> | 2022-10-28 05:29:44 +0000 |
commit | 67b54a690b74fc33bc727d92804d9449a70fa310 (patch) | |
tree | 06ab2ca9056ec26f9446422a4c7599e28b0e288e /Cart_Reader/GB.ino | |
parent | 3b05046ee9e40cc508b8c69c70dd05a88bc41302 (diff) | |
download | cartreader-67b54a690b74fc33bc727d92804d9449a70fa310.tar.gz cartreader-67b54a690b74fc33bc727d92804d9449a70fa310.zip |
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.
Diffstat (limited to 'Cart_Reader/GB.ino')
-rw-r--r-- | Cart_Reader/GB.ino | 16 |
1 files changed, 8 insertions, 8 deletions
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) { |