diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesControllerDeck.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesControllerDeck.cs index 3741468951..d5e86c4a73 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesControllerDeck.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesControllerDeck.cs @@ -39,6 +39,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES List tmp; Definition = ControllerDefinitionMerger.GetMerged(_ports.Select(p => p.Definition), out tmp); _mergers = tmp.ToArray(); + + // add buttons that the core itself will handle + Definition.BoolButtons.Add("Reset"); + Definition.BoolButtons.Add("Power"); + Definition.Name = "SNES Controller"; } public void NativeInit(LibsnesApi api) @@ -115,7 +120,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES } } - public class SnesMultitapController: ILibsnesController + public class SnesMultitapController : ILibsnesController { public LibsnesApi.SNES_INPUT_PORT PortType { get; } = LibsnesApi.SNES_INPUT_PORT.Multitap; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs index aa311ff57f..86d1ba2efd 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs @@ -67,8 +67,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES ScanlineHookManager = new MyScanlineHookManager(this); //TODO: set correct port inputs from sync settings - api.SetInputPortBeforeInit(0, LibsnesApi.SNES_INPUT_PORT.Joypad); - api.SetInputPortBeforeInit(1, LibsnesApi.SNES_INPUT_PORT.Joypad); + _controllerDeck = new LibsnesControllerDeck(LibsnesControllerDeck.ControllerType.Gamepad, + LibsnesControllerDeck.ControllerType.Gamepad); + _controllerDeck.NativeInit(api); api.CMD_init(); @@ -227,6 +228,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES public bool IsSGB { get; private set; } + private LibsnesControllerDeck _controllerDeck; + /// disable all external callbacks. the front end should not even know the core is frame advancing bool nocallbacks = false; @@ -507,39 +510,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES /// for regular controllers, one bit D0 of button status. for other controls, varying ranges depending on id ushort snes_input_state(int port, int device, int index, int id) { - // as this is implemented right now, only P1 and P2 normal controllers work - - // port = 0, oninputpoll = 2: left port was strobed - // port = 1, oninputpoll = 3: right port was strobed - - // InputCallbacks.Call(); - //Console.WriteLine("{0} {1} {2} {3}", port, device, index, id); - - string key = "P" + (1 + port) + " "; - if ((LibsnesApi.SNES_DEVICE)device == LibsnesApi.SNES_DEVICE.JOYPAD) - { - switch ((LibsnesApi.SNES_DEVICE_ID)id) - { - case LibsnesApi.SNES_DEVICE_ID.JOYPAD_A: key += "A"; break; - case LibsnesApi.SNES_DEVICE_ID.JOYPAD_B: key += "B"; break; - case LibsnesApi.SNES_DEVICE_ID.JOYPAD_X: key += "X"; break; - case LibsnesApi.SNES_DEVICE_ID.JOYPAD_Y: key += "Y"; break; - case LibsnesApi.SNES_DEVICE_ID.JOYPAD_UP: key += "Up"; break; - case LibsnesApi.SNES_DEVICE_ID.JOYPAD_DOWN: key += "Down"; break; - case LibsnesApi.SNES_DEVICE_ID.JOYPAD_LEFT: key += "Left"; break; - case LibsnesApi.SNES_DEVICE_ID.JOYPAD_RIGHT: key += "Right"; break; - case LibsnesApi.SNES_DEVICE_ID.JOYPAD_L: key += "L"; break; - case LibsnesApi.SNES_DEVICE_ID.JOYPAD_R: key += "R"; break; - case LibsnesApi.SNES_DEVICE_ID.JOYPAD_SELECT: key += "Select"; break; - case LibsnesApi.SNES_DEVICE_ID.JOYPAD_START: key += "Start"; break; - default: return 0; - } - - return (ushort)(Controller.IsPressed(key) ? 1 : 0); - } - - return 0; - + return _controllerDeck.CoreInputState(Controller, port, device, index, id); } void snes_input_poll()