Added control pad to Kempston interface
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using Core; // <-- This gives us access to SpectrumMachine
|
||||
using Core;
|
||||
using Core.Io;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing.Imaging;
|
||||
using Vortice.XInput;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
@@ -17,12 +17,6 @@ namespace Desktop
|
||||
private Bitmap _screenBitmap = null!;
|
||||
private string _baseTitle = "";
|
||||
|
||||
// ====================================================================
|
||||
// DEBUGGER PASS-THROUGHS
|
||||
// ====================================================================
|
||||
// The DebuggerForm still looks at Form1 for data. These properties act
|
||||
// as a bridge, instantly passing the request down to the actual engine!
|
||||
|
||||
public ushort? Breakpoint
|
||||
{
|
||||
get => _machine?.Breakpoint;
|
||||
@@ -84,11 +78,12 @@ namespace Desktop
|
||||
|
||||
private void Machine_OnFrameReady(int[] pixels)
|
||||
{
|
||||
// We must use BeginInvoke because the Machine is running on a background thread!
|
||||
PollGamepad();
|
||||
|
||||
this.BeginInvoke((System.Windows.Forms.MethodInvoker)delegate
|
||||
{
|
||||
UpdateScreenBitmap(pixels);
|
||||
this.Invalidate(); // Triggers OnPaint
|
||||
this.Invalidate();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -384,6 +379,35 @@ namespace Desktop
|
||||
_machine.Resume();
|
||||
}
|
||||
|
||||
|
||||
//Control pad method
|
||||
|
||||
private void PollGamepad()
|
||||
{
|
||||
// Only check Player 1 (Index 0)
|
||||
if (XInput.GetState(0, out State state))
|
||||
{
|
||||
byte kempston = 0x00;
|
||||
Gamepad gamepad = state.Gamepad;
|
||||
|
||||
// Map D-Pad to Kempston Bits
|
||||
if ((gamepad.Buttons & GamepadButtons.DPadRight) != 0) kempston |= 0x01; // Bit 0
|
||||
if ((gamepad.Buttons & GamepadButtons.DPadLeft) != 0) kempston |= 0x02; // Bit 1
|
||||
if ((gamepad.Buttons & GamepadButtons.DPadDown) != 0) kempston |= 0x04; // Bit 2
|
||||
if ((gamepad.Buttons & GamepadButtons.DPadUp) != 0) kempston |= 0x08; // Bit 3
|
||||
|
||||
// Map A Button (or whichever you prefer) to Fire
|
||||
if ((gamepad.Buttons & GamepadButtons.A) != 0) kempston |= 0x10; // Bit 4
|
||||
|
||||
// Send the final byte down to the emulator core!
|
||||
_machine.IoBus.KempstonState = kempston;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Controller disconnected, zero it out
|
||||
_machine.IoBus.KempstonState = 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user