src/video/gem/SDL_gemevents.c
author Patrice Mandin <patmandin@gmail.com>
Sat, 30 Sep 2017 15:43:28 +0200
branchSDL-1.2
changeset 11554 9694b296d6e6
parent 9132 b37013ec80de
child 11555 a3426706e128
permissions -rw-r--r--
atari:gem: Align window work area on 16-pixels boundary (faster for bitplanes modes). Remove commented function GEM_ToggleFullscreen not used, and some extra whitespaces.
slouken@281
     1
/*
slouken@281
     2
    SDL - Simple DirectMedia Layer
slouken@6137
     3
    Copyright (C) 1997-2012 Sam Lantinga
slouken@281
     4
slouken@281
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@281
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 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@1312
    13
    Lesser General Public License for more details.
slouken@281
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@281
    18
slouken@281
    19
    Sam Lantinga
slouken@281
    20
    slouken@libsdl.org
slouken@281
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@281
    23
slouken@281
    24
/*
slouken@281
    25
 * GEM SDL video driver implementation
slouken@281
    26
 * inspired from the Dummy SDL driver
patmandin@11554
    27
 *
slouken@281
    28
 * Patrice Mandin
slouken@281
    29
 * and work from
slouken@281
    30
 * Olivier Landemarre, Johan Klockars, Xavier Joubert, Claude Attard
slouken@281
    31
 */
slouken@281
    32
slouken@281
    33
#include <gem.h>
slouken@281
    34
patmandin@9042
    35
#include "SDL_timer.h"
slouken@1361
    36
#include "../../events/SDL_sysevents.h"
slouken@1361
    37
#include "../../events/SDL_events_c.h"
slouken@281
    38
#include "SDL_gemvideo.h"
slouken@281
    39
#include "SDL_gemevents_c.h"
patmandin@5649
    40
#include "SDL_gemmouse_c.h"
patmandin@1412
    41
#include "../ataricommon/SDL_atarikeys.h"	/* for keyboard scancodes */
patmandin@1412
    42
#include "../ataricommon/SDL_atarievents_c.h"
patmandin@1412
    43
#include "../ataricommon/SDL_xbiosevents_c.h"
patmandin@1420
    44
#include "../ataricommon/SDL_ataridevmouse_c.h"
slouken@281
    45
patmandin@9042
    46
/* Duration after which we consider key released */
patmandin@9042
    47
patmandin@9042
    48
#define KEY_PRESS_DURATION 100
patmandin@9042
    49
patmandin@9132
    50
#define MSG_SDL_ID	(('S'<<8)|'D')
patmandin@9132
    51
slouken@281
    52
/* Variables */
slouken@281
    53
slouken@281
    54
static unsigned char gem_currentkeyboard[ATARIBIOS_MAXKEYS];
slouken@281
    55
static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS];
patmandin@9042
    56
static Uint32 keyboard_ticks[ATARIBIOS_MAXKEYS];
slouken@281
    57
patmandin@6647
    58
static short prevmx=0,prevmy=0,prevmb=0;
patmandin@9132
    59
static short dummy_msgbuf[8] = {MSG_SDL_ID,0,0,0, 0,0,0,0};
patmandin@6647
    60
slouken@281
    61
/* Functions prototypes */
slouken@281
    62
patmandin@9132
    63
static int do_messages(_THIS, short *message, short latest_msg_id);
patmandin@9042
    64
static void do_keyboard(short kc, Uint32 tick);
patmandin@9042
    65
static void do_keyboard_special(short ks, Uint32 tick);
patmandin@6583
    66
static void do_mouse_motion(_THIS, short mx, short my);
patmandin@6583
    67
static void do_mouse_buttons(_THIS, short mb);
patmandin@6585
    68
static int mouse_in_work_area(int winhandle, short mx, short my);
patmandin@9042
    69
static void clearKeyboardState(Uint32 tick);
slouken@281
    70
slouken@281
    71
/* Functions */
slouken@281
    72
slouken@281
    73
void GEM_InitOSKeymap(_THIS)
slouken@281
    74
{
slouken@1336
    75
	SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
slouken@1336
    76
	SDL_memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard));
