[Coco] CoCo 3 keyboard interrupt

William Astle lost at l-w.ca
Sun Oct 28 13:03:16 EDT 2018


On 2018-10-27 9:36 p.m., Joel Rees wrote:
> Interrupts for unbuffered, undecoded keyboards is generally not a good
> idea, really, even for using them as game controllers. If you were to have
> a keyboard interrupt, you'd want it to interrupt on every transition of any
> of the keyboard pins, but you'd want the transitions properly debounced so
> that switch noise wouldn't tie up the CPU.

I wonder if they intended, in the early stages, to switch to a keyboard 
scheme where the keyboard provided scan codes and then realized it would 
both cost quite a bit more and create massive incompatibility because a 
great deal of software doesn't use the POLCAT ROM routine. Then some 
bright spark thought, why can't we have a keyboard interrupt anyway? And 
you get what we have. Which is probably about the best you can do 
without replacing the PIA with something else.

Either way, you can potentially save a few cycles in the IRQ handler by 
enabling the keyboard interrupt and tying it to the other interrupt 
(FIRQ probably). Then the FIRQ handler would set a flag for the IRQ to 
start scanning the keyboard and disable the keyboard interrupt. The IRQ 
routine would just have to test a single flag and if set, do the scan 
and once it has determined that nothing is pressed, re-enable the 
keyboard interrupt on the FIRQ. That saves a few cycles while the 
keyboard is idle since testing for a any keypress at all is several 
instructions long (strobe all columns, read the rows, complement the 
result, and mask off the comparator bit) compared to a single load/test 
instruction on a flag set by the FIRQ.

That said, the saving is very minor and it comes at the cost of extra 
code complexity. And, if you use the IRQ for both the regular 60Hz tick 
and the keyboard interrupt, you save less (possibly nothing) because you 
have to test which interrupt source caused the interrupt.

Basically, it's a novelty that is useful in some (probably quite rare) 
edge cases but otherwise not so much. Either way, it's still good to 
have emulators get it right. (I wouldn't be surprised if a demo 
somewhere uses it.)


More information about the Coco mailing list