public final void clock(long cycles) {
    if (nextCheck > cycles) return;

    autoForward(cycles);

    int delta = (int) (cycles - lastCycles);
    lastCycles = cycles;
    nextCheck = cycles + 13;

    via1T1Ctr = via1T1Ctr - delta;
    if (via1T1Ctr <= 0) {
      if ((via1AuxControl & 0x40) == 0x40) {
        // Increase by latch (to get correct square timing even if not
        // called each cycle!
        via1T1Ctr += via1T1Latch;
      } else {
        // Otherwise wrap around...
        via1T1Ctr &= 0xffff;
      }
      via1IFlag |= 0x40;
      checkInterrupt(1, "clock wrap, T1");
    }

    // Only count in one shot more?
    if ((via1AuxControl & 0x20) == 0) {
      via1T2Ctr = via1T2Ctr - delta;
      if (via1T2Ctr <= 0) {
        via1IFlag |= 0x20;
        via1T2Ctr &= 0xffff;

        checkInterrupt(1, "clock wrap, T2");
      }
    }


    // via 2
    via2T1Ctr = via2T1Ctr - delta;
    if (via2T1Ctr <= 0) {
      if ((via2AuxControl & 0x40) == 0x40) {
        // Increase by latch (to get correct square timing even if not
        // called each cycle!
        via2T1Ctr += via2T1Latch;
      } else {
        // Otherwise wrap around...
        via2T1Ctr &= 0xffff;
      }
      via2IFlag |= 0x40;

      checkInterrupt(2, "clock wrap, T1:  latch:" + via2T1Latch);
    }

    // Only count in one shot more?
    if ((via2AuxControl & 0x20) == 0) {
      via2T2Ctr = via2T2Ctr - delta;
      if (via2T2Ctr <= 0) {
        via2IFlag |= 0x20;
        via2T2Ctr &= 0xffff;

        checkInterrupt(2, "clock wrap, T2");
      }
    }
  }