| 1 |
#pragma once |
| 2 |
#ifndef JOYSTICK_H |
| 3 |
#define JOYSTICK_H |
| 4 |
|
| 5 |
#include <stdint.h> |
| 6 |
#include <stdbool.h> |
| 7 |
|
| 8 |
#ifdef __cplusplus |
| 9 |
extern "C" { |
| 10 |
#endif |
| 11 |
|
| 12 |
#define JOY_LATCH_MASK 0x04 |
| 13 |
#define JOY_CLK_MASK 0x08 |
| 14 |
|
| 15 |
#define NUM_JOYSTICKS 4 |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#define JOY_BIT_A (1 << 0) |
| 21 |
#define JOY_BIT_X (1 << 1) |
| 22 |
#define JOY_BIT_SELECT (1 << 2) |
| 23 |
#define JOY_BIT_START (1 << 3) |
| 24 |
#define JOY_BIT_DPAD_UP (1 << 4) |
| 25 |
#define JOY_BIT_DPAD_DOWN (1 << 5) |
| 26 |
#define JOY_BIT_DPAD_LEFT (1 << 6) |
| 27 |
#define JOY_BIT_DPAD_RIGHT (1 << 7) |
| 28 |
#define JOY_BIT_B (1 << 8) |
| 29 |
#define JOY_BIT_Y (1 << 9) |
| 30 |
#define JOY_BIT_LEFT_SHOULDER (1 << 10) |
| 31 |
#define JOY_BIT_RIGHT_SHOULDER (1 << 11) |
| 32 |
|
| 33 |
|
| 34 |
extern uint8_t Joystick_data; |
| 35 |
extern bool Joystick_slots_enabled[NUM_JOYSTICKS]; |
| 36 |
|
| 37 |
bool joystick_init(void); |
| 38 |
void joystick_add(int index); |
| 39 |
void joystick_remove(int index); |
| 40 |
|
| 41 |
void joystick_button_down(int instance_id, uint8_t button); |
| 42 |
void joystick_button_up(int instance_id, uint8_t button); |
| 43 |
|
| 44 |
void joystick_set_latch(bool value); |
| 45 |
void joystick_set_clock(bool value); |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
void joystick_set_virtual(int slot, uint16_t button_mask); |
| 58 |
void joystick_clear_virtual(int slot); |
| 59 |
bool joystick_virtual_active(int slot); |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
typedef struct { |
| 66 |
bool enabled; |
| 67 |
bool controller_bound; |
| 68 |
bool virtual_active; |
| 69 |
uint16_t button_mask; |
| 70 |
uint16_t shift_mask; |
| 71 |
} joystick_slot_debug_t; |
| 72 |
|
| 73 |
typedef struct { |
| 74 |
joystick_slot_debug_t slots[NUM_JOYSTICKS]; |
| 75 |
bool latch; |
| 76 |
uint8_t data; |
| 77 |
} joystick_debug_state_t; |
| 78 |
|
| 79 |
void joystick_debug_get_state(joystick_debug_state_t *out); |
| 80 |
|
| 81 |
#ifdef __cplusplus |
| 82 |
} |
| 83 |
#endif |
| 84 |
|
| 85 |
#endif |