Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL3 preparation (event_sdl.c). #420

Merged
merged 4 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions arch/switch/pad.config
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
# Buttons 17-24 are directional axis "buttons" ignored by MZX because MZX does
# its own internal analog-to-digital conversion.

# Because the Switch uses SDL2, MZX can generate mappings automatically with
# the SDL_GameController API. However, this API is based on XInput and has
# Because the Switch uses SDL, MZX can generate mappings automatically with
# the SDL gamepad API. However, this API is based on XInput and has
# the face buttons inverted from where they'd be expected on a Nintendo system.

gamecontroller.a = act_b
gamecontroller.b = act_a
gamecontroller.x = act_y
gamecontroller.y = act_x
gamepad.a = act_b
gamepad.b = act_a
gamepad.x = act_y
gamepad.y = act_x
58 changes: 29 additions & 29 deletions config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -650,47 +650,47 @@
# joystick number 'X' can be substituted with a range '[Z,W]', which will
# assign the control for all joysticks numbered Z through W (inclusive).

# Automatic mapping for actions is handled using SDL 2's game controller API.
# Supported controllers should generally "just work" when they're plugged in.
# Automatic mapping for actions is handled using SDL's gamepad API.
# Supported gamepads should generally "just work" when they're plugged in.
# This setting can be used to globally disable the automatic mapping feature
# entirely. If 1, it will be enabled (default). If 0, it will be disabled.

# gamecontroller_enable = 1
# gamepad_enable = 1

# Controllers that aren't supported can be fixed by adding SDL mapping strings.
# Gamepads that aren't supported can be fixed by adding SDL mapping strings.
# This config option adds a new mapping string and can be used multiple times;
# each line adds a new mapping. See docs/joystick.html for more information.

# gamecontroller_add =
# gamepad_add =

# The following settings can be used to globally customize the automated
# joystick mappings generated from SDL mapping strings.
# See docs/joystick.html for more information.

# gamecontroller.a = act_a
# gamecontroller.b = act_b
# gamecontroller.x = act_x
# gamecontroller.y = act_y
# gamecontroller.back = act_select
# gamecontroller.start = act_start
# gamecontroller.leftstick = act_lstick
# gamecontroller.rightstick = act_rstick
# gamecontroller.leftshoulder = act_lshoulder
# gamecontroller.rightshoulder = act_rshoulder
# gamecontroller.dpup = act_up
# gamecontroller.dpdown = act_down
# gamecontroller.dpleft = act_left
# gamecontroller.dpright = act_right
# gamecontroller.-leftx = act_l_left
# gamecontroller.+leftx = act_l_right
# gamecontroller.-lefty = act_l_up
# gamecontroller.+lefty = act_l_down
# gamecontroller.-rightx = act_r_left
# gamecontroller.+rightx = act_r_right
# gamecontroller.-righty = act_r_up
# gamecontroller.+righty = act_r_down
# gamecontroller.lefttrigger = act_ltrigger
# gamecontroller.righttrigger = act_rtrigger
# gamepad.a = act_a
# gamepad.b = act_b
# gamepad.x = act_x
# gamepad.y = act_y
# gamepad.back = act_select
# gamepad.start = act_start
# gamepad.leftstick = act_lstick
# gamepad.rightstick = act_rstick
# gamepad.leftshoulder = act_lshoulder
# gamepad.rightshoulder = act_rshoulder
# gamepad.dpup = act_up
# gamepad.dpdown = act_down
# gamepad.dpleft = act_left
# gamepad.dpright = act_right
# gamepad.-leftx = act_l_left
# gamepad.+leftx = act_l_right
# gamepad.-lefty = act_l_up
# gamepad.+lefty = act_l_down
# gamepad.-rightx = act_r_left
# gamepad.+rightx = act_r_right
# gamepad.-righty = act_r_up
# gamepad.+righty = act_r_down
# gamepad.lefttrigger = act_ltrigger
# gamepad.righttrigger = act_rtrigger


# Misc Options
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ FREAD/FREADn bugfixes, as the old behavior was unusably buggy.

USERS

+ All "gamecontroller[...]" config.txt options have been renamed
to "gamepad[...]". The old names are still supported.
+ HTML5: fixed the poor performance of FREADn and other features
that rely on calculating the length of an open file.
+ Setting a string offset, limit, or splice to FREADn now
Expand Down
18 changes: 9 additions & 9 deletions docs/joystick.html
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ <h3>Adding/Modifying Controller Support</h3>
</p>

<code class="example" style="word-wrap: break-word">
gamecontroller_add = 030000005e0400008e02000000007801,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Windows,
gamepad_add = 030000005e0400008e02000000007801,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,platform:Windows,
</code>

<p>
Expand All @@ -667,9 +667,9 @@ <h3>Adding/Modifying Controller Support</h3>
</p>

