Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support scrolling properly #2867

Merged
merged 6 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions source/Cosmos.HAL2/PS2Mouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down Expand Up @@ -131,12 +131,15 @@ public void HandleMouse(ref INTs.IRQContext context)
{
mouseCycle++;
}
}else if (mouseCycle == 3) {
GoldenretriverYT marked this conversation as resolved.
Show resolved Hide resolved
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove these two lines

var xTest2 = mouseCycle == 3 && HasScrollWheel;
var xTest2 = mouseCycle == 4 && HasScrollWheel;

if (xTest1 || xTest2)
GoldenretriverYT marked this conversation as resolved.
Show resolved Hide resolved
{
Expand Down Expand Up @@ -166,7 +169,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)
Expand Down
23 changes: 23 additions & 0 deletions source/Cosmos.System2/MouseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public static class MouseManager
private static int deltaX;
private static int deltaY;

private static int scrollDelta;

/// <summary>
/// The X location of the mouse.
/// </summary>
Expand Down Expand Up @@ -144,6 +146,18 @@ internal set
}
}

/// <summary>
/// The 'delta' for the mouse scroll wheel. Needs to be manually reset.
/// </summary>
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
Expand All @@ -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;
}

/// <summary>
/// Reset the scroll delta to 0.
/// </summary>
public static void ResetScrollDelta() {
ScrollDelta = 0;
}

/// <summary>
/// Add mouse to the mouse list.
/// </summary>
Expand Down
Loading