Avoid generating multiple key press/release messages for the same key
authorPatrice Mandin <patmandin@gmail.com>
Wed, 29 Jun 2005 20:32:46 +0000
changeset 108248436ffdf677
parent 1081 369dcdb52d70
child 1083 9f8aa754622b
Avoid generating multiple key press/release messages for the same key
src/video/ataricommon/SDL_ikbdevents.c
src/video/ataricommon/SDL_ikbdinterrupt.S
     1.1 --- a/src/video/ataricommon/SDL_ikbdevents.c	Wed Jun 29 16:18:46 2005 +0000
     1.2 +++ b/src/video/ataricommon/SDL_ikbdevents.c	Wed Jun 29 20:32:46 2005 +0000
     1.3 @@ -54,11 +54,11 @@
     1.4  	K_INSERT
     1.5  };
     1.6  
     1.7 -/* To save state of keyboard */
     1.8  #define ATARIBIOS_MAXKEYS 128
     1.9  
    1.10 -static unsigned char ikbd_previouskeyboard[ATARIBIOS_MAXKEYS];
    1.11 -static Uint16 atari_prevmouseb;	/* buttons */
    1.12 +#define KEY_PRESSED		0xff
    1.13 +#define KEY_UNDEFINED	0x80
    1.14 +#define KEY_RELEASED	0x00
    1.15  
    1.16  /* The translation tables from a console scancode to a SDL keysym */
    1.17  #define KT_NOCHANGE -1
    1.18 @@ -69,7 +69,8 @@
    1.19  	KT_CAPS=2
    1.20  };
    1.21  
    1.22 -static int caps_state;
    1.23 +static Uint16 atari_prevmouseb;	/* save state of mouse buttons */
    1.24 +static int caps_state;			/* caps lock state */
    1.25  _KEYTAB *curtables;
    1.26  static unsigned char *tab_unshift, *tab_shift, *tab_caps;
    1.27  static SDLKey keymap[ATARIBIOS_MAXKEYS];
    1.28 @@ -80,8 +81,7 @@
    1.29  {
    1.30  	int i;
    1.31  
    1.32 -	memset(SDL_AtariIkbd_keyboard, 0, ATARIBIOS_MAXKEYS);
    1.33 -	memset(ikbd_previouskeyboard, 0, ATARIBIOS_MAXKEYS);
    1.34 +	memset(SDL_AtariIkbd_keyboard, KEY_UNDEFINED, ATARIBIOS_MAXKEYS);
    1.35  
    1.36  	/* Initialize keymap */
    1.37  	for ( i=0; i<sizeof(keymap); i++ )
    1.38 @@ -152,30 +152,36 @@
    1.39  	/*--- Send keyboard events ---*/
    1.40  
    1.41  	/* Update caps lock state */
    1.42 -	if (SDL_AtariIkbd_keyboard[SCANCODE_CAPSLOCK] && !ikbd_previouskeyboard[SCANCODE_CAPSLOCK])
    1.43 +	if (SDL_AtariIkbd_keyboard[SCANCODE_CAPSLOCK]==KEY_PRESSED) {
    1.44  		caps_state ^= 1;
    1.45 +	}
    1.46  
    1.47  	/* Choose the translation table */
    1.48  	specialkeys=KT_UNSHIFT;
    1.49 -	if (SDL_AtariIkbd_keyboard[SCANCODE_LEFTSHIFT] || SDL_AtariIkbd_keyboard[SCANCODE_RIGHTSHIFT])
    1.50 +	if ((SDL_AtariIkbd_keyboard[SCANCODE_LEFTSHIFT]==KEY_PRESSED)
    1.51 +		|| (SDL_AtariIkbd_keyboard[SCANCODE_RIGHTSHIFT]==KEY_PRESSED))
    1.52 +	{
    1.53  		specialkeys = KT_SHIFT;
    1.54 -	if (caps_state)
    1.55 +	}
    1.56 +	if (caps_state) {
    1.57  		specialkeys = KT_CAPS;
    1.58 +	}
    1.59  
    1.60  	/* Now generate events */
    1.61  	for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
    1.62  		/* Key pressed ? */
    1.63 -		if (SDL_AtariIkbd_keyboard[i] && !ikbd_previouskeyboard[i])
    1.64 +		if (SDL_AtariIkbd_keyboard[i]==KEY_PRESSED) {
    1.65  			SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(i, specialkeys, &keysym));
    1.66 +			SDL_AtariIkbd_keyboard[i]=KEY_UNDEFINED;
    1.67 +		}
    1.68  			
    1.69 -		/* Key unpressed ? */
    1.70 -		if (ikbd_previouskeyboard[i] && !SDL_AtariIkbd_keyboard[i])
    1.71 +		/* Key released ? */
    1.72 +		if (SDL_AtariIkbd_keyboard[i]==KEY_RELEASED) {
    1.73  			SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(i, specialkeys, &keysym));
    1.74 +			SDL_AtariIkbd_keyboard[i]=KEY_UNDEFINED;
    1.75 +		}
    1.76  	}
    1.77  
    1.78 -	/* Will be previous table */
    1.79 -	memcpy(ikbd_previouskeyboard, SDL_AtariIkbd_keyboard, ATARIBIOS_MAXKEYS);
    1.80 -
    1.81  	/*--- Send mouse events ---*/
    1.82  
    1.83  	/* Mouse motion ? */
    1.84 @@ -238,4 +244,3 @@
    1.85  {
    1.86  	Supexec(SDL_AtariIkbdUninstall);
    1.87  }
    1.88 -
     2.1 --- a/src/video/ataricommon/SDL_ikbdinterrupt.S	Wed Jun 29 16:18:46 2005 +0000
     2.2 +++ b/src/video/ataricommon/SDL_ikbdinterrupt.S	Wed Jun 29 20:32:46 2005 +0000
     2.3 @@ -49,7 +49,7 @@
     2.4  _SDL_AtariIkbdInstall:
     2.5  	moveml	d0-d1/a0-a1,sp@-
     2.6  
     2.7 -	| Init interrupts
     2.8 +	| Disable interrupts
     2.9  
    2.10  	movew	#0x2700,sr
    2.11  
    2.12 @@ -57,9 +57,9 @@
    2.13  
    2.14  	lea	0xfffffa00:w,a0
    2.15  	btst	#6,a0@(0x09)
    2.16 -	sne	ikbd_ierb
    2.17 +	sne		ikbd_ierb
    2.18  	btst	#6,a0@(0x15)
    2.19 -	sne	ikbd_imrb
    2.20 +	sne		ikbd_imrb
    2.21  
    2.22  	| Set our routine
    2.23  
    2.24 @@ -68,8 +68,12 @@
    2.25  	bset	#6,0xfffffa09:w	| IERB
    2.26  	bset	#6,0xfffffa15:w	| IMRB
    2.27  
    2.28 +	| Set mouse relative mode
    2.29 +
    2.30  	moveb	#8,0xfffffc02:w
    2.31  
    2.32 +	| Reenable interrupts
    2.33 +
    2.34  	movew	#0x2300,sr
    2.35  
    2.36  	| Interrupts done
    2.37 @@ -84,7 +88,7 @@
    2.38  _SDL_AtariIkbdUninstall:
    2.39  	movel	a0,sp@-
    2.40  
    2.41 -	| Stop interrupt
    2.42 +	| Disable interrupts
    2.43  
    2.44  	movew	#0x2700,sr
    2.45  
    2.46 @@ -94,13 +98,13 @@
    2.47  
    2.48  	bclr	#6,a0@(0x09)
    2.49  	tstb	ikbd_ierb
    2.50 -	beq	ikbd_restoreierb
    2.51 +	beqs	ikbd_restoreierb
    2.52  	bset	#6,a0@(0x09)
    2.53  ikbd_restoreierb:
    2.54  
    2.55  	bclr	#6,a0@(0x15)
    2.56  	tstb	ikbd_imrb
    2.57 -	beq	ikbd_restoreimrb
    2.58 +	beqs	ikbd_restoreimrb
    2.59  	bset	#6,a0@(0x15)
    2.60  ikbd_restoreimrb:
    2.61  
    2.62 @@ -111,11 +115,13 @@
    2.63  	lea	0xfffffc00:w,a0
    2.64  ikbd_videbuffer:
    2.65  	btst	#0,a0@
    2.66 -	beq	ikbd_finbuffer
    2.67 +	beqs	ikbd_finbuffer
    2.68  	tstb	a0@(0x02)
    2.69 -	bra	ikbd_videbuffer
    2.70 +	bras	ikbd_videbuffer
    2.71  ikbd_finbuffer:
    2.72  
    2.73 +	| Reenable interrupts
    2.74 +
    2.75  	movew	#0x2300,sr
    2.76  
    2.77  	movel	sp@+,a0
    2.78 @@ -136,7 +142,6 @@
    2.79  	.comm	old_ikbd,4*1
    2.80  ikbd:
    2.81  	| Check if source is IKBD or MIDI
    2.82 -	
    2.83  	btst	#0,0xfffffc00.w
    2.84  	beqs	ikbd_oldmidi
    2.85  
    2.86 @@ -155,6 +160,8 @@
    2.87  	cmpb	#0xfc,d0
    2.88  	bpls	ikbd_no_mouse
    2.89  
    2.90 +	| Mouse packet, byte #1
    2.91 +
    2.92  ikbd_yes_mouse:
    2.93  	andw	#3,d0
    2.94  	movew	d0,_SDL_AtariIkbd_mouseb
    2.95 @@ -162,16 +169,20 @@
    2.96  	movel	#ikbd_mousex,0x118:w
    2.97  	bras	ikbd_endit_stack
    2.98  
    2.99 +	| Joystick packet, byte #1
   2.100 +
   2.101  ikbd_yes_joystick:
   2.102  	movel	#ikbd_joystick,0x118:w
   2.103  	bras	ikbd_endit_stack
   2.104  
   2.105 +	| Keyboard press/release
   2.106 +
   2.107  ikbd_no_mouse:
   2.108  	moveb	d0,d1
   2.109 -	lea	_SDL_AtariIkbd_keyboard,a0
   2.110 -	andl	#0x7f,d1
   2.111 -	tas	d0
   2.112 -	spl	a0@(0,d1:w)
   2.113 +	lea		_SDL_AtariIkbd_keyboard,a0
   2.114 +	andw	#0x7f,d1
   2.115 +	tas		d0
   2.116 +	spl		a0@(0,d1:w)
   2.117  
   2.118  	| End of interrupt
   2.119  
   2.120 @@ -187,9 +198,11 @@
   2.121  	movel	old_ikbd,sp@-
   2.122  	rts
   2.123  
   2.124 +	| Mouse packet, byte #2
   2.125 +
   2.126  ikbd_mousex:
   2.127 +
   2.128  	| Check if source is IKBD or MIDI
   2.129 -	
   2.130  	btst	#0,0xfffffc00.w
   2.131  	beqs	ikbd_oldmidi
   2.132  
   2.133 @@ -204,9 +217,11 @@
   2.134  	movel	#ikbd_mousey,0x118:w
   2.135  	bras	ikbd_endit
   2.136  
   2.137 +	| Mouse packet, byte #3
   2.138 +
   2.139  ikbd_mousey:
   2.140 +
   2.141  	| Check if source is IKBD or MIDI
   2.142 -	
   2.143  	btst	#0,0xfffffc00.w
   2.144  	beqs	ikbd_oldmidi
   2.145  
   2.146 @@ -221,9 +236,11 @@
   2.147  	movel	#ikbd,0x118:w
   2.148  	bras	ikbd_endit
   2.149  
   2.150 +	| Joystick packet, byte #2
   2.151 +
   2.152  ikbd_joystick:
   2.153 +
   2.154  	| Check if source is IKBD or MIDI
   2.155 -	
   2.156  	btst	#0,0xfffffc00.w
   2.157  	beqs	ikbd_oldmidi
   2.158