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”.
Here’s an example:
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:
Furthermore, when devices are mapped using mapdevice, you’ll see that in the verbose logging too, such as: