2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 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 "../ataricommon/SDL_atarikeys.h" /* for keyboard scancodes */
50 #define ATARIBIOS_MAXKEYS 128
54 static unsigned char gem_currentkeyboard[ATARIBIOS_MAXKEYS];
55 static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS];
56 static unsigned char gem_currentascii[ATARIBIOS_MAXKEYS];
58 static short prevmousex, prevmousey, prevmouseb;
60 /* The translation tables from a console scancode to a SDL keysym */
61 static SDLKey keymap[ATARIBIOS_MAXKEYS];
63 /* Functions prototypes */
65 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym);
66 static int do_messages(_THIS, short *message);
67 static void do_keyboard(short kc, short ks);
68 static void do_mouse(_THIS, short mx, short my, short mb);
72 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym)
74 /* Set the keysym information */
75 keysym->scancode = scancode;
78 keysym->sym = asciicode;
80 keysym->sym = keymap[scancode];
82 keysym->mod = KMOD_NONE;
88 void GEM_InitOSKeymap(_THIS)
92 memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
93 memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard));
94 memset(gem_currentascii, 0, sizeof(gem_currentascii));
96 /* Initialize keymap */
97 for ( i=0; i<sizeof(keymap); i++ )
98 keymap[i] = SDLK_UNKNOWN;
101 for ( i = 0; i<10; i++ )
102 keymap[SCANCODE_F1 + i] = SDLK_F1+i;
105 keymap[SCANCODE_HELP] = SDLK_HELP;
106 keymap[SCANCODE_UNDO] = SDLK_UNDO;
107 keymap[SCANCODE_INSERT] = SDLK_INSERT;
108 keymap[SCANCODE_CLRHOME] = SDLK_HOME;
109 keymap[SCANCODE_UP] = SDLK_UP;
110 keymap[SCANCODE_DOWN] = SDLK_DOWN;
111 keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
112 keymap[SCANCODE_LEFT] = SDLK_LEFT;
115 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
116 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
117 keymap[SCANCODE_TAB] = SDLK_TAB;
118 keymap[SCANCODE_ENTER] = SDLK_RETURN;
119 keymap[SCANCODE_DELETE] = SDLK_DELETE;
120 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
121 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
122 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
123 keymap[SCANCODE_LEFTALT] = SDLK_LALT;
124 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
127 prevmousex = prevmousey = prevmouseb = 0;
128 GEM_mouse_relative = SDL_FALSE;
131 void GEM_PumpEvents(_THIS)
133 short mx, my, mb, dummy;
137 memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard));
142 short buffer[8], kc, ks;
146 resultat = evnt_multi(
147 MU_MESAG|MU_TIMER|MU_KEYBD,
153 &dummy,&dummy,&dummy,&ks,&kc,&dummy
156 /* Message event ? */
157 if (resultat & MU_MESAG)
158 quit = do_messages(this, buffer);
160 /* Keyboard event ? */
161 if (resultat & MU_KEYBD)
167 if ((resultat & MU_TIMER) || quit)
172 graf_mkstate(&mx, &my, &mb, &dummy);
173 do_mouse(this, mx, my, mb);
175 /* Now generates keyboard events */
176 for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
178 if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
179 SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(i, gem_currentascii[i], &keysym));
181 /* Key unpressed ? */
182 if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
183 SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(i, gem_currentascii[i], &keysym));
186 memcpy(gem_previouskeyboard,gem_currentkeyboard,sizeof(gem_previouskeyboard));
189 static int do_messages(_THIS, short *message)
194 switch (message[0]) {
197 posted = SDL_PrivateQuit();
201 wind_set(message[3],WF_CURRXYWH,message[4],message[5],message[6],message[7]);
204 wind_set(message[3],WF_TOP,message[4],0,0,0);
205 SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
208 GEM_wind_redraw(this, message[3],&message[4]);
212 wind_set(message[3],WF_ICONIFY,message[4],message[5],message[6],message[7]);
213 /* If we're active, make ourselves inactive */
214 if ( SDL_GetAppState() & SDL_APPACTIVE ) {
215 /* Send an internal deactivate event */
216 SDL_PrivateAppActive(0, SDL_APPACTIVE|SDL_APPINPUTFOCUS);
220 wind_set(message[3],WF_UNICONIFY,message[4],message[5],message[6],message[7]);
221 /* If we're not active, make ourselves active */
222 if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) {
223 /* Send an internal activate event */
224 SDL_PrivateAppActive(1, SDL_APPACTIVE);
228 wind_set (message[3], WF_CURRXYWH, message[4], message[5], message[6], message[7]);
229 GEM_win_fulled = SDL_FALSE; /* Cancel maximized flag */
230 SDL_PrivateResize(message[6], message[7]);
236 if (GEM_win_fulled) {
237 wind_get (message[3], WF_PREVXYWH, &x, &y, &w, &h);
238 GEM_win_fulled = SDL_FALSE;
244 GEM_win_fulled = SDL_TRUE;
246 wind_set (message[3], WF_CURRXYWH, x, y, w, h);
247 SDL_PrivateResize(w, h);
252 SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
259 static void do_keyboard(short kc, short ks)
261 int scancode, asciicode;
265 scancode=(kc>>8) & 127;
268 gem_currentkeyboard[scancode]=0xFF;
269 gem_currentascii[scancode]=asciicode;
273 graf_mkstate(&dummy, &dummy, &dummy, &ks);
275 /* Read special keys */
277 gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;
279 gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF;
281 gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
283 gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;
286 static void do_mouse(_THIS, short mx, short my, short mb)
289 if ((prevmousex!=mx) || (prevmousey!=my)) {
290 if (GEM_mouse_relative) {
293 wind_get(GEM_handle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3]);
295 SDL_PrivateMouseMotion(0, 1, mx-wind_pxy[0], my-wind_pxy[1]);
297 SDL_PrivateMouseMotion(0, 1, mx, my);
304 if (prevmouseb!=mb) {
308 int curbutton, prevbutton;
310 curbutton = mb & (1<<i);
311 prevbutton = prevmouseb & (1<<i);
313 if (curbutton & !prevbutton) {
314 SDL_PrivateMouseButton(SDL_PRESSED, i, 0, 0);
316 if (!curbutton & prevbutton) {
317 SDL_PrivateMouseButton(SDL_RELEASED, i, 0, 0);