diff --git a/src/86box.c b/src/86box.c index a30ff970f..bb3f3dc3e 100644 --- a/src/86box.c +++ b/src/86box.c @@ -1593,8 +1593,9 @@ pc_reset_hard_init(void) the chances of the SCSI controller ending up on the bridge. */ video_voodoo_init(); - if (joystick_type) - gameport_update_joystick_type(); /* installs game port if no device provides one, must be late */ + /* installs first game port if no device provides one, must be late */ + if (joystick_type[0]) + gameport_update_joystick_type(0); ui_sb_update_panes(); @@ -1802,7 +1803,7 @@ pc_run(void) #ifdef USE_GDBSTUB /* avoid a KBC FIFO overflow when CPU emulation is stalled */ } #endif - joystick_process(); + joystick_process(0); // Gameport 0 endblit(); /* Done with this frame, update statistics. */ diff --git a/src/config.c b/src/config.c index 7f4279a02..345e2a483 100644 --- a/src/config.c +++ b/src/config.c @@ -529,62 +529,63 @@ load_input_devices(void) else mouse_type = 0; + uint8_t joy_insn = 0; p = ini_section_get_string(cat, "joystick_type", NULL); if (p != NULL) { - joystick_type = joystick_get_from_internal_name(p); + joystick_type[joy_insn] = joystick_get_from_internal_name(p); - if (!joystick_type) { + if (!joystick_type[joy_insn]) { /* Try to read an integer for backwards compatibility with old configs */ if (!strcmp(p, "0")) /* Workaround for ini_section_get_int returning 0 on non-integer data */ - joystick_type = joystick_get_from_internal_name("2axis_2button"); + joystick_type[joy_insn] = joystick_get_from_internal_name("2axis_2button"); else { int js = ini_section_get_int(cat, "joystick_type", 8); switch (js) { case JS_TYPE_2AXIS_4BUTTON: - joystick_type = joystick_get_from_internal_name("2axis_4button"); + joystick_type[joy_insn] = joystick_get_from_internal_name("2axis_4button"); break; case JS_TYPE_2AXIS_6BUTTON: - joystick_type = joystick_get_from_internal_name("2axis_6button"); + joystick_type[joy_insn] = joystick_get_from_internal_name("2axis_6button"); break; case JS_TYPE_2AXIS_8BUTTON: - joystick_type = joystick_get_from_internal_name("2axis_8button"); + joystick_type[joy_insn] = joystick_get_from_internal_name("2axis_8button"); break; case JS_TYPE_4AXIS_4BUTTON: - joystick_type = joystick_get_from_internal_name("4axis_4button"); + joystick_type[joy_insn] = joystick_get_from_internal_name("4axis_4button"); break; case JS_TYPE_CH_FLIGHTSTICK_PRO: - joystick_type = joystick_get_from_internal_name("ch_flightstick_pro"); + joystick_type[joy_insn] = joystick_get_from_internal_name("ch_flightstick_pro"); break; case JS_TYPE_SIDEWINDER_PAD: - joystick_type = joystick_get_from_internal_name("sidewinder_pad"); + joystick_type[joy_insn] = joystick_get_from_internal_name("sidewinder_pad"); break; case JS_TYPE_THRUSTMASTER_FCS: - joystick_type = joystick_get_from_internal_name("thrustmaster_fcs"); + joystick_type[joy_insn] = joystick_get_from_internal_name("thrustmaster_fcs"); break; default: - joystick_type = JS_TYPE_NONE; + joystick_type[joy_insn] = JS_TYPE_NONE; break; } } } } else - joystick_type = JS_TYPE_NONE; + joystick_type[joy_insn] = JS_TYPE_NONE; - for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) { + for (int js = 0; js < joystick_get_max_joysticks(joystick_type[joy_insn]); js++) { sprintf(temp, "joystick_%i_nr", js); joystick_state[0][js].plat_joystick_nr = ini_section_get_int(cat, temp, 0); if (joystick_state[0][js].plat_joystick_nr) { - for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) { + 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[0][js].axis_mapping[axis_nr] = ini_section_get_int(cat, temp, axis_nr); } - for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) { + 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[0][js].button_mapping[button_nr] = ini_section_get_int(cat, temp, button_nr); } - for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) { + 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[0][js].pov_mapping[pov_nr][0] = joystick_state[0][js].pov_mapping[pov_nr][1] = 0; @@ -2552,7 +2553,8 @@ save_input_devices(void) ini_section_set_string(cat, "mouse_type", mouse_get_internal_name(mouse_type)); - if (!joystick_type) { + uint8_t joy_insn = 0; + if (!joystick_type[joy_insn]) { ini_section_delete_var(cat, "joystick_type"); for (int js = 0; js < MAX_PLAT_JOYSTICKS; js++) { @@ -2573,22 +2575,22 @@ save_input_devices(void) } } } else { - ini_section_set_string(cat, "joystick_type", joystick_get_internal_name(joystick_type)); + 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); js++) { + 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[0][js].plat_joystick_nr); if (joystick_state[0][js].plat_joystick_nr) { - for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) { + 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[0][js].axis_mapping[axis_nr]); } - for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) { + 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[0][js].button_mapping[button_nr]); } - for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) { + 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[0][js].pov_mapping[pov_nr][0], joystick_state[0][js].pov_mapping[pov_nr][1]); diff --git a/src/game/gameport.c b/src/game/gameport.c index 45f34f1e1..f17e39efe 100644 --- a/src/game/gameport.c +++ b/src/game/gameport.c @@ -65,7 +65,7 @@ typedef struct _joystick_instance_ { void *dat; } joystick_instance_t; -int joystick_type = JS_TYPE_NONE; +int joystick_type[GAMEPORT_MAX] = { JS_TYPE_NONE, JS_TYPE_NONE }; static const joystick_t joystick_none = { .name = "None", @@ -299,17 +299,17 @@ timer_over(void *priv) } void -gameport_update_joystick_type(void) +gameport_update_joystick_type(uint8_t gp) { /* Add a standalone game port if a joystick is enabled but no other game ports exist. */ if (standalone_gameport_type) gameport_add(standalone_gameport_type); /* Reset the joystick interface. */ - if (joystick_instance[0]) { - joystick_instance[0]->intf->close(joystick_instance[0]->dat); - joystick_instance[0]->intf = joysticks[joystick_type].joystick; - joystick_instance[0]->dat = joystick_instance[0]->intf->init(); + if (joystick_instance[gp]) { + joystick_instance[gp]->intf->close(joystick_instance[gp]->dat); + joystick_instance[gp]->intf = joysticks[joystick_type[gp]].joystick; + joystick_instance[gp]->dat = joystick_instance[gp]->intf->init(); } } @@ -393,24 +393,27 @@ gameport_init(const device_t *info) { gameport_t *dev = calloc(1, sizeof(gameport_t)); + // TODO: Later we'll actually support more than one gameport + uint8_t joy_insn = 0; + /* Allocate global instance. */ - if (!joystick_instance[0] && joystick_type) { - joystick_instance[0] = calloc(1, sizeof(joystick_instance_t)); + if (!joystick_instance[joy_insn] && joystick_type[joy_insn]) { + joystick_instance[joy_insn] = calloc(1, sizeof(joystick_instance_t)); // For each analog joystick axis for (uint8_t i = 0; i < 4; i++) { - joystick_instance[0]->axis[i].joystick = joystick_instance[0]; + joystick_instance[joy_insn]->axis[i].joystick = joystick_instance[joy_insn]; - joystick_instance[0]->axis[i].axis_nr = i; + joystick_instance[joy_insn]->axis[i].axis_nr = i; - timer_add(&joystick_instance[0]->axis[i].timer, timer_over, &joystick_instance[0]->axis[i], 0); + timer_add(&joystick_instance[joy_insn]->axis[i].timer, timer_over, &joystick_instance[joy_insn]->axis[i], 0); } - joystick_instance[0]->intf = joysticks[joystick_type].joystick; - joystick_instance[0]->dat = joystick_instance[0]->intf->init(); + joystick_instance[joy_insn]->intf = joysticks[joystick_type[joy_insn]].joystick; + joystick_instance[joy_insn]->dat = joystick_instance[joy_insn]->intf->init(); } - dev->joystick = joystick_instance[0]; + dev->joystick = joystick_instance[joy_insn]; /* Map game port to the default address. Not applicable on PnP-only ports. */ dev->len = (info->local >> 16) & 0xff; @@ -475,15 +478,18 @@ gameport_close(void *priv) { gameport_t *dev = (gameport_t *) priv; + // TODO: Later we'll actually support more than one gameport + uint8_t joy_insn = 0; + /* If this port was active, remove it from the active ports list. */ gameport_remap(dev, 0); /* Free the global instance here, if it wasn't already freed. */ - if (joystick_instance[0]) { - joystick_instance[0]->intf->close(joystick_instance[0]->dat); + if (joystick_instance[joy_insn]) { + joystick_instance[joy_insn]->intf->close(joystick_instance[joy_insn]->dat); - free(joystick_instance[0]); - joystick_instance[0] = NULL; + free(joystick_instance[joy_insn]); + joystick_instance[joy_insn] = NULL; } free(dev); @@ -793,7 +799,7 @@ gameport_available(int port) /* UI */ const device_t * -gameport_getdevice(int port) +gameport_get_device(int port) { return (gameports[port].device); } diff --git a/src/include/86box/gameport.h b/src/include/86box/gameport.h index a990d018e..f9d7810e0 100644 --- a/src/include/86box/gameport.h +++ b/src/include/86box/gameport.h @@ -119,7 +119,7 @@ extern "C" { extern int gameport_available(int port); #ifdef EMU_DEVICE_H -extern const device_t *gameport_getdevice(int port); +extern const device_t *gameport_get_device(int port); #endif extern int gameport_has_config(int port); extern const char *gameport_get_internal_name(int port); @@ -151,11 +151,11 @@ extern plat_joystick_state_t plat_joystick_state[MAX_PLAT_JOYSTICKS]; extern joystick_state_t joystick_state[GAMEPORT_MAX][MAX_JOYSTICKS]; extern int joysticks_present; -extern int joystick_type; +extern int joystick_type[GAMEPORT_MAX]; extern void joystick_init(void); extern void joystick_close(void); -extern void joystick_process(void); +extern void joystick_process(uint8_t gp); extern const char *joystick_get_name(int js); extern const char *joystick_get_internal_name(int js); @@ -168,7 +168,7 @@ extern const char *joystick_get_axis_name(int js, int id); extern const char *joystick_get_button_name(int js, int id); extern const char *joystick_get_pov_name(int js, int id); -extern void gameport_update_joystick_type(void); +extern void gameport_update_joystick_type(uint8_t gp); extern void gameport_remap(void *priv, uint16_t address); extern void *gameport_add(const device_t *gameport_type); diff --git a/src/machine/m_europc.c b/src/machine/m_europc.c index 4f3a3b8ff..d85563241 100644 --- a/src/machine/m_europc.c +++ b/src/machine/m_europc.c @@ -625,7 +625,7 @@ europc_boot(UNUSED(const device_t *info)) mouse_bus_set_irq(sys->mouse, 2); /* Configure the port for (Bus Mouse Compatible) Mouse. */ b |= 0x01; - } else if (joystick_type) + } else if (joystick_type[0]) b |= 0x02; /* enable port as joysticks */ sys->nvr.regs[MRTC_CONF_C] = b; diff --git a/src/machine/m_xt_olivetti.c b/src/machine/m_xt_olivetti.c index ef10ab5dc..079cd4555 100644 --- a/src/machine/m_xt_olivetti.c +++ b/src/machine/m_xt_olivetti.c @@ -2397,7 +2397,7 @@ machine_xt_m240_init(const machine_t *model) if (fdc_current[0] == FDC_INTERNAL) device_add(&fdc_at_device); /* io.c logs clearly show it using port 3F7 */ - if (joystick_type) + if (joystick_type[0]) device_add(&gameport_200_device); nmi_init(); diff --git a/src/qt/qt_joystickconfiguration.cpp b/src/qt/qt_joystickconfiguration.cpp index 62a9302d1..2d8910f4a 100644 --- a/src/qt/qt_joystickconfiguration.cpp +++ b/src/qt/qt_joystickconfiguration.cpp @@ -27,10 +27,11 @@ extern "C" { #include #include "qt_models_common.hpp" -JoystickConfiguration::JoystickConfiguration(int type, int joystick_nr, QWidget *parent) +JoystickConfiguration::JoystickConfiguration(int type, uint8_t gameport_nr, int joystick_nr, QWidget *parent) : QDialog(parent) , ui(new Ui::JoystickConfiguration) , type(type) + , gameport_nr(gameport_nr) , joystick_nr(joystick_nr) { ui->setupUi(this); @@ -41,7 +42,7 @@ JoystickConfiguration::JoystickConfiguration(int type, int joystick_nr, QWidget Models::AddEntry(model, plat_joystick_state[c].name, c + 1); } - ui->comboBoxDevice->setCurrentIndex(joystick_state[0][joystick_nr].plat_joystick_nr); + ui->comboBoxDevice->setCurrentIndex(joystick_state[gameport_nr][joystick_nr].plat_joystick_nr); layout()->setSizeConstraint(QLayout::SetFixedSize); } @@ -119,7 +120,7 @@ JoystickConfiguration::on_comboBoxDevice_currentIndexChanged(int index) } int nr_axes = plat_joystick_state[joystick].nr_axes; - int mapping = joystick_state[0][joystick_nr].axis_mapping[c]; + int mapping = joystick_state[gameport_nr][joystick_nr].axis_mapping[c]; if (mapping & POV_X) cbox->setCurrentIndex(nr_axes + (mapping & 3) * 2); else if (mapping & POV_Y) @@ -147,7 +148,7 @@ JoystickConfiguration::on_comboBoxDevice_currentIndexChanged(int index) Models::AddEntry(model, plat_joystick_state[joystick].button[d].name, 0); } - cbox->setCurrentIndex(joystick_state[0][joystick_nr].button_mapping[c]); + cbox->setCurrentIndex(joystick_state[gameport_nr][joystick_nr].button_mapping[c]); ui->ct->addWidget(label, row, 0); ui->ct->addWidget(cbox, row, 1); @@ -179,7 +180,7 @@ JoystickConfiguration::on_comboBoxDevice_currentIndexChanged(int index) Models::AddEntry(model, plat_joystick_state[joystick].axis[d].name, 0); } - int mapping = joystick_state[0][joystick_nr].pov_mapping[c / 2][c & 1]; + int mapping = joystick_state[gameport_nr][joystick_nr].pov_mapping[c / 2][c & 1]; int nr_povs = plat_joystick_state[joystick].nr_povs; if (mapping & POV_X) cbox->setCurrentIndex((mapping & 3) * 2); diff --git a/src/qt/qt_joystickconfiguration.hpp b/src/qt/qt_joystickconfiguration.hpp index 0b185ad73..bff38992a 100644 --- a/src/qt/qt_joystickconfiguration.hpp +++ b/src/qt/qt_joystickconfiguration.hpp @@ -11,7 +11,7 @@ class JoystickConfiguration : public QDialog { Q_OBJECT public: - explicit JoystickConfiguration(int type, int joystick_nr, QWidget *parent = nullptr); + explicit JoystickConfiguration(int type, uint8_t gameport_nr, int joystick_nr, QWidget *parent = nullptr); ~JoystickConfiguration(); int selectedDevice(); @@ -25,6 +25,7 @@ private: Ui::JoystickConfiguration *ui; QList widgets; int type; + int gameport_nr; int joystick_nr; }; diff --git a/src/qt/qt_settingsinput.cpp b/src/qt/qt_settingsinput.cpp index d8cc7c029..50e3662e9 100644 --- a/src/qt/qt_settingsinput.cpp +++ b/src/qt/qt_settingsinput.cpp @@ -8,8 +8,6 @@ * * Mouse/Joystick configuration UI module. * - * - * * Authors: Joakim L. Gilje * * Copyright 2021 Joakim L. Gilje @@ -95,7 +93,7 @@ SettingsInput::save() keyboard_type = ui->comboBoxKeyboard->currentData().toInt(); mouse_type = ui->comboBoxMouse->currentData().toInt(); - joystick_type = ui->comboBoxJoystick->currentData().toInt(); + joystick_type[0] = ui->comboBoxJoystick0->currentData().toInt(); // Copy accelerators from working set to global set for(int x = 0; x < NUM_ACCELS; x++) { @@ -179,21 +177,22 @@ SettingsInput::onCurrentMachineChanged(int machineId) ui->comboBoxMouse->setCurrentIndex(-1); ui->comboBoxMouse->setCurrentIndex(selectedRow); + // Joysticks int i = 0; const char *joyName = joystick_get_name(i); - auto *joystickModel = ui->comboBoxJoystick->model(); + auto *joystickModel = ui->comboBoxJoystick0->model(); removeRows = joystickModel->rowCount(); selectedRow = 0; while (joyName) { int row = Models::AddEntry(joystickModel, tr(joyName).toUtf8().data(), i); - if (i == joystick_type) + if (i == joystick_type[0]) selectedRow = row - removeRows; ++i; joyName = joystick_get_name(i); } joystickModel->removeRows(0, removeRows); - ui->comboBoxJoystick->setCurrentIndex(selectedRow); + ui->comboBoxJoystick0->setCurrentIndex(selectedRow); } void @@ -309,11 +308,11 @@ SettingsInput::on_comboBoxMouse_currentIndexChanged(int index) } void -SettingsInput::on_comboBoxJoystick_currentIndexChanged(int index) +SettingsInput::on_comboBoxJoystick0_currentIndexChanged(int index) { - int joystickId = ui->comboBoxJoystick->currentData().toInt(); + int joystickId = ui->comboBoxJoystick0->currentData().toInt(); for (int i = 0; i < MAX_JOYSTICKS; ++i) { - auto *btn = findChild(QString("pushButtonJoystick%1").arg(i + 1)); + auto *btn = findChild(QString("pushButtonJoystick0%1").arg(i + 1)); if (btn == nullptr) continue; @@ -336,10 +335,10 @@ SettingsInput::on_pushButtonConfigureMouse_clicked() } static int -get_axis(JoystickConfiguration &jc, int axis, int joystick_nr) +get_axis(JoystickConfiguration &jc, int axis, uint8_t gameport_nr, int joystick_nr) { int axis_sel = jc.selectedAxis(axis); - int nr_axes = plat_joystick_state[joystick_state[0][joystick_nr].plat_joystick_nr - 1].nr_axes; + int nr_axes = plat_joystick_state[joystick_state[gameport_nr][joystick_nr].plat_joystick_nr - 1].nr_axes; if (axis_sel < nr_axes) return axis_sel; @@ -352,10 +351,10 @@ get_axis(JoystickConfiguration &jc, int axis, int joystick_nr) } static int -get_pov(JoystickConfiguration &jc, int pov, int joystick_nr) +get_pov(JoystickConfiguration &jc, int pov, uint8_t gameport_nr, int joystick_nr) { int pov_sel = jc.selectedPov(pov); - int nr_povs = plat_joystick_state[joystick_state[0][joystick_nr].plat_joystick_nr - 1].nr_povs * 2; + int nr_povs = plat_joystick_state[joystick_state[gameport_nr][joystick_nr].plat_joystick_nr - 1].nr_povs * 2; if (pov_sel < nr_povs) { if (pov_sel & 1) @@ -368,9 +367,9 @@ get_pov(JoystickConfiguration &jc, int pov, int joystick_nr) } static void -updateJoystickConfig(int type, int joystick_nr, QWidget *parent) +updateJoystickConfig(int type, uint8_t gameport_nr, int joystick_nr, QWidget *parent) { - JoystickConfiguration jc(type, joystick_nr, parent); + JoystickConfiguration jc(type, gameport_nr, joystick_nr, parent); switch (jc.exec()) { case QDialog::Rejected: return; @@ -378,43 +377,43 @@ updateJoystickConfig(int type, int joystick_nr, QWidget *parent) break; } - joystick_state[0][joystick_nr].plat_joystick_nr = jc.selectedDevice(); - if (joystick_state[0][joystick_nr].plat_joystick_nr) { + 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[0][joystick_nr].axis_mapping[axis_nr] = get_axis(jc, axis_nr, joystick_nr); + joystick_state[gameport_nr][joystick_nr].axis_mapping[axis_nr] = get_axis(jc, axis_nr, gameport_nr, joystick_nr); } for (int button_nr = 0; button_nr < joystick_get_button_count(type); button_nr++) { - joystick_state[0][joystick_nr].button_mapping[button_nr] = jc.selectedButton(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[0][joystick_nr].pov_mapping[pov_nr][0] = get_pov(jc, pov_nr, joystick_nr); - joystick_state[0][joystick_nr].pov_mapping[pov_nr][1] = get_pov(jc, pov_nr + 1, joystick_nr); + 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); } } } void -SettingsInput::on_pushButtonJoystick1_clicked() +SettingsInput::on_pushButtonJoystick01_clicked() { - updateJoystickConfig(ui->comboBoxJoystick->currentData().toInt(), 0, this); + updateJoystickConfig(ui->comboBoxJoystick0->currentData().toInt(), 0, 0, this); } void -SettingsInput::on_pushButtonJoystick2_clicked() +SettingsInput::on_pushButtonJoystick02_clicked() { - updateJoystickConfig(ui->comboBoxJoystick->currentData().toInt(), 1, this); + updateJoystickConfig(ui->comboBoxJoystick0->currentData().toInt(), 0, 1, this); } void -SettingsInput::on_pushButtonJoystick3_clicked() +SettingsInput::on_pushButtonJoystick03_clicked() { - updateJoystickConfig(ui->comboBoxJoystick->currentData().toInt(), 2, this); + updateJoystickConfig(ui->comboBoxJoystick0->currentData().toInt(), 0, 2, this); } void -SettingsInput::on_pushButtonJoystick4_clicked() +SettingsInput::on_pushButtonJoystick04_clicked() { - updateJoystickConfig(ui->comboBoxJoystick->currentData().toInt(), 3, this); + updateJoystickConfig(ui->comboBoxJoystick0->currentData().toInt(), 0, 3, this); } diff --git a/src/qt/qt_settingsinput.hpp b/src/qt/qt_settingsinput.hpp index 9a7702b4b..d5e8d58e1 100644 --- a/src/qt/qt_settingsinput.hpp +++ b/src/qt/qt_settingsinput.hpp @@ -32,11 +32,11 @@ private slots: void on_comboBoxMouse_currentIndexChanged(int index); void on_pushButtonConfigureMouse_clicked(); - void on_comboBoxJoystick_currentIndexChanged(int index); - void on_pushButtonJoystick1_clicked(); - void on_pushButtonJoystick2_clicked(); - void on_pushButtonJoystick3_clicked(); - void on_pushButtonJoystick4_clicked(); + void on_comboBoxJoystick0_currentIndexChanged(int index); + void on_pushButtonJoystick01_clicked(); + void on_pushButtonJoystick02_clicked(); + void on_pushButtonJoystick03_clicked(); + void on_pushButtonJoystick04_clicked(); void on_tableKeys_cellDoubleClicked(int row, int col); void on_tableKeys_currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn); diff --git a/src/qt/qt_settingsinput.ui b/src/qt/qt_settingsinput.ui index 8436c3a9d..02b3e388c 100644 --- a/src/qt/qt_settingsinput.ui +++ b/src/qt/qt_settingsinput.ui @@ -90,42 +90,42 @@ - + Joystick: - + 30 - + Joystick 1... - + Joystick 2... - + Joystick 3... - + Joystick 4... diff --git a/src/qt/sdl_joystick.c b/src/qt/sdl_joystick.c index 75234bca3..f1ba0380f 100644 --- a/src/qt/sdl_joystick.c +++ b/src/qt/sdl_joystick.c @@ -91,7 +91,7 @@ joystick_close(void) } static int -joystick_get_axis(int gameport, int joystick_nr, int mapping) +joystick_get_axis(int joystick_nr, int mapping) { if (mapping & POV_X) { switch (plat_joystick_state[joystick_nr].p[mapping & 3]) { @@ -128,9 +128,9 @@ joystick_get_axis(int gameport, int joystick_nr, int mapping) } void -joystick_process(void) +joystick_process(uint8_t gp) { - if (!joystick_type) + if (!joystick_type[gp]) return; SDL_JoystickUpdate(); @@ -146,44 +146,44 @@ joystick_process(void) #if 0 pclog("joystick %i - x=%i y=%i b[0]=%i b[1]=%i %i\n", js, - joystick_state[0][js].x, - joystick_state[0][js].y, - joystick_state[0][js].b[0], - joystick_state[0][js].b[1], - joysticks_present); + joystick_state[gp][js].x, + joystick_state[gp][js].y, + joystick_state[gp][js].b[0], + joystick_state[gp][js].b[1], + joysticks_present[gp]); #endif } - for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) { - if (joystick_state[0][js].plat_joystick_nr) { - int joystick_nr = joystick_state[0][js].plat_joystick_nr - 1; + for (int js = 0; js < joystick_get_max_joysticks(joystick_type[gp]); js++) { + if (joystick_state[gp][js].plat_joystick_nr) { + int joystick_nr = joystick_state[gp][js].plat_joystick_nr - 1; - for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) - joystick_state[0][js].axis[axis_nr] = joystick_get_axis(0, joystick_nr, joystick_state[0][js].axis_mapping[axis_nr]); + for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type[gp]); axis_nr++) + joystick_state[gp][js].axis[axis_nr] = joystick_get_axis(joystick_nr, joystick_state[gp][js].axis_mapping[axis_nr]); - for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) - joystick_state[0][js].button[button_nr] = plat_joystick_state[joystick_nr].b[joystick_state[0][js].button_mapping[button_nr]]; + for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type[gp]); button_nr++) + joystick_state[gp][js].button[button_nr] = plat_joystick_state[joystick_nr].b[joystick_state[gp][js].button_mapping[button_nr]]; - for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) { - int x = joystick_get_axis(0, joystick_nr, joystick_state[0][js].pov_mapping[pov_nr][0]); - int y = joystick_get_axis(0, joystick_nr, joystick_state[0][js].pov_mapping[pov_nr][1]); + for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type[gp]); pov_nr++) { + int x = joystick_get_axis(joystick_nr, joystick_state[gp][js].pov_mapping[pov_nr][0]); + int y = joystick_get_axis(joystick_nr, joystick_state[gp][js].pov_mapping[pov_nr][1]); double angle = (atan2((double) y, (double) x) * 360.0) / (2 * M_PI); double magnitude = sqrt((double) x * (double) x + (double) y * (double) y); if (magnitude < 16384) - joystick_state[0][js].pov[pov_nr] = -1; + joystick_state[gp][js].pov[pov_nr] = -1; else - joystick_state[0][js].pov[pov_nr] = ((int) angle + 90 + 360) % 360; + joystick_state[gp][js].pov[pov_nr] = ((int) angle + 90 + 360) % 360; } } else { - for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) - joystick_state[0][js].axis[axis_nr] = 0; + for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type[gp]); axis_nr++) + joystick_state[gp][js].axis[axis_nr] = 0; - for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) - joystick_state[0][js].button[button_nr] = 0; + for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type[gp]); button_nr++) + joystick_state[gp][js].button[button_nr] = 0; - for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) - joystick_state[0][js].pov[pov_nr] = -1; + for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type[gp]); pov_nr++) + joystick_state[gp][js].pov[pov_nr] = -1; } } } diff --git a/src/qt/win_joystick_rawinput.c b/src/qt/win_joystick_rawinput.c index c775b4bb3..24ad87f63 100644 --- a/src/qt/win_joystick_rawinput.c +++ b/src/qt/win_joystick_rawinput.c @@ -454,7 +454,7 @@ win_joystick_handle(PRAWINPUT raw) plat_joystick_state[j].a[axis_nr] = value; #if 0 - joystick_log("%s %-06d ", plat_joystick_state[0][j].axis[axis_nr].name, plat_joystick_state[j].a[axis_nr]); + joystick_log("%s %-06d ", plat_joystick_state[j].axis[axis_nr].name, plat_joystick_state[j].a[axis_nr]); #endif } @@ -476,7 +476,7 @@ win_joystick_handle(PRAWINPUT raw) plat_joystick_state[j].p[pov_nr] = value; #if 0 - joystick_log("%s %-3d ", plat_joystick_state[0][j].pov[pov_nr].name, plat_joystick_state[j].p[pov_nr]); + joystick_log("%s %-3d ", plat_joystick_state[j].pov[pov_nr].name, plat_joystick_state[j].p[pov_nr]); #endif } #if 0 @@ -505,41 +505,41 @@ joystick_get_axis(int joystick_nr, int mapping) } void -joystick_process(void) +joystick_process(uint8_t gp) { - if (joystick_type == JS_TYPE_NONE) + if (joystick_type[gp] == JS_TYPE_NONE) return; - for (int js = 0; js < joystick_get_max_joysticks(joystick_type); js++) { - if (joystick_state[0][js].plat_joystick_nr) { - int joystick_nr = joystick_state[0][js].plat_joystick_nr - 1; + for (int js = 0; js < joystick_get_max_joysticks(joystick_type[gp]); js++) { + if (joystick_state[gp][js].plat_joystick_nr) { + int joystick_nr = joystick_state[gp][js].plat_joystick_nr - 1; - for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) - joystick_state[0][js].axis[axis_nr] = joystick_get_axis(joystick_nr, joystick_state[0][js].axis_mapping[axis_nr]); + for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type[gp]); axis_nr++) + joystick_state[gp][js].axis[axis_nr] = joystick_get_axis(joystick_nr, joystick_state[gp][js].axis_mapping[axis_nr]); - for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) - joystick_state[0][js].button[button_nr] = plat_joystick_state[joystick_nr].b[joystick_state[0][js].button_mapping[button_nr]]; + for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type[gp]); button_nr++) + joystick_state[gp][js].button[button_nr] = plat_joystick_state[joystick_nr].b[joystick_state[gp][js].button_mapping[button_nr]]; - for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) { - int x = joystick_get_axis(joystick_nr, joystick_state[0][js].pov_mapping[pov_nr][0]); - int y = joystick_get_axis(joystick_nr, joystick_state[0][js].pov_mapping[pov_nr][1]); + for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type[gp]); pov_nr++) { + int x = joystick_get_axis(joystick_nr, joystick_state[gp][js].pov_mapping[pov_nr][0]); + int y = joystick_get_axis(joystick_nr, joystick_state[gp][js].pov_mapping[pov_nr][1]); double angle = (atan2((double) y, (double) x) * 360.0) / (2 * M_PI); double magnitude = sqrt((double) x * (double) x + (double) y * (double) y); if (magnitude < 16384) - joystick_state[0][js].pov[pov_nr] = -1; + joystick_state[gp][js].pov[pov_nr] = -1; else - joystick_state[0][js].pov[pov_nr] = ((int) angle + 90 + 360) % 360; + joystick_state[gp][js].pov[pov_nr] = ((int) angle + 90 + 360) % 360; } } else { - for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type); axis_nr++) - joystick_state[0][js].axis[axis_nr] = 0; + for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type[gp]); axis_nr++) + joystick_state[gp][js].axis[axis_nr] = 0; - for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type); button_nr++) - joystick_state[0][js].button[button_nr] = 0; + for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type[gp]); button_nr++) + joystick_state[gp][js].button[button_nr] = 0; - for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type); pov_nr++) - joystick_state[0][js].pov[pov_nr] = -1; + for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type[gp]); pov_nr++) + joystick_state[gp][js].pov[pov_nr] = -1; } } } diff --git a/src/unix/unix.c b/src/unix/unix.c index d35543548..bc9b9fedf 100644 --- a/src/unix/unix.c +++ b/src/unix/unix.c @@ -1484,7 +1484,7 @@ joystick_close(void) } void -joystick_process(void) +joystick_process(uint8_t gp) { /* No-op. */ }