src/video/ataricommon/SDL_biosevents.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1420 2405517b5eab
child 1668 4da1ee79c9af
     1.1 --- a/src/video/ataricommon/SDL_biosevents.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/src/video/ataricommon/SDL_biosevents.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -48,122 +48,129 @@
     1.4  static SDL_bool use_dev_mouse = SDL_FALSE;
     1.5  
     1.6  /* Special keys state */
     1.7 -enum {
     1.8 -	K_RSHIFT=0,
     1.9 -	K_LSHIFT,
    1.10 -	K_CTRL,
    1.11 -	K_ALT,
    1.12 -	K_CAPSLOCK,
    1.13 -	K_CLRHOME,
    1.14 -	K_INSERT
    1.15 +enum
    1.16 +{
    1.17 +    K_RSHIFT = 0,
    1.18 +    K_LSHIFT,
    1.19 +    K_CTRL,
    1.20 +    K_ALT,
    1.21 +    K_CAPSLOCK,
    1.22 +    K_CLRHOME,
    1.23 +    K_INSERT
    1.24  };
    1.25  
    1.26  /* The translation tables from a console scancode to a SDL keysym */
    1.27  static SDLKey keymap[ATARIBIOS_MAXKEYS];
    1.28  
    1.29 -static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym,
    1.30 -	SDL_bool pressed);
    1.31 -static void UpdateSpecialKeys(int special_keys_state);
    1.32 +static SDL_keysym *TranslateKey (int scancode, int asciicode,
    1.33 +                                 SDL_keysym * keysym, SDL_bool pressed);
    1.34 +static void UpdateSpecialKeys (int special_keys_state);
    1.35  
    1.36 -void AtariBios_InitOSKeymap(_THIS)
    1.37 +void
    1.38 +AtariBios_InitOSKeymap (_THIS)
    1.39  {
    1.40 -	int i, vectors_mask;
    1.41 -	unsigned long dummy;
    1.42 +    int i, vectors_mask;
    1.43 +    unsigned long dummy;
    1.44  
    1.45 -	SDL_memset(bios_currentkeyboard, 0, sizeof(bios_currentkeyboard));
    1.46 -	SDL_memset(bios_previouskeyboard, 0, sizeof(bios_previouskeyboard));
    1.47 +    SDL_memset (bios_currentkeyboard, 0, sizeof (bios_currentkeyboard));
    1.48 +    SDL_memset (bios_previouskeyboard, 0, sizeof (bios_previouskeyboard));
    1.49  
    1.50 -	/* Initialize keymap */
    1.51 -	for ( i=0; i<sizeof(keymap); i++ )
    1.52 -		keymap[i] = SDLK_UNKNOWN;
    1.53 +    /* Initialize keymap */
    1.54 +    for (i = 0; i < sizeof (keymap); i++)
    1.55 +        keymap[i] = SDLK_UNKNOWN;
    1.56  
    1.57 -	/* Functions keys */
    1.58 -	for ( i = 0; i<10; i++ )
    1.59 -		keymap[SCANCODE_F1 + i] = SDLK_F1+i;
    1.60 +    /* Functions keys */
    1.61 +    for (i = 0; i < 10; i++)
    1.62 +        keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
    1.63  
    1.64 -	/* Cursor keypad */
    1.65 -	keymap[SCANCODE_HELP] = SDLK_HELP;
    1.66 -	keymap[SCANCODE_UNDO] = SDLK_UNDO;
    1.67 -	keymap[SCANCODE_INSERT] = SDLK_INSERT;
    1.68 -	keymap[SCANCODE_CLRHOME] = SDLK_HOME;
    1.69 -	keymap[SCANCODE_UP] = SDLK_UP;
    1.70 -	keymap[SCANCODE_DOWN] = SDLK_DOWN;
    1.71 -	keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
    1.72 -	keymap[SCANCODE_LEFT] = SDLK_LEFT;
    1.73 +    /* Cursor keypad */
    1.74 +    keymap[SCANCODE_HELP] = SDLK_HELP;
    1.75 +    keymap[SCANCODE_UNDO] = SDLK_UNDO;
    1.76 +    keymap[SCANCODE_INSERT] = SDLK_INSERT;
    1.77 +    keymap[SCANCODE_CLRHOME] = SDLK_HOME;
    1.78 +    keymap[SCANCODE_UP] = SDLK_UP;
    1.79 +    keymap[SCANCODE_DOWN] = SDLK_DOWN;
    1.80 +    keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
    1.81 +    keymap[SCANCODE_LEFT] = SDLK_LEFT;
    1.82  
    1.83 -	/* Special keys */
    1.84 -	keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
    1.85 -	keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
    1.86 -	keymap[SCANCODE_TAB] = SDLK_TAB;
    1.87 -	keymap[SCANCODE_ENTER] = SDLK_RETURN;
    1.88 -	keymap[SCANCODE_DELETE] = SDLK_DELETE;
    1.89 -	keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
    1.90 -	keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
    1.91 -	keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
    1.92 -	keymap[SCANCODE_LEFTALT] = SDLK_LALT;
    1.93 -	keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
    1.94 +    /* Special keys */
    1.95 +    keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
    1.96 +    keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
    1.97 +    keymap[SCANCODE_TAB] = SDLK_TAB;
    1.98 +    keymap[SCANCODE_ENTER] = SDLK_RETURN;
    1.99 +    keymap[SCANCODE_DELETE] = SDLK_DELETE;
   1.100 +    keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
   1.101 +    keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
   1.102 +    keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
   1.103 +    keymap[SCANCODE_LEFTALT] = SDLK_LALT;
   1.104 +    keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
   1.105  
   1.106 -	use_dev_mouse = (SDL_AtariDevMouse_Open()!=0) ? SDL_TRUE : SDL_FALSE;
   1.107 +    use_dev_mouse = (SDL_AtariDevMouse_Open () != 0) ? SDL_TRUE : SDL_FALSE;
   1.108  
   1.109 -	vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS;	/* XBIOS joystick events */
   1.110 -	if (!use_dev_mouse) {
   1.111 -		vectors_mask |= ATARI_XBIOS_MOUSEEVENTS;	/* XBIOS mouse events */
   1.112 -	}
   1.113 -	if (Getcookie(C_MiNT, &dummy)==C_FOUND) {
   1.114 -		vectors_mask = 0;
   1.115 -	}
   1.116 +    vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS;  /* XBIOS joystick events */
   1.117 +    if (!use_dev_mouse) {
   1.118 +        vectors_mask |= ATARI_XBIOS_MOUSEEVENTS;        /* XBIOS mouse events */
   1.119 +    }
   1.120 +    if (Getcookie (C_MiNT, &dummy) == C_FOUND) {
   1.121 +        vectors_mask = 0;
   1.122 +    }
   1.123  
   1.124 -	SDL_AtariXbios_InstallVectors(vectors_mask);
   1.125 +    SDL_AtariXbios_InstallVectors (vectors_mask);
   1.126  }
   1.127  
   1.128 -void AtariBios_PumpEvents(_THIS)
   1.129 +void
   1.130 +AtariBios_PumpEvents (_THIS)
   1.131  {
   1.132 -	int i;
   1.133 -	SDL_keysym keysym;
   1.134 +    int i;
   1.135 +    SDL_keysym keysym;
   1.136  
   1.137 -	/* Update pressed keys */
   1.138 -	SDL_memset(bios_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
   1.139 +    /* Update pressed keys */
   1.140 +    SDL_memset (bios_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
   1.141  
   1.142 -	while (Bconstat(_CON)) {
   1.143 -		unsigned long key_pressed;
   1.144 -		unsigned char asciicode, scancode;
   1.145 +    while (Bconstat (_CON)) {
   1.146 +        unsigned long key_pressed;
   1.147 +        unsigned char asciicode, scancode;
   1.148  
   1.149 -		key_pressed=Bconin(_CON);
   1.150 +        key_pressed = Bconin (_CON);
   1.151  
   1.152 -		asciicode = key_pressed;
   1.153 -		scancode = key_pressed >> 16;
   1.154 +        asciicode = key_pressed;
   1.155 +        scancode = key_pressed >> 16;
   1.156  
   1.157 -		bios_currentkeyboard[scancode]=0xFF;
   1.158 -		bios_currentascii[scancode]=asciicode;
   1.159 -	}
   1.160 +        bios_currentkeyboard[scancode] = 0xFF;
   1.161 +        bios_currentascii[scancode] = asciicode;
   1.162 +    }
   1.163 +
   1.164 +    /* Read special keys */
   1.165 +    UpdateSpecialKeys (Kbshift (-1));
   1.166  
   1.167 -	/* Read special keys */
   1.168 -	UpdateSpecialKeys(Kbshift(-1));
   1.169 +    /* Now generate events */
   1.170 +    for (i = 0; i < ATARIBIOS_MAXKEYS; i++) {
   1.171 +        /* Key pressed ? */
   1.172 +        if (bios_currentkeyboard[i] && !bios_previouskeyboard[i])
   1.173 +            SDL_PrivateKeyboard (SDL_PRESSED,
   1.174 +                                 TranslateKey (i, bios_currentascii[i],
   1.175 +                                               &keysym, SDL_TRUE));
   1.176  
   1.177 -	/* Now generate events */
   1.178 -	for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
   1.179 -		/* Key pressed ? */
   1.180 -		if (bios_currentkeyboard[i] && !bios_previouskeyboard[i])
   1.181 -			SDL_PrivateKeyboard(SDL_PRESSED,
   1.182 -				TranslateKey(i, bios_currentascii[i], &keysym, SDL_TRUE));
   1.183 -			
   1.184 -		/* Key unpressed ? */
   1.185 -		if (bios_previouskeyboard[i] && !bios_currentkeyboard[i])
   1.186 -			SDL_PrivateKeyboard(SDL_RELEASED,
   1.187 -				TranslateKey(i, bios_currentascii[i], &keysym, SDL_FALSE));
   1.188 -	}
   1.189 +        /* Key unpressed ? */
   1.190 +        if (bios_previouskeyboard[i] && !bios_currentkeyboard[i])
   1.191 +            SDL_PrivateKeyboard (SDL_RELEASED,
   1.192 +                                 TranslateKey (i, bios_currentascii[i],
   1.193 +                                               &keysym, SDL_FALSE));
   1.194 +    }
   1.195  
   1.196 -	if (use_dev_mouse) {
   1.197 -		SDL_AtariDevMouse_PostMouseEvents(this, SDL_TRUE);
   1.198 -	} else {
   1.199 -		SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE);
   1.200 -	}
   1.201 +    if (use_dev_mouse) {
   1.202 +        SDL_AtariDevMouse_PostMouseEvents (this, SDL_TRUE);
   1.203 +    } else {
   1.204 +        SDL_AtariXbios_PostMouseEvents (this, SDL_TRUE);
   1.205 +    }
   1.206  
   1.207 -	/* Will be previous table */
   1.208 -	SDL_memcpy(bios_previouskeyboard, bios_currentkeyboard, ATARIBIOS_MAXKEYS);
   1.209 +    /* Will be previous table */
   1.210 +    SDL_memcpy (bios_previouskeyboard, bios_currentkeyboard,
   1.211 +                ATARIBIOS_MAXKEYS);
   1.212  }
   1.213  
   1.214 -static void UpdateSpecialKeys(int special_keys_state)
   1.215 +static void
   1.216 +UpdateSpecialKeys (int special_keys_state)
   1.217  {
   1.218  #define UPDATE_SPECIAL_KEYS(numbit,scancode) \
   1.219  	{	\
   1.220 @@ -173,37 +180,41 @@
   1.221  		}	\
   1.222  	}
   1.223  
   1.224 -	UPDATE_SPECIAL_KEYS(K_RSHIFT, SCANCODE_RIGHTSHIFT);
   1.225 -	UPDATE_SPECIAL_KEYS(K_LSHIFT, SCANCODE_LEFTSHIFT);
   1.226 -	UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL);
   1.227 -	UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT);
   1.228 -	UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
   1.229 +    UPDATE_SPECIAL_KEYS (K_RSHIFT, SCANCODE_RIGHTSHIFT);
   1.230 +    UPDATE_SPECIAL_KEYS (K_LSHIFT, SCANCODE_LEFTSHIFT);
   1.231 +    UPDATE_SPECIAL_KEYS (K_CTRL, SCANCODE_LEFTCONTROL);
   1.232 +    UPDATE_SPECIAL_KEYS (K_ALT, SCANCODE_LEFTALT);
   1.233 +    UPDATE_SPECIAL_KEYS (K_CAPSLOCK, SCANCODE_CAPSLOCK);
   1.234  }
   1.235  
   1.236 -static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym,
   1.237 -	SDL_bool pressed)
   1.238 +static SDL_keysym *
   1.239 +TranslateKey (int scancode, int asciicode, SDL_keysym * keysym,
   1.240 +              SDL_bool pressed)
   1.241  {
   1.242 -	/* Set the keysym information */
   1.243 -	keysym->scancode = scancode;
   1.244 +    /* Set the keysym information */
   1.245 +    keysym->scancode = scancode;
   1.246  
   1.247 -	if (asciicode)
   1.248 -		keysym->sym = asciicode;		
   1.249 -	else
   1.250 -		keysym->sym = keymap[scancode];
   1.251 +    if (asciicode)
   1.252 +        keysym->sym = asciicode;
   1.253 +    else
   1.254 +        keysym->sym = keymap[scancode];
   1.255  
   1.256 -	keysym->mod = KMOD_NONE;
   1.257 -	keysym->unicode = 0;
   1.258 -	if (SDL_TranslateUNICODE && pressed) {
   1.259 -		keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
   1.260 -	}
   1.261 +    keysym->mod = KMOD_NONE;
   1.262 +    keysym->unicode = 0;
   1.263 +    if (SDL_TranslateUNICODE && pressed) {
   1.264 +        keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
   1.265 +    }
   1.266  
   1.267 -	return(keysym);
   1.268 +    return (keysym);
   1.269  }
   1.270  
   1.271 -void AtariBios_ShutdownEvents(void)
   1.272 +void
   1.273 +AtariBios_ShutdownEvents (void)
   1.274  {
   1.275 -	SDL_AtariXbios_RestoreVectors();
   1.276 -	if (use_dev_mouse) {
   1.277 -		SDL_AtariDevMouse_Close();
   1.278 -	}
   1.279 +    SDL_AtariXbios_RestoreVectors ();
   1.280 +    if (use_dev_mouse) {
   1.281 +        SDL_AtariDevMouse_Close ();
   1.282 +    }
   1.283  }
   1.284 +
   1.285 +/* vi: set ts=4 sw=4 expandtab: */