Received: from eggs.gnu.org ([2001:4830:134:3::10]:43642) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aasVA-0005nW-0n for qemu-devel@nongnu.org; Tue, 01 Mar 2016 17:10:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aasV5-0000XU-15 for qemu-devel@nongnu.org; Tue, 01 Mar 2016 17:10:43 -0500 Received: from mail-ig0-x230.google.com ([2607:f8b0:4001:c05::230]:38337) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aasV4-0000XP-Pt for qemu-devel@nongnu.org; Tue, 01 Mar 2016 17:10:38 -0500 Received: by mail-ig0-x230.google.com with SMTP id y8so29187984igp.1 for ; Tue, 01 Mar 2016 14:10:38 -0800 (PST) From: Programmingkid Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Date: Tue, 1 Mar 2016 17:10:35 -0500 Message-Id: <801CD73C-2AB1-4421-9C09-1F7AE46AA272@gmail.com> Mime-Version: 1.0 (Apple Message framework v1084) Subject: [Qemu-devel] [PATCH] hw/input/adb.c: Replace pc_to_adb_keycode with more detailed array List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell , qemu-devel qemu-devel The pc_to_adb_keycode array was not very easy to work with. The = replacement array number_to_adb_keycode list all the element indexes on the left and = its value on the right. This makes finding a particular index or the meaning = for that index very easy. Signed-off-by: John Arbuckle --- hw/input/adb.c | 142 = +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 121 insertions(+), 21 deletions(-) diff --git a/hw/input/adb.c b/hw/input/adb.c index f0ad0d4..58ab1a0 100644 --- a/hw/input/adb.c +++ b/hw/input/adb.c @@ -25,6 +25,7 @@ #include "hw/hw.h" #include "hw/input/adb.h" #include "ui/console.h" +#include "include/hw/input/MacKeys.h" =20 /* debug ADB */ //#define DEBUG_ADB @@ -187,23 +188,121 @@ typedef struct ADBKeyboardClass { DeviceRealize parent_realize; } ADBKeyboardClass; =20 -static const uint8_t pc_to_adb_keycode[256] =3D { - 0, 53, 18, 19, 20, 21, 23, 22, 26, 28, 25, 29, 27, 24, 51, 48, - 12, 13, 14, 15, 17, 16, 32, 34, 31, 35, 33, 30, 36, 54, 0, 1, - 2, 3, 5, 4, 38, 40, 37, 41, 39, 50, 56, 42, 6, 7, 8, 9, - 11, 45, 46, 43, 47, 44,123, 67, 58, 49, 57,122,120, 99,118, 96, - 97, 98,100,101,109, 71,107, 89, 91, 92, 78, 86, 87, 88, 69, 83, - 84, 85, 82, 65, 0, 0, 10,103,111, 0, 0,110, 81, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 94, 0, 93, 0, 0, 0, 0, 0, 0,104,102, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 76,125, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,105, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 75, 0, 0,124, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0,115, 62,116, 0, 59, 0, 60, 0,119, - 61,121,114,117, 0, 0, 0, 0, 0, 0, 0, 55,126, 0,127, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 95, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +#define LARGEST_KEY_INDEX 0xe4 +/* number refers to the qcode_to_number array in input-keymap.c */ +static const unsigned int number_to_adb_keycode[LARGEST_KEY_INDEX + 1] = =3D { + [0x2a] =3D MAC_KEY_LEFT_SHIFT, + [0x36] =3D MAC_KEY_LEFT, + [0x38] =3D MAC_KEY_LEFT_OPTION, + [0xb8] =3D MAC_KEY_RIGHT, + [0x64] =3D MAC_KEY_LEFT_OPTION, + [0xe4] =3D MAC_KEY_RIGHT_OPTION, + [0x1d] =3D MAC_KEY_RIGHT_COMMAND, + [0x9d] =3D MAC_KEY_DOWN, + [0xdb] =3D MAC_KEY_LEFT_COMMAND, + [0xdc] =3D MAC_KEY_LEFT_COMMAND, + [0xdd] =3D 0, /* no Macintosh equivalent to the menu key */ + [0x01] =3D MAC_KEY_ESC, + [0x02] =3D MAC_KEY_1, + [0x03] =3D MAC_KEY_2, + [0x04] =3D MAC_KEY_3, + [0x05] =3D MAC_KEY_4, + [0x06] =3D MAC_KEY_5, + [0x07] =3D MAC_KEY_6, + [0x08] =3D MAC_KEY_7, + [0x09] =3D MAC_KEY_8, + [0x0a] =3D MAC_KEY_9, + [0x0b] =3D MAC_KEY_0, + [0x0c] =3D MAC_KEY_MINUS, + [0x0d] =3D MAC_KEY_EQUAL, + [0x0e] =3D MAC_KEY_DELETE, + [0x0f] =3D MAC_KEY_TAB, + [0x10] =3D MAC_KEY_Q, + [0x11] =3D MAC_KEY_W, + [0x12] =3D MAC_KEY_E, + [0x13] =3D MAC_KEY_R, + [0x14] =3D MAC_KEY_T, + [0x15] =3D MAC_KEY_Y, + [0x16] =3D MAC_KEY_U, + [0x17] =3D MAC_KEY_I, + [0x18] =3D MAC_KEY_O, + [0x19] =3D MAC_KEY_P, + [0x1a] =3D MAC_KEY_LEFT_BRACKET, + [0x1b] =3D MAC_KEY_RIGHT_BRACKET, + [0x1c] =3D MAC_KEY_RETURN, + [0x1e] =3D MAC_KEY_A, + [0x1f] =3D MAC_KEY_S, + [0x20] =3D MAC_KEY_D, + [0x21] =3D MAC_KEY_F, + [0x22] =3D MAC_KEY_G, + [0x23] =3D MAC_KEY_H, + [0x24] =3D MAC_KEY_J, + [0x25] =3D MAC_KEY_K, + [0x26] =3D MAC_KEY_L, + [0x27] =3D MAC_KEY_SEMICOLON, + [0x28] =3D MAC_KEY_APOSTROPHE, + [0x29] =3D MAC_KEY_GRAVE_ACCENT, + [0x2b] =3D MAC_KEY_BACKSLASH, + [0x2c] =3D MAC_KEY_Z, + [0x2d] =3D MAC_KEY_X, + [0x2e] =3D MAC_KEY_C, + [0x2f] =3D MAC_KEY_V, + [0x30] =3D MAC_KEY_B, + [0x31] =3D MAC_KEY_N, + [0x32] =3D MAC_KEY_M, + [0x33] =3D MAC_KEY_COMMA, + [0x34] =3D MAC_KEY_PERIOD, + [0x35] =3D MAC_KEY_FORWARD_SLASH, + [0x37] =3D MAC_KEY_KP_MULTIPLY, + [0x39] =3D MAC_KEY_SPACEBAR, + [0x3a] =3D MAC_KEY_CAPS_LOCK, + [0x3b] =3D MAC_KEY_F1, + [0x3c] =3D MAC_KEY_F2, + [0x3d] =3D MAC_KEY_F3, + [0x3e] =3D MAC_KEY_F4, + [0x3f] =3D MAC_KEY_F5, + [0x40] =3D MAC_KEY_F6, + [0x41] =3D MAC_KEY_F7, + [0x42] =3D MAC_KEY_F8, + [0x43] =3D MAC_KEY_F9, + [0x44] =3D MAC_KEY_F10, + [0x45] =3D MAC_KEY_KP_CLEAR, + [0x46] =3D MAC_KEY_F14, + [0xb5] =3D MAC_KEY_KP_DIVIDE, + [0x37] =3D MAC_KEY_KP_MULTIPLY, + [0x4a] =3D MAC_KEY_KP_SUBTRACT, + [0x4e] =3D MAC_KEY_KP_PLUS, + [0x9c] =3D MAC_KEY_KP_ENTER, + [0x53] =3D MAC_KEY_KP_PERIOD, + [0x54] =3D MAC_KEY_F13, + [0x55] =3D MAC_KEY_KP_EQUAL, + [0x52] =3D MAC_KEY_KP_0, + [0x4f] =3D MAC_KEY_KP_1, + [0x50] =3D MAC_KEY_KP_2, + [0x51] =3D MAC_KEY_KP_3, + [0x4b] =3D MAC_KEY_KP_4, + [0x4c] =3D MAC_KEY_KP_5, + [0x4d] =3D MAC_KEY_KP_6, + [0x47] =3D MAC_KEY_KP_7, + [0x48] =3D MAC_KEY_KP_8, + [0x49] =3D MAC_KEY_KP_9, + [0x56] =3D 0, /* There is no LESS key on the Macintosh keyboard */ + [0x57] =3D MAC_KEY_F11, + [0x58] =3D MAC_KEY_F12, + [0xb7] =3D MAC_KEY_F13, + [0xc7] =3D MAC_KEY_HOME, + [0xc9] =3D MAC_KEY_PAGE_UP, + [0xd1] =3D MAC_KEY_PAGE_DOWN, + [0xcf] =3D MAC_KEY_END, + [0xcb] =3D MAC_KEY_LEFT_CONTROL, + [0xc8] =3D MAC_KEY_RIGHT_CONTROL, + [0xd0] =3D MAC_KEY_RIGHT_OPTION, + [0xcd] =3D MAC_KEY_RIGHT_SHIFT, + [0xd2] =3D MAC_KEY_HELP, + [0xd3] =3D MAC_KEY_FORWARD_DELETE, + [0x73] =3D 0, /* There is no Ro key on the Macintosh keyboard */ + [0x7e] =3D 0, /* There is no keypad comma key on the Macintosh = keyboard */ + [0x5e] =3D MAC_KEY_POWER, }; =20 static void adb_kbd_put_keycode(void *opaque, int keycode) @@ -237,10 +336,11 @@ static int adb_kbd_poll(ADBDevice *d, uint8_t = *obuf) if (keycode =3D=3D 0xe0) { ext_keycode =3D 1; } else { - if (ext_keycode) - adb_keycode =3D pc_to_adb_keycode[keycode | 0x80]; - else - adb_keycode =3D pc_to_adb_keycode[keycode & 0x7f]; + if (ext_keycode) { + adb_keycode =3D number_to_adb_keycode[keycode | 0x80]; + } else { + adb_keycode =3D number_to_adb_keycode[keycode & 0x7f]; + } obuf[0] =3D adb_keycode | (keycode & 0x80); /* NOTE: could put a second keycode if needed */ obuf[1] =3D 0xff; --=20 1.7.5.4