From 66de82370fd9f609fefd119a6c63539c43b6abd4 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sun, 7 May 2023 14:09:48 +0200 Subject: [PATCH 01/34] Remove the last hardcoded memset from the USB code. --- src/usb.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/usb.c b/src/usb.c index 5b5e68bf2..fbe07a790 100644 --- a/src/usb.c +++ b/src/usb.c @@ -387,7 +387,7 @@ ohci_mmio_write(uint32_t addr, uint8_t val, void *p) /* bit HostControllerReset must be cleared for the controller to be seen as initialized */ if (val & 0x01) { - memset(dev->ohci_mmio, 0x00, 4096); + memset(dev->ohci_mmio, 0x00, sizeof(dev->ohci_mmio)); dev->ohci_mmio[OHCI_HcRevision].b[0] = 0x10; dev->ohci_mmio[OHCI_HcRevision].b[1] = 0x01; dev->ohci_mmio[OHCI_HcRhDescriptorA].b[0] = 0x02; @@ -673,10 +673,9 @@ usb_init_ext(const device_t *info, void *params) { usb_t *dev; - dev = (usb_t *) malloc(sizeof(usb_t)); + dev = (usb_t *) calloc(1, sizeof(usb_t)); if (dev == NULL) return (NULL); - memset(dev, 0x00, sizeof(usb_t)); dev->usb_params = (usb_params_t *) params; From ee4ee8e1bd50817facc805fcd4592f5433db9018 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sun, 7 May 2023 14:11:08 +0200 Subject: [PATCH 02/34] UPI-42. --- src/upi42.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/upi42.c b/src/upi42.c index 6937644ad..4c22c5ed5 100644 --- a/src/upi42.c +++ b/src/upi42.c @@ -1003,7 +1003,7 @@ upi42_reset(upi42_t *upi42) void upi42_do_init(upi32_t type, uint8_t *rom) { - memset(upi42, 0, sizeof(upi42_t)); + memset(upi42, 0x00, sizeof(upi42_t)); upi42->rom = rom; /* Set chip type. */ @@ -1022,7 +1022,7 @@ upi42_do_init(upi32_t type, uint8_t *rom) upi42->ops[0xe2] = NULL; /* SUSPEND */ } - memset(upi42_t->ports_in, 0xff, 0x08); + memset(upi42_t->ports_in, 0xff, sizeof(upi42_t->ports_in)); upi42_t->t0 = 1; upi42_t->t1 = 1; } From a6086c451e1bfc9d83d8582800ff71f049865ba5 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Mon, 8 May 2023 00:50:00 +0600 Subject: [PATCH 03/34] usb: Start finalizing work on OHCI --- src/include/86box/usb.h | 53 ++++++++++++++++------------- src/usb.c | 75 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 103 insertions(+), 25 deletions(-) diff --git a/src/include/86box/usb.h b/src/include/86box/usb.h index 4c6fc289b..1f5413cd7 100644 --- a/src/include/86box/usb.h +++ b/src/include/86box/usb.h @@ -24,6 +24,33 @@ extern "C" { typedef struct usb_t usb_t; +/* USB endpoint device struct. Incomplete and unused. */ +typedef struct +{ + uint16_t vendor_id; + uint16_t device_id; + + /* Reads from endpoint. Non-zero value indicates error. */ + uint8_t (*device_in)(void* priv, uint8_t* data, uint32_t len); + /* Writes to endpoint. Non-zero value indicates error. */ + uint8_t (*device_out)(void* priv, uint8_t* data, uint32_t len); + /* Process setup packets. */ + uint8_t (*device_setup)(void* priv, uint8_t* data); + /* Device reset. */ + void (*device_reset)(void* priv); + /* Get address. */ + uint8_t (*device_get_address)(void* priv); + + void* priv; +} usb_device_t; + +enum usb_bus_types +{ + USB_BUS_OHCI = 0, + USB_BUS_UHCI, + USB_BUS_MAX +}; + /* USB device creation parameters struct */ typedef struct { @@ -52,6 +79,8 @@ typedef struct usb_t pc_timer_t ohci_frame_timer; pc_timer_t ohci_port_reset_timer[2]; uint8_t ohci_interrupt_counter : 3; + usb_device_t* ohci_devices[2]; + usb_device_t* uhci_devices[2]; usb_params_t* usb_params; } usb_t; @@ -79,30 +108,6 @@ typedef struct #pragma pack(pop) -/* USB endpoint device struct. Incomplete and unused. */ -typedef struct -{ - uint16_t vendor_id; - uint16_t device_id; - - /* Reads from endpoint. Non-zero value indicates error. */ - uint8_t (*device_in)(void* priv, uint8_t* data, uint32_t len); - /* Writes to endpoint. Non-zero value indicates error. */ - uint8_t (*device_out)(void* priv, uint8_t* data, uint32_t len); - /* Process setup packets. */ - uint8_t (*device_setup)(void* priv, uint8_t* data); - /* Device reset */ - void (*device_reset)(void* priv); - - void* priv; -} usb_device_t; - -enum usb_bus_types -{ - USB_BUS_OHCI = 0, - USB_BUS_UHCI = 1 -}; - /* Global variables. */ extern const device_t usb_device; diff --git a/src/usb.c b/src/usb.c index 03b5f6546..0b9a8255f 100644 --- a/src/usb.c +++ b/src/usb.c @@ -371,12 +371,85 @@ ohci_set_interrupt(usb_t *dev, uint8_t bit) ohci_update_irq(dev); } +/* Next two functions ported over from QEMU. */ +static int ohci_copy_td_input(usb_t* dev, usb_td_t *td, + uint8_t *buf, int len) +{ + uint32_t ptr, n; + + ptr = td->CBP; + n = 0x1000 - (ptr & 0xfff); + if (n > len) { + n = len; + } + dma_bm_write(ptr, buf, n, 1); + if (n == len) { + return 0; + } + ptr = td->BE & ~0xfffu; + buf += n; + dma_bm_write(ptr, buf, len - n, 1); + return 0; +} + +static int ohci_copy_td_output(usb_t* dev, usb_td_t *td, + uint8_t *buf, int len) +{ + uint32_t ptr, n; + + ptr = td->CBP; + n = 0x1000 - (ptr & 0xfff); + if (n > len) { + n = len; + } + dma_bm_read(ptr, buf, n, 1); + if (n == len) { + return 0; + } + ptr = td->BE & ~0xfffu; + buf += n; + dma_bm_read(ptr, buf, len - n, 1); + return 0; +} + +uint8_t +ohci_service_transfer_desc(usb_t* dev, usb_ed_t* endpoint_desc) +{ + +} + uint8_t ohci_service_endpoint_desc(usb_t* dev, uint32_t head) { usb_ed_t endpoint_desc; + uint8_t active = 0; + uint32_t next = 0; + uint32_t cur = 0; + uint32_t limit_counter = 0; + + if (head == 0) + return 0; - return 0; + for (cur = head; cur && limit_counter++ < ENDPOINT_DESC_LIMIT; cur = next) { + dma_bm_read(cur, (uint8_t*)&endpoint_desc, sizeof(usb_ed_t), 4); + + next = endpoint_desc.NextED & ~(0xFu); + + if (endpoint_desc.flags.Skip || endpoint_desc.flags_2.Halted) + continue; + + if (endpoint_desc.flags.Format) { + fatal("OHCI: Isochronous transfers not implemented!\n"); + } + + while ((endpoint_desc.HeadP & ~(0xFu)) != endpoint_desc.TailP) { + ohci_service_transfer_desc(dev, &endpoint_desc); + } + + dma_bm_write(cur, (uint8_t*)&endpoint_desc, sizeof(usb_ed_t), 4); + } + + return active; } void From db568b8658b8c0ebc08efea6796bf37a133fa5c7 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sun, 7 May 2023 22:59:18 +0200 Subject: [PATCH 04/34] Correct the floatx80_abs() and floatx80_chs() declarations when used with C++ code - fixes the sign in some trigonometric instruction, fixes Quake on SoftFloat. --- src/cpu/softfloat/softfloatx80.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cpu/softfloat/softfloatx80.h b/src/cpu/softfloat/softfloatx80.h index 8378169e2..1f96141b4 100644 --- a/src/cpu/softfloat/softfloatx80.h +++ b/src/cpu/softfloat/softfloatx80.h @@ -80,7 +80,11 @@ int floatx80_compare_quiet(floatx80 a, floatx80 b, struct float_status_t *status | for Binary Floating-Point Arithmetic. *----------------------------------------------------------------------------*/ +#ifdef __cplusplus +BX_CPP_INLINE floatx80& floatx80_abs(floatx80 ®) +#else BX_CPP_INLINE floatx80 floatx80_abs(floatx80 reg) +#endif { reg.exp &= 0x7FFF; return reg; @@ -92,7 +96,11 @@ BX_CPP_INLINE floatx80 floatx80_abs(floatx80 reg) | Floating-Point Arithmetic. *----------------------------------------------------------------------------*/ +#ifdef __cplusplus +BX_CPP_INLINE floatx80& floatx80_chs(floatx80 ®) +#else BX_CPP_INLINE floatx80 floatx80_chs(floatx80 reg) +#endif { reg.exp ^= 0x8000; return reg; From 9c09d4260ed4bd88365a442977efc195d048e359 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Mon, 8 May 2023 16:51:16 +0600 Subject: [PATCH 05/34] usb: Finish work on OHCI --- src/include/86box/usb.h | 25 +++- src/usb.c | 260 ++++++++++++++++++++++++++++++++-------- 2 files changed, 229 insertions(+), 56 deletions(-) diff --git a/src/include/86box/usb.h b/src/include/86box/usb.h index 1f5413cd7..b9497b92e 100644 --- a/src/include/86box/usb.h +++ b/src/include/86box/usb.h @@ -24,18 +24,29 @@ extern "C" { typedef struct usb_t usb_t; +enum usb_pid +{ + USB_PID_OUT = 0xE1, + USB_PID_IN = 0x69, + USB_PID_SETUP = 0x2D +}; + +enum usb_errors +{ + USB_ERROR_NO_ERROR = 0, + USB_ERROR_NAK = 1, + USB_ERROR_OVERRUN = 2, + USB_ERROR_UNDERRUN = 3 +}; + /* USB endpoint device struct. Incomplete and unused. */ typedef struct { uint16_t vendor_id; uint16_t device_id; - /* Reads from endpoint. Non-zero value indicates error. */ - uint8_t (*device_in)(void* priv, uint8_t* data, uint32_t len); - /* Writes to endpoint. Non-zero value indicates error. */ - uint8_t (*device_out)(void* priv, uint8_t* data, uint32_t len); - /* Process setup packets. */ - uint8_t (*device_setup)(void* priv, uint8_t* data); + /* General-purpose function for I/O. Non-zero value indicates error. */ + uint8_t (*device_process)(void* priv, uint8_t* data, uint32_t *len, uint8_t pid_token, uint8_t endpoint, uint8_t underrun_not_allowed); /* Device reset. */ void (*device_reset)(void* priv); /* Get address. */ @@ -81,6 +92,8 @@ typedef struct usb_t uint8_t ohci_interrupt_counter : 3; usb_device_t* ohci_devices[2]; usb_device_t* uhci_devices[2]; + uint8_t ohci_usb_buf[4096]; + uint8_t ohci_initial_start; usb_params_t* usb_params; } usb_t; diff --git a/src/usb.c b/src/usb.c index 0b9a8255f..f6262e11f 100644 --- a/src/usb.c +++ b/src/usb.c @@ -22,6 +22,7 @@ #include #include #include +#include #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/device.h> @@ -238,20 +239,7 @@ typedef struct /* Transfer descriptors */ typedef struct { - union - { - uint32_t Control; - struct - { - uint32_t Reserved : 18; - uint8_t bufferRounding : 1; - uint8_t Direction : 2; - uint8_t DelayInterrupt : 3; - uint8_t DataToggle : 2; - uint8_t ErrorCount : 2; - uint8_t ConditionCode : 4; - } flags; - }; + uint32_t Control; uint32_t CBP; uint32_t NextTD; uint32_t BE; @@ -260,31 +248,9 @@ typedef struct /* Endpoint descriptors */ typedef struct { - union - { - uint32_t Control; - struct - { - uint8_t FunctionAddress : 7; - uint8_t EndpointNumber : 4; - uint8_t Direction : 2; - bool Speed : 1; - bool Skip : 1; - bool Format : 1; - uint16_t MaximumPacketSize : 11; - uint8_t Reserved : 5; - } flags; - }; + uint32_t Control; uint32_t TailP; - union - { - uint32_t HeadP; - struct - { - bool Halted : 1; - bool toggleCarry : 1; - } flags_2; - }; + uint32_t HeadP; uint32_t NextED; } usb_ed_t; @@ -368,6 +334,8 @@ ohci_set_interrupt(usb_t *dev, uint8_t bit) dev->ohci_mmio[OHCI_HcInterruptStatus].b[0] |= bit; + /* TODO: Does setting UnrecoverableError also assert PERR# on any emulated USB chipsets? */ + ohci_update_irq(dev); } @@ -412,10 +380,136 @@ static int ohci_copy_td_output(usb_t* dev, usb_td_t *td, return 0; } +#define OHCI_TD_DIR(val) ((val >> 19) & 3) +#define OHCI_ED_DIR(val) ((val >> 11) & 3) + uint8_t ohci_service_transfer_desc(usb_t* dev, usb_ed_t* endpoint_desc) { + uint32_t td_addr = endpoint_desc->HeadP & ~(0xf); + usb_td_t td; + uint8_t dir, pid_token; + uint32_t len = 0, pktlen = 0; + uint32_t actual_length = 0; + uint32_t i = 0; + uint8_t device_result = 0; + usb_device_t* target = NULL; + dma_bm_read(td_addr, (uint8_t*)&td, sizeof(usb_td_t), 4); + + switch (dir = OHCI_ED_DIR(endpoint_desc->Control)) { + case 1: + case 2: + break; + default: + dir = OHCI_TD_DIR(td.Control); + break; + } + + switch (dir) { + case 0: /* Setup */ + pid_token = USB_PID_SETUP; + break; + case 1: /* OUT */ + pid_token = USB_PID_OUT; + break; + case 2: /* IN */ + pid_token = USB_PID_IN; + break; + } + + if (td.CBP && td.BE) { + if ((td.CBP & 0xfffff000) != (td.BE & 0xfffff000)) { + len = (td.BE & 0xfff) + 0x1001 - (td.CBP & 0xfff); + } else { + if (td.CBP > td.BE) { + ohci_set_interrupt(dev, OHCI_HcInterruptEnable_UE); + return 1; + } + + len = (td.BE - td.CBP) + 1; + } + if (len > sizeof(dev->ohci_usb_buf)) { + len = sizeof(dev->ohci_usb_buf); + } + + pktlen = len; + if (len && pid_token != USB_PID_IN) { + pktlen = (endpoint_desc->Control >> 16) & 0xFFF; + if (pktlen > len) { + pktlen = len; + } + ohci_copy_td_output(dev, &td, dev->ohci_usb_buf, pktlen); + } + } + + for (i = 0; i < 2; i++) { + if (!dev->ohci_devices[i]) + continue; + + assert(dev->ohci_devices[i]->device_get_address != NULL); + + if (dev->ohci_devices[i]->device_get_address(dev->ohci_devices[i]->priv) != (endpoint_desc->Control & 0x7f)) + continue; + + target = dev->ohci_devices[i]; + break; + } + + if (!target) + return 1; + + device_result = target->device_process(target->priv, dev->ohci_usb_buf, &actual_length, pid_token, (endpoint_desc->Control & 0x780) >> 7, !(endpoint_desc->Control & (1 << 18))); + + if ((actual_length == pktlen) || (pid_token == USB_PID_IN && (endpoint_desc->Control & (1 << 18)) && device_result == USB_ERROR_NO_ERROR)) { + if (len == actual_length) { + td.CBP = 0; + } else { + if ((td.CBP & 0xfff) + actual_length > 0xfff) { + td.CBP = (td.BE & ~0xfff) + ((td.CBP + actual_length) & 0xfff); + } else { + td.CBP += actual_length; + } + } + + td.Control |= (1 << 25); /* dataToggle[1] */ + td.Control ^= (1 << 24); /* dataToggle[0] */ + td.Control &= ~0xFC000000; /* Set both ErrorCount and ConditionCode to 0. */ + + if (pid_token != USB_PID_IN && len != actual_length) { + goto exit_no_retire; + } + + endpoint_desc->HeadP &= ~0x2; + if (td.Control & (1 << 24)) { + endpoint_desc->HeadP |= 0x2; + } + } else { + if (actual_length != 0xFFFFFFFF && actual_length >= 0) { + td.Control &= ~0xF0000000; + td.Control |= 0x90000000; + } else { + switch (device_result) { + case USB_ERROR_NAK: + return 1; + } + dev->ohci_interrupt_counter = 0; + } + + endpoint_desc->HeadP |= 0x1; + } + + endpoint_desc->HeadP &= 0xf; + endpoint_desc->HeadP |= td.NextTD & ~0xf; + td.NextTD = dev->ohci_mmio[OHCI_HcDoneHead].l; + dev->ohci_mmio[OHCI_HcDoneHead].l = td_addr; + i = (td.Control >> 21) & 7; + if (i < dev->ohci_interrupt_counter) { + dev->ohci_interrupt_counter = i; + } +exit_no_retire: + dma_bm_write(td_addr, (uint8_t*)&td, sizeof(usb_td_t), 4); + return !(td.Control & 0xF0000000); } uint8_t @@ -435,13 +529,15 @@ ohci_service_endpoint_desc(usb_t* dev, uint32_t head) next = endpoint_desc.NextED & ~(0xFu); - if (endpoint_desc.flags.Skip || endpoint_desc.flags_2.Halted) + if ((endpoint_desc.Control & (1 << 13)) || (endpoint_desc.HeadP & (1 << 0))) continue; - if (endpoint_desc.flags.Format) { + if (endpoint_desc.Control & 0x8000) { fatal("OHCI: Isochronous transfers not implemented!\n"); } + active = 1; + while ((endpoint_desc.HeadP & ~(0xFu)) != endpoint_desc.TailP) { ohci_service_transfer_desc(dev, &endpoint_desc); } @@ -549,6 +645,23 @@ ohci_port_reset_callback_2(void* priv) dev->ohci_mmio[OHCI_HcRhPortStatus2].b[2] |= 0x10; } +static void +ohci_soft_reset(usb_t* dev) +{ + uint32_t old_HcControl = (dev->ohci_mmio[OHCI_HcControl].l & 0x100) | 0xc0; + memset(dev->ohci_mmio, 0x00, 4096); + dev->ohci_mmio[OHCI_HcRevision].b[0] = 0x10; + dev->ohci_mmio[OHCI_HcRevision].b[1] = 0x01; + dev->ohci_mmio[OHCI_HcRhDescriptorA].b[0] = 0x02; + dev->ohci_mmio[OHCI_HcRhDescriptorA].b[1] = 0x02; + dev->ohci_mmio[OHCI_HcFmInterval].l = 0x27782edf; /* FrameInterval = 11999, FSLargestDataPacket = 10104 */ + dev->ohci_mmio[OHCI_HcLSThreshold].l = 0x628; + dev->ohci_mmio[OHCI_HcInterruptEnable].l |= (1 << 31); + dev->ohci_mmio[OHCI_HcControl].l = old_HcControl; + dev->ohci_interrupt_counter = 7; + ohci_update_irq(dev); +} + static void ohci_mmio_write(uint32_t addr, uint8_t val, void *p) { @@ -563,9 +676,19 @@ ohci_mmio_write(uint32_t addr, uint8_t val, void *p) switch (addr) { case OHCI_aHcControl: + old = dev->ohci_mmio[OHCI_HcControl].b[0]; if ((val & 0xc0) == 0x00) { /* UsbReset */ dev->ohci_mmio[OHCI_HcRhPortStatus1].b[2] = dev->ohci_mmio[OHCI_HcRhPortStatus2].b[2] = 0x16; + for (int i = 0; i < 2; i++) { + if (dev->ohci_devices[i]) { + dev->ohci_devices[i]->device_reset(dev->ohci_devices[i]->priv); + } + } + } else if ((val & 0xc0) == 0x80 && (old & 0xc0) != (val & 0xc0)) { + dev->ohci_mmio[OHCI_HcFmRemaining].l = 0; + dev->ohci_initial_start = 1; + timer_on_auto(&dev->ohci_frame_timer, 1000.); } break; case OHCI_aHcCommandStatus: @@ -578,10 +701,7 @@ ohci_mmio_write(uint32_t addr, uint8_t val, void *p) /* bit HostControllerReset must be cleared for the controller to be seen as initialized */ if (val & 0x01) { - memset(dev->ohci_mmio, 0x00, 4096); - dev->ohci_mmio[OHCI_HcRevision].b[0] = 0x10; - dev->ohci_mmio[OHCI_HcRevision].b[1] = 0x01; - dev->ohci_mmio[OHCI_HcRhDescriptorA].b[0] = 0x02; + ohci_soft_reset(dev); val &= ~0x01; } break; @@ -722,6 +842,8 @@ ohci_mmio_write(uint32_t addr, uint8_t val, void *p) if (old & 0x01) { dev->ohci_mmio[addr >> 2].b[addr & 3] |= 0x10; timer_on_auto(&dev->ohci_port_reset_timer[(addr - OHCI_aHcRhPortStatus1) / 4], 10000.); + if (dev->ohci_devices[(addr - OHCI_aHcRhPortStatus1) >> 2]) + dev->ohci_devices[(addr - OHCI_aHcRhPortStatus1) >> 2]->device_reset(dev->ohci_devices[(addr - OHCI_aHcRhPortStatus1) >> 2]->priv); } else dev->ohci_mmio[(addr + 2) >> 2].b[(addr + 2) & 3] |= 0x01; } @@ -817,13 +939,54 @@ ohci_update_mem_mapping(usb_t *dev, uint8_t base1, uint8_t base2, uint8_t base3, uint8_t usb_attach_device(usb_t *dev, usb_device_t* device, uint8_t bus_type) { + switch (bus_type) { + case USB_BUS_OHCI: + { + for (int i = 0; i < 2; i++) { + if (!dev->ohci_devices[i]) { + dev->ohci_devices[i] = device; + dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].b[0] |= 0x1; + dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].b[2] |= 0x1; + if ((dev->ohci_mmio[OHCI_HcControl].b[0] & 0xc0) == 0xc0) { + ohci_set_interrupt(dev, OHCI_HcInterruptEnable_RD); + } + ohci_set_interrupt(dev, OHCI_HcInterruptEnable_RHSC); + return i; + } + } + } + break; + } return 255; } void usb_detach_device(usb_t *dev, uint8_t port, uint8_t bus_type) { - /* Unused. */ + switch (bus_type) { + case USB_BUS_OHCI: + { + for (int i = 0; i < 2; i++) { + if (dev->ohci_devices[i]) { + uint32_t old = dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].l; + dev->ohci_devices[i] = NULL; + if (dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].b[0] & 0x1) { + dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].b[0] &= ~0x1; + dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].b[2] |= 0x1; + } + if (dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].b[0] & 0x2) { + dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].b[0] &= ~0x2; + dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].b[2] |= 0x2; + } + if (old != dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].l) + ohci_set_interrupt(dev, OHCI_HcInterruptEnable_RHSC); + return; + } + } + } + break; + } + return; } static void @@ -835,11 +998,8 @@ usb_reset(void *priv) dev->uhci_io[0x0c] = 0x40; dev->uhci_io[0x10] = dev->uhci_io[0x12] = 0x80; - memset(dev->ohci_mmio, 0x00, sizeof(dev->ohci_mmio)); - dev->ohci_mmio[OHCI_HcRevision].b[0] = 0x10; - dev->ohci_mmio[OHCI_HcRevision].b[1] = 0x01; - dev->ohci_mmio[OHCI_HcRhDescriptorA].b[0] = 0x02; - dev->ohci_mmio[OHCI_HcRhDescriptorA].b[1] = 0x02; + ohci_soft_reset(dev); + dev->ohci_mmio[OHCI_HcControl].l = 0x00; io_removehandler(dev->uhci_io_base, 0x20, uhci_reg_read, NULL, NULL, uhci_reg_write, uhci_reg_writew, NULL, dev); dev->uhci_enable = 0; From 2fac3e5dc59b26e0e5e43c25be7bd56e52e93d95 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Mon, 8 May 2023 17:13:34 +0600 Subject: [PATCH 06/34] usb: don't process EOF on very first SOF --- src/usb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/usb.c b/src/usb.c index f6262e11f..1dd6aa02c 100644 --- a/src/usb.c +++ b/src/usb.c @@ -552,7 +552,8 @@ void ohci_end_of_frame(usb_t* dev) { usb_hcca_t hcca; - /* TODO: Put endpoint and transfer descriptor processing here. */ + if (dev->ohci_initial_start) + return; dma_bm_read(dev->ohci_mmio[OHCI_HcHCCA].l, (uint8_t*)&hcca, sizeof(usb_hcca_t), 4); if (dev->ohci_mmio[OHCI_HcControl].l & OHCI_HcControl_PeriodicListEnable) { @@ -605,6 +606,7 @@ ohci_end_of_frame(usb_t* dev) void ohci_start_of_frame(usb_t* dev) { + dev->ohci_initial_start = 0; ohci_set_interrupt(dev, OHCI_HcInterruptEnable_SO); } From 50b0fe499086fa36b85ecc214fa5332a7c109945 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Mon, 8 May 2023 22:30:28 +0600 Subject: [PATCH 07/34] usb: Add ability to attach and detach devices for real --- src/include/86box/usb.h | 1 + src/usb.c | 50 +++++++++++++++++++++++++---------------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/include/86box/usb.h b/src/include/86box/usb.h index b9497b92e..4dbec55c3 100644 --- a/src/include/86box/usb.h +++ b/src/include/86box/usb.h @@ -123,6 +123,7 @@ typedef struct /* Global variables. */ extern const device_t usb_device; +extern usb_t* usb_device_inst; /* Functions. */ extern void uhci_update_io_mapping(usb_t *dev, uint8_t base_l, uint8_t base_h, int enable); diff --git a/src/usb.c b/src/usb.c index 1dd6aa02c..2ef5bb895 100644 --- a/src/usb.c +++ b/src/usb.c @@ -129,6 +129,8 @@ enum OHCI_HcControl_BulkListEnable = 1 << 4 }; +usb_t* usb_device_inst = NULL; + static void usb_interrupt_ohci(usb_t *dev, uint32_t level) { @@ -851,8 +853,12 @@ ohci_mmio_write(uint32_t addr, uint8_t val, void *p) } if (val & 0x08) dev->ohci_mmio[addr >> 2].b[addr & 3] &= ~0x04; - if (val & 0x04) - dev->ohci_mmio[addr >> 2].b[addr & 3] |= 0x04; + if (val & 0x04) { + if (old & 0x01) + dev->ohci_mmio[addr >> 2].b[addr & 3] |= 0x04; + else + dev->ohci_mmio[(addr + 2) >> 2].b[(addr + 2) & 3] |= 0x01; + } if (val & 0x02) { if (old & 0x01) dev->ohci_mmio[addr >> 2].b[addr & 3] |= 0x02; @@ -946,13 +952,16 @@ usb_attach_device(usb_t *dev, usb_device_t* device, uint8_t bus_type) { for (int i = 0; i < 2; i++) { if (!dev->ohci_devices[i]) { + uint32_t old = dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].l; dev->ohci_devices[i] = device; dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].b[0] |= 0x1; - dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].b[2] |= 0x1; if ((dev->ohci_mmio[OHCI_HcControl].b[0] & 0xc0) == 0xc0) { ohci_set_interrupt(dev, OHCI_HcInterruptEnable_RD); } - ohci_set_interrupt(dev, OHCI_HcInterruptEnable_RHSC); + if (old != dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].l) { + dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].b[2] |= 0x1; + ohci_set_interrupt(dev, OHCI_HcInterruptEnable_RHSC); + } return i; } } @@ -968,23 +977,24 @@ usb_detach_device(usb_t *dev, uint8_t port, uint8_t bus_type) switch (bus_type) { case USB_BUS_OHCI: { - for (int i = 0; i < 2; i++) { - if (dev->ohci_devices[i]) { - uint32_t old = dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].l; - dev->ohci_devices[i] = NULL; - if (dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].b[0] & 0x1) { - dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].b[0] &= ~0x1; - dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].b[2] |= 0x1; - } - if (dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].b[0] & 0x2) { - dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].b[0] &= ~0x2; - dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].b[2] |= 0x2; - } - if (old != dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * i)].l) - ohci_set_interrupt(dev, OHCI_HcInterruptEnable_RHSC); - return; + if (port > 2) + return; + if (dev->ohci_devices[port]) { + uint32_t old = dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * port)].l; + dev->ohci_devices[port] = NULL; + if (dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * port)].b[0] & 0x1) { + dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * port)].b[0] &= ~0x1; + dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * port)].b[2] |= 0x1; } + if (dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * port)].b[0] & 0x2) { + dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * port)].b[0] &= ~0x2; + dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * port)].b[2] |= 0x2; + } + if (old != dev->ohci_mmio[OHCI_HcRhPortStatus1 + (4 * port)].l) + ohci_set_interrupt(dev, OHCI_HcInterruptEnable_RHSC); + return; } + } break; } @@ -1046,6 +1056,8 @@ usb_init_ext(const device_t *info, void *params) usb_reset(dev); + usb_device_inst = dev; + return dev; } From efedd983eb89496b1ddcae6fb83227ee804014bc Mon Sep 17 00:00:00 2001 From: cold-brewed Date: Mon, 8 May 2023 13:05:01 -0400 Subject: [PATCH 08/34] network: Add null network driver and make it the default mode --- src/include/86box/network.h | 6 +- src/network/CMakeLists.txt | 2 +- src/network/net_null.c | 224 ++++++++++++++++++++++++++++++++++ src/network/network.c | 48 ++++++-- src/qt/qt_mediamenu.cpp | 2 +- src/qt/qt_settingsnetwork.cpp | 9 +- src/win/languages/dialogs.rc | 8 +- src/win/win_settings.c | 2 +- 8 files changed, 277 insertions(+), 24 deletions(-) create mode 100644 src/network/net_null.c diff --git a/src/include/86box/network.h b/src/include/86box/network.h index 4f514d1ac..a49193de0 100644 --- a/src/include/86box/network.h +++ b/src/include/86box/network.h @@ -48,7 +48,7 @@ #include /* Network provider types. */ -#define NET_TYPE_NONE 0 /* networking disabled */ +#define NET_TYPE_NONE 0 /* use the null network driver */ #define NET_TYPE_SLIRP 1 /* use the SLiRP port forwarder */ #define NET_TYPE_PCAP 2 /* use the (Win)Pcap API */ #define NET_TYPE_VDE 3 /* use the VDE plug API */ @@ -57,6 +57,7 @@ /* Queue size must be a power of 2 */ #define NET_QUEUE_LEN 16 #define NET_QUEUE_LEN_MASK (NET_QUEUE_LEN - 1) +#define NET_QUEUE_COUNT 3 #define NET_CARD_MAX 4 #define NET_HOST_INTF_MAX 64 @@ -125,6 +126,7 @@ typedef struct netdrv_t { extern const netdrv_t net_pcap_drv; extern const netdrv_t net_slirp_drv; extern const netdrv_t net_vde_drv; +extern const netdrv_t net_null_drv; struct _netcard_t { const device_t *device; @@ -132,7 +134,7 @@ struct _netcard_t { struct netdrv_t host_drv; NETRXCB rx; NETSETLINKSTATE set_link_state; - netqueue_t queues[3]; + netqueue_t queues[NET_QUEUE_COUNT]; netpkt_t queued_pkt; mutex_t *tx_mutex; mutex_t *rx_mutex; diff --git a/src/network/CMakeLists.txt b/src/network/CMakeLists.txt index c6178a790..94e066a19 100644 --- a/src/network/CMakeLists.txt +++ b/src/network/CMakeLists.txt @@ -14,7 +14,7 @@ # set(net_sources) list(APPEND net_sources network.c net_pcap.c net_slirp.c net_dp8390.c net_3c501.c - net_3c503.c net_ne2000.c net_pcnet.c net_wd8003.c net_plip.c net_event.c) + net_3c503.c net_ne2000.c net_pcnet.c net_wd8003.c net_plip.c net_event.c net_null.c) option(SLIRP_EXTERNAL "Link against the system-provided libslirp library" OFF) mark_as_advanced(SLIRP_EXTERNAL) diff --git a/src/network/net_null.c b/src/network/net_null.c new file mode 100644 index 000000000..e69b4acb6 --- /dev/null +++ b/src/network/net_null.c @@ -0,0 +1,224 @@ +/* +* 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. +* +* This file is part of the 86Box distribution. +* +* Null network driver +* +* +* +* Authors: cold-brewed +* +* Copyright 2023 The 86Box development team +*/ + +#include +#include +#include +#include +#include +#include +#include +#ifdef _WIN32 +# define WIN32_LEAN_AND_MEAN +# include +# include +#else +# include +#endif + +#define HAVE_STDARG_H +#include <86box/86box.h> +#include <86box/device.h> +#include <86box/thread.h> +#include <86box/timer.h> +#include <86box/network.h> +#include <86box/net_event.h> + +enum { + NET_EVENT_STOP = 0, + NET_EVENT_TX, + NET_EVENT_RX, + NET_EVENT_MAX +}; + +/* Special define for the windows portion. Because we are not interested + * in NET_EVENT_RX for the null driver, we only need to poll up to + * NET_EVENT_TX. NET_EVENT_RX gives us a different NET_EVENT_MAX + * excluding NET_EVENT_RX. */ +#define NET_EVENT_TX_MAX NET_EVENT_RX + +#define NULL_PKT_BATCH NET_QUEUE_LEN + +typedef struct { + uint8_t mac_addr[6]; + netcard_t *card; + thread_t *poll_tid; + net_evt_t tx_event; + net_evt_t stop_event; + netpkt_t pkt; + netpkt_t pktv[NULL_PKT_BATCH]; +} net_null_t; + +#ifdef ENABLE_NET_NULL_LOG +int net_null_do_log = ENABLE_NET_NULL_LOG; + +static void +net_null_log(const char *fmt, ...) +{ + va_list ap; + + if (net_null_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define net_null_log(fmt, ...) +#endif + +#ifdef _WIN32 +static void +net_null_thread(void *priv) +{ + net_null_t *net_null = (net_null_t *) priv; + + net_null_log("Null Network: polling started.\n"); + + HANDLE events[NET_EVENT_TX_MAX]; + events[NET_EVENT_STOP] = net_event_get_handle(&net_null->stop_event); + events[NET_EVENT_TX] = net_event_get_handle(&net_null->tx_event); + + bool run = true; + + while (run) { + int ret = WaitForMultipleObjects(NET_EVENT_TX_MAX, events, FALSE, INFINITE); + + switch (ret - WAIT_OBJECT_0) { + case NET_EVENT_STOP: + net_event_clear(&net_null->stop_event); + run = false; + break; + + case NET_EVENT_TX: + net_event_clear(&net_null->tx_event); + int packets = network_tx_popv(net_null->card, net_null->pktv, NULL_PKT_BATCH); + for (int i = 0; i < packets; i++) { + net_null_log("Null Network: Ignoring TX packet (%d bytes)\n", net_null->pktv[i].len); + } + break; + + default: + net_null_log("Null Network: Unknown event.\n"); + break; + } + } + + net_null_log("Null Network: polling stopped.\n"); +} +#else +static void +net_null_thread(void *priv) +{ + net_null_t *net_null = (net_null_t *) priv; + + net_null_log("Null Network: polling started.\n"); + + struct pollfd pfd[NET_EVENT_MAX]; + pfd[NET_EVENT_STOP].fd = net_event_get_fd(&net_null->stop_event); + pfd[NET_EVENT_STOP].events = POLLIN | POLLPRI; + + pfd[NET_EVENT_TX].fd = net_event_get_fd(&net_null->tx_event); + pfd[NET_EVENT_TX].events = POLLIN | POLLPRI; + + while (1) { + poll(pfd, NET_EVENT_MAX, -1); + + if (pfd[NET_EVENT_STOP].revents & POLLIN) { + net_event_clear(&net_null->stop_event); + break; + } + + if (pfd[NET_EVENT_TX].revents & POLLIN) { + net_event_clear(&net_null->tx_event); + + int packets = network_tx_popv(net_null->card, net_null->pktv, NULL_PKT_BATCH); + for (int i = 0; i < packets; i++) { + net_null_log("Null Network: Ignoring TX packet (%d bytes)\n", net_null->pktv[i].len); + } + } + } + + net_null_log("Null Network: polling stopped.\n"); +} +#endif + +void * +net_null_init(const netcard_t *card, const uint8_t *mac_addr, void *priv) +{ + net_null_log("Null Network: Init\n"); + + net_null_t *net_null = calloc(1, sizeof(net_null_t)); + net_null->card = (netcard_t *) card; + memcpy(net_null->mac_addr, mac_addr, sizeof(net_null->mac_addr)); + + for (int i = 0; i < NULL_PKT_BATCH; i++) { + net_null->pktv[i].data = calloc(1, NET_MAX_FRAME); + } + net_null->pkt.data = calloc(1, NET_MAX_FRAME); + + net_event_init(&net_null->tx_event); + net_event_init(&net_null->stop_event); + net_null->poll_tid = thread_create(net_null_thread, net_null); + + return net_null; +} + + + +void +net_null_in_available(void *priv) +{ + net_null_t *net_null = (net_null_t *) priv; + net_event_set(&net_null->tx_event); +} + +void +net_null_close(void *priv) +{ + if (!priv) + return; + + net_null_t *net_null = (net_null_t *) priv; + + net_null_log("Null Network: closing.\n"); + + /* Tell the thread to terminate. */ + net_event_set(&net_null->stop_event); + + /* Wait for the thread to finish. */ + net_null_log("Null Network: waiting for thread to end...\n"); + thread_wait(net_null->poll_tid); + net_null_log("Null Network: thread ended\n"); + + for (int i = 0; i < NULL_PKT_BATCH; i++) { + free(net_null->pktv[i].data); + } + free(net_null->pkt.data); + + net_event_close(&net_null->tx_event); + net_event_close(&net_null->stop_event); + + free(net_null); +} + +const netdrv_t net_null_drv = { + &net_null_in_available, + &net_null_init, + &net_null_close, + NULL +}; \ No newline at end of file diff --git a/src/network/network.c b/src/network/network.c index ce81fcc93..a4f1369ed 100644 --- a/src/network/network.c +++ b/src/network/network.c @@ -442,13 +442,12 @@ network_attach(void *card_drv, uint8_t *mac, NETRXCB rx, NETSETLINKSTATE set_lin card->card_num = net_card_current; card->byte_period = NET_PERIOD_10M; - for (int i = 0; i < 3; i++) { + for (int i = 0; i < NET_QUEUE_COUNT; i++) { network_queue_init(&card->queues[i]); } switch (net_cards_conf[net_card_current].net_type) { case NET_TYPE_SLIRP: - default: card->host_drv = net_slirp_drv; card->host_drv.priv = card->host_drv.init(card, mac, NULL); break; @@ -463,18 +462,45 @@ network_attach(void *card_drv, uint8_t *mac, NETRXCB rx, NETSETLINKSTATE set_lin card->host_drv.priv = card->host_drv.init(card, mac, net_cards_conf[net_card_current].host_dev_name); break; #endif + default: + card->host_drv.priv = NULL; + break; } + // Use null driver on: + // * No specific driver selected (card->host_drv.priv is set to null above) + // * Failure to init a specific driver (in which case card->host_drv.priv is null) if (!card->host_drv.priv) { - thread_close_mutex(card->tx_mutex); - thread_close_mutex(card->rx_mutex); - for (int i = 0; i < 3; i++) { - network_queue_clear(&card->queues[i]); + + if(net_cards_conf[net_card_current].net_type != NET_TYPE_NONE) { + // We're here because of a failure + // Placeholder to display a msgbox about falling back to null + ui_msgbox(MBX_ERROR | MBX_ANSI, "Network driver initialization failed. Falling back to NULL driver."); + } + + // Init null driver + card->host_drv = net_null_drv; + card->host_drv.priv = card->host_drv.init(card, mac, NULL); + // Set link state to disconnected by default + network_connect(card->card_num, 0); + ui_sb_update_icon_state(SB_NETWORK | card->card_num, 1); + + // If null fails, something is very wrong + // Clean up and fatal + if(!card->host_drv.priv) { + thread_close_mutex(card->tx_mutex); + thread_close_mutex(card->rx_mutex); + for (int i = 0; i < NET_QUEUE_COUNT; i++) { + network_queue_clear(&card->queues[i]); + } + + free(card->queued_pkt.data); + free(card); + // Placeholder - insert the error message + fatal("Error initializing the network device: Null driver initialization failed"); + return NULL; } - free(card->queued_pkt.data); - free(card); - return NULL; } timer_add(&card->timer, network_rx_queue, card, 0); @@ -491,7 +517,7 @@ netcard_close(netcard_t *card) thread_close_mutex(card->tx_mutex); thread_close_mutex(card->rx_mutex); - for (int i = 0; i < 3; i++) { + for (int i = 0; i < NET_QUEUE_COUNT; i++) { network_queue_clear(&card->queues[i]); } @@ -641,7 +667,7 @@ network_dev_to_id(char *devname) int network_dev_available(int id) { - int available = (net_cards_conf[id].device_num > 0) && (net_cards_conf[id].net_type != NET_TYPE_NONE); + int available = (net_cards_conf[id].device_num > 0); if ((net_cards_conf[id].net_type == NET_TYPE_PCAP && (network_dev_to_id(net_cards_conf[id].host_dev_name) <= 0))) available = 0; diff --git a/src/qt/qt_mediamenu.cpp b/src/qt/qt_mediamenu.cpp index 841cd3053..26169b0d0 100644 --- a/src/qt/qt_mediamenu.cpp +++ b/src/qt/qt_mediamenu.cpp @@ -849,7 +849,7 @@ MediaMenu::nicUpdateMenu(int i) if (!netMenus.contains(i)) return; - QString netType = tr("None"); + QString netType = tr("Null Driver"); switch (net_cards_conf[i].net_type) { case NET_TYPE_SLIRP: netType = "SLiRP"; diff --git a/src/qt/qt_settingsnetwork.cpp b/src/qt/qt_settingsnetwork.cpp index ceb4810bc..acc7ebfc4 100644 --- a/src/qt/qt_settingsnetwork.cpp +++ b/src/qt/qt_settingsnetwork.cpp @@ -40,9 +40,10 @@ SettingsNetwork::enableElements(Ui::SettingsNetwork *ui) auto *socket_line = findChild(QString("socketVDENIC%1").arg(i + 1)); int netType = net_type_cbox->currentData().toInt(); - bool adaptersEnabled = netType == NET_TYPE_SLIRP - || NET_TYPE_VDE - || (netType == NET_TYPE_PCAP && intf_cbox->currentData().toInt() > 0); + bool adaptersEnabled = netType == NET_TYPE_NONE + || netType == NET_TYPE_SLIRP + || netType == NET_TYPE_VDE + || (netType == NET_TYPE_PCAP && intf_cbox->currentData().toInt() > 0); intf_cbox->setEnabled(net_type_cbox->currentData().toInt() == NET_TYPE_PCAP); nic_cbox->setEnabled(adaptersEnabled); @@ -133,7 +134,7 @@ SettingsNetwork::onCurrentMachineChanged(int machineId) cbox = findChild(QString("comboBoxNet%1").arg(i + 1)); model = cbox->model(); removeRows = model->rowCount(); - Models::AddEntry(model, tr("None"), NET_TYPE_NONE); + Models::AddEntry(model, tr("Null Driver"), NET_TYPE_NONE); Models::AddEntry(model, "SLiRP", NET_TYPE_SLIRP); if (network_ndev > 1) { diff --git a/src/win/languages/dialogs.rc b/src/win/languages/dialogs.rc index 3286ee2be..876fd8939 100644 --- a/src/win/languages/dialogs.rc +++ b/src/win/languages/dialogs.rc @@ -408,7 +408,7 @@ BEGIN CFG_HMARGIN + (CFG_PANE_LTEXT_PRI_WIDTH * 2) + 20, CFG_VMARGIN, CFG_PANE_LTEXT_PRI_WIDTH, CFG_PANE_LTEXT_HEIGHT COMBOBOX IDC_COMBO_NET1_TYPE, - CFG_HMARGIN, 28, 32, CFG_COMBO_HEIGHT, + CFG_HMARGIN, 28, 48, CFG_COMBO_HEIGHT, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_COMBO_PCAP1, @@ -422,7 +422,7 @@ BEGIN CFG_HMARGIN + (CFG_PANE_LTEXT_PRI_WIDTH * 3) + 50, 27, CFG_BTN_WIDTH, CFG_BTN_HEIGHT COMBOBOX IDC_COMBO_NET2_TYPE, - CFG_HMARGIN, 49, 32, CFG_COMBO_HEIGHT, + CFG_HMARGIN, 49, 48, CFG_COMBO_HEIGHT, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_COMBO_PCAP2, @@ -436,7 +436,7 @@ BEGIN CFG_HMARGIN + (CFG_PANE_LTEXT_PRI_WIDTH * 3) + 50, 48, CFG_BTN_WIDTH, CFG_BTN_HEIGHT COMBOBOX IDC_COMBO_NET3_TYPE, - CFG_HMARGIN, 70, 32, CFG_COMBO_HEIGHT, + CFG_HMARGIN, 70, 48, CFG_COMBO_HEIGHT, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_COMBO_PCAP3, @@ -450,7 +450,7 @@ BEGIN CFG_HMARGIN + (CFG_PANE_LTEXT_PRI_WIDTH * 3) + 50, 69, CFG_BTN_WIDTH, CFG_BTN_HEIGHT COMBOBOX IDC_COMBO_NET4_TYPE, - CFG_HMARGIN, 91, 32, CFG_COMBO_HEIGHT, + CFG_HMARGIN, 91, 48, CFG_COMBO_HEIGHT, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_COMBO_PCAP4, diff --git a/src/win/win_settings.c b/src/win/win_settings.c index 333888a65..2936f6639 100644 --- a/src/win/win_settings.c +++ b/src/win/win_settings.c @@ -2062,7 +2062,7 @@ win_settings_network_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) lptsTemp = (LPTSTR) malloc(512 * sizeof(WCHAR)); for (uint8_t i = 0; i < NET_CARD_MAX; i++) { - settings_add_string(hdlg, IDC_COMBO_NET1_TYPE + i, (LPARAM) L"None"); + settings_add_string(hdlg, IDC_COMBO_NET1_TYPE + i, (LPARAM) L"Null Driver"); settings_add_string(hdlg, IDC_COMBO_NET1_TYPE + i, (LPARAM) L"SLiRP"); settings_add_string(hdlg, IDC_COMBO_NET1_TYPE + i, (LPARAM) L"PCap"); settings_set_cur_sel(hdlg, IDC_COMBO_NET1_TYPE + i, temp_net_type[i]); From 41ca38341c31d2a4ad433f5f92e9093b9ac2184a Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Mon, 8 May 2023 23:27:52 +0600 Subject: [PATCH 09/34] usb: Structure definitions for USB device descriptors --- src/include/86box/usb.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/include/86box/usb.h b/src/include/86box/usb.h index 4dbec55c3..d94d8a137 100644 --- a/src/include/86box/usb.h +++ b/src/include/86box/usb.h @@ -107,6 +107,34 @@ typedef struct uint8_t bDescriptorType; } usb_desc_base_t; +typedef struct +{ + usb_desc_base_t base; + + uint8_t bInterfaceNumber; + uint8_t bAlternateSetting; + uint8_t bNumEndpoints; + uint8_t bInterfaceClass; + uint8_t bInterfaceSubClass; + uint8_t bInterfaceProtocol; + uint8_t iInterface; +} usb_desc_interface_t; + +typedef struct +{ + usb_desc_base_t base; + uint8_t bEndpointAddress; + uint8_t bmAttributes; + uint8_t wMaxPacketSize; + uint8_t bInterval; +} usb_desc_endpoint_t; + +typedef struct +{ + usb_desc_base_t base; + uint16_t bString[]; +} usb_desc_string_t; + typedef struct { usb_desc_base_t base; @@ -117,6 +145,8 @@ typedef struct uint8_t iConfiguration; uint8_t bmAttributes; uint8_t bMaxPower; + + usb_desc_interface_t interface_descs[]; } usb_desc_conf_t; #pragma pack(pop) From b86622c725b69881cb13b4a62b70842f29520696 Mon Sep 17 00:00:00 2001 From: cold-brewed Date: Mon, 8 May 2023 13:40:35 -0400 Subject: [PATCH 10/34] network: Add null network driver to win32 makefile --- src/win/Makefile.mingw | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index 0aa08d267..4b60cb930 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -669,7 +669,8 @@ NETOBJ := network.o \ net_dp8390.o net_3c501.o \ net_3c503.o net_ne2000.o \ net_pcnet.o net_wd8003.o \ - net_plip.o net_event.o + net_plip.o net_event.o \ + net_null.o PRINTOBJ := png.o prt_cpmap.o \ prt_escp.o prt_text.o prt_ps.o From 8f7752e63cb52d4af2bda4eaa7e7be870682670e Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Tue, 9 May 2023 00:14:15 +0600 Subject: [PATCH 11/34] usb: Add a bit of logging --- src/usb.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/usb.c b/src/usb.c index 2ef5bb895..894e0a864 100644 --- a/src/usb.c +++ b/src/usb.c @@ -681,6 +681,9 @@ ohci_mmio_write(uint32_t addr, uint8_t val, void *p) switch (addr) { case OHCI_aHcControl: old = dev->ohci_mmio[OHCI_HcControl].b[0]; +#ifdef ENABLE_USB_LOG + usb_log("OHCI: OHCI state 0x%X\n", (val & 0xc0)); +#endif if ((val & 0xc0) == 0x00) { /* UsbReset */ dev->ohci_mmio[OHCI_HcRhPortStatus1].b[2] = dev->ohci_mmio[OHCI_HcRhPortStatus2].b[2] = 0x16; From 4704e4e84755e1e1c0e10650b11616b4497b4e24 Mon Sep 17 00:00:00 2001 From: cold-brewed Date: Tue, 9 May 2023 10:53:06 -0400 Subject: [PATCH 12/34] vde: Don't fatal() in network driver --- src/network/net_vde.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/net_vde.c b/src/network/net_vde.c index 904b2789a..9bed78a9e 100644 --- a/src/network/net_vde.c +++ b/src/network/net_vde.c @@ -280,7 +280,7 @@ void *net_vde_init(const netcard_t *card, const uint8_t *mac_addr, void *priv) { // TODO: Once there is a solution for the mentioned crash, this should be removed // and/or replaced by proper error handling code. //- - fatal("Could not open the specified VDE socket (%s). Please fix your networking configuration.", socket_name); + // fatal("Could not open the specified VDE socket (%s). Please fix your networking configuration.", socket_name); // It makes no sense to issue this warning since the program will crash anyway... // ui_msgbox_header(MBX_WARNING, (wchar_t *) IDS_2167, (wchar_t *) IDS_2168); return NULL; From 0ab0caf5b16c324409f0a736afc8350ea2bad9f4 Mon Sep 17 00:00:00 2001 From: cold-brewed Date: Tue, 9 May 2023 13:11:00 -0400 Subject: [PATCH 13/34] vde: Properly initialize a variable and fix bit width --- src/include/86box/network.h | 6 +++--- src/network/network.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/include/86box/network.h b/src/include/86box/network.h index 4f514d1ac..ccd6f2f70 100644 --- a/src/include/86box/network.h +++ b/src/include/86box/network.h @@ -150,9 +150,9 @@ typedef struct { } netdev_t; typedef struct { - int has_slirp: 1; - int has_pcap: 1; - int has_vde: 1; + int has_slirp; + int has_pcap; + int has_vde; } network_devmap_t; diff --git a/src/network/network.c b/src/network/network.c index ce81fcc93..38f86f586 100644 --- a/src/network/network.c +++ b/src/network/network.c @@ -123,7 +123,7 @@ netcard_conf_t net_cards_conf[NET_CARD_MAX]; uint16_t net_card_current = 0; /* Global variables. */ -network_devmap_t network_devmap; +network_devmap_t network_devmap = {0}; int network_ndev; netdev_t network_devs[NET_HOST_INTF_MAX]; From d0845ccadeb360203693b13138c905446d273ee5 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 10 May 2023 17:09:13 +0600 Subject: [PATCH 14/34] usb: Infrastructure changes Make OHCI OwnershipChange work properly --- src/chipset/ali1543.c | 1 + src/chipset/ali6117.c | 1 - src/chipset/intel_piix.c | 1 + src/chipset/sis_5571.c | 1 + src/chipset/stpc.c | 1 + src/chipset/via_pipc.c | 1 + src/include/86box/usb.h | 96 ++++++++++++++++++++++++++++------------ src/usb.c | 4 +- 8 files changed, 76 insertions(+), 30 deletions(-) diff --git a/src/chipset/ali1543.c b/src/chipset/ali1543.c index 2e2f74305..26673edec 100644 --- a/src/chipset/ali1543.c +++ b/src/chipset/ali1543.c @@ -20,6 +20,7 @@ #include #include #include +#include #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/timer.h> diff --git a/src/chipset/ali6117.c b/src/chipset/ali6117.c index 98451067a..796ca880f 100644 --- a/src/chipset/ali6117.c +++ b/src/chipset/ali6117.c @@ -30,7 +30,6 @@ #include <86box/pit.h> #include <86box/device.h> #include <86box/port_92.h> -#include <86box/usb.h> #include <86box/hdc.h> #include <86box/hdc_ide.h> #include <86box/chipset.h> diff --git a/src/chipset/intel_piix.c b/src/chipset/intel_piix.c index 470978611..f550d9503 100644 --- a/src/chipset/intel_piix.c +++ b/src/chipset/intel_piix.c @@ -23,6 +23,7 @@ #include #include #include +#include #define HAVE_STDARG_H #include <86box/86box.h> #include "cpu.h" diff --git a/src/chipset/sis_5571.c b/src/chipset/sis_5571.c index c158e2d63..a20f5fadd 100644 --- a/src/chipset/sis_5571.c +++ b/src/chipset/sis_5571.c @@ -20,6 +20,7 @@ #include #include #include +#include #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/device.h> diff --git a/src/chipset/stpc.c b/src/chipset/stpc.c index 2e4b045f2..822f462ad 100644 --- a/src/chipset/stpc.c +++ b/src/chipset/stpc.c @@ -20,6 +20,7 @@ #include #include #include +#include #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/mem.h> diff --git a/src/chipset/via_pipc.c b/src/chipset/via_pipc.c index c2abc4465..067b733a2 100644 --- a/src/chipset/via_pipc.c +++ b/src/chipset/via_pipc.c @@ -26,6 +26,7 @@ #include #include #include +#include #define HAVE_STDARG_H #include <86box/86box.h> #include "cpu.h" diff --git a/src/include/86box/usb.h b/src/include/86box/usb.h index d94d8a137..455282f71 100644 --- a/src/include/86box/usb.h +++ b/src/include/86box/usb.h @@ -23,6 +23,7 @@ extern "C" { #endif typedef struct usb_t usb_t; +typedef struct usb_device_t usb_device_t; enum usb_pid { @@ -39,22 +40,6 @@ enum usb_errors USB_ERROR_UNDERRUN = 3 }; -/* USB endpoint device struct. Incomplete and unused. */ -typedef struct -{ - uint16_t vendor_id; - uint16_t device_id; - - /* General-purpose function for I/O. Non-zero value indicates error. */ - uint8_t (*device_process)(void* priv, uint8_t* data, uint32_t *len, uint8_t pid_token, uint8_t endpoint, uint8_t underrun_not_allowed); - /* Device reset. */ - void (*device_reset)(void* priv); - /* Get address. */ - uint8_t (*device_get_address)(void* priv); - - void* priv; -} usb_device_t; - enum usb_bus_types { USB_BUS_OHCI = 0, @@ -107,6 +92,35 @@ typedef struct uint8_t bDescriptorType; } usb_desc_base_t; +typedef struct +{ + uint8_t bmRequestType; + uint8_t bRequest; + uint16_t wValue; + uint16_t wIndex; + uint16_t wLength; +} usb_desc_setup_t; + +typedef struct +{ + usb_desc_base_t base; + uint8_t bEndpointAddress; + uint8_t bmAttributes; + uint16_t wMaxPacketSize; + uint8_t bInterval; +} usb_desc_endpoint_t; + +typedef struct +{ + usb_desc_base_t base; + + uint16_t bcdHID; + uint8_t bCountryCode; + uint8_t bNumDescriptors; + uint8_t bDescriptorType; + uint16_t wDescriptorLength; +} usb_desc_hid_t; + typedef struct { usb_desc_base_t base; @@ -123,16 +137,7 @@ typedef struct typedef struct { usb_desc_base_t base; - uint8_t bEndpointAddress; - uint8_t bmAttributes; - uint8_t wMaxPacketSize; - uint8_t bInterval; -} usb_desc_endpoint_t; - -typedef struct -{ - usb_desc_base_t base; - uint16_t bString[]; + char16_t bString[]; } usb_desc_string_t; typedef struct @@ -145,12 +150,47 @@ typedef struct uint8_t iConfiguration; uint8_t bmAttributes; uint8_t bMaxPower; - - usb_desc_interface_t interface_descs[]; } usb_desc_conf_t; +typedef struct +{ + usb_desc_base_t base; + + uint16_t bcdUSB; + uint8_t bDeviceClass; + uint8_t bDeviceSubClass; + uint8_t bDeviceProtocol; + uint8_t bMaxPacketSize; + uint16_t idVendor; + uint16_t idProduct; + uint16_t bcdDevice; + uint8_t iManufacturer; + uint8_t iProduct; + uint8_t iSerialNumber; + uint8_t bNumConfigurations; +} usb_desc_device_t; + #pragma pack(pop) +/* USB endpoint device struct. Incomplete and unused. */ +typedef struct usb_device_t +{ + usb_desc_device_t device_desc; + struct { + usb_desc_conf_t conf_desc; + usb_desc_base_t* other_descs[16]; + } conf_desc_items; + + /* General-purpose function for I/O. Non-zero value indicates error. */ + uint8_t (*device_process)(void* priv, uint8_t* data, uint32_t *len, uint8_t pid_token, uint8_t endpoint, uint8_t underrun_not_allowed); + /* Device reset. */ + void (*device_reset)(void* priv); + /* Get address. */ + uint8_t (*device_get_address)(void* priv); + + void* priv; +} usb_device_t; + /* Global variables. */ extern const device_t usb_device; extern usb_t* usb_device_inst; diff --git a/src/usb.c b/src/usb.c index 894e0a864..5d661bd72 100644 --- a/src/usb.c +++ b/src/usb.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #define HAVE_STDARG_H #include <86box/86box.h> @@ -702,8 +703,9 @@ ohci_mmio_write(uint32_t addr, uint8_t val, void *p) /* bit OwnershipChangeRequest triggers an ownership change (SMM <-> OS) */ if (val & 0x08) { dev->ohci_mmio[OHCI_HcInterruptStatus].b[3] = 0x40; - if ((dev->ohci_mmio[OHCI_HcInterruptEnable].b[3] & 0xc0) == 0xc0) + if ((dev->ohci_mmio[OHCI_HcInterruptEnable].b[3] & 0x40) == 0x40) { smi_raise(); + } } /* bit HostControllerReset must be cleared for the controller to be seen as initialized */ From 98ebfce4601df14b68634a4cce1a01eb7204bf51 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 10 May 2023 17:19:35 +0600 Subject: [PATCH 15/34] usb: Revert usage of uchar.h --- src/chipset/ali1543.c | 1 - src/chipset/intel_piix.c | 1 - src/chipset/sis_5571.c | 1 - src/chipset/stpc.c | 1 - src/chipset/via_pipc.c | 1 - src/include/86box/usb.h | 14 +++++++++++++- src/usb.c | 1 - 7 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/chipset/ali1543.c b/src/chipset/ali1543.c index 26673edec..2e2f74305 100644 --- a/src/chipset/ali1543.c +++ b/src/chipset/ali1543.c @@ -20,7 +20,6 @@ #include #include #include -#include #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/timer.h> diff --git a/src/chipset/intel_piix.c b/src/chipset/intel_piix.c index f550d9503..470978611 100644 --- a/src/chipset/intel_piix.c +++ b/src/chipset/intel_piix.c @@ -23,7 +23,6 @@ #include #include #include -#include #define HAVE_STDARG_H #include <86box/86box.h> #include "cpu.h" diff --git a/src/chipset/sis_5571.c b/src/chipset/sis_5571.c index a20f5fadd..c158e2d63 100644 --- a/src/chipset/sis_5571.c +++ b/src/chipset/sis_5571.c @@ -20,7 +20,6 @@ #include #include #include -#include #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/device.h> diff --git a/src/chipset/stpc.c b/src/chipset/stpc.c index 822f462ad..2e4b045f2 100644 --- a/src/chipset/stpc.c +++ b/src/chipset/stpc.c @@ -20,7 +20,6 @@ #include #include #include -#include #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/mem.h> diff --git a/src/chipset/via_pipc.c b/src/chipset/via_pipc.c index 067b733a2..c2abc4465 100644 --- a/src/chipset/via_pipc.c +++ b/src/chipset/via_pipc.c @@ -26,7 +26,6 @@ #include #include #include -#include #define HAVE_STDARG_H #include <86box/86box.h> #include "cpu.h" diff --git a/src/include/86box/usb.h b/src/include/86box/usb.h index 455282f71..d0801b99c 100644 --- a/src/include/86box/usb.h +++ b/src/include/86box/usb.h @@ -92,6 +92,18 @@ typedef struct uint8_t bDescriptorType; } usb_desc_base_t; +enum usb_desc_setup_req_types +{ + USB_SETUP_TYPE_DEVICE = 0x0, + USB_SETUP_TYPE_INTERFACE = 0x1, + USB_SETUP_TYPE_ENDPOING = 0x2, + USB_SETUP_TYPE_OTHER = 0x3, +}; + +#define USB_SETUP_TYPE_MAX 0x1F + +#define USB_SETUP_DEV_TO_HOST 0x80 + typedef struct { uint8_t bmRequestType; @@ -137,7 +149,7 @@ typedef struct typedef struct { usb_desc_base_t base; - char16_t bString[]; + uint16_t bString[]; } usb_desc_string_t; typedef struct diff --git a/src/usb.c b/src/usb.c index 5d661bd72..fce5fe0b0 100644 --- a/src/usb.c +++ b/src/usb.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #define HAVE_STDARG_H #include <86box/86box.h> From 889392539666e87292cf2cf647c5c4559bbeabd7 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 10 May 2023 17:28:40 +0600 Subject: [PATCH 16/34] usb: Return early on invalid directions --- src/usb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/usb.c b/src/usb.c index fce5fe0b0..85c2a6fc8 100644 --- a/src/usb.c +++ b/src/usb.c @@ -390,7 +390,7 @@ ohci_service_transfer_desc(usb_t* dev, usb_ed_t* endpoint_desc) { uint32_t td_addr = endpoint_desc->HeadP & ~(0xf); usb_td_t td; - uint8_t dir, pid_token; + uint8_t dir, pid_token = 255; uint32_t len = 0, pktlen = 0; uint32_t actual_length = 0; uint32_t i = 0; @@ -418,6 +418,8 @@ ohci_service_transfer_desc(usb_t* dev, usb_ed_t* endpoint_desc) case 2: /* IN */ pid_token = USB_PID_IN; break; + default: + return 1; } if (td.CBP && td.BE) { From 30ee26886986b543581c510329b901ab264db7cb Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 12 May 2023 01:44:54 -0400 Subject: [PATCH 17/34] LLVM doesn't support multiplication in rc macros --- src/win/languages/dialogs.rc | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/win/languages/dialogs.rc b/src/win/languages/dialogs.rc index 876fd8939..eb542a971 100644 --- a/src/win/languages/dialogs.rc +++ b/src/win/languages/dialogs.rc @@ -3,6 +3,8 @@ #define CFG_BTN_WIDTH 46 #define CFG_BTN_HEIGHT 14 #define CFG_PANE_LTEXT_PRI_WIDTH 85 +#define CFG_PANE_LTEXT_PRI_WIDTH_2 170 +#define CFG_PANE_LTEXT_PRI_WIDTH_3 255 #define CFG_PANE_LTEXT_HEIGHT 10 #define CFG_COMBO_BTN_WIDTH 212 #define CFG_COMBO_NOBTN_WIDTH CFG_COMBO_BTN_WIDTH + CFG_BTN_WIDTH + 8 @@ -405,7 +407,7 @@ BEGIN LTEXT STR_PCAP, IDT_PCAP, CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH - 10, CFG_VMARGIN, CFG_PANE_LTEXT_PRI_WIDTH, CFG_PANE_LTEXT_HEIGHT LTEXT STR_NET, IDT_NET, - CFG_HMARGIN + (CFG_PANE_LTEXT_PRI_WIDTH * 2) + 20, CFG_VMARGIN, CFG_PANE_LTEXT_PRI_WIDTH, CFG_PANE_LTEXT_HEIGHT + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_2 + 20, CFG_VMARGIN, CFG_PANE_LTEXT_PRI_WIDTH, CFG_PANE_LTEXT_HEIGHT COMBOBOX IDC_COMBO_NET1_TYPE, CFG_HMARGIN, 28, 48, CFG_COMBO_HEIGHT, @@ -416,10 +418,10 @@ BEGIN CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_COMBO_NET1, - CFG_HMARGIN + (CFG_PANE_LTEXT_PRI_WIDTH * 2) + 20, 28, 110, CFG_COMBO_HEIGHT, + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_2 + 20, 28, 110, CFG_COMBO_HEIGHT, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP PUSHBUTTON STR_CONFIGURE, IDC_CONFIGURE_NET1, - CFG_HMARGIN + (CFG_PANE_LTEXT_PRI_WIDTH * 3) + 50, 27, CFG_BTN_WIDTH, CFG_BTN_HEIGHT + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_3 + 50, 27, CFG_BTN_WIDTH, CFG_BTN_HEIGHT COMBOBOX IDC_COMBO_NET2_TYPE, CFG_HMARGIN, 49, 48, CFG_COMBO_HEIGHT, @@ -430,10 +432,10 @@ BEGIN CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_COMBO_NET2, - CFG_HMARGIN + (CFG_PANE_LTEXT_PRI_WIDTH * 2) + 20, 49, 110, CFG_COMBO_HEIGHT, + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_2 + 20, 49, 110, CFG_COMBO_HEIGHT, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP PUSHBUTTON STR_CONFIGURE, IDC_CONFIGURE_NET2, - CFG_HMARGIN + (CFG_PANE_LTEXT_PRI_WIDTH * 3) + 50, 48, CFG_BTN_WIDTH, CFG_BTN_HEIGHT + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_3 + 50, 48, CFG_BTN_WIDTH, CFG_BTN_HEIGHT COMBOBOX IDC_COMBO_NET3_TYPE, CFG_HMARGIN, 70, 48, CFG_COMBO_HEIGHT, @@ -444,10 +446,10 @@ BEGIN CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_COMBO_NET3, - CFG_HMARGIN + (CFG_PANE_LTEXT_PRI_WIDTH * 2) + 20, 70, 110, CFG_COMBO_HEIGHT, + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_2 + 20, 70, 110, CFG_COMBO_HEIGHT, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP PUSHBUTTON STR_CONFIGURE, IDC_CONFIGURE_NET3, - CFG_HMARGIN + (CFG_PANE_LTEXT_PRI_WIDTH * 3) + 50, 69, CFG_BTN_WIDTH, CFG_BTN_HEIGHT + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_3 + 50, 69, CFG_BTN_WIDTH, CFG_BTN_HEIGHT COMBOBOX IDC_COMBO_NET4_TYPE, CFG_HMARGIN, 91, 48, CFG_COMBO_HEIGHT, @@ -458,10 +460,10 @@ BEGIN CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_COMBO_NET4, - CFG_HMARGIN + (CFG_PANE_LTEXT_PRI_WIDTH * 2) + 20, 91, 110, CFG_COMBO_HEIGHT, + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_2 + 20, 91, 110, CFG_COMBO_HEIGHT, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP PUSHBUTTON STR_CONFIGURE, IDC_CONFIGURE_NET4, - CFG_HMARGIN + (CFG_PANE_LTEXT_PRI_WIDTH * 3) + 50, 90, CFG_BTN_WIDTH, CFG_BTN_HEIGHT + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_3 + 50, 90, CFG_BTN_WIDTH, CFG_BTN_HEIGHT END From e524b75352862375e34745cf1226b0456f088800 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 12 May 2023 00:41:45 -0400 Subject: [PATCH 18/34] Add support for sonarcloud --- .github/workflows/cmake.yml | 82 +++++++++++++++++++++++++++++++++---- sonar-project.properties | 12 ++++++ 2 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 sonar-project.properties diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 9041ca0fc..ab9cf96c7 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -30,6 +30,9 @@ jobs: runs-on: windows-2022 + env: + BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed + defaults: run: shell: msys2 {0} @@ -106,6 +109,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Install sonar-scanner and build-wrapper + uses: SonarSource/sonarcloud-github-c-cpp@v1 - name: Configure CMake run: >- @@ -117,7 +125,15 @@ jobs: -D STATIC_BUILD=${{ matrix.ui.static }} - name: Build - run: cmake --build build + run: | + build-wrapper-win-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build + + - name: Run sonar-scanner + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" - name: Generate package run: cmake --install build @@ -134,6 +150,7 @@ jobs: runs-on: windows-2022 env: + BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed VCPKG_BINARY_SOURCES: 'clear;nuget,GitHub,readwrite' strategy: @@ -209,6 +226,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Install sonar-scanner and build-wrapper + uses: SonarSource/sonarcloud-github-c-cpp@v1 - name: Configure CMake run: > @@ -229,13 +251,23 @@ jobs: - name: Reconfigure CMake if: matrix.ui.qt == 'on' - run: cmake clean build + run: | + cmake clean build - name: Build - run: cmake --build build + run: | + build-wrapper-win-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build + + - name: Run sonar-scanner + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" - name: Generate package - run: cmake --install build + run: | + cmake --install build - name: Upload artifact uses: actions/upload-artifact@v3 @@ -248,6 +280,9 @@ jobs: runs-on: ubuntu-22.04 + env: + BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed + strategy: fail-fast: true matrix: @@ -295,6 +330,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Install sonar-scanner and build-wrapper + uses: SonarSource/sonarcloud-github-c-cpp@v1 - name: Configure CMake run: >- @@ -305,10 +345,19 @@ jobs: -D QT=${{ matrix.ui.qt }} - name: Build - run: cmake --build build + run: | + build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build + + - name: Run sonar-scanner + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" - name: Generate package - run: cmake --install build + run: | + cmake --install build - name: Upload artifact uses: actions/upload-artifact@v3 @@ -321,6 +370,9 @@ jobs: runs-on: macos-11 + env: + BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed + strategy: fail-fast: true matrix: @@ -362,6 +414,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Install sonar-scanner and build-wrapper + uses: SonarSource/sonarcloud-github-c-cpp@v1 - name: Configure CMake run: >- @@ -375,10 +432,19 @@ jobs: -D OpenAL_ROOT=$(brew --prefix openal-soft) - name: Build - run: cmake --build build + run: | + build-wrapper-macosx-x86 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build + + - name: Run sonar-scanner + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" - name: Generate package - run: cmake --install build + run: | + cmake --install build - name: Upload artifact uses: actions/upload-artifact@v3 diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 000000000..9011c9954 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,12 @@ +sonar.projectKey=86Box_86Box +sonar.organization=86Box + +# This is the name and version displayed in the SonarCloud UI. +#sonar.projectName=86Box +#sonar.projectVersion=1.0 + +# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. +#sonar.sources=. + +# Encoding of the source code. Default is default system encoding +#sonar.sourceEncoding=UTF-8 From aa9e88587628234c79aaf58de9094975fad4fed8 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 12 May 2023 01:02:03 -0400 Subject: [PATCH 19/34] Temporary till I figure out the problem with msys2 --- .github/workflows/cmake.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index ab9cf96c7..80abcf79b 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -126,9 +126,10 @@ jobs: - name: Build run: | - build-wrapper-win-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build + cmake --build build - name: Run sonar-scanner + if: 0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From 7200fc1b4e7725d3531e2210c2225306d3238d95 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 12 May 2023 02:29:29 -0400 Subject: [PATCH 20/34] Disable running sonarcloud for now --- .github/workflows/cmake.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 80abcf79b..df09442e9 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -260,6 +260,7 @@ jobs: build-wrapper-win-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build - name: Run sonar-scanner + if: 0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} @@ -350,6 +351,7 @@ jobs: build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build - name: Run sonar-scanner + if: 0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} @@ -437,6 +439,7 @@ jobs: build-wrapper-macosx-x86 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build - name: Run sonar-scanner + if: 0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From cde2f87213ee40a07c72c7c36c7a916737a20880 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 12 May 2023 02:33:34 -0400 Subject: [PATCH 21/34] Disable LLVM builds till we can fix them properly --- .github/workflows/cmake.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index df09442e9..3d8e477dd 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -147,6 +147,7 @@ jobs: llvm-windows: name: "Windows vcpkg/LLVM (${{ matrix.ui.name }}, ${{ matrix.build.name }}, ${{ matrix.dynarec.name }}, ${{ matrix.target.name }})" + if: 0 runs-on: windows-2022 From 248741ddbcbe1b1927e3c8af430390fae8e5aa9c Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 12 May 2023 02:39:45 -0400 Subject: [PATCH 22/34] Consistancy for GHA scripts --- .github/workflows/codeql.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 107755af6..69c877776 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -129,8 +129,8 @@ jobs: -D STATIC_BUILD=${{ matrix.ui.static }} - name: Build - run: cmake --build build - + run: | + cmake --build build - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 @@ -212,7 +212,8 @@ jobs: -D QT=${{ matrix.ui.qt }} - name: Build - run: cmake --build build + run: | + cmake --build build - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 @@ -290,7 +291,8 @@ jobs: -D OpenAL_ROOT=$(brew --prefix openal-soft) - name: Build - run: cmake --build build + run: | + cmake --build build - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 From 9289910f353c39bb4a1f685a9f6b9d18af5aab69 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Sun, 14 May 2023 10:38:47 -0400 Subject: [PATCH 23/34] Enable sonarcloud --- .github/workflows/cmake.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 3d8e477dd..49ea8c890 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -261,7 +261,7 @@ jobs: build-wrapper-win-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build - name: Run sonar-scanner - if: 0 +# if: 0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} @@ -352,7 +352,7 @@ jobs: build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build - name: Run sonar-scanner - if: 0 +# if: 0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} @@ -440,7 +440,7 @@ jobs: build-wrapper-macosx-x86 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build - name: Run sonar-scanner - if: 0 +# if: 0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From 13b67fcc3544f385b3d0d8b71df7ffb546fe2175 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Sun, 14 May 2023 10:47:30 -0400 Subject: [PATCH 24/34] Fix sonar organization --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index 9011c9954..781fad035 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,5 +1,5 @@ sonar.projectKey=86Box_86Box -sonar.organization=86Box +sonar.organization=86box # This is the name and version displayed in the SonarCloud UI. #sonar.projectName=86Box From 4e994e1aef14f6cf085a68d4df6502280269e809 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 12 May 2023 20:49:02 -0400 Subject: [PATCH 25/34] Fix PCjr memory steps --- src/machine/machine_table.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/machine/machine_table.c b/src/machine/machine_table.c index f089fe93e..bb91e6977 100644 --- a/src/machine/machine_table.c +++ b/src/machine/machine_table.c @@ -303,7 +303,7 @@ const machine_t machines[] = { .ram = { .min = 128, .max = 640, - .step = 128 + .step = 64 }, .nvrmask = 0, .kbc_device = NULL, /* TODO: No specific kbd_device yet */ From 194918b86aae69ade917693636d7b8e00878efb9 Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 16 May 2023 00:20:09 +0200 Subject: [PATCH 26/34] Some minor keyboard and keyboard controller fixes and three-phased the keyboard and PS/2 mouse BAT. --- src/device/kbc_at.c | 2 ++ src/device/kbc_at_dev.c | 29 ++++++++++++++++------ src/device/keyboard.c | 8 ++++-- src/device/keyboard_at.c | 4 +++ src/device/mouse_ps2.c | 48 +++++++++++++++++++----------------- src/include/86box/keyboard.h | 8 +++--- 6 files changed, 64 insertions(+), 35 deletions(-) diff --git a/src/device/kbc_at.c b/src/device/kbc_at.c index aed771b9e..08c849c85 100644 --- a/src/device/kbc_at.c +++ b/src/device/kbc_at.c @@ -1449,6 +1449,7 @@ kbc_at_process_cmd(void *priv) /* TODO: Proper P1 implementation, with OR and AND flags in the machine table. */ dev->p1 = dev->p1 & 0xff; write_p2(dev, 0x4b); + picintc(0x1002); } dev->status = (dev->status & 0x0f) | 0x60; @@ -1467,6 +1468,7 @@ kbc_at_process_cmd(void *priv) /* TODO: Proper P1 implementation, with OR and AND flags in the machine table. */ dev->p1 = dev->p1 & 0xff; write_p2(dev, 0xcf); + picintc(0x0002); } dev->status = (dev->status & 0x0f) | 0x60; diff --git a/src/device/kbc_at_dev.c b/src/device/kbc_at_dev.c index 71a0b4e08..976b9e740 100644 --- a/src/device/kbc_at_dev.c +++ b/src/device/kbc_at_dev.c @@ -75,7 +75,7 @@ kbc_at_dev_queue_pos(atkbc_dev_t *dev, uint8_t main) uint8_t ret; if (main) - ret = ((dev->queue_end - dev->queue_start) & 0xf); + ret = ((dev->queue_end - dev->queue_start) & dev->fifo_mask); else ret = ((dev->cmd_queue_end - dev->cmd_queue_start) & 0xf); @@ -88,7 +88,7 @@ kbc_at_dev_queue_add(atkbc_dev_t *dev, uint8_t val, uint8_t main) if (main) { kbc_at_dev_log("%s: dev->queue[%02X] = %02X;\n", dev->name, dev->queue_end, val); dev->queue[dev->queue_end] = val; - dev->queue_end = (dev->queue_end + 1) & 0xf; + dev->queue_end = (dev->queue_end + 1) & dev->fifo_mask; } else { kbc_at_dev_log("%s: dev->cmd_queue[%02X] = %02X;\n", dev->name, dev->cmd_queue_end, val); dev->cmd_queue[dev->cmd_queue_end] = val; @@ -121,7 +121,7 @@ kbc_at_dev_poll(void *priv) if (*dev->scan && (dev->port->out_new == -1) && (dev->queue_start != dev->queue_end)) { kbc_at_dev_log("%s: %02X (DATA) on channel 1\n", dev->name, dev->queue[dev->queue_start]); dev->port->out_new = dev->queue[dev->queue_start]; - dev->queue_start = (dev->queue_start + 1) & 0xf; + dev->queue_start = (dev->queue_start + 1) & dev->fifo_mask; } if (!(*dev->scan) || dev->port->wantcmd) dev->state = DEV_STATE_MAIN_1; @@ -155,6 +155,20 @@ kbc_at_dev_poll(void *priv) dev->port->wantcmd = 0; } break; + case DEV_STATE_EXECUTE_BAT: + dev->state = DEV_STATE_MAIN_OUT; + dev->execute_bat(dev); + break; + case DEV_STATE_MAIN_WANT_EXECUTE_BAT: + /* Output command response and then return to main loop #2. */ + if ((dev->port->out_new == -1) && (dev->cmd_queue_start != dev->cmd_queue_end)) { + kbc_at_dev_log("%s: %02X (CMD ) on channel 1\n", dev->name, dev->cmd_queue[dev->cmd_queue_start]); + dev->port->out_new = dev->cmd_queue[dev->cmd_queue_start]; + dev->cmd_queue_start = (dev->cmd_queue_start + 1) & 0xf; + } + if (dev->cmd_queue_start == dev->cmd_queue_end) + dev->state = DEV_STATE_EXECUTE_BAT; + break; } } @@ -170,12 +184,11 @@ kbc_at_dev_reset(atkbc_dev_t *dev, int do_fa) *dev->scan = 1; - if (do_fa) + if (do_fa) { kbc_at_dev_queue_add(dev, 0xfa, 0); - - dev->state = DEV_STATE_MAIN_OUT; - - dev->execute_bat(dev); + dev->state = DEV_STATE_MAIN_WANT_EXECUTE_BAT; + } else + dev->state = DEV_STATE_EXECUTE_BAT; } atkbc_dev_t * diff --git a/src/device/keyboard.c b/src/device/keyboard.c index cc6469f9d..9d15db79b 100644 --- a/src/device/keyboard.c +++ b/src/device/keyboard.c @@ -90,14 +90,18 @@ key_process(uint16_t scan, int down) scancode *codes = scan_table; int c; + if (!codes) + return; + if (!keyboard_scan || (keyboard_send == NULL)) return; oldkey[scan] = down; - if (down && codes[scan].mk[0] == 0) + + if (down && (codes[scan].mk[0] == 0)) return; - if (!down && codes[scan].brk[0] == 0) + if (!down && (codes[scan].brk[0] == 0)) return; /* TODO: The keyboard controller needs to report the AT flag to us here. */ diff --git a/src/device/keyboard_at.c b/src/device/keyboard_at.c index 19a754d7b..6129f206d 100644 --- a/src/device/keyboard_at.c +++ b/src/device/keyboard_at.c @@ -28,6 +28,8 @@ #define FLAG_AT 0x00 /* dev is AT or PS/2 */ #define FLAG_TYPE_MASK 0x07 /* mask for type */ +#define FIFO_SIZE 16 + enum { KBD_84_KEY = 0, KBD_101_KEY, @@ -960,6 +962,8 @@ keyboard_at_init(const device_t *info) dev->scan = &keyboard_scan; + dev->fifo_mask = FIFO_SIZE - 1; + if (dev->port != NULL) kbc_at_dev_reset(dev, 0); diff --git a/src/device/mouse_ps2.c b/src/device/mouse_ps2.c index 7d9730f28..a1afb8afa 100644 --- a/src/device/mouse_ps2.c +++ b/src/device/mouse_ps2.c @@ -30,13 +30,15 @@ enum { MODE_ECHO }; -#define FLAG_EXPLORER 0x200 /* Has 5 buttons */ -#define FLAG_5BTN 0x100 /* using Intellimouse Optical mode */ -#define FLAG_INTELLI 0x80 /* device is IntelliMouse */ -#define FLAG_INTMODE 0x40 /* using Intellimouse mode */ -#define FLAG_SCALED 0x20 /* enable delta scaling */ -#define FLAG_ENABLED 0x10 /* dev is enabled for use */ -#define FLAG_CTRLDAT 0x08 /* ctrl or data mode */ +#define FLAG_EXPLORER 0x200 /* Has 5 buttons */ +#define FLAG_5BTN 0x100 /* using Intellimouse Optical mode */ +#define FLAG_INTELLI 0x80 /* device is IntelliMouse */ +#define FLAG_INTMODE 0x40 /* using Intellimouse mode */ +#define FLAG_SCALED 0x20 /* enable delta scaling */ +#define FLAG_ENABLED 0x10 /* dev is enabled for use */ +#define FLAG_CTRLDAT 0x08 /* ctrl or data mode */ + +#define FIFO_SIZE 16 int mouse_scan = 0; @@ -73,7 +75,7 @@ ps2_report_coordinates(atkbc_dev_t *dev, int main) int temp_z; if (dev->x > 255) { - dev->x = 255; + dev->x = 255; buff[0] |= 0x40; } if (dev->x < -256) { @@ -97,14 +99,7 @@ ps2_report_coordinates(atkbc_dev_t *dev, int main) buff[0] |= 0x10; if (dev->y < 0) buff[0] |= 0x20; - if (mouse_buttons & 0x01) - buff[0] |= 0x01; - if (mouse_buttons & 0x02) - buff[0] |= 0x02; - if (dev->flags & FLAG_INTELLI) { - if (mouse_buttons & 0x04) - buff[0] |= 0x04; - } + buff[0] |= (dev->b & ((dev->flags & FLAG_INTELLI) ? 0x07 : 0x03)); buff[1] = (dev->x & 0xff); buff[2] = (dev->y & 0xff); @@ -317,19 +312,26 @@ static int ps2_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv) { atkbc_dev_t *dev = (atkbc_dev_t *) priv; + int packet_size = (dev->flags & FLAG_INTMODE) ? 4 : 3; if (!mouse_scan || (!x && !y && !z && (b == dev->b))) return (0xff); - dev->x += x; - dev->y -= y; - dev->z -= z; - if ((dev->mode == MODE_STREAM) && (kbc_at_dev_queue_pos(dev, 1) < 13)) { + if ((dev->mode == MODE_STREAM) && (kbc_at_dev_queue_pos(dev, 1) < (FIFO_SIZE - packet_size))) { + dev->x = x; + dev->y = -y; + dev->z = -z; + dev->b = b; + } else { + dev->x += x; + dev->y -= y; + dev->z -= z; dev->b = b; - - ps2_report_coordinates(dev, 1); } + if ((dev->mode == MODE_STREAM) && (kbc_at_dev_queue_pos(dev, 1) < (FIFO_SIZE - packet_size))) + ps2_report_coordinates(dev, 1); + return (0); } @@ -367,6 +369,8 @@ mouse_ps2_init(const device_t *info) dev->scan = &mouse_scan; + dev->fifo_mask = FIFO_SIZE - 1; + if (dev->port != NULL) kbc_at_dev_reset(dev, 0); diff --git a/src/include/86box/keyboard.h b/src/include/86box/keyboard.h index fe642fec1..669d9c6f7 100644 --- a/src/include/86box/keyboard.h +++ b/src/include/86box/keyboard.h @@ -33,7 +33,9 @@ enum { DEV_STATE_MAIN_2, DEV_STATE_MAIN_CMD, DEV_STATE_MAIN_WANT_IN, - DEV_STATE_MAIN_IN + DEV_STATE_MAIN_IN, + DEV_STATE_EXECUTE_BAT, + DEV_STATE_MAIN_WANT_EXECUTE_BAT }; /* Used by the AT / PS/2 keyboard controller, common device, keyboard, and mouse. */ @@ -61,9 +63,9 @@ typedef struct { output multiple bytes. */ uint8_t cmd_queue[16]; - uint8_t queue[16]; + uint8_t queue[64]; - int mode, + int fifo_mask, mode, x, y, z, b; int *scan; From d97dd687a3c016429f3bba4886ce1b8dc1555478 Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 16 May 2023 00:35:39 +0200 Subject: [PATCH 27/34] Rewrite of FXSAVE/FXRSTOR and removed an unused variable from cpu_state_t. --- src/cpu/cpu.h | 2 - src/cpu/x86_ops_i686.h | 207 ++++++++++++++++++++++------------------- 2 files changed, 110 insertions(+), 99 deletions(-) diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index b93e6aa2e..029794bd6 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -402,8 +402,6 @@ typedef struct { uint16_t flags, eflags; uint32_t _smbase; - - uint8_t inside_emulation_mode; } cpu_state_t; typedef struct { diff --git a/src/cpu/x86_ops_i686.h b/src/cpu/x86_ops_i686.h index 8940a98a0..9e00249ca 100644 --- a/src/cpu/x86_ops_i686.h +++ b/src/cpu/x86_ops_i686.h @@ -52,7 +52,64 @@ fx_save_stor_common(uint32_t fetchdat, int bits) uint8_t ftwb = 0; uint16_t rec_ftw = 0; uint16_t fpus = 0; - uint64_t *p; + int i, mmx_tags = 0; + uint16_t exp = 0x0000; + uint64_t mant = 0x0000000000000000ULL; + uint64_t fraction; + uint8_t jm, valid; + /* Exp_all_1 Exp_all_0 Frac_all_0 J M FTW_Valid | Ent + ----------------------------------------------+------ */ + uint8_t ftw_table_idx; + uint8_t ftw_table[48] = { 0x03, /* 0 0 0 0 0 0 | 0x00 */ + 0x02, /* 0 0 0 0 0 1 | 0x01 */ + 0x03, /* 0 0 0 0 0 0 | 0x02 */ + 0x02, /* 0 0 0 0 1 1 | 0x03 */ + 0x03, /* 0 0 0 1 0 0 | 0x04 */ + 0x00, /* 0 0 0 1 0 1 | 0x05 */ + 0x03, /* 0 0 0 1 1 0 | 0x06 */ + 0x00, /* 0 0 0 1 1 1 | 0x07 */ + 0x03, /* 0 0 1 0 0 0 | 0x08 */ + 0x02, /* 0 0 1 0 0 1 | 0x09 */ + 0x03, /* 0 0 1 0 1 0 | 0x0a - Impossible */ + 0x03, /* 0 0 1 0 1 1 | 0x0b - Impossible */ + 0x03, /* 0 0 1 1 0 0 | 0x0c */ + 0x02, /* 0 0 1 1 0 1 | 0x0d */ + 0x03, /* 0 0 1 1 1 0 | 0x0e - Impossible */ + 0x03, /* 0 0 1 1 1 1 | 0x0f - Impossible */ + 0x03, /* 0 1 0 0 0 0 | 0x10 */ + 0x02, /* 0 1 0 0 0 1 | 0x11 */ + 0x03, /* 0 1 0 0 1 0 | 0x12 */ + 0x02, /* 0 1 0 0 1 1 | 0x13 */ + 0x03, /* 0 1 0 1 0 0 | 0x14 */ + 0x02, /* 0 1 0 1 0 1 | 0x15 */ + 0x03, /* 0 1 0 1 1 0 | 0x16 */ + 0x02, /* 0 1 0 1 1 1 | 0x17 */ + 0x03, /* 0 1 1 0 0 0 | 0x18 */ + 0x01, /* 0 1 1 0 0 1 | 0x19 */ + 0x03, /* 0 1 1 0 1 0 | 0x1a - Impossible */ + 0x03, /* 0 1 1 0 1 1 | 0x1b - Impossible */ + 0x03, /* 0 1 1 1 0 0 | 0x1c */ + 0x01, /* 0 1 1 1 0 1 | 0x1d */ + 0x03, /* 0 1 1 1 1 0 | 0x1e - Impossible */ + 0x03, /* 0 1 1 1 1 1 | 0x1f - Impossible */ + 0x03, /* 1 0 0 0 0 0 | 0x20 */ + 0x02, /* 1 0 0 0 0 1 | 0x21 */ + 0x03, /* 1 0 0 0 1 0 | 0x22 */ + 0x02, /* 1 0 0 0 1 1 | 0x23 */ + 0x03, /* 1 0 0 1 0 0 | 0x24 */ + 0x02, /* 1 0 0 1 0 1 | 0x25 */ + 0x03, /* 1 0 0 1 1 0 | 0x26 */ + 0x02, /* 1 0 0 1 1 1 | 0x27 */ + 0x03, /* 1 0 1 0 0 0 | 0x28 */ + 0x02, /* 1 0 1 0 0 1 | 0x29 */ + 0x03, /* 1 0 1 0 1 0 | 0x2a - Impossible */ + 0x03, /* 1 0 1 0 1 1 | 0x2b - Impossible */ + 0x03, /* 1 0 1 1 0 0 | 0x2c */ + 0x02, /* 1 0 1 1 0 1 | 0x2d */ + 0x03, /* 1 0 1 1 1 0 | 0x2e - Impossible */ + 0x03 }; /* 1 0 1 1 1 1 | 0x2f - Impossible */ + /* M is the most significant bit of the franction, so it is impossible + for M to o be 1 when the fraction is all 0's. */ if (CPUID < 0x650) return ILLEGAL(fetchdat); @@ -96,90 +153,70 @@ fx_save_stor_common(uint32_t fetchdat, int bits) ftwb = readmemb(easeg, cpu_state.eaaddr + 4); - if (ftwb & 0x01) - rec_ftw |= 0x0003; - if (ftwb & 0x02) - rec_ftw |= 0x000C; - if (ftwb & 0x04) - rec_ftw |= 0x0030; - if (ftwb & 0x08) - rec_ftw |= 0x00C0; - if (ftwb & 0x10) - rec_ftw |= 0x0300; - if (ftwb & 0x20) - rec_ftw |= 0x0C00; - if (ftwb & 0x40) - rec_ftw |= 0x3000; - if (ftwb & 0x80) - rec_ftw |= 0xC000; - x87_op_off = readmeml(easeg, cpu_state.eaaddr + 16); x87_op_off |= (readmemw(easeg, cpu_state.eaaddr + 6) >> 12) << 16; x87_op_seg = readmemw(easeg, cpu_state.eaaddr + 20); - cpu_state.eaaddr = old_eaaddr + 32; - x87_ldmmx(&(cpu_state.MM[0]), &(cpu_state.MM_w4[0])); - x87_ld_frstor(0); + for (i = 0; i <= 7; i++) { + cpu_state.eaaddr = old_eaaddr + 32 + (i << 4); + mant = readmemq(easeg, cpu_state.eaaddr); + fraction = mant & 0x7fffffffffffffffULL; + exp = readmemw(easeg, cpu_state.eaaddr + 8); + jm = (mant >> 62) & 0x03; + valid = !(ftwb & (1 << i)); - cpu_state.eaaddr = old_eaaddr + 48; - x87_ldmmx(&(cpu_state.MM[1]), &(cpu_state.MM_w4[1])); - x87_ld_frstor(1); + ftw_table_idx = (!!(exp == 0x1111)) << 5; + ftw_table_idx |= (!!(exp == 0x0000)) << 4; + ftw_table_idx |= (!!(fraction == 0x0000000000000000ULL)) << 3; + ftw_table_idx |= (jm << 1); + ftw_table_idx |= valid; - cpu_state.eaaddr = old_eaaddr + 64; - x87_ldmmx(&(cpu_state.MM[2]), &(cpu_state.MM_w4[2])); - x87_ld_frstor(2); + rec_ftw |= (ftw_table[ftw_table_idx] << (i << 1)); - cpu_state.eaaddr = old_eaaddr + 80; - x87_ldmmx(&(cpu_state.MM[3]), &(cpu_state.MM_w4[3])); - x87_ld_frstor(3); - - cpu_state.eaaddr = old_eaaddr + 96; - x87_ldmmx(&(cpu_state.MM[4]), &(cpu_state.MM_w4[4])); - x87_ld_frstor(4); - - cpu_state.eaaddr = old_eaaddr + 112; - x87_ldmmx(&(cpu_state.MM[5]), &(cpu_state.MM_w4[5])); - x87_ld_frstor(5); - - cpu_state.eaaddr = old_eaaddr + 128; - x87_ldmmx(&(cpu_state.MM[6]), &(cpu_state.MM_w4[6])); - x87_ld_frstor(6); - - cpu_state.eaaddr = old_eaaddr + 144; - x87_ldmmx(&(cpu_state.MM[7]), &(cpu_state.MM_w4[7])); - x87_ld_frstor(7); + if (exp == 0xffff) + mmx_tags++; + } cpu_state.ismmx = 0; - /*Horrible hack, but as 86Box doesn't keep the FPU stack in 80-bit precision at all times - something like this is needed*/ - p = (uint64_t *) cpu_state.tag; -#ifdef USE_NEW_DYNAREC - if (cpu_state.MM_w4[0] == 0xffff && cpu_state.MM_w4[1] == 0xffff && cpu_state.MM_w4[2] == 0xffff && cpu_state.MM_w4[3] == 0xffff && cpu_state.MM_w4[4] == 0xffff && cpu_state.MM_w4[5] == 0xffff && cpu_state.MM_w4[6] == 0xffff && cpu_state.MM_w4[7] == 0xffff && !cpu_state.TOP && (*p == 0x0101010101010101ull)) -#else - if (cpu_state.MM_w4[0] == 0xffff && cpu_state.MM_w4[1] == 0xffff && cpu_state.MM_w4[2] == 0xffff && cpu_state.MM_w4[3] == 0xffff && cpu_state.MM_w4[4] == 0xffff && cpu_state.MM_w4[5] == 0xffff && cpu_state.MM_w4[6] == 0xffff && cpu_state.MM_w4[7] == 0xffff && !cpu_state.TOP && !(*p)) -#endif + /* Determine, whether or not the saved state is x87 or MMX based on a heuristic, + because we do not keep the internal state in 64-bit precision. + + TODO: Is there no way to unify the whole lot? */ + if ((mmx_tags == 8) && !cpu_state.TOP) cpu_state.ismmx = 1; x87_settag(rec_ftw); + if (cpu_state.ismmx) { + for (i = 0; i <= 7; i++) { + cpu_state.eaaddr = old_eaaddr + 32 + (i << 4); + x87_ldmmx(&(cpu_state.MM[i]), &(cpu_state.MM_w4[i])); + } + } else { + for (i = 0; i <= 7; i++) { + cpu_state.eaaddr = old_eaaddr + 32 + (i << 4); + x87_ld_frstor(i); + } + } + CLOCK_CYCLES((cr0 & 1) ? 34 : 44); } else { /* FXSAVE */ - if ((twd & 0x0003) == 0x0003) + if ((twd & 0x0003) != 0x0003) ftwb |= 0x01; - if ((twd & 0x000C) == 0x000C) + if ((twd & 0x000c) != 0x000c) ftwb |= 0x02; - if ((twd & 0x0030) == 0x0030) + if ((twd & 0x0030) != 0x0030) ftwb |= 0x04; - if ((twd & 0x00C0) == 0x00C0) + if ((twd & 0x00c0) != 0x00c0) ftwb |= 0x08; - if ((twd & 0x0300) == 0x0300) + if ((twd & 0x0300) != 0x0300) ftwb |= 0x10; - if ((twd & 0x0C00) == 0x0C00) + if ((twd & 0x0c00) != 0x0c00) ftwb |= 0x20; - if ((twd & 0x3000) == 0x3000) + if ((twd & 0x3000) != 0x3000) ftwb |= 0x40; - if ((twd & 0xC000) == 0xC000) + if ((twd & 0xc000) != 0xc000) ftwb |= 0x80; writememw(easeg, cpu_state.eaaddr, cpu_state.npxc); @@ -193,44 +230,20 @@ fx_save_stor_common(uint32_t fetchdat, int bits) writememl(easeg, cpu_state.eaaddr + 16, x87_op_off); writememw(easeg, cpu_state.eaaddr + 20, x87_op_seg); - cpu_state.eaaddr = old_eaaddr + 32; - cpu_state.ismmx ? x87_stmmx(cpu_state.MM[0]) : x87_st_fsave(0); - - cpu_state.eaaddr = old_eaaddr + 48; - cpu_state.ismmx ? x87_stmmx(cpu_state.MM[1]) : x87_st_fsave(1); - - cpu_state.eaaddr = old_eaaddr + 64; - cpu_state.ismmx ? x87_stmmx(cpu_state.MM[2]) : x87_st_fsave(2); - - cpu_state.eaaddr = old_eaaddr + 80; - cpu_state.ismmx ? x87_stmmx(cpu_state.MM[3]) : x87_st_fsave(3); - - cpu_state.eaaddr = old_eaaddr + 96; - cpu_state.ismmx ? x87_stmmx(cpu_state.MM[4]) : x87_st_fsave(4); - - cpu_state.eaaddr = old_eaaddr + 112; - cpu_state.ismmx ? x87_stmmx(cpu_state.MM[5]) : x87_st_fsave(5); - - cpu_state.eaaddr = old_eaaddr + 128; - cpu_state.ismmx ? x87_stmmx(cpu_state.MM[6]) : x87_st_fsave(6); - - cpu_state.eaaddr = old_eaaddr + 144; - cpu_state.ismmx ? x87_stmmx(cpu_state.MM[7]) : x87_st_fsave(7); + if (cpu_state.ismmx) { + for (i = 0; i <= 7; i++) { + cpu_state.eaaddr = old_eaaddr + 32 + (i << 4); + x87_stmmx(cpu_state.MM[i]); + } + } else { + for (i = 0; i <= 7; i++) { + cpu_state.eaaddr = old_eaaddr + 32 + (i << 4); + x87_st_fsave(i); + } + } cpu_state.eaaddr = old_eaaddr; - cpu_state.npxc = 0x37F; - codegen_set_rounding_mode(X87_ROUNDING_NEAREST); - cpu_state.npxs = 0; - p = (uint64_t *) cpu_state.tag; -#ifdef USE_NEW_DYNAREC - *p = 0; -#else - *p = 0x0303030303030303ll; -#endif - cpu_state.TOP = 0; - cpu_state.ismmx = 0; - CLOCK_CYCLES((cr0 & 1) ? 56 : 67); } From 5c6255f7874987a9804881cef633619bd4b665ac Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 16 May 2023 00:36:57 +0200 Subject: [PATCH 28/34] Corrected the P54TP4XE keyboard controller. --- src/machine/m_at_socket7_3v.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/machine/m_at_socket7_3v.c b/src/machine/m_at_socket7_3v.c index 55a5068d9..d8be38bb1 100644 --- a/src/machine/m_at_socket7_3v.c +++ b/src/machine/m_at_socket7_3v.c @@ -81,7 +81,7 @@ machine_at_p54tp4xe_common_init(const machine_t *model) pci_register_slot(0x0A, PCI_CARD_NORMAL, 3, 4, 1, 2); pci_register_slot(0x09, PCI_CARD_NORMAL, 4, 1, 2, 3); pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); - device_add(&keyboard_ps2_pci_device); + device_add(&keyboard_ps2_ami_pci_device); device_add(&i430fx_device); device_add(&piix_device); device_add(&fdc37c665_device); From 1863b72f67d17759aa77d5d4c7e1a6296f30aa68 Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 16 May 2023 00:38:28 +0200 Subject: [PATCH 29/34] Changed the way the PIC keyboard and mouse IRQ latches operate to avoid spurious IRQ's. --- src/pic.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/pic.c b/src/pic.c index e078cb94a..9ebf9ac00 100644 --- a/src/pic.c +++ b/src/pic.c @@ -57,6 +57,8 @@ static int shadow = 0, elcr_enabled = 0, static uint16_t smi_irq_mask = 0x0000, smi_irq_status = 0x0000; +static uint16_t latched_irqs = 0x0000; + static void (*update_pending)(void); #ifdef ENABLE_PIC_LOG @@ -397,10 +399,10 @@ pic_latch_read(uint16_t addr, void *priv) pic_log("pic_latch_read(%i, %i): %02X%02X\n", kbd_latch, mouse_latch, pic2.lines & 0x10, pic.lines & 0x02); - if (kbd_latch && (pic.lines & 0x02)) + if (kbd_latch && (latched_irqs & 0x0002)) picintc(0x0002); - if (mouse_latch && (pic2.lines & 0x10)) + if (mouse_latch && (latched_irqs & 0x1000)) picintc(0x1000); /* Return FF - we just lower IRQ 1 and IRQ 12. */ @@ -572,6 +574,7 @@ pic_reset_hard(void) /* Explicitly reset the latches. */ kbd_latch = mouse_latch = 0; + latched_irqs = 0x0000; /* The situation is as follows: There is a giant mess when it comes to these latches on real hardware, to the point that there's even boards with board-level latched that get used in place of the latches @@ -656,7 +659,7 @@ picint_common(uint16_t num, int level, int set) /* Latch IRQ 12 if the mouse latch is enabled. */ if ((num & 0x1000) && mouse_latch) - pic2.lines |= 0x10; + latched_irqs |= 0x1000; pic2.irr |= (num >> 8); } @@ -665,8 +668,9 @@ picint_common(uint16_t num, int level, int set) if (level) pic.lines |= (num & 0x00ff); + /* Latch IRQ 1 if the keyboard latch is enabled. */ if (kbd_latch && (num & 0x0002)) - pic.lines |= 0x02; + latched_irqs |= 0x0002; pic.irr |= (num & 0x00ff); } @@ -676,12 +680,20 @@ picint_common(uint16_t num, int level, int set) if (num & 0xff00) { pic2.lines &= ~(num >> 8); + /* Unlatch IRQ 12 if the mouse latch is enabled. */ + if ((num & 0x1000) && mouse_latch) + latched_irqs &= 0xefff; + pic2.irr &= ~(num >> 8); } if (num & 0x00ff) { pic.lines &= ~(num & 0x00ff); + /* Unlatch IRQ 1 if the keyboard latch is enabled. */ + if (kbd_latch && (num & 0x0002)) + latched_irqs &= 0xfffd; + pic.irr &= ~(num & 0x00ff); } } From 326b329c971070b49167ff8d3f668c760fc75ef4 Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 16 May 2023 00:46:39 +0200 Subject: [PATCH 30/34] (REP) MOVS*, CMPS*: Make sure to do the segment checks first to ensure GPF has priority over page fault. --- src/cpu/x86_ops_rep.h | 12 +++++----- src/cpu/x86_ops_rep_dyn.h | 12 +++++----- src/cpu/x86_ops_string.h | 48 +++++++++++++++++++-------------------- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/cpu/x86_ops_rep.h b/src/cpu/x86_ops_rep.h index 4b8f42185..a49db7e81 100644 --- a/src/cpu/x86_ops_rep.h +++ b/src/cpu/x86_ops_rep.h @@ -226,11 +226,11 @@ uint8_t temp; \ \ CHECK_READ_REP(cpu_state.ea_seg, SRC_REG, SRC_REG); \ + CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG); \ high_page = 0; \ do_mmut_rb(cpu_state.ea_seg->base, SRC_REG, &addr64); \ if (cpu_state.abrt) \ break; \ - CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG); \ do_mmut_wb(es, DEST_REG, &addr64_2); \ if (cpu_state.abrt) \ break; \ @@ -280,11 +280,11 @@ uint16_t temp; \ \ CHECK_READ_REP(cpu_state.ea_seg, SRC_REG, SRC_REG + 1UL); \ + CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG + 1UL); \ high_page = 0; \ do_mmut_rw(cpu_state.ea_seg->base, SRC_REG, addr64a); \ if (cpu_state.abrt) \ break; \ - CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG + 1UL); \ do_mmut_ww(es, DEST_REG, addr64a_2); \ if (cpu_state.abrt) \ break; \ @@ -334,11 +334,11 @@ uint32_t temp; \ \ CHECK_READ_REP(cpu_state.ea_seg, SRC_REG, SRC_REG + 3UL); \ + CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG + 3UL); \ high_page = 0; \ do_mmut_rl(cpu_state.ea_seg->base, SRC_REG, addr64a); \ if (cpu_state.abrt) \ break; \ - CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG + 3UL); \ do_mmut_wl(es, DEST_REG, addr64a_2); \ if (cpu_state.abrt) \ break; \ @@ -582,11 +582,11 @@ SEG_CHECK_READ(cpu_state.ea_seg); \ SEG_CHECK_READ(&cpu_state.seg_es); \ CHECK_READ(cpu_state.ea_seg, SRC_REG, SRC_REG); \ + CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG); \ high_page = uncached = 0; \ do_mmut_rb(cpu_state.ea_seg->base, SRC_REG, &addr64); \ if (cpu_state.abrt) \ return 1; \ - CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG); \ do_mmut_rb2(es, DEST_REG, &addr64_2); \ if (cpu_state.abrt) \ return 1; \ @@ -636,11 +636,11 @@ SEG_CHECK_READ(cpu_state.ea_seg); \ SEG_CHECK_READ(&cpu_state.seg_es); \ CHECK_READ(cpu_state.ea_seg, SRC_REG, SRC_REG + 1UL); \ + CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG + 1UL); \ high_page = uncached = 0; \ do_mmut_rw(cpu_state.ea_seg->base, SRC_REG, addr64a); \ if (cpu_state.abrt) \ return 1; \ - CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG + 1UL); \ do_mmut_rw2(es, DEST_REG, addr64a_2); \ if (cpu_state.abrt) \ return 1; \ @@ -690,11 +690,11 @@ SEG_CHECK_READ(cpu_state.ea_seg); \ SEG_CHECK_READ(&cpu_state.seg_es); \ CHECK_READ(cpu_state.ea_seg, SRC_REG, SRC_REG + 3UL); \ + CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG + 3UL); \ high_page = uncached = 0; \ do_mmut_rl(cpu_state.ea_seg->base, SRC_REG, addr64a); \ if (cpu_state.abrt) \ return 1; \ - CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG + 3UL); \ do_mmut_rl2(es, DEST_REG, addr64a_2); \ if (cpu_state.abrt) \ return 1; \ diff --git a/src/cpu/x86_ops_rep_dyn.h b/src/cpu/x86_ops_rep_dyn.h index 5c64ed94d..cf32209cc 100644 --- a/src/cpu/x86_ops_rep_dyn.h +++ b/src/cpu/x86_ops_rep_dyn.h @@ -189,11 +189,11 @@ uint8_t temp; \ \ CHECK_READ_REP(cpu_state.ea_seg, SRC_REG, SRC_REG); \ + CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG); \ high_page = 0; \ do_mmut_rb(cpu_state.ea_seg->base, SRC_REG, &addr64); \ if (cpu_state.abrt) \ break; \ - CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG); \ do_mmut_wb(es, DEST_REG, &addr64_2); \ if (cpu_state.abrt) \ break; \ @@ -238,11 +238,11 @@ uint16_t temp; \ \ CHECK_READ_REP(cpu_state.ea_seg, SRC_REG, SRC_REG + 1UL); \ + CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG + 1UL); \ high_page = 0; \ do_mmut_rw(cpu_state.ea_seg->base, SRC_REG, addr64a); \ if (cpu_state.abrt) \ break; \ - CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG + 1UL); \ do_mmut_ww(es, DEST_REG, addr64a_2); \ if (cpu_state.abrt) \ break; \ @@ -287,11 +287,11 @@ uint32_t temp; \ \ CHECK_READ_REP(cpu_state.ea_seg, SRC_REG, SRC_REG + 3UL); \ + CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG + 3UL); \ high_page = 0; \ do_mmut_rl(cpu_state.ea_seg->base, SRC_REG, addr64a); \ if (cpu_state.abrt) \ break; \ - CHECK_WRITE_REP(&cpu_state.seg_es, DEST_REG, DEST_REG + 3UL); \ do_mmut_wl(es, DEST_REG, addr64a_2); \ if (cpu_state.abrt) \ break; \ @@ -507,11 +507,11 @@ SEG_CHECK_READ(cpu_state.ea_seg); \ SEG_CHECK_READ(&cpu_state.seg_es); \ CHECK_READ(cpu_state.ea_seg, SRC_REG, SRC_REG); \ + CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG); \ high_page = uncached = 0; \ do_mmut_rb(cpu_state.ea_seg->base, SRC_REG, &addr64); \ if (cpu_state.abrt) \ return 1; \ - CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG); \ do_mmut_rb2(es, DEST_REG, &addr64_2); \ if (cpu_state.abrt) \ return 1; \ @@ -558,11 +558,11 @@ SEG_CHECK_READ(cpu_state.ea_seg); \ SEG_CHECK_READ(&cpu_state.seg_es); \ CHECK_READ(cpu_state.ea_seg, SRC_REG, SRC_REG + 1UL); \ + CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG + 1UL); \ high_page = uncached = 0; \ do_mmut_rw(cpu_state.ea_seg->base, SRC_REG, addr64a); \ if (cpu_state.abrt) \ return 1; \ - CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG + 1UL); \ do_mmut_rw2(es, DEST_REG, addr64a_2); \ if (cpu_state.abrt) \ return 1; \ @@ -609,11 +609,11 @@ SEG_CHECK_READ(cpu_state.ea_seg); \ SEG_CHECK_READ(&cpu_state.seg_es); \ CHECK_READ(cpu_state.ea_seg, SRC_REG, SRC_REG + 3UL); \ + CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG + 3UL); \ high_page = uncached = 0; \ do_mmut_rl(cpu_state.ea_seg->base, SRC_REG, addr64a); \ if (cpu_state.abrt) \ return 1; \ - CHECK_READ(&cpu_state.seg_es, DEST_REG, DEST_REG + 3UL); \ do_mmut_rl2(es, DEST_REG, addr64a_2); \ if (cpu_state.abrt) \ return 1; \ diff --git a/src/cpu/x86_ops_string.h b/src/cpu/x86_ops_string.h index c3875a648..c9ba94760 100644 --- a/src/cpu/x86_ops_string.h +++ b/src/cpu/x86_ops_string.h @@ -6,13 +6,13 @@ opMOVSB_a16(uint32_t fetchdat) addr64 = addr64_2 = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, SI, SI); + CHECK_WRITE(&cpu_state.seg_es, DI, DI); high_page = 0; do_mmut_rb(cpu_state.ea_seg->base, SI, &addr64); if (cpu_state.abrt) return 1; - SEG_CHECK_WRITE(&cpu_state.seg_es); - CHECK_WRITE(&cpu_state.seg_es, DI, DI); do_mmut_wb(es, DI, &addr64_2); if (cpu_state.abrt) @@ -42,13 +42,13 @@ opMOVSB_a32(uint32_t fetchdat) addr64 = addr64_2 = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, ESI, ESI); + CHECK_WRITE(&cpu_state.seg_es, EDI, EDI); high_page = 0; do_mmut_rb(cpu_state.ea_seg->base, ESI, &addr64); if (cpu_state.abrt) return 1; - SEG_CHECK_WRITE(&cpu_state.seg_es); - CHECK_WRITE(&cpu_state.seg_es, EDI, EDI); do_mmut_wb(es, EDI, &addr64_2); if (cpu_state.abrt) return 1; @@ -79,13 +79,13 @@ opMOVSW_a16(uint32_t fetchdat) addr64a_2[0] = addr64a_2[1] = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, SI, SI + 1UL); + CHECK_WRITE(&cpu_state.seg_es, DI, DI + 1UL); high_page = 0; do_mmut_rw(cpu_state.ea_seg->base, SI, addr64a); if (cpu_state.abrt) return 1; - SEG_CHECK_WRITE(&cpu_state.seg_es); - CHECK_WRITE(&cpu_state.seg_es, DI, DI + 1UL); do_mmut_ww(es, DI, addr64a_2); if (cpu_state.abrt) return 1; @@ -115,13 +115,13 @@ opMOVSW_a32(uint32_t fetchdat) addr64a_2[0] = addr64a_2[1] = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, ESI, ESI + 1UL); + CHECK_WRITE(&cpu_state.seg_es, EDI, EDI + 1UL); high_page = 0; do_mmut_rw(cpu_state.ea_seg->base, ESI, addr64a); if (cpu_state.abrt) return 1; - SEG_CHECK_WRITE(&cpu_state.seg_es); - CHECK_WRITE(&cpu_state.seg_es, EDI, EDI + 1UL); do_mmut_ww(es, EDI, addr64a_2); if (cpu_state.abrt) return 1; @@ -152,13 +152,13 @@ opMOVSL_a16(uint32_t fetchdat) addr64a_2[0] = addr64a_2[1] = addr64a_2[2] = addr64a_2[3] = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, SI, SI + 3UL); + CHECK_WRITE(&cpu_state.seg_es, DI, DI + 3UL); high_page = 0; do_mmut_rl(cpu_state.ea_seg->base, SI, addr64a); if (cpu_state.abrt) return 1; - SEG_CHECK_WRITE(&cpu_state.seg_es); - CHECK_WRITE(&cpu_state.seg_es, DI, DI + 3UL); do_mmut_wl(es, DI, addr64a_2); if (cpu_state.abrt) return 1; @@ -188,13 +188,13 @@ opMOVSL_a32(uint32_t fetchdat) addr64a_2[0] = addr64a_2[1] = addr64a_2[2] = addr64a_2[3] = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_WRITE(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, ESI, ESI + 3UL); + CHECK_WRITE(&cpu_state.seg_es, EDI, EDI + 3UL); high_page = 0; do_mmut_rl(cpu_state.ea_seg->base, ESI, addr64a); if (cpu_state.abrt) return 1; - SEG_CHECK_WRITE(&cpu_state.seg_es); - CHECK_WRITE(&cpu_state.seg_es, EDI, EDI + 3UL); do_mmut_wl(es, EDI, addr64a_2); if (cpu_state.abrt) return 1; @@ -224,13 +224,13 @@ opCMPSB_a16(uint32_t fetchdat) addr64 = addr64_2 = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_READ(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, SI, SI); + CHECK_READ(&cpu_state.seg_es, DI, DI); high_page = uncached = 0; do_mmut_rb(cpu_state.ea_seg->base, SI, &addr64); if (cpu_state.abrt) return 1; - SEG_CHECK_READ(&cpu_state.seg_es); - CHECK_READ(&cpu_state.seg_es, DI, DI); do_mmut_rb2(es, DI, &addr64_2); if (cpu_state.abrt) return 1; @@ -264,13 +264,13 @@ opCMPSB_a32(uint32_t fetchdat) addr64 = addr64_2 = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_READ(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, ESI, ESI); + CHECK_READ(&cpu_state.seg_es, EDI, EDI); high_page = uncached = 0; do_mmut_rb(cpu_state.ea_seg->base, ESI, &addr64); if (cpu_state.abrt) return 1; - SEG_CHECK_READ(&cpu_state.seg_es); - CHECK_READ(&cpu_state.seg_es, EDI, EDI); do_mmut_rb2(es, EDI, &addr64_2); if (cpu_state.abrt) return 1; @@ -306,13 +306,13 @@ opCMPSW_a16(uint32_t fetchdat) addr64a_2[0] = addr64a_2[1] = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_READ(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, SI, SI + 1UL); + CHECK_READ(&cpu_state.seg_es, DI, DI + 1UL); high_page = uncached = 0; do_mmut_rw(cpu_state.ea_seg->base, SI, addr64a); if (cpu_state.abrt) return 1; - SEG_CHECK_READ(&cpu_state.seg_es); - CHECK_READ(&cpu_state.seg_es, DI, DI + 1UL); do_mmut_rw2(es, DI, addr64a_2); if (cpu_state.abrt) return 1; @@ -347,13 +347,13 @@ opCMPSW_a32(uint32_t fetchdat) addr64a_2[0] = addr64a_2[1] = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_READ(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, ESI, ESI + 1UL); + CHECK_READ(&cpu_state.seg_es, EDI, EDI + 1UL); high_page = uncached = 0; do_mmut_rw(cpu_state.ea_seg->base, ESI, addr64a); if (cpu_state.abrt) return 1; - SEG_CHECK_READ(&cpu_state.seg_es); - CHECK_READ(&cpu_state.seg_es, EDI, EDI + 1UL); do_mmut_rw2(es, EDI, addr64a_2); if (cpu_state.abrt) return 1; @@ -389,13 +389,13 @@ opCMPSL_a16(uint32_t fetchdat) addr64a_2[0] = addr64a_2[1] = addr64a_2[2] = addr64a_2[3] = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_READ(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, SI, SI + 3UL); + CHECK_READ(&cpu_state.seg_es, DI, DI + 3UL); high_page = uncached = 0; do_mmut_rl(cpu_state.ea_seg->base, SI, addr64a); if (cpu_state.abrt) return 1; - SEG_CHECK_READ(&cpu_state.seg_es); - CHECK_READ(&cpu_state.seg_es, DI, DI + 3UL); do_mmut_rl2(es, DI, addr64a_2); if (cpu_state.abrt) return 1; @@ -430,13 +430,13 @@ opCMPSL_a32(uint32_t fetchdat) addr64a_2[0] = addr64a_2[1] = addr64a_2[2] = addr64a_2[3] = 0x00000000; SEG_CHECK_READ(cpu_state.ea_seg); + SEG_CHECK_READ(&cpu_state.seg_es); CHECK_READ(cpu_state.ea_seg, ESI, ESI + 3UL); + CHECK_READ(&cpu_state.seg_es, EDI, EDI + 3UL); high_page = uncached = 0; do_mmut_rl(cpu_state.ea_seg->base, ESI, addr64a); if (cpu_state.abrt) return 1; - SEG_CHECK_READ(&cpu_state.seg_es); - CHECK_READ(&cpu_state.seg_es, EDI, EDI + 3UL); do_mmut_rl2(es, EDI, addr64a_2); if (cpu_state.abrt) return 1; From 6bb5942ad11f8c523cc6f3bc1585bdeba9976fa7 Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 16 May 2023 00:53:59 +0200 Subject: [PATCH 31/34] Finish merge. --- sonar-project.properties | 12 ++ src/chipset/ali6117.c | 1 - src/include/86box/network.h | 12 +- src/include/86box/usb.h | 149 +++++++++++++++++----- src/machine/machine_table.c | 2 +- src/network/CMakeLists.txt | 2 +- src/network/net_null.c | 224 ++++++++++++++++++++++++++++++++++ src/network/net_vde.c | 2 +- src/network/network.c | 50 ++++++-- src/qt/qt_mediamenu.cpp | 2 +- src/qt/qt_settingsnetwork.cpp | 9 +- src/win/Makefile.mingw | 3 +- src/win/languages/dialogs.rc | 28 +++-- src/win/win_settings.c | 2 +- 14 files changed, 429 insertions(+), 69 deletions(-) create mode 100644 sonar-project.properties create mode 100644 src/network/net_null.c diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 000000000..781fad035 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,12 @@ +sonar.projectKey=86Box_86Box +sonar.organization=86box + +# This is the name and version displayed in the SonarCloud UI. +#sonar.projectName=86Box +#sonar.projectVersion=1.0 + +# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. +#sonar.sources=. + +# Encoding of the source code. Default is default system encoding +#sonar.sourceEncoding=UTF-8 diff --git a/src/chipset/ali6117.c b/src/chipset/ali6117.c index 98451067a..796ca880f 100644 --- a/src/chipset/ali6117.c +++ b/src/chipset/ali6117.c @@ -30,7 +30,6 @@ #include <86box/pit.h> #include <86box/device.h> #include <86box/port_92.h> -#include <86box/usb.h> #include <86box/hdc.h> #include <86box/hdc_ide.h> #include <86box/chipset.h> diff --git a/src/include/86box/network.h b/src/include/86box/network.h index 4f514d1ac..3b5be7e76 100644 --- a/src/include/86box/network.h +++ b/src/include/86box/network.h @@ -48,7 +48,7 @@ #include /* Network provider types. */ -#define NET_TYPE_NONE 0 /* networking disabled */ +#define NET_TYPE_NONE 0 /* use the null network driver */ #define NET_TYPE_SLIRP 1 /* use the SLiRP port forwarder */ #define NET_TYPE_PCAP 2 /* use the (Win)Pcap API */ #define NET_TYPE_VDE 3 /* use the VDE plug API */ @@ -57,6 +57,7 @@ /* Queue size must be a power of 2 */ #define NET_QUEUE_LEN 16 #define NET_QUEUE_LEN_MASK (NET_QUEUE_LEN - 1) +#define NET_QUEUE_COUNT 3 #define NET_CARD_MAX 4 #define NET_HOST_INTF_MAX 64 @@ -125,6 +126,7 @@ typedef struct netdrv_t { extern const netdrv_t net_pcap_drv; extern const netdrv_t net_slirp_drv; extern const netdrv_t net_vde_drv; +extern const netdrv_t net_null_drv; struct _netcard_t { const device_t *device; @@ -132,7 +134,7 @@ struct _netcard_t { struct netdrv_t host_drv; NETRXCB rx; NETSETLINKSTATE set_link_state; - netqueue_t queues[3]; + netqueue_t queues[NET_QUEUE_COUNT]; netpkt_t queued_pkt; mutex_t *tx_mutex; mutex_t *rx_mutex; @@ -150,9 +152,9 @@ typedef struct { } netdev_t; typedef struct { - int has_slirp: 1; - int has_pcap: 1; - int has_vde: 1; + int has_slirp; + int has_pcap; + int has_vde; } network_devmap_t; diff --git a/src/include/86box/usb.h b/src/include/86box/usb.h index 6582f05e4..d0801b99c 100644 --- a/src/include/86box/usb.h +++ b/src/include/86box/usb.h @@ -23,6 +23,29 @@ extern "C" { #endif typedef struct usb_t usb_t; +typedef struct usb_device_t usb_device_t; + +enum usb_pid +{ + USB_PID_OUT = 0xE1, + USB_PID_IN = 0x69, + USB_PID_SETUP = 0x2D +}; + +enum usb_errors +{ + USB_ERROR_NO_ERROR = 0, + USB_ERROR_NAK = 1, + USB_ERROR_OVERRUN = 2, + USB_ERROR_UNDERRUN = 3 +}; + +enum usb_bus_types +{ + USB_BUS_OHCI = 0, + USB_BUS_UHCI, + USB_BUS_MAX +}; /* USB device creation parameters struct */ typedef struct @@ -50,14 +73,18 @@ typedef struct usb_t uint32_t ohci_mem_base, irq_level; mem_mapping_t ohci_mmio_mapping; pc_timer_t ohci_frame_timer; - pc_timer_t ohci_interrupt_desc_poll_timer; pc_timer_t ohci_port_reset_timer[2]; - uint8_t ohci_interrupt_counter : 5; + uint8_t ohci_interrupt_counter : 3; + usb_device_t* ohci_devices[2]; + usb_device_t* uhci_devices[2]; + uint8_t ohci_usb_buf[4096]; + uint8_t ohci_initial_start; usb_params_t* usb_params; } usb_t; #pragma pack(push, 1) + /* Base USB descriptor struct. */ typedef struct { @@ -65,6 +92,66 @@ typedef struct uint8_t bDescriptorType; } usb_desc_base_t; +enum usb_desc_setup_req_types +{ + USB_SETUP_TYPE_DEVICE = 0x0, + USB_SETUP_TYPE_INTERFACE = 0x1, + USB_SETUP_TYPE_ENDPOING = 0x2, + USB_SETUP_TYPE_OTHER = 0x3, +}; + +#define USB_SETUP_TYPE_MAX 0x1F + +#define USB_SETUP_DEV_TO_HOST 0x80 + +typedef struct +{ + uint8_t bmRequestType; + uint8_t bRequest; + uint16_t wValue; + uint16_t wIndex; + uint16_t wLength; +} usb_desc_setup_t; + +typedef struct +{ + usb_desc_base_t base; + uint8_t bEndpointAddress; + uint8_t bmAttributes; + uint16_t wMaxPacketSize; + uint8_t bInterval; +} usb_desc_endpoint_t; + +typedef struct +{ + usb_desc_base_t base; + + uint16_t bcdHID; + uint8_t bCountryCode; + uint8_t bNumDescriptors; + uint8_t bDescriptorType; + uint16_t wDescriptorLength; +} usb_desc_hid_t; + +typedef struct +{ + usb_desc_base_t base; + + uint8_t bInterfaceNumber; + uint8_t bAlternateSetting; + uint8_t bNumEndpoints; + uint8_t bInterfaceClass; + uint8_t bInterfaceSubClass; + uint8_t bInterfaceProtocol; + uint8_t iInterface; +} usb_desc_interface_t; + +typedef struct +{ + usb_desc_base_t base; + uint16_t bString[]; +} usb_desc_string_t; + typedef struct { usb_desc_base_t base; @@ -76,43 +163,49 @@ typedef struct uint8_t bmAttributes; uint8_t bMaxPower; } usb_desc_conf_t; + +typedef struct +{ + usb_desc_base_t base; + + uint16_t bcdUSB; + uint8_t bDeviceClass; + uint8_t bDeviceSubClass; + uint8_t bDeviceProtocol; + uint8_t bMaxPacketSize; + uint16_t idVendor; + uint16_t idProduct; + uint16_t bcdDevice; + uint8_t iManufacturer; + uint8_t iProduct; + uint8_t iSerialNumber; + uint8_t bNumConfigurations; +} usb_desc_device_t; + #pragma pack(pop) -typedef struct -{ - uint32_t HccaInterrruptTable[32]; - uint16_t HccaFrameNumber; - uint16_t HccaPad1; - uint32_t HccaDoneHead; - uint32_t Reserved[29]; -} usb_hcca_t; - /* USB endpoint device struct. Incomplete and unused. */ -typedef struct +typedef struct usb_device_t { - uint16_t vendor_id; - uint16_t device_id; + usb_desc_device_t device_desc; + struct { + usb_desc_conf_t conf_desc; + usb_desc_base_t* other_descs[16]; + } conf_desc_items; - /* Reads from endpoint. Non-zero value indicates error. */ - uint8_t (*device_in)(void* priv, uint8_t* data, uint32_t len); - /* Writes to endpoint. Non-zero value indicates error. */ - uint8_t (*device_out)(void* priv, uint8_t* data, uint32_t len); - /* Process setup packets. */ - uint8_t (*device_setup)(void* priv, uint8_t* data); - /* Device reset */ + /* General-purpose function for I/O. Non-zero value indicates error. */ + uint8_t (*device_process)(void* priv, uint8_t* data, uint32_t *len, uint8_t pid_token, uint8_t endpoint, uint8_t underrun_not_allowed); + /* Device reset. */ void (*device_reset)(void* priv); - + /* Get address. */ + uint8_t (*device_get_address)(void* priv); + void* priv; } usb_device_t; -enum usb_bus_types -{ - USB_BUS_OHCI = 0, - USB_BUS_UHCI = 1 -}; - /* Global variables. */ extern const device_t usb_device; +extern usb_t* usb_device_inst; /* Functions. */ extern void uhci_update_io_mapping(usb_t *dev, uint8_t base_l, uint8_t base_h, int enable); diff --git a/src/machine/machine_table.c b/src/machine/machine_table.c index f089fe93e..bb91e6977 100644 --- a/src/machine/machine_table.c +++ b/src/machine/machine_table.c @@ -303,7 +303,7 @@ const machine_t machines[] = { .ram = { .min = 128, .max = 640, - .step = 128 + .step = 64 }, .nvrmask = 0, .kbc_device = NULL, /* TODO: No specific kbd_device yet */ diff --git a/src/network/CMakeLists.txt b/src/network/CMakeLists.txt index c6178a790..94e066a19 100644 --- a/src/network/CMakeLists.txt +++ b/src/network/CMakeLists.txt @@ -14,7 +14,7 @@ # set(net_sources) list(APPEND net_sources network.c net_pcap.c net_slirp.c net_dp8390.c net_3c501.c - net_3c503.c net_ne2000.c net_pcnet.c net_wd8003.c net_plip.c net_event.c) + net_3c503.c net_ne2000.c net_pcnet.c net_wd8003.c net_plip.c net_event.c net_null.c) option(SLIRP_EXTERNAL "Link against the system-provided libslirp library" OFF) mark_as_advanced(SLIRP_EXTERNAL) diff --git a/src/network/net_null.c b/src/network/net_null.c new file mode 100644 index 000000000..e69b4acb6 --- /dev/null +++ b/src/network/net_null.c @@ -0,0 +1,224 @@ +/* +* 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. +* +* This file is part of the 86Box distribution. +* +* Null network driver +* +* +* +* Authors: cold-brewed +* +* Copyright 2023 The 86Box development team +*/ + +#include +#include +#include +#include +#include +#include +#include +#ifdef _WIN32 +# define WIN32_LEAN_AND_MEAN +# include +# include +#else +# include +#endif + +#define HAVE_STDARG_H +#include <86box/86box.h> +#include <86box/device.h> +#include <86box/thread.h> +#include <86box/timer.h> +#include <86box/network.h> +#include <86box/net_event.h> + +enum { + NET_EVENT_STOP = 0, + NET_EVENT_TX, + NET_EVENT_RX, + NET_EVENT_MAX +}; + +/* Special define for the windows portion. Because we are not interested + * in NET_EVENT_RX for the null driver, we only need to poll up to + * NET_EVENT_TX. NET_EVENT_RX gives us a different NET_EVENT_MAX + * excluding NET_EVENT_RX. */ +#define NET_EVENT_TX_MAX NET_EVENT_RX + +#define NULL_PKT_BATCH NET_QUEUE_LEN + +typedef struct { + uint8_t mac_addr[6]; + netcard_t *card; + thread_t *poll_tid; + net_evt_t tx_event; + net_evt_t stop_event; + netpkt_t pkt; + netpkt_t pktv[NULL_PKT_BATCH]; +} net_null_t; + +#ifdef ENABLE_NET_NULL_LOG +int net_null_do_log = ENABLE_NET_NULL_LOG; + +static void +net_null_log(const char *fmt, ...) +{ + va_list ap; + + if (net_null_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define net_null_log(fmt, ...) +#endif + +#ifdef _WIN32 +static void +net_null_thread(void *priv) +{ + net_null_t *net_null = (net_null_t *) priv; + + net_null_log("Null Network: polling started.\n"); + + HANDLE events[NET_EVENT_TX_MAX]; + events[NET_EVENT_STOP] = net_event_get_handle(&net_null->stop_event); + events[NET_EVENT_TX] = net_event_get_handle(&net_null->tx_event); + + bool run = true; + + while (run) { + int ret = WaitForMultipleObjects(NET_EVENT_TX_MAX, events, FALSE, INFINITE); + + switch (ret - WAIT_OBJECT_0) { + case NET_EVENT_STOP: + net_event_clear(&net_null->stop_event); + run = false; + break; + + case NET_EVENT_TX: + net_event_clear(&net_null->tx_event); + int packets = network_tx_popv(net_null->card, net_null->pktv, NULL_PKT_BATCH); + for (int i = 0; i < packets; i++) { + net_null_log("Null Network: Ignoring TX packet (%d bytes)\n", net_null->pktv[i].len); + } + break; + + default: + net_null_log("Null Network: Unknown event.\n"); + break; + } + } + + net_null_log("Null Network: polling stopped.\n"); +} +#else +static void +net_null_thread(void *priv) +{ + net_null_t *net_null = (net_null_t *) priv; + + net_null_log("Null Network: polling started.\n"); + + struct pollfd pfd[NET_EVENT_MAX]; + pfd[NET_EVENT_STOP].fd = net_event_get_fd(&net_null->stop_event); + pfd[NET_EVENT_STOP].events = POLLIN | POLLPRI; + + pfd[NET_EVENT_TX].fd = net_event_get_fd(&net_null->tx_event); + pfd[NET_EVENT_TX].events = POLLIN | POLLPRI; + + while (1) { + poll(pfd, NET_EVENT_MAX, -1); + + if (pfd[NET_EVENT_STOP].revents & POLLIN) { + net_event_clear(&net_null->stop_event); + break; + } + + if (pfd[NET_EVENT_TX].revents & POLLIN) { + net_event_clear(&net_null->tx_event); + + int packets = network_tx_popv(net_null->card, net_null->pktv, NULL_PKT_BATCH); + for (int i = 0; i < packets; i++) { + net_null_log("Null Network: Ignoring TX packet (%d bytes)\n", net_null->pktv[i].len); + } + } + } + + net_null_log("Null Network: polling stopped.\n"); +} +#endif + +void * +net_null_init(const netcard_t *card, const uint8_t *mac_addr, void *priv) +{ + net_null_log("Null Network: Init\n"); + + net_null_t *net_null = calloc(1, sizeof(net_null_t)); + net_null->card = (netcard_t *) card; + memcpy(net_null->mac_addr, mac_addr, sizeof(net_null->mac_addr)); + + for (int i = 0; i < NULL_PKT_BATCH; i++) { + net_null->pktv[i].data = calloc(1, NET_MAX_FRAME); + } + net_null->pkt.data = calloc(1, NET_MAX_FRAME); + + net_event_init(&net_null->tx_event); + net_event_init(&net_null->stop_event); + net_null->poll_tid = thread_create(net_null_thread, net_null); + + return net_null; +} + + + +void +net_null_in_available(void *priv) +{ + net_null_t *net_null = (net_null_t *) priv; + net_event_set(&net_null->tx_event); +} + +void +net_null_close(void *priv) +{ + if (!priv) + return; + + net_null_t *net_null = (net_null_t *) priv; + + net_null_log("Null Network: closing.\n"); + + /* Tell the thread to terminate. */ + net_event_set(&net_null->stop_event); + + /* Wait for the thread to finish. */ + net_null_log("Null Network: waiting for thread to end...\n"); + thread_wait(net_null->poll_tid); + net_null_log("Null Network: thread ended\n"); + + for (int i = 0; i < NULL_PKT_BATCH; i++) { + free(net_null->pktv[i].data); + } + free(net_null->pkt.data); + + net_event_close(&net_null->tx_event); + net_event_close(&net_null->stop_event); + + free(net_null); +} + +const netdrv_t net_null_drv = { + &net_null_in_available, + &net_null_init, + &net_null_close, + NULL +}; \ No newline at end of file diff --git a/src/network/net_vde.c b/src/network/net_vde.c index 904b2789a..9bed78a9e 100644 --- a/src/network/net_vde.c +++ b/src/network/net_vde.c @@ -280,7 +280,7 @@ void *net_vde_init(const netcard_t *card, const uint8_t *mac_addr, void *priv) { // TODO: Once there is a solution for the mentioned crash, this should be removed // and/or replaced by proper error handling code. //- - fatal("Could not open the specified VDE socket (%s). Please fix your networking configuration.", socket_name); + // fatal("Could not open the specified VDE socket (%s). Please fix your networking configuration.", socket_name); // It makes no sense to issue this warning since the program will crash anyway... // ui_msgbox_header(MBX_WARNING, (wchar_t *) IDS_2167, (wchar_t *) IDS_2168); return NULL; diff --git a/src/network/network.c b/src/network/network.c index ce81fcc93..c05c72cd0 100644 --- a/src/network/network.c +++ b/src/network/network.c @@ -123,7 +123,7 @@ netcard_conf_t net_cards_conf[NET_CARD_MAX]; uint16_t net_card_current = 0; /* Global variables. */ -network_devmap_t network_devmap; +network_devmap_t network_devmap = {0}; int network_ndev; netdev_t network_devs[NET_HOST_INTF_MAX]; @@ -442,13 +442,12 @@ network_attach(void *card_drv, uint8_t *mac, NETRXCB rx, NETSETLINKSTATE set_lin card->card_num = net_card_current; card->byte_period = NET_PERIOD_10M; - for (int i = 0; i < 3; i++) { + for (int i = 0; i < NET_QUEUE_COUNT; i++) { network_queue_init(&card->queues[i]); } switch (net_cards_conf[net_card_current].net_type) { case NET_TYPE_SLIRP: - default: card->host_drv = net_slirp_drv; card->host_drv.priv = card->host_drv.init(card, mac, NULL); break; @@ -463,18 +462,45 @@ network_attach(void *card_drv, uint8_t *mac, NETRXCB rx, NETSETLINKSTATE set_lin card->host_drv.priv = card->host_drv.init(card, mac, net_cards_conf[net_card_current].host_dev_name); break; #endif + default: + card->host_drv.priv = NULL; + break; } + // Use null driver on: + // * No specific driver selected (card->host_drv.priv is set to null above) + // * Failure to init a specific driver (in which case card->host_drv.priv is null) if (!card->host_drv.priv) { - thread_close_mutex(card->tx_mutex); - thread_close_mutex(card->rx_mutex); - for (int i = 0; i < 3; i++) { - network_queue_clear(&card->queues[i]); + + if(net_cards_conf[net_card_current].net_type != NET_TYPE_NONE) { + // We're here because of a failure + // Placeholder to display a msgbox about falling back to null + ui_msgbox(MBX_ERROR | MBX_ANSI, "Network driver initialization failed. Falling back to NULL driver."); + } + + // Init null driver + card->host_drv = net_null_drv; + card->host_drv.priv = card->host_drv.init(card, mac, NULL); + // Set link state to disconnected by default + network_connect(card->card_num, 0); + ui_sb_update_icon_state(SB_NETWORK | card->card_num, 1); + + // If null fails, something is very wrong + // Clean up and fatal + if(!card->host_drv.priv) { + thread_close_mutex(card->tx_mutex); + thread_close_mutex(card->rx_mutex); + for (int i = 0; i < NET_QUEUE_COUNT; i++) { + network_queue_clear(&card->queues[i]); + } + + free(card->queued_pkt.data); + free(card); + // Placeholder - insert the error message + fatal("Error initializing the network device: Null driver initialization failed"); + return NULL; } - free(card->queued_pkt.data); - free(card); - return NULL; } timer_add(&card->timer, network_rx_queue, card, 0); @@ -491,7 +517,7 @@ netcard_close(netcard_t *card) thread_close_mutex(card->tx_mutex); thread_close_mutex(card->rx_mutex); - for (int i = 0; i < 3; i++) { + for (int i = 0; i < NET_QUEUE_COUNT; i++) { network_queue_clear(&card->queues[i]); } @@ -641,7 +667,7 @@ network_dev_to_id(char *devname) int network_dev_available(int id) { - int available = (net_cards_conf[id].device_num > 0) && (net_cards_conf[id].net_type != NET_TYPE_NONE); + int available = (net_cards_conf[id].device_num > 0); if ((net_cards_conf[id].net_type == NET_TYPE_PCAP && (network_dev_to_id(net_cards_conf[id].host_dev_name) <= 0))) available = 0; diff --git a/src/qt/qt_mediamenu.cpp b/src/qt/qt_mediamenu.cpp index 841cd3053..26169b0d0 100644 --- a/src/qt/qt_mediamenu.cpp +++ b/src/qt/qt_mediamenu.cpp @@ -849,7 +849,7 @@ MediaMenu::nicUpdateMenu(int i) if (!netMenus.contains(i)) return; - QString netType = tr("None"); + QString netType = tr("Null Driver"); switch (net_cards_conf[i].net_type) { case NET_TYPE_SLIRP: netType = "SLiRP"; diff --git a/src/qt/qt_settingsnetwork.cpp b/src/qt/qt_settingsnetwork.cpp index ceb4810bc..acc7ebfc4 100644 --- a/src/qt/qt_settingsnetwork.cpp +++ b/src/qt/qt_settingsnetwork.cpp @@ -40,9 +40,10 @@ SettingsNetwork::enableElements(Ui::SettingsNetwork *ui) auto *socket_line = findChild(QString("socketVDENIC%1").arg(i + 1)); int netType = net_type_cbox->currentData().toInt(); - bool adaptersEnabled = netType == NET_TYPE_SLIRP - || NET_TYPE_VDE - || (netType == NET_TYPE_PCAP && intf_cbox->currentData().toInt() > 0); + bool adaptersEnabled = netType == NET_TYPE_NONE + || netType == NET_TYPE_SLIRP + || netType == NET_TYPE_VDE + || (netType == NET_TYPE_PCAP && intf_cbox->currentData().toInt() > 0); intf_cbox->setEnabled(net_type_cbox->currentData().toInt() == NET_TYPE_PCAP); nic_cbox->setEnabled(adaptersEnabled); @@ -133,7 +134,7 @@ SettingsNetwork::onCurrentMachineChanged(int machineId) cbox = findChild(QString("comboBoxNet%1").arg(i + 1)); model = cbox->model(); removeRows = model->rowCount(); - Models::AddEntry(model, tr("None"), NET_TYPE_NONE); + Models::AddEntry(model, tr("Null Driver"), NET_TYPE_NONE); Models::AddEntry(model, "SLiRP", NET_TYPE_SLIRP); if (network_ndev > 1) { diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index 0aa08d267..4b60cb930 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -669,7 +669,8 @@ NETOBJ := network.o \ net_dp8390.o net_3c501.o \ net_3c503.o net_ne2000.o \ net_pcnet.o net_wd8003.o \ - net_plip.o net_event.o + net_plip.o net_event.o \ + net_null.o PRINTOBJ := png.o prt_cpmap.o \ prt_escp.o prt_text.o prt_ps.o diff --git a/src/win/languages/dialogs.rc b/src/win/languages/dialogs.rc index 3286ee2be..eb542a971 100644 --- a/src/win/languages/dialogs.rc +++ b/src/win/languages/dialogs.rc @@ -3,6 +3,8 @@ #define CFG_BTN_WIDTH 46 #define CFG_BTN_HEIGHT 14 #define CFG_PANE_LTEXT_PRI_WIDTH 85 +#define CFG_PANE_LTEXT_PRI_WIDTH_2 170 +#define CFG_PANE_LTEXT_PRI_WIDTH_3 255 #define CFG_PANE_LTEXT_HEIGHT 10 #define CFG_COMBO_BTN_WIDTH 212 #define CFG_COMBO_NOBTN_WIDTH CFG_COMBO_BTN_WIDTH + CFG_BTN_WIDTH + 8 @@ -405,10 +407,10 @@ BEGIN LTEXT STR_PCAP, IDT_PCAP, CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH - 10, CFG_VMARGIN, CFG_PANE_LTEXT_PRI_WIDTH, CFG_PANE_LTEXT_HEIGHT LTEXT STR_NET, IDT_NET, - CFG_HMARGIN + (CFG_PANE_LTEXT_PRI_WIDTH * 2) + 20, CFG_VMARGIN, CFG_PANE_LTEXT_PRI_WIDTH, CFG_PANE_LTEXT_HEIGHT + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_2 + 20, CFG_VMARGIN, CFG_PANE_LTEXT_PRI_WIDTH, CFG_PANE_LTEXT_HEIGHT COMBOBOX IDC_COMBO_NET1_TYPE, - CFG_HMARGIN, 28, 32, CFG_COMBO_HEIGHT, + CFG_HMARGIN, 28, 48, CFG_COMBO_HEIGHT, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_COMBO_PCAP1, @@ -416,13 +418,13 @@ BEGIN CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_COMBO_NET1, - CFG_HMARGIN + (CFG_PANE_LTEXT_PRI_WIDTH * 2) + 20, 28, 110, CFG_COMBO_HEIGHT, + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_2 + 20, 28, 110, CFG_COMBO_HEIGHT, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP PUSHBUTTON STR_CONFIGURE, IDC_CONFIGURE_NET1, - CFG_HMARGIN + (CFG_PANE_LTEXT_PRI_WIDTH * 3) + 50, 27, CFG_BTN_WIDTH, CFG_BTN_HEIGHT + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_3 + 50, 27, CFG_BTN_WIDTH, CFG_BTN_HEIGHT COMBOBOX IDC_COMBO_NET2_TYPE, - CFG_HMARGIN, 49, 32, CFG_COMBO_HEIGHT, + CFG_HMARGIN, 49, 48, CFG_COMBO_HEIGHT, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_COMBO_PCAP2, @@ -430,13 +432,13 @@ BEGIN CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_COMBO_NET2, - CFG_HMARGIN + (CFG_PANE_LTEXT_PRI_WIDTH * 2) + 20, 49, 110, CFG_COMBO_HEIGHT, + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_2 + 20, 49, 110, CFG_COMBO_HEIGHT, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP PUSHBUTTON STR_CONFIGURE, IDC_CONFIGURE_NET2, - CFG_HMARGIN + (CFG_PANE_LTEXT_PRI_WIDTH * 3) + 50, 48, CFG_BTN_WIDTH, CFG_BTN_HEIGHT + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_3 + 50, 48, CFG_BTN_WIDTH, CFG_BTN_HEIGHT COMBOBOX IDC_COMBO_NET3_TYPE, - CFG_HMARGIN, 70, 32, CFG_COMBO_HEIGHT, + CFG_HMARGIN, 70, 48, CFG_COMBO_HEIGHT, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_COMBO_PCAP3, @@ -444,13 +446,13 @@ BEGIN CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_COMBO_NET3, - CFG_HMARGIN + (CFG_PANE_LTEXT_PRI_WIDTH * 2) + 20, 70, 110, CFG_COMBO_HEIGHT, + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_2 + 20, 70, 110, CFG_COMBO_HEIGHT, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP PUSHBUTTON STR_CONFIGURE, IDC_CONFIGURE_NET3, - CFG_HMARGIN + (CFG_PANE_LTEXT_PRI_WIDTH * 3) + 50, 69, CFG_BTN_WIDTH, CFG_BTN_HEIGHT + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_3 + 50, 69, CFG_BTN_WIDTH, CFG_BTN_HEIGHT COMBOBOX IDC_COMBO_NET4_TYPE, - CFG_HMARGIN, 91, 32, CFG_COMBO_HEIGHT, + CFG_HMARGIN, 91, 48, CFG_COMBO_HEIGHT, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_COMBO_PCAP4, @@ -458,10 +460,10 @@ BEGIN CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_COMBO_NET4, - CFG_HMARGIN + (CFG_PANE_LTEXT_PRI_WIDTH * 2) + 20, 91, 110, CFG_COMBO_HEIGHT, + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_2 + 20, 91, 110, CFG_COMBO_HEIGHT, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP PUSHBUTTON STR_CONFIGURE, IDC_CONFIGURE_NET4, - CFG_HMARGIN + (CFG_PANE_LTEXT_PRI_WIDTH * 3) + 50, 90, CFG_BTN_WIDTH, CFG_BTN_HEIGHT + CFG_HMARGIN + CFG_PANE_LTEXT_PRI_WIDTH_3 + 50, 90, CFG_BTN_WIDTH, CFG_BTN_HEIGHT END diff --git a/src/win/win_settings.c b/src/win/win_settings.c index 333888a65..2936f6639 100644 --- a/src/win/win_settings.c +++ b/src/win/win_settings.c @@ -2062,7 +2062,7 @@ win_settings_network_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) lptsTemp = (LPTSTR) malloc(512 * sizeof(WCHAR)); for (uint8_t i = 0; i < NET_CARD_MAX; i++) { - settings_add_string(hdlg, IDC_COMBO_NET1_TYPE + i, (LPARAM) L"None"); + settings_add_string(hdlg, IDC_COMBO_NET1_TYPE + i, (LPARAM) L"Null Driver"); settings_add_string(hdlg, IDC_COMBO_NET1_TYPE + i, (LPARAM) L"SLiRP"); settings_add_string(hdlg, IDC_COMBO_NET1_TYPE + i, (LPARAM) L"PCap"); settings_set_cur_sel(hdlg, IDC_COMBO_NET1_TYPE + i, temp_net_type[i]); From d31425536229ada96fb8e234d6f5c32833214f64 Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 16 May 2023 01:09:48 +0200 Subject: [PATCH 32/34] MM67: Convert year from BCD if it is stored in BCD mode. --- src/device/isartc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/device/isartc.c b/src/device/isartc.c index 67b5b94c2..e8f097c08 100644 --- a/src/device/isartc.c +++ b/src/device/isartc.c @@ -236,7 +236,10 @@ mm67_tick(nvr_t *nvr) regs[MM67_DOM] = RTC_BCDINC(regs[MM67_DOM], 1); mon = RTC_DCB(regs[MM67_MON]); if (dev->year != -1) { - year = RTC_DCB(regs[dev->year]); + if (dev->flags & FLAG_YEARBCD) + year = RTC_DCB(regs[dev->year]); + else + year = regs[dev->year]; if (dev->flags & FLAG_YEAR80) year += 80; } else From 6c1e4a8e2c003edcb28d2673cf4af8cc0e5cdd30 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Thu, 11 May 2023 03:02:36 -0400 Subject: [PATCH 33/34] Some code smell fixes from sonarlint --- src/86box.c | 49 +- src/acpi.c | 38 +- src/chipset/82c100.c | 8 +- src/chipset/ali1429.c | 6 +- src/chipset/ali1435.c | 632 ++-- src/chipset/ali1489.c | 3 +- src/chipset/ali1531.c | 9 +- src/chipset/ali1541.c | 12 +- src/chipset/ali1543.c | 21 +- src/chipset/ali1621.c | 18 +- src/chipset/ali6117.c | 18 +- src/chipset/contaq_82c59x.c | 3 +- src/chipset/gc100.c | 4 +- src/chipset/headland.c | 18 +- src/chipset/ims8848.c | 3 +- src/chipset/intel_420ex.c | 5 +- src/chipset/intel_4x0.c | 10 +- src/chipset/intel_82335.c | 9 +- src/chipset/intel_i450kx.c | 7 +- src/chipset/intel_piix.c | 24 +- src/chipset/neat.c | 23 +- src/chipset/opti283.c | 10 +- src/chipset/opti391.c | 9 +- src/chipset/opti495.c | 3 +- src/chipset/opti499.c | 3 +- src/chipset/opti822.c | 22 +- src/chipset/opti895.c | 3 +- src/chipset/scamp.c | 45 +- src/chipset/scat.c | 54 +- src/chipset/sis_5511.c | 4 +- src/chipset/sis_85c496.c | 14 +- src/chipset/sis_85c4xx.c | 16 +- src/chipset/sis_85c50x.c | 6 +- src/chipset/stpc.c | 20 +- src/chipset/umc_hb4.c | 4 +- src/chipset/via_apollo.c | 2 +- src/chipset/via_pipc.c | 20 +- src/chipset/via_vt82c49x.c | 13 +- src/chipset/via_vt82c505.c | 3 +- src/chipset/vl82c480.c | 5 +- src/config.c | 116 +- src/ddma.c | 7 +- src/device.c | 94 +- src/device/bugger.c | 18 +- src/device/cartridge.c | 4 +- src/device/cassette.c | 40 +- src/device/clock_ics9xxx.c | 3 +- src/device/hwm_lm78.c | 4 +- src/device/i2c.c | 30 +- src/device/isamem.c | 35 +- src/device/isapnp.c | 40 +- src/device/isartc.c | 14 +- src/device/kbc_at.c | 24 +- src/device/kbc_at_dev.c | 2 +- src/device/keyboard_at.c | 13 +- src/device/keyboard_xt.c | 26 +- src/device/mouse.c | 26 +- src/device/mouse_bus.c | 9 +- src/device/mouse_ps2.c | 11 +- src/device/mouse_serial.c | 15 +- src/device/mouse_wacom_tablet.c | 5 +- src/device/pci_bridge.c | 6 +- src/device/postcard.c | 3 +- src/device/serial.c | 7 +- src/device/serial_passthrough.c | 6 +- src/device/smbus_ali7101.c | 5 +- src/device/smbus_piix4.c | 9 +- src/discord.c | 6 +- src/dma.c | 56 +- src/fifo8.c | 3 +- src/game/gameport.c | 3 +- src/game/joystick_sw_pad.c | 9 +- src/gdbstub.c | 38 +- src/include/86box/86box.h | 67 +- src/include/86box/cassette.h | 6 +- src/include/86box/fdd.h | 3 +- src/include/86box/hdc_ide.h | 3 +- src/include/86box/i8080.h | 23 +- src/include/86box/keyboard.h | 6 +- src/include/86box/machine.h | 4 +- src/include/86box/mem.h | 32 +- src/include/86box/midi.h | 3 +- src/include/86box/mouse.h | 7 +- src/include/86box/pci.h | 6 +- src/include/86box/pic.h | 3 +- src/include/86box/pit.h | 19 +- src/include/86box/snd_ac97.h | 27 +- src/include/86box/snd_mpu401.h | 3 +- src/include/86box/snd_speaker.h | 3 +- src/include/86box/sound.h | 6 +- src/include/86box/vid_svga.h | 3 +- src/include/86box/vid_voodoo_codegen_x86-64.h | 3 +- src/include/86box/vid_voodoo_codegen_x86.h | 5 +- src/include/86box/vid_voodoo_common.h | 375 ++- src/include/86box/vid_xga.h | 7 +- src/include/86box/video.h | 16 +- src/ini.c | 65 +- src/io.c | 47 +- src/ioapic.c | 4 +- src/log.c | 6 +- src/lpt.c | 10 +- src/machine/m_amstrad.c | 100 +- src/machine/m_at_compaq.c | 45 +- src/machine/m_at_t3100e.c | 3 +- src/machine/m_at_t3100e_vid.c | 40 +- src/machine/m_elt.c | 5 +- src/machine/m_europc.c | 12 +- src/machine/m_pcjr.c | 58 +- src/machine/m_ps1.c | 2 +- src/machine/m_ps1_hdc.c | 30 +- src/machine/m_ps2_mca.c | 20 +- src/machine/m_tandy.c | 72 +- src/machine/m_v86p.c | 3 +- src/machine/m_xt.c | 3 +- src/machine/m_xt_laserxt.c | 10 +- src/machine/m_xt_olivetti.c | 48 +- src/machine/m_xt_t1000.c | 34 +- src/machine/m_xt_t1000_vid.c | 7 +- src/machine/machine_table.c | 4 +- src/mca.c | 12 +- src/mem/mem.c | 145 +- src/nvr.c | 26 +- src/nvr_at.c | 2688 ++++++++--------- src/nvr_ps2.c | 4 +- src/pci.c | 64 +- src/pci_dummy.c | 4 +- src/pic.c | 40 +- src/pit.c | 65 +- src/pit_fast.c | 4 +- src/port_6x.c | 10 +- src/random.c | 3 +- src/timer.c | 3 +- src/upi42.c | 9 +- src/usb.c | 26 +- src/vnc.c | 16 +- src/win/win_joystick_rawinput.c | 10 +- src/win/win_serial_passthrough.c | 4 +- 137 files changed, 3354 insertions(+), 2900 deletions(-) diff --git a/src/86box.c b/src/86box.c index 73f8a67ee..f46d3c64a 100644 --- a/src/86box.c +++ b/src/86box.c @@ -404,19 +404,25 @@ pc_log(const char *fmt, ...) int pc_init(int argc, char *argv[]) { - char *ppath = NULL, *rpath = NULL; - char *cfg = NULL, *p; - char temp[2048], *fn[FDD_NUM] = { NULL }; - char drive = 0, *temp2 = NULL; + char *ppath = NULL; + char *rpath = NULL; + char *cfg = NULL; + char *p; + char temp[2048]; + char *fn[FDD_NUM] = { NULL }; + char drive = 0; + char *temp2 = NULL; struct tm *info; time_t now; - int c, lvmp = 0; + int c; + int lvmp = 0; int i; #ifdef ENABLE_NG int ng = 0; #endif #ifdef _WIN32 - uint32_t *uid, *shwnd; + uint32_t *uid; + uint32_t *shwnd; #endif uint32_t lang_init = 0; @@ -493,7 +499,7 @@ usage: printf("-V or --vmname name - overrides the name of the running VM\n"); printf("-Z or --lastvmpath - the last parameter is VM path rather than config\n"); printf("\nA config file can be specified. If none is, the default file will be used.\n"); - return (0); + return 0; } else if (!strcasecmp(argv[c], "--lastvmpath") || !strcasecmp(argv[c], "-Z")) { lvmp = 1; } else if (!strcasecmp(argv[c], "--dumpcfg") || !strcasecmp(argv[c], "-O")) { @@ -585,7 +591,7 @@ usage: /* some (undocumented) test function here.. */ /* .. and then exit. */ - return (0); + return 0; #ifdef USE_INSTRUMENT } else if (!strcasecmp(argv[c], "--instrument")) { if ((c + 1) == argc) @@ -786,7 +792,7 @@ usage: gdbstub_init(); /* All good! */ - return (1); + return 1; } void @@ -812,7 +818,8 @@ pc_full_speed(void) int pc_init_modules(void) { - int c, m; + int c; + int m; wchar_t temp[512]; char tempc[512]; @@ -846,7 +853,7 @@ pc_init_modules(void) } if (c == 0) { /* No usable ROMs found, aborting. */ - return (0); + return 0; } pc_log("A total of %d ROM sets have been loaded.\n", c); @@ -867,7 +874,7 @@ pc_init_modules(void) if (machine == -1) { fatal("No available machines\n"); exit(-1); - return (0); + return 0; } } @@ -890,7 +897,7 @@ pc_init_modules(void) if (gfxcard[0] == -1) { fatal("No available video cards\n"); exit(-1); - return (0); + return 0; } } @@ -933,7 +940,7 @@ pc_init_modules(void) machine_status_init(); - return (1); + return 1; } void @@ -1136,7 +1143,10 @@ pc_reset_hard_init(void) void update_mouse_msg(void) { - wchar_t wcpufamily[2048], wcpu[2048], wmachine[2048], *wcp; + wchar_t wcpufamily[2048]; + wchar_t wcpu[2048]; + wchar_t wmachine[2048]; + wchar_t *wcp; mbstowcs(wmachine, machine_getname(), strlen(machine_getname()) + 1); @@ -1176,8 +1186,6 @@ pc_reset_hard(void) void pc_close(thread_t *ptr) { - int i; - /* Wait a while so things can shut down. */ plat_delay_ms(200); @@ -1205,7 +1213,7 @@ pc_close(thread_t *ptr) lpt_devices_close(); - for (i = 0; i < FDD_NUM; i++) + for (uint8_t i = 0; i < FDD_NUM; i++) fdd_close(i); #ifdef ENABLE_808X_LOG @@ -1305,7 +1313,10 @@ set_screen_size_monitor(int x, int y, int monitor_index) { int temp_overscan_x = monitors[monitor_index].mon_overscan_x; int temp_overscan_y = monitors[monitor_index].mon_overscan_y; - double dx, dy, dtx, dty; + double dx; + double dy; + double dtx; + double dty; /* Make sure we keep usable values. */ #if 0 diff --git a/src/acpi.c b/src/acpi.c index 625fdfef2..539da644b 100644 --- a/src/acpi.c +++ b/src/acpi.c @@ -148,7 +148,7 @@ acpi_raise_smi(void *priv, int do_smi) if (dev->regs.glbctl & 0x01) { if ((dev->vendor == VEN_VIA) || (dev->vendor == VEN_VIA_596B)) { - if ((!dev->regs.smi_lock || !dev->regs.smi_active)) { + if (!dev->regs.smi_lock || !dev->regs.smi_active) { if (do_smi) smi_raise(); dev->regs.smi_active = 1; @@ -173,7 +173,8 @@ acpi_reg_read_common_regs(int size, uint16_t addr, void *p) { acpi_t *dev = (acpi_t *) p; uint32_t ret = 0x00000000; - int shift16, shift32; + int shift16; + int shift32; addr &= 0x3f; shift16 = (addr & 1) << 3; @@ -224,7 +225,8 @@ acpi_reg_read_ali(int size, uint16_t addr, void *p) { acpi_t *dev = (acpi_t *) p; uint32_t ret = 0x00000000; - int shift16, shift32; + int shift16; + int shift32; addr &= 0x3f; shift16 = (addr & 1) << 3; @@ -291,7 +293,8 @@ acpi_reg_read_intel(int size, uint16_t addr, void *p) { acpi_t *dev = (acpi_t *) p; uint32_t ret = 0x00000000; - int shift16, shift32; + int shift16; + int shift32; addr &= 0x3f; shift16 = (addr & 1) << 3; @@ -387,7 +390,8 @@ acpi_reg_read_via_common(int size, uint16_t addr, void *p) { acpi_t *dev = (acpi_t *) p; uint32_t ret = 0x00000000; - int shift16, shift32; + int shift16; + int shift32; addr &= 0xff; shift16 = (addr & 1) << 3; @@ -539,7 +543,8 @@ acpi_reg_read_via_596b(int size, uint16_t addr, void *p) { acpi_t *dev = (acpi_t *) p; uint32_t ret = 0x00000000; - int shift16, shift32; + int shift16; + int shift32; addr &= 0x7f; shift16 = (addr & 1) << 3; @@ -643,7 +648,8 @@ static void acpi_reg_write_common_regs(int size, uint16_t addr, uint8_t val, void *p) { acpi_t *dev = (acpi_t *) p; - int shift16, sus_typ; + int shift16; + int sus_typ; addr &= 0x3f; #ifdef ENABLE_ACPI_LOG @@ -720,7 +726,8 @@ static void acpi_reg_write_ali(int size, uint16_t addr, uint8_t val, void *p) { acpi_t *dev = (acpi_t *) p; - int shift16, shift32; + int shift16; + int shift32; addr &= 0x3f; #ifdef ENABLE_ACPI_LOG @@ -791,7 +798,8 @@ static void acpi_reg_write_intel(int size, uint16_t addr, uint8_t val, void *p) { acpi_t *dev = (acpi_t *) p; - int shift16, shift32; + int shift16; + int shift32; addr &= 0x3f; #ifdef ENABLE_ACPI_LOG @@ -887,7 +895,8 @@ static void acpi_reg_write_via_common(int size, uint16_t addr, uint8_t val, void *p) { acpi_t *dev = (acpi_t *) p; - int shift16, shift32; + int shift16; + int shift32; addr &= 0xff; acpi_log("(%i) ACPI Write (%i) %02X: %02X\n", in_smm, size, addr, val); @@ -980,7 +989,8 @@ static void acpi_reg_write_via(int size, uint16_t addr, uint8_t val, void *p) { acpi_t *dev = (acpi_t *) p; - int shift16, shift32; + int shift16; + int shift32; addr &= 0xff; acpi_log("(%i) ACPI Write (%i) %02X: %02X\n", in_smm, size, addr, val); @@ -1043,7 +1053,8 @@ static void acpi_reg_write_via_596b(int size, uint16_t addr, uint8_t val, void *p) { acpi_t *dev = (acpi_t *) p; - int shift16, shift32; + int shift16; + int shift32; addr &= 0x7f; acpi_log("(%i) ACPI Write (%i) %02X: %02X\n", in_smm, size, addr, val); @@ -1592,7 +1603,6 @@ static void acpi_reset(void *priv) { acpi_t *dev = (acpi_t *) priv; - int i; memset(&dev->regs, 0x00, sizeof(acpi_regs_t)); dev->regs.gpireg[0] = 0xff; @@ -1603,7 +1613,7 @@ acpi_reset(void *priv) Gigabyte GA-686BX: - Bit 1: CMOS battery low (active high) */ dev->regs.gpireg[2] = dev->gpireg2_default; - for (i = 0; i < 4; i++) + for (uint8_t i = 0; i < 4; i++) dev->regs.gporeg[i] = dev->gporeg_default[i]; if (dev->vendor == VEN_VIA_596B) { dev->regs.gpo_val = 0x7fffffff; diff --git a/src/chipset/82c100.c b/src/chipset/82c100.c index 516768742..4d75ca387 100644 --- a/src/chipset/82c100.c +++ b/src/chipset/82c100.c @@ -70,10 +70,9 @@ ct_82c100_log(const char *fmt, ...) static void ct_82c100_ems_pages_recalc(ct_82c100_t *dev) { - int i; uint32_t page_base; - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { page_base = dev->ems_window_base + (i << 14); if ((i == 1) || (i == 2)) page_base ^= 0xc000; @@ -353,7 +352,6 @@ static void * ct_82c100_init(const device_t *info) { ct_82c100_t *dev; - uint32_t i; dev = (ct_82c100_t *) malloc(sizeof(ct_82c100_t)); memset(dev, 0x00, sizeof(ct_82c100_t)); @@ -367,7 +365,7 @@ ct_82c100_init(const device_t *info) io_sethandler(0x007e, 2, ct_82c100_in, NULL, NULL, ct_82c100_out, NULL, NULL, dev); - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { mem_mapping_add(&(dev->ems_mappings[i]), (i + 28) << 14, 0x04000, mem_read_emsb, mem_read_emsw, NULL, mem_write_emsb, mem_write_emsw, NULL, @@ -379,7 +377,7 @@ ct_82c100_init(const device_t *info) device_add(&port_92_device); - return (dev); + return dev; } const device_t ct_82c100_device = { diff --git a/src/chipset/ali1429.c b/src/chipset/ali1429.c index 02034e481..138c7db93 100644 --- a/src/chipset/ali1429.c +++ b/src/chipset/ali1429.c @@ -124,7 +124,9 @@ typedef struct static void ali1429_shadow_recalc(ali1429_t *dev) { - uint32_t base, i, can_write, can_read; + uint32_t base; + uint32_t can_write; + uint32_t can_read; shadowbios = (dev->regs[0x13] & 0x40) && (dev->regs[0x14] & 0x01); shadowbios_write = (dev->regs[0x13] & 0x40) && (dev->regs[0x14] & 0x02); @@ -132,7 +134,7 @@ ali1429_shadow_recalc(ali1429_t *dev) can_write = (dev->regs[0x14] & 0x02) ? MEM_WRITE_INTERNAL : MEM_WRITE_EXTANY; can_read = (dev->regs[0x14] & 0x01) ? MEM_READ_INTERNAL : MEM_READ_EXTANY; - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { base = 0xc0000 + (i << 15); if (dev->regs[0x13] & (1 << i)) diff --git a/src/chipset/ali1435.c b/src/chipset/ali1435.c index 2909a48b9..c80611e1b 100644 --- a/src/chipset/ali1435.c +++ b/src/chipset/ali1435.c @@ -1,315 +1,317 @@ -/* - * 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. - * - * Emulation of ALi M1435 chipset that acts as both the - * southbridge. - * - * - * - * Authors: Miran Grca, - * - * Copyright 2020 Miran Grca. - */ -#include -#include -#include -#include -#include -#include -#define HAVE_STDARG_H -#include <86box/86box.h> -#include <86box/device.h> -#include <86box/io.h> -#include <86box/apm.h> -#include <86box/dma.h> -#include <86box/mem.h> -#include <86box/smram.h> -#include <86box/pci.h> -#include <86box/timer.h> -#include <86box/pic.h> -#include <86box/pit.h> -#include <86box/port_92.h> -#include <86box/hdc_ide.h> -#include <86box/hdc.h> -#include <86box/machine.h> -#include <86box/chipset.h> -#include <86box/spd.h> - -#define MEM_STATE_SHADOW_R 0x01 -#define MEM_STATE_SHADOW_W 0x02 -#define MEM_STATE_SMRAM 0x04 - -typedef struct -{ - uint8_t index, cfg_locked, - regs[16], pci_regs[256]; -} ali1435_t; - -#define ENABLE_ALI1435_LOG 1 -#ifdef ENABLE_ALI1435_LOG -int ali1435_do_log = ENABLE_ALI1435_LOG; - -static void -ali1435_log(const char *fmt, ...) -{ - va_list ap; - - if (ali1435_do_log) { - va_start(ap, fmt); - pclog_ex(fmt, ap); - va_end(ap); - } -} -#else -# define ali1435_log(fmt, ...) -#endif - -/* NOTE: We cheat here. The real ALi M1435 uses a level to edge triggered IRQ converter - when the most siginificant bit is set. We work around that by manipulating the - emulated PIC's ELCR register. */ -static void -ali1435_update_irqs(ali1435_t *dev, int set) -{ - uint8_t val; - int i, reg; - int shift, irq; - int irq_map[8] = { -1, 5, 9, 10, 11, 12, 14, 15 }; - pic_t *temp_pic; - - for (i = 0; i < 4; i++) { - reg = 0x80 + (i >> 1); - shift = (i & 1) << 2; - val = (dev->pci_regs[reg] >> shift) & 0x0f; - irq = irq_map[val & 0x07]; - if (irq == -1) - continue; - temp_pic = (irq >= 8) ? &pic2 : &pic; - irq &= 7; - if (set && (val & 0x08)) - temp_pic->elcr |= (1 << irq); - else - temp_pic->elcr &= ~(1 << irq); - } -} - -static void -ali1435_pci_write(int func, int addr, uint8_t val, void *priv) -{ - ali1435_t *dev = (ali1435_t *) priv; - int irq, irq_map[8] = { -1, 5, 9, 10, 11, 12, 14, 15 }; - - ali1435_log("ali1435_write(%02X, %02X, %02X)\n", func, addr, val); - - if (func > 0) - return; - - if ((addr < 0x04) || (addr == 0x06) || ((addr >= 0x08) && (addr <= 0x0b))) - return; - - if ((addr >= 0x0f) && (addr < 0x30)) - return; - - if ((addr >= 0x34) && (addr < 0x40)) - return; - - switch (addr) { - /* Dummy PCI Config */ - case 0x04: - dev->pci_regs[addr] = (val & 0x7f) | 0x07; - break; - - case 0x05: - dev->pci_regs[addr] = (val & 0x01); - break; - - /* Dummy PCI Status */ - case 0x07: - dev->pci_regs[addr] &= ~(val & 0xb8); - break; - - case 0x80: - case 0x81: - dev->pci_regs[addr] = val; - ali1435_update_irqs(dev, 0); - irq = irq_map[val & 0x07]; - if (irq >= 0) { - ali1435_log("Set IRQ routing: INT %c -> %02X\n", 0x41 + ((addr & 0x01) << 1), irq); - pci_set_irq_routing(PCI_INTA + ((addr & 0x01) << 1), irq); - } else { - ali1435_log("Set IRQ routing: INT %c -> FF\n", 0x41 + ((addr & 0x01) << 1)); - pci_set_irq_routing(PCI_INTA + ((addr & 0x01) << 1), PCI_IRQ_DISABLED); - } - irq = irq_map[(val >> 4) & 0x07]; - if (irq >= 0) { - ali1435_log("Set IRQ routing: INT %c -> %02X\n", 0x42 + ((addr & 0x01) << 1), irq); - pci_set_irq_routing(PCI_INTB + ((addr & 0x01) << 1), irq); - } else { - ali1435_log("Set IRQ routing: INT %c -> FF\n", 0x42 + ((addr & 0x01) << 1)); - pci_set_irq_routing(PCI_INTB + ((addr & 0x01) << 1), PCI_IRQ_DISABLED); - } - ali1435_update_irqs(dev, 1); - break; - - default: - dev->pci_regs[addr] = val; - break; - } -} - -static uint8_t -ali1435_pci_read(int func, int addr, void *priv) -{ - ali1435_t *dev = (ali1435_t *) priv; - uint8_t ret; - - ret = 0xff; - - if (func == 0) - ret = dev->pci_regs[addr]; - - ali1435_log("ali1435_read(%02X, %02X) = %02X\n", func, addr, ret); - - return ret; -} - -static void -ali1435_write(uint16_t addr, uint8_t val, void *priv) -{ - ali1435_t *dev = (ali1435_t *) priv; - - switch (addr) { - case 0x22: - dev->index = val; - break; - - case 0x23: - /* #ifdef ENABLE_ALI1435_LOG - if (dev->index != 0x03) - ali1435_log("M1435: dev->regs[%02x] = %02x\n", dev->index, val); - #endif */ - - if (dev->index == 0x03) - dev->cfg_locked = (val != 0x69); - - if (!dev->cfg_locked) { - pclog("M1435: dev->regs[%02x] = %02x\n", dev->index, val); - - switch (dev->index) { - /* PCI Mechanism select? */ - case 0x00: - dev->regs[dev->index] = val; - pclog("PMC = %i\n", val != 0xc8); - pci_set_pmc(val != 0xc8); - break; - - /* ???? */ - case 0x06: - dev->regs[dev->index] = val; - break; - - /* ???? */ - case 0x07: - dev->regs[dev->index] = val; - break; - } - } - break; - } -} - -static uint8_t -ali1435_read(uint16_t addr, void *priv) -{ - ali1435_t *dev = (ali1435_t *) priv; - uint8_t ret = 0xff; - - if ((addr == 0x23) && (dev->index < 0x10)) - ret = dev->regs[dev->index]; - else if (addr == 0x22) - ret = dev->index; - - return ret; -} - -static void -ali1435_reset(void *priv) -{ - ali1435_t *dev = (ali1435_t *) priv; - - memset(dev->regs, 0, 16); - - dev->regs[0x00] = 0xff; - - pci_set_pmc(0); - - dev->cfg_locked = 1; - - memset(dev->pci_regs, 0, 256); - - dev->pci_regs[0x00] = 0x25; - dev->pci_regs[0x01] = 0x10; /*ALi*/ - dev->pci_regs[0x02] = 0x35; - dev->pci_regs[0x03] = 0x14; /*M1435*/ - dev->pci_regs[0x04] = 0x07; - dev->pci_regs[0x07] = 0x04; - dev->pci_regs[0x0b] = 0x06; - - dev->pci_regs[0x80] = 0x80; - dev->pci_regs[0x81] = 0x00; - - pci_set_irq_routing(PCI_INTA, PCI_IRQ_DISABLED); - pci_set_irq_routing(PCI_INTB, PCI_IRQ_DISABLED); - pci_set_irq_routing(PCI_INTC, PCI_IRQ_DISABLED); - pci_set_irq_routing(PCI_INTD, PCI_IRQ_DISABLED); -} - -static void -ali1435_close(void *p) -{ - ali1435_t *dev = (ali1435_t *) p; - - free(dev); -} - -static void * -ali1435_init(const device_t *info) -{ - ali1435_t *dev = (ali1435_t *) malloc(sizeof(ali1435_t)); - memset(dev, 0, sizeof(ali1435_t)); - - dev->cfg_locked = 1; - - /* M1435 Ports: - 22h Index Port - 23h Data Port - */ - io_sethandler(0x0022, 0x0002, ali1435_read, NULL, NULL, ali1435_write, NULL, NULL, dev); - - pci_add_card(PCI_ADD_NORTHBRIDGE, ali1435_pci_read, ali1435_pci_write, dev); - - ali1435_reset(dev); - - /* pci_set_irq_level(PCI_INTA, 0); - pci_set_irq_level(PCI_INTB, 0); - pci_set_irq_level(PCI_INTC, 0); - pci_set_irq_level(PCI_INTD, 0); */ - - return dev; -} - -const device_t ali1435_device = { - .name = "Intel ALi M1435", - .internal_name = "ali1435", - .flags = DEVICE_PCI, - .local = 0x00, - .init = ali1435_init, - .close = ali1435_close, - .reset = ali1435_reset, - { .available = NULL }, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; +/* + * 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. + * + * Emulation of ALi M1435 chipset that acts as both the + * southbridge. + * + * + * + * Authors: Miran Grca, + * + * Copyright 2020 Miran Grca. + */ +#include +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include <86box/device.h> +#include <86box/io.h> +#include <86box/apm.h> +#include <86box/dma.h> +#include <86box/mem.h> +#include <86box/smram.h> +#include <86box/pci.h> +#include <86box/timer.h> +#include <86box/pic.h> +#include <86box/pit.h> +#include <86box/port_92.h> +#include <86box/hdc_ide.h> +#include <86box/hdc.h> +#include <86box/machine.h> +#include <86box/chipset.h> +#include <86box/spd.h> + +#define MEM_STATE_SHADOW_R 0x01 +#define MEM_STATE_SHADOW_W 0x02 +#define MEM_STATE_SMRAM 0x04 + +typedef struct +{ + uint8_t index, cfg_locked, + regs[16], pci_regs[256]; +} ali1435_t; + +#define ENABLE_ALI1435_LOG 1 +#ifdef ENABLE_ALI1435_LOG +int ali1435_do_log = ENABLE_ALI1435_LOG; + +static void +ali1435_log(const char *fmt, ...) +{ + va_list ap; + + if (ali1435_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define ali1435_log(fmt, ...) +#endif + +/* NOTE: We cheat here. The real ALi M1435 uses a level to edge triggered IRQ converter + when the most siginificant bit is set. We work around that by manipulating the + emulated PIC's ELCR register. */ +static void +ali1435_update_irqs(ali1435_t *dev, int set) +{ + uint8_t val; + int reg; + int shift; + int irq; + int irq_map[8] = { -1, 5, 9, 10, 11, 12, 14, 15 }; + pic_t *temp_pic; + + for (uint8_t i = 0; i < 4; i++) { + reg = 0x80 + (i >> 1); + shift = (i & 1) << 2; + val = (dev->pci_regs[reg] >> shift) & 0x0f; + irq = irq_map[val & 0x07]; + if (irq == -1) + continue; + temp_pic = (irq >= 8) ? &pic2 : &pic; + irq &= 7; + if (set && (val & 0x08)) + temp_pic->elcr |= (1 << irq); + else + temp_pic->elcr &= ~(1 << irq); + } +} + +static void +ali1435_pci_write(int func, int addr, uint8_t val, void *priv) +{ + ali1435_t *dev = (ali1435_t *) priv; + int irq; + int irq_map[8] = { -1, 5, 9, 10, 11, 12, 14, 15 }; + + ali1435_log("ali1435_write(%02X, %02X, %02X)\n", func, addr, val); + + if (func > 0) + return; + + if ((addr < 0x04) || (addr == 0x06) || ((addr >= 0x08) && (addr <= 0x0b))) + return; + + if ((addr >= 0x0f) && (addr < 0x30)) + return; + + if ((addr >= 0x34) && (addr < 0x40)) + return; + + switch (addr) { + /* Dummy PCI Config */ + case 0x04: + dev->pci_regs[addr] = (val & 0x7f) | 0x07; + break; + + case 0x05: + dev->pci_regs[addr] = (val & 0x01); + break; + + /* Dummy PCI Status */ + case 0x07: + dev->pci_regs[addr] &= ~(val & 0xb8); + break; + + case 0x80: + case 0x81: + dev->pci_regs[addr] = val; + ali1435_update_irqs(dev, 0); + irq = irq_map[val & 0x07]; + if (irq >= 0) { + ali1435_log("Set IRQ routing: INT %c -> %02X\n", 0x41 + ((addr & 0x01) << 1), irq); + pci_set_irq_routing(PCI_INTA + ((addr & 0x01) << 1), irq); + } else { + ali1435_log("Set IRQ routing: INT %c -> FF\n", 0x41 + ((addr & 0x01) << 1)); + pci_set_irq_routing(PCI_INTA + ((addr & 0x01) << 1), PCI_IRQ_DISABLED); + } + irq = irq_map[(val >> 4) & 0x07]; + if (irq >= 0) { + ali1435_log("Set IRQ routing: INT %c -> %02X\n", 0x42 + ((addr & 0x01) << 1), irq); + pci_set_irq_routing(PCI_INTB + ((addr & 0x01) << 1), irq); + } else { + ali1435_log("Set IRQ routing: INT %c -> FF\n", 0x42 + ((addr & 0x01) << 1)); + pci_set_irq_routing(PCI_INTB + ((addr & 0x01) << 1), PCI_IRQ_DISABLED); + } + ali1435_update_irqs(dev, 1); + break; + + default: + dev->pci_regs[addr] = val; + break; + } +} + +static uint8_t +ali1435_pci_read(int func, int addr, void *priv) +{ + ali1435_t *dev = (ali1435_t *) priv; + uint8_t ret; + + ret = 0xff; + + if (func == 0) + ret = dev->pci_regs[addr]; + + ali1435_log("ali1435_read(%02X, %02X) = %02X\n", func, addr, ret); + + return ret; +} + +static void +ali1435_write(uint16_t addr, uint8_t val, void *priv) +{ + ali1435_t *dev = (ali1435_t *) priv; + + switch (addr) { + case 0x22: + dev->index = val; + break; + + case 0x23: + /* #ifdef ENABLE_ALI1435_LOG + if (dev->index != 0x03) + ali1435_log("M1435: dev->regs[%02x] = %02x\n", dev->index, val); + #endif */ + + if (dev->index == 0x03) + dev->cfg_locked = (val != 0x69); + + if (!dev->cfg_locked) { + pclog("M1435: dev->regs[%02x] = %02x\n", dev->index, val); + + switch (dev->index) { + /* PCI Mechanism select? */ + case 0x00: + dev->regs[dev->index] = val; + pclog("PMC = %i\n", val != 0xc8); + pci_set_pmc(val != 0xc8); + break; + + /* ???? */ + case 0x06: + dev->regs[dev->index] = val; + break; + + /* ???? */ + case 0x07: + dev->regs[dev->index] = val; + break; + } + } + break; + } +} + +static uint8_t +ali1435_read(uint16_t addr, void *priv) +{ + ali1435_t *dev = (ali1435_t *) priv; + uint8_t ret = 0xff; + + if ((addr == 0x23) && (dev->index < 0x10)) + ret = dev->regs[dev->index]; + else if (addr == 0x22) + ret = dev->index; + + return ret; +} + +static void +ali1435_reset(void *priv) +{ + ali1435_t *dev = (ali1435_t *) priv; + + memset(dev->regs, 0, 16); + + dev->regs[0x00] = 0xff; + + pci_set_pmc(0); + + dev->cfg_locked = 1; + + memset(dev->pci_regs, 0, 256); + + dev->pci_regs[0x00] = 0x25; + dev->pci_regs[0x01] = 0x10; /*ALi*/ + dev->pci_regs[0x02] = 0x35; + dev->pci_regs[0x03] = 0x14; /*M1435*/ + dev->pci_regs[0x04] = 0x07; + dev->pci_regs[0x07] = 0x04; + dev->pci_regs[0x0b] = 0x06; + + dev->pci_regs[0x80] = 0x80; + dev->pci_regs[0x81] = 0x00; + + pci_set_irq_routing(PCI_INTA, PCI_IRQ_DISABLED); + pci_set_irq_routing(PCI_INTB, PCI_IRQ_DISABLED); + pci_set_irq_routing(PCI_INTC, PCI_IRQ_DISABLED); + pci_set_irq_routing(PCI_INTD, PCI_IRQ_DISABLED); +} + +static void +ali1435_close(void *p) +{ + ali1435_t *dev = (ali1435_t *) p; + + free(dev); +} + +static void * +ali1435_init(const device_t *info) +{ + ali1435_t *dev = (ali1435_t *) malloc(sizeof(ali1435_t)); + memset(dev, 0, sizeof(ali1435_t)); + + dev->cfg_locked = 1; + + /* M1435 Ports: + 22h Index Port + 23h Data Port + */ + io_sethandler(0x0022, 0x0002, ali1435_read, NULL, NULL, ali1435_write, NULL, NULL, dev); + + pci_add_card(PCI_ADD_NORTHBRIDGE, ali1435_pci_read, ali1435_pci_write, dev); + + ali1435_reset(dev); + + /* pci_set_irq_level(PCI_INTA, 0); + pci_set_irq_level(PCI_INTB, 0); + pci_set_irq_level(PCI_INTC, 0); + pci_set_irq_level(PCI_INTD, 0); */ + + return dev; +} + +const device_t ali1435_device = { + .name = "Intel ALi M1435", + .internal_name = "ali1435", + .flags = DEVICE_PCI, + .local = 0x00, + .init = ali1435_init, + .close = ali1435_close, + .reset = ali1435_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/chipset/ali1489.c b/src/chipset/ali1489.c index 70ff509ab..c7139612a 100644 --- a/src/chipset/ali1489.c +++ b/src/chipset/ali1489.c @@ -206,7 +206,8 @@ static void ali1489_write(uint16_t addr, uint8_t val, void *priv) { ali1489_t *dev = (ali1489_t *) priv; - uint8_t old, irq; + uint8_t old; + uint8_t irq; const uint8_t irq_array[16] = { 0, 3, 4, 7, 0, 0, 0, 0, 9, 10, 5, 6, 11, 12, 14, 15 }; switch (addr) { diff --git a/src/chipset/ali1531.c b/src/chipset/ali1531.c index b92421e31..8d8358731 100644 --- a/src/chipset/ali1531.c +++ b/src/chipset/ali1531.c @@ -91,12 +91,15 @@ ali1531_smram_recalc(uint8_t val, ali1531_t *dev) static void ali1531_shadow_recalc(int cur_reg, ali1531_t *dev) { - int i, bit, r_reg, w_reg; - uint32_t base, flags = 0; + int bit; + int r_reg; + int w_reg; + uint32_t base; + uint32_t flags = 0; shadowbios = shadowbios_write = 0; - for (i = 0; i < 16; i++) { + for (uint8_t i = 0; i < 16; i++) { base = 0x000c0000 + (i << 14); bit = i & 7; r_reg = 0x4c + (i >> 3); diff --git a/src/chipset/ali1541.c b/src/chipset/ali1541.c index 37dd7c809..509bb95f2 100644 --- a/src/chipset/ali1541.c +++ b/src/chipset/ali1541.c @@ -92,12 +92,15 @@ ali1541_smram_recalc(uint8_t val, ali1541_t *dev) static void ali1541_shadow_recalc(int cur_reg, ali1541_t *dev) { - int i, bit, r_reg, w_reg; - uint32_t base, flags = 0; + int bit; + int r_reg; + int w_reg; + uint32_t base; + uint32_t flags = 0; shadowbios = shadowbios_write = 0; - for (i = 0; i < 16; i++) { + for (uint8_t i = 0; i < 16; i++) { base = 0x000c0000 + (i << 14); bit = i & 7; r_reg = 0x56 + (i >> 3); @@ -124,7 +127,8 @@ ali1541_shadow_recalc(int cur_reg, ali1541_t *dev) static void ali1541_mask_bar(ali1541_t *dev) { - uint32_t bar, mask; + uint32_t bar; + uint32_t mask; switch (dev->pci_conf[0xbc] & 0x0f) { case 0x00: diff --git a/src/chipset/ali1543.c b/src/chipset/ali1543.c index 2e2f74305..fcad2486a 100644 --- a/src/chipset/ali1543.c +++ b/src/chipset/ali1543.c @@ -112,7 +112,6 @@ static void ali1533_write(int func, int addr, uint8_t val, void *priv) { ali1543_t *dev = (ali1543_t *) priv; - int irq; ali1543_log("M1533: dev->pci_conf[%02x] = %02x\n", addr, val); if (func > 0) @@ -219,7 +218,7 @@ ali1533_write(int func, int addr, uint8_t val, void *priv) case 0x4c: /* PCI INT to ISA Level to Edge transfer */ dev->pci_conf[addr] = val; - for (irq = 1; irq < 9; irq++) + for (uint8_t irq = 1; irq < 9; irq++) pci_set_irq_level(irq, !(val & (1 << (irq - 1)))); break; @@ -468,7 +467,8 @@ ali1533_read(int func, int addr, void *priv) static void ali5229_ide_irq_handler(ali1543_t *dev) { - int ctl = 0, ch = 0; + int ctl = 0; + int ch = 0; int bit = 0; if (dev->ide_conf[0x52] & 0x10) { @@ -555,17 +555,20 @@ ali5229_ide_handler(ali1543_t *dev) { uint32_t ch = 0; - uint16_t native_base_pri_addr = ((dev->ide_conf[0x11] | dev->ide_conf[0x10] << 8)) & 0xfffe; - uint16_t native_side_pri_addr = ((dev->ide_conf[0x15] | dev->ide_conf[0x14] << 8)) & 0xfffe; - uint16_t native_base_sec_addr = ((dev->ide_conf[0x19] | dev->ide_conf[0x18] << 8)) & 0xfffe; - uint16_t native_side_sec_addr = ((dev->ide_conf[0x1c] | dev->ide_conf[0x1b] << 8)) & 0xfffe; + uint16_t native_base_pri_addr = (dev->ide_conf[0x11] | dev->ide_conf[0x10] << 8) & 0xfffe; + uint16_t native_side_pri_addr = (dev->ide_conf[0x15] | dev->ide_conf[0x14] << 8) & 0xfffe; + uint16_t native_base_sec_addr = (dev->ide_conf[0x19] | dev->ide_conf[0x18] << 8) & 0xfffe; + uint16_t native_side_sec_addr = (dev->ide_conf[0x1c] | dev->ide_conf[0x1b] << 8) & 0xfffe; uint16_t comp_base_pri_addr = 0x01f0; uint16_t comp_side_pri_addr = 0x03f6; uint16_t comp_base_sec_addr = 0x0170; uint16_t comp_side_sec_addr = 0x0376; - uint16_t current_pri_base, current_pri_side, current_sec_base, current_sec_side; + uint16_t current_pri_base; + uint16_t current_pri_side; + uint16_t current_sec_base; + uint16_t current_sec_side; /* Primary Channel Programming */ if (dev->ide_conf[0x52] & 0x10) { @@ -618,7 +621,7 @@ ali5229_ide_handler(ali1543_t *dev) ali1543_log("ali5229_ide_handler(): Enabling secondary IDE...\n"); ide_sec_enable(); - sff_bus_master_handler(dev->ide_controller[1], dev->ide_conf[0x04] & 0x01, (((dev->ide_conf[0x20] & 0xf0) | (dev->ide_conf[0x21] << 8))) + (8 ^ ch)); + sff_bus_master_handler(dev->ide_controller[1], dev->ide_conf[0x04] & 0x01, ((dev->ide_conf[0x20] & 0xf0) | (dev->ide_conf[0x21] << 8)) + (8 ^ ch)); ali1543_log("M5229 SEC: BASE %04x SIDE %04x\n", current_sec_base, current_sec_side); } } else { diff --git a/src/chipset/ali1621.c b/src/chipset/ali1621.c index 7db437b24..aba05e776 100644 --- a/src/chipset/ali1621.c +++ b/src/chipset/ali1621.c @@ -94,7 +94,8 @@ ali1621_log(const char *fmt, ...) static void ali1621_smram_recalc(uint8_t val, ali1621_t *dev) { - uint16_t access_smm = 0x0000, access_normal = 0x0000; + uint16_t access_smm = 0x0000; + uint16_t access_normal = 0x0000; smram_disable_all(); @@ -138,13 +139,16 @@ ali1621_smram_recalc(uint8_t val, ali1621_t *dev) static void ali1621_shadow_recalc(int cur_reg, ali1621_t *dev) { - int i, r_bit, w_bit, reg; - uint32_t base, flags = 0; + int r_bit; + int w_bit; + int reg; + uint32_t base; + uint32_t flags = 0; shadowbios = shadowbios_write = 0; /* C0000-EFFFF */ - for (i = 0; i < 12; i++) { + for (uint8_t i = 0; i < 12; i++) { base = 0x000c0000 + (i << 14); r_bit = (i << 1) + 4; reg = 0x84; @@ -199,7 +203,8 @@ ali1621_shadow_recalc(int cur_reg, ali1621_t *dev) static void ali1621_mask_bar(ali1621_t *dev) { - uint32_t bar, mask; + uint32_t bar; + uint32_t mask; switch (dev->pci_conf[0xbc] & 0x0f) { case 0x00: @@ -578,7 +583,6 @@ static void ali1621_reset(void *priv) { ali1621_t *dev = (ali1621_t *) priv; - int i; /* Default Registers */ dev->pci_conf[0x00] = 0xb9; @@ -633,7 +637,7 @@ ali1621_reset(void *priv) ali1621_write(0, 0x83, 0x08, dev); - for (i = 0; i < 4; i++) + for (uint8_t i = 0; i < 4; i++) ali1621_write(0, 0x84 + i, 0x00, dev); } diff --git a/src/chipset/ali6117.c b/src/chipset/ali6117.c index 796ca880f..3d86fbcd2 100644 --- a/src/chipset/ali6117.c +++ b/src/chipset/ali6117.c @@ -102,8 +102,8 @@ ali6117_log(const char *fmt, ...) static void ali6117_recalcmapping(ali6117_t *dev) { - uint8_t reg, bitpair; - uint32_t base, size; + uint32_t base; + uint32_t size; int state; shadowbios = 0; @@ -112,8 +112,8 @@ ali6117_recalcmapping(ali6117_t *dev) ali6117_log("ALI6117: Shadowing for A0000-BFFFF (reg 12 bit 1) = %s\n", (dev->regs[0x12] & 0x02) ? "on" : "off"); mem_set_mem_state(0xa0000, 0x20000, (dev->regs[0x12] & 0x02) ? (MEM_WRITE_INTERNAL | MEM_READ_INTERNAL) : (MEM_WRITE_EXTANY | MEM_READ_EXTANY)); - for (reg = 0; reg <= 1; reg++) { - for (bitpair = 0; bitpair <= 3; bitpair++) { + for (uint8_t reg = 0; reg <= 1; reg++) { + for (uint8_t bitpair = 0; bitpair <= 3; bitpair++) { size = 0x8000; base = 0xc0000 + (size * ((reg * 4) + bitpair)); ali6117_log("ALI6117: Shadowing for %05X-%05X (reg %02X bp %d wmask %02X rmask %02X) =", base, base + size - 1, 0x14 + reg, bitpair, 1 << ((bitpair * 2) + 1), 1 << (bitpair * 2)); @@ -148,10 +148,10 @@ ali6117_recalcmapping(ali6117_t *dev) static void ali6117_bank_recalc(ali6117_t *dev) { - int i; - uint32_t bank, addr; + uint32_t bank; + uint32_t addr; - for (i = 0x00000000; i < (mem_size << 10); i += 4096) { + for (uint32_t i = 0x00000000; i < (mem_size << 10); i += 4096) { if ((i >= 0x000a0000) && (i < 0x00100000)) continue; @@ -454,7 +454,7 @@ ali6117_close(void *priv) static void * ali6117_init(const device_t *info) { - int i, last_match = 0; + int last_match = 0; ali6117_log("ALI6117: init()\n"); @@ -467,7 +467,7 @@ ali6117_init(const device_t *info) ali6117_setup(dev); - for (i = 31; i >= 0; i--) { + for (int8_t i = 31; i >= 0; i--) { if ((mem_size >= ali6117_modes[i][0]) && (ali6117_modes[i][0] > last_match)) { last_match = ali6117_modes[i][0]; dev->mode = i; diff --git a/src/chipset/contaq_82c59x.c b/src/chipset/contaq_82c59x.c index 951a86b0a..720d7c81e 100644 --- a/src/chipset/contaq_82c59x.c +++ b/src/chipset/contaq_82c59x.c @@ -89,7 +89,8 @@ contaq_82c59x_isa_speed_recalc(contaq_82c59x_t *dev) static void contaq_82c59x_shadow_recalc(contaq_82c59x_t *dev) { - uint32_t i, base; + uint32_t i; + uint32_t base; uint8_t bit; shadowbios = shadowbios_write = 0; diff --git a/src/chipset/gc100.c b/src/chipset/gc100.c index 2aba21350..0df25b1d6 100644 --- a/src/chipset/gc100.c +++ b/src/chipset/gc100.c @@ -70,9 +70,9 @@ gc100_log(const char *fmt, ...) static uint8_t get_fdd_switch_settings(void) { - int i, fdd_count = 0; + int fdd_count = 0; - for (i = 0; i < FDD_NUM; i++) { + for (uint8_t i = 0; i < FDD_NUM; i++) { if (fdd_get_flags(i)) fdd_count++; } diff --git a/src/chipset/headland.c b/src/chipset/headland.c index 8b8ee1562..31cb75253 100644 --- a/src/chipset/headland.c +++ b/src/chipset/headland.c @@ -105,7 +105,11 @@ static const int mem_conf_cr1[41] = { static uint32_t get_addr(headland_t *dev, uint32_t addr, headland_mr_t *mr) { - uint32_t bank_base[4], bank_shift[4], shift, other_shift, bank; + uint32_t bank_base[4]; + uint32_t bank_shift[4]; + uint32_t shift; + uint32_t other_shift; + uint32_t bank; if ((addr >= 0x0e0000) && (addr <= 0x0fffff)) return addr; @@ -173,7 +177,8 @@ hl_ems_disable(headland_t *dev, uint8_t mar, uint32_t base_addr, uint8_t indx) static void hl_ems_update(headland_t *dev, uint8_t mar) { - uint32_t base_addr, virt_addr; + uint32_t base_addr; + uint32_t virt_addr; uint8_t indx = mar & 0x1f; base_addr = (indx + 16) << 14; @@ -202,9 +207,7 @@ hl_ems_update(headland_t *dev, uint8_t mar) static void set_global_EMS_state(headland_t *dev, int state) { - int i; - - for (i = 0; i < 32; i++) { + for (uint8_t i = 0; i < 32; i++) { hl_ems_update(dev, i | (((dev->cr[0] & 0x01) << 5) ^ 0x20)); hl_ems_update(dev, i | ((dev->cr[0] & 0x01) << 5)); } @@ -229,7 +232,6 @@ static void memmap_state_update(headland_t *dev) { uint32_t addr; - int i; uint8_t ht_cr0 = dev->cr[0]; uint8_t ht_romcs = !(dev->cr[4] & 0x01); if (dev->revision <= 1) @@ -237,7 +239,7 @@ memmap_state_update(headland_t *dev) if (!(dev->cr[0] & 0x04)) ht_cr0 &= ~0x18; - for (i = 0; i < 24; i++) { + for (uint8_t i = 0; i < 24; i++) { addr = get_addr(dev, 0x40000 + (i << 14), NULL); mem_mapping_set_exec(&dev->upper_mapping[i], addr < ((uint32_t) mem_size << 10) ? ram + addr : NULL); } @@ -684,7 +686,7 @@ headland_init(const device_t *info) memmap_state_update(dev); - return (dev); + return dev; } const device_t headland_gc10x_device = { diff --git a/src/chipset/ims8848.c b/src/chipset/ims8848.c index 0b67661ef..34a09ae35 100644 --- a/src/chipset/ims8848.c +++ b/src/chipset/ims8848.c @@ -148,7 +148,8 @@ ims8848_log(const char *fmt, ...) static void ims8848_recalc(ims8848_t *dev) { - int i, state_on; + int i; + int state_on; uint32_t base; ims8848_log("SHADOW: 00 = %02X, 08 = %02X, 1B = %02X, 1C = %02X\n", dev->regs[0x00], dev->regs[0x08], dev->regs[0x1b], dev->regs[0x1c]); diff --git a/src/chipset/intel_420ex.c b/src/chipset/intel_420ex.c index 492f7a0d1..b2a0e082b 100644 --- a/src/chipset/intel_420ex.c +++ b/src/chipset/intel_420ex.c @@ -113,8 +113,9 @@ i420ex_smram_handler_phase1(i420ex_t *dev) { uint8_t *regs = (uint8_t *) dev->regs; - uint32_t host_base = 0x000a0000, ram_base = 0x000a0000; - uint32_t size = 0x00010000; + uint32_t host_base = 0x000a0000; + uint32_t ram_base = 0x000a0000; + uint32_t size = 0x00010000; switch (regs[0x70] & 0x07) { case 0: diff --git a/src/chipset/intel_4x0.c b/src/chipset/intel_4x0.c index 8f74c79d9..bebfa6ade 100644 --- a/src/chipset/intel_4x0.c +++ b/src/chipset/intel_4x0.c @@ -119,7 +119,8 @@ i4x0_smram_handler_phase1(i4x0_t *dev) uint8_t *reg = (dev->type >= INTEL_430LX) ? &(regs[0x72]) : &(regs[0x57]); uint8_t *ext_reg = (dev->type >= INTEL_440BX) ? &(regs[0x73]) : &(regs[0x71]); - uint32_t s, base[2] = { 0x000a0000, 0x00000000 }; + uint32_t s; + uint32_t base[2] = { 0x000a0000, 0x00000000 }; uint32_t size[2] = { 0x00010000, 0x00000000 }; if ((dev->type <= INTEL_420ZX) || (dev->type >= INTEL_430FX)) { @@ -242,7 +243,6 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) i4x0_t *dev = (i4x0_t *) priv; uint8_t *regs = (uint8_t *) dev->regs; uint8_t *regs_l = (uint8_t *) dev->regs_locked; - int i; if (func > 0) return; @@ -1358,7 +1358,7 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440ZX: case INTEL_440GX: regs[0xe7] = 0x80; - for (i = 0; i < 16; i++) + for (uint8_t i = 0; i < 16; i++) regs_l[0xe0 + i] = !!(val & 0x80); if (!regs_l[0xe7]) { regs[0xe7] |= (val & 0x7f); @@ -1484,9 +1484,9 @@ static void regs[0x0d] = 0x20; /* According to information from FreeBSD 3.x source code: 0x00 = 486DX, 0x20 = 486SX, 0x40 = 486DX2 or 486DX4, 0x80 = Pentium OverDrive. */ - if (!(hasfpu) && (cpu_multi == 1)) + if (!hasfpu && (cpu_multi == 1)) regs[0x50] = 0x20; - else if (!(hasfpu) && (cpu_multi == 2)) + else if (!hasfpu && (cpu_multi == 2)) regs[0x50] = 0x60; /* Guess based on the SX, DX, and DX2 values. */ else if (hasfpu && (cpu_multi == 1)) regs[0x50] = 0x00; diff --git a/src/chipset/intel_82335.c b/src/chipset/intel_82335.c index e945f35d1..678c868f3 100644 --- a/src/chipset/intel_82335.c +++ b/src/chipset/intel_82335.c @@ -86,8 +86,11 @@ intel_82335_log(const char *fmt, ...) static void intel_82335_write(uint16_t addr, uint16_t val, void *priv) { - intel_82335_t *dev = (intel_82335_t *) priv; - uint32_t romsize = 0, base = 0, i = 0, rc1_remap = 0, rc2_remap = 0; + intel_82335_t *dev = (intel_82335_t *) priv; + uint32_t romsize = 0; + uint32_t base = 0; + uint32_t rc1_remap = 0; + uint32_t rc2_remap = 0; dev->regs[addr] = val; @@ -128,7 +131,7 @@ intel_82335_write(uint16_t addr, uint16_t val, void *priv) case 0x2e: /* Extended Granularity (Enabled if Bit 0 in Register 2Ch is set) */ if (EXTENDED_GRANULARITY_ENABLED) { - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { base = 0xc0000 + (i << 15); shadowbios = (dev->regs[0x2e] & (1 << (i + 8))) && (base == romsize); shadowbios_write = (dev->regs[0x2e] & (1 << i)) && (base == romsize); diff --git a/src/chipset/intel_i450kx.c b/src/chipset/intel_i450kx.c index ac3746492..de6d25422 100644 --- a/src/chipset/intel_i450kx.c +++ b/src/chipset/intel_i450kx.c @@ -89,7 +89,8 @@ static void i450kx_smram_recalc(i450kx_t *dev, int bus) { uint8_t *regs = bus ? dev->pb_pci_conf : dev->mc_pci_conf; - uint32_t addr, size; + uint32_t addr; + uint32_t size; smram_disable(dev->smram[bus]); @@ -386,10 +387,8 @@ pb_read(int func, int addr, void *priv) static void mc_fill_drbs(i450kx_t *dev) { - int i; - spd_write_drbs_interleaved(dev->mc_pci_conf, 0x60, 0x6f, 4); - for (i = 0x60; i <= 0x6f; i++) { + for (uint8_t i = 0x60; i <= 0x6f; i++) { if (i & 0x01) dev->mc_pci_conf[i] = 0x00; else diff --git a/src/chipset/intel_piix.c b/src/chipset/intel_piix.c index 470978611..3a65d5de3 100644 --- a/src/chipset/intel_piix.c +++ b/src/chipset/intel_piix.c @@ -101,7 +101,8 @@ piix_log(const char *fmt, ...) static void smsc_ide_irqs(piix_t *dev) { - int irq_line = 3, irq_mode[2] = { 0, 0 }; + int irq_line = 3; + uint8_t irq_mode[2] = { 0, 0 }; if (dev->regs[1][0x09] & 0x01) irq_mode[0] = (dev->regs[0][0xe1] & 0x01) ? 3 : 1; @@ -148,7 +149,8 @@ smsc_ide_irqs(piix_t *dev) static void piix_ide_handlers(piix_t *dev, int bus) { - uint16_t main, side; + uint16_t main; + uint16_t side; if (bus & 0x01) { ide_pri_disable(); @@ -317,7 +319,8 @@ static void piix_trap_update(void *priv) { piix_t *dev = (piix_t *) priv; - uint8_t trap_id = 0, *fregs = dev->regs[3]; + uint8_t trap_id = 0; + uint8_t *fregs = dev->regs[3]; uint16_t temp; piix_trap_update_devctl(dev, trap_id++, 0, 0x00000002, 1, 0x1f0, 8); @@ -459,7 +462,6 @@ piix_write(int func, int addr, uint8_t val, void *priv) piix_t *dev = (piix_t *) priv; uint8_t *fregs; uint16_t base; - int i; /* Return on unsupported function. */ if (dev->max_func > 0) { @@ -639,7 +641,7 @@ piix_write(int func, int addr, uint8_t val, void *priv) base = fregs[addr | 0x01] << 8; base |= fregs[addr & 0xfe]; - for (i = 0; i < 4; i++) + for (uint8_t i = 0; i < 4; i++) ddma_update_io_mapping(dev->ddma, (addr & 4) + i, fregs[addr & 0xfe] + (i << 4), fregs[addr | 0x01], (base != 0x0000)); } break; @@ -1149,8 +1151,9 @@ piix_write(int func, int addr, uint8_t val, void *priv) static uint8_t piix_read(int func, int addr, void *priv) { - piix_t *dev = (piix_t *) priv; - uint8_t ret = 0xff, *fregs; + piix_t *dev = (piix_t *) priv; + uint8_t ret = 0xff; + uint8_t *fregs; if ((dev->type == 3) && (func == 2) && (dev->max_func == 1) && (addr >= 0x40)) ret = 0x00; @@ -1202,7 +1205,6 @@ board_read(uint16_t port, void *priv) static void piix_reset_hard(piix_t *dev) { - int i; uint8_t *fregs; uint16_t old_base = (dev->regs[1][0x20] & 0xf0) | (dev->regs[1][0x21] << 8); @@ -1239,7 +1241,7 @@ piix_reset_hard(piix_t *dev) } /* Clear all 4 functions' arrays and set their vendor and device ID's. */ - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { memset(dev->regs[i], 0, 256); if (dev->type == 5) { dev->regs[i][0x00] = 0x55; @@ -1291,7 +1293,7 @@ piix_reset_hard(piix_t *dev) fregs[0xa0] = (dev->type < 4) ? 0x08 : 0x00; fregs[0xa8] = (dev->type < 4) ? 0x0f : 0x00; if (dev->type > 3) - fregs[0xb0] = (is_pentium) ? 0x00 : 0x04; + fregs[0xb0] = is_pentium ? 0x00 : 0x04; fregs[0xcb] = (dev->type > 3) ? 0x21 : 0x00; if (dev->type > 4) { fregs[0xd4] = 0x70; @@ -1497,7 +1499,7 @@ piix_reset(void *p) } if (dev->type >= 4) { - piix_write(0, 0xb0, (is_pentium) ? 0x00 : 0x04, p); + piix_write(0, 0xb0, is_pentium ? 0x00 : 0x04, p); piix_write(3, 0x40, 0x01, p); piix_write(3, 0x41, 0x00, p); piix_write(3, 0x5b, 0x00, p); diff --git a/src/chipset/neat.c b/src/chipset/neat.c index 83f3eb96a..2613b8de9 100644 --- a/src/chipset/neat.c +++ b/src/chipset/neat.c @@ -250,9 +250,9 @@ ems_readb(uint32_t addr, void *priv) uint8_t ret = 0xff; /* Grab the data. */ - ret = *(uint8_t *) (dev->ems[((addr & 0xffff) >> 14)].addr + (addr & 0x3fff)); + ret = *(uint8_t *) (dev->ems[(addr & 0xffff) >> 14].addr + (addr & 0x3fff)); - return (ret); + return ret; } /* Read one word from paged RAM. */ @@ -263,9 +263,9 @@ ems_readw(uint32_t addr, void *priv) uint16_t ret = 0xffff; /* Grab the data. */ - ret = *(uint16_t *) (dev->ems[((addr & 0xffff) >> 14)].addr + (addr & 0x3fff)); + ret = *(uint16_t *) (dev->ems[(addr & 0xffff) >> 14].addr + (addr & 0x3fff)); - return (ret); + return ret; } /* Write one byte to paged RAM. */ @@ -275,7 +275,7 @@ ems_writeb(uint32_t addr, uint8_t val, void *priv) neat_t *dev = (neat_t *) priv; /* Write the data. */ - *(uint8_t *) (dev->ems[((addr & 0xffff) >> 14)].addr + (addr & 0x3fff)) = val; + *(uint8_t *) (dev->ems[(addr & 0xffff) >> 14].addr + (addr & 0x3fff)) = val; } /* Write one word to paged RAM. */ @@ -285,7 +285,7 @@ ems_writew(uint32_t addr, uint16_t val, void *priv) neat_t *dev = (neat_t *) priv; /* Write the data. */ - *(uint16_t *) (dev->ems[((addr & 0xffff) >> 14)].addr + (addr & 0x3fff)) = val; + *(uint16_t *) (dev->ems[(addr & 0xffff) >> 14].addr + (addr & 0x3fff)) = val; } /* Re-calculate the active-page physical address. */ @@ -365,7 +365,7 @@ ems_read(uint16_t port, void *priv) neat_log("NEAT: ems_read(%04x) = %02x\n", port, ret); #endif - return (ret); + return ret; } /* Initialize the EMS module. */ @@ -435,9 +435,10 @@ ems_init(neat_t *dev, int en) static void neat_write(uint16_t port, uint8_t val, void *priv) { - neat_t *dev = (neat_t *) priv; - uint8_t xval, *reg; - int i; + neat_t *dev = (neat_t *) priv; + uint8_t xval; + uint8_t *reg; + int i; #if NEAT_DEBUG > 2 neat_log("NEAT: write(%04x, %02x)\n", port, val); @@ -647,7 +648,7 @@ neat_read(uint16_t port, void *priv) neat_log("NEAT: read(%04x) = %02x\n", port, ret); #endif - return (ret); + return ret; } static void diff --git a/src/chipset/opti283.c b/src/chipset/opti283.c index b3b51d8fa..8989139e4 100644 --- a/src/chipset/opti283.c +++ b/src/chipset/opti283.c @@ -113,10 +113,12 @@ opti283_write_remapped_raml(uint32_t addr, uint32_t val, void *priv) static void opti283_shadow_recalc(opti283_t *dev) { - uint32_t i, base; + uint32_t base; uint32_t rbase; - uint8_t sh_enable, sh_mode; - uint8_t rom, sh_copy; + uint8_t sh_enable; + uint8_t sh_mode; + uint8_t rom; + uint8_t sh_copy; shadowbios = shadowbios_write = 0; dev->shadow_high = 0; @@ -143,7 +145,7 @@ opti283_shadow_recalc(opti283_t *dev) } sh_copy = dev->regs[0x11] & 0x08; - for (i = 0; i < 12; i++) { + for (uint8_t i = 0; i < 12; i++) { base = 0xc0000 + (i << 14); if (i >= 4) sh_enable = dev->regs[0x12] & (1 << (i - 4)); diff --git a/src/chipset/opti391.c b/src/chipset/opti391.c index 4b9b8faff..1aad0a8cc 100644 --- a/src/chipset/opti391.c +++ b/src/chipset/opti391.c @@ -60,9 +60,12 @@ typedef struct static void opti391_shadow_recalc(opti391_t *dev) { - uint32_t i, base; - uint8_t sh_enable, sh_master; - uint8_t sh_wp, sh_write_internal; + uint32_t i; + uint32_t base; + uint8_t sh_enable; + uint8_t sh_master; + uint8_t sh_wp; + uint8_t sh_write_internal; shadowbios = shadowbios_write = 0; diff --git a/src/chipset/opti495.c b/src/chipset/opti495.c index 5eb5782e0..c02f19e10 100644 --- a/src/chipset/opti495.c +++ b/src/chipset/opti495.c @@ -60,7 +60,8 @@ static void opti495_recalc(opti495_t *dev) { uint32_t base; - uint32_t i, shflags = 0; + uint32_t i; + uint32_t shflags = 0; shadowbios = 0; shadowbios_write = 0; diff --git a/src/chipset/opti499.c b/src/chipset/opti499.c index c033cd4f5..b6219b1a4 100644 --- a/src/chipset/opti499.c +++ b/src/chipset/opti499.c @@ -59,7 +59,8 @@ static void opti499_recalc(opti499_t *dev) { uint32_t base; - uint32_t i, shflags = 0; + uint32_t i; + uint32_t shflags = 0; shadowbios = 0; shadowbios_write = 0; diff --git a/src/chipset/opti822.c b/src/chipset/opti822.c index 7db233935..f9b0bf8a7 100644 --- a/src/chipset/opti822.c +++ b/src/chipset/opti822.c @@ -71,11 +71,13 @@ opti822_log(const char *fmt, ...) static void opti822_recalc(opti822_t *dev) { - int i, reg, bit_r, bit_w; + int reg; + int bit_r; + int bit_w; int state; uint32_t base; - for (i = 0; i < 12; i++) { + for (uint8_t i = 0; i < 12; i++) { base = 0x000c0000 + (i << 14); reg = 0x44 + ((i >> 2) ^ 3); bit_w = (i & 3); @@ -99,15 +101,16 @@ static void opti822_update_irqs(opti822_t *dev, int set) { uint8_t val; - int i, reg; - int shift, irq; + int reg; + int shift; + int irq; int irq_map[8] = { -1, 5, 9, 10, 11, 12, 14, 15 }; pic_t *temp_pic; // dev->irq_convert = (dev->pci_regs[0x53] & 0x08); dev->irq_convert = 1; - for (i = 0; i < 16; i++) { + for (uint8_t i = 0; i < 16; i++) { reg = 0x88 + (i >> 1); shift = (i & 1) << 2; val = (dev->pci_regs[reg] >> shift) & 0x0f; @@ -127,8 +130,10 @@ static void opti822_pci_write(int func, int addr, uint8_t val, void *priv) { opti822_t *dev = (opti822_t *) priv; - int irq, irq_map[8] = { -1, 5, 9, 10, 11, 12, 14, 15 }; - int pin, slot; + int irq; + int irq_map[8] = { -1, 5, 9, 10, 11, 12, 14, 15 }; + int pin; + int slot; opti822_log("opti822_write(%02X, %02X, %02X)\n", func, addr, val); @@ -343,7 +348,6 @@ static void opti822_reset(void *priv) { opti822_t *dev = (opti822_t *) priv; - int i; memset(dev->pci_regs, 0, 256); @@ -366,7 +370,7 @@ opti822_reset(void *priv) dev->irq_convert = 1 /*0*/; - for (i = 0; i < 16; i++) + for (uint8_t i = 0; i < 16; i++) pci_set_irq_routing(PCI_INTA + i, PCI_IRQ_DISABLED); } diff --git a/src/chipset/opti895.c b/src/chipset/opti895.c index 51ffc7430..18f1791e8 100644 --- a/src/chipset/opti895.c +++ b/src/chipset/opti895.c @@ -64,7 +64,8 @@ static void opti895_recalc(opti895_t *dev) { uint32_t base; - uint32_t i, shflags = 0; + uint32_t i; + uint32_t shflags = 0; shadowbios = 0; shadowbios_write = 0; diff --git a/src/chipset/scamp.c b/src/chipset/scamp.c index 6e61db681..1ab5749f7 100644 --- a/src/chipset/scamp.c +++ b/src/chipset/scamp.c @@ -151,8 +151,10 @@ ram_mirrored_256k_in_4mi_read(uint32_t addr, void *priv) { ram_struct_t *rs = (ram_struct_t *) priv; scamp_t *dev = rs->parent; - int bank = rs->bank, byte; - int row, column; + int bank = rs->bank; + int byte; + int row; + int column; addr -= dev->ram_virt_base[bank]; byte = addr & 1; @@ -180,8 +182,10 @@ ram_mirrored_256k_in_4mi_write(uint32_t addr, uint8_t val, void *priv) { ram_struct_t *rs = (ram_struct_t *) priv; scamp_t *dev = rs->parent; - int bank = rs->bank, byte; - int row, column; + int bank = rs->bank; + int byte; + int row; + int column; addr -= dev->ram_virt_base[bank]; byte = addr & 1; @@ -211,8 +215,10 @@ ram_mirrored_interleaved_read(uint32_t addr, void *priv) { ram_struct_t *rs = (ram_struct_t *) priv; scamp_t *dev = rs->parent; - int bank = rs->bank, byte; - int row, column; + int bank = rs->bank; + int byte; + int row; + int column; addr -= dev->ram_virt_base[bank]; byte = addr & 1; @@ -240,8 +246,10 @@ ram_mirrored_interleaved_write(uint32_t addr, uint8_t val, void *priv) { ram_struct_t *rs = (ram_struct_t *) priv; scamp_t *dev = rs->parent; - int bank = rs->bank, byte; - int row, column; + int bank = rs->bank; + int byte; + int row; + int column; addr -= dev->ram_virt_base[bank]; byte = addr & 1; @@ -269,8 +277,10 @@ ram_mirrored_read(uint32_t addr, void *priv) { ram_struct_t *rs = (ram_struct_t *) priv; scamp_t *dev = rs->parent; - int bank = rs->bank, byte; - int row, column; + int bank = rs->bank; + int byte; + int row; + int column; addr -= dev->ram_virt_base[bank]; byte = addr & 1; @@ -286,8 +296,10 @@ ram_mirrored_write(uint32_t addr, uint8_t val, void *priv) { ram_struct_t *rs = (ram_struct_t *) priv; scamp_t *dev = rs->parent; - int bank = rs->bank, byte; - int row, column; + int bank = rs->bank; + int byte; + int row; + int column; addr -= dev->ram_virt_base[bank]; byte = addr & 1; @@ -302,15 +314,16 @@ static void recalc_mappings(void *priv) { scamp_t *dev = (scamp_t *) priv; - int c; - uint32_t virt_base = 0, old_virt_base; + uint32_t virt_base = 0; + uint32_t old_virt_base; uint8_t cur_rammap = dev->cfg_regs[CFG_RAMMAP] & 0xf; - int bank_nr = 0, phys_bank; + int bank_nr = 0; + int phys_bank; mem_set_mem_state_both((1 << 20), (16256 - 1024) * 1024, MEM_READ_EXTERNAL | MEM_WRITE_EXTERNAL); mem_set_mem_state(0xfe0000, 0x20000, MEM_READ_EXTANY | MEM_WRITE_EXTANY); - for (c = 0; c < 2; c++) + for (uint8_t c = 0; c < 2; c++) mem_mapping_disable(&dev->ram_mapping[c]); /* Once the BIOS programs the correct DRAM configuration, switch to regular diff --git a/src/chipset/scat.c b/src/chipset/scat.c index 2bbac6cc0..fe3846d89 100644 --- a/src/chipset/scat.c +++ b/src/chipset/scat.c @@ -113,13 +113,16 @@ static void scat_out(uint16_t port, uint8_t val, void *priv); static void shadow_state_update(scat_t *dev) { - int i, val; + int val; - uint32_t base, bit, romcs, shflags = 0; + uint32_t base; + uint32_t bit; + uint32_t romcs; + uint32_t shflags = 0; shadowbios = shadowbios_write = 0; - for (i = 0; i < 24; i++) { + for (uint8_t i = 0; i < 24; i++) { if ((dev->regs[SCAT_DRAM_CONFIGURATION] & 0xf) < 4) val = 0; else @@ -150,7 +153,6 @@ static void set_xms_bound(scat_t *dev, uint8_t val) { uint32_t xms_max = ((dev->regs[SCAT_VERSION] & 0xf0) != 0 && ((val & 0x10) != 0)) || (dev->regs[SCAT_VERSION] >= 4) ? 0xfe0000 : 0xfc0000; - int i; switch (val & 0x0f) { case 1: @@ -245,7 +247,7 @@ set_xms_bound(scat_t *dev, uint8_t val) mem_mapping_set_addr(&dev->low_mapping[31], 0xf80000, ((dev->regs[SCAT_VERSION] & 0xf0) != 0 && ((val & 0x10) != 0)) || (dev->regs[SCAT_VERSION] >= 4) ? 0x60000 : 0x40000); if (dev->regs[SCAT_VERSION] & 0xf0) { - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { if (val & 0x10) mem_mapping_disable(&bios_high_mapping); else @@ -258,7 +260,8 @@ static uint32_t get_addr(scat_t *dev, uint32_t addr, ems_page_t *p) { #if 1 - int nbanks_2048k, nbanks_512k; + int nbanks_2048k; + int nbanks_512k; uint32_t addr2; int nbank; #else @@ -882,10 +885,11 @@ get_addr(scat_t *dev, uint32_t addr, ems_page_t *p) static void set_global_EMS_state(scat_t *dev, int state) { - uint32_t base_addr, virt_addr; - int i, conf; + uint32_t base_addr; + uint32_t virt_addr; + int conf; - for (i = ((dev->regs[SCAT_VERSION] & 0xf0) == 0) ? 0 : 24; i < 32; i++) { + for (uint32_t i = ((dev->regs[SCAT_VERSION] & 0xf0) == 0) ? 0 : 24; i < 32; i++) { base_addr = (i + 16) << 14; if (i >= 24) @@ -1009,12 +1013,13 @@ memmap_state_update(scat_t *dev) static void scat_out(uint16_t port, uint8_t val, void *priv) { - scat_t *dev = (scat_t *) priv; - uint8_t reg_valid = 0, - shadow_update = 0, - map_update = 0, - indx; - uint32_t base_addr, virt_addr; + scat_t *dev = (scat_t *) priv; + uint8_t reg_valid = 0; + uint8_t shadow_update = 0; + uint8_t map_update = 0; + uint8_t indx; + uint32_t base_addr; + uint32_t virt_addr; switch (port) { case 0x22: @@ -1193,7 +1198,8 @@ static uint8_t scat_in(uint16_t port, void *priv) { scat_t *dev = (scat_t *) priv; - uint8_t ret = 0xff, indx; + uint8_t ret = 0xff; + uint8_t indx; switch (port) { case 0x23: @@ -1304,7 +1310,8 @@ mem_write_scatb(uint32_t addr, uint8_t val, void *priv) { ems_page_t *page = (ems_page_t *) priv; scat_t *dev = (scat_t *) page->scat; - uint32_t oldaddr = addr, chkaddr; + uint32_t oldaddr = addr; + uint32_t chkaddr; addr = get_addr(dev, addr, page); chkaddr = page->valid ? addr : oldaddr; @@ -1322,7 +1329,8 @@ mem_write_scatw(uint32_t addr, uint16_t val, void *priv) { ems_page_t *page = (ems_page_t *) priv; scat_t *dev = (scat_t *) page->scat; - uint32_t oldaddr = addr, chkaddr; + uint32_t oldaddr = addr; + uint32_t chkaddr; addr = get_addr(dev, addr, page); chkaddr = page->valid ? addr : oldaddr; @@ -1340,7 +1348,8 @@ mem_write_scatl(uint32_t addr, uint32_t val, void *priv) { ems_page_t *page = (ems_page_t *) priv; scat_t *dev = (scat_t *) page->scat; - uint32_t oldaddr = addr, chkaddr; + uint32_t oldaddr = addr; + uint32_t chkaddr; addr = get_addr(dev, addr, page); chkaddr = page->valid ? addr : oldaddr; @@ -1365,7 +1374,8 @@ static void * scat_init(const device_t *info) { scat_t *dev; - uint32_t i, k; + uint32_t i; + uint32_t k; int sx; dev = (scat_t *) malloc(sizeof(scat_t)); @@ -1418,7 +1428,7 @@ scat_init(const device_t *info) mem_mapping_disable(&ram_mid_mapping); mem_mapping_disable(&ram_high_mapping); - k = (sx) ? 0x80000 : 0x40000; + k = sx ? 0x80000 : 0x40000; dev->null_page.valid = 0; dev->null_page.regs_2x8 = 0xff; @@ -1511,7 +1521,7 @@ scat_init(const device_t *info) device_add(&port_92_device); - return (dev); + return dev; } const device_t scat_device = { diff --git a/src/chipset/sis_5511.c b/src/chipset/sis_5511.c index d13a1cf83..462db88ea 100644 --- a/src/chipset/sis_5511.c +++ b/src/chipset/sis_5511.c @@ -79,10 +79,10 @@ typedef struct sis_5511_t { static void sis_5511_shadow_recalc(sis_5511_t *dev) { - int i, state; + int state; uint32_t base; - for (i = 0x80; i <= 0x86; i++) { + for (uint8_t i = 0x80; i <= 0x86; i++) { if (i == 0x86) { state = (dev->pci_conf[i] & 0x80) ? MEM_READ_INTERNAL : MEM_READ_EXTANY; state |= (dev->pci_conf[i] & 0x20) ? MEM_WRITE_INTERNAL : MEM_WRITE_EXTANY; diff --git a/src/chipset/sis_85c496.c b/src/chipset/sis_85c496.c index 6a65e2d62..6b09cf87e 100644 --- a/src/chipset/sis_85c496.c +++ b/src/chipset/sis_85c496.c @@ -121,12 +121,12 @@ static void sis_85c496_recalcmapping(sis_85c496_t *dev) { uint32_t base; - uint32_t i, shflags = 0; + uint32_t shflags = 0; shadowbios = 0; shadowbios_write = 0; - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { base = 0xc0000 + (i << 15); if (dev->pci_conf[0x44] & (1 << i)) { @@ -185,9 +185,12 @@ static void sis_85c49x_pci_write(int func, int addr, uint8_t val, void *priv) { sis_85c496_t *dev = (sis_85c496_t *) priv; - uint8_t old, valxor; + uint8_t old; + uint8_t valxor; uint8_t smm_irq[4] = { 10, 11, 12, 15 }; - uint32_t host_base, ram_base, size; + uint32_t host_base; + uint32_t ram_base; + uint32_t size; old = dev->pci_conf[addr]; valxor = (dev->pci_conf[addr]) ^ val; @@ -526,7 +529,6 @@ static void sis_85c496_reset(void *priv) { sis_85c496_t *dev = (sis_85c496_t *) priv; - int i; sis_85c49x_pci_write(0, 0x44, 0x00, dev); sis_85c49x_pci_write(0, 0x45, 0x00, dev); @@ -535,7 +537,7 @@ sis_85c496_reset(void *priv) sis_85c49x_pci_write(0, 0x5a, 0x00, dev); // sis_85c49x_pci_write(0, 0x5a, 0x06, dev); - for (i = 0; i < 8; i++) + for (uint8_t i = 0; i < 8; i++) sis_85c49x_pci_write(0, 0x48 + i, 0x00, dev); sis_85c49x_pci_write(0, 0x80, 0x00, dev); diff --git a/src/chipset/sis_85c4xx.c b/src/chipset/sis_85c4xx.c index 670a2cc83..94a1fc876 100644 --- a/src/chipset/sis_85c4xx.c +++ b/src/chipset/sis_85c4xx.c @@ -62,10 +62,13 @@ sis_85c4xx_recalcremap(sis_85c4xx_t *dev) static void sis_85c4xx_recalcmapping(sis_85c4xx_t *dev) { - uint32_t base, n = 0; - uint32_t i, shflags = 0; - uint32_t readext, writeext; - uint8_t romcs = 0xc0, cur_romcs; + uint32_t base; + uint32_t n = 0; + uint32_t shflags = 0; + uint32_t readext; + uint32_t writeext; + uint8_t romcs = 0xc0; + uint8_t cur_romcs; dev->shadowed = 0x00; @@ -79,7 +82,7 @@ sis_85c4xx_recalcmapping(sis_85c4xx_t *dev) if (dev->regs[0x08] & 0x04) romcs |= 0x02; - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { base = 0xc0000 + (i << 15); cur_romcs = romcs & (1 << i); readext = cur_romcs ? MEM_READ_EXTANY : MEM_READ_EXTERNAL; @@ -155,7 +158,8 @@ sis_85c4xx_out(uint16_t port, uint8_t val, void *priv) sis_85c4xx_t *dev = (sis_85c4xx_t *) priv; uint8_t rel_reg = dev->cur_reg - dev->reg_base; uint8_t valxor = 0x00; - uint32_t host_base = 0x000e0000, ram_base = 0x000a0000; + uint32_t host_base = 0x000e0000; + uint32_t ram_base = 0x000a0000; switch (port) { case 0x22: diff --git a/src/chipset/sis_85c50x.c b/src/chipset/sis_85c50x.c index f174576c9..db274a60b 100644 --- a/src/chipset/sis_85c50x.c +++ b/src/chipset/sis_85c50x.c @@ -68,7 +68,9 @@ typedef struct sis_85c50x_t { static void sis_85c50x_shadow_recalc(sis_85c50x_t *dev) { - uint32_t base, i, can_read, can_write; + uint32_t base; + uint32_t can_read; + uint32_t can_write; can_read = (dev->pci_conf[0x53] & 0x40) ? MEM_READ_INTERNAL : MEM_READ_EXTANY; can_write = (dev->pci_conf[0x53] & 0x20) ? MEM_WRITE_EXTANY : MEM_WRITE_INTERNAL; @@ -79,7 +81,7 @@ sis_85c50x_shadow_recalc(sis_85c50x_t *dev) shadowbios = 1; shadowbios_write = 1; - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { base = 0xe0000 + (i << 14); mem_set_mem_state_both(base, 0x4000, (dev->pci_conf[0x54] & (1 << (7 - i))) ? (can_read | can_write) : (MEM_READ_EXTANY | MEM_WRITE_EXTANY)); base = 0xd0000 + (i << 14); diff --git a/src/chipset/stpc.c b/src/chipset/stpc.c index 2e4b045f2..eecaa0a58 100644 --- a/src/chipset/stpc.c +++ b/src/chipset/stpc.c @@ -104,15 +104,15 @@ stpc_log(const char *fmt, ...) static void stpc_recalcmapping(stpc_t *dev) { - uint8_t reg, bitpair; - uint32_t base, size; + uint32_t base; + uint32_t size; int state; shadowbios = 0; shadowbios_write = 0; - for (reg = 0; reg <= 3; reg++) { - for (bitpair = 0; bitpair <= ((reg == 3) ? 0 : 3); bitpair++) { + for (uint8_t reg = 0; reg <= 3; reg++) { + for (uint8_t bitpair = 0; bitpair <= ((reg == 3) ? 0 : 3); bitpair++) { if (reg == 3) { size = 0x10000; base = 0xf0000; @@ -271,7 +271,8 @@ stpc_nb_read(int func, int addr, void *priv) static void stpc_ide_handlers(stpc_t *dev, int bus) { - uint16_t main, side; + uint16_t main; + uint16_t side; if (bus & 0x01) { ide_pri_disable(); @@ -607,8 +608,10 @@ stpc_serial_handlers(uint8_t val) return 0; } - uint16_t uart0_io = 0x3f8, uart1_io = 0x3f8; - uint8_t uart0_irq = 4, uart1_irq = 3; + uint16_t uart0_io = 0x3f8; + uint16_t uart1_io = 0x3f8; + uint8_t uart0_irq = 4; + uint8_t uart1_irq = 3; if (val & 0x10) uart1_io &= 0xfeff; @@ -972,7 +975,8 @@ stpc_serial_init(const device_t *info) static void stpc_lpt_handlers(stpc_lpt_t *dev, uint8_t val) { - uint8_t old_addr = (dev->reg1 & 0x03), new_addr = (val & 0x03); + uint8_t old_addr = (dev->reg1 & 0x03); + uint8_t new_addr = (val & 0x03); switch (old_addr) { case 0x1: diff --git a/src/chipset/umc_hb4.c b/src/chipset/umc_hb4.c index 40d17533b..e3174be8a 100644 --- a/src/chipset/umc_hb4.c +++ b/src/chipset/umc_hb4.c @@ -191,10 +191,10 @@ hb4_shadow_bios_low(hb4_t *dev) int hb4_shadow_main(hb4_t *dev) { - int i, state; + int state; int n = 0; - for (i = 0; i < 6; i++) { + for (uint8_t i = 0; i < 6; i++) { state = shadow_read[dev->shadow && ((dev->pci_conf[0x54] >> (i + 2)) & 0x01)] | shadow_write[(dev->pci_conf[0x55] >> 6) & 0x01]; if (state != dev->mem_state[i + 1]) { diff --git a/src/chipset/via_apollo.c b/src/chipset/via_apollo.c index 6ed6f21fe..61485fc91 100644 --- a/src/chipset/via_apollo.c +++ b/src/chipset/via_apollo.c @@ -532,7 +532,7 @@ via_apollo_host_bridge_write(int func, int addr, uint8_t val, void *priv) break; case 0x70: - if ((dev->id >= VIA_693A)) + if (dev->id >= VIA_693A) dev->pci_conf[0x70] = (dev->pci_conf[0x70] & ~0xdf) | (val & 0xdf); else if (dev->id == VIA_597) dev->pci_conf[0x70] = (dev->pci_conf[0x70] & ~0xf1) | (val & 0xf1); diff --git a/src/chipset/via_pipc.c b/src/chipset/via_pipc.c index c2abc4465..aa83c99b9 100644 --- a/src/chipset/via_pipc.c +++ b/src/chipset/via_pipc.c @@ -510,7 +510,8 @@ pipc_reset_hard(void *priv) static void pipc_ide_handlers(pipc_t *dev) { - uint16_t main, side; + uint16_t main; + uint16_t side; ide_pri_disable(); ide_sec_disable(); @@ -573,10 +574,14 @@ pipc_bus_master_handlers(pipc_t *dev) static void pipc_pcs_update(pipc_t *dev) { - uint8_t i, io_base_reg, io_mask_reg, io_mask_shift, enable; - uint16_t io_base, io_mask; + uint8_t io_base_reg; + uint8_t io_mask_reg; + uint8_t io_mask_shift; + uint8_t enable; + uint16_t io_base; + uint16_t io_mask; - for (i = 0; i <= dev->max_pcs; i++) { + for (uint8_t i = 0; i <= dev->max_pcs; i++) { if (i & 2) { io_base_reg = 0x8c; io_mask_reg = 0x8a; @@ -650,7 +655,6 @@ static void pipc_trap_update_596(void *priv) { pipc_t *dev = (pipc_t *) priv; - int i; /* TRAP_DRQ (00000001) and TRAP_PIRQ (00000002) not implemented. */ @@ -681,7 +685,7 @@ pipc_trap_update_596(void *priv) by the Positive Decoding Control registers. I couldn't probe this behavior on hardware. It's better to be safe and cover all of them than to assume Intel-like behavior (one range). */ - for (i = 0; i < 3; i++) { + for (uint8_t i = 0; i < 3; i++) { pipc_trap_update_paden(dev, TRAP_AUD_MIDI_0 + i, 0x00000400, (dev->local <= VIA_PIPC_596B) || (dev->power_regs[0x40] & 0x01), 0x300 + (0x10 * i), 4); @@ -1158,7 +1162,7 @@ pipc_write(int func, int addr, uint8_t val, void *priv) case 0x71: case 0x72: case 0x73: - dev->pci_isa_regs[(addr - 0x44)] = val; + dev->pci_isa_regs[addr - 0x44] = val; break; case 0x74: @@ -1428,7 +1432,7 @@ pipc_write(int func, int addr, uint8_t val, void *priv) case 0x61: case 0x62: case 0x63: - dev->power_regs[(addr - 0x58)] = val; + dev->power_regs[addr - 0x58] = val; break; case 0x70: diff --git a/src/chipset/via_vt82c49x.c b/src/chipset/via_vt82c49x.c index 9bd5baf13..3be28b155 100644 --- a/src/chipset/via_vt82c49x.c +++ b/src/chipset/via_vt82c49x.c @@ -65,9 +65,12 @@ vt82c49x_log(const char *fmt, ...) static void vt82c49x_recalc(vt82c49x_t *dev) { - int i, relocate; - uint8_t reg, bit; - uint32_t base, state; + int i; + int relocate; + uint8_t reg; + uint8_t bit; + uint32_t base; + uint32_t state; uint32_t shadow_bitmap = 0x00000000; relocate = (dev->regs[0x33] >> 2) & 0x03; @@ -308,9 +311,7 @@ vt82c49x_read(uint16_t addr, void *priv) static void vt82c49x_reset(void *priv) { - uint16_t i; - - for (i = 0; i < 256; i++) + for (uint16_t i = 0; i < 256; i++) vt82c49x_write(i, 0x00, priv); } diff --git a/src/chipset/via_vt82c505.c b/src/chipset/via_vt82c505.c index 76c533574..5d494d7c1 100644 --- a/src/chipset/via_vt82c505.c +++ b/src/chipset/via_vt82c505.c @@ -160,12 +160,11 @@ static void vt82c505_reset(void *priv) { vt82c505_t *dev = (vt82c505_t *) malloc(sizeof(vt82c505_t)); - int i; dev->pci_conf[0x04] = 0x07; dev->pci_conf[0x07] = 0x00; - for (i = 0x80; i <= 0x9f; i++) { + for (uint8_t i = 0x80; i <= 0x9f; i++) { switch (i) { case 0x81: vt82c505_write(0, i, 0x01, priv); diff --git a/src/chipset/vl82c480.c b/src/chipset/vl82c480.c index 9e1b9b8f7..4b9df40fa 100644 --- a/src/chipset/vl82c480.c +++ b/src/chipset/vl82c480.c @@ -61,15 +61,14 @@ vl82c480_shflags(uint8_t access) static void vl82c480_recalc(vl82c480_t *dev) { - int i, j; uint32_t base; uint8_t access; shadowbios = 0; shadowbios_write = 0; - for (i = 0; i < 6; i++) { - for (j = 0; j < 8; j += 2) { + for (uint8_t i = 0; i < 6; i++) { + for (uint8_t j = 0; j < 8; j += 2) { base = 0x000a0000 + (i << 16) + (j << 13); access = (dev->regs[0x0d + i] >> j) & 3; mem_set_mem_state(base, 0x4000, vl82c480_shflags(access)); diff --git a/src/config.c b/src/config.c index f9570442b..f7f8d1949 100644 --- a/src/config.c +++ b/src/config.c @@ -78,7 +78,10 @@ #include <86box/ui.h> #include <86box/snd_opl.h> -static int cx, cy, cw, ch; +static int cx; +static int cy; +static int cw; +static int ch; static ini_t config; /* TODO: Backwards compatibility, get rid of this when enough time has passed. */ @@ -223,7 +226,8 @@ static void load_monitor(int monitor_index) { ini_section_t cat; - char name[512], temp[512]; + char name[512]; + char temp[512]; char *p = NULL; sprintf(name, "Monitor #%i", monitor_index + 1); @@ -251,8 +255,14 @@ static void load_machine(void) { ini_section_t cat = ini_find_section(config, "Machine"); - char *p, *migrate_from = NULL; - int c, i, j, speed, legacy_mfg, legacy_cpu; + char *p; + char *migrate_from = NULL; + int c; + int i; + int j; + int speed; + int legacy_mfg; + int legacy_cpu; double multi; p = ini_section_get_string(cat, "machine", NULL); @@ -582,7 +592,8 @@ load_input_devices(void) { ini_section_t cat = ini_find_section(config, "Input devices"); char temp[512]; - int c, d; + int c; + int d; char *p; p = ini_section_get_string(cat, "mouse_type", NULL); @@ -770,7 +781,8 @@ load_network(void) ini_section_t cat = ini_find_section(config, "Network"); char *p; char temp[512]; - uint16_t c = 0, min = 0; + uint16_t c = 0; + uint16_t min = 0; /* Handle legacy configuration which supported only one NIC */ p = ini_section_get_string(cat, "net_card", NULL); @@ -875,7 +887,8 @@ load_ports(void) ini_section_t cat = ini_find_section(config, "Ports (COM & LPT)"); char *p; char temp[512]; - int c, d; + int c; + int d; memset(temp, 0, sizeof(temp)); @@ -919,8 +932,10 @@ static void load_storage_controllers(void) { ini_section_t cat = ini_find_section(config, "Storage controllers"); - char *p, temp[512]; - int c, min = 0; + char *p; + char temp[512]; + int c; + int min = 0; int free_p = 0; /* TODO: Backwards compatibility, get rid of this when enough time has passed. */ @@ -1042,15 +1057,18 @@ static void load_hard_disks(void) { ini_section_t cat = ini_find_section(config, "Hard disks"); - char temp[512], tmp2[512]; + char temp[512]; + char tmp2[512]; char s[512]; - int c; char *p; - uint32_t max_spt, max_hpc, max_tracks; - uint32_t board = 0, dev = 0; + uint32_t max_spt; + uint32_t max_hpc; + uint32_t max_tracks; + uint32_t board = 0; + uint32_t dev = 0; memset(temp, '\0', sizeof(temp)); - for (c = 0; c < HDD_NUM; c++) { + for (uint8_t c = 0; c < HDD_NUM; c++) { sprintf(temp, "hdd_%02i_parameters", c + 1); p = ini_section_get_string(cat, temp, "0, 0, 0, 0, none"); sscanf(p, "%u, %u, %u, %i, %s", @@ -1243,13 +1261,13 @@ static void load_floppy_drives(void) { ini_section_t cat = ini_find_section(config, "Floppy drives"); - char temp[512], *p; - int c; + char temp[512]; + char *p; if (!backwards_compat) return; - for (c = 0; c < FDD_NUM; c++) { + for (uint8_t c = 0; c < FDD_NUM; c++) { sprintf(temp, "fdd_%02i_type", c + 1); p = ini_section_get_string(cat, temp, (c < 2) ? "525_2dd" : "none"); fdd_set_type(c, fdd_get_from_internal_name(p)); @@ -1304,10 +1322,14 @@ static void load_floppy_and_cdrom_drives(void) { ini_section_t cat = ini_find_section(config, "Floppy and CD-ROM drives"); - char temp[512], tmp2[512], *p; + char temp[512]; + char tmp2[512]; + char *p; char s[512]; - unsigned int board = 0, dev = 0; - int c, d = 0; + unsigned int board = 0; + unsigned int dev = 0; + int c; + int d = 0; /* TODO: Backwards compatibility, get rid of this when enough time has passed. */ backwards_compat = (cat == NULL); @@ -1524,10 +1546,14 @@ static void load_other_removable_devices(void) { ini_section_t cat = ini_find_section(config, "Other removable devices"); - char temp[512], tmp2[512], *p; + char temp[512]; + char tmp2[512]; + char *p; char s[512]; - unsigned int board = 0, dev = 0; - int c, d = 0; + unsigned int board = 0; + unsigned int dev = 0; + int c; + int d = 0; /* TODO: Backwards compatibility, get rid of this when enough time has passed. */ if (backwards_compat) { @@ -1802,7 +1828,7 @@ load_other_peripherals(void) ini_section_t cat = ini_find_section(config, "Other peripherals"); char *p; char temp[512]; - int c, free_p = 0; + int free_p = 0; if (backwards_compat2) { p = ini_section_get_string(cat, "scsicard", NULL); @@ -1859,7 +1885,7 @@ load_other_peripherals(void) bugger_enabled = !!ini_section_get_int(cat, "bugger_enabled", 0); postcard_enabled = !!ini_section_get_int(cat, "postcard_enabled", 0); - for (c = 0; c < ISAMEM_MAX; c++) { + for (uint8_t c = 0; c < ISAMEM_MAX; c++) { sprintf(temp, "isamem%d_type", c); p = ini_section_get_string(cat, temp, "none"); @@ -1980,7 +2006,8 @@ static void save_general(void) { ini_section_t cat = ini_find_or_create_section(config, "General"); - char temp[512], buffer[512] = { 0 }; + char temp[512]; + char buffer[512] = { 0 }; char *va_name; @@ -2182,7 +2209,11 @@ save_machine(void) { ini_section_t cat = ini_find_or_create_section(config, "Machine"); char *p; - int c, i = 0, legacy_mfg, legacy_cpu = -1, closest_legacy_cpu = -1; + int c; + int i = 0; + int legacy_mfg; + int legacy_cpu = -1; + int closest_legacy_cpu = -1; p = machine_get_internal_name(); ini_section_set_string(cat, "machine", p); @@ -2327,8 +2358,10 @@ static void save_input_devices(void) { ini_section_t cat = ini_find_or_create_section(config, "Input devices"); - char temp[512], tmp2[512]; - int c, d; + char temp[512]; + char tmp2[512]; + int c; + int d; ini_section_set_string(cat, "mouse_type", mouse_get_internal_name(mouse_type)); @@ -2462,7 +2495,6 @@ save_sound(void) static void save_network(void) { - int c = 0; char temp[512]; ini_section_t cat = ini_find_or_create_section(config, "Network"); @@ -2470,7 +2502,7 @@ save_network(void) ini_section_delete_var(cat, "net_host_device"); ini_section_delete_var(cat, "net_card"); - for (c = 0; c < NET_CARD_MAX; c++) { + for (uint8_t c = 0; c < NET_CARD_MAX; c++) { sprintf(temp, "net_%02i_card", c + 1); if (net_cards_conf[c].device_num == 0) { ini_section_delete_var(cat, temp); @@ -2522,7 +2554,8 @@ save_ports(void) { ini_section_t cat = ini_find_or_create_section(config, "Ports (COM & LPT)"); char temp[512]; - int c, d; + int c; + int d; for (c = 0; c < SERIAL_MAX; c++) { sprintf(temp, "serial%d_enabled", c + 1); @@ -2675,7 +2708,6 @@ save_other_peripherals(void) { ini_section_t cat = ini_find_or_create_section(config, "Other peripherals"); char temp[512]; - int c; if (bugger_enabled == 0) ini_section_delete_var(cat, "bugger_enabled"); @@ -2687,7 +2719,7 @@ save_other_peripherals(void) else ini_section_set_int(cat, "postcard_enabled", postcard_enabled); - for (c = 0; c < ISAMEM_MAX; c++) { + for (uint8_t c = 0; c < ISAMEM_MAX; c++) { sprintf(temp, "isamem%d_type", c); if (isamem_type[c] == 0) ini_section_delete_var(cat, temp); @@ -2710,12 +2742,12 @@ static void save_hard_disks(void) { ini_section_t cat = ini_find_or_create_section(config, "Hard disks"); - char temp[32], tmp2[512]; + char temp[32]; + char tmp2[512]; char *p; - int c; memset(temp, 0x00, sizeof(temp)); - for (c = 0; c < HDD_NUM; c++) { + for (uint8_t c = 0; c < HDD_NUM; c++) { sprintf(temp, "hdd_%02i_parameters", c + 1); if (hdd_is_valid(c)) { p = hdd_bus_to_string(hdd[c].bus, 0); @@ -2789,7 +2821,8 @@ static void save_floppy_and_cdrom_drives(void) { ini_section_t cat = ini_find_or_create_section(config, "Floppy and CD-ROM drives"); - char temp[512], tmp2[512]; + char temp[512]; + char tmp2[512]; int c; for (c = 0; c < FDD_NUM; c++) { @@ -2925,7 +2958,8 @@ static void save_other_removable_devices(void) { ini_section_t cat = ini_find_or_create_section(config, "Other removable devices"); - char temp[512], tmp2[512]; + char temp[512]; + char tmp2[512]; int c; for (c = 0; c < ZIP_NUM; c++) { @@ -3012,10 +3046,8 @@ save_other_removable_devices(void) void config_save(void) { - int i; - save_general(); /* General */ - for (i = 0; i < MONITORS_NUM; i++) + for (uint8_t i = 0; i < MONITORS_NUM; i++) save_monitor(i); save_machine(); /* Machine */ save_video(); /* Video */ diff --git a/src/ddma.c b/src/ddma.c index 7904163da..7623dc0df 100644 --- a/src/ddma.c +++ b/src/ddma.c @@ -91,7 +91,7 @@ ddma_reg_write(uint16_t addr, uint8_t val, void *p) ddma_channel_t *dev = (ddma_channel_t *) p; int ch = dev->channel; int page_regs[4] = { 7, 3, 1, 2 }; - int i, dmab = (ch >= 4) ? 0xc0 : 0x00; + int dmab = (ch >= 4) ? 0xc0 : 0x00; switch (addr & 0x0f) { case 0x00: @@ -132,7 +132,7 @@ ddma_reg_write(uint16_t addr, uint8_t val, void *p) outb(dmab + 0x0d, val); break; case 0x0e: - for (i = 0; i < 4; i++) + for (uint8_t i = 0; i < 4; i++) outb(dmab + 0x0a, i); break; case 0x0f: @@ -166,14 +166,13 @@ static void * ddma_init(const device_t *info) { ddma_t *dev; - int i; dev = (ddma_t *) malloc(sizeof(ddma_t)); if (dev == NULL) return (NULL); memset(dev, 0x00, sizeof(ddma_t)); - for (i = 0; i < 8; i++) + for (uint8_t i = 0; i < 8; i++) dev->channels[i].channel = i; return dev; diff --git a/src/device.c b/src/device.c index d0b502ca1..8c8ede245 100644 --- a/src/device.c +++ b/src/device.c @@ -59,7 +59,8 @@ static device_t *devices[DEVICE_MAX]; static void *device_priv[DEVICE_MAX]; -static device_context_t device_current, device_prev; +static device_context_t device_current; +static device_context_t device_prev; #ifdef ENABLE_DEVICE_LOG int device_do_log = ENABLE_DEVICE_LOG; @@ -89,7 +90,8 @@ device_init(void) void device_set_context(device_context_t *c, const device_t *d, int inst) { - void *sec, *single_sec; + void *sec; + void *single_sec; memset(c, 0, sizeof(device_context_t)); c->dev = d; @@ -184,7 +186,7 @@ device_add_common(const device_t *d, const device_t *cd, void *p, void *params, } else device_priv[c] = p; - return (priv); + return priv; } char * @@ -301,9 +303,7 @@ device_cadd_inst_ex_parameters(const device_t *d, const device_t *cd, void *priv void device_close_all(void) { - int c; - - for (c = (DEVICE_MAX - 1); c >= 0; c--) { + for (int16_t c = (DEVICE_MAX - 1); c >= 0; c--) { if (devices[c] != NULL) { if (devices[c]->name) device_log("Closing device: \"%s\"...\n", devices[c]->name); @@ -317,9 +317,7 @@ device_close_all(void) void device_reset_all(uint32_t match_flags) { - int c; - - for (c = 0; c < DEVICE_MAX; c++) { + for (uint16_t c = 0; c < DEVICE_MAX; c++) { if (devices[c] != NULL) { if ((devices[c]->reset != NULL) && (devices[c]->flags & match_flags)) devices[c]->reset(device_priv[c]); @@ -330,9 +328,7 @@ device_reset_all(uint32_t match_flags) void * device_get_priv(const device_t *d) { - int c; - - for (c = 0; c < DEVICE_MAX; c++) { + for (uint16_t c = 0; c < DEVICE_MAX; c++) { if (devices[c] != NULL) { if (devices[c] == d) return (device_priv[c]); @@ -347,7 +343,7 @@ device_available(const device_t *d) { device_config_t *config = NULL; device_config_bios_t *bios = NULL; - int bf, roms_present = 0; + int roms_present = 0; int i = 0; if (d != NULL) { @@ -360,7 +356,7 @@ device_available(const device_t *d) /* Go through the ROM's in the device configuration. */ while (bios->files_no != 0) { i = 0; - for (bf = 0; bf < bios->files_no; bf++) + for (int bf = 0; bf < bios->files_no; bf++) i += !!rom_present((char *) bios->files[bf]); if (i == bios->files_no) roms_present++; @@ -377,11 +373,11 @@ device_available(const device_t *d) if (d->available != NULL) return (d->available()); else - return (1); + return 1; } /* A NULL device is never available. */ - return (0); + return 0; } const char * @@ -443,9 +439,7 @@ device_has_config(const device_t *d) int device_poll(const device_t *d, int x, int y, int z, int b) { - int c; - - for (c = 0; c < DEVICE_MAX; c++) { + for (uint16_t c = 0; c < DEVICE_MAX; c++) { if (devices[c] != NULL) { if (devices[c] == d) { if (devices[c]->poll) @@ -454,15 +448,13 @@ device_poll(const device_t *d, int x, int y, int z, int b) } } - return (0); + return 0; } void device_register_pci_slot(const device_t *d, int device, int type, int inta, int intb, int intc, int intd) { - int c; - - for (c = 0; c < DEVICE_MAX; c++) { + for (uint16_t c = 0; c < DEVICE_MAX; c++) { if (devices[c] != NULL) { if (devices[c] == d) { if (devices[c]->register_pci_slot) @@ -478,8 +470,10 @@ device_register_pci_slot(const device_t *d, int device, int type, int inta, int void device_get_name(const device_t *d, int bus, char *name) { - char *sbus = NULL, *fbus; - char *tname, pbus[8] = { 0 }; + char *sbus = NULL; + char *fbus; + char *tname; + char pbus[8] = { 0 }; if (d == NULL) return; @@ -568,9 +562,7 @@ device_get_name(const device_t *d, int bus, char *name) void device_speed_changed(void) { - int c; - - for (c = 0; c < DEVICE_MAX; c++) { + for (uint16_t c = 0; c < DEVICE_MAX; c++) { if (devices[c] != NULL) { if (devices[c]->speed_changed != NULL) devices[c]->speed_changed(device_priv[c]); @@ -583,9 +575,7 @@ device_speed_changed(void) void device_force_redraw(void) { - int c; - - for (c = 0; c < DEVICE_MAX; c++) { + for (uint16_t c = 0; c < DEVICE_MAX; c++) { if (devices[c] != NULL) { if (devices[c]->force_redraw != NULL) devices[c]->force_redraw(device_priv[c]); @@ -626,7 +616,7 @@ device_get_config_int(const char *s) c++; } - return (0); + return 0; } int @@ -641,7 +631,7 @@ device_get_config_int_ex(const char *s, int def) c++; } - return (def); + return def; } int @@ -656,7 +646,7 @@ device_get_config_hex16(const char *s) c++; } - return (0); + return 0; } int @@ -671,7 +661,7 @@ device_get_config_hex20(const char *s) c++; } - return (0); + return 0; } int @@ -686,7 +676,7 @@ device_get_config_mac(const char *s, int def) c++; } - return (def); + return def; } void @@ -753,39 +743,39 @@ int device_is_valid(const device_t *device, int m) { if (device == NULL) - return (1); + return 1; if ((device->flags & DEVICE_AT) && !machine_has_bus(m, MACHINE_BUS_ISA16)) - return (0); + return 0; if ((device->flags & DEVICE_CBUS) && !machine_has_bus(m, MACHINE_BUS_CBUS)) - return (0); + return 0; if ((device->flags & DEVICE_ISA) && !machine_has_bus(m, MACHINE_BUS_ISA)) - return (0); + return 0; if ((device->flags & DEVICE_MCA) && !machine_has_bus(m, MACHINE_BUS_MCA)) - return (0); + return 0; if ((device->flags & DEVICE_EISA) && !machine_has_bus(m, MACHINE_BUS_EISA)) - return (0); + return 0; if ((device->flags & DEVICE_VLB) && !machine_has_bus(m, MACHINE_BUS_VLB)) - return (0); + return 0; if ((device->flags & DEVICE_PCI) && !machine_has_bus(m, MACHINE_BUS_PCI)) - return (0); + return 0; if ((device->flags & DEVICE_AGP) && !machine_has_bus(m, MACHINE_BUS_AGP)) - return (0); + return 0; if ((device->flags & DEVICE_PS2) && !machine_has_bus(m, MACHINE_BUS_PS2)) - return (0); + return 0; if ((device->flags & DEVICE_AC97) && !machine_has_bus(m, MACHINE_BUS_AC97)) - return (0); + return 0; - return (1); + return 1; } int @@ -795,7 +785,7 @@ machine_get_config_int(char *s) const device_config_t *c; if (d == NULL) - return (0); + return 0; c = d->config; while (c && c->type != -1) { @@ -805,7 +795,7 @@ machine_get_config_int(char *s) c++; } - return (0); + return 0; } char * @@ -815,7 +805,7 @@ machine_get_config_string(char *s) const device_config_t *c; if (d == NULL) - return (0); + return 0; c = d->config; while (c && c->type != -1) { @@ -825,5 +815,5 @@ machine_get_config_string(char *s) c++; } - return (NULL); + return NULL; } diff --git a/src/device/bugger.c b/src/device/bugger.c index 920fc4cef..05df6530e 100644 --- a/src/device/bugger.c +++ b/src/device/bugger.c @@ -74,14 +74,16 @@ #define CTRL_RESET 0xff /* this resets the board */ #define BUG_DATA 1 -static uint8_t bug_ctrl, /* control register */ - bug_data, /* data register */ - bug_ledr, bug_ledg, /* RED and GREEN LEDs */ - bug_seg1, bug_seg2, /* LEFT and RIGHT 7SEG displays */ - bug_spcfg; /* serial port configuration */ +static uint8_t bug_ctrl; /* control register */ +static uint8_t bug_data; /* data register */ +static uint8_t bug_ledr; /* RED LEDs */ +static uint8_t bug_ledg; /* GREEN LEDs */ +static uint8_t bug_seg1; +static uint8_t bug_seg2; /* LEFT and RIGHT 7SEG displays */ +static uint8_t bug_spcfg; /* serial port configuration */ #define FIFO_LEN 256 -static uint8_t bug_buff[FIFO_LEN], /* serial port data buffer */ - *bug_bptr; +static uint8_t bug_buff[FIFO_LEN]; /* serial port data buffer */ +static uint8_t *bug_bptr; #define UISTR_LEN 24 static char bug_str[UISTR_LEN]; /* UI output string */ @@ -312,7 +314,7 @@ bug_read(uint16_t port, void *priv) break; } - return (ret); + return ret; } /* Initialize the ISA BusBugger emulator. */ diff --git a/src/device/cartridge.c b/src/device/cartridge.c index 943ca2cb9..6f8424f70 100644 --- a/src/device/cartridge.c +++ b/src/device/cartridge.c @@ -175,15 +175,13 @@ cart_close(int drive) void cart_reset(void) { - int i; - cart_image_close(1); cart_image_close(0); if (!machine_has_cartridge(machine)) return; - for (i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 2; i++) { mem_mapping_add(&cart_mappings[i], 0x000d0000, 0x00002000, cart_read, NULL, NULL, NULL, NULL, NULL, diff --git a/src/device/cassette.c b/src/device/cassette.c index 8d8f15c80..4582e0751 100644 --- a/src/device/cassette.c +++ b/src/device/cassette.c @@ -45,9 +45,11 @@ pc_cassette_t *cassette; char cassette_fname[512]; char cassette_mode[512]; -unsigned long cassette_pos, cassette_srate; +unsigned long cassette_pos; +unsigned long cassette_srate; int cassette_enable; -int cassette_append, cassette_pcm; +int cassette_append; +int cassette_pcm; int cassette_ui_writeprot; static int cassette_cycles = -1; @@ -138,7 +140,7 @@ pc_cas_new(void) pc_cas_init(cas); - return (cas); + return cas; } void @@ -172,7 +174,7 @@ pc_cas_set_fname(pc_cassette_t *cas, const char *fname) if (fname == NULL) { ui_sb_update_icon_state(SB_CASSETTE, 1); - return (0); + return 0; } cas->fp = plat_fopen(fname, "r+b"); @@ -182,7 +184,7 @@ pc_cas_set_fname(pc_cassette_t *cas, const char *fname) if (cas->fp == NULL) { ui_sb_update_icon_state(SB_CASSETTE, 1); - return (1); + return 1; } cas->close = 1; @@ -215,14 +217,12 @@ pc_cas_set_fname(pc_cassette_t *cas, const char *fname) pc_cas_set_pcm(cas, 0); } - return (0); + return 0; } static void pc_cas_reset(pc_cassette_t *cas) { - unsigned i; - cas->clk_pcm = 0; cas->clk_out = cas->clk; @@ -237,7 +237,7 @@ pc_cas_reset(pc_cassette_t *cas) cas->cas_inp_buf = 0; cas->cas_inp_bit = 0; - for (i = 0; i < 3; i++) { + for (uint8_t i = 0; i < 3; i++) { cas->pcm_inp_fir[i] = 0; } } @@ -344,18 +344,18 @@ int pc_cas_set_position(pc_cassette_t *cas, unsigned long pos) { if (cas->fp == NULL) { - return (1); + return 1; } if (fseek(cas->fp, pos, SEEK_SET) != 0) { - return (1); + return 1; } cas->position = pos; pc_cas_reset(cas); - return (0); + return 0; } static void @@ -394,17 +394,18 @@ pc_cas_read_bit(pc_cassette_t *cas) static int pc_cas_read_smp(pc_cassette_t *cas) { - int smp, *fir; + int smp; + int *fir; if (feof(cas->fp)) { - return (0); + return 0; } smp = fgetc(cas->fp); if (smp == EOF) { cassette_log("cassette EOF at %lu\n", cas->position); - return (0); + return 0; } cas->position += 1; @@ -417,7 +418,7 @@ pc_cas_read_smp(pc_cassette_t *cas) smp = (fir[0] + 2 * fir[1] + fir[2]) / 4; - return (smp); + return smp; } static void @@ -461,8 +462,6 @@ pc_cas_write_smp(pc_cassette_t *cas, int val) void pc_cas_set_motor(pc_cassette_t *cas, unsigned char val) { - unsigned i; - val = (val != 0); if (val == cas->motor) { @@ -470,7 +469,7 @@ pc_cas_set_motor(pc_cassette_t *cas, unsigned char val) } if ((val == 0) && cas->save && cas->pcm) { - for (i = 0; i < (cas->srate / 16); i++) { + for (unsigned long i = 0; i < (cas->srate / 16); i++) { pc_cas_write_smp(cas, 0); } } @@ -553,7 +552,8 @@ pc_cas_print_state(const pc_cassette_t *cas) static void pc_cas_clock_pcm(pc_cassette_t *cas, unsigned long cnt) { - unsigned long i, n; + unsigned long i; + unsigned long n; int v = 0; n = cas->srate * cnt + cas->clk_pcm; diff --git a/src/device/clock_ics9xxx.c b/src/device/clock_ics9xxx.c index 7b04c5688..0fedfaef7 100644 --- a/src/device/clock_ics9xxx.c +++ b/src/device/clock_ics9xxx.c @@ -1147,7 +1147,8 @@ static uint8_t ics9xxx_find_bus_match(ics9xxx_t *dev, uint32_t bus, uint8_t preset_mask, uint8_t preset) { uint8_t best_match = 0; - uint32_t delta, best_delta = -1; + uint32_t delta; + uint32_t best_delta = -1; #ifdef ENABLE_ICS9xxx_DETECT if (dev->model_idx == ICS9xxx_xx) diff --git a/src/device/hwm_lm78.c b/src/device/hwm_lm78.c index f7585945a..9455a2ebd 100644 --- a/src/device/hwm_lm78.c +++ b/src/device/hwm_lm78.c @@ -328,7 +328,9 @@ lm78_i2c_start(void *bus, uint8_t addr, uint8_t read, void *priv) static uint8_t lm78_read(lm78_t *dev, uint8_t reg, uint8_t bank) { - uint8_t ret = 0, masked_reg = reg, bankswitched = ((reg & 0xf8) == 0x50); + uint8_t ret = 0; + uint8_t masked_reg = reg; + uint8_t bankswitched = ((reg & 0xf8) == 0x50); lm75_t *lm75; if ((dev->local & LM78_AS99127F) && (bank == 3) && (reg != 0x4e)) { diff --git a/src/device/i2c.c b/src/device/i2c.c index 17e795e74..7937aa10d 100644 --- a/src/device/i2c.c +++ b/src/device/i2c.c @@ -77,14 +77,14 @@ i2c_addbus(char *name) void i2c_removebus(void *bus_handle) { - int c; - i2c_t *p, *q; + i2c_t *p; + i2c_t *q; i2c_bus_t *bus = (i2c_bus_t *) bus_handle; if (!bus_handle) return; - for (c = 0; c < NADDRS; c++) { + for (uint8_t c = 0; c < NADDRS; c++) { p = bus->devices[c]; if (!p) continue; @@ -117,14 +117,14 @@ i2c_sethandler(void *bus_handle, uint8_t base, int size, void (*stop)(void *bus, uint8_t addr, void *priv), void *priv) { - int c; - i2c_t *p, *q = NULL; + i2c_t *p; + i2c_t *q = NULL; i2c_bus_t *bus = (i2c_bus_t *) bus_handle; if (!bus_handle || ((base + size) > NADDRS)) return; - for (c = 0; c < size; c++) { + for (int c = 0; c < size; c++) { p = bus->last[base + c]; q = (i2c_t *) malloc(sizeof(i2c_t)); memset(q, 0, sizeof(i2c_t)); @@ -156,14 +156,14 @@ i2c_removehandler(void *bus_handle, uint8_t base, int size, void (*stop)(void *bus, uint8_t addr, void *priv), void *priv) { - int c; - i2c_t *p, *q; + i2c_t *p; + i2c_t *q; i2c_bus_t *bus = (i2c_bus_t *) bus_handle; if (!bus_handle || ((base + size) > NADDRS)) return; - for (c = 0; c < size; c++) { + for (int c = 0; c < size; c++) { p = bus->devices[base + c]; if (!p) continue; @@ -209,7 +209,7 @@ i2c_start(void *bus_handle, uint8_t addr, uint8_t read) i2c_t *p; if (!bus) - return (ret); + return ret; p = bus->devices[addr]; if (p) { @@ -223,7 +223,7 @@ i2c_start(void *bus_handle, uint8_t addr, uint8_t read) i2c_log("I2C %s: start(%02X) = %d\n", bus->name, addr, ret); - return (ret); + return ret; } uint8_t @@ -234,7 +234,7 @@ i2c_read(void *bus_handle, uint8_t addr) i2c_t *p; if (!bus) - return (ret); + return ret; p = bus->devices[addr]; if (p) { @@ -249,7 +249,7 @@ i2c_read(void *bus_handle, uint8_t addr) i2c_log("I2C %s: read(%02X) = %02X\n", bus->name, addr, ret); - return (ret); + return ret; } uint8_t @@ -260,7 +260,7 @@ i2c_write(void *bus_handle, uint8_t addr, uint8_t data) i2c_bus_t *bus = (i2c_bus_t *) bus_handle; if (!bus) - return (ret); + return ret; p = bus->devices[addr]; if (p) { @@ -274,7 +274,7 @@ i2c_write(void *bus_handle, uint8_t addr, uint8_t data) i2c_log("I2C %s: write(%02X, %02X) = %d\n", bus->name, addr, data, ret); - return (ret); + return ret; } void diff --git a/src/device/isamem.c b/src/device/isamem.c index 52327ad2c..708274fca 100644 --- a/src/device/isamem.c +++ b/src/device/isamem.c @@ -186,7 +186,7 @@ ram_readb(uint32_t addr, void *priv) /* Grab the data. */ ret = *(uint8_t *) (dev->ptr + (addr - dev->base)); - return (ret); + return ret; } /* Read one word from onboard RAM. */ @@ -199,7 +199,7 @@ ram_readw(uint32_t addr, void *priv) /* Grab the data. */ ret = *(uint16_t *) (dev->ptr + (addr - dev->base)); - return (ret); + return ret; } /* Write one byte to onboard RAM. */ @@ -230,13 +230,13 @@ ems_readb(uint32_t addr, void *priv) uint8_t ret = 0xff; /* Grab the data. */ - ret = *(uint8_t *) (dev->ems[((addr & 0xffff) >> 14)].addr + (addr & 0x3fff)); + ret = *(uint8_t *) (dev->ems[(addr & 0xffff) >> 14].addr + (addr & 0x3fff)); #if ISAMEM_DEBUG if ((addr % 4096) == 0) isamem_log("EMS readb(%06x) = %02x\n", addr - dev & 0x3fff, ret); #endif - return (ret); + return ret; } /* Read one word from onboard paged RAM. */ @@ -247,13 +247,13 @@ ems_readw(uint32_t addr, void *priv) uint16_t ret = 0xffff; /* Grab the data. */ - ret = *(uint16_t *) (dev->ems[((addr & 0xffff) >> 14)].addr + (addr & 0x3fff)); + ret = *(uint16_t *) (dev->ems[(addr & 0xffff) >> 14].addr + (addr & 0x3fff)); #if ISAMEM_DEBUG if ((addr % 4096) == 0) isamem_log("EMS readw(%06x) = %04x\n", addr - dev & 0x3fff, ret); #endif - return (ret); + return ret; } /* Write one byte to onboard paged RAM. */ @@ -267,7 +267,7 @@ ems_writeb(uint32_t addr, uint8_t val, void *priv) if ((addr % 4096) == 0) isamem_log("EMS writeb(%06x, %02x)\n", addr - dev & 0x3fff, val); #endif - *(uint8_t *) (dev->ems[((addr & 0xffff) >> 14)].addr + (addr & 0x3fff)) = val; + *(uint8_t *) (dev->ems[(addr & 0xffff) >> 14].addr + (addr & 0x3fff)) = val; } /* Write one word to onboard paged RAM. */ @@ -281,7 +281,7 @@ ems_writew(uint32_t addr, uint16_t val, void *priv) if ((addr % 4096) == 0) isamem_log("EMS writew(%06x, %04x)\n", addr & 0x3fff, val); #endif - *(uint16_t *) (dev->ems[((addr & 0xffff) >> 14)].addr + (addr & 0x3fff)) = val; + *(uint16_t *) (dev->ems[(addr & 0xffff) >> 14].addr + (addr & 0x3fff)) = val; } /* Handle a READ operation from one of our registers. */ @@ -311,7 +311,7 @@ ems_read(uint16_t port, void *priv) isamem_log("ISAMEM: read(%04x) = %02x)\n", port, ret); #endif - return (ret); + return ret; } /* Handle a WRITE operation to one of our registers. */ @@ -391,11 +391,11 @@ static void * isamem_init(const device_t *info) { memdev_t *dev; - uint32_t k, t; + uint32_t k; + uint32_t t; uint32_t addr; uint32_t tot; uint8_t *ptr; - int i; /* Find our device and create an instance. */ dev = (memdev_t *) malloc(sizeof(memdev_t)); @@ -624,7 +624,7 @@ isamem_init(const device_t *info) * create, initialize and disable the mappings, and set * up the I/O control handler. */ - for (i = 0; i < EMS_MAXPAGE; i++) { + for (uint8_t i = 0; i < EMS_MAXPAGE; i++) { /* Create and initialize a page mapping. */ mem_mapping_add(&dev->ems[i].mapping, dev->frame_addr + (EMS_PGSIZE * i), EMS_PGSIZE, @@ -655,10 +655,9 @@ static void isamem_close(void *priv) { memdev_t *dev = (memdev_t *) priv; - int i; if (dev->flags & FLAG_EMS) { - for (i = 0; i < EMS_MAXPAGE; i++) { + for (uint8_t i = 0; i < EMS_MAXPAGE; i++) { io_removehandler(dev->base_addr + (EMS_PGSIZE * i), 2, ems_read, NULL, NULL, ems_write, NULL, NULL, dev); } @@ -1566,12 +1565,12 @@ static const struct { void isamem_reset(void) { - int k, i; + int k; /* We explicitly set to zero here or bad things happen */ isa_mem_size = 0; - for (i = 0; i < ISAMEM_MAX; i++) { + for (uint8_t i = 0; i < ISAMEM_MAX; i++) { k = isamem_type[i]; if (k == 0) continue; @@ -1603,12 +1602,12 @@ isamem_get_from_internal_name(const char *s) while (boards[c].dev != NULL) { if (!strcmp(boards[c].dev->internal_name, s)) - return (c); + return c; c++; } /* Not found. */ - return (0); + return 0; } const device_t * diff --git a/src/device/isapnp.c b/src/device/isapnp.c index 69d5e26ab..fcf6053ae 100644 --- a/src/device/isapnp.c +++ b/src/device/isapnp.c @@ -121,7 +121,8 @@ isapnp_device_config_changed(isapnp_card_t *card, isapnp_device_t *ld) /* Populate config structure, performing endianness conversion as needed. */ card->config.activate = ld->regs[0x30] & 0x01; - uint8_t i, reg_base; + uint8_t i; + uint8_t reg_base; for (i = 0; i < 4; i++) { reg_base = 0x40 + (8 * i); card->config.mem[i].base = (ld->regs[reg_base] << 16) | (ld->regs[reg_base + 1] << 8); @@ -168,7 +169,8 @@ isapnp_reset_ld_config(isapnp_device_t *ld) /* Populate configuration registers. */ ld->regs[0x30] = !!config->activate; - uint8_t i, reg_base; + uint8_t i; + uint8_t reg_base; uint32_t size; for (i = 0; i < 4; i++) { reg_base = 0x40 + (8 * i); @@ -253,7 +255,9 @@ static uint8_t isapnp_read_data(uint16_t addr, void *priv) { isapnp_t *dev = (isapnp_t *) priv; - uint8_t ret = 0xff, bit, next_shift; + uint8_t ret = 0xff; + uint8_t bit; + uint8_t next_shift; isapnp_card_t *card; switch (dev->reg) { @@ -450,7 +454,8 @@ isapnp_write_data(uint16_t addr, uint8_t val, void *priv) isapnp_t *dev = (isapnp_t *) priv; isapnp_card_t *card; isapnp_device_t *ld; - uint16_t io_addr, reset_cards = 0; + uint16_t io_addr; + uint16_t reset_cards = 0; isapnp_log("ISAPnP: write_data(%02X)\n", val); @@ -701,8 +706,10 @@ static void isapnp_close(void *priv) { isapnp_t *dev = (isapnp_t *) priv; - isapnp_card_t *card = dev->first_card, *next_card; - isapnp_device_t *ld, *next_ld; + isapnp_card_t *card = dev->first_card; + isapnp_card_t *next_card; + isapnp_device_t *ld; + isapnp_device_t *next_ld; while (card) { ld = card->first_ld; @@ -773,11 +780,22 @@ isapnp_update_card_rom(void *priv, uint8_t *rom, uint16_t rom_size) uint16_t vendor = (card->rom[0] << 8) | card->rom[1]; isapnp_log("ISAPnP: Parsing ROM resources for card %c%c%c%02X%02X (serial %08X)\n", '@' + ((vendor >> 10) & 0x1f), '@' + ((vendor >> 5) & 0x1f), '@' + (vendor & 0x1f), card->rom[2], card->rom[3], (card->rom[7] << 24) | (card->rom[6] << 16) | (card->rom[5] << 8) | card->rom[4]); #endif - uint16_t i = 9, j; - uint8_t existing = 0, ldn = 0, res, in_df = 0; - uint8_t irq = 0, io = 0, mem_range = 0, mem_range_32 = 0, irq_df = 0, io_df = 0, mem_range_df = 0, mem_range_32_df = 0; + uint16_t i = 9; + uint8_t existing = 0; + uint8_t ldn = 0; + uint8_t res; + uint8_t in_df = 0; + uint8_t irq = 0; + uint8_t io = 0; + uint8_t mem_range = 0; + uint8_t mem_range_32 = 0; + uint8_t irq_df = 0; + uint8_t io_df = 0; + uint8_t mem_range_df = 0; + uint8_t mem_range_32_df = 0; uint32_t len; - isapnp_device_t *ld = NULL, *prev_ld = NULL; + isapnp_device_t *ld = NULL; + isapnp_device_t *prev_ld = NULL; /* Check if this is an existing card which already has logical devices. Any new logical devices will be added to the list after existing ones. @@ -994,7 +1012,7 @@ isapnp_update_card_rom(void *priv, uint8_t *rom, uint16_t rom_size) case 0x0f: /* end tag */ /* Calculate checksum. */ res = 0x00; - for (j = 9; j <= i; j++) + for (uint16_t j = 9; j <= i; j++) res += card->rom[j]; card->rom[i + 1] = -res; diff --git a/src/device/isartc.c b/src/device/isartc.c index e8f097c08..7c12ae032 100644 --- a/src/device/isartc.c +++ b/src/device/isartc.c @@ -193,7 +193,9 @@ mm67_tick(nvr_t *nvr) { rtcdev_t *dev = (rtcdev_t *) nvr->data; uint8_t *regs = nvr->regs; - int mon, year, f = 0; + int mon; + int year; + int f = 0; /* Update and set interrupt if needed. */ regs[MM67_SEC] = RTC_BCDINC(nvr->regs[MM67_SEC], 1); @@ -372,10 +374,8 @@ mm67_start(nvr_t *nvr) static void mm67_reset(nvr_t *nvr) { - int i; - /* Initialize the RTC to a known state. */ - for (i = MM67_MSEC; i <= MM67_MON; i++) + for (uint8_t i = MM67_MSEC; i <= MM67_MON; i++) nvr->regs[i] = RTC_BCD(0); nvr->regs[MM67_DOW] = RTC_BCD(1); nvr->regs[MM67_DOM] = RTC_BCD(1); @@ -410,7 +410,7 @@ mm67_read(uint16_t port, void *priv) isartc_log("ISARTC: read(%04x) = %02x\n", port - dev->base_addr, ret); #endif - return (ret); + return ret; } /* Handle a WRITE operation to one of our registers. */ @@ -790,12 +790,12 @@ isartc_get_from_internal_name(char *s) while (boards[c].dev != NULL) { if (!strcmp(boards[c].dev->internal_name, s)) - return (c); + return c; c++; } /* Not found. */ - return (0); + return 0; } const device_t * diff --git a/src/device/kbc_at.c b/src/device/kbc_at.c index 08c849c85..5395f3ac2 100644 --- a/src/device/kbc_at.c +++ b/src/device/kbc_at.c @@ -795,7 +795,8 @@ static uint8_t write64_generic(void *priv, uint8_t val) { atkbc_t *dev = (atkbc_t *) priv; - uint8_t current_drive, fixed_bits; + uint8_t current_drive; + uint8_t fixed_bits; uint8_t kbc_ven = 0x0; kbc_ven = dev->flags & KBC_VEN_MASK; @@ -1276,7 +1277,7 @@ write64_olivetti(void *priv, uint8_t val) * bit 2: keyboard fuse present * bits 0-1: ??? */ - kbc_delay_to_ob(dev, (0x0c | ((is386) ? 0x00 : 0x80)) & 0xdf, 0, 0x00); + kbc_delay_to_ob(dev, (0x0c | (is386 ? 0x00 : 0x80)) & 0xdf, 0, 0x00); dev->p1 = ((dev->p1 + 1) & 3) | (dev->p1 & 0xfc); return 0; } @@ -1413,8 +1414,9 @@ static void kbc_at_process_cmd(void *priv) { atkbc_t *dev = (atkbc_t *) priv; - int i = 0, bad = 1; - uint8_t mask, kbc_ven = dev->flags & KBC_VEN_MASK; + int bad = 1; + uint8_t mask; + uint8_t kbc_ven = dev->flags & KBC_VEN_MASK; uint8_t cmd_ac_conv[16] = { 0x0b, 2, 3, 4, 5, 6, 7, 8, 9, 0x0a, 0x1e, 0x30, 0x2e, 0x20, 0x12, 0x21 }; if (dev->status & STAT_CD) { @@ -1508,7 +1510,7 @@ kbc_at_process_cmd(void *priv) dev->mem[0x32] = 0x00; /* T0 and T1. */ dev->mem[0x33] = 0x00; /* PSW - Program Status Word - always return 0x00 because we do not emulate this byte. */ /* 20 bytes in high nibble in set 1, low nibble in set 1, set 1 space format = 60 bytes. */ - for (i = 0; i < 20; i++) { + for (uint8_t i = 0; i < 20; i++) { kbc_at_queue_add(dev, cmd_ac_conv[dev->mem[i + 0x20] >> 4]); kbc_at_queue_add(dev, cmd_ac_conv[dev->mem[i + 0x20] & 0x0f]); kbc_at_queue_add(dev, 0x39); @@ -1760,7 +1762,7 @@ kbc_at_read(uint16_t port, void *priv) kbc_at_log("ATkbc: [%04X:%08X] read (%04X) = %02X\n", CS, cpu_state.pc, port, ret); - return (ret); + return ret; } static void @@ -1816,14 +1818,14 @@ static void kbc_at_close(void *priv) { atkbc_t *dev = (atkbc_t *) priv; - int i, max_ports = ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_1) ? 2 : 1; + int max_ports = ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_1) ? 2 : 1; kbc_at_reset(dev); /* Stop timers. */ timer_disable(&dev->send_delay_timer); - for (i = 0; i < max_ports; i++) { + for (int i = 0; i < max_ports; i++) { if (kbc_at_ports[i] != NULL) { free(kbc_at_ports[i]); kbc_at_ports[i] = NULL; @@ -1837,7 +1839,7 @@ static void * kbc_at_init(const device_t *info) { atkbc_t *dev; - int i, max_ports; + int max_ports; dev = (atkbc_t *) malloc(sizeof(atkbc_t)); memset(dev, 0x00, sizeof(atkbc_t)); @@ -1924,7 +1926,7 @@ kbc_at_init(const device_t *info) max_ports = ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_1) ? 2 : 1; - for (i = 0; i < max_ports; i++) { + for (int i = 0; i < max_ports; i++) { kbc_at_ports[i] = (kbc_at_port_t *) malloc(sizeof(kbc_at_port_t)); memset(kbc_at_ports[i], 0x00, sizeof(kbc_at_port_t)); kbc_at_ports[i]->out_new = -1; @@ -1936,7 +1938,7 @@ kbc_at_init(const device_t *info) /* The actual keyboard. */ device_add(&keyboard_at_generic_device); - return (dev); + return dev; } const device_t keyboard_at_device = { diff --git a/src/device/kbc_at_dev.c b/src/device/kbc_at_dev.c index 976b9e740..2715f94fa 100644 --- a/src/device/kbc_at_dev.c +++ b/src/device/kbc_at_dev.c @@ -207,5 +207,5 @@ kbc_at_dev_init(uint8_t inst) } /* Return our private data to the I/O layer. */ - return (dev); + return dev; } diff --git a/src/device/keyboard_at.c b/src/device/keyboard_at.c index 6129f206d..516303137 100644 --- a/src/device/keyboard_at.c +++ b/src/device/keyboard_at.c @@ -509,9 +509,7 @@ keyboard_at_set_scancode_set(void) static void add_data_vals(atkbc_dev_t *dev, uint8_t *val, uint8_t len) { - int i; - - for (i = 0; i < len; i++) + for (uint8_t i = 0; i < len; i++) kbc_at_dev_queue_add(dev, val[i], 1); } @@ -520,7 +518,8 @@ add_data_kbd(uint16_t val) { atkbc_dev_t *dev = SavedKbd; uint8_t fake_shift[4]; - uint8_t num_lock = 0, shift_states = 0; + uint8_t num_lock = 0; + uint8_t shift_states = 0; keyboard_get_states(NULL, &num_lock, NULL); shift_states = keyboard_get_shift() & STATE_SHIFT_MASK; @@ -722,7 +721,7 @@ static void keyboard_at_write(void *priv) { atkbc_dev_t *dev = (atkbc_dev_t *) priv; - uint8_t i, val; + uint8_t val; if (dev->port == NULL) return; @@ -826,7 +825,7 @@ keyboard_at_write(void *priv) /* TODO: After keyboard type selection is implemented, make this return the correct keyboard ID for the selected type. */ kbc_at_dev_queue_add(dev, 0xfa, 0); - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { if (id_bytes[dev->type][i] == 0) break; @@ -973,7 +972,7 @@ keyboard_at_init(const device_t *info) inv_cmd_response = (dev->type & FLAG_PS2) ? 0xfe : 0xfa; /* Return our private data to the I/O layer. */ - return (dev); + return dev; } static void diff --git a/src/device/keyboard_xt.c b/src/device/keyboard_xt.c index fe523cd2f..bdc1cc51b 100644 --- a/src/device/keyboard_xt.c +++ b/src/device/keyboard_xt.c @@ -343,10 +343,11 @@ const scancode scancode_xt[512] = { }; static uint8_t key_queue[16]; -static int key_queue_start = 0, - key_queue_end = 0; -static int is_tandy = 0, is_t1x00 = 0, - is_amstrad = 0; +static int key_queue_start = 0; +static int key_queue_end = 0; +static int is_tandy = 0; +static int is_t1x00 = 0; +static int is_amstrad = 0; #ifdef ENABLE_KEYBOARD_XT_LOG int keyboard_xt_do_log = ENABLE_KEYBOARD_XT_LOG; @@ -370,9 +371,9 @@ static uint8_t get_fdd_switch_settings(void) { - int i, fdd_count = 0; + uint8_t fdd_count = 0; - for (i = 0; i < FDD_NUM; i++) { + for (uint8_t i = 0; i < FDD_NUM; i++) { if (fdd_get_flags(i)) fdd_count++; } @@ -467,7 +468,8 @@ kbd_adddata(uint16_t val) void kbd_adddata_process(uint16_t val, void (*adddata)(uint16_t val)) { - uint8_t num_lock = 0, shift_states = 0; + uint8_t num_lock = 0; + uint8_t shift_states = 0; if (!adddata) return; @@ -515,7 +517,9 @@ static void kbd_write(uint16_t port, uint8_t val, void *priv) { xtkbd_t *kbd = (xtkbd_t *) priv; - uint8_t bit, set, new_clock; + uint8_t bit; + uint8_t set; + uint8_t new_clock; switch (port) { case 0x61: /* Keyboard Control Register (aka Port B) */ @@ -684,7 +688,7 @@ kbd_read(uint16_t port, void *priv) break; } - return (ret); + return ret; } static void @@ -700,7 +704,7 @@ kbd_reset(void *priv) keyboard_scan = 1; - key_queue_start = 0, + key_queue_start = 0; key_queue_end = 0; } @@ -873,7 +877,7 @@ kbd_init(const device_t *info) is_amstrad = 0; - return (kbd); + return kbd; } static void diff --git a/src/device/mouse.c b/src/device/mouse.c index 0ee714377..9409fa3cb 100644 --- a/src/device/mouse.c +++ b/src/device/mouse.c @@ -36,16 +36,16 @@ typedef struct { } mouse_t; int mouse_type = 0; -int mouse_x, - mouse_y, - mouse_z, - mouse_buttons, - mouse_mode, - mouse_tablet_in_proximity = 0, - tablet_tool_type = 1; /* 0 = Puck/Cursor, 1 = Pen */ +int mouse_x; +int mouse_y; +int mouse_z; +int mouse_buttons; +int mouse_mode; +int mouse_tablet_in_proximity = 0; +int tablet_tool_type = 1; /* 0 = Puck/Cursor, 1 = Pen */ -double mouse_x_abs, - mouse_y_abs; +double mouse_x_abs; +double mouse_y_abs; pc_timer_t mouse_timer; /* mouse event timer */ @@ -266,18 +266,18 @@ mouse_get_from_internal_name(char *s) while (mouse_devices[c].device != NULL) { if (!strcmp((char *) mouse_devices[c].device->internal_name, s)) - return (c); + return c; c++; } - return (0); + return 0; } int mouse_has_config(int mouse) { if (mouse_devices[mouse].device == NULL) - return (0); + return 0; return (mouse_devices[mouse].device->config ? 1 : 0); } @@ -291,7 +291,7 @@ mouse_get_device(int mouse) int mouse_get_buttons(void) { - return (mouse_nbut); + return mouse_nbut; } /* Return number of MOUSE types we know about. */ diff --git a/src/device/mouse_bus.c b/src/device/mouse_bus.c index 3e9cd28e2..5025871d8 100644 --- a/src/device/mouse_bus.c +++ b/src/device/mouse_bus.c @@ -455,11 +455,11 @@ bm_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv) int xor ; if (!(dev->flags & FLAG_ENABLED)) - return (1); /* Mouse is disabled, do nothing. */ + return 1; /* Mouse is disabled, do nothing. */ if (!x && !y && !((b ^ dev->mouse_buttons_last) & 0x07)) { dev->mouse_buttons_last = b; - return (1); /* State has not changed, do nothing. */ + return 1; /* State has not changed, do nothing. */ } /* Converts button states from MRL to LMR. */ @@ -512,7 +512,7 @@ bm_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv) bm_log("DEBUG: Data Interrupt Fired...\n"); } } - return (0); + return 0; } /* The timer calls us on every tick if the mouse is in timer mode @@ -520,7 +520,8 @@ bm_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv) static void bm_update_data(mouse_t *dev) { - int delta_x, delta_y; + int delta_x; + int delta_y; int xor ; /* If the counters are not frozen, update them. */ diff --git a/src/device/mouse_ps2.c b/src/device/mouse_ps2.c index a1afb8afa..46144e02e 100644 --- a/src/device/mouse_ps2.c +++ b/src/device/mouse_ps2.c @@ -108,7 +108,7 @@ ps2_report_coordinates(atkbc_dev_t *dev, int main) kbc_at_dev_queue_add(dev, buff[2], main); if (dev->flags & FLAG_INTMODE) { temp_z = dev->z & 0x0f; - if ((dev->flags & FLAG_5BTN)) { + if (dev->flags & FLAG_5BTN) { if (mouse_buttons & 8) temp_z |= 0x10; if (mouse_buttons & 16) @@ -150,7 +150,8 @@ static void ps2_write(void *priv) { atkbc_dev_t *dev = (atkbc_dev_t *) priv; - uint8_t temp, val; + uint8_t temp; + uint8_t val; static uint8_t last_data[6] = { 0x00 }; if (dev->port == NULL) @@ -315,7 +316,7 @@ ps2_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv) int packet_size = (dev->flags & FLAG_INTMODE) ? 4 : 3; if (!mouse_scan || (!x && !y && !z && (b == dev->b))) - return (0xff); + return 0xff; if ((dev->mode == MODE_STREAM) && (kbc_at_dev_queue_pos(dev, 1) < (FIFO_SIZE - packet_size))) { dev->x = x; @@ -332,7 +333,7 @@ ps2_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv) if ((dev->mode == MODE_STREAM) && (kbc_at_dev_queue_pos(dev, 1) < (FIFO_SIZE - packet_size))) ps2_report_coordinates(dev, 1); - return (0); + return 0; } /* @@ -375,7 +376,7 @@ mouse_ps2_init(const device_t *info) kbc_at_dev_reset(dev, 0); /* Return our private data to the I/O layer. */ - return (dev); + return dev; } static void diff --git a/src/device/mouse_serial.c b/src/device/mouse_serial.c index 58541d79a..58183e1df 100644 --- a/src/device/mouse_serial.c +++ b/src/device/mouse_serial.c @@ -284,7 +284,7 @@ static uint8_t sermouse_data_hex(mouse_t *dev, int x, int y, int b) { char ret[6] = { 0, 0, 0, 0, 0, 0 }; - uint8_t i, but = 0x00; + uint8_t but = 0x00; but |= (b & 0x01) ? 0x04 : 0x00; /* left button */ but |= (b & 0x04) ? 0x02 : 0x00; /* middle button */ @@ -292,7 +292,7 @@ sermouse_data_hex(mouse_t *dev, int x, int y, int b) sprintf(ret, "%02X%02X%01X", (int8_t) y, (int8_t) x, but & 0x0f); - for (i = 0; i < 5; i++) + for (uint8_t i = 0; i < 5; i++) dev->data[i] = ret[4 - i]; return 5; @@ -371,7 +371,8 @@ sermouse_last_button_status(mouse_t *dev) static void sermouse_update_delta(mouse_t *dev, int *local, int *global) { - int min, max; + int min; + int max; if (dev->format == 3) { min = -2048; @@ -397,7 +398,9 @@ static uint8_t sermouse_update_data(mouse_t *dev) { uint8_t ret = 0; - int delta_x, delta_y, delta_z; + int delta_x; + int delta_y; + int delta_z; /* Update the deltas and the delays. */ sermouse_update_delta(dev, &delta_x, &dev->rel_x); @@ -529,7 +532,7 @@ sermouse_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv if (!x && !y && !z && (b == dev->oldb)) { dev->oldb = b; - return (1); + return 1; } dev->oldb = b; @@ -568,7 +571,7 @@ sermouse_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv dev->rel_y += y; dev->rel_z += z; - return (0); + return 0; } static void diff --git a/src/device/mouse_wacom_tablet.c b/src/device/mouse_wacom_tablet.c index 2fa909286..d9466146d 100644 --- a/src/device/mouse_wacom_tablet.c +++ b/src/device/mouse_wacom_tablet.c @@ -373,7 +373,8 @@ wacom_write(struct serial_s *serial, void *priv, uint8_t data) if (!memcmp(wacom->data_rec, "~*", 2)) { uint32_t settings_dword = wacom->settings; if (strstr((const char *) wacom->data_rec, ",")) { - uint32_t x_res = wacom->x_res, y_res = wacom->y_res; + uint32_t x_res = wacom->x_res; + uint32_t y_res = wacom->y_res; uint32_t increment = wacom->increment; uint32_t interval = wacom->interval; @@ -423,7 +424,7 @@ wacom_poll(int x, int y, int z, int b, double abs_x, double abs_y, void *priv) if (wacom->b != b) wacom->oldb = wacom->b; wacom->b = b; - return (0); + return 0; } static int diff --git a/src/device/pci_bridge.c b/src/device/pci_bridge.c index c5ad77a4f..e54cdea74 100644 --- a/src/device/pci_bridge.c +++ b/src/device/pci_bridge.c @@ -473,7 +473,11 @@ pci_bridge_reset(void *priv) static void * pci_bridge_init(const device_t *info) { - uint8_t interrupts[4], interrupt_count, interrupt_mask, slot_count, i; + uint8_t interrupts[4]; + uint8_t interrupt_count; + uint8_t interrupt_mask; + uint8_t slot_count; + uint8_t i; pci_bridge_t *dev = (pci_bridge_t *) malloc(sizeof(pci_bridge_t)); memset(dev, 0, sizeof(pci_bridge_t)); diff --git a/src/device/postcard.c b/src/device/postcard.c index f91736b1a..8475f76fc 100644 --- a/src/device/postcard.c +++ b/src/device/postcard.c @@ -31,7 +31,8 @@ static uint16_t postcard_port; static uint8_t postcard_written; -static uint8_t postcard_code, postcard_prev_code; +static uint8_t postcard_code; +static uint8_t postcard_prev_code; #define UISTR_LEN 13 static char postcard_str[UISTR_LEN]; /* UI output string */ diff --git a/src/device/serial.c b/src/device/serial.c index c0f5bdb7d..bc4b3053d 100644 --- a/src/device/serial.c +++ b/src/device/serial.c @@ -266,13 +266,11 @@ serial_transmit(serial_t *dev, uint8_t val) static void serial_move_to_txsr(serial_t *dev) { - int i = 0; - if (dev->fifo_enabled) { dev->txsr = dev->xmit_fifo[0]; if (dev->xmit_fifo_pos > 0) { /* Move the entire fifo forward by one byte. */ - for (i = 1; i < 16; i++) + for (uint8_t i = 1; i < 16; i++) dev->xmit_fifo[i - 1] = dev->xmit_fifo[i]; /* Decrease FIFO position. */ dev->xmit_fifo_pos--; @@ -476,7 +474,8 @@ void serial_write(uint16_t addr, uint8_t val, void *p) { serial_t *dev = (serial_t *) p; - uint8_t new_msr, old; + uint8_t new_msr; + uint8_t old; // serial_log("UART: Write %02X to port %02X\n", val, addr); serial_log("UART: [%04X:%08X] Write %02X to port %02X\n", CS, cpu_state.pc, val, addr); diff --git a/src/device/serial_passthrough.c b/src/device/serial_passthrough.c index 672bc98c3..441d3e339 100644 --- a/src/device/serial_passthrough.c +++ b/src/device/serial_passthrough.c @@ -52,9 +52,7 @@ serial_passthrough_log(const char *fmt, ...) void serial_passthrough_init(void) { - int c; - - for (c = 0; c < SERIAL_MAX; c++) { + for (uint8_t c = 0; c < SERIAL_MAX; c++) { if (serial_passthrough_enabled[c]) { /* Instance n for COM n */ device_add_inst(&serial_passthrough_device, c + 1); @@ -139,7 +137,7 @@ serial_passthrough_transmit_period(serial_t *serial, void *p, double transmit_pe if (dev->mode != SERPT_MODE_HOSTSER) return; - dev->baudrate = 1000000.0 / (transmit_period); + dev->baudrate = 1000000.0 / transmit_period; serial_passthrough_speed_changed(p); plat_serpt_set_params(dev); diff --git a/src/device/smbus_ali7101.c b/src/device/smbus_ali7101.c index 2777740dd..9ca89456a 100644 --- a/src/device/smbus_ali7101.c +++ b/src/device/smbus_ali7101.c @@ -90,7 +90,10 @@ static void smbus_ali7101_write(uint16_t addr, uint8_t val, void *priv) { smbus_ali7101_t *dev = (smbus_ali7101_t *) priv; - uint8_t smbus_addr, cmd, read, prev_stat; + uint8_t smbus_addr; + uint8_t cmd; + uint8_t read; + uint8_t prev_stat; uint16_t timer_bytes = 0; smbus_ali7101_log("SMBus ALI7101: write(%02X, %02X)\n", addr, val); diff --git a/src/device/smbus_piix4.c b/src/device/smbus_piix4.c index 07a03454f..670a9adf4 100644 --- a/src/device/smbus_piix4.c +++ b/src/device/smbus_piix4.c @@ -94,8 +94,13 @@ static void smbus_piix4_write(uint16_t addr, uint8_t val, void *priv) { smbus_piix4_t *dev = (smbus_piix4_t *) priv; - uint8_t smbus_addr, cmd, read, block_len, prev_stat; - uint16_t timer_bytes = 0, i = 0; + uint8_t smbus_addr; + uint8_t cmd; + uint8_t read; + uint8_t block_len; + uint8_t prev_stat; + uint16_t timer_bytes = 0; + uint16_t i = 0; smbus_piix4_log("SMBus PIIX4: write(%02X, %02X)\n", addr, val); diff --git a/src/discord.c b/src/discord.c index fcc8d18c1..18faee696 100644 --- a/src/discord.c +++ b/src/discord.c @@ -135,7 +135,7 @@ int discord_load(void) { if (discord_handle != NULL) - return (1); + return 1; // Try to load the DLL discord_handle = dynld_module(PATH_DISCORD_DLL, discord_imports); @@ -144,11 +144,11 @@ discord_load(void) discord_log("discord: couldn't load " PATH_DISCORD_DLL "\n"); discord_close(); - return (0); + return 0; } discord_loaded = 1; - return (1); + return 1; } void diff --git a/src/dma.c b/src/dma.c index ecdc393ff..710ea0abf 100644 --- a/src/dma.c +++ b/src/dma.c @@ -132,7 +132,7 @@ dma_sg_next_addr(dma_t *dev) static void dma_block_transfer(int channel) { - int i, bit16; + int bit16; bit16 = (channel >= 4); @@ -140,7 +140,7 @@ dma_block_transfer(int channel) bit16 = !!(dma_transfer_size(&(dma[channel])) == 2); dma_req_is_soft = 1; - for (i = 0; i <= dma[channel].cb; i++) { + for (uint16_t i = 0; i <= dma[channel].cb; i++) { if ((dma[channel].mode & 0x8c) == 0x84) { if (bit16) dma_channel_write(channel, dma16_buffer[i]); @@ -422,10 +422,9 @@ dma_ext_mode_write(uint16_t addr, uint8_t val, void *priv) static uint8_t dma_sg_int_status_read(uint16_t addr, void *priv) { - int i; uint8_t ret = 0x00; - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { if (i != 4) ret = (!!(dma[i].sg_status & 8)) << i; } @@ -458,17 +457,17 @@ dma_read(uint16_t addr, void *priv) temp = dma[channel].cc & 0xff; else temp = dma[channel].cc >> 8; - return (temp); + return temp; case 8: /*Status register*/ temp = dma_stat_rq_pc & 0xf; temp <<= 4; temp |= dma_stat & 0xf; dma_stat &= ~0xf; - return (temp); + return temp; case 0xd: /*Temporary register*/ - return (0); + return 0; } return (dmaregs[0][addr & 0xf]); @@ -628,7 +627,7 @@ dma_ps2_read(uint16_t addr, void *priv) } break; } - return (temp); + return temp; } static void @@ -754,13 +753,13 @@ dma16_read(uint16_t addr, void *priv) temp = dma[channel].cc & 0xff; else temp = dma[channel].cc >> 8; - return (temp); + return temp; case 8: /*Status register*/ temp = (dma_stat_rq_pc & 0xf0); temp |= dma_stat >> 4; dma_stat &= ~0xf0; - return (temp); + return temp; } return (dmaregs[1][addr & 0xf]); @@ -890,7 +889,7 @@ dma_page_write(uint16_t addr, uint8_t val, void *priv) dma[addr].ab = (dma[addr].ab & 0xff01ffff & dma_mask) | (dma[addr].page << 16); dma[addr].ac = (dma[addr].ac & 0xff01ffff & dma_mask) | (dma[addr].page << 16); } else { - dma[addr].page = (dma_at) ? val : val & 0xf; + dma[addr].page = dma_at ? val : val & 0xf; dma[addr].ab = (dma[addr].ab & 0xff00ffff & dma_mask) | (dma[addr].page << 16); dma[addr].ac = (dma[addr].ac & 0xff00ffff & dma_mask) | (dma[addr].page << 16); } @@ -966,11 +965,9 @@ dma_set_params(uint8_t advanced, uint32_t mask) void dma_set_mask(uint32_t mask) { - int i; - dma_mask = mask; - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { dma[i].ab &= mask; dma[i].ac &= mask; } @@ -1021,14 +1018,12 @@ dma_reset(void) void dma_remove_sg(void) { - int i; - io_removehandler(dma_sg_base + 0x0a, 0x01, dma_sg_int_status_read, NULL, NULL, NULL, NULL, NULL, NULL); - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { io_removehandler(dma_sg_base + 0x10 + i, 0x01, dma_sg_read, dma_sg_readw, dma_sg_readl, dma_sg_write, dma_sg_writew, dma_sg_writel, @@ -1047,8 +1042,6 @@ dma_remove_sg(void) void dma_set_sg_base(uint8_t sg_base) { - int i; - dma_sg_base = sg_base << 8; io_sethandler(dma_sg_base + 0x0a, 0x01, @@ -1056,7 +1049,7 @@ dma_set_sg_base(uint8_t sg_base) NULL, NULL, NULL, NULL); - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { io_sethandler(dma_sg_base + 0x10 + i, 0x01, dma_sg_read, dma_sg_readw, dma_sg_readl, dma_sg_write, dma_sg_writew, dma_sg_writel, @@ -1178,7 +1171,8 @@ dma_sg(uint8_t *data, int transfer_length, int out, void *priv) char *sop; #endif - int force_end = 0, buffer_pos = 0; + int force_end = 0; + int buffer_pos = 0; #ifdef ENABLE_DMA_LOG sop = out ? "Read" : "Writ"; @@ -1247,7 +1241,7 @@ _dma_read(uint32_t addr, dma_t *dma_c) } else temp = mem_readb_phys(addr); - return (temp); + return temp; } static uint16_t @@ -1263,7 +1257,7 @@ _dma_readw(uint32_t addr, dma_t *dma_c) } else temp = _dma_read(addr, dma_c) | (_dma_read(addr + 1, dma_c) << 8); - return (temp); + return temp; } static void @@ -1416,7 +1410,7 @@ dma_channel_read(int channel) return (temp | DMA_OVER); } - return (temp); + return temp; } int @@ -1500,10 +1494,10 @@ dma_channel_write(int channel, uint16_t val) dma_c->sg_status |= 8; } - return (DMA_OVER); + return DMA_OVER; } - return (0); + return 0; } static void @@ -1604,7 +1598,8 @@ dma_mode(int channel) void dma_bm_read(uint32_t PhysAddress, uint8_t *DataRead, uint32_t TotalSize, int TransferSize) { - uint32_t i = 0, n, n2; + uint32_t n; + uint32_t n2; uint8_t bytes[4] = { 0, 0, 0, 0 }; n = TotalSize & ~(TransferSize - 1); @@ -1612,7 +1607,7 @@ dma_bm_read(uint32_t PhysAddress, uint8_t *DataRead, uint32_t TotalSize, int Tra /* Do the divisible block, if there is one. */ if (n) { - for (i = 0; i < n; i += TransferSize) + for (uint32_t i = 0; i < n; i += TransferSize) mem_read_phys((void *) &(DataRead[i]), PhysAddress + i, TransferSize); } @@ -1626,7 +1621,8 @@ dma_bm_read(uint32_t PhysAddress, uint8_t *DataRead, uint32_t TotalSize, int Tra void dma_bm_write(uint32_t PhysAddress, const uint8_t *DataWrite, uint32_t TotalSize, int TransferSize) { - uint32_t i = 0, n, n2; + uint32_t n; + uint32_t n2; uint8_t bytes[4] = { 0, 0, 0, 0 }; n = TotalSize & ~(TransferSize - 1); @@ -1634,7 +1630,7 @@ dma_bm_write(uint32_t PhysAddress, const uint8_t *DataWrite, uint32_t TotalSize, /* Do the divisible block, if there is one. */ if (n) { - for (i = 0; i < n; i += TransferSize) + for (uint32_t i = 0; i < n; i += TransferSize) mem_write_phys((void *) &(DataWrite[i]), PhysAddress + i, TransferSize); } diff --git a/src/fifo8.c b/src/fifo8.c index 5e3008a7d..683c44671 100644 --- a/src/fifo8.c +++ b/src/fifo8.c @@ -51,7 +51,8 @@ fifo8_push(Fifo8 *fifo, uint8_t data) void fifo8_push_all(Fifo8 *fifo, const uint8_t *data, uint32_t num) { - uint32_t start, avail; + uint32_t start; + uint32_t avail; assert(fifo->num + num <= fifo->capacity); diff --git a/src/game/gameport.c b/src/game/gameport.c index 03df9553d..110b884ec 100644 --- a/src/game/gameport.c +++ b/src/game/gameport.c @@ -285,7 +285,8 @@ gameport_update_joystick_type(void) void gameport_remap(void *priv, uint16_t address) { - gameport_t *dev = (gameport_t *) priv, *other_dev; + gameport_t *dev = (gameport_t *) priv; + gameport_t *other_dev; if (dev->addr) { /* Remove this port from the active ports list. */ diff --git a/src/game/joystick_sw_pad.c b/src/game/joystick_sw_pad.c index 26e26474b..9f3fd492c 100644 --- a/src/game/joystick_sw_pad.c +++ b/src/game/joystick_sw_pad.c @@ -183,10 +183,8 @@ sw_write(void *p) if (time_since_last > 9900 && time_since_last < 9940) { sw->poll_mode = 0; sw->poll_left = 49; - sw->poll_data = 0x2400ull | (0x1830ull << 15) | (0x19b0ull << 30); + sw->poll_data = 0x2400ULL | (0x1830ULL << 15) | (0x19b0ULL << 30); } else { - int c; - sw->poll_mode = sw->data_mode; sw->data_mode = !sw->data_mode; @@ -198,9 +196,8 @@ sw_write(void *p) sw->poll_data = 1; } - for (c = 0; c < 4; c++) { + for (uint8_t c = 0; c < 4; c++) { uint16_t data = 0x3fff; - int b; if (!JOYSTICK_PRESENT(c)) break; @@ -214,7 +211,7 @@ sw_write(void *p) if (joystick_state[c].axis[0] < -16383) data &= ~8; - for (b = 0; b < 10; b++) { + for (uint8_t b = 0; b < 10; b++) { if (joystick_state[c].button[b]) data &= ~(1 << (b + 4)); } diff --git a/src/gdbstub.c b/src/gdbstub.c index 92aa93cf1..867ebe1d1 100644 --- a/src/gdbstub.c +++ b/src/gdbstub.c @@ -322,16 +322,22 @@ static char target_xml[] = /* QEMU gdb-xml/i386-32bit.xml with modificati #ifdef _WIN32 static WSADATA wsa; #endif -static int gdbstub_socket = -1, stop_reason_len = 0, in_gdbstub = 0; +static int gdbstub_socket = -1; +static int stop_reason_len = 0; +static int in_gdbstub = 0; static uint32_t watch_addr; static char stop_reason[2048]; -static gdbstub_client_t *first_client = NULL, *last_client = NULL; +static gdbstub_client_t *first_client = NULL; +static gdbstub_client_t *last_client = NULL; static mutex_t *client_list_mutex; static void (*cpu_exec_shadow)(int cycs); -static gdbstub_breakpoint_t *first_swbreak = NULL, *first_hwbreak = NULL, - *first_rwatch = NULL, *first_wwatch = NULL, *first_awatch = NULL; +static gdbstub_breakpoint_t *first_swbreak = NULL; +static gdbstub_breakpoint_t *first_hwbreak = NULL; +static gdbstub_breakpoint_t *first_rwatch = NULL; +static gdbstub_breakpoint_t *first_wwatch = NULL; +static gdbstub_breakpoint_t *first_awatch = NULL; int gdbstub_step = 0, gdbstub_next_asap = 0; uint64_t gdbstub_watch_pages[(((uint32_t) -1) >> (MEM_GRANULARITY_BITS + 6)) + 1]; @@ -470,7 +476,8 @@ gdbstub_num_decode(char *p, int *dest, int mode) static int gdbstub_client_read_word(gdbstub_client_t *client, int *dest) { - char *p = &client->packet[client->packet_pos], *q = p; + char *p = &client->packet[client->packet_pos]; + char *q = p; while (((*p >= '0') && (*p <= '9')) || ((*p >= 'A') && (*p <= 'F')) || ((*p >= 'a') && (*p <= 'f'))) *dest = ((*dest) << 4) | gdbstub_hex_decode(*p++); return p - q; @@ -599,7 +606,8 @@ static void gdbstub_client_respond(gdbstub_client_t *client) { /* Calculate checksum. */ - int checksum = 0, i; + int checksum = 0; + int i; for (i = 0; i < client->response_pos; i++) checksum += client->response[i]; @@ -716,12 +724,17 @@ gdbstub_client_read_reg(int index, uint8_t *buf) static void gdbstub_client_packet(gdbstub_client_t *client) { - gdbstub_breakpoint_t *breakpoint, *prev_breakpoint = NULL, **first_breakpoint = NULL; + gdbstub_breakpoint_t *breakpoint; + gdbstub_breakpoint_t *prev_breakpoint = NULL; + gdbstub_breakpoint_t **first_breakpoint = NULL; #ifdef GDBSTUB_CHECK_CHECKSUM /* msys2 gdb 11.1 transmits qSupported and H with invalid checksum... */ uint8_t rcv_checksum = 0, checksum = 0; #endif - int i, j = 0, k = 0, l; + int i; + int j = 0; + int k = 0; + int l; uint8_t buf[10] = { 0 }; char *p; @@ -1411,14 +1424,14 @@ gdbstub_cpu_exec(int cycs) /* Add register dump. */ uint8_t buf[10] = { 0 }; - int i, j, k; - for (i = 0; i < GDB_REG_MAX; i++) { + int j; + for (int i = 0; i < GDB_REG_MAX; i++) { if (i >= 0x10) stop_reason[stop_reason_len++] = gdbstub_hex_encode(i >> 4); stop_reason[stop_reason_len++] = gdbstub_hex_encode(i & 0x0f); stop_reason[stop_reason_len++] = ':'; j = gdbstub_client_read_reg(i, buf); - for (k = 0; k < j; k++) { + for (int k = 0; k < j; k++) { stop_reason[stop_reason_len++] = gdbstub_hex_encode(buf[k] >> 4); stop_reason[stop_reason_len++] = gdbstub_hex_encode(buf[k] & 0x0f); } @@ -1717,7 +1730,8 @@ gdbstub_mem_access(uint32_t *addrs, int access) if (in_gdbstub) return; - int width = access & (GDBSTUB_MEM_WRITE - 1), i; + int width = access & (GDBSTUB_MEM_WRITE - 1); + int i; /* Go through the lists of watchpoints for this type of access. */ gdbstub_breakpoint_t *watchpoint = (access & GDBSTUB_MEM_WRITE) ? first_wwatch : first_rwatch; diff --git a/src/include/86box/86box.h b/src/include/86box/86box.h index d472a3e03..10fcd0096 100644 --- a/src/include/86box/86box.h +++ b/src/include/86box/86box.h @@ -97,52 +97,54 @@ extern uint64_t instru_run_ms; #define window_y monitor_settings[0].mon_window_y #define window_w monitor_settings[0].mon_window_w #define window_h monitor_settings[0].mon_window_h -extern int window_remember, - vid_resize, /* (C) allow resizing */ - invert_display, /* (C) invert the display */ - suppress_overscan; /* (C) suppress overscans */ +extern int window_remember; +extern int vid_resize; /* (C) allow resizing */ +extern int invert_display; /* (C) invert the display */ +extern int suppress_overscan; /* (C) suppress overscans */ extern uint32_t lang_id; /* (C) language code identifier */ extern char icon_set[256]; /* (C) iconset identifier */ extern int scale; /* (C) screen scale factor */ extern int dpi_scale; /* (C) DPI scaling of the emulated screen */ extern int vid_api; /* (C) video renderer */ -extern int vid_cga_contrast, /* (C) video */ - video_fullscreen, /* (C) video */ - video_fullscreen_first, /* (C) video */ - video_fullscreen_scale, /* (C) video */ - enable_overscan, /* (C) video */ - force_43, /* (C) video */ - video_filter_method, /* (C) video */ - video_vsync, /* (C) video */ - video_framerate, /* (C) video */ - gfxcard[2]; /* (C) graphics/video card */ +extern int vid_cga_contrast; /* (C) video */ +extern int video_fullscreen; /* (C) video */ +extern int video_fullscreen_first; /* (C) video */ +extern int video_fullscreen_scale; /* (C) video */ +extern int enable_overscan; /* (C) video */ +extern int force_43; /* (C) video */ +extern int video_filter_method; /* (C) video */ +extern int video_vsync; /* (C) video */ +extern int video_framerate; /* (C) video */ +extern int gfxcard[2]; /* (C) graphics/video card */ extern char video_shader[512]; /* (C) video */ -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 */ -extern int sound_is_float, /* (C) sound uses FP values */ - voodoo_enabled, /* (C) video option */ - ibm8514_enabled, /* (C) video option */ - xga_enabled; /* (C) video option */ +extern int bugger_enabled; /* (C) enable ISAbugger */ +extern int postcard_enabled; /* (C) enable POST card */ +extern int isamem_type[]; /* (C) enable ISA mem cards */ +extern int isartc_type; /* (C) enable ISA RTC card */ +extern int sound_is_float; /* (C) sound uses FP values */ +extern int voodoo_enabled; /* (C) video option */ +extern int ibm8514_enabled; /* (C) video option */ +extern int xga_enabled; /* (C) video option */ extern uint32_t mem_size; /* (C) memory size (Installed on system board) */ extern uint32_t isa_mem_size; /* (C) memory size (ISA Memory Cards) */ -extern int cpu, /* (C) cpu type */ - cpu_use_dynarec, /* (C) cpu uses/needs Dyna */ - fpu_type, /* (C) fpu type */ - fpu_softfloat; /* (C) fpu uses softfloat */ +extern int cpu; /* (C) cpu type */ +extern int cpu_use_dynarec; /* (C) cpu uses/needs Dyna */ +extern int fpu_type; /* (C) fpu type */ +extern int fpu_softfloat; /* (C) fpu uses softfloat */ extern int time_sync; /* (C) enable time sync */ extern int hdd_format_type; /* (C) hard disk file format */ -extern int confirm_reset, /* (C) enable reset confirmation */ - confirm_exit, /* (C) enable exit confirmation */ - confirm_save; /* (C) enable save confirmation */ +extern int confirm_reset; /* (C) enable reset confirmation */ +extern int confirm_exit; /* (C) enable exit confirmation */ +extern int confirm_save; /* (C) enable save confirmation */ extern int enable_discord; /* (C) enable Discord integration */ extern int is_pentium; /* TODO: Move back to cpu/cpu.h when it's figured out, how to remove that hack from the ET4000/W32p. */ -extern int fixed_size_x, fixed_size_y; +extern int fixed_size_x; +extern int fixed_size_y; extern double mouse_sensitivity; /* (C) Mouse sensitivity scale */ -extern double mouse_x_error, mouse_y_error; /* Mouse error accumulators */ +extern double mouse_x_error; /* Mouse error accumulator - Y */ +extern double mouse_y_error; /* Mouse error accumulator - Y */ extern int pit_mode; /* (C) force setting PIT mode */ extern int fm_driver; /* (C) select FM sound driver */ @@ -196,7 +198,8 @@ extern void sub_cycles(int c); extern void resub_cycles(int old_cycles); extern double isa_timing; -extern int io_delay, framecountx; +extern int io_delay; +extern int framecountx; extern volatile int cpu_thread_run; diff --git a/src/include/86box/cassette.h b/src/include/86box/cassette.h index 6e6eb646f..85e510225 100644 --- a/src/include/86box/cassette.h +++ b/src/include/86box/cassette.h @@ -157,9 +157,11 @@ extern pc_cassette_t *cassette; extern char cassette_fname[512]; extern char cassette_mode[512]; -extern unsigned long cassette_pos, cassette_srate; +extern unsigned long cassette_pos; +extern unsigned long cassette_srate; extern int cassette_enable; -extern int cassette_append, cassette_pcm; +extern int cassette_append; +extern int cassette_pcm; extern int cassette_ui_writeprot; extern const device_t cassette_device; diff --git a/src/include/86box/fdd.h b/src/include/86box/fdd.h index 19a2141d3..7e9edd624 100644 --- a/src/include/86box/fdd.h +++ b/src/include/86box/fdd.h @@ -120,7 +120,8 @@ extern int disable_write; extern int defaultwriteprot; -extern int writeprot[FDD_NUM], fwriteprot[FDD_NUM]; +extern int writeprot[FDD_NUM]; +extern int fwriteprot[FDD_NUM]; extern int fdd_changed[FDD_NUM]; extern int drive_empty[FDD_NUM]; diff --git a/src/include/86box/hdc_ide.h b/src/include/86box/hdc_ide.h index e7bd8d7cf..5a3251a3f 100644 --- a/src/include/86box/hdc_ide.h +++ b/src/include/86box/hdc_ide.h @@ -113,7 +113,8 @@ enum { TIMINGS_PIO_FC }; -extern int ide_ter_enabled, ide_qua_enabled; +extern int ide_ter_enabled; +extern int ide_qua_enabled; #ifdef SCSI_DEVICE_H extern ide_t *ide_get_drive(int ch); diff --git a/src/include/86box/i8080.h b/src/include/86box/i8080.h index a3f3fba64..b5ba3c7a4 100644 --- a/src/include/86box/i8080.h +++ b/src/include/86box/i8080.h @@ -21,31 +21,38 @@ typedef struct i8080 { union { uint16_t af; /* Intended in case we also go for μPD9002 emulation, which also has a Z80 emulation mode. */ struct { - uint8_t a, flags; + uint8_t a; + uint8_t flags; }; }; union { uint16_t bc; struct { - uint8_t b, c; + uint8_t b; + uint8_t c; }; }; union { uint16_t de; struct { - uint8_t d, e; + uint8_t d; + uint8_t e; }; }; union { uint16_t hl; struct { - uint8_t h, l; + uint8_t h; + uint8_t l; }; }; - uint16_t pc, sp; - uint16_t oldpc, ei; - uint32_t pmembase, dmembase; /* Base from where i8080 starts. */ - uint8_t emulated; /* 0 = not emulated, use separate registers, 1 = emulated, use x86 registers. */ + uint16_t pc; + uint16_t sp; + uint16_t oldpc; + uint16_t ei; + uint32_t pmembase; + uint32_t dmembase; /* Base from where i8080 starts. */ + uint8_t emulated; /* 0 = not emulated, use separate registers, 1 = emulated, use x86 registers. */ uint16_t *cpu_flags; void (*writemembyte)(uint32_t, uint8_t); uint8_t (*readmembyte)(uint32_t); diff --git a/src/include/86box/keyboard.h b/src/include/86box/keyboard.h index 669d9c6f7..4a1c04892 100644 --- a/src/include/86box/keyboard.h +++ b/src/include/86box/keyboard.h @@ -192,8 +192,10 @@ extern const scancode scancode_xt[512]; extern uint8_t keyboard_set3_flags[512]; extern uint8_t keyboard_set3_all_repeat; extern uint8_t keyboard_set3_all_break; -extern int mouse_queue_start, mouse_queue_end; -extern int mouse_cmd_queue_start, mouse_cmd_queue_end; +extern int mouse_queue_start; +extern int mouse_queue_end; +extern int mouse_cmd_queue_start; +extern int mouse_cmd_queue_end; extern int mouse_scan; extern kbc_at_port_t *kbc_at_ports[2]; diff --git a/src/include/86box/machine.h b/src/include/86box/machine.h index 4477c4781..6b0b1976a 100644 --- a/src/include/86box/machine.h +++ b/src/include/86box/machine.h @@ -317,8 +317,8 @@ typedef struct _machine_ { } machine_t; /* Global variables. */ -extern const machine_filter_t machine_types[], - machine_chipsets[]; +extern const machine_filter_t machine_types[]; +extern const machine_filter_t machine_chipsets[]; extern const machine_t machines[]; extern int bios_only; extern int machine; diff --git a/src/include/86box/mem.h b/src/include/86box/mem.h index f109776a6..8915b149c 100644 --- a/src/include/86box/mem.h +++ b/src/include/86box/mem.h @@ -270,27 +270,27 @@ extern int writelnext; extern uint32_t ram_mapped_addr[64]; extern uint8_t page_ff[4096]; -extern mem_mapping_t ram_low_mapping, +extern mem_mapping_t ram_low_mapping; #if 1 - ram_mid_mapping, +extern mem_mapping_t ram_mid_mapping; #endif - ram_remapped_mapping, - ram_high_mapping, - ram_2gb_mapping, - bios_mapping, - bios_high_mapping; +extern mem_mapping_t ram_remapped_mapping; +extern mem_mapping_t ram_high_mapping; +extern mem_mapping_t ram_2gb_mapping; +extern mem_mapping_t bios_mapping; +extern mem_mapping_t bios_high_mapping; extern uint32_t mem_logical_addr; -extern page_t *pages, - **page_lookup; +extern page_t *pages; +extern page_t **page_lookup; extern uint32_t get_phys_virt, get_phys_phys; -extern int shadowbios, - shadowbios_write; -extern int readlnum, - writelnum; +extern int shadowbios; +extern int shadowbios_write; +extern int readlnum; +extern int writelnum; extern int memspeed[11]; @@ -299,9 +299,9 @@ extern uint8_t high_page; /* if a high (> 4 gb) page was detected */ extern uint32_t pages_sz; /* #pages in table */ -extern int mem_a20_state, - mem_a20_alt, - mem_a20_key; +extern int mem_a20_state; +extern int mem_a20_alt; +extern int mem_a20_key; extern uint8_t read_mem_b(uint32_t addr); extern uint16_t read_mem_w(uint32_t addr); diff --git a/src/include/86box/midi.h b/src/include/86box/midi.h index e2b8c2626..f965e6c98 100644 --- a/src/include/86box/midi.h +++ b/src/include/86box/midi.h @@ -56,7 +56,8 @@ typedef struct midi_t { midi_device_t *m_out_device, *m_in_device; } midi_t; -extern midi_t *midi_out, *midi_in; +extern midi_t *midi_out; +extern midi_t *midi_in; extern void midi_out_init(midi_device_t *device); extern void midi_in_init(midi_device_t *device, midi_t **mididev); diff --git a/src/include/86box/mouse.h b/src/include/86box/mouse.h index b697c5d38..874bf30de 100644 --- a/src/include/86box/mouse.h +++ b/src/include/86box/mouse.h @@ -44,10 +44,13 @@ extern "C" { #endif extern int mouse_type; -extern int mouse_x, mouse_y, mouse_z; +extern int mouse_x; +extern int mouse_y; +extern int mouse_z; extern int mouse_mode; /* 1 = Absolute, 0 = Relative */ extern int mouse_tablet_in_proximity; -extern double mouse_x_abs, mouse_y_abs; +extern double mouse_x_abs; +extern double mouse_y_abs; extern int mouse_buttons; extern int tablet_tool_type; diff --git a/src/include/86box/pci.h b/src/include/86box/pci.h index c16d5a7e8..52c2df981 100644 --- a/src/include/86box/pci.h +++ b/src/include/86box/pci.h @@ -94,8 +94,10 @@ typedef union { uint8_t addr_regs[4]; } bar_t; -extern int pci_burst_time, agp_burst_time, - pci_nonburst_time, agp_nonburst_time; +extern int pci_burst_time; +extern int agp_burst_time; +extern int pci_nonburst_time; +extern int agp_nonburst_time; extern void pci_set_irq_routing(int pci_int, int irq); extern void pci_set_irq_level(int pci_int, int level); diff --git a/src/include/86box/pic.h b/src/include/86box/pic.h index eae6a6afb..25c866242 100644 --- a/src/include/86box/pic.h +++ b/src/include/86box/pic.h @@ -29,7 +29,8 @@ typedef struct pic { struct pic *slaves[8]; } pic_t; -extern pic_t pic, pic2; +extern pic_t pic; +extern pic_t pic2; extern void pic_reset_smi_irq_mask(void); extern void pic_set_smi_irq_mask(int irq, int set); diff --git a/src/include/86box/pit.h b/src/include/86box/pit.h index d50e45967..3f682b67d 100644 --- a/src/include/86box/pit.h +++ b/src/include/86box/pit.h @@ -84,15 +84,18 @@ typedef struct { extern pit_intf_t pit_devs[2]; extern const pit_intf_t pit_classic_intf; -extern double SYSCLK, PCICLK, AGPCLK; +extern double SYSCLK; +extern double PCICLK; +extern double AGPCLK; -extern uint64_t PITCONST, ISACONST, - CGACONST, - MDACONST, - HERCCONST, - VGACONST1, - VGACONST2, - RTCCONST; +extern uint64_t PITCONST; +extern uint64_t ISACONST; +extern uint64_t CGACONST; +extern uint64_t MDACONST; +extern uint64_t HERCCONST; +extern uint64_t VGACONST1; +extern uint64_t VGACONST2; +extern uint64_t RTCCONST; extern int refresh_at_enable; diff --git a/src/include/86box/snd_ac97.h b/src/include/86box/snd_ac97.h index 14d31dc40..d6d2eacae 100644 --- a/src/include/86box/snd_ac97.h +++ b/src/include/86box/snd_ac97.h @@ -104,14 +104,22 @@ enum { }; typedef struct { - const uint16_t index, value, write_mask; + const uint16_t index; + const uint16_t value; + const uint16_t write_mask; } ac97_vendor_reg_t; typedef struct { - uint32_t vendor_id, min_rate, max_rate, misc_flags; - uint16_t reset_flags, extid_flags, - powerdown_mask, regs[64]; - uint8_t codec_id, vendor_reg_page_max; + uint32_t vendor_id; + uint32_t min_rate; + uint32_t max_rate; + uint32_t misc_flags; + uint16_t reset_flags; + uint16_t extid_flags; + uint16_t powerdown_mask; + uint16_t regs[64]; + uint8_t codec_id; + uint8_t vendor_reg_page_max; const ac97_vendor_reg_t *vendor_regs; uint16_t *vendor_reg_pages; } ac97_codec_t; @@ -131,9 +139,12 @@ extern void ac97_via_remap_modem_sgd(void *priv, uint16_t new_io_base, uint8_ extern void ac97_via_remap_audio_codec(void *priv, uint16_t new_io_base, uint8_t enable); extern void ac97_via_remap_modem_codec(void *priv, uint16_t new_io_base, uint8_t enable); -extern ac97_codec_t **ac97_codec, **ac97_modem_codec; -extern int ac97_codec_count, ac97_modem_codec_count, - ac97_codec_id, ac97_modem_codec_id; +extern ac97_codec_t **ac97_codec; +extern ac97_codec_t **ac97_modem_codec; +extern int ac97_codec_count; +extern int ac97_modem_codec_count; +extern int ac97_codec_id; +extern int ac97_modem_codec_id; #ifdef EMU_DEVICE_H extern const device_t ad1881_device; diff --git a/src/include/86box/snd_mpu401.h b/src/include/86box/snd_mpu401.h index a6ef8d271..00fdd54f6 100644 --- a/src/include/86box/snd_mpu401.h +++ b/src/include/86box/snd_mpu401.h @@ -144,7 +144,8 @@ typedef struct mpu_t { void *priv; } mpu_t; -extern int mpu401_standalone_enable, mpu401_already_loaded; +extern int mpu401_standalone_enable; +extern int mpu401_already_loaded; extern const device_t mpu401_device; extern const device_t mpu401_mca_device; diff --git a/src/include/86box/snd_speaker.h b/src/include/86box/snd_speaker.h index 516d20588..fa1a6fe19 100644 --- a/src/include/86box/snd_speaker.h +++ b/src/include/86box/snd_speaker.h @@ -23,7 +23,8 @@ extern int speaker_mute; extern int speaker_gated; -extern int speaker_enable, was_speaker_enable; +extern int speaker_enable; +extern int was_speaker_enable; extern void speaker_init(void); diff --git a/src/include/86box/sound.h b/src/include/86box/sound.h index 9f36a70b6..4c01f289c 100644 --- a/src/include/86box/sound.h +++ b/src/include/86box/sound.h @@ -42,9 +42,9 @@ enum { }; extern int ppispeakon; -extern int gated, - speakval, - speakon; +extern int gated; +extern int speakval; +extern int speakon; extern int sound_pos_global; extern int sound_card_current[SOUND_CARD_MAX]; diff --git a/src/include/86box/vid_svga.h b/src/include/86box/vid_svga.h index a18e136dd..93fb9f17c 100644 --- a/src/include/86box/vid_svga.h +++ b/src/include/86box/vid_svga.h @@ -180,7 +180,8 @@ typedef struct svga_t { monitor_t* monitor; } svga_t; -extern int vga_on, ibm8514_on; +extern int vga_on; +extern int ibm8514_on; extern void ibm8514_poll(ibm8514_t *dev, svga_t *svga); extern void ibm8514_recalctimings(svga_t *svga); diff --git a/src/include/86box/vid_voodoo_codegen_x86-64.h b/src/include/86box/vid_voodoo_codegen_x86-64.h index 4999f38c5..b50d3332a 100644 --- a/src/include/86box/vid_voodoo_codegen_x86-64.h +++ b/src/include/86box/vid_voodoo_codegen_x86-64.h @@ -70,7 +70,8 @@ static __m128i xmm_01_w; // = 0x0001000100010001ull; static __m128i xmm_ff_w; // = 0x00ff00ff00ff00ffull; static __m128i xmm_ff_b; // = 0x00000000ffffffffull; -static __m128i alookup[257], aminuslookup[256]; +static __m128i alookup[257]; +static __m128i aminuslookup[256]; static __m128i minus_254; // = 0xff02ff02ff02ff02ull; static __m128i bilinear_lookup[256 * 2]; static __m128i xmm_00_ff_w[2]; diff --git a/src/include/86box/vid_voodoo_codegen_x86.h b/src/include/86box/vid_voodoo_codegen_x86.h index c04330190..9454c9bff 100644 --- a/src/include/86box/vid_voodoo_codegen_x86.h +++ b/src/include/86box/vid_voodoo_codegen_x86.h @@ -69,9 +69,10 @@ static __m128i xmm_ff_w; // = 0x00ff00ff00ff00ffull; static __m128i xmm_ff_b; // = 0x00000000ffffffffull; static uint32_t zero = 0; -static double const_1_48 = (double) (1ull << 4); +static double const_1_48 = (double) (1ULL << 4); -static __m128i alookup[257], aminuslookup[256]; +static __m128i alookup[257]; +static __m128i aminuslookup[256]; static __m128i minus_254; // = 0xff02ff02ff02ff02ull; static __m128i bilinear_lookup[256 * 2]; static __m128i xmm_00_ff_w[2]; diff --git a/src/include/86box/vid_voodoo_common.h b/src/include/86box/vid_voodoo_common.h index 7744ed08b..6eae0bf6d 100644 --- a/src/include/86box/vid_voodoo_common.h +++ b/src/include/86box/vid_voodoo_common.h @@ -53,17 +53,25 @@ typedef union int_float { } int_float; typedef struct rgbvoodoo_t { - uint8_t b, g, r; + uint8_t b; + uint8_t g; + uint8_t r; uint8_t pad; } rgbvoodoo_t; typedef struct rgba8_t { - uint8_t b, g, r, a; + uint8_t b; + uint8_t g; + uint8_t r; + uint8_t a; } rgba8_t; typedef union rgba_u { struct { - uint8_t b, g, r, a; + uint8_t b; + uint8_t g; + uint8_t r; + uint8_t a; } rgba; uint32_t u; } rgba_u; @@ -105,24 +113,53 @@ typedef struct typedef struct voodoo_params_t { int command; - int32_t vertexAx, vertexAy, vertexBx, vertexBy, vertexCx, vertexCy; + int32_t vertexAx; + int32_t vertexAy; + int32_t vertexBx; + int32_t vertexBy; + int32_t vertexCx; + int32_t vertexCy; - uint32_t startR, startG, startB, startZ, startA; + uint32_t startR; + uint32_t startG; + uint32_t startB; + uint32_t startZ; + uint32_t startA; - int32_t dBdX, dGdX, dRdX, dAdX, dZdX; + int32_t dBdX; + int32_t dGdX; + int32_t dRdX; + int32_t dAdX; + int32_t dZdX; - int32_t dBdY, dGdY, dRdY, dAdY, dZdY; + int32_t dBdY; + int32_t dGdY; + int32_t dRdY; + int32_t dAdY; + int32_t dZdY; - int64_t startW, dWdX, dWdY; + int64_t startW; + int64_t dWdX; + int64_t dWdY; struct { - int64_t startS, startT, startW, p1; - int64_t dSdX, dTdX, dWdX, p2; - int64_t dSdY, dTdY, dWdY, p3; + int64_t startS; + int64_t startT; + int64_t startW; + int64_t p1; + int64_t dSdX; + int64_t dTdX; + int64_t dWdX; + int64_t p2; + int64_t dSdY; + int64_t dTdY; + int64_t dWdY; + int64_t p3; } tmu[2]; - uint32_t color0, color1; + uint32_t color0; + uint32_t color1; uint32_t fbzMode; uint32_t fbzColorPath; @@ -131,20 +168,26 @@ typedef struct voodoo_params_t { rgbvoodoo_t fogColor; struct { - uint8_t fog, dfog; + uint8_t fog; + uint8_t dfog; } fogTable[64]; uint32_t alphaMode; uint32_t zaColor; - int chromaKey_r, chromaKey_g, chromaKey_b; + int chromaKey_r; + int chromaKey_g; + int chromaKey_b; uint32_t chromaKey; uint32_t textureMode[2]; uint32_t tLOD[2]; - uint32_t texBaseAddr[2], texBaseAddr1[2], texBaseAddr2[2], texBaseAddr38[2]; + uint32_t texBaseAddr[2]; + uint32_t texBaseAddr1[2]; + uint32_t texBaseAddr2[2]; + uint32_t texBaseAddr38[2]; uint32_t tex_base[2][LOD_MAX + 2]; uint32_t tex_end[2][LOD_MAX + 2]; @@ -155,14 +198,23 @@ typedef struct voodoo_params_t { int tex_shift[2][LOD_MAX + 2]; int tex_lod[2][LOD_MAX + 2]; int tex_entry[2]; - int detail_max[2], detail_bias[2], detail_scale[2]; + int detail_max[2]; + int detail_bias[2]; + int detail_scale[2]; - uint32_t draw_offset, aux_offset; + uint32_t draw_offset; + uint32_t aux_offset; int tformat[2]; - int clipLeft, clipRight, clipLowY, clipHighY; - int clipLeft1, clipRight1, clipLowY1, clipHighY1; + int clipLeft; + int clipRight; + int clipLowY; + int clipHighY; + int clipLeft1; + int clipRight1; + int clipLowY1; + int clipHighY1; int sign; @@ -172,31 +224,46 @@ typedef struct voodoo_params_t { uint32_t stipple; - int col_tiled, aux_tiled; - int row_width, aux_row_width; + int col_tiled; + int aux_tiled; + int row_width; + int aux_row_width; } voodoo_params_t; typedef struct texture_t { uint32_t base; uint32_t tLOD; - atomic_int refcount, refcount_r[4]; + atomic_int refcount; + atomic_int refcount_r[4]; int is16; uint32_t palette_checksum; - uint32_t addr_start[4], addr_end[4]; + uint32_t addr_start[4]; + uint32_t addr_end[4]; uint32_t *data; } texture_t; typedef struct vert_t { - float sVx, sVy; - float sRed, sGreen, sBlue, sAlpha; - float sVz, sWb; - float sW0, sS0, sT0; - float sW1, sS1, sT1; + float sVx; + float sVy; + float sRed; + float sGreen; + float sBlue; + float sAlpha; + float sVz; + float sWb; + float sW0; + float sS0; + float sT0; + float sW1; + float sS1; + float sT1; } vert_t; typedef struct clip_t { - int x_min, x_max; - int y_min, y_max; + int x_min; + int x_max; + int y_min; + int y_max; } clip_t; typedef struct voodoo_t { @@ -205,7 +272,8 @@ typedef struct voodoo_t { int pci_enable; uint8_t dac_data[8]; - int dac_reg, dac_reg_ff; + int dac_reg; + int dac_reg_ff; uint8_t dac_readdata; uint16_t dac_pll_regs[16]; @@ -214,8 +282,14 @@ typedef struct voodoo_t { voodoo_params_t params; - uint32_t fbiInit0, fbiInit1, fbiInit2, fbiInit3, fbiInit4; - uint32_t fbiInit5, fbiInit6, fbiInit7; /*Voodoo 2*/ + uint32_t fbiInit0; + uint32_t fbiInit1; + uint32_t fbiInit2; + uint32_t fbiInit3; + uint32_t fbiInit4; + uint32_t fbiInit5; + uint32_t fbiInit6; + uint32_t fbiInit7; /*Voodoo 2*/ uint32_t initEnable; @@ -223,18 +297,28 @@ typedef struct voodoo_t { uint32_t memBaseAddr; - int_float fvertexAx, fvertexAy, fvertexBx, fvertexBy, fvertexCx, fvertexCy; + int_float fvertexAx; + int_float fvertexAy; + int_float fvertexBx; + int_float fvertexBy; + int_float fvertexCx; + int_float fvertexCy; - uint32_t front_offset, back_offset; + uint32_t front_offset; + uint32_t back_offset; - uint32_t fb_read_offset, fb_write_offset; + uint32_t fb_read_offset; + uint32_t fb_write_offset; - int row_width, aux_row_width; + int row_width; + int aux_row_width; int block_width; - int col_tiled, aux_tiled; + int col_tiled; + int aux_tiled; - uint8_t *fb_mem, *tex_mem[2]; + uint8_t *fb_mem; + uint8_t *tex_mem[2]; uint16_t *tex_mem_w[2]; int rgb_sel; @@ -246,7 +330,8 @@ typedef struct voodoo_t { mutex_t *swap_mutex; int swap_count; - int disp_buffer, draw_buffer; + int disp_buffer; + int draw_buffer; pc_timer_t timer; int line; @@ -254,15 +339,20 @@ typedef struct voodoo_t { uint32_t backPorch; uint32_t videoDimensions; - uint32_t hSync, vSync; + uint32_t hSync; + uint32_t vSync; - int h_total, v_total, v_disp; + int h_total; + int v_total; + int v_disp; int h_disp; int v_retrace; struct { - uint32_t y[4], i[4], q[4]; + uint32_t y[4]; + uint32_t i[4]; + uint32_t q[4]; } nccTable[2][2]; rgba_u palette[2][256]; @@ -284,9 +374,15 @@ typedef struct voodoo_t { int render_threads; int odd_even_mask; - int pixel_count[4], texel_count[4], tri_count, frame_count; - int pixel_count_old[4], texel_count_old[4]; - int wr_count, rd_count, tex_count; + int pixel_count[4]; + int texel_count[4]; + int tri_count; + int frame_count; + int pixel_count_old[4]; + int texel_count_old[4]; + int wr_count; + int rd_count; + int tex_count; int retrace_count; int swap_interval; @@ -306,18 +402,27 @@ typedef struct voodoo_t { int type; fifo_entry_t fifo[FIFO_SIZE]; - atomic_int fifo_read_idx, fifo_write_idx; - atomic_int cmd_read, cmd_written, cmd_written_fifo; + atomic_int fifo_read_idx; + atomic_int fifo_write_idx; + atomic_int cmd_read; + atomic_int cmd_written; + atomic_int cmd_written_fifo; voodoo_params_t params_buffer[PARAM_SIZE]; - atomic_int params_read_idx[4], params_write_idx; + atomic_int params_read_idx[4]; + atomic_int params_write_idx; - uint32_t cmdfifo_base, cmdfifo_end, cmdfifo_size; - int cmdfifo_rp, cmdfifo_ret_addr; + uint32_t cmdfifo_base; + uint32_t cmdfifo_end; + uint32_t cmdfifo_size; + int cmdfifo_rp; + int cmdfifo_ret_addr; int cmdfifo_in_sub; - atomic_int cmdfifo_depth_rd, cmdfifo_depth_wr; + atomic_int cmdfifo_depth_rd; + atomic_int cmdfifo_depth_wr; atomic_int cmdfifo_enabled; - uint32_t cmdfifo_amin, cmdfifo_amax; + uint32_t cmdfifo_amin; + uint32_t cmdfifo_amax; int cmdfifo_holecount; atomic_uint cmd_status; @@ -346,21 +451,37 @@ typedef struct voodoo_t { uint32_t bltSrcBaseAddr; uint32_t bltDstBaseAddr; - int bltSrcXYStride, bltDstXYStride; - uint32_t bltSrcChromaRange, bltDstChromaRange; - int bltSrcChromaMinR, bltSrcChromaMinG, bltSrcChromaMinB; - int bltSrcChromaMaxR, bltSrcChromaMaxG, bltSrcChromaMaxB; - int bltDstChromaMinR, bltDstChromaMinG, bltDstChromaMinB; - int bltDstChromaMaxR, bltDstChromaMaxG, bltDstChromaMaxB; + int bltSrcXYStride; + int bltDstXYStride; + uint32_t bltSrcChromaRange; + uint32_t bltDstChromaRange; + int bltSrcChromaMinR; + int bltSrcChromaMinG; + int bltSrcChromaMinB; + int bltSrcChromaMaxR; + int bltSrcChromaMaxG; + int bltSrcChromaMaxB; + int bltDstChromaMinR; + int bltDstChromaMinG; + int bltDstChromaMinB; + int bltDstChromaMaxR; + int bltDstChromaMaxG; + int bltDstChromaMaxB; - int bltClipRight, bltClipLeft; - int bltClipHighY, bltClipLowY; + int bltClipRight; + int bltClipLeft; + int bltClipHighY; + int bltClipLowY; - int bltSrcX, bltSrcY; - int bltDstX, bltDstY; - int bltSizeX, bltSizeY; + int bltSrcX; + int bltSrcY; + int bltDstX; + int bltDstY; + int bltSizeX; + int bltSizeY; int bltRop[4]; - uint16_t bltColorFg, bltColorBg; + uint16_t bltColorFg; + uint16_t bltColorBg; uint32_t bltCommand; @@ -368,20 +489,28 @@ typedef struct voodoo_t { struct { - int dst_x, dst_y; + int dst_x; + int dst_y; int cur_x; - int size_x, size_y; - int x_dir, y_dir; + int size_x; + int size_y; + int x_dir; + int y_dir; int dst_stride; } blt; struct { - uint32_t bresError0, bresError1; - uint32_t clip0Min, clip0Max; - uint32_t clip1Min, clip1Max; - uint32_t colorBack, colorFore; - uint32_t command, commandExtra; + uint32_t bresError0; + uint32_t bresError1; + uint32_t clip0Min; + uint32_t clip0Max; + uint32_t clip1Min; + uint32_t clip1Max; + uint32_t colorBack; + uint32_t colorFore; + uint32_t command; + uint32_t commandExtra; uint32_t dstBaseAddr; uint32_t dstFormat; uint32_t dstSize; @@ -396,20 +525,31 @@ typedef struct voodoo_t { uint32_t colorPattern[64]; - int bres_error_0, bres_error_1; - uint32_t colorPattern8[64], colorPattern16[64], colorPattern24[64]; - int cur_x, cur_y; + int bres_error_0; + int bres_error_1; + uint32_t colorPattern8[64]; + uint32_t colorPattern16[64]; + uint32_t colorPattern24[64]; + int cur_x; + int cur_y; uint32_t dstBaseAddr_tiled; - uint32_t dstColorkeyMin, dstColorkeyMax; - int dstSizeX, dstSizeY; - int dstX, dstY; + uint32_t dstColorkeyMin; + uint32_t dstColorkeyMax; + int dstSizeX; + int dstSizeY; + int dstX; + int dstY; int dst_stride; - int patoff_x, patoff_y; + int patoff_x; + int patoff_y; uint8_t rops[4]; uint32_t srcBaseAddr_tiled; - uint32_t srcColorkeyMin, srcColorkeyMax; - int srcSizeX, srcSizeY; - int srcX, srcY; + uint32_t srcColorkeyMin; + uint32_t srcColorkeyMax; + int srcSizeX; + int srcSizeY; + int srcX; + int srcY; int src_stride; int old_srcX; @@ -418,39 +558,52 @@ typedef struct voodoo_t { uint32_t old_host_data; /*Polyfill coordinates*/ - int lx[2], rx[2]; - int ly[2], ry[2]; + int lx[2]; + int rx[2]; + int ly[2]; + int ry[2]; /*Polyfill state*/ int error[2]; - int dx[2], dy[2]; + int dx[2]; + int dy[2]; int x_inc[2]; /*y_inc is always 1 for polyfill*/ - int lx_cur, rx_cur; + int lx_cur; + int rx_cur; clip_t clip[2]; uint8_t host_data[16384]; int host_data_count; - int host_data_size_src, host_data_size_dest; - int src_stride_src, src_stride_dest; + int host_data_size_src; + int host_data_size_dest; + int src_stride_src; + int src_stride_dest; int src_bpp; - int line_pix_pos, line_bit_pos; - int line_rep_cnt, line_bit_mask_size; + int line_pix_pos; + int line_bit_pos; + int line_rep_cnt; + int line_bit_mask_size; } banshee_blt; struct { uint32_t vidOverlayStartCoords; uint32_t vidOverlayEndScreenCoords; - uint32_t vidOverlayDudx, vidOverlayDudxOffsetSrcWidth; - uint32_t vidOverlayDvdy, vidOverlayDvdyOffset; + uint32_t vidOverlayDudx; + uint32_t vidOverlayDudxOffsetSrcWidth; + uint32_t vidOverlayDvdy; + uint32_t vidOverlayDvdyOffset; // uint32_t vidDesktopOverlayStride; - int start_x, start_y; - int end_x, end_y; - int size_x, size_y; + int start_x; + int start_y; + int end_x; + int end_y; + int size_x; + int size_y; int overlay_bytes; unsigned int src_y; @@ -462,17 +615,24 @@ typedef struct voodoo_t { uint32_t video_16to32[0x10000]; uint8_t dirty_line[2048]; - int dirty_line_low, dirty_line_high; + int dirty_line_low; + int dirty_line_high; - int fb_write_buffer, fb_draw_buffer; + int fb_write_buffer; + int fb_draw_buffer; int buffer_cutoff; - uint32_t tile_base, tile_stride; - int tile_stride_shift, tile_x, tile_x_real; + uint32_t tile_base; + uint32_t tile_stride; + int tile_stride_shift; + int tile_x; + int tile_x_real; int y_origin_swap; - int read_time, write_time, burst_time; + int read_time; + int write_time; + int burst_time; pc_timer_t wake_timer; @@ -501,9 +661,11 @@ typedef struct voodoo_t { struct voodoo_set_t *set; - uint8_t fifo_thread_run, render_thread_run[4]; + uint8_t fifo_thread_run; + uint8_t render_thread_run[4]; - uint8_t *vram, *changedvram; + uint8_t *vram; + uint8_t *changedvram; void *p; uint8_t monitor_index; @@ -517,7 +679,12 @@ typedef struct voodoo_set_t { int nr_cards; } voodoo_set_t; -extern rgba8_t rgb332[0x100], ai44[0x100], rgb565[0x10000], argb1555[0x10000], argb4444[0x10000], ai88[0x10000]; +extern rgba8_t rgb332[0x100]; +extern rgba8_t ai44[0x100]; +extern rgba8_t rgb565[0x10000]; +extern rgba8_t argb1555[0x10000]; +extern rgba8_t argb4444[0x10000]; +extern rgba8_t ai88[0x10000]; void voodoo_generate_vb_filters(voodoo_t *voodoo, int fcr, int fcg); diff --git a/src/include/86box/vid_xga.h b/src/include/86box/vid_xga.h index 5bc580335..069718b9f 100644 --- a/src/include/86box/vid_xga.h +++ b/src/include/86box/vid_xga.h @@ -22,7 +22,12 @@ typedef struct { int ena; - int x, y, xoff, yoff, cur_xsize, cur_ysize; + int x; + int y; + int xoff; + int yoff; + int cur_xsize; + int cur_ysize; uint32_t addr; } xga_hwcursor_t; diff --git a/src/include/86box/video.h b/src/include/86box/video.h index a49f3bf34..418423ea9 100644 --- a/src/include/86box/video.h +++ b/src/include/86box/video.h @@ -163,12 +163,12 @@ extern volatile int screenshots; #define efscrnsz_y (monitors[monitor_index_global].mon_efscrnsz_y) #define unscaled_size_x (monitors[monitor_index_global].mon_unscaled_size_x) #define unscaled_size_y (monitors[monitor_index_global].mon_unscaled_size_y) -extern PALETTE cgapal, - cgapal_mono[6]; +extern PALETTE cgapal; +extern PALETTE cgapal_mono[6]; // extern uint32_t pal_lookup[256]; -extern int video_fullscreen, - video_fullscreen_scale, - video_fullscreen_first; +extern int video_fullscreen; +extern int video_fullscreen_scale; +extern int video_fullscreen_first; extern uint8_t fontdat[2048][8]; extern uint8_t fontdatm[2048][16]; extern uint8_t fontdatw[512][32]; @@ -190,9 +190,9 @@ extern int video_grayscale; extern int video_graytype; extern double cpuclock; -extern int emu_fps, - frames; -extern int readflash; +extern int emu_fps; +extern int frames; +extern int readflash; /* Function handler pointers. */ extern void (*video_recalctimings)(void); diff --git a/src/ini.c b/src/ini.c index d41573bed..0921b61ff 100644 --- a/src/ini.c +++ b/src/ini.c @@ -111,7 +111,7 @@ find_section(list_t *head, const char *name) while (sec != NULL) { if (!strncmp(sec->name, name, sizeof(sec->name))) - return (sec); + return sec; sec = (section_t *) sec->list.next; } @@ -149,7 +149,7 @@ find_entry(section_t *section, const char *name) while (ent != NULL) { if (!strncmp(ent->name, name, sizeof(ent->name))) - return (ent); + return ent; ent = (entry_t *) ent->list.next; } @@ -172,7 +172,7 @@ entries_num(section_t *section) ent = (entry_t *) ent->list.next; } - return (i); + return i; } static void @@ -205,7 +205,7 @@ create_section(list_t *head, const char *name) memcpy(ns->name, name, strlen(name) + 1); list_add(&ns->list, head); - return (ns); + return ns; } ini_section_t @@ -230,13 +230,14 @@ create_entry(section_t *section, const char *name) memcpy(ne->name, name, strlen(name) + 1); list_add(&ne->list, §ion->entry_head); - return (ne); + return ne; } void ini_close(ini_t ini) { - section_t *sec, *ns; + section_t *sec; + section_t *ns; entry_t *ent; list_t *list = (list_t *) ini; @@ -274,7 +275,7 @@ ini_detect_bom(const char *fn) f = plat_fopen(fn, "rt, ccs=UTF-8"); #endif if (f == NULL) - return (0); + return 0; (void) !fread(bom, 1, 3, f); if (bom[0] == 0xEF && bom[1] == 0xBB && bom[2] == 0xBF) { fclose(f); @@ -313,11 +314,15 @@ ini_fgetws(wchar_t *str, int count, FILE *stream) ini_t ini_read(const char *fn) { - char sname[128], ename[128]; + char sname[128]; + char ename[128]; wchar_t buff[1024]; - section_t *sec, *ns; + section_t *sec; + section_t *ns; entry_t *ne; - int c, d, bom; + int c; + int d; + int bom; FILE *f; list_t *head; @@ -544,15 +549,15 @@ ini_section_get_int(ini_section_t self, const char *name, int def) int value; if (section == NULL) - return (def); + return def; entry = find_entry(section, name); if (entry == NULL) - return (def); + return def; sscanf(entry->data, "%i", &value); - return (value); + return value; } double @@ -563,15 +568,15 @@ ini_section_get_double(ini_section_t self, const char *name, double def) double value; if (section == NULL) - return (def); + return def; entry = find_entry(section, name); if (entry == NULL) - return (def); + return def; sscanf(entry->data, "%lg", &value); - return (value); + return value; } int @@ -582,15 +587,15 @@ ini_section_get_hex16(ini_section_t self, const char *name, int def) unsigned int value; if (section == NULL) - return (def); + return def; entry = find_entry(section, name); if (entry == NULL) - return (def); + return def; sscanf(entry->data, "%04X", &value); - return (value); + return value; } int @@ -601,15 +606,15 @@ ini_section_get_hex20(ini_section_t self, const char *name, int def) unsigned int value; if (section == NULL) - return (def); + return def; entry = find_entry(section, name); if (entry == NULL) - return (def); + return def; sscanf(entry->data, "%05X", &value); - return (value); + return value; } int @@ -617,14 +622,16 @@ ini_section_get_mac(ini_section_t self, const char *name, int def) { section_t *section = (section_t *) self; entry_t *entry; - unsigned int val0 = 0, val1 = 0, val2 = 0; + unsigned int val0 = 0; + unsigned int val1 = 0; + unsigned int val2 = 0; if (section == NULL) - return (def); + return def; entry = find_entry(section, name); if (entry == NULL) - return (def); + return def; sscanf(entry->data, "%02x:%02x:%02x", &val0, &val1, &val2); @@ -638,11 +645,11 @@ ini_section_get_string(ini_section_t self, const char *name, char *def) entry_t *entry; if (section == NULL) - return (def); + return def; entry = find_entry(section, name); if (entry == NULL) - return (def); + return def; return (entry->data); } @@ -654,11 +661,11 @@ ini_section_get_wstring(ini_section_t self, const char *name, wchar_t *def) entry_t *entry; if (section == NULL) - return (def); + return def; entry = find_entry(section, name); if (entry == NULL) - return (def); + return def; return (entry->wdata); } diff --git a/src/io.c b/src/io.c index 0cd7cd87b..99b4954f8 100644 --- a/src/io.c +++ b/src/io.c @@ -54,7 +54,8 @@ typedef struct { } io_trap_t; int initialized = 0; -io_t *io[NPORTS], *io_last[NPORTS]; +io_t *io[NPORTS]; +io_t *io_last[NPORTS]; #ifdef ENABLE_IO_LOG int io_do_log = ENABLE_IO_LOG; @@ -78,7 +79,8 @@ void io_init(void) { int c; - io_t *p, *q; + io_t *p; + io_t *q; if (!initialized) { for (c = 0; c < NPORTS; c++) @@ -114,10 +116,10 @@ io_sethandler_common(uint16_t base, int size, void (*outl)(uint16_t addr, uint32_t val, void *priv), void *priv, int step) { - int c; - io_t *p, *q = NULL; + io_t *p; + io_t *q = NULL; - for (c = 0; c < size; c += step) { + for (int c = 0; c < size; c += step) { p = io_last[base + c]; q = (io_t *) malloc(sizeof(io_t)); memset(q, 0, sizeof(io_t)); @@ -154,10 +156,10 @@ io_removehandler_common(uint16_t base, int size, void (*outl)(uint16_t addr, uint32_t val, void *priv), void *priv, int step) { - int c; - io_t *p, *q; + io_t *p; + io_t *q; - for (c = 0; c < size; c += step) { + for (int c = 0; c < size; c += step) { p = io[base + c]; if (!p) continue; @@ -279,7 +281,8 @@ uint8_t inb(uint16_t port) { uint8_t ret = 0xff; - io_t *p, *q; + io_t *p; + io_t *q; int found = 0; int qfound = 0; @@ -312,13 +315,14 @@ inb(uint16_t port) io_log("[%04X:%08X] (%i, %i, %04i) in b(%04X) = %02X\n", CS, cpu_state.pc, in_smm, found, qfound, port, ret); - return (ret); + return ret; } void outb(uint16_t port, uint8_t val) { - io_t *p, *q; + io_t *p; + io_t *q; int found = 0; int qfound = 0; @@ -349,12 +353,12 @@ outb(uint16_t port, uint8_t val) uint16_t inw(uint16_t port) { - io_t *p, *q; + io_t *p; + io_t *q; uint16_t ret = 0xffff; int found = 0; int qfound = 0; uint8_t ret8[2]; - int i = 0; p = io[port]; while (p) { @@ -369,7 +373,7 @@ inw(uint16_t port) ret8[0] = ret & 0xff; ret8[1] = (ret >> 8) & 0xff; - for (i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 2; i++) { p = io[(port + i) & 0xffff]; while (p) { q = p->next; @@ -403,10 +407,10 @@ inw(uint16_t port) void outw(uint16_t port, uint16_t val) { - io_t *p, *q; + io_t *p; + io_t *q; int found = 0; int qfound = 0; - int i = 0; p = io[port]; while (p) { @@ -419,7 +423,7 @@ outw(uint16_t port, uint16_t val) p = q; } - for (i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 2; i++) { p = io[(port + i) & 0xffff]; while (p) { q = p->next; @@ -448,13 +452,13 @@ outw(uint16_t port, uint16_t val) uint32_t inl(uint16_t port) { - io_t *p, *q; + io_t *p; + io_t *q; uint32_t ret = 0xffffffff; uint16_t ret16[2]; uint8_t ret8[4]; int found = 0; int qfound = 0; - int i = 0; p = io[port]; while (p) { @@ -496,7 +500,7 @@ inl(uint16_t port) ret8[1] = (ret >> 8) & 0xff; ret8[2] = (ret >> 16) & 0xff; ret8[3] = (ret >> 24) & 0xff; - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { p = io[(port + i) & 0xffff]; while (p) { q = p->next; @@ -530,7 +534,8 @@ inl(uint16_t port) void outl(uint16_t port, uint32_t val) { - io_t *p, *q; + io_t *p; + io_t *q; int found = 0; int qfound = 0; int i = 0; diff --git a/src/ioapic.c b/src/ioapic.c index 7d1a62cca..1fed64220 100644 --- a/src/ioapic.c +++ b/src/ioapic.c @@ -53,7 +53,7 @@ ioapic_log(const char *fmt, ...) static void ioapic_write(uint16_t port, uint8_t val, void *priv) { - uint32_t addr, pcmp; + uint32_t pcmp; /* target POST FF, issued by Award before jumping to the bootloader */ if (val != 0xff) @@ -63,7 +63,7 @@ ioapic_write(uint16_t port, uint8_t val, void *priv) /* The _MP_ table must be located in the BIOS area, the EBDA, or the last 1k of conventional memory; at a 16-byte boundary in all cases. Award writes both tables to the BIOS area. */ - for (addr = 0xf0000; addr <= 0xfffff; addr += 16) { + for (uint32_t addr = 0xf0000; addr <= 0xfffff; addr += 16) { /* check signature for the _MP_ table (Floating Point Structure) */ if (mem_readl_phys(addr) != 0x5f504d5f) /* ASCII "_MP_" */ continue; diff --git a/src/log.c b/src/log.c index e36ab69f9..02bb6132e 100644 --- a/src/log.c +++ b/src/log.c @@ -81,7 +81,8 @@ void log_out(void *priv, const char *fmt, va_list ap) { log_t *log = (log_t *) priv; - char temp[1024], fmt2[1024]; + char temp[1024]; + char fmt2[1024]; if (log == NULL) return; @@ -119,7 +120,8 @@ void log_fatal(void *priv, const char *fmt, ...) { log_t *log = (log_t *) priv; - char temp[1024], fmt2[1024]; + char temp[1024]; + char fmt2[1024]; va_list ap; if (log == NULL) diff --git a/src/lpt.c b/src/lpt.c index b20b25641..f4d2ad67c 100644 --- a/src/lpt.c +++ b/src/lpt.c @@ -80,9 +80,7 @@ lpt_device_get_from_internal_name(char *s) void lpt_devices_init(void) { - int i = 0; - - for (i = 0; i < PARALLEL_MAX; i++) { + for (uint8_t i = 0; i < PARALLEL_MAX; i++) { lpt_ports[i].dt = (lpt_device_t *) lpt_devices[lpt_ports[i].device].device; if (lpt_ports[i].dt && lpt_ports[i].dt->init) @@ -93,10 +91,9 @@ lpt_devices_init(void) void lpt_devices_close(void) { - int i = 0; lpt_port_t *dev; - for (i = 0; i < PARALLEL_MAX; i++) { + for (uint8_t i = 0; i < PARALLEL_MAX; i++) { dev = &lpt_ports[i]; if (lpt_ports[i].dt && lpt_ports[i].dt->close) @@ -178,11 +175,10 @@ lpt_irq(void *priv, int raise) void lpt_init(void) { - int i; uint16_t default_ports[PARALLEL_MAX] = { LPT1_ADDR, LPT2_ADDR, LPT_MDA_ADDR, LPT4_ADDR }; uint8_t default_irqs[PARALLEL_MAX] = { LPT1_IRQ, LPT2_IRQ, LPT_MDA_IRQ, LPT4_IRQ }; - for (i = 0; i < PARALLEL_MAX; i++) { + for (uint8_t i = 0; i < PARALLEL_MAX; i++) { lpt_ports[i].addr = 0xffff; lpt_ports[i].irq = 0xff; lpt_ports[i].enable_irq = 0x10; diff --git a/src/machine/m_amstrad.c b/src/machine/m_amstrad.c index a37427de1..17caf6141 100644 --- a/src/machine/m_amstrad.c +++ b/src/machine/m_amstrad.c @@ -159,8 +159,8 @@ typedef struct { uint32_t amstrad_latch; static uint8_t key_queue[16]; -static int key_queue_start = 0, - key_queue_end = 0; +static int key_queue_start = 0; +static int key_queue_end = 0; static uint8_t crtc_mask[32] = { 0xff, 0xff, 0xff, 0xff, 0x7f, 0x1f, 0x7f, 0x7f, 0xf3, 0x1f, 0x7f, 0x1f, 0x3f, 0xff, 0x3f, 0xff, @@ -202,7 +202,9 @@ amstrad_log(const char *fmt, ...) static void recalc_timings_1512(amsvid_t *vid) { - double _dispontime, _dispofftime, disptime; + double _dispontime; + double _dispofftime; + double disptime; disptime = /*128*/ 114; /*Fixed on PC1512*/ _dispontime = 80; @@ -287,7 +289,7 @@ vid_in_1512(uint16_t addr, void *priv) break; } - return (ret); + return ret; } static void @@ -331,9 +333,16 @@ vid_poll_1512(void *priv) amsvid_t *vid = (amsvid_t *) priv; uint16_t ca = (vid->crtc[15] | (vid->crtc[14] << 8)) & 0x3fff; int drawcursor; - int x, c, xs_temp, ys_temp; - uint8_t chr, attr; - uint16_t dat, dat2, dat3, dat4; + int x; + int c; + int xs_temp; + int ys_temp; + uint8_t chr; + uint8_t attr; + uint16_t dat; + uint16_t dat2; + uint16_t dat3; + uint16_t dat4; int cols[4]; int col; int oldsc; @@ -351,25 +360,25 @@ vid_poll_1512(void *priv) vid->lastline = vid->displine; for (c = 0; c < 8; c++) { if ((vid->cgamode & 0x12) == 0x12) { - buffer32->line[(vid->displine << 1)][c] = buffer32->line[(vid->displine << 1) + 1][c] = (vid->border & 15) + 16; + buffer32->line[vid->displine << 1][c] = buffer32->line[(vid->displine << 1) + 1][c] = (vid->border & 15) + 16; if (vid->cgamode & 1) { - buffer32->line[(vid->displine << 1)][c + (vid->crtc[1] << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 3) + 8] = 0; + buffer32->line[vid->displine << 1][c + (vid->crtc[1] << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 3) + 8] = 0; } else { - buffer32->line[(vid->displine << 1)][c + (vid->crtc[1] << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 4) + 8] = 0; + buffer32->line[vid->displine << 1][c + (vid->crtc[1] << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 4) + 8] = 0; } } else { - buffer32->line[(vid->displine << 1)][c] = buffer32->line[(vid->displine << 1) + 1][c] = (vid->cgacol & 15) + 16; + buffer32->line[vid->displine << 1][c] = buffer32->line[(vid->displine << 1) + 1][c] = (vid->cgacol & 15) + 16; if (vid->cgamode & 1) { - buffer32->line[(vid->displine << 1)][c + (vid->crtc[1] << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 3) + 8] = (vid->cgacol & 15) + 16; + buffer32->line[vid->displine << 1][c + (vid->crtc[1] << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 3) + 8] = (vid->cgacol & 15) + 16; } else { - buffer32->line[(vid->displine << 1)][c + (vid->crtc[1] << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 4) + 8] = (vid->cgacol & 15) + 16; + buffer32->line[vid->displine << 1][c + (vid->crtc[1] << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 4) + 8] = (vid->cgacol & 15) + 16; } } } if (vid->cgamode & 1) { for (x = 0; x < 80; x++) { - chr = vid->vram[((vid->ma << 1) & 0x3fff)]; - attr = vid->vram[(((vid->ma << 1) + 1) & 0x3fff)]; + chr = vid->vram[(vid->ma << 1) & 0x3fff]; + attr = vid->vram[((vid->ma << 1) + 1) & 0x3fff]; drawcursor = ((vid->ma == ca) && vid->con && vid->cursoron); if (vid->cgamode & 0x20) { cols[1] = (attr & 15) + 16; @@ -382,19 +391,19 @@ vid_poll_1512(void *priv) } if (drawcursor) { for (c = 0; c < 8; c++) { - buffer32->line[(vid->displine << 1)][(x << 3) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[vid->fontbase + chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; + buffer32->line[vid->displine << 1][(x << 3) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[vid->fontbase + chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; } } else { for (c = 0; c < 8; c++) { - buffer32->line[(vid->displine << 1)][(x << 3) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[vid->fontbase + chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; + buffer32->line[vid->displine << 1][(x << 3) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[vid->fontbase + chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; } } vid->ma++; } } else if (!(vid->cgamode & 2)) { for (x = 0; x < 40; x++) { - chr = vid->vram[((vid->ma << 1) & 0x3fff)]; - attr = vid->vram[(((vid->ma << 1) + 1) & 0x3fff)]; + chr = vid->vram[(vid->ma << 1) & 0x3fff]; + attr = vid->vram[((vid->ma << 1) + 1) & 0x3fff]; drawcursor = ((vid->ma == ca) && vid->con && vid->cursoron); if (vid->cgamode & 0x20) { cols[1] = (attr & 15) + 16; @@ -408,11 +417,11 @@ vid_poll_1512(void *priv) vid->ma++; if (drawcursor) { for (c = 0; c < 8; c++) { - buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[vid->fontbase + chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; + buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[vid->fontbase + chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0] ^ 15; } } else { for (c = 0; c < 8; c++) { - buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[vid->fontbase + chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; + buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[vid->fontbase + chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; } } } @@ -436,7 +445,7 @@ vid_poll_1512(void *priv) dat = (vid->vram[((vid->ma << 1) & 0x1fff) + ((vid->sc & 1) * 0x2000)] << 8) | vid->vram[((vid->ma << 1) & 0x1fff) + ((vid->sc & 1) * 0x2000) + 1]; vid->ma++; for (c = 0; c < 8; c++) { - buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[dat >> 14]; + buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[dat >> 14]; dat <<= 2; } } @@ -450,7 +459,7 @@ vid_poll_1512(void *priv) vid->ma++; for (c = 0; c < 16; c++) { - buffer32->line[(vid->displine << 1)][(x << 4) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + c + 8] = (((dat >> 15) | ((dat2 >> 15) << 1) | ((dat3 >> 15) << 2) | ((dat4 >> 15) << 3)) & (vid->cgacol & 15)) + 16; + buffer32->line[vid->displine << 1][(x << 4) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + c + 8] = (((dat >> 15) | ((dat2 >> 15) << 1) | ((dat3 >> 15) << 2) | ((dat4 >> 15) << 3)) & (vid->cgacol & 15)) + 16; dat <<= 1; dat2 <<= 1; dat3 <<= 1; @@ -897,7 +906,8 @@ const device_t vid_1640_device = { extern int nmi_mask; -static uint32_t blue, green; +static uint32_t blue; +static uint32_t green; static uint32_t lcdcols[256][2][2]; @@ -981,9 +991,8 @@ static void set_lcd_cols(uint8_t mode_reg) { unsigned char *mapping = (mode_reg & 0x80) ? mapping2 : mapping1; - int c; - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { switch (mapping[c]) { case 0: lcdcols[c][0][0] = lcdcols[c][1][0] = green; @@ -1027,7 +1036,7 @@ vid_in_200(uint16_t addr, void *priv) ret = vid->crtc_index; /* Read NMI reason */ vid->crtc_index &= 0x1f; /* Reset NMI reason */ nmi = 0; /* And reset NMI flag */ - return (ret); + return ret; case 0x03de: return ((vid->operation_ctrl & 0xc7) | vid->dipswitches); /*External CGA*/ @@ -1216,7 +1225,6 @@ lcd_draw_char_40(amsvid_t *vid, uint32_t *buffer, uint8_t chr, uint8_t attr, int drawcursor, int blink, int sc, uint8_t control) { - int c; uint8_t bits = fontdat[chr + vid->cga.fontbase][sc]; uint8_t mask = 0x80; @@ -1225,7 +1233,7 @@ lcd_draw_char_40(amsvid_t *vid, uint32_t *buffer, uint8_t chr, if (drawcursor) bits ^= 0xFF; - for (c = 0; c < 8; c++, mask >>= 1) { + for (uint8_t c = 0; c < 8; c++, mask >>= 1) { if (control & 0x20) { buffer[c * 2] = buffer[c * 2 + 1] = lcdcols[attr & 0x7F][blink][(bits & mask) ? 1 : 0]; } else { @@ -1242,7 +1250,8 @@ lcdm_poll(amsvid_t *vid) int drawcursor; int x; int oldvc; - uint8_t chr, attr; + uint8_t chr; + uint8_t attr; int oldsc; int blink; @@ -1351,7 +1360,7 @@ lcdm_poll(amsvid_t *vid) mda->sc &= 31; mda->ma = mda->maback; } - if ((mda->sc == (mda->crtc[10] & 31) || ((mda->crtc[8] & 3) == 3 && mda->sc == ((mda->crtc[10] & 31) >> 1)))) + if (mda->sc == (mda->crtc[10] & 31) || ((mda->crtc[8] & 3) == 3 && mda->sc == ((mda->crtc[10] & 31) >> 1))) mda->con = 1; } } @@ -1361,9 +1370,12 @@ lcdc_poll(amsvid_t *vid) { cga_t *cga = &vid->cga; int drawcursor; - int x, c, xs_temp, ys_temp; + int x; + int xs_temp; + int ys_temp; int oldvc; - uint8_t chr, attr; + uint8_t chr; + uint8_t attr; uint16_t dat; int oldsc; uint16_t ca; @@ -1391,17 +1403,17 @@ lcdc_poll(amsvid_t *vid) attr = cga->charbuffer[(x << 1) + 1]; drawcursor = ((cga->ma == ca) && cga->con && cga->cursoron); blink = ((cga->cgablink & 16) && (cga->cgamode & 0x20) && (attr & 0x80) && !drawcursor); - lcd_draw_char_80(vid, &(buffer32->line[(cga->displine << 1)])[x * 8], chr, attr, drawcursor, blink, cga->sc, cga->cgamode & 0x40, cga->cgamode); + lcd_draw_char_80(vid, &(buffer32->line[cga->displine << 1])[x * 8], chr, attr, drawcursor, blink, cga->sc, cga->cgamode & 0x40, cga->cgamode); lcd_draw_char_80(vid, &(buffer32->line[(cga->displine << 1) + 1])[x * 8], chr, attr, drawcursor, blink, cga->sc, cga->cgamode & 0x40, cga->cgamode); cga->ma++; } } else if (!(cga->cgamode & 2)) { for (x = 0; x < cga->crtc[1]; x++) { - chr = cga->vram[((cga->ma << 1) & 0x3fff)]; - attr = cga->vram[(((cga->ma << 1) + 1) & 0x3fff)]; + chr = cga->vram[(cga->ma << 1) & 0x3fff]; + attr = cga->vram[((cga->ma << 1) + 1) & 0x3fff]; drawcursor = ((cga->ma == ca) && cga->con && cga->cursoron); blink = ((cga->cgablink & 16) && (cga->cgamode & 0x20) && (attr & 0x80) && !drawcursor); - lcd_draw_char_40(vid, &(buffer32->line[(cga->displine << 1)])[x * 16], chr, attr, drawcursor, blink, cga->sc, cga->cgamode); + lcd_draw_char_40(vid, &(buffer32->line[cga->displine << 1])[x * 16], chr, attr, drawcursor, blink, cga->sc, cga->cgamode); lcd_draw_char_40(vid, &(buffer32->line[(cga->displine << 1) + 1])[x * 16], chr, attr, drawcursor, blink, cga->sc, cga->cgamode); cga->ma++; } @@ -1409,7 +1421,7 @@ lcdc_poll(amsvid_t *vid) for (x = 0; x < cga->crtc[1]; x++) { dat = (cga->vram[((cga->ma << 1) & 0x1fff) + ((cga->sc & 1) * 0x2000)] << 8) | cga->vram[((cga->ma << 1) & 0x1fff) + ((cga->sc & 1) * 0x2000) + 1]; cga->ma++; - for (c = 0; c < 16; c++) { + for (uint8_t c = 0; c < 16; c++) { buffer32->line[(cga->displine << 1)][(x << 4) + c] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + c] = (dat & 0x8000) ? blue : green; dat <<= 1; } @@ -1546,11 +1558,11 @@ lcdc_poll(amsvid_t *vid) } if (cga->cgadispon) cga->cgastat &= ~1; - if ((cga->sc == (cga->crtc[10] & 31) || ((cga->crtc[8] & 3) == 3 && cga->sc == ((cga->crtc[10] & 31) >> 1)))) + if (cga->sc == (cga->crtc[10] & 31) || ((cga->crtc[8] & 3) == 3 && cga->sc == ((cga->crtc[10] & 31) >> 1))) cga->con = 1; if (cga->cgadispon && (cga->cgamode & 1)) { for (x = 0; x < (cga->crtc[1] << 1); x++) - cga->charbuffer[x] = cga->vram[(((cga->ma << 1) + x) & 0x3fff)]; + cga->charbuffer[x] = cga->vram[((cga->ma << 1) + x) & 0x3fff]; } } } @@ -1981,7 +1993,7 @@ ms_read(uint16_t addr, void *priv) ams->mousey = 0; } - return (ret); + return ret; } static int @@ -2004,7 +2016,7 @@ ms_poll(int x, int y, int z, int b, void *priv) ams->oldb = b; - return (0); + return 0; } static void @@ -2172,7 +2184,7 @@ kbd_read(uint16_t port, void *priv) amstrad_log("AMDkb: bad keyboard read %04X\n", port); } - return (ret); + return ret; } static void @@ -2290,7 +2302,7 @@ ams_read(uint16_t port, void *priv) break; } - return (ret); + return ret; } static const scancode scancode_pc200[512] = { diff --git a/src/machine/m_at_compaq.c b/src/machine/m_at_compaq.c index e74261b8a..dd8370a4f 100644 --- a/src/machine/m_at_compaq.c +++ b/src/machine/m_at_compaq.c @@ -58,7 +58,8 @@ enum { #define VID_CLOCK (double) (651 * 416 * 60) /* Mapping of attributes to colours */ -static uint32_t amber, black; +static uint32_t amber; +static uint32_t black; static uint32_t blinkcols[256][2]; static uint32_t normcols[256][2]; @@ -108,7 +109,9 @@ static void compaq_plasma_recalcattrs(compaq_plasma_t *self); static void compaq_plasma_recalctimings(compaq_plasma_t *self) { - double _dispontime, _dispofftime, disptime; + double _dispontime; + double _dispofftime; + double disptime; if (!self->internal_monitor && !(self->port_23c6 & 1)) { cga_recalctimings(&self->cga); @@ -118,8 +121,8 @@ compaq_plasma_recalctimings(compaq_plasma_t *self) disptime = 651; _dispontime = 640; _dispofftime = disptime - _dispontime; - self->dispontime = (uint64_t) (_dispontime * (cpuclock / VID_CLOCK) * (double) (1ull << 32)); - self->dispofftime = (uint64_t) (_dispofftime * (cpuclock / VID_CLOCK) * (double) (1ull << 32)); + self->dispontime = (uint64_t) (_dispontime * (cpuclock / VID_CLOCK) * (double) (1ULL << 32)); + self->dispofftime = (uint64_t) (_dispofftime * (cpuclock / VID_CLOCK) * (double) (1ULL << 32)); } static void @@ -146,8 +149,9 @@ static void compaq_plasma_text80(compaq_plasma_t *self) { uint32_t cols[2]; - int x, c; - uint8_t chr, attr; + int c; + uint8_t chr; + uint8_t attr; int drawcursor; int cursorline; int blink; @@ -165,7 +169,7 @@ compaq_plasma_text80(compaq_plasma_t *self) else cursorline = ((self->cga.crtc[10] & 0x0F) * 2 <= sc) && ((self->cga.crtc[11] & 0x0F) * 2 >= sc); - for (x = 0; x < 80; x++) { + for (uint8_t x = 0; x < 80; x++) { chr = self->vram[(addr + 2 * x) & 0x7FFF]; attr = self->vram[(addr + 2 * x + 1) & 0x7FFF]; drawcursor = ((ma == ca) && cursorline && (self->cga.cgamode & 8) && (self->cga.cgablink & 16)); @@ -197,8 +201,9 @@ static void compaq_plasma_text40(compaq_plasma_t *self) { uint32_t cols[2]; - int x, c; - uint8_t chr, attr; + int c; + uint8_t chr; + uint8_t attr; int drawcursor; int cursorline; int blink; @@ -216,7 +221,7 @@ compaq_plasma_text40(compaq_plasma_t *self) else cursorline = ((self->cga.crtc[10] & 0x0F) * 2 <= sc) && ((self->cga.crtc[11] & 0x0F) * 2 >= sc); - for (x = 0; x < 40; x++) { + for (uint8_t x = 0; x < 40; x++) { chr = self->vram[(addr + 2 * x) & 0x7FFF]; attr = self->vram[(addr + 2 * x + 1) & 0x7FFF]; drawcursor = ((ma == ca) && cursorline && (self->cga.cgamode & 8) && (self->cga.cgablink & 16)); @@ -249,7 +254,6 @@ compaq_plasma_text40(compaq_plasma_t *self) static void compaq_plasma_cgaline6(compaq_plasma_t *self) { - int x, c; uint8_t dat; uint32_t ink = 0; uint16_t addr; @@ -263,11 +267,11 @@ compaq_plasma_cgaline6(compaq_plasma_t *self) } else { addr = ((self->displine >> 1) & 1) * 0x2000 + (self->displine >> 2) * 80 + ((ma & ~1) << 1); } - for (x = 0; x < 80; x++) { - dat = self->vram[(addr & 0x7FFF)]; + for (uint8_t x = 0; x < 80; x++) { + dat = self->vram[addr & 0x7FFF]; addr++; - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { ink = (dat & 0x80) ? fg : bg; if (!(self->cga.cgamode & 8)) ink = black; @@ -282,9 +286,10 @@ compaq_plasma_cgaline6(compaq_plasma_t *self) static void compaq_plasma_cgaline4(compaq_plasma_t *self) { - int x, c; - uint8_t dat, pattern; - uint32_t ink0 = 0, ink1 = 0; + uint8_t dat; + uint8_t pattern; + uint32_t ink0 = 0; + uint32_t ink1 = 0; uint16_t addr; uint16_t ma = (self->cga.crtc[13] | (self->cga.crtc[12] << 8)) & 0x7fff; @@ -292,11 +297,11 @@ compaq_plasma_cgaline4(compaq_plasma_t *self) /* 320*200 */ addr = ((self->displine >> 1) & 1) * 0x2000 + (self->displine >> 2) * 80 + ((ma & ~1) << 1); - for (x = 0; x < 80; x++) { - dat = self->vram[(addr & 0x7FFF)]; + for (uint8_t x = 0; x < 80; x++) { + dat = self->vram[addr & 0x7FFF]; addr++; - for (c = 0; c < 4; c++) { + for (uint8_t c = 0; c < 4; c++) { pattern = (dat & 0xC0) >> 6; if (!(self->cga.cgamode & 8)) pattern = 0; diff --git a/src/machine/m_at_t3100e.c b/src/machine/m_at_t3100e.c index 080f22977..b1f8d10f6 100644 --- a/src/machine/m_at_t3100e.c +++ b/src/machine/m_at_t3100e.c @@ -382,7 +382,6 @@ void dump_mappings(void) void t3100e_map_ram(uint8_t val) { - int n; int32_t upper_len; #ifdef ENABLE_T3100E_LOG @@ -433,7 +432,7 @@ t3100e_map_ram(uint8_t val) mem_mapping_disable(&t3100e_ems.upper_mapping); } /* Recalculate EMS mappings */ - for (n = 0; n < 4; n++) { + for (uint8_t n = 0; n < 4; n++) { t3100e_ems_out(t3100e_ems_page_reg[n], t3100e_ems.page[n], &t3100e_ems); } diff --git a/src/machine/m_at_t3100e_vid.c b/src/machine/m_at_t3100e_vid.c index 53571c49e..9602b7b9e 100644 --- a/src/machine/m_at_t3100e_vid.c +++ b/src/machine/m_at_t3100e_vid.c @@ -74,7 +74,8 @@ #define VID_CLOCK (double) (651 * 416 * 60) /* Mapping of attributes to colours */ -static uint32_t amber, black; +static uint32_t amber; +static uint32_t black; static uint8_t boldcols[256]; /* Which attributes use the bold font */ static uint32_t blinkcols[256][2]; static uint32_t normcols[256][2]; @@ -222,7 +223,8 @@ void t3100e_recalctimings(t3100e_t *t3100e) { double disptime; - double _dispontime, _dispofftime; + double _dispontime; + double _dispofftime; if (!t3100e->internal) { cga_recalctimings(&t3100e->cga); @@ -231,8 +233,8 @@ t3100e_recalctimings(t3100e_t *t3100e) disptime = 651; _dispontime = 640; _dispofftime = disptime - _dispontime; - t3100e->dispontime = (uint64_t) (_dispontime * (cpuclock / VID_CLOCK) * (double) (1ull << 32)); - t3100e->dispofftime = (uint64_t) (_dispofftime * (cpuclock / VID_CLOCK) * (double) (1ull << 32)); + t3100e->dispontime = (uint64_t) (_dispontime * (cpuclock / VID_CLOCK) * (double) (1ULL << 32)); + t3100e->dispofftime = (uint64_t) (_dispofftime * (cpuclock / VID_CLOCK) * (double) (1ULL << 32)); } /* Draw a row of text in 80-column mode */ @@ -240,8 +242,9 @@ void t3100e_text_row80(t3100e_t *t3100e) { uint32_t cols[2]; - int x, c; - uint8_t chr, attr; + int c; + uint8_t chr; + uint8_t attr; int drawcursor; int cursorline; int bold; @@ -260,7 +263,7 @@ t3100e_text_row80(t3100e_t *t3100e) } else { cursorline = ((t3100e->cga.crtc[10] & 0x0F) * 2 <= sc) && ((t3100e->cga.crtc[11] & 0x0F) * 2 >= sc); } - for (x = 0; x < 80; x++) { + for (uint8_t x = 0; x < 80; x++) { chr = t3100e->vram[(addr + 2 * x) & 0x7FFF]; attr = t3100e->vram[(addr + 2 * x + 1) & 0x7FFF]; drawcursor = ((ma == ca) && cursorline && (t3100e->cga.cgamode & 8) && (t3100e->cga.cgablink & 16)); @@ -300,8 +303,9 @@ void t3100e_text_row40(t3100e_t *t3100e) { uint32_t cols[2]; - int x, c; - uint8_t chr, attr; + int c; + uint8_t chr; + uint8_t attr; int drawcursor; int cursorline; int bold; @@ -320,7 +324,7 @@ t3100e_text_row40(t3100e_t *t3100e) } else { cursorline = ((t3100e->cga.crtc[10] & 0x0F) * 2 <= sc) && ((t3100e->cga.crtc[11] & 0x0F) * 2 >= sc); } - for (x = 0; x < 40; x++) { + for (uint8_t x = 0; x < 40; x++) { chr = t3100e->vram[(addr + 2 * x) & 0x7FFF]; attr = t3100e->vram[(addr + 2 * x + 1) & 0x7FFF]; drawcursor = ((ma == ca) && cursorline && (t3100e->cga.cgamode & 8) && (t3100e->cga.cgablink & 16)); @@ -360,7 +364,6 @@ t3100e_text_row40(t3100e_t *t3100e) void t3100e_cgaline6(t3100e_t *t3100e) { - int x, c; uint8_t dat; uint32_t ink = 0; uint16_t addr; @@ -375,11 +378,11 @@ t3100e_cgaline6(t3100e_t *t3100e) } else { addr = ((t3100e->displine >> 1) & 1) * 0x2000 + (t3100e->displine >> 2) * 80 + ((ma & ~1) << 1); } - for (x = 0; x < 80; x++) { + for (uint8_t x = 0; x < 80; x++) { dat = t3100e->vram[addr & 0x7FFF]; addr++; - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { ink = (dat & 0x80) ? fg : bg; if (!(t3100e->cga.cgamode & 8)) ink = black; @@ -394,9 +397,10 @@ t3100e_cgaline6(t3100e_t *t3100e) void t3100e_cgaline4(t3100e_t *t3100e) { - int x, c; - uint8_t dat, pattern; - uint32_t ink0 = 0, ink1 = 0; + uint8_t dat; + uint8_t pattern; + uint32_t ink0 = 0; + uint32_t ink1 = 0; uint16_t addr; uint16_t ma = (t3100e->cga.crtc[13] | (t3100e->cga.crtc[12] << 8)) & 0x7fff; @@ -407,11 +411,11 @@ t3100e_cgaline4(t3100e_t *t3100e) { addr = ((t3100e->displine >> 1) & 1) * 0x2000 + (t3100e->displine >> 2) * 80 + ((ma & ~1) << 1); } - for (x = 0; x < 80; x++) { + for (uint8_t x = 0; x < 80; x++) { dat = t3100e->vram[addr & 0x7FFF]; addr++; - for (c = 0; c < 4; c++) { + for (uint8_t c = 0; c < 4; c++) { pattern = (dat & 0xC0) >> 6; if (!(t3100e->cga.cgamode & 8)) pattern = 0; diff --git a/src/machine/m_elt.c b/src/machine/m_elt.c index 0370b45a2..fb7919f26 100644 --- a/src/machine/m_elt.c +++ b/src/machine/m_elt.c @@ -143,9 +143,8 @@ elt_vid_in(uint16_t addr, void *p) static void load_font_rom(uint32_t font_data) { - int c, d; - for (c = 0; c < 256; c++) - for (d = 0; d < 8; d++) + for (uint16_t c = 0; c < 256; c++) + for (uint8_t d = 0; d < 8; d++) fontdat[c][d] = mem_readb_phys(font_data++); } diff --git a/src/machine/m_europc.c b/src/machine/m_europc.c index b1368dd5d..615d6ff7b 100644 --- a/src/machine/m_europc.c +++ b/src/machine/m_europc.c @@ -173,7 +173,8 @@ static void europc_rtc_tick(nvr_t *nvr) { uint8_t *regs; - int mon, yr; + int mon; + int yr; /* Only if RTC is running.. */ regs = nvr->regs; @@ -266,14 +267,13 @@ static uint8_t rtc_checksum(uint8_t *ptr) { uint8_t sum; - int i; /* Calculate all bytes with XOR. */ sum = 0x00; - for (i = MRTC_CONF_A; i <= MRTC_CONF_E; i++) + for (uint8_t i = MRTC_CONF_A; i <= MRTC_CONF_E; i++) sum += ptr[i]; - return (sum); + return sum; } /* Reset the machine's NVR to a sane state. */ @@ -523,7 +523,7 @@ jim_read(uint16_t addr, void *priv) europc_log("EuroPC: jim_rd(%04x): %02x\n", addr, r); #endif - return (r); + return r; } /* Initialize the mainboard 'device' of the machine. */ @@ -638,7 +638,7 @@ europc_boot(const device_t *info) if (hdc_current == 1) (void) device_add(&xta_hd20_device); - return (sys); + return sys; } static void diff --git a/src/machine/m_pcjr.c b/src/machine/m_pcjr.c index d1eafef79..c2163746b 100644 --- a/src/machine/m_pcjr.c +++ b/src/machine/m_pcjr.c @@ -107,8 +107,8 @@ static uint8_t crtcmask[32] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static uint8_t key_queue[16]; -static int key_queue_start = 0, - key_queue_end = 0; +static int key_queue_start = 0; +static int key_queue_end = 0; static void recalc_address(pcjr_t *pcjr) @@ -125,7 +125,9 @@ recalc_address(pcjr_t *pcjr) static void recalc_timings(pcjr_t *pcjr) { - double _dispontime, _dispofftime, disptime; + double _dispontime; + double _dispofftime; + double disptime; if (pcjr->array[0] & 1) { disptime = pcjr->crtc[0] + 1; @@ -207,7 +209,7 @@ vid_in(uint16_t addr, void *p) break; } - return (ret); + return ret; } static void @@ -227,7 +229,7 @@ vid_read(uint32_t addr, void *p) pcjr_t *pcjr = (pcjr_t *) p; if (pcjr->memctrl == -1) - return (0xff); + return 0xff; return (pcjr->b8000[addr & 0x3fff]); } @@ -238,9 +240,13 @@ vid_poll(void *p) pcjr_t *pcjr = (pcjr_t *) p; uint16_t ca = (pcjr->crtc[15] | (pcjr->crtc[14] << 8)) & 0x3fff; int drawcursor; - int x, c, xs_temp, ys_temp; + int x; + int c; + int xs_temp; + int ys_temp; int oldvc; - uint8_t chr, attr; + uint8_t chr; + uint8_t attr; uint16_t dat; int cols[4]; int oldsc; @@ -265,9 +271,9 @@ vid_poll(void *p) for (c = 0; c < 8; c++) { ((uint32_t *) buffer32->line[pcjr->displine])[c] = cols[0]; if (pcjr->array[0] & 1) { - buffer32->line[(pcjr->displine << 1)][c + (pcjr->crtc[1] << 3) + 8] = buffer32->line[(pcjr->displine << 1) + 1][c + (pcjr->crtc[1] << 3) + 8] = cols[0]; + buffer32->line[pcjr->displine << 1][c + (pcjr->crtc[1] << 3) + 8] = buffer32->line[(pcjr->displine << 1) + 1][c + (pcjr->crtc[1] << 3) + 8] = cols[0]; } else { - buffer32->line[(pcjr->displine << 1)][c + (pcjr->crtc[1] << 4) + 8] = buffer32->line[(pcjr->displine << 1) + 1][c + (pcjr->crtc[1] << 4) + 8] = cols[0]; + buffer32->line[pcjr->displine << 1][c + (pcjr->crtc[1] << 4) + 8] = buffer32->line[(pcjr->displine << 1) + 1][c + (pcjr->crtc[1] << 4) + 8] = cols[0]; } } @@ -288,20 +294,20 @@ vid_poll(void *p) for (x = 0; x < pcjr->crtc[1]; x++) { dat = (pcjr->vram[((pcjr->ma << 1) & mask) + offset] << 8) | pcjr->vram[((pcjr->ma << 1) & mask) + offset + 1]; pcjr->ma++; - buffer32->line[(pcjr->displine << 1)][(x << 3) + 8] = buffer32->line[(pcjr->displine << 1)][(x << 3) + 9] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 9] = pcjr->array[((dat >> 12) & pcjr->array[1]) + 16] + 16; - buffer32->line[(pcjr->displine << 1)][(x << 3) + 10] = buffer32->line[(pcjr->displine << 1)][(x << 3) + 11] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 10] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 11] = pcjr->array[((dat >> 8) & pcjr->array[1]) + 16] + 16; - buffer32->line[(pcjr->displine << 1)][(x << 3) + 12] = buffer32->line[(pcjr->displine << 1)][(x << 3) + 13] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 12] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 13] = pcjr->array[((dat >> 4) & pcjr->array[1]) + 16] + 16; - buffer32->line[(pcjr->displine << 1)][(x << 3) + 14] = buffer32->line[(pcjr->displine << 1)][(x << 3) + 15] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 14] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 15] = pcjr->array[(dat & pcjr->array[1]) + 16] + 16; + buffer32->line[pcjr->displine << 1][(x << 3) + 8] = buffer32->line[pcjr->displine << 1][(x << 3) + 9] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 9] = pcjr->array[((dat >> 12) & pcjr->array[1]) + 16] + 16; + buffer32->line[pcjr->displine << 1][(x << 3) + 10] = buffer32->line[pcjr->displine << 1][(x << 3) + 11] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 10] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 11] = pcjr->array[((dat >> 8) & pcjr->array[1]) + 16] + 16; + buffer32->line[pcjr->displine << 1][(x << 3) + 12] = buffer32->line[pcjr->displine << 1][(x << 3) + 13] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 12] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 13] = pcjr->array[((dat >> 4) & pcjr->array[1]) + 16] + 16; + buffer32->line[pcjr->displine << 1][(x << 3) + 14] = buffer32->line[pcjr->displine << 1][(x << 3) + 15] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 14] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 15] = pcjr->array[(dat & pcjr->array[1]) + 16] + 16; } break; case 0x12: /*160x200x16*/ for (x = 0; x < pcjr->crtc[1]; x++) { dat = (pcjr->vram[((pcjr->ma << 1) & mask) + offset] << 8) | pcjr->vram[((pcjr->ma << 1) & mask) + offset + 1]; pcjr->ma++; - buffer32->line[(pcjr->displine << 1)][(x << 4) + 8] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 9] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 10] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 11] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 9] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 10] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 11] = pcjr->array[((dat >> 12) & pcjr->array[1]) + 16] + 16; - buffer32->line[(pcjr->displine << 1)][(x << 4) + 12] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 13] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 14] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 15] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 12] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 13] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 14] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 15] = pcjr->array[((dat >> 8) & pcjr->array[1]) + 16] + 16; - buffer32->line[(pcjr->displine << 1)][(x << 4) + 16] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 17] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 18] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 19] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 16] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 17] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 18] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 19] = pcjr->array[((dat >> 4) & pcjr->array[1]) + 16] + 16; - buffer32->line[(pcjr->displine << 1)][(x << 4) + 20] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 21] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 22] = buffer32->line[(pcjr->displine << 1)][(x << 4) + 23] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 20] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 21] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 22] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 23] = pcjr->array[(dat & pcjr->array[1]) + 16] + 16; + buffer32->line[pcjr->displine << 1][(x << 4) + 8] = buffer32->line[pcjr->displine << 1][(x << 4) + 9] = buffer32->line[pcjr->displine << 1][(x << 4) + 10] = buffer32->line[pcjr->displine << 1][(x << 4) + 11] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 9] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 10] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 11] = pcjr->array[((dat >> 12) & pcjr->array[1]) + 16] + 16; + buffer32->line[pcjr->displine << 1][(x << 4) + 12] = buffer32->line[pcjr->displine << 1][(x << 4) + 13] = buffer32->line[pcjr->displine << 1][(x << 4) + 14] = buffer32->line[pcjr->displine << 1][(x << 4) + 15] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 12] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 13] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 14] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 15] = pcjr->array[((dat >> 8) & pcjr->array[1]) + 16] + 16; + buffer32->line[pcjr->displine << 1][(x << 4) + 16] = buffer32->line[pcjr->displine << 1][(x << 4) + 17] = buffer32->line[pcjr->displine << 1][(x << 4) + 18] = buffer32->line[pcjr->displine << 1][(x << 4) + 19] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 16] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 17] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 18] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 19] = pcjr->array[((dat >> 4) & pcjr->array[1]) + 16] + 16; + buffer32->line[pcjr->displine << 1][(x << 4) + 20] = buffer32->line[pcjr->displine << 1][(x << 4) + 21] = buffer32->line[pcjr->displine << 1][(x << 4) + 22] = buffer32->line[pcjr->displine << 1][(x << 4) + 23] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 20] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 21] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 22] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + 23] = pcjr->array[(dat & pcjr->array[1]) + 16] + 16; } break; case 0x03: /*640x200x4*/ @@ -311,7 +317,7 @@ vid_poll(void *p) for (c = 0; c < 8; c++) { chr = (dat >> 7) & 1; chr |= ((dat >> 14) & 2); - buffer32->line[(pcjr->displine << 1)][(x << 3) + 8 + c] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 8 + c] = pcjr->array[(chr & pcjr->array[1]) + 16] + 16; + buffer32->line[pcjr->displine << 1][(x << 3) + 8 + c] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 8 + c] = pcjr->array[(chr & pcjr->array[1]) + 16] + 16; dat <<= 1; } } @@ -332,16 +338,16 @@ vid_poll(void *p) } if (pcjr->sc & 8) { for (c = 0; c < 8; c++) { - buffer32->line[(pcjr->displine << 1)][(x << 3) + c + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + c + 8] = cols[0]; + buffer32->line[pcjr->displine << 1][(x << 3) + c + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + c + 8] = cols[0]; } } else { for (c = 0; c < 8; c++) { - buffer32->line[(pcjr->displine << 1)][(x << 3) + c + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[chr][pcjr->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; + buffer32->line[pcjr->displine << 1][(x << 3) + c + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[chr][pcjr->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; } } if (drawcursor) { for (c = 0; c < 8; c++) { - buffer32->line[(pcjr->displine << 1)][(x << 3) + c + 8] ^= 15; + buffer32->line[pcjr->displine << 1][(x << 3) + c + 8] ^= 15; buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + c + 8] ^= 15; } } @@ -365,11 +371,11 @@ vid_poll(void *p) pcjr->ma++; if (pcjr->sc & 8) { for (c = 0; c < 8; c++) { - buffer32->line[(pcjr->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[0]; + buffer32->line[pcjr->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[0]; } } else { for (c = 0; c < 8; c++) { - buffer32->line[(pcjr->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[chr][pcjr->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; + buffer32->line[(pcjr->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[pcjr->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[chr][pcjr->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; } } if (drawcursor) { @@ -633,14 +639,16 @@ kbd_read(uint16_t port, void *priv) break; } - return (ret); + return ret; } static void kbd_poll(void *priv) { pcjr_t *pcjr = (pcjr_t *) priv; - int c, p = 0, key; + int c; + int p = 0; + int key; timer_advance_u64(&pcjr->send_delay_timer, 220 * TIMER_USEC); diff --git a/src/machine/m_ps1.c b/src/machine/m_ps1.c index d002ba6bd..e3675e74b 100644 --- a/src/machine/m_ps1.c +++ b/src/machine/m_ps1.c @@ -233,7 +233,7 @@ ps1_read(uint16_t port, void *priv) break; } - return (ret); + return ret; } static void diff --git a/src/machine/m_ps1_hdc.c b/src/machine/m_ps1_hdc.c index 4355a0ad6..bd0c8851d 100644 --- a/src/machine/m_ps1_hdc.c +++ b/src/machine/m_ps1_hdc.c @@ -502,15 +502,14 @@ static int ibm_drive_type(drive_t *drive) { const geom_t *ptr; - int i; - for (i = 0; i < (sizeof(ibm_type_table) / sizeof(geom_t)); i++) { + for (uint16_t i = 0; i < (sizeof(ibm_type_table) / sizeof(geom_t)); i++) { ptr = &ibm_type_table[i]; if ((drive->tracks == ptr->cyl) && (drive->hpc == ptr->hpc) && (drive->spt == ptr->spt)) - return (i); + return i; } - return (HDC_TYPE_USER); + return HDC_TYPE_USER; } static void @@ -534,25 +533,25 @@ get_sector(hdc_t *dev, drive_t *drive, off64_t *addr) ps1_hdc_log("HDC: get_sector: wrong cylinder %d/%d\n", drive->cur_cyl, dev->track); dev->ssb.wrong_cyl = 1; - return (1); + return 1; } if (dev->head >= drive->hpc) { ps1_hdc_log("HDC: get_sector: past end of heads\n"); dev->ssb.cylinder_err = 1; - return (1); + return 1; } if (dev->sector > drive->spt) { ps1_hdc_log("HDC: get_sector: past end of sectors\n"); dev->ssb.mark_not_found = 1; - return (1); + return 1; } /* Calculate logical address (block number) of desired sector. */ *addr = ((((off64_t) dev->track * drive->hpc) + dev->head) * drive->spt) + dev->sector - 1; - return (0); + return 0; } static void @@ -590,13 +589,13 @@ do_seek(hdc_t *dev, drive_t *drive, uint16_t cyl) { if (cyl >= drive->tracks) { dev->ssb.cylinder_err = 1; - return (1); + return 1; } dev->track = cyl; drive->cur_cyl = dev->track; - return (0); + return 0; } /* Format a track or an entire drive. */ @@ -1128,7 +1127,7 @@ hdc_read(uint16_t port, void *priv) break; } - return (ret); + return ret; } static void @@ -1240,7 +1239,7 @@ ps1_hdc_init(const device_t *info) { drive_t *drive; hdc_t *dev; - int c, i; + int c; /* Allocate and initialize device block. */ dev = malloc(sizeof(hdc_t)); @@ -1256,7 +1255,7 @@ ps1_hdc_init(const device_t *info) /* Load any disks for this device class. */ c = 0; - for (i = 0; i < HDD_NUM; i++) { + for (uint8_t i = 0; i < HDD_NUM; i++) { if ((hdd[i].bus == HDD_BUS_XTA) && (hdd[i].xta_channel < 1)) { drive = &dev->drives[hdd[i].xta_channel]; @@ -1299,7 +1298,7 @@ ps1_hdc_init(const device_t *info) /* Create a timer for command delays. */ timer_add(&dev->timer, hdc_callback, dev, 0); - return (dev); + return dev; } static void @@ -1307,14 +1306,13 @@ ps1_hdc_close(void *priv) { hdc_t *dev = (hdc_t *) priv; drive_t *drive; - int d; /* Remove the I/O handler. */ io_removehandler(dev->base, 5, hdc_read, NULL, NULL, hdc_write, NULL, NULL, dev); /* Close all disks and their images. */ - for (d = 0; d < XTA_NUM; d++) { + for (uint8_t d = 0; d < XTA_NUM; d++) { drive = &dev->drives[d]; if (drive->present) diff --git a/src/machine/m_ps2_mca.c b/src/machine/m_ps2_mca.c index 8eb6565fc..c43f7ef9b 100644 --- a/src/machine/m_ps2_mca.c +++ b/src/machine/m_ps2_mca.c @@ -398,12 +398,14 @@ model_50_write(uint16_t port, uint8_t val) static void model_55sx_mem_recalc(void) { - int i, j, state; + int state; #ifdef ENABLE_PS2_MCA_LOG int enabled_mem = 0; #endif - int base = 0, remap_size = (ps2.option[3] & 0x10) ? 384 : 256; - int bit_mask = 0x00, max_rows = 4; + int base = 0; + int remap_size = (ps2.option[3] & 0x10) ? 384 : 256; + int bit_mask = 0x00; + int max_rows = 4; int bank_to_rows[16] = { 4, 2, 1, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 2, 1, 0 }; ps2_mca_log("%02X %02X\n", ps2.option[1], ps2.option[3]); @@ -412,13 +414,13 @@ model_55sx_mem_recalc(void) mem_set_mem_state(0x00000000, (mem_size + 384) * 1024, MEM_READ_EXTERNAL | MEM_WRITE_EXTERNAL); mem_set_mem_state(0x000e0000, 0x00020000, MEM_READ_EXTANY | MEM_WRITE_DISABLED); - for (i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 2; i++) { max_rows = bank_to_rows[(ps2.memory_bank[i] >> 4) & 0x0f]; if (max_rows == 0) continue; - for (j = 0; j < max_rows; j++) { + for (int j = 0; j < max_rows; j++) { if (ps2.memory_bank[i] & (1 << j)) { ps2_mca_log("Set memory at %06X-%06X to internal\n", (base * 1024), (base * 1024) + (((base > 0) ? 1024 : 640) * 1024) - 1); mem_set_mem_state(base * 1024, ((base > 0) ? 1024 : 640) * 1024, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); @@ -850,7 +852,8 @@ ps2_mem_expansion_feedb(void *p) static void ps2_mca_mem_fffc_init(int start_mb) { - uint32_t planar_size, expansion_start; + uint32_t planar_size; + uint32_t expansion_start; planar_size = (start_mb - 1) << 20; expansion_start = start_mb << 20; @@ -906,7 +909,8 @@ ps2_mca_mem_fffc_init(int start_mb) static void ps2_mca_mem_d071_init(int start_mb) { - uint32_t planar_size, expansion_start; + uint32_t planar_size; + uint32_t expansion_start; planar_size = (start_mb - 1) << 20; expansion_start = start_mb << 20; @@ -1212,7 +1216,7 @@ ps2_mca_board_model_70_type34_init(int is_type4, int slots) mem_mapping_add(&ps2.cache_mapping, 0, - (is_type4) ? (8 * 1024) : (64 * 1024), + is_type4 ? (8 * 1024) : (64 * 1024), ps2_read_cache_ram, ps2_read_cache_ramw, ps2_read_cache_raml, diff --git a/src/machine/m_tandy.c b/src/machine/m_tandy.c index 04f5e5381..24ecc654a 100644 --- a/src/machine/m_tandy.c +++ b/src/machine/m_tandy.c @@ -448,7 +448,9 @@ recalc_timings(tandy_t *dev) { t1kvid_t *vid = dev->vid; - double _dispontime, _dispofftime, disptime; + double _dispontime; + double _dispofftime; + double disptime; if (vid->mode & 1) { disptime = vid->crtc[0] + 1; @@ -598,7 +600,7 @@ vid_in(uint16_t addr, void *priv) break; } - return (ret); + return ret; } static void @@ -629,7 +631,7 @@ vid_read(uint32_t addr, void *priv) t1kvid_t *vid = dev->vid; if (vid->memctrl == -1) - return (0xff); + return 0xff; if (dev->is_sl2) { if (vid->array[5] & 1) @@ -637,7 +639,7 @@ vid_read(uint32_t addr, void *priv) if ((addr & 0x7fff) < vid->b8000_limit) return (vid->b8000[addr & 0x7fff]); else - return (0xff); + return 0xff; } else { return (vid->b8000[addr & vid->b8000_mask]); } @@ -650,9 +652,13 @@ vid_poll(void *priv) t1kvid_t *vid = dev->vid; uint16_t ca = (vid->crtc[15] | (vid->crtc[14] << 8)) & 0x3fff; int drawcursor; - int x, c, xs_temp, ys_temp; + int x; + int c; + int xs_temp; + int ys_temp; int oldvc; - uint8_t chr, attr; + uint8_t chr; + uint8_t attr; uint16_t dat; int cols[4]; int col; @@ -674,25 +680,25 @@ vid_poll(void *priv) cols[0] = (vid->array[2] & 0xf) + 16; for (c = 0; c < 8; c++) { if (vid->array[3] & 4) { - buffer32->line[(vid->displine << 1)][c] = buffer32->line[(vid->displine << 1) + 1][c] = cols[0]; + buffer32->line[vid->displine << 1][c] = buffer32->line[(vid->displine << 1) + 1][c] = cols[0]; if (vid->mode & 1) { - buffer32->line[(vid->displine << 1)][c + (vid->crtc[1] << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 3) + 8] = cols[0]; + buffer32->line[vid->displine << 1][c + (vid->crtc[1] << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 3) + 8] = cols[0]; } else { - buffer32->line[(vid->displine << 1)][c + (vid->crtc[1] << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 4) + 8] = cols[0]; + buffer32->line[vid->displine << 1][c + (vid->crtc[1] << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 4) + 8] = cols[0]; } } else if ((vid->mode & 0x12) == 0x12) { - buffer32->line[(vid->displine << 1)][c] = buffer32->line[(vid->displine << 1) + 1][c] = 0; + buffer32->line[vid->displine << 1][c] = buffer32->line[(vid->displine << 1) + 1][c] = 0; if (vid->mode & 1) { - buffer32->line[(vid->displine << 1)][c + (vid->crtc[1] << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 3) + 8] = 0; + buffer32->line[vid->displine << 1][c + (vid->crtc[1] << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 3) + 8] = 0; } else { - buffer32->line[(vid->displine << 1)][c + (vid->crtc[1] << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 4) + 8] = 0; + buffer32->line[vid->displine << 1][c + (vid->crtc[1] << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 4) + 8] = 0; } } else { - buffer32->line[(vid->displine << 1)][c] = buffer32->line[(vid->displine << 1) + 1][c] = (vid->col & 15) + 16; + buffer32->line[vid->displine << 1][c] = buffer32->line[(vid->displine << 1) + 1][c] = (vid->col & 15) + 16; if (vid->mode & 1) { buffer32->line[(vid->displine << 1)][c + (vid->crtc[1] << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 3) + 8] = (vid->col & 15) + 16; } else { - buffer32->line[(vid->displine << 1)][c + (vid->crtc[1] << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 4) + 8] = (vid->col & 15) + 16; + buffer32->line[vid->displine << 1][c + (vid->crtc[1] << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][c + (vid->crtc[1] << 4) + 8] = (vid->col & 15) + 16; } } } @@ -700,19 +706,19 @@ vid_poll(void *priv) for (x = 0; x < vid->crtc[1] * 2; x++) { dat = (vid->vram[(vid->ma << 1) & 0xffff] << 8) | vid->vram[((vid->ma << 1) + 1) & 0xffff]; vid->ma++; - buffer32->line[(vid->displine << 1)][(x << 2) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 2) + 8] = vid->array[((dat >> 12) & 0xf) + 16] + 16; - buffer32->line[(vid->displine << 1)][(x << 2) + 9] = buffer32->line[(vid->displine << 1) + 1][(x << 2) + 9] = vid->array[((dat >> 8) & 0xf) + 16] + 16; - buffer32->line[(vid->displine << 1)][(x << 2) + 10] = buffer32->line[(vid->displine << 1) + 1][(x << 2) + 10] = vid->array[((dat >> 4) & 0xf) + 16] + 16; - buffer32->line[(vid->displine << 1)][(x << 2) + 11] = buffer32->line[(vid->displine << 1) + 1][(x << 2) + 11] = vid->array[(dat & 0xf) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 2) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 2) + 8] = vid->array[((dat >> 12) & 0xf) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 2) + 9] = buffer32->line[(vid->displine << 1) + 1][(x << 2) + 9] = vid->array[((dat >> 8) & 0xf) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 2) + 10] = buffer32->line[(vid->displine << 1) + 1][(x << 2) + 10] = vid->array[((dat >> 4) & 0xf) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 2) + 11] = buffer32->line[(vid->displine << 1) + 1][(x << 2) + 11] = vid->array[(dat & 0xf) + 16] + 16; } } else if ((vid->array[3] & 0x10) && (vid->mode & 1)) { /*320x200x16*/ for (x = 0; x < vid->crtc[1]; x++) { dat = (vid->vram[((vid->ma << 1) & 0x1fff) + ((vid->sc & 3) * 0x2000)] << 8) | vid->vram[((vid->ma << 1) & 0x1fff) + ((vid->sc & 3) * 0x2000) + 1]; vid->ma++; - buffer32->line[(vid->displine << 1)][(x << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 8] = buffer32->line[(vid->displine << 1)][(x << 3) + 9] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 9] = vid->array[((dat >> 12) & vid->array[1]) + 16] + 16; - buffer32->line[(vid->displine << 1)][(x << 3) + 10] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 10] = buffer32->line[(vid->displine << 1)][(x << 3) + 11] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 11] = vid->array[((dat >> 8) & vid->array[1]) + 16] + 16; - buffer32->line[(vid->displine << 1)][(x << 3) + 12] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 12] = buffer32->line[(vid->displine << 1)][(x << 3) + 13] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 13] = vid->array[((dat >> 4) & vid->array[1]) + 16] + 16; - buffer32->line[(vid->displine << 1)][(x << 3) + 14] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 14] = buffer32->line[(vid->displine << 1)][(x << 3) + 15] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 15] = vid->array[(dat & vid->array[1]) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 3) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 8] = buffer32->line[vid->displine << 1][(x << 3) + 9] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 9] = vid->array[((dat >> 12) & vid->array[1]) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 3) + 10] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 10] = buffer32->line[vid->displine << 1][(x << 3) + 11] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 11] = vid->array[((dat >> 8) & vid->array[1]) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 3) + 12] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 12] = buffer32->line[vid->displine << 1][(x << 3) + 13] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 13] = vid->array[((dat >> 4) & vid->array[1]) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 3) + 14] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 14] = buffer32->line[vid->displine << 1][(x << 3) + 15] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 15] = vid->array[(dat & vid->array[1]) + 16] + 16; } } else if (vid->array[3] & 0x10) { /*160x200x16*/ for (x = 0; x < vid->crtc[1]; x++) { @@ -722,10 +728,10 @@ vid_poll(void *priv) dat = (vid->vram[((vid->ma << 1) & 0x1fff) + ((vid->sc & 3) * 0x2000)] << 8) | vid->vram[((vid->ma << 1) & 0x1fff) + ((vid->sc & 3) * 0x2000) + 1]; } vid->ma++; - buffer32->line[(vid->displine << 1)][(x << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 8] = buffer32->line[(vid->displine << 1)][(x << 4) + 9] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 9] = buffer32->line[(vid->displine << 1)][(x << 4) + 10] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 10] = buffer32->line[(vid->displine << 1)][(x << 4) + 11] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 11] = vid->array[((dat >> 12) & vid->array[1]) + 16] + 16; - buffer32->line[(vid->displine << 1)][(x << 4) + 12] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 12] = buffer32->line[(vid->displine << 1)][(x << 4) + 13] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 13] = buffer32->line[(vid->displine << 1)][(x << 4) + 14] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 14] = buffer32->line[(vid->displine << 1)][(x << 4) + 15] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 15] = vid->array[((dat >> 8) & vid->array[1]) + 16] + 16; - buffer32->line[(vid->displine << 1)][(x << 4) + 16] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 16] = buffer32->line[(vid->displine << 1)][(x << 4) + 17] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 17] = buffer32->line[(vid->displine << 1)][(x << 4) + 18] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 18] = buffer32->line[(vid->displine << 1)][(x << 4) + 19] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 19] = vid->array[((dat >> 4) & vid->array[1]) + 16] + 16; - buffer32->line[(vid->displine << 1)][(x << 4) + 20] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 20] = buffer32->line[(vid->displine << 1)][(x << 4) + 21] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 21] = buffer32->line[(vid->displine << 1)][(x << 4) + 22] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 22] = buffer32->line[(vid->displine << 1)][(x << 4) + 23] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 23] = vid->array[(dat & vid->array[1]) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 4) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 8] = buffer32->line[vid->displine << 1][(x << 4) + 9] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 9] = buffer32->line[vid->displine << 1][(x << 4) + 10] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 10] = buffer32->line[vid->displine << 1][(x << 4) + 11] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 11] = vid->array[((dat >> 12) & vid->array[1]) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 4) + 12] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 12] = buffer32->line[vid->displine << 1][(x << 4) + 13] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 13] = buffer32->line[vid->displine << 1][(x << 4) + 14] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 14] = buffer32->line[vid->displine << 1][(x << 4) + 15] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 15] = vid->array[((dat >> 8) & vid->array[1]) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 4) + 16] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 16] = buffer32->line[vid->displine << 1][(x << 4) + 17] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 17] = buffer32->line[vid->displine << 1][(x << 4) + 18] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 18] = buffer32->line[vid->displine << 1][(x << 4) + 19] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 19] = vid->array[((dat >> 4) & vid->array[1]) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 4) + 20] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 20] = buffer32->line[vid->displine << 1][(x << 4) + 21] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 21] = buffer32->line[vid->displine << 1][(x << 4) + 22] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 22] = buffer32->line[vid->displine << 1][(x << 4) + 23] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + 23] = vid->array[(dat & vid->array[1]) + 16] + 16; } } else if (vid->array[3] & 0x08) { /*640x200x4 - this implementation is a complete guess!*/ for (x = 0; x < vid->crtc[1]; x++) { @@ -734,7 +740,7 @@ vid_poll(void *priv) for (c = 0; c < 8; c++) { chr = (dat >> 6) & 2; chr |= ((dat >> 15) & 1); - buffer32->line[(vid->displine << 1)][(x << 3) + 8 + c] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 8 + c] = vid->array[(chr & vid->array[1]) + 16] + 16; + buffer32->line[vid->displine << 1][(x << 3) + 8 + c] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + 8 + c] = vid->array[(chr & vid->array[1]) + 16] + 16; dat <<= 1; } } @@ -754,14 +760,14 @@ vid_poll(void *priv) } if (vid->sc & 8) { for (c = 0; c < 8; c++) { - buffer32->line[(vid->displine << 1)][(x << 3) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] = cols[0]; + buffer32->line[vid->displine << 1][(x << 3) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] = cols[0]; } } else { for (c = 0; c < 8; c++) { if (vid->sc == 8) { - buffer32->line[(vid->displine << 1)][(x << 3) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[chr][7] & (1 << (c ^ 7))) ? 1 : 0]; + buffer32->line[vid->displine << 1][(x << 3) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[chr][7] & (1 << (c ^ 7))) ? 1 : 0]; } else { - buffer32->line[(vid->displine << 1)][(x << 3) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; + buffer32->line[vid->displine << 1][(x << 3) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; } } } @@ -1239,7 +1245,7 @@ eep_init(const device_t *info) io_sethandler(0x037c, 1, NULL, NULL, NULL, eep_write, NULL, NULL, eep); - return (eep); + return eep; } static void @@ -1336,7 +1342,7 @@ tandy_read(uint16_t addr, void *priv) break; } - return (ret); + return ret; } static void @@ -1479,7 +1485,7 @@ machine_tandy1k_init(const machine_t *model, int type) int tandy1k_eeprom_read(void) { - return (eep_data_out); + return eep_data_out; } int diff --git a/src/machine/m_v86p.c b/src/machine/m_v86p.c index af90ab629..62b6e4834 100644 --- a/src/machine/m_v86p.c +++ b/src/machine/m_v86p.c @@ -51,7 +51,8 @@ int machine_v86p_init(const machine_t *model) { - int ret, rom = 0; + int ret; + int rom = 0; ret = bios_load_interleavedr("roms/machines/v86p/INTEL8086AWD_BIOS_S3.1_V86P_122089_Even.rom", "roms/machines/v86p/INTEL8086AWD_BIOS_S3.1_V86P_122089_Odd.rom", diff --git a/src/machine/m_xt.c b/src/machine/m_xt.c index b8d318438..84eb517c8 100644 --- a/src/machine/m_xt.c +++ b/src/machine/m_xt.c @@ -67,7 +67,8 @@ machine_pc_init(const machine_t *model) int machine_pc82_init(const machine_t *model) { - int ret, ret2; + int ret; + int ret2; ret = bios_load_linear("roms/machines/ibmpc82/pc102782.bin", 0x000fe000, 40960, 0); diff --git a/src/machine/m_xt_laserxt.c b/src/machine/m_xt_laserxt.c index 418835a0b..59db0cbe0 100644 --- a/src/machine/m_xt_laserxt.c +++ b/src/machine/m_xt_laserxt.c @@ -39,8 +39,8 @@ get_laserxt_ems_addr(uint32_t addr) static void laserxt_write(uint16_t port, uint8_t val, void *priv) { - int i; - uint32_t paddr, vaddr; + uint32_t paddr; + uint32_t vaddr; switch (port) { case 0x0208: case 0x4208: @@ -63,7 +63,7 @@ laserxt_write(uint16_t port, uint8_t val, void *priv) case 0xC209: laserxt_emscontrol[port >> 14] = val; laserxt_ems_baseaddr_index = 0; - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { laserxt_ems_baseaddr_index |= (laserxt_emscontrol[i] & 0x80) >> (7 - i); } @@ -116,8 +116,6 @@ mem_read_laserxtems(uint32_t addr, void *priv) static void laserxt_init(int is_lxt3) { - int i; - if (mem_size > 640) { io_sethandler(0x0208, 0x0002, laserxt_read, NULL, NULL, laserxt_write, NULL, NULL, NULL); io_sethandler(0x4208, 0x0002, laserxt_read, NULL, NULL, laserxt_write, NULL, NULL, NULL); @@ -126,7 +124,7 @@ laserxt_init(int is_lxt3) mem_mapping_set_addr(&ram_low_mapping, 0, !is_lxt3 ? 0x70000 + (((mem_size + 64) & 255) << 10) : 0x30000 + (((mem_size + 320) & 511) << 10)); } - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { laserxt_emspage[i] = 0x7F; laserxt_emscontrol[i] = (i == 3) ? 0x00 : 0x80; mem_mapping_add(&laserxt_ems_mapping[i], 0xE0000 + (i << 14), 0x4000, mem_read_laserxtems, NULL, NULL, mem_write_laserxtems, NULL, NULL, ram + 0xA0000 + (i << 14), 0, NULL); diff --git a/src/machine/m_xt_olivetti.c b/src/machine/m_xt_olivetti.c index e9c24f88f..4d6522295 100644 --- a/src/machine/m_xt_olivetti.c +++ b/src/machine/m_xt_olivetti.c @@ -141,8 +141,8 @@ typedef struct { } m19_vid_t; static uint8_t key_queue[16]; -static int key_queue_start = 0, - key_queue_end = 0; +static int key_queue_start = 0; +static int key_queue_end = 0; video_timings_t timing_m19_vid = { VIDEO_ISA, 8, 16, 32, 8, 16, 32 }; @@ -346,7 +346,7 @@ mm58274_time_set(uint8_t *regs, struct tm *tm) regs[MM58274_HOUR10] = (tm->tm_hour / 10); } else { regs[MM58274_HOUR1] = ((tm->tm_hour % 12) % 10); - regs[MM58274_HOUR10] = (((tm->tm_hour % 12) / 10)); + regs[MM58274_HOUR10] = ((tm->tm_hour % 12) / 10); if (tm->tm_hour >= 12) regs[MM58274_SETTINGS] |= 0x04; else @@ -419,7 +419,7 @@ mm58274_write(uint16_t addr, uint8_t val, void *priv) val &= 0x0f; /* Update non-read-only changed values if not synchronizing time to host */ - if ((addr != MM58274_TENTHS)) + if (addr != MM58274_TENTHS) if ((nvr->regs[addr] != val) && !(time_sync & TIME_SYNC_ENABLED)) nvr_dosave = 1; @@ -680,7 +680,7 @@ m24_kbd_read(uint16_t port, void *priv) xt_olivetti_log("\nBad M24 keyboard read %04X\n", port); } - return (ret); + return ret; } static void @@ -733,7 +733,7 @@ ms_poll(int x, int y, int z, int b, void *priv) m24_kbd->y += y; if (((key_queue_end - key_queue_start) & 0xf) > 14) - return (0xff); + return 0xff; if ((b & 1) && !(m24_kbd->b & 1)) m24_kbd_adddata(m24_kbd->scan[0]); @@ -742,7 +742,7 @@ ms_poll(int x, int y, int z, int b, void *priv) m24_kbd->b = (m24_kbd->b & ~1) | (b & 1); if (((key_queue_end - key_queue_start) & 0xf) > 14) - return (0xff); + return 0xff; if ((b & 2) && !(m24_kbd->b & 2)) m24_kbd_adddata(m24_kbd->scan[2]); @@ -751,7 +751,7 @@ ms_poll(int x, int y, int z, int b, void *priv) m24_kbd->b = (m24_kbd->b & ~2) | (b & 2); if (((key_queue_end - key_queue_start) & 0xf) > 14) - return (0xff); + return 0xff; if ((b & 4) && !(m24_kbd->b & 4)) m24_kbd_adddata(m24_kbd->scan[1]); @@ -761,10 +761,10 @@ ms_poll(int x, int y, int z, int b, void *priv) if (m24_kbd->mouse_mode) { if (((key_queue_end - key_queue_start) & 0xf) > 12) - return (0xff); + return 0xff; if (!m24_kbd->x && !m24_kbd->y) - return (0xff); + return 0xff; m24_kbd->y = -m24_kbd->y; @@ -790,31 +790,31 @@ ms_poll(int x, int y, int z, int b, void *priv) } else { while (m24_kbd->x < -4) { if (((key_queue_end - key_queue_start) & 0xf) > 14) - return (0xff); + return 0xff; m24_kbd->x += 4; m24_kbd_adddata(m24_kbd->scan[3]); } while (m24_kbd->x > 4) { if (((key_queue_end - key_queue_start) & 0xf) > 14) - return (0xff); + return 0xff; m24_kbd->x -= 4; m24_kbd_adddata(m24_kbd->scan[4]); } while (m24_kbd->y < -4) { if (((key_queue_end - key_queue_start) & 0xf) > 14) - return (0xff); + return 0xff; m24_kbd->y += 4; m24_kbd_adddata(m24_kbd->scan[5]); } while (m24_kbd->y > 4) { if (((key_queue_end - key_queue_start) & 0xf) > 14) - return (0xff); + return 0xff; m24_kbd->y -= 4; m24_kbd_adddata(m24_kbd->scan[6]); } } - return (0); + return 0; } /* Remapping as follows: @@ -1604,8 +1604,8 @@ const device_t m19_vid_device = { static uint8_t m24_read(uint16_t port, void *priv) { - uint8_t ret = 0x00; - int i, fdd_count = 0; + uint8_t ret = 0x00; + int fdd_count = 0; switch (port) { case 0x62: @@ -1674,7 +1674,7 @@ m24_read(uint16_t port, void *priv) * on on EGA/VGA (works only for BIOS ROM 1.43) */ case 0x67: - for (i = 0; i < FDD_NUM; i++) { + for (uint8_t i = 0; i < FDD_NUM; i++) { if (fdd_get_flags(i)) fdd_count++; } @@ -1708,14 +1708,14 @@ m24_read(uint16_t port, void *priv) break; } - return (ret); + return ret; } static uint8_t m240_read(uint16_t port, void *priv) { uint8_t ret = 0x00; - int i, fdd_count = 0; + int fdd_count = 0; switch (port) { case 0x62: @@ -1723,7 +1723,7 @@ m240_read(uint16_t port, void *priv) ret = 0x00; if (ppi.pb & 0x8) { /* Switches 4, 5 - floppy drives (number) */ - for (i = 0; i < FDD_NUM; i++) { + for (uint8_t i = 0; i < FDD_NUM; i++) { if (fdd_get_flags(i)) fdd_count++; } @@ -1763,7 +1763,7 @@ m240_read(uint16_t port, void *priv) break; } - return (ret); + return ret; } /* @@ -1802,7 +1802,7 @@ machine_xt_m24_init(const machine_t *model) /* Allocate an NVR for this machine. */ nvr = (nvr_t *) malloc(sizeof(nvr_t)); if (nvr == NULL) - return (0); + return 0; memset(nvr, 0x00, sizeof(nvr_t)); mm58174_init(nvr, model->nvrmask + 1); @@ -1876,7 +1876,7 @@ machine_xt_m240_init(const machine_t *model) /* Allocate an NVR for this machine. */ nvr = (nvr_t *) malloc(sizeof(nvr_t)); if (nvr == NULL) - return (0); + return 0; memset(nvr, 0x00, sizeof(nvr_t)); mm58274_init(nvr, model->nvrmask + 1); diff --git a/src/machine/m_xt_t1000.c b/src/machine/m_xt_t1000.c index f632003ac..755840599 100644 --- a/src/machine/m_xt_t1000.c +++ b/src/machine/m_xt_t1000.c @@ -339,9 +339,9 @@ static uint32_t ems_execaddr(t1000_t *sys, int pg, uint16_t val) { if (!(val & 0x80)) - return (0); /* Bit 7 reset => not mapped */ + return 0; /* Bit 7 reset => not mapped */ if (!sys->ems_pages) - return (0); /* No EMS available: all used by + return 0; /* No EMS available: all used by * HardRAM or conventional RAM */ val &= 0x7f; @@ -354,7 +354,7 @@ ems_execaddr(t1000_t *sys, int pg, uint16_t val) return ((512 * 1024) + (sys->ems_base * 0x10000) + (0x4000 * val)); } - return (0); + return 0; } static uint8_t @@ -392,8 +392,6 @@ ems_out(uint16_t addr, uint8_t val, void *priv) static void ems_set_hardram(t1000_t *sys, uint8_t val) { - int n; - val &= 0x1f; /* Mask off pageframe address */ if (val && mem_size > 512) sys->ems_base = val; @@ -408,7 +406,7 @@ ems_set_hardram(t1000_t *sys, uint8_t val) sys->ems_pages = 0; /* Recalculate EMS mappings */ - for (n = 0; n < 4; n++) + for (uint8_t n = 0; n < 4; n++) ems_out(n << 14, sys->ems_reg[n], sys); } @@ -473,7 +471,7 @@ ems_read_ram(uint32_t addr, void *priv) int pg = addr_to_page(addr); if (pg < 0) - return (0xff); + return 0xff; addr = sys->page_exec[pg] + (addr & 0x3fff); return (ram[addr]); @@ -486,7 +484,7 @@ ems_read_ramw(uint32_t addr, void *priv) int pg = addr_to_page(addr); if (pg < 0) - return (0xff); + return 0xff; #if 0 t1000_log("ems_read_ramw addr=%05x ", addr); @@ -507,7 +505,7 @@ ems_read_raml(uint32_t addr, void *priv) int pg = addr_to_page(addr); if (pg < 0) - return (0xff); + return 0xff; addr = sys->page_exec[pg] + (addr & 0x3fff); return (*(uint32_t *) &ram[addr]); @@ -604,7 +602,7 @@ read_ctl(uint16_t addr, void *priv) ret = (sys->sys_ctl[addr & 0x0f]); } - return (ret); + return ret; } static void @@ -693,7 +691,7 @@ t1000_read_nvram(uint16_t addr, void *priv) break; } - return (tmp); + return tmp; } static void @@ -790,7 +788,7 @@ t1000_read_rom(uint32_t addr, void *priv) t1000_t *sys = (t1000_t *) priv; if (!sys->romdrive) - return (0xff); + return 0xff; return (sys->romdrive[sys->rom_offset + (addr & 0xffff)]); } @@ -801,7 +799,7 @@ t1000_read_romw(uint32_t addr, void *priv) t1000_t *sys = (t1000_t *) priv; if (!sys->romdrive) - return (0xffff); + return 0xffff; return (*(uint16_t *) (&sys->romdrive[sys->rom_offset + (addr & 0xffff)])); } @@ -812,7 +810,7 @@ t1000_read_roml(uint32_t addr, void *priv) t1000_t *sys = (t1000_t *) priv; if (!sys->romdrive) - return (0xffffffff); + return 0xffffffff; return (*(uint32_t *) (&sys->romdrive[sys->rom_offset + (addr & 0xffff)])); } @@ -821,8 +819,6 @@ int machine_xt_t1000_init(const machine_t *model) { FILE *f; - int pg; - int ret; ret = bios_load_linear("roms/machines/t1000/t1000.rom", @@ -861,7 +857,7 @@ machine_xt_t1000_init(const machine_t *model) mem_mapping_disable(&t1000.rom_mapping); /* Map the EMS page frame */ - for (pg = 0; pg < 4; pg++) { + for (uint8_t pg = 0; pg < 4; pg++) { mem_mapping_add(&t1000.mapping[pg], 0xd0000 + (0x4000 * pg), 16384, ems_read_ram, ems_read_ramw, ems_read_raml, ems_write_ram, ems_write_ramw, ems_write_raml, @@ -906,8 +902,6 @@ machine_xt_t1000_init(const machine_t *model) int machine_xt_t1200_init(const machine_t *model) { - int pg; - int ret; ret = bios_load_linear("roms/machines/t1200/t1200_019e.ic15.bin", @@ -924,7 +918,7 @@ machine_xt_t1200_init(const machine_t *model) loadfont("roms/machines/t1000/t1000font.bin", 2); /* Map the EMS page frame */ - for (pg = 0; pg < 4; pg++) { + for (uint8_t pg = 0; pg < 4; pg++) { mem_mapping_add(&t1000.mapping[pg], 0xd0000 + (0x4000 * pg), 16384, ems_read_ram, ems_read_ramw, ems_read_raml, diff --git a/src/machine/m_xt_t1000_vid.c b/src/machine/m_xt_t1000_vid.c index 48c00d3c3..45a15649d 100644 --- a/src/machine/m_xt_t1000_vid.c +++ b/src/machine/m_xt_t1000_vid.c @@ -231,8 +231,9 @@ static void t1000_text_row80(t1000_t *t1000) { uint32_t cols[2]; - int x, c; - uint8_t chr, attr; + int c; + uint8_t chr; + uint8_t attr; int drawcursor; int cursorline; int bold; @@ -251,7 +252,7 @@ t1000_text_row80(t1000_t *t1000) } else { cursorline = ((t1000->cga.crtc[10] & 0x0F) <= sc) && ((t1000->cga.crtc[11] & 0x0F) >= sc); } - for (x = 0; x < 80; x++) { + for (uint8_t x = 0; x < 80; x++) { chr = t1000->vram[(addr + 2 * x) & 0x3FFF]; attr = t1000->vram[(addr + 2 * x + 1) & 0x3FFF]; drawcursor = ((ma == ca) && cursorline && (t1000->cga.cgamode & 8) && (t1000->cga.cgablink & 16)); diff --git a/src/machine/machine_table.c b/src/machine/machine_table.c index bb91e6977..330244477 100644 --- a/src/machine/machine_table.c +++ b/src/machine/machine_table.c @@ -13092,11 +13092,11 @@ machine_get_machine_from_internal_name(char *s) while (machines[c].init != NULL) { if (!strcmp(machines[c].internal_name, (const char *) s)) - return (c); + return c; c++; } - return (0); + return 0; } int diff --git a/src/mca.c b/src/mca.c index b48bdd2a7..871060bb4 100644 --- a/src/mca.c +++ b/src/mca.c @@ -17,9 +17,7 @@ static int mca_nr_cards; void mca_init(int nr_cards) { - int c; - - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { mca_card_read[c] = NULL; mca_card_write[c] = NULL; mca_card_reset[c] = NULL; @@ -83,9 +81,7 @@ mca_feedb(void) void mca_reset(void) { - int c; - - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { if (mca_card_reset[c]) mca_card_reset[c](mca_priv[c]); } @@ -94,9 +90,7 @@ mca_reset(void) 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) { - int c; - - for (c = 0; c < mca_nr_cards; c++) { + for (int c = 0; c < mca_nr_cards; c++) { if (!mca_card_read[c] && !mca_card_write[c]) { mca_card_read[c] = read; mca_card_write[c] = write; diff --git a/src/mem/mem.c b/src/mem/mem.c index 910f67619..c6010c8a1 100644 --- a/src/mem/mem.c +++ b/src/mem/mem.c @@ -54,28 +54,30 @@ # define BLOCK_INVALID 0 #endif -mem_mapping_t ram_low_mapping, /* 0..640K mapping */ - ram_mid_mapping, /* 640..1024K mapping */ - ram_mid_mapping2, /* 640..1024K mapping, second part, for SiS 471 in relocate mode */ - ram_remapped_mapping, /* 640..1024K mapping */ - ram_remapped_mapping2, /* 640..1024K second mapping, for SiS 471 mode */ - ram_high_mapping, /* 1024K+ mapping */ - ram_2gb_mapping, /* 1024M+ mapping */ - ram_split_mapping, - bios_mapping, - bios_high_mapping; +mem_mapping_t ram_low_mapping; /* 0..640K mapping */ +mem_mapping_t ram_mid_mapping; /* 640..1024K mapping */ +mem_mapping_t ram_mid_mapping2; /* 640..1024K mapping, second part, for SiS 471 in relocate mode */ +mem_mapping_t ram_remapped_mapping; /* 640..1024K mapping */ +mem_mapping_t ram_remapped_mapping2; /* 640..1024K second mapping, for SiS 471 mode */ +mem_mapping_t ram_high_mapping; /* 1024K+ mapping */ +mem_mapping_t ram_2gb_mapping; /* 1024M+ mapping */ +mem_mapping_t ram_split_mapping; +mem_mapping_t bios_mapping; +mem_mapping_t bios_high_mapping; -page_t *pages, /* RAM page table */ - **page_lookup; /* pagetable lookup */ -uint32_t pages_sz; /* #pages in table */ +page_t *pages; /* RAM page table */ +page_t **page_lookup; /* pagetable lookup */ +uint32_t pages_sz; /* #pages in table */ -uint8_t *ram, *ram2; /* the virtual RAM */ +uint8_t *ram; +uint8_t *ram2; /* the virtual RAM */ uint8_t page_ff[4096]; uint32_t rammask; uint32_t addr_space_size; uint8_t *rom; /* the virtual ROM */ -uint32_t biosmask, biosaddr; +uint32_t biosmask; +uint32_t biosaddr; uint32_t pccache; uint8_t *pccache2; @@ -91,18 +93,18 @@ uintptr_t *writelookup2; uint32_t mem_logical_addr; -int shadowbios = 0, - shadowbios_write; -int readlnum = 0, - writelnum = 0; +int shadowbios = 0; +int shadowbios_write; +int readlnum = 0; +int writelnum = 0; int cachesize = 256; -uint32_t get_phys_virt, - get_phys_phys; +uint32_t get_phys_virt; +uint32_t get_phys_phys; -int mem_a20_key = 0, - mem_a20_alt = 0, - mem_a20_state = 0; +int mem_a20_key = 0; +int mem_a20_alt = 0; +int mem_a20_state = 0; int mmuflush = 0; int mmu_perm = 4; @@ -121,7 +123,8 @@ uint8_t high_page = 0; /* if a high (> 4 gb) page was detected */ static uint8_t *page_lookupp; /* pagetable mmu_perm lookup */ static uint8_t *readlookupp; static uint8_t *writelookupp; -static mem_mapping_t *base_mapping, *last_mapping; +static mem_mapping_t *base_mapping; +static mem_mapping_t *last_mapping; static mem_mapping_t *read_mapping[MEM_MAPPINGS_NO]; static mem_mapping_t *write_mapping[MEM_MAPPINGS_NO]; static mem_mapping_t *read_mapping_bus[MEM_MAPPINGS_NO]; @@ -129,9 +132,11 @@ static mem_mapping_t *write_mapping_bus[MEM_MAPPINGS_NO]; static uint8_t *_mem_exec[MEM_MAPPINGS_NO]; static uint8_t ff_pccache[4] = { 0xff, 0xff, 0xff, 0xff }; static mem_state_t _mem_state[MEM_MAPPINGS_NO]; -static uint32_t remap_start_addr, remap_start_addr2; +static uint32_t remap_start_addr; +static uint32_t remap_start_addr2; #if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) -static size_t ram_size = 0, ram2_size = 0; +static size_t ram_size = 0; +static size_t ram2_size = 0; #else static size_t ram_size = 0; #endif @@ -166,13 +171,11 @@ mem_addr_is_ram(uint32_t addr) void resetreadlookup(void) { - int c; - /* Initialize the page lookup table. */ memset(page_lookup, 0x00, (1 << 20) * sizeof(page_t *)); /* Initialize the tables for lower (<= 1024K) RAM. */ - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { readlookup[c] = 0xffffffff; writelookup[c] = 0xffffffff; } @@ -193,9 +196,7 @@ resetreadlookup(void) void flushmmucache(void) { - int c; - - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { if (readlookup[c] != (int) 0xffffffff) { readlookup2[readlookup[c]] = LOOKUP_INV; readlookupp[readlookup[c]] = 4; @@ -222,9 +223,7 @@ flushmmucache(void) void flushmmucache_nopc(void) { - int c; - - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { if (readlookup[c] != (int) 0xffffffff) { readlookup2[readlookup[c]] = LOOKUP_INV; readlookupp[readlookup[c]] = 4; @@ -244,12 +243,11 @@ void mem_flush_write_page(uint32_t addr, uint32_t virt) { page_t *page_target = &pages[addr >> 12]; - int c; #if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) uint32_t a; #endif - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { if (writelookup[c] != (int) 0xffffffff) { #if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) uintptr_t target = (uintptr_t) &ram[(uintptr_t) (addr & ~0xfff) - (virt & ~0xfff)]; @@ -280,7 +278,9 @@ mem_flush_write_page(uint32_t addr, uint32_t virt) static __inline uint64_t mmutranslatereal_normal(uint32_t addr, int rw) { - uint32_t temp, temp2, temp3; + uint32_t temp; + uint32_t temp2; + uint32_t temp3; uint32_t addr2; if (cpu_state.abrt) @@ -345,8 +345,13 @@ mmutranslatereal_normal(uint32_t addr, int rw) static __inline uint64_t mmutranslatereal_pae(uint32_t addr, int rw) { - uint64_t temp, temp2, temp3, temp4; - uint64_t addr2, addr3, addr4; + uint64_t temp; + uint64_t temp2; + uint64_t temp3; + uint64_t temp4; + uint64_t addr2; + uint64_t addr3; + uint64_t addr4; if (cpu_state.abrt) return 0xffffffffffffffffULL; @@ -449,7 +454,9 @@ mmutranslatereal32(uint32_t addr, int rw) static __inline uint64_t mmutranslate_noabrt_normal(uint32_t addr, int rw) { - uint32_t temp, temp2, temp3; + uint32_t temp; + uint32_t temp2; + uint32_t temp3; uint32_t addr2; if (cpu_state.abrt) @@ -481,8 +488,13 @@ mmutranslate_noabrt_normal(uint32_t addr, int rw) static __inline uint64_t mmutranslate_noabrt_pae(uint32_t addr, int rw) { - uint64_t temp, temp2, temp3, temp4; - uint64_t addr2, addr3, addr4; + uint64_t temp; + uint64_t temp2; + uint64_t temp3; + uint64_t temp4; + uint64_t addr2; + uint64_t addr3; + uint64_t addr4; if (cpu_state.abrt) return 0xffffffffffffffffULL; @@ -885,7 +897,6 @@ uint16_t readmemwl(uint32_t addr) { mem_mapping_t *map; - int i; uint64_t a; addr64a[0] = addr; @@ -901,7 +912,7 @@ readmemwl(uint32_t addr) cycles -= timing_misaligned; if ((addr & 0xfff) > 0xffe) { if (cr0 >> 31) { - for (i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 2; i++) { a = mmutranslate_read(addr + i); addr64a[i] = (uint32_t) a; @@ -944,7 +955,6 @@ void writememwl(uint32_t addr, uint16_t val) { mem_mapping_t *map; - int i; uint64_t a; addr64a[0] = addr; @@ -960,7 +970,7 @@ writememwl(uint32_t addr, uint16_t val) cycles -= timing_misaligned; if ((addr & 0xfff) > 0xffe) { if (cr0 >> 31) { - for (i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 2; i++) { /* Do not translate a page that has a valid lookup, as that is by definition valid and the whole purpose of the lookup is to avoid repeat identical translations. */ if (!page_lookup[(addr + i) >> 12] || !page_lookup[(addr + i) >> 12]->write_b) { @@ -1563,7 +1573,8 @@ writememql(uint32_t addr, uint64_t val) void do_mmutranslate(uint32_t addr, uint32_t *a64, int num, int write) { - int i, cond = 1; + int i; + int cond = 1; uint32_t last_addr = addr + (num - 1); uint64_t a = 0x0000000000000000ULL; @@ -1631,7 +1642,8 @@ uint16_t mem_readw_phys(uint32_t addr) { mem_mapping_t *map = read_mapping_bus[addr >> MEM_GRANULARITY_BITS]; - uint16_t ret, *p; + uint16_t ret; + uint16_t *p; mem_logical_addr = 0xffffffff; @@ -1652,7 +1664,8 @@ uint32_t mem_readl_phys(uint32_t addr) { mem_mapping_t *map = read_mapping_bus[addr >> MEM_GRANULARITY_BITS]; - uint32_t ret, *p; + uint32_t ret; + uint32_t *p; mem_logical_addr = 0xffffffff; @@ -2530,13 +2543,11 @@ mem_mapping_enable(mem_mapping_t *map) void mem_set_access(uint8_t bitmap, int mode, uint32_t base, uint32_t size, uint16_t access) { - uint32_t c; - uint16_t mask, smstate = 0x0000; + uint16_t mask; + uint16_t smstate = 0x0000; const uint16_t smstates[4] = { 0x0000, (MEM_READ_SMRAM | MEM_WRITE_SMRAM), MEM_READ_SMRAM_EX, (MEM_READ_DISABLED_EX | MEM_WRITE_DISABLED_EX) }; - int i; - if (mode) mask = 0x2d6b; else @@ -2558,8 +2569,8 @@ mem_set_access(uint8_t bitmap, int mode, uint32_t base, uint32_t size, uint16_t } else smstate = access & 0x6f7b; - for (c = 0; c < size; c += MEM_GRANULARITY_SIZE) { - for (i = 0; i < 4; i++) { + for (uint32_t c = 0; c < size; c += MEM_GRANULARITY_SIZE) { + for (uint8_t i = 0; i < 4; i++) { if (bitmap & (1 << i)) { _mem_state[(c + base) >> MEM_GRANULARITY_BITS].vals[i] = (_mem_state[(c + base) >> MEM_GRANULARITY_BITS].vals[i] & mask) | smstate; } @@ -2597,7 +2608,8 @@ mem_a20_init(void) void mem_close(void) { - mem_mapping_t *map = base_mapping, *next; + mem_mapping_t *map = base_mapping; + mem_mapping_t *next; while (map != NULL) { next = map->next; @@ -2628,7 +2640,6 @@ mem_init_ram_mapping(mem_mapping_t *mapping, uint32_t base, uint32_t size) void mem_reset(void) { - uint32_t c; size_t m; memset(page_ff, 0xff, sizeof(page_ff)); @@ -2744,7 +2755,7 @@ mem_reset(void) memset(byte_code_present_mask, 0, (mem_size * 1024) / 8); #endif - for (c = 0; c < pages_sz; c++) { + for (uint32_t c = 0; c < pages_sz; c++) { if ((c << 12) >= (mem_size << 10)) pages[c].mem = page_ff; else { @@ -2857,11 +2868,13 @@ mem_remap_top(int kb) { uint32_t c; uint32_t start = (mem_size >= 1024) ? mem_size : 1024; - int offset, size = mem_size - 640; + int offset; + int size = mem_size - 640; int set = 1; static int old_kb = 0; int sis_mode = 0; - uint32_t start_addr = 0, addr = 0; + uint32_t start_addr = 0; + uint32_t addr = 0; mem_log("MEM: remapping top %iKB (mem=%i)\n", kb, mem_size); if (mem_size <= 640) @@ -2983,12 +2996,10 @@ mem_remap_top(int kb) void mem_reset_page_blocks(void) { - uint32_t c; - if (pages == NULL) return; - for (c = 0; c < pages_sz; c++) { + for (uint32_t c = 0; c < pages_sz; c++) { pages[c].write_b = mem_write_ramb_page; pages[c].write_w = mem_write_ramw_page; pages[c].write_l = mem_write_raml_page; @@ -3019,12 +3030,12 @@ mem_a20_recalc(void) state = mem_a20_key | mem_a20_alt; if (state && !mem_a20_state) { - rammask = (cpu_16bitbus) ? 0xffffff : 0xffffffff; + rammask = cpu_16bitbus ? 0xffffff : 0xffffffff; if (is6117) rammask |= 0x03000000; flushmmucache(); } else if (!state && mem_a20_state) { - rammask = (cpu_16bitbus) ? 0xefffff : 0xffefffff; + rammask = cpu_16bitbus ? 0xefffff : 0xffefffff; if (is6117) rammask |= 0x03000000; flushmmucache(); diff --git a/src/nvr.c b/src/nvr.c index 4b073c48f..aefee99a8 100644 --- a/src/nvr.c +++ b/src/nvr.c @@ -89,13 +89,13 @@ int nvr_is_leap(int year) { if (year % 400 == 0) - return (1); + return 1; if (year % 100 == 0) - return (0); + return 0; if (year % 4 == 0) - return (1); + return 1; - return (0); + return 0; } /* Determine the days in the current month. */ @@ -207,7 +207,7 @@ nvr_path(char *str) path_slash(temp); strcat(temp, str); - return (temp); + return temp; } /* @@ -230,7 +230,7 @@ nvr_load(void) /* Make sure we have been initialized. */ if (saved_nvr == NULL) - return (0); + return 0; /* Clear out any old data. */ memset(saved_nvr->regs, 0x00, sizeof(saved_nvr->regs)); @@ -261,7 +261,7 @@ nvr_load(void) if (saved_nvr->start != NULL) saved_nvr->start(saved_nvr); - return (1); + return 1; } void @@ -279,7 +279,7 @@ nvr_save(void) /* Make sure we have been initialized. */ if (saved_nvr == NULL) - return (0); + return 0; if (saved_nvr->size != 0) { path = nvr_path(saved_nvr->fn); @@ -298,7 +298,7 @@ nvr_save(void) /* Device is clean again. */ nvr_dosave = 0; - return (1); + return 1; } void @@ -328,8 +328,12 @@ nvr_time_sync(void) void nvr_time_get(struct tm *tm) { - uint8_t dom, mon, sum, wd; - uint16_t cent, yr; + uint8_t dom; + uint8_t mon; + uint8_t sum; + uint8_t wd; + uint16_t cent; + uint16_t yr; tm->tm_sec = intclk.tm_sec; tm->tm_min = intclk.tm_min; diff --git a/src/nvr_at.c b/src/nvr_at.c index bd0bbe34e..52bc7c9b5 100644 --- a/src/nvr_at.c +++ b/src/nvr_at.c @@ -1,1344 +1,1344 @@ -/* - * 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. - * - * This file is part of the 86Box distribution. - * - * Implement a more-or-less defacto-standard RTC/NVRAM. - * - * When IBM released the PC/AT machine, it came standard with a - * battery-backed RTC chip to keep the time of day, something - * that was optional on standard PC's with a myriad variants - * being put on the market, often on cheap multi-I/O cards. - * - * The PC/AT had an on-board DS12885-series chip ("the black - * block") which was an RTC/clock chip with onboard oscillator - * and a backup battery (hence the big size.) The chip also had - * a small amount of RAM bytes available to the user, which was - * used by IBM's ROM BIOS to store machine configuration data. - * Later versions and clones used the 12886 and/or 1288(C)7 - * series, or the MC146818 series, all with an external battery. - * Many of those batteries would create corrosion issues later - * on in mainboard life... - * - * Since then, pretty much any PC has an implementation of that - * device, which became known as the "nvr" or "cmos". - * - * NOTES Info extracted from the data sheets: - * - * * The century register at location 32h is a BCD register - * designed to automatically load the BCD value 20 as the - * year register changes from 99 to 00. The MSB of this - * register is not affected when the load of 20 occurs, - * and remains at the value written by the user. - * - * * Rate Selector (RS3:RS0) - * These four rate-selection bits select one of the 13 - * taps on the 15-stage divider or disable the divider - * output. The tap selected can be used to generate an - * output square wave (SQW pin) and/or a periodic interrupt. - * - * The user can do one of the following: - * - enable the interrupt with the PIE bit; - * - enable the SQW output pin with the SQWE bit; - * - enable both at the same time and the same rate; or - * - enable neither. - * - * Table 3 lists the periodic interrupt rates and the square - * wave frequencies that can be chosen with the RS bits. - * These four read/write bits are not affected by !RESET. - * - * * Oscillator (DV2:DV0) - * These three bits are used to turn the oscillator on or - * off and to reset the countdown chain. A pattern of 010 - * is the only combination of bits that turn the oscillator - * on and allow the RTC to keep time. A pattern of 11x - * enables the oscillator but holds the countdown chain in - * reset. The next update occurs at 500ms after a pattern - * of 010 is written to DV0, DV1, and DV2. - * - * * Update-In-Progress (UIP) - * This bit is a status flag that can be monitored. When the - * UIP bit is a 1, the update transfer occurs soon. When - * UIP is a 0, the update transfer does not occur for at - * least 244us. The time, calendar, and alarm information - * in RAM is fully available for access when the UIP bit - * is 0. The UIP bit is read-only and is not affected by - * !RESET. Writing the SET bit in Register B to a 1 - * inhibits any update transfer and clears the UIP status bit. - * - * * Daylight Saving Enable (DSE) - * This bit is a read/write bit that enables two daylight - * saving adjustments when DSE is set to 1. On the first - * Sunday in April (or the last Sunday in April in the - * MC146818A), the time increments from 1:59:59 AM to - * 3:00:00 AM. On the last Sunday in October when the time - * first reaches 1:59:59 AM, it changes to 1:00:00 AM. - * - * When DSE is enabled, the internal logic test for the - * first/last Sunday condition at midnight. If the DSE bit - * is not set when the test occurs, the daylight saving - * function does not operate correctly. These adjustments - * do not occur when the DSE bit is 0. This bit is not - * affected by internal functions or !RESET. - * - * * 24/12 - * The 24/12 control bit establishes the format of the hours - * byte. A 1 indicates the 24-hour mode and a 0 indicates - * the 12-hour mode. This bit is read/write and is not - * affected by internal functions or !RESET. - * - * * Data Mode (DM) - * This bit indicates whether time and calendar information - * is in binary or BCD format. The DM bit is set by the - * program to the appropriate format and can be read as - * required. This bit is not modified by internal functions - * or !RESET. A 1 in DM signifies binary data, while a 0 in - * DM specifies BCD data. - * - * * Square-Wave Enable (SQWE) - * When this bit is set to 1, a square-wave signal at the - * frequency set by the rate-selection bits RS3-RS0 is driven - * out on the SQW pin. When the SQWE bit is set to 0, the - * SQW pin is held low. SQWE is a read/write bit and is - * cleared by !RESET. SQWE is low if disabled, and is high - * impedance when VCC is below VPF. SQWE is cleared to 0 on - * !RESET. - * - * * Update-Ended Interrupt Enable (UIE) - * This bit is a read/write bit that enables the update-end - * flag (UF) bit in Register C to assert !IRQ. The !RESET - * pin going low or the SET bit going high clears the UIE bit. - * The internal functions of the device do not affect the UIE - * bit, but is cleared to 0 on !RESET. - * - * * Alarm Interrupt Enable (AIE) - * This bit is a read/write bit that, when set to 1, permits - * the alarm flag (AF) bit in Register C to assert !IRQ. An - * alarm interrupt occurs for each second that the three time - * bytes equal the three alarm bytes, including a don't-care - * alarm code of binary 11XXXXXX. The AF bit does not - * initiate the !IRQ signal when the AIE bit is set to 0. - * The internal functions of the device do not affect the AIE - * bit, but is cleared to 0 on !RESET. - * - * * Periodic Interrupt Enable (PIE) - * The PIE bit is a read/write bit that allows the periodic - * interrupt flag (PF) bit in Register C to drive the !IRQ pin - * low. When the PIE bit is set to 1, periodic interrupts are - * generated by driving the !IRQ pin low at a rate specified - * by the RS3-RS0 bits of Register A. A 0 in the PIE bit - * blocks the !IRQ output from being driven by a periodic - * interrupt, but the PF bit is still set at the periodic - * rate. PIE is not modified b any internal device functions, - * but is cleared to 0 on !RESET. - * - * * SET - * When the SET bit is 0, the update transfer functions - * normally by advancing the counts once per second. When - * the SET bit is written to 1, any update transfer is - * inhibited, and the program can initialize the time and - * calendar bytes without an update occurring in the midst of - * initializing. Read cycles can be executed in a similar - * manner. SET is a read/write bit and is not affected by - * !RESET or internal functions of the device. - * - * * Update-Ended Interrupt Flag (UF) - * This bit is set after each update cycle. When the UIE - * bit is set to 1, the 1 in UF causes the IRQF bit to be - * a 1, which asserts the !IRQ pin. This bit can be - * cleared by reading Register C or with a !RESET. - * - * * Alarm Interrupt Flag (AF) - * A 1 in the AF bit indicates that the current time has - * matched the alarm time. If the AIE bit is also 1, the - * !IRQ pin goes low and a 1 appears in the IRQF bit. This - * bit can be cleared by reading Register C or with a - * !RESET. - * - * * Periodic Interrupt Flag (PF) - * This bit is read-only and is set to 1 when an edge is - * detected on the selected tap of the divider chain. The - * RS3 through RS0 bits establish the periodic rate. PF is - * set to 1 independent of the state of the PIE bit. When - * both PF and PIE are 1s, the !IRQ signal is active and - * sets the IRQF bit. This bit can be cleared by reading - * Register C or with a !RESET. - * - * * Interrupt Request Flag (IRQF) - * The interrupt request flag (IRQF) is set to a 1 when one - * or more of the following are true: - * - PF == PIE == 1 - * - AF == AIE == 1 - * - UF == UIE == 1 - * Any time the IRQF bit is a 1, the !IRQ pin is driven low. - * All flag bits are cleared after Register C is read by the - * program or when the !RESET pin is low. - * - * * Valid RAM and Time (VRT) - * This bit indicates the condition of the battery connected - * to the VBAT pin. This bit is not writeable and should - * always be 1 when read. If a 0 is ever present, an - * exhausted internal lithium energy source is indicated and - * both the contents of the RTC data and RAM data are - * questionable. This bit is unaffected by !RESET. - * - * This file implements a generic version of the RTC/NVRAM chip, - * including the later update (DS12887A) which implemented a - * "century" register to be compatible with Y2K. - * - * - * - * Authors: Fred N. van Kempen, - * Miran Grca, - * Mahod, - * Sarah Walker, - * - * Copyright 2017-2020 Fred N. van Kempen. - * Copyright 2016-2020 Miran Grca. - * Copyright 2008-2020 Sarah Walker. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the: - * - * Free Software Foundation, Inc. - * 59 Temple Place - Suite 330 - * Boston, MA 02111-1307 - * USA. - */ -#include -#include -#include -#include -#include -#include -#include -#include <86box/86box.h> -#include "cpu.h" -#include <86box/machine.h> -#include <86box/io.h> -#include <86box/mem.h> -#include <86box/nmi.h> -#include <86box/pic.h> -#include <86box/timer.h> -#include <86box/pit.h> -#include <86box/rom.h> -#include <86box/device.h> -#include <86box/nvr.h> - -/* RTC registers and bit definitions. */ -#define RTC_SECONDS 0 -#define RTC_ALSECONDS 1 -#define AL_DONTCARE 0xc0 /* Alarm time is not set */ -#define RTC_MINUTES 2 -#define RTC_ALMINUTES 3 -#define RTC_HOURS 4 -#define RTC_AMPM 0x80 /* PM flag if 12h format in use */ -#define RTC_ALHOURS 5 -#define RTC_DOW 6 -#define RTC_DOM 7 -#define RTC_MONTH 8 -#define RTC_YEAR 9 -#define RTC_REGA 10 -#define REGA_UIP 0x80 -#define REGA_DV2 0x40 -#define REGA_DV1 0x20 -#define REGA_DV0 0x10 -#define REGA_DV 0x70 -#define REGA_RS3 0x08 -#define REGA_RS2 0x04 -#define REGA_RS1 0x02 -#define REGA_RS0 0x01 -#define REGA_RS 0x0f -#define RTC_REGB 11 -#define REGB_SET 0x80 -#define REGB_PIE 0x40 -#define REGB_AIE 0x20 -#define REGB_UIE 0x10 -#define REGB_SQWE 0x08 -#define REGB_DM 0x04 -#define REGB_2412 0x02 -#define REGB_DSE 0x01 -#define RTC_REGC 12 -#define REGC_IRQF 0x80 -#define REGC_PF 0x40 -#define REGC_AF 0x20 -#define REGC_UF 0x10 -#define RTC_REGD 13 -#define REGD_VRT 0x80 -#define RTC_CENTURY_AT 0x32 /* century register for AT etc */ -#define RTC_CENTURY_PS 0x37 /* century register for PS/1 PS/2 */ -#define RTC_CENTURY_ELT 0x1A /* century register for Epson Equity LT */ -#define RTC_ALDAY 0x7D /* VIA VT82C586B - alarm day */ -#define RTC_ALMONTH 0x7E /* VIA VT82C586B - alarm month */ -#define RTC_CENTURY_VIA 0x7F /* century register for VIA VT82C586B */ - -#define RTC_ALDAY_SIS 0x7E /* Day of Month Alarm for SiS */ -#define RTC_ALMONT_SIS 0x7F /* Month Alarm for SiS */ - -#define RTC_REGS 14 /* number of registers */ - -#define FLAG_NO_NMI 0x01 -#define FLAG_AMI_1992_HACK 0x02 -#define FLAG_AMI_1994_HACK 0x04 -#define FLAG_AMI_1995_HACK 0x08 -#define FLAG_P6RP4_HACK 0x10 -#define FLAG_PIIX4 0x20 - -typedef struct { - int8_t stat; - - uint8_t cent, def, - flags, read_addr, - wp_0d, wp_32, - pad, pad0; - - uint8_t addr[8], wp[2], - bank[8], *lock; - - int16_t count, state; - - uint64_t ecount, - rtc_time; - pc_timer_t update_timer, - rtc_timer; -} local_t; - -static uint8_t nvr_at_inited = 0; - -/* Get the current NVR time. */ -static void -time_get(nvr_t *nvr, struct tm *tm) -{ - local_t *local = (local_t *) nvr->data; - int8_t temp; - - if (nvr->regs[RTC_REGB] & REGB_DM) { - /* NVR is in Binary data mode. */ - tm->tm_sec = nvr->regs[RTC_SECONDS]; - tm->tm_min = nvr->regs[RTC_MINUTES]; - temp = nvr->regs[RTC_HOURS]; - tm->tm_wday = (nvr->regs[RTC_DOW] - 1); - tm->tm_mday = nvr->regs[RTC_DOM]; - tm->tm_mon = (nvr->regs[RTC_MONTH] - 1); - tm->tm_year = nvr->regs[RTC_YEAR]; - if (local->cent != 0xFF) - tm->tm_year += (nvr->regs[local->cent] * 100) - 1900; - } else { - /* NVR is in BCD data mode. */ - tm->tm_sec = RTC_DCB(nvr->regs[RTC_SECONDS]); - tm->tm_min = RTC_DCB(nvr->regs[RTC_MINUTES]); - temp = RTC_DCB(nvr->regs[RTC_HOURS]); - tm->tm_wday = (RTC_DCB(nvr->regs[RTC_DOW]) - 1); - tm->tm_mday = RTC_DCB(nvr->regs[RTC_DOM]); - tm->tm_mon = (RTC_DCB(nvr->regs[RTC_MONTH]) - 1); - tm->tm_year = RTC_DCB(nvr->regs[RTC_YEAR]); - if (local->cent != 0xFF) - tm->tm_year += (RTC_DCB(nvr->regs[local->cent]) * 100) - 1900; - } - - /* Adjust for 12/24 hour mode. */ - if (nvr->regs[RTC_REGB] & REGB_2412) - tm->tm_hour = temp; - else - tm->tm_hour = ((temp & ~RTC_AMPM) % 12) + ((temp & RTC_AMPM) ? 12 : 0); -} - -/* Set the current NVR time. */ -static void -time_set(nvr_t *nvr, struct tm *tm) -{ - local_t *local = (local_t *) nvr->data; - int year = (tm->tm_year + 1900); - - if (nvr->regs[RTC_REGB] & REGB_DM) { - /* NVR is in Binary data mode. */ - nvr->regs[RTC_SECONDS] = tm->tm_sec; - nvr->regs[RTC_MINUTES] = tm->tm_min; - nvr->regs[RTC_DOW] = (tm->tm_wday + 1); - nvr->regs[RTC_DOM] = tm->tm_mday; - nvr->regs[RTC_MONTH] = (tm->tm_mon + 1); - nvr->regs[RTC_YEAR] = (year % 100); - if (local->cent != 0xFF) - nvr->regs[local->cent] = (year / 100); - - if (nvr->regs[RTC_REGB] & REGB_2412) { - /* NVR is in 24h mode. */ - nvr->regs[RTC_HOURS] = tm->tm_hour; - } else { - /* NVR is in 12h mode. */ - nvr->regs[RTC_HOURS] = (tm->tm_hour % 12) ? (tm->tm_hour % 12) : 12; - if (tm->tm_hour > 11) - nvr->regs[RTC_HOURS] |= RTC_AMPM; - } - } else { - /* NVR is in BCD data mode. */ - nvr->regs[RTC_SECONDS] = RTC_BCD(tm->tm_sec); - nvr->regs[RTC_MINUTES] = RTC_BCD(tm->tm_min); - nvr->regs[RTC_DOW] = RTC_BCD(tm->tm_wday + 1); - nvr->regs[RTC_DOM] = RTC_BCD(tm->tm_mday); - nvr->regs[RTC_MONTH] = RTC_BCD(tm->tm_mon + 1); - nvr->regs[RTC_YEAR] = RTC_BCD(year % 100); - if (local->cent != 0xFF) - nvr->regs[local->cent] = RTC_BCD(year / 100); - - if (nvr->regs[RTC_REGB] & REGB_2412) { - /* NVR is in 24h mode. */ - nvr->regs[RTC_HOURS] = RTC_BCD(tm->tm_hour); - } else { - /* NVR is in 12h mode. */ - nvr->regs[RTC_HOURS] = (tm->tm_hour % 12) - ? RTC_BCD(tm->tm_hour % 12) - : RTC_BCD(12); - if (tm->tm_hour > 11) - nvr->regs[RTC_HOURS] |= RTC_AMPM; - } - } -} - -/* Check if the current time matches a set alarm time. */ -static int8_t -check_alarm(nvr_t *nvr, int8_t addr) -{ - return ((nvr->regs[addr + 1] == nvr->regs[addr]) || ((nvr->regs[addr + 1] & AL_DONTCARE) == AL_DONTCARE)); -} - -/* Check for VIA stuff. */ -static int8_t -check_alarm_via(nvr_t *nvr, int8_t addr, int8_t addr_2) -{ - local_t *local = (local_t *) nvr->data; - - if (local->cent == RTC_CENTURY_VIA) { - return ((nvr->regs[addr_2] == nvr->regs[addr]) || ((nvr->regs[addr_2] & AL_DONTCARE) == AL_DONTCARE)); - } else - return 1; -} - -/* Update the NVR registers from the internal clock. */ -static void -timer_update(void *priv) -{ - nvr_t *nvr = (nvr_t *) priv; - local_t *local = (local_t *) nvr->data; - struct tm tm; - - local->ecount = 0LL; - - if (!(nvr->regs[RTC_REGB] & REGB_SET)) { - /* Get the current time from the internal clock. */ - nvr_time_get(&tm); - - /* Update registers with current time. */ - time_set(nvr, &tm); - - /* Clear update status. */ - local->stat = 0x00; - - /* Check for any alarms we need to handle. */ - if (check_alarm(nvr, RTC_SECONDS) && check_alarm(nvr, RTC_MINUTES) && check_alarm(nvr, RTC_HOURS) && check_alarm_via(nvr, RTC_DOM, RTC_ALDAY) && check_alarm_via(nvr, RTC_MONTH, RTC_ALMONTH) /* && - check_alarm_via(nvr, RTC_DOM, RTC_ALDAY_SIS) && - check_alarm_via(nvr, RTC_MONTH, RTC_ALMONT_SIS)*/ - ) { - nvr->regs[RTC_REGC] |= REGC_AF; - if (nvr->regs[RTC_REGB] & REGB_AIE) { - /* Generate an interrupt. */ - if ((nvr->irq != -1) && (!(nvr->regs[RTC_REGC] & REGC_IRQF))) { - picintlevel(1 << nvr->irq); - nvr->regs[RTC_REGC] |= REGC_IRQF; - } - } - } - - /* - * The flag and interrupt should be issued - * on update ended, not started. - */ - nvr->regs[RTC_REGC] |= REGC_UF; - if (nvr->regs[RTC_REGB] & REGB_UIE) { - /* Generate an interrupt. */ - if ((nvr->irq != -1) && (!(nvr->regs[RTC_REGC] & REGC_IRQF))) { - picintlevel(1 << nvr->irq); - nvr->regs[RTC_REGC] |= REGC_IRQF; - } - } - } -} - -static void -timer_load_count(nvr_t *nvr) -{ - int c = nvr->regs[RTC_REGA] & REGA_RS; - local_t *local = (local_t *) nvr->data; - - timer_disable(&local->rtc_timer); - - if ((nvr->regs[RTC_REGA] & 0x70) != 0x20) { - local->state = 0; - return; - } - - local->state = 1; - - switch (c) { - case 0: - local->state = 0; - break; - case 1: - case 2: - local->count = 1 << (c + 6); - timer_set_delay_u64(&local->rtc_timer, (local->count) * RTCCONST); - break; - default: - local->count = 1 << (c - 1); - timer_set_delay_u64(&local->rtc_timer, (local->count) * RTCCONST); - break; - } -} - -static void -timer_intr(void *priv) -{ - nvr_t *nvr = (nvr_t *) priv; - local_t *local = (local_t *) nvr->data; - - if (local->state == 1) { - timer_load_count(nvr); - - nvr->regs[RTC_REGC] |= REGC_PF; - if (nvr->regs[RTC_REGB] & REGB_PIE) { - /* Generate an interrupt. */ - if ((nvr->irq != -1) && (!(nvr->regs[RTC_REGC] & REGC_IRQF))) { - picintlevel(1 << nvr->irq); - nvr->regs[RTC_REGC] |= REGC_IRQF; - } - } - } -} - -/* Callback from internal clock, another second passed. */ -static void -timer_tick(nvr_t *nvr) -{ - local_t *local = (local_t *) nvr->data; - - /* Only update it there is no SET in progress. */ - if (!(nvr->regs[RTC_REGB] & REGB_SET)) { - /* Set the UIP bit, announcing the update. */ - local->stat = REGA_UIP; - - rtc_tick(); - - /* Schedule the actual update. */ - local->ecount = (244ULL + 1984ULL) * TIMER_USEC; - timer_set_delay_u64(&local->update_timer, local->ecount); - } -} - -static void -nvr_reg_common_write(uint16_t reg, uint8_t val, nvr_t *nvr, local_t *local) -{ - if ((reg == 0x2c) && (local->flags & FLAG_AMI_1994_HACK)) - nvr->is_new = 0; - if ((reg == 0x2d) && (local->flags & FLAG_AMI_1992_HACK)) - nvr->is_new = 0; - if ((reg == 0x52) && (local->flags & FLAG_AMI_1995_HACK)) - nvr->is_new = 0; - if ((reg >= 0x38) && (reg <= 0x3f) && local->wp[0]) - return; - if ((reg >= 0xb8) && (reg <= 0xbf) && local->wp[1]) - return; - if (local->lock[reg]) - return; - if (nvr->regs[reg] != val) { - nvr->regs[reg] = val; - nvr_dosave = 1; - } -} - -/* This must be exposed because ACPI uses it. */ -void -nvr_reg_write(uint16_t reg, uint8_t val, void *priv) -{ - nvr_t *nvr = (nvr_t *) priv; - local_t *local = (local_t *) nvr->data; - struct tm tm; - uint8_t old; - uint8_t irq = 0, old_irq = 0; - - old = nvr->regs[reg]; - switch (reg) { - case RTC_REGA: - nvr->regs[RTC_REGA] = val; - timer_load_count(nvr); - break; - - case RTC_REGB: - old_irq = (nvr->regs[RTC_REGB] & nvr->regs[RTC_REGC]) & 0x70; - nvr->regs[RTC_REGB] = val; - if (((old ^ val) & REGB_SET) && (val & REGB_SET)) { - /* According to the datasheet... */ - nvr->regs[RTC_REGA] &= ~REGA_UIP; - nvr->regs[RTC_REGB] &= ~REGB_UIE; - } - irq = (nvr->regs[RTC_REGB] & nvr->regs[RTC_REGC]) & 0x70; - if (old_irq && !irq) { - picintc(1 << nvr->irq); - nvr->regs[RTC_REGC] &= ~REGC_IRQF; - } else if (!old_irq && irq) { - picintlevel(1 << nvr->irq); - nvr->regs[RTC_REGC] |= REGC_IRQF; - } - break; - - case RTC_REGC: /* R/O */ - break; - - case RTC_REGD: /* R/O */ - /* This is needed for VIA, where writing to this register changes a write-only - bit whose value is read from power management register 42. */ - nvr->regs[RTC_REGD] = val & 0x80; - break; - - case 0x32: - if ((reg == 0x32) && (local->cent == RTC_CENTURY_VIA) && local->wp_32) - break; - nvr_reg_common_write(reg, val, nvr, local); - break; - - default: /* non-RTC registers are just NVRAM */ - nvr_reg_common_write(reg, val, nvr, local); - break; - } - - if ((reg < RTC_REGA) || ((local->cent != 0xff) && (reg == local->cent))) { - if ((reg != 1) && (reg != 3) && (reg != 5)) { - if ((old != val) && !(time_sync & TIME_SYNC_ENABLED)) { - /* Update internal clock. */ - time_get(nvr, &tm); - nvr_time_set(&tm); - nvr_dosave = 1; - } - } - } -} - -/* Write to one of the NVR registers. */ -static void -nvr_write(uint16_t addr, uint8_t val, void *priv) -{ - nvr_t *nvr = (nvr_t *) priv; - local_t *local = (local_t *) nvr->data; - uint8_t addr_id = (addr & 0x0e) >> 1; - - cycles -= ISA_CYCLES(8); - - if (local->bank[addr_id] == 0xff) - return; - - if (addr & 1) { - // if (local->bank[addr_id] == 0xff) - // return; - nvr_reg_write(local->addr[addr_id], val, priv); - } else { - local->addr[addr_id] = (val & (nvr->size - 1)); - /* Some chipsets use a 256 byte NVRAM but ports 70h and 71h always access only 128 bytes. */ - if (addr_id == 0x0) - local->addr[addr_id] &= 0x7f; - else if ((addr_id == 0x1) && (local->flags & FLAG_PIIX4)) - local->addr[addr_id] = (local->addr[addr_id] & 0x7f) | 0x80; - if (local->bank[addr_id] > 0) - local->addr[addr_id] = (local->addr[addr_id] & 0x7f) | (0x80 * local->bank[addr_id]); - if (!(local->flags & FLAG_NO_NMI)) - nmi_mask = (~val & 0x80); - } -} - -/* Read from one of the NVR registers. */ -static uint8_t -nvr_read(uint16_t addr, void *priv) -{ - nvr_t *nvr = (nvr_t *) priv; - local_t *local = (local_t *) nvr->data; - uint8_t ret; - uint8_t addr_id = (addr & 0x0e) >> 1; - uint16_t i, checksum = 0x0000; - - cycles -= ISA_CYCLES(8); - - if (local->bank[addr_id] == 0xff) - ret = 0xff; - else if (addr & 1) - switch (local->addr[addr_id]) { - case RTC_REGA: - ret = (nvr->regs[RTC_REGA] & 0x7f) | local->stat; - break; - - case RTC_REGC: - ret = nvr->regs[RTC_REGC]; - picintc(1 << nvr->irq); - nvr->regs[RTC_REGC] = 0x00; - break; - - case RTC_REGD: - /* Bits 6-0 of this register always read 0. Bit 7 is battery state, - we should always return it set, as that means the battery is OK. */ - ret = REGD_VRT; - break; - - case 0x2c: - if (!nvr->is_new && (local->flags & FLAG_AMI_1994_HACK)) - ret = nvr->regs[local->addr[addr_id]] & 0x7f; - else - ret = nvr->regs[local->addr[addr_id]]; - break; - - case 0x2d: - if (!nvr->is_new && (local->flags & FLAG_AMI_1992_HACK)) - ret = nvr->regs[local->addr[addr_id]] & 0xf7; - else - ret = nvr->regs[local->addr[addr_id]]; - break; - - case 0x2e: - case 0x2f: - if (!nvr->is_new && (local->flags & FLAG_AMI_1992_HACK)) { - for (i = 0x10; i <= 0x2d; i++) { - if (i == 0x2d) - checksum += (nvr->regs[i] & 0xf7); - else - checksum += nvr->regs[i]; - } - if (local->addr[addr_id] == 0x2e) - ret = checksum >> 8; - else - ret = checksum & 0xff; - } else if (!nvr->is_new && (local->flags & FLAG_AMI_1994_HACK)) { - for (i = 0x10; i <= 0x2d; i++) { - if (i == 0x2c) - checksum += (nvr->regs[i] & 0x7f); - else - checksum += nvr->regs[i]; - } - if (local->addr[addr_id] == 0x2e) - ret = checksum >> 8; - else - ret = checksum & 0xff; - } else - ret = nvr->regs[local->addr[addr_id]]; - break; - - case 0x3e: - case 0x3f: - if (!nvr->is_new && (local->flags & FLAG_AMI_1995_HACK)) { - /* The checksum at 3E-3F is for 37-3D and 40-7F. */ - for (i = 0x37; i <= 0x3d; i++) - checksum += nvr->regs[i]; - for (i = 0x40; i <= 0x7f; i++) { - if (i == 0x52) - checksum += (nvr->regs[i] & 0xf3); - else - checksum += nvr->regs[i]; - } - if (local->addr[addr_id] == 0x3e) - ret = checksum >> 8; - else - ret = checksum & 0xff; - } else if (!nvr->is_new && (local->flags & FLAG_P6RP4_HACK)) { - /* The checksum at 3E-3F is for 37-3D and 40-51. */ - for (i = 0x37; i <= 0x3d; i++) - checksum += nvr->regs[i]; - for (i = 0x40; i <= 0x51; i++) { - if (i == 0x43) - checksum += (nvr->regs[i] | 0x02); - else - checksum += nvr->regs[i]; - } - if (local->addr[addr_id] == 0x3e) - ret = checksum >> 8; - else - ret = checksum & 0xff; - } else - ret = nvr->regs[local->addr[addr_id]]; - break; - - case 0x43: - if (!nvr->is_new && (local->flags & FLAG_P6RP4_HACK)) - ret = nvr->regs[local->addr[addr_id]] | 0x02; - else - ret = nvr->regs[local->addr[addr_id]]; - break; - - case 0x52: - if (!nvr->is_new && (local->flags & FLAG_AMI_1995_HACK)) - ret = nvr->regs[local->addr[addr_id]] & 0xf3; - else - ret = nvr->regs[local->addr[addr_id]]; - break; - - default: - ret = nvr->regs[local->addr[addr_id]]; - break; - } - else { - ret = local->addr[addr_id]; - if (!local->read_addr) - ret &= 0x80; - if (alt_access) - ret = (ret & 0x7f) | (nmi_mask ? 0x00 : 0x80); - } - - return (ret); -} - -/* Secondary NVR write - used by SMC. */ -static void -nvr_sec_write(uint16_t addr, uint8_t val, void *priv) -{ - nvr_write(0x72 + (addr & 1), val, priv); -} - -/* Secondary NVR read - used by SMC. */ -static uint8_t -nvr_sec_read(uint16_t addr, void *priv) -{ - return nvr_read(0x72 + (addr & 1), priv); -} - -/* Reset the RTC state to 1980/01/01 00:00. */ -static void -nvr_reset(nvr_t *nvr) -{ - local_t *local = (local_t *) nvr->data; - - /* memset(nvr->regs, local->def, RTC_REGS); */ - memset(nvr->regs, local->def, nvr->size); - nvr->regs[RTC_DOM] = 1; - nvr->regs[RTC_MONTH] = 1; - nvr->regs[RTC_YEAR] = RTC_BCD(80); - if (local->cent != 0xFF) - nvr->regs[local->cent] = RTC_BCD(19); - - nvr->regs[RTC_REGD] = REGD_VRT; -} - -/* Process after loading from file. */ -static void -nvr_start(nvr_t *nvr) -{ - int i; - local_t *local = (local_t *) nvr->data; - - struct tm tm; - int default_found = 0; - - for (i = 0; i < nvr->size; i++) { - if (nvr->regs[i] == local->def) - default_found++; - } - - if (default_found == nvr->size) - nvr->regs[0x0e] = 0xff; /* If load failed or it loaded an uninitialized NVR, - mark everything as bad. */ - - /* Initialize the internal and chip times. */ - if (time_sync & TIME_SYNC_ENABLED) { - /* Use the internal clock's time. */ - nvr_time_get(&tm); - time_set(nvr, &tm); - } else { - /* Set the internal clock from the chip time. */ - time_get(nvr, &tm); - nvr_time_set(&tm); - } - - /* Start the RTC. */ - nvr->regs[RTC_REGA] = (REGA_RS2 | REGA_RS1); - nvr->regs[RTC_REGB] = REGB_2412; -} - -static void -nvr_at_speed_changed(void *priv) -{ - nvr_t *nvr = (nvr_t *) priv; - local_t *local = (local_t *) nvr->data; - - timer_load_count(nvr); - - timer_disable(&local->update_timer); - if (local->ecount > 0ULL) - timer_set_delay_u64(&local->update_timer, local->ecount); - - timer_disable(&nvr->onesec_time); - timer_set_delay_u64(&nvr->onesec_time, (10000ULL * TIMER_USEC)); -} - -void -nvr_at_handler(int set, uint16_t base, nvr_t *nvr) -{ - io_handler(set, base, 2, - nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr); -} - -void -nvr_at_index_read_handler(int set, uint16_t base, nvr_t *nvr) -{ - io_handler(0, base, 1, - NULL, NULL, NULL, nvr_write, NULL, NULL, nvr); - nvr_at_handler(0, base, nvr); - - if (set) - nvr_at_handler(1, base, nvr); - else { - io_handler(1, base, 1, - NULL, NULL, NULL, nvr_write, NULL, NULL, nvr); - io_handler(1, base + 1, 1, - nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr); - } -} - -void -nvr_at_sec_handler(int set, uint16_t base, nvr_t *nvr) -{ - io_handler(set, base, 2, - nvr_sec_read, NULL, NULL, nvr_sec_write, NULL, NULL, nvr); -} - -void -nvr_read_addr_set(int set, nvr_t *nvr) -{ - local_t *local = (local_t *) nvr->data; - - local->read_addr = set; -} - -void -nvr_wp_set(int set, int h, nvr_t *nvr) -{ - local_t *local = (local_t *) nvr->data; - - local->wp[h] = set; -} - -void -nvr_via_wp_set(int set, int reg, nvr_t *nvr) -{ - local_t *local = (local_t *) nvr->data; - - if (reg == 0x0d) - local->wp_0d = set; - else - local->wp_32 = set; -} - -void -nvr_bank_set(int base, uint8_t bank, nvr_t *nvr) -{ - local_t *local = (local_t *) nvr->data; - - local->bank[base] = bank; -} - -void -nvr_lock_set(int base, int size, int lock, nvr_t *nvr) -{ - local_t *local = (local_t *) nvr->data; - int i; - - for (i = 0; i < size; i++) - local->lock[base + i] = lock; -} - -void -nvr_irq_set(int irq, nvr_t *nvr) -{ - nvr->irq = irq; -} - -static void -nvr_at_reset(void *priv) -{ - nvr_t *nvr = (nvr_t *) priv; - - /* These bits are reset on reset. */ - nvr->regs[RTC_REGB] &= ~(REGB_PIE | REGB_AIE | REGB_UIE | REGB_SQWE); - nvr->regs[RTC_REGC] &= ~(REGC_PF | REGC_AF | REGC_UF | REGC_IRQF); -} - -static void * -nvr_at_init(const device_t *info) -{ - local_t *local; - nvr_t *nvr; - - /* Allocate an NVR for this machine. */ - nvr = (nvr_t *) malloc(sizeof(nvr_t)); - if (nvr == NULL) - return (NULL); - memset(nvr, 0x00, sizeof(nvr_t)); - - local = (local_t *) malloc(sizeof(local_t)); - memset(local, 0x00, sizeof(local_t)); - nvr->data = local; - - /* This is machine specific. */ - nvr->size = machines[machine].nvrmask + 1; - local->lock = (uint8_t *) malloc(nvr->size); - memset(local->lock, 0x00, nvr->size); - local->def = 0xff /*0x00*/; - local->flags = 0x00; - switch (info->local & 0x0f) { - case 0: /* standard AT, no century register */ - if (info->local == 32) { - local->flags |= FLAG_P6RP4_HACK; - nvr->irq = 8; - local->cent = RTC_CENTURY_AT; - } else { - nvr->irq = 8; - local->cent = 0xff; - } - break; - - case 1: /* standard AT */ - case 5: /* AMI WinBIOS 1994 */ - case 6: /* AMI BIOS 1995 */ - if ((info->local & 0x1f) == 0x11) - local->flags |= FLAG_PIIX4; - else { - local->def = 0x00; - if ((info->local & 0x1f) == 0x15) - local->flags |= FLAG_AMI_1994_HACK; - else if ((info->local & 0x1f) == 0x16) - local->flags |= FLAG_AMI_1995_HACK; - else - local->def = 0xff; - } - nvr->irq = 8; - local->cent = RTC_CENTURY_AT; - break; - - case 2: /* PS/1 or PS/2 */ - nvr->irq = 8; - local->cent = RTC_CENTURY_PS; - local->def = 0x00; - if (info->local & 0x10) - local->flags |= FLAG_NO_NMI; - break; - - case 3: /* Amstrad PC's */ - nvr->irq = 1; - local->cent = RTC_CENTURY_AT; - local->def = 0xff; - if (info->local & 0x10) - local->flags |= FLAG_NO_NMI; - break; - - case 4: /* IBM AT */ - if (info->local & 0x10) { - local->def = 0x00; - local->flags |= FLAG_AMI_1992_HACK; - } else if (info->local == 36) - local->def = 0x00; - else - local->def = 0xff; - nvr->irq = 8; - local->cent = RTC_CENTURY_AT; - break; - - case 7: /* VIA VT82C586B */ - nvr->irq = 8; - local->cent = RTC_CENTURY_VIA; - break; - case 8: /* Epson Equity LT */ - nvr->irq = -1; - local->cent = RTC_CENTURY_ELT; - break; - } - - local->read_addr = 1; - - /* Set up any local handlers here. */ - nvr->reset = nvr_reset; - nvr->start = nvr_start; - nvr->tick = timer_tick; - - /* Initialize the generic NVR. */ - nvr_init(nvr); - - if (nvr_at_inited == 0) { - /* Start the timers. */ - timer_add(&local->update_timer, timer_update, nvr, 0); - - timer_add(&local->rtc_timer, timer_intr, nvr, 0); - /* On power on, if the oscillator is disabled, it's reenabled. */ - if ((nvr->regs[RTC_REGA] & 0x70) == 0x00) - nvr->regs[RTC_REGA] = (nvr->regs[RTC_REGA] & 0x8f) | 0x20; - nvr_at_reset(nvr); - timer_load_count(nvr); - - /* Set up the I/O handler for this device. */ - if (info->local == 8) { - io_sethandler(0x11b4, 2, - nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr); - } else { - io_sethandler(0x0070, 2, - nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr); - } - if (((info->local & 0x1f) == 0x11) || ((info->local & 0x1f) == 0x17)) { - io_sethandler(0x0072, 2, - nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr); - } - - nvr_at_inited = 1; - } - - return (nvr); -} - -static void -nvr_at_close(void *priv) -{ - nvr_t *nvr = (nvr_t *) priv; - local_t *local = (local_t *) nvr->data; - - nvr_close(); - - timer_disable(&local->rtc_timer); - timer_disable(&local->update_timer); - timer_disable(&nvr->onesec_time); - - if (nvr != NULL) { - if (nvr->fn != NULL) - free(nvr->fn); - - if (nvr->data != NULL) - free(nvr->data); - - free(nvr); - } - - if (nvr_at_inited == 1) - nvr_at_inited = 0; -} - -const device_t at_nvr_old_device = { - .name = "PC/AT NVRAM (No century)", - .internal_name = "at_nvr_old", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t at_nvr_device = { - .name = "PC/AT NVRAM", - .internal_name = "at_nvr", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 1, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t ps_nvr_device = { - .name = "PS/1 or PS/2 NVRAM", - .internal_name = "ps_nvr", - .flags = DEVICE_PS2, - .local = 2, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t amstrad_nvr_device = { - .name = "Amstrad NVRAM", - .internal_name = "amstrad_nvr", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 3, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t ibmat_nvr_device = { - .name = "IBM AT NVRAM", - .internal_name = "ibmat_nvr", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 4, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t piix4_nvr_device = { - .name = "Intel PIIX4 PC/AT NVRAM", - .internal_name = "piix4_nvr", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0x10 | 1, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t ps_no_nmi_nvr_device = { - .name = "PS/1 or PS/2 NVRAM (No NMI)", - .internal_name = "ps1_nvr", - .flags = DEVICE_PS2, - .local = 0x10 | 2, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t amstrad_no_nmi_nvr_device = { - .name = "Amstrad NVRAM (No NMI)", - .internal_name = "amstrad_nvr", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0x10 | 3, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t ami_1992_nvr_device = { - .name = "AMI Color 1992 PC/AT NVRAM", - .internal_name = "ami_1992_nvr", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0x10 | 4, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t ami_1994_nvr_device = { - .name = "AMI WinBIOS 1994 PC/AT NVRAM", - .internal_name = "ami_1994_nvr", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0x10 | 5, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t ami_1995_nvr_device = { - .name = "AMI WinBIOS 1995 PC/AT NVRAM", - .internal_name = "ami_1995_nvr", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0x10 | 6, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t via_nvr_device = { - .name = "VIA PC/AT NVRAM", - .internal_name = "via_nvr", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 0x10 | 7, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t p6rp4_nvr_device = { - .name = "ASUS P/I-P6RP4 PC/AT NVRAM", - .internal_name = "p6rp4_nvr", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 32, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t amstrad_megapc_nvr_device = { - .name = "Amstrad MegaPC NVRAM", - .internal_name = "amstrad_megapc_nvr", - .flags = DEVICE_ISA | DEVICE_AT, - .local = 36, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; - -const device_t elt_nvr_device = { - .name = "Epson Equity LT NVRAM", - .internal_name = "elt_nvr", - .flags = DEVICE_ISA, - .local = 8, - .init = nvr_at_init, - .close = nvr_at_close, - .reset = nvr_at_reset, - { .available = NULL }, - .speed_changed = nvr_at_speed_changed, - .force_redraw = NULL, - .config = NULL -}; +/* + * 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. + * + * This file is part of the 86Box distribution. + * + * Implement a more-or-less defacto-standard RTC/NVRAM. + * + * When IBM released the PC/AT machine, it came standard with a + * battery-backed RTC chip to keep the time of day, something + * that was optional on standard PC's with a myriad variants + * being put on the market, often on cheap multi-I/O cards. + * + * The PC/AT had an on-board DS12885-series chip ("the black + * block") which was an RTC/clock chip with onboard oscillator + * and a backup battery (hence the big size.) The chip also had + * a small amount of RAM bytes available to the user, which was + * used by IBM's ROM BIOS to store machine configuration data. + * Later versions and clones used the 12886 and/or 1288(C)7 + * series, or the MC146818 series, all with an external battery. + * Many of those batteries would create corrosion issues later + * on in mainboard life... + * + * Since then, pretty much any PC has an implementation of that + * device, which became known as the "nvr" or "cmos". + * + * NOTES Info extracted from the data sheets: + * + * * The century register at location 32h is a BCD register + * designed to automatically load the BCD value 20 as the + * year register changes from 99 to 00. The MSB of this + * register is not affected when the load of 20 occurs, + * and remains at the value written by the user. + * + * * Rate Selector (RS3:RS0) + * These four rate-selection bits select one of the 13 + * taps on the 15-stage divider or disable the divider + * output. The tap selected can be used to generate an + * output square wave (SQW pin) and/or a periodic interrupt. + * + * The user can do one of the following: + * - enable the interrupt with the PIE bit; + * - enable the SQW output pin with the SQWE bit; + * - enable both at the same time and the same rate; or + * - enable neither. + * + * Table 3 lists the periodic interrupt rates and the square + * wave frequencies that can be chosen with the RS bits. + * These four read/write bits are not affected by !RESET. + * + * * Oscillator (DV2:DV0) + * These three bits are used to turn the oscillator on or + * off and to reset the countdown chain. A pattern of 010 + * is the only combination of bits that turn the oscillator + * on and allow the RTC to keep time. A pattern of 11x + * enables the oscillator but holds the countdown chain in + * reset. The next update occurs at 500ms after a pattern + * of 010 is written to DV0, DV1, and DV2. + * + * * Update-In-Progress (UIP) + * This bit is a status flag that can be monitored. When the + * UIP bit is a 1, the update transfer occurs soon. When + * UIP is a 0, the update transfer does not occur for at + * least 244us. The time, calendar, and alarm information + * in RAM is fully available for access when the UIP bit + * is 0. The UIP bit is read-only and is not affected by + * !RESET. Writing the SET bit in Register B to a 1 + * inhibits any update transfer and clears the UIP status bit. + * + * * Daylight Saving Enable (DSE) + * This bit is a read/write bit that enables two daylight + * saving adjustments when DSE is set to 1. On the first + * Sunday in April (or the last Sunday in April in the + * MC146818A), the time increments from 1:59:59 AM to + * 3:00:00 AM. On the last Sunday in October when the time + * first reaches 1:59:59 AM, it changes to 1:00:00 AM. + * + * When DSE is enabled, the internal logic test for the + * first/last Sunday condition at midnight. If the DSE bit + * is not set when the test occurs, the daylight saving + * function does not operate correctly. These adjustments + * do not occur when the DSE bit is 0. This bit is not + * affected by internal functions or !RESET. + * + * * 24/12 + * The 24/12 control bit establishes the format of the hours + * byte. A 1 indicates the 24-hour mode and a 0 indicates + * the 12-hour mode. This bit is read/write and is not + * affected by internal functions or !RESET. + * + * * Data Mode (DM) + * This bit indicates whether time and calendar information + * is in binary or BCD format. The DM bit is set by the + * program to the appropriate format and can be read as + * required. This bit is not modified by internal functions + * or !RESET. A 1 in DM signifies binary data, while a 0 in + * DM specifies BCD data. + * + * * Square-Wave Enable (SQWE) + * When this bit is set to 1, a square-wave signal at the + * frequency set by the rate-selection bits RS3-RS0 is driven + * out on the SQW pin. When the SQWE bit is set to 0, the + * SQW pin is held low. SQWE is a read/write bit and is + * cleared by !RESET. SQWE is low if disabled, and is high + * impedance when VCC is below VPF. SQWE is cleared to 0 on + * !RESET. + * + * * Update-Ended Interrupt Enable (UIE) + * This bit is a read/write bit that enables the update-end + * flag (UF) bit in Register C to assert !IRQ. The !RESET + * pin going low or the SET bit going high clears the UIE bit. + * The internal functions of the device do not affect the UIE + * bit, but is cleared to 0 on !RESET. + * + * * Alarm Interrupt Enable (AIE) + * This bit is a read/write bit that, when set to 1, permits + * the alarm flag (AF) bit in Register C to assert !IRQ. An + * alarm interrupt occurs for each second that the three time + * bytes equal the three alarm bytes, including a don't-care + * alarm code of binary 11XXXXXX. The AF bit does not + * initiate the !IRQ signal when the AIE bit is set to 0. + * The internal functions of the device do not affect the AIE + * bit, but is cleared to 0 on !RESET. + * + * * Periodic Interrupt Enable (PIE) + * The PIE bit is a read/write bit that allows the periodic + * interrupt flag (PF) bit in Register C to drive the !IRQ pin + * low. When the PIE bit is set to 1, periodic interrupts are + * generated by driving the !IRQ pin low at a rate specified + * by the RS3-RS0 bits of Register A. A 0 in the PIE bit + * blocks the !IRQ output from being driven by a periodic + * interrupt, but the PF bit is still set at the periodic + * rate. PIE is not modified b any internal device functions, + * but is cleared to 0 on !RESET. + * + * * SET + * When the SET bit is 0, the update transfer functions + * normally by advancing the counts once per second. When + * the SET bit is written to 1, any update transfer is + * inhibited, and the program can initialize the time and + * calendar bytes without an update occurring in the midst of + * initializing. Read cycles can be executed in a similar + * manner. SET is a read/write bit and is not affected by + * !RESET or internal functions of the device. + * + * * Update-Ended Interrupt Flag (UF) + * This bit is set after each update cycle. When the UIE + * bit is set to 1, the 1 in UF causes the IRQF bit to be + * a 1, which asserts the !IRQ pin. This bit can be + * cleared by reading Register C or with a !RESET. + * + * * Alarm Interrupt Flag (AF) + * A 1 in the AF bit indicates that the current time has + * matched the alarm time. If the AIE bit is also 1, the + * !IRQ pin goes low and a 1 appears in the IRQF bit. This + * bit can be cleared by reading Register C or with a + * !RESET. + * + * * Periodic Interrupt Flag (PF) + * This bit is read-only and is set to 1 when an edge is + * detected on the selected tap of the divider chain. The + * RS3 through RS0 bits establish the periodic rate. PF is + * set to 1 independent of the state of the PIE bit. When + * both PF and PIE are 1s, the !IRQ signal is active and + * sets the IRQF bit. This bit can be cleared by reading + * Register C or with a !RESET. + * + * * Interrupt Request Flag (IRQF) + * The interrupt request flag (IRQF) is set to a 1 when one + * or more of the following are true: + * - PF == PIE == 1 + * - AF == AIE == 1 + * - UF == UIE == 1 + * Any time the IRQF bit is a 1, the !IRQ pin is driven low. + * All flag bits are cleared after Register C is read by the + * program or when the !RESET pin is low. + * + * * Valid RAM and Time (VRT) + * This bit indicates the condition of the battery connected + * to the VBAT pin. This bit is not writeable and should + * always be 1 when read. If a 0 is ever present, an + * exhausted internal lithium energy source is indicated and + * both the contents of the RTC data and RAM data are + * questionable. This bit is unaffected by !RESET. + * + * This file implements a generic version of the RTC/NVRAM chip, + * including the later update (DS12887A) which implemented a + * "century" register to be compatible with Y2K. + * + * + * + * Authors: Fred N. van Kempen, + * Miran Grca, + * Mahod, + * Sarah Walker, + * + * Copyright 2017-2020 Fred N. van Kempen. + * Copyright 2016-2020 Miran Grca. + * Copyright 2008-2020 Sarah Walker. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the: + * + * Free Software Foundation, Inc. + * 59 Temple Place - Suite 330 + * Boston, MA 02111-1307 + * USA. + */ +#include +#include +#include +#include +#include +#include +#include +#include <86box/86box.h> +#include "cpu.h" +#include <86box/machine.h> +#include <86box/io.h> +#include <86box/mem.h> +#include <86box/nmi.h> +#include <86box/pic.h> +#include <86box/timer.h> +#include <86box/pit.h> +#include <86box/rom.h> +#include <86box/device.h> +#include <86box/nvr.h> + +/* RTC registers and bit definitions. */ +#define RTC_SECONDS 0 +#define RTC_ALSECONDS 1 +#define AL_DONTCARE 0xc0 /* Alarm time is not set */ +#define RTC_MINUTES 2 +#define RTC_ALMINUTES 3 +#define RTC_HOURS 4 +#define RTC_AMPM 0x80 /* PM flag if 12h format in use */ +#define RTC_ALHOURS 5 +#define RTC_DOW 6 +#define RTC_DOM 7 +#define RTC_MONTH 8 +#define RTC_YEAR 9 +#define RTC_REGA 10 +#define REGA_UIP 0x80 +#define REGA_DV2 0x40 +#define REGA_DV1 0x20 +#define REGA_DV0 0x10 +#define REGA_DV 0x70 +#define REGA_RS3 0x08 +#define REGA_RS2 0x04 +#define REGA_RS1 0x02 +#define REGA_RS0 0x01 +#define REGA_RS 0x0f +#define RTC_REGB 11 +#define REGB_SET 0x80 +#define REGB_PIE 0x40 +#define REGB_AIE 0x20 +#define REGB_UIE 0x10 +#define REGB_SQWE 0x08 +#define REGB_DM 0x04 +#define REGB_2412 0x02 +#define REGB_DSE 0x01 +#define RTC_REGC 12 +#define REGC_IRQF 0x80 +#define REGC_PF 0x40 +#define REGC_AF 0x20 +#define REGC_UF 0x10 +#define RTC_REGD 13 +#define REGD_VRT 0x80 +#define RTC_CENTURY_AT 0x32 /* century register for AT etc */ +#define RTC_CENTURY_PS 0x37 /* century register for PS/1 PS/2 */ +#define RTC_CENTURY_ELT 0x1A /* century register for Epson Equity LT */ +#define RTC_ALDAY 0x7D /* VIA VT82C586B - alarm day */ +#define RTC_ALMONTH 0x7E /* VIA VT82C586B - alarm month */ +#define RTC_CENTURY_VIA 0x7F /* century register for VIA VT82C586B */ + +#define RTC_ALDAY_SIS 0x7E /* Day of Month Alarm for SiS */ +#define RTC_ALMONT_SIS 0x7F /* Month Alarm for SiS */ + +#define RTC_REGS 14 /* number of registers */ + +#define FLAG_NO_NMI 0x01 +#define FLAG_AMI_1992_HACK 0x02 +#define FLAG_AMI_1994_HACK 0x04 +#define FLAG_AMI_1995_HACK 0x08 +#define FLAG_P6RP4_HACK 0x10 +#define FLAG_PIIX4 0x20 + +typedef struct { + int8_t stat; + + uint8_t cent, def, + flags, read_addr, + wp_0d, wp_32, + pad, pad0; + + uint8_t addr[8], wp[2], + bank[8], *lock; + + int16_t count, state; + + uint64_t ecount, + rtc_time; + pc_timer_t update_timer, + rtc_timer; +} local_t; + +static uint8_t nvr_at_inited = 0; + +/* Get the current NVR time. */ +static void +time_get(nvr_t *nvr, struct tm *tm) +{ + local_t *local = (local_t *) nvr->data; + int8_t temp; + + if (nvr->regs[RTC_REGB] & REGB_DM) { + /* NVR is in Binary data mode. */ + tm->tm_sec = nvr->regs[RTC_SECONDS]; + tm->tm_min = nvr->regs[RTC_MINUTES]; + temp = nvr->regs[RTC_HOURS]; + tm->tm_wday = (nvr->regs[RTC_DOW] - 1); + tm->tm_mday = nvr->regs[RTC_DOM]; + tm->tm_mon = (nvr->regs[RTC_MONTH] - 1); + tm->tm_year = nvr->regs[RTC_YEAR]; + if (local->cent != 0xFF) + tm->tm_year += (nvr->regs[local->cent] * 100) - 1900; + } else { + /* NVR is in BCD data mode. */ + tm->tm_sec = RTC_DCB(nvr->regs[RTC_SECONDS]); + tm->tm_min = RTC_DCB(nvr->regs[RTC_MINUTES]); + temp = RTC_DCB(nvr->regs[RTC_HOURS]); + tm->tm_wday = (RTC_DCB(nvr->regs[RTC_DOW]) - 1); + tm->tm_mday = RTC_DCB(nvr->regs[RTC_DOM]); + tm->tm_mon = (RTC_DCB(nvr->regs[RTC_MONTH]) - 1); + tm->tm_year = RTC_DCB(nvr->regs[RTC_YEAR]); + if (local->cent != 0xFF) + tm->tm_year += (RTC_DCB(nvr->regs[local->cent]) * 100) - 1900; + } + + /* Adjust for 12/24 hour mode. */ + if (nvr->regs[RTC_REGB] & REGB_2412) + tm->tm_hour = temp; + else + tm->tm_hour = ((temp & ~RTC_AMPM) % 12) + ((temp & RTC_AMPM) ? 12 : 0); +} + +/* Set the current NVR time. */ +static void +time_set(nvr_t *nvr, struct tm *tm) +{ + local_t *local = (local_t *) nvr->data; + int year = (tm->tm_year + 1900); + + if (nvr->regs[RTC_REGB] & REGB_DM) { + /* NVR is in Binary data mode. */ + nvr->regs[RTC_SECONDS] = tm->tm_sec; + nvr->regs[RTC_MINUTES] = tm->tm_min; + nvr->regs[RTC_DOW] = (tm->tm_wday + 1); + nvr->regs[RTC_DOM] = tm->tm_mday; + nvr->regs[RTC_MONTH] = (tm->tm_mon + 1); + nvr->regs[RTC_YEAR] = (year % 100); + if (local->cent != 0xFF) + nvr->regs[local->cent] = (year / 100); + + if (nvr->regs[RTC_REGB] & REGB_2412) { + /* NVR is in 24h mode. */ + nvr->regs[RTC_HOURS] = tm->tm_hour; + } else { + /* NVR is in 12h mode. */ + nvr->regs[RTC_HOURS] = (tm->tm_hour % 12) ? (tm->tm_hour % 12) : 12; + if (tm->tm_hour > 11) + nvr->regs[RTC_HOURS] |= RTC_AMPM; + } + } else { + /* NVR is in BCD data mode. */ + nvr->regs[RTC_SECONDS] = RTC_BCD(tm->tm_sec); + nvr->regs[RTC_MINUTES] = RTC_BCD(tm->tm_min); + nvr->regs[RTC_DOW] = RTC_BCD(tm->tm_wday + 1); + nvr->regs[RTC_DOM] = RTC_BCD(tm->tm_mday); + nvr->regs[RTC_MONTH] = RTC_BCD(tm->tm_mon + 1); + nvr->regs[RTC_YEAR] = RTC_BCD(year % 100); + if (local->cent != 0xFF) + nvr->regs[local->cent] = RTC_BCD(year / 100); + + if (nvr->regs[RTC_REGB] & REGB_2412) { + /* NVR is in 24h mode. */ + nvr->regs[RTC_HOURS] = RTC_BCD(tm->tm_hour); + } else { + /* NVR is in 12h mode. */ + nvr->regs[RTC_HOURS] = (tm->tm_hour % 12) + ? RTC_BCD(tm->tm_hour % 12) + : RTC_BCD(12); + if (tm->tm_hour > 11) + nvr->regs[RTC_HOURS] |= RTC_AMPM; + } + } +} + +/* Check if the current time matches a set alarm time. */ +static int8_t +check_alarm(nvr_t *nvr, int8_t addr) +{ + return ((nvr->regs[addr + 1] == nvr->regs[addr]) || ((nvr->regs[addr + 1] & AL_DONTCARE) == AL_DONTCARE)); +} + +/* Check for VIA stuff. */ +static int8_t +check_alarm_via(nvr_t *nvr, int8_t addr, int8_t addr_2) +{ + local_t *local = (local_t *) nvr->data; + + if (local->cent == RTC_CENTURY_VIA) { + return ((nvr->regs[addr_2] == nvr->regs[addr]) || ((nvr->regs[addr_2] & AL_DONTCARE) == AL_DONTCARE)); + } else + return 1; +} + +/* Update the NVR registers from the internal clock. */ +static void +timer_update(void *priv) +{ + nvr_t *nvr = (nvr_t *) priv; + local_t *local = (local_t *) nvr->data; + struct tm tm; + + local->ecount = 0LL; + + if (!(nvr->regs[RTC_REGB] & REGB_SET)) { + /* Get the current time from the internal clock. */ + nvr_time_get(&tm); + + /* Update registers with current time. */ + time_set(nvr, &tm); + + /* Clear update status. */ + local->stat = 0x00; + + /* Check for any alarms we need to handle. */ + if (check_alarm(nvr, RTC_SECONDS) && check_alarm(nvr, RTC_MINUTES) && check_alarm(nvr, RTC_HOURS) && check_alarm_via(nvr, RTC_DOM, RTC_ALDAY) && check_alarm_via(nvr, RTC_MONTH, RTC_ALMONTH) /* && + check_alarm_via(nvr, RTC_DOM, RTC_ALDAY_SIS) && + check_alarm_via(nvr, RTC_MONTH, RTC_ALMONT_SIS)*/ + ) { + nvr->regs[RTC_REGC] |= REGC_AF; + if (nvr->regs[RTC_REGB] & REGB_AIE) { + /* Generate an interrupt. */ + if ((nvr->irq != -1) && (!(nvr->regs[RTC_REGC] & REGC_IRQF))) { + picintlevel(1 << nvr->irq); + nvr->regs[RTC_REGC] |= REGC_IRQF; + } + } + } + + /* + * The flag and interrupt should be issued + * on update ended, not started. + */ + nvr->regs[RTC_REGC] |= REGC_UF; + if (nvr->regs[RTC_REGB] & REGB_UIE) { + /* Generate an interrupt. */ + if ((nvr->irq != -1) && (!(nvr->regs[RTC_REGC] & REGC_IRQF))) { + picintlevel(1 << nvr->irq); + nvr->regs[RTC_REGC] |= REGC_IRQF; + } + } + } +} + +static void +timer_load_count(nvr_t *nvr) +{ + int c = nvr->regs[RTC_REGA] & REGA_RS; + local_t *local = (local_t *) nvr->data; + + timer_disable(&local->rtc_timer); + + if ((nvr->regs[RTC_REGA] & 0x70) != 0x20) { + local->state = 0; + return; + } + + local->state = 1; + + switch (c) { + case 0: + local->state = 0; + break; + case 1: + case 2: + local->count = 1 << (c + 6); + timer_set_delay_u64(&local->rtc_timer, (local->count) * RTCCONST); + break; + default: + local->count = 1 << (c - 1); + timer_set_delay_u64(&local->rtc_timer, (local->count) * RTCCONST); + break; + } +} + +static void +timer_intr(void *priv) +{ + nvr_t *nvr = (nvr_t *) priv; + local_t *local = (local_t *) nvr->data; + + if (local->state == 1) { + timer_load_count(nvr); + + nvr->regs[RTC_REGC] |= REGC_PF; + if (nvr->regs[RTC_REGB] & REGB_PIE) { + /* Generate an interrupt. */ + if ((nvr->irq != -1) && (!(nvr->regs[RTC_REGC] & REGC_IRQF))) { + picintlevel(1 << nvr->irq); + nvr->regs[RTC_REGC] |= REGC_IRQF; + } + } + } +} + +/* Callback from internal clock, another second passed. */ +static void +timer_tick(nvr_t *nvr) +{ + local_t *local = (local_t *) nvr->data; + + /* Only update it there is no SET in progress. */ + if (!(nvr->regs[RTC_REGB] & REGB_SET)) { + /* Set the UIP bit, announcing the update. */ + local->stat = REGA_UIP; + + rtc_tick(); + + /* Schedule the actual update. */ + local->ecount = (244ULL + 1984ULL) * TIMER_USEC; + timer_set_delay_u64(&local->update_timer, local->ecount); + } +} + +static void +nvr_reg_common_write(uint16_t reg, uint8_t val, nvr_t *nvr, local_t *local) +{ + if ((reg == 0x2c) && (local->flags & FLAG_AMI_1994_HACK)) + nvr->is_new = 0; + if ((reg == 0x2d) && (local->flags & FLAG_AMI_1992_HACK)) + nvr->is_new = 0; + if ((reg == 0x52) && (local->flags & FLAG_AMI_1995_HACK)) + nvr->is_new = 0; + if ((reg >= 0x38) && (reg <= 0x3f) && local->wp[0]) + return; + if ((reg >= 0xb8) && (reg <= 0xbf) && local->wp[1]) + return; + if (local->lock[reg]) + return; + if (nvr->regs[reg] != val) { + nvr->regs[reg] = val; + nvr_dosave = 1; + } +} + +/* This must be exposed because ACPI uses it. */ +void +nvr_reg_write(uint16_t reg, uint8_t val, void *priv) +{ + nvr_t *nvr = (nvr_t *) priv; + local_t *local = (local_t *) nvr->data; + struct tm tm; + uint8_t old; + uint8_t irq = 0; + uint8_t old_irq = 0; + + old = nvr->regs[reg]; + switch (reg) { + case RTC_REGA: + nvr->regs[RTC_REGA] = val; + timer_load_count(nvr); + break; + + case RTC_REGB: + old_irq = (nvr->regs[RTC_REGB] & nvr->regs[RTC_REGC]) & 0x70; + nvr->regs[RTC_REGB] = val; + if (((old ^ val) & REGB_SET) && (val & REGB_SET)) { + /* According to the datasheet... */ + nvr->regs[RTC_REGA] &= ~REGA_UIP; + nvr->regs[RTC_REGB] &= ~REGB_UIE; + } + irq = (nvr->regs[RTC_REGB] & nvr->regs[RTC_REGC]) & 0x70; + if (old_irq && !irq) { + picintc(1 << nvr->irq); + nvr->regs[RTC_REGC] &= ~REGC_IRQF; + } else if (!old_irq && irq) { + picintlevel(1 << nvr->irq); + nvr->regs[RTC_REGC] |= REGC_IRQF; + } + break; + + case RTC_REGC: /* R/O */ + break; + + case RTC_REGD: /* R/O */ + /* This is needed for VIA, where writing to this register changes a write-only + bit whose value is read from power management register 42. */ + nvr->regs[RTC_REGD] = val & 0x80; + break; + + case 0x32: + if ((reg == 0x32) && (local->cent == RTC_CENTURY_VIA) && local->wp_32) + break; + nvr_reg_common_write(reg, val, nvr, local); + break; + + default: /* non-RTC registers are just NVRAM */ + nvr_reg_common_write(reg, val, nvr, local); + break; + } + + if ((reg < RTC_REGA) || ((local->cent != 0xff) && (reg == local->cent))) { + if ((reg != 1) && (reg != 3) && (reg != 5)) { + if ((old != val) && !(time_sync & TIME_SYNC_ENABLED)) { + /* Update internal clock. */ + time_get(nvr, &tm); + nvr_time_set(&tm); + nvr_dosave = 1; + } + } + } +} + +/* Write to one of the NVR registers. */ +static void +nvr_write(uint16_t addr, uint8_t val, void *priv) +{ + nvr_t *nvr = (nvr_t *) priv; + local_t *local = (local_t *) nvr->data; + uint8_t addr_id = (addr & 0x0e) >> 1; + + cycles -= ISA_CYCLES(8); + + if (local->bank[addr_id] == 0xff) + return; + + if (addr & 1) { + // if (local->bank[addr_id] == 0xff) + // return; + nvr_reg_write(local->addr[addr_id], val, priv); + } else { + local->addr[addr_id] = (val & (nvr->size - 1)); + /* Some chipsets use a 256 byte NVRAM but ports 70h and 71h always access only 128 bytes. */ + if (addr_id == 0x0) + local->addr[addr_id] &= 0x7f; + else if ((addr_id == 0x1) && (local->flags & FLAG_PIIX4)) + local->addr[addr_id] = (local->addr[addr_id] & 0x7f) | 0x80; + if (local->bank[addr_id] > 0) + local->addr[addr_id] = (local->addr[addr_id] & 0x7f) | (0x80 * local->bank[addr_id]); + if (!(local->flags & FLAG_NO_NMI)) + nmi_mask = (~val & 0x80); + } +} + +/* Read from one of the NVR registers. */ +static uint8_t +nvr_read(uint16_t addr, void *priv) +{ + nvr_t *nvr = (nvr_t *) priv; + local_t *local = (local_t *) nvr->data; + uint8_t ret; + uint8_t addr_id = (addr & 0x0e) >> 1; + uint16_t i; + uint16_t checksum = 0x0000; + + cycles -= ISA_CYCLES(8); + + if (local->bank[addr_id] == 0xff) + ret = 0xff; + else if (addr & 1) + switch (local->addr[addr_id]) { + case RTC_REGA: + ret = (nvr->regs[RTC_REGA] & 0x7f) | local->stat; + break; + + case RTC_REGC: + ret = nvr->regs[RTC_REGC]; + picintc(1 << nvr->irq); + nvr->regs[RTC_REGC] = 0x00; + break; + + case RTC_REGD: + /* Bits 6-0 of this register always read 0. Bit 7 is battery state, + we should always return it set, as that means the battery is OK. */ + ret = REGD_VRT; + break; + + case 0x2c: + if (!nvr->is_new && (local->flags & FLAG_AMI_1994_HACK)) + ret = nvr->regs[local->addr[addr_id]] & 0x7f; + else + ret = nvr->regs[local->addr[addr_id]]; + break; + + case 0x2d: + if (!nvr->is_new && (local->flags & FLAG_AMI_1992_HACK)) + ret = nvr->regs[local->addr[addr_id]] & 0xf7; + else + ret = nvr->regs[local->addr[addr_id]]; + break; + + case 0x2e: + case 0x2f: + if (!nvr->is_new && (local->flags & FLAG_AMI_1992_HACK)) { + for (i = 0x10; i <= 0x2d; i++) { + if (i == 0x2d) + checksum += (nvr->regs[i] & 0xf7); + else + checksum += nvr->regs[i]; + } + if (local->addr[addr_id] == 0x2e) + ret = checksum >> 8; + else + ret = checksum & 0xff; + } else if (!nvr->is_new && (local->flags & FLAG_AMI_1994_HACK)) { + for (i = 0x10; i <= 0x2d; i++) { + if (i == 0x2c) + checksum += (nvr->regs[i] & 0x7f); + else + checksum += nvr->regs[i]; + } + if (local->addr[addr_id] == 0x2e) + ret = checksum >> 8; + else + ret = checksum & 0xff; + } else + ret = nvr->regs[local->addr[addr_id]]; + break; + + case 0x3e: + case 0x3f: + if (!nvr->is_new && (local->flags & FLAG_AMI_1995_HACK)) { + /* The checksum at 3E-3F is for 37-3D and 40-7F. */ + for (i = 0x37; i <= 0x3d; i++) + checksum += nvr->regs[i]; + for (i = 0x40; i <= 0x7f; i++) { + if (i == 0x52) + checksum += (nvr->regs[i] & 0xf3); + else + checksum += nvr->regs[i]; + } + if (local->addr[addr_id] == 0x3e) + ret = checksum >> 8; + else + ret = checksum & 0xff; + } else if (!nvr->is_new && (local->flags & FLAG_P6RP4_HACK)) { + /* The checksum at 3E-3F is for 37-3D and 40-51. */ + for (i = 0x37; i <= 0x3d; i++) + checksum += nvr->regs[i]; + for (i = 0x40; i <= 0x51; i++) { + if (i == 0x43) + checksum += (nvr->regs[i] | 0x02); + else + checksum += nvr->regs[i]; + } + if (local->addr[addr_id] == 0x3e) + ret = checksum >> 8; + else + ret = checksum & 0xff; + } else + ret = nvr->regs[local->addr[addr_id]]; + break; + + case 0x43: + if (!nvr->is_new && (local->flags & FLAG_P6RP4_HACK)) + ret = nvr->regs[local->addr[addr_id]] | 0x02; + else + ret = nvr->regs[local->addr[addr_id]]; + break; + + case 0x52: + if (!nvr->is_new && (local->flags & FLAG_AMI_1995_HACK)) + ret = nvr->regs[local->addr[addr_id]] & 0xf3; + else + ret = nvr->regs[local->addr[addr_id]]; + break; + + default: + ret = nvr->regs[local->addr[addr_id]]; + break; + } + else { + ret = local->addr[addr_id]; + if (!local->read_addr) + ret &= 0x80; + if (alt_access) + ret = (ret & 0x7f) | (nmi_mask ? 0x00 : 0x80); + } + + return ret; +} + +/* Secondary NVR write - used by SMC. */ +static void +nvr_sec_write(uint16_t addr, uint8_t val, void *priv) +{ + nvr_write(0x72 + (addr & 1), val, priv); +} + +/* Secondary NVR read - used by SMC. */ +static uint8_t +nvr_sec_read(uint16_t addr, void *priv) +{ + return nvr_read(0x72 + (addr & 1), priv); +} + +/* Reset the RTC state to 1980/01/01 00:00. */ +static void +nvr_reset(nvr_t *nvr) +{ + local_t *local = (local_t *) nvr->data; + + /* memset(nvr->regs, local->def, RTC_REGS); */ + memset(nvr->regs, local->def, nvr->size); + nvr->regs[RTC_DOM] = 1; + nvr->regs[RTC_MONTH] = 1; + nvr->regs[RTC_YEAR] = RTC_BCD(80); + if (local->cent != 0xFF) + nvr->regs[local->cent] = RTC_BCD(19); + + nvr->regs[RTC_REGD] = REGD_VRT; +} + +/* Process after loading from file. */ +static void +nvr_start(nvr_t *nvr) +{ + local_t *local = (local_t *) nvr->data; + + struct tm tm; + int default_found = 0; + + for (uint16_t i = 0; i < nvr->size; i++) { + if (nvr->regs[i] == local->def) + default_found++; + } + + if (default_found == nvr->size) + nvr->regs[0x0e] = 0xff; /* If load failed or it loaded an uninitialized NVR, + mark everything as bad. */ + + /* Initialize the internal and chip times. */ + if (time_sync & TIME_SYNC_ENABLED) { + /* Use the internal clock's time. */ + nvr_time_get(&tm); + time_set(nvr, &tm); + } else { + /* Set the internal clock from the chip time. */ + time_get(nvr, &tm); + nvr_time_set(&tm); + } + + /* Start the RTC. */ + nvr->regs[RTC_REGA] = (REGA_RS2 | REGA_RS1); + nvr->regs[RTC_REGB] = REGB_2412; +} + +static void +nvr_at_speed_changed(void *priv) +{ + nvr_t *nvr = (nvr_t *) priv; + local_t *local = (local_t *) nvr->data; + + timer_load_count(nvr); + + timer_disable(&local->update_timer); + if (local->ecount > 0ULL) + timer_set_delay_u64(&local->update_timer, local->ecount); + + timer_disable(&nvr->onesec_time); + timer_set_delay_u64(&nvr->onesec_time, (10000ULL * TIMER_USEC)); +} + +void +nvr_at_handler(int set, uint16_t base, nvr_t *nvr) +{ + io_handler(set, base, 2, + nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr); +} + +void +nvr_at_index_read_handler(int set, uint16_t base, nvr_t *nvr) +{ + io_handler(0, base, 1, + NULL, NULL, NULL, nvr_write, NULL, NULL, nvr); + nvr_at_handler(0, base, nvr); + + if (set) + nvr_at_handler(1, base, nvr); + else { + io_handler(1, base, 1, + NULL, NULL, NULL, nvr_write, NULL, NULL, nvr); + io_handler(1, base + 1, 1, + nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr); + } +} + +void +nvr_at_sec_handler(int set, uint16_t base, nvr_t *nvr) +{ + io_handler(set, base, 2, + nvr_sec_read, NULL, NULL, nvr_sec_write, NULL, NULL, nvr); +} + +void +nvr_read_addr_set(int set, nvr_t *nvr) +{ + local_t *local = (local_t *) nvr->data; + + local->read_addr = set; +} + +void +nvr_wp_set(int set, int h, nvr_t *nvr) +{ + local_t *local = (local_t *) nvr->data; + + local->wp[h] = set; +} + +void +nvr_via_wp_set(int set, int reg, nvr_t *nvr) +{ + local_t *local = (local_t *) nvr->data; + + if (reg == 0x0d) + local->wp_0d = set; + else + local->wp_32 = set; +} + +void +nvr_bank_set(int base, uint8_t bank, nvr_t *nvr) +{ + local_t *local = (local_t *) nvr->data; + + local->bank[base] = bank; +} + +void +nvr_lock_set(int base, int size, int lock, nvr_t *nvr) +{ + local_t *local = (local_t *) nvr->data; + + for (int i = 0; i < size; i++) + local->lock[base + i] = lock; +} + +void +nvr_irq_set(int irq, nvr_t *nvr) +{ + nvr->irq = irq; +} + +static void +nvr_at_reset(void *priv) +{ + nvr_t *nvr = (nvr_t *) priv; + + /* These bits are reset on reset. */ + nvr->regs[RTC_REGB] &= ~(REGB_PIE | REGB_AIE | REGB_UIE | REGB_SQWE); + nvr->regs[RTC_REGC] &= ~(REGC_PF | REGC_AF | REGC_UF | REGC_IRQF); +} + +static void * +nvr_at_init(const device_t *info) +{ + local_t *local; + nvr_t *nvr; + + /* Allocate an NVR for this machine. */ + nvr = (nvr_t *) malloc(sizeof(nvr_t)); + if (nvr == NULL) + return (NULL); + memset(nvr, 0x00, sizeof(nvr_t)); + + local = (local_t *) malloc(sizeof(local_t)); + memset(local, 0x00, sizeof(local_t)); + nvr->data = local; + + /* This is machine specific. */ + nvr->size = machines[machine].nvrmask + 1; + local->lock = (uint8_t *) malloc(nvr->size); + memset(local->lock, 0x00, nvr->size); + local->def = 0xff /*0x00*/; + local->flags = 0x00; + switch (info->local & 0x0f) { + case 0: /* standard AT, no century register */ + if (info->local == 32) { + local->flags |= FLAG_P6RP4_HACK; + nvr->irq = 8; + local->cent = RTC_CENTURY_AT; + } else { + nvr->irq = 8; + local->cent = 0xff; + } + break; + + case 1: /* standard AT */ + case 5: /* AMI WinBIOS 1994 */ + case 6: /* AMI BIOS 1995 */ + if ((info->local & 0x1f) == 0x11) + local->flags |= FLAG_PIIX4; + else { + local->def = 0x00; + if ((info->local & 0x1f) == 0x15) + local->flags |= FLAG_AMI_1994_HACK; + else if ((info->local & 0x1f) == 0x16) + local->flags |= FLAG_AMI_1995_HACK; + else + local->def = 0xff; + } + nvr->irq = 8; + local->cent = RTC_CENTURY_AT; + break; + + case 2: /* PS/1 or PS/2 */ + nvr->irq = 8; + local->cent = RTC_CENTURY_PS; + local->def = 0x00; + if (info->local & 0x10) + local->flags |= FLAG_NO_NMI; + break; + + case 3: /* Amstrad PC's */ + nvr->irq = 1; + local->cent = RTC_CENTURY_AT; + local->def = 0xff; + if (info->local & 0x10) + local->flags |= FLAG_NO_NMI; + break; + + case 4: /* IBM AT */ + if (info->local & 0x10) { + local->def = 0x00; + local->flags |= FLAG_AMI_1992_HACK; + } else if (info->local == 36) + local->def = 0x00; + else + local->def = 0xff; + nvr->irq = 8; + local->cent = RTC_CENTURY_AT; + break; + + case 7: /* VIA VT82C586B */ + nvr->irq = 8; + local->cent = RTC_CENTURY_VIA; + break; + case 8: /* Epson Equity LT */ + nvr->irq = -1; + local->cent = RTC_CENTURY_ELT; + break; + } + + local->read_addr = 1; + + /* Set up any local handlers here. */ + nvr->reset = nvr_reset; + nvr->start = nvr_start; + nvr->tick = timer_tick; + + /* Initialize the generic NVR. */ + nvr_init(nvr); + + if (nvr_at_inited == 0) { + /* Start the timers. */ + timer_add(&local->update_timer, timer_update, nvr, 0); + + timer_add(&local->rtc_timer, timer_intr, nvr, 0); + /* On power on, if the oscillator is disabled, it's reenabled. */ + if ((nvr->regs[RTC_REGA] & 0x70) == 0x00) + nvr->regs[RTC_REGA] = (nvr->regs[RTC_REGA] & 0x8f) | 0x20; + nvr_at_reset(nvr); + timer_load_count(nvr); + + /* Set up the I/O handler for this device. */ + if (info->local == 8) { + io_sethandler(0x11b4, 2, + nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr); + } else { + io_sethandler(0x0070, 2, + nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr); + } + if (((info->local & 0x1f) == 0x11) || ((info->local & 0x1f) == 0x17)) { + io_sethandler(0x0072, 2, + nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr); + } + + nvr_at_inited = 1; + } + + return nvr; +} + +static void +nvr_at_close(void *priv) +{ + nvr_t *nvr = (nvr_t *) priv; + local_t *local = (local_t *) nvr->data; + + nvr_close(); + + timer_disable(&local->rtc_timer); + timer_disable(&local->update_timer); + timer_disable(&nvr->onesec_time); + + if (nvr != NULL) { + if (nvr->fn != NULL) + free(nvr->fn); + + if (nvr->data != NULL) + free(nvr->data); + + free(nvr); + } + + if (nvr_at_inited == 1) + nvr_at_inited = 0; +} + +const device_t at_nvr_old_device = { + .name = "PC/AT NVRAM (No century)", + .internal_name = "at_nvr_old", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t at_nvr_device = { + .name = "PC/AT NVRAM", + .internal_name = "at_nvr", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 1, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ps_nvr_device = { + .name = "PS/1 or PS/2 NVRAM", + .internal_name = "ps_nvr", + .flags = DEVICE_PS2, + .local = 2, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t amstrad_nvr_device = { + .name = "Amstrad NVRAM", + .internal_name = "amstrad_nvr", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 3, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ibmat_nvr_device = { + .name = "IBM AT NVRAM", + .internal_name = "ibmat_nvr", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 4, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t piix4_nvr_device = { + .name = "Intel PIIX4 PC/AT NVRAM", + .internal_name = "piix4_nvr", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0x10 | 1, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ps_no_nmi_nvr_device = { + .name = "PS/1 or PS/2 NVRAM (No NMI)", + .internal_name = "ps1_nvr", + .flags = DEVICE_PS2, + .local = 0x10 | 2, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t amstrad_no_nmi_nvr_device = { + .name = "Amstrad NVRAM (No NMI)", + .internal_name = "amstrad_nvr", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0x10 | 3, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ami_1992_nvr_device = { + .name = "AMI Color 1992 PC/AT NVRAM", + .internal_name = "ami_1992_nvr", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0x10 | 4, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ami_1994_nvr_device = { + .name = "AMI WinBIOS 1994 PC/AT NVRAM", + .internal_name = "ami_1994_nvr", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0x10 | 5, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ami_1995_nvr_device = { + .name = "AMI WinBIOS 1995 PC/AT NVRAM", + .internal_name = "ami_1995_nvr", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0x10 | 6, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t via_nvr_device = { + .name = "VIA PC/AT NVRAM", + .internal_name = "via_nvr", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 0x10 | 7, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t p6rp4_nvr_device = { + .name = "ASUS P/I-P6RP4 PC/AT NVRAM", + .internal_name = "p6rp4_nvr", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 32, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t amstrad_megapc_nvr_device = { + .name = "Amstrad MegaPC NVRAM", + .internal_name = "amstrad_megapc_nvr", + .flags = DEVICE_ISA | DEVICE_AT, + .local = 36, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; + +const device_t elt_nvr_device = { + .name = "Epson Equity LT NVRAM", + .internal_name = "elt_nvr", + .flags = DEVICE_ISA, + .local = 8, + .init = nvr_at_init, + .close = nvr_at_close, + .reset = nvr_at_reset, + { .available = NULL }, + .speed_changed = nvr_at_speed_changed, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/nvr_ps2.c b/src/nvr_ps2.c index 1ab97d8a3..dd87cbb80 100644 --- a/src/nvr_ps2.c +++ b/src/nvr_ps2.c @@ -78,7 +78,7 @@ ps2_nvr_read(uint16_t port, void *priv) break; } - return (ret); + return ret; } static void @@ -134,7 +134,7 @@ ps2_nvr_init(const device_t *info) fclose(f); } - return (nvr); + return nvr; } static void diff --git a/src/pci.c b/src/pci.c index 692733422..5b6a40138 100644 --- a/src/pci.c +++ b/src/pci.c @@ -49,25 +49,33 @@ typedef struct { uint8_t irq_line; } pci_mirq_t; -int pci_burst_time, agp_burst_time, - pci_nonburst_time, agp_nonburst_time; +int pci_burst_time; +int agp_burst_time; +int pci_nonburst_time; +int agp_nonburst_time; static pci_card_t pci_cards[32]; -static uint8_t pci_pmc = 0, last_pci_card = 0, last_normal_pci_card = 0, last_pci_bus = 1; -static uint8_t pci_card_to_slot_mapping[256][32], pci_bus_number_to_index_mapping[256]; -static uint8_t pci_irqs[16], pci_irq_level[16]; +static uint8_t pci_pmc = 0; +static uint8_t last_pci_card = 0; +static uint8_t last_normal_pci_card = 0; +static uint8_t last_pci_bus = 1; +static uint8_t pci_card_to_slot_mapping[256][32]; +static uint8_t pci_bus_number_to_index_mapping[256]; +static uint8_t pci_irqs[16]; +static uint8_t pci_irq_level[16]; static uint64_t pci_irq_hold[16]; static pci_mirq_t pci_mirqs[8]; -static int pci_type, - pci_switch, - pci_index, - pci_func, - pci_card, - pci_bus, - pci_enable, - pci_key; +static int pci_type; +static int pci_switch; +static int pci_index; +static int pci_func; +static int pci_card; +static int pci_bus; +static int pci_enable; +static int pci_key; static int trc_reg = 0; -static uint32_t pci_base = 0xc000, pci_size = 0x1000; +static uint32_t pci_base = 0xc000; +static uint32_t pci_size = 0x1000; static void pci_reset_regs(void); @@ -92,14 +100,12 @@ pci_log(const char *fmt, ...) static void pci_clear_slot(int card) { - int i; - pci_card_to_slot_mapping[pci_cards[card].bus][pci_cards[card].id] = 0xff; pci_cards[card].id = 0xff; pci_cards[card].type = 0xff; - for (i = 0; i < 4; i++) + for (uint8_t i = 0; i < 4; i++) pci_cards[card].irq_routing[i] = 0; pci_cards[card].read = NULL; @@ -110,14 +116,14 @@ pci_clear_slot(int card) void pci_relocate_slot(int type, int new_slot) { - int i, card = -1; + int card = -1; int old_slot; uint8_t mapping; if ((new_slot < 0) || (new_slot > 31)) return; - for (i = 0; i < 32; i++) { + for (uint8_t i = 0; i < 32; i++) { if ((pci_cards[i].bus == 0) && (pci_cards[i].type == type)) { card = i; break; @@ -495,9 +501,7 @@ pci_type2_write(uint16_t port, uint8_t val, void *priv) static void pci_type2_writel(uint16_t port, uint32_t val, void *priv) { - int i; - - for (i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { /* Make sure to have the DWORD write not pass through to PMC if mechanism 1 is in use, as otherwise, the PCI enable bits clobber it. */ if (!pci_pmc || ((port + i) != 0x0cfb)) @@ -837,11 +841,9 @@ pci_pic_reset(void) static void pci_reset_hard(void) { - int i; - pci_reset_regs(); - for (i = 0; i < 16; i++) { + for (uint8_t i = 0; i < 16; i++) { if (pci_irq_hold[i]) { pci_irq_hold[i] = 0; @@ -879,8 +881,7 @@ pci_reset(void) static void pci_slots_clear(void) { - uint8_t i, j; - + uint8_t i; last_pci_card = last_normal_pci_card = 0; last_pci_bus = 1; @@ -889,7 +890,7 @@ pci_slots_clear(void) i = 0; do { - for (j = 0; j < 32; j++) + for (uint8_t j = 0; j < 32; j++) pci_card_to_slot_mapping[i][j] = 0xff; pci_bus_number_to_index_mapping[i] = 0xff; } while (i++ < 0xff); @@ -1095,9 +1096,9 @@ uint8_t pci_find_slot(uint8_t add_type, uint8_t ignore_slot) { pci_card_t *dev; - uint8_t i, ret = 0xff; + uint8_t ret = 0xff; - for (i = 0; i < last_pci_card; i++) { + for (uint8_t i = 0; i < last_pci_card; i++) { dev = &pci_cards[i]; if (!dev->read && !dev->write && ((ignore_slot == 0xff) || (i != ignore_slot))) { @@ -1122,7 +1123,8 @@ uint8_t pci_add_card(uint8_t add_type, uint8_t (*read)(int func, int addr, void *priv), void (*write)(int func, int addr, uint8_t val, void *priv), void *priv) { pci_card_t *dev; - uint8_t i, j; + uint8_t i; + uint8_t j; if (add_type < PCI_ADD_AGP) pci_log("pci_add_card(): Adding PCI CARD at specific slot %02X [SPECIFIC]\n", add_type); diff --git a/src/pci_dummy.c b/src/pci_dummy.c index 1d0c95be2..b85df7ab9 100644 --- a/src/pci_dummy.c +++ b/src/pci_dummy.c @@ -278,9 +278,9 @@ const device_t pci_dummy_device = { void pci_dummy_init(int min_slot, int max_slot, int nb_slot, int sb_slot) { - int i = 0, j = 1; + int j = 1; - for (i = min_slot; i <= max_slot; i++) { + for (int i = min_slot; i <= max_slot; i++) { if ((i != nb_slot) && (i != sb_slot)) { pci_register_slot(i, PCI_CARD_NORMAL, 1, 3, 2, 4); device_add_inst(&pci_dummy_device, j); diff --git a/src/pic.c b/src/pic.c index 9ebf9ac00..53cd76876 100644 --- a/src/pic.c +++ b/src/pic.c @@ -45,17 +45,21 @@ enum { STATE_ICW4 }; -pic_t pic, pic2; +pic_t pic; +pic_t pic2; static pc_timer_t pic_timer; -static int shadow = 0, elcr_enabled = 0, - tmr_inited = 0, latched = 0, - pic_pci = 0, kbd_latch = 0, - mouse_latch = 0; +static int shadow = 0; +static int elcr_enabled = 0; +static int tmr_inited = 0; +static int latched = 0; +static int pic_pci = 0; +static int kbd_latch = 0; +static int mouse_latch = 0; -static uint16_t smi_irq_mask = 0x0000, - smi_irq_status = 0x0000; +static uint16_t smi_irq_mask = 0x0000; +static uint16_t smi_irq_status = 0x0000; static uint16_t latched_irqs = 0x0000; @@ -187,10 +191,10 @@ find_best_interrupt(pic_t *dev) { uint8_t b; uint8_t intr; - int i, j; + int j; int ret = -1; - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { j = (i + dev->priority) & 7; b = 1 << j; @@ -330,10 +334,11 @@ pic_acknowledge(pic_t *dev) static uint8_t pic_non_specific_find(pic_t *dev) { - int i, j; - uint8_t b, irq = 0xff; + int j; + uint8_t b; + uint8_t irq = 0xff; - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { j = (i + dev->priority) & 7; b = (1 << j); @@ -616,12 +621,13 @@ pic2_init(void) void picint_common(uint16_t num, int level, int set) { - int i, raise; - uint8_t b, slaves = 0; + int raise; + uint8_t b; + uint8_t slaves = 0; /* Make sure to ignore all slave IRQ's, and in case of AT+, translate IRQ 2 to IRQ 9. */ - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { b = (1 << i); raise = num & b; @@ -804,7 +810,7 @@ pic_irq_ack(void) int picinterrupt(void) { - int i, ret = -1; + int ret = -1; if (pic.int_pending) { if (pic_slave_on(&pic, pic.interrupt)) { @@ -822,7 +828,7 @@ picinterrupt(void) pit_devs[1].set_gate(pit_devs[1].data, 0, 0); /* Two ACK's - do them in a loop to avoid potential compiler misoptimizations. */ - for (i = 0; i < 2; i++) { + for (uint8_t i = 0; i < 2; i++) { ret = pic_irq_ack_read(&pic, pic.ack_bytes); pic.ack_bytes = (pic.ack_bytes + 1) % (pic_i86_mode(&pic) ? 2 : 3); diff --git a/src/pit.c b/src/pit.c index 27e1beaad..e0c500ea6 100644 --- a/src/pit.c +++ b/src/pit.c @@ -44,20 +44,28 @@ pit_intf_t pit_devs[2]; -double cpuclock, PITCONSTD, - SYSCLK, - isa_timing, - bus_timing, pci_timing, agp_timing, - PCICLK, AGPCLK; +double cpuclock; +double PITCONSTD; +double SYSCLK; +double isa_timing; +double bus_timing; +double pci_timing; +double agp_timing; +double PCICLK; +double AGPCLK; -uint64_t PITCONST, ISACONST, - CGACONST, - MDACONST, HERCCONST, - VGACONST1, VGACONST2, - RTCCONST, ACPICONST; +uint64_t PITCONST; +uint64_t ISACONST; +uint64_t CGACONST; +uint64_t MDACONST; +uint64_t HERCCONST; +uint64_t VGACONST1; +uint64_t VGACONST2; +uint64_t RTCCONST; +uint64_t ACPICONST; -int refresh_at_enable = 1, - io_delay = 5; +int refresh_at_enable = 1; +int io_delay = 5; int64_t firsttime = 1; @@ -482,11 +490,10 @@ static void pit_timer_over(void *p) { pit_t *dev = (pit_t *) p; - int i; dev->clock ^= 1; - for (i = 0; i < 3; i++) + for (uint8_t i = 0; i < 3; i++) pit_ctr_set_clock_common(&dev->counters[i], dev->clock); timer_advance_u64(&dev->callback_timer, PITCONST >> 1ULL); @@ -605,7 +612,8 @@ pit_read(uint16_t addr, void *priv) { pit_t *dev = (pit_t *) priv; uint8_t ret = 0xff; - int count, t = (addr & 3); + int count; + int t = (addr & 3); ctr_t *ctr; switch (addr & 3) { @@ -752,13 +760,11 @@ ctr_reset(ctr_t *ctr) void pit_reset(pit_t *dev) { - int i; - memset(dev, 0, sizeof(pit_t)); dev->clock = 0; - for (i = 0; i < 3; i++) + for (uint8_t i = 0; i < 3; i++) ctr_reset(&dev->counters[i]); /* Disable speaker gate. */ @@ -880,7 +886,6 @@ const device_t i8254_ps2_device = { pit_t * pit_common_init(int type, void (*out0)(int new_out, int old_out), void (*out1)(int new_out, int old_out)) { - int i; void *pit; pit_intf_t *pit_intf = &pit_devs[0]; @@ -907,7 +912,7 @@ pit_common_init(int type, void (*out0)(int new_out, int old_out), void (*out1)(i pit_intf->data = pit; - for (i = 0; i < 3; i++) { + for (uint8_t i = 0; i < 3; i++) { pit_intf->set_gate(pit_intf->data, i, 1); pit_intf->set_using_timer(pit_intf->data, i, 1); } @@ -972,9 +977,9 @@ pit_set_clock(int clock) cpuclock = (double) clock; PITCONSTD = (cpuclock / 1193182.0); - PITCONST = (uint64_t) (PITCONSTD * (double) (1ull << 32)); - CGACONST = (uint64_t) ((cpuclock / (19687503.0 / 11.0)) * (double) (1ull << 32)); - ISACONST = (uint64_t) ((cpuclock / (double) cpu_isa_speed) * (double) (1ull << 32)); + PITCONST = (uint64_t) (PITCONSTD * (double) (1ULL << 32)); + CGACONST = (uint64_t) ((cpuclock / (19687503.0 / 11.0)) * (double) (1ULL << 32)); + ISACONST = (uint64_t) ((cpuclock / (double) cpu_isa_speed) * (double) (1ULL << 32)); xt_cpu_multi = 1ULL; } else { cpuclock = 14318184.0; @@ -1022,8 +1027,8 @@ pit_set_clock(int clock) CGACONST = (16ULL << 32LL); } else if (cpuclock != 14318184.0) { PITCONSTD = (cpuclock / 1193182.0); - PITCONST = (uint64_t) (PITCONSTD * (double) (1ull << 32)); - CGACONST = (uint64_t) (((cpuclock / (19687503.0 / 11.0)) * (double) (1ull << 32))); + PITCONST = (uint64_t) (PITCONSTD * (double) (1ULL << 32)); + CGACONST = (uint64_t) ((cpuclock / (19687503.0 / 11.0)) * (double) (1ULL << 32)); } ISACONST = (1ULL << 32ULL); @@ -1033,13 +1038,13 @@ pit_set_clock(int clock) /* Delay for empty I/O ports. */ io_delay = (int) round(((double) cpu_s->rspeed) / 3000000.0); - MDACONST = (uint64_t) (cpuclock / 2032125.0 * (double) (1ull << 32)); + MDACONST = (uint64_t) (cpuclock / 2032125.0 * (double) (1ULL << 32)); HERCCONST = MDACONST; - VGACONST1 = (uint64_t) (cpuclock / 25175000.0 * (double) (1ull << 32)); - VGACONST2 = (uint64_t) (cpuclock / 28322000.0 * (double) (1ull << 32)); - RTCCONST = (uint64_t) (cpuclock / 32768.0 * (double) (1ull << 32)); + VGACONST1 = (uint64_t) (cpuclock / 25175000.0 * (double) (1ULL << 32)); + VGACONST2 = (uint64_t) (cpuclock / 28322000.0 * (double) (1ULL << 32)); + RTCCONST = (uint64_t) (cpuclock / 32768.0 * (double) (1ULL << 32)); - TIMER_USEC = (uint64_t) ((cpuclock / 1000000.0) * (double) (1ull << 32)); + TIMER_USEC = (uint64_t) ((cpuclock / 1000000.0) * (double) (1ULL << 32)); isa_timing = (cpuclock / (double) cpu_isa_speed); if (cpu_64bitbus) diff --git a/src/pit_fast.c b/src/pit_fast.c index dac71aaec..4e7bc77c7 100644 --- a/src/pit_fast.c +++ b/src/pit_fast.c @@ -577,11 +577,9 @@ ctr_reset(ctrf_t *ctr) static void pitf_reset(pitf_t *dev) { - int i; - memset(dev, 0, sizeof(pitf_t)); - for (i = 0; i < 3; i++) + for (uint8_t i = 0; i < 3; i++) ctr_reset(&dev->counters[i]); /* Disable speaker gate. */ diff --git a/src/port_6x.c b/src/port_6x.c index 88d8820b7..2bfebcee0 100644 --- a/src/port_6x.c +++ b/src/port_6x.c @@ -79,7 +79,7 @@ port_61_read_simple(uint16_t port, void *priv) if (ppispeakon) ret |= 0x20; - return (ret); + return ret; } static uint8_t @@ -102,7 +102,7 @@ port_61_read(uint16_t port, void *priv) if (dev->flags & PORT_6X_TURBO) ret = (ret & 0xfb) | (xi8088_turbo_get() ? 0x04 : 0x00); - return (ret); + return ret; } static uint8_t @@ -114,8 +114,8 @@ port_62_read(uint16_t port, void *priv) ret = 0x00; if (ppi.pb & 0x8) { /* Switches 4, 5 - floppy drives (number) */ - int i, fdd_count = 0; - for (i = 0; i < FDD_NUM; i++) { + int fdd_count = 0; + for (uint8_t i = 0; i < FDD_NUM; i++) { if (fdd_get_flags(i)) fdd_count++; } @@ -138,7 +138,7 @@ port_62_read(uint16_t port, void *priv) ret |= 0x02; } - return (ret); + return ret; } static void diff --git a/src/random.c b/src/random.c index 18c52ef02..3f5fed1b9 100644 --- a/src/random.c +++ b/src/random.c @@ -51,7 +51,8 @@ static __inline unsigned long long rdtsc(void) { #if defined(__i386__) || defined(__x86_64__) - unsigned hi, lo; + unsigned int hi; + unsigned int lo; # ifdef _MSC_VER __asm { rdtsc diff --git a/src/timer.c b/src/timer.c index 7a6600fc3..2d75e532e 100644 --- a/src/timer.c +++ b/src/timer.c @@ -132,7 +132,8 @@ timer_process(void) void timer_close(void) { - pc_timer_t *t = timer_head, *r; + pc_timer_t *t = timer_head; + pc_timer_t *r; /* Set all timers' prev and next to NULL so it is assured that timers that are not in malloc'd structs don't keep pointing diff --git a/src/upi42.c b/src/upi42.c index 4c22c5ed5..e35a0752f 100644 --- a/src/upi42.c +++ b/src/upi42.c @@ -224,7 +224,8 @@ upi42_op_XCH_A_Rr(upi42_t *upi42, uint32_t fetchdat) static int upi42_op_XCH_A_indRr(upi42_t *upi42, uint32_t fetchdat) { - uint8_t temp = upi42->a, addr = upi42->ram[fetchdat & 1] & upi42->rammask; + uint8_t temp = upi42->a; + uint8_t addr = upi42->ram[fetchdat & 1] & upi42->rammask; upi42->a = upi42->ram[addr]; upi42->ram[addr] = temp; return 1; @@ -233,7 +234,8 @@ upi42_op_XCH_A_indRr(upi42_t *upi42, uint32_t fetchdat) static int upi42_op_XCHD_A_indRr(upi42_t *upi42, uint32_t fetchdat) { - uint8_t temp = upi42->a, addr = upi42->ram[fetchdat & 1] & upi42->rammask; + uint8_t temp = upi42->a; + uint8_t addr = upi42->ram[fetchdat & 1] & upi42->rammask; upi42->a = (upi42->a & 0xf0) | (upi42->ram[addr] & 0x0f); upi42->ram[addr] = (upi42->ram[addr] & 0xf0) | (temp & 0x0f); return 1; @@ -1172,7 +1174,8 @@ static void upi42_write(uint16_t port, uint8_t val, void *priv) { upi42_t *upi42 = (upi42_t *) priv; - uint32_t temp_type, uint8_t *temp_rom; + uint32_t temp_type; + uint8_t *temp_rom; int i; switch (port) { diff --git a/src/usb.c b/src/usb.c index c6351ec48..9993193ce 100644 --- a/src/usb.c +++ b/src/usb.c @@ -149,8 +149,9 @@ usb_interrupt_ohci(usb_t *dev, uint32_t level) static uint8_t uhci_reg_read(uint16_t addr, void *p) { - usb_t *dev = (usb_t *) p; - uint8_t ret, *regs = dev->uhci_io; + usb_t *dev = (usb_t *) p; + uint8_t ret; + uint8_t *regs = dev->uhci_io; addr &= 0x0000001f; @@ -345,7 +346,8 @@ ohci_set_interrupt(usb_t *dev, uint8_t bit) static int ohci_copy_td_input(usb_t* dev, usb_td_t *td, uint8_t *buf, int len) { - uint32_t ptr, n; + uint32_t ptr; + uint32_t n; ptr = td->CBP; n = 0x1000 - (ptr & 0xfff); @@ -365,7 +367,8 @@ static int ohci_copy_td_input(usb_t* dev, usb_td_t *td, static int ohci_copy_td_output(usb_t* dev, usb_td_t *td, uint8_t *buf, int len) { - uint32_t ptr, n; + uint32_t ptr; + uint32_t n; ptr = td->CBP; n = 0x1000 - (ptr & 0xfff); @@ -388,10 +391,12 @@ static int ohci_copy_td_output(usb_t* dev, usb_td_t *td, uint8_t ohci_service_transfer_desc(usb_t* dev, usb_ed_t* endpoint_desc) { - uint32_t td_addr = endpoint_desc->HeadP & ~(0xf); + uint32_t td_addr = endpoint_desc->HeadP & ~0xf; usb_td_t td; - uint8_t dir, pid_token = 255; - uint32_t len = 0, pktlen = 0; + uint8_t dir; + uint8_t pid_token = 255; + uint32_t len = 0; + uint32_t pktlen = 0; uint32_t actual_length = 0; uint32_t i = 0; uint8_t device_result = 0; @@ -522,16 +527,15 @@ ohci_service_endpoint_desc(usb_t* dev, uint32_t head) usb_ed_t endpoint_desc; uint8_t active = 0; uint32_t next = 0; - uint32_t cur = 0; uint32_t limit_counter = 0; if (head == 0) return 0; - for (cur = head; cur && limit_counter++ < ENDPOINT_DESC_LIMIT; cur = next) { + for (uint32_t cur = head; cur && limit_counter++ < ENDPOINT_DESC_LIMIT; cur = next) { dma_bm_read(cur, (uint8_t*)&endpoint_desc, sizeof(usb_ed_t), 4); - next = endpoint_desc.NextED & ~(0xFu); + next = endpoint_desc.NextED & ~0xFu; if ((endpoint_desc.Control & (1 << 13)) || (endpoint_desc.HeadP & (1 << 0))) continue; @@ -542,7 +546,7 @@ ohci_service_endpoint_desc(usb_t* dev, uint32_t head) active = 1; - while ((endpoint_desc.HeadP & ~(0xFu)) != endpoint_desc.TailP) { + while ((endpoint_desc.HeadP & ~0xFu) != endpoint_desc.TailP) { ohci_service_transfer_desc(dev, &endpoint_desc); } diff --git a/src/vnc.c b/src/vnc.c index fcf966d65..8743c1e17 100644 --- a/src/vnc.c +++ b/src/vnc.c @@ -40,9 +40,11 @@ static rfbScreenInfoPtr rfb = NULL; static int clients; static int updatingSize; -static int allowedX, - allowedY; -static int ptr_x, ptr_y, ptr_but; +static int allowedX; +static int allowedY; +static int ptr_x; +static int ptr_y; +static int ptr_but; typedef struct { int buttons; @@ -174,7 +176,7 @@ vnc_newclient(rfbClientPtr cl) } /* For now, we always accept clients. */ - return (RFB_CLIENT_ACCEPT); + return RFB_CLIENT_ACCEPT; } static void @@ -194,14 +196,12 @@ vnc_display(rfbClientPtr cl) static void vnc_blit(int x, int y, int w, int h, int monitor_index) { - int row; - if (monitor_index || (x < 0) || (y < 0) || (w < VNC_MIN_X) || (h < VNC_MIN_Y) || (w > VNC_MAX_X) || (h > VNC_MAX_Y) || (buffer32 == NULL)) { video_blit_complete_monitor(monitor_index); return; } - for (row = 0; row < h; ++row) + for (int row = 0; row < h; ++row) video_copy(&(((uint8_t *) rfb->frameBuffer)[row * 2048 * sizeof(uint32_t)]), &(buffer32->line[y + row][x]), w * sizeof(uint32_t)); if (screenshots) @@ -267,7 +267,7 @@ vnc_init(UNUSED(void *arg)) vnc_log("VNC: init complete.\n"); - return (1); + return 1; } void diff --git a/src/win/win_joystick_rawinput.c b/src/win/win_joystick_rawinput.c index 2976a54b9..c4424e484 100644 --- a/src/win/win_joystick_rawinput.c +++ b/src/win/win_joystick_rawinput.c @@ -443,12 +443,12 @@ joystick_get_axis(int joystick_nr, int mapping) void joystick_process(void) { - int c, d; + int d; if (joystick_type == 7) return; - for (c = 0; c < joystick_get_max_joysticks(joystick_type); c++) { + for (int c = 0; c < joystick_get_max_joysticks(joystick_type); c++) { if (joystick_state[c].plat_joystick_nr) { int joystick_nr = joystick_state[c].plat_joystick_nr - 1; @@ -458,8 +458,10 @@ joystick_process(void) joystick_state[c].button[d] = plat_joystick_state[joystick_nr].b[joystick_state[c].button_mapping[d]]; for (d = 0; d < joystick_get_pov_count(joystick_type); d++) { - int x, y; - double angle, magnitude; + int x; + int y; + double angle; + double magnitude; x = joystick_get_axis(joystick_nr, joystick_state[c].pov_mapping[d][0]); y = joystick_get_axis(joystick_nr, joystick_state[c].pov_mapping[d][1]); diff --git a/src/win/win_serial_passthrough.c b/src/win/win_serial_passthrough.c index 1e190956d..274f83926 100644 --- a/src/win/win_serial_passthrough.c +++ b/src/win/win_serial_passthrough.c @@ -111,9 +111,9 @@ plat_serpt_set_params(void *p) } else { serialattr.fParity = 1; if (dev->serial->lcr & 0x20) { - serialattr.Parity = (MARKPARITY) + !!(dev->serial->lcr & 0x10); + serialattr.Parity = MARKPARITY + !!(dev->serial->lcr & 0x10); } else { - serialattr.Parity = (ODDPARITY) + !!(dev->serial->lcr & 0x10); + serialattr.Parity = ODDPARITY + !!(dev->serial->lcr & 0x10); } } From b48a56419ea766fdaa261589a70fd879b7abd464 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Mon, 15 May 2023 19:52:19 -0400 Subject: [PATCH 34/34] Re-add sonarcloud integration Somehow it got lost --- .github/workflows/cmake.yml | 87 +++++++++++++++++++++++++++++++++---- 1 file changed, 79 insertions(+), 8 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 9041ca0fc..49ea8c890 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -30,6 +30,9 @@ jobs: runs-on: windows-2022 + env: + BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed + defaults: run: shell: msys2 {0} @@ -106,6 +109,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Install sonar-scanner and build-wrapper + uses: SonarSource/sonarcloud-github-c-cpp@v1 - name: Configure CMake run: >- @@ -117,7 +125,16 @@ jobs: -D STATIC_BUILD=${{ matrix.ui.static }} - name: Build - run: cmake --build build + run: | + cmake --build build + + - name: Run sonar-scanner + if: 0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" - name: Generate package run: cmake --install build @@ -130,10 +147,12 @@ jobs: llvm-windows: name: "Windows vcpkg/LLVM (${{ matrix.ui.name }}, ${{ matrix.build.name }}, ${{ matrix.dynarec.name }}, ${{ matrix.target.name }})" + if: 0 runs-on: windows-2022 env: + BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed VCPKG_BINARY_SOURCES: 'clear;nuget,GitHub,readwrite' strategy: @@ -209,6 +228,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Install sonar-scanner and build-wrapper + uses: SonarSource/sonarcloud-github-c-cpp@v1 - name: Configure CMake run: > @@ -229,13 +253,24 @@ jobs: - name: Reconfigure CMake if: matrix.ui.qt == 'on' - run: cmake clean build + run: | + cmake clean build - name: Build - run: cmake --build build + run: | + build-wrapper-win-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build + + - name: Run sonar-scanner +# if: 0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" - name: Generate package - run: cmake --install build + run: | + cmake --install build - name: Upload artifact uses: actions/upload-artifact@v3 @@ -248,6 +283,9 @@ jobs: runs-on: ubuntu-22.04 + env: + BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed + strategy: fail-fast: true matrix: @@ -295,6 +333,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Install sonar-scanner and build-wrapper + uses: SonarSource/sonarcloud-github-c-cpp@v1 - name: Configure CMake run: >- @@ -305,10 +348,20 @@ jobs: -D QT=${{ matrix.ui.qt }} - name: Build - run: cmake --build build + run: | + build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build + + - name: Run sonar-scanner +# if: 0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" - name: Generate package - run: cmake --install build + run: | + cmake --install build - name: Upload artifact uses: actions/upload-artifact@v3 @@ -321,6 +374,9 @@ jobs: runs-on: macos-11 + env: + BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed + strategy: fail-fast: true matrix: @@ -362,6 +418,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Install sonar-scanner and build-wrapper + uses: SonarSource/sonarcloud-github-c-cpp@v1 - name: Configure CMake run: >- @@ -375,10 +436,20 @@ jobs: -D OpenAL_ROOT=$(brew --prefix openal-soft) - name: Build - run: cmake --build build + run: | + build-wrapper-macosx-x86 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build + + - name: Run sonar-scanner +# if: 0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" - name: Generate package - run: cmake --install build + run: | + cmake --install build - name: Upload artifact uses: actions/upload-artifact@v3