     Serial.println(":Entering terminal mode");
     Serial.println(":Exit with Ctrl-D");
     char next = 0, last;
-    byte out;
     bool ansi = false;
     for (;;) {
       if (Serial.available()) {
+        byte out;
         last = next;
         next = Serial.read();
         sendEcho(next, last);

void loop()
{
  // Check Gigatron's vPulse for incoming data
  static byte inByte, inBit, hasChars;

  critical();
  byte newValue = waitVSync();
  nonCritical();

  switch (newValue) {
    case 9:                            // Received one bit
      inByte |= inBit;
      // !!! FALL THROUGH !!!
    case 7:                            // Received zero bit
      inBit <<= 1;

      if (saveIndex >= EEPROM_length)  // EEPROM overflow
        if (hasChars)                  // Only break if this isn't an empty line
          sendController(3, 10);       // Send long Ctrl-C back to stop LIST

      if (inBit != 0)                  // Still a partial byte
        break;

      EEPROM.write(saveIndex++, inByte);// Store every full byte

      #if hasSerial
        if (inByte == 10)
          Serial.print('\r');
        Serial.print((char)inByte);    // Forward to host
        noInterrupts();
      #endif

      if (inByte == 10) {              // End of line?
        EEPROM.write(saveIndex, 255);  // EOF terminator, in case this becomes the last line
        if (!hasChars)                 // An empty line clears the old program
          saveIndex = fileStart;
        hasChars = false;
      } else if (inByte != 13)         // Don't count CR towards line length
        hasChars = true;

      inByte = 0;                      // Prepare for next byte
      inBit = 1;
      break;

    default:
      inByte = 0;                      // Reset incoming data state
      inBit = 1;
      hasChars = false;
      break;
  }

  // Game controller pass through (Courtesy norgate)

  return count;
}

// For polling the game controller
void sendPulse(byte pin)
{
  digitalWrite(pin, HIGH);
