From 9b9f2d7c7c379eefd3c09a846b9c193d38cc4fce Mon Sep 17 00:00:00 2001 From: Panagiotis <58827426+tiseno100@users.noreply.github.com> Date: Fri, 1 Jan 2021 20:07:39 +0200 Subject: [PATCH 1/7] Properly implemented the ACC 2046/2168 Based on the ACC 2046 datasheet. 2168 is just the Green variation of it. --- src/chipset/acc2168.c | 148 +++++++++++++++++++++++++++++++----------- 1 file changed, 109 insertions(+), 39 deletions(-) diff --git a/src/chipset/acc2168.c b/src/chipset/acc2168.c index 5461cb71a..66783022e 100644 --- a/src/chipset/acc2168.c +++ b/src/chipset/acc2168.c @@ -6,13 +6,15 @@ * * This file is part of the 86Box distribution. * - * Implementation of the ACC 2168 chipset + * Implementation of the ACC 2046/2168 chipset * * * * Authors: Sarah Walker, + * Tiseno100 * * Copyright 2019 Sarah Walker. + * Copyright 2021 Tiseno100. */ #include #include @@ -28,84 +30,152 @@ #include <86box/port_92.h> #include <86box/chipset.h> -#define enabled_shadow (MEM_READ_INTERNAL | ((dev->regs[0x02] & 0x20) ? MEM_WRITE_DISABLED : MEM_WRITE_INTERNAL)) -#define disabled_shadow (MEM_READ_EXTANY | MEM_WRITE_EXTANY) +#define ENABLED_SHADOW (MEM_READ_INTERNAL | ((dev->regs[0x02] & 0x20) ? MEM_WRITE_DISABLED : MEM_WRITE_INTERNAL)) +#define DISABLED_SHADOW (MEM_READ_EXTANY | MEM_WRITE_EXTANY) +#define SHADOW_ADDR ((i <= 1) ? (0xc0000 + (i << 15)) : (0xd0000 + ((i - 2) << 16))) +#define SHADOW_SIZE ((i <= 1) ? 0x8000 : 0x10000) +#define SHADOW_RECALC ((dev->regs[0x02] & (1 << i)) ? ENABLED_SHADOW : DISABLED_SHADOW) typedef struct acc2168_t { - int reg_idx; - uint8_t regs[256]; + uint8_t reg_idx, regs[256]; } acc2168_t; -static void +static void acc2168_shadow_recalc(acc2168_t *dev) { -mem_set_mem_state_both(0xc0000, 0x8000, ((dev->regs[0x02] & 0x01) ? enabled_shadow : disabled_shadow)); -mem_set_mem_state_both(0xc8000, 0x8000, ((dev->regs[0x02] & 0x02) ? enabled_shadow : disabled_shadow)); -mem_set_mem_state_both(0xd0000, 0x10000, ((dev->regs[0x02] & 0x04) ? enabled_shadow : disabled_shadow)); -mem_set_mem_state_both(0xe0000, 0x10000, ((dev->regs[0x02] & 0x08) ? enabled_shadow : disabled_shadow)); -mem_set_mem_state_both(0xf0000, 0x10000, ((dev->regs[0x02] & 0x10) ? enabled_shadow : disabled_shadow)); + for (uint32_t i = 0; i < 5; i++) + mem_set_mem_state_both(SHADOW_ADDR, SHADOW_SIZE, SHADOW_RECALC); } -static void +static void acc2168_write(uint16_t addr, uint8_t val, void *p) { acc2168_t *dev = (acc2168_t *)p; - if (!(addr & 1)) - dev->reg_idx = val; - else { - dev->regs[dev->reg_idx] = val; + switch (addr) + { + case 0xf2: + dev->reg_idx = val; + break; + case 0xf3: + pclog("dev->regs[%02x] = %02x\n", dev->reg_idx, val); + switch (dev->reg_idx) + { + case 0x00: + dev->regs[dev->reg_idx] = val; + break; - switch (dev->reg_idx) { - case 0x02: - acc2168_shadow_recalc(dev); - break; - } + case 0x01: + dev->regs[dev->reg_idx] = val & 0xd3; + cpu_update_waitstates(); + break; + + case 0x02: + dev->regs[dev->reg_idx] = val & 0x7f; + acc2168_shadow_recalc(dev); + break; + + case 0x03: + dev->regs[dev->reg_idx] = val & 0x1f; + break; + + case 0x04: + dev->regs[dev->reg_idx] = val; + cpu_cache_ext_enabled = !!(val & 0x01); + cpu_update_waitstates(); + break; + + case 0x05: + dev->regs[dev->reg_idx] = val & 0xf3; + break; + + case 0x06: + case 0x07: + dev->regs[dev->reg_idx] = val & 0x1f; + break; + + case 0x08: + dev->regs[dev->reg_idx] = val & 0x0f; + break; + + case 0x09: + dev->regs[dev->reg_idx] = val & 0x03; + break; + + case 0x0a: + case 0x0b: + case 0x0c: + case 0x0d: + case 0x0e: + case 0x0f: + case 0x10: + case 0x11: + dev->regs[dev->reg_idx] = val; + break; + + case 0x12: + dev->regs[dev->reg_idx] = val & 0xbb; + break; + + case 0x18: + dev->regs[dev->reg_idx] = val & 0x77; + break; + + case 0x19: + dev->regs[dev->reg_idx] = val & 0xfb; + break; + + case 0x1a: + dev->regs[dev->reg_idx] = val; + cpu_cache_int_enabled = !(val & 0x40); + cpu_update_waitstates(); + break; + + case 0x1b: + dev->regs[dev->reg_idx] = val & 0xef; + break; + } + break; } } - -static uint8_t +static uint8_t acc2168_read(uint16_t addr, void *p) { acc2168_t *dev = (acc2168_t *)p; - if (!(addr & 1)) - return dev->reg_idx; - - return dev->regs[dev->reg_idx]; + return (addr == 0xf3) ? dev->regs[dev->reg_idx] : dev->reg_idx; } static void acc2168_close(void *priv) { - acc2168_t *dev = (acc2168_t *) priv; + acc2168_t *dev = (acc2168_t *)priv; free(dev); } - static void * acc2168_init(const device_t *info) { acc2168_t *dev = (acc2168_t *)malloc(sizeof(acc2168_t)); memset(dev, 0, sizeof(acc2168_t)); - - io_sethandler(0x00f2, 0x0002, - acc2168_read, NULL, NULL, acc2168_write, NULL, NULL, dev); - device_add(&port_92_inv_device); + device_add(&port_92_device); + io_sethandler(0x00f2, 0x0002, acc2168_read, NULL, NULL, acc2168_write, NULL, NULL, dev); return dev; } - const device_t acc2168_device = { - "ACC 2168", + "ACC 2046/2168", 0, 0, - acc2168_init, acc2168_close, NULL, - { NULL }, NULL, NULL, - NULL -}; + acc2168_init, + acc2168_close, + NULL, + {NULL}, + NULL, + NULL, + NULL}; From 2b1e9a5656a607458b21076d4dc72fe9f34da46a Mon Sep 17 00:00:00 2001 From: Panagiotis <58827426+tiseno100@users.noreply.github.com> Date: Fri, 1 Jan 2021 20:11:03 +0200 Subject: [PATCH 2/7] Properly done logging --- src/chipset/acc2168.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/chipset/acc2168.c b/src/chipset/acc2168.c index 66783022e..b9e6a2c18 100644 --- a/src/chipset/acc2168.c +++ b/src/chipset/acc2168.c @@ -16,11 +16,13 @@ * Copyright 2019 Sarah Walker. * Copyright 2021 Tiseno100. */ -#include +#include #include +#include #include #include #include +#define HAVE_STDARG_H #include <86box/86box.h> #include "cpu.h" #include <86box/timer.h> @@ -36,6 +38,23 @@ #define SHADOW_SIZE ((i <= 1) ? 0x8000 : 0x10000) #define SHADOW_RECALC ((dev->regs[0x02] & (1 << i)) ? ENABLED_SHADOW : DISABLED_SHADOW) +#ifdef ENABLE_ACC2168_LOG +int ali1429_do_log = ENABLE_ACC2168_LOG; +static void +acc2168_log(const char *fmt, ...) +{ + va_list ap; + + if (acc2168_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +#define acc2168_log(fmt, ...) +#endif + typedef struct acc2168_t { uint8_t reg_idx, regs[256]; @@ -59,7 +78,7 @@ acc2168_write(uint16_t addr, uint8_t val, void *p) dev->reg_idx = val; break; case 0xf3: - pclog("dev->regs[%02x] = %02x\n", dev->reg_idx, val); + acc2168_log("ACC2168: dev->regs[%02x] = %02x\n", dev->reg_idx, val); switch (dev->reg_idx) { case 0x00: From fea33c18c5bbe57b8239d63b95f2d99c5536b5d0 Mon Sep 17 00:00:00 2001 From: Panagiotis <58827426+tiseno100@users.noreply.github.com> Date: Fri, 1 Jan 2021 20:11:46 +0200 Subject: [PATCH 3/7] wrong naming on log. --- src/chipset/acc2168.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chipset/acc2168.c b/src/chipset/acc2168.c index b9e6a2c18..4cdf41a2c 100644 --- a/src/chipset/acc2168.c +++ b/src/chipset/acc2168.c @@ -39,7 +39,7 @@ #define SHADOW_RECALC ((dev->regs[0x02] & (1 << i)) ? ENABLED_SHADOW : DISABLED_SHADOW) #ifdef ENABLE_ACC2168_LOG -int ali1429_do_log = ENABLE_ACC2168_LOG; +int acc2168_do_log = ENABLE_ACC2168_LOG; static void acc2168_log(const char *fmt, ...) { From 83a8f93d7018ccc59347aceb7cd64f2ae69a06ed Mon Sep 17 00:00:00 2001 From: Panagiotis <58827426+tiseno100@users.noreply.github.com> Date: Fri, 1 Jan 2021 20:23:56 +0200 Subject: [PATCH 4/7] Include a default switch for undocumented registers --- src/acc2168.c | 207 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 src/acc2168.c diff --git a/src/acc2168.c b/src/acc2168.c new file mode 100644 index 000000000..384486faa --- /dev/null +++ b/src/acc2168.c @@ -0,0 +1,207 @@ +/* + * 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. + * + * Implementation of the ACC 2046/2168 chipset + * + * + * + * Authors: Sarah Walker, + * Tiseno100 + * + * Copyright 2019 Sarah Walker. + * Copyright 2021 Tiseno100. + */ +#include +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include "cpu.h" +#include <86box/timer.h> +#include <86box/device.h> +#include <86box/io.h> +#include <86box/mem.h> +#include <86box/port_92.h> +#include <86box/chipset.h> + +#define ENABLED_SHADOW (MEM_READ_INTERNAL | ((dev->regs[0x02] & 0x20) ? MEM_WRITE_DISABLED : MEM_WRITE_INTERNAL)) +#define DISABLED_SHADOW (MEM_READ_EXTANY | MEM_WRITE_EXTANY) +#define SHADOW_ADDR ((i <= 1) ? (0xc0000 + (i << 15)) : (0xd0000 + ((i - 2) << 16))) +#define SHADOW_SIZE ((i <= 1) ? 0x8000 : 0x10000) +#define SHADOW_RECALC ((dev->regs[0x02] & (1 << i)) ? ENABLED_SHADOW : DISABLED_SHADOW) + +#define ENABLE_ACC2168_LOG 1 + +#ifdef ENABLE_ACC2168_LOG +int acc2168_do_log = ENABLE_ACC2168_LOG; +static void +acc2168_log(const char *fmt, ...) +{ + va_list ap; + + if (acc2168_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +#define acc2168_log(fmt, ...) +#endif + +typedef struct acc2168_t +{ + uint8_t reg_idx, regs[256]; +} acc2168_t; + +static void +acc2168_shadow_recalc(acc2168_t *dev) +{ + for (uint32_t i = 0; i < 5; i++) + mem_set_mem_state_both(SHADOW_ADDR, SHADOW_SIZE, SHADOW_RECALC); +} + +static void +acc2168_write(uint16_t addr, uint8_t val, void *p) +{ + acc2168_t *dev = (acc2168_t *)p; + + switch (addr) + { + case 0xf2: + dev->reg_idx = val; + break; + case 0xf3: + acc2168_log("ACC2168: dev->regs[%02x] = %02x\n", dev->reg_idx, val); + switch (dev->reg_idx) + { + case 0x00: + dev->regs[dev->reg_idx] = val; + break; + + case 0x01: + dev->regs[dev->reg_idx] = val & 0xd3; + cpu_update_waitstates(); + break; + + case 0x02: + dev->regs[dev->reg_idx] = val & 0x7f; + acc2168_shadow_recalc(dev); + break; + + case 0x03: + dev->regs[dev->reg_idx] = val & 0x1f; + break; + + case 0x04: + dev->regs[dev->reg_idx] = val; + cpu_cache_ext_enabled = !!(val & 0x01); + cpu_update_waitstates(); + break; + + case 0x05: + dev->regs[dev->reg_idx] = val & 0xf3; + break; + + case 0x06: + case 0x07: + dev->regs[dev->reg_idx] = val & 0x1f; + break; + + case 0x08: + dev->regs[dev->reg_idx] = val & 0x0f; + break; + + case 0x09: + dev->regs[dev->reg_idx] = val & 0x03; + break; + + case 0x0a: + case 0x0b: + case 0x0c: + case 0x0d: + case 0x0e: + case 0x0f: + case 0x10: + case 0x11: + dev->regs[dev->reg_idx] = val; + break; + + case 0x12: + dev->regs[dev->reg_idx] = val & 0xbb; + break; + + case 0x18: + dev->regs[dev->reg_idx] = val & 0x77; + break; + + case 0x19: + dev->regs[dev->reg_idx] = val & 0xfb; + break; + + case 0x1a: + dev->regs[dev->reg_idx] = val; + cpu_cache_int_enabled = !(val & 0x40); + cpu_update_waitstates(); + break; + + case 0x1b: + dev->regs[dev->reg_idx] = val & 0xef; + break; + + default: /* ACC 2168 has way more registers which we haven't documented */ + dev->regs[dev->reg_idx] = val; + break; + + } + break; + } +} + +static uint8_t +acc2168_read(uint16_t addr, void *p) +{ + acc2168_t *dev = (acc2168_t *)p; + + return (addr == 0xf3) ? dev->regs[dev->reg_idx] : dev->reg_idx; +} + +static void +acc2168_close(void *priv) +{ + acc2168_t *dev = (acc2168_t *)priv; + + free(dev); +} + +static void * +acc2168_init(const device_t *info) +{ + acc2168_t *dev = (acc2168_t *)malloc(sizeof(acc2168_t)); + memset(dev, 0, sizeof(acc2168_t)); + + device_add(&port_92_device); + io_sethandler(0x00f2, 0x0002, acc2168_read, NULL, NULL, acc2168_write, NULL, NULL, dev); + + return dev; +} + +const device_t acc2168_device = { + "ACC 2046/2168", + 0, + 0, + acc2168_init, + acc2168_close, + NULL, + {NULL}, + NULL, + NULL, + NULL}; From abca8ec142e6b8c69097d8532ac6bc9ee989230b Mon Sep 17 00:00:00 2001 From: Panagiotis <58827426+tiseno100@users.noreply.github.com> Date: Fri, 1 Jan 2021 20:24:15 +0200 Subject: [PATCH 5/7] Delete acc2168.c --- src/acc2168.c | 207 -------------------------------------------------- 1 file changed, 207 deletions(-) delete mode 100644 src/acc2168.c diff --git a/src/acc2168.c b/src/acc2168.c deleted file mode 100644 index 384486faa..000000000 --- a/src/acc2168.c +++ /dev/null @@ -1,207 +0,0 @@ -/* - * 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. - * - * Implementation of the ACC 2046/2168 chipset - * - * - * - * Authors: Sarah Walker, - * Tiseno100 - * - * Copyright 2019 Sarah Walker. - * Copyright 2021 Tiseno100. - */ -#include -#include -#include -#include -#include -#include -#define HAVE_STDARG_H -#include <86box/86box.h> -#include "cpu.h" -#include <86box/timer.h> -#include <86box/device.h> -#include <86box/io.h> -#include <86box/mem.h> -#include <86box/port_92.h> -#include <86box/chipset.h> - -#define ENABLED_SHADOW (MEM_READ_INTERNAL | ((dev->regs[0x02] & 0x20) ? MEM_WRITE_DISABLED : MEM_WRITE_INTERNAL)) -#define DISABLED_SHADOW (MEM_READ_EXTANY | MEM_WRITE_EXTANY) -#define SHADOW_ADDR ((i <= 1) ? (0xc0000 + (i << 15)) : (0xd0000 + ((i - 2) << 16))) -#define SHADOW_SIZE ((i <= 1) ? 0x8000 : 0x10000) -#define SHADOW_RECALC ((dev->regs[0x02] & (1 << i)) ? ENABLED_SHADOW : DISABLED_SHADOW) - -#define ENABLE_ACC2168_LOG 1 - -#ifdef ENABLE_ACC2168_LOG -int acc2168_do_log = ENABLE_ACC2168_LOG; -static void -acc2168_log(const char *fmt, ...) -{ - va_list ap; - - if (acc2168_do_log) { - va_start(ap, fmt); - pclog_ex(fmt, ap); - va_end(ap); - } -} -#else -#define acc2168_log(fmt, ...) -#endif - -typedef struct acc2168_t -{ - uint8_t reg_idx, regs[256]; -} acc2168_t; - -static void -acc2168_shadow_recalc(acc2168_t *dev) -{ - for (uint32_t i = 0; i < 5; i++) - mem_set_mem_state_both(SHADOW_ADDR, SHADOW_SIZE, SHADOW_RECALC); -} - -static void -acc2168_write(uint16_t addr, uint8_t val, void *p) -{ - acc2168_t *dev = (acc2168_t *)p; - - switch (addr) - { - case 0xf2: - dev->reg_idx = val; - break; - case 0xf3: - acc2168_log("ACC2168: dev->regs[%02x] = %02x\n", dev->reg_idx, val); - switch (dev->reg_idx) - { - case 0x00: - dev->regs[dev->reg_idx] = val; - break; - - case 0x01: - dev->regs[dev->reg_idx] = val & 0xd3; - cpu_update_waitstates(); - break; - - case 0x02: - dev->regs[dev->reg_idx] = val & 0x7f; - acc2168_shadow_recalc(dev); - break; - - case 0x03: - dev->regs[dev->reg_idx] = val & 0x1f; - break; - - case 0x04: - dev->regs[dev->reg_idx] = val; - cpu_cache_ext_enabled = !!(val & 0x01); - cpu_update_waitstates(); - break; - - case 0x05: - dev->regs[dev->reg_idx] = val & 0xf3; - break; - - case 0x06: - case 0x07: - dev->regs[dev->reg_idx] = val & 0x1f; - break; - - case 0x08: - dev->regs[dev->reg_idx] = val & 0x0f; - break; - - case 0x09: - dev->regs[dev->reg_idx] = val & 0x03; - break; - - case 0x0a: - case 0x0b: - case 0x0c: - case 0x0d: - case 0x0e: - case 0x0f: - case 0x10: - case 0x11: - dev->regs[dev->reg_idx] = val; - break; - - case 0x12: - dev->regs[dev->reg_idx] = val & 0xbb; - break; - - case 0x18: - dev->regs[dev->reg_idx] = val & 0x77; - break; - - case 0x19: - dev->regs[dev->reg_idx] = val & 0xfb; - break; - - case 0x1a: - dev->regs[dev->reg_idx] = val; - cpu_cache_int_enabled = !(val & 0x40); - cpu_update_waitstates(); - break; - - case 0x1b: - dev->regs[dev->reg_idx] = val & 0xef; - break; - - default: /* ACC 2168 has way more registers which we haven't documented */ - dev->regs[dev->reg_idx] = val; - break; - - } - break; - } -} - -static uint8_t -acc2168_read(uint16_t addr, void *p) -{ - acc2168_t *dev = (acc2168_t *)p; - - return (addr == 0xf3) ? dev->regs[dev->reg_idx] : dev->reg_idx; -} - -static void -acc2168_close(void *priv) -{ - acc2168_t *dev = (acc2168_t *)priv; - - free(dev); -} - -static void * -acc2168_init(const device_t *info) -{ - acc2168_t *dev = (acc2168_t *)malloc(sizeof(acc2168_t)); - memset(dev, 0, sizeof(acc2168_t)); - - device_add(&port_92_device); - io_sethandler(0x00f2, 0x0002, acc2168_read, NULL, NULL, acc2168_write, NULL, NULL, dev); - - return dev; -} - -const device_t acc2168_device = { - "ACC 2046/2168", - 0, - 0, - acc2168_init, - acc2168_close, - NULL, - {NULL}, - NULL, - NULL, - NULL}; From 92168311bfb6e924bf0db93652767ba3a9533e2b Mon Sep 17 00:00:00 2001 From: Panagiotis <58827426+tiseno100@users.noreply.github.com> Date: Fri, 1 Jan 2021 20:24:32 +0200 Subject: [PATCH 6/7] Position fix. --- src/chipset/acc2168.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/chipset/acc2168.c b/src/chipset/acc2168.c index 4cdf41a2c..384486faa 100644 --- a/src/chipset/acc2168.c +++ b/src/chipset/acc2168.c @@ -38,6 +38,8 @@ #define SHADOW_SIZE ((i <= 1) ? 0x8000 : 0x10000) #define SHADOW_RECALC ((dev->regs[0x02] & (1 << i)) ? ENABLED_SHADOW : DISABLED_SHADOW) +#define ENABLE_ACC2168_LOG 1 + #ifdef ENABLE_ACC2168_LOG int acc2168_do_log = ENABLE_ACC2168_LOG; static void @@ -154,6 +156,11 @@ acc2168_write(uint16_t addr, uint8_t val, void *p) case 0x1b: dev->regs[dev->reg_idx] = val & 0xef; break; + + default: /* ACC 2168 has way more registers which we haven't documented */ + dev->regs[dev->reg_idx] = val; + break; + } break; } From 84c713411f19a4fc403dbb0b4e9bf860fa9784a4 Mon Sep 17 00:00:00 2001 From: Panagiotis <58827426+tiseno100@users.noreply.github.com> Date: Fri, 1 Jan 2021 20:25:09 +0200 Subject: [PATCH 7/7] Disable logging --- src/chipset/acc2168.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/chipset/acc2168.c b/src/chipset/acc2168.c index 384486faa..b30a7951e 100644 --- a/src/chipset/acc2168.c +++ b/src/chipset/acc2168.c @@ -38,8 +38,6 @@ #define SHADOW_SIZE ((i <= 1) ? 0x8000 : 0x10000) #define SHADOW_RECALC ((dev->regs[0x02] & (1 << i)) ? ENABLED_SHADOW : DISABLED_SHADOW) -#define ENABLE_ACC2168_LOG 1 - #ifdef ENABLE_ACC2168_LOG int acc2168_do_log = ENABLE_ACC2168_LOG; static void