Jo Engine 2026.11.6
Jo Sega Saturn Engine
Loading...
Searching...
No Matches
input.h File Reference

Jo Engine Gamepad functions. More...

Go to the source code of this file.

Macros

#define JO_INPUT_MAX_DEVICE
#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_vblank()).
#define JO_INPUT_PORT2_FIRST_DEVICE
#define __JO_KEY_PRESSED(PORT, KEY)

Enumerations

enum  jo_gamepad_keys {
  JO_KEY_RIGHT , JO_KEY_LEFT , JO_KEY_DOWN , JO_KEY_UP ,
  JO_KEY_START , JO_KEY_A , JO_KEY_B , JO_KEY_C ,
  JO_KEY_X , JO_KEY_Y , JO_KEY_Z , JO_KEY_L ,
  JO_KEY_R , JO_MOUSE_START_BUTTON , JO_MOUSE_LEFT_BUTTON , JO_MOUSE_MIDDLE_BUTTON ,
  JO_MOUSE_RIGHT_BUTTON , JO_GUN_TRIGGER , JO_GUN_START_BUTTON
}
 Input keys. More...
enum  jo_gamepad_type {
  JoNotConnectedGamepad , JoUnsupportedGamepad , JoRegularGamepad , JoRegularMouse ,
  JoShuttleMouse , JoRegularKeyboard , JoNightsPad , JoMissionStick ,
  JoRacingWheel , JoLightGun
}
 Input type. More...
enum  jo_input_axis {
  JoAxis1 , JoAxis2 , JoAxis3 , JoAxis4 ,
  JoAxis5 , JoAxis6
}
 Input axis type. More...

Functions

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_analog (const int port)
 Check if connected input is analog.
static __jo_force_inline bool jo_is_input_available (const int port)
 Check if the input is available for the given port.
int jo_get_input_count (void)
 Get the number of input available.
int jo_get_player_input_port (const int player)
 The port (the index of jo_inputs) of the gamepad of a player: the devices of the port 1 are 0 to 5 (a multitap), those of the port 2 are 6 to 11; 2 gamepads without multitap: 0 and 6.
unsigned char jo_get_input_axis (const int port, const jo_input_axis axis)
 Get analog axis value.
int jo_get_input_axis_centered (const int port, const jo_input_axis axis)
 Get a centered analog axis (a stick or a wheel): 0 in the middle.
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.
static __jo_force_inline jo_8_directions jo_get_input_direction_pressed (const int port)
 Get the direction pressed for the given port.
static __jo_force_inline unsigned short jo_get_raw_input_key_pressed (const int port)
 Get raw input data for the given port.
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.
static __jo_force_inline int jo_get_mouse_pos_x (const int port)
 Get mouse X position.
static __jo_force_inline int jo_get_mouse_pos_y (const int port)
 Get mouse Y position.
bool jo_get_input_gun_position (const int port, int *const x, int *const y)
 Get the position on the screen where the light gun points.
bool jo_calibrate_input_gun (const int port, const int target_x, const int target_y)
 Calibrate a light gun: the player shoots at a target, the position read is moved onto the target.
static __jo_force_inline bool jo_is_pad1_available (void)
 Check if the first gamepad is plugged.
static __jo_force_inline bool jo_is_pad2_available (void)
 Check if the second gamepad is plugged (the second device: on the port 2, or on a multitap of the port 1).
static __jo_force_inline bool jo_is_pad1_key_pressed (jo_gamepad_keys key)
 Check if the key is pressed on the first gamepad.
static __jo_force_inline bool jo_is_pad1_key_down (jo_gamepad_keys key)
 Check if the key is down on the first gamepad.
static __jo_force_inline bool jo_is_pad2_key_pressed (jo_gamepad_keys key)
 Check if the key is pressed on the second gamepad.
static __jo_force_inline bool jo_is_pad2_key_down (jo_gamepad_keys key)
 Check if the key is down on the second gamepad.

Variables

jo_peripheral jo_inputs [(12)]

Detailed Description

Jo Engine Gamepad functions.

Author
Johannes Fetz
Bug
No known bugs.

Macro Definition Documentation

◆ __JO_KEY_PRESSED

#define __JO_KEY_PRESSED ( PORT,
KEY )

◆ JO_INPUT_MAX_DEVICE

#define JO_INPUT_MAX_DEVICE

◆ JO_INPUT_PORT1_FIRST_DEVICE

#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_vblank()).

◆ JO_INPUT_PORT2_FIRST_DEVICE

#define JO_INPUT_PORT2_FIRST_DEVICE

Enumeration Type Documentation

◆ jo_gamepad_keys

Input keys.

Enumerator
JO_KEY_RIGHT 
JO_KEY_LEFT 
JO_KEY_DOWN 
JO_KEY_UP 
JO_KEY_START 
JO_KEY_A 
JO_KEY_B 
JO_KEY_C 
JO_KEY_X 
JO_KEY_Y 
JO_KEY_Z 
JO_KEY_L 
JO_KEY_R 
JO_MOUSE_START_BUTTON 
JO_MOUSE_LEFT_BUTTON 
JO_MOUSE_MIDDLE_BUTTON 
JO_MOUSE_RIGHT_BUTTON 
JO_GUN_TRIGGER 

