QEMU (was Re: [ros-kernel] Feature freeze)

Filip Navara xnavara at volny.cz
Thu Apr 8 18:58:22 CEST 2004


Mike Nordell wrote:

>Filip: Could you please check your patch and kbd input behaviour with and
>without that env. var?
>  
>
I have an updated version of the patch that works almost correctly with 
both the DInput and Event based SDL messages. After some testing I'll 
consider sending it to Fabrice.

- Filip

-------------- next part --------------
--- qemu/sdl.c	Wed Apr  7 21:32:52 2004
+++ qemu.win32/sdl.c	Thu Apr  8 14:42:04 2004
@@ -57,101 +57,400 @@
     ds->depth = screen->format->BitsPerPixel;
 }
 
-static const uint32_t x_keycode_to_pc_keycode[61] = {
-   0x47e0,      /*  97  Home   */
-   0x48e0,      /*  98  Up     */
-   0x49e0,      /*  99  PgUp   */
-   0x4be0,      /* 100  Left   */
-   0x4c,        /* 101  KP-5   */
-   0x4de0,      /* 102  Right  */
-   0x4fe0,      /* 103  End    */
-   0x50e0,      /* 104  Down   */
-   0x51e0,      /* 105  PgDn   */
-   0x52e0,      /* 106  Ins    */
-   0x53e0,      /* 107  Del    */
-   0x1ce0,      /* 108  Enter  */
-   0x1de0,      /* 109  Ctrl-R */
-   0x451de1,    /* 110  Pause  */
-   0x37e0,      /* 111  Print  */
-   0x35e0,      /* 112  Divide */
-   0x38e0,      /* 113  Alt-R  */
-   0x46e0,      /* 114  Break  */   
-   0x0,         /* 115 */
-   0x0,         /* 116 */
-   0x0,         /* 117 */
-   0x0,         /* 118 */
-   0x0,         /* 119 */
-   0x0,         /* 120 */
-   0x0,         /* 121 */
-   0x0,         /* 122 */
-   0x0,         /* 123 */
-   0x0,         /* 124 */
-   0x0,         /* 125 */
-   0x0,         /* 126 */
-   0x0,         /* 127 */
-   0x0,         /* 128 */
-   0x0,         /* 129 */
-   0x0,         /* 130 */
-   0x0,         /* 131 */
-   0x0,         /* 132 */
-   0x0,         /* 133 */
-   0x0,         /* 134 */
-   0x0,         /* 135 */
-   0x47,         /* 136 KP_7 */
-   0x48,         /* 137 KP_8 */
-   0x49,         /* 138 KP_9 */
-   0x4b,         /* 139 KP_4 */
-   0x4c,         /* 140 KP_5 */
-   0x4d,         /* 141 KP_6 */
-   0x4f,         /* 142 KP_1 */
-   0x50,         /* 143 KP_2 */
-   0x51,         /* 144 KP_3 */
-   0x52,         /* 145 KP_0 */
-   0x53,         /* 146 KP_. */
-   0x47,         /* 147 KP_HOME */
-   0x48,         /* 148 KP_UP */
-   0x49,         /* 149 KP_PgUp */
-   0x4b,         /* 150 KP_Left */
-   0x4c,         /* 151 KP_ */
-   0x4d,         /* 152 KP_Right */

-   0x4f,         /* 153 KP_End */
-   0x50,         /* 154 KP_Down */
-   0x51,         /* 155 KP_PgDn */
-   0x52,         /* 156 KP_Ins */
-   0x53,         /* 157 KP_Del */
+static const unsigned long sdl_keycode_to_pc_keycode[] = {
+   0x0,         /* SDLK_UNKNOWN */
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0xe,         /* SDLK_BACKSPACE */
+   0xf,         /* SDLK_TAB */
+   0x0,
+   0x0,
+   0x0,         /* SDLK_CLEAR */
+   0x1c,        /* SDLK_RETURN	*/
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x451de1,    /* SDLK_PAUSE */
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x1,         /* SDLK_ESCAPE	*/
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x39,        /* SDLK_SPACE */
+   0x2,         /* SDLK_EXCLAIM */
+   0x28,        /* SDLK_QUOTEDBL */
+   0x4,         /* SDLK_HASH */
+   0x5,         /* SDLK_DOLLAR */
+   0x0,
+   0x8,         /* SDLK_AMPERSAND */
+   0x28,        /* SDLK_QUOTE */
+   0xa,         /* SDLK_LEFTPAREN */
+   0xb,         /* SDLK_RIGHTPAREN */
+   0x9,         /* SDLK_ASTERISK */
+   0xd,         /* SDLK_PLUS */
+   0x33,        /* SDLK_COMMA */
+   0xc,         /* SDLK_MINUS */
+   0x34,        /* SDLK_PERIOD */
+   0x35,        /* SDLK_SLASH */
+   0xb,         /* SDLK_0 */
+   0x2,         /* SDLK_1 */
+   0x3,         /* SDLK_2 */
+   0x4,         /* SDLK_3 */
+   0x5,         /* SDLK_4 */
+   0x6,         /* SDLK_5 */
+   0x7,         /* SDLK_6 */
+   0x8,         /* SDLK_7 */
+   0x9,         /* SDLK_8 */
+   0xa,         /* SDLK_9 */
+   0x27,        /* SDLK_COLON */
+   0x27,        /* SDLK_SEMICOLON */
+   0x33,        /* SDLK_LESS */
+   0xd,         /* SDLK_EQUALS */
+   0x34,        /* SDLK_GREATER */
+   0x35,        /* SDLK_QUESTION */
+   0x3,         /* SDLK_AT */
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x1a,        /* SDLK_LEFTBRACKET */
+   0x2b,        /* SDLK_BACKSLASH */
+   0x1b,        /* SDLK_RIGHTBRACKET */
+   0x7,         /* SDLK_CARET */
+   0xc,         /* SDLK_UNDERSCORE */
+   0x29,        /* SDLK_BACKQUOTE */
+   0x1e,        /* SDLK_a */
+   0x30,        /* SDLK_b */
+   0x2e,        /* SDLK_c */
+   0x20,        /* SDLK_d */
+   0x12,        /* SDLK_e */
+   0x21,        /* SDLK_f */
+   0x22,        /* SDLK_g */
+   0x23,        /* SDLK_h */
+   0x17,        /* SDLK_i */
+   0x24,        /* SDLK_j */
+   0x25,        /* SDLK_k */
+   0x26,        /* SDLK_l */
+   0x32,        /* SDLK_m */
+   0x31,        /* SDLK_n */
+   0x18,        /* SDLK_o */
+   0x19,        /* SDLK_p */
+   0x10,        /* SDLK_q */
+   0x13,        /* SDLK_r */
+   0x1f,        /* SDLK_s */
+   0x14,        /* SDLK_t */
+   0x16,        /* SDLK_u */
+   0x2f,        /* SDLK_v */
+   0x11,        /* SDLK_w */
+   0x2d,        /* SDLK_x */
+   0x15,        /* SDLK_y */
+   0x2c,        /* SDLK_z */
+   0x0,
+   0x0,
+   0x0,
+   0x0,
+   0x53e0,      /* SDLK_DELETE */
+
+   0xFFFF,      /* 128 */
+   0xFFFF,      /* 129 */
+   0xFFFF,      /* 130 */
+   0xFFFF,      /* 131 */
+   0xFFFF,      /* 132 */
+   0xFFFF,      /* 133 */
+   0xFFFF,      /* 134 */
+   0xFFFF,      /* 135 */
+   0xFFFF,      /* 136 */
+   0xFFFF,      /* 137 */
+   0xFFFF,      /* 138 */
+   0xFFFF,      /* 139 */
+   0xFFFF,      /* 140 */
+   0xFFFF,      /* 141 */
+   0xFFFF,      /* 142 */
+   0xFFFF,      /* 143 */
+   0xFFFF,      /* 144 */
+   0xFFFF,      /* 145 */
+   0xFFFF,      /* 146 */
+   0xFFFF,      /* 147 */
+   0xFFFF,      /* 148 */
+   0xFFFF,      /* 149 */
+   0xFFFF,      /* 150 */
+   0xFFFF,      /* 151 */
+   0xFFFF,      /* 152 */
+   0xFFFF,      /* 153 */
+   0xFFFF,      /* 154 */
+   0xFFFF,      /* 155 */
+   0xFFFF,      /* 156 */
+   0xFFFF,      /* 157 */
+   0xFFFF,      /* 158 */
+   0xFFFF,      /* 159 */
+   0xFFFF,      /* 160 */
+   0xFFFF,      /* 161 */
+   0xFFFF,      /* 162 */
+   0xFFFF,      /* 163 */
+   0xFFFF,      /* 164 */
+   0xFFFF,      /* 165 */
+   0xFFFF,      /* 166 */
+   0xFFFF,      /* 167 */
+   0xFFFF,      /* 168 */
+   0xFFFF,      /* 169 */
+   0xFFFF,      /* 170 */
+   0xFFFF,      /* 171 */
+   0xFFFF,      /* 172 */
+   0xFFFF,      /* 173 */
+   0xFFFF,      /* 174 */
+   0xFFFF,      /* 175 */
+   0xFFFF,      /* 176 */
+   0xFFFF,      /* 177 */
+   0xFFFF,      /* 178 */
+   0xFFFF,      /* 179 */
+   0xFFFF,      /* 180 */
+   0xFFFF,      /* 181 */
+   0xFFFF,      /* 182 */
+   0xFFFF,      /* 183 */
+   0xFFFF,      /* 184 */
+   0xFFFF,      /* 185 */
+   0xFFFF,      /* 186 */
+   0xFFFF,      /* 187 */
+   0xFFFF,      /* 188 */
+   0xFFFF,      /* 189 */
+   0xFFFF,      /* 190 */
+   0xFFFF,      /* 191 */
+   0xFFFF,      /* 192 */
+   0xFFFF,      /* 193 */
+   0xFFFF,      /* 194 */
+   0xFFFF,      /* 195 */
+   0xFFFF,      /* 196 */
+   0xFFFF,      /* 197 */
+   0xFFFF,      /* 198 */
+   0xFFFF,      /* 199 */
+   0xFFFF,      /* 200 */
+   0xFFFF,      /* 201 */
+   0xFFFF,      /* 202 */
+   0xFFFF,      /* 203 */
+   0xFFFF,      /* 204 */
+   0xFFFF,      /* 205 */
+   0xFFFF,      /* 206 */
+   0xFFFF,      /* 207 */
+   0xFFFF,      /* 208 */
+   0xFFFF,      /* 209 */
+   0xFFFF,      /* 210 */
+   0xFFFF,      /* 211 */
+   0xFFFF,      /* 212 */
+   0xFFFF,      /* 213 */
+   0xFFFF,      /* 214 */
+   0xFFFF,      /* 215 */
+   0xFFFF,      /* 216 */
+   0xFFFF,      /* 217 */
+   0xFFFF,      /* 218 */
+   0xFFFF,      /* 219 */
+   0xFFFF,      /* 220 */
+   0xFFFF,      /* 221 */
+   0xFFFF,      /* 222 */
+   0xFFFF,      /* 223 */
+   0xFFFF,      /* 224 */
+   0xFFFF,      /* 225 */
+   0xFFFF,      /* 226 */
+   0xFFFF,      /* 227 */
+   0xFFFF,      /* 228 */
+   0xFFFF,      /* 229 */
+   0xFFFF,      /* 230 */
+   0xFFFF,      /* 231 */
+   0xFFFF,      /* 232 */
+   0xFFFF,      /* 233 */
+   0xFFFF,      /* 234 */
+   0xFFFF,      /* 235 */
+   0xFFFF,      /* 236 */
+   0xFFFF,      /* 237 */
+   0xFFFF,      /* 238 */
+   0xFFFF,      /* 239 */
+   0xFFFF,      /* 240 */
+   0xFFFF,      /* 241 */
+   0xFFFF,      /* 242 */
+   0xFFFF,      /* 243 */
+   0xFFFF,      /* 244 */
+   0xFFFF,      /* 245 */
+   0xFFFF,      /* 246 */
+   0xFFFF,      /* 247 */
+   0xFFFF,      /* 248 */
+   0xFFFF,      /* 249 */
+   0xFFFF,      /* 250 */
+   0xFFFF,      /* 251 */
+   0xFFFF,      /* 252 */
+   0xFFFF,      /* 253 */
+   0xFFFF,      /* 254 */
+   0xFFFF,      /* 255 */
+   
+   0x52,        /* SDLK_KP0 */
+   0x4f,        /* SDLK_KP1 */
+   0x50,        /* SDLK_KP2 */
+   0x51,        /* SDLK_KP3 */
+   0x4b,        /* SDLK_KP4 */
+   0x4c,        /* SDLK_KP5 */
+   0x4d,        /* SDLK_KP6 */
+   0x47,        /* SDLK_KP7 */
+   0x48,        /* SDLK_KP8 */
+   0x49,        /* SDLK_KP9 */
+   0x53,        /* SDLK_KP_PERIOD */
+   0x35e0,      /* SDLK_KP_DIVIDE */
+   0x37,        /* SDLK_KP_MULTIPLY */
+   0x4a,        /* SDLK_KP_MINUS */
+   0x4e,        /* SDLK_KP_PLUS */
+   0x1ce0,      /* SDLK_KP_ENTER */
+   0x0,         /* SDLK_KP_EQUALS */
+   0x48e0,      /* SDLK_UP */
+   0x50e0,      /* SDLK_DOWN */
+   0x4de0,      /* SDLK_RIGHT */
+   0x4be0,      /* SDLK_LEFT */
+   0x52e0,      /* SDLK_INSERT */
+   0x47e0,      /* SDLK_HOME */
+   0x4fe0,      /* SDLK_END */
+   0x49e0,      /* SDLK_PAGEUP */
+   0x51e0,      /* SDLK_PAGEDOWN */
+   0x3b,        /* SDLK_F1 */
+   0x3c,        /* SDLK_F2 */
+   0x3d,        /* SDLK_F3 */
+   0x3e,        /* SDLK_F4 */
+   0x3f,        /* SDLK_F5 */
+   0x40,        /* SDLK_F6 */
+   0x41,        /* SDLK_F7 */
+   0x42,        /* SDLK_F8 */
+   0x43,        /* SDLK_F9 */
+   0x44,        /* SDLK_F10 */
+   0x57,        /* SDLK_F11 */
+   0x58,        /* SDLK_F12 */
+   0x0,         /* SDLK_F13 */
+   0x0,         /* SDLK_F14 */
+   0x0,         /* SDLK_F15 */
+   0x0,
+   0x0,
+   0x0,
+   0x45,        /* SDLK_NUMLOCK */
+   0x3a,        /* SDLK_CAPSLOCK */
+   0x46,        /* SDLK_SCROLLOCK */
+   0x36,        /* SDLK_RSHIFT */
+   0x2a,        /* SDLK_LSHIFT */
+   0x1de0,      /* SDLK_RCTRL */
+   0x1d,        /* SDLK_LCTRL */
+   0x38e0,      /* SDLK_RALT */
+   0x38,        /* SDLK_LALT */
+   0x38e0,      /* SDLK_RMETA */
+   0x0,         /* SDLK_LMETA */
+   0x5be0,      /* SDLK_LSUPER */
+   0x5ce0,      /* SDLK_RSUPER */
+   0x38e0,      /* SDLK_MODE */
+   0x0,         /* SDLK_COMPOSE */
+   0x0,         /* SDLK_HELP */
+   0x37e0,      /* SDLK_PRINT */
+   0x84,        /* SDLK_SYSREQ */
+   0x451de1,    /* SDLK_BREAK */
+   0x5de0,      /* SDLK_MENU */
+   0x0,         /* SDLK_POWER */
+   0x0,         /* SDLK_EURO */
+   0x0          /* SDLK_UNDO */
 };
 
+#define sdl_keycode_table_size (sizeof(sdl_keycode_to_pc_keycode) / sizeof(uint32_t))
+
 static void sdl_process_key(SDL_KeyboardEvent *ev)
 {
     int keycode, v;
     
-    /* XXX: not portable, but avoids complicated mappings */
+    if (ev->keysym.sym < sdl_keycode_table_size) {
+        keycode = sdl_keycode_to_pc_keycode[ev->keysym.sym];
+        if (keycode == 0xFFFF)
     keycode = ev->keysym.scancode;
-#ifdef _WIN32
-    if (keycode < 97) {
-        /* nothing to do */
-    } else 
-#else
-    if (keycode < 9) {
-        keycode = 0;
-    } else if (keycode < 97) {
-        keycode -= 8; /* just an offset */
-    } else 
-#endif
-    if (keycode < 158) {
-        /* use conversion table */
-        keycode = x_keycode_to_pc_keycode[keycode - 97];
     } else {
-        keycode = 0;
+        keycode = ev->keysym.scancode;
+    }
+
+    /* fake shifts */
+    if (ev->type == SDL_KEYDOWN) {
+        if (((ev->keysym.sym >= SDLK_UP && ev->keysym.sym <= SDLK_PAGEDOWN) ||
+             ev->keysym.sym == SDLK_DELETE)) {
+            if (ev->keysym.mod & KMOD_SHIFT) {
+                kbd_put_keycode(0xe0);
+                kbd_put_keycode(0xaa);
+            }
+        } else if ((ev->keysym.sym >= SDLK_KP0 && ev->keysym.sym <= SDLK_KP_EQUALS)) {
+            if (ev->keysym.mod & KMOD_NUM) {
+                if (ev->keysym.mod & KMOD_SHIFT) {
+                    kbd_put_keycode(0xe0);
+                    kbd_put_keycode(0xaa);
+                } else {
+                    kbd_put_keycode(0xe0);
+                    kbd_put_keycode(0x2a);
+                }
+            }
+        }
     }
     
     /* now send the key code */
     while (keycode != 0) {
         v = keycode & 0xff;
-        if (ev->type == SDL_KEYUP)
+        if (ev->type == SDL_KEYUP &&
+            ev->keysym.sym != SDLK_NUMLOCK &&
+            ev->keysym.sym != SDLK_CAPSLOCK &&
+            ev->keysym.sym != SDLK_SCROLLOCK)
             v |= 0x80;
         kbd_put_keycode(v);
         keycode >>= 8;
+    }
+
+    /* fake shifts */
+    if (ev->type == SDL_KEYUP) {
+        if (((ev->keysym.sym >= SDLK_UP && ev->keysym.sym <= SDLK_PAGEDOWN) ||
+             ev->keysym.sym == SDLK_DELETE)) {
+            if (ev->keysym.mod & KMOD_SHIFT) {
+                kbd_put_keycode(0xe0);
+                kbd_put_keycode(0x2a);
+            }
+        } else if ((ev->keysym.sym >= SDLK_KP0 && ev->keysym.sym <= SDLK_KP_EQUALS)) {
+            if (ev->keysym.mod & KMOD_NUM) {
+                if (ev->keysym.mod & KMOD_SHIFT) {
+                    kbd_put_keycode(0xe0);
+                    kbd_put_keycode(0x2a);
+                } else {
+                    kbd_put_keycode(0xe0);
+                    kbd_put_keycode(0xaa);
+                }
+            }
+        }
     }
 }
 


More information about the Ros-kernel mailing list