<code class="example">
gamecontroller.SDLBUTTON = act_NAME
gamecontroller.+SDLAXIS = act_NAME
gamecontroller.-SDLAXIS = act_NAME
gamepad.SDLBUTTON = act_NAME
gamepad.+SDLAXIS = act_NAME
gamepad.-SDLAXIS = act_NAME
</code>

<p>
Expand All @@ -687,7 +687,7 @@ <h3>Adding/Modifying Controller Support</h3>
</p>

<code class="example">
gamecontroller_enable = 0
gamepad_enable = 0
</code>
</section>

Expand Down Expand Up @@ -1151,10 +1151,10 @@ <h3>Switch</h3>
</p>

<code class="example">
gamecontroller.a = act_b
gamecontroller.b = act_a
gamecontroller.x = act_y
gamecontroller.y = act_x
gamepad.a = act_b
gamepad.b = act_a
gamepad.x = act_y
gamepad.y = act_x
</code>

<p>
Expand Down
36 changes: 23 additions & 13 deletions src/configure.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ static const struct config_info user_conf_default =
true, // pc_speaker_on

// Event options
true, // allow_gamecontroller
true, // allow_gamepad
false, // pause_on_unfocus
1, // num_buffered_events

Expand Down Expand Up @@ -957,36 +957,43 @@ static void config_set_joy_axis_threshold(struct config_info *conf, char *name,

#ifdef CONFIG_SDL
#if SDL_VERSION_ATLEAST(2,0,0)
#define GC_ENUM "%15[-+0-9A-Za-z_]"
#define GAMEPAD_ENUM "%15[-+0-9A-Za-z_]"

static void config_sdl_gc_set(struct config_info *conf, char *name,
static void config_gamepad_set(struct config_info *conf, char *name,
char *value, char *extended_data)
{
char gc_sym[16];
char gamepad_sym[16];
char key[16];
int read = 0;

if(sscanf(name, "gamecontroller." GC_ENUM "%n", gc_sym, &read) != 1
// Option may be either "gamepad.[enum]" or "gamecontroller.[enum]".
if(!strncmp(name, "gamepad", 7))
name += 7;
else
if(!strncmp(name, "gamecontroller", 14))
name += 14;

if(sscanf(name, "." GAMEPAD_ENUM "%n", gamepad_sym, &read) != 1
|| (name[read] != 0))
return;

read = 0;
if(sscanf(value, JOY_ENUM "%n", key, &read) != 1 || (value[read] != 0))
return;

gamecontroller_map_sym(gc_sym, key);
gamepad_map_sym(gamepad_sym, key);
}

static void config_sdl_gc_add(struct config_info *conf, char *name,
static void config_gamepad_add(struct config_info *conf, char *name,
char *value, char *extended_data)
{
gamecontroller_add_mapping(value);
gamepad_add_mapping(value);
}

static void config_sdl_gc_enable(struct config_info *conf, char *name,
static void config_gamepad_enable(struct config_info *conf, char *name,
char *value, char *extended_data)
{
config_boolean(&conf->allow_gamecontroller, value);
config_boolean(&conf->allow_gamepad, value);
}

#endif // SDL_VERSION_ATLEAST(2,0,0)
Expand Down Expand Up @@ -1231,9 +1238,12 @@ static const struct config_entry config_options[] =
{ "fullscreen_windowed", config_set_fullscreen_windowed, false },
#ifdef CONFIG_SDL
#if SDL_VERSION_ATLEAST(2,0,0)
{ "gamecontroller.*", config_sdl_gc_set, false },
{ "gamecontroller_add", config_sdl_gc_add, false },
{ "gamecontroller_enable", config_sdl_gc_enable, false },
{ "gamecontroller.*", config_gamepad_set, false },
{ "gamecontroller_add", config_gamepad_add, false },
{ "gamecontroller_enable", config_gamepad_enable, false },
{ "gamepad.*", config_gamepad_set, false },
{ "gamepad_add", config_gamepad_add, false },
{ "gamepad_enable", config_gamepad_enable, false },
#endif
#endif
{ "gl_filter_method", config_set_gl_filter_method, false },
Expand Down
2 changes: 1 addition & 1 deletion src/configure.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ struct config_info
boolean pc_speaker_on;

// Event options
boolean allow_gamecontroller;
boolean allow_gamepad;
boolean pause_on_unfocus;
int num_buffered_events;

Expand Down
4 changes: 2 additions & 2 deletions src/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ void __wait_event(void);
void __warp_mouse(int x, int y);

// "Driver" functions currently only supported by SDL.
void gamecontroller_map_sym(const char *sym, const char *value);
void gamecontroller_add_mapping(const char *mapping);
void gamepad_map_sym(const char *sym, const char *value);
void gamepad_add_mapping(const char *mapping);

#ifdef CONFIG_NDS
const struct buffered_status *load_status(void);
Expand Down
Loading