mirror of
https://github.com/holub/mame
synced 2025-04-22 08:22:15 +03:00
Fix input issues on big endian systems (fixes #963)
This commit is contained in:
parent
d0cff39af6
commit
7babf07020
@ -551,20 +551,22 @@ protected:
|
||||
virtual void before_poll(running_machine &machine) {}
|
||||
};
|
||||
|
||||
inline static int generic_button_get_state(void *device_internal, void *item_internal)
|
||||
template <class TItem>
|
||||
int generic_button_get_state(void *device_internal, void *item_internal)
|
||||
{
|
||||
device_info *devinfo = (device_info *)device_internal;
|
||||
unsigned char *itemdata = (unsigned char*)item_internal;
|
||||
device_info *devinfo = static_cast<device_info *>(device_internal);
|
||||
TItem *itemdata = static_cast<TItem*>(item_internal);
|
||||
|
||||
// return the current state
|
||||
devinfo->module().poll_if_necessary(devinfo->machine());
|
||||
return *itemdata >> 7;
|
||||
}
|
||||
|
||||
inline static int generic_axis_get_state(void *device_internal, void *item_internal)
|
||||
template <class TItem>
|
||||
int generic_axis_get_state(void *device_internal, void *item_internal)
|
||||
{
|
||||
device_info *devinfo = (device_info *)device_internal;
|
||||
int *axisdata = (int*)item_internal;
|
||||
device_info *devinfo = static_cast<device_info *>(device_internal);
|
||||
TItem *axisdata = static_cast<TItem*>(item_internal);
|
||||
|
||||
// return the current state
|
||||
devinfo->module().poll_if_necessary(devinfo->machine());
|
||||
|
@ -329,7 +329,7 @@ public:
|
||||
name = device_item_name(devinfo, keynum, defname, nullptr);
|
||||
|
||||
// add the item to the device
|
||||
devinfo->device()->add_item(name.c_str(), itemid, generic_button_get_state, &devinfo->keyboard.state[keynum]);
|
||||
devinfo->device()->add_item(name.c_str(), itemid, generic_button_get_state<std::uint8_t>, &devinfo->keyboard.state[keynum]);
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -406,7 +406,11 @@ public:
|
||||
{
|
||||
// add to the mouse device and optionally to the gun device as well
|
||||
std::string name = device_item_name(devinfo, offsetof(DIMOUSESTATE, lX) + axisnum * sizeof(LONG), default_axis_name[axisnum], nullptr);
|
||||
devinfo->device()->add_item(name.c_str(), static_cast<input_item_id>(ITEM_ID_XAXIS + axisnum), generic_axis_get_state, &devinfo->mouse.lX + axisnum);
|
||||
devinfo->device()->add_item(
|
||||
name.c_str(),
|
||||
static_cast<input_item_id>(ITEM_ID_XAXIS + axisnum),
|
||||
generic_axis_get_state<LONG>,
|
||||
&devinfo->mouse.lX + axisnum);
|
||||
}
|
||||
|
||||
// populate the buttons
|
||||
@ -416,7 +420,11 @@ public:
|
||||
|
||||
// add to the mouse device
|
||||
std::string name = device_item_name(devinfo, offset, default_button_name(butnum), nullptr);
|
||||
devinfo->device()->add_item(name.c_str(), static_cast<input_item_id>(ITEM_ID_BUTTON1 + butnum), generic_button_get_state, &devinfo->mouse.rgbButtons[butnum]);
|
||||
devinfo->device()->add_item(
|
||||
name.c_str(),
|
||||
static_cast<input_item_id>(ITEM_ID_BUTTON1 + butnum),
|
||||
generic_button_get_state<BYTE>,
|
||||
&devinfo->mouse.rgbButtons[butnum]);
|
||||
}
|
||||
|
||||
exit:
|
||||
@ -506,7 +514,11 @@ int dinput_joystick_device::configure()
|
||||
|
||||
// populate the item description as well
|
||||
name = dinput_module::device_item_name(this, offsetof(DIJOYSTATE2, lX) + axisnum * sizeof(LONG), default_axis_name[axisnum], nullptr);
|
||||
device()->add_item(name.c_str(), static_cast<input_item_id>(ITEM_ID_XAXIS + axisnum), generic_axis_get_state, &joystick.state.lX + axisnum);
|
||||
device()->add_item(
|
||||
name.c_str(),
|
||||
static_cast<input_item_id>(ITEM_ID_XAXIS + axisnum),
|
||||
generic_axis_get_state<LONG>,
|
||||
&joystick.state.lX + axisnum);
|
||||
|
||||
axiscount++;
|
||||
}
|
||||
@ -548,7 +560,7 @@ int dinput_joystick_device::configure()
|
||||
else
|
||||
itemid = ITEM_ID_OTHER_SWITCH;
|
||||
|
||||
device()->add_item(name.c_str(), itemid, generic_button_get_state, &joystick.state.rgbButtons[butnum]);
|
||||
device()->add_item(name.c_str(), itemid, generic_button_get_state<BYTE>, &joystick.state.rgbButtons[butnum]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -617,7 +617,7 @@ protected:
|
||||
name = utf8_from_tstring(keyname);
|
||||
|
||||
// add the item to the device
|
||||
devinfo->device()->add_item(name, itemid, generic_button_get_state, &devinfo->keyboard.state[keynum]);
|
||||
devinfo->device()->add_item(name, itemid, generic_button_get_state<std::uint8_t>, &devinfo->keyboard.state[keynum]);
|
||||
osd_free(name);
|
||||
}
|
||||
}
|
||||
@ -652,13 +652,21 @@ protected:
|
||||
// populate the axes
|
||||
for (int axisnum = 0; axisnum < 3; axisnum++)
|
||||
{
|
||||
devinfo->device()->add_item(default_axis_name[axisnum], static_cast<input_item_id>(ITEM_ID_XAXIS + axisnum), generic_axis_get_state, &devinfo->mouse.lX + axisnum);
|
||||
devinfo->device()->add_item(
|
||||
default_axis_name[axisnum],
|
||||
static_cast<input_item_id>(ITEM_ID_XAXIS + axisnum),
|
||||
generic_axis_get_state<LONG>,
|
||||
&devinfo->mouse.lX + axisnum);
|
||||
}
|
||||
|
||||
// populate the buttons
|
||||
for (int butnum = 0; butnum < 5; butnum++)
|
||||
{
|
||||
devinfo->device()->add_item(default_button_name(butnum), static_cast<input_item_id>(ITEM_ID_BUTTON1 + butnum), generic_button_get_state, &devinfo->mouse.rgbButtons[butnum]);
|
||||
devinfo->device()->add_item(
|
||||
default_button_name(butnum),
|
||||
static_cast<input_item_id>(ITEM_ID_BUTTON1 + butnum),
|
||||
generic_button_get_state<BYTE>,
|
||||
&devinfo->mouse.rgbButtons[butnum]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -541,7 +541,7 @@ public:
|
||||
char defname[20];
|
||||
snprintf(defname, sizeof(defname) - 1, "%s", local_table[keynum].ui_name);
|
||||
|
||||
devinfo->device()->add_item(defname, itemid, generic_button_get_state, &devinfo->keyboard.state[local_table[keynum].sdl_scancode]);
|
||||
devinfo->device()->add_item(defname, itemid, generic_button_get_state<std::int32_t>, &devinfo->keyboard.state[local_table[keynum].sdl_scancode]);
|
||||
}
|
||||
|
||||
osd_printf_verbose("Keyboard: Registered %s\n", devinfo->name());
|
||||
@ -669,15 +669,15 @@ public:
|
||||
devinfo = devicelist()->create_device<sdl_mouse_device>(machine, "System mouse", *this);
|
||||
|
||||
// add the axes
|
||||
devinfo->device()->add_item("X", ITEM_ID_XAXIS, generic_axis_get_state, &devinfo->mouse.lX);
|
||||
devinfo->device()->add_item("Y", ITEM_ID_YAXIS, generic_axis_get_state, &devinfo->mouse.lY);
|
||||
devinfo->device()->add_item("X", ITEM_ID_XAXIS, generic_axis_get_state<std::int32_t>, &devinfo->mouse.lX);
|
||||
devinfo->device()->add_item("Y", ITEM_ID_YAXIS, generic_axis_get_state<std::int32_t>, &devinfo->mouse.lY);
|
||||
|
||||
for (button = 0; button < 4; button++)
|
||||
{
|
||||
input_item_id itemid = (input_item_id)(ITEM_ID_BUTTON1 + button);
|
||||
snprintf(defname, sizeof(defname), "B%d", button + 1);
|
||||
|
||||
devinfo->device()->add_item(defname, itemid, generic_button_get_state, &devinfo->mouse.buttons[button]);
|
||||
devinfo->device()->add_item(defname, itemid, generic_button_get_state<std::int32_t>, &devinfo->mouse.buttons[button]);
|
||||
}
|
||||
|
||||
osd_printf_verbose("Mouse: Registered %s\n", devinfo->name());
|
||||
@ -788,7 +788,7 @@ public:
|
||||
itemid = ITEM_ID_OTHER_AXIS_ABSOLUTE;
|
||||
|
||||
snprintf(tempname, sizeof(tempname), "A%d %s", axis, devinfo->name());
|
||||
devinfo->device()->add_item(tempname, itemid, generic_axis_get_state, &devinfo->joystick.axes[axis]);
|
||||
devinfo->device()->add_item(tempname, itemid, generic_axis_get_state<std::int32_t>, &devinfo->joystick.axes[axis]);
|
||||
}
|
||||
|
||||
// loop over all buttons
|
||||
@ -806,7 +806,7 @@ public:
|
||||
itemid = ITEM_ID_OTHER_SWITCH;
|
||||
|
||||
snprintf(tempname, sizeof(tempname), "button %d", button);
|
||||
devinfo->device()->add_item(tempname, itemid, generic_button_get_state, &devinfo->joystick.buttons[button]);
|
||||
devinfo->device()->add_item(tempname, itemid, generic_button_get_state<std::int32_t>, &devinfo->joystick.buttons[button]);
|
||||
}
|
||||
|
||||
// loop over all hats
|
||||
@ -816,16 +816,16 @@ public:
|
||||
|
||||
snprintf(tempname, sizeof(tempname), "hat %d Up", hat);
|
||||
itemid = (input_item_id)((hat < INPUT_MAX_HATS) ? ITEM_ID_HAT1UP + 4 * hat : ITEM_ID_OTHER_SWITCH);
|
||||
devinfo->device()->add_item(tempname, itemid, generic_button_get_state, &devinfo->joystick.hatsU[hat]);
|
||||
devinfo->device()->add_item(tempname, itemid, generic_button_get_state<std::int32_t>, &devinfo->joystick.hatsU[hat]);
|
||||
snprintf(tempname, sizeof(tempname), "hat %d Down", hat);
|
||||
itemid = (input_item_id)((hat < INPUT_MAX_HATS) ? ITEM_ID_HAT1DOWN + 4 * hat : ITEM_ID_OTHER_SWITCH);
|
||||
devinfo->device()->add_item(tempname, itemid, generic_button_get_state, &devinfo->joystick.hatsD[hat]);
|
||||
devinfo->device()->add_item(tempname, itemid, generic_button_get_state<std::int32_t>, &devinfo->joystick.hatsD[hat]);
|
||||
snprintf(tempname, sizeof(tempname), "hat %d Left", hat);
|
||||
itemid = (input_item_id)((hat < INPUT_MAX_HATS) ? ITEM_ID_HAT1LEFT + 4 * hat : ITEM_ID_OTHER_SWITCH);
|
||||
devinfo->device()->add_item(tempname, itemid, generic_button_get_state, &devinfo->joystick.hatsL[hat]);
|
||||
devinfo->device()->add_item(tempname, itemid, generic_button_get_state<std::int32_t>, &devinfo->joystick.hatsL[hat]);
|
||||
snprintf(tempname, sizeof(tempname), "hat %d Right", hat);
|
||||
itemid = (input_item_id)((hat < INPUT_MAX_HATS) ? ITEM_ID_HAT1RIGHT + 4 * hat : ITEM_ID_OTHER_SWITCH);
|
||||
devinfo->device()->add_item(tempname, itemid, generic_button_get_state, &devinfo->joystick.hatsR[hat]);
|
||||
devinfo->device()->add_item(tempname, itemid, generic_button_get_state<std::int32_t>, &devinfo->joystick.hatsR[hat]);
|
||||
}
|
||||
|
||||
// loop over all (track)balls
|
||||
@ -839,9 +839,9 @@ public:
|
||||
itemid = ITEM_ID_OTHER_AXIS_RELATIVE;
|
||||
|
||||
snprintf(tempname, sizeof(tempname), "R%d %s", ball * 2, devinfo->name());
|
||||
devinfo->device()->add_item(tempname, (input_item_id)itemid, generic_axis_get_state, &devinfo->joystick.balls[ball * 2]);
|
||||
devinfo->device()->add_item(tempname, (input_item_id)itemid, generic_axis_get_state<std::int32_t>, &devinfo->joystick.balls[ball * 2]);
|
||||
snprintf(tempname, sizeof(tempname), "R%d %s", ball * 2 + 1, devinfo->name());
|
||||
devinfo->device()->add_item(tempname, (input_item_id)(itemid + 1), generic_axis_get_state, &devinfo->joystick.balls[ball * 2 + 1]);
|
||||
devinfo->device()->add_item(tempname, (input_item_id)(itemid + 1), generic_axis_get_state<std::int32_t>, &devinfo->joystick.balls[ball * 2 + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ public:
|
||||
_snprintf(name, ARRAY_LENGTH(name), "Scan%03d", keynum);
|
||||
|
||||
// add the item to the device
|
||||
devinfo->device()->add_item(name, itemid, generic_button_get_state, &devinfo->keyboard.state[keynum]);
|
||||
devinfo->device()->add_item(name, itemid, generic_button_get_state<std::uint8_t>, &devinfo->keyboard.state[keynum]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,13 +208,21 @@ public:
|
||||
// populate the axes
|
||||
for (axisnum = 0; axisnum < 2; axisnum++)
|
||||
{
|
||||
devinfo->device()->add_item(default_axis_name[axisnum], (input_item_id)(ITEM_ID_XAXIS + axisnum), generic_axis_get_state, &devinfo->mouse.lX + axisnum);
|
||||
devinfo->device()->add_item(
|
||||
default_axis_name[axisnum],
|
||||
static_cast<input_item_id>(ITEM_ID_XAXIS + axisnum),
|
||||
generic_axis_get_state<LONG>,
|
||||
&devinfo->mouse.lX + axisnum);
|
||||
}
|
||||
|
||||
// populate the buttons
|
||||
for (butnum = 0; butnum < 2; butnum++)
|
||||
{
|
||||
devinfo->device()->add_item(default_button_name(butnum), (input_item_id)(ITEM_ID_BUTTON1 + butnum), generic_button_get_state, &devinfo->mouse.rgbButtons[butnum]);
|
||||
devinfo->device()->add_item(
|
||||
default_button_name(butnum),
|
||||
static_cast<input_item_id>(ITEM_ID_BUTTON1 + butnum),
|
||||
generic_button_get_state<BYTE>,
|
||||
&devinfo->mouse.rgbButtons[butnum]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -383,13 +391,21 @@ public:
|
||||
// populate the axes
|
||||
for (axisnum = 0; axisnum < 2; axisnum++)
|
||||
{
|
||||
devinfo->device()->add_item(default_axis_name[axisnum], (input_item_id)(ITEM_ID_XAXIS + axisnum), generic_axis_get_state, &devinfo->mouse.lX + axisnum);
|
||||
devinfo->device()->add_item(
|
||||
default_axis_name[axisnum],
|
||||
static_cast<input_item_id>(ITEM_ID_XAXIS + axisnum),
|
||||
generic_axis_get_state<LONG>,
|
||||
&devinfo->mouse.lX + axisnum);
|
||||
}
|
||||
|
||||
// populate the buttons
|
||||
for (butnum = 0; butnum < 2; butnum++)
|
||||
{
|
||||
devinfo->device()->add_item(default_button_name(butnum), (input_item_id)(ITEM_ID_BUTTON1 + butnum), generic_button_get_state, &devinfo->mouse.rgbButtons[butnum]);
|
||||
devinfo->device()->add_item(
|
||||
default_button_name(butnum),
|
||||
static_cast<input_item_id>(ITEM_ID_BUTTON1 + butnum),
|
||||
generic_button_get_state<BYTE>,
|
||||
&devinfo->mouse.rgbButtons[butnum]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,10 +82,4 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
//============================================================
|
||||
// INLINE FUNCTIONS
|
||||
//============================================================
|
||||
|
||||
INT32 generic_button_get_state(void *device_internal, void *item_internal);
|
||||
INT32 generic_axis_get_state(void *device_internal, void *item_internal);
|
||||
#endif
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
// standard sdl header
|
||||
#include "sdlinc.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <ctype.h>
|
||||
#include <stddef.h>
|
||||
#include <mutex>
|
||||
@ -471,10 +471,10 @@ public:
|
||||
|
||||
// Add X and Y axis
|
||||
sprintf(defname, "X %s", devinfo->name());
|
||||
devinfo->device()->add_item(defname, ITEM_ID_XAXIS, generic_axis_get_state, &devinfo->lightgun.lX);
|
||||
devinfo->device()->add_item(defname, ITEM_ID_XAXIS, generic_axis_get_state<std::int32_t>, &devinfo->lightgun.lX);
|
||||
|
||||
sprintf(defname, "Y %s", devinfo->name());
|
||||
devinfo->device()->add_item(defname, ITEM_ID_YAXIS, generic_axis_get_state, &devinfo->lightgun.lY);
|
||||
devinfo->device()->add_item(defname, ITEM_ID_YAXIS, generic_axis_get_state<std::int32_t>, &devinfo->lightgun.lY);
|
||||
|
||||
// Save the device id
|
||||
devinfo->x11_state.deviceid = info->id;
|
||||
@ -489,7 +489,7 @@ public:
|
||||
x11_event_manager::instance().subscribe(event_types, ARRAY_LENGTH(event_types), this);
|
||||
}
|
||||
|
||||
osd_printf_verbose("Lightgun: End initialization\n");
|
||||
osd_printf_verbose("Lightgun: End initialization\n");
|
||||
}
|
||||
|
||||
bool should_poll_devices(running_machine &machine) override
|
||||
@ -554,7 +554,7 @@ private:
|
||||
for (int button = 0; button < b->num_buttons; button++)
|
||||
{
|
||||
input_item_id itemid = (input_item_id)(ITEM_ID_BUTTON1 + button);
|
||||
devinfo->device()->add_item(default_button_name(button), itemid, generic_button_get_state, &devinfo->lightgun.buttons[button]);
|
||||
devinfo->device()->add_item(default_button_name(button), itemid, generic_button_get_state<std::int32_t>, &devinfo->lightgun.buttons[button]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ void xinput_joystick_device::configure()
|
||||
device()->add_item(
|
||||
xinput_axis_name[axisnum],
|
||||
xinput_axis_ids[axisnum],
|
||||
generic_axis_get_state,
|
||||
generic_axis_get_state<LONG>,
|
||||
&gamepad.left_thumb_x + axisnum);
|
||||
}
|
||||
|
||||
@ -166,7 +166,7 @@ void xinput_joystick_device::configure()
|
||||
device()->add_item(
|
||||
xinput_pov_names[povnum],
|
||||
ITEM_ID_OTHER_SWITCH,
|
||||
generic_button_get_state,
|
||||
generic_button_get_state<BYTE>,
|
||||
&gamepad.povs[povnum]);
|
||||
}
|
||||
|
||||
@ -176,20 +176,20 @@ void xinput_joystick_device::configure()
|
||||
device()->add_item(
|
||||
xinput_button_names[butnum],
|
||||
static_cast<input_item_id>(ITEM_ID_BUTTON1 + butnum),
|
||||
generic_button_get_state,
|
||||
generic_button_get_state<BYTE>,
|
||||
&gamepad.buttons[butnum]);
|
||||
}
|
||||
|
||||
device()->add_item(
|
||||
"Left Trigger",
|
||||
ITEM_ID_ZAXIS,
|
||||
generic_axis_get_state,
|
||||
generic_axis_get_state<LONG>,
|
||||
&gamepad.left_trigger);
|
||||
|
||||
device()->add_item(
|
||||
"Right Trigger",
|
||||
ITEM_ID_RZAXIS,
|
||||
generic_axis_get_state,
|
||||
generic_axis_get_state<LONG>,
|
||||
&gamepad.right_trigger);
|
||||
|
||||
m_configured = true;
|
||||
|
Loading…
Reference in New Issue
Block a user