Difference between revisions of "KEYV"

From BeebWiki
Jump to: navigation, search
m (Corrected category.)
m (Adjusted formatting.)
 
Line 1: Line 1:
 
[[Category:MOS API]]
 
[[Category:MOS API]]
 
==Specification==
 
==Specification==
This vector is only called by the operating system to do keyboard processing, and can
+
This vector is only called by the operating system to do keyboard processing,
be called by user programs through the relevant OSBYTE calls to read keyboard
+
and can be called by user programs through the relevant OSBYTE calls to read
information.
+
keyboard information.
 
   
 
   
 
   On entry:
 
   On entry:

Latest revision as of 20:05, 8 October 2021

Specification

This vector is only called by the operating system to do keyboard processing, and can be called by user programs through the relevant OSBYTE calls to read keyboard information.

 On entry:
   VS=Keyboard interupt
      CC=Keypress interupt
      CS=Centisecond keypress poll
   VC=Scan keyboard for keypresses
      CC=Test SHIFT and CTRL keys
      CS=Scan full keyboard
   All registers can be trashed by the handler

VS+CC - Keypress interupt

The keyboard hardware has caused an interrupt, the MOS has called the keyboard handler to deal with it. The handler should clear the interupt, scan the keyboard to find which key has been pressed, and set up for the timer entry. All registers can be trashed.

VS+CS - Centisecond keypress poll

Once a key has been pressed, the MOS calls the keyboard handler every 1cs to read the keypress, debounce it, deal with rollover and repeats, and enter bytes into the keyboard buffer.

The handler should update the keyboard status variable with the state of SHIFT and CTRL and other modifier keys, debounce the keypress, if it is different from the previous keypress cancel the previous keypress and reset the repeat counter, else update the repeat counter. The keypress should be translated to an ASCII key, and inserted into the keyboard buffer, checking for the current Escape character. All registers can be trashed.

VC+CC - Test SHIFT and CTRL keys

OSBYTE &76 or various parts of the MOS have called to read the state of the SHIFT and CTRL keys. An example is the VDU driver testing CTRL and SHIFT for pausing text output.

The driver should update the state of the keyboard LEDs to match the state of the keyboard, and test the state of the CTRL and SHIFT keys.

On exit: MI=Control, VS=Shift, A.b7=Control, A.b6=Shift

As various callers either use the flags or the A register on return, they must match. The easiest way to do this is to set the flags then end the routine with PHP:PLA:RTS to copy the flags into bit 7 and bit 6 of A. You must not copy the other way as that will set the other flags to indeterminate values. The X and Y registers may be trashed.

Note that these flags are returned to OSBYTE &76, but then the OSBYTE handler uses the flags for other purposes. The only result returned by OSBYTE &76 is X.b7=CTRL pressed, so OSBYTE &76 is normally documented as Update state of keyboard LEDs. SHIFT and CTRL would normally be read the normal way with INKEY-1 and INKEY-2.

VC+CS - Scan full keyboard

OSBYTE &79, OSBYTE &7A or OSBYTE &81 has been called to to do a negative INKEY keyscan.

On entry: X=&00-&7F scan range, X=&80-&FF scan for single keypress

On exit: A=X=bit 7 set if key pressed, Y can be trashed

As various callers either test the X register or the A register on return, they must match. The simplest way to do this is to end your routine with TXA:RTS or TAX:RTS as appropriate.