src/video/ataricommon/SDL_biosevents.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 BIOS
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 bios_currentkeyboard[ATARIBIOS_MAXKEYS];
slouken@281
    46
static unsigned char bios_previouskeyboard[ATARIBIOS_MAXKEYS];
slouken@281
    47
static unsigned char bios_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@281
    62
/* The translation tables from a console scancode to a SDL keysym */
slouken@281
    63
static SDLKey keymap[ATARIBIOS_MAXKEYS];
slouken@281
    64
slouken@1662
    65
static SDL_keysym *TranslateKey (int scancode, int asciicode,
slouken@1662
    66
                                 SDL_keysym * keysym, SDL_bool pressed);
slouken@1662
    67
static void UpdateSpecialKeys (int special_keys_state);
slouken@281
    68
slouken@1662
    69
void
slouken@1662
    70
AtariBios_InitOSKeymap (_THIS)
slouken@281
    71
{
slouken@1662
    72
    int i, vectors_mask;
slouken@1662
    73
    unsigned long dummy;
slouken@281
    74
slouken@1662
    75
    SDL_memset (bios_currentkeyboard, 0, sizeof (bios_currentkeyboard));
slouken@1662
    76
    SDL_memset (bios_previouskeyboard, 0, sizeof (bios_previouskeyboard));
slouken@281
    77
slouken@1662
    78
    /* Initialize keymap */
slouken@1662
    79
    for (i = 0; i < sizeof (keymap); i++)
slouken@1662
    80
        keymap[i] = SDLK_UNKNOWN;
slouken@281
    81
slouken@1662
    82
    /* Functions keys */
slouken@1662
    83
    for (i = 0; i < 10; i++)
slouken@1662
    84
        keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
slouken@281
    85
slouken@1662
    86
    /* Cursor keypad */
slouken@1662
    87
    keymap[SCANCODE_HELP] = SDLK_HELP;
slouken@1662
    88
    keymap[SCANCODE_UNDO] = SDLK_UNDO;
slouken@1662
    89
    keymap[SCANCODE_INSERT] = SDLK_INSERT;
slouken@1662
    90
    keymap[SCANCODE_CLRHOME] = SDLK_HOME;
slouken@1662
    91
    keymap[SCANCODE_UP] = SDLK_UP;
slouken@1662
    92
    keymap[SCANCODE_DOWN] = SDLK_DOWN;
slouken@1662
    93
    keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
slouken@1662
    94
    keymap[SCANCODE_LEFT] = SDLK_LEFT;
slouken@281
    95
slouken@1662
    96
    /* Special keys */
slouken@1662
    97
    keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
slouken@1662
    98
    keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
slouken@1662
    99
    keymap[SCANCODE_TAB] = SDLK_TAB;
slouken@1662
   100
    keymap[SCANCODE_ENTER] = SDLK_RETURN;
slouken@1662
   101
    keymap[SCANCODE_DELETE] = SDLK_DELETE;
slouken@1662
   102
    keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
slouken@1662
   103
    keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
slouken@1662
   104
    keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
slouken@1662
   105
    keymap[SCANCODE_LEFTALT] = SDLK_LALT;
slouken@1662
   106
    keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
slouken@281
   107
slouken@1662
   108
    use_dev_mouse = (SDL_AtariDevMouse_Open () != 0) ? SDL_TRUE : SDL_FALSE;
patmandin@1420
   109
slouken@1662
   110
    vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS;  /* XBIOS joystick events */
slouken@1662
   111
    if (!use_dev_mouse) {
slouken@1662
   112
        vectors_mask |= ATARI_XBIOS_MOUSEEVENTS;        /* XBIOS mouse events */
slouken@1662
   113
    }
slouken@1662
   114
    if (Getcookie (C_MiNT, &dummy) == C_FOUND) {
slouken@1662
   115
        vectors_mask = 0;
slouken@1662
   116
    }
patmandin@1237
   117
slouken@1662
   118
    SDL_AtariXbios_InstallVectors (vectors_mask);
slouken@281
   119
}
slouken@281
   120
slouken@1662
   121
void
slouken@1662
   122
AtariBios_PumpEvents (_THIS)
slouken@281
   123
{
slouken@1662
   124
    int i;
slouken@1662
   125
    SDL_keysym keysym;
slouken@281
   126
slouken@1662
   127
    /* Update pressed keys */
slouken@1662
   128
    SDL_memset (bios_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
slouken@281
   129
slouken@1662
   130
    while (Bconstat (_CON)) {
slouken@1662
   131
        unsigned long key_pressed;
slouken@1662
   132
        unsigned char asciicode, scancode;
slouken@281
   133
slouken@1662
   134
        key_pressed = Bconin (_CON);
slouken@281
   135
slouken@1662
   136
        asciicode = key_pressed;
slouken@1662
   137
        scancode = key_pressed >> 16;
slouken@281
   138
slouken@1662
   139
        bios_currentkeyboard[scancode] = 0xFF;
slouken@1662
   140
        bios_currentascii[scancode] = asciicode;
slouken@1662
   141
    }
slouken@1662
   142
slouken@1662
   143
    /* Read special keys */
slouken@1662
   144
    UpdateSpecialKeys (Kbshift (-1));
slouken@281
   145
slouken@1662
   146
    /* Now generate events */
slouken@1662
   147
    for (i = 0; i < ATARIBIOS_MAXKEYS; i++) {
slouken@1662
   148
        /* Key pressed ? */
slouken@1662
   149
        if (bios_currentkeyboard[i] && !bios_previouskeyboard[i])
slouken@1662
   150
            SDL_PrivateKeyboard (SDL_PRESSED,
slouken@1662
   151
                                 TranslateKey (i, bios_currentascii[i],
slouken@1662
   152
                                               &keysym, SDL_TRUE));
slouken@281
   153
slouken@1662
   154
        /* Key unpressed ? */
slouken@1662
   155
        if (bios_previouskeyboard[i] && !bios_currentkeyboard[i])
slouken@1662
   156
            SDL_PrivateKeyboard (SDL_RELEASED,
slouken@1662
   157
                                 TranslateKey (i, bios_currentascii[i],
slouken@1662
   158
                                               &keysym, SDL_FALSE));
slouken@1662
   159
    }
slouken@281
   160
slouken@1662
   161
    if (use_dev_mouse) {
slouken@1662
   162
        SDL_AtariDevMouse_PostMouseEvents (this, SDL_TRUE);
slouken@1662
   163
    } else {
slouken@1662
   164
        SDL_AtariXbios_PostMouseEvents (this, SDL_TRUE);
slouken@1662
   165
    }
slouken@281
   166
slouken@1662
   167
    /* Will be previous table */
slouken@1662
   168
    SDL_memcpy (bios_previouskeyboard, bios_currentkeyboard,
slouken@1662
   169
                ATARIBIOS_MAXKEYS);
slouken@281
   170
}
slouken@281
   171
slouken@1662
   172
static void
slouken@1662
   173
UpdateSpecialKeys (int special_keys_state)
slouken@281
   174
{
slouken@281
   175
#define UPDATE_SPECIAL_KEYS(numbit,scancode) \
slouken@281
   176
	{	\
slouken@281
   177
		if (special_keys_state & (1<<(numbit))) { \
slouken@281
   178
			bios_currentkeyboard[scancode]=0xFF; \
slouken@281
   179
			bios_currentascii[scancode]=0; \
slouken@281
   180
		}	\
slouken@281
   181
	}
slouken@281
   182
slouken@1662
   183
    UPDATE_SPECIAL_KEYS (K_RSHIFT, SCANCODE_RIGHTSHIFT);
slouken@1662
   184
    UPDATE_SPECIAL_KEYS (K_LSHIFT, SCANCODE_LEFTSHIFT);
slouken@1662
   185
    UPDATE_SPECIAL_KEYS (K_CTRL, SCANCODE_LEFTCONTROL);
slouken@1662
   186
    UPDATE_SPECIAL_KEYS (K_ALT, SCANCODE_LEFTALT);
slouken@1662
   187
    UPDATE_SPECIAL_KEYS (K_CAPSLOCK, SCANCODE_CAPSLOCK);
slouken@281
   188
}
slouken@281
   189
slouken@1662
   190
static SDL_keysym *
slouken@1662
   191
TranslateKey (int scancode, int asciicode, SDL_keysym * keysym,
slouken@1662
   192
              SDL_bool pressed)
slouken@281
   193
{
slouken@1662
   194
    /* Set the keysym information */
slouken@1662
   195
    keysym->scancode = scancode;
slouken@281
   196
slouken@1662
   197
    if (asciicode)
slouken@1662
   198
        keysym->sym = asciicode;
slouken@1662
   199
    else
slouken@1662
   200
        keysym->sym = keymap[scancode];
slouken@281
   201
slouken@1662
   202
    keysym->mod = KMOD_NONE;
slouken@1662
   203
    keysym->unicode = 0;
slouken@1662
   204
    if (SDL_TranslateUNICODE && pressed) {
slouken@1662
   205
        keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
slouken@1662
   206
    }
slouken@281
   207
slouken@1662
   208
    return (keysym);
slouken@281
   209
}
slouken@281
   210
slouken@1662
   211
void
slouken@1662
   212
AtariBios_ShutdownEvents (void)
slouken@281
   213
{
slouken@1662
   214
    SDL_AtariXbios_RestoreVectors ();
slouken@1662
   215
    if (use_dev_mouse) {
slouken@1662
   216
        SDL_AtariDevMouse_Close ();
slouken@1662
   217
    }
slouken@281
   218
}
slouken@1662
   219
slouken@1662
   220
/* vi: set ts=4 sw=4 expandtab: */