mirror of
https://github.com/holub/mame
synced 2025-04-24 01:11:11 +03:00
Merge pull request #1405 from tverona1/master
Adding support for stable controller id's
This commit is contained in:
commit
31a9c62d1f
76
docs/source/advanced/devicemap.rst
Normal file
76
docs/source/advanced/devicemap.rst
Normal file
@ -0,0 +1,76 @@
|
||||
Stable Controller IDs
|
||||
===============================
|
||||
|
||||
By default, the mapping between devices and controller IDs is not stable. For instance, a gamepad controller may be assigned to "Joy 1" initially, but after a reboot, it may get re-assigned to "Joy 3".
|
||||
|
||||
The reason is that MAME enumerates attached devices and assigns controller IDs based on the enumeration order. Factors that can cause controller IDs to change include plugging / unplugging USB devices, changing ports / hubs and even system reboots.
|
||||
|
||||
It is quite cumbersome to ensure that controller IDs are always correct.
|
||||
|
||||
That's where the "mapdevice" configuration setting comes into the picture. This setting allows you to map a device id to a controller ID, ensuring that the specified device always maps to the same controller ID in MAME.
|
||||
|
||||
Usage of mapdevice
|
||||
------------------
|
||||
The "mapdevice" xml element is specified under the input xml element in the controller configuration file. It requires two attributes, "device" and "controller".
|
||||
NOTE: This setting only take effect when added to the **ctrlr** config file.
|
||||
|
||||
The "device" attribute specifies the id of the device to match. It may also be a substring of the id. To see the list of available devices, enable verbose output and available devices will then be listed to the console at startup (more on this below).
|
||||
|
||||
The "controller" attribute specifies the MAME controller ID. It is made up of a controller class (i.e. "JOYCODE", "GUNCODE", "MOUSECODE") and controller index. For example: "JOYCODE_1".
|
||||
|
||||
Example
|
||||
-------
|
||||
Here's an example:
|
||||
|
||||
| <mameconfig version="10">
|
||||
| <system name="default">
|
||||
| <input>
|
||||
| **<mapdevice device="VID_D209&PID_1601" controller="GUNCODE_1" />**
|
||||
| **<mapdevice device="VID_D209&PID_1602" controller="GUNCODE_2" />**
|
||||
| **<mapdevice device="XInput Player 1" controller="JOYCODE_1" />**
|
||||
| **<mapdevice device="XInput Player 2" controller="JOYCODE_2" />**
|
||||
|
|
||||
| <port type="P1_JOYSTICK_UP">
|
||||
| <newseq type="standard">
|
||||
| JOYCODE_1_YAXIS_UP_SWITCH OR KEYCODE_8PAD
|
||||
| </newseq>
|
||||
| </port>
|
||||
| ...
|
||||
|
|
||||
|
||||
In the above example, we have four device mappings specified:
|
||||
|
||||
The first two mapdevice entries map player 1 and 2 lightguns to Gun 1 and Gun 2, respectively. We use a substring of the full raw device names to match each devices. Note that, since this is XML, we needed to escape the '&' using '&'.
|
||||
|
||||
The last two mapdevices entries map player 1 and player 2 gamepad controllers to Joy 1 and Joy 2, respectively. In this case, these are XInput devices.
|
||||
|
||||
Listing Available Devices
|
||||
-------------------------
|
||||
How did we obtain the device id's in the above example? Easy!
|
||||
|
||||
Run MAME with -v parameter to enable verbose output. It will then list available devices include the corresponding "device id" to the console.
|
||||
|
||||
Here an example:
|
||||
|
||||
| Input: Adding Gun #0:
|
||||
| Input: Adding Gun #1:
|
||||
| Input: Adding Gun #2: HID-compliant mouse (**device id: \\?\HID#VID_045E&PID_0053#7&18297dcb&0&0000#{378de44c-56ef-11d1-bc8c-00a0c91405dd}**)
|
||||
| Input: Adding Gun #3: HID-compliant mouse (**device id: \\?\HID#IrDeviceV2&Col08#2&2818a073&0&0007#{378de44c-56ef-11d1-bc8c-00a0c91405dd}**)
|
||||
| Input: Adding Gun #4: HID-compliant mouse (**device id: \\?\HID#VID_D209&PID_1602&MI_02#8&389ab7f3&0&0000#{378de44c-56ef-11d1-bc8c-00a0c91405dd}**)
|
||||
| Input: Adding Gun #5: HID-compliant mouse (**device id: \\?\HID#VID_D209&PID_1601&MI_02#9&375eebb1&0&0000#{378de44c-56ef-11d1-bc8c-00a0c91405dd}**)
|
||||
| Input: Adding Gun #6: HID-compliant mouse (**device id: \\?\HID#VID_1241&PID_1111#8&198f3adc&0&0000#{378de44c-56ef-11d1-bc8c-00a0c91405dd}**)
|
||||
| Skipping DirectInput for XInput compatible joystick Controller (XBOX 360 For Windows).
|
||||
| Input: Adding Joy #0: ATRAK Device #1 (**device id: ATRAK Device #1**)
|
||||
| Skipping DirectInput for XInput compatible joystick Controller (XBOX 360 For Windows).
|
||||
| Input: Adding Joy #1: ATRAK Device #2 (**device id: ATRAK Device #2**)
|
||||
| Input: Adding Joy #2: XInput Player 1 (**device id: XInput Player 1**)
|
||||
| Input: Adding Joy #3: XInput Player 2 (**device id: XInput Player 2**)
|
||||
|
|
||||
|
||||
Furthermore, when devices are mapped using mapdevice, you'll see that in the verbose logging too, such as:
|
||||
|
||||
| Input: Remapped Gun #0: HID-compliant mouse (device id: \\?\HID#VID_D209&PID_1601&MI_02#9&375eebb1&0&0000#{378de44c-56ef-11d1-bc8c-00a0c91405dd})
|
||||
| Input: Remapped Gun #1: HID-compliant mouse (device id: \\?\HID#VID_D209&PID_1602&MI_02#8&389ab7f3&0&0000#{378de44c-56ef-11d1-bc8c-00a0c91405dd})
|
||||
| Input: Remapped Joy #0: XInput Player 1 (device id: XInput Player 1)
|
||||
| Input: Remapped Joy #1: XInput Player 2 (device id: XInput Player 2)
|
||||
|
|
@ -9,4 +9,5 @@ Advanced configuration
|
||||
shiftertoggle
|
||||
bgfx
|
||||
hlsl
|
||||
glsl
|
||||
glsl
|
||||
devicemap
|
@ -794,9 +794,10 @@ void input_seq::replace(input_code oldcode, input_code newcode)
|
||||
// input_device - constructor
|
||||
//-------------------------------------------------
|
||||
|
||||
input_device::input_device(input_class &_class, int devindex, const char *name, void *internal)
|
||||
input_device::input_device(input_class &_class, int devindex, const char *name, const char *id, void *internal)
|
||||
: m_class(_class),
|
||||
m_name(name),
|
||||
m_id(id),
|
||||
m_devindex(devindex),
|
||||
m_maxitem(input_item_id(0)),
|
||||
m_internal(internal),
|
||||
@ -941,6 +942,21 @@ void input_device::apply_steadykey() const
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------
|
||||
// match_device_id - match device id via
|
||||
// substring search
|
||||
//-------------------------------------------------
|
||||
|
||||
bool input_device::match_device_id(const char *deviceid)
|
||||
{
|
||||
std::string deviceidupper(deviceid);
|
||||
std::string idupper(m_id);
|
||||
|
||||
strmakeupper(deviceidupper);
|
||||
strmakeupper(idupper);
|
||||
|
||||
return std::string::npos == idupper.find(deviceidupper) ? false : true;
|
||||
}
|
||||
|
||||
|
||||
//**************************************************************************
|
||||
@ -968,7 +984,7 @@ input_class::input_class(input_manager &manager, input_device_class devclass, bo
|
||||
// add_device - add a new input device
|
||||
//-------------------------------------------------
|
||||
|
||||
input_device *input_class::add_device(const char *name, void *internal)
|
||||
input_device *input_class::add_device(const char *name, const char *id, void *internal)
|
||||
{
|
||||
// find the next empty index
|
||||
int devindex;
|
||||
@ -977,23 +993,28 @@ input_device *input_class::add_device(const char *name, void *internal)
|
||||
break;
|
||||
|
||||
// call through
|
||||
return add_device(devindex, name, internal);
|
||||
return add_device(devindex, name, id, internal);
|
||||
}
|
||||
|
||||
input_device *input_class::add_device(int devindex, const char *name, void *internal)
|
||||
input_device *input_class::add_device(int devindex, const char *name, const char *id, void *internal)
|
||||
{
|
||||
assert_always(machine().phase() == MACHINE_PHASE_INIT, "Can only call input_class::add_device at init time!");
|
||||
assert(name != nullptr);
|
||||
assert(id != nullptr);
|
||||
assert(devindex >= 0 && devindex < DEVICE_INDEX_MAXIMUM);
|
||||
assert(m_device[devindex] == nullptr);
|
||||
|
||||
// allocate a new device
|
||||
m_device[devindex] = std::make_unique<input_device>(*this, devindex, name, internal);
|
||||
m_device[devindex] = std::make_unique<input_device>(*this, devindex, name, id, internal);
|
||||
|
||||
// update the maximum index found
|
||||
m_maxindex = std::max(m_maxindex, devindex);
|
||||
|
||||
osd_printf_verbose("Input: Adding %s #%d: %s\n", (*devclass_string_table)[m_devclass], devindex, name);
|
||||
if (0 == strlen(id))
|
||||
osd_printf_verbose("Input: Adding %s #%d: %s\n", (*devclass_string_table)[m_devclass], devindex, name);
|
||||
else
|
||||
osd_printf_verbose("Input: Adding %s #%d: %s (device id: %s)\n", (*devclass_string_table)[m_devclass], devindex, name, id);
|
||||
|
||||
return m_device[devindex].get();
|
||||
}
|
||||
|
||||
@ -1019,6 +1040,32 @@ input_item_class input_class::standard_item_class(input_item_id itemid)
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// remap_device_index - remaps device index by
|
||||
// mapping oldindex to newindex
|
||||
//-------------------------------------------------
|
||||
|
||||
void input_class::remap_device_index(int oldindex, int newindex)
|
||||
{
|
||||
assert(oldindex >= 0 && oldindex < DEVICE_INDEX_MAXIMUM);
|
||||
assert(newindex >= 0 && newindex < DEVICE_INDEX_MAXIMUM);
|
||||
|
||||
// swap indexes in m_device array
|
||||
m_device[oldindex].swap(m_device[newindex]);
|
||||
|
||||
// update device indexes
|
||||
if (nullptr != m_device[oldindex].get())
|
||||
m_device[oldindex]->set_devindex(oldindex);
|
||||
|
||||
if (nullptr != m_device[newindex].get())
|
||||
m_device[newindex]->set_devindex(newindex);
|
||||
|
||||
// update the maximum index found, since newindex may
|
||||
// exceed current m_maxindex
|
||||
m_maxindex = std::max(m_maxindex, newindex);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// frame_callback - per-frame callback for various
|
||||
// bookkeeping
|
||||
@ -2058,6 +2105,72 @@ void input_manager::seq_from_tokens(input_seq &seq, const char *string)
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------
|
||||
// map_device_to_controller - map device to
|
||||
// controller based on device map table
|
||||
//-------------------------------------------------
|
||||
|
||||
bool input_manager::map_device_to_controller(const devicemap_table_type *devicemap_table)
|
||||
{
|
||||
if (nullptr == devicemap_table)
|
||||
return true;
|
||||
|
||||
for (devicemap_table_type::const_iterator it = devicemap_table->begin(); it != devicemap_table->end(); it++)
|
||||
{
|
||||
const char *deviceid = it->first.c_str();
|
||||
const char *controllername = it->second.c_str();
|
||||
|
||||
// tokenize the controller name into device class and index (i.e. controller name should be of the form "GUNCODE_1")
|
||||
std::string token[2];
|
||||
int numtokens;
|
||||
const char *_token = controllername;
|
||||
for (numtokens = 0; numtokens < ARRAY_LENGTH(token); )
|
||||
{
|
||||
// make a token up to the next underscore
|
||||
char *score = (char *)strchr(_token, '_');
|
||||
token[numtokens++].assign(_token, (score == nullptr) ? strlen(_token) : (score - _token));
|
||||
|
||||
// if we hit the end, we're done, else advance our pointer
|
||||
if (score == nullptr)
|
||||
break;
|
||||
_token = score + 1;
|
||||
}
|
||||
if (2 != numtokens)
|
||||
return false;
|
||||
|
||||
// first token should be the devclass
|
||||
input_device_class devclass = input_device_class((*devclass_token_table)[strmakeupper(token[0]).c_str()]);
|
||||
if (devclass == ~input_device_class(0))
|
||||
return false;
|
||||
|
||||
// second token should be the devindex
|
||||
int devindex = 0;
|
||||
if (1 != sscanf(token[1].c_str(), "%d", &devindex))
|
||||
return false;
|
||||
devindex--;
|
||||
|
||||
if (devindex >= DEVICE_INDEX_MAXIMUM)
|
||||
return false;
|
||||
|
||||
// enumerate through devices and look for a match
|
||||
input_class *input_devclass = m_class[devclass];
|
||||
for (int devnum = 0; devnum <= input_devclass->maxindex(); devnum++)
|
||||
{
|
||||
input_device *device = input_devclass->device(devnum);
|
||||
if (device != nullptr && device->match_device_id(deviceid))
|
||||
{
|
||||
// remap devindex
|
||||
input_devclass->remap_device_index(device->devindex(), devindex);
|
||||
osd_printf_verbose("Input: Remapped %s #%d: %s (device id: %s)\n", (*devclass_string_table)[input_devclass->devclass()], devindex, device->name(), device->id());
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// set_global_joystick_map - set the joystick map
|
||||
|
@ -352,6 +352,8 @@ class input_manager;
|
||||
// callback for getting the value of an item on a device
|
||||
typedef INT32 (*item_get_state_func)(void *device_internal, void *item_internal);
|
||||
|
||||
// controller alias table typedef
|
||||
typedef std::map<std::string, std::string> devicemap_table_type;
|
||||
|
||||
// ======================> joystick_map
|
||||
|
||||
@ -547,13 +549,14 @@ class input_device
|
||||
|
||||
public:
|
||||
// construction/destruction
|
||||
input_device(input_class &_class, int _devindex, const char *_name, void *_internal);
|
||||
input_device(input_class &_class, int _devindex, const char *_name, const char *_id, void *_internal);
|
||||
// getters
|
||||
input_class &device_class() const { return m_class; }
|
||||
input_manager &manager() const;
|
||||
running_machine &machine() const;
|
||||
input_device_class devclass() const;
|
||||
const char *name() const { return m_name.c_str(); }
|
||||
const char *id() const { return m_id.c_str(); }
|
||||
int devindex() const { return m_devindex; }
|
||||
input_device_item *item(input_item_id index) const { return m_item[index].get(); }
|
||||
input_item_id maxitem() const { return m_maxitem; }
|
||||
@ -562,6 +565,9 @@ public:
|
||||
bool steadykey_enabled() const { return m_steadykey_enabled; }
|
||||
bool lightgun_reload_button() const { return m_lightgun_reload_button; }
|
||||
|
||||
// setters
|
||||
void set_devindex(int devindex) { m_devindex = devindex; }
|
||||
|
||||
// item management
|
||||
input_item_id add_item(const char *name, input_item_id itemid, item_get_state_func getstate, void *internal = nullptr);
|
||||
void set_joystick_map(const joystick_map &map) { m_joymap = map; }
|
||||
@ -569,11 +575,13 @@ public:
|
||||
// helpers
|
||||
INT32 apply_deadzone_and_saturation(INT32 value) const;
|
||||
void apply_steadykey() const;
|
||||
bool match_device_id(const char * deviceid);
|
||||
|
||||
private:
|
||||
// internal state
|
||||
input_class & m_class; // reference to our class
|
||||
std::string m_name; // string name of device
|
||||
std::string m_id; // id of device
|
||||
int m_devindex; // device index of this device
|
||||
std::unique_ptr<input_device_item> m_item[ITEM_ID_ABSOLUTE_MAXIMUM+1]; // array of pointers to items
|
||||
input_item_id m_maxitem; // maximum item index
|
||||
@ -611,11 +619,12 @@ public:
|
||||
void set_multi(bool multi = true) { m_multi = multi; }
|
||||
|
||||
// device management
|
||||
input_device *add_device(const char *name, void *internal = nullptr);
|
||||
input_device *add_device(int devindex, const char *name, void *internal = nullptr);
|
||||
input_device *add_device(const char *name, const char *id, void *internal = nullptr);
|
||||
input_device *add_device(int devindex, const char *name, const char *id, void *internal = nullptr);
|
||||
|
||||
// misc helpers
|
||||
input_item_class standard_item_class(input_item_id itemid);
|
||||
void remap_device_index(int oldindex, int newindex);
|
||||
|
||||
private:
|
||||
// internal helpers
|
||||
@ -679,6 +688,7 @@ public:
|
||||
|
||||
// misc
|
||||
bool set_global_joystick_map(const char *mapstring);
|
||||
bool map_device_to_controller(const devicemap_table_type *devicemap_table = nullptr);
|
||||
|
||||
private:
|
||||
// internal helpers
|
||||
|
@ -2904,6 +2904,27 @@ void ioport_manager::load_config(config_type cfg_type, xml_data_node *parentnode
|
||||
if (cfg_type == config_type::CONFIG_TYPE_CONTROLLER)
|
||||
load_remap_table(parentnode);
|
||||
|
||||
// load device map table for controller configs only
|
||||
if (cfg_type == config_type::CONFIG_TYPE_CONTROLLER)
|
||||
{
|
||||
std::unique_ptr<devicemap_table_type> devicemap_table = std::make_unique<devicemap_table_type>();
|
||||
for (xml_data_node *mapdevice_node = xml_get_sibling(parentnode->child, "mapdevice"); mapdevice_node != nullptr; mapdevice_node = xml_get_sibling(mapdevice_node->next, "mapdevice"))
|
||||
{
|
||||
const char *devicename = xml_get_attribute_string(mapdevice_node, "device", nullptr);
|
||||
const char *controllername = xml_get_attribute_string(mapdevice_node, "controller", nullptr);
|
||||
if (devicename != nullptr && controllername != nullptr)
|
||||
{
|
||||
devicemap_table->insert(std::make_pair(std::string(devicename), std::string(controllername)));
|
||||
}
|
||||
}
|
||||
|
||||
// map device to controller if we have a device map
|
||||
if (!devicemap_table->empty())
|
||||
{
|
||||
machine().input().map_device_to_controller(devicemap_table.get());
|
||||
}
|
||||
}
|
||||
|
||||
// iterate over all the port nodes
|
||||
for (xml_data_node *portnode = xml_get_sibling(parentnode->child, "port"); portnode; portnode = xml_get_sibling(portnode->next, "port"))
|
||||
{
|
||||
|
@ -202,6 +202,7 @@ class device_info
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
std::string m_id;
|
||||
input_device * m_device;
|
||||
running_machine & m_machine;
|
||||
input_module & m_module;
|
||||
@ -209,8 +210,9 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
device_info(running_machine &machine, const char *name, input_device_class deviceclass, input_module &module)
|
||||
device_info(running_machine &machine, const char *name, const char *id, input_device_class deviceclass, input_module &module)
|
||||
: m_name(name),
|
||||
m_id(id),
|
||||
m_device(nullptr),
|
||||
m_machine(machine),
|
||||
m_module(module),
|
||||
@ -224,6 +226,7 @@ public:
|
||||
// Getters
|
||||
running_machine & machine() const { return m_machine; }
|
||||
const char * name() const { return m_name.c_str(); }
|
||||
const char * id() const { return m_id.c_str(); }
|
||||
input_device * device() const { return m_device; }
|
||||
input_module & module() const { return m_module; }
|
||||
input_device_class deviceclass() const { return m_deviceclass; }
|
||||
@ -251,8 +254,8 @@ protected:
|
||||
virtual void process_event(TEvent &ev) = 0;
|
||||
|
||||
public:
|
||||
event_based_device(running_machine &machine, const char *name, input_device_class deviceclass, input_module &module)
|
||||
: device_info(machine, name, deviceclass, module)
|
||||
event_based_device(running_machine &machine, const char *name, const char *id, input_device_class deviceclass, input_module &module)
|
||||
: device_info(machine, name, id, deviceclass, module)
|
||||
{
|
||||
}
|
||||
|
||||
@ -327,13 +330,13 @@ public:
|
||||
}
|
||||
|
||||
template <typename TActual, typename... TArgs>
|
||||
TActual* create_device(running_machine &machine, const char *name, input_module &module, TArgs&&... args)
|
||||
TActual* create_device(running_machine &machine, const char *name, const char *id, input_module &module, TArgs&&... args)
|
||||
{
|
||||
// allocate the device object
|
||||
auto devinfo = std::make_unique<TActual>(machine, name, module, std::forward<TArgs>(args)...);
|
||||
auto devinfo = std::make_unique<TActual>(machine, name, id, module, std::forward<TArgs>(args)...);
|
||||
|
||||
// Add the device to the machine
|
||||
devinfo->m_device = machine.input().device_class(devinfo->deviceclass()).add_device(devinfo->name(), devinfo.get());
|
||||
devinfo->m_device = machine.input().device_class(devinfo->deviceclass()).add_device(devinfo->name(), devinfo->id(), devinfo.get());
|
||||
|
||||
// append us to the list
|
||||
m_list.push_back(std::move(devinfo));
|
||||
|
@ -68,8 +68,8 @@ static HRESULT dinput_set_dword_property(ComPtr<IDirectInputDevice> device, REFG
|
||||
// dinput_device - base directinput device
|
||||
//============================================================
|
||||
|
||||
dinput_device::dinput_device(running_machine &machine, const char *name, input_device_class deviceclass, input_module &module)
|
||||
: device_info(machine, name, deviceclass, module),
|
||||
dinput_device::dinput_device(running_machine &machine, const char *name, const char *id, input_device_class deviceclass, input_module &module)
|
||||
: device_info(machine, name, id, deviceclass, module),
|
||||
dinput({nullptr})
|
||||
{
|
||||
}
|
||||
@ -110,8 +110,8 @@ HRESULT dinput_device::poll_dinput(LPVOID pState) const
|
||||
// dinput_keyboard_device - directinput keyboard device
|
||||
//============================================================
|
||||
|
||||
dinput_keyboard_device::dinput_keyboard_device(running_machine &machine, const char *name, input_module &module)
|
||||
: dinput_device(machine, name, DEVICE_CLASS_KEYBOARD, module),
|
||||
dinput_keyboard_device::dinput_keyboard_device(running_machine &machine, const char *name, const char *id, input_module &module)
|
||||
: dinput_device(machine, name, id, DEVICE_CLASS_KEYBOARD, module),
|
||||
keyboard({{0}})
|
||||
{
|
||||
}
|
||||
@ -328,8 +328,8 @@ public:
|
||||
};
|
||||
|
||||
|
||||
dinput_mouse_device::dinput_mouse_device(running_machine &machine, const char *name, input_module &module)
|
||||
: dinput_device(machine, name, DEVICE_CLASS_MOUSE, module),
|
||||
dinput_mouse_device::dinput_mouse_device(running_machine &machine, const char *name, const char *id, input_module &module)
|
||||
: dinput_device(machine, name, id, DEVICE_CLASS_MOUSE, module),
|
||||
mouse({0})
|
||||
{
|
||||
}
|
||||
@ -427,8 +427,8 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
dinput_joystick_device::dinput_joystick_device(running_machine &machine, const char *name, input_module &module)
|
||||
: dinput_device(machine, name, DEVICE_CLASS_JOYSTICK, module),
|
||||
dinput_joystick_device::dinput_joystick_device(running_machine &machine, const char *name, const char *id, input_module &module)
|
||||
: dinput_device(machine, name, id, DEVICE_CLASS_JOYSTICK, module),
|
||||
joystick({{0}})
|
||||
{
|
||||
}
|
||||
|
@ -81,8 +81,11 @@ public:
|
||||
// convert instance name to utf8
|
||||
std::string utf8_instance_name = utf8_from_tstring(instance->tszInstanceName);
|
||||
|
||||
// set device id to name
|
||||
std::string utf8_instance_id = utf8_instance_name;
|
||||
|
||||
// allocate memory for the device object
|
||||
TDevice* devinfo = module.devicelist()->create_device<TDevice>(machine, utf8_instance_name.c_str(), module);
|
||||
TDevice* devinfo = module.devicelist()->create_device<TDevice>(machine, utf8_instance_name.c_str(), utf8_instance_id.c_str(), module);
|
||||
|
||||
// attempt to create a device
|
||||
result = m_dinput->CreateDevice(instance->guidInstance, devinfo->dinput.device.GetAddressOf(), nullptr);
|
||||
@ -137,7 +140,7 @@ class dinput_device : public device_info
|
||||
public:
|
||||
dinput_api_state dinput;
|
||||
|
||||
dinput_device(running_machine &machine, const char *name, input_device_class deviceclass, input_module &module);
|
||||
dinput_device(running_machine &machine, const char *name, const char *id, input_device_class deviceclass, input_module &module);
|
||||
virtual ~dinput_device();
|
||||
|
||||
protected:
|
||||
@ -152,7 +155,7 @@ private:
|
||||
public:
|
||||
keyboard_state keyboard;
|
||||
|
||||
dinput_keyboard_device(running_machine &machine, const char *name, input_module &module);
|
||||
dinput_keyboard_device(running_machine &machine, const char *name, const char *id, input_module &module);
|
||||
|
||||
void poll() override;
|
||||
void reset() override;
|
||||
@ -164,7 +167,7 @@ public:
|
||||
mouse_state mouse;
|
||||
|
||||
public:
|
||||
dinput_mouse_device(running_machine &machine, const char *name, input_module &module);
|
||||
dinput_mouse_device(running_machine &machine, const char *name, const char *id, input_module &module);
|
||||
void poll() override;
|
||||
void reset() override;
|
||||
};
|
||||
@ -182,7 +185,7 @@ class dinput_joystick_device : public dinput_device
|
||||
public:
|
||||
dinput_joystick_state joystick;
|
||||
public:
|
||||
dinput_joystick_device(running_machine &machine, const char *name, input_module &module);
|
||||
dinput_joystick_device(running_machine &machine, const char *name, const char *id, input_module &module);
|
||||
void reset() override;
|
||||
void poll() override;
|
||||
int configure();
|
||||
|
@ -289,8 +289,8 @@ private:
|
||||
HANDLE m_handle;
|
||||
|
||||
public:
|
||||
rawinput_device(running_machine& machine, const char* name, input_device_class deviceclass, input_module& module)
|
||||
: event_based_device(machine, name, deviceclass, module),
|
||||
rawinput_device(running_machine& machine, const char *name, const char *id, input_device_class deviceclass, input_module& module)
|
||||
: event_based_device(machine, name, id, deviceclass, module),
|
||||
m_handle(nullptr)
|
||||
{
|
||||
}
|
||||
@ -308,8 +308,8 @@ class rawinput_keyboard_device : public rawinput_device
|
||||
public:
|
||||
keyboard_state keyboard;
|
||||
|
||||
rawinput_keyboard_device(running_machine& machine, const char* name, input_module& module)
|
||||
: rawinput_device(machine, name, DEVICE_CLASS_KEYBOARD, module),
|
||||
rawinput_keyboard_device(running_machine& machine, const char *name, const char *id, input_module& module)
|
||||
: rawinput_device(machine, name, id, DEVICE_CLASS_KEYBOARD, module),
|
||||
keyboard({{0}})
|
||||
{
|
||||
}
|
||||
@ -344,8 +344,8 @@ private:
|
||||
public:
|
||||
mouse_state mouse;
|
||||
|
||||
rawinput_mouse_device(running_machine& machine, const char* name, input_module& module)
|
||||
: rawinput_device(machine, name, DEVICE_CLASS_MOUSE, module),
|
||||
rawinput_mouse_device(running_machine& machine, const char *name, const char *id, input_module& module)
|
||||
: rawinput_device(machine, name, id, DEVICE_CLASS_MOUSE, module),
|
||||
mouse({0})
|
||||
{
|
||||
}
|
||||
@ -404,8 +404,8 @@ private:
|
||||
public:
|
||||
mouse_state lightgun;
|
||||
|
||||
rawinput_lightgun_device(running_machine& machine, const char* name, input_module& module)
|
||||
: rawinput_device(machine, name, DEVICE_CLASS_LIGHTGUN, module),
|
||||
rawinput_lightgun_device(running_machine& machine, const char *name, const char *id, input_module& module)
|
||||
: rawinput_device(machine, name, id, DEVICE_CLASS_LIGHTGUN, module),
|
||||
lightgun({0})
|
||||
{
|
||||
}
|
||||
@ -574,8 +574,11 @@ protected:
|
||||
|
||||
// convert name to utf8
|
||||
std::string utf8_name = utf8_from_wstring(name.c_str());
|
||||
|
||||
// set device id to raw input name
|
||||
std::string utf8_id = utf8_from_wstring(tname.get());
|
||||
|
||||
devinfo = devicelist()->create_device<TDevice>(machine, utf8_name.c_str(), *this);
|
||||
devinfo = devicelist()->create_device<TDevice>(machine, utf8_name.c_str(), utf8_id.c_str(), *this);
|
||||
|
||||
// Add the handle
|
||||
devinfo->set_handle(rawinputdevice->hDevice);
|
||||
|
@ -110,8 +110,8 @@ static int lookup_sdl_code(const char *scode)
|
||||
class sdl_device : public event_based_device<SDL_Event>
|
||||
{
|
||||
public:
|
||||
sdl_device(running_machine &machine, const char* name, input_device_class devclass, input_module &module)
|
||||
: event_based_device(machine, name, devclass, module)
|
||||
sdl_device(running_machine &machine, const char *name, const char *id, input_device_class devclass, input_module &module)
|
||||
: event_based_device(machine, name, id, devclass, module)
|
||||
{
|
||||
}
|
||||
|
||||
@ -132,8 +132,8 @@ class sdl_keyboard_device : public sdl_device
|
||||
public:
|
||||
keyboard_state keyboard;
|
||||
|
||||
sdl_keyboard_device(running_machine &machine, const char* name, input_module &module)
|
||||
: sdl_device(machine, name, DEVICE_CLASS_KEYBOARD, module),
|
||||
sdl_keyboard_device(running_machine &machine, const char *name, const char *id, input_module &module)
|
||||
: sdl_device(machine, name, id, DEVICE_CLASS_KEYBOARD, module),
|
||||
keyboard({{0}})
|
||||
{
|
||||
}
|
||||
@ -201,8 +201,8 @@ private:
|
||||
public:
|
||||
mouse_state mouse;
|
||||
|
||||
sdl_mouse_device(running_machine &machine, const char* name, input_module &module)
|
||||
: sdl_device(machine, name, DEVICE_CLASS_MOUSE, module),
|
||||
sdl_mouse_device(running_machine &machine, const char *name, const char *id, input_module &module)
|
||||
: sdl_device(machine, name, id, DEVICE_CLASS_MOUSE, module),
|
||||
last_x(0),
|
||||
last_y(0),
|
||||
mouse({0})
|
||||
@ -338,8 +338,8 @@ public:
|
||||
sdl_joystick_state joystick;
|
||||
sdl_api_state sdl_state;
|
||||
|
||||
sdl_joystick_device(running_machine &machine, const char *name, input_module &module)
|
||||
: sdl_device(machine, name, DEVICE_CLASS_JOYSTICK, module),
|
||||
sdl_joystick_device(running_machine &machine, const char *name, const char *id, input_module &module)
|
||||
: sdl_device(machine, name, id, DEVICE_CLASS_JOYSTICK, module),
|
||||
joystick({{0}}),
|
||||
sdl_state({ nullptr })
|
||||
{
|
||||
@ -419,8 +419,8 @@ public:
|
||||
class sdl_sixaxis_joystick_device : public sdl_joystick_device
|
||||
{
|
||||
public:
|
||||
sdl_sixaxis_joystick_device(running_machine &machine, const char *name, input_module &module)
|
||||
: sdl_joystick_device(machine, name, module)
|
||||
sdl_sixaxis_joystick_device(running_machine &machine, const char *name, const char *id, input_module &module)
|
||||
: sdl_joystick_device(machine, name, id, module)
|
||||
{
|
||||
}
|
||||
|
||||
@ -536,7 +536,7 @@ public:
|
||||
osd_printf_verbose("Keyboard: Start initialization\n");
|
||||
|
||||
// SDL only has 1 keyboard add it now
|
||||
devinfo = devicelist()->create_device<sdl_keyboard_device>(machine, "System keyboard", *this);
|
||||
devinfo = devicelist()->create_device<sdl_keyboard_device>(machine, "System keyboard", "System keyboard", *this);
|
||||
|
||||
// populate it
|
||||
for (int keynum = 0; local_table[keynum].mame_key != ITEM_ID_INVALID; keynum++)
|
||||
@ -672,7 +672,7 @@ public:
|
||||
osd_printf_verbose("Mouse: Start initialization\n");
|
||||
|
||||
// SDL currently only supports one mouse
|
||||
devinfo = devicelist()->create_device<sdl_mouse_device>(machine, "System mouse", *this);
|
||||
devinfo = devicelist()->create_device<sdl_mouse_device>(machine, "System mouse", "System mouse", *this);
|
||||
|
||||
// add the axes
|
||||
devinfo->device()->add_item("X", ITEM_ID_XAXIS, generic_axis_get_state<std::int32_t>, &devinfo->mouse.lX);
|
||||
@ -890,16 +890,16 @@ private:
|
||||
{
|
||||
snprintf(tempname, ARRAY_LENGTH(tempname), "NC%d", index);
|
||||
m_sixaxis_mode
|
||||
? devicelist()->create_device<sdl_sixaxis_joystick_device>(machine, tempname, *this)
|
||||
: devicelist()->create_device<sdl_joystick_device>(machine, tempname, *this);
|
||||
? devicelist()->create_device<sdl_sixaxis_joystick_device>(machine, tempname, tempname, *this)
|
||||
: devicelist()->create_device<sdl_joystick_device>(machine, tempname, tempname, *this);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return m_sixaxis_mode
|
||||
? devicelist()->create_device<sdl_sixaxis_joystick_device>(machine, devmap->map[index].name.c_str(), *this)
|
||||
: devicelist()->create_device<sdl_joystick_device>(machine, devmap->map[index].name.c_str(), *this);
|
||||
? devicelist()->create_device<sdl_sixaxis_joystick_device>(machine, devmap->map[index].name.c_str(), devmap->map[index].name.c_str(), *this)
|
||||
: devicelist()->create_device<sdl_joystick_device>(machine, devmap->map[index].name.c_str(), devmap->map[index].name.c_str(), *this);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -38,8 +38,8 @@ class win32_keyboard_device : public event_based_device<KeyPressEventArgs>
|
||||
public:
|
||||
keyboard_state keyboard;
|
||||
|
||||
win32_keyboard_device(running_machine& machine, const char *name, input_module &module)
|
||||
: event_based_device(machine, name, DEVICE_CLASS_KEYBOARD, module),
|
||||
win32_keyboard_device(running_machine& machine, const char *name, const char *id, input_module &module)
|
||||
: event_based_device(machine, name, id, DEVICE_CLASS_KEYBOARD, module),
|
||||
keyboard({{0}})
|
||||
{
|
||||
}
|
||||
@ -73,7 +73,7 @@ public:
|
||||
virtual void input_init(running_machine &machine) override
|
||||
{
|
||||
// Add a single win32 keyboard device that we'll monitor using Win32
|
||||
win32_keyboard_device *devinfo = devicelist()->create_device<win32_keyboard_device>(machine, "Win32 Keyboard 1", *this);
|
||||
win32_keyboard_device *devinfo = devicelist()->create_device<win32_keyboard_device>(machine, "Win32 Keyboard 1", "Win32 Keyboard 1", *this);
|
||||
|
||||
keyboard_trans_table &table = keyboard_trans_table::instance();
|
||||
|
||||
@ -133,8 +133,8 @@ public:
|
||||
mouse_state mouse;
|
||||
win32_mouse_state win32_mouse;
|
||||
|
||||
win32_mouse_device(running_machine& machine, const char *name, input_module &module)
|
||||
: event_based_device(machine, name, DEVICE_CLASS_MOUSE, module),
|
||||
win32_mouse_device(running_machine& machine, const char *name, const char *id, input_module &module)
|
||||
: event_based_device(machine, name, id, DEVICE_CLASS_MOUSE, module),
|
||||
mouse({0}),
|
||||
win32_mouse({{0}})
|
||||
{
|
||||
@ -206,7 +206,7 @@ public:
|
||||
return;
|
||||
|
||||
// allocate a device
|
||||
devinfo = devicelist()->create_device<win32_mouse_device>(machine, "Win32 Mouse 1", *this);
|
||||
devinfo = devicelist()->create_device<win32_mouse_device>(machine, "Win32 Mouse 1", "Win32 Mouse 1", *this);
|
||||
if (devinfo == nullptr)
|
||||
return;
|
||||
|
||||
@ -261,8 +261,8 @@ private:
|
||||
public:
|
||||
mouse_state mouse;
|
||||
|
||||
win32_lightgun_device(running_machine& machine, const char *name, input_module &module)
|
||||
: event_based_device(machine, name, DEVICE_CLASS_LIGHTGUN, module),
|
||||
win32_lightgun_device(running_machine& machine, const char *name, const char *id, input_module &module)
|
||||
: event_based_device(machine, name, id, DEVICE_CLASS_LIGHTGUN, module),
|
||||
m_lightgun_shared_axis_mode(FALSE),
|
||||
m_gun_index(0),
|
||||
mouse({0})
|
||||
@ -393,7 +393,7 @@ public:
|
||||
int axisnum, butnum;
|
||||
|
||||
// allocate a device
|
||||
devinfo = devicelist()->create_device<win32_lightgun_device>(machine, gun_names[gunnum], *this);
|
||||
devinfo = devicelist()->create_device<win32_lightgun_device>(machine, gun_names[gunnum], gun_names[gunnum], *this);
|
||||
if (devinfo == nullptr)
|
||||
break;
|
||||
|
||||
|
@ -338,8 +338,8 @@ class x11_input_device : public event_based_device<XEvent>
|
||||
public:
|
||||
x11_api_state x11_state;
|
||||
|
||||
x11_input_device(running_machine &machine, const char* name, input_device_class devclass, input_module &module)
|
||||
: event_based_device(machine, name, devclass, module),
|
||||
x11_input_device(running_machine &machine, const char *name, const char *id, input_device_class devclass, input_module &module)
|
||||
: event_based_device(machine, name, id, devclass, module),
|
||||
x11_state({0})
|
||||
{
|
||||
}
|
||||
@ -354,8 +354,8 @@ class x11_lightgun_device : public x11_input_device
|
||||
public:
|
||||
lightgun_state lightgun;
|
||||
|
||||
x11_lightgun_device(running_machine &machine, const char* name, input_module &module)
|
||||
: x11_input_device(machine, name, DEVICE_CLASS_LIGHTGUN, module),
|
||||
x11_lightgun_device(running_machine &machine, const char *name, const char *id, input_module &module)
|
||||
: x11_input_device(machine, name, id, DEVICE_CLASS_LIGHTGUN, module),
|
||||
lightgun({0})
|
||||
{
|
||||
}
|
||||
@ -533,13 +533,13 @@ private:
|
||||
if (m_lightgun_map.initialized)
|
||||
{
|
||||
snprintf(tempname, ARRAY_LENGTH(tempname), "NC%d", index);
|
||||
devicelist()->create_device<x11_lightgun_device>(machine, tempname, *this);
|
||||
devicelist()->create_device<x11_lightgun_device>(machine, tempname, tempname, *this);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return devicelist()->create_device<x11_lightgun_device>(machine, m_lightgun_map.map[index].name.c_str(), *this);
|
||||
return devicelist()->create_device<x11_lightgun_device>(machine, m_lightgun_map.map[index].name.c_str(), m_lightgun_map.map[index].name.c_str(), *this);
|
||||
}
|
||||
|
||||
void add_lightgun_buttons(XAnyClassPtr first_info_class, int num_classes, x11_lightgun_device *devinfo) const
|
||||
|
@ -74,7 +74,7 @@ xinput_joystick_device * xinput_api_helper::create_xinput_device(running_machine
|
||||
snprintf(device_name, sizeof(device_name), "XInput Player %u", index + 1);
|
||||
|
||||
// allocate the device object
|
||||
devinfo = module.devicelist()->create_device<xinput_joystick_device>(machine, device_name, module, shared_from_this());
|
||||
devinfo = module.devicelist()->create_device<xinput_joystick_device>(machine, device_name, device_name, module, shared_from_this());
|
||||
|
||||
// Set the player ID
|
||||
devinfo->xinput_state.player_index = index;
|
||||
@ -89,8 +89,8 @@ xinput_joystick_device * xinput_api_helper::create_xinput_device(running_machine
|
||||
// xinput_joystick_device
|
||||
//============================================================
|
||||
|
||||
xinput_joystick_device::xinput_joystick_device(running_machine &machine, const char *name, input_module &module, std::shared_ptr<xinput_api_helper> helper)
|
||||
: device_info(machine, name, DEVICE_CLASS_JOYSTICK, module),
|
||||
xinput_joystick_device::xinput_joystick_device(running_machine &machine, const char *name, char const *id, input_module &module, std::shared_ptr<xinput_api_helper> helper)
|
||||
: device_info(machine, name, id, DEVICE_CLASS_JOYSTICK, module),
|
||||
gamepad({{0}}),
|
||||
xinput_state({0}),
|
||||
m_xinput_helper(helper),
|
||||
|
@ -135,7 +135,7 @@ private:
|
||||
bool m_configured;
|
||||
|
||||
public:
|
||||
xinput_joystick_device(running_machine &machine, const char *name, input_module &module, std::shared_ptr<xinput_api_helper> helper);
|
||||
xinput_joystick_device(running_machine &machine, const char *name, const char *id, input_module &module, std::shared_ptr<xinput_api_helper> helper);
|
||||
|
||||
void poll() override;
|
||||
void reset() override;
|
||||
|
Loading…
Reference in New Issue
Block a user