# MAME controller mapping

MAME emulator control mapping is very complexe because each machine it emulates had a different control layout.

RetroBat offers multiple ways to change controller mapping for MAME, as well as libretro-mame. Each method is described in this page.

## MAME (standalone)

RetroBat offers multiple ways to manage MAME controller configuration, either manually, or with automatic configuration:

* RetroBat standard autoconfiguration
* RetroBat xml override files (per-game)
* Specific configuration for special controller types
* Manual Game specific configuration
* Manual Custom configuration

### RetroBat autoconfiguration

By default, RetroBat will try to autoconfigure controls in MAME either by using RetroBat-provided per-game configuration, or by setting a default configuration.

Autoconfiguration can change depending on the controller layout that you specify in **ADVANCED SETTINGS > CONTROLS**:

<div align="left"><figure><img src="https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FezFyDXL2Bjc3GBQzQdK6%2Fimage.png?alt=media&#x26;token=f6f12083-a9f9-4c25-b4b7-b5b7602a825f" alt=""><figcaption></figcaption></figure></div>

**The default button for each layout is the following:**

**Controller**: this profile is adapted to gamepads, where ![](https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2Fxdo1JzVyl1d8qhCWOUKb%2Fimage.png?alt=media\&token=ba032be4-be30-49f0-9c16-a4f57286ce77) is assigned to button 1, ![](https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FijyCGzzVSV4qeiZRK0CS%2Fimage.png?alt=media\&token=de775262-526e-4db4-b007-bdbfcd54aaf9) is assigned to button 2, ![](https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FiiijSkMaBLlyDTgsCTy7%2Fimage.png?alt=media\&token=00d063e9-3cf3-4172-9303-ad319f7b3f61) is assigned to button 3, ![](https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FO3DJl1zogGhJq2qhShrA%2Fimage.png?alt=media\&token=e164d5b1-c4c2-40ce-aaba-8b4d36221b55) is assigned to button 4, L1 to button 5, R1 to button 6, L2 to button 7 and R2 to button 8

**Modern 8 buttons**: this profile is the most common one for modern arcade sticks, upper 4 buttons are buttons 1 (![](https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FRWjZycPJ3LLhsMjcJGRO%2Fimage.png?alt=media\&token=0403914d-2781-49a5-ad34-79e7b4656ead)), 2(![](https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2Ff4Z5g1ZYcaGv1B9zK3wq%2Fimage.png?alt=media\&token=d6847f07-55e1-465f-9f51-75f7fa0f1a7b)), 3(R1) and 7(L1), lower 4 buttons are buttons 4(![](https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FYhWKu026ji9eoden8u1P%2Fimage.png?alt=media\&token=9fcf38f7-3c27-46d4-9fb3-af176a758089)), 5(![](https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FNtMUyOCzk1Jat5IdwRNj%2Fimage.png?alt=media\&token=b9425bda-aed5-425e-a0fa-ee1db7f198f5)), 6(R2) and 8(L2)

**Classic 8 buttons**: upper 4 buttons are buttons 1 (![](https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FRWjZycPJ3LLhsMjcJGRO%2Fimage.png?alt=media\&token=0403914d-2781-49a5-ad34-79e7b4656ead)), 2(![](https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2Ff4Z5g1ZYcaGv1B9zK3wq%2Fimage.png?alt=media\&token=d6847f07-55e1-465f-9f51-75f7fa0f1a7b)), 3(L1) and 7(L2), lower 4 buttons are buttons 4(![](https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FYhWKu026ji9eoden8u1P%2Fimage.png?alt=media\&token=9fcf38f7-3c27-46d4-9fb3-af176a758089)), 5(![](https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FNtMUyOCzk1Jat5IdwRNj%2Fimage.png?alt=media\&token=b9425bda-aed5-425e-a0fa-ee1db7f198f5)), 6(R1) and 8(R2)

**6 buttons**: similar to classic 8 buttons but without buttons 7 and 8

**8 buttons alternative**: default is the same as Controller mapping

### Per-Game automatic xml overrides

RetroBat ships with adapted per-game configuration, for each of the layouts described above, for approximately 130 games, the override files shipped with RetroBat are located in the `\system\resources\inputmapping\mame` folder:

<div align="left"><figure><img src="https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FXWzA41yPNQIr0rjz7CKY%2Fimage.png?alt=media&#x26;token=941dff87-2ece-4ce5-bb39-b2b93c214bcf" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
You can create your own file and share it with the RetroBat team, or save it in the `\user\inputmapping\mame` folder of your RetroBat installation if you need a variation of the profile provided by RetroBat.
{% endhint %}

The override file is a xml file, almost similar to the MAME format used for its own config files, but with generic button names, that will be converted by RetroBat based on your connected controller and selected profile:

