allow remapping from L3/R3 (eg. VB)

This commit is contained in:
Shaun Inman 2023-02-03 20:02:38 -05:00
parent af73880160
commit e046f464d7
2 changed files with 42 additions and 32 deletions

View file

@ -402,8 +402,9 @@ enum {
SHORTCUT_COUNT, SHORTCUT_COUNT,
}; };
#define RETRO_BUTTON_COUNT 14 #define LOCAL_BUTTON_COUNT 14
static const char* device_button_names[RETRO_BUTTON_COUNT] = { #define RETRO_BUTTON_COUNT 16 // allow L3/R3 to be remapped by user if desired, eg. Virtual Boy uses extra buttons for right d-pad
static const char* device_button_names[LOCAL_BUTTON_COUNT] = {
[BTN_ID_UP] = "UP", [BTN_ID_UP] = "UP",
[BTN_ID_DOWN] = "DOWN", [BTN_ID_DOWN] = "DOWN",
[BTN_ID_LEFT] = "LEFT", [BTN_ID_LEFT] = "LEFT",
@ -434,6 +435,8 @@ static ButtonMapping default_button_mapping[] = {
{"R1 Button", RETRO_DEVICE_ID_JOYPAD_R, BTN_ID_R1}, {"R1 Button", RETRO_DEVICE_ID_JOYPAD_R, BTN_ID_R1},
{"L2 Button", RETRO_DEVICE_ID_JOYPAD_L2, BTN_ID_L2}, {"L2 Button", RETRO_DEVICE_ID_JOYPAD_L2, BTN_ID_L2},
{"R2 Button", RETRO_DEVICE_ID_JOYPAD_R2, BTN_ID_R2}, {"R2 Button", RETRO_DEVICE_ID_JOYPAD_R2, BTN_ID_R2},
{"L3 Button", RETRO_DEVICE_ID_JOYPAD_L3, BTN_ID_NONE},
{"R3 Button", RETRO_DEVICE_ID_JOYPAD_R3, BTN_ID_NONE},
{NULL,0,0} {NULL,0,0}
}; };
static const char* core_button_names[RETRO_BUTTON_COUNT]; static const char* core_button_names[RETRO_BUTTON_COUNT];
@ -687,8 +690,8 @@ static void Config_read(void) {
} }
int mod = 0; int mod = 0;
if (id>RETRO_BUTTON_COUNT) { if (id>LOCAL_BUTTON_COUNT) {
id -= RETRO_BUTTON_COUNT; id -= LOCAL_BUTTON_COUNT;
mod = 1; mod = 1;
} }
mapping->local = id; mapping->local = id;
@ -722,13 +725,13 @@ static void Config_write(int override) {
for (int i=0; config.controls[i].name; i++) { for (int i=0; config.controls[i].name; i++) {
ButtonMapping* mapping = &config.controls[i]; ButtonMapping* mapping = &config.controls[i];
int j = mapping->local + 1; int j = mapping->local + 1;
if (mapping->mod) j += RETRO_BUTTON_COUNT; if (mapping->mod) j += LOCAL_BUTTON_COUNT;
fprintf(file, "bind %s = %s\n", mapping->name, shortcut_labels[j]); fprintf(file, "bind %s = %s\n", mapping->name, shortcut_labels[j]);
} }
for (int i=0; config.shortcuts[i].name; i++) { for (int i=0; config.shortcuts[i].name; i++) {
ButtonMapping* mapping = &config.shortcuts[i]; ButtonMapping* mapping = &config.shortcuts[i];
int j = mapping->local + 1; int j = mapping->local + 1;
if (mapping->mod) j += RETRO_BUTTON_COUNT; if (mapping->mod) j += LOCAL_BUTTON_COUNT;
fprintf(file, "bind %s = %s\n", mapping->name, shortcut_labels[j]); fprintf(file, "bind %s = %s\n", mapping->name, shortcut_labels[j]);
} }
@ -1165,6 +1168,8 @@ static bool environment_callback(unsigned cmd, void *data) { // copied from pico
// default_button_mapping (indexed by RETRO_DEVICE_ID_JOYPAD_*?) // default_button_mapping (indexed by RETRO_DEVICE_ID_JOYPAD_*?)
// override_button_mapping (indexed by RETRO_DEVICE_ID_JOYPAD_*?) // override_button_mapping (indexed by RETRO_DEVICE_ID_JOYPAD_*?)
// ButtonMapping needs to be redefined to include retro_name local_name retro_id local_id local_default
// TODO: move all this to an Input_init()? // TODO: move all this to an Input_init()?
config.controls = core.overrides && core.overrides->button_mapping ? core.overrides->button_mapping : default_button_mapping; config.controls = core.overrides && core.overrides->button_mapping ? core.overrides->button_mapping : default_button_mapping;
@ -1178,7 +1183,9 @@ static bool environment_callback(unsigned cmd, void *data) { // copied from pico
memset(&present, 0, RETRO_BUTTON_COUNT * sizeof(int)); memset(&present, 0, RETRO_BUTTON_COUNT * sizeof(int));
for (int i=0; vars[i].description; i++) { for (int i=0; vars[i].description; i++) {
const struct retro_input_descriptor* var = &vars[i]; const struct retro_input_descriptor* var = &vars[i];
if (var->port==0 && var->device==RETRO_DEVICE_JOYPAD && var->index==0) { if (var->port!=0 || var->device!=RETRO_DEVICE_JOYPAD || var->index!=0) continue;
// TODO: don't ignore unavailable buttons, just override them to BTN_ID_NONE!
if (var->id>=RETRO_BUTTON_COUNT) { if (var->id>=RETRO_BUTTON_COUNT) {
printf("UNAVAILABLE: %s\n", var->description); fflush(stdout); printf("UNAVAILABLE: %s\n", var->description); fflush(stdout);
continue; continue;
@ -1189,7 +1196,6 @@ static bool environment_callback(unsigned cmd, void *data) { // copied from pico
present[var->id] = 1; present[var->id] = 1;
core_button_names[var->id] = var->description; core_button_names[var->id] = var->description;
} }
}
for (int i=0;default_button_mapping[i].name; i++) { for (int i=0;default_button_mapping[i].name; i++) {
ButtonMapping* mapping = &default_button_mapping[i]; ButtonMapping* mapping = &default_button_mapping[i];
@ -2611,7 +2617,7 @@ int OptionControls_bind(MenuList* list, int i) {
PAD_poll(); PAD_poll();
// NOTE: off by one because of the initial NONE value // NOTE: off by one because of the initial NONE value
for (int id=0; id<=RETRO_BUTTON_COUNT; id++) { for (int id=0; id<=LOCAL_BUTTON_COUNT; id++) {
if (PAD_justPressed(1 << id-1)) { if (PAD_justPressed(1 << id-1)) {
item->value = id; item->value = id;
button->local = id - 1; button->local = id - 1;
@ -2637,7 +2643,6 @@ static int OptionControls_openMenu(MenuList* list, int i) {
ButtonMapping* button = &config.controls[j]; ButtonMapping* button = &config.controls[j];
MenuItem* item = &OptionControls_menu.items[j]; MenuItem* item = &OptionControls_menu.items[j];
item->id = j; item->id = j;
// item->key = button->name; // TODO: tmp, lowercase this? prefix with "bind_" or don't lowercase and "bind "
item->name = button->name; item->name = button->name;
item->desc = NULL; item->desc = NULL;
item->value = button->local + 1; item->value = button->local + 1;
@ -2665,13 +2670,13 @@ static int OptionShortcuts_bind(MenuList* list, int i) {
PAD_poll(); PAD_poll();
// NOTE: off by one because of the initial NONE value // NOTE: off by one because of the initial NONE value
for (int id=0; id<=RETRO_BUTTON_COUNT; id++) { for (int id=0; id<=LOCAL_BUTTON_COUNT; id++) {
if (PAD_justPressed(1 << id-1)) { if (PAD_justPressed(1 << id-1)) {
fflush(stdout); fflush(stdout);
item->value = id; item->value = id;
button->local = id - 1; button->local = id - 1;
if (PAD_isPressed(BTN_MENU)) { if (PAD_isPressed(BTN_MENU)) {
item->value += RETRO_BUTTON_COUNT; item->value += LOCAL_BUTTON_COUNT;
button->mod = 1; button->mod = 1;
} }
else { else {
@ -2710,7 +2715,7 @@ static int OptionShortcuts_openMenu(MenuList* list, int i) {
item->name = button->name; item->name = button->name;
item->desc = NULL; item->desc = NULL;
item->value = button->local + 1; item->value = button->local + 1;
if (button->mod) item->value += RETRO_BUTTON_COUNT; if (button->mod) item->value += LOCAL_BUTTON_COUNT;
item->values = shortcut_labels; item->values = shortcut_labels;
} }
} }
@ -2720,7 +2725,7 @@ static int OptionShortcuts_openMenu(MenuList* list, int i) {
ButtonMapping* button = &config.shortcuts[j]; ButtonMapping* button = &config.shortcuts[j];
MenuItem* item = &OptionShortcuts_menu.items[j]; MenuItem* item = &OptionShortcuts_menu.items[j];
item->value = button->local + 1; item->value = button->local + 1;
if (button->mod) item->value += RETRO_BUTTON_COUNT; if (button->mod) item->value += LOCAL_BUTTON_COUNT;
} }
} }
Menu_options(&OptionShortcuts_menu); Menu_options(&OptionShortcuts_menu);

View file

@ -4,20 +4,25 @@ static CoreOverrides mednafen_vb_overrides = {
.core_name = "mednafen_vb", .core_name = "mednafen_vb",
.option_overrides = (OptionOverride[]){ .option_overrides = (OptionOverride[]){
{"vb_3dmode", "anaglyph", 1}, // others crash frontend {"vb_3dmode", "anaglyph", 1}, // others crash frontend
{"vb_right_analog_to_digital", "disabled", 1}, // no analog
{NULL,NULL}, {NULL,NULL},
}, },
.button_mapping = (ButtonMapping[]){ .button_mapping = (ButtonMapping[]){
{"Up", RETRO_DEVICE_ID_JOYPAD_UP, BTN_ID_UP}, {"L. Up", RETRO_DEVICE_ID_JOYPAD_UP, BTN_ID_UP},
{"Down", RETRO_DEVICE_ID_JOYPAD_DOWN, BTN_ID_DOWN}, {"L. Down", RETRO_DEVICE_ID_JOYPAD_DOWN, BTN_ID_DOWN},
{"Left", RETRO_DEVICE_ID_JOYPAD_LEFT, BTN_ID_LEFT}, {"L. Left", RETRO_DEVICE_ID_JOYPAD_LEFT, BTN_ID_LEFT},
{"Right", RETRO_DEVICE_ID_JOYPAD_RIGHT, BTN_ID_RIGHT}, {"L. Right", RETRO_DEVICE_ID_JOYPAD_RIGHT, BTN_ID_RIGHT},
{"Select", RETRO_DEVICE_ID_JOYPAD_SELECT, BTN_ID_SELECT}, {"Select", RETRO_DEVICE_ID_JOYPAD_SELECT, BTN_ID_SELECT}, // ALT: L2
{"Start", RETRO_DEVICE_ID_JOYPAD_START, BTN_ID_START}, {"Start", RETRO_DEVICE_ID_JOYPAD_START, BTN_ID_START}, // ALT: R2
{"A", RETRO_DEVICE_ID_JOYPAD_A, BTN_ID_A}, {"A", RETRO_DEVICE_ID_JOYPAD_A, BTN_ID_A}, // ALT: START
{"B", RETRO_DEVICE_ID_JOYPAD_B, BTN_ID_B}, {"B", RETRO_DEVICE_ID_JOYPAD_B, BTN_ID_B}, // ALT: SELECT
{"Low Battery", RETRO_DEVICE_ID_JOYPAD_X, BTN_ID_NONE},
{"L Button", RETRO_DEVICE_ID_JOYPAD_L, BTN_ID_L1}, {"L Button", RETRO_DEVICE_ID_JOYPAD_L, BTN_ID_L1},
{"R Button", RETRO_DEVICE_ID_JOYPAD_R, BTN_ID_R1}, {"R Button", RETRO_DEVICE_ID_JOYPAD_R, BTN_ID_R1},
{"Low Battery", RETRO_DEVICE_ID_JOYPAD_X, BTN_ID_NONE},
{"R. Up", RETRO_DEVICE_ID_JOYPAD_L2, BTN_ID_NONE}, // ALT: X
{"R. Down", RETRO_DEVICE_ID_JOYPAD_L3, BTN_ID_NONE}, // ALT: B
{"R. Left", RETRO_DEVICE_ID_JOYPAD_R2, BTN_ID_NONE}, // ALT: Y
{"R. Right", RETRO_DEVICE_ID_JOYPAD_R3, BTN_ID_NONE}, // ALT: A
{NULL}, {NULL},
}, },
}; };