Added support for (track)balls to osd/sdl. [Couriersud]

To test it, I used my Logitech Trackball (normally a mouse) and configured it as a joystick.

Prerequisites:

- Locate your linux input device for the trackball. In my case that's /dev/input/event3
- "sudo chmod a+r /dev/input/event3"
- "export SDL_JOYSTICK_DEVICE=/dev/input/event3"

This forces sdl to recognize the trackball as a input device.

-mame64 missile -nomouse -w

Configure the trackball axis. Make sure the mouse pointer is outside the window and window still has keyboard focus - most modern window manager should support this. 

Quit and restart with

-mame64 missile -mouse -now

to hide the mouse. Voila. Works.
This commit is contained in:
Couriersud 2012-02-15 21:40:35 +00:00
parent 19f9947d9f
commit 19c3217408

View File

@ -95,6 +95,7 @@ struct _joystick_state
INT32 axes[MAX_AXES]; INT32 axes[MAX_AXES];
INT32 buttons[MAX_BUTTONS]; INT32 buttons[MAX_BUTTONS];
INT32 hatsU[MAX_HATS], hatsD[MAX_HATS], hatsL[MAX_HATS], hatsR[MAX_HATS]; INT32 hatsU[MAX_HATS], hatsD[MAX_HATS], hatsL[MAX_HATS], hatsR[MAX_HATS];
INT32 balls[MAX_AXES];
}; };
// generic device information // generic device information
@ -681,7 +682,7 @@ static device_info *devmap_class_register(running_machine &machine, device_map_t
static void sdlinput_register_joysticks(running_machine &machine) static void sdlinput_register_joysticks(running_machine &machine)
{ {
device_info *devinfo; device_info *devinfo;
int physical_stick, axis, button, hat, stick; int physical_stick, axis, button, hat, stick, ball;
char tempname[512]; char tempname[512];
SDL_Joystick *joy; SDL_Joystick *joy;
@ -709,7 +710,7 @@ static void sdlinput_register_joysticks(running_machine &machine)
devinfo->joystick.device = joy; devinfo->joystick.device = joy;
mame_printf_verbose("Joystick: %s\n", devinfo->name); mame_printf_verbose("Joystick: %s\n", devinfo->name);
mame_printf_verbose("Joystick: ... %d axes, %d buttons %d hats\n", SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumHats(joy)); mame_printf_verbose("Joystick: ... %d axes, %d buttons %d hats %d balls\n", SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumHats(joy), SDL_JoystickNumBalls(joy));
mame_printf_verbose("Joystick: ... Physical id %d mapped to logical id %d\n", physical_stick, stick); mame_printf_verbose("Joystick: ... Physical id %d mapped to logical id %d\n", physical_stick, stick);
// loop over all axes // loop over all axes
@ -764,6 +765,22 @@ static void sdlinput_register_joysticks(running_machine &machine)
itemid = (input_item_id) ((hat < INPUT_MAX_HATS) ? ITEM_ID_HAT1RIGHT + 4 * hat : ITEM_ID_OTHER_SWITCH); itemid = (input_item_id) ((hat < INPUT_MAX_HATS) ? ITEM_ID_HAT1RIGHT + 4 * hat : ITEM_ID_OTHER_SWITCH);
devinfo->device->add_item(tempname, itemid, generic_button_get_state, &devinfo->joystick.hatsR[hat]); devinfo->device->add_item(tempname, itemid, generic_button_get_state, &devinfo->joystick.hatsR[hat]);
} }
// loop over all (track)balls
for (ball = 0; ball < SDL_JoystickNumBalls(joy); ball++)
{
int itemid;
if (ball * 2 < INPUT_MAX_ADD_RELATIVE)
itemid = ITEM_ID_ADD_RELATIVE1 + ball * 2;
else
itemid = ITEM_ID_OTHER_AXIS_RELATIVE;
sprintf(tempname, "R%d %s", ball * 2, devinfo->name);
devinfo->device->add_item(tempname, (input_item_id) itemid, generic_axis_get_state, &devinfo->joystick.balls[ball * 2]);
sprintf(tempname, "R%d %s", ball * 2 + 1, devinfo->name);
devinfo->device->add_item(tempname, (input_item_id) (itemid + 1), generic_axis_get_state, &devinfo->joystick.balls[ball * 2 + 1]);
}
} }
mame_printf_verbose("Joystick: End initialization\n"); mame_printf_verbose("Joystick: End initialization\n");
} }
@ -1477,6 +1494,12 @@ void sdlinput_poll(running_machine &machine)
ui_input_push_mouse_move_event(machine, window->target, cx, cy); ui_input_push_mouse_move_event(machine, window->target, cx, cy);
} }
break; break;
case SDL_JOYBALLMOTION:
devinfo = generic_device_find_index(joystick_list, joy_map.logical[event.jball.which]);
//printf("Ball %d %d\n", event.jball.xrel, event.jball.yrel);
devinfo->joystick.balls[event.jball.ball * 2] = event.jball.xrel * INPUT_RELATIVE_PER_PIXEL;
devinfo->joystick.balls[event.jball.ball * 2 + 1] = event.jball.yrel * INPUT_RELATIVE_PER_PIXEL;
break;
#if (!SDLMAME_SDL2) #if (!SDLMAME_SDL2)
case SDL_APPMOUSEFOCUS: case SDL_APPMOUSEFOCUS:
app_has_mouse_focus = event.active.gain; app_has_mouse_focus = event.active.gain;