src/video/gem/SDL_gemevents.c
author Patrice Mandin <patmandin@gmail.com>
Sun, 01 Jan 2006 19:14:11 +0000
changeset 1209 a55ac374271c
parent 1092 1f37386ef508
child 1221 8ef3e7e92a91
permissions -rw-r--r--
Added preliminary missingtranslation from Atari to Unicode charset
slouken@281
     1
/*
slouken@281
     2
    SDL - Simple DirectMedia Layer
slouken@769
     3
    Copyright (C) 1997-2004 Sam Lantinga
slouken@281
     4
slouken@281
     5
    This library is free software; you can redistribute it and/or
slouken@281
     6
    modify it under the terms of the GNU Library General Public
slouken@281
     7
    License as published by the Free Software Foundation; either
slouken@281
     8
    version 2 of the License, or (at your option) any later version.
slouken@281
     9
slouken@281
    10
    This library is distributed in the hope that it will be useful,
slouken@281
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@281
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@281
    13
    Library General Public License for more details.
slouken@281
    14
slouken@281
    15
    You should have received a copy of the GNU Library General Public
slouken@281
    16
    License along with this library; if not, write to the Free
slouken@281
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@281
    18
slouken@281
    19
    Sam Lantinga
slouken@281
    20
    slouken@libsdl.org
slouken@281
    21
*/
slouken@281
    22
slouken@281
    23
#ifdef SAVE_RCSID
slouken@281
    24
static char rcsid =
slouken@281
    25
 "@(#) $Id$";
slouken@281
    26
#endif
slouken@281
    27
slouken@281
    28
/*
slouken@281
    29
 * GEM SDL video driver implementation
slouken@281
    30
 * inspired from the Dummy SDL driver
slouken@281
    31
 * 
slouken@281
    32
 * Patrice Mandin
slouken@281
    33
 * and work from
slouken@281
    34
 * Olivier Landemarre, Johan Klockars, Xavier Joubert, Claude Attard
slouken@281
    35
 */
slouken@281
    36
slouken@281
    37
#include <string.h>
slouken@281
    38
slouken@281
    39
#include <gem.h>
slouken@281
    40
slouken@281
    41
#include "SDL.h"
slouken@281
    42
#include "SDL_sysevents.h"
slouken@281
    43
#include "SDL_events_c.h"
slouken@281
    44
#include "SDL_gemvideo.h"
slouken@281
    45
#include "SDL_gemevents_c.h"
slouken@319
    46
#include "SDL_atarikeys.h"	/* for keyboard scancodes */
patmandin@1209
    47
#include "SDL_atarievents_c.h"
slouken@319
    48
#include "SDL_xbiosinterrupt_s.h"
slouken@281
    49
slouken@281
    50
/* Defines */
slouken@281
    51
slouken@281
    52
#define ATARIBIOS_MAXKEYS 128
slouken@281
    53
slouken@281
    54
/* Variables */
slouken@281
    55
slouken@281
    56
static unsigned char gem_currentkeyboard[ATARIBIOS_MAXKEYS];
slouken@281
    57
static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS];
slouken@281
    58
static unsigned char gem_currentascii[ATARIBIOS_MAXKEYS];
slouken@281
    59
slouken@281
    60
/* The translation tables from a console scancode to a SDL keysym */
slouken@281
    61
static SDLKey keymap[ATARIBIOS_MAXKEYS];
slouken@281
    62
slouken@281
    63
/* Functions prototypes */
slouken@281
    64
patmandin@1209
    65
static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym,
patmandin@1209
    66
	SDL_bool pressed);
slouken@281
    67
static int do_messages(_THIS, short *message);
slouken@281
    68
static void do_keyboard(short kc, short ks);
slouken@319
    69
static void do_mouse(_THIS, short mx, short my, short mb, short ks);
slouken@281
    70
slouken@281
    71
/* Functions */
slouken@281
    72
patmandin@1209
    73
