From 8b33566187f769ffcd1a0f7f786b5ac9eea82c98 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Thu, 28 Jul 2022 16:50:49 -0400 Subject: [PATCH] More serial cleanups --- src/86box.c | 1 - src/config.c | 21 +++++++++++---------- src/device/serial.c | 8 +++++--- src/include/86box/86box.h | 3 +-- src/include/86box/config.h | 2 -- src/include/86box/serial.h | 6 ++++++ src/qt/qt_settingsports.cpp | 5 +++-- src/win/win_settings.c | 7 ++++--- 8 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/86box.c b/src/86box.c index f6b791901..8569ae53f 100644 --- a/src/86box.c +++ b/src/86box.c @@ -157,7 +157,6 @@ int video_filter_method = 1; /* (C) video */ int video_vsync = 0; /* (C) video */ int video_framerate = -1; /* (C) video */ char video_shader[512] = { '\0' }; /* (C) video */ -int serial_enabled[SERIAL_MAX] = {0,0}; /* (C) enable serial ports */ int bugger_enabled = 0; /* (C) enable ISAbugger */ int postcard_enabled = 0; /* (C) enable POST card */ int isamem_type[ISAMEM_MAX] = { 0,0,0,0 }; /* (C) enable ISA mem cards */ diff --git a/src/config.c b/src/config.c index 81bbc016f..b46bfc22d 100644 --- a/src/config.c +++ b/src/config.c @@ -45,6 +45,7 @@ #include <86box/isamem.h> #include <86box/isartc.h> #include <86box/lpt.h> +#include <86box/serial.h> #include <86box/hdd.h> #include <86box/hdc.h> #include <86box/hdc_ide.h> @@ -1178,7 +1179,7 @@ load_ports(void) for (c = 0; c < SERIAL_MAX; c++) { sprintf(temp, "serial%d_enabled", c + 1); - serial_enabled[c] = !!config_get_int(cat, temp, (c >= 2) ? 0 : 1); + com_ports[c].enabled = !!config_get_int(cat, temp, (c >= 2) ? 0 : 1); /* sprintf(temp, "serial%d_device", c + 1); @@ -2163,10 +2164,10 @@ config_load(void) time_sync = TIME_SYNC_ENABLED; hdc_current = hdc_get_from_internal_name("none"); - serial_enabled[0] = 1; - serial_enabled[1] = 1; + com_ports[0].enabled = 1; + com_ports[1].enabled = 1; for (i = 2; i < SERIAL_MAX; i++) - serial_enabled[i] = 0; + com_ports[i].enabled = 0; lpt_ports[0].enabled = 1; @@ -2684,17 +2685,17 @@ save_ports(void) for (c = 0; c < SERIAL_MAX; c++) { sprintf(temp, "serial%d_enabled", c + 1); - if (((c < 2) && serial_enabled[c]) || ((c >= 2) && !serial_enabled[c])) + if (((c < 2) && com_ports[c].enabled) || ((c >= 2) && !com_ports[c].enabled)) config_delete_var(cat, temp); else - config_set_int(cat, temp, serial_enabled[c]); + config_set_int(cat, temp, com_ports[c].enabled); - /* +/* sprintf(temp, "serial%d_type", c + 1); - if (!serial_enabled[c]) + if (!com_ports[c].enabled)) config_delete_var(cat, temp); - // else - // config_set_string(cat, temp, (char *) serial_type[c]) +// else +// config_set_string(cat, temp, (char *) serial_type[c]) sprintf(temp, "serial%d_device", c + 1); if (com_ports[c].device == 0) diff --git a/src/device/serial.c b/src/device/serial.c index ebc87cd59..67063413f 100644 --- a/src/device/serial.c +++ b/src/device/serial.c @@ -38,6 +38,8 @@ #include <86box/serial.h> #include <86box/mouse.h> +serial_port_t com_ports[SERIAL_MAX]; + enum { SERIAL_INT_LSR = 1, SERIAL_INT_RECEIVE = 2, @@ -578,7 +580,7 @@ serial_remove(serial_t *dev) if (dev == NULL) return; - if (!serial_enabled[dev->inst]) + if (!com_ports[dev->inst].enabled) return; if (!dev->base_address) @@ -599,7 +601,7 @@ serial_setup(serial_t *dev, uint16_t addr, uint8_t irq) if (dev == NULL) return; - if (!serial_enabled[dev->inst]) + if (!com_ports[dev->inst].enabled) return; if (dev->base_address != 0x0000) serial_remove(dev); @@ -650,7 +652,7 @@ serial_init(const device_t *info) dev->inst = next_inst; - if (serial_enabled[next_inst]) { + if (com_ports[next_inst].enabled) { serial_log("Adding serial port %i...\n", next_inst); dev->type = info->local; memset(&(serial_devices[next_inst]), 0, sizeof(serial_device_t)); diff --git a/src/include/86box/86box.h b/src/include/86box/86box.h index 75226e727..93a9fa0a1 100644 --- a/src/include/86box/86box.h +++ b/src/include/86box/86box.h @@ -101,8 +101,7 @@ extern int vid_cga_contrast, /* (C) video */ video_framerate, /* (C) video */ gfxcard; /* (C) graphics/video card */ extern char video_shader[512]; /* (C) video */ -extern int serial_enabled[], /* (C) enable serial ports */ - bugger_enabled, /* (C) enable ISAbugger */ +extern int bugger_enabled, /* (C) enable ISAbugger */ postcard_enabled, /* (C) enable POST card */ isamem_type[], /* (C) enable ISA mem cards */ isartc_type; /* (C) enable ISA RTC card */ diff --git a/src/include/86box/config.h b/src/include/86box/config.h index d84b5d25f..86bf39dce 100644 --- a/src/include/86box/config.h +++ b/src/include/86box/config.h @@ -111,8 +111,6 @@ typedef struct { # ifdef USE_SERIAL_DEVICES char serial_devices[SERIAL_MAX][32]; /* Serial device names */ # endif - int serial_enabled[SERIAL_MAX], /* Serial ports 1, 2, 3, 4 enabled */ - parallel_enabled[PARALLEL_MAX]; /* LPT1, LPT2, LPT3, LPT4 enabled */ /* Other peripherals category */ int fdc_type, /* Floppy disk controller type */ diff --git a/src/include/86box/serial.h b/src/include/86box/serial.h index be1ab957e..9f8bf1b98 100644 --- a/src/include/86box/serial.h +++ b/src/include/86box/serial.h @@ -74,6 +74,12 @@ typedef struct serial_device_s { serial_t *serial; } serial_device_t; +typedef struct { + uint8_t enabled; +} serial_port_t; + +extern serial_port_t com_ports[SERIAL_MAX]; + extern serial_t *serial_attach(int port, void (*rcr_callback)(struct serial_s *serial, void *p), void (*dev_write)(struct serial_s *serial, void *p, uint8_t data), diff --git a/src/qt/qt_settingsports.cpp b/src/qt/qt_settingsports.cpp index 6e0388ede..34c000c87 100644 --- a/src/qt/qt_settingsports.cpp +++ b/src/qt/qt_settingsports.cpp @@ -26,6 +26,7 @@ extern "C" { #include <86box/device.h> #include <86box/machine.h> #include <86box/lpt.h> +#include <86box/serial.h> } #include "qt_deviceconfig.hpp" @@ -63,7 +64,7 @@ SettingsPorts::SettingsPorts(QWidget *parent) : for (int i = 0; i < SERIAL_MAX; i++) { auto* checkBox = findChild(QString("checkBoxSerial%1").arg(i+1)); - checkBox->setChecked(serial_enabled[i] > 0); + checkBox->setChecked(com_ports[i].enabled > 0); } } @@ -82,7 +83,7 @@ void SettingsPorts::save() { for (int i = 0; i < SERIAL_MAX; i++) { auto* checkBox = findChild(QString("checkBoxSerial%1").arg(i+1)); - serial_enabled[i] = checkBox->isChecked() ? 1 : 0; + com_ports[i].enabled = checkBox->isChecked() ? 1 : 0; } } diff --git a/src/win/win_settings.c b/src/win/win_settings.c index d7445867a..bd5451b64 100644 --- a/src/win/win_settings.c +++ b/src/win/win_settings.c @@ -48,6 +48,7 @@ #include <86box/isartc.h> #include <86box/lpt.h> #include <86box/mouse.h> +#include <86box/serial.h> #include <86box/scsi.h> #include <86box/scsi_device.h> #include <86box/cdrom.h> @@ -352,7 +353,7 @@ win_settings_init(void) temp_lpt[i] = lpt_ports[i].enabled; } for (i = 0; i < SERIAL_MAX; i++) - temp_serial[i] = serial_enabled[i]; + temp_serial[i] = com_ports[i].enabled; /* Storage devices category */ for (i = 0; i < SCSI_BUS_MAX; i++) @@ -474,7 +475,7 @@ win_settings_changed(void) i = i || (temp_lpt[j] != lpt_ports[j].enabled); } for (j = 0; j < SERIAL_MAX; j++) - i = i || (temp_serial[j] != serial_enabled[j]); + i = i || (temp_serial[j] != com_ports[j].enabled); /* Storage devices category */ for (j = 0; j < SCSI_BUS_MAX; j++) @@ -567,7 +568,7 @@ win_settings_save(void) lpt_ports[i].enabled = temp_lpt[i]; } for (i = 0; i < SERIAL_MAX; i++) - serial_enabled[i] = temp_serial[i]; + com_ports[i].enabled = temp_serial[i]; /* Storage devices category */ for (i = 0; i < SCSI_BUS_MAX; i++)