From 61ab0e60ca3c1ccb27ae13bc74d95770abdb019c Mon Sep 17 00:00:00 2001 From: "Joakim L. Gilje" Date: Tue, 14 Dec 2021 13:53:56 +0100 Subject: [PATCH] merged in machine flags/bus refactoring started in 6661ff5dcc33bc0cdb199d0b167087e6575e5cee --- src/qt/qt_machinestatus.cpp | 16 ++++----- src/qt/qt_machinestatus.hpp | 1 - src/qt/qt_mediamenu.cpp | 2 +- src/qt/qt_settingsdisplay.cpp | 9 +++--- src/qt/qt_settingsinput.cpp | 4 +-- src/qt/qt_settingsmachine.cpp | 41 +++++++++++++++--------- src/qt/qt_settingsnetwork.cpp | 2 +- src/qt/qt_settingssound.cpp | 18 +++++++---- src/qt/qt_settingsstoragecontrollers.cpp | 8 ++--- 9 files changed, 54 insertions(+), 47 deletions(-) diff --git a/src/qt/qt_machinestatus.cpp b/src/qt/qt_machinestatus.cpp index b0644c0f3..a2b44b36e 100644 --- a/src/qt/qt_machinestatus.cpp +++ b/src/qt/qt_machinestatus.cpp @@ -218,16 +218,12 @@ bool MachineStatus::hasCassette() { return cassette_enable > 0 ? true : false; } -bool MachineStatus::hasCartridge() { - return machines[machine].flags & MACHINE_CARTRIDGE; -} - bool MachineStatus::hasIDE() { - return machines[machine].flags & MACHINE_IDE_QUAD; + return machine_has_flags(machine, MACHINE_IDE_QUAD) > 0; } bool MachineStatus::hasSCSI() { - return machines[machine].flags & MACHINE_SCSI_DUAL; + return machine_has_flags(machine, MACHINE_SCSI_DUAL) > 0; } void MachineStatus::iterateFDD(const std::function &cb) { @@ -303,9 +299,9 @@ static int hdd_count(int bus) { } void MachineStatus::refresh(QStatusBar* sbar) { - bool has_mfm = machines[machine].flags & MACHINE_MFM; - bool has_xta = machines[machine].flags & MACHINE_XTA; - bool has_esdi = machines[machine].flags & MACHINE_ESDI; + bool has_mfm = machine_has_flags(machine, MACHINE_MFM) > 0; + bool has_xta = machine_has_flags(machine, MACHINE_XTA) > 0; + bool has_esdi = machine_has_flags(machine, MACHINE_ESDI) > 0; int c_mfm = hdd_count(HDD_BUS_MFM); int c_esdi = hdd_count(HDD_BUS_ESDI); @@ -346,7 +342,7 @@ void MachineStatus::refresh(QStatusBar* sbar) { sbar->addWidget(d->cassette.label.get()); } - if (hasCartridge()) { + if (machine_has_cartridge(machine)) { for (int i = 0; i < 2; ++i) { d->cartridge[i].label = std::make_unique(); d->cartridge[i].setEmpty(QString(cart_fns[i]).isEmpty()); diff --git a/src/qt/qt_machinestatus.hpp b/src/qt/qt_machinestatus.hpp index df901ab45..09ef80fa4 100644 --- a/src/qt/qt_machinestatus.hpp +++ b/src/qt/qt_machinestatus.hpp @@ -32,7 +32,6 @@ public: ~MachineStatus(); static bool hasCassette(); - static bool hasCartridge(); static bool hasIDE(); static bool hasSCSI(); static void iterateFDD(const std::function& cb); diff --git a/src/qt/qt_mediamenu.cpp b/src/qt/qt_mediamenu.cpp index 2b7faef0f..07b073968 100644 --- a/src/qt/qt_mediamenu.cpp +++ b/src/qt/qt_mediamenu.cpp @@ -56,7 +56,7 @@ void MediaMenu::refresh(QMenu *parentMenu) { } cartridgeMenus.clear(); - if (MachineStatus::hasCartridge()) { + if (machine_has_cartridge(machine)) { for(int i = 0; i < 2; i++) { auto* menu = parentMenu->addMenu(""); menu->addAction("Image", [this, i]() { cartridgeSelectImage(i); }); diff --git a/src/qt/qt_settingsdisplay.cpp b/src/qt/qt_settingsdisplay.cpp index 70ec09c89..4cd604305 100644 --- a/src/qt/qt_settingsdisplay.cpp +++ b/src/qt/qt_settingsdisplay.cpp @@ -36,7 +36,6 @@ void SettingsDisplay::onCurrentMachineChanged(int machineId) { // win_settings_video_proc, WM_INITDIALOG this->machineId = machineId; - auto* machine = &machines[machineId]; auto* model = ui->comboBoxVideo->model(); auto removeRows = model->rowCount(); @@ -44,7 +43,7 @@ void SettingsDisplay::onCurrentMachineChanged(int machineId) { int selectedRow = 0; while (true) { /* Skip "internal" if machine doesn't have it. */ - if ((c == 1) && !(machine->flags & MACHINE_VIDEO)) { + if ((c == 1) && (machine_has_flags(machineId, MACHINE_VIDEO) == 0)) { c++; continue; } @@ -56,7 +55,7 @@ void SettingsDisplay::onCurrentMachineChanged(int machineId) { } if (video_card_available(c) && - device_is_valid(video_dev, machine->flags)) { + device_is_valid(video_dev, machineId)) { int row = Models::AddEntry(model, name, c); if (c == gfxcard) { selectedRow = row - removeRows; @@ -67,7 +66,7 @@ void SettingsDisplay::onCurrentMachineChanged(int machineId) { } model->removeRows(0, removeRows); - if (machine->flags & MACHINE_VIDEO_ONLY) { + if (machine_has_flags(machineId, MACHINE_VIDEO_ONLY) > 0) { ui->comboBoxVideo->setEnabled(false); selectedRow = 1; } else { @@ -92,7 +91,7 @@ void SettingsDisplay::on_comboBoxVideo_currentIndexChanged(int index) { int videoCard = ui->comboBoxVideo->currentData().toInt(); ui->pushButtonConfigure->setEnabled(video_card_has_config(videoCard) > 0); - bool machineHasPci = machines[machineId].flags & MACHINE_BUS_PCI; + bool machineHasPci = machine_has_bus(machineId, MACHINE_BUS_PCI) > 0; ui->checkBoxVoodoo->setEnabled(machineHasPci); if (machineHasPci) { ui->checkBoxVoodoo->setChecked(voodoo_enabled); diff --git a/src/qt/qt_settingsinput.cpp b/src/qt/qt_settingsinput.cpp index 04c8a8f3d..b34cb31ca 100644 --- a/src/qt/qt_settingsinput.cpp +++ b/src/qt/qt_settingsinput.cpp @@ -45,11 +45,11 @@ void SettingsInput::onCurrentMachineChanged(int machineId) { int selectedRow = 0; for (int i = 0; i < mouse_get_ndev(); ++i) { const auto* dev = mouse_get_device(i); - if ((i == MOUSE_TYPE_INTERNAL) && !(machines[machineId].flags & MACHINE_MOUSE)) { + if ((i == MOUSE_TYPE_INTERNAL) && (machine_has_flags(machineId, MACHINE_MOUSE) == 0)) { continue; } - if (device_is_valid(dev, machine->flags) == 0) { + if (device_is_valid(dev, machineId) == 0) { continue; } diff --git a/src/qt/qt_settingsmachine.cpp b/src/qt/qt_settingsmachine.cpp index e43494e8f..9b8455f11 100644 --- a/src/qt/qt_settingsmachine.cpp +++ b/src/qt/qt_settingsmachine.cpp @@ -57,8 +57,8 @@ SettingsMachine::SettingsMachine(QWidget *parent) : int selectedMachineType = 0; auto* machineTypesModel = ui->comboBoxMachineType->model(); for (int i = 0; i < MACHINE_TYPE_MAX; ++i) { - Models::AddEntry(machineTypesModel, machine_types[i].name, machine_types[i].id); - if (machine_types[i].id == machines[machine].type) { + Models::AddEntry(machineTypesModel, machine_getname_ex(i), machine_types[i].id); + if (machine_types[i].id == machine_get_type(machine)) { selectedMachineType = i; } } @@ -75,11 +75,21 @@ void SettingsMachine::save() { cpu = ui->comboBoxSpeed->currentData().toInt(); fpu_type = ui->comboBoxFPU->currentData().toInt(); cpu_use_dynarec = ui->checkBoxDynamicRecompiler->isChecked() ? 1 : 0; - if (machines[machine].ram_granularity < 1024) { - mem_size = ui->spinBoxRAM->value(); + int64_t temp_mem_size; + if (machine_get_ram_granularity(machine) < 1024) { + temp_mem_size = ui->spinBoxRAM->value(); } else { - mem_size = ui->spinBoxRAM->value() * 1024; + temp_mem_size = ui->spinBoxRAM->value() * 1024; } + + temp_mem_size &= ~(machine_get_ram_granularity(machine) - 1); + if (temp_mem_size < machine_get_min_ram(machine)) { + temp_mem_size = machine_get_min_ram(machine); + } else if (temp_mem_size > machine_get_max_ram(machine)) { + temp_mem_size = machine_get_max_ram(machine); + } + mem_size = static_cast(temp_mem_size); + if (ui->comboBoxWaitStates->isEnabled()) { cpu_waitstates = ui->comboBoxWaitStates->currentData().toInt(); } else { @@ -101,7 +111,7 @@ void SettingsMachine::on_comboBoxMachineType_currentIndexChanged(int index) { int selectedMachineRow = 0; for (int i = 0; i < machine_count(); ++i) { - if ((machines[i].type == index) && machine_available(i)) { + if ((machine_get_type(i) == index) && machine_available(i)) { int row = Models::AddEntry(model, machines[i].name, i); if (i == machine) { selectedMachineRow = row - removeRows; @@ -148,26 +158,25 @@ void SettingsMachine::on_comboBoxMachine_currentIndexChanged(int index) { auto* machine = &machines[machineId]; if ((machine->ram_granularity < 1024)) { - ui->spinBoxRAM->setMinimum(machine->min_ram); - ui->spinBoxRAM->setMaximum(machine->max_ram); - ui->spinBoxRAM->setSingleStep(machine->ram_granularity); + ui->spinBoxRAM->setMinimum(machine_get_min_ram(machineId)); + ui->spinBoxRAM->setMaximum(machine_get_max_ram(machineId)); + ui->spinBoxRAM->setSingleStep(machine_get_ram_granularity(machineId)); ui->spinBoxRAM->setSuffix(" KiB"); ui->spinBoxRAM->setValue(mem_size); } else { - uint maxram; + int maxram; #if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) - maxram = std::min(machine->max_ram, 2097152U); + maxram = std::min(machine->max_ram, 2097152); #else - maxram = std::min(machine->max_ram, 3145728U); + maxram = std::min(machine_get_max_ram(machineId), 3145728); #endif - ui->spinBoxRAM->setMinimum(machine->min_ram / 1024); + ui->spinBoxRAM->setMinimum(machine_get_min_ram(machineId) / 1024); ui->spinBoxRAM->setMaximum(maxram / 1024); - ui->spinBoxRAM->setSingleStep(machine->ram_granularity / 1024); + ui->spinBoxRAM->setSingleStep(machine_get_ram_granularity(machineId) / 1024); ui->spinBoxRAM->setSuffix(" MiB"); ui->spinBoxRAM->setValue(mem_size / 1024); } - ui->spinBoxRAM->setEnabled(machine->min_ram != machine->max_ram); - ui->spinBoxRAM->setEnabled(machine->min_ram != machine->max_ram); + ui->spinBoxRAM->setEnabled(machine_get_min_ram(machineId) != machine_get_max_ram(machineId)); emit currentMachineChanged(machineId); } diff --git a/src/qt/qt_settingsnetwork.cpp b/src/qt/qt_settingsnetwork.cpp index 18d06a520..201a61fea 100644 --- a/src/qt/qt_settingsnetwork.cpp +++ b/src/qt/qt_settingsnetwork.cpp @@ -76,7 +76,7 @@ void SettingsNetwork::onCurrentMachineChanged(int machineId) { break; } - if (network_card_available(c) && device_is_valid(network_card_getdevice(c), machine->flags)) { + if (network_card_available(c) && device_is_valid(network_card_getdevice(c), machineId)) { int row = Models::AddEntry(model, name, c); if (c == network_card) { selectedRow = row - removeRows; diff --git a/src/qt/qt_settingssound.cpp b/src/qt/qt_settingssound.cpp index 8e686f870..35adcf295 100644 --- a/src/qt/qt_settingssound.cpp +++ b/src/qt/qt_settingssound.cpp @@ -40,7 +40,6 @@ void SettingsSound::save() { void SettingsSound::onCurrentMachineChanged(int machineId) { this->machineId = machineId; - auto* machine = &machines[machineId]; auto* model = ui->comboBoxSoundCard->model(); auto removeRows = model->rowCount(); @@ -48,7 +47,7 @@ void SettingsSound::onCurrentMachineChanged(int machineId) { int selectedRow = 0; while (true) { /* Skip "internal" if machine doesn't have it. */ - if ((c == 1) && !(machine->flags & MACHINE_SOUND)) { + if ((c == 1) && (machine_has_flags(machineId, MACHINE_SOUND) == 0)) { c++; continue; } @@ -60,7 +59,7 @@ void SettingsSound::onCurrentMachineChanged(int machineId) { } if (sound_card_available(c)) { - if (device_is_valid(sound_dev, machine->flags)) { + if (device_is_valid(sound_dev, machineId)) { int row = Models::AddEntry(model, name, c); if (c == sound_card_current) { selectedRow = row - removeRows; @@ -128,9 +127,14 @@ void SettingsSound::onCurrentMachineChanged(int machineId) { ui->checkBoxGUS->setChecked(GUS > 0); ui->checkBoxFloat32->setChecked(sound_is_float > 0); - ui->pushButtonConfigureSSI2001->setEnabled((SSI2001 > 0) && (machine->flags & MACHINE_BUS_ISA)); - ui->pushButtonConfigureCMS->setEnabled((GAMEBLASTER > 0) && (machine->flags & MACHINE_BUS_ISA)); - ui->pushButtonConfigureGUS->setEnabled((GUS > 0) && (machine->flags & MACHINE_BUS_ISA16)); + bool hasIsa = machine_has_bus(machineId, MACHINE_BUS_ISA) > 0; + bool hasIsa16 = machine_has_bus(machineId, MACHINE_BUS_ISA) > 0; + ui->checkBoxCMS->setEnabled(hasIsa); + ui->pushButtonConfigureCMS->setEnabled((GAMEBLASTER > 0) && hasIsa); + ui->checkBoxGUS->setEnabled(hasIsa16); + ui->pushButtonConfigureGUS->setEnabled((GUS > 0) && hasIsa16); + ui->checkBoxSSI2001->setEnabled(hasIsa); + ui->pushButtonConfigureSSI2001->setEnabled((SSI2001 > 0) && hasIsa); } static bool allowMpu401(Ui::SettingsSound *ui) { @@ -203,7 +207,7 @@ void SettingsSound::on_checkBoxGUS_stateChanged(int state) { } void SettingsSound::on_pushButtonConfigureMPU401_clicked() { - if (machines[machineId].flags & MACHINE_MCA) { + if (machine_has_bus(machineId, MACHINE_BUS_MCA) > 0) { DeviceConfig::ConfigureDevice(&mpu401_mca_device); } else { DeviceConfig::ConfigureDevice(&mpu401_device); diff --git a/src/qt/qt_settingsstoragecontrollers.cpp b/src/qt/qt_settingsstoragecontrollers.cpp index fb5dd47cc..8432a300a 100644 --- a/src/qt/qt_settingsstoragecontrollers.cpp +++ b/src/qt/qt_settingsstoragecontrollers.cpp @@ -57,7 +57,7 @@ void SettingsStorageControllers::onCurrentMachineChanged(int machineId) { int selectedRow = 0; while (true) { /* Skip "internal" if machine doesn't have it. */ - if ((c == 1) && !(machine->flags & MACHINE_HDC)) { + if ((c == 1) && (machine_has_flags(machineId, MACHINE_HDC) == 0)) { c++; continue; } @@ -70,7 +70,7 @@ void SettingsStorageControllers::onCurrentMachineChanged(int machineId) { if (hdc_available(c)) { auto* hdc_dev = hdc_get_device(c); - if (device_is_valid(hdc_dev, machine->flags)) { + if (device_is_valid(hdc_dev, machineId)) { int row = Models::AddEntry(model, name, c); if (c == hdc_current) { selectedRow = row - removeRows; @@ -98,7 +98,7 @@ void SettingsStorageControllers::onCurrentMachineChanged(int machineId) { if (fdc_card_available(c)) { auto* fdc_dev = fdc_card_getdevice(c); - if (device_is_valid(fdc_dev, machine->flags)) { + if (device_is_valid(fdc_dev, machineId)) { int row = Models::AddEntry(model, name, c); if (c == fdc_type) { selectedRow = row - removeRows; @@ -127,7 +127,7 @@ void SettingsStorageControllers::onCurrentMachineChanged(int machineId) { if (scsi_card_available(c)) { auto* scsi_dev = scsi_card_getdevice(c); - if (device_is_valid(scsi_dev, machine->flags)) { + if (device_is_valid(scsi_dev, machineId)) { int row = Models::AddEntry(model, name, c); if (c == scsi_card_current[i]) { selectedRow = row - removeRows;