From 373fe0f258a726bf616961a47e3b2e76da031aa0 Mon Sep 17 00:00:00 2001 From: cold-brewed <47337035+cold-brewed@users.noreply.github.com> Date: Sun, 24 Mar 2024 12:07:58 -0400 Subject: [PATCH] qt: Disable bus channels that are currently in use --- src/qt/qt_harddiskdialog.cpp | 2 +- src/qt/qt_harddrive_common.cpp | 24 +++++++++++++++++- src/qt/qt_harddrive_common.hpp | 3 ++- src/qt/qt_settings.cpp | 4 +++ src/qt/qt_settings_bus_tracking.cpp | 39 +++++++++++++++++++++++++++++ src/qt/qt_settings_bus_tracking.hpp | 2 ++ src/qt/qt_settingsfloppycdrom.cpp | 22 +++++++++++++++- src/qt/qt_settingsfloppycdrom.hpp | 4 +++ src/qt/qt_settingsharddisks.cpp | 26 ++++++++++++++++++- src/qt/qt_settingsharddisks.hpp | 5 ++++ 10 files changed, 126 insertions(+), 5 deletions(-) diff --git a/src/qt/qt_harddiskdialog.cpp b/src/qt/qt_harddiskdialog.cpp index 5efd895dc..df10a6d38 100644 --- a/src/qt/qt_harddiskdialog.cpp +++ b/src/qt/qt_harddiskdialog.cpp @@ -746,7 +746,7 @@ HarddiskDialog::on_comboBoxBus_currentIndexChanged(int index) ui->lineEditHeads->setValidator(new QIntValidator(1, max_heads, this)); ui->lineEditSectors->setValidator(new QIntValidator(1, max_sectors, this)); - Harddrives::populateBusChannels(ui->comboBoxChannel->model(), ui->comboBoxBus->currentData().toInt()); + Harddrives::populateBusChannels(ui->comboBoxChannel->model(), ui->comboBoxBus->currentData().toInt(), Harddrives::busTrackClass); Harddrives::populateSpeeds(ui->comboBoxSpeed->model(), ui->comboBoxBus->currentData().toInt()); switch (ui->comboBoxBus->currentData().toInt()) { diff --git a/src/qt/qt_harddrive_common.cpp b/src/qt/qt_harddrive_common.cpp index dda36917f..213ebf07b 100644 --- a/src/qt/qt_harddrive_common.cpp +++ b/src/qt/qt_harddrive_common.cpp @@ -24,6 +24,7 @@ extern "C" { } #include +#include void Harddrives::populateBuses(QAbstractItemModel *model) @@ -96,7 +97,7 @@ Harddrives::populateSpeeds(QAbstractItemModel *model, int bus) } void -Harddrives::populateBusChannels(QAbstractItemModel *model, int bus) +Harddrives::populateBusChannels(QAbstractItemModel *model, int bus, SettingsBusTracking *sbt) { model->removeRows(0, model->rowCount()); @@ -104,6 +105,8 @@ Harddrives::populateBusChannels(QAbstractItemModel *model, int bus) int shifter = 1; int orer = 1; int subChannelWidth = 1; + QList busesToCheck; + QList channelsInUse; switch (bus) { case HDD_BUS_MFM: case HDD_BUS_XTA: @@ -111,15 +114,29 @@ Harddrives::populateBusChannels(QAbstractItemModel *model, int bus) busRows = 2; break; case HDD_BUS_IDE: + busRows = 8; + busesToCheck.append(HDD_BUS_ATAPI); + busesToCheck.append(HDD_BUS_IDE); + break; case HDD_BUS_ATAPI: busRows = 8; + busesToCheck.append(HDD_BUS_IDE); + busesToCheck.append(HDD_BUS_ATAPI); break; case HDD_BUS_SCSI: shifter = 4; orer = 15; busRows = 64; subChannelWidth = 2; + busesToCheck.append(HDD_BUS_SCSI); break; + default: + break; + } + if(sbt != nullptr && !busesToCheck.empty()) { + for (auto const &checkBus : busesToCheck) { + channelsInUse.append(sbt->busChannelsInUse(checkBus)); + } } model->insertRows(0, busRows); @@ -127,6 +144,11 @@ Harddrives::populateBusChannels(QAbstractItemModel *model, int bus) auto idx = model->index(i, 0); model->setData(idx, QString("%1:%2").arg(i >> shifter).arg(i & orer, subChannelWidth, 10, QChar('0'))); model->setData(idx, ((i >> shifter) << shifter) | (i & orer), Qt::UserRole); + const auto *channelModel = qobject_cast(model); + auto *channelItem = channelModel->item(i); + if(channelItem) { + channelItem->setEnabled(!channelsInUse.contains(i)); + } } } diff --git a/src/qt/qt_harddrive_common.hpp b/src/qt/qt_harddrive_common.hpp index 2aca184b3..28189f328 100644 --- a/src/qt/qt_harddrive_common.hpp +++ b/src/qt/qt_harddrive_common.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include "qt_settings_bus_tracking.hpp" class QString; class QAbstractItemModel; @@ -9,7 +10,7 @@ class SettingsBusTracking; namespace Harddrives { void populateBuses(QAbstractItemModel *model); void populateRemovableBuses(QAbstractItemModel *model); -void populateBusChannels(QAbstractItemModel *model, int bus); +void populateBusChannels(QAbstractItemModel *model, int bus, SettingsBusTracking *sbt = nullptr); void populateSpeeds(QAbstractItemModel *model, int bus); QString BusChannelName(uint8_t bus, uint8_t channel); inline SettingsBusTracking *busTrackClass = nullptr; diff --git a/src/qt/qt_settings.cpp b/src/qt/qt_settings.cpp index c7cb99086..a7e52c342 100644 --- a/src/qt/qt_settings.cpp +++ b/src/qt/qt_settings.cpp @@ -153,6 +153,10 @@ Settings::Settings(QWidget *parent) &SettingsStorageControllers::onCurrentMachineChanged); connect(machine, &SettingsMachine::currentMachineChanged, otherPeripherals, &SettingsOtherPeripherals::onCurrentMachineChanged); + connect(floppyCdrom, &SettingsFloppyCDROM::cdromChannelChanged, harddisks, + &SettingsHarddisks::reloadBusChannels); + connect(harddisks, &SettingsHarddisks::driveChannelChanged, floppyCdrom, + &SettingsFloppyCDROM::reloadBusChannels); connect(ui->listView->selectionModel(), &QItemSelectionModel::currentChanged, this, [this](const QModelIndex ¤t, const QModelIndex &previous) { diff --git a/src/qt/qt_settings_bus_tracking.cpp b/src/qt/qt_settings_bus_tracking.cpp index 4fe112627..064fbe0b4 100644 --- a/src/qt/qt_settings_bus_tracking.cpp +++ b/src/qt/qt_settings_bus_tracking.cpp @@ -198,6 +198,45 @@ SettingsBusTracking::scsi_bus_full() return (count == 64); } +QList SettingsBusTracking::busChannelsInUse(const int bus) { + + QList channelsInUse; + int element; + uint64_t mask; + switch (bus) { + case HDD_BUS_IDE: + for (uint8_t i = 0; i < 32; i++) { + element = ((i << 3) >> 6); + mask = ((uint64_t) DEV_HDD) << ((uint64_t) ((i << 3) & 0x3f)); + if (ide_tracking[element] & mask) { + channelsInUse.append(i); + } + } + break; + case HDD_BUS_ATAPI: + for (uint8_t i = 0; i < 32; i++) { + element = ((i << 3) >> 6); + mask = ((uint64_t) DEV_CDROM) << ((uint64_t) ((i << 3) & 0x3f)); + if (ide_tracking[element] & mask) { + channelsInUse.append(i); + } + } + break; + case HDD_BUS_SCSI: + for (uint8_t i = 0; i < 64; i++) { + element = ((i << 3) >> 6); + mask = 0xffULL << ((uint64_t) ((i << 3) & 0x3f)); + if (scsi_tracking[element] & mask) + channelsInUse.append(i); + } + break; + default: + break; + } + + return channelsInUse; +} + void SettingsBusTracking::device_track(int set, uint8_t dev_type, int bus, int channel) { diff --git a/src/qt/qt_settings_bus_tracking.hpp b/src/qt/qt_settings_bus_tracking.hpp index 3ec61dfb7..279d3247e 100644 --- a/src/qt/qt_settings_bus_tracking.hpp +++ b/src/qt/qt_settings_bus_tracking.hpp @@ -28,6 +28,8 @@ public: explicit SettingsBusTracking(); ~SettingsBusTracking() = default; + QList busChannelsInUse(int bus); + /* These return 0xff is none is free. */ uint8_t next_free_mfm_channel(); uint8_t next_free_esdi_channel(); diff --git a/src/qt/qt_settingsfloppycdrom.cpp b/src/qt/qt_settingsfloppycdrom.cpp index 988f9e856..bb536e603 100644 --- a/src/qt/qt_settingsfloppycdrom.cpp +++ b/src/qt/qt_settingsfloppycdrom.cpp @@ -263,6 +263,7 @@ SettingsFloppyCDROM::onCDROMRowChanged(const QModelIndex ¤t) ui->comboBoxSpeed->setCurrentIndex(speed == 0 ? 7 : speed - 1); ui->comboBoxCDROMType->setCurrentIndex(type); + enableCurrentlySelectedChannel(); } void @@ -288,6 +289,13 @@ SettingsFloppyCDROM::on_comboBoxFloppyType_activated(int index) ui->tableViewFloppy->selectionModel()->currentIndex(), index); } +void SettingsFloppyCDROM::reloadBusChannels() { + auto selected = ui->comboBoxChannel->currentIndex(); + Harddrives::populateBusChannels(ui->comboBoxChannel->model(), ui->comboBoxBus->currentData().toInt(), Harddrives::busTrackClass); + ui->comboBoxChannel->setCurrentIndex(selected); + enableCurrentlySelectedChannel(); +} + void SettingsFloppyCDROM::on_comboBoxBus_currentIndexChanged(int index) { @@ -298,7 +306,7 @@ SettingsFloppyCDROM::on_comboBoxBus_currentIndexChanged(int index) ui->comboBoxSpeed->setEnabled((bus == CDROM_BUS_MITSUMI) ? 0 : enabled); ui->comboBoxCDROMType->setEnabled((bus == CDROM_BUS_MITSUMI) ? 0 : enabled); - Harddrives::populateBusChannels(ui->comboBoxChannel->model(), bus); + Harddrives::populateBusChannels(ui->comboBoxChannel->model(), bus, Harddrives::busTrackClass); } } @@ -362,6 +370,17 @@ SettingsFloppyCDROM::on_comboBoxBus_activated(int) ui->comboBoxCDROMType->currentData().toUInt()); } +void +SettingsFloppyCDROM::enableCurrentlySelectedChannel() +{ + const auto *item_model = qobject_cast(ui->comboBoxChannel->model()); + const auto index = ui->comboBoxChannel->currentIndex(); + auto *item = item_model->item(index); + if(item) { + item->setEnabled(true); + } +} + void SettingsFloppyCDROM::on_comboBoxChannel_activated(int) { @@ -376,6 +395,7 @@ SettingsFloppyCDROM::on_comboBoxChannel_activated(int) Harddrives::busTrackClass->device_track(1, DEV_CDROM, ui->tableViewCDROM->model()->data(i, Qt::UserRole).toInt(), ui->tableViewCDROM->model()->data(i, Qt::UserRole + 1).toInt()); + emit cdromChannelChanged(); } void diff --git a/src/qt/qt_settingsfloppycdrom.hpp b/src/qt/qt_settingsfloppycdrom.hpp index 3d6dd0e45..0a3424216 100644 --- a/src/qt/qt_settingsfloppycdrom.hpp +++ b/src/qt/qt_settingsfloppycdrom.hpp @@ -13,9 +13,12 @@ class SettingsFloppyCDROM : public QWidget { public: explicit SettingsFloppyCDROM(QWidget *parent = nullptr); ~SettingsFloppyCDROM(); + void reloadBusChannels(); void save(); +signals: + void cdromChannelChanged(); private slots: void on_comboBoxCDROMType_activated(int index); void on_comboBoxChannel_activated(int index); @@ -30,6 +33,7 @@ private slots: private: Ui::SettingsFloppyCDROM *ui; + void enableCurrentlySelectedChannel(); }; #endif // QT_SETTINGSFLOPPYCDROM_HPP diff --git a/src/qt/qt_settingsharddisks.cpp b/src/qt/qt_settingsharddisks.cpp index a66203406..3f02ffe54 100644 --- a/src/qt/qt_settingsharddisks.cpp +++ b/src/qt/qt_settingsharddisks.cpp @@ -166,6 +166,13 @@ SettingsHarddisks::save() } } +void SettingsHarddisks::reloadBusChannels() { + const auto selected = ui->comboBoxChannel->currentIndex(); + Harddrives::populateBusChannels(ui->comboBoxChannel->model(), ui->comboBoxBus->currentData().toInt(), Harddrives::busTrackClass); + ui->comboBoxChannel->setCurrentIndex(selected); + enableCurrentlySelectedChannel(); +} + void SettingsHarddisks::on_comboBoxBus_currentIndexChanged(int index) { @@ -184,7 +191,7 @@ SettingsHarddisks::on_comboBoxBus_currentIndexChanged(int index) model->setData(col, ui->comboBoxBus->currentData(Qt::UserRole), DataBusPrevious); } - Harddrives::populateBusChannels(ui->comboBoxChannel->model(), ui->comboBoxBus->currentData().toInt()); + Harddrives::populateBusChannels(ui->comboBoxChannel->model(), ui->comboBoxBus->currentData().toInt(), Harddrives::busTrackClass); Harddrives::populateSpeeds(ui->comboBoxSpeed->model(), ui->comboBoxBus->currentData().toInt()); int chanIdx = 0; @@ -233,6 +240,18 @@ SettingsHarddisks::on_comboBoxChannel_currentIndexChanged(int index) Harddrives::busTrackClass->device_track(0, DEV_HDD, model->data(col, DataBus).toInt(), model->data(col, DataBusChannelPrevious).toUInt()); Harddrives::busTrackClass->device_track(1, DEV_HDD, model->data(col, DataBus).toInt(), model->data(col, DataBusChannel).toUInt()); model->setData(col, ui->comboBoxChannel->currentData(Qt::UserRole), DataBusChannelPrevious); + emit driveChannelChanged(); + } +} + +void +SettingsHarddisks::enableCurrentlySelectedChannel() +{ + const auto *item_model = qobject_cast(ui->comboBoxChannel->model()); + const auto index = ui->comboBoxChannel->currentIndex(); + auto *item = item_model->item(index); + if(item) { + item->setEnabled(true); } } @@ -283,6 +302,7 @@ SettingsHarddisks::onTableRowChanged(const QModelIndex ¤t) if (!match.isEmpty()) { ui->comboBoxSpeed->setCurrentIndex(match.first().row()); } + reloadBusChannels(); } static void @@ -317,6 +337,7 @@ SettingsHarddisks::on_pushButtonNew_clicked() switch (dialog.exec()) { case QDialog::Accepted: addDriveFromDialog(ui, dialog); + reloadBusChannels(); break; } } @@ -328,6 +349,7 @@ SettingsHarddisks::on_pushButtonExisting_clicked() switch (dialog.exec()) { case QDialog::Accepted: addDriveFromDialog(ui, dialog); + reloadBusChannels(); break; } } @@ -341,6 +363,8 @@ SettingsHarddisks::on_pushButtonRemove_clicked() } auto *model = ui->tableView->model(); + const auto col = idx.siblingAtColumn(ColumnBus); + Harddrives::busTrackClass->device_track(0, DEV_HDD, model->data(col, DataBus).toInt(), model->data(col, DataBusChannel).toInt()); model->removeRow(idx.row()); ui->pushButtonNew->setEnabled(true); ui->pushButtonExisting->setEnabled(true); diff --git a/src/qt/qt_settingsharddisks.hpp b/src/qt/qt_settingsharddisks.hpp index 68d7ca3d6..4bd287d29 100644 --- a/src/qt/qt_settingsharddisks.hpp +++ b/src/qt/qt_settingsharddisks.hpp @@ -13,9 +13,13 @@ class SettingsHarddisks : public QWidget { public: explicit SettingsHarddisks(QWidget *parent = nullptr); ~SettingsHarddisks(); + void reloadBusChannels(); void save(); +signals: + void driveChannelChanged(); + private slots: void on_comboBoxChannel_currentIndexChanged(int index); void on_comboBoxSpeed_currentIndexChanged(int index); @@ -30,6 +34,7 @@ private slots: private: Ui::SettingsHarddisks *ui; + void enableCurrentlySelectedChannel(); bool buschangeinprogress = false; };