<div align="left"><figure><img src="https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FIuZ0Xl1TIvMTb2621fBd%2Fimage.png?alt=media&#x26;token=b1353a78-8368-4277-9a61-289aa1f40a2b" alt=""><figcaption></figcaption></figure></div>

Each file contains multiple "*layout*" sections, which corresponds to the available layouts in RetroBat. Based on the selected value in RetroBat controls settings, the corresponding layout from the file will be picked.

Each layout contains the specific button mappings to use for the game, for example the following line means that the **button 3** of the arcade machine "*altbeast*", for the player 1, will be mapped to the **east face button** of the controller when using the *default* layout:

<div align="left"><figure><img src="https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FyCgHwJtenMASHyDZmBFa%2Fimage.png?alt=media&#x26;token=f86df0fd-26db-4a77-925c-d046bcd15e45" alt=""><figcaption></figcaption></figure></div>

In the same file you can see that this button is mapped to the **R1 button** when using the modern8 layout (which corresponds to the 3rd button of the upper range of the arcade stick):

<div align="left"><figure><img src="https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FOR5DZS2Ie6JdsMfmWMLm%2Fimage.png?alt=media&#x26;token=402254ab-cf7e-4a59-9c4b-d5589a87e6ec" alt=""><figcaption></figcaption></figure></div>