Trigger of a light gun (the same bit as JO_KEY_A: a gun works with the code written for a pad).

JO_GUN_START_BUTTON 

Start button of a light gun (the same bit as JO_KEY_START).

◆ jo_gamepad_type

Input type.

Enumerator
JoNotConnectedGamepad 
JoUnsupportedGamepad 
JoRegularGamepad 
JoRegularMouse 
JoShuttleMouse 
JoRegularKeyboard 
JoNightsPad 

Nights 3D pad, Axis1 and Axis2 are analog stick, Axis3 is right trigger and Axis4 is left trigger.

JoMissionStick 

Mission stick, Axis1 and Axis2 are the analog stick, Axis3 is throttle.

JoRacingWheel 

Racing wheel, Axis1 is the wheel.

JoLightGun 

Light gun (Virtua Gun, Stunner): JO_GUN_TRIGGER, JO_GUN_START_BUTTON and jo_get_input_gun_position().

◆ jo_input_axis

Input axis type.

Enumerator
JoAxis1 
JoAxis2 
JoAxis3 
JoAxis4 
JoAxis5 
JoAxis6 

Function Documentation

◆ jo_calibrate_input_gun()

bool jo_calibrate_input_gun ( const int port,
const int target_x,
const int target_y )

Calibrate a light gun: the player shoots at a target, the position read is moved onto the target.

Parameters
portGamepad port: 0 (port 1) or JO_INPUT_PORT2_FIRST_DEVICE (port 2)
target_xHorizontal position of the target (pixels of the screen, from the left)
target_yVertical position of the target (pixels of the screen, from the top)
Returns
true if the gun saw the screen during the last frame (the next positions are corrected), false otherwise (nothing changes)
Remarks
Sega's advice: draw a cross at the center of the screen, ask the player to aim at it and to pull the trigger, then call jo_calibrate_input_gun(port, JO_TV_WIDTH_2, JO_TV_HEIGHT_2). The correction of each port is kept until the next calibration (calibrate again after jo_core_set_screen_resolution())
Before the calibration, the position is corrected by the delay of the gun measured in Mednafen (29 dots in the 320 and 640 pixel modes, 31 dots in the 352 and 704 pixel modes)

◆ jo_get_input_axis()

unsigned char jo_get_input_axis ( const int port,
const jo_input_axis axis )

Get analog axis value.

Parameters
portGamepad port
axisAnalog axis
Returns
Analog axis value

◆ jo_get_input_axis_centered()

int jo_get_input_axis_centered ( const int port,
const jo_input_axis axis )

Get a centered analog axis (a stick or a wheel): 0 in the middle.

Parameters
portGamepad port
axisAnalog axis: JoAxis1 and JoAxis2 (the stick of the Nights pad and of the mission stick), JoAxis1 (the racing wheel)
Returns
-128 (left, up) to 127 (right, down), 0 if the device has no such centered axis (not connected, a trigger, the throttle: see jo_get_input_axis(), 0 to 255)
Remarks
jo_get_input_axis() gives 0 to 255 with the middle at 128 (128 is subtracted here)

◆ jo_get_input_count()

int jo_get_input_count ( void )

Get the number of input available.

Returns
Input count

◆ jo_get_input_direction_pressed()

__jo_force_inline jo_8_directions jo_get_input_direction_pressed ( const int port)
static

Get the direction pressed for the given port.

Parameters
portGamepad port
Returns
jo_8_directions

◆ jo_get_input_gun_position()

bool jo_get_input_gun_position ( const int port,
int *const x,
int *const y )

Get the position on the screen where the light gun points.

Parameters
portGamepad port: 0 (port 1) or JO_INPUT_PORT2_FIRST_DEVICE (port 2), the gun can't be used behind a multitap
xHorizontal position in pixels of the screen (0 to jo_core_get_screen_width() - 1, from the left), -1 when false is returned
yVertical position in lines of the screen (0 to jo_core_get_screen_height() - 1, from the top), -1 when false is returned
Returns
true if the light sensor of the gun saw the screen during the last frame, false if it points out of the screen, at a dark area of the screen, or if there is no gun on the port
Remarks
The gun is found automatically (jo_get_input_type() returns JoLightGun). The trigger and the start button are read like the keys of a pad: jo_is_input_key_down(port, JO_GUN_TRIGGER), jo_is_pad1_key_pressed(JO_GUN_START_BUTTON)...
How it works: the light sensor sees the beam of the CRT draw the pixel, the VDP2 keeps the position of the beam at this time (HV counter latch). Only a CRT TV works (no LCD TV, no upscaler): a gun sees nothing on the other TVs. The gun sees a bright area only: when the trigger is pulled at a dark area (false is returned), draw a white screen for 2 frames: the position comes 2 frames after the trigger (see the sample "demo - light gun")
With 2 guns, each one gets a position every other field (the VDP2 has one latch)
Each gun and each TV is a little different: see jo_calibrate_input_gun()
int x;
int y;
if (jo_get_input_type(0) == JoLightGun && jo_is_input_key_down(0, JO_GUN_TRIGGER) && jo_get_input_gun_position(0, &x, &y))
jo_sprite_draw3D(hit_sprite_id, x - JO_TV_WIDTH_2, y - JO_TV_HEIGHT_2, 100);
#define JO_TV_HEIGHT_2
Screen height divided by 2 (math optimization purpose).
Definition conf.h:126
#define JO_TV_WIDTH_2
Screen width divided by 2 (math optimization purpose).
Definition conf.h:122
bool jo_get_input_gun_position(const int port, int *const x, int *const y)
Get the position on the screen where the light gun points.
@ JO_GUN_TRIGGER
Trigger of a light gun (the same bit as JO_KEY_A: a gun works with the code written for a pad).
Definition input.h:72
jo_gamepad_type jo_get_input_type(const int port)
Get input type for the given port.
@ JoLightGun
Light gun (Virtua Gun, Stunner): JO_GUN_TRIGGER, JO_GUN_START_BUTTON and jo_get_input_gun_position().
Definition input.h:102

