OXYGENHUB
◆ main x16-emulator / src / joystick.h
1.5 KiB · Objective-C · last changed chore(): initial commit 15 days ago source blame history raw
1
#pragma once
2
#ifndef JOYSTICK_H
3
#define JOYSTICK_H
4
5
#include <stdint.h>
6
#include <stdbool.h>
7
8
#define JOY_LATCH_MASK 0x04
9
#define JOY_CLK_MASK 0x08
10
11
#define NUM_JOYSTICKS 4
12
13
extern uint8_t Joystick_data;
14
extern bool Joystick_slots_enabled[NUM_JOYSTICKS];
15
16
bool joystick_init(void); //initialize SDL controllers
17
void joystick_add(int index);
18
void joystick_remove(int index);
19
20
void joystick_button_down(int instance_id, uint8_t button);
21
void joystick_button_up(int instance_id, uint8_t button);
22
23
void joystick_set_latch(bool value);
24
void joystick_set_clock(bool value);
25
26
/* --- Virtual pads, for the RRDC control port (contract 0.5) ----------
27
 *
28
 * A harness has no SDL controller to plug in, so it asks for one to be
29
 * synthesised in a joystick slot. `mask` is the X16's own SNES bit
30
 * order and is ACTIVE LOW, exactly like joystick_info::button_mask —
31
 * converting from RRDC's canonical layout is the caller's job, not
32
 * this layer's.
33
 *
34
 * A virtual pad is a LEVEL, not an event: what it holds persists across
35
 * frames until set again, which is what makes "hold RIGHT for 60
36
 * frames" expressible. Returns false if `slot` is out of range. */
37
bool joystick_virtual_set(int slot, bool connected, bool set_buttons, uint16_t mask);
38
39
/* Read back what is present in `slot` — a virtual pad OR a real one, so
40
 * a harness can tell "no controller at all" from "controller present,
41
 * nothing held". Returns false if `slot` is out of range. */
42
bool joystick_virtual_get(int slot, bool *connected, uint16_t *mask);
43
44
#endif