cpct_scanKeyboard_i

Reads the status of keyboard and joysticks and stores it in the 10 bytes reserved as cpct_keyboardStatusBuffer.  (Interrupt-Unsafe version)

C Definition

void cpct_scanKeyboard ()

Output results (10 bytes)

cpct_keyboardStatusBuffer filled up with pressed / not pressed info about all the 80 available Amstrad CPC’s keys / buttons.

Assembly call

call cpct_scanKeyboard_i_asm

Known limitations

  • This function may not work properly if an interrupt occurs during the execution of this code.  You should use this function always in interrupt-safe places (inside an Interrupt Service Routine (ISR), for instance)

Details

This function reads the pressed / not pressed status of the entire set of 80 keys / buttons from the Amstrad CPC and writes this status in cpct_keyboardStatusBuffercpct_keyboardStatusBuffer is a 10-bytes buffer (80 bits) that holds 1 bit for each key / button of the Amstrad CPC, meaning 0 = pressed, and 1 = not pressed.  This codification is the same as the one returned by the AY-3-8912 chip, which reads the keyboard when Programmable Peripheral Interface (PPI) chip demands it.  For more details on how all this process works, check Keyboard topic.

The function does not disable nor reenable interrupts (contrary to what cpct_scanKeyboard does).  This means that this function is Interrupt-Unsafe.  If an interrupt happens during the execution of this function’s code, the output may be corrupt.  To prevent this from happening, you should ensure that this function is called only in interrupt-safe places.  You may call in a syncronized part of your code, knowing that no interrupt will happen there, inside a manually disabled interrupts section, or inside an interrupt service routine.  In any case, is up to you to ensure that no interrupt happens during key scanning.

Destroyed Register values

AF, BC, DE, HL

Required memory

47 bytes

Time Measures

Case | microSecs (us) | CPU Cycles
------------------------------------
Any  |     210        |    840
------------------------------------

Credits

This fragment of code is based on a scanKeyboard code issued by CPCWiki.  http://www.cpcwiki.eu/index.php/Programming:Keyboard_scanning.  This version of the code is, however, 4 microseconds faster than CPCWiki’s (207 vs 211, excluding the 3 microseconds from the ret instruction)

extern u8 cpct_keyboardStatusBuffer[10]
10-bytes (80-bits) array containing pressed / not pressed status of all the keys / buttons the Amstrad CPC can manage (up to 80).
Reads the status of keyboard and joysticks and stores it in the 10 bytes reserved as cpct_keyboardStatusBuffer
Keyboard and joystick are connected to AY-3-8912 Programmable Sound Generator (PSG) which receives, processes and stores pressed / not pressed information.
Close