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