From ce45d3f2dae90d40414d57ed32a85081c73171c9 Mon Sep 17 00:00:00 2001 From: sorgelig Date: Fri, 24 Apr 2020 07:50:58 +0800 Subject: [PATCH] input: support for JammaSD to joystick translation. --- MiSTer.ini | 5 +++++ cfg.cpp | 2 ++ cfg.h | 2 ++ input.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+) diff --git a/MiSTer.ini b/MiSTer.ini index ddad794..8b0fa0a 100644 --- a/MiSTer.ini +++ b/MiSTer.ini @@ -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 diff --git a/cfg.cpp b/cfg.cpp index 9374bb2..91fb7ff 100644 --- a/cfg.cpp +++ b/cfg.cpp @@ -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)); diff --git a/cfg.h b/cfg.h index b98cf44..2664d4b 100644 --- a/cfg.h +++ b/cfg.h @@ -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]; diff --git a/input.cpp b/input.cpp index 6ef6b05..36b7e88 100644 --- a/input.cpp +++ b/input.cpp @@ -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) {