Loading...
Searching...
No Matches
input.h File Reference

SNES Controller Input. More...

#include <snes/types.h>

Go to the source code of this file.

Macros

#define KEY_A   BIT(7)
 
#define KEY_B   BIT(15)
 
#define KEY_DOWN   BIT(10)
 
#define KEY_DPAD   (KEY_UP | KEY_DOWN | KEY_LEFT | KEY_RIGHT)
 All D-pad directions.
 
#define KEY_FACE   (KEY_A | KEY_B | KEY_X | KEY_Y)
 All face buttons.
 
#define KEY_L   BIT(5)
 
#define KEY_LEFT   BIT(9)
 
#define KEY_R   BIT(4)
 
#define KEY_RIGHT   BIT(8)
 
#define KEY_SELECT   BIT(13)
 
#define KEY_START   BIT(12)
 
#define KEY_UP   BIT(11)
 
#define KEY_X   BIT(6)
 
#define KEY_Y   BIT(14)
 
#define MOUSE_BUTTON_LEFT   0x01
 
#define MOUSE_BUTTON_RIGHT   0x02
 
#define MOUSE_SENS_HIGH   2
 
#define MOUSE_SENS_LOW   0
 
#define MOUSE_SENS_MEDIUM   1
 
#define SSC_CURSOR   0x4000
 
#define SSC_FIRE   0x8000
 
#define SSC_NOISE   0x0100
 
#define SSC_OFFSCREEN   0x0200
 
#define SSC_PAUSE   0x1000
 
#define SSC_TURBO   0x2000
 

Functions

u8 mouseButtonsHeld (u8 port)
 Get currently held mouse buttons.
 
u8 mouseButtonsPressed (u8 port)
 Get newly pressed mouse buttons this frame.
 
u8 mouseGetSensitivity (u8 port)
 Get current mouse sensitivity.
 
s16 mouseGetX (u8 port)
 Get X displacement since last frame.
 
s16 mouseGetY (u8 port)
 Get Y displacement since last frame.
 
u8 mouseInit (u8 port)
 Initialize mouse on given port.
 
u8 mouseIsConnected (u8 port)
 Check if mouse is connected on port.
 
void mouseSetSensitivity (u8 port, u8 sensitivity)
 Set mouse sensitivity.
 
u16 padHeld (u8 pad)
 Get buttons currently held.
 
u8 padIsConnected (u8 pad)
 Check if controller is connected.
 
u16 padPressed (u8 pad)
 Get buttons pressed this frame.
 
u16 padRaw (u8 pad)
 Get raw button state.
 
u16 padReleased (u8 pad)
 Get buttons released this frame.
 
u16 scopeButtonsDown (void)
 Get currently held buttons.
 
u16 scopeButtonsHeld (void)
 Get buttons held past the hold delay threshold.
 
u16 scopeButtonsPressed (void)
 Get newly pressed buttons this frame.
 
void scopeCalibrate (void)
 Calibrate aim from a center-screen shot.
 
u16 scopeGetRawX (void)
 Get raw (uncalibrated) H position from PPU.
 
u16 scopeGetRawY (void)
 Get raw (uncalibrated) V position from PPU.
 
u16 scopeGetX (void)
 Get calibration-adjusted H position.
 
u16 scopeGetY (void)
 Get calibration-adjusted V position.
 
u8 scopeInit (void)
 Detect Super Scope on port 2.
 
u8 scopeIsConnected (void)
 Check if Super Scope is connected.
 
void scopeSetHoldDelay (u16 frames)
 Set hold delay (frames before hold triggers).
 
void scopeSetRepeatDelay (u16 frames)
 Set repeat delay (frames between repeat fires after hold).
 
u16 scopeSinceShot (void)
 Get frames since last detected shot.
 

Detailed Description

SNES Controller Input.

Functions for reading controller input.

Button Constants

Use these constants with padPressed(), padHeld(), etc:

Constant Button
KEY_A A button
KEY_B B button
KEY_X X button
KEY_Y Y button
KEY_L L shoulder
KEY_R R shoulder
KEY_START Start
KEY_SELECT Select
KEY_UP D-pad up
KEY_DOWN D-pad down
KEY_LEFT D-pad left
KEY_RIGHT D-pad right

Usage

// Check for button press (just pressed this frame)
if (padPressed(0) & KEY_A) {
playerJump();
}
// Check for button held (continuously pressed)
if (padHeld(0) & KEY_RIGHT) {
playerMoveRight();
}
#define KEY_RIGHT
Definition input.h:78
#define KEY_A
Definition input.h:81
u16 padHeld(u8 pad)
Get buttons currently held.
u16 padPressed(u8 pad)
Get buttons pressed this frame.
Author
OpenSNES Team

Function Documentation

◆ padHeld()

u16 padHeld ( u8  pad)

Get buttons currently held.

Returns all buttons currently being pressed.

Parameters
padController number (0-3)
Returns
Button mask of held buttons
if (padHeld(0) & KEY_RIGHT) {
}
static s16 player_x
Player X position in screen coordinates.
Definition main.c:55

◆ padIsConnected()

u8 padIsConnected ( u8  pad)

Check if controller is connected.

Parameters
padController number (0-3)
Returns
TRUE if connected, FALSE otherwise

◆ padPressed()

u16 padPressed ( u8  pad)

Get buttons pressed this frame.

Returns buttons that were just pressed (not held from previous frame).

Parameters
padController number (0-3)
Returns
Button mask of newly pressed buttons
if (padPressed(0) & KEY_A) {
// A was just pressed
}

◆ padRaw()

u16 padRaw ( u8  pad)

Get raw button state.

Returns the raw hardware state without edge detection.

Parameters
padController number (0-3)
Returns
Raw button state

◆ padReleased()

u16 padReleased ( u8  pad)

Get buttons released this frame.

Returns buttons that were just released (held last frame, not now).

Parameters
padController number (0-3)
Returns
Button mask of released buttons