PVSnesLib  4.3.0
Documentation to code in C or ASM for the Nintendo SNES
Loading...
Searching...
No Matches
input.h File Reference

input support. More...

#include <snes/snestypes.h>
#include <snes/interrupt.h>

Go to the source code of this file.

Macros

#define mouse_L   0x01
 SNES Mouse Left button mask.
 
#define mouse_R   0x02
 SNES Mouse Right button mask.
 
#define padsCurrent(value)   (pad_keys[value])
 Return current value of selected pad.
 
#define padsDown(value)   (pad_keysdown[value])
 Return value of down keys for selected pad.
 
#define REG_JOYxLH(a)   (((vuint16 *)0x4218)[(a)])
 SNES Controllers I/O Ports - Automatic Reading. 4218h/4219h - JOY1L/JOY1H - Joypad 1 (gameport 1, pin 4) (R) 421Ah/421Bh - JOY2L/JOY2H - Joypad 2 (gameport 2, pin 4) (R) 421Ch/421Dh - JOY3L/JOY3H - Joypad 3 (gameport 1, pin 5) (R) 421Eh/421Fh - JOY4L/JOY4H - Joypad 4 (gameport 2, pin 5) (R)
 

Typedefs

typedef enum KEYPAD_BITS KEYPAD_BITS
 common values for pad input.
 
typedef enum MOUSE_SENSITIVITY MOUSE_SENSITIVITY
 Mouse sensitivity values.
 
typedef enum SUPERSCOPE_BITS SUPERSCOPE_BITS
 common values for SuperScope input.
 

Enumerations

enum  KEYPAD_BITS {
  KEY_A = BIT(7) , KEY_B = BIT(15) , KEY_SELECT = BIT(13) , KEY_START = BIT(12) ,
  KEY_RIGHT = BIT(8) , KEY_LEFT = BIT(9) , KEY_DOWN = BIT(10) , KEY_UP = BIT(11) ,
  KEY_R = BIT(4) , KEY_L = BIT(5) , KEY_X = BIT(6) , KEY_Y = BIT(14)
}
 common values for pad input. More...
 
enum  MOUSE_SENSITIVITY { MOUSE_SLOW = 0 , MOUSE_MEDIUM = 1 , MOUSE_FAST = 2 }
 Mouse sensitivity values. More...
 
enum  SUPERSCOPE_BITS {
  SSC_FIRE = BIT(15) , SSC_CURSOR = BIT(14) , SSC_PAUSE = BIT(12) , SSC_TURBO = BIT(13) ,
  SSC_OFFSCREEN = BIT(9) , SSC_NOISE = BIT(8)
}
 common values for SuperScope input. More...
 

Functions

void detectMouse (void)
 Check if Mouse is connected and populate snes_mouse (0 or 1 for connected)
 
void detectMPlay5 (void)
 Check if MultiPlayer5 is connected and populate snes_mplay5 (0 or 1 for connected)
 
void detectSuperScope (void)
 Detects if SuperScope is connected on Port 1 (second controller port on console) and populate snes_sscope (0 or 1 for connected)
 
void initMouse (u8 sensitivity)
 Enable mouse reading and set the initial mouse sensitivity.
 
void mouseCycleSensitivity (u16 port)
 Queue a cycle mouse sensitivity command for the next VBlank.
 
void mouseCycleSensitivityTwice (u16 port)
 Queue a cycle mouse sensitivity twice (decrementing the sensitivity) command for the next VBlank.
 
void mouseSetSensitivity (u16 port, u8 sensitivity)
 Queue a set mouse sensitivity command (to be executed on the next VBlank).
 
void padsClear (u16 value)
 Clear internal variables for selected pad.
 
unsigned short padsUp (u16 value)
 Return value of up keys for selected pad.
 

Variables

u8 mouse_x [2]
 Mouse horizontal displacement. daaaaaaa, d = direction (1: left, 0: right), a = acceleration.
 
u8 mouse_y [2]
 Mouse vertical displacement. daaaaaaa, d = direction (1: up, 0: down), a = acceleration.
 
u8 mouseButton [2]
 Mouse buttons that are pressed on this frame (Click mode).
 
u8 mouseConnect [2]
 1 if Mouse present
 
