src/video/ataricommon/SDL_gemdosevents.c
author Patrice Mandin
Wed, 20 Sep 2006 19:49:23 +0000
changeset 2031 f54073d86c82
parent 2030 d774e9d7c2a8
child 2033 b657f0bc72c2
permissions -rw-r--r--
Reenable mouse usage using xbios vectors under MiNT
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
slouken@281
    44
static unsigned char gemdos_currentkeyboard[ATARIBIOS_MAXKEYS];
slouken@281
    45
static unsigned char gemdos_previouskeyboard[ATARIBIOS_MAXKEYS];
patmandin@1420
    46
static SDL_bool use_dev_mouse = SDL_FALSE;
slouken@281
    47
patmandin@2030
    48
enum {
patmandin@2030
    49
	DEV_BUSY=0,
patmandin@2030
    50
	DEV_READY
slouken@281
    51
};
slouken@281
    52
slouken@281
    53
static void UpdateSpecialKeys(int special_keys_state);
slouken@281
    54
slouken@1895
    55
void
slouken@1895
    56
AtariGemdos_InitOSKeymap(_THIS)
slouken@281
    57
{
slouken@1895
    58
    int i, vectors_mask;
slouken@1895
    59
    unsigned long dummy;
slouken@281
    60
slouken@1895
    61
    SDL_memset(gemdos_currentkeyboard, 0, sizeof(gemdos_currentkeyboard));
slouken@1895
    62
    SDL_memset(gemdos_previouskeyboard, 0, sizeof(gemdos_previouskeyboard));
slouken@281
    63
slouken@1895
    64
    use_dev_mouse = (SDL_AtariDevMouse_Open() != 0) ? SDL_TRUE : SDL_FALSE;
patmandin@1420
    65
slouken@1895
    66
    vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS;  /* XBIOS joystick events */
slouken@1895
    67
    if (!use_dev_mouse) {
slouken@1895
    68
        vectors_mask |= ATARI_XBIOS_MOUSEEVENTS;        /* XBIOS mouse events */
slouken@1895
    69
    }
patmandin@2031
    70
    /*if (Getcookie(C_MiNT, &dummy) == C_FOUND) {
slouken@1895
    71
        vectors_mask = 0;
patmandin@2031
    72
    }*/
patmandin@2031
    73
slouken@1895
    74
    SDL_AtariXbios_InstallVectors(vectors_mask);
slouken@281
    75
}
slouken@281
    76
slouken@1895
    77
void
slouken@1895
    78
AtariGemdos_PumpEvents(_THIS)
slouken@281
    79
{
slouken@1895
    80
    int i;
slouken@1895
    81
    SDL_keysym keysym;
slouken@281
    82
slouken@1895
    83
    /* Update pressed keys */
slouken@1895
    84
    SDL_memset(gemdos_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
slouken@281
    85
slouken@1895
    86
    while (Cconis() != DEV_BUSY) {
slouken@1895
    87
        unsigned long key_pressed;
patmandin@2030
    88
        key_pressed=Cnecin();
patmandin@2030
    89
        gemdos_currentkeyboard[(key_pressed>>16)&(ATARIBIOS_MAXKEYS-1)]=0xFF;
slouken@1895
    90
    }
slouken@1895
    91
slouken@1895
    92
    /* Read special keys */
slouken@1895
    93
    UpdateSpecialKeys(Kbshift(-1));
slouken@281
    94
slouken@1895
    95
    /* Now generate events */
slouken@1895
    96
    for (i = 0; i < ATARIBIOS_MAXKEYS; i++) {
slouken@1895
    97
        /* Key pressed ? */
slouken@1895
    98
        if (gemdos_currentkeyboard[i] && !gemdos_previouskeyboard[i])
slouken@1895
    99
            SDL_PrivateKeyboard(SDL_PRESSED,
patmandin@2030
   100
                                SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
slouken@281
   101
slouken@1895
   102
        /* Key unpressed ? */
slouken@1895
   103
        if (gemdos_previouskeyboard[i] && !gemdos_currentkeyboard[i])
slouken@1895
   104
            SDL_PrivateKeyboard(SDL_RELEASED,
patmandin@2030
   105
                                SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE));
slouken@1895
   106
    }
slouken@281
   107
slouken@1895
   108
    if (use_dev_mouse) {
slouken@1895
   109
        SDL_AtariDevMouse_PostMouseEvents(this, SDL_TRUE);
slouken@1895
   110
    } else {
slouken@1895
   111
        SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE);
slouken@1895
   112
    }
slouken@281
   113
slouken@1895
   114
    /* Will be previous table */
slouken@1895
   115
    SDL_memcpy(gemdos_previouskeyboard, gemdos_currentkeyboard,
patmandin@2030
   116
               sizeof(gemdos_previouskeyboard));
slouken@281
   117
}
slouken@281
   118
slouken@1895
   119
static void
slouken@1895
   120
UpdateSpecialKeys(int special_keys_state)
slouken@281
   121
{
slouken@281
   122
#define UPDATE_SPECIAL_KEYS(numbit,scancode) \
slouken@281
   123
	{	\
slouken@281
   124
		if (special_keys_state & (1<<(numbit))) { \
slouken@281
   125
			gemdos_currentkeyboard[scancode]=0xFF; \
slouken@281
   126
			gemdos_currentascii[scancode]=0; \
slouken@281
   127
		}	\
slouken@281
   128
	}
slouken@281
   129
slouken@1895
   130
    UPDATE_SPECIAL_KEYS(K_RSHIFT, SCANCODE_RIGHTSHIFT);
slouken@1895
   131
    UPDATE_SPECIAL_KEYS(K_LSHIFT, SCANCODE_LEFTSHIFT);
slouken@1895
   132
    UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL);
slouken@1895
   133
    UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT);
slouken@1895
   134
    UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
slouken@281
   135
}
slouken@281
   136
slouken@1895
   137
void
slouken@1895
   138
AtariGemdos_ShutdownEvents(void)
slouken@281
   139
{
slouken@1895
   140
    SDL_AtariXbios_RestoreVectors();
slouken@1895
   141
    if (use_dev_mouse) {
slouken@1895
   142
        SDL_AtariDevMouse_Close();
slouken@1895
   143
    }
slouken@281
   144
}
slouken@1895
   145
slouken@1895
   146
/* vi: set ts=4 sw=4 expandtab: */