comparison src/video/ataricommon/SDL_ikbdevents.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents d910939febfa
children d20f4510c718
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
36 #include "SDL_atarikeys.h" 36 #include "SDL_atarikeys.h"
37 #include "SDL_atarievents_c.h" 37 #include "SDL_atarievents_c.h"
38 #include "SDL_ikbdinterrupt_s.h" 38 #include "SDL_ikbdinterrupt_s.h"
39 39
40 /* Special keys state */ 40 /* Special keys state */
41 enum { 41 enum
42 K_RSHIFT=0, 42 {
43 K_LSHIFT, 43 K_RSHIFT = 0,
44 K_CTRL, 44 K_LSHIFT,
45 K_ALT, 45 K_CTRL,
46 K_CAPSLOCK, 46 K_ALT,
47 K_CLRHOME, 47 K_CAPSLOCK,
48 K_INSERT 48 K_CLRHOME,
49 K_INSERT
49 }; 50 };
50 51
51 #define ATARIBIOS_MAXKEYS 128 52 #define ATARIBIOS_MAXKEYS 128
52 53
53 #define KEY_PRESSED 0xff 54 #define KEY_PRESSED 0xff
55 #define KEY_RELEASED 0x00 56 #define KEY_RELEASED 0x00
56 57
57 /* The translation tables from a console scancode to a SDL keysym */ 58 /* The translation tables from a console scancode to a SDL keysym */
58 #define KT_NOCHANGE -1 59 #define KT_NOCHANGE -1
59 60
60 enum { 61 enum
61 KT_UNSHIFT=0, 62 {
62 KT_SHIFT=1, 63 KT_UNSHIFT = 0,
63 KT_CAPS=2 64 KT_SHIFT = 1,
65 KT_CAPS = 2
64 }; 66 };
65 67
66 static Uint16 atari_prevmouseb; /* save state of mouse buttons */ 68 static Uint16 atari_prevmouseb; /* save state of mouse buttons */
67 static int caps_state; /* caps lock state */ 69 static int caps_state; /* caps lock state */
68 _KEYTAB *curtables; 70 _KEYTAB *curtables;
69 static unsigned char *tab_unshift, *tab_shift, *tab_caps; 71 static unsigned char *tab_unshift, *tab_shift, *tab_caps;
70 static SDLKey keymap[ATARIBIOS_MAXKEYS]; 72 static SDLKey keymap[ATARIBIOS_MAXKEYS];
71 73
72 static SDL_keysym *TranslateKey(int scancode, int numkeytable, SDL_keysym *keysym, 74 static SDL_keysym *TranslateKey(int scancode, int numkeytable,
73 SDL_bool pressed); 75 SDL_keysym * keysym, SDL_bool pressed);
74 76
75 void AtariIkbd_InitOSKeymap(_THIS) 77 void
76 { 78 AtariIkbd_InitOSKeymap(_THIS)
77 int i; 79 {
78 80 int i;
79 SDL_memset(SDL_AtariIkbd_keyboard, KEY_UNDEFINED, ATARIBIOS_MAXKEYS); 81
80 82 SDL_memset(SDL_AtariIkbd_keyboard, KEY_UNDEFINED, ATARIBIOS_MAXKEYS);
81 /* Initialize keymap */ 83
82 for ( i=0; i<sizeof(keymap); i++ ) 84 /* Initialize keymap */
83 keymap[i] = SDLK_UNKNOWN; 85 for (i = 0; i < sizeof(keymap); i++)
84 86 keymap[i] = SDLK_UNKNOWN;
85 /* Functions keys */ 87
86 for ( i = 0; i<10; i++ ) 88 /* Functions keys */
87 keymap[SCANCODE_F1 + i] = SDLK_F1+i; 89 for (i = 0; i < 10; i++)
88 90 keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
89 /* Cursor keypad */ 91
90 keymap[SCANCODE_HELP] = SDLK_HELP; 92 /* Cursor keypad */
91 keymap[SCANCODE_UNDO] = SDLK_UNDO; 93 keymap[SCANCODE_HELP] = SDLK_HELP;
92 keymap[SCANCODE_INSERT] = SDLK_INSERT; 94 keymap[SCANCODE_UNDO] = SDLK_UNDO;
93 keymap[SCANCODE_CLRHOME] = SDLK_HOME; 95 keymap[SCANCODE_INSERT] = SDLK_INSERT;
94 keymap[SCANCODE_UP] = SDLK_UP; 96 keymap[SCANCODE_CLRHOME] = SDLK_HOME;
95 keymap[SCANCODE_DOWN] = SDLK_DOWN; 97 keymap[SCANCODE_UP] = SDLK_UP;
96 keymap[SCANCODE_RIGHT] = SDLK_RIGHT; 98 keymap[SCANCODE_DOWN] = SDLK_DOWN;
97 keymap[SCANCODE_LEFT] = SDLK_LEFT; 99 keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
98 100 keymap[SCANCODE_LEFT] = SDLK_LEFT;
99 /* Special keys */ 101
100 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE; 102 /* Special keys */
101 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE; 103 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
102 keymap[SCANCODE_TAB] = SDLK_TAB; 104 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
103 keymap[SCANCODE_ENTER] = SDLK_RETURN; 105 keymap[SCANCODE_TAB] = SDLK_TAB;
104 keymap[SCANCODE_DELETE] = SDLK_DELETE; 106 keymap[SCANCODE_ENTER] = SDLK_RETURN;
105 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL; 107 keymap[SCANCODE_DELETE] = SDLK_DELETE;
106 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT; 108 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
107 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT; 109 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
108 keymap[SCANCODE_LEFTALT] = SDLK_LALT; 110 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
109 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK; 111 keymap[SCANCODE_LEFTALT] = SDLK_LALT;
110 112 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
111 /* Read XBIOS tables for scancode -> ascii translation */ 113
112 curtables=Keytbl(KT_NOCHANGE, KT_NOCHANGE, KT_NOCHANGE); 114 /* Read XBIOS tables for scancode -> ascii translation */
113 tab_unshift=curtables->unshift; 115 curtables = Keytbl(KT_NOCHANGE, KT_NOCHANGE, KT_NOCHANGE);
114 tab_shift=curtables->shift; 116 tab_unshift = curtables->unshift;
115 tab_caps=curtables->caps; 117 tab_shift = curtables->shift;
116 118 tab_caps = curtables->caps;
117 /* Set Caps lock initial state */ 119
118 caps_state=(Kbshift(-1) & (1<<K_CAPSLOCK)); 120 /* Set Caps lock initial state */
119 121 caps_state = (Kbshift(-1) & (1 << K_CAPSLOCK));
120 /* Now install our handler */ 122
121 SDL_AtariIkbd_mouseb = SDL_AtariIkbd_mousex = SDL_AtariIkbd_mousey = 0; 123 /* Now install our handler */
122 atari_prevmouseb = 0; 124 SDL_AtariIkbd_mouseb = SDL_AtariIkbd_mousex = SDL_AtariIkbd_mousey = 0;
123 125 atari_prevmouseb = 0;
124 Supexec(SDL_AtariIkbdInstall); 126
125 } 127 Supexec(SDL_AtariIkbdInstall);
126 128 }
127 static int atari_GetButton(int button) 129
128 { 130 static int
129 switch(button) 131 atari_GetButton(int button)
130 { 132 {
131 case 0: 133 switch (button) {
132 return SDL_BUTTON_RIGHT; 134 case 0:
133 break; 135 return SDL_BUTTON_RIGHT;
134 case 1: 136 break;
135 default: 137 case 1:
136 return SDL_BUTTON_LEFT; 138 default:
137 break; 139 return SDL_BUTTON_LEFT;
138 } 140 break;
139 } 141 }
140 142 }
141 void AtariIkbd_PumpEvents(_THIS) 143
142 { 144 void
143 int i; 145 AtariIkbd_PumpEvents(_THIS)
144 SDL_keysym keysym; 146 {
145 int specialkeys; 147 int i;
146 148 SDL_keysym keysym;
147 /*--- Send keyboard events ---*/ 149 int specialkeys;
148 150
149 /* Update caps lock state */ 151 /*--- Send keyboard events ---*/
150 if (SDL_AtariIkbd_keyboard[SCANCODE_CAPSLOCK]==KEY_PRESSED) { 152
151 caps_state ^= 1; 153 /* Update caps lock state */
152 } 154 if (SDL_AtariIkbd_keyboard[SCANCODE_CAPSLOCK] == KEY_PRESSED) {
153 155 caps_state ^= 1;
154 /* Choose the translation table */ 156 }
155 specialkeys=KT_UNSHIFT; 157
156 if ((SDL_AtariIkbd_keyboard[SCANCODE_LEFTSHIFT]==KEY_PRESSED) 158 /* Choose the translation table */
157 || (SDL_AtariIkbd_keyboard[SCANCODE_RIGHTSHIFT]==KEY_PRESSED)) 159 specialkeys = KT_UNSHIFT;
158 { 160 if ((SDL_AtariIkbd_keyboard[SCANCODE_LEFTSHIFT] == KEY_PRESSED)
159 specialkeys = KT_SHIFT; 161 || (SDL_AtariIkbd_keyboard[SCANCODE_RIGHTSHIFT] == KEY_PRESSED)) {
160 } 162 specialkeys = KT_SHIFT;
161 if (caps_state) { 163 }
162 specialkeys = KT_CAPS; 164 if (caps_state) {
163 } 165 specialkeys = KT_CAPS;
164 166 }
165 /* Now generate events */ 167
166 for (i=0; i<ATARIBIOS_MAXKEYS; i++) { 168 /* Now generate events */
167 /* Key pressed ? */ 169 for (i = 0; i < ATARIBIOS_MAXKEYS; i++) {
168 if (SDL_AtariIkbd_keyboard[i]==KEY_PRESSED) { 170 /* Key pressed ? */
169 SDL_PrivateKeyboard(SDL_PRESSED, 171 if (SDL_AtariIkbd_keyboard[i] == KEY_PRESSED) {
170 TranslateKey(i, specialkeys, &keysym, SDL_TRUE)); 172 SDL_PrivateKeyboard(SDL_PRESSED,
171 SDL_AtariIkbd_keyboard[i]=KEY_UNDEFINED; 173 TranslateKey(i, specialkeys, &keysym,
172 } 174 SDL_TRUE));
173 175 SDL_AtariIkbd_keyboard[i] = KEY_UNDEFINED;
174 /* Key released ? */ 176 }
175 if (SDL_AtariIkbd_keyboard[i]==KEY_RELEASED) { 177
176 SDL_PrivateKeyboard(SDL_RELEASED, 178 /* Key released ? */
177 TranslateKey(i, specialkeys, &keysym, SDL_FALSE)); 179 if (SDL_AtariIkbd_keyboard[i] == KEY_RELEASED) {
178 SDL_AtariIkbd_keyboard[i]=KEY_UNDEFINED; 180 SDL_PrivateKeyboard(SDL_RELEASED,
179 } 181 TranslateKey(i, specialkeys, &keysym,
180 } 182 SDL_FALSE));
181 183 SDL_AtariIkbd_keyboard[i] = KEY_UNDEFINED;
182 /*--- Send mouse events ---*/ 184 }
183 185 }
184 /* Mouse motion ? */ 186
185 if (SDL_AtariIkbd_mousex || SDL_AtariIkbd_mousey) { 187 /*--- Send mouse events ---*/
186 SDL_PrivateMouseMotion(0, 1, SDL_AtariIkbd_mousex, SDL_AtariIkbd_mousey); 188
187 SDL_AtariIkbd_mousex = SDL_AtariIkbd_mousey = 0; 189 /* Mouse motion ? */
188 } 190 if (SDL_AtariIkbd_mousex || SDL_AtariIkbd_mousey) {
189 191 SDL_PrivateMouseMotion(0, 1, SDL_AtariIkbd_mousex,
190 /* Mouse button ? */ 192 SDL_AtariIkbd_mousey);
191 if (SDL_AtariIkbd_mouseb != atari_prevmouseb) { 193 SDL_AtariIkbd_mousex = SDL_AtariIkbd_mousey = 0;
192 for (i=0;i<2;i++) { 194 }
193 int curbutton, prevbutton; 195
194 196 /* Mouse button ? */
195 curbutton = SDL_AtariIkbd_mouseb & (1<<i); 197 if (SDL_AtariIkbd_mouseb != atari_prevmouseb) {
196 prevbutton = atari_prevmouseb & (1<<i); 198 for (i = 0; i < 2; i++) {
197 199 int curbutton, prevbutton;
198 if (curbutton && !prevbutton) { 200
199 SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0); 201 curbutton = SDL_AtariIkbd_mouseb & (1 << i);
200 } 202 prevbutton = atari_prevmouseb & (1 << i);
201 if (!curbutton && prevbutton) { 203
202 SDL_PrivateMouseButton(SDL_RELEASED, atari_GetButton(i), 0, 0); 204 if (curbutton && !prevbutton) {
203 } 205 SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0);
204 } 206 }
205 atari_prevmouseb = SDL_AtariIkbd_mouseb; 207 if (!curbutton && prevbutton) {
206 } 208 SDL_PrivateMouseButton(SDL_RELEASED,
207 } 209 atari_GetButton(i), 0, 0);
208 210 }
209 static SDL_keysym *TranslateKey(int scancode, int numkeytable, SDL_keysym *keysym, 211 }
210 SDL_bool pressed) 212 atari_prevmouseb = SDL_AtariIkbd_mouseb;
211 { 213 }
212 unsigned char asciicode; 214 }
213 215
214 /* Set the keysym information */ 216 static SDL_keysym *
215 keysym->scancode = scancode; 217 TranslateKey(int scancode, int numkeytable, SDL_keysym * keysym,
216 218 SDL_bool pressed)
217 asciicode=0; 219 {
218 switch(numkeytable) { 220 unsigned char asciicode;
219 case KT_UNSHIFT: 221
220 asciicode=tab_unshift[scancode]; 222 /* Set the keysym information */
221 break; 223 keysym->scancode = scancode;
222 case KT_SHIFT: 224
223 asciicode=tab_shift[scancode]; 225 asciicode = 0;
224 break; 226 switch (numkeytable) {
225 case KT_CAPS: 227 case KT_UNSHIFT:
226 asciicode=tab_caps[scancode]; 228 asciicode = tab_unshift[scancode];
227 break; 229 break;
228 } 230 case KT_SHIFT:
229 231 asciicode = tab_shift[scancode];
230 if (asciicode) 232 break;
231 keysym->sym = asciicode; 233 case KT_CAPS:
232 else 234 asciicode = tab_caps[scancode];
233 keysym->sym = keymap[scancode]; 235 break;
234 236 }
235 keysym->mod = KMOD_NONE; 237
236 keysym->unicode = 0; 238 if (asciicode)
237 if (SDL_TranslateUNICODE && pressed) { 239 keysym->sym = asciicode;
238 keysym->unicode = SDL_AtariToUnicodeTable[asciicode]; 240 else
239 } 241 keysym->sym = keymap[scancode];
240 242
241 return(keysym); 243 keysym->mod = KMOD_NONE;
242 } 244 keysym->unicode = 0;
243 245 if (SDL_TranslateUNICODE && pressed) {
244 void AtariIkbd_ShutdownEvents(void) 246 keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
245 { 247 }
246 Supexec(SDL_AtariIkbdUninstall); 248
247 } 249 return (keysym);
250 }
251
252 void
253 AtariIkbd_ShutdownEvents(void)
254 {
255 Supexec(SDL_AtariIkbdUninstall);
256 }
257
258 /* vi: set ts=4 sw=4 expandtab: */