patmandin@9042
    77
	SDL_memset(keyboard_ticks, 0, sizeof(keyboard_ticks));
slouken@281
    78
slouken@281
    79
	/* Mouse init */
slouken@281
    80
	GEM_mouse_relative = SDL_FALSE;
patmandin@3861
    81
patmandin@3861
    82
	SDL_Atari_InitInternalKeymap(this);
slouken@281
    83
}
slouken@281
    84
slouken@281
    85
void GEM_PumpEvents(_THIS)
slouken@281
    86
{
patmandin@6647
    87
	short prevkc=0, mousex, mousey, mouseb, kstate;
patmandin@9132
    88
	int i, quit = 0;
patmandin@6647
    89
	SDL_keysym keysym;
patmandin@9042
    90
	Uint32 cur_tick;
patmandin@9132
    91
	static Uint32 prev_now = 0, prev_msg = 0;
patmandin@9132
    92
	static short latest_msg_id = 0;
slouken@281
    93
patmandin@9042
    94
	cur_tick = SDL_GetTicks();
patmandin@9132
    95
	if (prev_now == cur_tick) {
patmandin@9132
    96
		return;
patmandin@9132
    97
	}
patmandin@9132
    98
	prev_now = cur_tick;
patmandin@9132
    99
patmandin@9132
   100
	SDL_AtariMint_BackgroundTasks();
patmandin@9042
   101
	clearKeyboardState(cur_tick);
patmandin@4564
   102
patmandin@9132
   103
	if (prev_msg) {
patmandin@9132
   104
		/* Wait at least 20ms before each event processing loop */
patmandin@9132
   105
		if (cur_tick-prev_msg < 20) {
patmandin@9132
   106
			return;
patmandin@9132
   107
		}
patmandin@9132
   108
	}
patmandin@9132
   109
	prev_msg = cur_tick;
patmandin@9132
   110
patmandin@9132
   111
	dummy_msgbuf[1] = ++latest_msg_id;
patmandin@9132
   112
	if (appl_write(GEM_ap_id, sizeof(dummy_msgbuf), dummy_msgbuf) == 0) {
patmandin@9132
   113
		/* If it fails, wait for previous id */
patmandin@9132
   114
		--latest_msg_id;
patmandin@9132
   115
	}
patmandin@9132
   116
patmandin@9132
   117
	while (!quit) {
patmandin@9132
   118
		int resultat;
patmandin@6647
   119
		short buffer[8], kc, dummy;
slouken@281
   120
slouken@281
   121
		resultat = evnt_multi(
patmandin@6649
   122
			MU_MESAG|MU_TIMER|MU_KEYBD,
patmandin@6649
   123
			0,0,0,
patmandin@6649
   124
			0,0,0,0,0,
patmandin@1089
   125
			0,0,0,0,0,
slouken@281
   126
			buffer,
patmandin@9132
   127
			1000,
patmandin@6649
   128
			&dummy,&dummy,&dummy,&kstate,&kc,&dummy
slouken@281
   129
		);
slouken@281
   130
slouken@281
   131
		/* Message event ? */
slouken@281
   132
		if (resultat & MU_MESAG)
patmandin@9132
   133
			quit = do_messages(this, buffer, latest_msg_id);
slouken@281
   134
slouken@281
   135
		/* Keyboard event ? */
slouken@319
   136
		if (resultat & MU_KEYBD) {
patmandin@9042
   137
			do_keyboard_special(kstate, cur_tick);
patmandin@6582
   138
			if (prevkc != kc) {
patmandin@9042
   139
				do_keyboard(kc, cur_tick);
patmandin@6572
   140
				prevkc = kc;
slouken@319
   141
			}
slouken@319
   142
		}
slouken@281
   143
patmandin@9132
   144
		/* Timer event ? Just used as a safeguard */
patmandin@9132
   145
		if (resultat & MU_TIMER) {
patmandin@9132
   146
			quit = 1;
patmandin@9132
   147
		}
slouken@281
   148
	}
slouken@281
   149
patmandin@9130
   150
	GEM_CheckMouseMode(this);
patmandin@9130
   151
patmandin@6649
   152
	/* Update mouse state */
patmandin@6649
   153
	graf_mkstate(&mousex, &mousey, &mouseb, &kstate);
patmandin@9042
   154
	do_keyboard_special(kstate, cur_tick);
patmandin@6649
   155
	do_mouse_motion(this, mousex, mousey);
patmandin@6649
   156
	do_mouse_buttons(this, mouseb);
patmandin@6649
   157
slouken@319
   158
	/* Now generate keyboard events */
slouken@281
   159
	for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
slouken@281
   160
		/* Key pressed ? */
slouken@281
   161
		if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
patmandin@1209
   162
			SDL_PrivateKeyboard(SDL_PRESSED,
patmandin@3861
   163
				SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
patmandin@11554
   164
slouken@281
   165
		/* Key unpressed ? */
slouken@281
   166
		if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
patmandin@1209
   167
			SDL_PrivateKeyboard(SDL_RELEASED,
patmandin@3861
   168
				SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE));
slouken@281
   169
	}
