Beispiel #1
0
static bool android_joypad_button(unsigned port, uint16_t joykey)
{
   uint8_t *buf             = NULL;
   driver_t *driver         = driver_get_ptr();
   android_input_t *android = (android_input_t*)driver->input_data;

   if (!android || port >= MAX_PADS)
      return false;

   buf = android->pad_state[port];

   if (GET_HAT_DIR(joykey))
   {
      unsigned h = GET_HAT(joykey);
      if (h > 0)
         return false;

      switch (GET_HAT_DIR(joykey))
      {
         case HAT_LEFT_MASK:
            return android->hat_state[port][0] == -1;
         case HAT_RIGHT_MASK:
            return android->hat_state[port][0] ==  1;
         case HAT_UP_MASK:
            return android->hat_state[port][1] == -1;
         case HAT_DOWN_MASK:
            return android->hat_state[port][1] ==  1;
         default:
            return false;
      }
   }

   return joykey < LAST_KEYCODE && BIT_GET(buf, joykey);
}
Beispiel #2
0
static void input_get_bind_string_joykey(char *buf, const char *prefix, const struct retro_keybind *bind, size_t size)
{
   if (driver.input->set_keybinds)
   {
      struct platform_bind key_label;
      strlcpy(key_label.desc, "Unknown", sizeof(key_label.desc));
      key_label.joykey = bind->joykey;
      driver.input->set_keybinds(&key_label, 0, 0, 0, (1ULL << KEYBINDS_ACTION_GET_BIND_LABEL));
      snprintf(buf, size, "%s%s (btn) ", prefix, key_label.desc);
   }
   else if (GET_HAT_DIR(bind->joykey))
   {
      const char *dir;
      switch (GET_HAT_DIR(bind->joykey))
      {
         case HAT_UP_MASK: dir = "up"; break;
         case HAT_DOWN_MASK: dir = "down"; break;
         case HAT_LEFT_MASK: dir = "left"; break;
         case HAT_RIGHT_MASK: dir = "right"; break;
         default: dir = "?"; break;
      }
      snprintf(buf, size, "%sHat #%u %s ", prefix, (unsigned)GET_HAT(bind->joykey), dir);
   }
   else
      snprintf(buf, size, "%s%u (btn) ", prefix, (unsigned)bind->joykey);
}
Beispiel #3
0
static bool sdl_joykey_pressed(sdl_input_t *sdl, int port_num, uint16_t joykey)
{
   if (joykey == NO_BTN)
      return false;

   // Check hat.
   if (GET_HAT_DIR(joykey))
   {
      uint16_t hat = GET_HAT(joykey);
      if (hat >= sdl->num_hats[port_num])
         return false;

      Uint8 dir = SDL_JoystickGetHat(sdl->joysticks[port_num], hat);
      switch (GET_HAT_DIR(joykey))
      {
         case HAT_UP_MASK:
            return dir & SDL_HAT_UP;
         case HAT_DOWN_MASK:
            return dir & SDL_HAT_DOWN;
         case HAT_LEFT_MASK:
            return dir & SDL_HAT_LEFT;
         case HAT_RIGHT_MASK:
            return dir & SDL_HAT_RIGHT;
         default:
            return false;
      }
   }
   else // Check the button
   {
      if (joykey < sdl->num_buttons[port_num] && SDL_JoystickGetButton(sdl->joysticks[port_num], joykey))
         return true;

      return false;
   }
}
Beispiel #4
0
static bool android_joypad_button(unsigned port, uint16_t joykey)
{
   unsigned hat_dir                = 0;
   uint8_t *buf                    = android_keyboard_state_get(port);
   struct android_app *android_app = (struct android_app*)g_android;

   if (port >= MAX_PADS)
      return false;

   hat_dir = GET_HAT_DIR(joykey);

   if (hat_dir)
   {
      unsigned h = GET_HAT(joykey);
      if (h > 0)
         return false;

      switch (hat_dir)
      {
         case HAT_LEFT_MASK:
            return android_app->hat_state[port][0] == -1;
         case HAT_RIGHT_MASK:
            return android_app->hat_state[port][0] ==  1;
         case HAT_UP_MASK:
            return android_app->hat_state[port][1] == -1;
         case HAT_DOWN_MASK:
            return android_app->hat_state[port][1] ==  1;
         default:
            return false;
      }
   }

   return joykey < LAST_KEYCODE && BIT_GET(buf, joykey);
}
Beispiel #5
0
void input_get_bind_string(char *buf, const struct retro_keybind *bind, size_t size)
{
   *buf = '\0';
   if (bind->joykey != NO_BTN)
   {
      if (driver.input->set_keybinds)
      {
         struct platform_bind key_label;
         strlcpy(key_label.desc, "Unknown", sizeof(key_label.desc));
         key_label.joykey = bind->joykey;
         driver.input->set_keybinds(&key_label, 0, 0, 0, (1ULL << KEYBINDS_ACTION_GET_BIND_LABEL));
         snprintf(buf, size, "%s (btn) ", key_label.desc);
      }
      else if (GET_HAT_DIR(bind->joykey))
      {
         const char *dir;
         switch (GET_HAT_DIR(bind->joykey))
         {
            case HAT_UP_MASK: dir = "up"; break;
            case HAT_DOWN_MASK: dir = "down"; break;
            case HAT_LEFT_MASK: dir = "left"; break;
            case HAT_RIGHT_MASK: dir = "right"; break;
            default: dir = "?"; break;
         }
         snprintf(buf, size, "Hat #%u %s ", (unsigned)GET_HAT(bind->joykey), dir);
      }
      else
         snprintf(buf, size, "%u (btn) ", (unsigned)bind->joykey);
   }
   else if (bind->joyaxis != AXIS_NONE)
   {
      unsigned axis = 0;
      char dir = '\0';
      if (AXIS_NEG_GET(bind->joyaxis) != AXIS_DIR_NONE)
      {
         dir = '-';
         axis = AXIS_NEG_GET(bind->joyaxis);
      }
      else if (AXIS_POS_GET(bind->joyaxis) != AXIS_DIR_NONE)
      {
         dir = '+';
         axis = AXIS_POS_GET(bind->joyaxis);
      }
      snprintf(buf, size, "%c%u (axis) ", dir, axis);
   }

#ifndef RARCH_CONSOLE
   char key[64];
   input_translate_rk_to_str(bind->key, key, sizeof(key));
   if (!strcmp(key, "nul"))
      *key = '\0';

   char keybuf[64];
   snprintf(keybuf, sizeof(keybuf), "(Key: %s)", key);
   strlcat(buf, keybuf, size);
#endif
}
Beispiel #6
0
static bool dinput_joypad_button(unsigned port_num, uint16_t joykey)
{
    const struct dinput_joypad *pad = NULL;

    if (joykey == NO_BTN)
        return false;

    pad = &g_pads[port_num];
    if (!pad->joypad)
        return false;

    /* Check hat. */
    if (GET_HAT_DIR(joykey))
    {
        unsigned pov;
        unsigned hat   = GET_HAT(joykey);
        unsigned elems = sizeof(pad->joy_state.rgdwPOV) /
                         sizeof(pad->joy_state.rgdwPOV[0]);

        if (hat >= elems)
            return false;

        pov = pad->joy_state.rgdwPOV[hat];

        /* Magic numbers I'm not sure where originate from. */
        if (pov < 36000)
        {
            switch (GET_HAT_DIR(joykey))
            {
            case HAT_UP_MASK:
                return (pov >= 31500) || (pov <= 4500);
            case HAT_RIGHT_MASK:
                return (pov >= 4500) && (pov <= 13500);
            case HAT_DOWN_MASK:
                return (pov >= 13500) && (pov <= 22500);
            case HAT_LEFT_MASK:
                return (pov >= 22500) && (pov <= 31500);
            }
        }

        return false;
    }
    else
    {
        unsigned elems = sizeof(pad->joy_state.rgbButtons) /
                         sizeof(pad->joy_state.rgbButtons[0]);

        if (joykey < elems)
            return pad->joy_state.rgbButtons[joykey];
    }

    return false;
}
Beispiel #7
0
void input_get_bind_string(char *buf, const struct retro_keybind *bind, size_t size)
{
   *buf = '\0';
   if (bind->joykey != NO_BTN)
   {
      if (GET_HAT_DIR(bind->joykey))
      {
         const char *dir;
         switch (GET_HAT_DIR(bind->joykey))
         {
            case HAT_UP_MASK: dir = "up"; break;
            case HAT_DOWN_MASK: dir = "down"; break;
            case HAT_LEFT_MASK: dir = "left"; break;
            case HAT_RIGHT_MASK: dir = "right"; break;
            default: dir = "?"; break;
         }
         snprintf(buf, size, "Hat #%u %s ", (unsigned)GET_HAT(bind->joykey), dir);
      }
      else
         snprintf(buf, size, "%u (btn) ", (unsigned)bind->joykey);
   }
   else if (bind->joyaxis != AXIS_NONE)
   {
      unsigned axis = 0;
      char dir = '\0';
      if (AXIS_NEG_GET(bind->joyaxis) != AXIS_DIR_NONE)
      {
         dir = '-';
         axis = AXIS_NEG_GET(bind->joyaxis);
      }
      else if (AXIS_POS_GET(bind->joyaxis) != AXIS_DIR_NONE)
      {
         dir = '+';
         axis = AXIS_POS_GET(bind->joyaxis);
      }
      snprintf(buf, size, "%c%u (axis) ", dir, axis);
   }

   char key[64];
   input_translate_rk_to_str(bind->key, key, sizeof(key));
   if (!strcmp(key, "nul"))
      *key = '\0';

   char keybuf[64];
   snprintf(keybuf, sizeof(keybuf), "(Key: %s)", key);
   strlcat(buf, keybuf, size);
}
Beispiel #8
0
static void input_config_get_bind_string_joykey(char *buf, const char *prefix,
      const struct retro_keybind *bind, size_t size)
{
   settings_t *settings = config_get_ptr();

   if (GET_HAT_DIR(bind->joykey))
   {
      const char *dir = "?";

      switch (GET_HAT_DIR(bind->joykey))
      {
         case HAT_UP_MASK:
            dir = "up";
            break;
         case HAT_DOWN_MASK:
            dir = "down";
            break;
         case HAT_LEFT_MASK:
            dir = "left";
            break;
         case HAT_RIGHT_MASK:
            dir = "right";
            break;
         default:
            break;
      }

      if (!string_is_empty(bind->joykey_label) 
            && settings->input.input_descriptor_label_show)
         snprintf(buf, size, "%s %s ", prefix, bind->joykey_label);
      else
         snprintf(buf, size, "%sHat #%u %s (%s)", prefix,
               (unsigned)GET_HAT(bind->joykey), dir,
               msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE));
   }
   else
   {
      if (!string_is_empty(bind->joykey_label) 
            && settings->input.input_descriptor_label_show)
         snprintf(buf, size, "%s%s (btn) ", prefix, bind->joykey_label);
      else
         snprintf(buf, size, "%s%u (%s) ", prefix, (unsigned)bind->joykey,
               msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE));
   }
}
static void input_get_bind_string_joykey(char *buf, const char *prefix,
      const struct retro_keybind *bind, size_t size)
{
   settings_t *settings = config_get_ptr();

   if (GET_HAT_DIR(bind->joykey))
   {
      const char *dir = NULL;

      switch (GET_HAT_DIR(bind->joykey))
      {
         case HAT_UP_MASK:
            dir = "up";
            break;
         case HAT_DOWN_MASK:
            dir = "down";
            break;
         case HAT_LEFT_MASK:
            dir = "left";
            break;
         case HAT_RIGHT_MASK:
            dir = "right";
            break;
         default:
            dir = "?";
            break;
      }

      if (bind->joykey_label[0] != '\0' && settings->input.autoconfig_descriptor_label_show)
         snprintf(buf, size, "%s %s ", prefix, bind->joykey_label);
      else
         snprintf(buf, size, "%sHat #%u %s ", prefix,
               (unsigned)GET_HAT(bind->joykey), dir);
   }
   else
   {
      if (bind->joykey_label[0] != '\0' && settings->input.autoconfig_descriptor_label_show)
         snprintf(buf, size, "%s%s (btn) ", prefix, bind->joykey_label);
      else
         snprintf(buf, size, "%s%u (btn) ", prefix, (unsigned)bind->joykey);
   }
}
Beispiel #10
0
static bool sdl_joypad_button(unsigned port, uint16_t joykey)
{
   sdl_joypad_t *pad = NULL;
   if (joykey == NO_BTN)
      return false;

   pad = (sdl_joypad_t*)&sdl_pads[port];
   if (!pad->joypad)
      return false;

   /* Check hat. */
   if (GET_HAT_DIR(joykey))
   {
      uint8_t  dir;
      uint16_t hat = GET_HAT(joykey);
      if (hat >= pad->num_hats)
         return false;

      dir = sdl_pad_get_hat(pad, hat);

      switch (GET_HAT_DIR(joykey))
      {
         case HAT_UP_MASK:
            return dir & SDL_HAT_UP;
         case HAT_DOWN_MASK:
            return dir & SDL_HAT_DOWN;
         case HAT_LEFT_MASK:
            return dir & SDL_HAT_LEFT;
         case HAT_RIGHT_MASK:
            return dir & SDL_HAT_RIGHT;
         default:
            break;
      }
      return false;
   }

   /* Check the button */
   if (joykey < pad->num_buttons && sdl_pad_get_button(pad, joykey))
      return true;

   return false;
}
Beispiel #11
0
static void input_get_bind_string_joykey(char *buf, const char *prefix,
      const struct retro_keybind *bind, size_t size)
{
   if (GET_HAT_DIR(bind->joykey))
   {
      const char *dir;
      switch (GET_HAT_DIR(bind->joykey))
      {
         case HAT_UP_MASK: dir = "up"; break;
         case HAT_DOWN_MASK: dir = "down"; break;
         case HAT_LEFT_MASK: dir = "left"; break;
         case HAT_RIGHT_MASK: dir = "right"; break;
         default: dir = "?"; break;
      }
      snprintf(buf, size, "%sHat #%u %s ", prefix,
            (unsigned)GET_HAT(bind->joykey), dir);
   }
   else
      snprintf(buf, size, "%s%u (btn) ", prefix, (unsigned)bind->joykey);
}
Beispiel #12
0
static bool sdl_joypad_button(unsigned port, uint16_t joykey)
{
   if (joykey == NO_BTN)
      return false;

   const struct sdl_joypad *pad = &g_pads[port];
   if (!pad->joypad)
      return false;

   // Check hat.
   if (GET_HAT_DIR(joykey))
   {
      uint16_t hat = GET_HAT(joykey);
      if (hat >= pad->num_hats)
         return false;

      Uint8 dir = SDL_JoystickGetHat(pad->joypad, hat);
      switch (GET_HAT_DIR(joykey))
      {
         case HAT_UP_MASK:
            return dir & SDL_HAT_UP;
         case HAT_DOWN_MASK:
            return dir & SDL_HAT_DOWN;
         case HAT_LEFT_MASK:
            return dir & SDL_HAT_LEFT;
         case HAT_RIGHT_MASK:
            return dir & SDL_HAT_RIGHT;
         default:
            return false;
      }
   }
   else // Check the button
   {
      if (joykey < pad->num_buttons && SDL_JoystickGetButton(pad->joypad, joykey))
         return true;

      return false;
   }
}
Beispiel #13
0
static bool iohidmanager_hid_joypad_button(void *data,
      unsigned port, uint16_t joykey)
{
  retro_bits_t buttons;
  iohidmanager_hid_t *hid   = (iohidmanager_hid_t*)data;
  unsigned hat_dir = GET_HAT_DIR(joykey);

  iohidmanager_hid_joypad_get_buttons(data, port, &buttons);

   /* Check hat. */
   if (hat_dir)
   {
      unsigned h = GET_HAT(joykey);
      if(h >= 1)
         return false;

      switch(hat_dir)
      {
         case HAT_LEFT_MASK:
            return hid->hats[port][0] < 0;
         case HAT_RIGHT_MASK:
            return hid->hats[port][0] > 0;
         case HAT_UP_MASK:
            return hid->hats[port][1] < 0;
         case HAT_DOWN_MASK:
            return hid->hats[port][1] > 0;
      }

      return 0;
   }

   /* Check the button. */
   if ((port < MAX_USERS) && (joykey < 32))
      return (BIT256_GET(buttons, joykey) != 0)
         || ((hid->buttons[port] & (1 << joykey)) != 0);

   return false;
}