static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym,
patmandin@1209
    74
	SDL_bool pressed)
slouken@281
    75
{
slouken@281
    76
	/* Set the keysym information */
slouken@281
    77
	keysym->scancode = scancode;
slouken@281
    78
slouken@281
    79
	if (asciicode)
slouken@281
    80
		keysym->sym = asciicode;		
slouken@281
    81
	else
slouken@281
    82
		keysym->sym = keymap[scancode];
slouken@281
    83
slouken@281
    84
	keysym->mod = KMOD_NONE;
slouken@281
    85
	keysym->unicode = 0;
patmandin@1209
    86
	if (pressed && (asciicode!=0)) {
patmandin@1209
    87
		keysym->unicode = SDL_AtariToUnicode(asciicode);
patmandin@1209
    88
	}
slouken@281
    89
slouken@281
    90
	return(keysym);
slouken@281
    91
}
slouken@281
    92
slouken@281
    93
void GEM_InitOSKeymap(_THIS)
slouken@281
    94
{
slouken@281
    95
	int i;
slouken@281
    96
slouken@281
    97
	memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
slouken@281
    98
	memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard));
slouken@281
    99
	memset(gem_currentascii, 0, sizeof(gem_currentascii));
slouken@281
   100
slouken@281
   101
	/* Initialize keymap */
slouken@281
   102
	for ( i=0; i<sizeof(keymap); i++ )
slouken@281
   103
		keymap[i] = SDLK_UNKNOWN;
slouken@281
   104
slouken@281
   105
	/* Functions keys */
slouken@281
   106
	for ( i = 0; i<10; i++ )
slouken@281
   107
		keymap[SCANCODE_F1 + i] = SDLK_F1+i;
slouken@281
   108
slouken@281
   109
	/* Cursor keypad */
slouken@281
   110
	keymap[SCANCODE_HELP] = SDLK_HELP;
slouken@281
   111
	keymap[SCANCODE_UNDO] = SDLK_UNDO;
slouken@281
   112
	keymap[SCANCODE_INSERT] = SDLK_INSERT;
slouken@281
   113
	keymap[SCANCODE_CLRHOME] = SDLK_HOME;
slouken@281
   114
	keymap[SCANCODE_UP] = SDLK_UP;
slouken@281
   115
	keymap[SCANCODE_DOWN] = SDLK_DOWN;
slouken@281
   116
	keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
slouken@281
   117
	keymap[SCANCODE_LEFT] = SDLK_LEFT;
slouken@281
   118
slouken@281
   119
	/* Special keys */
slouken@281
   120
	keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
slouken@281
   121
	keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
slouken@281
   122
	keymap[SCANCODE_TAB] = SDLK_TAB;
slouken@281
   123
	keymap[SCANCODE_ENTER] = SDLK_RETURN;
slouken@281
   124
	keymap[SCANCODE_DELETE] = SDLK_DELETE;
slouken@281
   125
	keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
slouken@281
   126
	keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
slouken@281
   127
	keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
slouken@281
   128
	keymap[SCANCODE_LEFTALT] = SDLK_LALT;
slouken@281
   129
	keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
slouken@281
   130
slouken@281
   131
	/* Mouse init */
slouken@281
   132
	GEM_mouse_relative = SDL_FALSE;
slouken@281
   133
}
slouken@281
   134
slouken@281
   135
void GEM_PumpEvents(_THIS)
slouken@281
   136
{
slouken@319
   137
	short mousex, mousey, mouseb, dummy;
slouken@319
   138
	short kstate, prevkc, prevks;
slouken@281
   139
	int i;
slouken@281
   140
	SDL_keysym	keysym;
slouken@281
   141
slouken@281
   142
	memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard));
slouken@319
   143
	prevkc = prevks = 0;
slouken@281
   144
	
slouken@281
   145
	for (;;)
