From 3c04277d98405509e745d7c8bb36452b66633e92 Mon Sep 17 00:00:00 2001 From: sanni Date: Fri, 9 Aug 2024 12:37:55 +0200 Subject: [PATCH] Update FLASH.ino --- Cart_Reader/FLASH.ino | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/Cart_Reader/FLASH.ino b/Cart_Reader/FLASH.ino index b4058b0..08c0d27 100644 --- a/Cart_Reader/FLASH.ino +++ b/Cart_Reader/FLASH.ino @@ -2067,7 +2067,7 @@ void verifyFlash(byte currChip, byte totalChips, boolean reversed) { blank = 0; // Adjust filesize to fit flashchip - adjustFileSize(currChip, totalChips, reversed); + adjustFileSizeOffset(currChip, totalChips, reversed); //Initialize progress bar uint32_t processedProgressBar = 0; @@ -2857,19 +2857,30 @@ void identifyCFI_Flash() { display_Update(); } -// Adjust file size to fit flash chip -void adjustFileSize(byte currChip, byte totalChips, boolean reversed) { - // 1 flash chip - if ((currChip == 1) && (totalChips == 1) && reversed) { - myFile.seekSet(4194304); +// Adjust file size to fit flash chip and goto needed file offset +void adjustFileSizeOffset(byte currChip, byte totalChips, boolean reversed) { + // 1*2MB, 1*4MB or 1*8MB + if ((currChip == 1) && (totalChips == 1)) { + if (reversed) + myFile.seekSet(4194304); } - // 2 flash chips + + // 2*2MB or 2*4MB else if ((currChip == 1) && (totalChips == 2)) { - if (fileSize > flashSize / 2) + if (reversed) { + fileSize = fileSize - flashSize / 2; + myFile.seekSet(4194304); + } else if (fileSize > flashSize / 2) fileSize = flashSize / 2; - } else if ((currChip == 2) && (totalChips == 2) && (fileSize > flashSize / 2)) { - fileSize = fileSize - flashSize / 2; - myFile.seekSet(flashSize / 2); + + } else if ((currChip == 2) && (totalChips == 2)) { + if (reversed) { + fileSize = flashSize / 2; + myFile.seekSet(0); + } else if (fileSize > flashSize / 2) { + fileSize = fileSize - flashSize / 2; + myFile.seekSet(flashSize / 2); + } } // 4*2MB @@ -2966,7 +2977,7 @@ void writeCFI_Flash(byte currChip, byte totalChips, boolean reversed) { } // Adjust filesize to fit flashchip - adjustFileSize(currChip, totalChips, reversed); + adjustFileSizeOffset(currChip, totalChips, reversed); print_Msg(F("Writing flash"));