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 {
K_INSERT
};
/* To save state of keyboard */
#define ATARIBIOS_MAXKEYS 128
static unsigned char ikbd_previouskeyboard[ATARIBIOS_MAXKEYS];
static Uint16 atari_prevmouseb; /* buttons */
#define KEY_PRESSED 0xff
#define KEY_UNDEFINED 0x80
#define KEY_RELEASED 0x00
/* The translation tables from a console scancode to a SDL keysym */
#define KT_NOCHANGE -1
......@@ -69,7 +69,8 @@ enum {
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;
static unsigned char *tab_unshift, *tab_shift, *tab_caps;
static SDLKey keymap[ATARIBIOS_MAXKEYS];
......@@ -80,8 +81,7 @@ void AtariIkbd_InitOSKeymap(_THIS)
{
int i;
memset(SDL_AtariIkbd_keyboard, 0, ATARIBIOS_MAXKEYS);
memset(ikbd_previouskeyboard, 0, ATARIBIOS_MAXKEYS);
memset(SDL_AtariIkbd_keyboard, KEY_UNDEFINED, ATARIBIOS_MAXKEYS);
/* Initialize keymap */
for ( i=0; i<sizeof(keymap); i++ )
......@@ -152,30 +152,36 @@ void AtariIkbd_PumpEvents(_THIS)
/*--- Send keyboard events ---*/
/* 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;
}
/* Choose the translation table */
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;
if (caps_state)
}
if (caps_state) {
specialkeys = KT_CAPS;
}
/* Now generate events */
for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
/* 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_AtariIkbd_keyboard[i]=KEY_UNDEFINED;
}
/* Key unpressed ? */
if (ikbd_previouskeyboard[i] && !SDL_AtariIkbd_keyboard[i])
/* Key released ? */
if (SDL_AtariIkbd_keyboard[i]==KEY_RELEASED) {
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 ---*/
/* Mouse motion ? */
......@@ -238,4 +244,3 @@ void AtariIkbd_ShutdownEvents(void)
{
Supexec(SDL_AtariIkbdUninstall);
}
......@@ -49,7 +49,7 @@ static char rcsid =
_SDL_AtariIkbdInstall:
moveml d0-d1/a0-a1,sp@-
| Init interrupts
| Disable interrupts
movew #0x2700,sr
......@@ -57,9 +57,9 @@ _SDL_AtariIkbdInstall:
lea 0xfffffa00:w,a0
btst #6,a0@(0x09)
sne ikbd_ierb
sne ikbd_ierb
btst #6,a0@(0x15)
sne ikbd_imrb
sne ikbd_imrb
| Set our routine
......@@ -68,8 +68,12 @@ _SDL_AtariIkbdInstall:
bset #6,0xfffffa09:w | IERB
bset #6,0xfffffa15:w | IMRB
| Set mouse relative mode
moveb #8,0xfffffc02:w
| Reenable interrupts
movew #0x2300,sr
| Interrupts done
......@@ -84,7 +88,7 @@ _SDL_AtariIkbdInstall:
_SDL_AtariIkbdUninstall:
movel a0,sp@-
| Stop interrupt
| Disable interrupts
movew #0x2700,sr
......@@ -94,13 +98,13 @@ _SDL_AtariIkbdUninstall:
bclr #6,a0@(0x09)
tstb ikbd_ierb
beq ikbd_restoreierb
beqs ikbd_restoreierb
bset #6,a0@(0x09)
ikbd_restoreierb:
bclr #6,a0@(0x15)
tstb ikbd_imrb
beq ikbd_restoreimrb
beqs ikbd_restoreimrb
bset #6,a0@(0x15)
ikbd_restoreimrb:
......@@ -111,11 +115,13 @@ ikbd_restoreimrb:
lea 0xfffffc00:w,a0
ikbd_videbuffer:
btst #0,a0@
beq ikbd_finbuffer
beqs ikbd_finbuffer
tstb a0@(0x02)
bra ikbd_videbuffer
bras ikbd_videbuffer
ikbd_finbuffer:
| Reenable interrupts
movew #0x2300,sr
movel sp@+,a0
......@@ -136,7 +142,6 @@ ikbd_finbuffer:
.comm old_ikbd,4*1
ikbd:
| Check if source is IKBD or MIDI
btst #0,0xfffffc00.w
beqs ikbd_oldmidi
......@@ -155,6 +160,8 @@ ikbd:
cmpb #0xfc,d0
bpls ikbd_no_mouse
| Mouse packet, byte #1
ikbd_yes_mouse:
andw #3,d0
movew d0,_SDL_AtariIkbd_mouseb
......@@ -162,16 +169,20 @@ ikbd_yes_mouse:
movel #ikbd_mousex,0x118:w
bras ikbd_endit_stack
| Joystick packet, byte #1
ikbd_yes_joystick:
movel #ikbd_joystick,0x118:w
bras ikbd_endit_stack
| Keyboard press/release
ikbd_no_mouse:
moveb d0,d1
lea _SDL_AtariIkbd_keyboard,a0
andl #0x7f,d1
tas d0
spl a0@(0,d1:w)
lea _SDL_AtariIkbd_keyboard,a0
andw #0x7f,d1
tas d0
spl a0@(0,d1:w)
| End of interrupt
......@@ -187,9 +198,11 @@ ikbd_oldmidi:
movel old_ikbd,sp@-
rts
| Mouse packet, byte #2
ikbd_mousex:
| Check if source is IKBD or MIDI
btst #0,0xfffffc00.w
beqs ikbd_oldmidi
......@@ -204,9 +217,11 @@ ikbd_mousex:
movel #ikbd_mousey,0x118:w
bras ikbd_endit
| Mouse packet, byte #3
ikbd_mousey:
| Check if source is IKBD or MIDI
btst #0,0xfffffc00.w
beqs ikbd_oldmidi
......@@ -221,9 +236,11 @@ ikbd_mousey:
movel #ikbd,0x118:w
bras ikbd_endit
| Joystick packet, byte #2
ikbd_joystick:
| Check if source is IKBD or MIDI
btst #0,0xfffffc00.w
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