Skip to content

Commit

Permalink
Device runtime config
Browse files Browse the repository at this point in the history
  • Loading branch information
Cacodemon345 committed Feb 2, 2024
1 parent 285acca commit 4543db0
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@

#define DEVICE_MAX 256 /* max # of devices */

static device_t *devices[DEVICE_MAX];
static void *device_priv[DEVICE_MAX];
/* Only intended to be accessed by UI code for runtime configuration. */
device_t *devices[DEVICE_MAX];
int devices_instances[DEVICE_MAX];
void *device_priv[DEVICE_MAX];

static device_context_t device_current;
static device_context_t device_prev;

Expand Down Expand Up @@ -188,6 +191,7 @@ device_add_common(const device_t *dev, const device_t *cd, void *p, void *params

memcpy(&device_current, &device_prev, sizeof(device_context_t));
device_priv[c] = priv;
devices_instances[c] = inst;
} else
device_priv[c] = p;

Expand Down Expand Up @@ -315,6 +319,7 @@ device_close_all(void)
if (devices[c]->close != NULL)
devices[c]->close(device_priv[c]);
devices[c] = device_priv[c] = NULL;
devices_instances[c] = 0;
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/include/86box/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
#define CONFIG_SUBTYPE_MASK (CONFIG_IS_STRING - 1)

#define CONFIG_DEP (16 << CONFIG_SHIFT)
#define CONFIG_RUNTIME (32 << CONFIG_SHIFT)
#define CONFIG_TYPE_MASK (CONFIG_DEP - 1)

