PVSnesLib
4.3.0
Documentation to code in C or ASM for the Nintendo SNES
|
input support. More...
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 | |
input support.
The inputs are automatically read by the VBlank-ISR on non-lag frames.
padsCurrent | ( | value | ) | (pad_keys[value]) |
Return current value of selected pad.
value | pad index to use (0-1 or 0-4 if multiplayer 5 connected) |
padsDown | ( | value | ) | (pad_keysdown[value]) |
Return value of down keys for selected pad.
value | pad index to use (0-1 or 0-4 if multiplayer 5 connected) |
#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 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.
typedef enum MOUSE_SENSITIVITY MOUSE_SENSITIVITY |
Mouse sensitivity values.
enum values for the mouse sensitivity.
typedef enum SUPERSCOPE_BITS SUPERSCOPE_BITS |
common values for SuperScope input.
enum values for the SuperScope buttons and flags.
enum KEYPAD_BITS |
common values for pad input.
common values that can be used to test auto pad. enum values for the pad buttons.
enum MOUSE_SENSITIVITY |
enum SUPERSCOPE_BITS |
common values for SuperScope input.
enum values for the SuperScope buttons and flags.
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.)
void initMouse | ( | u8 | sensitivity | ) |
Enable mouse reading and set the initial mouse sensitivity.
Initialises mouse variables and enable mouse reading in the VBlank ISR.
sensitivity | sensitivity to use when the mouse is connected to the console (has no effect on a Hyperkin clone mouse) |
void mouseCycleSensitivity | ( | u16 | port | ) |
Queue a cycle mouse sensitivity command for the next VBlank.
port | the port the mouse is connected to (0 or 1). |
CAUTION:
void mouseCycleSensitivityTwice | ( | u16 | port | ) |
Queue a cycle mouse sensitivity twice (decrementing the sensitivity) command for the next VBlank.
port | the port the mouse is connected to (0 or 1). |
CAUTION:
void mouseSetSensitivity | ( | u16 | port, |
u8 | sensitivity | ||
) |
Queue a set mouse sensitivity command (to be executed on the next VBlank).
port | the port the mouse is connected to (0 or 1). |
sensitivity | the sensitivity to set the mouse to (0 - 2). |
CAUTION:
padsClear | ( | u16 | value | ) |
Clear internal variables for selected pad.
value | pad index to use (0-1 or 0-4 if multiplayer 5 connected) |
padsUp | ( | u16 | value | ) |
Return value of up keys for selected pad.
value | pad index to use (0-1 or 0-4 if multiplayer 5 connected) |
|
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.
|
extern |
Mouse sensitivity.
CAUTION: The Hyperkin clone mouse ignores sensitivity changes and always reports a sensitivity of 0.