4 * Open Hack'Ware BIOS generic keyboard input translation.
6 * Copyright (c) 2005 Jocelyn Mayer
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License V2
10 * as published by the Free Software Foundation
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #define KBD_DPRINTF(fmt, args...) \
30 do { dprintf("KBD - %s: " fmt, __func__ , ##args); } while (0)
32 #define KBD_DPRINTF(fmt, args...) do { } while (0)
35 void *kbd_new (int len)
39 if (len < (int)sizeof(kbd_t)) {
50 int kbd_set_keymap (kbd_t *kbd, int nb_keys, keymap_t *keymap)
52 kbd->nb_keys = nb_keys;
58 int kbd_translate_key (kbd_t *kbd, int keycode, int up_down)
61 int mod_state, key, type;
66 if (keycode < kbd->nb_keys) {
67 keyt = &kbd->keymap[keycode];
68 /* Get modifier state */
69 mod_state = (kbd->mod_state | (kbd->mod_state >> 8)) & 0xFF;
70 /* Adjust with lock */
71 if (keyt->lck_shift >= 0) {
72 if ((kbd->mod_state >> (16 + keyt->lck_shift)) & 0x01) {
73 KBD_DPRINTF("adjust with lock %02x => %02x (%d %08x)\n",
75 mod_state ^ ((kbd->mod_state >>
76 (16 + keyt->lck_shift)) &
78 keyt->lck_shift, kbd->mod_state);
80 mod_state ^= (kbd->mod_state >> (16 + keyt->lck_shift)) & 0x01;
82 key = keyt->trans[mod_state];
83 type = key & 0xFF000000;
86 case KBD_TYPE_REGULAR:
88 /* We don't care about up events on "normal" keys */
94 kbd->mod_state ^= key;
96 KBD_DPRINTF("Change modifier type %d key %04x %s => %08x\n",
97 type, key, up_down ? "up" : "down",
104 kbd->mod_state &= ~key;
106 kbd->mod_state |= key;
107 KBD_DPRINTF("Change modifier type %d key %04x %s => %08x\n",
108 type, key, up_down ? "up" : "down", kbd->mod_state);
109 ret = -2; /* The caller may know the key was a modifier */
112 KBD_DPRINTF("Unknown key: keycode=%02x mod_state=%02x (%08x)\n",
113 keycode, mod_state, kbd->mod_state);
117 KBD_DPRINTF("Unmanaged key: keycode=%02x mod_state %08x\n",
118 keycode, kbd->mod_state);