src/video/ataricommon/SDL_atarievents.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
slouken@281
    26
 *
slouken@281
    27
 *	Patrice Mandin
slouken@281
    28
 *
slouken@281
    29
 *	This routines choose what the final event manager will be
slouken@281
    30
 */
slouken@281
    31
slouken@557
    32
#include <mint/cookie.h>
patmandin@2030
    33
#include <mint/ostruct.h>
patmandin@2030
    34
#include <mint/osbind.h>
slouken@281
    35
slouken@1361
    36
#include "../../events/SDL_sysevents.h"
slouken@1361
    37
#include "../../events/SDL_events_c.h"
slouken@281
    38
patmandin@2030
    39
#include "SDL_atarikeys.h"
slouken@281
    40
#include "SDL_atarievents_c.h"
slouken@281
    41
#include "SDL_biosevents_c.h"
slouken@281
    42
#include "SDL_gemdosevents_c.h"
slouken@281
    43
#include "SDL_ikbdevents_c.h"
slouken@281
    44
slouken@1895
    45
enum
slouken@1895
    46
{
slouken@1895
    47
    MCH_ST = 0,
slouken@1895
    48
    MCH_STE,
slouken@1895
    49
    MCH_TT,
slouken@1895
    50
    MCH_F30,
slouken@1895
    51
    MCH_CLONE,
slouken@1895
    52
    MCH_ARANYM
slouken@281
    53
};
slouken@281
    54
patmandin@2030
    55
#ifndef KT_NOCHANGE
patmandin@2030
    56
# define KT_NOCHANGE -1
patmandin@2030
    57
#endif
patmandin@2030
    58
patmandin@2030
    59
/* The translation tables from a console scancode to a SDL keysym */
patmandin@2030
    60
static SDLKey keymap[ATARIBIOS_MAXKEYS];
patmandin@2030
    61
static unsigned char *keytab_normal;
patmandin@2030
    62
patmandin@2032
    63
void (*SDL_Atari_ShutdownEvents) (void);
slouken@281
    64
slouken@1895
    65
static void
patmandin@2032
    66
SDL_Atari_InitializeEvents(_THIS)
slouken@281
    67
{
slouken@1895
    68
    const char *envr;
slouken@1895
    69
    unsigned long cookie_mch;
slouken@281
    70
slouken@1895
    71
    /* Test if we are on an Atari machine or not */
slouken@1895
    72
    if (Getcookie(C__MCH, &cookie_mch) == C_NOTFOUND) {
slouken@1895
    73
        cookie_mch = 0;
slouken@1895
    74
    }
slouken@1895
    75
    cookie_mch >>= 16;
slouken@281
    76
slouken@1895
    77
    /* Default is Ikbd, the faster except for clones */
slouken@1895
    78
    switch (cookie_mch) {
slouken@1895
    79
    case MCH_ST:
slouken@1895
    80
    case MCH_STE:
slouken@1895
    81
    case MCH_TT:
slouken@1895
    82
    case MCH_F30:
slouken@1895
    83
    case MCH_ARANYM:
patmandin@2032
    84
        _this->PumpEvents = AtariIkbd_PumpEvents;
patmandin@2032
    85
        SDL_Atari_ShutdownEvents = AtariIkbd_ShutdownEvents;
slouken@1895
    86
        break;
slouken@1895
    87
    default:
patmandin@2032
    88
        _this->PumpEvents = AtariGemdos_PumpEvents;
patmandin@2032
    89
        SDL_Atari_ShutdownEvents = AtariGemdos_ShutdownEvents;
slouken@1895
    90
        break;
slouken@1895
    91
    }
slouken@281
    92
slouken@1895
    93
    envr = SDL_getenv("SDL_ATARI_EVENTSDRIVER");
slouken@281
    94
slouken@1895
    95
    if (!envr) {
slouken@1895
    96
        return;
slouken@1895
    97
    }
slouken@281
    98
slouken@1895
    99
    if (SDL_strcmp(envr, "ikbd") == 0) {
patmandin@2032
   100
        _this->PumpEvents = AtariIkbd_PumpEvents;
patmandin@2032
   101
        SDL_Atari_ShutdownEvents = AtariIkbd_ShutdownEvents;
slouken@1895
   102
    }
slouken@281
   103
slouken@1895
   104
    if (SDL_strcmp(envr, "gemdos") == 0) {
patmandin@2032
   105
        _this->PumpEvents = AtariGemdos_PumpEvents;
patmandin@2032
   106
        SDL_Atari_ShutdownEvents = AtariGemdos_ShutdownEvents;
slouken@1895
   107
    }
slouken@281
   108
slouken@1895
   109
    if (SDL_strcmp(envr, "bios") == 0) {
patmandin@2032
   110
        _this->PumpEvents = AtariBios_PumpEvents;
patmandin@2032
   111
        SDL_Atari_ShutdownEvents = AtariBios_ShutdownEvents;
slouken@1895
   112
    }
slouken@281
   113
patmandin@2032
   114
    SDL_Atari_InitInternalKeymap(_this);
slouken@281
   115
}
slouken@281
   116
