From 29e81096062c9847b95472f97bdccc7cf5c909cb Mon Sep 17 00:00:00 2001 From: Robert Neumann Date: Wed, 11 Sep 2019 20:02:26 +0200 Subject: [PATCH] SNES, MD: avoid dumping/writing 0 Byte files to SD card --- Cart_Reader/MD.ino | 16 ++++++++++++---- Cart_Reader/N64.ino | 1 + Cart_Reader/SNES.ino | 43 +++++++++++++++++++++++++------------------ 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/Cart_Reader/MD.ino b/Cart_Reader/MD.ino index b10841e..9d87de8 100644 --- a/Cart_Reader/MD.ino +++ b/Cart_Reader/MD.ino @@ -195,10 +195,18 @@ void mdCartMenu() { { case 0: display_Clear(); - // Change working dir to root - sd.chdir("/"); - readROM_MD(); - //compare_checksum_MD(); + + // common ROM read fail state: no cart inserted - tends to report impossibly large cartSize + // largest known game so far is supposedly "Paprium" at 10MB, so cap sanity check at 16MB + if (cartSize != 0 && cartSize <= 16777216) { + // Change working dir to root + sd.chdir("/"); + readROM_MD(); + //compare_checksum_MD(); + } + else { + print_Error(F("Cart has no ROM"), false); + } break; case 1: diff --git a/Cart_Reader/N64.ino b/Cart_Reader/N64.ino index ffaaa84..c8b4cd2 100644 --- a/Cart_Reader/N64.ino +++ b/Cart_Reader/N64.ino @@ -298,6 +298,7 @@ void n64CartMenu() { } } else { + display_Clear(); print_Error(F("Savetype Error"), false); } println_Msg(F("Press Button...")); diff --git a/Cart_Reader/SNES.ino b/Cart_Reader/SNES.ino index abce40a..e7e6f20 100644 --- a/Cart_Reader/SNES.ino +++ b/Cart_Reader/SNES.ino @@ -49,7 +49,7 @@ static const char confMenuItem2[] PROGMEM = "4MB LoRom 256K Sram"; static const char confMenuItem3[] PROGMEM = "4MB HiRom 64K Sram"; static const char confMenuItem4[] PROGMEM = "6MB ExRom 256K Sram"; static const char confMenuItem5[] PROGMEM = "Reset"; -static const char* const menuOptionsConf[] PROGMEM = {confMenuItem1, confMenuItem2, confMenuItem3, confMenuItem4, confMenuItem5}; +static const char* const menuOptionsConfManual[] PROGMEM = {confMenuItem1, confMenuItem2, confMenuItem3, confMenuItem4, confMenuItem5}; // SNES start menu void snsMenu() { @@ -118,19 +118,25 @@ void snesMenu() { { case 0: { - display_Clear(); - // Change working dir to root - sd.chdir("/"); - // get current time - unsigned long startTime = millis(); - // start reading from cart - readROM_SNES(); - compare_checksum(); - // print elapsed time - print_Msg(F("Time elapsed: ")); - print_Msg((millis() - startTime) / 1000); - println_Msg(F("s")); - display_Update(); + if (numBanks > 0) { + display_Clear(); + // Change working dir to root + sd.chdir("/"); + // get current time + unsigned long startTime = millis(); + // start reading from cart + readROM_SNES(); + compare_checksum(); + // print elapsed time + print_Msg(F("Time elapsed: ")); + print_Msg((millis() - startTime) / 1000); + println_Msg(F("s")); + display_Update(); + } + else { + display_Clear(); + print_Error(F("Does not have ROM"), false); + } } break; @@ -239,11 +245,11 @@ void snesMenu() { } // Menu for manual configuration -void confMenu() { +void confMenuManual() { // create menu with title and 5 options to choose from unsigned char subMenu; // Copy menuOptions out of progmem - convertPgm(menuOptionsConf, 5); + convertPgm(menuOptionsConfManual, 5); subMenu = question_box(F("Choose mapping"), menuOptions, 5, 0); // wait for user choice to come back from the question box menu @@ -658,7 +664,7 @@ void getCartInfo_SNES() { // Start manual config if (manualConfig == 1) { - confMenu(); + confMenuManual(); } } @@ -834,7 +840,8 @@ boolean checkcart_SNES() { } // Calculate sramSize - if (sramSizeExp != 0) { + // Fail states usually have sramSizeExp at 255 (no cart inserted, SA-1 failure, etc) + if (sramSizeExp != 0 && sramSizeExp != 255) { sramSizeExp = sramSizeExp + 3; sramSize = 1; while (sramSizeExp--)