slouken@281
   170
slouken@1336
   171
	SDL_memcpy(gem_previouskeyboard,gem_currentkeyboard,sizeof(gem_previouskeyboard));
patmandin@996
   172
patmandin@996
   173
	/* Refresh window name ? */
patmandin@996
   174
	if (GEM_refresh_name) {
patmandin@4059
   175
		const char *window_name =
patmandin@4059
   176
			(SDL_GetAppState() & SDL_APPACTIVE)
patmandin@4059
   177
			? GEM_title_name : GEM_icon_name;
patmandin@4059
   178
		if (window_name) {
patmandin@4059
   179
			wind_set(GEM_handle,WF_NAME,
patmandin@4059
   180
				(short)(((unsigned long)window_name)>>16),
patmandin@4059
   181
				(short)(((unsigned long)window_name) & 0xffff),
patmandin@4059
   182
				0,0);
patmandin@996
   183
		}
patmandin@996
   184
		GEM_refresh_name = SDL_FALSE;
patmandin@996
   185
	}
slouken@281
   186
}
slouken@281
   187
patmandin@9132
   188
static int do_messages(_THIS, short *message, short latest_msg_id)
slouken@281
   189
{
patmandin@9130
   190
	int quit;
patmandin@922
   191
	short x2,y2,w2,h2;
slouken@281
   192
patmandin@9130
   193
	quit = 0;
slouken@281
   194
	switch (message[0]) {
patmandin@9132
   195
		case MSG_SDL_ID:
patmandin@9132
   196
			quit=(message[1] == latest_msg_id);
patmandin@9132
   197
			break;
slouken@281
   198
		case WM_CLOSED:
patmandin@11554
   199
		case AP_TERM:
patmandin@5867
   200
			SDL_PrivateQuit();
slouken@281
   201
			quit=1;
slouken@281
   202
			break;
slouken@281
   203
		case WM_MOVED:
slouken@281
   204
			wind_set(message[3],WF_CURRXYWH,message[4],message[5],message[6],message[7]);
slouken@281
   205
			break;
slouken@281
   206
		case WM_TOPPED:
slouken@281
   207
			wind_set(message[3],WF_TOP,message[4],0,0,0);
patmandin@1091
   208
			/* Continue with TOP event processing */
patmandin@1091
   209
		case WM_ONTOP:
slouken@281
   210
			SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
patmandin@1074
   211
			if (VDI_setpalette) {
patmandin@1074
   212
				VDI_setpalette(this, VDI_curpalette);
patmandin@1074
   213
			}
slouken@281
   214
			break;
slouken@281
   215
		case WM_REDRAW:
patmandin@964
   216
			if (!GEM_lock_redraw) {
patmandin@964
   217
				GEM_wind_redraw(this, message[3],&message[4]);
patmandin@964
   218
			}
slouken@281
   219
			break;
slouken@281
   220
		case WM_ICONIFY:
slouken@281
   221
		case WM_ALLICONIFY:
slouken@281
   222
			wind_set(message[3],WF_ICONIFY,message[4],message[5],message[6],message[7]);
slouken@281
   223
			/* If we're active, make ourselves inactive */
slouken@281
   224
			if ( SDL_GetAppState() & SDL_APPACTIVE ) {
slouken@281
   225
				/* Send an internal deactivate event */
patmandin@1088
   226
				SDL_PrivateAppActive(0, SDL_APPACTIVE);
slouken@281
   227
			}
patmandin@736
   228
			/* Update window title */
patmandin@736
   229
			if (GEM_refresh_name && GEM_icon_name) {
patmandin@11554
   230
				wind_set(GEM_handle,WF_NAME,
patmandin@11554
   231
					(short)(((unsigned long)GEM_icon_name)>>16),
patmandin@11554
   232
					(short)(((unsigned long)GEM_icon_name) & 0xffff),
patmandin@11554
   233
					0,0);
patmandin@736
   234
				GEM_refresh_name = SDL_FALSE;
patmandin@736
   235
			}
slouken@281
   236
			break;
slouken@281
   237
		case WM_UNICONIFY:
slouken@281
   238
			wind_set(message[3],WF_UNICONIFY,message[4],message[5],message[6],message[7]);
slouken@281
   239
			/* If we're not active, make ourselves active */
slouken@281
   240
			if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) {
slouken@281
   241
				/* Send an internal activate event */
slouken@281
   242
				SDL_PrivateAppActive(1, SDL_APPACTIVE);
slouken@281
   243
			}
patmandin@736
   244
			if (GEM_refresh_name && GEM_title_name) {
patmandin@11554
   245
				wind_set(GEM_handle,WF_NAME,
patmandin@11554
   246
					(short)(((unsigned long)GEM_title_name)>>16),
patmandin@11554
   247
					(short)(((unsigned long)GEM_title_name) & 0xffff),
patmandin@11554
   248
					0,0);
patmandin@736
   249
				GEM_refresh_name = SDL_FALSE;
patmandin@736
   250
			}
slouken@281
   251
			break;
slouken@281
   252
		case WM_SIZED:
slouken@281
   253
			wind_set (message[3], WF_CURRXYWH, message[4], message[5], message[6], message[7]);
patmandin@964
   254
			wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
slouken@281
   255
			GEM_win_fulled = SDL_FALSE;		/* Cancel maximized flag */
patmandin@964
   256
			GEM_lock_redraw = SDL_TRUE;		/* Prevent redraw till buffers resized */
patmandin@922
   257
			SDL_PrivateResize(w2, h2);
slouken@281
   258
			break;
slouken@281
   259
		case WM_FULLED:
slouken@281
   260
			{
slouken@281
   261
				short x,y,w,h;
slouken@281
   262
slouken@281
   263
				if (GEM_win_fulled) {
slouken@281
   264
					wind_get (message[3], WF_PREVXYWH, &x, &y, &w, &h);
slouken@281
   265
					GEM_win_fulled = SDL_FALSE;
slouken@281
   266
				} else {
slouken@281
   267
					x = GEM_desk_x;
slouken@281
   268
					y = GEM_desk_y;
slouken@281
   269
					w = GEM_desk_w;
slouken@281
   270
					h = GEM_desk_h;
slouken@281
   271
					GEM_win_fulled = SDL_TRUE;
slouken@281
   272
				}
slouken@281
   273
				wind_set (message[3], WF_CURRXYWH, x, y, w, h);
patmandin@922
   274
				wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
patmandin@964
   275
				GEM_lock_redraw = SDL_TRUE;		/* Prevent redraw till buffers resized */
patmandin@922
   276
				SDL_PrivateResize(w2, h2);
slouken@281
   277
			}
slouken@281
   278
			break;
slouken@281
   279
		case WM_BOTTOMED:
patmandin@1091
   280
			wind_set(message[3],WF_BOTTOM,0,0,0,0);
patmandin@1091
   281
			/* Continue with BOTTOM event processing */
slouken@281
   282
		case WM_UNTOPPED:
slouken@281
   283
			SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
patmandin@1074
   284
			if (VDI_setpalette) {
patmandin@1074
   285
				VDI_setpalette(this, VDI_oldpalette);
patmandin@1074
   286
			}
slouken@281
   287
			break;
slouken@281
   288
	}
