diff --git a/Breaknes/Breaknes/Breaknes.csproj b/Breaknes/Breaknes/Breaknes.csproj index e249139c..800f8377 100644 --- a/Breaknes/Breaknes/Breaknes.csproj +++ b/Breaknes/Breaknes/Breaknes.csproj @@ -18,6 +18,7 @@ + diff --git a/Breaknes/Breaknes/FormMain.cs b/Breaknes/Breaknes/FormMain.cs index a99a396f..14eb5be5 100644 --- a/Breaknes/Breaknes/FormMain.cs +++ b/Breaknes/Breaknes/FormMain.cs @@ -10,9 +10,10 @@ public partial class FormMain : Form static extern bool AllocConsole(); private BoardControl board = new(); - private VideoRender vid_out = null; - private AudioRender snd_out = null; - private string original_title; + private VideoRender? vid_out = null; + private AudioRender? snd_out = null; + private InputProcessor? input = null; + private string original_title = ""; private List debuggers = new(); public FormMain() @@ -74,6 +75,7 @@ private void loadROMDumpToolStripMenuItem_Click(object sender, EventArgs e) vid_out = new(OnRenderField, settings.DumpVideo, settings.DumpVideoDir, rom_name); vid_out.SetOutputPictureBox(pictureBox1); snd_out = new(Handle, settings.DumpAudio, settings.DumpAudioDir, rom_name, settings.IIR, settings.CutoffFrequency); + input = new InputProcessor(); board.Paused = debuggers.Count != 0; foreach (var inst in debuggers) @@ -125,6 +127,11 @@ private void Debugger_FormClosed(object? sender, FormClosedEventArgs e) private void OnRenderField() { + if (input != null) + { + input.PollDevices(); + } + foreach (var inst in debuggers) { inst.UpdateOnRenderField(); diff --git a/Breaknes/Breaknes/InputProcessing.cs b/Breaknes/Breaknes/InputProcessing.cs new file mode 100644 index 00000000..252eb0fe --- /dev/null +++ b/Breaknes/Breaknes/InputProcessing.cs @@ -0,0 +1,78 @@ +using SharpDX.DirectInput; + +// Demo: +// https://github.com/sharpdx/SharpDX-Samples/blob/master/Desktop/DirectInput/JoystickApp/Program.cs + +namespace Breaknes +{ + + public class InputProcessor + { + Keyboard? keyboard = null; + Joystick? joystick = null; + + public InputProcessor() + { + var directInput = new DirectInput(); + + // Find keyboard + keyboard = new Keyboard(directInput); + keyboard.Properties.BufferSize = 128; + keyboard.Acquire(); + + // Find a Joystick Guid + var joystickGuid = Guid.Empty; + + foreach (var deviceInstance in directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices)) + joystickGuid = deviceInstance.InstanceGuid; + + // If Gamepad not found, look for a Joystick + if (joystickGuid == Guid.Empty) + foreach (var deviceInstance in directInput.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices)) + joystickGuid = deviceInstance.InstanceGuid; + + // If Joystick not found, throws an error + if (joystickGuid == Guid.Empty) + { + return; + } + + // Instantiate the joystick + joystick = new Joystick(directInput, joystickGuid); + + Console.WriteLine("Found Joystick/Gamepad with GUID: {0}", joystickGuid); + + // Query all suported ForceFeedback effects + var allEffects = joystick.GetEffects(); + foreach (var effectInfo in allEffects) + Console.WriteLine("Effect available {0}", effectInfo.Name); + + // Set BufferSize in order to use buffered data. + joystick.Properties.BufferSize = 128; + + // Acquire the joystick + joystick.Acquire(); + } + + public void PollDevices() + { + if (keyboard != null) + { + keyboard.Poll(); + var datas = keyboard.GetBufferedData(); + foreach (var state in datas) + Console.WriteLine(state); + } + + if (joystick != null) + { + joystick.Poll(); + var datas = joystick.GetBufferedData(); + foreach (var state in datas) + Console.WriteLine(state); + } + } + + } + +}