Minor cleanup
This commit is contained in:
parent
04b19cf51b
commit
023be2fbe1
2 changed files with 149 additions and 219 deletions
|
@ -5136,7 +5136,8 @@ static void setbuttonstateall (struct uae_input_device *id, struct uae_input_dev
|
|||
|
||||
if (buttonstate) {
|
||||
switchdevice_timeout = t;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (switchdevice_timeout) {
|
||||
int port = button;
|
||||
if (t - switchdevice_timeout >= syncbase) // 1s
|
||||
|
@ -5179,9 +5180,11 @@ static void setbuttonstateall (struct uae_input_device *id, struct uae_input_dev
|
|||
|
||||
if (buttonstate < 0) {
|
||||
state = buttonstate;
|
||||
} else if (invert) {
|
||||
}
|
||||
else if (invert) {
|
||||
state = buttonstate ? 0 : 1;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
state = buttonstate;
|
||||
}
|
||||
if (setmode) {
|
||||
|
@ -5203,16 +5206,19 @@ static void setbuttonstateall (struct uae_input_device *id, struct uae_input_dev
|
|||
continue;
|
||||
handle_input_event(evt, 1, 1, HANDLE_IE_FLAG_CANSTOPPLAYBACK);
|
||||
didcustom |= process_custom_event(id, ID_BUTTON_OFFSET + button, state, qualmask, 0, i);
|
||||
} else if (inverttoggle) {
|
||||
}
|
||||
else if (inverttoggle) {
|
||||
/* pressed = firebutton, not pressed = autofire */
|
||||
if (state) {
|
||||
queue_input_event(evt, NULL, -1, 0, 0, 1);
|
||||
handle_input_event(evt, 2, 1, HANDLE_IE_FLAG_CANSTOPPLAYBACK);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
handle_input_event(evt, 2, 1, (autofire ? HANDLE_IE_FLAG_AUTOFIRE : 0) | HANDLE_IE_FLAG_CANSTOPPLAYBACK);
|
||||
}
|
||||
didcustom |= process_custom_event(id, ID_BUTTON_OFFSET + button, state, qualmask, autofire, i);
|
||||
} else if (toggle) {
|
||||
}
|
||||
else if (toggle) {
|
||||
if (!state)
|
||||
continue;
|
||||
if (omask & mask)
|
||||
|
@ -5223,12 +5229,14 @@ static void setbuttonstateall (struct uae_input_device *id, struct uae_input_dev
|
|||
int toggled = (*flagsp & ID_FLAG_TOGGLED) ? 2 : 0;
|
||||
handle_input_event(evt, toggled, 1, (autofire ? HANDLE_IE_FLAG_AUTOFIRE : 0) | HANDLE_IE_FLAG_CANSTOPPLAYBACK);
|
||||
didcustom |= process_custom_event(id, ID_BUTTON_OFFSET + button, toggled, qualmask, autofire, i);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (!checkqualifiers(evt, flags, qualmask, NULL)) {
|
||||
if (!state && !(flags & ID_FLAG_CANRELEASE)) {
|
||||
if (!invert)
|
||||
continue;
|
||||
} else if (state) {
|
||||
}
|
||||
else if (state) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -421,12 +421,9 @@ int input_get_default_mouse(struct uae_input_device* uid, const int i, const int
|
|||
setid(uid, i, ID_AXIS_OFFSET + 0, 0, port, port ? INPUTEVENT_MOUSE2_HORIZ : INPUTEVENT_MOUSE1_HORIZ, gp);
|
||||
setid(uid, i, ID_AXIS_OFFSET + 1, 0, port, port ? INPUTEVENT_MOUSE2_VERT : INPUTEVENT_MOUSE1_VERT, gp);
|
||||
setid(uid, i, ID_AXIS_OFFSET + 2, 0, port, port ? 0 : INPUTEVENT_MOUSE1_WHEEL, gp);
|
||||
setid_af(uid, i, ID_BUTTON_OFFSET + 0, 0, port,
|
||||
port ? INPUTEVENT_JOY2_FIRE_BUTTON : INPUTEVENT_JOY1_FIRE_BUTTON, af, gp);
|
||||
setid(uid, i, ID_BUTTON_OFFSET + 1, 0, port, port ? INPUTEVENT_JOY2_2ND_BUTTON : INPUTEVENT_JOY1_2ND_BUTTON,
|
||||
gp);
|
||||
setid(uid, i, ID_BUTTON_OFFSET + 2, 0, port, port ? INPUTEVENT_JOY2_3RD_BUTTON : INPUTEVENT_JOY1_3RD_BUTTON,
|
||||
gp);
|
||||
setid_af(uid, i, ID_BUTTON_OFFSET + 0, 0, port, port ? INPUTEVENT_JOY2_FIRE_BUTTON : INPUTEVENT_JOY1_FIRE_BUTTON, af, gp);
|
||||
setid(uid, i, ID_BUTTON_OFFSET + 1, 0, port, port ? INPUTEVENT_JOY2_2ND_BUTTON : INPUTEVENT_JOY1_2ND_BUTTON, gp);
|
||||
setid(uid, i, ID_BUTTON_OFFSET + 2, 0, port, port ? INPUTEVENT_JOY2_3RD_BUTTON : INPUTEVENT_JOY1_3RD_BUTTON, gp);
|
||||
}
|
||||
|
||||
else
|
||||
|
@ -530,7 +527,6 @@ int find_retroarch(const TCHAR* find_setting, char* retroarch_file, host_input_b
|
|||
std::ifstream readFile(retroarch_file);
|
||||
std::string line;
|
||||
std::string delimiter = " = ";
|
||||
|
||||
auto tempbutton = 0;
|
||||
|
||||
// read each line in
|
||||
|
@ -553,7 +549,8 @@ int find_retroarch(const TCHAR* find_setting, char* retroarch_file, host_input_b
|
|||
|
||||
// time to get the output number
|
||||
if (param.find("h") != 0) // check it isnt some kind of hat starting 'h' (so if D-pad uses buttons)
|
||||
{ tempbutton = abs(atol(param.c_str()));
|
||||
{
|
||||
tempbutton = abs(atol(param.c_str()));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -561,29 +558,17 @@ int find_retroarch(const TCHAR* find_setting, char* retroarch_file, host_input_b
|
|||
}
|
||||
|
||||
// gets the parameter
|
||||
|
||||
if (strncmp(find_setting, "count_hats", 10) == 0 && param.find("h0") == 0)
|
||||
{
|
||||
tempbutton = 1;
|
||||
break;
|
||||
}
|
||||
//else if (param.find("h0") == 0)
|
||||
//{
|
||||
|
||||
//}
|
||||
|
||||
// ok, this is the 'normal' storing of values
|
||||
if (option == find_setting)
|
||||
break;
|
||||
|
||||
// ignore anthing that isnt our special case(s), and keep looping
|
||||
//if (strncmp(find_setting, "count_hats", 10) != 0)
|
||||
// tempbutton = -1;
|
||||
}
|
||||
}
|
||||
|
||||
write_log("Controller Detection: %s : %d\n", find_setting, tempbutton);
|
||||
|
||||
return tempbutton;
|
||||
}
|
||||
|
||||
|
@ -594,7 +579,6 @@ bool find_retroarch_polarity(const TCHAR* find_setting, char* retroarch_file)
|
|||
std::ifstream readFile(retroarch_file);
|
||||
std::string line;
|
||||
std::string delimiter = " = ";
|
||||
|
||||
auto tempbutton = false;
|
||||
|
||||
// read each line in
|
||||
|
@ -627,7 +611,6 @@ bool find_retroarch_polarity(const TCHAR* find_setting, char* retroarch_file)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tempbutton;
|
||||
}
|
||||
|
||||
|
@ -637,7 +620,6 @@ const TCHAR* find_retroarch_key(const TCHAR* find_setting, char* retroarch_file)
|
|||
ifstream read_file(retroarch_file);
|
||||
string line;
|
||||
string delimiter = " = ";
|
||||
|
||||
auto output = "nul";
|
||||
|
||||
// read each line in
|
||||
|
@ -670,7 +652,6 @@ const TCHAR* find_retroarch_key(const TCHAR* find_setting, char* retroarch_file)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
@ -686,7 +667,6 @@ int find_string_in_array(const char* arr[], const int n, const char* key)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
|
@ -705,7 +685,6 @@ static std::string sanitize_retroarch_name(std::string s)
|
|||
{
|
||||
s.erase(remove(s.begin(), s.end(), illegal_chars[i]), s.end());
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
@ -721,8 +700,6 @@ static int init_joystick(void)
|
|||
{
|
||||
struct host_keyboard_button temp_keyboard_buttons {};
|
||||
|
||||
|
||||
|
||||
auto tempkey = find_retroarch_key("input_player1_y", retroarch_file);
|
||||
auto x = find_string_in_array(remap_key_map_list_strings, remap_key_map_list_size, tempkey);
|
||||
temp_keyboard_buttons.north_button = remap_key_map_list[x];
|
||||
|
@ -814,8 +791,6 @@ static int init_joystick(void)
|
|||
if (SDL_JoystickNameForIndex(cpt) != nullptr)
|
||||
strncpy(joystick_name[cpt], SDL_JoystickNameForIndex(cpt), sizeof joystick_name[cpt] - 1);
|
||||
#endif
|
||||
//else
|
||||
//sprintf(joystick_name[cpt], "Joystick%d", cpt);
|
||||
write_log("Controller Detection for Device: %s \n", joystick_name[cpt]);
|
||||
|
||||
//this now uses controllers path (in tmp)
|
||||
|
@ -823,18 +798,13 @@ static int init_joystick(void)
|
|||
strcpy(control_config, tmp);
|
||||
auto sanitized_name = sanitize_retroarch_name(joystick_name[cpt]);
|
||||
strcat(control_config, sanitized_name.c_str());
|
||||
//strcat(control_config, joystick_name[cpt]);
|
||||
strcat(control_config, ".cfg");
|
||||
|
||||
//printf("Trying to match >>%s<<\n",control_config);
|
||||
|
||||
if (zfile_exists(control_config))
|
||||
{
|
||||
fill_blank_controller();
|
||||
host_input_buttons[cpt] = default_controller_map;
|
||||
|
||||
//printf("Retroarch search for: >>%s<<\n",joystick_name[cpt]);
|
||||
|
||||
host_input_buttons[cpt].is_retroarch = true;
|
||||
|
||||
host_input_buttons[cpt].hotkey_button = find_retroarch("input_enable_hotkey_btn", control_config,
|
||||
|
@ -921,28 +891,19 @@ static int init_joystick(void)
|
|||
host_input_buttons[cpt].rstick_axis_x_invert = find_retroarch_polarity("input_r_x_plus_axis", control_config);
|
||||
host_input_buttons[cpt].rstick_axis_y_invert = find_retroarch_polarity("input_r_y_plus_axis", control_config);
|
||||
|
||||
//i'll just leave this here for when we have a working debug logging
|
||||
|
||||
write_log("Controller Detection: invert left y axis: %d\n", host_input_buttons[cpt].lstick_axis_y_invert);
|
||||
write_log("Controller Detection: invert left x axis: %d\n", host_input_buttons[cpt].lstick_axis_x_invert);
|
||||
write_log("Controller Detection: invert right y axis: %d\n", host_input_buttons[cpt].rstick_axis_y_invert);
|
||||
write_log("Controller Detection: invert right x axis: %d\n", host_input_buttons[cpt].rstick_axis_x_invert);
|
||||
//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");
|
||||
//printf(" Using default controller layout: with n/s/e/w mapping.\n");
|
||||
fill_default_controller();
|
||||
host_input_buttons[cpt] = default_controller_map;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1098,7 +1059,7 @@ static int get_joystick_flags(int num)
|
|||
}
|
||||
|
||||
|
||||
static void read_joystick(void)
|
||||
static void read_joystick()
|
||||
{
|
||||
for (auto joyid = 0; joyid < MAX_JPORTS; joyid++)
|
||||
{
|
||||
|
@ -1137,9 +1098,7 @@ static void read_joystick(void)
|
|||
{
|
||||
// Now we handle real SDL joystick...
|
||||
const auto hostjoyid = currprefs.jports[joyid].id - JSEM_JOYS - num_keys_as_joys;
|
||||
|
||||
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)
|
||||
|
@ -1183,20 +1142,17 @@ static void read_joystick(void)
|
|||
if (current_controller_map.menu_button != -1)
|
||||
{
|
||||
setjoybuttonstate(hostjoyid + 1, 14,
|
||||
(SDL_JoystickGetButton(joysticktable[hostjoyid],
|
||||
current_controller_map.menu_button) & 1));
|
||||
SDL_JoystickGetButton(joysticktable[hostjoyid], current_controller_map.menu_button) & 1);
|
||||
}
|
||||
if (current_controller_map.quit_button != -1)
|
||||
{
|
||||
setjoybuttonstate(hostjoyid + 1, 15,
|
||||
(SDL_JoystickGetButton(joysticktable[hostjoyid],
|
||||
current_controller_map.quit_button) & 1));
|
||||
SDL_JoystickGetButton(joysticktable[hostjoyid], current_controller_map.quit_button) & 1);
|
||||
}
|
||||
if (current_controller_map.reset_button != -1)
|
||||
{
|
||||
setjoybuttonstate(hostjoyid + 1, 30,
|
||||
(SDL_JoystickGetButton(joysticktable[hostjoyid],
|
||||
current_controller_map.reset_button) & 1));
|
||||
SDL_JoystickGetButton(joysticktable[hostjoyid], current_controller_map.reset_button) & 1);
|
||||
}
|
||||
}
|
||||
// temporary solution for retroarch buttons inc. HOTKEY
|
||||
|
@ -1204,16 +1160,13 @@ static void read_joystick(void)
|
|||
{
|
||||
held_offset = REMAP_BUTTONS;
|
||||
setjoybuttonstate(hostjoyid + 1, 14,
|
||||
(SDL_JoystickGetButton(joysticktable[hostjoyid], current_controller_map.menu_button) &
|
||||
1));
|
||||
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));
|
||||
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));
|
||||
SDL_JoystickGetButton(joysticktable[hostjoyid], current_controller_map.reset_button) & 1);
|
||||
// reset button
|
||||
}
|
||||
|
||||
|
@ -1258,26 +1211,14 @@ static void read_joystick(void)
|
|||
// alternative code for custom remapping the left stick
|
||||
// handle the Y axis (left stick)
|
||||
setjoybuttonstate(hostjoyid + 1, 7 + held_offset,
|
||||
SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.lstick_axis_y) <=
|
||||
lower_bound
|
||||
? 1
|
||||
: 0);
|
||||
SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.lstick_axis_y) <= lower_bound ? 1 : 0);
|
||||
setjoybuttonstate(hostjoyid + 1, 8 + held_offset,
|
||||
SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.lstick_axis_y) >=
|
||||
upper_bound
|
||||
? 1
|
||||
: 0);
|
||||
SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.lstick_axis_y) >= upper_bound ? 1 : 0);
|
||||
// handle the X axis
|
||||
setjoybuttonstate(hostjoyid + 1, 9 + held_offset,
|
||||
SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.lstick_axis_x) <=
|
||||
lower_bound
|
||||
? 1
|
||||
: 0);
|
||||
SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.lstick_axis_x) <= lower_bound ? 1 : 0);
|
||||
setjoybuttonstate(hostjoyid + 1, 10 + held_offset,
|
||||
SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.lstick_axis_x) >=
|
||||
upper_bound
|
||||
? 1
|
||||
: 0);
|
||||
SDL_JoystickGetAxis(joysticktable[hostjoyid], current_controller_map.lstick_axis_x) >= upper_bound ? 1 : 0);
|
||||
}
|
||||
|
||||
// right stick
|
||||
|
@ -1296,33 +1237,26 @@ static void read_joystick(void)
|
|||
// cd32 red, blue, green, yellow
|
||||
// south
|
||||
setjoybuttonstate(hostjoyid + 1, 0 + held_offset,
|
||||
(SDL_JoystickGetButton(joysticktable[hostjoyid], current_controller_map.south_button) & 1
|
||||
));
|
||||
SDL_JoystickGetButton(joysticktable[hostjoyid], current_controller_map.south_button) & 1);
|
||||
// east
|
||||
setjoybuttonstate(hostjoyid + 1, 1 + held_offset,
|
||||
(SDL_JoystickGetButton(joysticktable[hostjoyid],
|
||||
current_controller_map.east_button) & 1));
|
||||
SDL_JoystickGetButton(joysticktable[hostjoyid], current_controller_map.east_button) & 1);
|
||||
// west
|
||||
setjoybuttonstate(hostjoyid + 1, 2 + held_offset,
|
||||
(SDL_JoystickGetButton(joysticktable[hostjoyid],
|
||||
current_controller_map.west_button) & 1));
|
||||
SDL_JoystickGetButton(joysticktable[hostjoyid], current_controller_map.west_button) & 1);
|
||||
// north
|
||||
setjoybuttonstate(hostjoyid + 1, 3 + held_offset,
|
||||
(SDL_JoystickGetButton(joysticktable[hostjoyid], current_controller_map.north_button) & 1
|
||||
));
|
||||
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
|
||||
));
|
||||
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));
|
||||
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
|
||||
));
|
||||
SDL_JoystickGetButton(joysticktable[hostjoyid], current_controller_map.start_button) & 1);
|
||||
// start
|
||||
|
||||
// up down left right
|
||||
|
@ -1330,45 +1264,33 @@ static void read_joystick(void)
|
|||
const int hat = SDL_JoystickGetHat(joysticktable[hostjoyid], 0);
|
||||
|
||||
setjoybuttonstate(hostjoyid + 1, 7 + held_offset, current_controller_map.dpad_up + 1
|
||||
? (SDL_JoystickGetButton(
|
||||
joysticktable[hostjoyid],
|
||||
current_controller_map.dpad_up) & 1)
|
||||
? SDL_JoystickGetButton(joysticktable[hostjoyid], current_controller_map.dpad_up) & 1
|
||||
: hat & SDL_HAT_UP);
|
||||
setjoybuttonstate(hostjoyid + 1, 8 + held_offset, current_controller_map.dpad_down + 1
|
||||
? (SDL_JoystickGetButton(
|
||||
joysticktable[hostjoyid],
|
||||
current_controller_map.dpad_down) & 1)
|
||||
? SDL_JoystickGetButton(joysticktable[hostjoyid], current_controller_map.dpad_down) & 1
|
||||
: hat & SDL_HAT_DOWN);
|
||||
setjoybuttonstate(hostjoyid + 1, 9 + held_offset, current_controller_map.dpad_left + 1
|
||||
? (SDL_JoystickGetButton(
|
||||
joysticktable[hostjoyid],
|
||||
current_controller_map.dpad_left) & 1)
|
||||
? SDL_JoystickGetButton(joysticktable[hostjoyid], current_controller_map.dpad_left) & 1
|
||||
: hat & SDL_HAT_LEFT);
|
||||
setjoybuttonstate(hostjoyid + 1, 10 + held_offset, current_controller_map.dpad_right + 1
|
||||
? (SDL_JoystickGetButton(
|
||||
joysticktable[hostjoyid],
|
||||
current_controller_map.dpad_right) & 1)
|
||||
? SDL_JoystickGetButton(joysticktable[hostjoyid], current_controller_map.dpad_right) & 1
|
||||
: hat & SDL_HAT_RIGHT);
|
||||
|
||||
// stick left/right/select
|
||||
setjoybuttonstate(hostjoyid + 1, 11 + held_offset,
|
||||
(SDL_JoystickGetButton(joysticktable[hostjoyid], current_controller_map.lstick_button) & 1
|
||||
));
|
||||
SDL_JoystickGetButton(joysticktable[hostjoyid], current_controller_map.lstick_button) & 1);
|
||||
// left stick
|
||||
setjoybuttonstate(hostjoyid + 1, 12 + held_offset,
|
||||
(SDL_JoystickGetButton(joysticktable[hostjoyid], current_controller_map.rstick_button) & 1
|
||||
));
|
||||
SDL_JoystickGetButton(joysticktable[hostjoyid], current_controller_map.rstick_button) & 1);
|
||||
// right stick
|
||||
|
||||
setjoybuttonstate(hostjoyid + 1, 13 + held_offset,
|
||||
(SDL_JoystickGetButton(joysticktable[hostjoyid], current_controller_map.select_button) & 1
|
||||
));
|
||||
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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue