libElysianVMU 1.6.0
Full-featured, accurate, cross-platform library emulating the Dreamcast's Visual Memory Unit
Loading...
Searching...
No Matches
evmu_gamepad.h
Go to the documentation of this file.
1/*! \file
2 * \brief EvmuGamepad and Port 3 Button Management
3 * \ingroup peripherals
4 *
5 * This file provides an API for accessing and setting
6 * the button states of a Gamepad. This is done via the
7 * EvmuGamepad instance.
8 *
9 * To implement a new input back-end, you may simply set
10 * the current state variables based on the source input
11 * device; however, a more sophisticated method would be
12 * to either reimplement EvmuGamepadClass::pFnPollButtons
13 * with this logic, or to connect a closure to the
14 * "updatingButtons" signal, which will synchronize external
15 * polling and internal update logic.
16 *
17 * \copyright 2023 Falco Girgis
18 */
19
20#ifndef EVMU_GAMEPAD_H
21#define EVMU_GAMEPAD_H
22
23#include "../types/evmu_peripheral.h"
24#include <gimbal/meta/signals/gimbal_signal.h>
25
26/*! \name Type System
27 * \brief Type UUID and cast operators
28 * @{
29 */
30#define EVMU_GAMEPAD_TYPE (GBL_TYPEID(EvmuGamepad)) //!< GblType UUID for EvmuGamepad
31#define EVMU_GAMEPAD(self) (GBL_CAST(EvmuGamepad, self)) //!< Cast GblInstance to EvmuGamepad
32#define EVMU_GAMEPAD_CLASS(klass) (GBL_CLASS_CAST(EvmuGamepad, klass)) //!< Cast GblClass to EvmuGamepadClass
33#define EVMU_GAMEPAD_GET_CLASS(self) (GBL_CLASSOF(EvmuGamepad, self)) //!< Function-style class accessor
34//! @}
35
36#define EVMU_GAMEPAD_NAME "gamepad" //!< Gamepad GblObject name
37
38#define GBL_SELF_TYPE EvmuGamepad
39
40GBL_DECLS_BEGIN
41
42GBL_FORWARD_DECLARE_STRUCT(EvmuGamepad);
43
44/*! \struct EvmuGamepadClass
45 * \extends EvmuPeripheralClass
46 * \brief GblClass VTable structure for EvmuGamepad
47 *
48 * EvmuGamepadClass is the virtual table/class structure
49 * for the EvmuGamepad peripheral instance.
50 *
51 * \sa EvmuGamepad
52 */
53GBL_CLASS_DERIVE(EvmuGamepad, EvmuPeripheral)
54 //! Invoked when time to update input (default fires "updatingButtons" signal)
55 EVMU_RESULT (*pFnPollButtons)(GBL_SELF);
56GBL_CLASS_END
57
58/*! \struct EvmuGamepad
59 * \extends EvmuPeripheral
60 * \ingroup peripherals
61 * \brief Gamepad peripheral for managing button states
62 *
63 * The EvmuGamepad peripheral provides both an API for accessing
64 * current Port 3 button states and for implementing an input
65 * back-end to drive these button states via virtual override or signal.
66 *
67 * \sa EvmuGamepadClass
68 */
69GBL_INSTANCE_DERIVE(EvmuGamepad, EvmuPeripheral)
70 // physical buttons (input)
71 uint16_t up : 1; //!< Dpad Up button state (1: pressed, 0: released)
72 uint16_t down : 1; //!< Dpad Down button state (1: pressed, 0: released)
73 uint16_t left : 1; //!< Dpad Left button state (1: pressed, 0: released)
74 uint16_t right : 1; //!< Dpad Right button state (1: pressed, 0: released)
75 uint16_t a : 1; //!< A button state (1: pressed, 0: released)
76 uint16_t b : 1; //!< B button state (1: pressed, 0: released)
77 uint16_t mode : 1; //!< Mode button state (1: pressed, 0: released)
78 uint16_t sleep : 1; //!< Sleep button state (1: pressed, 0: released)
79 // additional virtual buttons (input) (WIP)
80 uint16_t turboA : 1; //!< TurboA button state (1: pressed, 0: released)
81 uint16_t turboB : 1; //!< TurboB button state (1: pressed, 0: released)
82 uint16_t fastForward : 1; //!< Fast-Forward button state (1: pressed, 0: released)
83 uint16_t slowMotion : 1; //!< Rewind button state (1: preseed, 0: released)
84GBL_INSTANCE_END
85
86//!\cond
87GBL_PROPERTIES(EvmuGamepad,
88 (configured, GBL_GENERIC, (READ), GBL_BOOL_TYPE),
89 (up, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE),
90 (down, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE),
91 (left, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE),
92 (right, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE),
93 (a, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE),
94 (b, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE),
95 (mode, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE),
96 (sleep, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE),
97 (turboA, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE),
98 (turboB, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE),
99 (fastForward, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE),
100 (slowMotion, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE)
101)
102
103GBL_SIGNALS(EvmuGamepad,
104 (updatingButtons, (GBL_INSTANCE_TYPE, receiver))
105)
106//!\endcond
107
108//! Returns the GblType UUID associated with EvmuGamepad
110
111/*! \name Configuration
112 * \brief Method(s) for querying configuration state
113 * \relatesalso EvmuGamepad
114 * @{
115 */
116//! Returns GBL_TRUE if the port 3 DDR pins have been configured properly for button input
118//! @}
119
120GBL_DECLS_END
121
122#undef GBL_SELF_TYPE
123
124#endif // EVMU_GAMEPAD_H
#define EVMU_EXPORT
Define used for adding attributes to export public symbols.
Definition evmu_api.h:18
GblType EvmuGamepad_type(void)
Returns the GblType UUID associated with EvmuGamepad.
#define GBL_BOOL_TYPE
#define GBL_PROPERTIES(object,...)
uint8_t GblBool
uintptr_t GblType
Gamepad peripheral for managing button states.
uint16_t turboA
TurboA button state (1: pressed, 0: released)
uint16_t b
B button state (1: pressed, 0: released)
GblBool EvmuGamepad_isConfigured(const EvmuGamepad *pSelf)
Returns GBL_TRUE if the port 3 DDR pins have been configured properly for button input.
uint16_t mode
Mode button state (1: pressed, 0: released)
uint16_t turboB
TurboB button state (1: pressed, 0: released)
uint16_t sleep
Sleep button state (1: pressed, 0: released)
uint16_t a
A button state (1: pressed, 0: released)
uint16_t left
Dpad Left button state (1: pressed, 0: released)
uint16_t down
Dpad Down button state (1: pressed, 0: released)
uint16_t slowMotion
Rewind button state (1: preseed, 0: released)
uint16_t right
Dpad Right button state (1: pressed, 0: released)
uint16_t fastForward
Fast-Forward button state (1: pressed, 0: released)
uint16_t up
Dpad Up button state (1: pressed, 0: released)
#define GBL_CLASS_CAST(cType, klass)
#define GBL_CLASSOF(cType, self)
#define GBL_CAST(cType, self)