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., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
23 #include "libc/string.h"
24 #include "asm/types.h"
29 #define KBD_DPRINTF(fmt, args...) \
30 do { printk("KBD - %s: " fmt, __func__ , ##args); } while (0)
32 #define KBD_DPRINTF(fmt, args...) do { } while (0)
35 int kbd_set_keymap (kbd_t *kbd, int nb_keys, const keymap_t *keymap, const char **sequences)
37 kbd->nb_keys = nb_keys;
39 kbd->sequences = sequences;
44 int kbd_translate_key (kbd_t *kbd, int keycode, int up_down, char *sequence)
47 int mod_state, key, type;
52 if (keycode < kbd->nb_keys) {
53 keyt = &kbd->keymap[keycode];
54 /* Get modifier state */
55 mod_state = (kbd->mod_state | (kbd->mod_state >> 8)) & 0xFF;
56 /* Adjust with lock */
57 if (keyt->lck_shift >= 0) {
58 if ((kbd->mod_state >> (16 + keyt->lck_shift)) & 0x01) {
59 KBD_DPRINTF("adjust with lock %02x => %02x (%d %08x)\n",
61 mod_state ^ ((kbd->mod_state >>
62 (16 + keyt->lck_shift)) &
64 keyt->lck_shift, kbd->mod_state);
66 mod_state ^= (kbd->mod_state >> (16 + keyt->lck_shift)) & 0x01;
68 key = keyt->trans[mod_state];
69 type = key & 0xFF000000;
72 case KBD_TYPE_REGULAR:
74 /* We don't care about up events on "normal" keys */
79 case KBD_TYPE_SEQUENCE:
81 /* We don't care about up events on "normal" keys */
82 ret = strlen(kbd->sequences[key]);
83 memcpy(sequence, kbd->sequences[key], ret);
88 kbd->mod_state ^= key;
90 KBD_DPRINTF("Change modifier type %d key %04x %s => %08x\n",
91 type, key, up_down ? "up" : "down",
98 kbd->mod_state &= ~key;
100 kbd->mod_state |= key;
101 KBD_DPRINTF("Change modifier type %d key %04x %s => %08x\n",
102 type, key, up_down ? "up" : "down", kbd->mod_state);
103 ret = -2; /* The caller may know the key was a modifier */
106 KBD_DPRINTF("Unknown key: keycode=%02x mod_state=%02x (%08x)\n",
107 keycode, mod_state, kbd->mod_state);
111 KBD_DPRINTF("Unmanaged key: keycode=%02x mod_state %08x\n",
112 keycode, kbd->mod_state);