2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "SDL_config.h"
25 * GEM SDL video driver implementation
26 * inspired from the Dummy SDL driver
30 * Olivier Landemarre, Johan Klockars, Xavier Joubert, Claude Attard
35 #include "../../events/SDL_sysevents.h"
36 #include "../../events/SDL_events_c.h"
37 #include "SDL_gemvideo.h"
38 #include "SDL_gemevents_c.h"
39 #include "../ataricommon/SDL_atarikeys.h" /* for keyboard scancodes */
40 #include "../ataricommon/SDL_atarievents_c.h"
41 #include "../ataricommon/SDL_xbiosevents_c.h"
42 #include "../ataricommon/SDL_ataridevmouse_c.h"
46 static unsigned char gem_currentkeyboard[ATARIBIOS_MAXKEYS];
47 static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS];
49 /* Functions prototypes */
51 static int do_messages(_THIS, short *message);
52 static void do_keyboard(short kc, short ks);
53 static void do_mouse(_THIS, short mx, short my, short mb, short ks);
57 void GEM_InitOSKeymap(_THIS)
59 SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
60 SDL_memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard));
63 GEM_mouse_relative = SDL_FALSE;
65 SDL_Atari_InitInternalKeymap(this);
68 void GEM_PumpEvents(_THIS)
70 short mousex, mousey, mouseb, dummy;
71 short kstate, prevkc, prevks;
75 SDL_memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard));
80 int quit, resultat, event_mask, mouse_event;
88 event_mask = MU_MESAG|MU_TIMER|MU_KEYBD;
89 if (!GEM_fullscreen && (GEM_handle>=0)) {
90 wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
92 mouse_event = ( (SDL_GetAppState() & SDL_APPMOUSEFOCUS)
93 == SDL_APPMOUSEFOCUS) ? MO_LEAVE : MO_ENTER;
96 resultat = evnt_multi(
99 mouse_event,x2,y2,w2,h2,
103 &dummy,&dummy,&dummy,&kstate,&kc,&dummy
106 /* Message event ? */
107 if (resultat & MU_MESAG)
108 quit = do_messages(this, buffer);
110 /* Keyboard event ? */
111 if (resultat & MU_KEYBD) {
112 if ((prevkc != kc) || (prevks != kstate)) {
113 do_keyboard(kc,kstate);
115 /* Avoid looping, if repeating same key */
120 /* Mouse entering/leaving window */
121 if (resultat & MU_M1) {
122 if (this->input_grab == SDL_GRAB_OFF) {
123 /* Switch mouse focus state */
124 SDL_PrivateAppActive((mouse_event == MO_ENTER),
127 GEM_CheckMouseMode(this);
131 if ((resultat & MU_TIMER) || quit)
136 graf_mkstate(&mousex, &mousey, &mouseb, &kstate);
137 do_mouse(this, mousex, mousey, mouseb, kstate);
139 /* Now generate keyboard events */
140 for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
142 if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
143 SDL_PrivateKeyboard(SDL_PRESSED,
144 SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
146 /* Key unpressed ? */
147 if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
148 SDL_PrivateKeyboard(SDL_RELEASED,
149 SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE));
152 SDL_memcpy(gem_previouskeyboard,gem_currentkeyboard,sizeof(gem_previouskeyboard));
154 /* Refresh window name ? */
155 if (GEM_refresh_name) {
156 const char *window_name =
157 (SDL_GetAppState() & SDL_APPACTIVE)
158 ? GEM_title_name : GEM_icon_name;
160 wind_set(GEM_handle,WF_NAME,
161 (short)(((unsigned long)window_name)>>16),
162 (short)(((unsigned long)window_name) & 0xffff),
165 GEM_refresh_name = SDL_FALSE;
169 static int do_messages(_THIS, short *message)
171 int quit, posted, check_mouse_mode;
174 quit = check_mouse_mode = 0;
175 switch (message[0]) {
178 posted = SDL_PrivateQuit();
182 wind_set(message[3],WF_CURRXYWH,message[4],message[5],message[6],message[7]);
185 wind_set(message[3],WF_TOP,message[4],0,0,0);
186 /* Continue with TOP event processing */
188 SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
189 if (VDI_setpalette) {
190 VDI_setpalette(this, VDI_curpalette);
192 check_mouse_mode = 1;
195 if (!GEM_lock_redraw) {
196 GEM_wind_redraw(this, message[3],&message[4]);
201 wind_set(message[3],WF_ICONIFY,message[4],message[5],message[6],message[7]);
202 /* If we're active, make ourselves inactive */
203 if ( SDL_GetAppState() & SDL_APPACTIVE ) {
204 /* Send an internal deactivate event */
205 SDL_PrivateAppActive(0, SDL_APPACTIVE);
207 /* Update window title */
208 if (GEM_refresh_name && GEM_icon_name) {
209 wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_icon_name)>>16),(short)(((unsigned long)GEM_icon_name) & 0xffff),0,0);
210 GEM_refresh_name = SDL_FALSE;
212 check_mouse_mode = 1;
215 wind_set(message[3],WF_UNICONIFY,message[4],message[5],message[6],message[7]);
216 /* If we're not active, make ourselves active */
217 if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) {
218 /* Send an internal activate event */
219 SDL_PrivateAppActive(1, SDL_APPACTIVE);
221 if (GEM_refresh_name && GEM_title_name) {
222 wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
223 GEM_refresh_name = SDL_FALSE;
225 check_mouse_mode = 1;
228 wind_set (message[3], WF_CURRXYWH, message[4], message[5], message[6], message[7]);
229 wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
230 GEM_win_fulled = SDL_FALSE; /* Cancel maximized flag */
231 GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers resized */
232 SDL_PrivateResize(w2, h2);
238 if (GEM_win_fulled) {
239 wind_get (message[3], WF_PREVXYWH, &x, &y, &w, &h);
240 GEM_win_fulled = SDL_FALSE;
246 GEM_win_fulled = SDL_TRUE;
248 wind_set (message[3], WF_CURRXYWH, x, y, w, h);
249 wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
250 GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers resized */
251 SDL_PrivateResize(w2, h2);
255 wind_set(message[3],WF_BOTTOM,0,0,0,0);
256 /* Continue with BOTTOM event processing */
258 SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
259 if (VDI_setpalette) {
260 VDI_setpalette(this, VDI_oldpalette);
262 check_mouse_mode = 1;
266 if (check_mouse_mode) {
267 GEM_CheckMouseMode(this);
273 static void do_keyboard(short kc, short ks)
278 scancode=(kc>>8) & (ATARIBIOS_MAXKEYS-1);
279 gem_currentkeyboard[scancode]=0xFF;
282 /* Read special keys */
284 gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;
286 gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF;
288 gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
290 gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;
293 static void do_mouse(_THIS, short mx, short my, short mb, short ks)
295 static short prevmousex=0, prevmousey=0, prevmouseb=0;
296 short x2, y2, w2, h2;
298 /* Don't return mouse events if out of window */
299 if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS)==0) {
303 /* Retrieve window coords, and generate mouse events accordingly */
307 if ((!GEM_fullscreen) && (GEM_handle>=0)) {
308 wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
310 /* Do not generate mouse button event if out of window working area */
311 if ((mx<x2) || (mx>=x2+w2) || (my<y2) || (my>=y2+h2)) {
317 if (GEM_mouse_relative) {
318 if (GEM_usedevmouse) {
319 SDL_AtariDevMouse_PostMouseEvents(this, SDL_FALSE);
321 SDL_AtariXbios_PostMouseEvents(this, SDL_FALSE);
324 if ((prevmousex!=mx) || (prevmousey!=my)) {
327 /* Give mouse position relative to window position */
329 if (posx<0) posx = 0;
330 if (posx>w2) posx = w2-1;
332 if (posy<0) posy = 0;
333 if (posy>h2) posy = h2-1;
335 SDL_PrivateMouseMotion(0, 0, posx, posy);
342 if (prevmouseb!=mb) {
346 int curbutton, prevbutton;
348 curbutton = mb & (1<<i);
349 prevbutton = prevmouseb & (1<<i);
351 if (curbutton && !prevbutton) {
352 SDL_PrivateMouseButton(SDL_PRESSED, i+1, 0, 0);
354 if (!curbutton && prevbutton) {
355 SDL_PrivateMouseButton(SDL_RELEASED, i+1, 0, 0);
361 /* Read special keys */
363 gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;
365 gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF;
367 gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
369 gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;