slouken@281
   146
	{
patmandin@1092
   147
		int quit, resultat, event_mask, mouse_event;
slouken@319
   148
		short buffer[8], kc;
patmandin@1067
   149
		short x2,y2,w2,h2;
slouken@281
   150
patmandin@1089
   151
		quit =
patmandin@1089
   152
			mouse_event =
patmandin@1089
   153
			x2=y2=w2=h2 = 0;
slouken@281
   154
patmandin@1067
   155
		event_mask = MU_MESAG|MU_TIMER|MU_KEYBD;
patmandin@1067
   156
		if (!GEM_fullscreen && (GEM_handle>=0)) {
patmandin@1067
   157
			wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
patmandin@1089
   158
			event_mask |= MU_M1;
patmandin@1089
   159
			if ( (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
patmandin@1089
   160
				mouse_event = MO_LEAVE;				
patmandin@1089
   161
			} else {
patmandin@1089
   162
				mouse_event = MO_ENTER;				
patmandin@1089
   163
			}
patmandin@1067
   164
		}
patmandin@1067
   165
slouken@281
   166
		resultat = evnt_multi(
patmandin@1067
   167
			event_mask,
slouken@281
   168
			0,0,0,
patmandin@1089
   169
			mouse_event,x2,y2,w2,h2,
patmandin@1089
   170
			0,0,0,0,0,
slouken@281
   171
			buffer,
slouken@281
   172
			10,
slouken@319
   173
			&dummy,&dummy,&dummy,&kstate,&kc,&dummy
slouken@281
   174
		);
slouken@281
   175
slouken@281
   176
		/* Message event ? */
slouken@281
   177
		if (resultat & MU_MESAG)
slouken@281
   178
			quit = do_messages(this, buffer);
slouken@281
   179
slouken@281
   180
		/* Keyboard event ? */
slouken@319
   181
		if (resultat & MU_KEYBD) {
slouken@319
   182
			if ((prevkc != kc) || (prevks != kstate)) {
slouken@319
   183
				do_keyboard(kc,kstate);
slouken@319
   184
			} else {
slouken@319
   185
				/* Avoid looping, if repeating same key */
slouken@319
   186
				break;
slouken@319
   187
			}
slouken@319
   188
		}
slouken@281
   189
patmandin@1067
   190
		/* Mouse entering/leaving window */
patmandin@1067
   191
		if (resultat & MU_M1) {
patmandin@1067
   192
			if (this->input_grab == SDL_GRAB_OFF) {
patmandin@1089
   193
				if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) {
patmandin@1089
   194
					SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
patmandin@1089
   195
				} else {
patmandin@1088
   196
					SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
patmandin@1088
   197
				}
patmandin@1067
   198
			}
patmandin@1067
   199
		}
patmandin@1067
   200
slouken@281
   201
		/* Timer event ? */
slouken@281
   202
		if ((resultat & MU_TIMER) || quit)
slouken@281
   203
			break;
slouken@281
   204
	}
slouken@281
   205
slouken@281
   206
	/* Update mouse */
slouken@319
   207
	graf_mkstate(&mousex, &mousey, &mouseb, &kstate);
slouken@319
   208
	do_mouse(this, mousex, mousey, mouseb, kstate);
slouken@281
   209
slouken@319
   210
	/* Now generate keyboard events */
slouken@281
   211
	for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
slouken@281
   212
		/* Key pressed ? */
slouken@281
   213
		if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
patmandin@1209
   214
			SDL_PrivateKeyboard(SDL_PRESSED,
patmandin@1209
   215
				TranslateKey(i, gem_currentascii[i], &keysym, SDL_TRUE));
slouken@281
   216
			
slouken@281
   217
		/* Key unpressed ? */
slouken@281
   218
		if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
patmandin@1209
   219
			SDL_PrivateKeyboard(SDL_RELEASED,
patmandin@1209
   220
				TranslateKey(i, gem_currentascii[i], &keysym, SDL_FALSE));
slouken@281
   221
	}
slouken@281
   222
