fix controller assignment

This commit is contained in:
radius 2018-07-01 10:20:01 -05:00
parent c85d981201
commit 5a75d5dec8
1 changed files with 89 additions and 70 deletions

View File

@ -194,13 +194,15 @@ void retro_set_environment(retro_environment_t cb)
environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, variables); environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, variables);
const struct retro_controller_description port_1[] = { static const struct retro_controller_description port_1[] = {
{ "None", RETRO_DEVICE_NONE },
{ "SNES Joypad", RETRO_DEVICE_JOYPAD }, { "SNES Joypad", RETRO_DEVICE_JOYPAD },
{ "SNES Mouse", RETRO_DEVICE_MOUSE }, { "SNES Mouse", RETRO_DEVICE_MOUSE },
{ "Multitap", RETRO_DEVICE_JOYPAD_MULTITAP }, { "Multitap", RETRO_DEVICE_JOYPAD_MULTITAP },
}; };
const struct retro_controller_description port_2[] = { static const struct retro_controller_description port_2[] = {
{ "None", RETRO_DEVICE_NONE },
{ "SNES Joypad", RETRO_DEVICE_JOYPAD }, { "SNES Joypad", RETRO_DEVICE_JOYPAD },
{ "SNES Mouse", RETRO_DEVICE_MOUSE }, { "SNES Mouse", RETRO_DEVICE_MOUSE },
{ "Multitap", RETRO_DEVICE_JOYPAD_MULTITAP }, { "Multitap", RETRO_DEVICE_JOYPAD_MULTITAP },
@ -208,10 +210,21 @@ void retro_set_environment(retro_environment_t cb)
{ "Justifier", RETRO_DEVICE_LIGHTGUN_JUSTIFIER }, { "Justifier", RETRO_DEVICE_LIGHTGUN_JUSTIFIER },
}; };
const struct retro_controller_info ports[] = { static const struct retro_controller_description port_3[] = {
{ port_1, 3 }, { "None", RETRO_DEVICE_NONE },
{ port_2, 5 }, { "SNES Joypad", RETRO_DEVICE_JOYPAD },
{ 0, 0 }, };
static const struct retro_controller_info ports[] = {
{ port_1, 4 },
{ port_2, 6 },
{ port_3, 2 },
{ port_3, 2 },
{ port_3, 2 },
{ port_3, 2 },
{ port_3, 2 },
{ port_3, 2 },
{},
}; };
environ_cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports); environ_cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports);
@ -447,7 +460,7 @@ void retro_reset()
static unsigned snes_devices[2]; static unsigned snes_devices[2];
void retro_set_controller_port_device(unsigned port, unsigned device) void retro_set_controller_port_device(unsigned port, unsigned device)
{ {
if (port < 2) if (port < 8)
{ {
int offset = snes_devices[0] == RETRO_DEVICE_JOYPAD_MULTITAP ? 4 : 1; int offset = snes_devices[0] == RETRO_DEVICE_JOYPAD_MULTITAP ? 4 : 1;
switch (device) switch (device)
@ -472,12 +485,15 @@ void retro_set_controller_port_device(unsigned port, unsigned device)
S9xSetController(port, CTL_JUSTIFIER, 0, 0, 0, 0); S9xSetController(port, CTL_JUSTIFIER, 0, 0, 0, 0);
snes_devices[port] = RETRO_DEVICE_LIGHTGUN_JUSTIFIER; snes_devices[port] = RETRO_DEVICE_LIGHTGUN_JUSTIFIER;
break; break;
case RETRO_DEVICE_NONE:
S9xSetController(port, CTL_NONE, 0, 0, 0, 0);
snes_devices[port] = RETRO_DEVICE_NONE;
break;
default: default:
if (log_cb) if (log_cb)
log_cb(RETRO_LOG_ERROR, "[libretro]: Invalid device (%d).\n", device); log_cb(RETRO_LOG_ERROR, "[libretro]: Invalid device (%d).\n", device);
break;
} }
if (!port)
retro_set_controller_port_device(1, snes_devices[1]);
} }
else if(device != RETRO_DEVICE_NONE) else if(device != RETRO_DEVICE_NONE)
log_cb(RETRO_LOG_INFO, "[libretro]: Nonexistent Port (%d).\n", port); log_cb(RETRO_LOG_INFO, "[libretro]: Nonexistent Port (%d).\n", port);
@ -1201,6 +1217,9 @@ static void report_buttons()
S9xReportButton(MAKE_BUTTON(2, i), input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, i)); S9xReportButton(MAKE_BUTTON(2, i), input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, i));
break; break;
case RETRO_DEVICE_NONE:
break;
default: default:
if (log_cb) if (log_cb)
log_cb(RETRO_LOG_ERROR, "[libretro]: Unknown device...\n"); log_cb(RETRO_LOG_ERROR, "[libretro]: Unknown device...\n");