Files
86Box/src/qt/qt_settingsstoragecontrollers.cpp

364 lines
11 KiB
C++
Raw Normal View History

2022-02-07 15:00:02 +06:00
/*
2023-01-08 14:25:18 +01:00
* 86Box A hypervisor and IBM PC system emulator that specializes in
* running old operating systems and software designed for IBM
* PC systems and compatibles from 1981 through fairly recent
* system designs based on the PCI bus.
2022-02-07 15:00:02 +06:00
*
2023-01-08 14:25:18 +01:00
* This file is part of the 86Box distribution.
2022-02-07 15:00:02 +06:00
*
2023-01-08 14:25:18 +01:00
* Storage devices configuration UI module.
2022-02-07 15:00:02 +06:00
*
*
*
2023-01-08 14:25:18 +01:00
* Authors: Joakim L. Gilje <jgilje@jgilje.net>
2022-02-07 15:00:02 +06:00
*
2023-01-08 14:25:18 +01:00
* Copyright 2021 Joakim L. Gilje
2022-02-07 15:00:02 +06:00
*/
2021-11-25 10:20:56 +01:00
#include "qt_settingsstoragecontrollers.hpp"
#include "ui_qt_settingsstoragecontrollers.h"
extern "C" {
#include <86box/86box.h>
#include <86box/timer.h>
#include <86box/device.h>
#include <86box/machine.h>
#include <86box/hdc.h>
#include <86box/hdc_ide.h>
#include <86box/fdc_ext.h>
#include <86box/cdrom_interface.h>
2021-11-25 10:20:56 +01:00
#include <86box/scsi.h>
#include <86box/scsi_device.h>
#include <86box/cassette.h>
}
#include "qt_deviceconfig.hpp"
#include "qt_models_common.hpp"
2022-11-19 08:49:04 -05:00
SettingsStorageControllers::SettingsStorageControllers(QWidget *parent)
: QWidget(parent)
, ui(new Ui::SettingsStorageControllers)
2021-11-25 10:20:56 +01:00
{
ui->setupUi(this);
onCurrentMachineChanged(machine);
}
SettingsStorageControllers::~SettingsStorageControllers()
{
delete ui;
}
2022-11-19 08:49:04 -05:00
void
SettingsStorageControllers::save()
{
2021-11-25 10:20:56 +01:00
/* Storage devices category */
for (uint8_t i = 0; i < SCSI_CARD_MAX; ++i) {
QComboBox *cbox = findChild<QComboBox *>(QString("comboBoxSCSI%1").arg(i + 1));
2021-11-25 10:20:56 +01:00
scsi_card_current[i] = cbox->currentData().toInt();
}
fdc_current[0] = ui->comboBoxFD->currentData().toInt();
hdc_current[0] = ui->comboBoxHD->currentData().toInt();
2023-06-29 03:48:04 +05:00
cdrom_interface_current = ui->comboBoxCDInterface->currentData().toInt();
ide_ter_enabled = ui->checkBoxTertiaryIDE->isChecked() ? 1 : 0;
ide_qua_enabled = ui->checkBoxQuaternaryIDE->isChecked() ? 1 : 0;
cassette_enable = ui->checkBoxCassette->isChecked() ? 1 : 0;
2021-11-25 10:20:56 +01:00
}
2022-11-19 08:49:04 -05:00
void
SettingsStorageControllers::onCurrentMachineChanged(int machineId)
{
2021-11-25 10:20:56 +01:00
this->machineId = machineId;
/*HD controller config*/
int c = 0;
2022-11-19 08:49:04 -05:00
auto *model = ui->comboBoxHD->model();
auto removeRows = model->rowCount();
int selectedRow = 0;
2021-11-25 10:20:56 +01:00
while (true) {
/* Skip "internal" if machine doesn't have it. */
if ((c == 1) && (machine_has_flags(machineId, MACHINE_HDC) == 0)) {
2021-11-25 10:20:56 +01:00
c++;
continue;
}
QString name = DeviceConfig::DeviceName(hdc_get_device(c), hdc_get_internal_name(c), 1);
2025-05-09 21:12:19 -04:00
if (name.isEmpty())
2021-11-25 10:20:56 +01:00
break;
if (hdc_available(c)) {
const device_t *hdc_dev = hdc_get_device(c);
2021-11-25 10:20:56 +01:00
if (device_is_valid(hdc_dev, machineId)) {
2021-11-25 10:20:56 +01:00
int row = Models::AddEntry(model, name, c);
2025-05-09 21:12:19 -04:00
if (c == hdc_current[0])
2021-11-25 10:20:56 +01:00
selectedRow = row - removeRows;
}
}
c++;
}
model->removeRows(0, removeRows);
ui->comboBoxHD->setEnabled(model->rowCount() > 0);
ui->comboBoxHD->setCurrentIndex(-1);
ui->comboBoxHD->setCurrentIndex(selectedRow);
2025-05-09 21:12:19 -04:00
/* FD controller config */
2022-11-19 08:49:04 -05:00
model = ui->comboBoxFD->model();
removeRows = model->rowCount();
c = 0;
2021-11-25 10:20:56 +01:00
selectedRow = 0;
while (true) {
#if 0
/* Skip "internal" if machine doesn't have it. */
if ((c == 1) && (machine_has_flags(machineId, MACHINE_FDC) == 0)) {
c++;
continue;
}
#endif
2021-11-25 10:20:56 +01:00
QString name = DeviceConfig::DeviceName(fdc_card_getdevice(c), fdc_card_get_internal_name(c), 1);
if (name.isEmpty()) {
break;
}
if (fdc_card_available(c)) {
const device_t *fdc_dev = fdc_card_getdevice(c);
2021-11-25 10:20:56 +01:00
if (device_is_valid(fdc_dev, machineId)) {
2021-11-25 10:20:56 +01:00
int row = Models::AddEntry(model, name, c);
if (c == fdc_current[0]) {
2021-11-25 10:20:56 +01:00
selectedRow = row - removeRows;
}
}
}
c++;
}
model->removeRows(0, removeRows);
ui->comboBoxFD->setEnabled(model->rowCount() > 0);
ui->comboBoxFD->setCurrentIndex(-1);
ui->comboBoxFD->setCurrentIndex(selectedRow);
/*CD interface controller config*/
#ifdef USE_CDROM_MITSUMI
2025-05-09 21:12:19 -04:00
ui->labelCDInterface->setVisible(true);
ui->comboBoxCDInterface->setVisible(true);
ui->pushButtonCDInterface->setVisible(true);
#else
2025-05-09 21:12:19 -04:00
ui->labelCDInterface->setVisible(false);
ui->comboBoxCDInterface->setVisible(false);
ui->pushButtonCDInterface->setVisible(false);
#endif
c = 0;
model = ui->comboBoxCDInterface->model();
removeRows = model->rowCount();
selectedRow = 0;
while (true) {
/* Skip "internal" if machine doesn't have it. */
QString name = DeviceConfig::DeviceName(cdrom_interface_get_device(c), cdrom_interface_get_internal_name(c), 1);
if (name.isEmpty()) {
break;
}
if (cdrom_interface_available(c)) {
const device_t *cdrom_interface_dev = cdrom_interface_get_device(c);
if (device_is_valid(cdrom_interface_dev, machineId)) {
int row = Models::AddEntry(model, name, c);
if (c == cdrom_interface_current) {
selectedRow = row - removeRows;
}
}
}
c++;
}
model->removeRows(0, removeRows);
ui->comboBoxCDInterface->setEnabled(model->rowCount() > 0);
ui->comboBoxCDInterface->setCurrentIndex(-1);
ui->comboBoxCDInterface->setCurrentIndex(selectedRow);
// SCSI Card
QComboBox * cbox[SCSI_CARD_MAX] = { 0 };
QAbstractItemModel *models[SCSI_CARD_MAX] = { 0 };
int removeRows_[SCSI_CARD_MAX] = { 0 };
int selectedRows[SCSI_CARD_MAX] = { 0 };
for (uint8_t i = 0; i < SCSI_CARD_MAX; ++i) {
cbox[i] = findChild<QComboBox *>(QString("comboBoxSCSI%1").arg(i + 1));
models[i] = cbox[i]->model();
removeRows_[i] = models[i]->rowCount();
}
c = 0;
while (true) {
const QString name = DeviceConfig::DeviceName(scsi_card_getdevice(c),
scsi_card_get_internal_name(c), 1);
if (name.isEmpty())
break;
if (scsi_card_available(c)) {
if (device_is_valid(scsi_card_getdevice(c), machineId)) {
for (uint8_t i = 0; i < SCSI_CARD_MAX; ++i) {
int row = Models::AddEntry(models[i], name, c);
2021-11-25 10:20:56 +01:00
if (c == scsi_card_current[i])
selectedRows[i] = row - removeRows_[i];
2021-11-25 10:20:56 +01:00
}
}
}
c++;
}
for (uint8_t i = 0; i < SCSI_CARD_MAX; ++i) {
models[i]->removeRows(0, removeRows_[i]);
cbox[i]->setEnabled(models[i]->rowCount() > 1);
cbox[i]->setCurrentIndex(-1);
cbox[i]->setCurrentIndex(selectedRows[i]);
2021-11-25 10:20:56 +01:00
}
int is_at = IS_AT(machineId);
ui->checkBoxTertiaryIDE->setEnabled(is_at > 0);
ui->checkBoxQuaternaryIDE->setEnabled(is_at > 0);
ui->checkBoxTertiaryIDE->setChecked(ui->checkBoxTertiaryIDE->isEnabled() && ide_ter_enabled);
ui->checkBoxQuaternaryIDE->setChecked(ui->checkBoxQuaternaryIDE->isEnabled() && ide_qua_enabled);
if (machine_has_bus(machineId, MACHINE_BUS_CASSETTE)) {
ui->checkBoxCassette->setChecked(cassette_enable > 0);
ui->checkBoxCassette->setEnabled(true);
} else {
ui->checkBoxCassette->setChecked(false);
ui->checkBoxCassette->setEnabled(false);
}
2021-11-25 10:20:56 +01:00
}
2022-11-19 08:49:04 -05:00
void
SettingsStorageControllers::on_comboBoxFD_currentIndexChanged(int index)
2022-11-19 08:49:04 -05:00
{
2025-05-09 21:12:19 -04:00
if (index < 0)
2021-11-25 10:20:56 +01:00
return;
2025-05-09 21:12:19 -04:00
ui->pushButtonFD->setEnabled(fdc_card_has_config(ui->comboBoxFD->currentData().toInt()) > 0);
2021-11-25 10:20:56 +01:00
}
2022-11-19 08:49:04 -05:00
void
SettingsStorageControllers::on_comboBoxHD_currentIndexChanged(int index)
2022-11-19 08:49:04 -05:00
{
2025-05-09 21:12:19 -04:00
if (index < 0)
2021-11-25 10:20:56 +01:00
return;
2025-05-09 21:12:19 -04:00
ui->pushButtonHD->setEnabled(hdc_has_config(ui->comboBoxHD->currentData().toInt()) > 0);
2021-11-25 10:20:56 +01:00
}
void
SettingsStorageControllers::on_comboBoxCDInterface_currentIndexChanged(int index)
{
2025-05-09 21:12:19 -04:00
if (index < 0)
return;
2025-05-09 21:12:19 -04:00
ui->pushButtonCDInterface->setEnabled(cdrom_interface_has_config(ui->comboBoxCDInterface->currentData().toInt()) > 0);
}
2022-11-19 08:49:04 -05:00
void
SettingsStorageControllers::on_checkBoxTertiaryIDE_stateChanged(int arg1)
{
2021-11-25 10:20:56 +01:00
ui->pushButtonTertiaryIDE->setEnabled(arg1 == Qt::Checked);
}
2022-11-19 08:49:04 -05:00
void
SettingsStorageControllers::on_checkBoxQuaternaryIDE_stateChanged(int arg1)
{
2021-11-25 10:20:56 +01:00
ui->pushButtonQuaternaryIDE->setEnabled(arg1 == Qt::Checked);
}
2022-11-19 08:49:04 -05:00
void
SettingsStorageControllers::on_pushButtonFD_clicked()
2022-11-19 08:49:04 -05:00
{
DeviceConfig::ConfigureDevice(fdc_card_getdevice(ui->comboBoxFD->currentData().toInt()));
2021-11-25 10:20:56 +01:00
}
2022-11-19 08:49:04 -05:00
void
SettingsStorageControllers::on_pushButtonHD_clicked()
2022-11-19 08:49:04 -05:00
{
DeviceConfig::ConfigureDevice(hdc_get_device(ui->comboBoxHD->currentData().toInt()));
2021-11-25 10:20:56 +01:00
}
2023-01-08 00:05:58 +01:00
void
SettingsStorageControllers::on_pushButtonCDInterface_clicked()
{
DeviceConfig::ConfigureDevice(cdrom_interface_get_device(ui->comboBoxCDInterface->currentData().toInt()));
2023-01-08 00:05:58 +01:00
}
2022-11-19 08:49:04 -05:00
void
SettingsStorageControllers::on_pushButtonTertiaryIDE_clicked()
{
DeviceConfig::ConfigureDevice(&ide_ter_device);
2021-11-25 10:20:56 +01:00
}
2022-11-19 08:49:04 -05:00
void
SettingsStorageControllers::on_pushButtonQuaternaryIDE_clicked()
{
DeviceConfig::ConfigureDevice(&ide_qua_device);
2021-11-25 10:20:56 +01:00
}
2022-11-19 08:49:04 -05:00
void
SettingsStorageControllers::on_comboBoxSCSI1_currentIndexChanged(int index)
{
2025-05-09 21:12:19 -04:00
if (index < 0)
2021-11-25 10:20:56 +01:00
return;
2025-05-09 21:12:19 -04:00
2021-11-25 10:20:56 +01:00
ui->pushButtonSCSI1->setEnabled(scsi_card_has_config(ui->comboBoxSCSI1->currentData().toInt()) > 0);
}
2022-11-19 08:49:04 -05:00
void
SettingsStorageControllers::on_comboBoxSCSI2_currentIndexChanged(int index)
{
2025-05-09 21:12:19 -04:00
if (index < 0)
2021-11-25 10:20:56 +01:00
return;
2025-05-09 21:12:19 -04:00
2021-11-25 10:20:56 +01:00
ui->pushButtonSCSI2->setEnabled(scsi_card_has_config(ui->comboBoxSCSI2->currentData().toInt()) > 0);
}
2022-11-19 08:49:04 -05:00
void
SettingsStorageControllers::on_comboBoxSCSI3_currentIndexChanged(int index)
{
2025-05-09 21:12:19 -04:00
if (index < 0)
2021-11-25 10:20:56 +01:00
return;
2025-05-09 21:12:19 -04:00
2021-11-25 10:20:56 +01:00
ui->pushButtonSCSI3->setEnabled(scsi_card_has_config(ui->comboBoxSCSI3->currentData().toInt()) > 0);
}
2022-11-19 08:49:04 -05:00
void
SettingsStorageControllers::on_comboBoxSCSI4_currentIndexChanged(int index)
{
2025-05-09 21:12:19 -04:00
if (index < 0)
2021-11-25 10:20:56 +01:00
return;
2025-05-09 21:12:19 -04:00
2021-11-25 10:20:56 +01:00
ui->pushButtonSCSI4->setEnabled(scsi_card_has_config(ui->comboBoxSCSI4->currentData().toInt()) > 0);
}
2022-11-19 08:49:04 -05:00
void
SettingsStorageControllers::on_pushButtonSCSI1_clicked()
{
DeviceConfig::ConfigureDevice(scsi_card_getdevice(ui->comboBoxSCSI1->currentData().toInt()), 1);
2021-11-25 10:20:56 +01:00
}
2022-11-19 08:49:04 -05:00
void
SettingsStorageControllers::on_pushButtonSCSI2_clicked()
{
DeviceConfig::ConfigureDevice(scsi_card_getdevice(ui->comboBoxSCSI2->currentData().toInt()), 2);
2021-11-25 10:20:56 +01:00
}
2022-11-19 08:49:04 -05:00
void
SettingsStorageControllers::on_pushButtonSCSI3_clicked()
{
DeviceConfig::ConfigureDevice(scsi_card_getdevice(ui->comboBoxSCSI3->currentData().toInt()), 3);
2021-11-25 10:20:56 +01:00
}
2022-11-19 08:49:04 -05:00
void
SettingsStorageControllers::on_pushButtonSCSI4_clicked()
{
DeviceConfig::ConfigureDevice(scsi_card_getdevice(ui->comboBoxSCSI4->currentData().toInt()), 4);
2021-11-25 10:20:56 +01:00
}