src/video/ataricommon/SDL_gemdosevents.c
author Sam Lantinga
Sun, 28 May 2006 13:04:16 +0000
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1420 2405517b5eab
child 1668 4da1ee79c9af
permissions -rw-r--r--
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.

WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.

The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce

The headers are being converted to automatically generate doxygen documentation.
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 Gemdos
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>
patmandin@1237
    32
#include <mint/cookie.h>
slouken@281
    33
slouken@1361
    34
#include "../../events/SDL_sysevents.h"
slouken@1361
    35
#include "../../events/SDL_events_c.h"
slouken@281
    36
slouken@281
    37
#include "SDL_atarikeys.h"
patmandin@1209
    38
#include "SDL_atarievents_c.h"
slouken@305
    39
#include "SDL_xbiosevents_c.h"
patmandin@1420
    40
#include "SDL_ataridevmouse_c.h"
slouken@281
    41
slouken@281
    42
/* To save state of keyboard */
slouken@281
    43
#define ATARIBIOS_MAXKEYS 128
slouken@281
    44
slouken@281
    45
static unsigned char gemdos_currentkeyboard[ATARIBIOS_MAXKEYS];
slouken@281
    46
static unsigned char gemdos_previouskeyboard[ATARIBIOS_MAXKEYS];
slouken@281
    47
static unsigned char gemdos_currentascii[ATARIBIOS_MAXKEYS];
patmandin@1420
    48
static SDL_bool use_dev_mouse = SDL_FALSE;
slouken@281
    49
slouken@281
    50
/* Special keys state */
slouken@1662
    51
enum
slouken@1662
    52
{
slouken@1662
    53
    K_RSHIFT = 0,
slouken@1662
    54
    K_LSHIFT,
slouken@1662
    55
    K_CTRL,
slouken@1662
    56
    K_ALT,
slouken@1662
    57
    K_CAPSLOCK,
slouken@1662
    58
    K_CLRHOME,
slouken@1662
    59
    K_INSERT
slouken@281
    60
};
slouken@281
    61
slouken@1662
    62
enum
slouken@1662
    63
{
slouken@1662
    64
    DEV_BUSY = 0,
slouken@1662
    65
    DEV_READY
slouken@281
    66
};
slouken@281
    67
slouken@281
    68
/* The translation tables from a console scancode to a SDL keysym */
slouken@281
    69
static SDLKey keymap[ATARIBIOS_MAXKEYS];
slouken@281
    70
slouken@1662
    71
static SDL_keysym *TranslateKey (int scancode, int asciicode,
slouken@1662
    72
                                 SDL_keysym * keysym, SDL_bool pressed);
slouken@1662
    73
static void UpdateSpecialKeys (int special_keys_state);
slouken@281
    74
slouken@1662
    75
void
slouken@1662
    76
