2016-02-05 23:14:27 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-07-28 17:45:18 -04:00
|
|
|
|
using System.Xml.Serialization;
|
2016-02-05 23:14:27 -05:00
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Config
|
|
|
|
|
{
|
|
|
|
|
public class KeyMappings
|
|
|
|
|
{
|
2016-07-28 17:45:18 -04:00
|
|
|
|
public UInt32 A;
|
|
|
|
|
public UInt32 B;
|
|
|
|
|
public UInt32 Select;
|
|
|
|
|
public UInt32 Start;
|
|
|
|
|
public UInt32 Up;
|
|
|
|
|
public UInt32 Down;
|
|
|
|
|
public UInt32 Left;
|
|
|
|
|
public UInt32 Right;
|
2016-02-05 23:14:27 -05:00
|
|
|
|
|
2016-07-28 17:45:18 -04:00
|
|
|
|
public UInt32 TurboA;
|
|
|
|
|
public UInt32 TurboB;
|
|
|
|
|
public UInt32 TurboStart;
|
|
|
|
|
public UInt32 TurboSelect;
|
2016-02-05 23:14:27 -05:00
|
|
|
|
|
|
|
|
|
public KeyMappings()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public KeyMappings(int controllerIndex, int keySetIndex)
|
|
|
|
|
{
|
|
|
|
|
if(controllerIndex == 0) {
|
|
|
|
|
if(keySetIndex == 0) {
|
2016-07-28 17:45:18 -04:00
|
|
|
|
A = InteropEmu.GetKeyCode("A");
|
|
|
|
|
B = InteropEmu.GetKeyCode("S");
|
|
|
|
|
Select = InteropEmu.GetKeyCode("Q");
|
|
|
|
|
Start = InteropEmu.GetKeyCode("W");
|
|
|
|
|
Up = InteropEmu.GetKeyCode("Up Arrow");
|
|
|
|
|
Down = InteropEmu.GetKeyCode("Down Arrow");
|
|
|
|
|
Left = InteropEmu.GetKeyCode("Left Arrow");
|
|
|
|
|
Right = InteropEmu.GetKeyCode("Right Arrow");
|
2016-02-05 23:14:27 -05:00
|
|
|
|
|
2016-07-28 17:45:18 -04:00
|
|
|
|
TurboA = InteropEmu.GetKeyCode("Z");
|
|
|
|
|
TurboB = InteropEmu.GetKeyCode("X");
|
2016-02-05 23:14:27 -05:00
|
|
|
|
} else if(keySetIndex == 1) {
|
2016-07-16 16:25:57 -04:00
|
|
|
|
//XInput Default (Xbox controllers)
|
2016-07-28 17:45:18 -04:00
|
|
|
|
A = InteropEmu.GetKeyCode("Pad1 A");
|
|
|
|
|
B = InteropEmu.GetKeyCode("Pad1 X");
|
|
|
|
|
Select = InteropEmu.GetKeyCode("Pad1 Back");
|
|
|
|
|
Start = InteropEmu.GetKeyCode("Pad1 Start");
|
|
|
|
|
Up = InteropEmu.GetKeyCode("Pad1 Up");
|
|
|
|
|
Down = InteropEmu.GetKeyCode("Pad1 Down");
|
|
|
|
|
Left = InteropEmu.GetKeyCode("Pad1 Left");
|
|
|
|
|
Right = InteropEmu.GetKeyCode("Pad1 Right");
|
2016-02-05 23:14:27 -05:00
|
|
|
|
|
2016-07-28 17:45:18 -04:00
|
|
|
|
TurboA = InteropEmu.GetKeyCode("Pad1 B");
|
|
|
|
|
TurboB = InteropEmu.GetKeyCode("Pad1 Y");
|
2016-07-16 16:25:57 -04:00
|
|
|
|
} else if(keySetIndex == 2) {
|
|
|
|
|
//DirectInput Default (Used PS4 controller as a default)
|
2016-07-28 17:45:18 -04:00
|
|
|
|
A = InteropEmu.GetKeyCode("Joy1 But2");
|
|
|
|
|
B = InteropEmu.GetKeyCode("Joy1 But1");
|
|
|
|
|
Select = InteropEmu.GetKeyCode("Joy1 But9");
|
|
|
|
|
Start = InteropEmu.GetKeyCode("Joy1 But10");
|
|
|
|
|
Up = InteropEmu.GetKeyCode("Joy1 DPad Up");
|
|
|
|
|
Down = InteropEmu.GetKeyCode("Joy1 DPad Down");
|
|
|
|
|
Left = InteropEmu.GetKeyCode("Joy1 DPad Left");
|
|
|
|
|
Right = InteropEmu.GetKeyCode("Joy1 DPad Right");
|
2016-07-16 16:25:57 -04:00
|
|
|
|
|
2016-07-28 17:45:18 -04:00
|
|
|
|
TurboA = InteropEmu.GetKeyCode("Joy1 But3");
|
|
|
|
|
TurboB = InteropEmu.GetKeyCode("Joy1 But4");
|
2016-02-05 23:14:27 -05:00
|
|
|
|
}
|
2016-06-12 22:22:17 -04:00
|
|
|
|
} else if(controllerIndex == 1) {
|
|
|
|
|
if(keySetIndex == 0) {
|
2016-07-28 17:45:18 -04:00
|
|
|
|
A = InteropEmu.GetKeyCode("G");
|
|
|
|
|
B = InteropEmu.GetKeyCode("H");
|
|
|
|
|
Select = InteropEmu.GetKeyCode("T");
|
|
|
|
|
Start = InteropEmu.GetKeyCode("Y");
|
|
|
|
|
Up = InteropEmu.GetKeyCode("I");
|
|
|
|
|
Down = InteropEmu.GetKeyCode("K");
|
|
|
|
|
Left = InteropEmu.GetKeyCode("J");
|
|
|
|
|
Right = InteropEmu.GetKeyCode("L");
|
2016-06-12 22:22:17 -04:00
|
|
|
|
|
2016-07-28 17:45:18 -04:00
|
|
|
|
TurboA = InteropEmu.GetKeyCode("B");
|
|
|
|
|
TurboB = InteropEmu.GetKeyCode("N");
|
2016-06-12 22:22:17 -04:00
|
|
|
|
} else if(keySetIndex == 1) {
|
2016-07-16 16:25:57 -04:00
|
|
|
|
//XInput Default (Xbox controllers)
|
2016-07-28 17:45:18 -04:00
|
|
|
|
A = InteropEmu.GetKeyCode("Pad2 A");
|
|
|
|
|
B = InteropEmu.GetKeyCode("Pad2 X");
|
|
|
|
|
Select = InteropEmu.GetKeyCode("Pad2 Back");
|
|
|
|
|
Start = InteropEmu.GetKeyCode("Pad2 Start");
|
|
|
|
|
Up = InteropEmu.GetKeyCode("Pad2 Up");
|
|
|
|
|
Down = InteropEmu.GetKeyCode("Pad2 Down");
|
|
|
|
|
Left = InteropEmu.GetKeyCode("Pad2 Left");
|
|
|
|
|
Right = InteropEmu.GetKeyCode("Pad2 Right");
|
2016-06-12 22:22:17 -04:00
|
|
|
|
|
2016-07-28 17:45:18 -04:00
|
|
|
|
TurboA = InteropEmu.GetKeyCode("Pad2 B");
|
|
|
|
|
TurboB = InteropEmu.GetKeyCode("Pad2 Y");
|
2016-07-16 16:25:57 -04:00
|
|
|
|
} else if(keySetIndex == 2) {
|
|
|
|
|
//DirectInput Default (Used PS4 controller as a default)
|
2016-07-28 17:45:18 -04:00
|
|
|
|
A = InteropEmu.GetKeyCode("Joy2 But2");
|
|
|
|
|
B = InteropEmu.GetKeyCode("Joy2 But1");
|
|
|
|
|
Select = InteropEmu.GetKeyCode("Joy2 But9");
|
|
|
|
|
Start = InteropEmu.GetKeyCode("Joy2 But10");
|
|
|
|
|
Up = InteropEmu.GetKeyCode("Joy2 DPad Up");
|
|
|
|
|
Down = InteropEmu.GetKeyCode("Joy2 DPad Down");
|
|
|
|
|
Left = InteropEmu.GetKeyCode("Joy2 DPad Left");
|
|
|
|
|
Right = InteropEmu.GetKeyCode("Joy2 DPad Right");
|
2016-07-16 16:25:57 -04:00
|
|
|
|
|
2016-07-28 17:45:18 -04:00
|
|
|
|
TurboA = InteropEmu.GetKeyCode("Joy2 But3");
|
|
|
|
|
TurboB = InteropEmu.GetKeyCode("Joy2 But4");
|
2016-06-12 22:22:17 -04:00
|
|
|
|
}
|
2016-02-05 23:14:27 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public InteropEmu.KeyMapping ToInteropMapping()
|
|
|
|
|
{
|
|
|
|
|
InteropEmu.KeyMapping mapping = new InteropEmu.KeyMapping();
|
|
|
|
|
|
2016-07-28 17:45:18 -04:00
|
|
|
|
mapping.A = A;
|
|
|
|
|
mapping.B = B;
|
|
|
|
|
mapping.Start = Start;
|
|
|
|
|
mapping.Select = Select;
|
|
|
|
|
mapping.Up = Up;
|
|
|
|
|
mapping.Down = Down;
|
|
|
|
|
mapping.Left = Left;
|
|
|
|
|
mapping.Right = Right;
|
|
|
|
|
mapping.TurboA = TurboA;
|
|
|
|
|
mapping.TurboB = TurboB;
|
|
|
|
|
mapping.TurboStart = TurboStart;
|
|
|
|
|
mapping.TurboSelect = TurboSelect;
|
2016-02-05 23:14:27 -05:00
|
|
|
|
|
|
|
|
|
return mapping;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ControllerInfo
|
|
|
|
|
{
|
|
|
|
|
public InteropEmu.ControllerType ControllerType = InteropEmu.ControllerType.StandardController;
|
|
|
|
|
public List<KeyMappings> Keys = new List<KeyMappings>();
|
|
|
|
|
public UInt32 TurboSpeed = 2;
|
|
|
|
|
|
|
|
|
|
public InteropEmu.KeyMappingSet GetKeyMappingSet()
|
|
|
|
|
{
|
|
|
|
|
while(Keys.Count < 4) {
|
|
|
|
|
Keys.Add(new KeyMappings());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InteropEmu.KeyMappingSet mappingSet = new InteropEmu.KeyMappingSet();
|
|
|
|
|
mappingSet.Mapping1 = Keys[0].ToInteropMapping();
|
|
|
|
|
mappingSet.Mapping2 = Keys[1].ToInteropMapping();
|
|
|
|
|
mappingSet.Mapping3 = Keys[2].ToInteropMapping();
|
|
|
|
|
mappingSet.Mapping4 = Keys[3].ToInteropMapping();
|
|
|
|
|
mappingSet.TurboSpeed = TurboSpeed;
|
|
|
|
|
return mappingSet;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class InputInfo
|
|
|
|
|
{
|
|
|
|
|
public ConsoleType ConsoleType = ConsoleType.Nes;
|
|
|
|
|
public InteropEmu.ExpansionPortDevice ExpansionPortDevice = InteropEmu.ExpansionPortDevice.None;
|
|
|
|
|
public bool UseFourScore = false;
|
2016-07-09 15:58:49 -04:00
|
|
|
|
public bool AutoConfigureInput = true;
|
2016-02-05 23:14:27 -05:00
|
|
|
|
|
2016-07-19 16:30:18 -04:00
|
|
|
|
public bool DisplayInputPort1 = false;
|
|
|
|
|
public bool DisplayInputPort2 = false;
|
|
|
|
|
public bool DisplayInputPort3 = false;
|
|
|
|
|
public bool DisplayInputPort4 = false;
|
|
|
|
|
public InteropEmu.InputDisplayPosition DisplayInputPosition = InteropEmu.InputDisplayPosition.BottomRight;
|
|
|
|
|
public bool DisplayInputHorizontally = true;
|
|
|
|
|
|
2016-08-13 15:45:18 -04:00
|
|
|
|
[XmlElement(ElementName = "InputDevice")]
|
2016-02-05 23:14:27 -05:00
|
|
|
|
public List<ControllerInfo> Controllers = new List<ControllerInfo>();
|
|
|
|
|
|
|
|
|
|
public void InitializeDefaults()
|
|
|
|
|
{
|
|
|
|
|
while(Controllers.Count < 4) {
|
|
|
|
|
var controllerInfo = new ControllerInfo();
|
2016-06-12 22:22:17 -04:00
|
|
|
|
controllerInfo.ControllerType = Controllers.Count <= 1 ? InteropEmu.ControllerType.StandardController : InteropEmu.ControllerType.None;
|
2016-02-05 23:14:27 -05:00
|
|
|
|
|
2016-06-12 22:22:17 -04:00
|
|
|
|
if(Controllers.Count <= 1) {
|
|
|
|
|
controllerInfo.Keys.Add(new KeyMappings(Controllers.Count, 0));
|
|
|
|
|
controllerInfo.Keys.Add(new KeyMappings(Controllers.Count, 1));
|
2016-07-16 16:25:57 -04:00
|
|
|
|
controllerInfo.Keys.Add(new KeyMappings(Controllers.Count, 2));
|
2016-02-05 23:14:27 -05:00
|
|
|
|
}
|
|
|
|
|
Controllers.Add(controllerInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ApplyConfig()
|
|
|
|
|
{
|
|
|
|
|
InputInfo inputInfo = ConfigManager.Config.InputInfo;
|
|
|
|
|
|
|
|
|
|
InteropEmu.ExpansionPortDevice expansionDevice;
|
|
|
|
|
if(inputInfo.ConsoleType == ConsoleType.Nes) {
|
|
|
|
|
expansionDevice = InteropEmu.ExpansionPortDevice.None;
|
|
|
|
|
} else {
|
|
|
|
|
expansionDevice = inputInfo.ExpansionPortDevice;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-09 15:58:49 -04:00
|
|
|
|
InteropEmu.SetFlag(EmulationFlags.AutoConfigureInput, inputInfo.AutoConfigureInput);
|
2016-02-05 23:14:27 -05:00
|
|
|
|
InteropEmu.SetConsoleType(inputInfo.ConsoleType);
|
|
|
|
|
InteropEmu.SetExpansionDevice(inputInfo.ExpansionPortDevice);
|
2016-02-06 15:33:45 -05:00
|
|
|
|
bool hasFourScore = (inputInfo.ConsoleType == ConsoleType.Nes && inputInfo.UseFourScore) || (inputInfo.ConsoleType == ConsoleType.Famicom && expansionDevice == InteropEmu.ExpansionPortDevice.FourPlayerAdapter);
|
|
|
|
|
InteropEmu.SetFlag(EmulationFlags.HasFourScore, hasFourScore);
|
2016-02-05 23:14:27 -05:00
|
|
|
|
for(int i = 0; i < 4; i++) {
|
2016-02-06 15:33:45 -05:00
|
|
|
|
InteropEmu.SetControllerType(i, i < 2 || hasFourScore ? inputInfo.Controllers[i].ControllerType : InteropEmu.ControllerType.None);
|
2016-02-05 23:14:27 -05:00
|
|
|
|
InteropEmu.SetControllerKeys(i, inputInfo.Controllers[i].GetKeyMappingSet());
|
|
|
|
|
}
|
2016-07-19 16:30:18 -04:00
|
|
|
|
|
|
|
|
|
byte displayPorts = (byte)((inputInfo.DisplayInputPort1 ? 1 : 0) + (inputInfo.DisplayInputPort2 ? 2 : 0) + (inputInfo.DisplayInputPort3 ? 4 : 0) + (inputInfo.DisplayInputPort4 ? 8 : 0));
|
|
|
|
|
InteropEmu.SetInputDisplaySettings(displayPorts, inputInfo.DisplayInputPosition, inputInfo.DisplayInputHorizontally);
|
2016-02-05 23:14:27 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|