slouken@1895
   117
void
slouken@1895
   118
Atari_PumpEvents(_THIS)
slouken@281
   119
{
patmandin@2034
   120
    Atari_InitializeEvents(_this);
slouken@281
   121
slouken@1895
   122
    /* Call choosen routine */
patmandin@2032
   123
    _this->PumpEvents(_this);
slouken@281
   124
}
patmandin@1209
   125
patmandin@2030
   126
void
patmandin@2030
   127
SDL_Atari_InitInternalKeymap(_THIS)
patmandin@2030
   128
{
patmandin@2030
   129
    int i;
patmandin@2030
   130
    _KEYTAB *key_tables;
patmandin@2030
   131
patmandin@2030
   132
    /* Read system tables for scancode -> ascii translation */
patmandin@2030
   133
    key_tables = (_KEYTAB *) Keytbl(KT_NOCHANGE, KT_NOCHANGE, KT_NOCHANGE);
patmandin@2030
   134
    keytab_normal = key_tables->unshift;
patmandin@2030
   135
patmandin@2030
   136
    /* Initialize keymap */
slouken@2043
   137
    for (i = 0; i < ATARIBIOS_MAXKEYS; i++)
patmandin@2030
   138
        keymap[i] = SDLK_UNKNOWN;
patmandin@2030
   139
patmandin@2030
   140
    /* Functions keys */
slouken@2043
   141
    for (i = 0; i < 10; i++)
slouken@2043
   142
        keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
patmandin@2030
   143
patmandin@2030
   144
    /* Cursor keypad */
patmandin@2030
   145
    keymap[SCANCODE_HELP] = SDLK_HELP;
patmandin@2030
   146
    keymap[SCANCODE_UNDO] = SDLK_UNDO;
patmandin@2030
   147
    keymap[SCANCODE_INSERT] = SDLK_INSERT;
patmandin@2030
   148
    keymap[SCANCODE_CLRHOME] = SDLK_HOME;
patmandin@2030
   149
    keymap[SCANCODE_UP] = SDLK_UP;
patmandin@2030
   150
    keymap[SCANCODE_DOWN] = SDLK_DOWN;
patmandin@2030
   151
    keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
patmandin@2030
   152
    keymap[SCANCODE_LEFT] = SDLK_LEFT;
patmandin@2030
   153
patmandin@2030
   154
    /* Special keys */
patmandin@2030
   155
    keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
patmandin@2030
   156
    keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
patmandin@2030
   157
    keymap[SCANCODE_TAB] = SDLK_TAB;
patmandin@2030
   158
    keymap[SCANCODE_ENTER] = SDLK_RETURN;
patmandin@2030
   159
    keymap[SCANCODE_DELETE] = SDLK_DELETE;
patmandin@2030
   160
    keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
patmandin@2030
   161
    keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
patmandin@2030
   162
    keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
patmandin@2030
   163
    keymap[SCANCODE_LEFTALT] = SDLK_LALT;
patmandin@2030
   164
    keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
patmandin@2030
   165
}
patmandin@2030
   166
