comparison src/video/ataricommon/SDL_gemdosevents.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 2405517b5eab
children d20f4510c718
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
46 static unsigned char gemdos_previouskeyboard[ATARIBIOS_MAXKEYS]; 46 static unsigned char gemdos_previouskeyboard[ATARIBIOS_MAXKEYS];
47 static unsigned char gemdos_currentascii[ATARIBIOS_MAXKEYS]; 47 static unsigned char gemdos_currentascii[ATARIBIOS_MAXKEYS];
48 static SDL_bool use_dev_mouse = SDL_FALSE; 48 static SDL_bool use_dev_mouse = SDL_FALSE;
49 49
50 /* Special keys state */ 50 /* Special keys state */
51 enum { 51 enum
52 K_RSHIFT=0, 52 {
53 K_LSHIFT, 53 K_RSHIFT = 0,
54 K_CTRL, 54 K_LSHIFT,
55 K_ALT, 55 K_CTRL,
56 K_CAPSLOCK, 56 K_ALT,
57 K_CLRHOME, 57 K_CAPSLOCK,
58 K_INSERT 58 K_CLRHOME,
59 K_INSERT
59 }; 60 };
60 61
61 enum { 62 enum
62 DEV_BUSY=0, 63 {
63 DEV_READY 64 DEV_BUSY = 0,
65 DEV_READY
64 }; 66 };
65 67
66 /* The translation tables from a console scancode to a SDL keysym */ 68 /* The translation tables from a console scancode to a SDL keysym */
67 static SDLKey keymap[ATARIBIOS_MAXKEYS]; 69 static SDLKey keymap[ATARIBIOS_MAXKEYS];
68 70
69 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym, 71 static SDL_keysym *TranslateKey(int scancode, int asciicode,
70 SDL_bool pressed); 72 SDL_keysym * keysym, SDL_bool pressed);
71 static void UpdateSpecialKeys(int special_keys_state); 73 static void UpdateSpecialKeys(int special_keys_state);
72 74
73 void AtariGemdos_InitOSKeymap(_THIS) 75 void
74 { 76 AtariGemdos_InitOSKeymap(_THIS)
75 int i, vectors_mask; 77 {
76 unsigned long dummy; 78 int i, vectors_mask;
77 79 unsigned long dummy;
78 SDL_memset(gemdos_currentkeyboard, 0, sizeof(gemdos_currentkeyboard)); 80
79 SDL_memset(gemdos_previouskeyboard, 0, sizeof(gemdos_previouskeyboard)); 81 SDL_memset(gemdos_currentkeyboard, 0, sizeof(gemdos_currentkeyboard));
80 82 SDL_memset(gemdos_previouskeyboard, 0, sizeof(gemdos_previouskeyboard));
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 use_dev_mouse = (SDL_AtariDevMouse_Open()!=0) ? SDL_TRUE : SDL_FALSE; 113
112 114 use_dev_mouse = (SDL_AtariDevMouse_Open() != 0) ? SDL_TRUE : SDL_FALSE;
113 vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS; /* XBIOS joystick events */ 115
114 if (!use_dev_mouse) { 116 vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS; /* XBIOS joystick events */
115 vectors_mask |= ATARI_XBIOS_MOUSEEVENTS; /* XBIOS mouse events */ 117 if (!use_dev_mouse) {
116 } 118 vectors_mask |= ATARI_XBIOS_MOUSEEVENTS; /* XBIOS mouse events */
117 if (Getcookie(C_MiNT, &dummy)==C_FOUND) { 119 }
118 vectors_mask = 0; 120 if (Getcookie(C_MiNT, &dummy) == C_FOUND) {
119 } 121 vectors_mask = 0;
120 SDL_AtariXbios_InstallVectors(vectors_mask); 122 }
121 } 123 SDL_AtariXbios_InstallVectors(vectors_mask);
122 124 }
123 void AtariGemdos_PumpEvents(_THIS) 125
124 { 126 void
125 int i; 127 AtariGemdos_PumpEvents(_THIS)
126 SDL_keysym keysym; 128 {
127 129 int i;
128 /* Update pressed keys */ 130 SDL_keysym keysym;
129 SDL_memset(gemdos_currentkeyboard, 0, ATARIBIOS_MAXKEYS); 131
130 132 /* Update pressed keys */
131 while (Cconis()!=DEV_BUSY) { 133 SDL_memset(gemdos_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
132 unsigned long key_pressed; 134
133 unsigned char scancode, asciicode; 135 while (Cconis() != DEV_BUSY) {
134 136 unsigned long key_pressed;
135 key_pressed=Cnecin(); 137 unsigned char scancode, asciicode;
136 138
137 asciicode = key_pressed; 139 key_pressed = Cnecin();
138 scancode = key_pressed >> 16; 140
139 141 asciicode = key_pressed;
140 gemdos_currentkeyboard[scancode]=0xFF; 142 scancode = key_pressed >> 16;
141 gemdos_currentascii[scancode]=asciicode; 143
142 } 144 gemdos_currentkeyboard[scancode] = 0xFF;
143 145 gemdos_currentascii[scancode] = asciicode;
144 /* Read special keys */ 146 }
145 UpdateSpecialKeys(Kbshift(-1)); 147
146 148 /* Read special keys */
147 /* Now generate events */ 149 UpdateSpecialKeys(Kbshift(-1));
148 for (i=0; i<ATARIBIOS_MAXKEYS; i++) { 150
149 /* Key pressed ? */ 151 /* Now generate events */
150 if (gemdos_currentkeyboard[i] && !gemdos_previouskeyboard[i]) 152 for (i = 0; i < ATARIBIOS_MAXKEYS; i++) {
151 SDL_PrivateKeyboard(SDL_PRESSED, 153 /* Key pressed ? */
152 TranslateKey(i, gemdos_currentascii[i], &keysym, SDL_TRUE)); 154 if (gemdos_currentkeyboard[i] && !gemdos_previouskeyboard[i])
153 155 SDL_PrivateKeyboard(SDL_PRESSED,
154 /* Key unpressed ? */ 156 TranslateKey(i, gemdos_currentascii[i],
155 if (gemdos_previouskeyboard[i] && !gemdos_currentkeyboard[i]) 157 &keysym, SDL_TRUE));
156 SDL_PrivateKeyboard(SDL_RELEASED, 158
157 TranslateKey(i, gemdos_currentascii[i], &keysym, SDL_FALSE)); 159 /* Key unpressed ? */
158 } 160 if (gemdos_previouskeyboard[i] && !gemdos_currentkeyboard[i])
159 161 SDL_PrivateKeyboard(SDL_RELEASED,
160 if (use_dev_mouse) { 162 TranslateKey(i, gemdos_currentascii[i],
161 SDL_AtariDevMouse_PostMouseEvents(this, SDL_TRUE); 163 &keysym, SDL_FALSE));
162 } else { 164 }
163 SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE); 165
164 } 166 if (use_dev_mouse) {
165 167 SDL_AtariDevMouse_PostMouseEvents(this, SDL_TRUE);
166 /* Will be previous table */ 168 } else {
167 SDL_memcpy(gemdos_previouskeyboard, gemdos_currentkeyboard, ATARIBIOS_MAXKEYS); 169 SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE);
168 } 170 }
169 171
170 static void UpdateSpecialKeys(int special_keys_state) 172 /* Will be previous table */
173 SDL_memcpy(gemdos_previouskeyboard, gemdos_currentkeyboard,
174 ATARIBIOS_MAXKEYS);
175 }
176
177 static void
178 UpdateSpecialKeys(int special_keys_state)
171 { 179 {
172 #define UPDATE_SPECIAL_KEYS(numbit,scancode) \ 180 #define UPDATE_SPECIAL_KEYS(numbit,scancode) \
173 { \ 181 { \
174 if (special_keys_state & (1<<(numbit))) { \ 182 if (special_keys_state & (1<<(numbit))) { \
175 gemdos_currentkeyboard[scancode]=0xFF; \ 183 gemdos_currentkeyboard[scancode]=0xFF; \
176 gemdos_currentascii[scancode]=0; \ 184 gemdos_currentascii[scancode]=0; \
177 } \ 185 } \
178 } 186 }
179 187
180 UPDATE_SPECIAL_KEYS(K_RSHIFT, SCANCODE_RIGHTSHIFT); 188 UPDATE_SPECIAL_KEYS(K_RSHIFT, SCANCODE_RIGHTSHIFT);
181 UPDATE_SPECIAL_KEYS(K_LSHIFT, SCANCODE_LEFTSHIFT); 189 UPDATE_SPECIAL_KEYS(K_LSHIFT, SCANCODE_LEFTSHIFT);
182 UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL); 190 UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL);
183 UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT); 191 UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT);
184 UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK); 192 UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
185 } 193 }
186 194
187 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym, 195 static SDL_keysym *
188 SDL_bool pressed) 196 TranslateKey(int scancode, int asciicode, SDL_keysym * keysym,
189 { 197 SDL_bool pressed)
190 /* Set the keysym information */ 198 {
191 keysym->scancode = scancode; 199 /* Set the keysym information */
192 200 keysym->scancode = scancode;
193 if (asciicode) 201
194 keysym->sym = asciicode; 202 if (asciicode)
195 else 203 keysym->sym = asciicode;
196 keysym->sym = keymap[scancode]; 204 else
197 205 keysym->sym = keymap[scancode];
198 keysym->mod = KMOD_NONE; 206
199 keysym->unicode = 0; 207 keysym->mod = KMOD_NONE;
200 if (SDL_TranslateUNICODE && pressed) { 208 keysym->unicode = 0;
201 keysym->unicode = SDL_AtariToUnicodeTable[asciicode]; 209 if (SDL_TranslateUNICODE && pressed) {
202 } 210 keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
203 211 }
204 return(keysym); 212
205 } 213 return (keysym);
206 214 }
207 void AtariGemdos_ShutdownEvents(void) 215
208 { 216 void
209 SDL_AtariXbios_RestoreVectors(); 217 AtariGemdos_ShutdownEvents(void)
210 if (use_dev_mouse) { 218 {
211 SDL_AtariDevMouse_Close(); 219 SDL_AtariXbios_RestoreVectors();
212 } 220 if (use_dev_mouse) {
213 } 221 SDL_AtariDevMouse_Close();
222 }
223 }
224
225 /* vi: set ts=4 sw=4 expandtab: */