Help with interrupts firing inconsistently

Hi, I’m working on implementing a Super Nintendo controller with the eventual goal of making a USB mouse to Super Nintendo mouse adapter.

I’ve been having issues with the interrupt on the latch pin firing every time the console sends the latch signal, oddly my clock interrupts seem to be fine because I can consistently get the same button to fire it just doesn’t stay “held down” because I’m not responding to all the latch calls.

Is there something I could be doing better? Or maybe something in Arduino is taking up extra time and superseding my interrupts.

I’m currently using a ATSAMD21E18 on the Trinket Pro since it has USB host support.

SNES protocol if anyone is interested: Sci.Electronics FAQ: Repair: SNES Protocols

Thanks!

Here is my current code:

#include "samd21/include/samd21e18a.h"

const byte ledPin = 13;
const byte latchPin = 0;
const byte clockPin = 1;
const byte dataPin = 2;

volatile byte controllerData[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
volatile int clockCycle = 0;

byte stateLight = 0;

void blink() {
  controllerData[5] = !controllerData[5];
}

byte latchState = 0;

void latch() {
  clockCycle = 0;
  setData();
}

void snesClock() {
  clockCycle++;

  if (clockCycle < 16) {
    setData();
  }
  else {
    PORT->Group[0].OUTSET.reg = (1<<9);
  }
}  

void setData() {
  if (controllerData[clockCycle]) {
    PORT->Group[0].OUTCLR.reg = (1<<9);
  }
  else {
    PORT->Group[0].OUTSET.reg = (1<<9);
  }
}

int main( void ) {
  pinMode(3, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(3), blink, CHANGE);

  pinMode(latchPin, INPUT_PULLUP);
  pinMode(clockPin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

  digitalWrite(dataPin, HIGH);

  attachInterrupt(digitalPinToInterrupt(latchPin), latch, FALLING);
  attachInterrupt(digitalPinToInterrupt(clockPin), snesClock, RISING);
  
  while(true) {
    
  }

  return 0;
}