src/video/ataricommon/SDL_biosevents.c
changeset 281 c5010ab8ba35
child 284 d8b7eae78652
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/ataricommon/SDL_biosevents.c	Sun Feb 17 19:54:28 2002 +0000
     1.3 @@ -0,0 +1,187 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Library General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Library General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Library General Public
    1.19 +    License along with this library; if not, write to the Free
    1.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@libsdl.org
    1.24 +*/
    1.25 +
    1.26 +#ifdef SAVE_RCSID
    1.27 +static char rcsid =
    1.28 + "@(#) $Id$";
    1.29 +#endif
    1.30 +
    1.31 +/*
    1.32 + *	Atari keyboard events manager, using BIOS
    1.33 + *
    1.34 + *	Patrice Mandin
    1.35 + */
    1.36 +
    1.37 +#include <string.h>
    1.38 +
    1.39 +/* Mint includes */
    1.40 +#include <mint/osbind.h>
    1.41 +
    1.42 +#include "SDL.h"
    1.43 +#include "SDL_sysevents.h"
    1.44 +#include "SDL_events_c.h"
    1.45 +
    1.46 +#include "SDL_atarikeys.h"
    1.47 +#include "SDL_xbiosmouseevents_c.h"
    1.48 +
    1.49 +/* To save state of keyboard */
    1.50 +#define ATARIBIOS_MAXKEYS 128
    1.51 +
    1.52 +static unsigned char bios_currentkeyboard[ATARIBIOS_MAXKEYS];
    1.53 +static unsigned char bios_previouskeyboard[ATARIBIOS_MAXKEYS];
    1.54 +static unsigned char bios_currentascii[ATARIBIOS_MAXKEYS];
    1.55 +
    1.56 +/* Special keys state */
    1.57 +enum {
    1.58 +	K_RSHIFT=0,
    1.59 +	K_LSHIFT,
    1.60 +	K_CTRL,
    1.61 +	K_ALT,
    1.62 +	K_CAPSLOCK,
    1.63 +	K_CLRHOME,
    1.64 +	K_INSERT
    1.65 +};
    1.66 +
    1.67 +/* The translation tables from a console scancode to a SDL keysym */
    1.68 +static SDLKey keymap[ATARIBIOS_MAXKEYS];
    1.69 +
    1.70 +static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym);
    1.71 +static void UpdateSpecialKeys(int special_keys_state);
    1.72 +
    1.73 +void AtariBios_InitOSKeymap(_THIS)
    1.74 +{
    1.75 +	int i;
    1.76 +
    1.77 +	memset(bios_currentkeyboard, 0, sizeof(bios_currentkeyboard));
    1.78 +	memset(bios_previouskeyboard, 0, sizeof(bios_previouskeyboard));
    1.79 +
    1.80 +	/* Initialize keymap */
    1.81 +	for ( i=0; i<sizeof(keymap); i++ )
    1.82 +		keymap[i] = SDLK_UNKNOWN;
    1.83 +
    1.84 +	/* Functions keys */
    1.85 +	for ( i = 0; i<10; i++ )
    1.86 +		keymap[SCANCODE_F1 + i] = SDLK_F1+i;
    1.87 +
    1.88 +	/* Cursor keypad */
    1.89 +	keymap[SCANCODE_HELP] = SDLK_HELP;
    1.90 +	keymap[SCANCODE_UNDO] = SDLK_UNDO;
    1.91 +	keymap[SCANCODE_INSERT] = SDLK_INSERT;
    1.92 +	keymap[SCANCODE_CLRHOME] = SDLK_HOME;
    1.93 +	keymap[SCANCODE_UP] = SDLK_UP;
    1.94 +	keymap[SCANCODE_DOWN] = SDLK_DOWN;
    1.95 +	keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
    1.96 +	keymap[SCANCODE_LEFT] = SDLK_LEFT;
    1.97 +
    1.98 +	/* Special keys */
    1.99 +	keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
   1.100 +	keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
   1.101 +	keymap[SCANCODE_TAB] = SDLK_TAB;
   1.102 +	keymap[SCANCODE_ENTER] = SDLK_RETURN;
   1.103 +	keymap[SCANCODE_DELETE] = SDLK_DELETE;
   1.104 +	keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
   1.105 +	keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
   1.106 +	keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
   1.107 +	keymap[SCANCODE_LEFTALT] = SDLK_LALT;
   1.108 +	keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
   1.109 +
   1.110 +	AtariXbios_InstallMouseVector();
   1.111 +}
   1.112 +
   1.113 +void AtariBios_PumpEvents(_THIS)
   1.114 +{
   1.115 +	int i;
   1.116 +	SDL_keysym keysym;
   1.117 +
   1.118 +	/* Update pressed keys */
   1.119 +	memset(bios_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
   1.120 +
   1.121 +	while (Bconstat(_CON)) {
   1.122 +		unsigned long key_pressed;
   1.123 +		unsigned char asciicode, scancode;
   1.124 +
   1.125 +		key_pressed=Bconin(_CON);
   1.126 +
   1.127 +		asciicode = key_pressed;
   1.128 +		scancode = key_pressed >> 16;
   1.129 +
   1.130 +		bios_currentkeyboard[scancode]=0xFF;
   1.131 +		bios_currentascii[scancode]=asciicode;
   1.132 +	}
   1.133 +
   1.134 +	/* Read special keys */
   1.135 +	UpdateSpecialKeys(Kbshift(-1));
   1.136 +
   1.137 +	/* Now generate events */
   1.138 +	for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
   1.139 +		/* Key pressed ? */
   1.140 +		if (bios_currentkeyboard[i] && !bios_previouskeyboard[i])
   1.141 +			SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(i, bios_currentascii[i], &keysym));
   1.142 +			
   1.143 +		/* Key unpressed ? */
   1.144 +		if (bios_previouskeyboard[i] && !bios_currentkeyboard[i])
   1.145 +			SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(i, 0, &keysym));
   1.146 +	}
   1.147 +
   1.148 +	AtariXbios_PostMouseEvents(this);
   1.149 +
   1.150 +	/* Will be previous table */
   1.151 +	memcpy(bios_previouskeyboard, bios_currentkeyboard, ATARIBIOS_MAXKEYS);
   1.152 +}
   1.153 +
   1.154 +static void UpdateSpecialKeys(int special_keys_state)
   1.155 +{
   1.156 +#define UPDATE_SPECIAL_KEYS(numbit,scancode) \
   1.157 +	{	\
   1.158 +		if (special_keys_state & (1<<(numbit))) { \
   1.159 +			bios_currentkeyboard[scancode]=0xFF; \
   1.160 +			bios_currentascii[scancode]=0; \
   1.161 +		}	\
   1.162 +	}
   1.163 +
   1.164 +	UPDATE_SPECIAL_KEYS(K_RSHIFT, SCANCODE_RIGHTSHIFT);
   1.165 +	UPDATE_SPECIAL_KEYS(K_LSHIFT, SCANCODE_LEFTSHIFT);
   1.166 +	UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL);
   1.167 +	UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT);
   1.168 +	UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
   1.169 +}
   1.170 +
   1.171 +static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym)
   1.172 +{
   1.173 +	/* Set the keysym information */
   1.174 +	keysym->scancode = scancode;
   1.175 +
   1.176 +	if (asciicode)
   1.177 +		keysym->sym = asciicode;		
   1.178 +	else
   1.179 +		keysym->sym = keymap[scancode];
   1.180 +
   1.181 +	keysym->mod = KMOD_NONE;
   1.182 +	keysym->unicode = 0;
   1.183 +
   1.184 +	return(keysym);
   1.185 +}
   1.186 +
   1.187 +void AtariBios_ShutdownEvents(void)
   1.188 +{
   1.189 +	AtariXbios_RestoreMouseVector();
   1.190 +}