// #define CONFIG_ONBOARD 256 /* only avaialble on the on-board variant */
Expand Down Expand Up @@ -101,6 +102,7 @@ enum {
DEVICE_LPT = 0x200000, /* requires a parallel port */
DEVICE_KBC = 0x400000, /* is a keyboard controller */

DEVICE_RTCONFIG = 0x10000000, /* can reload settings at run-time. */
DEVICE_ONBOARD = 0x20000000, /* is on-board */
DEVICE_EXTPARAMS = 0x40000000, /* accepts extended parameters */

Expand Down Expand Up @@ -182,6 +184,7 @@ typedef struct _device_ {
};
void (*speed_changed)(void *priv);
void (*force_redraw)(void *priv);
void (*reload_config)(void *priv);

const device_config_t *config;
} device_t;
Expand Down
19 changes: 15 additions & 4 deletions src/qt/qt_deviceconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ extern "C" {
#include <86box/ini.h>
#include <86box/config.h>
#include <86box/device.h>
#include <86box/plat.h>
#include <86box/midi_rtmidi.h>
#include <86box/mem.h>
#include <86box/rom.h>
Expand All @@ -51,6 +52,8 @@ extern "C" {
#include <windows.h>
#endif

extern void *device_priv[256];

DeviceConfig::DeviceConfig(QWidget *parent)
: QDialog(parent)
, ui(new Ui::DeviceConfig)
Expand Down Expand Up @@ -105,13 +108,12 @@ EnumerateSerialDevices()
}

void
DeviceConfig::ConfigureDevice(const _device_ *device, int instance, Settings *settings)
DeviceConfig::ConfigureDevice(const _device_ *device, int instance, Settings *settings, bool atRuntime)
{
DeviceConfig dc(settings);
dc.setWindowTitle(QString("%1 Device Configuration").arg(device->name));
int p;
int q;

device_context_t device_context;
device_set_context(&device_context, device, instance);

Expand All @@ -123,7 +125,9 @@ DeviceConfig::ConfigureDevice(const _device_ *device, int instance, Settings *se
dc.ui->formLayout->addRow(line);
const auto *config = device->config;
while (config->type != -1) {
switch (config->type) {
if (atRuntime && !(config->type & CONFIG_RUNTIME))
continue;
switch (config->type & CONFIG_TYPE_MASK) {
case CONFIG_BINARY:
{
auto value = config_get_int(device_context.name, const_cast<char *>(config->name), config->default_int);
Expand Down Expand Up @@ -294,13 +298,19 @@ DeviceConfig::ConfigureDevice(const _device_ *device, int instance, Settings *se
}
++config;
}
if (atRuntime)
endblit();

dc.setFixedSize(dc.minimumSizeHint());
int res = dc.exec();
if (res == QDialog::Accepted) {
if (atRuntime)
startblit();
config = device->config;
while (config->type != -1) {
switch (config->type) {
if (atRuntime && !(config->type & CONFIG_RUNTIME))
continue;
switch (config->type & CONFIG_TYPE_MASK) {
case CONFIG_BINARY:
{
auto *cbox = dc.findChild<QCheckBox *>(config->name);
Expand Down Expand Up @@ -365,6 +375,7 @@ DeviceConfig::ConfigureDevice(const _device_ *device, int instance, Settings *se
}
config++;
}
// Endblit will be called in qt_mainwindow.cpp.
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/qt/qt_deviceconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DeviceConfig : public QDialog {
explicit DeviceConfig(QWidget *parent = nullptr);
~DeviceConfig();

static void ConfigureDevice(const _device_ *device, int instance = 0, Settings *settings = nullptr);
static void ConfigureDevice(const _device_ *device, int instance = 0, Settings *settings = nullptr, bool atRuntime = false);
static QString DeviceName(const _device_ *device, const char *internalName, int bus);

private:
Expand Down
19 changes: 19 additions & 0 deletions src/qt/qt_mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "qt_soundgain.hpp"
#include "qt_progsettings.hpp"
#include "qt_mcadevicelist.hpp"
#include "qt_deviceconfig.hpp"

#include "qt_rendererstack.hpp"
#include "qt_renderercommon.hpp"
Expand All @@ -54,6 +55,10 @@ extern "C" {
extern atomic_int acpi_pwrbut_pressed;
extern int acpi_enabled;

extern device_t *devices[256];
extern int devices_instances[256];
extern void *device_priv[256];

#ifdef USE_VNC
# include <86box/vnc.h>
#endif
Expand Down Expand Up @@ -206,6 +211,20 @@ MainWindow::MainWindow(QWidget *parent)

connect(this, &MainWindow::hardResetCompleted, this, [this]() {
ui->actionMCA_devices->setVisible(machine_has_bus(machine, MACHINE_BUS_MCA));
ui->menuDevice_settings->clear();
for (int i = 0; i < 256; i++) {
device_context_t ctx;
if (!devices[i] || (devices[i] && !(devices[i]->flags & DEVICE_RTCONFIG)))
continue;

device_set_context(&ctx, devices[i], devices_instances[i]);

auto action = ui->menuDevice_settings->addAction(QString(ctx.name), [this, ctx, i] {
DeviceConfig::ConfigureDevice(devices[i], devices_instances[i], nullptr, true);
devices[i]->reload_config(device_priv[i]);
endblit();
});
}
QApplication::setOverrideCursor(Qt::ArrowCursor);
#ifdef USE_WACOM
ui->menuTablet_tool->menuAction()->setVisible(mouse_input_mode >= 1);
Expand Down
9 changes: 8 additions & 1 deletion src/qt/qt_mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<x>0</x>
<y>0</y>
<width>724</width>
<height>23</height>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuAction">
Expand Down Expand Up @@ -87,7 +87,14 @@
<property name="title">
<string>&amp;Tools</string>
</property>
<widget class="QMenu" name="menuDevice_settings">
<property name="title">
<string>Device settings...</string>
</property>
<addaction name="separator"/>
</widget>
<addaction name="actionSettings"/>
<addaction name="menuDevice_settings"/>
<addaction name="actionUpdate_status_bar_icons"/>
<addaction name="separator"/>
<addaction name="actionEnable_Discord_integration"/>
Expand Down

0 comments on commit 4543db0

Please sign in to comment.