◆ jo_get_input_type()

jo_gamepad_type jo_get_input_type ( const int port)

Get input type for the given port.

Parameters
portGamepad port
Returns
Input type (Pad, Mouse, etc)

◆ jo_get_mouse_pos_x()

__jo_force_inline int jo_get_mouse_pos_x ( const int port)
static

Get mouse X position.

Parameters
portGamepad port
Returns
X coordinate

◆ jo_get_mouse_pos_y()

__jo_force_inline int jo_get_mouse_pos_y ( const int port)
static

Get mouse Y position.

Parameters
portGamepad port
Returns
Y coordinate

◆ jo_get_player_input_port()

int jo_get_player_input_port ( const int player)

The port (the index of jo_inputs) of the gamepad of a player: the devices of the port 1 are 0 to 5 (a multitap), those of the port 2 are 6 to 11; 2 gamepads without multitap: 0 and 6.

Parameters
player0: the first connected device, 1: the second one...
Returns
The port, -1 if there are not so many devices

◆ jo_get_raw_input_key_pressed()

__jo_force_inline unsigned short jo_get_raw_input_key_pressed ( const int port)
static

Get raw input data for the given port.

Parameters
portGamepad port
Returns
Raw input data

◆ jo_is_input_analog()

__jo_force_inline bool jo_is_input_analog ( const int port)
static

Check if connected input is analog.

Parameters
portinput port
Returns
true if connected controller has analog axies

◆ jo_is_input_available()

__jo_force_inline bool jo_is_input_available ( const int port)
static

Check if the input is available for the given port.

Parameters
portGamepad port
Returns
true if the input is available otherwise false

◆ jo_is_input_key_down()

__jo_force_inline bool jo_is_input_key_down ( const int port,
const jo_gamepad_keys key )
static

Check if the key is down for the given port.

Parameters
portGamepad port
keyKey value
Returns
true if the key is down otherwise false

◆ jo_is_input_key_pressed()

__jo_force_inline bool jo_is_input_key_pressed ( const int port,
const jo_gamepad_keys key )
static

Check if the key is pressed for the given port.

Parameters
portGamepad port
keyKey value
Returns
true if the key is pressed otherwise false

◆ jo_is_pad1_available()

__jo_force_inline bool jo_is_pad1_available ( void )
static

Check if the first gamepad is plugged.

Returns
true if the first gamepad is plugged otherwise false

◆ jo_is_pad1_key_down()

__jo_force_inline bool jo_is_pad1_key_down ( jo_gamepad_keys key)
static

Check if the key is down on the first gamepad.

Parameters
keyKey value
Returns
true if the key is down on the first gamepad otherwise false

◆ jo_is_pad1_key_pressed()

__jo_force_inline bool jo_is_pad1_key_pressed ( jo_gamepad_keys key)
static

Check if the key is pressed on the first gamepad.

Parameters
keyKey value
Returns
true if the key is pressed on the first gamepad otherwise false

◆ jo_is_pad2_available()

__jo_force_inline bool jo_is_pad2_available ( void )
static

Check if the second gamepad is plugged (the second device: on the port 2, or on a multitap of the port 1).

Returns
true if the second gamepad is plugged otherwise false

◆ jo_is_pad2_key_down()

__jo_force_inline bool jo_is_pad2_key_down ( jo_gamepad_keys key)
static

Check if the key is down on the second gamepad.

Parameters
keyKey value
Returns
true if the key is down on the second gamepad otherwise false

◆ jo_is_pad2_key_pressed()

__jo_force_inline bool jo_is_pad2_key_pressed ( jo_gamepad_keys key)
static

Check if the key is pressed on the second gamepad.

Parameters
keyKey value
Returns
true if the key is pressed on the second gamepad otherwise false

Variable Documentation

◆ jo_inputs

jo_peripheral jo_inputs[(12)]
extern