cpct_isKeyPressed

Checks if a concrete key is pressed or not.

C Definition

u8 cpct_isKeyPressed (cpct_keyID key);

Input Parameters (2 Bytes)

(2B HL) keyA 16-bit value containing a Matrix-Line(1B, L) and a BitMask(1B, H).

Assembly call (Input parameters on registers)

call cpct_isKeyPressed_asm

Parameter Restrictions

  • key (HL) must be a valid cpct_keyID, containing a Matrix Line (1st byte, 0-9) and a Bit Mask (2nd byte, only 1 bit enabled).  All keyID values are defined in cpct_keyID enum.  Giving any other value is possible, but returned value would be meaningless.  If given value asks for a Matrix Line greater than 9, unexpected results may happen.

Return value (for Assembly, L=A=key_status)

<u8>false (0, if not pressed) or true (>0, if pressed).  Take into account that true is not 1, but any non-0 number.

Details

Checks if a concrete key is pressed or not.  It does it looking at the cpct_keyboardStatusBuffer, which is an 80-bit array holding the pressed / not pressed status of each of the 80 keys in the CPC keyboard.  Matrix Line is used to determine which of the 10 bytes in the buffer contains the bit associated to the key, then Bit Mask is used to get the concrete bit using XOR and AND operations.

The cpct_keyboardStatusBuffer is just an array in memory that must be updated with current key status.  To do this, cpct_scanKeyboard routines must be used before calling this function.

Destroyed Register values

A, D, BC, HL

Required memory

12 bytes

Time Measures

  Case      | microSecs (us) | CPU Cycles
-------------------------------------------
Any         |      14        |    56
-------------------------------------------
unsigned char (u8 = unsigned 8-bits, 1 byte )
Checks if a concrete key is pressed or not.
Enumerated type with symbols for all the 80 possible Key/Joy definitions.
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
Close