133 lines
4.5 KiB
C
133 lines
4.5 KiB
C
// Keyboard, mouse, and joystick input polling.
|
|
//
|
|
// Call joeyInputPoll() once per frame (typically right before
|
|
// drawing) to refresh keyboard, mouse, and joystick state. After
|
|
// polling, the joeyKey* predicates return the current state of every
|
|
// key:
|
|
//
|
|
// joeyKeyDown(k) -- is key k held down right now
|
|
// joeyKeyPressed(k) -- rising edge since the previous poll
|
|
// joeyKeyReleased(k) -- falling edge since the previous poll
|
|
//
|
|
// The mouse predicates return the pointer state:
|
|
//
|
|
// joeyMouseX/Y() -- pointer position in surface
|
|
// coords (0..SURFACE_WIDTH-1,
|
|
// 0..SURFACE_HEIGHT-1)
|
|
// joeyMouseDown(b) -- is button b held right now
|
|
// joeyMousePressed(b) -- rising edge since last poll
|
|
// joeyMouseReleased(b) -- falling edge since last poll
|
|
//
|
|
// The joystick predicates return per-stick state:
|
|
//
|
|
// joeyJoystickConnected(js) -- true if the platform reports a
|
|
// stick on this port
|
|
// joeyJoystickX/Y(js) -- axis values, signed -127..+127.
|
|
// Digital sticks snap to the
|
|
// extremes; analog sticks return
|
|
// the raw centered value.
|
|
// joeyJoyDown(js, b) -- is button b held on stick js
|
|
// joeyJoyPressed(js, b) -- rising edge since last poll
|
|
// joeyJoyReleased(js, b) -- falling edge since last poll
|
|
//
|
|
// Edge predicates are one-shot: they return true only in the
|
|
// frame the transition occurred and false thereafter.
|
|
|
|
#ifndef JOEYLIB_INPUT_H
|
|
#define JOEYLIB_INPUT_H
|
|
|
|
#include "platform.h"
|
|
#include "types.h"
|
|
|
|
typedef enum {
|
|
KEY_NONE = 0,
|
|
|
|
KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G, KEY_H, KEY_I,
|
|
KEY_J, KEY_K, KEY_L, KEY_M, KEY_N, KEY_O, KEY_P, KEY_Q, KEY_R,
|
|
KEY_S, KEY_T, KEY_U, KEY_V, KEY_W, KEY_X, KEY_Y, KEY_Z,
|
|
|
|
KEY_0, KEY_1, KEY_2, KEY_3, KEY_4,
|
|
KEY_5, KEY_6, KEY_7, KEY_8, KEY_9,
|
|
|
|
KEY_SPACE, KEY_ESCAPE, KEY_RETURN, KEY_TAB, KEY_BACKSPACE,
|
|
|
|
KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT,
|
|
|
|
KEY_LSHIFT, KEY_RSHIFT, KEY_LCTRL, KEY_LALT,
|
|
|
|
KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5,
|
|
KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10,
|
|
|
|
KEY_COUNT
|
|
} JoeyKeyE;
|
|
|
|
typedef enum {
|
|
MOUSE_BUTTON_NONE = 0,
|
|
MOUSE_BUTTON_LEFT,
|
|
MOUSE_BUTTON_RIGHT,
|
|
MOUSE_BUTTON_MIDDLE,
|
|
|
|
MOUSE_BUTTON_COUNT
|
|
} JoeyMouseButtonE;
|
|
|
|
typedef enum {
|
|
JOYSTICK_0 = 0,
|
|
JOYSTICK_1,
|
|
|
|
JOYSTICK_COUNT
|
|
} JoeyJoystickE;
|
|
|
|
typedef enum {
|
|
JOY_BUTTON_0 = 0,
|
|
JOY_BUTTON_1,
|
|
|
|
JOY_BUTTON_COUNT
|
|
} JoeyJoyButtonE;
|
|
|
|
#define JOYSTICK_AXIS_MAX 127
|
|
#define JOYSTICK_AXIS_MIN (-127)
|
|
|
|
void joeyInputPoll(void);
|
|
|
|
// Block until the user presses any key. Internally polls via
|
|
// joeyInputPoll, so per-port halInputPoll machinery (including
|
|
// audio-friendly IRQ-driven samplers) keeps working while the
|
|
// wait loop runs.
|
|
void joeyWaitForAnyKey(void);
|
|
|
|
bool joeyKeyDown(JoeyKeyE key);
|
|
bool joeyKeyPressed(JoeyKeyE key);
|
|
bool joeyKeyReleased(JoeyKeyE key);
|
|
|
|
int16_t joeyMouseX(void);
|
|
int16_t joeyMouseY(void);
|
|
bool joeyMouseDown(JoeyMouseButtonE button);
|
|
bool joeyMousePressed(JoeyMouseButtonE button);
|
|
bool joeyMouseReleased(JoeyMouseButtonE button);
|
|
|
|
bool joeyJoystickConnected(JoeyJoystickE js);
|
|
int8_t joeyJoystickX(JoeyJoystickE js);
|
|
int8_t joeyJoystickY(JoeyJoystickE js);
|
|
bool joeyJoyDown(JoeyJoystickE js, JoeyJoyButtonE button);
|
|
bool joeyJoyPressed(JoeyJoystickE js, JoeyJoyButtonE button);
|
|
bool joeyJoyReleased(JoeyJoystickE js, JoeyJoyButtonE button);
|
|
|
|
// Re-enable joystick polling and recalibrate the resting (center)
|
|
// position. The IIgs port auto-disables polling after a short window
|
|
// of detecting no stick (saves ~3 ms/frame of busy-wait). It does NOT
|
|
// auto-re-probe -- the application must call this function to resume
|
|
// polling after plugging a stick in.
|
|
//
|
|
// The next poll after this call captures the stick's CURRENT raw
|
|
// position as the new center -- so the user must hold the stick
|
|
// centered when calling. Subsequent polls report position relative
|
|
// to that center; raw readings within `deadZone` units of the center
|
|
// clamp to 0 (use 0 to disable the dead zone).
|
|
//
|
|
// On platforms with truly digital sticks (Amiga / ST / DOS) the
|
|
// recalibration is a no-op -- those ports already report -1 / 0 / +1
|
|
// directly -- and `deadZone` is ignored. The function still clears
|
|
// any auto-disconnect state so polling resumes.
|
|
void joeyJoystickReset(JoeyJoystickE js, uint8_t deadZone);
|
|
|
|
#endif
|