   Serial.println(dat[3], HEX);
 }
 
+static bool setPinMode(const String& cmd)
+{
+  if (cmd.length() < 3)
+    return false;
+  if (cmd[1] != ':')
+    return false;
+
+  int pinNumber = cmd.substring(2).toInt();
+
+  if (cmd[0] == 'I')
+    pinMode(pinNumber, INPUT);
+  else if (cmd[0] == 'O')
+    pinMode(pinNumber, OUTPUT);
+  else if (cmd[0] == 'U')
+    pinMode(pinNumber, INPUT_PULLUP);
+  else if (cmd[0] == 'D')
+    pinMode(pinNumber, INPUT_PULLDOWN);
+  else
+    return false;
+
+  return true;
+}
+
+static bool writePin(const String& cmd)
+{
+  if (cmd.length() < 3)
+    return false;
+  if (cmd[1] != ':')
+    return false;
+
+  int pinNumber = cmd.substring(2).toInt();
+
+  if (cmd[0] == '0')
+    digitalWrite(pinNumber, LOW);
+  else if (cmd[0] == '1')
+    digitalWrite(pinNumber, HIGH);
+  else
+    return false;
+
+  return true;
+}
+
 static FatFile writeFile;
 
-const bool skippingInput = false;
+bool skippingInput = false;
 static String inputString;
 
 static void handleCommand(const String& cmd)

static char n64_raw_dump[36]; // maximum recv is 1+2+32 bytes + 1 bit
// n64_raw_dump does not include the command byte. That gets pushed into
// n64_command:
static unsigned char n64_command;
// bytes to send to the 64
// maximum we'll need to send is 33, 32 for a read request and 1 CRC byte
static unsigned char n64_buffer[33];

      if (skippingInput)
        Serial.println("Skipped line longer than 256 chars");
      else
        handleCommand(inputString);
      inputString = "";
      skippingInput = false;
    } else if (inputString.length() > 256) {
      skippingInput = true;
    } else {
      inputString += (char)newChar;
    }
  }
}

static void waitForIdle(int us)
{
  LED_HIGH;
  N64_HIGH;
  startTimer();
  int lastReset = 0;
  while (readTimer() - lastReset < us * MICRO_CYCLES && readTimer() < us * MICRO_CYCLES * 4) {
    if (!N64_QUERY)
      lastReset = readTimer();
  }
  LED_LOW;
}

static void mainLoop()
