Commit 8197bd21 authored by Patrice Mandin's avatar Patrice Mandin

Avoid generating multiple key press/release messages for the same key

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401083
parent 17068ad4
...@@ -54,11 +54,11 @@ enum { ...@@ -54,11 +54,11 @@ enum {
K_INSERT K_INSERT
}; };
/* To save state of keyboard */
#define ATARIBIOS_MAXKEYS 128 #define ATARIBIOS_MAXKEYS 128
static unsigned char ikbd_previouskeyboard[ATARIBIOS_MAXKEYS]; #define KEY_PRESSED 0xff
static Uint16 atari_prevmouseb; /* buttons */ #define KEY_UNDEFINED 0x80
#define KEY_RELEASED 0x00
/* The translation tables from a console scancode to a SDL keysym */ /* The translation tables from a console scancode to a SDL keysym */
#define KT_NOCHANGE -1 #define KT_NOCHANGE -1
...@@ -69,7 +69,8 @@ enum { ...@@ -69,7 +69,8 @@ enum {
KT_CAPS=2 KT_CAPS=2
}; };
static int caps_state; static Uint16 atari_prevmouseb; /* save state of mouse buttons */
static int caps_state; /* caps lock state */
_KEYTAB *curtables; _KEYTAB *curtables;
static unsigned char *tab_unshift, *tab_shift, *tab_caps; static unsigned char *tab_unshift, *tab_shift, *tab_caps;
static SDLKey keymap[ATARIBIOS_MAXKEYS]; static SDLKey keymap[ATARIBIOS_MAXKEYS];
...@@ -80,8 +81,7 @@ void AtariIkbd_InitOSKeymap(_THIS) ...@@ -80,8 +81,7 @@ void AtariIkbd_InitOSKeymap(_THIS)
{ {
int i; int i;
memset(SDL_AtariIkbd_keyboard, 0, ATARIBIOS_MAXKEYS); memset(SDL_AtariIkbd_keyboard, KEY_UNDEFINED, ATARIBIOS_MAXKEYS);
memset(ikbd_previouskeyboard, 0, ATARIBIOS_MAXKEYS);
/* Initialize keymap */ /* Initialize keymap */
for ( i=0; i<sizeof(keymap); i++ ) for ( i=0; i<sizeof(keymap); i++ )
...@@ -152,30 +152,36 @@ void AtariIkbd_PumpEvents(_THIS) ...@@ -152,30 +152,36 @@ void AtariIkbd_PumpEvents(_THIS)
/*--- Send keyboard events ---*/ /*--- Send keyboard events ---*/
/* Update caps lock state */ /* Update caps lock state */
if (SDL_AtariIkbd_keyboard[SCANCODE_CAPSLOCK] && !ikbd_previouskeyboard[SCANCODE_CAPSLOCK]) if (SDL_AtariIkbd_keyboard[SCANCODE_CAPSLOCK]==KEY_PRESSED) {
caps_state ^= 1; caps_state ^= 1;
}
/* Choose the translation table */ /* Choose the translation table */
specialkeys=KT_UNSHIFT; specialkeys=KT_UNSHIFT;
if (SDL_AtariIkbd_keyboard[SCANCODE_LEFTSHIFT] || SDL_AtariIkbd_keyboard[SCANCODE_RIGHTSHIFT]) if ((SDL_AtariIkbd_keyboard[SCANCODE_LEFTSHIFT]==KEY_PRESSED)
|| (SDL_AtariIkbd_keyboard[SCANCODE_RIGHTSHIFT]==KEY_PRESSED))
{
specialkeys = KT_SHIFT; specialkeys = KT_SHIFT;
if (caps_state) }
if (caps_state) {
specialkeys = KT_CAPS; specialkeys = KT_CAPS;
}
/* Now generate events */ /* Now generate events */
for (i=0; i<ATARIBIOS_MAXKEYS; i++) { for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
/* Key pressed ? */ /* Key pressed ? */
if (SDL_AtariIkbd_keyboard[i] && !ikbd_previouskeyboard[i]) if (SDL_AtariIkbd_keyboard[i]==KEY_PRESSED) {
SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(i, specialkeys, &keysym)); SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(i, specialkeys, &keysym));
SDL_AtariIkbd_keyboard[i]=KEY_UNDEFINED;
}
/* Key unpressed ? */ /* Key released ? */
if (ikbd_previouskeyboard[i] && !SDL_AtariIkbd_keyboard[i]) if (SDL_AtariIkbd_keyboard[i]==KEY_RELEASED) {
SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(i, specialkeys, &keysym)); SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(i, specialkeys, &keysym));
SDL_AtariIkbd_keyboard[i]=KEY_UNDEFINED;
}
} }
/* Will be previous table */
memcpy(ikbd_previouskeyboard, SDL_AtariIkbd_keyboard, ATARIBIOS_MAXKEYS);
/*--- Send mouse events ---*/ /*--- Send mouse events ---*/
/* Mouse motion ? */ /* Mouse motion ? */
...@@ -238,4 +244,3 @@ void AtariIkbd_ShutdownEvents(void) ...@@ -238,4 +244,3 @@ void AtariIkbd_ShutdownEvents(void)
{ {
Supexec(SDL_AtariIkbdUninstall); Supexec(SDL_AtariIkbdUninstall);
} }
...@@ -49,7 +49,7 @@ static char rcsid = ...@@ -49,7 +49,7 @@ static char rcsid =
_SDL_AtariIkbdInstall: _SDL_AtariIkbdInstall:
moveml d0-d1/a0-a1,sp@- moveml d0-d1/a0-a1,sp@-
| Init interrupts | Disable interrupts
movew #0x2700,sr movew #0x2700,sr
...@@ -57,9 +57,9 @@ _SDL_AtariIkbdInstall: ...@@ -57,9 +57,9 @@ _SDL_AtariIkbdInstall:
lea 0xfffffa00:w,a0 lea 0xfffffa00:w,a0
btst #6,a0@(0x09) btst #6,a0@(0x09)
sne ikbd_ierb sne ikbd_ierb
btst #6,a0@(0x15) btst #6,a0@(0x15)
sne ikbd_imrb sne ikbd_imrb
| Set our routine | Set our routine
...@@ -68,8 +68,12 @@ _SDL_AtariIkbdInstall: ...@@ -68,8 +68,12 @@ _SDL_AtariIkbdInstall:
bset #6,0xfffffa09:w | IERB bset #6,0xfffffa09:w | IERB
bset #6,0xfffffa15:w | IMRB bset #6,0xfffffa15:w | IMRB
| Set mouse relative mode
moveb #8,0xfffffc02:w moveb #8,0xfffffc02:w
| Reenable interrupts
movew #0x2300,sr movew #0x2300,sr
| Interrupts done | Interrupts done
...@@ -84,7 +88,7 @@ _SDL_AtariIkbdInstall: ...@@ -84,7 +88,7 @@ _SDL_AtariIkbdInstall:
_SDL_AtariIkbdUninstall: _SDL_AtariIkbdUninstall:
movel a0,sp@- movel a0,sp@-
| Stop interrupt | Disable interrupts
movew #0x2700,sr movew #0x2700,sr
...@@ -94,13 +98,13 @@ _SDL_AtariIkbdUninstall: ...@@ -94,13 +98,13 @@ _SDL_AtariIkbdUninstall:
bclr #6,a0@(0x09) bclr #6,a0@(0x09)
tstb ikbd_ierb tstb ikbd_ierb
beq ikbd_restoreierb beqs ikbd_restoreierb
bset #6,a0@(0x09) bset #6,a0@(0x09)
ikbd_restoreierb: ikbd_restoreierb:
bclr #6,a0@(0x15) bclr #6,a0@(0x15)
tstb ikbd_imrb tstb ikbd_imrb
beq ikbd_restoreimrb beqs ikbd_restoreimrb
bset #6,a0@(0x15) bset #6,a0@(0x15)
ikbd_restoreimrb: ikbd_restoreimrb:
...@@ -111,11 +115,13 @@ ikbd_restoreimrb: ...@@ -111,11 +115,13 @@ ikbd_restoreimrb:
lea 0xfffffc00:w,a0 lea 0xfffffc00:w,a0
ikbd_videbuffer: ikbd_videbuffer:
btst #0,a0@ btst #0,a0@
beq ikbd_finbuffer beqs ikbd_finbuffer
tstb a0@(0x02) tstb a0@(0x02)
bra ikbd_videbuffer bras ikbd_videbuffer
ikbd_finbuffer: ikbd_finbuffer:
| Reenable interrupts
movew #0x2300,sr movew #0x2300,sr
movel sp@+,a0 movel sp@+,a0
...@@ -136,7 +142,6 @@ ikbd_finbuffer: ...@@ -136,7 +142,6 @@ ikbd_finbuffer:
.comm old_ikbd,4*1 .comm old_ikbd,4*1
ikbd: ikbd:
| Check if source is IKBD or MIDI | Check if source is IKBD or MIDI
btst #0,0xfffffc00.w btst #0,0xfffffc00.w
beqs ikbd_oldmidi beqs ikbd_oldmidi
...@@ -155,6 +160,8 @@ ikbd: ...@@ -155,6 +160,8 @@ ikbd:
cmpb #0xfc,d0 cmpb #0xfc,d0
bpls ikbd_no_mouse bpls ikbd_no_mouse
| Mouse packet, byte #1
ikbd_yes_mouse: ikbd_yes_mouse:
andw #3,d0 andw #3,d0
movew d0,_SDL_AtariIkbd_mouseb movew d0,_SDL_AtariIkbd_mouseb
...@@ -162,16 +169,20 @@ ikbd_yes_mouse: ...@@ -162,16 +169,20 @@ ikbd_yes_mouse:
movel #ikbd_mousex,0x118:w movel #ikbd_mousex,0x118:w
bras ikbd_endit_stack bras ikbd_endit_stack
| Joystick packet, byte #1
ikbd_yes_joystick: ikbd_yes_joystick:
movel #ikbd_joystick,0x118:w movel #ikbd_joystick,0x118:w
bras ikbd_endit_stack bras ikbd_endit_stack
| Keyboard press/release
ikbd_no_mouse: ikbd_no_mouse:
moveb d0,d1 moveb d0,d1
lea _SDL_AtariIkbd_keyboard,a0 lea _SDL_AtariIkbd_keyboard,a0
andl #0x7f,d1 andw #0x7f,d1
tas d0 tas d0
spl a0@(0,d1:w) spl a0@(0,d1:w)
| End of interrupt | End of interrupt
...@@ -187,9 +198,11 @@ ikbd_oldmidi: ...@@ -187,9 +198,11 @@ ikbd_oldmidi:
movel old_ikbd,sp@- movel old_ikbd,sp@-
rts rts
| Mouse packet, byte #2
ikbd_mousex: ikbd_mousex:
| Check if source is IKBD or MIDI | Check if source is IKBD or MIDI
btst #0,0xfffffc00.w btst #0,0xfffffc00.w
beqs ikbd_oldmidi beqs ikbd_oldmidi
...@@ -204,9 +217,11 @@ ikbd_mousex: ...@@ -204,9 +217,11 @@ ikbd_mousex:
movel #ikbd_mousey,0x118:w movel #ikbd_mousey,0x118:w
bras ikbd_endit bras ikbd_endit
| Mouse packet, byte #3
ikbd_mousey: ikbd_mousey:
| Check if source is IKBD or MIDI | Check if source is IKBD or MIDI
btst #0,0xfffffc00.w btst #0,0xfffffc00.w
beqs ikbd_oldmidi beqs ikbd_oldmidi
...@@ -221,9 +236,11 @@ ikbd_mousey: ...@@ -221,9 +236,11 @@ ikbd_mousey:
movel #ikbd,0x118:w movel #ikbd,0x118:w
bras ikbd_endit bras ikbd_endit
| Joystick packet, byte #2
ikbd_joystick: ikbd_joystick:
| Check if source is IKBD or MIDI | Check if source is IKBD or MIDI
btst #0,0xfffffc00.w btst #0,0xfffffc00.w
beqs ikbd_oldmidi beqs ikbd_oldmidi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment