src/video/ataricommon/SDL_biosevents.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 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
static unsigned char bios_currentkeyboard[ATARIBIOS_MAXKEYS];
slouken@281
    43
static unsigned char bios_previouskeyboard[ATARIBIOS_MAXKEYS];
patmandin@1420
    44
static SDL_bool use_dev_mouse = SDL_FALSE;
slouken@281
    45
slouken@281
    46
static void UpdateSpecialKeys(int special_keys_state);
slouken@281
    47
slouken@1895
    48
void
slouken@1895
    49
AtariBios_InitOSKeymap(_THIS)
slouken@281
    50
{
slouken@1895
    51
    int i, vectors_mask;
slouken@1895
    52
    unsigned long dummy;
slouken@281
    53
slouken@1895
    54
    SDL_memset(bios_currentkeyboard, 0, sizeof(bios_currentkeyboard));
slouken@1895
    55
    SDL_memset(bios_previouskeyboard, 0, sizeof(bios_previouskeyboard));
slouken@281
    56
slouken@1895
    57
    use_dev_mouse = (SDL_AtariDevMouse_Open() != 0) ? SDL_TRUE : SDL_FALSE;
patmandin@1420
    58
slouken@1895
    59
    vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS;  /* XBIOS joystick events */
slouken@1895
    60
    if (!use_dev_mouse) {
slouken@1895
    61
        vectors_mask |= ATARI_XBIOS_MOUSEEVENTS;        /* XBIOS mouse events */
slouken@1895
    62
    }
patmandin@2031
    63
    /*if (Getcookie(C_MiNT, &dummy) == C_FOUND) {
slouken@2043
    64
       vectors_mask = 0;
slouken@2043
    65
       } */
patmandin@1237
    66
slouken@1895
    67
    SDL_AtariXbios_InstallVectors(vectors_mask);
slouken@281
    68
}
slouken@281
    69
slouken@1895
    70
void
slouken@1895
    71
AtariBios_PumpEvents(_THIS)
slouken@281
    72
{
slouken@1895
    73
    int i;
slouken@1895
    74
    SDL_keysym keysym;
slouken@281
    75
slouken@1895
    76
    /* Update pressed keys */
slouken@1895
    77
    SDL_memset(bios_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
slouken@281
    78
slouken@1895
    79
    while (Bconstat(_CON)) {
slouken@1895
    80
        unsigned long key_pressed;
slouken@2043
    81
        key_pressed = Bconin(_CON);
slouken@2043
    82
        bios_currentkeyboard[(key_pressed >> 16) & (ATARIBIOS_MAXKEYS - 1)] =
slouken@2043
    83
            0xFF;
slouken@1895
    84
    }
slouken@1895
    85
slouken@1895
    86
    /* Read special keys */
slouken@1895
    87
    UpdateSpecialKeys(Kbshift(-1));
slouken@281
    88
slouken@1895
    89
    /* Now generate events */
slouken@1895
    90
    for (i = 0; i < ATARIBIOS_MAXKEYS; i++) {
slouken@1895
    91
        /* Key pressed ? */
slouken@1895
    92
        if (bios_currentkeyboard[i] && !bios_previouskeyboard[i])
slouken@1895
    93
            SDL_PrivateKeyboard(SDL_PRESSED,
patmandin@2030
    94
                                SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
slouken@281
    95
slouken@1895
    96
        /* Key unpressed ? */
slouken@1895
    97
        if (bios_previouskeyboard[i] && !bios_currentkeyboard[i])
slouken@1895
    98
            SDL_PrivateKeyboard(SDL_RELEASED,
slouken@2043
    99
                                SDL_Atari_TranslateKey(i, &keysym,
slouken@2043
   100
                                                       SDL_FALSE));
slouken@1895
   101
    }
slouken@281
   102
slouken@1895
   103
    if (use_dev_mouse) {
patmandin@2033
   104
        SDL_AtariDevMouse_PostMouseEvents(_this, SDL_TRUE);
slouken@1895
   105
    } else {
patmandin@2033
   106
        SDL_AtariXbios_PostMouseEvents(_this, SDL_TRUE);
slouken@1895
   107
    }
slouken@281
   108
slouken@1895
   109
    /* Will be previous table */
slouken@1895
   110
    SDL_memcpy(bios_previouskeyboard, bios_currentkeyboard,
patmandin@2030
   111
               sizeof(bios_previouskeyboard));
slouken@281
   112
}
slouken@281
   113
slouken@1895
   114
static void
slouken@1895
   115
UpdateSpecialKeys(int special_keys_state)
slouken@281
   116
{
slouken@281
   117
#define UPDATE_SPECIAL_KEYS(numbit,scancode) \
slouken@281
   118
	{	\
slouken@281
   119
		if (special_keys_state & (1<<(numbit))) { \
slouken@281
   120
			bios_currentkeyboard[scancode]=0xFF; \
slouken@281
   121
		}	\
slouken@281
   122
	}
slouken@281
   123
slouken@1895
   124
    UPDATE_SPECIAL_KEYS(K_RSHIFT, SCANCODE_RIGHTSHIFT);
slouken@1895
   125
    UPDATE_SPECIAL_KEYS(K_LSHIFT, SCANCODE_LEFTSHIFT);
slouken@1895
   126
    UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL);
slouken@1895
   127
    UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT);
slouken@1895
   128
    UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
slouken@281
   129
}
slouken@281
   130
slouken@1895
   131
void
slouken@1895
   132
AtariBios_ShutdownEvents(void)
slouken@281
   133
{
slouken@1895
   134
    SDL_AtariXbios_RestoreVectors();
slouken@1895
   135
    if (use_dev_mouse) {
slouken@1895
   136
        SDL_AtariDevMouse_Close();
slouken@1895
   137
    }
slouken@281
   138
}
slouken@1895
   139
slouken@1895
   140
/* vi: set ts=4 sw=4 expandtab: */