From ce4e26c686c4e017e13fa29cf66adb159d85c063 Mon Sep 17 00:00:00 2001 From: sanni Date: Thu, 27 Jun 2024 10:55:54 +0200 Subject: [PATCH] Fix verifyFlash() --- Cart_Reader/FLASH.ino | 37 +++++++++++++++++++++++++++---------- Cart_Reader/SNES.ino | 4 ++-- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/Cart_Reader/FLASH.ino b/Cart_Reader/FLASH.ino index 206f1f2..e3786fa 100644 --- a/Cart_Reader/FLASH.ino +++ b/Cart_Reader/FLASH.ino @@ -1793,17 +1793,26 @@ void blankcheck_Flash() { } void verifyFlash() { - verifyFlash(0, 0); + verifyFlash(0); } -void verifyFlash(unsigned long verifyStart, unsigned long verifyEnd) { +void verifyFlash(byte romChips) { if (openVerifyFlashFile()) { blank = 0; - if (verifyStart != 0) - myFile.seekCur(verifyStart); - if (verifyEnd != 0) - fileSize = verifyEnd; + if (romChips == 1) { + myFile.seekCur(0); + // Truncate file to size of 1st flash chip + if (fileSize > flashSize / 2) { + fileSize = flashSize / 2; + } + } else if (romChips == 2) { + if (fileSize > flashSize / 2) { + myFile.seekCur(flashSize / 2); + fileSize = fileSize - (flashSize / 2); + } else + fileSize = 0; + } for (unsigned long currByte = 0; currByte < fileSize; currByte += 512) { //fill sdBuffer @@ -2608,17 +2617,25 @@ void writeCFI_Flash(byte romChips) { // If we have two ROM chips only write half the ROM file here and skip to second half of file on second write if (romChips == 0) { println_Msg(F("")); - } else if (romChips == 1) { + } + + else if (romChips == 1) { println_Msg(F(" 1/2")); myFile.seekCur(0); // Truncate file to size of 1st flash chip if (fileSize > flashSize / 2) { fileSize = flashSize / 2; } - } else if (romChips == 2) { + } + + else if (romChips == 2) { println_Msg(F(" 2/2")); - myFile.seekCur(flashSize / 2); - fileSize = fileSize - flashSize / 2; + if (fileSize > flashSize / 2) { + myFile.seekCur(flashSize / 2); + fileSize = fileSize - (flashSize / 2); + } else { + fileSize = 0; + } } display_Update(); diff --git a/Cart_Reader/SNES.ino b/Cart_Reader/SNES.ino index a6067ac..b0b0e0b 100644 --- a/Cart_Reader/SNES.ino +++ b/Cart_Reader/SNES.ino @@ -107,7 +107,7 @@ void reproCFIMenu() { flashSize = 4194304; // Write first rom chip writeCFI_Flash(1); - verifyFlash(0, 2097152); + verifyFlash(1); delay(300); // Switch to second ROM chip, see flash.ino low level functions line 811 @@ -121,7 +121,7 @@ void reproCFIMenu() { // Write second rom chip display_Clear(); writeCFI_Flash(2); - verifyFlash(2097152, 2097152); + verifyFlash(2); break; case 2: