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