patmandin@11554
   289
slouken@281
   290
	return quit;
slouken@281
   291
}
slouken@281
   292
patmandin@9042
   293
static void do_keyboard(short kc, Uint32 tick)
slouken@281
   294
{
patmandin@3861
   295
	int scancode;
slouken@281
   296
slouken@281
   297
	if (kc) {
patmandin@3861
   298
		scancode=(kc>>8) & (ATARIBIOS_MAXKEYS-1);
slouken@281
   299
		gem_currentkeyboard[scancode]=0xFF;
patmandin@9042
   300
		keyboard_ticks[scancode]=tick;
slouken@281
   301
	}
patmandin@6582
   302
}
slouken@281
   303
patmandin@9042
   304
static void do_keyboard_special(short ks, Uint32 tick)
patmandin@6582
   305
{
patmandin@9042
   306
	int scancode=0;
patmandin@9042
   307
slouken@281
   308
	/* Read special keys */
slouken@281
   309
	if (ks & K_RSHIFT)
patmandin@9042
   310
		scancode=SCANCODE_RIGHTSHIFT;
slouken@281
   311
	if (ks & K_LSHIFT)
patmandin@9042
   312
		scancode=SCANCODE_LEFTSHIFT;
slouken@281
   313
	if (ks & K_CTRL)
patmandin@9042
   314
		scancode=SCANCODE_LEFTCONTROL;
slouken@281
   315
	if (ks & K_ALT)
patmandin@9042
   316
		scancode=SCANCODE_LEFTALT;
patmandin@9042
   317
patmandin@9042
   318
	if (scancode) {
patmandin@9042
   319
		gem_currentkeyboard[scancode]=0xFF;
patmandin@9042
   320
		keyboard_ticks[scancode]=tick;
patmandin@9042
   321
	}
slouken@281
   322
}
slouken@281
   323
