comparison src/video/ataricommon/SDL_gemdosevents.c @ 3860:bf1586b58ef2 SDL-1.2

Factorize keyboard mapping between drivers
author Patrice Mandin <patmandin@gmail.com>
date Wed, 13 Sep 2006 21:18:35 +0000
parents f1816773a309
children 2325dd996f73
comparison
equal deleted inserted replaced
3859:5d14acfdf84d 3860:bf1586b58ef2
38 #include "SDL_atarievents_c.h" 38 #include "SDL_atarievents_c.h"
39 #include "SDL_xbiosevents_c.h" 39 #include "SDL_xbiosevents_c.h"
40 #include "SDL_ataridevmouse_c.h" 40 #include "SDL_ataridevmouse_c.h"
41 41
42 /* To save state of keyboard */ 42 /* To save state of keyboard */
43 #define ATARIBIOS_MAXKEYS 128
44 43
45 static unsigned char gemdos_currentkeyboard[ATARIBIOS_MAXKEYS]; 44 static unsigned char gemdos_currentkeyboard[ATARIBIOS_MAXKEYS];
46 static unsigned char gemdos_previouskeyboard[ATARIBIOS_MAXKEYS]; 45 static unsigned char gemdos_previouskeyboard[ATARIBIOS_MAXKEYS];
47 static unsigned char gemdos_currentascii[ATARIBIOS_MAXKEYS];
48 static SDL_bool use_dev_mouse = SDL_FALSE; 46 static SDL_bool use_dev_mouse = SDL_FALSE;
49
50 /* Special keys state */
51 enum {
52 K_RSHIFT=0,
53 K_LSHIFT,
54 K_CTRL,
55 K_ALT,
56 K_CAPSLOCK,
57 K_CLRHOME,
58 K_INSERT
59 };
60 47
61 enum { 48 enum {
62 DEV_BUSY=0, 49 DEV_BUSY=0,
63 DEV_READY 50 DEV_READY
64 }; 51 };
65 52
66 /* The translation tables from a console scancode to a SDL keysym */
67 static SDLKey keymap[ATARIBIOS_MAXKEYS];
68
69 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym,
70 SDL_bool pressed);
71 static void UpdateSpecialKeys(int special_keys_state); 53 static void UpdateSpecialKeys(int special_keys_state);
72 54
73 void AtariGemdos_InitOSKeymap(_THIS) 55 void AtariGemdos_InitOSKeymap(_THIS)
74 { 56 {
75 int i, vectors_mask; 57 int i, vectors_mask;
76 unsigned long dummy; 58 unsigned long dummy;
77 59
78 SDL_memset(gemdos_currentkeyboard, 0, sizeof(gemdos_currentkeyboard)); 60 SDL_memset(gemdos_currentkeyboard, 0, sizeof(gemdos_currentkeyboard));
79 SDL_memset(gemdos_previouskeyboard, 0, sizeof(gemdos_previouskeyboard)); 61 SDL_memset(gemdos_previouskeyboard, 0, sizeof(gemdos_previouskeyboard));
80 62
81 /* Initialize keymap */
82 for ( i=0; i<ATARIBIOS_MAXKEYS; i++ )
83 keymap[i] = SDLK_UNKNOWN;
84
85 /* Functions keys */
86 for ( i = 0; i<10; i++ )
87 keymap[SCANCODE_F1 + i] = SDLK_F1+i;
88
89 /* Cursor keypad */
90 keymap[SCANCODE_HELP] = SDLK_HELP;
91 keymap[SCANCODE_UNDO] = SDLK_UNDO;
92 keymap[SCANCODE_INSERT] = SDLK_INSERT;
93 keymap[SCANCODE_CLRHOME] = SDLK_HOME;
94 keymap[SCANCODE_UP] = SDLK_UP;
95 keymap[SCANCODE_DOWN] = SDLK_DOWN;
96 keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
97 keymap[SCANCODE_LEFT] = SDLK_LEFT;
98
99 /* Special keys */
100 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
101 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
102 keymap[SCANCODE_TAB] = SDLK_TAB;
103 keymap[SCANCODE_ENTER] = SDLK_RETURN;
104 keymap[SCANCODE_DELETE] = SDLK_DELETE;
105 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
106 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
107 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
108 keymap[SCANCODE_LEFTALT] = SDLK_LALT;
109 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
110
111 use_dev_mouse = (SDL_AtariDevMouse_Open()!=0) ? SDL_TRUE : SDL_FALSE; 63 use_dev_mouse = (SDL_AtariDevMouse_Open()!=0) ? SDL_TRUE : SDL_FALSE;
112 64
113 vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS; /* XBIOS joystick events */ 65 vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS; /* XBIOS joystick events */
114 if (!use_dev_mouse) { 66 if (!use_dev_mouse) {
115 vectors_mask |= ATARI_XBIOS_MOUSEEVENTS; /* XBIOS mouse events */ 67 vectors_mask |= ATARI_XBIOS_MOUSEEVENTS; /* XBIOS mouse events */
116 } 68 }
117 if (Getcookie(C_MiNT, &dummy)==C_FOUND) { 69 /* if (Getcookie(C_MiNT, &dummy)==C_FOUND) {
118 vectors_mask = 0; 70 vectors_mask = 0;
119 } 71 }*/
120 SDL_AtariXbios_InstallVectors(vectors_mask); 72 SDL_AtariXbios_InstallVectors(vectors_mask);
121 } 73 }
122 74
123 void AtariGemdos_PumpEvents(_THIS) 75 void AtariGemdos_PumpEvents(_THIS)
124 { 76 {
128 /* Update pressed keys */ 80 /* Update pressed keys */
129 SDL_memset(gemdos_currentkeyboard, 0, ATARIBIOS_MAXKEYS); 81 SDL_memset(gemdos_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
130 82
131 while (Cconis()!=DEV_BUSY) { 83 while (Cconis()!=DEV_BUSY) {
132 unsigned long key_pressed; 84 unsigned long key_pressed;
133 unsigned char scancode, asciicode;
134
135 key_pressed=Cnecin(); 85 key_pressed=Cnecin();
136 86 gemdos_currentkeyboard[(key_pressed>>16)&(ATARIBIOS_MAXKEYS-1)]=0xFF;
137 asciicode = key_pressed;
138 scancode = key_pressed >> 16;
139
140 gemdos_currentkeyboard[scancode]=0xFF;
141 gemdos_currentascii[scancode]=asciicode;
142 } 87 }
143 88
144 /* Read special keys */ 89 /* Read special keys */
145 UpdateSpecialKeys(Kbshift(-1)); 90 UpdateSpecialKeys(Kbshift(-1));
146 91
147 /* Now generate events */ 92 /* Now generate events */
148 for (i=0; i<ATARIBIOS_MAXKEYS; i++) { 93 for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
149 /* Key pressed ? */ 94 /* Key pressed ? */
150 if (gemdos_currentkeyboard[i] && !gemdos_previouskeyboard[i]) 95 if (gemdos_currentkeyboard[i] && !gemdos_previouskeyboard[i])
151 SDL_PrivateKeyboard(SDL_PRESSED, 96 SDL_PrivateKeyboard(SDL_PRESSED,
152 TranslateKey(i, gemdos_currentascii[i], &keysym, SDL_TRUE)); 97 SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
153 98
154 /* Key unpressed ? */ 99 /* Key unpressed ? */
155 if (gemdos_previouskeyboard[i] && !gemdos_currentkeyboard[i]) 100 if (gemdos_previouskeyboard[i] && !gemdos_currentkeyboard[i])
156 SDL_PrivateKeyboard(SDL_RELEASED, 101 SDL_PrivateKeyboard(SDL_RELEASED,
157 TranslateKey(i, gemdos_currentascii[i], &keysym, SDL_FALSE)); 102 SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE));
158 } 103 }
159 104
160 if (use_dev_mouse) { 105 if (use_dev_mouse) {
161 SDL_AtariDevMouse_PostMouseEvents(this, SDL_TRUE); 106 SDL_AtariDevMouse_PostMouseEvents(this, SDL_TRUE);
162 } else { 107 } else {
163 SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE); 108 SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE);
164 } 109 }
165 110
166 /* Will be previous table */ 111 /* Will be previous table */
167 SDL_memcpy(gemdos_previouskeyboard, gemdos_currentkeyboard, ATARIBIOS_MAXKEYS); 112 SDL_memcpy(gemdos_previouskeyboard, gemdos_currentkeyboard, sizeof(gemdos_previouskeyboard));
168 } 113 }
169 114
170 static void UpdateSpecialKeys(int special_keys_state) 115 static void UpdateSpecialKeys(int special_keys_state)
171 { 116 {
172 #define UPDATE_SPECIAL_KEYS(numbit,scancode) \ 117 #define UPDATE_SPECIAL_KEYS(numbit,scancode) \
173 { \ 118 { \
174 if (special_keys_state & (1<<(numbit))) { \ 119 if (special_keys_state & (1<<(numbit))) { \
175 gemdos_currentkeyboard[scancode]=0xFF; \ 120 gemdos_currentkeyboard[scancode]=0xFF; \
176 gemdos_currentascii[scancode]=0; \
177 } \ 121 } \
178 } 122 }
179 123
180 UPDATE_SPECIAL_KEYS(K_RSHIFT, SCANCODE_RIGHTSHIFT); 124 UPDATE_SPECIAL_KEYS(K_RSHIFT, SCANCODE_RIGHTSHIFT);
181 UPDATE_SPECIAL_KEYS(K_LSHIFT, SCANCODE_LEFTSHIFT); 125 UPDATE_SPECIAL_KEYS(K_LSHIFT, SCANCODE_LEFTSHIFT);
182 UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL); 126 UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL);
183 UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT); 127 UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT);
184 UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK); 128 UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
185 } 129 }
186 130
187 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym,
188 SDL_bool pressed)
189 {
190 /* Set the keysym information */
191 keysym->scancode = scancode;
192
193 if (asciicode)
194 keysym->sym = asciicode;
195 else
196 keysym->sym = keymap[scancode];
197
198 keysym->mod = KMOD_NONE;
199 keysym->unicode = 0;
200 if (SDL_TranslateUNICODE && pressed) {
201 keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
202 }
203
204 return(keysym);
205 }
206
207 void AtariGemdos_ShutdownEvents(void) 131 void AtariGemdos_ShutdownEvents(void)
208 { 132 {
209 SDL_AtariXbios_RestoreVectors(); 133 SDL_AtariXbios_RestoreVectors();
210 if (use_dev_mouse) { 134 if (use_dev_mouse) {
211 SDL_AtariDevMouse_Close(); 135 SDL_AtariDevMouse_Close();