mirror of
https://github.com/86Box/86Box.git
synced 2026-02-22 01:25:33 -07:00
Fix POV hat config code
This commit is contained in:
65
src/config.c
65
src/config.c
@@ -569,6 +569,7 @@ load_input_devices(void)
|
||||
{
|
||||
ini_section_t cat = ini_find_section(config, "Input devices");
|
||||
char temp[512];
|
||||
char tmp2[32];
|
||||
char *p;
|
||||
|
||||
p = ini_section_get_string(cat, "keyboard_type", NULL);
|
||||
@@ -646,18 +647,25 @@ load_input_devices(void)
|
||||
joystick_state[gp][js].plat_joystick_nr = ini_section_get_int(cat, temp, 0);
|
||||
|
||||
if (joystick_state[gp][js].plat_joystick_nr) {
|
||||
// --- Load Axis Mappings ---
|
||||
for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type[joy_insn]); axis_nr++) {
|
||||
sprintf(temp, "joystick_%i_axis_%i", js, axis_nr);
|
||||
joystick_state[gp][js].axis_mapping[axis_nr] = ini_section_get_int(cat, temp, axis_nr);
|
||||
}
|
||||
|
||||
// --- Load Button Mappings ---
|
||||
for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type[joy_insn]); button_nr++) {
|
||||
sprintf(temp, "joystick_%i_button_%i", js, button_nr);
|
||||
joystick_state[gp][js].button_mapping[button_nr] = ini_section_get_int(cat, temp, button_nr);
|
||||
}
|
||||
|
||||
// --- Load POV (Hat Switch) Mappings ---
|
||||
for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type[joy_insn]); pov_nr++) {
|
||||
sprintf(temp, "joystick_%i_pov_%i", js, pov_nr);
|
||||
p = ini_section_get_string(cat, temp, "0, 0");
|
||||
joystick_state[gp][js].pov_mapping[pov_nr][0] = joystick_state[gp][js].pov_mapping[pov_nr][1] = 0;
|
||||
sprintf(tmp2, "%i, %i", 0, 0);
|
||||
p = ini_section_get_string(cat, temp, tmp2);
|
||||
joystick_state[gp][js].pov_mapping[pov_nr][0] = 0;
|
||||
joystick_state[gp][js].pov_mapping[pov_nr][1] = 0;
|
||||
sscanf(p, "%i, %i", &joystick_state[gp][js].pov_mapping[pov_nr][0],
|
||||
&joystick_state[gp][js].pov_mapping[pov_nr][1]);
|
||||
}
|
||||
@@ -2702,7 +2710,7 @@ save_input_devices(void)
|
||||
{
|
||||
ini_section_t cat = ini_find_or_create_section(config, "Input devices");
|
||||
char temp[512];
|
||||
char tmp2[512];
|
||||
char tmp2[32];
|
||||
|
||||
ini_section_set_string(cat, "keyboard_type", keyboard_get_internal_name(keyboard_type));
|
||||
|
||||
@@ -2713,20 +2721,25 @@ save_input_devices(void)
|
||||
ini_section_delete_var(cat, "joystick_type");
|
||||
|
||||
for (int js = 0; js < MAX_PLAT_JOYSTICKS; js++) {
|
||||
sprintf(tmp2, "joystick_%i_nr", js);
|
||||
ini_section_delete_var(cat, tmp2);
|
||||
sprintf(temp, "joystick_%i_nr", js);
|
||||
ini_section_delete_var(cat, temp);
|
||||
|
||||
// --- Save Axis Mappings ---
|
||||
for (int axis_nr = 0; axis_nr < MAX_JOY_AXES; axis_nr++) {
|
||||
sprintf(tmp2, "joystick_%i_axis_%i", js, axis_nr);
|
||||
ini_section_delete_var(cat, tmp2);
|
||||
sprintf(temp, "joystick_%i_axis_%i", js, axis_nr);
|
||||
ini_section_delete_var(cat, temp);
|
||||
}
|
||||
|
||||
// --- Save Button Mappings ---
|
||||
for (int button_nr = 0; button_nr < MAX_JOY_BUTTONS; button_nr++) {
|
||||
sprintf(tmp2, "joystick_%i_button_%i", js, button_nr);
|
||||
ini_section_delete_var(cat, tmp2);
|
||||
sprintf(temp, "joystick_%i_button_%i", js, button_nr);
|
||||
ini_section_delete_var(cat, temp);
|
||||
}
|
||||
|
||||
// --- Save POV (Hat Switch) Mappings ---
|
||||
for (int pov_nr = 0; pov_nr < MAX_JOY_POVS; pov_nr++) {
|
||||
sprintf(tmp2, "joystick_%i_pov_%i", js, pov_nr);
|
||||
ini_section_delete_var(cat, tmp2);
|
||||
sprintf(temp, "joystick_%i_pov_%i", js, pov_nr);
|
||||
ini_section_delete_var(cat, temp);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -2735,33 +2748,37 @@ save_input_devices(void)
|
||||
ini_section_set_string(cat, "joystick_type", joystick_get_internal_name(joystick_type[joy_insn]));
|
||||
|
||||
for (int js = 0; js < joystick_get_max_joysticks(joystick_type[joy_insn]); js++) {
|
||||
sprintf(tmp2, "joystick_%i_nr", js);
|
||||
ini_section_set_int(cat, tmp2, joystick_state[gp][js].plat_joystick_nr);
|
||||
sprintf(temp, "joystick_%i_nr", js);
|
||||
ini_section_set_int(cat, temp, joystick_state[gp][js].plat_joystick_nr);
|
||||
|
||||
if (joystick_state[gp][js].plat_joystick_nr) {
|
||||
// --- Save Axis Mappings ---
|
||||
for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type[joy_insn]); axis_nr++) {
|
||||
sprintf(tmp2, "joystick_%i_axis_%i", js, axis_nr);
|
||||
ini_section_set_int(cat, tmp2, joystick_state[gp][js].axis_mapping[axis_nr]);
|
||||
sprintf(temp, "joystick_%i_axis_%i", js, axis_nr);
|
||||
ini_section_set_int(cat, temp, joystick_state[gp][js].axis_mapping[axis_nr]);
|
||||
}
|
||||
|
||||
// --- Save Button Mappings ---
|
||||
for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type[joy_insn]); button_nr++) {
|
||||
sprintf(tmp2, "joystick_%i_button_%i", js, button_nr);
|
||||
ini_section_set_int(cat, tmp2, joystick_state[gp][js].button_mapping[button_nr]);
|
||||
sprintf(temp, "joystick_%i_button_%i", js, button_nr);
|
||||
ini_section_set_int(cat, temp, joystick_state[gp][js].button_mapping[button_nr]);
|
||||
}
|
||||
|
||||
// --- Save POV (Hat Switch) Mappings ---
|
||||
for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type[joy_insn]); pov_nr++) {
|
||||
sprintf(tmp2, "joystick_%i_pov_%i", js, pov_nr);
|
||||
sprintf(temp, "%i, %i", joystick_state[gp][js].pov_mapping[pov_nr][0],
|
||||
joystick_state[gp][js].pov_mapping[pov_nr][1]);
|
||||
ini_section_set_string(cat, tmp2, temp);
|
||||
sprintf(temp, "joystick_%i_pov_%i", js, pov_nr);
|
||||
sprintf(tmp2, "%i, %i", joystick_state[gp][js].pov_mapping[pov_nr][0],
|
||||
joystick_state[gp][js].pov_mapping[pov_nr][1]);
|
||||
ini_section_set_string(cat, temp, tmp2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tablet_tool_type != 1) {
|
||||
if (tablet_tool_type != 1)
|
||||
ini_section_set_int(cat, "tablet_tool_type", tablet_tool_type);
|
||||
} else {
|
||||
else
|
||||
ini_section_delete_var(cat, "tablet_tool_type");
|
||||
}
|
||||
|
||||
ini_delete_section_if_empty(config, cat);
|
||||
}
|
||||
|
||||
@@ -335,7 +335,7 @@ SettingsInput::on_pushButtonConfigureMouse_clicked()
|
||||
}
|
||||
|
||||
static int
|
||||
get_axis(JoystickConfiguration &jc, int axis, uint8_t gameport_nr, int joystick_nr)
|
||||
get_axis(JoystickConfiguration &jc, uint8_t gameport_nr, int joystick_nr, int axis)
|
||||
{
|
||||
int axis_sel = jc.selectedAxis(axis);
|
||||
int nr_axes = plat_joystick_state[joystick_state[gameport_nr][joystick_nr].plat_joystick_nr - 1].nr_axes;
|
||||
@@ -351,7 +351,7 @@ get_axis(JoystickConfiguration &jc, int axis, uint8_t gameport_nr, int joystick_
|
||||
}
|
||||
|
||||
static int
|
||||
get_pov(JoystickConfiguration &jc, int pov, uint8_t gameport_nr, int joystick_nr)
|
||||
get_pov(JoystickConfiguration &jc, uint8_t gameport_nr, int joystick_nr, int pov)
|
||||
{
|
||||
int pov_sel = jc.selectedPov(pov);
|
||||
int nr_povs = plat_joystick_state[joystick_state[gameport_nr][joystick_nr].plat_joystick_nr - 1].nr_povs * 2;
|
||||
@@ -379,17 +379,15 @@ updateJoystickConfig(int type, uint8_t gameport_nr, int joystick_nr, QWidget *pa
|
||||
|
||||
joystick_state[gameport_nr][joystick_nr].plat_joystick_nr = jc.selectedDevice();
|
||||
if (joystick_state[gameport_nr][joystick_nr].plat_joystick_nr) {
|
||||
for (int axis_nr = 0; axis_nr < joystick_get_axis_count(type); axis_nr++) {
|
||||
joystick_state[gameport_nr][joystick_nr].axis_mapping[axis_nr] = get_axis(jc, axis_nr, gameport_nr, joystick_nr);
|
||||
}
|
||||
for (int axis_nr = 0; axis_nr < joystick_get_axis_count(type); axis_nr++)
|
||||
joystick_state[gameport_nr][joystick_nr].axis_mapping[axis_nr] = get_axis(jc, gameport_nr, joystick_nr, axis_nr);
|
||||
|
||||
for (int button_nr = 0; button_nr < joystick_get_button_count(type); button_nr++) {
|
||||
for (int button_nr = 0; button_nr < joystick_get_button_count(type); button_nr++)
|
||||
joystick_state[gameport_nr][joystick_nr].button_mapping[button_nr] = jc.selectedButton(button_nr);
|
||||
}
|
||||
|
||||
for (int pov_nr = 0; pov_nr < joystick_get_pov_count(type) * 2; pov_nr += 2) {
|
||||
joystick_state[gameport_nr][joystick_nr].pov_mapping[pov_nr][0] = get_pov(jc, pov_nr, gameport_nr, joystick_nr);
|
||||
joystick_state[gameport_nr][joystick_nr].pov_mapping[pov_nr][1] = get_pov(jc, pov_nr + 1, gameport_nr, joystick_nr);
|
||||
for (int pov_nr = 0; pov_nr < joystick_get_pov_count(type); pov_nr++) {
|
||||
joystick_state[gameport_nr][joystick_nr].pov_mapping[pov_nr][0] = get_pov(jc, gameport_nr, joystick_nr, pov_nr * 2); // X Axis
|
||||
joystick_state[gameport_nr][joystick_nr].pov_mapping[pov_nr][1] = get_pov(jc, gameport_nr, joystick_nr, pov_nr * 2 + 1); // Y Axis
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user