Skip to content

Commit

Permalink
Merge pull request #291 from undisbeliever/fix-mouse-with-new-api
Browse files Browse the repository at this point in the history
Fix Hyperkin mouse and new mouse API
  • Loading branch information
alekmaul authored Aug 18, 2024
2 parents 8f64843 + 56c038b commit ad4957a
Show file tree
Hide file tree
Showing 10 changed files with 950 additions and 339 deletions.
147 changes: 115 additions & 32 deletions pvsneslib/include/snes/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,36 +76,75 @@ typedef enum SUPERSCOPE_BITS
SSC_NOISE = BIT(8), //!< superscope NOISE flag.
} SUPERSCOPE_BITS;

/*!
* \brief Mouse sensitivity values
*
* enum values for the mouse sensitivity.
*/
typedef enum MOUSE_SENSITIVITY
{
MOUSE_SLOW = 0, //!< slow sensitivity
MOUSE_MEDIUM = 1, //!< medium sensitivity
MOUSE_FAST = 2, //!< fast sensitivity
} MOUSE_SENSITIVITY;

extern u16 pad_keys[5]; //!< current pad value
extern u16 pad_keysold[5]; //!< previous pad value
extern u16 pad_keysdown[5]; //!< newly pressed down pad keys

extern u8 snes_mplay5; /*! \brief 1 if MultiPlay5 is connected */
extern u8 snes_mouse; /*! \brief 1 if Mouse is going to be used */
extern u8 snes_sscope; /*! \brief 1 if SuperScope is connected */

extern u8 mouseConnect[2]; /*! \brief 1 if Mouse present */
extern u8 mouseButton[2]; /*! \brief 1 if button is pressed, stays for a bit and then it gets released (Click mode). */
extern u8 mousePressed[2]; /*! \brief 1 if button is pressed, stays until is unpressed (Turbo mode). */
extern u8 mouse_x[2], mouse_y[2]; /*! \brief Mouse acceleration. daaaaaaa, d = direction (0: up/left, 1: down/right), a = acceleration. */
extern u8 mouseSpeedSet[2]; /*! \brief Mouse speed setting. 0: slow, 1: normal, 2: fast */

#define mouse_L 0x01 /*! \brief SNES Mouse Left button mask.*/
#define mouse_R 0x02 /*! \brief SNES Mouse Right button mask.*/

extern u16 scope_holddelay; /*! \brief Hold delay. */
extern u16 scope_repdelay; /*! \brief Repeat rate. */
extern u16 scope_shothraw; /*! \brief Horizontal shot position, not adjusted. */
extern u16 scope_shotvraw; /*! \brief Vertical shot position, not adjusted. */
extern u16 scope_shoth; /*! \brief Horizontal shot position, adjusted for aim. */
extern u16 scope_shotv; /*! \brief Vertical shot position, adjusted for aim. */
extern u16 scope_centerh; /*! \brief 0x0000 is the center of the screen, positive values go to bottom right. */
extern u16 scope_centerv; /*! \brief 0x0000 is the center of the screen, positive values go to bottom right. */
extern u16 scope_down; /*! \brief flags that are currently true.*/
extern u16 scope_now; /*! \brief flags that have become true this frame.*/
extern u16 scope_held; /*! \brief flagsthat have been true for a certain length of time.*/
extern u16 scope_last; /*! \brief flags that were true on the previous frame.*/
extern u16 scope_sinceshot; /*! \brief Number of frames elapsed since last shot was fired.*/
extern u8 snes_mplay5; /*!< \brief 1 if MultiPlay5 is connected */
extern u8 snes_mouse; /*!< \brief 1 if Mouse is going to be used */
extern u8 snes_sscope; /*!< \brief 1 if SuperScope is connected */

extern u8 mouseConnect[2]; /*!< \brief 1 if Mouse present */
extern u8 mouseButton[2]; /*!< \brief Mouse buttons that are pressed on this frame (Click mode). */
extern u8 mousePressed[2]; /*!< \brief Mouse buttons that are currently pressed, stays until is unpressed (Turbo mode). */
extern u8 mousePreviousPressed[2];/*!< \brief Mouse buttons held or pressed in the previous frame */
extern u8 mouse_x[2]; /*!< \brief Mouse horizontal displacement. daaaaaaa, d = direction (1: left, 0: right), a = acceleration. */
extern u8 mouse_y[2]; /*!< \brief Mouse vertical displacement. daaaaaaa, d = direction (1: up, 0: down), a = acceleration. */

/*!
* \brief Mouse sensitivity
*
* * When a mouse is connected to the port: sensitivity bits read from the mouse.
* * When no mouse is connected: The sensitivity to set the mouse to when the mouse is connected to the console.
*
* CAUTION: The Hyperkin clone mouse ignores sensitivity changes and always reports a sensitivity of 0.
*/
extern u8 mouseSensitivity[2];

