Changes

Jump to: navigation, search

Programming:Keyboard scanning

1,149 bytes added, 12:57, 27 August 2006
added routine for complete keyboard scanning
This is a routine which scans the keyboard directly. It is approximately 8% faster then the firmware routine and doesn't enable interrupts.
 
'''Input:''' A = ''layer (&40 - &49)
 
'''Output:''' A = ''hardware keyboard value''
 
'''Destroyed:''' BC
 
 
== Hardware scancode table ==
{|{{Prettytable|width: 700px; font-size: 2em;}}
|}
== Scanning One line scanning routine == This is a routine which scans one line of the keyboard directly. It is approximately 8% faster then the firmware routine and doesn't enable interrupts. '''Input:''' A = ''layer (&40 - &49) '''Output:''' A = ''hardware keyboard value'' '''Destroyed:''' BC 
<pre>
ld a, layer ;use the value from the table above
ld bc, &F600
out (c), c
</pre>
 
Now check for the value from the table
e.g. with''' 'cp <value>' '''
and a condition
e.g.''' 'jp <condition>, xxxx' '''or''' 'call <condition>, xxxx' '''
 
Please note:
* Bit = 0: Key is pressed
* Bit = 1: Key is not pressed
 
 
== Complete keyboard scanning routine ==
 
This routine scans the complete keyboard and writes all key status bits in a map.
 
<pre>
keymap ds 10 ;map with 10*8 = 80 key status bits (bit=0 key is pressed)
keyscan di ;now check for the value from the table1 ##%%## C P C VERSION ##%%## ld hl,keymap ;3 ld bc,#f782 ;3 out (c),c ;4 ld bc,#f40e ;3 ld e.g. with 'cp <value>',b ;1 out (c),c ;and 4 ld bc,#f6c0 ;3 ld d,b ;1 out (c),c ;4 ld c,0 ;2 out (c),c ;4 ld bc,#f792 ;3 out (c),c ;4 ld a condition,#40 ;2 ld c,#4a ;2 44loop ld b,d ;1 out (c),a ;4 select line ld b,e.g. 'jp <condition> ;1 ini ;5 read bits and write into KEYMAP inc a ;1 cp c ;1 jr c, xxxx' or 'call <condition>loop ;2/3 9*16+1*15=159 ld bc, xxxx'#f782 ;3 out (c),c ;4 ei ;1 8 =211 microseconds ret
</pre>