As far as I could understand:
exec6502() , scanKeys() and Serial.available() are executed regularly in the Arduino loop().
The CPU emulation exec6502() executes 100 instructions each time is called.
The key debounce time is associated with the duration of this main loop.
New key inputs can come from the keypad or the serial port.
In the 6502 cpu emulation:
- Any read memory to the GETKEY address (0x1F6A in the KIM monitor) is intercepted to check for a new key.
- Also, any read to the keyboard input port address (0x1740, Port A of the 6530-002 RIOT) signals the emulation to check the keypad as the source.
In any case @oscarv is the wizard behind this.