src/video/ataricommon/SDL_gemdosevents.c
author Patrice Mandin
Thu, 07 Aug 2008 20:38:35 +0000
branchSDL-1.2
changeset 4149 2325dd996f73
parent 3860 bf1586b58ef2
child 4159 a1b03ba2fcd0
permissions -rw-r--r--
Check defines do not already exist in recent system headers
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@4149
    48
#ifndef DEV_BUSY
slouken@281
    49
enum {
slouken@281
    50
	DEV_BUSY=0,
slouken@281
    51
	DEV_READY
slouken@281
    52
};
patmandin@4149
    53
#endif
slouken@281
    54
slouken@281
    55
static void UpdateSpecialKeys(int special_keys_state);
slouken@281
    56
slouken@281
    57
void AtariGemdos_InitOSKeymap(_THIS)
slouken@281
    58
{
patmandin@1237
    59
	int i, vectors_mask;
patmandin@1237
    60
	unsigned long dummy;
slouken@281
    61
slouken@1336
    62
	SDL_memset(gemdos_currentkeyboard, 0, sizeof(gemdos_currentkeyboard));
slouken@1336
    63
	SDL_memset(gemdos_previouskeyboard, 0, sizeof(gemdos_previouskeyboard));
slouken@281
    64
patmandin@1420
    65
	use_dev_mouse = (SDL_AtariDevMouse_Open()!=0) ? SDL_TRUE : SDL_FALSE;
patmandin@1420
    66
patmandin@1420
    67
	vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS;	/* XBIOS joystick events */
patmandin@1420
    68
	if (!use_dev_mouse) {
patmandin@1420
    69
		vectors_mask |= ATARI_XBIOS_MOUSEEVENTS;	/* XBIOS mouse events */
patmandin@1420
    70
	}
patmandin@3860
    71
/*	if (Getcookie(C_MiNT, &dummy)==C_FOUND) {
patmandin@1237
    72
		vectors_mask = 0;
patmandin@3860
    73
	}*/
patmandin@1237
    74
	SDL_AtariXbios_InstallVectors(vectors_mask);
slouken@281
    75
}
slouken@281
    76
slouken@281
    77
void AtariGemdos_PumpEvents(_THIS)
slouken@281
    78
{
slouken@281
    79
	int i;
slouken@281
    80
	SDL_keysym keysym;
slouken@281
    81
slouken@281
    82
	/* Update pressed keys */
slouken@1336
    83
	SDL_memset(gemdos_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
slouken@281
    84
slouken@281
    85
	while (Cconis()!=DEV_BUSY) {
slouken@281
    86
		unsigned long key_pressed;
slouken@281
    87
		key_pressed=Cnecin();
patmandin@3860
    88
		gemdos_currentkeyboard[(key_pressed>>16)&(ATARIBIOS_MAXKEYS-1)]=0xFF;
slouken@281
    89
	}
slouken@281
    90
slouken@281
    91
	/* Read special keys */
slouken@281
    92
	UpdateSpecialKeys(Kbshift(-1));
slouken@281
    93
slouken@281
    94
	/* Now generate events */
slouken@281
    95
	for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
slouken@281
    96
		/* Key pressed ? */
slouken@281
    97
		if (gemdos_currentkeyboard[i] && !gemdos_previouskeyboard[i])
patmandin@1209
    98
			SDL_PrivateKeyboard(SDL_PRESSED,
patmandin@3860
    99
				SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
slouken@281
   100
			
slouken@281
   101
		/* Key unpressed ? */
slouken@281
   102
		if (gemdos_previouskeyboard[i] && !gemdos_currentkeyboard[i])
patmandin@1209
   103
			SDL_PrivateKeyboard(SDL_RELEASED,
patmandin@3860
   104
				SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE));
slouken@281
   105
	}
slouken@281
   106
patmandin@1420
   107
	if (use_dev_mouse) {
patmandin@1420
   108
		SDL_AtariDevMouse_PostMouseEvents(this, SDL_TRUE);
patmandin@1420
   109
	} else {
patmandin@1420
   110
		SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE);
patmandin@1420
   111
	}
slouken@281
   112
slouken@281
   113
	/* Will be previous table */
patmandin@3860
   114
	SDL_memcpy(gemdos_previouskeyboard, gemdos_currentkeyboard, sizeof(gemdos_previouskeyboard));
slouken@281
   115
}
slouken@281
   116
slouken@281
   117
static void UpdateSpecialKeys(int special_keys_state)
slouken@281
   118
{
slouken@281
   119
#define UPDATE_SPECIAL_KEYS(numbit,scancode) \
slouken@281
   120
	{	\
slouken@281
   121
		if (special_keys_state & (1<<(numbit))) { \
slouken@281
   122
			gemdos_currentkeyboard[scancode]=0xFF; \
slouken@281
   123
		}	\
slouken@281
   124
	}
slouken@281
   125
slouken@281
   126
	UPDATE_SPECIAL_KEYS(K_RSHIFT, SCANCODE_RIGHTSHIFT);
slouken@281
   127
	UPDATE_SPECIAL_KEYS(K_LSHIFT, SCANCODE_LEFTSHIFT);
slouken@281
   128
	UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL);
slouken@281
   129
	UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT);
slouken@281
   130
	UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
slouken@281
   131
}
slouken@281
   132
slouken@281
   133
void AtariGemdos_ShutdownEvents(void)
slouken@281
   134
{
slouken@305
   135
	SDL_AtariXbios_RestoreVectors();
patmandin@1420
   136
	if (use_dev_mouse) {
patmandin@1420
   137
		SDL_AtariDevMouse_Close();
patmandin@1420
   138
	}
slouken@281
   139
}