== Key redefinition library ==
This is a little library to allow you to scan keyboard, test keys and redefine them.Functions are explained in source code.
Keycodes returned by GetPressed and used for IsPressed/GetMask are the same than firmware keycodes (you know the one you have on disc plate on CPC 664/6128)
For performance , it is possible to compute directly offset and mask in keyboard buffer with GetMask function.This is usefull for game as IsPressed function can be considered as slow.
As SHIFT or CONTROL status can be a problem , you can inhibate them using IgnoreSHITFCTRL.
<pre>
;simple keyboard module
ret
;check if there is a key is down at (HL);only the first key found is returned
;return carry is a key is down
;return key code in A : key code = (line*8)+bit
GetPressed
push HL
ld C,10.loop_col
ld B,8
ld A,(HL++).loop_bit rla jr nc,.pressed
djnz .loop_bit
dec C
rrca
rrca
ld E,A ld D,0
add HL,DE
;so we get the address
pop AF;now get the
and 7
inc A
.loop
rra ;get bit in carry
djnz .loop
ccf ;reverse bit
pop HL
ENDMODULE</pre>
[[Category:Programming]]