diff --git a/source/Cosmos.HAL2/PS2Mouse.cs b/source/Cosmos.HAL2/PS2Mouse.cs
index 8ff18518b8..4f39e6df6e 100644
--- a/source/Cosmos.HAL2/PS2Mouse.cs
+++ b/source/Cosmos.HAL2/PS2Mouse.cs
@@ -36,7 +36,7 @@ enum Command : byte
#region Properties
- private bool HasScrollWheel => mouseID == 3 || mouseID == 4;
+ public bool HasScrollWheel => mouseID == 3 || mouseID == 4;
public byte PS2Port { get; }
@@ -132,13 +132,13 @@ public void HandleMouse(ref INTs.IRQContext context)
mouseCycle++;
}
}
+ else if (mouseCycle == 3)
+ {
+ mouseByte[3] = IOPort.Read8(Core.IOGroup.PS2Controller.Data);
+ mouseCycle++;
+ }
- // TODO: move conditions to the if statement when stack corruption detection
- // works better for complex conditions
- var xTest1 = mouseCycle == 2 && !HasScrollWheel;
- var xTest2 = mouseCycle == 3 && HasScrollWheel;
-
- if (xTest1 || xTest2)
+ if ((mouseCycle == 2 && !HasScrollWheel) || (mouseCycle == 4 && HasScrollWheel))
{
int xDeltaX = 0;
int xDeltaY = 0;
@@ -166,7 +166,8 @@ public void HandleMouse(ref INTs.IRQContext context)
if (HasScrollWheel)
{
- var xScrollWheelByte = mouseByte[3] & 0x0F;
+ var xScrollWheelByte = mouseByte[3];
+
xScrollWheel = (xScrollWheelByte & 0b1000) == 0 ? xScrollWheelByte : xScrollWheelByte | ~0x0F;
if (mouseID == 4)
@@ -231,4 +232,4 @@ private void SendCommand(Command aCommand, byte? aByte = null)
#endregion
}
-}
\ No newline at end of file
+}
diff --git a/source/Cosmos.System2/MouseManager.cs b/source/Cosmos.System2/MouseManager.cs
index 765e7bd5f7..db704184ac 100644
--- a/source/Cosmos.System2/MouseManager.cs
+++ b/source/Cosmos.System2/MouseManager.cs
@@ -38,6 +38,8 @@ public static class MouseManager
private static int deltaX;
private static int deltaY;
+ private static int scrollDelta;
+
///
/// The X location of the mouse.
///
@@ -144,6 +146,18 @@ internal set
}
}
+ ///
+ /// The 'delta' for the mouse scroll wheel. Needs to be manually reset.
+ ///
+ public static int ScrollDelta {
+ get {
+ return scrollDelta;
+ }
+ internal set => scrollDelta = value;
+ }
+
+ public static bool ScrollWheelPresent => mouseList.Exists(x => (x is PS2Mouse xPs2 && xPs2.HasScrollWheel));
+
#endregion
#region Methods
@@ -167,12 +181,21 @@ public static void HandleMouse(int deltaX, int deltaY, int mouseState, int scrol
DeltaX = deltaX;
DeltaY = deltaY;
+ ScrollDelta += scrollWheel;
+
X = (uint)Math.Clamp(X + (MouseSensitivity * deltaX), 0, ScreenWidth - 1);
Y = (uint)Math.Clamp(Y + (MouseSensitivity * deltaY), 0, ScreenHeight - 1);
LastMouseState = MouseState;
MouseState = (MouseState)mouseState;
}
+ ///
+ /// Reset the scroll delta to 0.
+ ///
+ public static void ResetScrollDelta() {
+ ScrollDelta = 0;
+ }
+
///
/// Add mouse to the mouse list.
///