/*!
* \brief Request a change mouse sensitivity.
*
* To prevent auto-joypad read corruption the change sensitivity commands are delayed until the
* next non-lag VBlank ISR (after the mouse data has been read).
*
* Values:
* * `0x00`: No changes to mouse sensitivity.
* * `0x01`: Cycle the mouse sensitivity once.
* * `0x02-0x7f`: Cycle the mouse sensitivity twice.
* * `0x80-0xff`: Set the sensitivity to `value & 3`.
*
* CAUTION: The Hyperkin clone mouse ignores sensitivity changes and always reports a sensitivity of 0.
*/
extern u8 mouseRequestChangeSensitivity[2];

#define mouse_L 0x01 /*!< \brief SNES Mouse Left button mask.*/
#define mouse_R 0x02 /*!< \brief SNES Mouse Right button mask.*/

extern u16 scope_holddelay; /*!< \brief Hold delay. */
extern u16 scope_repdelay; /*!< \brief Repeat rate. */
extern u16 scope_shothraw; /*!< \brief Horizontal shot position, not adjusted. */
extern u16 scope_shotvraw; /*!< \brief Vertical shot position, not adjusted. */
extern u16 scope_shoth; /*!< \brief Horizontal shot position, adjusted for aim. */
extern u16 scope_shotv; /*!< \brief Vertical shot position, adjusted for aim. */
extern u16 scope_centerh; /*!< \brief 0x0000 is the center of the screen, positive values go to bottom right. */
extern u16 scope_centerv; /*!< \brief 0x0000 is the center of the screen, positive values go to bottom right. */
extern u16 scope_down; /*!< \brief flags that are currently true.*/
extern u16 scope_now; /*!< \brief flags that have become true this frame.*/
extern u16 scope_held; /*!< \brief flagsthat have been true for a certain length of time.*/
extern u16 scope_last; /*!< \brief flags that were true on the previous frame.*/
extern u16 scope_sinceshot; /*!< \brief Number of frames elapsed since last shot was fired.*/

/*! \def REG_JOYxLH
Expand Down Expand Up @@ -192,15 +231,59 @@ void detectMPlay5(void);
*/
void detectMouse(void);

/*! \fn mouseSpeedChange(u8 port)
\brief Set mouse hardware speed (populate mouseSpeed[] first).
\param port Specify wich port to use (0-1)
*/
void mouseSpeedChange(u8 port);

/*! \fn detectSuperScope(void)
\brief Detects if SuperScope is connected on Port 1 (second controller port on console) and populate snes_sscope (0 or 1 for connected)
*/
void detectSuperScope(void);


/*!
* \brief Enable mouse reading and set the initial mouse sensitivity
*
* Initialises mouse variables and enable mouse reading in the VBlank ISR.
*
* \param sensitivity sensitivity to use when the mouse is connected to the console
* (has no effect on a Hyperkin clone mouse)
*/
void initMouse(u8 sensitivity);


/*!
* \brief Queue a cycle mouse sensitivity command for the next VBlank.
*
* \param port the port the mouse is connected to (0 or 1).
*
* CAUTION:
* * The changes to @ref mouseSensitivity are delayed one frame.
* * This function will override any pending @ref mouseRequestChangeSensitivity commands.
* * This function has no effect on the Hyperkin clone mouse.
*/
void mouseCycleSensitivity(u16 port);

/*!
* \brief Queue a cycle mouse sensitivity twice (decrementing the sensitivity) command for the next VBlank.
*
* \param port the port the mouse is connected to (0 or 1).
*
* CAUTION:
* * The changes to @ref mouseSensitivity are delayed one frame.
* * This function will override any pending @ref mouseRequestChangeSensitivity commands.
* * This function has no effect on the Hyperkin clone mouse.
*/
void mouseCycleSensitivityTwice(u16 port);

/*!
* \brief Queue a set mouse sensitivity command (to be executed on the next VBlank).
*
* \param port the port the mouse is connected to (0 or 1).
* \param sensitivity the sensitivity to set the mouse to (0 - 2).
*
* CAUTION:
* * The changes to @ref mouseSensitivity are delayed one frame.
* * A sensitivity value of 3 is invalid.
* * This function will override any pending @ref mouseRequestChangeSensitivity commands.
* * This function has no effect on the Hyperkin clone mouse.
*/
void mouseSetSensitivity(u16 port, u8 sensitivity);

#endif // SNES_PADS_INCLUDE
Loading

0 comments on commit ad4957a

Please sign in to comment.