rayzor
diff src/dosemu/dosemu.c @ 12:d94a69933a71
lots of stuff, can't remember
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 12 Apr 2014 23:28:24 +0300 |
parents | 70e332156d02 |
children | a9a948809c6f |
line diff
1.1 --- a/src/dosemu/dosemu.c Thu Apr 10 08:42:33 2014 +0300 1.2 +++ b/src/dosemu/dosemu.c Sat Apr 12 23:28:24 2014 +0300 1.3 @@ -12,6 +12,8 @@ 1.4 1.5 static void cleanup(void); 1.6 static void proc_events(void); 1.7 +static int translate_sdlkey(int sym); 1.8 +static void update_modkeys(void); 1.9 static void capture_frame(unsigned char *frame); 1.10 1.11 static void init_sdl(void) 1.12 @@ -314,11 +316,51 @@ 1.13 } 1.14 1.15 /* ----- improved event handling (keyb.h) ---- */ 1.16 +static char sdlkey_tbl[SDLK_LAST]; 1.17 1.18 int kb_init(int bufsz) 1.19 { 1.20 + int i; 1.21 init_sdl(); 1.22 1.23 + /* construct the SDL key translation table */ 1.24 + for(i=0; i<256; i++) { 1.25 + sdlkey_tbl[i] = i; /* start from an identity mapping for the first 256 */ 1.26 + } 1.27 + /* then change the special keys */ 1.28 + sdlkey_tbl[SDLK_LALT] = KB_LALT; 1.29 + sdlkey_tbl[SDLK_RALT] = KB_RALT; 1.30 + sdlkey_tbl[SDLK_LCTRL] = KB_LCTRL; 1.31 + sdlkey_tbl[SDLK_RCTRL] = KB_RCTRL; 1.32 + sdlkey_tbl[SDLK_LSHIFT] = KB_LSHIFT; 1.33 + for(i=0; i<12; i++) { 1.34 + sdlkey_tbl[SDLK_F1 + i] = KB_F1 + i; 1.35 + } 1.36 + sdlkey_tbl[SDLK_CAPSLOCK] = KB_CAPSLK; 1.37 + sdlkey_tbl[SDLK_NUMLOCK] = KB_NUMLK; 1.38 + sdlkey_tbl[SDLK_SCROLLOCK] = KB_SCRLK; 1.39 + sdlkey_tbl[SDLK_SYSREQ] = KB_SYSRQ; 1.40 + sdlkey_tbl[SDLK_ESCAPE] = KB_ESC; 1.41 + sdlkey_tbl[SDLK_INSERT] = KB_INSERT; 1.42 + sdlkey_tbl[SDLK_DELETE] = KB_DEL; 1.43 + sdlkey_tbl[SDLK_HOME] = KB_HOME; 1.44 + sdlkey_tbl[SDLK_END] = KB_END; 1.45 + sdlkey_tbl[SDLK_PAGEUP] = KB_PGUP; 1.46 + sdlkey_tbl[SDLK_PAGEDOWN] = KB_PGDN; 1.47 + sdlkey_tbl[SDLK_LEFT] = KB_LEFT; 1.48 + sdlkey_tbl[SDLK_RIGHT] = KB_RIGHT; 1.49 + sdlkey_tbl[SDLK_UP] = KB_UP; 1.50 + sdlkey_tbl[SDLK_DOWN] = KB_DOWN; 1.51 + sdlkey_tbl[SDLK_KP_PERIOD] = KB_NUM_DOT; 1.52 + sdlkey_tbl[SDLK_KP_ENTER] = KB_NUM_ENTER; 1.53 + sdlkey_tbl[SDLK_KP_PLUS] = KB_NUM_PLUS; 1.54 + sdlkey_tbl[SDLK_KP_MINUS] = KB_NUM_MINUS; 1.55 + sdlkey_tbl[SDLK_KP_MULTIPLY] = KB_NUM_MUL; 1.56 + sdlkey_tbl[SDLK_KP_DIVIDE] = KB_NUM_DIV; 1.57 + /* TODO missing numeric keypad numbers */ 1.58 + sdlkey_tbl[SDLK_BACKSPACE] = KB_BACKSP; 1.59 + 1.60 + 1.61 return 0; 1.62 } 1.63 1.64 @@ -332,7 +374,7 @@ 1.65 1.66 proc_events(); 1.67 if(keybev) { 1.68 - res = keybev->key.keysym.sym; 1.69 + res = translate_sdlkey(keybev->key.keysym.sym); 1.70 keybev = 0; 1.71 } 1.72 return res; 1.73 @@ -340,8 +382,15 @@ 1.74 1.75 int kb_isdown(int key) 1.76 { 1.77 - if(key == KB_ANY) { 1.78 + switch(key) { 1.79 + case KB_ANY: 1.80 return num_pressed; 1.81 + 1.82 + case KB_ALT: 1.83 + return keystate[KB_LALT] + keystate[KB_RALT]; 1.84 + 1.85 + case KB_CTRL: 1.86 + return keystate[KB_LCTRL] + keystate[KB_RCTRL]; 1.87 } 1.88 return keystate[key]; 1.89 } 1.90 @@ -388,7 +437,7 @@ 1.91 switch(ev.type) { 1.92 case SDL_KEYDOWN: 1.93 { 1.94 - int key = ev.key.keysym.sym; 1.95 + int key = translate_sdlkey(ev.key.keysym.sym); 1.96 1.97 if(!keybev) { 1.98 keybev = &ev; 1.99 @@ -398,12 +447,14 @@ 1.100 keystate[key] = 1; 1.101 num_pressed++; 1.102 } 1.103 + 1.104 + update_modkeys(); 1.105 } 1.106 break; 1.107 1.108 case SDL_KEYUP: 1.109 { 1.110 - int key = ev.key.keysym.sym; 1.111 + int key = translate_sdlkey(ev.key.keysym.sym); 1.112 1.113 if(keystate[key]) { 1.114 keystate[key] = 0; 1.115 @@ -411,6 +462,8 @@ 1.116 num_pressed = 0; 1.117 } 1.118 } 1.119 + 1.120 + update_modkeys(); 1.121 } 1.122 break; 1.123 1.124 @@ -453,6 +506,26 @@ 1.125 } 1.126 } 1.127 1.128 +static int translate_sdlkey(int sym) 1.129 +{ 1.130 + if(sym >= 0 && sym < 256) { 1.131 + return sdlkey_tbl[sym]; 1.132 + } 1.133 + return sym; 1.134 +} 1.135 + 1.136 +static void update_modkeys(void) 1.137 +{ 1.138 + unsigned int mod = SDL_GetModState(); 1.139 + 1.140 + keystate[KB_LALT] = mod & KMOD_LALT; 1.141 + keystate[KB_RALT] = mod & KMOD_RALT; 1.142 + keystate[KB_LCTRL] = mod & KMOD_LCTRL; 1.143 + keystate[KB_RCTRL] = mod & KMOD_RCTRL; 1.144 + keystate[KB_LSHIFT] = mod & KMOD_LSHIFT; 1.145 + keystate[KB_RSHIFT] = mod & KMOD_RSHIFT; 1.146 +} 1.147 + 1.148 /* ---- timer.c implementation ---- */ 1.149 static Uint32 start_time; 1.150