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

Fix Hyperkin mouse and new mouse API #291

Merged
merged 22 commits into from
Aug 18, 2024

Conversation

undisbeliever
Copy link
Contributor

This PR serves two purposes.

First, it fixes multiple bugs in the mouse code:

Secondly, it changes the mouse API.
This new API delays all change-mouse-sensitivity commands to the VBlank ISR to prevent a potential timing-conflict that can corrupt the joypad registers (and the mouse reading code).

  • An initMouse(u8 sensitivity) function has been added to simplify mouse initialisation.

  • snes_mouse is no-longer cleared when the mouse is disconnected

    • If the developer was unaware snes_mouse was cleared by the VBlank ISR then the player could lock the game if the mouse was ever disconnected.
    • snes_mouse can no-longer be used to detect if the mouse has been disconnected from the console. The developer will have to check the mouseConnect[] variable instead.
  • The mouseSpeedSet variable and the mouseSpeedChange() function have been removed and replaced with a
    mouseRequestChangeSensitivity variable that will signal to the VBlank ISR that the MainLoop wants to either:

    • Cycle the mouse sensitivity once.
    • Cycle the mouse sensitivity twice (decrementing the sensitivity).
    • Setting the mouse sensitivity to a specific value.
  • A mouseSensitivity variable has been added that serves three purposes:

    1. Allows the developer to read the reported mouse sensitivity.
    2. Allows the developer to set the initial mouse sensitivity.
    3. Restores the mouse sensitivity when the mouse is disconnected, then reconnected.
  • Three helper functions have been added to simplify the mouseRequestChangeSensitivity writes:

    • void mouseCycleSensitivity(u16 port)
    • void mouseCycleSensitivityTwice(u16 port)
    • void mouseSetSensitivity(u16 port, u16 sensitivity)

The existing mouse example has been updated to the new API a new mouse example (mouse-data-test) has been added.

The two mouse examples in this PR have been tested on my 1-chip Super Famicom console with a Nintendo mouse and a Hyperkin Hyper Click Retro Style Mouse.

The Hyperkin mouse always outputs a sensitivity of 0, which
will cause the mouseSpeedChange loop to always timeout.

Decreasing the maximum number of loops will reduce CPU usage when using
a Hyperkin mouse.
Also removes the unread private `mouse_sp` variable
and into mouseSpeedChange, since mouseConnect is always true when
speed_change is called by the VBlank ISR.
if a non-standard controller is connected to the other controller port.
If the developer was unaware `snes_mouse` was cleared by the VBlank ISR
then the player could lock the game if the mouse was ever disconnected.

`snes_mouse` can no-longer be used to detect if the mouse has been
disconnected from the console.  The developer will have to check the
`mouseConnect[]` variable instead.
Fixes a typo in the `mouseSpeedSet` mask.
… API)

The old `mouseSpeedChange(u8 port)` function has a timing conflict with
the auto-joypad-read.  The automatic joypad read must not start while
the CPU is in the middle of the `mouseSpeedChange()` function.

Delaying all mouse sensitivity changes to the VBlank ISR will remove
this timing conflict and ensure the mouse sensitivity is cycled at the
correct time.

This commit removes the old `mouseSpeedSet` variable and the
`mouseSpeedChange()` function, replacing them with a
`mouseRequestChangeSensitivity` variable that will signal to
`_MouseData` that the MainLoop wants to either:
 * Cycle the mouse sensitivity once.
 * Cycle the mouse sensitivity twice (decrementing the sensitivity).
 * Setting the mouse sensitivity to a specific value.

This commit also adds a `mouseSensitivity` variable that serves three
purposes:
 1. Allows the developer to read the reported mouse sensitivity.
 2. Allows the developer to set the initial mouse sensitivity.
 3. Restore the mouse sensitivity when the mouse is disconnected, then
    reconnected.

Three helper functions have been added to simplify the
`mouseRequestChangeSensitivity` writes:
 * void mouseCycleSensitivity(u16 port)
 * void mouseCycleSensitivityTwice(u16 port)
 * void mouseSetSensitivity(u16 port, u16 sensitivity)

The two mouse examples have been modified to use the new mouse
sensitivity functions and to display the reported mouse sensitivity.
not matching the mouseSetSensitivity comment in
`pvsneslib/source/input.asm`.
Also added a few notes about the mouse buttons and mouse sensitivity
@RetroAntho RetroAntho changed the base branch from master to develop August 14, 2024 20:21
@alekmaul alekmaul merged commit ad4957a into alekmaul:develop Aug 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Potential Hyperkin mouse read errors with FastROM
2 participants