Jo Engine 2026.11.1
Jo Sega Saturn Engine
Loading...
Searching...
No Matches
input.h
Go to the documentation of this file.
1/*
2** Jo Sega Saturn Engine
3** Copyright (c) 2012-2026, Johannes Fetz (johannesfetz@gmail.com)
4** All rights reserved.
5**
6** Redistribution and use in source and binary forms, with or without
7** modification, are permitted provided that the following conditions are met:
8** * Redistributions of source code must retain the above copyright
9** notice, this list of conditions and the following disclaimer.
10** * Redistributions in binary form must reproduce the above copyright
11** notice, this list of conditions and the following disclaimer in the
12** documentation and/or other materials provided with the distribution.
13** * Neither the name of the Johannes Fetz nor the
14** names of its contributors may be used to endorse or promote products
15** derived from this software without specific prior written permission.
16**
17** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20** DISCLAIMED. IN NO EVENT SHALL Johannes Fetz BE LIABLE FOR ANY
21** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
35
36#ifndef __JO_INPUT_H__
37# define __JO_INPUT_H__
38
39# define JO_INPUT_MAX_DEVICE (12)
40
42# define JO_INPUT_PORT1_FIRST_DEVICE (0)
43# define JO_INPUT_PORT2_FIRST_DEVICE (6)
44
46# define __JO_KEY_PRESSED(PORT, KEY) ((jo_inputs[PORT].data & KEY) == 0)
47
48
51typedef enum
52{
53 JO_KEY_RIGHT = 1 << 15,
54 JO_KEY_LEFT = 1 << 14,
55 JO_KEY_DOWN = 1 << 13,
56 JO_KEY_UP = 1 << 12,
57 JO_KEY_START = 1 << 11,
58 JO_KEY_A = 1 << 10,
59 JO_KEY_B = 1 << 8,
60 JO_KEY_C = 1 << 9,
61 JO_KEY_X = 1 << 6,
62 JO_KEY_Y = 1 << 5,
63 JO_KEY_Z = 1 << 4,
64 JO_KEY_L = 1 << 3,
65 JO_KEY_R = 1 << 7,
66
72
96
99typedef enum
100{
108
114
119static __jo_force_inline bool jo_is_input_analog(const int port)
120{
121 // TODO: Add other analog devices (wheel, mission stick)
122 return (jo_inputs[port].id == JO_PERIPHERAL_ID_NIGHTS_PAD);
123}
124
129static __jo_force_inline bool jo_is_input_available(const int port)
130{
131 return (jo_inputs[port].id != JO_PERIPHERAL_ID_NOT_CONNECTED);
132}
133
138
144unsigned char jo_get_input_axis(const int port, const jo_input_axis axis);
145
151static __jo_force_inline bool jo_is_input_key_pressed(const int port, const jo_gamepad_keys key)
152{
153 return __JO_KEY_PRESSED(port, key);
154}
155
161{
162 if (__JO_KEY_PRESSED(port, JO_KEY_UP))
163 {
164 if (__JO_KEY_PRESSED(port, JO_KEY_LEFT))
165 return (UP_LEFT);
167 return (UP_RIGHT);
168 return (UP);
169 }
170 if (__JO_KEY_PRESSED(port, JO_KEY_DOWN))
171 {
172 if (__JO_KEY_PRESSED(port, JO_KEY_LEFT))
173 return (DOWN_LEFT);
175 return (DOWN_RIGHT);
176 return (DOWN);
177 }
178 if (__JO_KEY_PRESSED(port, JO_KEY_LEFT))
179 return (LEFT);
181 return (RIGHT);
182 return (NONE);
183}
184
189static __jo_force_inline unsigned short jo_get_raw_input_key_pressed(const int port)
190{
191 return ((unsigned short)jo_inputs[port].data);
192}
193
199static __jo_force_inline bool jo_is_input_key_down(const int port, const jo_gamepad_keys key)
200{
201 return ((jo_inputs[port].push & key) == 0);
202}
203
204
205
210static __jo_force_inline int jo_get_mouse_pos_x(const int port)
211{
212 return (((jo_peripheral_pointer *)&jo_inputs[port])->x);
213}
214
219static __jo_force_inline int jo_get_mouse_pos_y(const int port)
220{
221 return (((jo_peripheral_pointer *)&jo_inputs[port])->y);
222}
223
224
225/*
226** HELPER
227*/
228
236
244
253
262
271
280
281#endif /* !__JO_INPUT_H__ */
282
283/*
284** END OF FILE
285*/
static __jo_force_inline bool jo_is_pad1_key_pressed(jo_gamepad_keys key)
Check if the key is pressed on the first gamepad.
Definition input.h:249
static __jo_force_inline bool jo_is_input_key_pressed(const int port, const jo_gamepad_keys key)
Check if the key is pressed for the given port.
Definition input.h:151
static __jo_force_inline unsigned short jo_get_raw_input_key_pressed(const int port)
Get raw input data for the given port.
Definition input.h:189
static __jo_force_inline bool jo_is_input_available(const int port)
Check if the input is available for the given port.
Definition input.h:129
static __jo_force_inline bool jo_is_pad1_available(void)
Check if the first gamepad is plugged.
Definition input.h:232
#define JO_INPUT_PORT1_FIRST_DEVICE
Index in jo_inputs of the first peripheral of each port (6 peripherals per port, see jo_get_inputs_vb...
Definition input.h:42
static __jo_force_inline bool jo_is_pad2_key_down(jo_gamepad_keys key)
Check if the key is down on the second gamepad.
Definition input.h:276
static __jo_force_inline bool jo_is_pad2_available(void)
Check if the second gamepad is plugged.
Definition input.h:240
jo_gamepad_keys
Input keys.
Definition input.h:52
@ JO_KEY_RIGHT
Definition input.h:53
@ JO_MOUSE_LEFT_BUTTON
Definition input.h:68
@ JO_KEY_L
Definition input.h:64
@ JO_KEY_R
Definition input.h:65
@ JO_KEY_B
Definition input.h:59
@ JO_KEY_LEFT
Definition input.h:54
@ JO_KEY_X
Definition input.h:61
@ JO_KEY_START
Definition input.h:57
@ JO_KEY_Y
Definition input.h:62
@ JO_MOUSE_MIDDLE_BUTTON
Definition input.h:69
@ JO_KEY_Z
Definition input.h:63
@ JO_KEY_UP
Definition input.h:56
@ JO_KEY_C
Definition input.h:60
@ JO_MOUSE_RIGHT_BUTTON
Definition input.h:70
@ JO_KEY_DOWN
Definition input.h:55
@ JO_KEY_A
Definition input.h:58
@ JO_MOUSE_START_BUTTON
Definition input.h:67
jo_gamepad_type jo_get_input_type(const int port)
Get input type for the given port.
static __jo_force_inline int jo_get_mouse_pos_y(const int port)
Get mouse Y position.
Definition input.h:219
static __jo_force_inline int jo_get_mouse_pos_x(const int port)
Get mouse X position.
Definition input.h:210
static __jo_force_inline bool jo_is_pad1_key_down(jo_gamepad_keys key)
Check if the key is down on the first gamepad.
Definition input.h:258
static __jo_force_inline jo_8_directions jo_get_input_direction_pressed(const int port)
Get the direction pressed for the given port.
Definition input.h:160
#define __JO_KEY_PRESSED(PORT, KEY)
Definition input.h:46
jo_peripheral jo_inputs[(12)]
unsigned char jo_get_input_axis(const int port, const jo_input_axis axis)
Get analog axis value.
jo_gamepad_type
Input type.
Definition input.h:76
@ JoMissionStick
Mission stick, Axis1 and Axis2 are the analog stick, Axis3 is throttle.
Definition input.h:90
@ JoShuttleMouse
Definition input.h:81
@ JoNightsPad
Nights 3D pad, Axis1 and Axis2 are analog stick, Axis3 is right trigger and Axis4 is left trigger.
Definition input.h:86
@ JoRegularKeyboard
Definition input.h:82
@ JoNotConnectedGamepad
Definition input.h:77
@ JoRegularGamepad
Definition input.h:79
@ JoUnsupportedGamepad
Definition input.h:78
@ JoRacingWheel
Racing wheel, Axis1 is the wheel.
Definition input.h:94
@ JoRegularMouse
Definition input.h:80
static __jo_force_inline bool jo_is_pad2_key_pressed(jo_gamepad_keys key)
Check if the key is pressed on the second gamepad.
Definition input.h:267
#define JO_INPUT_MAX_DEVICE
Definition input.h:39
jo_input_axis
Input axis type.
Definition input.h:100
@ JoAxis5
Definition input.h:105
@ JoAxis2
Definition input.h:102
@ JoAxis4
Definition input.h:104
@ JoAxis6
Definition input.h:106
@ JoAxis3
Definition input.h:103
@ JoAxis1
Definition input.h:101
static __jo_force_inline bool jo_is_input_analog(const int port)
Check if connected input is analog.
Definition input.h:119
static __jo_force_inline bool jo_is_input_key_down(const int port, const jo_gamepad_keys key)
Check if the key is down for the given port.
Definition input.h:199
#define JO_INPUT_PORT2_FIRST_DEVICE
Definition input.h:43
int jo_get_input_count(void)
Get the number of input available.
#define JO_PERIPHERAL_ID_NOT_CONNECTED
Peripheral ID: nothing connected.
Definition smpc.h:166
#define JO_PERIPHERAL_ID_NIGHTS_PAD
Peripheral ID: 3D pad (NiGHTS pad).
Definition smpc.h:174
Digital peripheral data (gamepad).
Definition smpc.h:197
Pointing peripheral data (mouse).
Definition smpc.h:227
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition types.h:39
jo_8_directions
8 directions definition
Definition types.h:308
@ DOWN_LEFT
Definition types.h:316
@ DOWN_RIGHT
Definition types.h:317
@ UP_RIGHT
Definition types.h:315
@ DOWN
Definition types.h:313
@ UP_LEFT
Definition types.h:314
@ UP
Definition types.h:312
@ NONE
Definition types.h:309
@ LEFT
Definition types.h:310
@ RIGHT
Definition types.h:311