OpenSNES
Modern Open-Source SNES Development SDK
Loading...
Searching...
No Matches
input.h
Go to the documentation of this file.
1
43
44#ifndef OPENSNES_INPUT_H
45#define OPENSNES_INPUT_H
46
47#include <snes/types.h>
48
49/* Removed on 2026-10-05 (1.0 plan, lot C): padRaw, scopeButtonsDown.
50 * The replacements are in docs/UPGRADING.md; `make check-upgrade` names them. */
51
52/*============================================================================
53 * Button Constants
54 *============================================================================*/
55
59
60/*
61 * SNES Joypad Register Layout (16-bit read as JOY1L | JOY1H << 8):
62 *
63 * $4219 (JOY1H) → bits 15-8: B, Y, Select, Start, Up, Down, Left, Right
64 * $4218 (JOY1L) → bits 7-0: A, X, L, R, (signature bits)
65 *
66 * Bit layout (16-bit, active high):
67 * 15 14 13 12 11 10 9 8 7 6 5 4 3-0
68 * B Y Sel Sta Up Dn Lt Rt A X L R ID
69 *
70 * Verified against fullsnes documentation and real hardware.
71 */
72
73/* High byte ($4219 → result bits 15-8) */
74#define KEY_B BIT(15)
75#define KEY_Y BIT(14)
76#define KEY_SELECT BIT(13)
77#define KEY_START BIT(12)
78#define KEY_UP BIT(11)
79#define KEY_DOWN BIT(10)
80#define KEY_LEFT BIT(9)
81#define KEY_RIGHT BIT(8)
82
83/* Low byte ($4218 → result bits 7-0) */
84#define KEY_A BIT(7)
85#define KEY_X BIT(6)
86#define KEY_L BIT(5)
87#define KEY_R BIT(4)
88
90#define KEY_DPAD (KEY_UP | KEY_DOWN | KEY_LEFT | KEY_RIGHT)
91
93#define KEY_FACE (KEY_A | KEY_B | KEY_X | KEY_Y)
94
96
97/*============================================================================
98 * Functions
99 *============================================================================*/
100
118
136
147
148/* padHeld() and padPressed() read one word that the NMI handler filled, so
149 * they are also macros (since 2026-10-09): a call cost about 125 CPU cycles,
150 * three times a frame in most games, for what is one load. The handler
151 * already stores 0 for a port that holds no pad, which is all the functions
152 * added. The functions remain — `(padHeld)(0)` calls one, and so does taking
153 * its address. Unlike them the macros do not check `pad`: an index above 4
154 * reads whatever follows the array. */
155extern u16 pad_keys[5];
156extern u16 pad_keysold[5];
157extern u16 pad_keysdown[5];
158#define padHeld(pad) (pad_keys[(pad)])
159#define padPressed(pad) (pad_keysdown[(pad)])
160
190
191/*============================================================================
192 * Mouse Constants
193 *============================================================================*/
194
223
224#define MOUSE_BUTTON_LEFT 0x01
225#define MOUSE_BUTTON_RIGHT 0x02
226
227#define MOUSE_SENS_LOW 0
228#define MOUSE_SENS_MEDIUM 1
229#define MOUSE_SENS_HIGH 2
230
242
253
264
274
282
290
300void mouseSetSensitivity(u8 port, u8 sensitivity);
301
309
311
312/*============================================================================
313 * Super Scope Constants
314 *============================================================================*/
315
346
347#define SSC_FIRE 0x8000
348#define SSC_CURSOR 0x4000
349#define SSC_TURBO 0x2000
350#define SSC_PAUSE 0x1000
351#define SSC_OFFSCREEN 0x0200
352#define SSC_NOISE 0x0100
353
364
376
383
390
397
404
420
427
436
445void scopeCalibrate(void);
446
453
460
467
469
470#endif /* OPENSNES_INPUT_H */
u8 mouseGetSensitivity(u8 port)
Get current mouse sensitivity.
s16 mouseGetY(u8 port)
Get Y displacement since last frame.
u8 mouseButtonsHeld(u8 port)
Get currently held mouse buttons.
u8 mouseIsConnected(u8 port)
Check if mouse is connected on port.
u8 mouseInit(u8 port)
Initialize mouse on given port.
s16 mouseGetX(u8 port)
Get X displacement since last frame.
void mouseSetSensitivity(u8 port, u8 sensitivity)
Set mouse sensitivity.
u8 mouseButtonsPressed(u8 port)
Get newly pressed mouse buttons this frame.
u16 scopeButtonsHeld(void)
Buttons currently down — the same meaning as padHeld() and mouseButtonsHeld().
u16 scopeSinceShot(void)
Get frames since last detected shot.
u16 scopeButtonsRepeat(void)
Buttons held past the hold delay, re-triggering every repeat delay (see scopeSetRepeatDelay()) — a ke...
u16 scopeGetRawY(void)
Get raw (uncalibrated) V position from PPU.
void scopeCalibrate(void)
Calibrate aim from a center-screen shot.
void scopeSetHoldDelay(u16 frames)
Set hold delay (frames before hold triggers).
u16 scopeButtonsPressed(void)
Get newly pressed buttons this frame.
u8 scopeIsConnected(void)
Check if Super Scope is connected.
u16 scopeGetX(void)
Get calibration-adjusted H position.
u8 scopeInit(void)
Detect Super Scope on port 2.
void scopeSetRepeatDelay(u16 frames)
Set repeat delay (frames between repeat fires after hold).
u16 scopeGetRawX(void)
Get raw (uncalibrated) H position from PPU.
u16 scopeGetY(void)
Get calibration-adjusted V position.
signed short s16
16-bit signed integer (-32768 to 32767)
Definition types.h:50
unsigned short u16
16-bit unsigned integer (0 to 65535)
Definition types.h:53
unsigned char u8
8-bit unsigned integer (0 to 255)
Definition types.h:47
u16 pad_keysold[5]
u16 padReleased(u8 pad)
Get buttons released this frame.
u16 pad_keys[5]
u8 padIsConnected(u8 pad)
Check if controller is connected.
#define padHeld(pad)
Definition input.h:158
u16 pad_keysdown[5]
#define padPressed(pad)
Definition input.h:159
OpenSNES Standard Types.