Jo Engine  9
Jo Sega Saturn Engine
input.h
Go to the documentation of this file.
1 /*
2 ** Jo Sega Saturn Engine
3 ** Copyright (c) 2012-2017, 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 */
36 #ifndef __JO_INPUT_H__
37 # define __JO_INPUT_H__
38 
39 # define JO_INPUT_MAX_DEVICE (8)
40 
41 #if !JO_COMPILE_USING_SGL
42 
46 typedef struct
47 {
48  unsigned char id;
49  unsigned short pressed;
50  unsigned short on_keydown;
51  unsigned short on_keyup;
52 } jo_input;
53 
58 
59 #endif
60 
63 #if JO_COMPILE_USING_SGL
64 typedef enum
65 {
66  JO_KEY_RIGHT = 1 << 15,
67  JO_KEY_LEFT = 1 << 14,
68  JO_KEY_DOWN = 1 << 13,
69  JO_KEY_UP = 1 << 12,
70  JO_KEY_START = 1 << 11,
71  JO_KEY_A = 1 << 10,
72  JO_KEY_B = 1 << 8,
73  JO_KEY_C = 1 << 9,
74  JO_KEY_X = 1 << 6,
75  JO_KEY_Y = 1 << 5,
76  JO_KEY_Z = 1 << 4,
77  JO_KEY_L = 1 << 3,
78  JO_KEY_R = 1 << 7,
79 
80  JO_MOUSE_START_BUTTON = 1 << 11,
81  JO_MOUSE_LEFT_BUTTON = 1 << 10,
82  JO_MOUSE_MIDDLE_BUTTON = 1 << 8,
83  JO_MOUSE_RIGHT_BUTTON = 1 << 9
85 #else
86 typedef enum
87 {
88  JO_KEY_RIGHT = 1 << 7,
89  JO_KEY_LEFT = 1 << 6,
90  JO_KEY_DOWN = 1 << 5,
91  JO_KEY_UP = 1 << 4,
92  JO_KEY_START = 1 << 11,
93  JO_KEY_A = 1 << 10,
94  JO_KEY_B = 1 << 8,
95  JO_KEY_C = 1 << 9,
96  JO_KEY_X = 1 << 2,
97  JO_KEY_Y = 1 << 1,
98  JO_KEY_Z = 1 << 0,
99  JO_KEY_L = 1 << 15,
100  JO_KEY_R = 1 << 3,
101 
107 #endif
108 
111 typedef enum
112 {
119 
124 jo_gamepad_type jo_get_input_type(const int port);
125 
130 static __jo_force_inline bool jo_is_input_available(const int port)
131 {
132 #if JO_COMPILE_USING_SGL
133  return (Smpc_Peripheral[port].id != PER_ID_NotConnect);
134 #else
135  return (jo_inputs[port].id != PER_ID_NotConnect);
136 #endif
137 }
138 
144 static __jo_force_inline bool jo_is_input_key_pressed(const int port, const jo_gamepad_keys key)
145 {
146 #if JO_COMPILE_USING_SGL
147  return ((Smpc_Peripheral[port].data & key) == 0);
148 #else
149  return ((jo_inputs[port].pressed & key) == key);
150 #endif
151 }
152 
158 static __jo_force_inline bool jo_is_input_key_down(const int port, const jo_gamepad_keys key)
159 {
160 #if JO_COMPILE_USING_SGL
161  return ((Smpc_Peripheral[port].push & key) == 0);
162 #else
163  return ((jo_inputs[port].on_keydown & key) == key);
164 #endif
165 }
166 
167 #if !JO_COMPILE_USING_SGL
168 
174 static __jo_force_inline bool jo_is_input_key_up(const int port, const jo_gamepad_keys key)
175 {
176  return ((jo_inputs[port].on_keyup & key) == key);
177 }
178 #endif
179 
184 static __jo_force_inline int jo_get_mouse_pos_x(const int port)
185 {
186  return (JO_DIV_BY_65536(Smpc_Peripheral[port].dummy2[0]));
187 }
188 
193 static __jo_force_inline int jo_get_mouse_pos_y(const int port)
194 {
195  return (JO_DIV_BY_65536((JO_MULT_BY_65536(Smpc_Peripheral[port].dummy2[0]))));
196 }
197 
198 /*
199 ** HELPER
200 */
201 
206 {
207  return jo_is_input_available(0);
208 }
209 
214 {
215  return jo_is_input_available(1);
216 }
217 
223 {
224  return (jo_is_input_key_pressed(0, key));
225 }
226 
232 {
233  return (jo_is_input_key_down(0, key));
234 }
235 
241 {
242  return (jo_is_input_key_pressed(1, key));
243 }
244 
250 {
251  return (jo_is_input_key_down(1, key));
252 }
253 
254 #endif /* !__JO_INPUT_H__ */
255 
256 /*
257 ** END OF FILE
258 */
Definition: input.h:100
Definition: input.h:92
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:158
unsigned short on_keydown
Definition: input.h:50
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:231
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:240
jo_gamepad_keys
Input keys.
Definition: input.h:86
jo_input jo_inputs[(8)]
Input status (internal engine usage)
Definition: input.h:117
static __jo_force_inline bool jo_is_pad2_available(void)
Check if the second gamepad is plugged.
Definition: input.h:213
static __jo_force_inline int jo_get_mouse_pos_x(const int port)
Get mouse X position.
Definition: input.h:184
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:222
unsigned char id
Definition: input.h:48
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition: conf.h:154
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:249
Definition: input.h:91
jo_gamepad_type jo_get_input_type(const int port)
Get input type for the given port.
static __jo_force_inline bool jo_is_input_key_up(const int port, const jo_gamepad_keys key)
Check if the key is up for the given port.
Definition: input.h:174
PerDigital * Smpc_Peripheral
#define JO_DIV_BY_65536(X)
Devide a variable by 65536.
Definition: math.h:166
unsigned short pressed
Definition: input.h:49
Definition: input.h:113
Definition: input.h:96
Definition: input.h:93
Definition: input.h:98
#define PER_ID_NotConnect
Definition: sgl_prototypes.h:65
#define JO_INPUT_MAX_DEVICE
Definition: input.h:39
Definition: input.h:103
Definition: input.h:116
Definition: input.h:102
Definition: input.h:95
Definition: input.h:105
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:144
Input structure (internal engine usage)
Definition: input.h:46
Definition: input.h:89
Definition: input.h:114
jo_gamepad_type
Input type.
Definition: input.h:111
Definition: input.h:90
Definition: input.h:115
static __jo_force_inline bool jo_is_pad1_available(void)
Check if the first gamepad is plugged.
Definition: input.h:205
#define JO_MULT_BY_65536(X)
Multiply a variable by 65536.
Definition: math.h:123
Definition: input.h:88
static __jo_force_inline int jo_get_mouse_pos_y(const int port)
Get mouse Y position.
Definition: input.h:193
Definition: input.h:94
unsigned short on_keyup
Definition: input.h:51
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:130
Definition: input.h:97
Definition: input.h:99
Definition: input.h:104