From 2aa75f02b57d945509c5f2bdc72ad1f1d88ed432 Mon Sep 17 00:00:00 2001
From: sanni <sanni@users.noreply.github.com>
Date: Mon, 15 Aug 2016 15:12:36 +0200
Subject: [PATCH] V17E: Added +500ns delay per byte on SNES reads

That's an added delay of 0.5 seconds per read Megabyte.
---
 Cart_Reader/Cart_Reader.ino | 53 ++++---------------------------------
 Cart_Reader/SNS.ino         | 25 +++++++++++------
 2 files changed, 22 insertions(+), 56 deletions(-)

diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino
index 805263e..683795a 100644
--- a/Cart_Reader/Cart_Reader.ino
+++ b/Cart_Reader/Cart_Reader.ino
@@ -2,15 +2,15 @@
                   Nintendo Cart Reader for Arduino Mega2560
 
    Author:           sanni
-   Date:             2016-07-31
-   Version:          V17D
+   Date:             2016-08-15
+   Version:          V17E
 
    SD  lib:          https://github.com/greiman/SdFat
    LCD lib:          https://github.com/adafruit/Adafruit_SSD1306
    Clockgen:         https://github.com/etherkit/Si5351Arduino
    RGB Tools lib:    https://github.com/joushx/Arduino-RGB-Tools
 
-   Compiled with Arduino 1.6.9
+   Compiled with Arduino 1.6.10
 
    Thanks to:
    MichlK - ROM-Reader for Super Nintendo
@@ -31,7 +31,7 @@
    Pickle - SDD1 fix
 
 **********************************************************************************/
-char ver[5] = "V17D";
+char ver[5] = "V17E";
 
 /******************************************
    Choose Output
@@ -635,15 +635,6 @@ unsigned char question_box(const char* question, char answers[7][20], int num_an
   }
 }
 
-void fileBrowser(const char browserTitle[]) {
-  if (enable_OLED) {
-    fileBrowser_OLED(browserTitle);
-  }
-  if (enable_Serial) {
-    fileBrowser_Serial(browserTitle);
-  }
-}
-
 /******************************************
   Serial Out
 *****************************************/
@@ -678,40 +669,6 @@ byte questionBox_Serial(const char* question, char answers[7][20], int num_answe
   return incomingByte;
 }
 
-// Prompt a filename from the Serial Monitor
-void fileBrowser_Serial(const char browserTitle[]) {
-  Serial.println(browserTitle);
-  // Print all files in root of SD
-  Serial.println(F("Name - Size"));
-  // Rewind filesystem and reset filepath
-  sd.vwd()->rewind();
-  filePath[0] = '\0';
-
-  while (myFile.openNext(sd.vwd(), O_READ)) {
-    if (myFile.isHidden()) {
-    }
-    else {
-      if (myFile.isDir()) {
-        // Indicate a directory.
-        Serial.write('/');
-      }
-      myFile.printName(&Serial);
-      Serial.write(' ');
-      myFile.printFileSize(&Serial);
-      Serial.println();
-    }
-    myFile.close();
-  }
-  Serial.println("");
-  Serial.print(F("Please enter a filename in 8.3 format: _"));
-  while (Serial.available() == 0) {
-  }
-  String strBuffer;
-  strBuffer = Serial.readString();
-  strBuffer.toCharArray(fileName, 13);
-  Serial.println(fileName);
-}
-
 /******************************************
   RGB LED
 *****************************************/
@@ -958,7 +915,7 @@ unsigned char questionBox_OLED(const char* question, char answers[7][20], int nu
 /******************************************
   Filebrowser Module
 *****************************************/
-void fileBrowser_OLED(const char browserTitle[]) {
+void fileBrowser(const char browserTitle[]) {
   char fileNames[30][26];
   int currFile;
   filebrowse = 1;
diff --git a/Cart_Reader/SNS.ino b/Cart_Reader/SNS.ino
index 07f10d3..619b101 100644
--- a/Cart_Reader/SNS.ino
+++ b/Cart_Reader/SNS.ino
@@ -310,8 +310,8 @@ byte readBank_SNES(byte myBank, word myAddress) {
   PORTF = myAddress & 0xFF;
   PORTK = (myAddress >> 8) & 0xFF;
 
-  // Arduino running at 16Mhz -> one nop = 62.5ns
-  __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+  // Arduino running at 16Mhz -> one nop = 62.5ns -> 1000ns total
+  __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
 
   // Read
   byte tempByte = PINC;
@@ -429,6 +429,10 @@ void getCartInfo_SNES() {
     wait();
   }
 
+  else if (enable_Serial) {
+    println_Msg(F(" "));
+  }
+
   // Start manual config
   if (manualConfig == 1) {
     confMenu();
@@ -965,6 +969,16 @@ void readSRAM () {
   sd.mkdir(folder, true);
   sd.chdir(folder);
 
+  // Signal end of process
+  print_Msg(F("Reading to SAVE/"));
+  print_Msg(romName);
+  print_Msg(F("/"));
+  print_Msg(foldern);
+  print_Msg(F("/"));
+  print_Msg(fileName);
+  print_Msg(F("..."));
+  display_Update();
+
   // write new folder number back to eeprom
   foldern = foldern + 1;
   EEPROM_writeAnything(0, foldern);
@@ -1012,12 +1026,7 @@ void readSRAM () {
   myFile.close();
 
   // Signal end of process
-  print_Msg(F("Saved to SAVE/"));
-  print_Msg(romName);
-  print_Msg(F("/"));
-  print_Msg(foldern - 1);
-  print_Msg(F("/"));
-  println_Msg(fileName);
+  println_Msg(F("Done"));
   display_Update();
 }