summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/input/input_xinput.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/osd/modules/input/input_xinput.h')
-rw-r--r--src/osd/modules/input/input_xinput.h142
1 files changed, 24 insertions, 118 deletions
diff --git a/src/osd/modules/input/input_xinput.h b/src/osd/modules/input/input_xinput.h
index 9772e941bb7..fa36b7a2622 100644
--- a/src/osd/modules/input/input_xinput.h
+++ b/src/osd/modules/input/input_xinput.h
@@ -1,111 +1,30 @@
-#ifndef INPUT_XINPUT_H_
-#define INPUT_XINPUT_H_
+// license:BSD-3-Clause
+// copyright-holders:Brad Hughes, Vas Crabb
+#ifndef MAME_OSD_INPUT_INPUT_XINPUT_H
+#define MAME_OSD_INPUT_INPUT_XINPUT_H
-#include <mutex>
+#pragma once
-#include "modules/lib/osdlib.h"
-
-#define XINPUT_MAX_POV 4
-#define XINPUT_MAX_BUTTONS 10
-#define XINPUT_MAX_AXIS 4
-
-#define XINPUT_AXIS_MINVALUE -32767
-#define XINPUT_AXIS_MAXVALUE 32767
-
-class xinput_joystick_device;
-// default axis names
-static const char *const xinput_axis_name[] =
-{
- "LSX",
- "LSY",
- "RSX",
- "RSY"
-};
-
-static const input_item_id xinput_axis_ids[] =
-{
- ITEM_ID_XAXIS,
- ITEM_ID_YAXIS,
- ITEM_ID_RXAXIS,
- ITEM_ID_RYAXIS
-};
-
-static const USHORT xinput_pov_dir[] = {
- XINPUT_GAMEPAD_DPAD_UP,
- XINPUT_GAMEPAD_DPAD_DOWN,
- XINPUT_GAMEPAD_DPAD_LEFT,
- XINPUT_GAMEPAD_DPAD_RIGHT
-};
-
-static const char *const xinput_pov_names[] = {
- "DPAD Up",
- "DPAD Down",
- "DPAD Left",
- "DPAD Right"
-};
+#include "input_common.h"
-static const USHORT xinput_buttons[] = {
- XINPUT_GAMEPAD_A,
- XINPUT_GAMEPAD_B,
- XINPUT_GAMEPAD_X,
- XINPUT_GAMEPAD_Y,
- XINPUT_GAMEPAD_LEFT_SHOULDER,
- XINPUT_GAMEPAD_RIGHT_SHOULDER,
- XINPUT_GAMEPAD_START,
- XINPUT_GAMEPAD_BACK,
- XINPUT_GAMEPAD_LEFT_THUMB,
- XINPUT_GAMEPAD_RIGHT_THUMB,
-};
+#include "modules/lib/osdlib.h"
-static const char *const xinput_button_names[] = {
- "A",
- "B",
- "X",
- "Y",
- "LB",
- "RB",
- "Start",
- "Back",
- "LS",
- "RS"
-};
+#include <memory>
-struct gamepad_state
-{
- BYTE buttons[XINPUT_MAX_BUTTONS];
- BYTE povs[XINPUT_MAX_POV];
- LONG left_trigger;
- LONG right_trigger;
- LONG left_thumb_x;
- LONG left_thumb_y;
- LONG right_thumb_x;
- LONG right_thumb_y;
-};
+#include <windows.h>
+#include <xinput.h>
-// state information for a gamepad; state must be first element
-struct xinput_api_state
-{
- uint32_t player_index;
- XINPUT_STATE xstate;
- XINPUT_CAPABILITIES caps;
-};
-// Typedefs for dynamically loaded functions
-typedef DWORD (WINAPI *xinput_get_state_fn)(DWORD, XINPUT_STATE *);
-typedef DWORD (WINAPI *xinput_get_caps_fn)(DWORD, DWORD, XINPUT_CAPABILITIES *);
+namespace osd {
-class xinput_api_helper : public std::enable_shared_from_this<xinput_api_helper>
+class xinput_api_helper
{
public:
- xinput_api_helper()
- : m_xinput_dll(nullptr),
- XInputGetState(nullptr),
- XInputGetCapabilities(nullptr)
- {
- }
+ xinput_api_helper() { }
int initialize();
- xinput_joystick_device * create_xinput_device(running_machine &machine, UINT index, wininput_module &module);
+
+ std::unique_ptr<device_info> create_xinput_device(UINT index, input_module_base &module);
DWORD xinput_get_state(DWORD dwUserindex, XINPUT_STATE *pState) const
{
@@ -118,28 +37,15 @@ public:
}
private:
- osd::dynamic_module::ptr m_xinput_dll;
- xinput_get_state_fn XInputGetState;
- xinput_get_caps_fn XInputGetCapabilities;
-};
-
-class xinput_joystick_device : public device_info
-{
-public:
- gamepad_state gamepad;
- xinput_api_state xinput_state;
-
-private:
- std::shared_ptr<xinput_api_helper> m_xinput_helper;
- std::mutex m_device_lock;
- bool m_configured;
-
-public:
- xinput_joystick_device(running_machine &machine, const char *name, const char *id, input_module &module, std::shared_ptr<xinput_api_helper> helper);
+ // Typedefs for dynamically loaded functions
+ typedef DWORD (WINAPI *xinput_get_state_fn)(DWORD, XINPUT_STATE *);
+ typedef DWORD (WINAPI *xinput_get_caps_fn)(DWORD, DWORD, XINPUT_CAPABILITIES *);
- void poll() override;
- void reset() override;
- void configure();
+ dynamic_module::ptr m_xinput_dll = nullptr;
+ xinput_get_state_fn XInputGetState = nullptr;
+ xinput_get_caps_fn XInputGetCapabilities = nullptr;
};
-#endif
+} // namespace osd
+
+#endif // MAME_OSD_INPUT_INPUT_XINPUT_H