   
     // Check for file end
     if (!m64File.available()) {
-        Serial.println(F("End of M64 loaded into buffer"));
+//        screen.println(F("End of M64 loaded into buffer"));
         
         // Set end
         if (!bufferAInUse) {

            // send it
            n64_send(n64_buffer, 1, 1);
            interrupts();
            Serial.println(F("Got a write, what?"));

            // end of time critical code
            // was the address the rumble latch at 0xC000?


static bool finished = false;

//static unsigned int progressPos = 0;
static unsigned long numFrames = 0, curFrame = 0;

#define dirPos curFrame
#define numFiles numFrames
//static unsigned long &dirPos = curFrame, &numFiles = numFrames;

TFT screen = TFT(CS, DC, RESET);

Bounce next;
Bounce select;

static void drawLogo(void)
{
  PImage logo = screen.loadImage("mario.bmp");
  if (!logo.isValid()) {
    screen.println(F("error while loading mario.bmp"));
  }
  screen.image(logo, screen.width() - logo.width(), 0);
  logo.close();
}

static void clear(void)
{
  screen.setCursor(0,0);
  screen.background(0,0,0);
  drawLogo();
}

static bool extMatches(const char *name)
{
  int len = strlen(name);
  if (len < 5)
    return false;

  return !strcmp_P(name + len - 4, PSTR(".M64"));
}

static void drawList()
{
  screen.setCursor(0,0);
  File dir = SD.open(F("/"));
  if (!dir) {
    screen.println(F("Failed to open root"));
    return;
  }
  dir.rewindDirectory();
  int pos = 0;
  for (m64File = dir.openNextFile(); m64File; m64File = dir.openNextFile()) {
    const char *name = m64File.name();
    if (!m64File.isDirectory() && extMatches(name)) {
      if (pos == dirPos) {
        screen.stroke(0,255,0);
        strcpy(n64_raw_dump, name);
      } else {
        screen.stroke(255,255,255);
      }

      screen.println(name);
      pos++;
    }
    m64File.close();
  }
  dir.close();
  numFiles = pos;
  screen.stroke(255,255,255);
}

void setup()
{
  screen.begin();
  screen.background(0,0,0);

  Serial.begin(SERIAL_BAUD_RATE);
  while (!Serial) { ; } // wait for serial port to connect. Needed for native USB port only
  screen.println(F("Starting up"));

  // Status LED
  digitalWrite(STATUS_PIN, LOW);
