2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 * GEM SDL video driver implementation
30 * inspired from the Dummy SDL driver
34 * Olivier Landemarre, Johan Klockars, Xavier Joubert, Claude Attard
42 #include "SDL_sysevents.h"
43 #include "SDL_events_c.h"
44 #include "SDL_gemvideo.h"
45 #include "SDL_gemevents_c.h"
46 #include "SDL_atarikeys.h" /* for keyboard scancodes */
47 #include "SDL_xbiosinterrupt_s.h"
51 #define ATARIBIOS_MAXKEYS 128
55 static unsigned char gem_currentkeyboard[ATARIBIOS_MAXKEYS];
56 static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS];
57 static unsigned char gem_currentascii[ATARIBIOS_MAXKEYS];
59 /* The translation tables from a console scancode to a SDL keysym */
60 static SDLKey keymap[ATARIBIOS_MAXKEYS];
62 /* Functions prototypes */
64 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym);
65 static int do_messages(_THIS, short *message);
66 static void do_keyboard(short kc, short ks);
67 static void do_mouse(_THIS, short mx, short my, short mb, short ks);
71 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym)
73 /* Set the keysym information */
74 keysym->scancode = scancode;
77 keysym->sym = asciicode;
79 keysym->sym = keymap[scancode];
81 keysym->mod = KMOD_NONE;
87 void GEM_InitOSKeymap(_THIS)
91 memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
92 memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard));
93 memset(gem_currentascii, 0, sizeof(gem_currentascii));
95 /* Initialize keymap */
96 for ( i=0; i<sizeof(keymap); i++ )
97 keymap[i] = SDLK_UNKNOWN;
100 for ( i = 0; i<10; i++ )
101 keymap[SCANCODE_F1 + i] = SDLK_F1+i;
104 keymap[SCANCODE_HELP] = SDLK_HELP;
105 keymap[SCANCODE_UNDO] = SDLK_UNDO;
106 keymap[SCANCODE_INSERT] = SDLK_INSERT;
107 keymap[SCANCODE_CLRHOME] = SDLK_HOME;
108 keymap[SCANCODE_UP] = SDLK_UP;
109 keymap[SCANCODE_DOWN] = SDLK_DOWN;
110 keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
111 keymap[SCANCODE_LEFT] = SDLK_LEFT;
114 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
115 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
116 keymap[SCANCODE_TAB] = SDLK_TAB;
117 keymap[SCANCODE_ENTER] = SDLK_RETURN;
118 keymap[SCANCODE_DELETE] = SDLK_DELETE;
119 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
120 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
121 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
122 keymap[SCANCODE_LEFTALT] = SDLK_LALT;
123 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
126 GEM_mouse_relative = SDL_FALSE;
129 void GEM_PumpEvents(_THIS)
131 short mousex, mousey, mouseb, dummy;
132 short kstate, prevkc, prevks;
136 memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard));
146 resultat = evnt_multi(
147 MU_MESAG|MU_TIMER|MU_KEYBD,
153 &dummy,&dummy,&dummy,&kstate,&kc,&dummy
156 /* Message event ? */
157 if (resultat & MU_MESAG)
158 quit = do_messages(this, buffer);
160 /* Keyboard event ? */
161 if (resultat & MU_KEYBD) {
162 if ((prevkc != kc) || (prevks != kstate)) {
163 do_keyboard(kc,kstate);
165 /* Avoid looping, if repeating same key */
171 if ((resultat & MU_TIMER) || quit)
176 graf_mkstate(&mousex, &mousey, &mouseb, &kstate);
177 do_mouse(this, mousex, mousey, mouseb, kstate);
179 /* Now generate keyboard events */
180 for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
182 if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
183 SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(i, gem_currentascii[i], &keysym));
185 /* Key unpressed ? */
186 if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
187 SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(i, gem_currentascii[i], &keysym));
190 memcpy(gem_previouskeyboard,gem_currentkeyboard,sizeof(gem_previouskeyboard));
193 static int do_messages(_THIS, short *message)
198 switch (message[0]) {
201 posted = SDL_PrivateQuit();
205 wind_set(message[3],WF_CURRXYWH,message[4],message[5],message[6],message[7]);
208 wind_set(message[3],WF_TOP,message[4],0,0,0);
209 SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
212 GEM_wind_redraw(this, message[3],&message[4]);
216 wind_set(message[3],WF_ICONIFY,message[4],message[5],message[6],message[7]);
217 /* If we're active, make ourselves inactive */
218 if ( SDL_GetAppState() & SDL_APPACTIVE ) {
219 /* Send an internal deactivate event */
220 SDL_PrivateAppActive(0, SDL_APPACTIVE|SDL_APPINPUTFOCUS);
222 /* Update window title */
223 if (GEM_refresh_name && GEM_icon_name) {
224 wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_icon_name)>>16),(short)(((unsigned long)GEM_icon_name) & 0xffff),0,0);
225 GEM_refresh_name = SDL_FALSE;
229 wind_set(message[3],WF_UNICONIFY,message[4],message[5],message[6],message[7]);
230 /* If we're not active, make ourselves active */
231 if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) {
232 /* Send an internal activate event */
233 SDL_PrivateAppActive(1, SDL_APPACTIVE);
235 if (GEM_refresh_name && GEM_title_name) {
236 wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
237 GEM_refresh_name = SDL_FALSE;
241 wind_set (message[3], WF_CURRXYWH, message[4], message[5], message[6], message[7]);
242 GEM_win_fulled = SDL_FALSE; /* Cancel maximized flag */
243 SDL_PrivateResize(message[6], message[7]);
249 if (GEM_win_fulled) {
250 wind_get (message[3], WF_PREVXYWH, &x, &y, &w, &h);
251 GEM_win_fulled = SDL_FALSE;
257 GEM_win_fulled = SDL_TRUE;
259 wind_set (message[3], WF_CURRXYWH, x, y, w, h);
260 SDL_PrivateResize(w, h);
265 SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
272 static void do_keyboard(short kc, short ks)
274 int scancode, asciicode;
277 scancode=(kc>>8) & 127;
280 gem_currentkeyboard[scancode]=0xFF;
281 gem_currentascii[scancode]=asciicode;
284 /* Read special keys */
286 gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;
288 gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF;
290 gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
292 gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;
295 static void do_mouse(_THIS, short mx, short my, short mb, short ks)
297 static short prevmousex=0, prevmousey=0, prevmouseb=0;
300 if ((prevmousex!=mx) || (prevmousey!=my)) {
301 if (GEM_mouse_relative) {
302 SDL_PrivateMouseMotion(0, 1, SDL_AtariXbios_mousex, SDL_AtariXbios_mousey);
303 SDL_AtariXbios_mousex = SDL_AtariXbios_mousey = 0;
305 SDL_PrivateMouseMotion(0, 1, mx, my);
312 if (prevmouseb!=mb) {
316 int curbutton, prevbutton;
318 curbutton = mb & (1<<i);
319 prevbutton = prevmouseb & (1<<i);
321 if (curbutton && !prevbutton) {
322 SDL_PrivateMouseButton(SDL_PRESSED, i+1, 0, 0);
324 if (!curbutton && prevbutton) {
325 SDL_PrivateMouseButton(SDL_RELEASED, i+1, 0, 0);
331 /* Read special keys */
333 gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;
335 gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF;
337 gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
339 gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;