patmandin@6583
   324
static void do_mouse_motion(_THIS, short mx, short my)
slouken@281
   325
{
patmandin@926
   326
	short x2, y2, w2, h2;
patmandin@926
   327
patmandin@6648
   328
	if (this->input_grab == SDL_GRAB_OFF) {
patmandin@6648
   329
		/* Switch mouse focus state */
patmandin@6648
   330
		if (!GEM_fullscreen && (GEM_handle>=0)) {
patmandin@6648
   331
			SDL_PrivateAppActive(
patmandin@6648
   332
				mouse_in_work_area(GEM_handle, mx,my),
patmandin@6648
   333
				SDL_APPMOUSEFOCUS);
patmandin@6648
   334
		}
patmandin@6648
   335
	}
patmandin@6648
   336
	GEM_CheckMouseMode(this);
patmandin@6648
   337
patmandin@1067
   338
	/* Don't return mouse events if out of window */
patmandin@1067
   339
	if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS)==0) {
patmandin@1067
   340
		return;
patmandin@1067
   341
	}
patmandin@1067
   342
patmandin@6584
   343
	/* Relative mouse motion ? */
patmandin@6584
   344
	if (GEM_mouse_relative) {
patmandin@6584
   345
		if (GEM_usedevmouse) {
patmandin@6584
   346
			SDL_AtariDevMouse_PostMouseEvents(this, SDL_FALSE);
patmandin@6584
   347
		} else {
patmandin@6584
   348
			SDL_AtariXbios_PostMouseEvents(this, SDL_FALSE);
patmandin@6584
   349
		}
patmandin@6584
   350
		return;
patmandin@6584
   351
	}
patmandin@6584
   352
patmandin@926
   353
	/* Retrieve window coords, and generate mouse events accordingly */
patmandin@926
   354
	x2 = y2 = 0;
patmandin@928
   355
	w2 = VDI_w;
patmandin@928
   356
	h2 = VDI_h;
patmandin@926
   357
	if ((!GEM_fullscreen) && (GEM_handle>=0)) {
patmandin@926
   358
		wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
patmandin@926
   359
	}
slouken@319
   360
