Skip to content

Commit

Permalink
Avoid generating multiple key press/release messages for the same key
Browse files Browse the repository at this point in the history
  • Loading branch information
pmandin committed Jun 29, 2005
1 parent 7e800ff commit 0de5a6e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 32 deletions.
37 changes: 21 additions & 16 deletions src/video/ataricommon/SDL_ikbdevents.c
Expand Up @@ -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
Expand All @@ -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];
Expand All @@ -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++ )
Expand Down Expand Up @@ -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 ? */
Expand Down Expand Up @@ -238,4 +244,3 @@ void AtariIkbd_ShutdownEvents(void)
{
Supexec(SDL_AtariIkbdUninstall);
}

49 changes: 33 additions & 16 deletions src/video/ataricommon/SDL_ikbdinterrupt.S
Expand Up @@ -49,17 +49,17 @@ static char rcsid =
_SDL_AtariIkbdInstall:
moveml d0-d1/a0-a1,sp@-

| Init interrupts
| Disable interrupts

movew #0x2700,sr

| Save MFP registers used for keyboard

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

Expand All @@ -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
Expand All @@ -84,7 +88,7 @@ _SDL_AtariIkbdInstall:
_SDL_AtariIkbdUninstall:
movel a0,sp@-

| Stop interrupt
| Disable interrupts

movew #0x2700,sr

Expand All @@ -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:

Expand All @@ -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
Expand All @@ -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

Expand All @@ -155,23 +160,29 @@ ikbd:
cmpb #0xfc,d0
bpls ikbd_no_mouse

| Mouse packet, byte #1

ikbd_yes_mouse:
andw #3,d0
movew d0,_SDL_AtariIkbd_mouseb

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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 0de5a6e

Please sign in to comment.