From f82be2d5dbaab05a88d7f299fc27822473e8d066 Mon Sep 17 00:00:00 2001 From: smesgr9000 Date: Mon, 20 May 2024 11:57:32 +0200 Subject: [PATCH] remove duplicate code to open file for verfication --- Cart_Reader/FLASH.ino | 71 ++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 49 deletions(-) diff --git a/Cart_Reader/FLASH.ino b/Cart_Reader/FLASH.ino index 1cb1215..fa474b9 100644 --- a/Cart_Reader/FLASH.ino +++ b/Cart_Reader/FLASH.ino @@ -1055,14 +1055,7 @@ word readWord_Flash(unsigned long myAddress) { /****************************************** write helper functions *****************************************/ -bool openFlashFile() { - // Create filepath - sprintf(filePath, "%s/%s", filePath, fileName); - print_STR(flashing_file_STR, 0); - print_Msg(filePath); - println_Msg(F("...")); - display_Update(); - +bool openFileOnSD() { // Open file on sd card if (myFile.open(filePath, O_READ)) { // Get rom size from file @@ -1076,6 +1069,24 @@ bool openFlashFile() { return false; } +bool openFlashFile() { + // Create filepath + sprintf(filePath, "%s/%s", filePath, fileName); + print_STR(flashing_file_STR, 0); + print_Msg(filePath); + println_Msg(F("...")); + display_Update(); + + return openFileOnSD(); +} + +bool openVerifyFlashFile() { + print_STR(verifying_STR, 1); + display_Update(); + + return openFileOnSD(); +} + /****************************************** 29F032 flashrom functions *****************************************/ @@ -1710,16 +1721,7 @@ void blankcheck_Flash() { } void verifyFlash() { - print_STR(verifying_STR, 1); - display_Update(); - - // Open file on sd card - if (myFile.open(filePath, O_READ)) { - // Get rom size from file - fileSize = myFile.fileSize(); - if (fileSize > flashSize) - print_FatalError(file_too_big_STR); - + if (openVerifyFlashFile()) { blank = 0; for (unsigned long currByte = 0; currByte < fileSize; currByte += 512) { //fill sdBuffer @@ -1741,9 +1743,6 @@ void verifyFlash() { } // Close the file: myFile.close(); - } else { - print_STR(open_file_STR, 1); - display_Update(); } } @@ -1994,17 +1993,7 @@ void blankcheck16() { } void verifyFlash16() { - print_STR(verifying_STR, 1); - display_Update(); - - // Open file on sd card - if (myFile.open(filePath, O_READ)) { - // Get rom size from file - fileSize = myFile.fileSize(); - if (fileSize > flashSize) { - print_FatalError(file_too_big_STR); - } - + if (openVerifyFlashFile()) { blank = 0; word d = 0; for (unsigned long currByte = 0; currByte < fileSize / 2; currByte += 256) { @@ -2031,9 +2020,6 @@ void verifyFlash16() { } // Close the file: myFile.close(); - } else { - println_Msg(F("Can't open file on SD.")); - display_Update(); } } @@ -2417,17 +2403,7 @@ void write_Eprom() { } void verify_Eprom() { - print_STR(verifying_STR, 1); - display_Update(); - - // Open file on sd card - if (myFile.open(filePath, O_READ)) { - // Get rom size from file - fileSize = myFile.fileSize(); - if (fileSize > flashSize) { - print_FatalError(file_too_big_STR); - } - + if (openVerifyFlashFile()) { blank = 0; word d = 0; for (unsigned long currWord = 0; currWord < (fileSize / 2); currWord += 256) { @@ -2454,9 +2430,6 @@ void verify_Eprom() { } // Close the file: myFile.close(); - } else { - println_Msg(F("Can't open file on SD.")); - display_Update(); } }