diff options
author | 2016-03-12 12:31:13 +0100 | |
---|---|---|
committer | 2016-03-12 12:31:13 +0100 | |
commit | a026a582f1a0ea8c1ede3acaddacef506ef3f3b0 (patch) | |
tree | e31573822f2359677de519f9f3b600d98e8764cd /src/osd/modules/input | |
parent | 477d2abd43984f076b7e45f5527591fa8fd0d241 (diff) | |
parent | dcab55bf53b94713a6f72e9633f5101c8dd6c08c (diff) |
Merge pull request #15 from mamedev/master
Sync to base master
Diffstat (limited to 'src/osd/modules/input')
-rw-r--r-- | src/osd/modules/input/input_common.cpp | 12 | ||||
-rw-r--r-- | src/osd/modules/input/input_dinput.cpp | 8 | ||||
-rw-r--r-- | src/osd/modules/input/input_rawinput.cpp | 106 | ||||
-rw-r--r-- | src/osd/modules/input/input_sdl.cpp | 19 | ||||
-rw-r--r-- | src/osd/modules/input/input_win32.cpp | 13 | ||||
-rw-r--r-- | src/osd/modules/input/input_xinput.cpp | 4 |
6 files changed, 80 insertions, 82 deletions
diff --git a/src/osd/modules/input/input_common.cpp b/src/osd/modules/input/input_common.cpp index c3d6367da5f..72a0261c99a 100644 --- a/src/osd/modules/input/input_common.cpp +++ b/src/osd/modules/input/input_common.cpp @@ -33,13 +33,16 @@ #include <windows.h> #define KEY_TRANS_ENTRY0(mame, sdlsc, sdlkey, disc, virtual, ascii, UI) { ITEM_ID_##mame, KEY_ ## disc, virtual, ascii, "ITEM_ID_"#mame, (char *) UI } #define KEY_TRANS_ENTRY1(mame, sdlsc, sdlkey, disc, virtual, ascii) { ITEM_ID_##mame, KEY_ ## disc, virtual, ascii, "ITEM_ID_"#mame, (char*) #mame } -#else +#elif defined(OSD_SDL) // SDL include #include <sdlinc.h> #define KEY_TRANS_ENTRY0(mame, sdlsc, sdlkey, disc, virtual, ascii, UI) { ITEM_ID_##mame, SDL_SCANCODE_ ## sdlsc, SDLK_ ## sdlkey, ascii, "ITEM_ID_"#mame, (char *) UI } #define KEY_TRANS_ENTRY1(mame, sdlsc, sdlkey, disc, virtual, ascii) { ITEM_ID_##mame, SDL_SCANCODE_ ## sdlsc, SDLK_ ## sdlkey, ascii, "ITEM_ID_"#mame, (char*) #mame } +#else +// osd mini #endif +#if defined(OSD_WINDOWS) || defined(OSD_SDL) key_trans_entry keyboard_trans_table::s_default_table[] = { // MAME key sdl scancode sdl key di scancode virtual key ascii ui @@ -181,7 +184,14 @@ keyboard_trans_table::keyboard_trans_table() m_table = s_default_table; m_table_size = ARRAY_LENGTH(s_default_table); } +#else +keyboard_trans_table::keyboard_trans_table() +{ + m_table = nullptr; + m_table_size = 0; +} +#endif // public constructor to allow creation of non-default instances keyboard_trans_table::keyboard_trans_table(std::unique_ptr<key_trans_entry[]> entries, unsigned int size) { diff --git a/src/osd/modules/input/input_dinput.cpp b/src/osd/modules/input/input_dinput.cpp index a80eb4c994d..a56f913854d 100644 --- a/src/osd/modules/input/input_dinput.cpp +++ b/src/osd/modules/input/input_dinput.cpp @@ -115,8 +115,6 @@ protected: class dinput_keyboard_device : public dinput_device { private: - HANDLE m_dataEvent; - HANDLE m_exitEvent; std::mutex m_device_lock; public: @@ -124,7 +122,7 @@ public: dinput_keyboard_device(running_machine &machine, const char *name, input_module &module) : dinput_device(machine, name, DEVICE_CLASS_KEYBOARD, module), - keyboard({0}) + keyboard({{0}}) { } @@ -152,8 +150,6 @@ class dinput_module : public wininput_module private: LPDIRECTINPUT m_dinput; int m_dinput_version; - int didevtype_keyboard; - int didevtype_mouse; public: dinput_module(const char* type, const char* name) @@ -493,7 +489,7 @@ public: dinput_joystick_device(running_machine &machine, const char *name, input_module &module) : dinput_device(machine, name, DEVICE_CLASS_JOYSTICK, module), - joystick({0}) + joystick({{0}}) { } diff --git a/src/osd/modules/input/input_rawinput.cpp b/src/osd/modules/input/input_rawinput.cpp index 5f930e5d780..cf17742ce58 100644 --- a/src/osd/modules/input/input_rawinput.cpp +++ b/src/osd/modules/input/input_rawinput.cpp @@ -27,6 +27,7 @@ #include "strconv.h" // MAMEOS headers +#include "winutil.h" #include "winmain.h" #include "window.h" @@ -44,10 +45,10 @@ #endif // RawInput APIs -typedef /*WINUSERAPI*/ INT(WINAPI *get_rawinput_device_list_ptr)(OUT PRAWINPUTDEVICELIST pRawInputDeviceList, IN OUT PINT puiNumDevices, IN UINT cbSize); -typedef /*WINUSERAPI*/ INT(WINAPI *get_rawinput_data_ptr)(IN HRAWINPUT hRawInput, IN UINT uiCommand, OUT LPVOID pData, IN OUT PINT pcbSize, IN UINT cbSizeHeader); -typedef /*WINUSERAPI*/ INT(WINAPI *get_rawinput_device_info_ptr)(IN HANDLE hDevice, IN UINT uiCommand, OUT LPVOID pData, IN OUT PINT pcbSize); -typedef /*WINUSERAPI*/ BOOL(WINAPI *register_rawinput_devices_ptr)(IN PCRAWINPUTDEVICE pRawInputDevices, IN UINT uiNumDevices, IN UINT cbSize); +typedef lazy_loaded_function_p3<INT, PRAWINPUTDEVICELIST, PINT, UINT> get_rawinput_device_list_ptr; +typedef lazy_loaded_function_p5<INT, HRAWINPUT, UINT, LPVOID, PINT, UINT> get_rawinput_data_ptr; +typedef lazy_loaded_function_p4<INT, HANDLE, UINT, LPVOID, PINT> get_rawinput_device_info_ptr; +typedef lazy_loaded_function_p3<BOOL, PCRAWINPUTDEVICE, UINT, UINT> register_rawinput_devices_ptr; //============================================================ // reg_query_string @@ -262,7 +263,7 @@ public: rawinput_keyboard_device(running_machine& machine, const char* name, input_module& module) : rawinput_device(machine, name, DEVICE_CLASS_KEYBOARD, module), - keyboard({0}) + keyboard({{0}}) { } @@ -289,19 +290,11 @@ public: // rawinput_mouse_device //============================================================ -struct rawinput_mouse_state -{ - int raw_x; - int raw_y; - int raw_z; -}; - class rawinput_mouse_device : public rawinput_device { private: std::mutex m_device_lock; public: - //rawinput_mouse_state raw_mouse; mouse_state mouse; rawinput_mouse_device(running_machine& machine, const char* name, input_module& module) @@ -317,18 +310,6 @@ public: mouse.lZ = 0; rawinput_device::poll(); - - //std::lock_guard<std::mutex> scope_lock(m_device_lock); - - //// copy the accumulated raw state to the actual state - //mouse.lX = raw_mouse.raw_x; - //mouse.lY = raw_mouse.raw_y; - //mouse.lZ = raw_mouse.raw_z; - //raw_mouse.raw_x = 0; - //raw_mouse.raw_y = 0; - //raw_mouse.raw_z = 0; - - //osd_printf_verbose("At poll: lX=%d, lY=%d, lZ=%d\n", (int)mouse.lX, (int)mouse.lY, (int)mouse.lZ); } void reset() override @@ -345,13 +326,6 @@ public: mouse.lX += rawinput.data.mouse.lLastX * INPUT_RELATIVE_PER_PIXEL; mouse.lY += rawinput.data.mouse.lLastY * INPUT_RELATIVE_PER_PIXEL; - /*osd_printf_verbose( - "Mouse Abs : lastX = %d, lastY = %d, rawx = %d, rawy = %d\n", - (int)rawinput.data.mouse.lLastX, - (int)rawinput.data.mouse.lLastY, - (int)raw_mouse.raw_x, - (int)raw_mouse.raw_y);*/ - // update zaxis if (rawinput.data.mouse.usButtonFlags & RI_MOUSE_WHEEL) mouse.lZ += (INT16)rawinput.data.mouse.usButtonData * INPUT_RELATIVE_PER_PIXEL; @@ -370,6 +344,13 @@ public: } }; +/* +register_rawinput_devices = (register_rawinput_devices_ptr)GetProcAddress(user32, "RegisterRawInputDevices"); +get_rawinput_device_list = (get_rawinput_device_list_ptr)GetProcAddress(user32, "GetRawInputDeviceList"); +get_rawinput_device_info = (get_rawinput_device_info_ptr)GetProcAddress(user32, "GetRawInputDeviceInfo" UNICODE_SUFFIX); +get_rawinput_data = (get_rawinput_data_ptr)GetProcAddress(user32, "GetRawInputData"); +*/ + //============================================================ // rawinput_module - base class for rawinput modules //============================================================ @@ -387,25 +368,38 @@ private: public: rawinput_module(const char *type, const char* name) : wininput_module(type, name), - get_rawinput_device_list(nullptr), - get_rawinput_data(nullptr), - get_rawinput_device_info(nullptr), - register_rawinput_devices(nullptr) + get_rawinput_device_list("GetRawInputDeviceList", L"user32.dll"), + get_rawinput_data("GetRawInputData", L"user32.dll"), + get_rawinput_device_info("GetRawInputDeviceInfo", L"user32.dll"), + register_rawinput_devices("RegisterRawInputDevices", L"user32.dll") { } + bool probe() override + { + int status = get_rawinput_device_list.initialize(); + status |= get_rawinput_data.initialize(); + status |= get_rawinput_device_info.initialize(); + status |= register_rawinput_devices.initialize(); + + if (status != 0) + return false; + + return true; + } + void input_init(running_machine &machine) override { // get the number of devices, allocate a device list, and fetch it int device_count = 0; - if ((*get_rawinput_device_list)(NULL, &device_count, sizeof(RAWINPUTDEVICELIST)) != 0) + if (get_rawinput_device_list(NULL, &device_count, sizeof(RAWINPUTDEVICELIST)) != 0) return; if (device_count == 0) return; auto rawinput_devices = std::make_unique<RAWINPUTDEVICELIST[]>(device_count); - if ((*get_rawinput_device_list)(rawinput_devices.get(), &device_count, sizeof(RAWINPUTDEVICELIST)) == -1) + if (get_rawinput_device_list(rawinput_devices.get(), &device_count, sizeof(RAWINPUTDEVICELIST)) == -1) return; // iterate backwards through devices; new devices are added at the head @@ -433,7 +427,7 @@ public: registration.hwndTarget = win_window_list->m_hwnd; // register the device - (*register_rawinput_devices)(®istration, 1, sizeof(registration)); + register_rawinput_devices(®istration, 1, sizeof(registration)); } protected: @@ -443,23 +437,15 @@ protected: int init_internal() override { - HMODULE user32; - - // look in user32 for the raw input APIs - user32 = LoadLibrary(TEXT("user32.dll")); - if (user32 == NULL) - return 1; - // look up the entry points - register_rawinput_devices = (register_rawinput_devices_ptr)GetProcAddress(user32, "RegisterRawInputDevices"); - get_rawinput_device_list = (get_rawinput_device_list_ptr)GetProcAddress(user32, "GetRawInputDeviceList"); - get_rawinput_device_info = (get_rawinput_device_info_ptr)GetProcAddress(user32, "GetRawInputDeviceInfo" UNICODE_SUFFIX); - get_rawinput_data = (get_rawinput_data_ptr)GetProcAddress(user32, "GetRawInputData"); - if (register_rawinput_devices == NULL || get_rawinput_device_list == NULL || get_rawinput_device_info == NULL || get_rawinput_data == NULL) + int status = get_rawinput_device_list.initialize(); + status |= get_rawinput_data.initialize(); + status |= get_rawinput_device_info.initialize(); + status |= register_rawinput_devices.initialize(); + if (status != 0) return 1; osd_printf_verbose("RawInput: APIs detected\n"); - return 0; } @@ -469,11 +455,11 @@ protected: TDevice* devinfo = nullptr; INT name_length = 0; // determine the length of the device name, allocate it, and fetch it if not nameless - if ((*get_rawinput_device_info)(rawinputdevice->hDevice, RIDI_DEVICENAME, NULL, &name_length) != 0) + if (get_rawinput_device_info(rawinputdevice->hDevice, RIDI_DEVICENAME, NULL, &name_length) != 0) return nullptr; std::unique_ptr<TCHAR[]> tname = std::make_unique<TCHAR[]>(name_length + 1); - if (name_length > 1 && (*get_rawinput_device_info)(rawinputdevice->hDevice, RIDI_DEVICENAME, tname.get(), &name_length) == -1) + if (name_length > 1 && get_rawinput_device_info(rawinputdevice->hDevice, RIDI_DEVICENAME, tname.get(), &name_length) == -1) return nullptr; // if this is an RDP name, skip it @@ -514,7 +500,7 @@ protected: return FALSE; // determine the size of databuffer we need - if ((*get_rawinput_data)(rawinputdevice, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER)) != 0) + if (get_rawinput_data(rawinputdevice, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER)) != 0) return FALSE; // if necessary, allocate a temporary buffer and fetch the data @@ -527,7 +513,7 @@ protected: } // fetch the data and process the appropriate message types - result = (*get_rawinput_data)((HRAWINPUT)rawinputdevice, RID_INPUT, data, &size, sizeof(RAWINPUTHEADER)); + result = get_rawinput_data((HRAWINPUT)rawinputdevice, RID_INPUT, data, &size, sizeof(RAWINPUTHEADER)); if (result) { std::lock_guard<std::mutex> scope_lock(m_module_lock); @@ -563,8 +549,8 @@ public: } protected: - USHORT usagepage() { return 1; } - USHORT usage() { return 6; } + USHORT usagepage() override { return 1; } + USHORT usage() override { return 6; } void add_rawinput_device(running_machine& machine, RAWINPUTDEVICELIST * device) override { // make sure this is a keyboard @@ -610,8 +596,8 @@ public: } protected: - USHORT usagepage() { return 1; } - USHORT usage() { return 2; } + USHORT usagepage() override { return 1; } + USHORT usage() override { return 2; } void add_rawinput_device(running_machine& machine, RAWINPUTDEVICELIST * device) override { // make sure this is a mouse diff --git a/src/osd/modules/input/input_sdl.cpp b/src/osd/modules/input/input_sdl.cpp index 3894f25e1b4..43d4cbf6a6c 100644 --- a/src/osd/modules/input/input_sdl.cpp +++ b/src/osd/modules/input/input_sdl.cpp @@ -688,11 +688,20 @@ public: int physical_stick; for (physical_stick = 0; physical_stick < SDL_NumJoysticks(); physical_stick++) { - SDL_Joystick *joy = SDL_JoystickOpen(physical_stick); - std::string joy_name = remove_spaces(SDL_JoystickName(joy)); - SDL_JoystickClose(joy); - - devmap_register(&m_joy_map, physical_stick, joy_name.c_str()); + if (SDL_IsGameController(physical_stick)) { + osd_printf_verbose("Joystick %i is supported by the game controller interface!\n", physical_stick); + osd_printf_verbose("Compatible controller, named \'%s\'\n", SDL_GameControllerNameForIndex(physical_stick)); + SDL_GameController *joy = SDL_GameControllerOpen(physical_stick); + osd_printf_verbose("Controller is mapped as \"%s\".\n", SDL_GameControllerMapping(joy)); + std::string joy_name = remove_spaces(SDL_GameControllerName(joy)); + SDL_GameControllerClose(joy); + devmap_register(&m_joy_map, physical_stick, joy_name.c_str()); + } else { + SDL_Joystick *joy = SDL_JoystickOpen(physical_stick); + std::string joy_name = remove_spaces(SDL_JoystickName(joy)); + SDL_JoystickClose(joy); + devmap_register(&m_joy_map, physical_stick, joy_name.c_str()); + } } for (int stick = 0; stick < MAX_DEVMAP_ENTRIES; stick++) diff --git a/src/osd/modules/input/input_win32.cpp b/src/osd/modules/input/input_win32.cpp index e1b69c8091c..0fb86095112 100644 --- a/src/osd/modules/input/input_win32.cpp +++ b/src/osd/modules/input/input_win32.cpp @@ -45,7 +45,7 @@ public: win32_keyboard_device(running_machine& machine, const char *name, input_module &module) : event_based_device(machine, name, DEVICE_CLASS_KEYBOARD, module), - keyboard({0}) + keyboard({{0}}) { } @@ -68,7 +68,6 @@ protected: class keyboard_input_win32 : public wininput_module { private: - const osd_options * m_options; public: keyboard_input_win32() @@ -138,7 +137,7 @@ public: win32_mouse_device(running_machine& machine, const char *name, input_module &module) : event_based_device(machine, name, DEVICE_CLASS_MOUSE, module), mouse({0}), - win32_mouse({0}) + win32_mouse({{0}}) { } @@ -172,10 +171,11 @@ public: void reset() override { memset(&mouse, 0, sizeof(mouse)); + memset(&win32_mouse, 0, sizeof(win32_mouse)); } protected: - void process_event(MouseButtonEventArgs &args) + void process_event(MouseButtonEventArgs &args) override { // set the button state mouse.rgbButtons[args.button] = args.keydown ? 0x80 : 0x00; @@ -192,9 +192,6 @@ protected: class mouse_input_win32 : public wininput_module { -private: - const osd_options * m_options; - public: mouse_input_win32() : wininput_module(OSD_MOUSEINPUT_PROVIDER, "win32") @@ -301,7 +298,7 @@ public: } protected: - void process_event(MouseButtonEventArgs &args) + void process_event(MouseButtonEventArgs &args) override { // Are we in shared axis mode? if (m_lightgun_shared_axis_mode) diff --git a/src/osd/modules/input/input_xinput.cpp b/src/osd/modules/input/input_xinput.cpp index e256b04b101..b88dbe24c1a 100644 --- a/src/osd/modules/input/input_xinput.cpp +++ b/src/osd/modules/input/input_xinput.cpp @@ -16,7 +16,7 @@ #include <windows.h> // XInput header -#include <Xinput.h> +#include <xinput.h> #undef interface @@ -187,7 +187,7 @@ private: public: xinput_joystick_device(running_machine &machine, const char *name, input_module &module) : device_info(machine, name, DEVICE_CLASS_JOYSTICK, module), - gamepad({0}), + gamepad({{0}}), xinput_state({0}), xinput_api(nullptr) { |