If I modify the program and remove the main() loop to drop back to BASIC when the program quits the keyboard handler works for about 2 seconds then seems to go dead.
Reading through some docs I suppose this is because the IRQ handler has intefered with the keyboard handler code and therefore the vector for the handler is no longer being processed. I wonder if it would be possible to add another chain command to include the default keyboard handler vector?
Mmmm... I don't know what might be going on, but I assume that exiting C and getting back to BASIC while a C function is running as Interrupt Service routine might not be a good idea. I know that C uses page zero to implement registers and temporal variables as well as pointers to the C stack, which is kept in main memory. However once you exit... who knows.
There is no such thing as keyboard handler vector or other nice vectors as such. I think there is a service routine in the ROM which is called to handle all this, so if you are using chain_irq_vector it should be calling both that routine and your function. You also cannot change the pace at which IRQs occur. You can, however, have a variable to count the number of IRQs and act accordingly.
As allways it is nearly a must to write the routine in asm to be sure it works.
I expect without this change my program would need to monitor the memory locaiton of the last key pressed rather than use the getchar() funciton.
I think I do not get the point of this sentence. I think the getchar function calls a ROM routine which does exactly this: see if a key was pressed and return the code or wait if it is not the case. The actual keyboard scanning is done in the default IRQ (please somebody explain this). Other C functions as keyb (is it implemented?) return inmediately both if a key is pressed or not.
FYI what I do in asm is having a ProcessKeyboard function which calls the ROM (though a page 2 pointer, I think) to see if a key is pressed and do what is needed. If a key is not pressed it returns inmediately:
If a keyb function is not implemented, you can directly call that routine. Addint such a function in C shouldn't be too difficult, as $023B returns in reg A the keycode (in ascii, IIRC, so directly as a char). If the return value is negative, then no key was pressed.