Revision: 45547
http://sourceforge.net/p/vice-emu/code/45547
Author: compyx
Date: 2025-03-19 21:46:40 +0000 (Wed, 19 Mar 2025)
Log Message:
-----------
Joystick: fix SDL UI to use updated joystick event functions
Only tested with SDL 2.x so far.
Modified Paths:
--------------
branches/compyx/joymap-001/vice/src/arch/sdl/joy.c
branches/compyx/joymap-001/vice/src/arch/sdl/joy.h
branches/compyx/joymap-001/vice/src/arch/sdl/ui.c
branches/compyx/joymap-001/vice/src/arch/sdl/uimenu.c
Modified: branches/compyx/joymap-001/vice/src/arch/sdl/joy.c
===================================================================
--- branches/compyx/joymap-001/vice/src/arch/sdl/joy.c 2025-03-19 15:39:19 UTC (rev 45546)
+++ branches/compyx/joymap-001/vice/src/arch/sdl/joy.c 2025-03-19 21:46:40 UTC (rev 45547)
@@ -164,12 +164,12 @@
/* ------------------------------------------------------------------------- */
-static bool sdl_joystick_open(int joyport, joystick_device_t *joydev)
+static bool sdl_joystick_open(joystick_device_t *joydev)
{
return true;
}
-static void sdl_joystick_poll(int joyport, joystick_device_t *joydev)
+static void sdl_joystick_poll(joystick_device_t *joydev)
{
/* NOP: handled in SDL event loop */
}
@@ -461,6 +461,55 @@
return 0;
}
+
+bool sdljoy_get_joy_for_event(VICE_SDL_JoystickID device_id,
+ joystick_device_t **joy_device,
+ int *joy_index)
+{
+ int count = joystick_device_count();
+
+ if (count > 0) {
+ int i;
+
+ for (i = 0; i < count; i++) {
+ joystick_device_t *joydev = joystick_device_by_index(i);
+ joy_priv_t *priv = joydev->priv;
+
+ if (priv->id == device_id) {
+ if (joy_device != NULL) {
+ *joy_device = joydev;
+ }
+ if (joy_index != NULL) {
+ *joy_index = i;
+ }
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+
+joystick_device_t *sdljoy_get_joydev_for_event(VICE_SDL_JoystickID event_device_id)
+{
+ int i;
+ int count;
+
+ count = joystick_device_count();
+ for (i = 0; i < count; i++) {
+ joystick_device_t *joydev = joystick_device_by_index(i);
+
+ if (joydev != NULL) {
+ joy_priv_t *priv = joydev->priv;
+
+ if (priv->id == event_device_id) {
+ return joydev;
+ }
+ }
+ }
+}
+
+
int sdljoy_get_joynum_for_event(VICE_SDL_JoystickID event_device_id)
{
int i;
@@ -481,6 +530,9 @@
return -1;
}
+
+
+
static joystick_mapping_t *sdljoy_get_mapping(SDL_Event e)
{
joystick_mapping_t *retval = NULL;
@@ -593,15 +645,17 @@
return cur;
}
-void sdljoy_axis_event(Uint8 joynum, Uint8 axis, Sint16 value)
+void sdljoy_axis_event(Uint8 joynum, Uint8 axisnum, Sint16 value)
{
+ joystick_device_t *joydev = joystick_device_by_index(joynum);
+ joystick_axis_t *axis = joydev->axes[axisnum];
joystick_axis_value_t cur, prev;
- prev = joy_axis_prev(joynum, axis);
+ prev = joy_axis_prev(joynum, axisnum);
cur = sdljoy_axis_direction(value, prev);
- joy_axis_event(joynum, axis, cur);
+ joy_axis_event(joydev, axis, cur);
}
static ui_menu_action_t sdljoy_perform_event_for_menu_action(joystick_mapping_t* event, Sint16 value)
Modified: branches/compyx/joymap-001/vice/src/arch/sdl/joy.h
===================================================================
--- branches/compyx/joymap-001/vice/src/arch/sdl/joy.h 2025-03-19 15:39:19 UTC (rev 45546)
+++ branches/compyx/joymap-001/vice/src/arch/sdl/joy.h 2025-03-19 21:46:40 UTC (rev 45547)
@@ -34,7 +34,7 @@
#include "types.h"
#include "vice_sdl.h"
-
+#include "joystick.h"
#include "uimenu.h"
void joystick_close(void);
@@ -59,7 +59,12 @@
void sdljoy_unset(SDL_Event e);
void sdljoy_set_joystick_axis(SDL_Event e, int pot);
void sdljoy_delete_extra_mapping(int type);
+joystick_device_t *sdljoy_get_joydev_for_event(VICE_SDL_JoystickID event_device_id);
int sdljoy_get_joynum_for_event(VICE_SDL_JoystickID event_device_id);
+bool sdljoy_get_joy_for_event(VICE_SDL_JoystickID device_id,
+ joystick_device_t **joy_device,
+ int *joy_index);
+
int sdljoy_rescan(void);
void sdljoy_clear_presses(void);
Modified: branches/compyx/joymap-001/vice/src/arch/sdl/ui.c
===================================================================
--- branches/compyx/joymap-001/vice/src/arch/sdl/ui.c 2025-03-19 15:39:19 UTC (rev 45546)
+++ branches/compyx/joymap-001/vice/src/arch/sdl/ui.c 2025-03-19 21:46:40 UTC (rev 45547)
@@ -260,6 +260,10 @@
int joynum;
while (SDL_PollEvent(&e)) {
+ joystick_device_t *joydev = NULL;
+ joystick_button_t *button = NULL;
+ joystick_hat_t *hat = NULL;
+
switch (e.type) {
case SDL_KEYDOWN:
ui_display_kbd_status(&e);
@@ -271,28 +275,21 @@
break;
#ifdef HAVE_SDL_NUMJOYSTICKS
case SDL_JOYAXISMOTION:
- joynum = sdljoy_get_joynum_for_event((VICE_SDL_JoystickID)e.jaxis.which);
- if (joynum != -1) {
+ if (sdljoy_get_joy_for_event((VICE_SDL_JoystickID)e.jaxis.which, &joydev, &joynum)) {
sdljoy_axis_event(joynum, e.jaxis.axis, e.jaxis.value);
joystick_set_axis_value(joynum, e.jaxis.axis, (uint8_t)((~e.jaxis.value + 32768) >> 8));
}
break;
- case SDL_JOYBUTTONDOWN:
- joynum = sdljoy_get_joynum_for_event((VICE_SDL_JoystickID)e.jaxis.which);
- if (joynum != -1) {
- joy_button_event(joynum, e.jbutton.button, 1);
- }
- break;
+ case SDL_JOYBUTTONDOWN: /* fall through */
case SDL_JOYBUTTONUP:
- joynum = sdljoy_get_joynum_for_event((VICE_SDL_JoystickID)e.jaxis.which);
- if (joynum != -1) {
- joy_button_event(joynum, e.jbutton.button, 0);
+ if (sdljoy_get_joy_for_event((VICE_SDL_JoystickID)e.jbutton.which, &joydev, &joynum)) {
+ button = joydev->buttons[e.jbutton.button];
+ joy_button_event(joydev, button, e.type == SDL_JOYBUTTONDOWN ? 1: 0);
}
break;
case SDL_JOYHATMOTION:
- joynum = sdljoy_get_joynum_for_event((VICE_SDL_JoystickID)e.jaxis.which);
- if (joynum != -1) {
- joy_hat_event(joynum, e.jhat.hat, hat_map[e.jhat.value]);
+ if (sdljoy_get_joy_for_event((VICE_SDL_JoystickID)e.jaxis.which, &joydev, &joynum)) {
+ joy_hat_event(joydev, joydev->hats[e.jhat.hat], hat_map[e.jhat.value]);
}
break;
#endif
Modified: branches/compyx/joymap-001/vice/src/arch/sdl/uimenu.c
===================================================================
--- branches/compyx/joymap-001/vice/src/arch/sdl/uimenu.c 2025-03-19 15:39:19 UTC (rev 45546)
+++ branches/compyx/joymap-001/vice/src/arch/sdl/uimenu.c 2025-03-19 21:46:40 UTC (rev 45547)
@@ -1163,6 +1163,9 @@
#endif
do {
+ joystick_device_t *joydev = NULL;
+ int joynum = -1;
+
SDL_WaitEvent(&e);
switch (e.type) {
@@ -1198,13 +1201,22 @@
#ifdef HAVE_SDL_NUMJOYSTICKS
case SDL_JOYAXISMOTION:
- sdljoy_axis_event(e.jaxis.which, e.jaxis.axis, e.jaxis.value);
+ if (sdljoy_get_joy_for_event(e.jaxis.which, &joydev, &joynum)) {
+ sdljoy_axis_event(joynum, e.jaxis.axis, e.jaxis.value);
+ }
break;
- case SDL_JOYBUTTONDOWN:
- joy_button_event(e.jbutton.which, e.jbutton.button, 1);
+ case SDL_JOYBUTTONDOWN: /* fall through */
+ case SDL_JOYBUTTONUP:
+ if (sdljoy_get_joy_for_event(e.jbutton.which, &joydev, &joynum)) {
+ joy_button_event(joydev,
+ joydev->buttons[e.jbutton.button],
+ e.type == SDL_JOYBUTTONDOWN ? 1 : 0);
+ }
break;
case SDL_JOYHATMOTION:
- joy_hat_event(e.jhat.which, e.jhat.hat, e.jhat.value);
+ if (sdljoy_get_joy_for_event(e.jhat.which, &joydev, &joynum)) {
+ joy_hat_event(joydev, joydev->hats[e.jhat.hat], e.jhat.value);
+ }
break;
#endif
default:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|