src/video/ataricommon/SDL_biosevents.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 06 Jan 2006 13:20:10 +0000
changeset 1234 73676c1f56ee
parent 1221 8ef3e7e92a91
child 1237 a8068adf156b
permissions -rw-r--r--
For sanity's sake, removed the '&' when passing copy_row array to asm.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2004 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Library General Public
     7     License as published by the Free Software Foundation; either
     8     version 2 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Library General Public License for more details.
    14 
    15     You should have received a copy of the GNU Library General Public
    16     License along with this library; if not, write to the Free
    17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 
    23 #ifdef SAVE_RCSID
    24 static char rcsid =
    25  "@(#) $Id$";
    26 #endif
    27 
    28 /*
    29  *	Atari keyboard events manager, using BIOS
    30  *
    31  *	Patrice Mandin
    32  */
    33 
    34 #include <string.h>
    35 
    36 /* Mint includes */
    37 #include <mint/osbind.h>
    38 
    39 #include "SDL.h"
    40 #include "SDL_sysevents.h"
    41 #include "SDL_events_c.h"
    42 
    43 #include "SDL_atarikeys.h"
    44 #include "SDL_atarievents_c.h"
    45 #include "SDL_xbiosevents_c.h"
    46 
    47 /* To save state of keyboard */
    48 #define ATARIBIOS_MAXKEYS 128
    49 
    50 static unsigned char bios_currentkeyboard[ATARIBIOS_MAXKEYS];
    51 static unsigned char bios_previouskeyboard[ATARIBIOS_MAXKEYS];
    52 static unsigned char bios_currentascii[ATARIBIOS_MAXKEYS];
    53 
    54 /* Special keys state */
    55 enum {
    56 	K_RSHIFT=0,
    57 	K_LSHIFT,
    58 	K_CTRL,
    59 	K_ALT,
    60 	K_CAPSLOCK,
    61 	K_CLRHOME,
    62 	K_INSERT
    63 };
    64 
    65 /* The translation tables from a console scancode to a SDL keysym */
    66 static SDLKey keymap[ATARIBIOS_MAXKEYS];
    67 
    68 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym,
    69 	SDL_bool pressed);
    70 static void UpdateSpecialKeys(int special_keys_state);
    71 
    72 void AtariBios_InitOSKeymap(_THIS)
    73 {
    74 	int i;
    75 
    76 	memset(bios_currentkeyboard, 0, sizeof(bios_currentkeyboard));
    77 	memset(bios_previouskeyboard, 0, sizeof(bios_previouskeyboard));
    78 
    79 	/* Initialize keymap */
    80 	for ( i=0; i<sizeof(keymap); i++ )
    81 		keymap[i] = SDLK_UNKNOWN;
    82 
    83 	/* Functions keys */
    84 	for ( i = 0; i<10; i++ )
    85 		keymap[SCANCODE_F1 + i] = SDLK_F1+i;
    86 
    87 	/* Cursor keypad */
    88 	keymap[SCANCODE_HELP] = SDLK_HELP;
    89 	keymap[SCANCODE_UNDO] = SDLK_UNDO;
    90 	keymap[SCANCODE_INSERT] = SDLK_INSERT;
    91 	keymap[SCANCODE_CLRHOME] = SDLK_HOME;
    92 	keymap[SCANCODE_UP] = SDLK_UP;
    93 	keymap[SCANCODE_DOWN] = SDLK_DOWN;
    94 	keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
    95 	keymap[SCANCODE_LEFT] = SDLK_LEFT;
    96 
    97 	/* Special keys */
    98 	keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
    99 	keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
   100 	keymap[SCANCODE_TAB] = SDLK_TAB;
   101 	keymap[SCANCODE_ENTER] = SDLK_RETURN;
   102 	keymap[SCANCODE_DELETE] = SDLK_DELETE;
   103 	keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
   104 	keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
   105 	keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
   106 	keymap[SCANCODE_LEFTALT] = SDLK_LALT;
   107 	keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
   108 
   109 	SDL_AtariXbios_InstallVectors(ATARI_XBIOS_MOUSEEVENTS|ATARI_XBIOS_JOYSTICKEVENTS);
   110 }
   111 
   112 void AtariBios_PumpEvents(_THIS)
   113 {
   114 	int i;
   115 	SDL_keysym keysym;
   116 
   117 	/* Update pressed keys */
   118 	memset(bios_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
   119 
   120 	while (Bconstat(_CON)) {
   121 		unsigned long key_pressed;
   122 		unsigned char asciicode, scancode;
   123 
   124 		key_pressed=Bconin(_CON);
   125 
   126 		asciicode = key_pressed;
   127 		scancode = key_pressed >> 16;
   128 
   129 		bios_currentkeyboard[scancode]=0xFF;
   130 		bios_currentascii[scancode]=asciicode;
   131 	}
   132 
   133 	/* Read special keys */
   134 	UpdateSpecialKeys(Kbshift(-1));
   135 
   136 	/* Now generate events */
   137 	for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
   138 		/* Key pressed ? */
   139 		if (bios_currentkeyboard[i] && !bios_previouskeyboard[i])
   140 			SDL_PrivateKeyboard(SDL_PRESSED,
   141 				TranslateKey(i, bios_currentascii[i], &keysym, SDL_TRUE));
   142 			
   143 		/* Key unpressed ? */
   144 		if (bios_previouskeyboard[i] && !bios_currentkeyboard[i])
   145 			SDL_PrivateKeyboard(SDL_RELEASED,
   146 				TranslateKey(i, bios_currentascii[i], &keysym, SDL_FALSE));
   147 	}
   148 
   149 	SDL_AtariXbios_PostMouseEvents(this);
   150 
   151 	/* Will be previous table */
   152 	memcpy(bios_previouskeyboard, bios_currentkeyboard, ATARIBIOS_MAXKEYS);
   153 }
   154 
   155 static void UpdateSpecialKeys(int special_keys_state)
   156 {
   157 #define UPDATE_SPECIAL_KEYS(numbit,scancode) \
   158 	{	\
   159 		if (special_keys_state & (1<<(numbit))) { \
   160 			bios_currentkeyboard[scancode]=0xFF; \
   161 			bios_currentascii[scancode]=0; \
   162 		}	\
   163 	}
   164 
   165 	UPDATE_SPECIAL_KEYS(K_RSHIFT, SCANCODE_RIGHTSHIFT);
   166 	UPDATE_SPECIAL_KEYS(K_LSHIFT, SCANCODE_LEFTSHIFT);
   167 	UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL);
   168 	UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT);
   169 	UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
   170 }
   171 
   172 static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym,
   173 	SDL_bool pressed)
   174 {
   175 	/* Set the keysym information */
   176 	keysym->scancode = scancode;
   177 
   178 	if (asciicode)
   179 		keysym->sym = asciicode;		
   180 	else
   181 		keysym->sym = keymap[scancode];
   182 
   183 	keysym->mod = KMOD_NONE;
   184 	keysym->unicode = 0;
   185 	if (SDL_TranslateUNICODE && pressed) {
   186 		keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
   187 	}
   188 
   189 	return(keysym);
   190 }
   191 
   192 void AtariBios_ShutdownEvents(void)
   193 {
   194 	SDL_AtariXbios_RestoreVectors();
   195 }