diff --git a/src/osdep/amiberry_input.cpp b/src/osdep/amiberry_input.cpp index 7c800905..a4c7c3bf 100644 --- a/src/osdep/amiberry_input.cpp +++ b/src/osdep/amiberry_input.cpp @@ -12,7 +12,6 @@ #include /// Horace added /* atol */ - static struct host_input_button default_controller_map; struct host_input_button host_input_buttons[MAX_INPUT_DEVICES]; @@ -41,122 +40,122 @@ static int numKeysAsJoys; static void fill_default_controller(void) { - default_controller_map.hotkey_button = -1; - default_controller_map.quit_button = -1; - default_controller_map.reset_button = -1; - default_controller_map.menu_button = -1; - - default_controller_map.number_of_hats = 1; + default_controller_map.hotkey_button = -1; + default_controller_map.quit_button = -1; + default_controller_map.reset_button = -1; + default_controller_map.menu_button = -1; + + default_controller_map.number_of_hats = 1; default_controller_map.north_button = 3; // yellow - default_controller_map.east_button = 1; // blue + default_controller_map.east_button = 1; // blue default_controller_map.south_button = 0; // red - default_controller_map.west_button = 2; // green + default_controller_map.west_button = 2; // green - default_controller_map.dpad_left = -1; + default_controller_map.dpad_left = -1; default_controller_map.dpad_right = -1; - default_controller_map.dpad_up = -1; - default_controller_map.dpad_down = -1; + default_controller_map.dpad_up = -1; + default_controller_map.dpad_down = -1; - default_controller_map.select_button = -1; // - default_controller_map.start_button = 4; // play - default_controller_map.left_shoulder = 6; // rwd + default_controller_map.select_button = -1; // + default_controller_map.start_button = 4; // play + default_controller_map.left_shoulder = 6; // rwd default_controller_map.right_shoulder = 5; // fwd - - default_controller_map.left_shoulder = -1; // rwd + + default_controller_map.left_shoulder = -1; // rwd default_controller_map.right_shoulder = -1; // fwd - default_controller_map.left_trigger = -1; // alt. fire - default_controller_map.right_trigger = -1; // esc? + default_controller_map.left_trigger = -1; // alt. fire + default_controller_map.right_trigger = -1; // esc? default_controller_map.lstick_button = -1; - default_controller_map.lstick_left = -1; - default_controller_map.lstick_right = -1; - default_controller_map.lstick_up = -1; - default_controller_map.lstick_down = -1; + default_controller_map.lstick_left = -1; + default_controller_map.lstick_right = -1; + default_controller_map.lstick_up = -1; + default_controller_map.lstick_down = -1; default_controller_map.lstick_axis_y = 1; default_controller_map.lstick_axis_x = 0; default_controller_map.rstick_button = -1; - default_controller_map.rstick_left = -1; - default_controller_map.rstick_right = -1; - default_controller_map.rstick_up = -1; - default_controller_map.rstick_down = -1; + default_controller_map.rstick_left = -1; + default_controller_map.rstick_right = -1; + default_controller_map.rstick_up = -1; + default_controller_map.rstick_down = -1; default_controller_map.rstick_axis_y = 3; default_controller_map.rstick_axis_x = 2; - default_controller_map.is_retroarch = false; + + default_controller_map.is_retroarch = false; } static void fill_blank_controller(void) { - default_controller_map.hotkey_button = -1; - default_controller_map.quit_button = -1; - default_controller_map.reset_button = -1; - default_controller_map.menu_button = -1; - - default_controller_map.number_of_hats = -1; + default_controller_map.hotkey_button = -1; + default_controller_map.quit_button = -1; + default_controller_map.reset_button = -1; + default_controller_map.menu_button = -1; + + default_controller_map.number_of_hats = -1; default_controller_map.north_button = -1; // yellow - default_controller_map.east_button = -1; // blue + default_controller_map.east_button = -1; // blue default_controller_map.south_button = -1; // red - default_controller_map.west_button = -1; // green + default_controller_map.west_button = -1; // green - default_controller_map.dpad_left = -1; + default_controller_map.dpad_left = -1; default_controller_map.dpad_right = -1; - default_controller_map.dpad_up = -1; - default_controller_map.dpad_down = -1; + default_controller_map.dpad_up = -1; + default_controller_map.dpad_down = -1; - default_controller_map.select_button = -1; // - default_controller_map.start_button = -1; // play - default_controller_map.left_shoulder = -1; // rwd + default_controller_map.select_button = -1; // + default_controller_map.start_button = -1; // play + default_controller_map.left_shoulder = -1; // rwd default_controller_map.right_shoulder = -1; // fwd - default_controller_map.left_shoulder = -1; // rwd + default_controller_map.left_shoulder = -1; // rwd default_controller_map.right_shoulder = -1; // fwd - default_controller_map.left_trigger = -1; // alt. fire - default_controller_map.right_trigger = -1; // esc? + default_controller_map.left_trigger = -1; // alt. fire + default_controller_map.right_trigger = -1; // esc? default_controller_map.lstick_button = -1; - default_controller_map.lstick_left = -1; - default_controller_map.lstick_right = -1; - default_controller_map.lstick_up = -1; - default_controller_map.lstick_down = -1; + default_controller_map.lstick_left = -1; + default_controller_map.lstick_right = -1; + default_controller_map.lstick_up = -1; + default_controller_map.lstick_down = -1; default_controller_map.lstick_axis_y = -1; default_controller_map.lstick_axis_x = -1; default_controller_map.rstick_button = -1; - default_controller_map.rstick_left = -1; - default_controller_map.rstick_right = -1; - default_controller_map.rstick_up = -1; - default_controller_map.rstick_down = -1; + default_controller_map.rstick_left = -1; + default_controller_map.rstick_right = -1; + default_controller_map.rstick_up = -1; + default_controller_map.rstick_down = -1; default_controller_map.rstick_axis_y = -1; default_controller_map.rstick_axis_x = -1; - - default_controller_map.is_retroarch = false; + default_controller_map.is_retroarch = false; } - + static void fill_default_keyboard(void) { - // test using iPac layout - default_keyboard_map.north_button = SDLK_LSHIFT; - default_keyboard_map.east_button = SDLK_LCTRL; - default_keyboard_map.south_button = SDLK_LALT;; - default_keyboard_map.west_button = SDLK_SPACE; - default_keyboard_map.dpad_left = SDLK_LEFT; - default_keyboard_map.dpad_right = SDLK_RIGHT; - default_keyboard_map.dpad_up = SDLK_UP; - default_keyboard_map.dpad_down = SDLK_DOWN; - default_keyboard_map.left_shoulder = SDLK_z; + // test using iPac layout + default_keyboard_map.north_button = SDLK_LSHIFT; + default_keyboard_map.east_button = SDLK_LCTRL; + default_keyboard_map.south_button = SDLK_LALT; + default_keyboard_map.west_button = SDLK_SPACE; + default_keyboard_map.dpad_left = SDLK_LEFT; + default_keyboard_map.dpad_right = SDLK_RIGHT; + default_keyboard_map.dpad_up = SDLK_UP; + default_keyboard_map.dpad_down = SDLK_DOWN; + default_keyboard_map.left_shoulder = SDLK_z; default_keyboard_map.right_shoulder = SDLK_x; - default_keyboard_map.select_button = SDLK_1; - default_keyboard_map.start_button = SDLK_2; - default_keyboard_map.lstick_button = SDLK_F1; - default_keyboard_map.rstick_button = SDLK_F2; - - default_keyboard_map.is_retroarch = false; - + default_keyboard_map.select_button = SDLK_1; + default_keyboard_map.start_button = SDLK_2; + default_keyboard_map.lstick_button = SDLK_F1; + default_keyboard_map.rstick_button = SDLK_F2; + + default_keyboard_map.is_retroarch = false; } + //# Keyboard input. Will recognize letters (a to z) and the following special keys (where kp_ //# is for keypad keys): //# @@ -170,65 +169,65 @@ static void fill_default_keyboard(void) //# backslash, rightbracket, kp_period, kp_equals, rctrl, ralt const int RemapKeyMapList[] = { - -1, - SDLK_a, SDLK_b, SDLK_c, SDLK_d, SDLK_e, - SDLK_f, SDLK_g, SDLK_h, SDLK_i, SDLK_j, - SDLK_k, SDLK_l, SDLK_m, SDLK_n, SDLK_o, - SDLK_p, SDLK_q, SDLK_r, SDLK_s, SDLK_t, - SDLK_u, SDLK_v, SDLK_w, SDLK_x, SDLK_y, SDLK_z, - SDLK_LEFT, SDLK_RIGHT, SDLK_UP, SDLK_DOWN, SDLK_RETURN, - SDLK_KP_ENTER, SDLK_TAB, SDLK_INSERT, SDLK_DELETE, SDLK_END, SDLK_HOME, - SDLK_RSHIFT, SDLK_LSHIFT, SDLK_LCTRL, SDLK_LALT, SDLK_SPACE, - SDLK_ESCAPE, SDLK_PLUS, SDLK_MINUS, SDLK_KP_PLUS, SDLK_KP_MINUS, - SDLK_F1, SDLK_F2, SDLK_F3, SDLK_F4, SDLK_F5, SDLK_F6, - SDLK_F7, SDLK_F8, SDLK_F9, SDLK_F10, SDLK_F11, SDLK_F12, - SDLK_0, SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, - SDLK_6, SDLK_7, SDLK_8, SDLK_9, SDLK_PAGEUP, SDLK_PAGEDOWN, - SDLK_KP_0, SDLK_KP_1, SDLK_KP_2, SDLK_KP_3, SDLK_KP_4, - SDLK_KP_5, SDLK_KP_6, SDLK_KP_7, SDLK_KP_8, SDLK_KP_9, - SDLK_PERIOD, SDLK_CAPSLOCK, SDLK_NUMLOCKCLEAR, SDLK_BACKSPACE, - // divide - SDLK_ASTERISK, -1, SDLK_PRINTSCREEN, SDLK_SCROLLLOCK, - // tilde - -1, SDLK_BACKQUOTE,SDLK_PAUSE, SDLK_QUOTE, SDLK_COMMA, - SDLK_MINUS, SDLK_SLASH, SDLK_SEMICOLON,SDLK_EQUALS, SDLK_LEFTPAREN, - SDLK_BACKSLASH, SDLK_RIGHTPAREN, - SDLK_KP_PERIOD, SDLK_KP_EQUALS,SDLK_RCTRL, SDLK_RALT + -1, + SDLK_a, SDLK_b, SDLK_c, SDLK_d, SDLK_e, + SDLK_f, SDLK_g, SDLK_h, SDLK_i, SDLK_j, + SDLK_k, SDLK_l, SDLK_m, SDLK_n, SDLK_o, + SDLK_p, SDLK_q, SDLK_r, SDLK_s, SDLK_t, + SDLK_u, SDLK_v, SDLK_w, SDLK_x, SDLK_y, SDLK_z, + SDLK_LEFT, SDLK_RIGHT, SDLK_UP, SDLK_DOWN, SDLK_RETURN, + SDLK_KP_ENTER, SDLK_TAB, SDLK_INSERT, SDLK_DELETE, SDLK_END, SDLK_HOME, + SDLK_RSHIFT, SDLK_LSHIFT, SDLK_LCTRL, SDLK_LALT, SDLK_SPACE, + SDLK_ESCAPE, SDLK_PLUS, SDLK_MINUS, SDLK_KP_PLUS, SDLK_KP_MINUS, + SDLK_F1, SDLK_F2, SDLK_F3, SDLK_F4, SDLK_F5, SDLK_F6, + SDLK_F7, SDLK_F8, SDLK_F9, SDLK_F10, SDLK_F11, SDLK_F12, + SDLK_0, SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, + SDLK_6, SDLK_7, SDLK_8, SDLK_9, SDLK_PAGEUP, SDLK_PAGEDOWN, + SDLK_KP_0, SDLK_KP_1, SDLK_KP_2, SDLK_KP_3, SDLK_KP_4, + SDLK_KP_5, SDLK_KP_6, SDLK_KP_7, SDLK_KP_8, SDLK_KP_9, + SDLK_PERIOD, SDLK_CAPSLOCK, SDLK_NUMLOCKCLEAR, SDLK_BACKSPACE, + // divide + SDLK_ASTERISK, -1, SDLK_PRINTSCREEN, SDLK_SCROLLLOCK, + // tilde + -1, SDLK_BACKQUOTE,SDLK_PAUSE, SDLK_QUOTE, SDLK_COMMA, + SDLK_MINUS, SDLK_SLASH, SDLK_SEMICOLON,SDLK_EQUALS, SDLK_LEFTPAREN, + SDLK_BACKSLASH, SDLK_RIGHTPAREN, + SDLK_KP_PERIOD, SDLK_KP_EQUALS,SDLK_RCTRL, SDLK_RALT }; const char* RemapKeyMapListStrings[] = { - "nul", - "a", "b", "c", "d", "e", - "f", "g", "h", "i", "j", - "k", "l", "m", "n", "o", - "p", "q", "r", "s", "t", - "u", "v", "w", "x", "y", "z", - "left", "right", "up", "down", "enter", - "kp_enter", "tab", "insert", "del", "end", "home", - "rshift", "shift", "ctrl", "alt", "space", - "escape", "add", "subtract", "kp_plus", "kp_minus", - "f1", "f2", "f3", "f4", "f5", "f6", - "f7", "f8", "f9", "f10", "f11", "f12", - "num0", "num1", "num2", "num3", "num4", "num5", - "num6", "num7", "num8", "num9", "pageup", "pagedown", - "keypad0", "keypad1", "keypad2", "keypad3", "keypad4", - "keypad5", "keypad6", "keypad7", "keypad8", "keypad9", - "period", "capslock", "numlock", "backspace", - "multiply", "divide", "print_screen", "scroll_lock", - "tilde", "backquote","pause", "quote", "comma", - "minus", "slash", "semicolon","equals", "leftbracket", - "backslash", "rightbracket", - "kp_period", "kp_equals","rctrl", "ralt" - + "nul", + "a", "b", "c", "d", "e", + "f", "g", "h", "i", "j", + "k", "l", "m", "n", "o", + "p", "q", "r", "s", "t", + "u", "v", "w", "x", "y", "z", + "left", "right", "up", "down", "enter", + "kp_enter", "tab", "insert", "del", "end", "home", + "rshift", "shift", "ctrl", "alt", "space", + "escape", "add", "subtract", "kp_plus", "kp_minus", + "f1", "f2", "f3", "f4", "f5", "f6", + "f7", "f8", "f9", "f10", "f11", "f12", + "num0", "num1", "num2", "num3", "num4", "num5", + "num6", "num7", "num8", "num9", "pageup", "pagedown", + "keypad0", "keypad1", "keypad2", "keypad3", "keypad4", + "keypad5", "keypad6", "keypad7", "keypad8", "keypad9", + "period", "capslock", "numlock", "backspace", + "multiply", "divide", "print_screen", "scroll_lock", + "tilde", "backquote","pause", "quote", "comma", + "minus", "slash", "semicolon","equals", "leftbracket", + "backslash", "rightbracket", + "kp_period", "kp_equals","rctrl", "ralt" + }; -const int RemapKeyMapListSize = sizeof( RemapKeyMapList ) / sizeof( RemapKeyMapList[0] ); +const int RemapKeyMapListSize = sizeof(RemapKeyMapList) / sizeof(RemapKeyMapList[0]); static int init_mouse(void) { - int mouse = open("/dev/input/mouse0", O_RDONLY); + const int mouse = open("/dev/input/mouse0", O_RDONLY); if (mouse != -1) { numMice++; @@ -456,7 +455,6 @@ int input_get_default_keyboard(int num) return 1; } return 0; - } #define MAX_JOY_BUTTONS 16 @@ -472,215 +470,226 @@ static char IsPS3Controller[MAX_INPUT_DEVICES]; static SDL_Joystick* Joysticktable[MAX_INPUT_DEVICES]; -int find_retroarch(const TCHAR *find_setting, char *retroarch_file, host_input_button current_hostinput) -{ - // opening file and parsing - ifstream readFile(retroarch_file); - string line; - string delimiter = " = "; +int find_retroarch(const TCHAR* find_setting, char* retroarch_file, host_input_button current_hostinput) +{ + // opening file and parsing + ifstream readFile(retroarch_file); + string line; + string delimiter = " = "; - int tempbutton = -1; - -// read each line in - while (std::getline(readFile, line)) - { - const string option = line.substr(0, line.find(delimiter)); - - if (option != line) // exit if we got no result from splitting the string - { - // using the " = " to work out whis is the option, and which is the parameter. - string param = line.substr(line.find(delimiter) + delimiter.length(), line.length()); + int tempbutton = -1; - // remove leading " - if (param.at(0) == '"') - { param.erase(0, 1); } + // read each line in + while (std::getline(readFile, line)) + { + const string option = line.substr(0, line.find(delimiter)); - // remove trailing " - if (param.at(param.length() - 1) == '"') - { param.erase(param.length() - 1, 1); } - - // time to get the output number - if (param.at(0) != 'h') // check it isnt some kind of hat starting 'h' (so if D-pad uses buttons) - { tempbutton = abs(atol(param.c_str())); } // gets the parameter - - // this will need something separate to pull out the number of hats - // use SET_BIT on hX numbers - - if (find_setting == "count_hats" && param.at(0) == 'h') - { if (param.at(1) == '0') { SET_BIT (tempbutton,0);} - if (param.at(1) == '1') { SET_BIT (tempbutton,1);} - if (param.at(1) == '2') { SET_BIT (tempbutton,2);} - if (param.at(1) == '3') { SET_BIT (tempbutton,3);} - } - - // ok, this is the 'normal' storing of values - if (option == find_setting) - { break; } - else if (find_setting != "count_hats") - {tempbutton = -1;} - - } - } - readFile.close(); + if (option != line) // exit if we got no result from splitting the string + { + // using the " = " to work out whis is the option, and which is the parameter. + string param = line.substr(line.find(delimiter) + delimiter.length(), line.length()); - return tempbutton; + // remove leading " + if (param.at(0) == '"') + { + param.erase(0, 1); + } + + // remove trailing " + if (param.at(param.length() - 1) == '"') + { + param.erase(param.length() - 1, 1); + } + + // time to get the output number + if (param.at(0) != 'h') // check it isnt some kind of hat starting 'h' (so if D-pad uses buttons) + { + tempbutton = abs(atol(param.c_str())); + } // gets the parameter + + // this will need something separate to pull out the number of hats + // use SET_BIT on hX numbers + + if (find_setting == "count_hats" && param.at(0) == 'h') + { + if (param.at(1) == '0') { SET_BIT (tempbutton,0); } + if (param.at(1) == '1') { SET_BIT (tempbutton,1); } + if (param.at(1) == '2') { SET_BIT (tempbutton,2); } + if (param.at(1) == '3') { SET_BIT (tempbutton,3); } + } + + // ok, this is the 'normal' storing of values + if (option == find_setting) + { + break; + } + if (find_setting != "count_hats") + { + tempbutton = -1; + } + } + } + readFile.close(); + + return tempbutton; } +const TCHAR* find_retroarch_key(const TCHAR* find_setting, char* retroarch_file) +{ + // opening file and parsing + ifstream readFile(retroarch_file); + string line; + string delimiter = " = "; + const TCHAR* output = "nul"; + // read each line in + while (std::getline(readFile, line)) + { + const string option = line.substr(0, line.find(delimiter)); -const TCHAR* find_retroarch_key(const TCHAR *find_setting, char *retroarch_file) -{ - // opening file and parsing - ifstream readFile(retroarch_file); - string line; - string delimiter = " = "; + if (option != line) // exit if we got no result from splitting the string + { + // using the " = " to work out whis is the option, and which is the parameter. + string param = line.substr(line.find(delimiter) + delimiter.length(), line.length()); - const TCHAR* output = "nul"; - -// read each line in - while (std::getline(readFile, line)) - { - const string option = line.substr(0, line.find(delimiter)); - - if (option != line) // exit if we got no result from splitting the string - { - // using the " = " to work out whis is the option, and which is the parameter. - string param = line.substr(line.find(delimiter) + delimiter.length(), line.length()); + // remove leading " + if (param.at(0) == '"') + { + param.erase(0, 1); + } - // remove leading " - if (param.at(0) == '"') - { param.erase(0, 1); } + // remove trailing " + if (param.at(param.length() - 1) == '"') + { + param.erase(param.length() - 1, 1); + } - // remove trailing " - if (param.at(param.length() - 1) == '"') - { param.erase(param.length() - 1, 1); } - - output = ¶m[0u]; - - // ok, this is the 'normal' storing of values - if (option == find_setting) - { break; } - else - { output = "nul";} - - } - } - readFile.close(); + output = ¶m[0u]; - return output; + // ok, this is the 'normal' storing of values + if (option == find_setting) + { + break; + } + output = "nul"; + } + } + readFile.close(); + + return output; } int find_string_in_array(const char* arr[], int n, const char* key) { - int index = -1; + int index = -1; - for(int i=0; i MAX_INPUT_DEVICES) nr_joysticks = MAX_INPUT_DEVICES; - - // set up variables / paths etc. - char tmp[MAX_PATH]; - extern void fetch_controllerspath (char *out, int size); - fetch_controllerspath(tmp, MAX_PATH); - - // do the loop + + // set up variables / paths etc. + char tmp[MAX_PATH]; + extern void fetch_controllerspath(char* out, int size); + fetch_controllerspath(tmp, MAX_PATH); + + // do the loop for (int cpt = 0; cpt < nr_joysticks; cpt++) { Joysticktable[cpt] = SDL_JoystickOpen(cpt); @@ -691,7 +700,7 @@ static int init_joystick(void) strncpy(JoystickName[cpt], SDL_JoystickNameForIndex(cpt), sizeof JoystickName[cpt] - 1); else sprintf(JoystickName[cpt], "Joystick%d", cpt); - + //this now uses controllers path (in tmp) char ControlConfig[255]; strcpy(ControlConfig, tmp); @@ -699,56 +708,66 @@ static int init_joystick(void) strcat(ControlConfig, ".cfg"); if (zfile_exists(ControlConfig)) - { - fill_blank_controller(); - host_input_buttons[cpt] = default_controller_map; + { + fill_blank_controller(); + host_input_buttons[cpt] = default_controller_map; - host_input_buttons[cpt].is_retroarch = true; + host_input_buttons[cpt].is_retroarch = true; - host_input_buttons[cpt].hotkey_button = find_retroarch("input_enable_hotkey_btn" ,ControlConfig, host_input_buttons[cpt]); + host_input_buttons[cpt].hotkey_button = find_retroarch("input_enable_hotkey_btn", ControlConfig, + host_input_buttons[cpt]); - host_input_buttons[cpt].quit_button = find_retroarch("input_exit_emulator_btn" ,ControlConfig, host_input_buttons[cpt]); - host_input_buttons[cpt].menu_button = find_retroarch("input_menu_toggle_btn" ,ControlConfig, host_input_buttons[cpt]); - host_input_buttons[cpt].reset_button = find_retroarch("input_reset_btn" ,ControlConfig, host_input_buttons[cpt]); + host_input_buttons[cpt].quit_button = find_retroarch("input_exit_emulator_btn", ControlConfig, + host_input_buttons[cpt]); + host_input_buttons[cpt].menu_button = find_retroarch("input_menu_toggle_btn", ControlConfig, + host_input_buttons[cpt]); + host_input_buttons[cpt].reset_button = find_retroarch("input_reset_btn", ControlConfig, host_input_buttons[cpt]); - host_input_buttons[cpt].east_button = find_retroarch("input_a_btn" ,ControlConfig, host_input_buttons[cpt]); - host_input_buttons[cpt].south_button = find_retroarch("input_b_btn" ,ControlConfig, host_input_buttons[cpt]); - host_input_buttons[cpt].north_button = find_retroarch("input_x_btn" ,ControlConfig, host_input_buttons[cpt]); - host_input_buttons[cpt].west_button = find_retroarch("input_y_btn" ,ControlConfig, host_input_buttons[cpt]); - - host_input_buttons[cpt].dpad_left = find_retroarch("input_left_btn" ,ControlConfig, host_input_buttons[cpt]); - host_input_buttons[cpt].dpad_right = find_retroarch("input_right_btn" ,ControlConfig, host_input_buttons[cpt]); - host_input_buttons[cpt].dpad_up = find_retroarch("input_up_btn" ,ControlConfig, host_input_buttons[cpt]); - host_input_buttons[cpt].dpad_down = find_retroarch("input_down_btn" ,ControlConfig, host_input_buttons[cpt]); + host_input_buttons[cpt].east_button = find_retroarch("input_a_btn", ControlConfig, host_input_buttons[cpt]); + host_input_buttons[cpt].south_button = find_retroarch("input_b_btn", ControlConfig, host_input_buttons[cpt]); + host_input_buttons[cpt].north_button = find_retroarch("input_x_btn", ControlConfig, host_input_buttons[cpt]); + host_input_buttons[cpt].west_button = find_retroarch("input_y_btn", ControlConfig, host_input_buttons[cpt]); - host_input_buttons[cpt].select_button = find_retroarch("input_select_btn" ,ControlConfig, host_input_buttons[cpt]); - host_input_buttons[cpt].start_button = find_retroarch("input_start_btn" ,ControlConfig, host_input_buttons[cpt]); + host_input_buttons[cpt].dpad_left = find_retroarch("input_left_btn", ControlConfig, host_input_buttons[cpt]); + host_input_buttons[cpt].dpad_right = find_retroarch("input_right_btn", ControlConfig, host_input_buttons[cpt]); + host_input_buttons[cpt].dpad_up = find_retroarch("input_up_btn", ControlConfig, host_input_buttons[cpt]); + host_input_buttons[cpt].dpad_down = find_retroarch("input_down_btn", ControlConfig, host_input_buttons[cpt]); - host_input_buttons[cpt].left_shoulder = find_retroarch("input_l_btn" ,ControlConfig, host_input_buttons[cpt]); - host_input_buttons[cpt].right_shoulder = find_retroarch("input_r_btn" ,ControlConfig, host_input_buttons[cpt]); - host_input_buttons[cpt].left_trigger = find_retroarch("input_l2_btn" ,ControlConfig, host_input_buttons[cpt]); - host_input_buttons[cpt].right_trigger = find_retroarch("input_r2_btn" ,ControlConfig, host_input_buttons[cpt]); - host_input_buttons[cpt].lstick_button = find_retroarch("input_l3_btn" ,ControlConfig, host_input_buttons[cpt]); - host_input_buttons[cpt].rstick_button = find_retroarch("input_r3_btn" ,ControlConfig, host_input_buttons[cpt]); - - host_input_buttons[cpt].lstick_axis_x = find_retroarch("input_l_x_plus_axis" ,ControlConfig, host_input_buttons[cpt]); - if (host_input_buttons[cpt].lstick_axis_x == -1) - { host_input_buttons[cpt].lstick_axis_x = find_retroarch("input_right_axis" ,ControlConfig, host_input_buttons[cpt]); } - - host_input_buttons[cpt].lstick_axis_y = find_retroarch("input_l_y_plus_axis" ,ControlConfig, host_input_buttons[cpt]); - if (host_input_buttons[cpt].lstick_axis_y == -1) - { host_input_buttons[cpt].lstick_axis_y = find_retroarch("input_down_axis" ,ControlConfig, host_input_buttons[cpt]); } + host_input_buttons[cpt].select_button = find_retroarch("input_select_btn", ControlConfig, host_input_buttons[cpt]); + host_input_buttons[cpt].start_button = find_retroarch("input_start_btn", ControlConfig, host_input_buttons[cpt]); - host_input_buttons[cpt].rstick_axis_x = find_retroarch("input_r_x_plus_axis" ,ControlConfig, host_input_buttons[cpt]); - host_input_buttons[cpt].rstick_axis_y = find_retroarch("input_r_y_plus_axis" ,ControlConfig, host_input_buttons[cpt]); - - host_input_buttons[cpt].number_of_hats = find_retroarch("count_hats" ,ControlConfig, host_input_buttons[cpt]); - - //input_state_slot_increase_axis - //input_state_slot_decrease_axis - + host_input_buttons[cpt].left_shoulder = find_retroarch("input_l_btn", ControlConfig, host_input_buttons[cpt]); + host_input_buttons[cpt].right_shoulder = find_retroarch("input_r_btn", ControlConfig, host_input_buttons[cpt]); + host_input_buttons[cpt].left_trigger = find_retroarch("input_l2_btn", ControlConfig, host_input_buttons[cpt]); + host_input_buttons[cpt].right_trigger = find_retroarch("input_r2_btn", ControlConfig, host_input_buttons[cpt]); + host_input_buttons[cpt].lstick_button = find_retroarch("input_l3_btn", ControlConfig, host_input_buttons[cpt]); + host_input_buttons[cpt].rstick_button = find_retroarch("input_r3_btn", ControlConfig, host_input_buttons[cpt]); + + host_input_buttons[cpt].lstick_axis_x = find_retroarch("input_l_x_plus_axis", ControlConfig, + host_input_buttons[cpt]); + if (host_input_buttons[cpt].lstick_axis_x == -1) + { + host_input_buttons[cpt].lstick_axis_x = find_retroarch("input_right_axis", ControlConfig, host_input_buttons[cpt]); + } + + host_input_buttons[cpt].lstick_axis_y = find_retroarch("input_l_y_plus_axis", ControlConfig, + host_input_buttons[cpt]); + if (host_input_buttons[cpt].lstick_axis_y == -1) + { + host_input_buttons[cpt].lstick_axis_y = find_retroarch("input_down_axis", ControlConfig, host_input_buttons[cpt]); + } + + host_input_buttons[cpt].rstick_axis_x = find_retroarch("input_r_x_plus_axis", ControlConfig, + host_input_buttons[cpt]); + host_input_buttons[cpt].rstick_axis_y = find_retroarch("input_r_y_plus_axis", ControlConfig, + host_input_buttons[cpt]); + + host_input_buttons[cpt].number_of_hats = find_retroarch("count_hats", ControlConfig, host_input_buttons[cpt]); + + //input_state_slot_increase_axis + //input_state_slot_decrease_axis } // end of .cfg file found - + else // do manual checks if there is no .cfg { //printf(" No .cfg config file found.\n"); @@ -756,19 +775,16 @@ static int init_joystick(void) fill_default_controller(); host_input_buttons[cpt] = default_controller_map; } - } } - - - + return 1; } void import_joysticks(void) { - init_joystick(); + init_joystick(); } static void close_joystick(void) @@ -793,18 +809,19 @@ static void unacquire_joystick(int num) static const TCHAR* get_joystick_friendlyname(int joy) { - TCHAR* tmp1 = new char[255]; - for (int n = 0 ; n < numKeysAsJoys; ++n) - { - if (joy == n) - { - if (host_keyboard_buttons[n].is_retroarch == true) - { sprintf (tmp1, "RetroArch Keyboard as Joystick [Input #%d]",n + 1); - return tmp1;} - else - { return "Keyboard as Joystick [Default]";} - } - } + TCHAR* tmp1 = new char[255]; + for (int n = 0; n < numKeysAsJoys; ++n) + { + if (joy == n) + { + if (host_keyboard_buttons[n].is_retroarch == true) + { + sprintf(tmp1, "RetroArch Keyboard as Joystick [Input #%d]", n + 1); + return tmp1; + } + return "Keyboard as Joystick [Default]"; + } + } return JoystickName[joy - numKeysAsJoys]; } @@ -917,66 +934,107 @@ static void read_joystick(void) for (int joyid = 0; joyid < MAX_JPORTS; joyid++) { // First handle retroarch (or default) keys as Joystick... - if (currprefs.jports[joyid].id >= JSEM_JOYS && currprefs.jports[joyid].id < JSEM_JOYS + numKeysAsJoys) - { - - int hostkeyid = currprefs.jports[joyid].id - JSEM_JOYS; - - const Uint8* keystate = SDL_GetKeyboardState(nullptr); - - // cd32 red, blue, green, yellow - setjoybuttonstate(0, 0, keystate[host_keyboard_buttons[hostkeyid].south_button]); // b - setjoybuttonstate(0, 1, keystate[host_keyboard_buttons[hostkeyid].east_button]); // a - setjoybuttonstate(0, 2, keystate[host_keyboard_buttons[hostkeyid].north_button]); //y - setjoybuttonstate(0, 3, keystate[host_keyboard_buttons[hostkeyid].west_button]); // x - - setjoybuttonstate(0, 4, keystate[host_keyboard_buttons[hostkeyid].left_shoulder]); // z - setjoybuttonstate(0, 5, keystate[host_keyboard_buttons[hostkeyid].right_shoulder]); // x - setjoybuttonstate(0, 6, keystate[host_keyboard_buttons[hostkeyid].start_button]); //num1 - // up down left right - setjoybuttonstate(0, 7, keystate[host_keyboard_buttons[hostkeyid].dpad_up]); - setjoybuttonstate(0, 8, keystate[host_keyboard_buttons[hostkeyid].dpad_down]); - setjoybuttonstate(0, 9, keystate[host_keyboard_buttons[hostkeyid].dpad_left]); - setjoybuttonstate(0, 10, keystate[host_keyboard_buttons[hostkeyid].dpad_right]); - - //stick left/right - setjoybuttonstate(0, 11, keystate[host_keyboard_buttons[hostkeyid].lstick_button]); - setjoybuttonstate(0, 12, keystate[host_keyboard_buttons[hostkeyid].rstick_button]); - setjoybuttonstate(0, 13, keystate[host_keyboard_buttons[hostkeyid].select_button]); // num2 - + { + const int hostkeyid = currprefs.jports[joyid].id - JSEM_JOYS; + + const Uint8* keystate = SDL_GetKeyboardState(nullptr); + + // cd32 red, blue, green, yellow + setjoybuttonstate(0, 0, keystate[host_keyboard_buttons[hostkeyid].south_button]); // b + setjoybuttonstate(0, 1, keystate[host_keyboard_buttons[hostkeyid].east_button]); // a + setjoybuttonstate(0, 2, keystate[host_keyboard_buttons[hostkeyid].north_button]); //y + setjoybuttonstate(0, 3, keystate[host_keyboard_buttons[hostkeyid].west_button]); // x + + setjoybuttonstate(0, 4, keystate[host_keyboard_buttons[hostkeyid].left_shoulder]); // z + setjoybuttonstate(0, 5, keystate[host_keyboard_buttons[hostkeyid].right_shoulder]); // x + setjoybuttonstate(0, 6, keystate[host_keyboard_buttons[hostkeyid].start_button]); //num1 + // up down left right + setjoybuttonstate(0, 7, keystate[host_keyboard_buttons[hostkeyid].dpad_up]); + setjoybuttonstate(0, 8, keystate[host_keyboard_buttons[hostkeyid].dpad_down]); + setjoybuttonstate(0, 9, keystate[host_keyboard_buttons[hostkeyid].dpad_left]); + setjoybuttonstate(0, 10, keystate[host_keyboard_buttons[hostkeyid].dpad_right]); + + //stick left/right + setjoybuttonstate(0, 11, keystate[host_keyboard_buttons[hostkeyid].lstick_button]); + setjoybuttonstate(0, 12, keystate[host_keyboard_buttons[hostkeyid].rstick_button]); + setjoybuttonstate(0, 13, keystate[host_keyboard_buttons[hostkeyid].select_button]); // num2 } - // this is what we actually use on the Pi (for joysticks :) else if (jsem_isjoy(joyid, &currprefs) != -1) { // Now we handle real SDL joystick... - int hostjoyid = currprefs.jports[joyid].id - JSEM_JOYS - numKeysAsJoys; - - static struct host_input_button current_controller_map; - - current_controller_map = host_input_buttons[hostjoyid]; - - if (current_controller_map.east_button == current_controller_map.hotkey_button ) {current_controller_map.east_button = -1;} - if (current_controller_map.south_button == current_controller_map.hotkey_button ) {current_controller_map.south_button = -1;} - if (current_controller_map.north_button == current_controller_map.hotkey_button ) {current_controller_map.north_button = -1;} - if (current_controller_map.west_button == current_controller_map.hotkey_button ) {current_controller_map.west_button = -1;} - if (current_controller_map.dpad_left == current_controller_map.hotkey_button ) {current_controller_map.dpad_left = -1;} - if (current_controller_map.dpad_right == current_controller_map.hotkey_button ) {current_controller_map.dpad_right = -1;} - if (current_controller_map.dpad_up == current_controller_map.hotkey_button ) {current_controller_map.dpad_up = -1;} - if (current_controller_map.dpad_down == current_controller_map.hotkey_button ) {current_controller_map.dpad_down = -1;} - if (current_controller_map.select_button == current_controller_map.hotkey_button ) {current_controller_map.select_button = -1;} - if (current_controller_map.start_button == current_controller_map.hotkey_button ) {current_controller_map.start_button = -1;} - if (current_controller_map.left_trigger == current_controller_map.hotkey_button ) {current_controller_map.left_trigger = -1;} - if (current_controller_map.right_trigger == current_controller_map.hotkey_button ) {current_controller_map.right_trigger = -1;} - if (current_controller_map.lstick_button == current_controller_map.hotkey_button ) {current_controller_map.lstick_button = -1;} - if (current_controller_map.rstick_button == current_controller_map.hotkey_button ) {current_controller_map.rstick_button = -1;} - - if (current_controller_map.left_shoulder == current_controller_map.hotkey_button ) {current_controller_map.left_shoulder = -1;} - if (current_controller_map.right_shoulder == current_controller_map.hotkey_button ) {current_controller_map.right_shoulder = -1;} - - + const int hostjoyid = currprefs.jports[joyid].id - JSEM_JOYS - numKeysAsJoys; + + static struct host_input_button current_controller_map; + + current_controller_map = host_input_buttons[hostjoyid]; + + if (current_controller_map.east_button == current_controller_map.hotkey_button) + { + current_controller_map.east_button = -1; + } + if (current_controller_map.south_button == current_controller_map.hotkey_button) + { + current_controller_map.south_button = -1; + } + if (current_controller_map.north_button == current_controller_map.hotkey_button) + { + current_controller_map.north_button = -1; + } + if (current_controller_map.west_button == current_controller_map.hotkey_button) + { + current_controller_map.west_button = -1; + } + if (current_controller_map.dpad_left == current_controller_map.hotkey_button) + { + current_controller_map.dpad_left = -1; + } + if (current_controller_map.dpad_right == current_controller_map.hotkey_button) + { + current_controller_map.dpad_right = -1; + } + if (current_controller_map.dpad_up == current_controller_map.hotkey_button) { current_controller_map.dpad_up = -1; } + if (current_controller_map.dpad_down == current_controller_map.hotkey_button) + { + current_controller_map.dpad_down = -1; + } + if (current_controller_map.select_button == current_controller_map.hotkey_button) + { + current_controller_map.select_button = -1; + } + if (current_controller_map.start_button == current_controller_map.hotkey_button) + { + current_controller_map.start_button = -1; + } + if (current_controller_map.left_trigger == current_controller_map.hotkey_button) + { + current_controller_map.left_trigger = -1; + } + if (current_controller_map.right_trigger == current_controller_map.hotkey_button) + { + current_controller_map.right_trigger = -1; + } + if (current_controller_map.lstick_button == current_controller_map.hotkey_button) + { + current_controller_map.lstick_button = -1; + } + if (current_controller_map.rstick_button == current_controller_map.hotkey_button) + { + current_controller_map.rstick_button = -1; + } + + if (current_controller_map.left_shoulder == current_controller_map.hotkey_button) + { + current_controller_map.left_shoulder = -1; + } + if (current_controller_map.right_shoulder == current_controller_map.hotkey_button) + { + current_controller_map.right_shoulder = -1; + } + + // left stick // handle the X axis (left stick) and d-pad (Hat) int val = SDL_JoystickGetAxis(Joysticktable[hostjoyid], current_controller_map.lstick_axis_x); @@ -993,31 +1051,37 @@ static void read_joystick(void) val = SDL_JoystickGetAxis(Joysticktable[hostjoyid], current_controller_map.rstick_axis_y); setjoystickstate(hostjoyid + 1, 3, val, 32767); - + int held_offset = 0; - - // temporary solution for retroarch buttons inc. HOTKEY - if (SDL_JoystickGetButton(Joysticktable[hostjoyid], current_controller_map.hotkey_button) & 1) - {held_offset = REMAP_BUTTONS; - setjoybuttonstate(hostjoyid + 1, 14 ,(SDL_JoystickGetButton(Joysticktable[hostjoyid], current_controller_map.menu_button) & 1)); // menu button - setjoybuttonstate(hostjoyid + 1, 15 ,(SDL_JoystickGetButton(Joysticktable[hostjoyid], current_controller_map.quit_button) & 1)); // quit button - setjoybuttonstate(hostjoyid + 1, 30 ,(SDL_JoystickGetButton(Joysticktable[hostjoyid], current_controller_map.reset_button) & 1)); // reest button - } - // this *should* allow us to handle function buttons (l2/r2/select) <<< except there were issues this work, picking a fixed number!! - // these two cannot be used whilst we are limtied to 32 buttons, since 'REMAP_BUTTONS' = 14 - // else if (SDL_JoystickGetButton(Joysticktable[hostjoyid], host_input_buttons[hostjoyid].left_trigger) & 1) - // held_offset = REMAP_BUTTONS * 2; - // else if (SDL_JoystickGetButton(Joysticktable[hostjoyid], host_input_buttons[hostjoyid].right_trigger) & 1) - // held_offset = REMAP_BUTTONS * 3; - - else - held_offset = 0; - - + // temporary solution for retroarch buttons inc. HOTKEY + if (SDL_JoystickGetButton(Joysticktable[hostjoyid], current_controller_map.hotkey_button) & 1) + { + held_offset = REMAP_BUTTONS; + setjoybuttonstate(hostjoyid + 1, 14, + (SDL_JoystickGetButton(Joysticktable[hostjoyid], current_controller_map.menu_button) & 1)); + // menu button + setjoybuttonstate(hostjoyid + 1, 15, + (SDL_JoystickGetButton(Joysticktable[hostjoyid], current_controller_map.quit_button) & 1)); + // quit button + setjoybuttonstate(hostjoyid + 1, 30, + (SDL_JoystickGetButton(Joysticktable[hostjoyid], current_controller_map.reset_button) & 1)); + // reest button + } + + // this *should* allow us to handle function buttons (l2/r2/select) <<< except there were issues this work, picking a fixed number!! + // these two cannot be used whilst we are limtied to 32 buttons, since 'REMAP_BUTTONS' = 14 + // else if (SDL_JoystickGetButton(Joysticktable[hostjoyid], host_input_buttons[hostjoyid].left_trigger) & 1) + // held_offset = REMAP_BUTTONS * 2; + // else if (SDL_JoystickGetButton(Joysticktable[hostjoyid], host_input_buttons[hostjoyid].right_trigger) & 1) + // held_offset = REMAP_BUTTONS * 3; + + else + held_offset = 0; + // cd32 red, blue, green, yellow - // south + // south setjoybuttonstate(hostjoyid + 1, 0 + held_offset, (SDL_JoystickGetButton(Joysticktable[hostjoyid], current_controller_map.south_button) & 1)); // east @@ -1029,20 +1093,22 @@ static void read_joystick(void) // north setjoybuttonstate(hostjoyid + 1, 3 + held_offset, (SDL_JoystickGetButton(Joysticktable[hostjoyid], current_controller_map.north_button) & 1)); - + // cd32 rwd, ffw, start setjoybuttonstate(hostjoyid + 1, 4 + held_offset, - (SDL_JoystickGetButton(Joysticktable[hostjoyid], current_controller_map.left_shoulder) & 1)); // left shoulder + (SDL_JoystickGetButton(Joysticktable[hostjoyid], current_controller_map.left_shoulder) & 1)); + // left shoulder setjoybuttonstate(hostjoyid + 1, 5 + held_offset, - (SDL_JoystickGetButton(Joysticktable[hostjoyid], current_controller_map.right_shoulder) & 1)); // right shoulder + (SDL_JoystickGetButton(Joysticktable[hostjoyid], current_controller_map.right_shoulder) & 1)); + // right shoulder setjoybuttonstate(hostjoyid + 1, 6 + held_offset, (SDL_JoystickGetButton(Joysticktable[hostjoyid], current_controller_map.start_button) & 1)); // start // up down left right // HAT Handling *or* D-PAD buttons - int hat = SDL_JoystickGetHat(Joysticktable[hostjoyid], 0); + const int hat = SDL_JoystickGetHat(Joysticktable[hostjoyid], 0); setjoybuttonstate(hostjoyid + 1, 7 + held_offset, current_controller_map.dpad_up + 1 ? (SDL_JoystickGetButton( @@ -1072,24 +1138,15 @@ static void read_joystick(void) setjoybuttonstate(hostjoyid + 1, 12 + held_offset, (SDL_JoystickGetButton(Joysticktable[hostjoyid], current_controller_map.rstick_button) & 1)); // right stick - - setjoybuttonstate(hostjoyid + 1, 13 + held_offset, + + setjoybuttonstate(hostjoyid + 1, 13 + held_offset, (SDL_JoystickGetButton(Joysticktable[hostjoyid], current_controller_map.select_button) & 1)); // select button - - - - - - - } + } } } - - - struct inputdevice_functions inputdevicefunc_joystick = { init_joystick, close_joystick, acquire_joystick, unacquire_joystick, read_joystick, get_joystick_num, get_joystick_friendlyname, get_joystick_uniquename, @@ -1101,207 +1158,209 @@ struct inputdevice_functions inputdevicefunc_joystick = { int input_get_default_joystick(struct uae_input_device* uid, int num, int port, int af, int mode, bool gp, bool joymouseswap) { - // DEAL WITH AXIS INPUT EVENTS int h, v; - if (port < 2) // ports 0, 1 ... both sticks, with mousemap - { - for (int n = 0; n < 2; ++n) - { - if (CHECK_BIT(currprefs.jports[port].mousemap,n)) - { h = port ? INPUTEVENT_MOUSE2_HORIZ : INPUTEVENT_MOUSE1_HORIZ; - v = port ? INPUTEVENT_MOUSE2_VERT : INPUTEVENT_MOUSE1_VERT; } - else - { h = port ? INPUTEVENT_JOY2_HORIZ : INPUTEVENT_JOY1_HORIZ; - v = port ? INPUTEVENT_JOY2_VERT : INPUTEVENT_JOY1_VERT; } + if (port < 2) // ports 0, 1 ... both sticks, with mousemap + { + for (int n = 0; n < 2; ++n) + { + if (CHECK_BIT(currprefs.jports[port].mousemap, n)) + { + h = port ? INPUTEVENT_MOUSE2_HORIZ : INPUTEVENT_MOUSE1_HORIZ; + v = port ? INPUTEVENT_MOUSE2_VERT : INPUTEVENT_MOUSE1_VERT; + } + else + { + h = port ? INPUTEVENT_JOY2_HORIZ : INPUTEVENT_JOY1_HORIZ; + v = port ? INPUTEVENT_JOY2_VERT : INPUTEVENT_JOY1_VERT; + } + + setid(uid, num, ID_AXIS_OFFSET + (n * 2) + 0, 0, port, h, gp); + setid(uid, num, ID_AXIS_OFFSET + (n * 2) + 1, 0, port, v, gp); + } + } + else // ports 2, 3 (parallel ports) ... both sticks, + { + for (int n = 0; n < 2; ++n) + { + h = port - 2 ? INPUTEVENT_PAR_JOY1_HORIZ : INPUTEVENT_PAR_JOY2_HORIZ; + v = port - 2 ? INPUTEVENT_PAR_JOY1_VERT : INPUTEVENT_PAR_JOY2_VERT; + setid(uid, num, ID_AXIS_OFFSET + (n * 2) + 0, 0, port, h, gp); + setid(uid, num, ID_AXIS_OFFSET + (n * 2) + 1, 0, port, v, gp); + } + } - setid(uid, num, ID_AXIS_OFFSET + (n*2) + 0, 0, port, h, gp); - setid(uid, num, ID_AXIS_OFFSET + (n*2) + 1, 0, port, v, gp); - } - } - else // ports 2, 3 (parallel ports) ... both sticks, - { - for (int n = 0; n < 2; ++n) - { - h = port - 2 ? INPUTEVENT_PAR_JOY1_HORIZ : INPUTEVENT_PAR_JOY2_HORIZ; - v = port - 2 ? INPUTEVENT_PAR_JOY1_VERT : INPUTEVENT_PAR_JOY2_VERT; - setid(uid, num, ID_AXIS_OFFSET + (n*2) + 0, 0, port, h, gp); - setid(uid, num, ID_AXIS_OFFSET + (n*2) + 1, 0, port, v, gp); - } - } - // - + // ASSIGN ALL INPUT EVENT ACTIONS, EITHER CUSTOM OR DEFAULT // // set up a temporary control layout/ called 'thismap' struct joypad_map_layout thismap[4]; - - + + // here, we will fill thismap with defaults, if a custom value is not set. // this will do a lot of the 'logic' of the original code. thismap[0] = currprefs.jports[port].amiberry_custom_none; // grab the 'no selection' options for the current map // directions - - if (port < 2) // ports 0, 1 ... - { - if (CHECK_BIT(currprefs.jports[port].mousemap,0)) - { - thismap[0].dpad_up_action = (thismap[0].dpad_up_action - ? thismap[0].dpad_up_action - : (port ? INPUTEVENT_MOUSE2_UP : INPUTEVENT_MOUSE1_UP)); - thismap[0].dpad_down_action = (thismap[0].dpad_down_action - ? thismap[0].dpad_down_action - : (port ? INPUTEVENT_MOUSE2_DOWN : INPUTEVENT_MOUSE1_DOWN)); - thismap[0].dpad_left_action = (thismap[0].dpad_left_action - ? thismap[0].dpad_left_action - : (port ? INPUTEVENT_MOUSE2_LEFT : INPUTEVENT_MOUSE1_LEFT)); - thismap[0].dpad_right_action = (thismap[0].dpad_right_action - ? thismap[0].dpad_right_action - : (port ? INPUTEVENT_MOUSE2_RIGHT : INPUTEVENT_MOUSE1_RIGHT)); - } - else - { - thismap[0].dpad_up_action = (thismap[0].dpad_up_action - ? thismap[0].dpad_up_action - : (port ? INPUTEVENT_JOY2_UP : INPUTEVENT_JOY1_UP)); - thismap[0].dpad_down_action = (thismap[0].dpad_down_action - ? thismap[0].dpad_down_action - : (port ? INPUTEVENT_JOY2_DOWN : INPUTEVENT_JOY1_DOWN)); - thismap[0].dpad_left_action = (thismap[0].dpad_left_action - ? thismap[0].dpad_left_action - : (port ? INPUTEVENT_JOY2_LEFT : INPUTEVENT_JOY1_LEFT)); - thismap[0].dpad_right_action = (thismap[0].dpad_right_action - ? thismap[0].dpad_right_action - : (port ? INPUTEVENT_JOY2_RIGHT : INPUTEVENT_JOY1_RIGHT)); - } - // standard fire buttons - if (mode == JSEM_MODE_JOYSTICK_CD32) // CD32 joypad - { - thismap[0].south_action = (thismap[0].south_action - ? thismap[0].south_action : - (port ? INPUTEVENT_JOY2_CD32_RED : INPUTEVENT_JOY1_CD32_RED)); - thismap[0].east_action = (thismap[0].east_action - ? thismap[0].east_action : - ( port ? INPUTEVENT_JOY2_CD32_BLUE : INPUTEVENT_JOY1_CD32_BLUE)); - thismap[0].west_action = (thismap[0].west_action - ? thismap[0].west_action : - ( port ? INPUTEVENT_JOY2_CD32_GREEN : INPUTEVENT_JOY1_CD32_GREEN)); - thismap[0].north_action = (thismap[0].north_action - ? thismap[0].north_action : - ( port ? INPUTEVENT_JOY2_CD32_YELLOW : INPUTEVENT_JOY1_CD32_YELLOW)); - thismap[0].start_action = (thismap[0].start_action - ? thismap[0].start_action : - ( port ? INPUTEVENT_JOY2_CD32_PLAY : INPUTEVENT_JOY1_CD32_PLAY)); - } - else // default, normal joystick - { - thismap[0].south_action = (thismap[0].south_action - ? thismap[0].south_action : - ( port ? INPUTEVENT_JOY2_FIRE_BUTTON : INPUTEVENT_JOY1_FIRE_BUTTON)); - thismap[0].east_action = (thismap[0].east_action - ? thismap[0].east_action : - ( port ? INPUTEVENT_JOY2_2ND_BUTTON : INPUTEVENT_JOY1_2ND_BUTTON)); - thismap[0].west_action = (thismap[0].west_action - ? thismap[0].west_action : - (port ? INPUTEVENT_JOY2_UP : INPUTEVENT_JOY1_UP)); - thismap[0].north_action = (thismap[0].north_action - ? thismap[0].north_action : - ( port ? INPUTEVENT_JOY2_3RD_BUTTON : INPUTEVENT_JOY1_3RD_BUTTON)); + if (port < 2) // ports 0, 1 ... + { + if (CHECK_BIT(currprefs.jports[port].mousemap,0)) + { + thismap[0].dpad_up_action = (thismap[0].dpad_up_action + ? thismap[0].dpad_up_action + : (port ? INPUTEVENT_MOUSE2_UP : INPUTEVENT_MOUSE1_UP)); + thismap[0].dpad_down_action = (thismap[0].dpad_down_action + ? thismap[0].dpad_down_action + : (port ? INPUTEVENT_MOUSE2_DOWN : INPUTEVENT_MOUSE1_DOWN)); + thismap[0].dpad_left_action = (thismap[0].dpad_left_action + ? thismap[0].dpad_left_action + : (port ? INPUTEVENT_MOUSE2_LEFT : INPUTEVENT_MOUSE1_LEFT)); + thismap[0].dpad_right_action = (thismap[0].dpad_right_action + ? thismap[0].dpad_right_action + : (port ? INPUTEVENT_MOUSE2_RIGHT : INPUTEVENT_MOUSE1_RIGHT)); + } + else + { + thismap[0].dpad_up_action = (thismap[0].dpad_up_action + ? thismap[0].dpad_up_action + : (port ? INPUTEVENT_JOY2_UP : INPUTEVENT_JOY1_UP)); + thismap[0].dpad_down_action = (thismap[0].dpad_down_action + ? thismap[0].dpad_down_action + : (port ? INPUTEVENT_JOY2_DOWN : INPUTEVENT_JOY1_DOWN)); + thismap[0].dpad_left_action = (thismap[0].dpad_left_action + ? thismap[0].dpad_left_action + : (port ? INPUTEVENT_JOY2_LEFT : INPUTEVENT_JOY1_LEFT)); + thismap[0].dpad_right_action = (thismap[0].dpad_right_action + ? thismap[0].dpad_right_action + : (port ? INPUTEVENT_JOY2_RIGHT : INPUTEVENT_JOY1_RIGHT)); + } + // standard fire buttons + if (mode == JSEM_MODE_JOYSTICK_CD32) // CD32 joypad + { + thismap[0].south_action = (thismap[0].south_action + ? thismap[0].south_action + : (port ? INPUTEVENT_JOY2_CD32_RED : INPUTEVENT_JOY1_CD32_RED)); + thismap[0].east_action = (thismap[0].east_action + ? thismap[0].east_action + : (port ? INPUTEVENT_JOY2_CD32_BLUE : INPUTEVENT_JOY1_CD32_BLUE)); + thismap[0].west_action = (thismap[0].west_action + ? thismap[0].west_action + : (port ? INPUTEVENT_JOY2_CD32_GREEN : INPUTEVENT_JOY1_CD32_GREEN)); + thismap[0].north_action = (thismap[0].north_action + ? thismap[0].north_action + : (port ? INPUTEVENT_JOY2_CD32_YELLOW : INPUTEVENT_JOY1_CD32_YELLOW)); + thismap[0].start_action = (thismap[0].start_action + ? thismap[0].start_action + : (port ? INPUTEVENT_JOY2_CD32_PLAY : INPUTEVENT_JOY1_CD32_PLAY)); + } + else // default, normal joystick + { + thismap[0].south_action = (thismap[0].south_action + ? thismap[0].south_action + : (port ? INPUTEVENT_JOY2_FIRE_BUTTON : INPUTEVENT_JOY1_FIRE_BUTTON)); + thismap[0].east_action = (thismap[0].east_action + ? thismap[0].east_action + : (port ? INPUTEVENT_JOY2_2ND_BUTTON : INPUTEVENT_JOY1_2ND_BUTTON)); + thismap[0].west_action = (thismap[0].west_action + ? thismap[0].west_action + : (port ? INPUTEVENT_JOY2_UP : INPUTEVENT_JOY1_UP)); + thismap[0].north_action = (thismap[0].north_action + ? thismap[0].north_action + : (port ? INPUTEVENT_JOY2_3RD_BUTTON : INPUTEVENT_JOY1_3RD_BUTTON)); - thismap[0].start_action = (thismap[0].start_action ? thismap[0].start_action : INPUTEVENT_KEY_P); - } + thismap[0].start_action = (thismap[0].start_action ? thismap[0].start_action : INPUTEVENT_KEY_P); + } - // shoulder buttons - if (CHECK_BIT(currprefs.jports[port].mousemap,1)) - // if we use right-analogue as mouse, then we will use shoulder buttons as LMB/RMB - //if (1==0) - { - thismap[0].left_shoulder_action = (thismap[0].left_shoulder_action - ? thismap[0].left_shoulder_action - : port - ? INPUTEVENT_JOY2_FIRE_BUTTON - : INPUTEVENT_JOY1_FIRE_BUTTON); - thismap[0].right_shoulder_action = (thismap[0].right_shoulder_action - ? thismap[0].right_shoulder_action - : port - ? INPUTEVENT_JOY2_2ND_BUTTON - : INPUTEVENT_JOY1_2ND_BUTTON); - } + // shoulder buttons + if (CHECK_BIT(currprefs.jports[port].mousemap,1)) + // if we use right-analogue as mouse, then we will use shoulder buttons as LMB/RMB + //if (1==0) + { + thismap[0].left_shoulder_action = (thismap[0].left_shoulder_action + ? thismap[0].left_shoulder_action + : port + ? INPUTEVENT_JOY2_FIRE_BUTTON + : INPUTEVENT_JOY1_FIRE_BUTTON); + thismap[0].right_shoulder_action = (thismap[0].right_shoulder_action + ? thismap[0].right_shoulder_action + : port + ? INPUTEVENT_JOY2_2ND_BUTTON + : INPUTEVENT_JOY1_2ND_BUTTON); + } - else if (mode == JSEM_MODE_JOYSTICK_CD32) // CD32 joypad, use RWD/FWD - { - thismap[0].left_shoulder_action = (thismap[0].left_shoulder_action - ? thismap[0].left_shoulder_action : - ( port ? INPUTEVENT_JOY2_CD32_RWD : INPUTEVENT_JOY1_CD32_RWD)); + else if (mode == JSEM_MODE_JOYSTICK_CD32) // CD32 joypad, use RWD/FWD + { + thismap[0].left_shoulder_action = (thismap[0].left_shoulder_action + ? thismap[0].left_shoulder_action + : (port ? INPUTEVENT_JOY2_CD32_RWD : INPUTEVENT_JOY1_CD32_RWD)); - thismap[0].right_shoulder_action = (thismap[0].right_shoulder_action - ? thismap[0].right_shoulder_action : - ( port ? INPUTEVENT_JOY2_CD32_FFW : INPUTEVENT_JOY1_CD32_FFW)); - } - else // default, normal joystick - { - thismap[0].left_shoulder_action = (thismap[0].left_shoulder_action - ? thismap[0].left_shoulder_action : INPUTEVENT_KEY_SPACE); - thismap[0].right_shoulder_action = (thismap[0].right_shoulder_action - ? thismap[0].right_shoulder_action : INPUTEVENT_KEY_RETURN); - } + thismap[0].right_shoulder_action = (thismap[0].right_shoulder_action + ? thismap[0].right_shoulder_action + : (port ? INPUTEVENT_JOY2_CD32_FFW : INPUTEVENT_JOY1_CD32_FFW)); + } + else // default, normal joystick + { + thismap[0].left_shoulder_action = (thismap[0].left_shoulder_action + ? thismap[0].left_shoulder_action + : INPUTEVENT_KEY_SPACE); + thismap[0].right_shoulder_action = (thismap[0].right_shoulder_action + ? thismap[0].right_shoulder_action + : INPUTEVENT_KEY_RETURN); + } + } + else // ports 2, 3 ... parallel ports + { + thismap[0].dpad_up_action = (thismap[0].dpad_up_action + ? thismap[0].dpad_up_action + : (port - 2 ? INPUTEVENT_PAR_JOY2_UP : INPUTEVENT_PAR_JOY1_UP)); + thismap[0].dpad_down_action = (thismap[0].dpad_down_action + ? thismap[0].dpad_down_action + : (port - 2 ? INPUTEVENT_PAR_JOY2_DOWN : INPUTEVENT_PAR_JOY1_DOWN)); + thismap[0].dpad_left_action = (thismap[0].dpad_left_action + ? thismap[0].dpad_left_action + : (port - 2 ? INPUTEVENT_PAR_JOY2_LEFT : INPUTEVENT_PAR_JOY1_LEFT)); + thismap[0].dpad_right_action = (thismap[0].dpad_right_action + ? thismap[0].dpad_right_action + : (port - 2 ? INPUTEVENT_PAR_JOY2_RIGHT : INPUTEVENT_PAR_JOY1_RIGHT)); + + thismap[0].south_action = (thismap[0].south_action + ? thismap[0].south_action + : (port - 2 ? INPUTEVENT_PAR_JOY2_FIRE_BUTTON : INPUTEVENT_PAR_JOY1_FIRE_BUTTON)); + thismap[0].east_action = (thismap[0].east_action + ? thismap[0].east_action + : (port - 2 ? INPUTEVENT_PAR_JOY2_2ND_BUTTON : INPUTEVENT_PAR_JOY1_2ND_BUTTON)); + + thismap[0].start_action = (thismap[0].start_action ? thismap[0].start_action : INPUTEVENT_KEY_P); + thismap[0].left_shoulder_action = (thismap[0].left_shoulder_action + ? thismap[0].left_shoulder_action + : INPUTEVENT_KEY_SPACE); + thismap[0].right_shoulder_action = (thismap[0].right_shoulder_action + ? thismap[0].right_shoulder_action + : INPUTEVENT_KEY_RETURN); + } - } - else // ports 2, 3 ... parallel ports - { - thismap[0].dpad_up_action = (thismap[0].dpad_up_action - ? thismap[0].dpad_up_action - : (port - 2 ? INPUTEVENT_PAR_JOY2_UP : INPUTEVENT_PAR_JOY1_UP)); - thismap[0].dpad_down_action = (thismap[0].dpad_down_action - ? thismap[0].dpad_down_action - : (port - 2 ? INPUTEVENT_PAR_JOY2_DOWN : INPUTEVENT_PAR_JOY1_DOWN)); - thismap[0].dpad_left_action = (thismap[0].dpad_left_action - ? thismap[0].dpad_left_action - : (port - 2 ? INPUTEVENT_PAR_JOY2_LEFT : INPUTEVENT_PAR_JOY1_LEFT)); - thismap[0].dpad_right_action = (thismap[0].dpad_right_action - ? thismap[0].dpad_right_action - : (port - 2 ? INPUTEVENT_PAR_JOY2_RIGHT : INPUTEVENT_PAR_JOY1_RIGHT)); - - thismap[0].south_action = (thismap[0].south_action - ? thismap[0].south_action : - ( port - 2 ? INPUTEVENT_PAR_JOY2_FIRE_BUTTON : INPUTEVENT_PAR_JOY1_FIRE_BUTTON)); - thismap[0].east_action = (thismap[0].east_action - ? thismap[0].east_action : - ( port - 2 ? INPUTEVENT_PAR_JOY2_2ND_BUTTON : INPUTEVENT_PAR_JOY1_2ND_BUTTON)); - - thismap[0].start_action = (thismap[0].start_action ? thismap[0].start_action : INPUTEVENT_KEY_P); - thismap[0].left_shoulder_action = (thismap[0].left_shoulder_action - ? thismap[0].left_shoulder_action : INPUTEVENT_KEY_SPACE); - thismap[0].right_shoulder_action = (thismap[0].right_shoulder_action - ? thismap[0].right_shoulder_action : INPUTEVENT_KEY_RETURN); - - } - - - thismap[1] = currprefs.jports[port].amiberry_custom_hotkey; // grab the 'select button' options for the current map - - // currently disabled -// thismap[2] = currprefs.jports[port].amiberry_custom_left_trigger; // grab the 'left trigger' options for the current map -// thismap[3] = currprefs.jports[port].amiberry_custom_right_trigger; // grab the 'right trigger' options for the current map + + // currently disabled + // thismap[2] = currprefs.jports[port].amiberry_custom_left_trigger; // grab the 'left trigger' options for the current map + // thismap[3] = currprefs.jports[port].amiberry_custom_right_trigger; // grab the 'right trigger' options for the current map // Now assign the actual buttons VALUES (TRUE/FALSE) to trigger the EVENTS - int function_offset = 0; - - + int function_offset = 0; + + for (int n = 0; n < 2; ++n) /// temporarily limited to '2' only { - function_offset = n * REMAP_BUTTONS; - + function_offset = n * REMAP_BUTTONS; + // s/e/w/n - setid_af(uid, num, ID_BUTTON_OFFSET + 0 + function_offset, 0, port, thismap[n].south_action, af, gp); + setid_af(uid, num, ID_BUTTON_OFFSET + 0 + function_offset, 0, port, thismap[n].south_action, af, gp); setid(uid, num, ID_BUTTON_OFFSET + 1 + function_offset, 0, port, thismap[n].east_action, gp); setid(uid, num, ID_BUTTON_OFFSET + 2 + function_offset, 0, port, thismap[n].west_action, gp); setid(uid, num, ID_BUTTON_OFFSET + 3 + function_offset, 0, port, thismap[n].north_action, gp); @@ -1320,15 +1379,24 @@ int input_get_default_joystick(struct uae_input_device* uid, int num, int port, // stick buttons setid(uid, num, ID_BUTTON_OFFSET + 11 + function_offset, 0, port, thismap[n].lstick_select_action, gp); setid(uid, num, ID_BUTTON_OFFSET + 12 + function_offset, 0, port, thismap[n].rstick_select_action, gp); - - setid(uid, num, ID_BUTTON_OFFSET + 13 + function_offset, 0, port, thismap[n].select_action, gp); + + setid(uid, num, ID_BUTTON_OFFSET + 13 + function_offset, 0, port, thismap[n].select_action, gp); + } + + // if using retroarch options + if (currprefs.amiberry_use_retroarch_menu == true) + { + setid(uid, num, ID_BUTTON_OFFSET + 14, 0, port, INPUTEVENT_SPC_ENTERGUI, gp); + } + if (currprefs.amiberry_use_retroarch_quit == true) + { + setid(uid, num, ID_BUTTON_OFFSET + 15, 0, port, INPUTEVENT_SPC_QUIT, gp); + } + if (currprefs.amiberry_use_retroarch_reset == true) + { + setid(uid, num, ID_BUTTON_OFFSET + 30, 0, port, INPUTEVENT_SPC_SOFTRESET, gp); } - // if using retroarch options - if (currprefs.amiberry_use_retroarch_menu == true) {setid(uid, num, ID_BUTTON_OFFSET + 14, 0, port, INPUTEVENT_SPC_ENTERGUI, gp);} - if (currprefs.amiberry_use_retroarch_quit == true) {setid(uid, num, ID_BUTTON_OFFSET + 15, 0, port, INPUTEVENT_SPC_QUIT, gp); } - if (currprefs.amiberry_use_retroarch_reset == true) {setid(uid, num, ID_BUTTON_OFFSET + 30, 0, port, INPUTEVENT_SPC_SOFTRESET, gp); } - if (num >= 0 && num < nr_joysticks) { return 1; diff --git a/src/osdep/gui/main_window.cpp b/src/osdep/gui/main_window.cpp index fb8adf91..8e0d8453 100644 --- a/src/osdep/gui/main_window.cpp +++ b/src/osdep/gui/main_window.cpp @@ -199,7 +199,7 @@ void RegisterRefreshFunc(void (*func)(void)) static void ShowHelpRequested() { - std::vector helptext; + vector helptext; if (categories[last_active_panel].HelpFunc != nullptr && categories[last_active_panel].HelpFunc(helptext)) { //------------------------------------------------ @@ -275,6 +275,12 @@ namespace sdl gui_texture = SDL_CreateTextureFromSurface(renderer, gui_screen); check_error_sdl(gui_texture == nullptr, "Unable to create texture"); +#ifdef ANDROIDSDL + // Enable Android multitouch + SDL_InitSubSystem(SDL_INIT_JOYSTICK); + SDL_JoystickOpen(0); +#endif + if (cursor) { SDL_ShowCursor(SDL_ENABLE); @@ -306,7 +312,10 @@ namespace sdl delete gui_graphics; SDL_FreeSurface(gui_screen); + SDL_DestroyTexture(gui_texture); + gui_texture = nullptr; + if (cursor) { SDL_FreeCursor(cursor); @@ -324,7 +333,96 @@ namespace sdl { while (SDL_PollEvent(&gui_event)) { - if (gui_event.type == SDL_KEYDOWN) + if (gui_event.type == SDL_QUIT) + { + //------------------------------------------------- + // Quit entire program via SQL-Quit + //------------------------------------------------- + uae_quit(); + gui_running = false; + break; + } + + // Horace's start at implementing Joystick control + if (gui_event.type == SDL_JOYBUTTONDOWN || gui_event.type == SDL_JOYHATMOTION) + { + gcn::FocusHandler* focusHdl; + gcn::Widget* activeWidget; + + const int hat = SDL_JoystickGetHat(GUIjoy, 0); + + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_up) || (hat & SDL_HAT_UP)) // dpad + { + if (HandleNavigation(DIRECTION_UP)) + continue; // Don't change value when enter Slider -> don't send event to control + PushFakeKey(SDLK_UP); + break; + } + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_down) || (hat & SDL_HAT_DOWN)) // dpad + { + if (HandleNavigation(DIRECTION_DOWN)) + continue; // Don't change value when enter Slider -> don't send event to control + PushFakeKey(SDLK_DOWN); + break; + } + + + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].left_shoulder)) // dpad + { + for (int z = 0; z<10; ++z) + { + PushFakeKey(SDLK_UP); + } + } + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].right_shoulder)) // dpad + { + for (int z = 0; z<10; ++z) + { + PushFakeKey(SDLK_DOWN); + } + } + + + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_right) || (hat & SDL_HAT_RIGHT)) // dpad + { + if (HandleNavigation(DIRECTION_RIGHT)) + continue; // Don't change value when enter Slider -> don't send event to control + PushFakeKey(SDLK_RIGHT); + break; + } + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_left) || (hat & SDL_HAT_LEFT)) // dpad + { + if (HandleNavigation(DIRECTION_LEFT)) + continue; // Don't change value when enter Slider -> don't send event to control + PushFakeKey(SDLK_LEFT); + break; + } + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button)) // need this to be X button + { + PushFakeKey(SDLK_RETURN); + continue; + } + + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].quit_button) && + SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].hotkey_button)) // use the HOTKEY button + { + uae_quit(); + gui_running = false; + break; + } + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].left_trigger)) + { + ShowHelpRequested(); + widgets::cmdHelp->requestFocus(); + break; + } + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].menu_button)) // use the HOTKEY button + { + gui_running = false; + } + } + + if (gui_event.type == SDL_KEYDOWN && gui_event.key.repeat == 0) { gcn::FocusHandler* focusHdl; gcn::Widget* activeWidget; @@ -406,14 +504,7 @@ namespace sdl break; } } - else if (gui_event.type == SDL_QUIT) - { - //------------------------------------------------- - // Quit entire program via SQL-Quit - //------------------------------------------------- - uae_quit(); - gui_running = false; - } + //------------------------------------------------- // Send event to guisan-controls //------------------------------------------------- @@ -427,6 +518,8 @@ namespace sdl void gui_run() { + GUIjoy = SDL_JoystickOpen(0); + //------------------------------------------------- // The main loop //------------------------------------------------- @@ -442,8 +535,8 @@ namespace sdl uae_gui->logic(); // Now we let the Gui object draw itself. uae_gui->draw(); - // Finally we update the screen. + // Finally we update the screen. UpdateGuiScreen(); if (refreshFuncAfterDraw != nullptr)