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