 bool detectGigatron()
 {
   unsigned long timeout = millis() + 85;
-  long T[] = {0, 0, 0, 0};
+  long T[2][2] = {{0, 0}, {0, 0}};
 
   // Sample the sync signals coming out of the controller port
-  while (millis() < timeout)
-    T[(PINB >> PORTB3) & 3]++; // capture PORTB3 and PORTB4
-
-  float S = T[0] + T[1] + T[2] + T[3] + .1; // Avoid zero division (pedantic)
-  float vSync = (T[0] + T[1]) / ( 8 * S / 521); // Adjusted vSync signal
-  float hSync = (T[0] + T[2]) / (96 * S / 800); // Standard hSync signal
+  while (millis() < timeout) {
+    byte pinb = PINB; // capture SER_PULSE and SER_LATCH at the same time
+    T[ (pinb>>SER_LATCH)&1 ][ (pinb>>SER_PULSE)&1 ]++;
+  }
+
+  float S = T[0][0] + T[0][1] + T[1][0] + T[1][1] + .1; // Avoid zero division (pedantic)
+  float vSync = (T[0][0] + T[0][1]) / ( 8 * S / 521); // Adjusted vSync signal
+  float hSync = (T[0][0] + T[1][0]) / (96 * S / 800); // Standard hSync signal
 
   // Check that vSync and hSync characteristics look normal
   return 0.95 <= vSync && vSync <= 1.20 && 0.95 <= hSync && hSync <= 1.05;

// XXX Keyboard: Is it possible to mimic key hold-down properly???
// XXX Embed a Gigatron Terminal program. Or better: GigaMon

const byte gt1File[] PROGMEM = {
  //#include "Blinky.h" // Blink pixel in middle of screen
  #include "Lines.h"    // Draw randomized lines
};

/*
 *  Link to Gigatron using its serial game controller port
 */

// Arduino AVR    Gigatron Schematic Controller PCB
// Uno     Name   OUT bit            CD4021     74HC595 (U39)
// ------- ------ -------- --------- ---------- ----------------
// Pin 13  PORTB5 None     SER_DATA  11 SER INP 14 SER
// Pin 12  PORTB4 7 vSync  SER_LATCH  0 PAR/SER None
// Pin 11  PORTB3 6 hSync  SER_PULSE 10 CLOCK   11 SRCLK 12 RCLK

// Game controller button mapping. The kit's controller gives inverted signals.
#define buttonRight  1
#define buttonLeft   2
#define buttonDown   4


// Concept tester for interfacing with the
// Gigatron TTL microcomputer

// Select 1 of the platforms
#define ArduinoUno   1
#define ArduinoMicro 0
#define ATtiny85     0

// Select a built-in GT1 image
const byte gt1File[] PROGMEM = {
  //#include "Blinky.h" // Blink pixel in middle of screen
  #include "Lines.h"    // Draw randomized lines (at67)
};

// The object file is embedded (in PROGMEM) in GT1 format. It would be
// GREAT if we can find a way to receive the file over the Arduino's