slouken@281
   223
	memcpy(gem_previouskeyboard,gem_currentkeyboard,sizeof(gem_previouskeyboard));
patmandin@996
   224
patmandin@996
   225
	/* Refresh window name ? */
patmandin@996
   226
	if (GEM_refresh_name) {
patmandin@996
   227
		if ( SDL_GetAppState() & SDL_APPACTIVE ) {
patmandin@996
   228
			/* Fullscreen/windowed */
patmandin@996
   229
			if (GEM_title_name) {
patmandin@996
   230
				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
patmandin@996
   231
			}
patmandin@996
   232
		} else {
patmandin@996
   233
			/* Iconified */
patmandin@996
   234
			if (GEM_icon_name) {
patmandin@996
   235
				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_icon_name)>>16),(short)(((unsigned long)GEM_icon_name) & 0xffff),0,0);
patmandin@996
   236
			}
patmandin@996
   237
		}
patmandin@996
   238
		GEM_refresh_name = SDL_FALSE;
patmandin@996
   239
	}
slouken@281
   240
}
slouken@281
   241
slouken@281
   242
static int do_messages(_THIS, short *message)
slouken@281
   243
{
slouken@281
   244
	int quit, posted;
patmandin@922
   245
	short x2,y2,w2,h2;
slouken@281
   246
slouken@281
   247
	quit=0;
slouken@281
   248
	switch (message[0]) {
slouken@281
   249
		case WM_CLOSED:
slouken@281
   250
		case AP_TERM:    
slouken@281
   251
			posted = SDL_PrivateQuit();
slouken@281
   252
			quit=1;
slouken@281
   253
			break;
slouken@281
   254
		case WM_MOVED:
slouken@281
   255
			wind_set(message[3],WF_CURRXYWH,message[4],message[5],message[6],message[7]);
slouken@281
   256
			break;
slouken@281
   257
		case WM_TOPPED:
slouken@281
   258
			wind_set(message[3],WF_TOP,message[4],0,0,0);
patmandin@1091
   259
			/* Continue with TOP event processing */
patmandin@1091
   260
		case WM_ONTOP:
slouken@281
   261
			SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
patmandin@1074
   262
			if (VDI_setpalette) {
patmandin@1074
   263
				VDI_setpalette(this, VDI_curpalette);
patmandin@1074
   264
			}
slouken@281
   265
			break;
slouken@281
   266
		case WM_REDRAW:
patmandin@964
   267
			if (!GEM_lock_redraw) {
patmandin@964
   268
				GEM_wind_redraw(this, message[3],&message[4]);
patmandin@964
   269
			}
slouken@281
   270
			break;
slouken@281
   271
		case WM_ICONIFY:
slouken@281
   272
		case WM_ALLICONIFY:
slouken@281
   273
			wind_set(message[3],WF_ICONIFY,message[4],message[5],message[6],message[7]);
slouken@281
   274
			/* If we're active, make ourselves inactive */
slouken@281
   275
			if ( SDL_GetAppState() & SDL_APPACTIVE ) {
slouken@281
   276
				/* Send an internal deactivate event */
patmandin@1088
   277
				SDL_PrivateAppActive(0, SDL_APPACTIVE);
slouken@281
   278
			}
patmandin@736
   279
			/* Update window title */
patmandin@736
   280
			if (GEM_refresh_name && GEM_icon_name) {
patmandin@736
   281
				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_icon_name)>>16),(short)(((unsigned long)GEM_icon_name) & 0xffff),0,0);
patmandin@736
   282
				GEM_refresh_name = SDL_FALSE;
patmandin@736
   283
			}
slouken@281
   284
			break;
slouken@281
   285
		case WM_UNICONIFY:
slouken@281
   286
			wind_set(message[3],WF_UNICONIFY,message[4],message[5],message[6],message[7]);
slouken@281
   287
			/* If we're not active, make ourselves active */
slouken@281
   288
			if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) {
slouken@281
   289
				/* Send an internal activate event */
slouken@281
   290
				SDL_PrivateAppActive(1, SDL_APPACTIVE);
slouken@281
   291
			}
