src/video/ataricommon/SDL_ikbdevents.c
author Edgar Simo <bobbens@gmail.com>
Sun, 06 Jul 2008 17:06:37 +0000
branchgsoc2008_force_feedback
changeset 2498 ab567bd667bf
parent 2043 adf732f1f016
child 2859 99210400e8b9
permissions -rw-r--r--
Fixed various mistakes in the doxygen.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 /*
    25  *	Atari keyboard events manager, using hardware IKBD
    26  *
    27  *	Patrice Mandin
    28  */
    29 
    30 /* Mint includes */
    31 #include <mint/osbind.h>
    32 
    33 #include "../../events/SDL_sysevents.h"
    34 #include "../../events/SDL_events_c.h"
    35 
    36 #include "SDL_atarikeys.h"
    37 #include "SDL_atarievents_c.h"
    38 #include "SDL_ikbdinterrupt_s.h"
    39 
    40 #define KEY_PRESSED		0xff
    41 #define KEY_UNDEFINED	0x80
    42 #define KEY_RELEASED	0x00
    43 
    44 static Uint16 atari_prevmouseb; /* save state of mouse buttons */
    45 
    46 void
    47 AtariIkbd_InitOSKeymap(_THIS)
    48 {
    49     SDL_memset(SDL_AtariIkbd_keyboard, KEY_UNDEFINED,
    50                sizeof(SDL_AtariIkbd_keyboard));
    51 
    52     /* Now install our handler */
    53     SDL_AtariIkbd_mouseb = SDL_AtariIkbd_mousex = SDL_AtariIkbd_mousey = 0;
    54     atari_prevmouseb = 0;
    55 
    56     Supexec(SDL_AtariIkbdInstall);
    57 }
    58 
    59 static int
    60 atari_GetButton(int button)
    61 {
    62     switch (button) {
    63     case 0:
    64         return SDL_BUTTON_RIGHT;
    65         break;
    66     case 1:
    67     default:
    68         return SDL_BUTTON_LEFT;
    69         break;
    70     }
    71 }
    72 
    73 void
    74 AtariIkbd_PumpEvents(_THIS)
    75 {
    76     int i;
    77     SDL_keysym keysym;
    78     int specialkeys;
    79 
    80         /*--- Send keyboard events ---*/
    81 
    82     /* Now generate events */
    83     for (i = 0; i < ATARIBIOS_MAXKEYS; i++) {
    84         /* Key pressed ? */
    85         if (SDL_AtariIkbd_keyboard[i] == KEY_PRESSED) {
    86             SDL_PrivateKeyboard(SDL_PRESSED,
    87                                 SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
    88             SDL_AtariIkbd_keyboard[i] = KEY_UNDEFINED;
    89         }
    90 
    91         /* Key released ? */
    92         if (SDL_AtariIkbd_keyboard[i] == KEY_RELEASED) {
    93             SDL_PrivateKeyboard(SDL_RELEASED,
    94                                 SDL_Atari_TranslateKey(i, &keysym,
    95                                                        SDL_FALSE));
    96             SDL_AtariIkbd_keyboard[i] = KEY_UNDEFINED;
    97         }
    98     }
    99 
   100         /*--- Send mouse events ---*/
   101 
   102     /* Mouse motion ? */
   103     if (SDL_AtariIkbd_mousex || SDL_AtariIkbd_mousey) {
   104         SDL_PrivateMouseMotion(0, 1, SDL_AtariIkbd_mousex,
   105                                SDL_AtariIkbd_mousey);
   106         SDL_AtariIkbd_mousex = SDL_AtariIkbd_mousey = 0;
   107     }
   108 
   109     /* Mouse button ? */
   110     if (SDL_AtariIkbd_mouseb != atari_prevmouseb) {
   111         for (i = 0; i < 2; i++) {
   112             int curbutton, prevbutton;
   113 
   114             curbutton = SDL_AtariIkbd_mouseb & (1 << i);
   115             prevbutton = atari_prevmouseb & (1 << i);
   116 
   117             if (curbutton && !prevbutton) {
   118                 SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0);
   119             }
   120             if (!curbutton && prevbutton) {
   121                 SDL_PrivateMouseButton(SDL_RELEASED,
   122                                        atari_GetButton(i), 0, 0);
   123             }
   124         }
   125         atari_prevmouseb = SDL_AtariIkbd_mouseb;
   126     }
   127 }
   128 
   129 void
   130 AtariIkbd_ShutdownEvents(void)
   131 {
   132     Supexec(SDL_AtariIkbdUninstall);
   133 }
   134 
   135 /* vi: set ts=4 sw=4 expandtab: */