Difference between revisions of "Programming:Keyboard scanning"
From CPCWiki - THE Amstrad CPC encyclopedia!
(added routine for complete keyboard scanning) |
m |
||
Line 1: | Line 1: | ||
== Hardware scancode table == | == Hardware scancode table == | ||
{|{{Prettytable|width: 700px; font-size: 2em;}} | {|{{Prettytable|width: 700px; font-size: 2em;}} | ||
− | |''' | + | |'''Bit:<br>Line''' || '''7''' || '''6''' || '''5''' || '''4''' || '''3''' || '''2''' || '''1''' || '''0''' |
|- | |- | ||
|'''&40''' || (ZB) || ENTER || F3 || F6 || F9 || CURDOWN || CURRIGHT || CURUP | |'''&40''' || (ZB) || ENTER || F3 || F6 || F9 || CURDOWN || CURRIGHT || CURUP | ||
Line 28: | Line 28: | ||
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. | 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 = '' | + | '''Input:''' A = ''line (&40 - &49) |
'''Output:''' A = ''hardware keyboard value'' | '''Output:''' A = ''hardware keyboard value'' | ||
Line 35: | Line 35: | ||
<pre> | <pre> | ||
− | ld a, | + | ld a, line ;use the value from the table above |
ld bc, &F6C0 | ld bc, &F6C0 | ||
out (c), c | out (c), c | ||
Line 53: | Line 53: | ||
Now check for the value from the table | Now check for the value from the table | ||
− | e.g. with''' ' | + | e.g. with''' 'bit x,A' ''' |
and a condition | and a condition | ||
− | e.g.''' 'jp | + | e.g.''' 'jp z,xxxx' '''or''' 'call z,xxxx' ''' |
Please note: | Please note: |
Revision as of 08:11, 27 August 2006
Hardware scancode table
Bit: Line |
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
&40 | (ZB) | ENTER | F3 | F6 | F9 | CURDOWN | CURRIGHT | CURUP |
&41 | F0 | F2 | F1 | F5 | F8 | F7 | COPY | CURLEFT |
&42 | CONTROL | \ | SHIFT | F4 | ] | RETURN | [ | CLR |
&43 | . | / | : | ; | P | @ | - | ^ |
&44 | , | M | K | L | I | O | 9 | 0 |
&45 | SPACE | N | J | H | Y | U | 7 | 8 |
&46 | V | B | F | G | T | R | 5 | 6 |
&47 | X | C | D | S | W | E | 3 | 4 |
&48 | Z | CAPSLOCK | A | TAB | Q | ESC | 2 | 1 |
&49 | DEL | - | - | - | - | - | - | - |
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 = line (&40 - &49)
Output: A = hardware keyboard value
Destroyed: BC
ld a, line ;use the value from the table above ld bc, &F6C0 out (c), c ld bc, &F40E out (c), c ld bc, &F792 out (c), c ld b, &F6 out (c), c ld b, &F4 in a, (c) ld bc, &F782 out (c), c ld bc, &F600 out (c), c
Now check for the value from the table e.g. with 'bit x,A' and a condition e.g. 'jp z,xxxx' or 'call z,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.
keymap ds 10 ;map with 10*8 = 80 key status bits (bit=0 key is pressed) keyscan di ;1 ##%%## C P C VERSION ##%%## ld hl,keymap ;3 ld bc,#f782 ;3 out (c),c ;4 ld bc,#f40e ;3 ld e,b ;1 out (c),c ;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,#40 ;2 ld c,#4a ;2 44 loop ld b,d ;1 out (c),a ;4 select line ld b,e ;1 ini ;5 read bits and write into KEYMAP inc a ;1 cp c ;1 jr c,loop ;2/3 9*16+1*15=159 ld bc,#f782 ;3 out (c),c ;4 ei ;1 8 =211 microseconds ret