patmandin@736
   292
			if (GEM_refresh_name && GEM_title_name) {
patmandin@736
   293
				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
patmandin@736
   294
				GEM_refresh_name = SDL_FALSE;
patmandin@736
   295
			}
slouken@281
   296
			break;
slouken@281
   297
		case WM_SIZED:
slouken@281
   298
			wind_set (message[3], WF_CURRXYWH, message[4], message[5], message[6], message[7]);
patmandin@964
   299
			wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
slouken@281
   300
			GEM_win_fulled = SDL_FALSE;		/* Cancel maximized flag */
patmandin@964
   301
			GEM_lock_redraw = SDL_TRUE;		/* Prevent redraw till buffers resized */
patmandin@922
   302
			SDL_PrivateResize(w2, h2);
slouken@281
   303
			break;
slouken@281
   304
		case WM_FULLED:
slouken@281
   305
			{
slouken@281
   306
				short x,y,w,h;
slouken@281
   307
slouken@281
   308
				if (GEM_win_fulled) {
slouken@281
   309
					wind_get (message[3], WF_PREVXYWH, &x, &y, &w, &h);
slouken@281
   310
					GEM_win_fulled = SDL_FALSE;
slouken@281
   311
				} else {
slouken@281
   312
					x = GEM_desk_x;
slouken@281
   313
					y = GEM_desk_y;
slouken@281
   314
					w = GEM_desk_w;
slouken@281
   315
					h = GEM_desk_h;
slouken@281
   316
					GEM_win_fulled = SDL_TRUE;
slouken@281
   317
				}
slouken@281
   318
				wind_set (message[3], WF_CURRXYWH, x, y, w, h);
patmandin@922
   319
				wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
patmandin@964
   320
				GEM_lock_redraw = SDL_TRUE;		/* Prevent redraw till buffers resized */
patmandin@922
   321
				SDL_PrivateResize(w2, h2);
slouken@281
   322
			}
slouken@281
   323
			break;
slouken@281
   324
		case WM_BOTTOMED:
patmandin@1091
   325
			wind_set(message[3],WF_BOTTOM,0,0,0,0);
patmandin@1091
   326
			/* Continue with BOTTOM event processing */
slouken@281
   327
		case WM_UNTOPPED:
slouken@281
   328
			SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
patmandin@1074
   329
			if (VDI_setpalette) {
patmandin@1074
   330
				VDI_setpalette(this, VDI_oldpalette);
patmandin@1074
   331
			}
slouken@281
   332
			break;
slouken@281
   333
	}
slouken@281
   334
	
slouken@281
   335
	return quit;
slouken@281
   336
}
slouken@281
   337
slouken@281
   338
static void do_keyboard(short kc, short ks)
slouken@281
   339
{
slouken@281
   340
	int			scancode, asciicode;
slouken@281
   341
slouken@281
   342
	if (kc) {
slouken@281
   343
		scancode=(kc>>8) & 127;
slouken@281
   344
		asciicode=kc & 255;
slouken@281
   345
slouken@281
   346
		gem_currentkeyboard[scancode]=0xFF;
slouken@281
   347
		gem_currentascii[scancode]=asciicode;
slouken@281
   348
	}
slouken@281
   349
slouken@281
   350
	/* Read special keys */
slouken@281
   351
	if (ks & K_RSHIFT)
slouken@281
   352
		gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;
slouken@281
   353
	if (ks & K_LSHIFT)
slouken@281
   354
		gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF;
slouken@281
   355
	if (ks & K_CTRL)
slouken@281
   356
		gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
slouken@281
   357
	if (ks & K_ALT)
slouken@281
   358
		gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;
slouken@281
   359
}
slouken@281
   360
slouken@319
   361