u8 mousePressed [2]
 Mouse buttons that are currently pressed, stays until is unpressed (Turbo mode).
 
u8 mousePreviousPressed [2]
 Mouse buttons held or pressed in the previous frame.
 
u8 mouseRequestChangeSensitivity [2]
 Request a change mouse sensitivity.
 
u8 mouseSensitivity [2]
 Mouse sensitivity.
 
u16 pad_keys [5]
 current pad value
 
u16 pad_keysdown [5]
 newly pressed down pad keys
 
u16 pad_keysold [5]
 previous pad value
 
u16 scope_centerh
 0x0000 is the center of the screen, positive values go to bottom right.
 
u16 scope_centerv
 0x0000 is the center of the screen, positive values go to bottom right.
 
u16 scope_down
 flags that are currently true.
 
u16 scope_held
 flagsthat have been true for a certain length of time.
 
u16 scope_holddelay
 Hold delay.
 
u16 scope_last
 flags that were true on the previous frame.
 
u16 scope_now
 flags that have become true this frame.
 
u16 scope_repdelay
 Repeat rate.
 
u16 scope_shoth
 Horizontal shot position, adjusted for aim.
 
u16 scope_shothraw
 Horizontal shot position, not adjusted.
 
u16 scope_shotv
 Vertical shot position, adjusted for aim.
 
u16 scope_shotvraw
 Vertical shot position, not adjusted.
 
u16 scope_sinceshot
 Number of frames elapsed since last shot was fired.
 
u8 snes_mouse
 1 if Mouse is going to be used
 
u8 snes_mplay5
 1 if MultiPlay5 is connected
 
u8 snes_sscope
 1 if SuperScope is connected
 

Detailed Description

input support.

The inputs are automatically read by the VBlank-ISR on non-lag frames.

Macro Definition Documentation

◆ padsCurrent

◆ padsDown

padsDown (   value)    (pad_keysdown[value])

Return value of down keys for selected pad.

Parameters
valuepad index to use (0-1 or 0-4 if multiplayer 5 connected)
Returns
unsigned short of the newly pressed down keys (0 -> 1 transition)
Examples
graphics/Effects/HDMAGradient/HDMAGradient.c.

◆ REG_JOYxLH

#define REG_JOYxLH (   a)    (((vuint16 *)0x4218)[(a)])

SNES Controllers I/O Ports - Automatic Reading. 4218h/4219h - JOY1L/JOY1H - Joypad 1 (gameport 1, pin 4) (R) 421Ah/421Bh - JOY2L/JOY2H - Joypad 2 (gameport 2, pin 4) (R) 421Ch/421Dh - JOY3L/JOY3H - Joypad 3 (gameport 1, pin 5) (R) 421Eh/421Fh - JOY4L/JOY4H - Joypad 4 (gameport 2, pin 5) (R)

Register Serial Default Bit Transfer Purpose Number______Order______(Joypads)_____ 15 1st B Button (1=Low=Pressed) 14 2nd Y Button 13 3rd Select Button 12 4th Start Button 11 5th Up 10 6th Down 9 7th Left 8 8th Right 7 9th A Button 6 10th X Button 5 11th L Button 4 12th R Button 3 13th 0 (High) 2 14th 0 (High) 1 15th 0 (High) 0 16th 0 (High)

When enabled, the SNES will read 16 bits from each of the 4 controller port data lines into registers $4218-f. This begins between H=32.5 and H=95.5 of the first V-Blank scanline, and ends 4224 master cycles later. Register $4212 bit 0 is set during this time. Specifically, it begins at H=74.5 on the first frame, and thereafter some multiple of 256 cycles after the start of the previous read that falls within the observed range.

Reading $4218-f during this time will read back incorrect values. The only reliable value is that no buttons pressed will return 0 (however, if buttons are pressed 0 could still be returned incorrectly). Presumably reading $4016/7 or writing $4016 during this time will also screw things up.

Typedef Documentation

◆ KEYPAD_BITS

typedef enum KEYPAD_BITS KEYPAD_BITS

common values for pad input.

common values that can be used to test auto pad. enum values for the pad buttons.

◆ MOUSE_SENSITIVITY

