comparison src/video/ataricommon/SDL_gemdosevents.c @ 2030:d774e9d7c2a8

Forward keyboard reworking from 1.2
author Patrice Mandin <patmandin@gmail.com>
date Wed, 20 Sep 2006 19:47:09 +0000
parents d20f4510c718
children f54073d86c82
comparison
equal deleted inserted replaced
2029:8640d90b0406 2030:d774e9d7c2a8
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 47
50 /* Special keys state */ 48 enum {
51 enum 49 DEV_BUSY=0,
52 { 50 DEV_READY
53 K_RSHIFT = 0,
54 K_LSHIFT,
55 K_CTRL,
56 K_ALT,
57 K_CAPSLOCK,
58 K_CLRHOME,
59 K_INSERT
60 }; 51 };
61 52
62 enum
63 {
64 DEV_BUSY = 0,
65 DEV_READY
66 };
67
68 /* The translation tables from a console scancode to a SDL keysym */
69 static SDLKey keymap[ATARIBIOS_MAXKEYS];
70
71 static SDL_keysym *TranslateKey(int scancode, int asciicode,
72 SDL_keysym * keysym, SDL_bool pressed);
73 static void UpdateSpecialKeys(int special_keys_state); 53 static void UpdateSpecialKeys(int special_keys_state);
74 54
75 void 55 void
76 AtariGemdos_InitOSKeymap(_THIS) 56 AtariGemdos_InitOSKeymap(_THIS)
77 { 57 {
78 int i, vectors_mask; 58 int i, vectors_mask;
79 unsigned long dummy; 59 unsigned long dummy;
80 60
81 SDL_memset(gemdos_currentkeyboard, 0, sizeof(gemdos_currentkeyboard)); 61 SDL_memset(gemdos_currentkeyboard, 0, sizeof(gemdos_currentkeyboard));
82 SDL_memset(gemdos_previouskeyboard, 0, sizeof(gemdos_previouskeyboard)); 62 SDL_memset(gemdos_previouskeyboard, 0, sizeof(gemdos_previouskeyboard));
83
84 /* Initialize keymap */
85 for (i = 0; i < ATARIBIOS_MAXKEYS; i++)
86 keymap[i] = SDLK_UNKNOWN;
87
88 /* Functions keys */
89 for (i = 0; i < 10; i++)
90 keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
91
92 /* Cursor keypad */
93 keymap[SCANCODE_HELP] = SDLK_HELP;
94 keymap[SCANCODE_UNDO] = SDLK_UNDO;
95 keymap[SCANCODE_INSERT] = SDLK_INSERT;
96 keymap[SCANCODE_CLRHOME] = SDLK_HOME;
97 keymap[SCANCODE_UP] = SDLK_UP;
98 keymap[SCANCODE_DOWN] = SDLK_DOWN;
99 keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
100 keymap[SCANCODE_LEFT] = SDLK_LEFT;
101
102 /* Special keys */
103 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
104 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
105 keymap[SCANCODE_TAB] = SDLK_TAB;
106 keymap[SCANCODE_ENTER] = SDLK_RETURN;
107 keymap[SCANCODE_DELETE] = SDLK_DELETE;
108 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
109 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
110 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
111 keymap[SCANCODE_LEFTALT] = SDLK_LALT;
112 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
113 63
114 use_dev_mouse = (SDL_AtariDevMouse_Open() != 0) ? SDL_TRUE : SDL_FALSE; 64 use_dev_mouse = (SDL_AtariDevMouse_Open() != 0) ? SDL_TRUE : SDL_FALSE;
115 65
116 vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS; /* XBIOS joystick events */ 66 vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS; /* XBIOS joystick events */
117 if (!use_dev_mouse) { 67 if (!use_dev_mouse) {
132 /* Update pressed keys */ 82 /* Update pressed keys */
133 SDL_memset(gemdos_currentkeyboard, 0, ATARIBIOS_MAXKEYS); 83 SDL_memset(gemdos_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
134 84
135 while (Cconis() != DEV_BUSY) { 85 while (Cconis() != DEV_BUSY) {
136 unsigned long key_pressed; 86 unsigned long key_pressed;
137 unsigned char scancode, asciicode; 87 key_pressed=Cnecin();
138 88 gemdos_currentkeyboard[(key_pressed>>16)&(ATARIBIOS_MAXKEYS-1)]=0xFF;
139 key_pressed = Cnecin();
140
141 asciicode = key_pressed;
142 scancode = key_pressed >> 16;
143
144 gemdos_currentkeyboard[scancode] = 0xFF;
145 gemdos_currentascii[scancode] = asciicode;
146 } 89 }
147 90
148 /* Read special keys */ 91 /* Read special keys */
149 UpdateSpecialKeys(Kbshift(-1)); 92 UpdateSpecialKeys(Kbshift(-1));
150 93
151 /* Now generate events */ 94 /* Now generate events */
152 for (i = 0; i < ATARIBIOS_MAXKEYS; i++) { 95 for (i = 0; i < ATARIBIOS_MAXKEYS; i++) {
153 /* Key pressed ? */ 96 /* Key pressed ? */
154 if (gemdos_currentkeyboard[i] && !gemdos_previouskeyboard[i]) 97 if (gemdos_currentkeyboard[i] && !gemdos_previouskeyboard[i])
155 SDL_PrivateKeyboard(SDL_PRESSED, 98 SDL_PrivateKeyboard(SDL_PRESSED,
156 TranslateKey(i, gemdos_currentascii[i], 99 SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
157 &keysym, SDL_TRUE));
158 100
159 /* Key unpressed ? */ 101 /* Key unpressed ? */
160 if (gemdos_previouskeyboard[i] && !gemdos_currentkeyboard[i]) 102 if (gemdos_previouskeyboard[i] && !gemdos_currentkeyboard[i])
161 SDL_PrivateKeyboard(SDL_RELEASED, 103 SDL_PrivateKeyboard(SDL_RELEASED,
162 TranslateKey(i, gemdos_currentascii[i], 104 SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE));
163 &keysym, SDL_FALSE));
164 } 105 }
165 106
166 if (use_dev_mouse) { 107 if (use_dev_mouse) {
167 SDL_AtariDevMouse_PostMouseEvents(this, SDL_TRUE); 108 SDL_AtariDevMouse_PostMouseEvents(this, SDL_TRUE);
168 } else { 109 } else {
169 SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE); 110 SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE);
170 } 111 }
171 112
172 /* Will be previous table */ 113 /* Will be previous table */
173 SDL_memcpy(gemdos_previouskeyboard, gemdos_currentkeyboard, 114 SDL_memcpy(gemdos_previouskeyboard, gemdos_currentkeyboard,
174 ATARIBIOS_MAXKEYS); 115 sizeof(gemdos_previouskeyboard));
175 } 116 }
176 117
177 static void 118 static void
178 UpdateSpecialKeys(int special_keys_state) 119 UpdateSpecialKeys(int special_keys_state)
179 { 120 {
190 UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL); 131 UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL);
191 UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT); 132 UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT);
192 UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK); 133 UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
193 } 134 }
194 135
195 static SDL_keysym *
196 TranslateKey(int scancode, int asciicode, SDL_keysym * keysym,
197 SDL_bool pressed)
198 {
199 /* Set the keysym information */
200 keysym->scancode = scancode;
201
202 if (asciicode)
203 keysym->sym = asciicode;
204 else
205 keysym->sym = keymap[scancode];
206
207 keysym->mod = KMOD_NONE;
208 keysym->unicode = 0;
209 if (SDL_TranslateUNICODE && pressed) {
210 keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
211 }
212
213 return (keysym);
214 }
215
216 void 136 void
217 AtariGemdos_ShutdownEvents(void) 137 AtariGemdos_ShutdownEvents(void)
218 { 138 {
219 SDL_AtariXbios_RestoreVectors(); 139 SDL_AtariXbios_RestoreVectors();
220 if (use_dev_mouse) { 140 if (use_dev_mouse) {