patmandin@1221
   167
/* Atari to Unicode charset translation table */
patmandin@1221
   168
slouken@1895
   169
Uint16 SDL_AtariToUnicodeTable[256] = {
slouken@1895
   170
    /* Standard ASCII characters from 0x00 to 0x7e */
slouken@1895
   171
    /* Unicode stuff from 0x7f to 0xff */
patmandin@1221
   172
slouken@1895
   173
    0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
slouken@1895
   174
    0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
slouken@1895
   175
    0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
slouken@1895
   176
    0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
slouken@1895
   177
    0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
slouken@1895
   178
    0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
slouken@1895
   179
    0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
slouken@1895
   180
    0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
patmandin@1209
   181
slouken@1895
   182
    0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
slouken@1895
   183
    0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
slouken@1895
   184
    0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
slouken@1895
   185
    0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
slouken@1895
   186
    0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
slouken@1895
   187
    0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
slouken@1895
   188
    0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
slouken@1895
   189
    0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x0394,
patmandin@1221
   190
slouken@1895
   191
    0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
slouken@1895
   192
    0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
slouken@1895
   193
    0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
slouken@1895
   194
    0x00FF, 0x00D6, 0x00DC, 0x00A2, 0x00A3, 0x00A5, 0x00DF, 0x0192,
slouken@1895
   195
    0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA,
slouken@1895
   196
    0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
slouken@1895
   197
    0x00C3, 0x00F5, 0x00D8, 0x00F8, 0x0153, 0x0152, 0x00C0, 0x00C3,
slouken@1895
   198
    0x00D5, 0x00A8, 0x00B4, 0x2020, 0x00B6, 0x00A9, 0x00AE, 0x2122,
patmandin@1221
   199
slouken@1895
   200
    0x0133, 0x0132, 0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5,
slouken@1895
   201
    0x05D6, 0x05D7, 0x05D8, 0x05D9, 0x05DB, 0x05DC, 0x05DE, 0x05E0,
slouken@1895
   202
    0x05E1, 0x05E2, 0x05E4, 0x05E6, 0x05E7, 0x05E8, 0x05E9, 0x05EA,
slouken@1895
   203
    0x05DF, 0x05DA, 0x05DD, 0x05E3, 0x05E5, 0x00A7, 0x2038, 0x221E,
slouken@1895
   204
    0x03B1, 0x03B2, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4,
slouken@1895
   205
    0x03A6, 0x0398, 0x03A9, 0x03B4, 0x222E, 0x03C6, 0x2208, 0x2229,
slouken@1895
   206
    0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248,
slouken@1895
   207
    0x00B0, 0x2022, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x00B3, 0x00AF
patmandin@1221
   208
};
slouken@1895
   209
patmandin@2030
   210
SDL_keysym *
slouken@2043
   211
SDL_Atari_TranslateKey(int scancode, SDL_keysym * keysym, SDL_bool pressed)
patmandin@2030
   212
{
patmandin@2030
   213
    int asciicode = 0;
patmandin@2030
   214
patmandin@2030
   215
    /* Set the keysym information */
patmandin@2030
   216
    keysym->scancode = scancode;
patmandin@2030
   217
    keysym->mod = KMOD_NONE;
patmandin@2030
   218
    keysym->sym = keymap[scancode];
patmandin@2030
   219
    keysym->unicode = 0;
patmandin@2030
   220
patmandin@2030
   221
    if (keysym->sym == SDLK_UNKNOWN) {
slouken@2043
   222
        keysym->sym = asciicode = keytab_normal[scancode];
patmandin@2030
   223
    }
patmandin@2030
   224
patmandin@2030
   225
    if (SDL_TranslateUNICODE && pressed) {
patmandin@2030
   226
        keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
patmandin@2030
   227
    }
patmandin@2030
   228
slouken@2043
   229
    return (keysym);
patmandin@2030
   230
}
patmandin@2030
   231
slouken@1895
   232
/* vi: set ts=4 sw=4 expandtab: */