static void do_mouse(_THIS, short mx, short my, short mb, short ks)
slouken@281
   362
{
slouken@319
   363
	static short prevmousex=0, prevmousey=0, prevmouseb=0;
patmandin@926
   364
	short x2, y2, w2, h2;
patmandin@926
   365
patmandin@1067
   366
	/* Don't return mouse events if out of window */
patmandin@1067
   367
	if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS)==0) {
patmandin@1067
   368
		return;
patmandin@1067
   369
	}
patmandin@1067
   370
patmandin@926
   371
	/* Retrieve window coords, and generate mouse events accordingly */
patmandin@926
   372
	x2 = y2 = 0;
patmandin@928
   373
	w2 = VDI_w;
patmandin@928
   374
	h2 = VDI_h;
patmandin@926
   375
	if ((!GEM_fullscreen) && (GEM_handle>=0)) {
patmandin@926
   376
		wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
patmandin@926
   377
patmandin@926
   378
		/* Do not generate mouse button event if out of window working area */
patmandin@926
   379
		if ((mx<x2) || (mx>=x2+w2) || (my<y2) || (my>=y2+h2)) {
patmandin@926
   380
			mb=prevmouseb;
patmandin@926
   381
		}
patmandin@926
   382
	}
slouken@319
   383
slouken@281
   384
	/* Mouse motion ? */
slouken@281
   385
	if ((prevmousex!=mx) || (prevmousey!=my)) {
slouken@281
   386
		if (GEM_mouse_relative) {
slouken@319
   387
			SDL_PrivateMouseMotion(0, 1, SDL_AtariXbios_mousex, SDL_AtariXbios_mousey);
slouken@319
   388
			SDL_AtariXbios_mousex = SDL_AtariXbios_mousey = 0;
slouken@281
   389
		} else {
patmandin@926
   390
			int posx, posy;
patmandin@926
   391
patmandin@926
   392
			/* Give mouse position relative to window position */
patmandin@926
   393
			posx = mx - x2;
patmandin@927
   394
			if (posx<0) posx = 0;
patmandin@926
   395
			if (posx>w2) posx = w2-1;
patmandin@926
   396
			posy = my - y2;
patmandin@927
   397
			if (posy<0) posy = 0;
patmandin@926
   398
			if (posy>h2) posy = h2-1;
patmandin@926
   399
patmandin@926
   400
			SDL_PrivateMouseMotion(0, 0, posx, posy);
slouken@281
   401
		}
slouken@281
   402
		prevmousex = mx;
slouken@281
   403
		prevmousey = my;
slouken@281
   404
	}
slouken@281
   405
slouken@281
   406
	/* Mouse button ? */
slouken@281
   407
	if (prevmouseb!=mb) {
slouken@281
   408
		int i;
slouken@281
   409
slouken@319
   410
		for (i=0;i<2;i++) {
slouken@281
   411
			int curbutton, prevbutton;
slouken@281
   412
		
slouken@281
   413
			curbutton = mb & (1<<i);
slouken@281
   414
			prevbutton = prevmouseb & (1<<i);
slouken@281
   415
		
slouken@319
   416
			if (curbutton && !prevbutton) {
slouken@319
   417
				SDL_PrivateMouseButton(SDL_PRESSED, i+1, 0, 0);
slouken@281
   418
			}
slouken@319
   419
			if (!curbutton && prevbutton) {
slouken@319
   420
				SDL_PrivateMouseButton(SDL_RELEASED, i+1, 0, 0);
slouken@281
   421
			}
slouken@281
   422
		}
slouken@281
   423
		prevmouseb = mb;
slouken@281
   424
	}
slouken@319
   425
slouken@319
   426
	/* Read special keys */
slouken@319
   427
	if (ks & K_RSHIFT)
slouken@319
   428
		gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;
slouken@319
   429
	if (ks & K_LSHIFT)
slouken@319
   430
		gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF;
slouken@319
   431
	if (ks & K_CTRL)
slouken@319
   432
		gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
slouken@319
   433
	if (ks & K_ALT)
slouken@319
   434
		gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;
slouken@281
   435
}