Example #1
0
static int16_t sdl_analog_device_state(sdl_input_t *sdl, const struct snes_keybind **binds_,
      unsigned port_num, unsigned index, unsigned id)
{
   const struct snes_keybind *binds = binds_[port_num];
   if (id >= RARCH_BIND_LIST_END)
      return 0;

   unsigned id_minus = 0;
   unsigned id_plus  = 0;
   conv_analog_id_to_bind_id(index, id, &id_minus, &id_plus);

   const struct snes_keybind *bind_minus = &binds[id_minus];
   const struct snes_keybind *bind_plus  = &binds[id_plus];
   if (!bind_minus->valid || !bind_plus->valid)
      return 0;

   // A user might have bound minus axis to positive axis in SDL.
#ifdef HAVE_DINPUT
   int16_t pressed_minus = abs(sdl_dinput_axis(sdl->di, port_num, bind_minus));
   int16_t pressed_plus  = abs(sdl_dinput_axis(sdl->di, port_num, bind_plus));
#else
   int16_t pressed_minus = abs(sdl_axis_analog(sdl, port_num, bind_minus->joyaxis));
   int16_t pressed_plus  = abs(sdl_axis_analog(sdl, port_num, bind_plus->joyaxis));
#endif

   int16_t res = pressed_plus - pressed_minus;

   // TODO: Does it make sense to use axis thresholding here?
   if (res != 0)
      return res;

   int16_t digital_left  = sdl_is_pressed(sdl, port_num, bind_minus) ? -0x7fff : 0;
   int16_t digital_right = sdl_is_pressed(sdl, port_num, bind_plus)  ?  0x7fff : 0;
   return digital_right + digital_left;
}
Example #2
0
static bool sdl_input_key_pressed(void *data, int key)
{
   if (key >= 0 && key < RARCH_BIND_LIST_END)
   {
      sdl_input_t *sdl     = (sdl_input_t*)data;
      settings_t *settings = config_get_ptr();
      int port             = 0;
      const struct retro_keybind *binds = settings->input.binds[0];

      if (sdl_is_pressed(sdl, 0, binds, key))
         return true;

      if (settings->input.all_users_control_menu)
      {
         for (port = 0; port < MAX_USERS; port++)
            if (input_joypad_pressed(sdl->joypad,
                  port, settings->input.binds[0], key))
               return true;
      }
      else
         if (input_joypad_pressed(sdl->joypad,
               0, settings->input.binds[0], key))
            return true;
   }

   return false;
}
Example #3
0
static int16_t sdl_joypad_device_state(sdl_input_t *sdl, const struct retro_keybind **binds_, 
      unsigned port_num, unsigned id)
{
   const struct retro_keybind *binds = binds_[port_num];
   if (id < RARCH_BIND_LIST_END)
      return binds[id].valid && sdl_is_pressed(sdl, port_num, binds, id);
   return 0;
}
Example #4
0
static bool sdl_bind_button_pressed(void *data, int key)
{
   settings_t *settings = config_get_ptr();
   const struct retro_keybind *binds = settings->input.binds[0];
   if (key >= 0 && key < RARCH_BIND_LIST_END)
      return sdl_is_pressed((sdl_input_t*)data, 0, binds, key);
   return false;
}
Example #5
0
static bool sdl_bind_button_pressed(void *data, int key)
{
   const struct retro_keybind *binds = g_settings.input.binds[0];
   if (key >= 0 && key < RARCH_BIND_LIST_END)
      return sdl_is_pressed((sdl_input_t*)data, 0, binds, key);
   else
      return false;
}
Example #6
0
static int16_t sdl_joypad_device_state(sdl_input_t *sdl, const struct snes_keybind **binds_, 
      unsigned port_num, unsigned id)
{
   const struct snes_keybind *binds = binds_[port_num];
   if (id < RARCH_BIND_LIST_END)
   {
      const struct snes_keybind *bind = &binds[id];
      return bind->valid ? (sdl_is_pressed(sdl, port_num, bind) ? 1 : 0) : 0;
   }
   else
      return 0;
}
Example #7
0
static bool sdl_input_key_pressed(void *data, int key)
{
   if (key >= 0 && key < RARCH_BIND_LIST_END)
   {
      sdl_input_t *sdl     = (sdl_input_t*)data;
      settings_t *settings = config_get_ptr();
      const struct retro_keybind *binds = settings->input.binds[0];

      if (sdl_is_pressed(sdl, 0, binds, key))
         return true;
      if (input_joypad_pressed(sdl->joypad, 0, binds, key))
         return true;
   }

   return false;
}
Example #8
0
static int16_t sdl_joypad_device_state(sdl_input_t *sdl, const struct retro_keybind **binds_, 
      unsigned port_num, unsigned id, enum input_device_type *device)
{
   if (id < RARCH_BIND_LIST_END)
   {
      const struct retro_keybind *binds = binds_[port_num];
      if (binds[id].valid && sdl_is_pressed(sdl, port_num, binds, id))
      {
         *device = INPUT_DEVICE_TYPE_KEYBOARD;
         return 1;
      }
      if (binds[id].valid && input_joypad_pressed(sdl->joypad, 0, binds, id))
      {
         *device = INPUT_DEVICE_TYPE_JOYPAD;
         return 1;
      }
   }
   return 0;
}