# RetroArch controller mapping

RetroArch controller mapping is very specific, before going into details, it is important to understand the general RetroArch mapping principles.

## RetroArch mapping principle

Information on how RetroArch manages controls can be found here:

{% embed url="<https://docs.libretro.com/guides/input-and-controls/>" %}

RetroArch has a 2-step approach with controllers mapping:

* Step 1: mapping of your physical gamepad with RetroArch "RetroPad"
* Step 2: mapping of the Retropad with the original console or computer game controller

<div align="left"><figure><img src="https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2Fdmx5RuEHc8ZQkvXfF484%2Fretroarch%20remap%20principle.png?alt=media&#x26;token=226593e0-071b-4d70-81a8-86970d3bac4b" alt=""><figcaption></figcaption></figure></div>

The guide in this page mostly treats about the second step, as it is assumed that RetroBat is passing all your physical gamepad buttons to RetroArch (this should always be the case if you have correctly configured your controller in RetroBat).

#### General Binding

The mapping done in Step 1 can be found in the following section of RetroArch configuration:

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

<div align="left"><figure><img src="https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2F0amCGrpkUFPX4PhuIPal%2Fimage.png?alt=media&#x26;token=3c6705e7-ac0a-4057-8515-f8bdc360e4a6" alt="" width="375"><figcaption></figcaption></figure></div>

{% hint style="info" %}
General binding is stored in the "**retroarch.cfg**" file located in `/emulators/retroarch`
{% endhint %}

#### Remap

The remap information (step 2) can be found in the Quick Settings menu of RetroArch, while a core is running:

<div align="left"><figure><img src="https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2Ftd9MinQgRXd2RrgoGifm%2Fimage.png?alt=media&#x26;token=e9364ded-f659-4440-ab69-dab8bb5bf8cb" alt="" width="294"><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FpqGwZdtubJ9wAnKWMGcZ%2Fimage.png?alt=media&#x26;token=cacaa251-2294-4b1b-adfe-e86d1ff3f928" alt="" width="342"><figcaption></figcaption></figure></div>

{% hint style="info" %}
Remap files are saved as .rmp files in `/emulators/retroarch/config/remaps` folder.
{% endhint %}

## How to change mapping for RetroArch when using RetroBat ?

RetroBat allows multiple ways to modify mapping of your controller in RetroArch, the wiki will guide you through the following methods:

