6 #define KBD_STATUS 0x64
8 #define KBD_BUF_SIZE 16
9 static int kbd_buf
[KBD_BUF_SIZE
];
10 static int kbd_buf_head
, kbd_buf_tail
;
12 void kbd_cmd(unsigned char cmd
)
14 while (inb(KBD_STATUS
) & 0x2);
17 while ((inb(KBD_STATUS
) & 0x1) == 0);
23 while (inb(KBD_STATUS
) & 0x1) {
30 static void kbd_queue_key(int scancode
)
32 if ((kbd_buf_head
+ 1) % KBD_BUF_SIZE
== kbd_buf_tail
) {
33 /* Buffer full, ignore keypress */
37 kbd_buf
[kbd_buf_head
] = scancode
;
38 kbd_buf_head
= (kbd_buf_head
+ 1) % KBD_BUF_SIZE
;
41 int kbd_wait_key(void)
45 while (kbd_buf_head
== kbd_buf_tail
) {
49 ret
= kbd_buf
[kbd_buf_tail
];
50 kbd_buf_tail
= (kbd_buf_tail
+ 1) % KBD_BUF_SIZE
;
59 } kbd_state
= KBD_STATE_NORMAL
;
61 int scancode
= inb(KBD_DATA
);
64 case KBD_STATE_NORMAL
:
65 if (scancode
== 0xe0) {
66 kbd_state
= KBD_STATE_E0
;
69 if (scancode
& 0x80) {
70 /* Ignore break codes */
73 kbd_queue_key(scancode
);
77 kbd_state
= KBD_STATE_NORMAL
;
78 if (scancode
& 0x80) {
79 /* Ignore break codes */
82 kbd_queue_key(0x100 | scancode
);