input: display controller's player number.
This commit is contained in:
84
input.cpp
84
input.cpp
@@ -1801,6 +1801,9 @@ static int ds_mouse_emu = 0;
|
||||
|
||||
static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int dev)
|
||||
{
|
||||
if (ev->type != EV_KEY && ev->type != EV_ABS && ev->type != EV_REL) return;
|
||||
if (ev->type == EV_KEY && !ev->code) return;
|
||||
|
||||
static uint16_t last_axis = 0;
|
||||
|
||||
int sub_dev = dev;
|
||||
@@ -1808,8 +1811,6 @@ static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int
|
||||
//check if device is a part of multifunctional device
|
||||
if (input[dev].bind >= 0) dev = input[dev].bind;
|
||||
|
||||
if (ev->type == EV_KEY && !ev->code) return;
|
||||
|
||||
//mouse
|
||||
if (ev->type == EV_KEY && ev->code >= BTN_MOUSE && ev->code < BTN_JOYSTICK)
|
||||
{
|
||||
@@ -1826,6 +1827,29 @@ static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int
|
||||
int enter = (ev->type == EV_KEY && ev->code == KEY_ENTER);
|
||||
int origcode = ev->code;
|
||||
|
||||
if (!input[dev].num && ((ev->type == EV_KEY && ev->code >= 256) || (input[dev].quirk == QUIRK_PDSP && ev->type == EV_REL)))
|
||||
{
|
||||
for (uint8_t num = 1; num < NUMDEV + 1; num++)
|
||||
{
|
||||
int found = 0;
|
||||
for (int i = 0; i < NUMDEV; i++)
|
||||
{
|
||||
// paddles/spinners overlay on top of other gamepad
|
||||
if (!((input[dev].quirk == QUIRK_PDSP) ^ (input[i].quirk == QUIRK_PDSP)))
|
||||
{
|
||||
found = (input[i].num == num);
|
||||
if (found) break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
input[dev].num = num;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!input[dev].has_mmap)
|
||||
{
|
||||
if (input[dev].quirk != QUIRK_PDSP)
|
||||
@@ -1846,6 +1870,12 @@ static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int
|
||||
{
|
||||
memset(input[dev].map, 0, sizeof(input[dev].map));
|
||||
input[dev].map[map_paddle_btn()] = 0x120;
|
||||
if (cfg.controller_info)
|
||||
{
|
||||
char str[32];
|
||||
sprintf(str, "P%d paddle/spinner", input[dev].num);
|
||||
Info(str, cfg.controller_info * 1000);
|
||||
}
|
||||
}
|
||||
else if (!load_map(get_map_name(dev, 0), &input[dev].map, sizeof(input[dev].map)))
|
||||
{
|
||||
@@ -1855,7 +1885,7 @@ static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int
|
||||
if (input[dev].has_mmap == 1)
|
||||
{
|
||||
// not defined try to guess the mapping
|
||||
map_joystick(input[dev].map, input[dev].mmap);
|
||||
map_joystick(input[dev].map, input[dev].mmap, input[dev].num);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1866,7 +1896,7 @@ static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int
|
||||
}
|
||||
else
|
||||
{
|
||||
map_joystick_show(input[dev].map, input[dev].mmap);
|
||||
map_joystick_show(input[dev].map, input[dev].mmap, input[dev].num);
|
||||
}
|
||||
input[dev].has_map++;
|
||||
}
|
||||
@@ -1914,29 +1944,6 @@ static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int
|
||||
osd_timer = 0;
|
||||
}
|
||||
|
||||
if (!input[dev].num && ev->type == EV_KEY && ev->code >= 256)
|
||||
{
|
||||
for (uint8_t num = 1; num < NUMDEV + 1; num++)
|
||||
{
|
||||
int found = 0;
|
||||
for (int i = 0; i < NUMDEV; i++)
|
||||
{
|
||||
// paddles/spinners overlay on top of other gamepad
|
||||
if (!((input[dev].quirk == QUIRK_PDSP) ^ (input[i].quirk == QUIRK_PDSP)))
|
||||
{
|
||||
found = (input[i].num == num);
|
||||
if (found) break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
input[dev].num = num;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//mapping
|
||||
if (mapping && (mapping_dev >= 0 || ev->value)
|
||||
&& !((mapping_type < 2 || !mapping_button) && (cancel || enter))
|
||||
@@ -2624,29 +2631,6 @@ static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int
|
||||
case EV_REL:
|
||||
if (!user_io_osd_is_visible() && ev->code == 7)
|
||||
{
|
||||
// paddles/spinners overlay on top of other gamepad
|
||||
if (input[dev].quirk == QUIRK_PDSP && !input[dev].num)
|
||||
{
|
||||
for (uint8_t num = 1; num < NUMDEV + 1; num++)
|
||||
{
|
||||
int found = 0;
|
||||
for (int i = 0; i < NUMDEV; i++)
|
||||
{
|
||||
if (input[dev].quirk == QUIRK_PDSP)
|
||||
{
|
||||
found = (input[i].num == num);
|
||||
if (found) break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
input[dev].num = num;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (input[dev].num && input[dev].num <= NUMPLAYERS)
|
||||
{
|
||||
int value = ev->value;
|
||||
|
||||
@@ -114,7 +114,7 @@ static int is_fire(char* name)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void map_joystick(uint32_t *map, uint32_t *mmap)
|
||||
void map_joystick(uint32_t *map, uint32_t *mmap, int num)
|
||||
{
|
||||
static char mapinfo[1024];
|
||||
/*
|
||||
@@ -125,7 +125,8 @@ void map_joystick(uint32_t *map, uint32_t *mmap)
|
||||
A, B, X, Y, L, R, Select, Start
|
||||
*/
|
||||
read_buttons();
|
||||
sprintf(mapinfo, "Default (%s) map:", defaults ? "pos" : "name");
|
||||
sprintf(mapinfo, "P%d map:", num);
|
||||
if (!num) sprintf(mapinfo, "Map:");
|
||||
|
||||
map[SYS_BTN_RIGHT] = mmap[SYS_BTN_RIGHT] & 0xFFFF;
|
||||
map[SYS_BTN_LEFT] = mmap[SYS_BTN_LEFT] & 0xFFFF;
|
||||
@@ -269,18 +270,20 @@ static const char* get_std_name(uint16_t code, uint32_t *mmap)
|
||||
return "[ ]";
|
||||
}
|
||||
|
||||
void map_joystick_show(uint32_t *map, uint32_t *mmap)
|
||||
void map_joystick_show(uint32_t *map, uint32_t *mmap, int num)
|
||||
{
|
||||
static char mapinfo[1024];
|
||||
read_buttons();
|
||||
mapinfo[0] = 0;
|
||||
|
||||
sprintf(mapinfo, "P%d, map:", num);
|
||||
if(!num) sprintf(mapinfo, "Map:");
|
||||
|
||||
// loop through core requested buttons and construct result map
|
||||
for (int i = 0; i < joy_count; i++)
|
||||
{
|
||||
if (!strcmp(joy_names[i], "-")) continue;
|
||||
|
||||
if(mapinfo[0]) strcat(mapinfo, "\n");
|
||||
strcat(mapinfo, "\n");
|
||||
strcat(mapinfo, get_std_name((uint16_t)(map[i + DPAD_COUNT]), mmap));
|
||||
strcat(mapinfo, ": ");
|
||||
strcat(mapinfo, joy_names[i]);
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
void map_joystick(uint32_t *map, uint32_t *mmap);
|
||||
void map_joystick_show(uint32_t *map, uint32_t *mmap);
|
||||
void map_joystick(uint32_t *map, uint32_t *mmap, int num);
|
||||
void map_joystick_show(uint32_t *map, uint32_t *mmap, int num);
|
||||
int map_paddle_btn();
|
||||
|
||||
#endif // JOYMAPPING_H
|
||||
|
||||
Reference in New Issue
Block a user