You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.6 KiB

  1. #ifndef _gamepads_h__
  2. #define _gamepads_h__
  3. #undef PAD_DATA_HAS_RAW
  4. #define PAD_TYPE_NONE 0
  5. #define PAD_TYPE_N64 4
  6. #define PAD_TYPE_GAMECUBE 5
  7. #define PAD_TYPE_GC_KB 6
  8. #define N64_RAW_SIZE 4
  9. #define GC_RAW_SIZE 8
  10. typedef struct _n64_pad_data {
  11. unsigned char pad_type; // PAD_TYPE_N64
  12. char x,y;
  13. unsigned short buttons;
  14. #ifdef PAD_DATA_HAS_RAW
  15. unsigned char raw_data[N64_RAW_SIZE];
  16. #endif
  17. } n64_pad_data;
  18. #define N64_BTN_A 0x8000
  19. #define N64_BTN_B 0x4000
  20. #define N64_BTN_Z 0x2000
  21. #define N64_BTN_START 0x1000
  22. #define N64_BTN_DPAD_UP 0x0800
  23. #define N64_BTN_DPAD_DOWN 0x0400
  24. #define N64_BTN_DPAD_LEFT 0x0200
  25. #define N64_BTN_DPAD_RIGHT 0x0100
  26. #define N64_BTN_RSVD_LOW1 0x0080
  27. #define N64_BTN_RSVD_LOW2 0x0040
  28. #define N64_BTN_L 0x0020
  29. #define N64_BTN_R 0x0010
  30. #define N64_BTN_C_UP 0x0008
  31. #define N64_BTN_C_DOWN 0x0004
  32. #define N64_BTN_C_LEFT 0x0002
  33. #define N64_BTN_C_RIGHT 0x0001
  34. typedef struct _gc_pad_data {
  35. unsigned char pad_type; // PAD_TYPE_GAMECUBE
  36. char x,y,cx,cy;
  37. unsigned char lt,rt;
  38. unsigned short buttons;
  39. #ifdef PAD_DATA_HAS_RAW
  40. unsigned char raw_data[GC_RAW_SIZE];
  41. #endif
  42. } gc_pad_data;
  43. #define GC_BTN_A 0x0001
  44. #define GC_BTN_B 0x0002
  45. #define GC_BTN_X 0x0004
  46. #define GC_BTN_Y 0x0008
  47. #define GC_BTN_START 0x0010
  48. #define GC_BTN_RSVD0 0x0020
  49. #define GC_BTN_RSVD1 0x0040
  50. #define GC_BTN_RSVD2 0x0080
  51. #define GC_BTN_DPAD_LEFT 0x0100
  52. #define GC_BTN_DPAD_RIGHT 0x0200
  53. #define GC_BTN_DPAD_DOWN 0x0400
  54. #define GC_BTN_DPAD_UP 0x0800
  55. #define GC_BTN_Z 0x1000
  56. #define GC_BTN_R 0x2000
  57. #define GC_BTN_L 0x4000
  58. #define GC_BTN_RSVD3 0x8000
  59. #define GC_ALL_BUTTONS (GC_BTN_START|GC_BTN_Y|GC_BTN_X|GC_BTN_B|GC_BTN_A|GC_BTN_L|GC_BTN_R|GC_BTN_Z|GC_BTN_DPAD_UP|GC_BTN_DPAD_DOWN|GC_BTN_DPAD_RIGHT|GC_BTN_DPAD_LEFT)
  60. typedef struct _gc_keyboard_data {
  61. unsigned char pad_type;
  62. unsigned char keys[3];
  63. } gc_keyboard_data;
  64. typedef struct _gamepad_data {
  65. union {
  66. unsigned char pad_type; // PAD_TYPE_*
  67. n64_pad_data n64;
  68. gc_pad_data gc;
  69. gc_keyboard_data gckb;
  70. };
  71. } gamepad_data;
  72. #define GAMEPAD_MAX_CHANNELS 2
  73. typedef struct {
  74. void (*init)(unsigned char chn);
  75. char (*update)(unsigned char chn);
  76. char (*changed)(unsigned char chn);
  77. void (*hotplug)(unsigned char chn);
  78. void (*getReport)(unsigned char chn, gamepad_data *dst);
  79. void (*setVibration)(unsigned char chn, char enable);
  80. char (*probe)(unsigned char chn); /* return true if found */
  81. } Gamepad;
  82. /* What was most recently read from the controller */
  83. extern gamepad_data last_built_report[GAMEPAD_MAX_CHANNELS];
  84. /* What was most recently sent to the host */
  85. extern gamepad_data last_sent_report[GAMEPAD_MAX_CHANNELS];
  86. #endif // _gamepads_h__