From f9e8520c415a7cd19aec4f974e7e5f37f36095b2 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Mon, 23 May 2022 17:29:45 +0600 Subject: [PATCH] qt: Add MCA device list to Tools --- src/include/86box/mca.h | 2 + src/mca.c | 14 +++++++ src/qt/CMakeLists.txt | 4 ++ src/qt/qt_mainwindow.cpp | 10 +++++ src/qt/qt_mainwindow.hpp | 2 + src/qt/qt_mainwindow.ui | 7 ++++ src/qt/qt_mcadevicelist.cpp | 42 +++++++++++++++++++++ src/qt/qt_mcadevicelist.hpp | 22 +++++++++++ src/qt/qt_mcadevicelist.ui | 74 +++++++++++++++++++++++++++++++++++++ 9 files changed, 177 insertions(+) create mode 100644 src/qt/qt_mcadevicelist.cpp create mode 100644 src/qt/qt_mcadevicelist.hpp create mode 100644 src/qt/qt_mcadevicelist.ui diff --git a/src/include/86box/mca.h b/src/include/86box/mca.h index 68aa2563f..f41eda9cf 100644 --- a/src/include/86box/mca.h +++ b/src/include/86box/mca.h @@ -5,8 +5,10 @@ extern void mca_init(int nr_cards); extern void mca_add(uint8_t (*read)(int addr, void *priv), void (*write)(int addr, uint8_t val, void *priv), uint8_t (*feedb)(void *priv), void (*reset)(void *priv), void *priv); extern void mca_set_index(int index); extern uint8_t mca_read(uint16_t port); +extern uint8_t mca_read_index(uint16_t port, int index); extern void mca_write(uint16_t port, uint8_t val); extern uint8_t mca_feedb(void); +extern int mca_get_nr_cards(void); extern void mca_reset(void); extern void ps2_cache_clean(void); diff --git a/src/mca.c b/src/mca.c index 5a9b355f8..4ef00318d 100644 --- a/src/mca.c +++ b/src/mca.c @@ -45,6 +45,20 @@ uint8_t mca_read(uint16_t port) return mca_card_read[mca_index](port, mca_priv[mca_index]); } +uint8_t mca_read_index(uint16_t port, int index) +{ + if (mca_index >= mca_nr_cards) + return 0xff; + if (!mca_card_read[index]) + return 0xff; + return mca_card_read[index](port, mca_priv[index]); +} + +int mca_get_nr_cards(void) +{ + return mca_nr_cards; +} + void mca_write(uint16_t port, uint8_t val) { if (mca_index >= mca_nr_cards) diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index f895e53b4..2364f5a9e 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -151,6 +151,10 @@ add_library(ui STATIC qt_vulkanrenderer.hpp qt_vulkanrenderer.cpp + qt_mcadevicelist.hpp + qt_mcadevicelist.cpp + qt_mcadevicelist.ui + ../qt_resources.qrc ) diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index f3be72b08..4c7a19402 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -26,6 +26,7 @@ #include "qt_specifydimensions.h" #include "qt_soundgain.hpp" #include "qt_progsettings.hpp" +#include "qt_mcadevicelist.hpp" #include "qt_rendererstack.hpp" #include "qt_renderercommon.hpp" @@ -1875,3 +1876,12 @@ void MainWindow::on_actionRenderer_options_triggered() if (dlg) dlg->exec(); } + +void MainWindow::on_actionMCA_devices_triggered() +{ + auto dlg = new MCADeviceList(this); + + if (dlg) + dlg->exec(); +} + diff --git a/src/qt/qt_mainwindow.hpp b/src/qt/qt_mainwindow.hpp index 84d08f8ed..ffecdd773 100644 --- a/src/qt/qt_mainwindow.hpp +++ b/src/qt/qt_mainwindow.hpp @@ -103,6 +103,8 @@ private slots: void showMessage_(const QString& header, const QString& message); void getTitle_(wchar_t* title); + void on_actionMCA_devices_triggered(); + protected: void keyPressEvent(QKeyEvent* event) override; void keyReleaseEvent(QKeyEvent* event) override; diff --git a/src/qt/qt_mainwindow.ui b/src/qt/qt_mainwindow.ui index 4720afc2a..b26e11f55 100644 --- a/src/qt/qt_mainwindow.ui +++ b/src/qt/qt_mainwindow.ui @@ -89,6 +89,8 @@ + + @@ -738,6 +740,11 @@ 4 + + + MCA devices... + + diff --git a/src/qt/qt_mcadevicelist.cpp b/src/qt/qt_mcadevicelist.cpp new file mode 100644 index 000000000..d89bc7725 --- /dev/null +++ b/src/qt/qt_mcadevicelist.cpp @@ -0,0 +1,42 @@ +#include "qt_mcadevicelist.hpp" +#include "ui_qt_mcadevicelist.h" + +extern "C" +{ +#include <86box/86box.h> +#include <86box/video.h> +#include <86box/mca.h> +#include <86box/plat.h> +} + +MCADeviceList::MCADeviceList(QWidget *parent) : + QDialog(parent), + ui(new Ui::MCADeviceList) +{ + ui->setupUi(this); + + startblit(); + if (mca_get_nr_cards() == 0) + { + ui->listWidget->addItem(QObject::tr("No MCA devices.")); + ui->listWidget->setDisabled(true); + } + else + { + for (int i = 0; i < mca_get_nr_cards(); i++) + { + uint32_t deviceId = (mca_read_index(0x00, i) | (mca_read_index(0x01, i) << 8)); + if (deviceId != 0xFFFF) + { + QString hexRepresentation = QString::number(deviceId, 16).toUpper(); + ui->listWidget->addItem(QString("Slot %1: 0x%2 (@%3.ADF)").arg(i).arg(hexRepresentation, hexRepresentation)); + } + } + } + endblit(); +} + +MCADeviceList::~MCADeviceList() +{ + delete ui; +} diff --git a/src/qt/qt_mcadevicelist.hpp b/src/qt/qt_mcadevicelist.hpp new file mode 100644 index 000000000..e45992519 --- /dev/null +++ b/src/qt/qt_mcadevicelist.hpp @@ -0,0 +1,22 @@ +#ifndef QT_MCADEVICELIST_HPP +#define QT_MCADEVICELIST_HPP + +#include + +namespace Ui { +class MCADeviceList; +} + +class MCADeviceList : public QDialog +{ + Q_OBJECT + +public: + explicit MCADeviceList(QWidget *parent = nullptr); + ~MCADeviceList(); + +private: + Ui::MCADeviceList *ui; +}; + +#endif // QT_MCADEVICELIST_HPP diff --git a/src/qt/qt_mcadevicelist.ui b/src/qt/qt_mcadevicelist.ui new file mode 100644 index 000000000..559f2c589 --- /dev/null +++ b/src/qt/qt_mcadevicelist.ui @@ -0,0 +1,74 @@ + + + MCADeviceList + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + + List of MCA devices: + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + MCADeviceList + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + MCADeviceList + reject() + + + 316 + 260 + + + 286 + 274 + + + + +