Skip to content

Latest commit

 

History

History
340 lines (285 loc) · 8.73 KB

SDL_gemevents.c

File metadata and controls

340 lines (285 loc) · 8.73 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Jan 4, 2004
Jan 4, 2004
3
Copyright (C) 1997-2004 Sam Lantinga
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id$";
#endif
/*
* GEM SDL video driver implementation
* inspired from the Dummy SDL driver
*
* Patrice Mandin
* and work from
* Olivier Landemarre, Johan Klockars, Xavier Joubert, Claude Attard
*/
#include <string.h>
#include <gem.h>
#include "SDL.h"
#include "SDL_sysevents.h"
#include "SDL_events_c.h"
#include "SDL_gemvideo.h"
#include "SDL_gemevents_c.h"
Mar 26, 2002
Mar 26, 2002
46
47
#include "SDL_atarikeys.h" /* for keyboard scancodes */
#include "SDL_xbiosinterrupt_s.h"
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* Defines */
#define ATARIBIOS_MAXKEYS 128
/* Variables */
static unsigned char gem_currentkeyboard[ATARIBIOS_MAXKEYS];
static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS];
static unsigned char gem_currentascii[ATARIBIOS_MAXKEYS];
/* The translation tables from a console scancode to a SDL keysym */
static SDLKey keymap[ATARIBIOS_MAXKEYS];
/* Functions prototypes */
static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym);
static int do_messages(_THIS, short *message);
static void do_keyboard(short kc, short ks);
Mar 26, 2002
Mar 26, 2002
67
static void do_mouse(_THIS, short mx, short my, short mb, short ks);
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* Functions */
static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym)
{
/* Set the keysym information */
keysym->scancode = scancode;
if (asciicode)
keysym->sym = asciicode;
else
keysym->sym = keymap[scancode];
keysym->mod = KMOD_NONE;
keysym->unicode = 0;
return(keysym);
}
void GEM_InitOSKeymap(_THIS)
{
int i;
memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard));
memset(gem_currentascii, 0, sizeof(gem_currentascii));
/* Initialize keymap */
for ( i=0; i<sizeof(keymap); i++ )
keymap[i] = SDLK_UNKNOWN;
/* Functions keys */
for ( i = 0; i<10; i++ )
keymap[SCANCODE_F1 + i] = SDLK_F1+i;
/* Cursor keypad */
keymap[SCANCODE_HELP] = SDLK_HELP;
keymap[SCANCODE_UNDO] = SDLK_UNDO;
keymap[SCANCODE_INSERT] = SDLK_INSERT;
keymap[SCANCODE_CLRHOME] = SDLK_HOME;
keymap[SCANCODE_UP] = SDLK_UP;
keymap[SCANCODE_DOWN] = SDLK_DOWN;
keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
keymap[SCANCODE_LEFT] = SDLK_LEFT;
/* Special keys */
keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
keymap[SCANCODE_TAB] = SDLK_TAB;
keymap[SCANCODE_ENTER] = SDLK_RETURN;
keymap[SCANCODE_DELETE] = SDLK_DELETE;
keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
keymap[SCANCODE_LEFTALT] = SDLK_LALT;
keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
/* Mouse init */
GEM_mouse_relative = SDL_FALSE;
}
void GEM_PumpEvents(_THIS)
{
Mar 26, 2002
Mar 26, 2002
131
132
short mousex, mousey, mouseb, dummy;
short kstate, prevkc, prevks;
133
134
135
136
int i;
SDL_keysym keysym;
memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard));
Mar 26, 2002
Mar 26, 2002
137
prevkc = prevks = 0;
138
139
140
141
for (;;)
{
int quit, resultat;
Mar 26, 2002
Mar 26, 2002
142
short buffer[8], kc;
143
144
145
146
147
148
149
150
151
152
quit = 0;
resultat = evnt_multi(
MU_MESAG|MU_TIMER|MU_KEYBD,
0,0,0,
0,0,0,0,0,
0,0,0,0,0,
buffer,
10,
Mar 26, 2002
Mar 26, 2002
153
&dummy,&dummy,&dummy,&kstate,&kc,&dummy
154
155
156
157
158
159
160
);
/* Message event ? */
if (resultat & MU_MESAG)
quit = do_messages(this, buffer);
/* Keyboard event ? */
Mar 26, 2002
Mar 26, 2002
161
162
163
164
165
166
167
168
if (resultat & MU_KEYBD) {
if ((prevkc != kc) || (prevks != kstate)) {
do_keyboard(kc,kstate);
} else {
/* Avoid looping, if repeating same key */
break;
}
}
169
170
171
172
173
174
175
/* Timer event ? */
if ((resultat & MU_TIMER) || quit)
break;
}
/* Update mouse */
Mar 26, 2002
Mar 26, 2002
176
177
graf_mkstate(&mousex, &mousey, &mouseb, &kstate);
do_mouse(this, mousex, mousey, mouseb, kstate);
Mar 26, 2002
Mar 26, 2002
179
/* Now generate keyboard events */
180
181
182
183
184
185
186
for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
/* Key pressed ? */
if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(i, gem_currentascii[i], &keysym));
/* Key unpressed ? */
if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
Feb 22, 2002
Feb 22, 2002
187
SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(i, gem_currentascii[i], &keysym));
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
}
memcpy(gem_previouskeyboard,gem_currentkeyboard,sizeof(gem_previouskeyboard));
}
static int do_messages(_THIS, short *message)
{
int quit, posted;
quit=0;
switch (message[0]) {
case WM_CLOSED:
case AP_TERM:
posted = SDL_PrivateQuit();
quit=1;
break;
case WM_MOVED:
wind_set(message[3],WF_CURRXYWH,message[4],message[5],message[6],message[7]);
break;
case WM_TOPPED:
wind_set(message[3],WF_TOP,message[4],0,0,0);
SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
break;
case WM_REDRAW:
GEM_wind_redraw(this, message[3],&message[4]);
break;
case WM_ICONIFY:
case WM_ALLICONIFY:
wind_set(message[3],WF_ICONIFY,message[4],message[5],message[6],message[7]);
/* If we're active, make ourselves inactive */
if ( SDL_GetAppState() & SDL_APPACTIVE ) {
/* Send an internal deactivate event */
SDL_PrivateAppActive(0, SDL_APPACTIVE|SDL_APPINPUTFOCUS);
}
Nov 12, 2003
Nov 12, 2003
222
223
224
225
226
/* Update window title */
if (GEM_refresh_name && GEM_icon_name) {
wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_icon_name)>>16),(short)(((unsigned long)GEM_icon_name) & 0xffff),0,0);
GEM_refresh_name = SDL_FALSE;
}
227
228
229
230
231
232
233
234
break;
case WM_UNICONIFY:
wind_set(message[3],WF_UNICONIFY,message[4],message[5],message[6],message[7]);
/* If we're not active, make ourselves active */
if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) {
/* Send an internal activate event */
SDL_PrivateAppActive(1, SDL_APPACTIVE);
}
Nov 12, 2003
Nov 12, 2003
235
236
237
238
if (GEM_refresh_name && GEM_title_name) {
wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
GEM_refresh_name = SDL_FALSE;
}
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
break;
case WM_SIZED:
wind_set (message[3], WF_CURRXYWH, message[4], message[5], message[6], message[7]);
GEM_win_fulled = SDL_FALSE; /* Cancel maximized flag */
SDL_PrivateResize(message[6], message[7]);
break;
case WM_FULLED:
{
short x,y,w,h;
if (GEM_win_fulled) {
wind_get (message[3], WF_PREVXYWH, &x, &y, &w, &h);
GEM_win_fulled = SDL_FALSE;
} else {
x = GEM_desk_x;
y = GEM_desk_y;
w = GEM_desk_w;
h = GEM_desk_h;
GEM_win_fulled = SDL_TRUE;
}
wind_set (message[3], WF_CURRXYWH, x, y, w, h);
SDL_PrivateResize(w, h);
}
break;
case WM_BOTTOMED:
case WM_UNTOPPED:
SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
break;
}
return quit;
}
static void do_keyboard(short kc, short ks)
{
int scancode, asciicode;
if (kc) {
scancode=(kc>>8) & 127;
asciicode=kc & 255;
gem_currentkeyboard[scancode]=0xFF;
gem_currentascii[scancode]=asciicode;
}
/* Read special keys */
if (ks & K_RSHIFT)
gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;
if (ks & K_LSHIFT)
gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF;
if (ks & K_CTRL)
gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
if (ks & K_ALT)
gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;
}
Mar 26, 2002
Mar 26, 2002
295
static void do_mouse(_THIS, short mx, short my, short mb, short ks)
Mar 26, 2002
Mar 26, 2002
297
298
static short prevmousex=0, prevmousey=0, prevmouseb=0;
299
300
301
/* Mouse motion ? */
if ((prevmousex!=mx) || (prevmousey!=my)) {
if (GEM_mouse_relative) {
Mar 26, 2002
Mar 26, 2002
302
303
SDL_PrivateMouseMotion(0, 1, SDL_AtariXbios_mousex, SDL_AtariXbios_mousey);
SDL_AtariXbios_mousex = SDL_AtariXbios_mousey = 0;
304
305
306
307
308
309
310
311
312
313
314
} else {
SDL_PrivateMouseMotion(0, 1, mx, my);
}
prevmousex = mx;
prevmousey = my;
}
/* Mouse button ? */
if (prevmouseb!=mb) {
int i;
Mar 26, 2002
Mar 26, 2002
315
for (i=0;i<2;i++) {
316
317
318
319
320
int curbutton, prevbutton;
curbutton = mb & (1<<i);
prevbutton = prevmouseb & (1<<i);
Mar 26, 2002
Mar 26, 2002
321
322
if (curbutton && !prevbutton) {
SDL_PrivateMouseButton(SDL_PRESSED, i+1, 0, 0);
Mar 26, 2002
Mar 26, 2002
324
325
if (!curbutton && prevbutton) {
SDL_PrivateMouseButton(SDL_RELEASED, i+1, 0, 0);
326
327
328
329
}
}
prevmouseb = mb;
}
Mar 26, 2002
Mar 26, 2002
330
331
332
333
334
335
336
337
338
339
/* Read special keys */
if (ks & K_RSHIFT)
gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;
if (ks & K_LSHIFT)
gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF;
if (ks & K_CTRL)
gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
if (ks & K_ALT)
gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;