input: support for JammaSD to joystick translation.

This commit is contained in:
sorgelig
2020-04-24 07:50:58 +08:00
parent e666f71d6c
commit ce45d3f2da
4 changed files with 73 additions and 0 deletions

View File

@@ -97,3 +97,8 @@ refresh_max=0
; 1-10 (seconds) to display controller's button map upon first time key press
; 0 - disable
controller_info=6
; JammaSD keys to joysticks translation
; You have to provide correct VID and PID of your input device
jammasd_vid=0x04D8
jammasd_pid=0xF3AD

View File

@@ -66,6 +66,8 @@ static const ini_var_t ini_vars[] =
{ "CONTROLLER_INFO", (void*)(&(cfg.controller_info)), UINT8, 0, 10 },
{ "REFRESH_MIN", (void*)(&(cfg.refresh_min)), UINT8, 0, 150 },
{ "REFRESH_MAX", (void*)(&(cfg.refresh_max)), UINT8, 0, 150 },
{ "JAMMASD_VID", (void*)(&(cfg.jammasd_vid)), UINT16, 0, 0xFFFF },
{ "JAMMASD_PID", (void*)(&(cfg.jammasd_pid)), UINT16, 0, 0xFFFF },
};
static const int nvars = (int)(sizeof(ini_vars) / sizeof(ini_var_t));

2
cfg.h
View File

@@ -40,6 +40,8 @@ typedef struct {
uint16_t osd_timeout;
uint8_t gamepad_defaults;
uint8_t recents;
uint16_t jammasd_vid;
uint16_t jammasd_pid;
char bootcore[256];
char video_conf[1024];
char video_conf_pal[1024];

View File

@@ -852,6 +852,7 @@ enum QUIRK
QUIRK_MADCATZ360,
QUIRK_PDSP,
QUIRK_PDSP_ARCADE,
QUIRK_JAMMASD,
};
typedef struct
@@ -2635,6 +2636,49 @@ void mergedevs()
}
}
// jammasd have shifted keys: when 1P start is kept pressed, it acts as a shift key,
// outputting other key signals. Example: 1P start + 2P start = KEY_ESC
// Shifted keys are passed as normal keyboard keys.
static struct
{
uint16_t key;
uint16_t player;
uint16_t btn;
} jammasd2joy[] =
{
{KEY_5, 1, 0x120}, // 1P coin
{KEY_1, 1, 0x121}, // 1P start (shift key)
{KEY_UP, 1, 0x122}, // 1P up
{KEY_DOWN, 1, 0x123}, // 1P down
{KEY_LEFT, 1, 0x124}, // 1P left
{KEY_RIGHT, 1, 0x125}, // 1P right
{KEY_LEFTCTRL, 1, 0x126}, // 1P 1
{KEY_LEFTALT, 1, 0x127}, // 1P 2
{KEY_SPACE, 1, 0x128}, // 1P 3
{KEY_LEFTSHIFT, 1, 0x129}, // 1P 4
{KEY_Z, 1, 0x12A}, // 1P 5
{KEY_X, 1, 0x12B}, // 1P 6
{KEY_C, 1, 0x12C}, // 1P 7
{KEY_V, 1, 0x12D}, // 1P 8
{KEY_9, 1, 0x12E}, // Test
{KEY_F2, 1, 0x12F}, // service
{KEY_6, 2, 0x120}, // 2P coin
{KEY_2, 2, 0x121}, // 2P start
{KEY_R, 2, 0x122}, // 2P up
{KEY_F, 2, 0x123}, // 2P down
{KEY_D, 2, 0x124}, // 2P left
{KEY_G, 2, 0x125}, // 2P right
{KEY_A, 2, 0x126}, // 2P 1
{KEY_S, 2, 0x127}, // 2P 2
{KEY_Q, 2, 0x128}, // 2P 3
{KEY_W, 2, 0x129}, // 2P 4
{KEY_I, 2, 0x12A}, // 2P 5
{KEY_K, 2, 0x12B}, // 2P 6
{KEY_J, 2, 0x12C}, // 2P 7
{KEY_L, 2, 0x12D}, // 2P 8
};
int input_test(int getchar)
{
static char cur_leds = 0;
@@ -2805,6 +2849,12 @@ int input_test(int getchar)
// Includes other buttons and axes, works as a full featured gamepad.
if (strstr(uniq, "MiSTer-A1")) input[n].quirk = QUIRK_PDSP_ARCADE;
//JammaSD
if (cfg.jammasd_vid && cfg.jammasd_pid && input[n].vid == cfg.jammasd_vid && input[n].pid == cfg.jammasd_pid)
{
input[n].quirk = QUIRK_JAMMASD;
}
//Arduino and Teensy devices may share the same VID:PID, so additional field UNIQ is used to differentiate them
if ((input[n].vid == 0x2341 || (input[n].vid == 0x16C0 && (input[n].pid>>8) == 0x4)) && strlen(uniq))
{
@@ -3031,6 +3081,20 @@ int input_test(int getchar)
}
}
if (input[dev].quirk == QUIRK_JAMMASD && ev.type == EV_KEY)
{
input[dev].num = 0;
for (uint32_t i = 0; i <= sizeof(jammasd2joy) / sizeof(jammasd2joy[0]); i++)
{
if (jammasd2joy[i].key == ev.code)
{
ev.code = jammasd2joy[i].btn;
input[dev].num = jammasd2joy[i].player;
break;
}
}
}
//Menu combo on 8BitDo receiver in PSC mode
if (input[dev].vid == 0x054c && input[dev].pid == 0x0cda && ev.type == EV_KEY)
{