AtariGemdos_InitOSKeymap (_THIS)
slouken@281
    77
{
slouken@1662
    78
    int i, vectors_mask;
slouken@1662
    79
    unsigned long dummy;
slouken@281
    80
slouken@1662
    81
    SDL_memset (gemdos_currentkeyboard, 0, sizeof (gemdos_currentkeyboard));
slouken@1662
    82
    SDL_memset (gemdos_previouskeyboard, 0, sizeof (gemdos_previouskeyboard));
slouken@281
    83
slouken@1662
    84
    /* Initialize keymap */
slouken@1662
    85
    for (i = 0; i < sizeof (keymap); i++)
slouken@1662
    86
        keymap[i] = SDLK_UNKNOWN;
slouken@281
    87
slouken@1662
    88
    /* Functions keys */
slouken@1662
    89
    for (i = 0; i < 10; i++)
slouken@1662
    90
        keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
slouken@281
    91
slouken@1662
    92
    /* Cursor keypad */
slouken@1662
    93
    keymap[SCANCODE_HELP] = SDLK_HELP;
slouken@1662
    94
    keymap[SCANCODE_UNDO] = SDLK_UNDO;
slouken@1662
    95
    keymap[SCANCODE_INSERT] = SDLK_INSERT;
slouken@1662
    96
    keymap[SCANCODE_CLRHOME] = SDLK_HOME;
slouken@1662
    97
    keymap[SCANCODE_UP] = SDLK_UP;
slouken@1662
    98
    keymap[SCANCODE_DOWN] = SDLK_DOWN;
slouken@1662
    99
    keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
slouken@1662
   100
    keymap[SCANCODE_LEFT] = SDLK_LEFT;
slouken@281
   101
slouken@1662
   102
    /* Special keys */
slouken@1662
   103
    keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
slouken@1662
   104
    keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
slouken@1662
   105
    keymap[SCANCODE_TAB] = SDLK_TAB;
slouken@1662
   106
    keymap[SCANCODE_ENTER] = SDLK_RETURN;
slouken@1662
   107
    keymap[SCANCODE_DELETE] = SDLK_DELETE;
slouken@1662
   108
    keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
slouken@1662
   109
    keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
slouken@1662
   110
    keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
slouken@1662
   111
    keymap[SCANCODE_LEFTALT] = SDLK_LALT;
slouken@1662
   112
    keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
slouken@281
   113
slouken@1662
   114
    use_dev_mouse = (SDL_AtariDevMouse_Open () != 0) ? SDL_TRUE : SDL_FALSE;
patmandin@1420
   115
slouken@1662
   116
    vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS;  /* XBIOS joystick events */
slouken@1662
   117
    if (!use_dev_mouse) {
slouken@1662
   118
        vectors_mask |= ATARI_XBIOS_MOUSEEVENTS;        /* XBIOS mouse events */
slouken@1662
   119
    }
slouken@1662
   120
    if (Getcookie (C_MiNT, &dummy) == C_FOUND) {
slouken@1662
   121
        vectors_mask = 0;
slouken@1662
   122
    }
slouken@1662
   123
    SDL_AtariXbios_InstallVectors (vectors_mask);
slouken@281
   124
}
slouken@281
   125
slouken@1662
   126
void
slouken@1662
   127