Mouse sensitivity values.

enum values for the mouse sensitivity.

◆ SUPERSCOPE_BITS

common values for SuperScope input.

enum values for the SuperScope buttons and flags.

Enumeration Type Documentation

◆ KEYPAD_BITS

common values for pad input.

common values that can be used to test auto pad. enum values for the pad buttons.

Enumerator
KEY_A 

pad A button.

KEY_B 

pad B button.

KEY_SELECT 

pad SELECT button.

KEY_START 

pad START button.

KEY_RIGHT 

pad RIGHT button.

KEY_LEFT 

pad LEFT button.

KEY_DOWN 

pad DOWN button.

KEY_UP 

pad UP button.

KEY_R 

Right shoulder button.

KEY_L 

Left shoulder button.

KEY_X 

pad X button.

KEY_Y 

pad Y button.

◆ MOUSE_SENSITIVITY

Mouse sensitivity values.

enum values for the mouse sensitivity.

Enumerator
MOUSE_SLOW 

slow sensitivity

MOUSE_MEDIUM 

medium sensitivity

MOUSE_FAST 

fast sensitivity

◆ SUPERSCOPE_BITS

common values for SuperScope input.

enum values for the SuperScope buttons and flags.

Enumerator
SSC_FIRE 

superscope FIRE button.

SSC_CURSOR 

superscope CURSOR button.

SSC_PAUSE 

superscope PAUSE button.

SSC_TURBO 

superscope TURBO flag.

SSC_OFFSCREEN 

superscope OFFSCREEN flag.

SSC_NOISE 

superscope NOISE flag.

Function Documentation

◆ detectMPlay5()

detectMPlay5 ( void  )

Check if MultiPlayer5 is connected and populate snes_mplay5 (0 or 1 for connected)

CAUTION: REG_WRIO ($4201) must not be written to while MultiPlayer5 is active. (Bit 7 of REG_WRIO must be set when Auto Joy reads the controllers, shortly after the VBlank Period starts.)

Examples
input/multiplay5/multiplay5.c.

◆ initMouse()

void initMouse ( u8  sensitivity)

Enable mouse reading and set the initial mouse sensitivity.

Initialises mouse variables and enable mouse reading in the VBlank ISR.

Parameters
sensitivitysensitivity to use when the mouse is connected to the console (has no effect on a Hyperkin clone mouse)
Examples
input/mouse/mouse.c.

◆ mouseCycleSensitivity()

void mouseCycleSensitivity ( u16  port)

Queue a cycle mouse sensitivity command for the next VBlank.

Parameters
portthe port the mouse is connected to (0 or 1).

CAUTION:

◆ mouseCycleSensitivityTwice()

void mouseCycleSensitivityTwice ( u16  port)

Queue a cycle mouse sensitivity twice (decrementing the sensitivity) command for the next VBlank.

Parameters
portthe port the mouse is connected to (0 or 1).

CAUTION:

◆ mouseSetSensitivity()

void mouseSetSensitivity ( u16  port,
u8  sensitivity 
)

Queue a set mouse sensitivity command (to be executed on the next VBlank).

Parameters
portthe port the mouse is connected to (0 or 1).
sensitivitythe sensitivity to set the mouse to (0 - 2).

CAUTION:

  • The changes to mouseSensitivity are delayed one frame.
  • A sensitivity value of 3 is invalid.
  • This function will override any pending mouseRequestChangeSensitivity commands.
  • This function has no effect on the Hyperkin clone mouse.
Examples
input/mouse/mouse.c.

◆ padsClear()

padsClear ( u16  value)

Clear internal variables for selected pad.

Parameters
valuepad index to use (0-1 or 0-4 if multiplayer 5 connected)

◆ padsUp()

padsUp ( u16  value)

Return value of up keys for selected pad.

Parameters
valuepad index to use (0-1 or 0-4 if multiplayer 5 connected)
Returns
unsigned short of the released keys (1 -> 0 transition)

Variable Documentation

◆ mouseRequestChangeSensitivity

u8 mouseRequestChangeSensitivity[2]
extern

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.

◆ mouseSensitivity

u8 mouseSensitivity[2]
extern

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.

Examples
input/mouse/mouse.c.