You can use the [same method as described below](#creating-a-specific-controller-configuration-file-for-mame) to create your own mapping file, however you will need to change the button values with the generic ones from RetroBat:

<details>

<summary>List of generic RetroBat button values</summary>

* JOY\_west
* JOY\_north
* JOY\_east
* JOY\_south
* JOY\_down (dpad down)
* JOY\_lsdown (left stick down)
* JOY\_up / JOY\_lsup
* JOY\_left / JOY\_lsleft
* JOY\_right / JOY\_lsright
* JOY\_r1
* JOY\_l1
* JOY\_r2trigger
* JOY\_l2trigger
* JOY\_r3
* JOY\_l3
* JOY\_leftstickx (left stick horizontal axis) / JOY\_rightstickx
* JOY\_leftsticky (left stick vertical axis) / JOY\_leftstickx
* JOY\_lsup / JOY\_lsdown / JOY\_lsleft / JOY\_lsright (left stick directions)

It is also possible to add "reverse" after and axis in order to set \_REVERSE in MAME config file.

</details>

### Using manual specific configuration

Use the following setting in RetroBat **ADVANCED SETTINGS > CONTROLS** menu to enable specific configuration:

<div align="left"><figure><img src="https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FUsk2siKNnOmzII16cyWy%2Fimage.png?alt=media&#x26;token=2b88e3f1-0322-4cb4-945e-17a4291eee1d" alt=""><figcaption></figcaption></figure></div>

All the settings other than RetroBat Auto can be used to point MAME to use a controller config file in the `\saves\mame\ctrlr\` folder of your retrobat installation.

RetroBat ships with 2 files, one for the IPAC2 controller and one for the X-Arcade TankStick controller, if you own one of these controllers, you can use these options to autoconfigure these.

The other profiles can be used to point to files that you need to create, either custom files, or per-game files (named after the game rom). Such files are not provided with RetroBat and need to be created, here is the procedure:

### Creating a specific controller configuration file for MAME

#### STEP 1 : Preliminary explanations

MAME standalone will read the controller configuration files in the following ordre of priority (from less priority to highest priority - meaning the last file found will override what is found before):

1. Native controller configuration
2. Default.cfg file located in `\bios\mame\cfg` folder
3. Game specific config files located in `\bios\mame\cfg` folder
4. Controller configuration file located in `\saves\mame\ctrlr` folder as per selection in RetroBat options

#### STEP 2 : Create controller mapping file in MAME

Run *mame.exe*, the executable is located in the `emulators\mame` folder of your RetroBat installation.

Click on "General Settings":

<div align="left"><figure><img src="https://i.imgur.com/7FfrAyr.png" alt=""><figcaption></figcaption></figure></div>

Select "Input Assignments"

<div align="left"><figure><img src="https://i.imgur.com/P23EUU1.png" alt=""><figcaption></figcaption></figure></div>

Select the controls you want to assign:

* User Interface section lets you map buttons to actions in the MAME Menu
* Player X Controls allows you to map in-game controls

<div align="left"><figure><img src="https://i.imgur.com/pgXcIQM.png" alt=""><figcaption></figcaption></figure></div>

Map controls as you would like them:

<div align="left"><figure><img src="https://i.imgur.com/kxVLMtw.png" alt=""><figcaption></figcaption></figure></div>

When using left and right buttons (or keys), you can select whether to add a key to the same button or whether to reset the mapping for the control.

<div align="left"><figure><img src="https://i.imgur.com/ubjsXry.png" alt=""><figcaption><p>You can APPEND</p></figcaption></figure></div>

<div align="left"><figure><img src="https://i.imgur.com/6pGoFrF.png" alt=""><figcaption><p>Are clear and reset</p></figcaption></figure></div>

Once the mapping done, go back and click on "Save Settings":

<div align="left"><figure><img src="https://i.imgur.com/pDLsvFJ.png" alt=""><figcaption></figcaption></figure></div>

A file name "default.cfg" has been saved in the `\emulators\mame\cfg` folder.

<div align="left"><figure><img src="https://i.imgur.com/PmZJO4I.png" alt=""><figcaption></figcaption></figure></div>

#### STEP 3 : Manage the cfg file

Open the default.cfg file and check the content:

<div align="left"><figure><img src="https://i.imgur.com/tYgSbfM.png" alt=""><figcaption></figcaption></figure></div>

The file has an xml format, the mapping that you have performed is located in the \<input> section of the file.

*In the example, the keyboard key "Q" has been assigned to the action "UI\_MENU" that opens the MAME menu.*

Finally, copy the default.cfg file in the `\bios\mame\cfg` folder of your installation : this will now be the default controller configuration.

#### STEP 4 : Create a dedicated profile

Proceed as explained in step 1, then rename the file to one of the following values:

* custom1.cfg
* custom2.cfg
* custom3.cfg
* ...
* custom8.cfg

Move the file in the `\saves\mame\ctrlr` folder of your RetroBat installation:

<div align="left"><figure><img src="https://i.imgur.com/15wt2XH.png" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
You can also perform the mapping directly in the cfg file if you feel comfortable with xml document processing.

Additional information on the file structure can be found here:

<http://mirrors.arcadecontrols.com/easyemu/mameguidenew/mameguide-controlini.htm>

<https://docs.mamedev.org/advanced/ctrlr_config.html>
{% endhint %}

#### STEP 5 : Select the controller profile in RetroBat

From the MAME [Game view](https://wiki.retrobat.org/navigation/system-view-and-game-view#game-view), press SELECT to open the [View Options](https://wiki.retrobat.org/navigation/view-options) menu and select "ADVANCED SYSTEM OPTIONS"

<div align="left"><figure><img src="https://i.imgur.com/Y3mGW33.png" alt=""><figcaption></figcaption></figure></div>

Ensure the MAME64 emulator is set as EMULATOR and navigate to the CONTROLS submenu:

<div align="left"><figure><img src="https://i.imgur.com/3xCkZOg.png" alt=""><figcaption></figcaption></figure></div>

Select the "CONTROLLER PROFILE" option and choose the profile used for the file that you have created:

{% hint style="info" %}
RetroBat provides 8 custom profiles as well as the ability to use a per\_game cfg file.

When using "per\_game", the name of the file must match the name of the game file (without extension), for example name the file "wjammers.cfg" for the game file "wjammers.zip" (WindJammers).
{% endhint %}

<div align="left"><figure><img src="https://i.imgur.com/mD9Dn89.png" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
Do not hesitate to share the files you have created with the RetroBat team if you have a general profile that can be shared with other users.
{% endhint %}

## Libretro-mame

RetroBat offers autoconfiguration for MAME as part of RetroArch autoconfiguration, however, as MAME arcade machines have a huge variety of control types, it is possible to generate specific per-game configuration. The following configuration methods are available for libretro-mame within RetroBat:

* RetroBat standard autoconfiguration
* RetroBat xml override files (per-game)

### RetroBat autoconfiguration

By default, RetroBat will try to autoconfigure controls in libretro-mame either by using RetroBat-provided per-game configuration, or by using the default RetroArch RetroPad mapping.

Autoconfiguration can change depending on the controller layout that you specify in **ADVANCED SETTINGS > CONTROLS**:

<div align="left"><figure><img src="https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FezFyDXL2Bjc3GBQzQdK6%2Fimage.png?alt=media&#x26;token=f6f12083-a9f9-4c25-b4b7-b5b7602a825f" alt=""><figcaption></figcaption></figure></div>

### Using the mame core override remap file

Read [this chapter](https://wiki.retrobat.org/controllers/retroarch-controller-mapping#using-a-core-override-remap-file) for more information.

RetroBat can use a core override remap YAML file for libretro-mame, the file is located in the `system/resources/inputmapping` folder of your RetroBat installation and is named **libretro\_mame.yml**.

{% hint style="info" %}
If you want to modify the file, copy it first in the `user\inputmapping` folder of your RetroBat installation, else it might get erased with a future RetroBat update.
{% endhint %}

The remap file is a YAML file, each container contains the RetroArch remap for a game/layout:

<div align="left"><figure><img src="https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FNFXuQvoC3l1LAohwoISf%2Fimage.png?alt=media&#x26;token=7f5b7f35-ee45-4f71-82f6-353774c24908" alt=""><figcaption></figcaption></figure></div>
