mirror of
https://github.com/libretro/RetroArch
synced 2025-03-14 01:19:01 +00:00
Fix mouse code for the most part. :)
This commit is contained in:
parent
a2a31e5944
commit
f9bd0ab672
@ -84,8 +84,8 @@ struct global
|
||||
bool audio_active;
|
||||
bool video_active;
|
||||
|
||||
bool has_mouse;
|
||||
bool has_scope;
|
||||
bool has_mouse[2];
|
||||
bool has_scope[2];
|
||||
|
||||
FILE *rom_file;
|
||||
char config_path[256];
|
||||
|
35
input/sdl.c
35
input/sdl.c
@ -183,36 +183,22 @@ static int16_t sdl_joypad_device_state(sdl_input_t *sdl, const struct snes_keybi
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Broken at the moment. Need more info.
|
||||
static int16_t sdl_mouse_device_state(sdl_input_t *sdl, const struct snes_keybind **binds,
|
||||
bool port, unsigned device, unsigned index, unsigned id)
|
||||
{
|
||||
int _x, _y;
|
||||
Uint8 btn = SDL_GetRelativeMouseState(&_x, &_y);
|
||||
sdl->mouse_x += _x;
|
||||
sdl->mouse_y += _y;
|
||||
SSNES_LOG("Mouse rel: %d %d, total %d %d\n", _x, _y, (int)sdl->mouse_x, (int)sdl->mouse_y);
|
||||
|
||||
int16_t retval;
|
||||
switch (id)
|
||||
{
|
||||
case SNES_DEVICE_ID_MOUSE_LEFT:
|
||||
retval = SDL_BUTTON(1) & btn ? 1 : 0;
|
||||
break;
|
||||
return sdl->mouse_l;
|
||||
case SNES_DEVICE_ID_MOUSE_RIGHT:
|
||||
retval = SDL_BUTTON(3) & btn ? 1 : 0;
|
||||
break;
|
||||
return sdl->mouse_r;
|
||||
case SNES_DEVICE_ID_MOUSE_X:
|
||||
retval = sdl->mouse_x;
|
||||
break;
|
||||
return sdl->mouse_x;
|
||||
case SNES_DEVICE_ID_MOUSE_Y:
|
||||
retval = sdl->mouse_y;
|
||||
break;
|
||||
return sdl->mouse_y;
|
||||
default:
|
||||
retval = 0;
|
||||
return 0;
|
||||
}
|
||||
SSNES_LOG("Retval: %d\n", (int)retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
// TODO: :D
|
||||
@ -258,11 +244,22 @@ static void sdl_input_free(void *data)
|
||||
}
|
||||
}
|
||||
|
||||
static void sdl_poll_mouse(sdl_input_t *sdl)
|
||||
{
|
||||
int _x, _y;
|
||||
Uint8 btn = SDL_GetRelativeMouseState(&_x, &_y);
|
||||
sdl->mouse_x = _x;
|
||||
sdl->mouse_y = _y;
|
||||
sdl->mouse_l = SDL_BUTTON(1) & btn ? 1 : 0;
|
||||
sdl->mouse_r = SDL_BUTTON(3) & btn ? 1 : 0;
|
||||
}
|
||||
|
||||
static void sdl_input_poll(void *data)
|
||||
{
|
||||
SDL_PumpEvents();
|
||||
SDL_Event event;
|
||||
SDL_JoystickUpdate();
|
||||
sdl_poll_mouse(data);
|
||||
|
||||
sdl_input_t *sdl = data;
|
||||
// Search for events...
|
||||
|
@ -33,6 +33,7 @@ typedef struct sdl_input
|
||||
unsigned *new_width;
|
||||
unsigned *new_height;
|
||||
int16_t mouse_x, mouse_y;
|
||||
int16_t mouse_l, mouse_r;
|
||||
} sdl_input_t;
|
||||
|
||||
#endif
|
||||
|
57
ssnes.c
57
ssnes.c
@ -234,13 +234,15 @@ static void print_help(void)
|
||||
puts("=================================================");
|
||||
puts("ssnes: Simple Super Nintendo Emulator (libsnes)");
|
||||
puts("=================================================");
|
||||
puts("Usage: ssnes [rom file] [-h/--help | -s/--save" FFMPEG_HELP_QUARK "]");
|
||||
puts("Usage: ssnes [rom file] [-h/--help | -c/--config | -v/--verbose | -t/--savestate | -m/--mouse | -p/--scope | -s/--save" FFMPEG_HELP_QUARK "]");
|
||||
puts("\t-h/--help: Show this help message");
|
||||
puts("\t-s/--save: Path for save file (*.srm). Required when rom is input from stdin");
|
||||
puts("\t-t/--savestate: Path to use for save states. If not selected, *.state will be assumed.");
|
||||
puts("\t-c/--config: Path for config file." SSNES_DEFAULT_CONF_PATH_STR);
|
||||
puts("\t-m/--mouse: Connect a virtual mouse into port 2 of the SNES.");
|
||||
puts("\t-p/--scope: Connect a virtual SuperScope into port 2 of the SNES.");
|
||||
puts("\t-m/--mouse: Connect a virtual mouse into designated port of the SNES (1 or 2).");
|
||||
puts("\tThis argument can be specified several times to connect more mice.");
|
||||
puts("\t-p/--scope: Connect a virtual SuperScope into designated port of the SNES (1 or 2).");
|
||||
puts("\tThis argument can be specified several times to connect more scopes.");
|
||||
|
||||
#ifdef HAVE_FFMPEG
|
||||
puts("\t-r/--record: Path to record video file. Settings for video/audio codecs are found in config file.");
|
||||
@ -264,8 +266,8 @@ static void parse_input(int argc, char *argv[])
|
||||
#endif
|
||||
{ "verbose", 0, NULL, 'v' },
|
||||
{ "config", 0, NULL, 'c' },
|
||||
{ "mouse", 0, NULL, 'm' },
|
||||
{ "scope", 0, NULL, 'p' },
|
||||
{ "mouse", 1, NULL, 'm' },
|
||||
{ "scope", 1, NULL, 'p' },
|
||||
{ "savestate", 1, NULL, 't' },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
@ -278,10 +280,11 @@ static void parse_input(int argc, char *argv[])
|
||||
#define FFMPEG_RECORD_ARG
|
||||
#endif
|
||||
|
||||
char optstring[] = "hs:vc:t:m" FFMPEG_RECORD_ARG;
|
||||
char optstring[] = "hs:vc:t:m:p:" FFMPEG_RECORD_ARG;
|
||||
for(;;)
|
||||
{
|
||||
int c = getopt_long(argc, argv, optstring, opts, &option_index);
|
||||
int port;
|
||||
|
||||
if (c == -1)
|
||||
break;
|
||||
@ -305,11 +308,25 @@ static void parse_input(int argc, char *argv[])
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
g_extern.has_mouse = true;
|
||||
port = strtol(optarg, NULL, 0);
|
||||
if (port < 1 || port > 2)
|
||||
{
|
||||
SSNES_ERR("Connect mouse to port 1 or 2.\n");
|
||||
print_help();
|
||||
exit(1);
|
||||
}
|
||||
g_extern.has_mouse[port - 1] = true;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
g_extern.has_scope = true;
|
||||
port = strtol(optarg, NULL, 0);
|
||||
if (port < 1 || port > 2)
|
||||
{
|
||||
SSNES_ERR("Connect scope to port 1 or 2.\n");
|
||||
print_help();
|
||||
exit(1);
|
||||
}
|
||||
g_extern.has_scope[port - 1] = true;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
@ -377,6 +394,24 @@ static void parse_input(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add rest of the controllers.
|
||||
static void init_controllers(void)
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (g_extern.has_mouse[i])
|
||||
{
|
||||
SSNES_LOG("Connecting mouse to port %d\n", i + 1);
|
||||
psnes_set_controller_port_device(i, SNES_DEVICE_MOUSE);
|
||||
}
|
||||
else if (g_extern.has_scope[i])
|
||||
{
|
||||
SSNES_LOG("Connecting scope to port %d\n", i + 1);
|
||||
psnes_set_controller_port_device(i, SNES_DEVICE_SUPER_SCOPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
parse_input(argc, argv);
|
||||
@ -420,11 +455,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
free(rom_buf);
|
||||
|
||||
if (g_extern.has_mouse)
|
||||
psnes_set_controller_port_device(1, SNES_DEVICE_MOUSE);
|
||||
else if (g_extern.has_scope)
|
||||
psnes_set_controller_port_device(1, SNES_DEVICE_SUPER_SCOPE);
|
||||
|
||||
init_controllers();
|
||||
|
||||
unsigned serial_size = psnes_serialize_size();
|
||||
uint8_t *serial_data = malloc(serial_size);
|
||||
|
Loading…
x
Reference in New Issue
Block a user