patmandin@6647
   361
	if ((prevmx!=mx) || (prevmy!=my)) {
patmandin@6584
   362
		int posx, posy;
patmandin@926
   363
patmandin@6584
   364
		/* Give mouse position relative to window position */
patmandin@6584
   365
		posx = mx - x2;
patmandin@6584
   366
		if (posx<0) posx = 0;
patmandin@6584
   367
		if (posx>w2) posx = w2-1;
patmandin@6584
   368
		posy = my - y2;
patmandin@6584
   369
		if (posy<0) posy = 0;
patmandin@6584
   370
		if (posy>h2) posy = h2-1;
patmandin@926
   371
patmandin@6584
   372
		SDL_PrivateMouseMotion(0, 0, posx, posy);
slouken@281
   373
	}
patmandin@6647
   374
patmandin@6647
   375
	prevmx = mx;
patmandin@6647
   376
	prevmy = my;
patmandin@6583
   377
}
slouken@281
   378
patmandin@6583
   379
static void do_mouse_buttons(_THIS, short mb)
patmandin@6583
   380
{
patmandin@6583
   381
	int i;
slouken@281
   382
patmandin@6583
   383
	/* Don't return mouse events if out of window */
patmandin@6583
   384
	if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS)==0)
patmandin@6583
   385
		return;
patmandin@6583
   386
patmandin@6647
   387
	if (prevmb==mb)
patmandin@6583
   388
		return;
patmandin@6583
   389
patmandin@6583
   390
	for (i=0;i<3;i++) {
patmandin@6583
   391
		int curbutton, prevbutton;
patmandin@11554
   392
patmandin@6583
   393
		curbutton = mb & (1<<i);
patmandin@6647
   394
		prevbutton = prevmb & (1<<i);
patmandin@11554
   395
patmandin@6583
   396
		if (curbutton && !prevbutton) {
patmandin@6583
   397
			SDL_PrivateMouseButton(SDL_PRESSED, i+1, 0, 0);
slouken@281
   398
		}
patmandin@6583
   399
		if (!curbutton && prevbutton) {
patmandin@6583
   400
			SDL_PrivateMouseButton(SDL_RELEASED, i+1, 0, 0);
patmandin@6583
   401
		}
slouken@281
   402
	}
patmandin@6583
   403
patmandin@6647
   404
	prevmb = mb;
slouken@281
   405
}
patmandin@6585
   406
patmandin@6585
   407
/* Check if mouse in visible area of the window */
patmandin@6585
   408
static int mouse_in_work_area(int winhandle, short mx, short my)
patmandin@6585
   409
{
patmandin@6585
   410
	short todo[4];
patmandin@6585
   411
	short inside[4] = {mx,my,1,1};
patmandin@6585
   412
patmandin@6585
   413
	/* Browse the rectangle list */
patmandin@6585
   414
	if (wind_get(winhandle, WF_FIRSTXYWH, &todo[0], &todo[1], &todo[2], &todo[3])!=0) {
patmandin@6585
   415
		while (todo[2] && todo[3]) {
patmandin@6585
   416
			if (rc_intersect((GRECT *)inside,(GRECT *)todo)) {
patmandin@6585
   417
				return 1;
patmandin@6585
   418
			}
patmandin@6585
   419
patmandin@6585
   420
			if (wind_get(winhandle, WF_NEXTXYWH, &todo[0], &todo[1], &todo[2], &todo[3])==0) {
patmandin@6585
   421
				break;
patmandin@6585
   422
			}
patmandin@6585
   423
		}
patmandin@6585
   424
patmandin@6585
   425
	}
patmandin@6585
   426
patmandin@6585
   427
	return 0;
patmandin@6585
   428
}
patmandin@9042
   429
patmandin@9042
   430
/* Clear key state for which we did not receive events for a while */
patmandin@9042
   431
patmandin@9042
   432
static void clearKeyboardState(Uint32 tick)
patmandin@9042
   433
{
patmandin@9042
   434
	int i;
patmandin@9042
   435
patmandin@9042
   436
	for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
patmandin@9042
   437
		if (keyboard_ticks[i]) {
patmandin@9042
   438
			if (tick-keyboard_ticks[i] > KEY_PRESS_DURATION) {
patmandin@9042
   439
				gem_currentkeyboard[i]=0;
patmandin@9042
   440
				keyboard_ticks[i]=0;
patmandin@9042
   441
			}
patmandin@9042
   442
		}
patmandin@9042
   443
	}
patmandin@9042
   444
}