* [Manually saving a remap file for a game](#manually-create-a-remap-file-for-a-game) (remap)
* [Using a YAML core override file](#using-a-core-override-remap-file) (remap)
* [Forcing a controller binding configuration](#force-a-controller-binding-configuration) (change controller binding)
* Forcing a keyboard controller (such as IPAC2 or TankStick controllers)
* [Enabling a special controller type](#enable-a-special-controller-type) (for some systems/cores only)
* [Using a different input layout provided by RetroBat](#use-a-pre-defined-layout)

### Manually create a remap file for a game

Open RetroBat and launch the game for which you require a specific remapping.

Once in the game, press SELECT + ![](https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FW8q8wzu0yW9Htt5h4zEA%2Fimage.png?alt=media\&token=a4ae3ad3-3a80-4c28-8b15-92a1b5a80da7) buttons simultaneously to open the RetroArch menu, and select **Quick Menu**:

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

In the QUICK MENU list, you will find " **Controls** "

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

From there, proceed with the required remapping:

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

In this example, i have mapped the RetroPad left analog up input to the key defined for A in RetroBat (which is W on my keyboard):

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

{% hint style="info" %}
Note that you can only remap the keys that have been passed by RetroBat to retroArch based on your controller.
{% endhint %}

Once the mapping is performed, exit and go back to the **CONTROLS** menu, then select the "*Manage Remap Files*" option:

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

In the next submenu, save the remap file for the game (it will apply to this game only)

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

Once saved, the new remap will now be used next time you run the game.

{% hint style="info" %}
You cannot use the option to "save for core", as this would automatically be erased by RetroBat upon next launch.
{% endhint %}

### Using a core override remap file

Read [this chapter](https://wiki.retrobat.org/controller-configuration#file-override-general-principle) for general information.

RetroArch core remap files provided with RetroBat are located in the `\system\resources\inputmapping` folder of your RetroBat installation, they start with the "**libretro\_**" prefix.

The logic RetroBat uses to find a file is the following:

1. Search in `\user\inputmapping` for a file named **libretro\_\<core>\_\<system>.yml**
2. Search in `\user\inputmapping` for a file named **libretro\_\<core>.yml**
3. Search in `\user\inputmapping` for a file named **libretro.yml**
4. Search in `\system\resources\inputmapping` for a file named **libretro\_\<core>\_\<system>.yml**
5. Search in `\system\resources\inputmapping` for a file named **libretro\_\<core>.yml**
6. Search in `\system\resources\inputmapping` for a file named **libretro.yml**

If a yaml file is found, RetroBat reads the file and searches for a container matching the name of the game rom file:

<div align="left"><figure><img src="https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2F91DaXvnrBbBcsV0uhBPL%2Fimage.png?alt=media&#x26;token=01ed7a9d-a73a-4b0c-862c-639c37743031" alt=""><figcaption></figcaption></figure></div>

If no container exists for the game, RetroBat tries to get the "default" container:

<div align="left"><figure><img src="https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2Ft61LmwvkaLMORy0Kyu8A%2Fimage.png?alt=media&#x26;token=a64711d3-03e5-448a-b475-e94eaa13b1eb" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
For arcade systems, a single game can have multiple layouts based on the option set in RetroBat interface ADVANCED SETTINGS > CONTROLS:

![](https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FnilcXTkaKMJsMWtRcXEn%2Fimage.png?alt=media\&token=50f9246b-3073-4ffc-aacf-33cfa3448bca)

RetroBat will first look for the container with the selected layout, before falling back to the game specific container:

![](https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FHFilgNrpnN4Gd9UOeJe1%2Fimage.png?alt=media\&token=46c22623-6f5b-49f8-9476-ffd702fd792d)
{% endhint %}

When a specific container is found, RetroBat automatically generates and modifies the core remap file when running a game, which automatically applies the selected remap:

<div align="left"><figure><img src="https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FLh06Zh57rWadiPvvD4Fe%2Fimage.png?alt=media&#x26;token=97c7aa88-55c9-40b5-b8d9-d6a7503eb428" alt=""><figcaption></figcaption></figure></div>

### Force a controller binding configuration

It is possible to force a controller with a specific binding in RetroArch, this is useful in case a specific controller would not be correctly configured by RetroBat or in case it is unknownn by RetroArch but working correctly when perforing a manual mapping in RetroArch binding options.

RetroBat ships with a specificfile named "**retroarch\_controller.json**" located in the `\system\resources\inputmapping` folder of the RetroBat installation.

This file is a json-formatted file, it contains the exact mapping required in the `retroarch.cfg` file based on the controller SDL guid:

<div align="left"><figure><img src="https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2F8l4tOcxMctLKQpD2iAFV%2Fimage.png?alt=media&#x26;token=a2ca68fb-c6b8-4d6d-9187-a604ead0f8d8" alt=""><figcaption></figcaption></figure></div>

The above example is for the NSO N64 controller, the different values required in the file are the following:

* **Name**: for information only
* **Guid**: allows RetroBat to enable the specific mapping based on the connected controller (the SDL GUID of the controller can be found in the es\_input.cfg file or in the emulatorlauncher.log after having launched a game). Multiple guids can be entered if a controller has multiple revisions.
* **Driver**: can be used if the RetroArch mapping is different depending on the selected Joyapd Driver in RetroArch, possible values are : sdl2 (RetroBat default), xinput, dinput
* **Mapping**: the actual mapping to be set in `retroarch.cfg file`, for each button. In order to know the mapping for the controller, perform the configuration manually by running retroarch.exe, exit retroarch, and open the retroarch.cfg file, search for the lines starting with input\_player1\_ and ending with btn or axis.
* **HotkeyMapping**: the mapping for hotkeys for the controller
* **ControllerInfo**: can be used to adjust analog sensitivity or for other specific purposes (ask the RetroBat team if a feature is required)

{% hint style="info" %}
Do not hesitate to share with the RetroBat team any specific controller mapping that you have created.
{% endhint %}

### Forcing a keyboard controller

Some controllers are recognized by windows as keyboards, this is the case for example for the X-Arcade Tankstick or the IPAC2.

RetroBat provides an autoconfiguration for these controller, which is forced from a YAML file located in the `\system\resources\inputmapping\kbpads` folder of your RetroBat installation:

<div align="left"><figure><img src="https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FJOfPDAU5W78Br1YIgZvi%2Fimage.png?alt=media&#x26;token=5369f1ad-dd6f-484e-b7a8-862e1545ee56" alt=""><figcaption></figcaption></figure></div>

The file contains the mapping to force in RetroArch for a device:

<div align="left"><figure><img src="https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FjKqvqYjV77NcFfuA1ypa%2Fimage.png?alt=media&#x26;token=dcb9eff6-b9c5-4113-8dbf-9d3ca8184fef" alt=""><figcaption></figcaption></figure></div>

If you own one of these devices, you can enable the automatic mapping within the RetroBat **MAIN MENU > GAME SETTINGS > RETROARCH OPTIONS > CONTROLS**:

<div align="left"><figure><img src="https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FxnRrjeHbInNVSzy3SQ1E%2Fimage.png?alt=media&#x26;token=2cdd686b-d3a3-449a-b0c6-60493d293de1" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2F9uJzCcN4ShOw3wbRQzbc%2Fimage.png?alt=media&#x26;token=167aed5a-1799-49a4-812e-4e257476ed0d" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
If you own a different controller that is recognized as a keyboard, you can share the keyboard mapping for the stick with the RetroBat team and it will be added to RetroBat.
{% endhint %}

### Enable a special controller type

Look at [this wiki page](https://wiki.retrobat.org/controllers/supported-controllers/gamepads/special-controllers) for more details.

### Use a pre-defined layout

RetroBat does offer, for multiple systems, the ability to change the button mapping layout.

The option can usually be found in the RetroBat **advanced settings > controls** menu:

<div align="left"><figure><img src="https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2FUsjSlVr7kCjUoHQ2PV1Y%2Fimage.png?alt=media&#x26;token=635c1b29-744d-4592-9a44-1b6401932261" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://990680527-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FexdzL60ZuqPLldz2AYta%2Fuploads%2F4qjKGhqwBUbmxDBt51dq%2Fimage.png?alt=media&#x26;token=e0f3fd73-3588-4dc9-822a-a083c30664e2" alt="" width="245"><figcaption><p>Example for megadrive</p></figcaption></figure></div>

More information about the different layouts can be found on the [page for the system](https://wiki.retrobat.org/systems-and-emulators/supported-game-systems).