AtariGemdos_PumpEvents (_THIS)
slouken@281
   128
{
slouken@1662
   129
    int i;
slouken@1662
   130
    SDL_keysym keysym;
slouken@281
   131
slouken@1662
   132
    /* Update pressed keys */
slouken@1662
   133
    SDL_memset (gemdos_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
slouken@281
   134
slouken@1662
   135
    while (Cconis () != DEV_BUSY) {
slouken@1662
   136
        unsigned long key_pressed;
slouken@1662
   137
        unsigned char scancode, asciicode;
slouken@281
   138
slouken@1662
   139
        key_pressed = Cnecin ();
slouken@281
   140
slouken@1662
   141
        asciicode = key_pressed;
slouken@1662
   142
        scancode = key_pressed >> 16;
slouken@281
   143
slouken@1662
   144
        gemdos_currentkeyboard[scancode] = 0xFF;
slouken@1662
   145
        gemdos_currentascii[scancode] = asciicode;
slouken@1662
   146
    }
slouken@1662
   147
slouken@1662
   148
    /* Read special keys */
slouken@1662
   149
    UpdateSpecialKeys (Kbshift (-1));
slouken@281
   150
slouken@1662
   151
    /* Now generate events */
slouken@1662
   152
    for (i = 0; i < ATARIBIOS_MAXKEYS; i++) {
slouken@1662
   153
        /* Key pressed ? */
slouken@1662
   154
        if (gemdos_currentkeyboard[i] && !gemdos_previouskeyboard[i])
slouken@1662
   155
            SDL_PrivateKeyboard (SDL_PRESSED,
slouken@1662
   156
                                 TranslateKey (i, gemdos_currentascii[i],
slouken@1662
   157
                                               &keysym, SDL_TRUE));
slouken@281
   158
slouken@1662
   159
        /* Key unpressed ? */
slouken@1662
   160
        if (gemdos_previouskeyboard[i] && !gemdos_currentkeyboard[i])
slouken@1662
   161
            SDL_PrivateKeyboard (SDL_RELEASED,
slouken@1662
   162
                                 TranslateKey (i, gemdos_currentascii[i],
slouken@1662
   163
                                               &keysym, SDL_FALSE));
slouken@1662
   164
    }
slouken@281
   165
slouken@1662
   166
    if (use_dev_mouse) {
slouken@1662
   167
        SDL_AtariDevMouse_PostMouseEvents (this, SDL_TRUE);
slouken@1662
   168
    } else {
slouken@1662
   169
        SDL_AtariXbios_PostMouseEvents (this, SDL_TRUE);
slouken@1662
   170
    }
slouken@281
   171
slouken@1662
   172
    /* Will be previous table */
slouken@1662
   173
    SDL_memcpy (gemdos_previouskeyboard, gemdos_currentkeyboard,
slouken@1662
   174
                ATARIBIOS_MAXKEYS);
slouken@281
   175
}
slouken@281
   176
slouken@1662
   177
static void
slouken@1662
   178
UpdateSpecialKeys (int special_keys_state)
slouken@281
   179
{
slouken@281
   180
#define UPDATE_SPECIAL_KEYS(numbit,scancode) \
slouken@281
   181
	{	\
slouken@281
   182
		if (special_keys_state & (1<<(numbit))) { \
slouken@281
   183
			gemdos_currentkeyboard[scancode]=0xFF; \
slouken@281
   184
			gemdos_currentascii[scancode]=0; \
slouken@281
   185
		}	\
slouken@281
   186
	}
slouken@281
   187
slouken@1662
   188
    UPDATE_SPECIAL_KEYS (K_RSHIFT, SCANCODE_RIGHTSHIFT);
slouken@1662
   189
    UPDATE_SPECIAL_KEYS (K_LSHIFT, SCANCODE_LEFTSHIFT);
slouken@1662
   190
    UPDATE_SPECIAL_KEYS (K_CTRL, SCANCODE_LEFTCONTROL);
slouken@1662
   191
    UPDATE_SPECIAL_KEYS (K_ALT, SCANCODE_LEFTALT);
slouken@1662
   192
    UPDATE_SPECIAL_KEYS (K_CAPSLOCK, SCANCODE_CAPSLOCK);
slouken@281
   193
}
slouken@281
   194
slouken@1662
   195
static SDL_keysym *
slouken@1662
   196
TranslateKey (int scancode, int asciicode, SDL_keysym * keysym,
slouken@1662
   197
              SDL_bool pressed)
slouken@281
   198
{
slouken@1662
   199
    /* Set the keysym information */
slouken@1662
   200
    keysym->scancode = scancode;
slouken@281
   201
slouken@1662
   202
    if (asciicode)
slouken@1662
   203
        keysym->sym = asciicode;
slouken@1662
   204
    else
slouken@1662
   205
        keysym->sym = keymap[scancode];
slouken@281
   206
slouken@1662
   207
    keysym->mod = KMOD_NONE;
slouken@1662
   208
    keysym->unicode = 0;
slouken@1662
   209
    if (SDL_TranslateUNICODE && pressed) {
slouken@1662
   210
        keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
slouken@1662
   211
    }
slouken@281
   212
slouken@1662
   213
    return (keysym);
slouken@281
   214
}
slouken@281
   215
slouken@1662
   216
void
slouken@1662
   217
AtariGemdos_ShutdownEvents (void)
slouken@281
   218
{
slouken@1662
   219
    SDL_AtariXbios_RestoreVectors ();
slouken@1662
   220
    if (use_dev_mouse) {
slouken@1662
   221
        SDL_AtariDevMouse_Close ();
slouken@1662
   222
    }
slouken@281
   223
}
slouken@1662
   224
slouken@1662
   225
/* vi: set ts=4 sw=4 expandtab: */