From 3e70c7e98a2cceed896cdde62bab59651290664b Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Sat, 13 Nov 2021 17:33:43 -0500 Subject: [PATCH] Trivial fixes and cleanups for serial & parallel --- src/config.c | 10 +++++----- src/device/serial.c | 16 ++-------------- src/include/86box/config.h | 4 ++-- src/include/86box/serial.h | 4 +++- src/machine/m_pcjr.c | 2 +- src/machine/m_xt_zenith.c | 2 +- 6 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/config.c b/src/config.c index 0bd8dbfe3..872ed41a2 100644 --- a/src/config.c +++ b/src/config.c @@ -1042,12 +1042,12 @@ load_ports(void) char temp[512]; int c, d; - for (c = 0; c < 4; c++) { + 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); } - for (c = 0; c < 3; c++) { + for (c = 0; c < PARALLEL_MAX; c++) { sprintf(temp, "lpt%d_enabled", c + 1); lpt_ports[c].enabled = !!config_get_int(cat, temp, (c == 0) ? 1 : 0); @@ -1059,7 +1059,7 @@ load_ports(void) /* Legacy config compatibility. */ d = config_get_int(cat, "lpt_enabled", 2); if (d < 2) { - for (c = 0; c < 3; c++) + for (c = 0; c < PARALLEL_MAX; c++) lpt_ports[c].enabled = d; } config_delete_var(cat, "lpt_enabled"); @@ -2512,7 +2512,7 @@ save_ports(void) char temp[512]; int c, d; - for (c = 0; c < 4; c++) { + 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])) config_delete_var(cat, temp); @@ -2520,7 +2520,7 @@ save_ports(void) config_set_int(cat, temp, serial_enabled[c]); } - for (c = 0; c < 3; c++) { + for (c = 0; c < PARALLEL_MAX; c++) { sprintf(temp, "lpt%d_enabled", c + 1); d = (c == 0) ? 1 : 0; if (lpt_ports[c].enabled == d) diff --git a/src/device/serial.c b/src/device/serial.c index 3de0c6826..15527fad4 100644 --- a/src/device/serial.c +++ b/src/device/serial.c @@ -717,20 +717,8 @@ serial_set_next_inst(int ni) void serial_standalone_init(void) { - if (next_inst == 0) { - device_add_inst(&i8250_device, 1); - device_add_inst(&i8250_device, 2); - device_add_inst(&i8250_device, 3); - device_add_inst(&i8250_device, 4); - } else if (next_inst == 1) { - device_add_inst(&i8250_device, 2); - device_add_inst(&i8250_device, 3); - device_add_inst(&i8250_device, 4); - } else if (next_inst == 2) { - device_add_inst(&i8250_device, 3); - device_add_inst(&i8250_device, 4); - } else - device_add_inst(&i8250_device, 4); + for ( ; next_inst < 4; ) + device_add_inst(&i8250_device, next_inst + 1); }; diff --git a/src/include/86box/config.h b/src/include/86box/config.h index 549306daa..b630d0c80 100644 --- a/src/include/86box/config.h +++ b/src/include/86box/config.h @@ -110,9 +110,9 @@ typedef struct { /* Ports category */ char parallel_devices[3][32]; /* LPT device names */ #ifdef USE_SERIAL_DEVICES - char serial_devices[2][32]; /* Serial device names */ + char serial_devices[4][32]; /* Serial device names */ #endif - int serial_enabled[2], /* Serial ports 1 and 2 enabled */ + int serial_enabled[4], /* Serial ports 1 and 2 enabled */ parallel_enabled[3]; /* LPT1, LPT2, LPT3 enabled */ /* Other peripherals category */ diff --git a/src/include/86box/serial.h b/src/include/86box/serial.h index 0b6b99aa5..f580f9f9f 100644 --- a/src/include/86box/serial.h +++ b/src/include/86box/serial.h @@ -27,6 +27,8 @@ #define SERIAL_NS16450 2 #define SERIAL_NS16550 3 +#define SERIAL_FIFO_SIZE 16 + /* Default settings for the standard ports. */ #define SERIAL1_ADDR 0x03f8 #define SERIAL1_IRQ 4 @@ -54,7 +56,7 @@ typedef struct serial_s uint8_t rcvr_fifo_pos, xmit_fifo_pos, pad0, pad1, - rcvr_fifo[16], xmit_fifo[16]; + rcvr_fifo[SERIAL_FIFO_SIZE], xmit_fifo[SERIAL_FIFO_SIZE]; pc_timer_t transmit_timer, timeout_timer; double clock_src, transmit_period; diff --git a/src/machine/m_pcjr.c b/src/machine/m_pcjr.c index 35ddfe6da..482c26ed6 100644 --- a/src/machine/m_pcjr.c +++ b/src/machine/m_pcjr.c @@ -867,7 +867,7 @@ machine_pcjr_init(const machine_t *model) device_add(&fdc_pcjr_device); device_add(&i8250_pcjr_device); - serial_set_next_inst(2); /* So that serial_standalone_init() won't do anything. */ + serial_set_next_inst(MAX_SERIAL); /* So that serial_standalone_init() won't do anything. */ return ret; } diff --git a/src/machine/m_xt_zenith.c b/src/machine/m_xt_zenith.c index 1ca553227..791ebdcd1 100644 --- a/src/machine/m_xt_zenith.c +++ b/src/machine/m_xt_zenith.c @@ -154,7 +154,7 @@ machine_xt_z184_init(const machine_t *model) lpt2_remove(); lpt1_init(0x278); device_add(&i8250_device); - serial_set_next_inst(2); /* So that serial_standalone_init() won't do anything. */ + serial_set_next_inst(MAX_SERIAL); /* So that serial_standalone_init() won't do anything. */ device_add(&cga_device);