From 257890ed835988fbd16ee4c806142797329825bc Mon Sep 17 00:00:00 2001 From: TC1995 Date: Fri, 29 Jan 2021 23:09:10 +0100 Subject: [PATCH 01/14] Fixed the solid foreground/background mode of the v7vga, makes the Windows 2.x/286 v7 1024i 4bpp drivers look correct. Partial fix for the too wide Win3.0 built-in v7 8bpp drivers as well as cursor movement (v7 1024i only) --- src/video/vid_ht216.c | 45 +++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/video/vid_ht216.c b/src/video/vid_ht216.c index 7d5ec5452..1f6c1778d 100644 --- a/src/video/vid_ht216.c +++ b/src/video/vid_ht216.c @@ -154,14 +154,17 @@ ht216_out(uint16_t addr, uint8_t val, void *p) switch (svga->seqaddr & 0xff) { case 0x83: svga->attraddr = val & 0x1f; - svga->attrff = (val & 0x80) ? 1 : 0; + svga->attrff = !!(val & 0x80); break; case 0x94: - svga->hwcursor.addr = ((val << 6) | (3 << 14) | ((ht216->ht_regs[0xff] & 0x60) << 11)) << 2; + case 0xff: + svga->hwcursor.addr = ((ht216->ht_regs[0x94] << 6) | (3 << 14) | ((ht216->ht_regs[0xff] & 0x60) << 11)) << 2; break; case 0x9c: case 0x9d: svga->hwcursor.x = ht216->ht_regs[0x9d] | ((ht216->ht_regs[0x9c] & 7) << 8); + if (ht216->ht_regs[0xff] & 0x10) + svga->hwcursor.x >>= 1; break; case 0x9e: case 0x9f: svga->hwcursor.y = ht216->ht_regs[0x9f] | ((ht216->ht_regs[0x9e] & 3) << 8); @@ -221,10 +224,6 @@ ht216_out(uint16_t addr, uint8_t val, void *p) svga->fullchange = changeframecount; svga_recalctimings(svga); break; - - case 0xff: - svga->hwcursor.addr = ((ht216->ht_regs[0x94] << 6) | (3 << 14) | ((val & 0x60) << 11)) << 2; - break; } switch (svga->seqaddr & 0xff) { case 0xc8: case 0xc9: case 0xcf: case 0xe0: @@ -487,6 +486,7 @@ void ht216_recalctimings(svga_t *svga) { ht216_t *ht216 = (ht216_t *)svga->p; + int high_res_256 = 0; switch (ht216->clk_sel) { case 5: svga->clock = (cpuclock * (double)(1ull << 32)) / 65000000.0; break; @@ -499,7 +499,14 @@ ht216_recalctimings(svga_t *svga) svga->interlace = ht216->ht_regs[0xe0] & 1; - if ((svga->bpp == 8) && !svga->lowres) { + if (svga->interlace) + high_res_256 = (svga->htotal * 8) > (svga->vtotal * 4); + else + high_res_256 = (svga->htotal * 8) > (svga->vtotal * 2); + + if ((svga->bpp == 8) && (!svga->lowres || high_res_256)) { + if (high_res_256) + svga->hdisp /= 2; svga->render = svga_render_8bpp_highres; } } @@ -619,22 +626,18 @@ ht216_dm_write(ht216_t *ht216, uint32_t addr, uint8_t cpu_dat, uint8_t cpu_dat_u break; case 0x04: if (ht216->ht_regs[0xfe] & HT_REG_FE_FBRC) { - if (addr & 4) { - for (i = 0; i < count; i++) { - fg_data[i] = (cpu_dat_unexpanded & (1 << (((addr + i + 4) & 7) ^ 7))) ? ht216->ht_regs[0xfa] : ht216->ht_regs[0xfb]; - } - } else { - for (i = 0; i < count; i++) { - fg_data[i] = (cpu_dat_unexpanded & (1 << (((addr + i) & 7) ^ 7))) ? ht216->ht_regs[0xfa] : ht216->ht_regs[0xfb]; - } + for (i = 0; i < count; i++) { + if (ht216->ht_regs[0xfa] & (1 << i)) + fg_data[i] = cpu_dat_unexpanded; + else if (ht216->ht_regs[0xfb] & (1 << i)) + fg_data[i] = 0xff - cpu_dat_unexpanded; } } else { - if (addr & 4) { - for (i = 0; i < count; i++) - fg_data[i] = (ht216->ht_regs[0xf5] & (1 << (((addr + i + 4) & 7) ^ 7))) ? ht216->ht_regs[0xfa] : ht216->ht_regs[0xfb]; - } else { - for (i = 0; i < count; i++) - fg_data[i] = (ht216->ht_regs[0xf5] & (1 << (((addr + i) & 7) ^ 7))) ? ht216->ht_regs[0xfa] : ht216->ht_regs[0xfb]; + for (i = 0; i < count; i++) { + if (ht216->ht_regs[0xfa] & (1 << i)) + fg_data[i] = ht216->ht_regs[0xf5]; + else if (ht216->ht_regs[0xfb] & (1 << i)) + fg_data[i] = 0xff - ht216->ht_regs[0xf5]; } } break; From fb015c3f76e2784d3130b6531f7da70f490ce51b Mon Sep 17 00:00:00 2001 From: OBattler Date: Fri, 29 Jan 2021 23:36:16 +0100 Subject: [PATCH 02/14] Fixed the hardware cursor on divided-by-two clock modes. --- src/video/vid_ht216.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/video/vid_ht216.c b/src/video/vid_ht216.c index 1f6c1778d..b3393aed4 100644 --- a/src/video/vid_ht216.c +++ b/src/video/vid_ht216.c @@ -43,6 +43,7 @@ typedef struct ht216_t rom_t bios_rom; uint32_t vram_mask; + uint8_t adjust_cursor; int ext_reg_enable; int clk_sel; @@ -163,8 +164,6 @@ ht216_out(uint16_t addr, uint8_t val, void *p) break; case 0x9c: case 0x9d: svga->hwcursor.x = ht216->ht_regs[0x9d] | ((ht216->ht_regs[0x9c] & 7) << 8); - if (ht216->ht_regs[0xff] & 0x10) - svga->hwcursor.x >>= 1; break; case 0x9e: case 0x9f: svga->hwcursor.y = ht216->ht_regs[0x9f] | ((ht216->ht_regs[0x9e] & 3) << 8); @@ -504,9 +503,12 @@ ht216_recalctimings(svga_t *svga) else high_res_256 = (svga->htotal * 8) > (svga->vtotal * 2); + ht216->adjust_cursor = 0; if ((svga->bpp == 8) && (!svga->lowres || high_res_256)) { - if (high_res_256) + if (high_res_256) { svga->hdisp /= 2; + ht216->adjust_cursor = 1; + } svga->render = svga_render_8bpp_highres; } } @@ -515,9 +517,14 @@ ht216_recalctimings(svga_t *svga) static void ht216_hwcursor_draw(svga_t *svga, int displine) { - int x; + ht216_t *ht216 = (ht216_t *)svga->p; + int x, shift = (ht216->adjust_cursor ? 2 : 1); uint32_t dat[2]; int offset = svga->hwcursor_latch.x + svga->hwcursor_latch.xoff; + int width = (ht216->adjust_cursor ? 16 : 32); + + if (ht216->adjust_cursor) + offset >>= 1; if (svga->interlace && svga->hwcursor_oddeven) svga->hwcursor_latch.addr += 4; @@ -531,14 +538,14 @@ ht216_hwcursor_draw(svga_t *svga, int displine) (svga->vram[svga->hwcursor_latch.addr+128+2] << 8) | svga->vram[svga->hwcursor_latch.addr+128+3]; - for (x = 0; x < 32; x++) { + for (x = 0; x < width; x++) { if (!(dat[0] & 0x80000000)) ((uint32_t *)buffer32->line[displine])[svga->x_add + offset + x] = 0; if (dat[1] & 0x80000000) ((uint32_t *)buffer32->line[displine])[svga->x_add + offset + x] ^= 0xffffff; - dat[0] <<= 1; - dat[1] <<= 1; + dat[0] <<= shift; + dat[1] <<= shift; } svga->hwcursor_latch.addr += 4; From c912c94e4f7091178ae2cae99fd1f578c1fc5a38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Sat, 30 Jan 2021 01:45:04 +0100 Subject: [PATCH 03/14] Use the static CRT with CMake/MSVC builds --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8664b1387..95c4d425e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,8 +15,11 @@ cmake_minimum_required(VERSION 3.16) +cmake_policy(SET CMP0091 NEW) +set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + project(86Box - VERSION 2.10 + VERSION 3.0 DESCRIPTION "Emulator of x86-based systems" HOMEPAGE_URL "https://86box.github.io/" LANGUAGES C CXX) From 4fc03e7e131e50acd4ddc949f05d5fb4342ad405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Sat, 30 Jan 2021 14:41:50 +0100 Subject: [PATCH 04/14] tinyglib: implement `g_strdup` Fixes AddressSanitizer with SLiRP enabled. --- src/include/tinyglib.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/include/tinyglib.h b/src/include/tinyglib.h index fabdefcfc..686257e7f 100644 --- a/src/include/tinyglib.h +++ b/src/include/tinyglib.h @@ -215,6 +215,24 @@ g_strv_length(gchar **str_array) } +/* Implementation borrowed from GLib itself. */ +static gchar* +g_strdup(const gchar *str) +{ + gchar *new_str; + gsize length; + + if (str) { + length = strlen(str) + 1; + new_str = malloc(sizeof(char) * length); + memcpy(new_str, str, length); + } else + new_str = NULL; + + return new_str; +} + + /* Macros */ #define tinyglib_pclog(f, s, ...) pclog("TinyGLib " f "(): " s "\n", ##__VA_ARGS__) @@ -271,7 +289,6 @@ g_strv_length(gchar **str_array) #define g_rand_free free #define g_realloc realloc #define g_snprintf snprintf -#define g_strdup strdup #define g_strerror strerror #define g_strfreev free #define g_string_append_printf sprintf /* unimplemented */ From 5ef085253178bb99c85cbb7ac15d7ad5c5db686b Mon Sep 17 00:00:00 2001 From: Panagiotis <58827426+tiseno100@users.noreply.github.com> Date: Sat, 30 Jan 2021 18:01:56 +0200 Subject: [PATCH 05/14] Adapt the DTK FDC to 86Box Rewrote few parts so the DTK FDC is more adaptive on 86Box standards. --- src/floppy/fdc_pii15xb.c | 111 ++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 65 deletions(-) diff --git a/src/floppy/fdc_pii15xb.c b/src/floppy/fdc_pii15xb.c index b85738129..5090f8307 100644 --- a/src/floppy/fdc_pii15xb.c +++ b/src/floppy/fdc_pii15xb.c @@ -21,7 +21,7 @@ * or without modification, are permitted provided that the * following conditions are met: * - * 1. Redistributions of source code must retain the entire + * 1. Redistributions of source code must retain the entire * above notice, this list of conditions and the following * disclaimer. * @@ -47,9 +47,6 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define _LARGEFILE_SOURCE -#define _LARGEFILE64_SOURCE -#define _GNU_SOURCE #include #include #include @@ -61,57 +58,45 @@ #include <86box/device.h> #include <86box/io.h> #include <86box/mem.h> -#include <86box/pic.h> #include <86box/rom.h> #include <86box/machine.h> #include <86box/timer.h> -#include <86box/plat.h> -#include <86box/ui.h> #include <86box/fdd.h> #include <86box/fdc.h> #include <86box/fdc_ext.h> -#define ROM_PII_151B L"roms/floppy/dtk/pii-151b.rom" -#define ROM_PII_158B L"roms/floppy/dtk/pii-158b.rom" +#define ROM_PII_151B L"roms/floppy/dtk/pii-151b.rom" +#define ROM_PII_158B L"roms/floppy/dtk/pii-158b.rom" -typedef struct { - const char *name; - int type; +#ifdef ENABLE_PII15XB_LOG +int pii15xb_do_log = ENABLE_PII15XB_LOG; - uint32_t bios_addr, - bios_size; - rom_t bios_rom; - - fdc_t *fdc; -} pii_t; - - -/* Load and enable a BIOS ROM if we have one, and is enabled. */ static void -set_bios(pii_t *dev, wchar_t *fn) +pii15xb_log(const char *fmt, ...) { - uint32_t temp; - FILE *fp; + va_list ap; - /* Only do this if needed. */ - if ((fn == NULL) || (dev->bios_addr == 0)) return; - - if ((fp = rom_fopen(fn, L"rb")) == NULL) return; - - (void)fseek(fp, 0L, SEEK_END); - temp = ftell(fp); - (void)fclose(fp); - - /* Assume 128K, then go down. */ - dev->bios_size = 0x020000; - while (temp < dev->bios_size) - dev->bios_size >>= 1; - - /* Create a memory mapping for the space. */ - rom_init(&dev->bios_rom, fn, dev->bios_addr, - dev->bios_size, dev->bios_size-1, 0, MEM_MAPPING_EXTERNAL); + if (fdc_do_log) + { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } } +#else +#define pii15xb_log(fmt, ...) +#endif +typedef struct +{ + const char *name; + int type; + + uint32_t bios_addr; + rom_t bios_rom; + + fdc_t *fdc; +} pii_t; static void pii_close(void *priv) @@ -121,7 +106,6 @@ pii_close(void *priv) free(dev); } - static void * pii_init(const device_t *info) { @@ -133,24 +117,14 @@ pii_init(const device_t *info) dev->bios_addr = device_get_config_hex20("bios_addr"); - if (dev->bios_addr != 0x000000) { - switch (dev->type) { - case 151: - set_bios(dev, ROM_PII_151B); - break; - case 158: - set_bios(dev, ROM_PII_158B); - break; - } - } + if (dev->bios_addr != 0) + rom_init(&dev->bios_rom, (dev->type == 0x158) ? ROM_PII_158B : ROM_PII_151B, dev->bios_addr, 0x2000, 0x1ffff, 0, MEM_MAPPING_EXTERNAL); - /* Attach the DP8473 chip. */ - dev->fdc = device_add(&fdc_at_device); + dev->fdc = device_add(&fdc_at_device); //Our DP8473 emulation is broken. If fixed this has to be changed! - //pclog("FDC: %s (I/O=%04X, flags=%08x)\n", - // info->name, dev->fdc->base_address, dev->fdc->flags); + pii15xb_log("PII15XB: %s (I/O=%04X, flags=%08x)\n", info->name, dev->fdc->base_address, dev->fdc->flags); - return(dev); + return (dev); } static int pii_151b_available(void) @@ -163,6 +137,7 @@ static int pii_158_available(void) return rom_present(ROM_PII_158B); } + static const device_config_t pii_config[] = { { "bios_addr", "BIOS address", CONFIG_HEX20, "", 0x0ce000, "", { 0 }, @@ -193,16 +168,22 @@ const device_t fdc_pii151b_device = { "DTK PII-151B (MiniMicro) Floppy Drive Controller", DEVICE_ISA, 151, - pii_init, pii_close, NULL, - { pii_151b_available }, NULL, NULL, - pii_config -}; + pii_init, + pii_close, + NULL, + {pii_151b_available}, + NULL, + NULL, + pii_config}; const device_t fdc_pii158b_device = { "DTK PII-158B (MiniMicro4) Floppy Drive Controller", DEVICE_ISA, 158, - pii_init, pii_close, NULL, - { pii_158_available }, NULL, NULL, - pii_config -}; + pii_init, + pii_close, + NULL, + {pii_158_available}, + NULL, + NULL, + pii_config}; From 782d8d9c956c37787383d0abd187aab84f5cf8ca Mon Sep 17 00:00:00 2001 From: Panagiotis <58827426+tiseno100@users.noreply.github.com> Date: Sat, 30 Jan 2021 18:24:47 +0200 Subject: [PATCH 06/14] Minor improvements and fixes on the DTK FDC's --- src/floppy/fdc_pii15xb.c | 49 ++++++++-------------------------------- 1 file changed, 10 insertions(+), 39 deletions(-) diff --git a/src/floppy/fdc_pii15xb.c b/src/floppy/fdc_pii15xb.c index 5090f8307..b3f32a22e 100644 --- a/src/floppy/fdc_pii15xb.c +++ b/src/floppy/fdc_pii15xb.c @@ -65,37 +65,14 @@ #include <86box/fdc.h> #include <86box/fdc_ext.h> +#define DTK_VARIANT ((info->local == 158) ? ROM_PII_158B : ROM_PII_151B) +#define BIOS_ADDR (uint32_t)(device_get_config_hex20("bios_addr") & 0x000fffff) #define ROM_PII_151B L"roms/floppy/dtk/pii-151b.rom" #define ROM_PII_158B L"roms/floppy/dtk/pii-158b.rom" -#ifdef ENABLE_PII15XB_LOG -int pii15xb_do_log = ENABLE_PII15XB_LOG; - -static void -pii15xb_log(const char *fmt, ...) -{ - va_list ap; - - if (fdc_do_log) - { - va_start(ap, fmt); - pclog_ex(fmt, ap); - va_end(ap); - } -} -#else -#define pii15xb_log(fmt, ...) -#endif - typedef struct { - const char *name; - int type; - - uint32_t bios_addr; rom_t bios_rom; - - fdc_t *fdc; } pii_t; static void @@ -112,17 +89,12 @@ pii_init(const device_t *info) pii_t *dev; dev = (pii_t *)malloc(sizeof(pii_t)); - memset(dev, 0x00, sizeof(pii_t)); - dev->type = info->local; + memset(dev, 0, sizeof(pii_t)); - dev->bios_addr = device_get_config_hex20("bios_addr"); + if (BIOS_ADDR != 0) + rom_init(&dev->bios_rom, DTK_VARIANT, BIOS_ADDR, 0x2000, 0x1ffff, 0, MEM_MAPPING_EXTERNAL); - if (dev->bios_addr != 0) - rom_init(&dev->bios_rom, (dev->type == 0x158) ? ROM_PII_158B : ROM_PII_151B, dev->bios_addr, 0x2000, 0x1ffff, 0, MEM_MAPPING_EXTERNAL); - - dev->fdc = device_add(&fdc_at_device); //Our DP8473 emulation is broken. If fixed this has to be changed! - - pii15xb_log("PII15XB: %s (I/O=%04X, flags=%08x)\n", info->name, dev->fdc->base_address, dev->fdc->flags); + device_add(&fdc_at_device); /* Our DP8473 emulation is broken. If fixed this has to be changed! */ return (dev); } @@ -137,22 +109,21 @@ static int pii_158_available(void) return rom_present(ROM_PII_158B); } - static const device_config_t pii_config[] = { { - "bios_addr", "BIOS address", CONFIG_HEX20, "", 0x0ce000, "", { 0 }, + "bios_addr", "BIOS Address:", CONFIG_HEX20, "", 0xce000, "", { 0 }, { { "Disabled", 0 }, { - "CA00H", 0x0ca000 + "CA00H", 0xca000 }, { - "CC00H", 0x0cc000 + "CC00H", 0xcc000 }, { - "CE00H", 0x0ce000 + "CE00H", 0xce000 }, { "" From 1290fdb06504641d7d106507558a2b7c7dd05c74 Mon Sep 17 00:00:00 2001 From: Panagiotis <58827426+tiseno100@users.noreply.github.com> Date: Sun, 31 Jan 2021 13:09:42 +0200 Subject: [PATCH 07/14] Few more changes on the DTK FDC's DP8473 now uses the correct flags. Included few notes related to the DTK FDC. --- src/floppy/fdc.c | 2 +- src/floppy/fdc_pii15xb.c | 72 +++++++++++++++++++++++----------------- src/include/86box/fdc.h | 1 - 3 files changed, 43 insertions(+), 32 deletions(-) diff --git a/src/floppy/fdc.c b/src/floppy/fdc.c index a48307b2f..8194d35f4 100644 --- a/src/floppy/fdc.c +++ b/src/floppy/fdc.c @@ -2426,7 +2426,7 @@ const device_t fdc_at_nsc_device = { const device_t fdc_dp8473_device = { "NS DP8473 Floppy Drive Controller", 0, - FDC_FLAG_NSDP, + FDC_FLAG_AT | FDC_FLAG_NSC, fdc_init, fdc_close, fdc_reset, diff --git a/src/floppy/fdc_pii15xb.c b/src/floppy/fdc_pii15xb.c index b3f32a22e..1a6fc8fad 100644 --- a/src/floppy/fdc_pii15xb.c +++ b/src/floppy/fdc_pii15xb.c @@ -1,52 +1,63 @@ /* * VARCem Virtual ARchaeological Computer EMulator. * An emulator of (mostly) x86-based PC systems and devices, - * using the ISA,EISA,VLB,MCA and PCI system buses, roughly + * using the ISA,EISA,VLB,MCA and PCI system buses, roughly * spanning the era between 1981 and 1995. * * This file is part of the VARCem Project. * - * Implementation of the DTK PII-151B and PII-158B cards. + * Implementation of the DTK MiniMicro series of Floppy Disk Controllers. + * Original code from VARCem. Fully rewritten, fixed and improved for 86Box. * - * These are DP8473-based floppy controller ISA cards for XT - * class systems, and allow usage of standard and high-density - * drives on them. They have their own BIOS which takes over - * from the standard system BIOS. - * - * Author: Fred N. van Kempen, + * Author: Fred N. van Kempen, , + * Tiseno100 * * Copyright 2019 Fred N. van Kempen. + * Copyright 2021 Tiseno100 * - * Redistribution and use in source and binary forms, with - * or without modification, are permitted provided that the + * Redistribution and use in source and binary forms, with + * or without modification, are permitted provided that the * following conditions are met: * * 1. Redistributions of source code must retain the entire - * above notice, this list of conditions and the following - * disclaimer. + * above notice, this list of conditions and the following + * disclaimer. * * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other - * materials provided with the distribution. + * copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. * - * 3. Neither the name of the copyright holder nor the names - * of its contributors may be used to endorse or promote - * products derived from this software without specific - * prior written permission. + * 3. Neither the name of the copyright holder nor the names + * of its contributors may be used to endorse or promote + * products derived from this software without specific + * prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +/* +Notes: +VARCem uses the DP8473 for both floppy disk controllers. The statement though is wrong. + +MiniMicro 4 uses a Zilog Z0765A08PSC(Clone of the NEC 765) +MiniMicro 1 uses a National Semiconductor DP8473(Clone of the NEC 765 with additional NSC commands) + +Issues: +MiniMicro 4 WON'T WORK with XT machines. This statement has to be confirmed by someone with the real card itself. +MiniMicro 4 also won't work with the XT FDC which the Zilog claims to be. +*/ + #include #include #include @@ -66,6 +77,7 @@ #include <86box/fdc_ext.h> #define DTK_VARIANT ((info->local == 158) ? ROM_PII_158B : ROM_PII_151B) +#define DTK_CHIP ((info->local == 158) ? &fdc_at_device : &fdc_dp8473_device) #define BIOS_ADDR (uint32_t)(device_get_config_hex20("bios_addr") & 0x000fffff) #define ROM_PII_151B L"roms/floppy/dtk/pii-151b.rom" #define ROM_PII_158B L"roms/floppy/dtk/pii-158b.rom" @@ -94,9 +106,9 @@ pii_init(const device_t *info) if (BIOS_ADDR != 0) rom_init(&dev->bios_rom, DTK_VARIANT, BIOS_ADDR, 0x2000, 0x1ffff, 0, MEM_MAPPING_EXTERNAL); - device_add(&fdc_at_device); /* Our DP8473 emulation is broken. If fixed this has to be changed! */ + device_add(DTK_CHIP); - return (dev); + return dev; } static int pii_151b_available(void) diff --git a/src/include/86box/fdc.h b/src/include/86box/fdc.h index 68d4ea0ce..b818258de 100644 --- a/src/include/86box/fdc.h +++ b/src/include/86box/fdc.h @@ -34,7 +34,6 @@ extern int fdc_type; #define FDC_FLAG_NSC 0x80 /* PC87306, PC87309 */ #define FDC_FLAG_TOSHIBA 0x100 /* T1000, T1200 */ #define FDC_FLAG_AMSTRAD 0x200 /* Non-AT Amstrad machines */ -#define FDC_FLAG_NSDP 0x400 /* DP8473N, DP8473V */ typedef struct { From 41c3dbc451e14d20d99dc8a7cb9e8d12a384fcf8 Mon Sep 17 00:00:00 2001 From: Panagiotis <58827426+tiseno100@users.noreply.github.com> Date: Sun, 31 Jan 2021 13:49:14 +0200 Subject: [PATCH 08/14] Added the Magitronic B215 Intended for just testing the XT FDC issues --- src/floppy/CMakeLists.txt | 2 +- src/floppy/fdc.c | 1 + src/floppy/fdc_magitronic.c | 99 +++++++++++++++++++++++++++++++++++++ src/include/86box/fdc_ext.h | 1 + src/win/Makefile.mingw | 2 +- 5 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 src/floppy/fdc_magitronic.c diff --git a/src/floppy/CMakeLists.txt b/src/floppy/CMakeLists.txt index a3039ddd5..75e7b5947 100644 --- a/src/floppy/CMakeLists.txt +++ b/src/floppy/CMakeLists.txt @@ -13,5 +13,5 @@ # Copyright 2020,2021 David Hrdlička. # -add_library(fdd OBJECT fdd.c fdc.c fdc_pii15xb.c fdi2raw.c fdd_common.c +add_library(fdd OBJECT fdd.c fdc.c fdc_magitronic.c fdc_pii15xb.c fdi2raw.c fdd_common.c fdd_86f.c fdd_fdi.c fdd_imd.c fdd_img.c fdd_json.c fdd_mfm.c fdd_td0.c) \ No newline at end of file diff --git a/src/floppy/fdc.c b/src/floppy/fdc.c index 8194d35f4..459370724 100644 --- a/src/floppy/fdc.c +++ b/src/floppy/fdc.c @@ -109,6 +109,7 @@ typedef const struct { /* All emulated machines have at least one integrated FDC controller */ static fdc_cards_t fdc_cards[] = { { "internal", NULL }, + { "b215", &fdc_b215_device }, { "dtk_pii151b", &fdc_pii151b_device }, { "dtk_pii158b", &fdc_pii158b_device }, { "", NULL }, diff --git a/src/floppy/fdc_magitronic.c b/src/floppy/fdc_magitronic.c new file mode 100644 index 000000000..3b7ceb64d --- /dev/null +++ b/src/floppy/fdc_magitronic.c @@ -0,0 +1,99 @@ +/* + * 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 Magitronic B215 XT-FDC Controller. + * + * Authors: Tiseno100 + * + * Copyright 2021 Tiseno100 + * + */ + +#include +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include <86box/timer.h> +#include <86box/io.h> +#include <86box/device.h> +#include <86box/mem.h> +#include <86box/rom.h> +#include <86box/fdd.h> +#include <86box/fdc.h> +#include <86box/fdc_ext.h> + +#define ROM_B215 L"roms/floppy/magitronic/Magitronic B215 - BIOS ROM.bin" +#define ROM_ADDR (uint32_t)(device_get_config_hex20("bios_addr") & 0x000fffff) + +typedef struct +{ + fdc_t *fdc_controller; + rom_t rom; +} b215_t; + +static void +b215_close(void *priv) +{ + b215_t *dev = (b215_t *)priv; + + free(dev); +} + +static void * +b215_init(const device_t *info) +{ + b215_t *dev = (b215_t *)malloc(sizeof(b215_t)); + memset(dev, 0, sizeof(b215_t)); + + rom_init(&dev->rom, ROM_B215, ROM_ADDR, 0x2000, 0x1fff, 0, MEM_MAPPING_EXTERNAL); + + device_add(&fdc_at_device); + + return dev; +} + +static int b215_available(void) +{ + return rom_present(ROM_B215); +} + +static const device_config_t b215_config[] = { + { + "bios_addr", "BIOS Address:", CONFIG_HEX20, "", 0xca000, "", { 0 }, + { + { + "CA00H", 0xca000 + }, + { + "CC00H", 0xcc000 + }, + { + "" + } + } + }, + { + "", "", -1 + } +}; + +const device_t fdc_b215_device = { + "Magitronic B215", + DEVICE_ISA, + 0, + b215_init, + b215_close, + NULL, + {b215_available}, + NULL, + NULL, + b215_config}; diff --git a/src/include/86box/fdc_ext.h b/src/include/86box/fdc_ext.h index a9aa000f3..c87786dc0 100644 --- a/src/include/86box/fdc_ext.h +++ b/src/include/86box/fdc_ext.h @@ -27,6 +27,7 @@ extern int fdc_type; /* Controller types. */ #define FDC_INTERNAL 0 +extern const device_t fdc_b215_device; extern const device_t fdc_pii151b_device; extern const device_t fdc_pii158b_device; diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index 7b2488060..b4aaa599d 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -658,7 +658,7 @@ SIOOBJ := sio_acc3221.o \ sio_um8669f.o \ sio_vt82c686.o -FDDOBJ := fdd.o fdc.o fdc_pii15xb.o \ +FDDOBJ := fdd.o fdc.o fdc_magitronic.o fdc_pii15xb.o \ fdi2raw.o \ fdd_common.o fdd_86f.o \ fdd_fdi.o fdd_imd.o fdd_img.o fdd_json.o \ From a42b4263f9cd14d7d8e4c478cb39ef0da6ca47db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Sun, 31 Jan 2021 17:13:14 +0100 Subject: [PATCH 09/14] cmake: add CPack support --- CMakeLists.txt | 2 ++ src/CMakeLists.txt | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 95c4d425e..b130c1d92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,8 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(TargetArch) target_architecture(CMAKE_TARGET_ARCHITECTURES) +include(CPack) + include(CMakeDependentOption) add_compile_definitions(CMAKE) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b5e9746a8..48324bc99 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -94,6 +94,11 @@ else() add_subdirectory(codegen) endif() +install(TARGETS 86Box) +if(VCPKG_TOOLCHAIN) + x_vcpkg_install_local_dependencies(TARGETS 86Box DESTINATION "bin") +endif() + add_subdirectory(device) add_subdirectory(disk) add_subdirectory(floppy) From f277faa6adf22aa9880dc24b58668f85d2eeeb5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Sun, 31 Jan 2021 17:21:40 +0100 Subject: [PATCH 10/14] workflows: minor fixes to the cmake build - build as release with debug info - change a job id from `clang` to `vs2019` - use the v142 (2019) toolset instead of the v141 (2017) one - build when root CMakeLists.txt changes --- .github/workflows/cmake.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 89f2cffe5..b49ae07d1 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -5,17 +5,19 @@ on: push: paths: - src/** + - "**/CMakeLists.txt" - .github/workflows/** - vcpkg.json pull_request: paths: - src/** + - "**/CMakeLists.txt" - .github/workflows/** - vcpkg.json env: - BUILD_TYPE: Release + BUILD_TYPE: RelWithDebInfo jobs: mingw: @@ -56,14 +58,14 @@ jobs: run: >- cmake -S . -B build -G "MSYS Makefiles" - -D CMAKE_BUILD_TYPE=$BUILD_TYPE + -D CMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -D DEV_BRANCH=${{ matrix.dev-build }} -D NEW_DYNAREC=${{ matrix.new-dynarec }} -D VNC=OFF - name: Build - run: cmake --build build --config $BUILD_TYPE + run: cmake --build build - clang: + vs2019: name: VS2019 ${{ matrix.toolset }} ${{ matrix.target-arch }} build (DEV_BUILD=${{ matrix.dev-build }}, NEW_DYNAREC=${{ matrix.new-dynarec }}) runs-on: windows-latest @@ -74,7 +76,7 @@ jobs: dev-build: ['ON', 'OFF'] new-dynarec: ['ON', 'OFF'] target-arch: ['Win32', 'x64', 'ARM', 'ARM64'] - toolset: ['clangcl', 'v141'] + toolset: ['clangcl', 'v142'] exclude: - target-arch: 'ARM' new-dynarec: 'OFF' @@ -94,9 +96,8 @@ jobs: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.target-arch }} -T ${{ matrix.toolset }} -D CMAKE_TOOLCHAIN_FILE=C:\vcpkg\scripts\buildsystems\vcpkg.cmake - -D CMAKE_BUILD_TYPE=$BUILD_TYPE -D DEV_BRANCH=${{ matrix.dev-build }} -D NEW_DYNAREC=${{ matrix.new-dynarec }} -D VNC=OFF - name: Build - run: cmake --build build --config $BUILD_TYPE + run: cmake --build build --config ${{ env.BUILD_TYPE }} From 953f64d9d97294b275612df16e89c0916d4d9d38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Sun, 31 Jan 2021 17:22:16 +0100 Subject: [PATCH 11/14] workflows: add CPack to the VS2019 build --- .github/workflows/cmake.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index b49ae07d1..da50bb912 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -96,8 +96,15 @@ jobs: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.target-arch }} -T ${{ matrix.toolset }} -D CMAKE_TOOLCHAIN_FILE=C:\vcpkg\scripts\buildsystems\vcpkg.cmake + -D CPACK_GENERATOR=ZIP -D DEV_BRANCH=${{ matrix.dev-build }} -D NEW_DYNAREC=${{ matrix.new-dynarec }} -D VNC=OFF - name: Build run: cmake --build build --config ${{ env.BUILD_TYPE }} + - name: Package + run: cmake --build build --config ${{ env.BUILD_TYPE }} --target package + - uses: actions/upload-artifact@v2 + with: + name: '86Box-VS2019-${{ matrix.toolset }}-${{ matrix.target-arch}}-${{ matrix.dev-build }}-${{ matrix.new-dynarec }}-${{ github.run_number }}' + path: build/*.zip From e4c0319d2703a5a0f74e3173daec7a5298ac1fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Sun, 31 Jan 2021 17:27:19 +0100 Subject: [PATCH 12/14] tinyglib: change `g_strdup` to a macro --- src/include/tinyglib.h | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/include/tinyglib.h b/src/include/tinyglib.h index 686257e7f..24f9409a3 100644 --- a/src/include/tinyglib.h +++ b/src/include/tinyglib.h @@ -215,24 +215,6 @@ g_strv_length(gchar **str_array) } -/* Implementation borrowed from GLib itself. */ -static gchar* -g_strdup(const gchar *str) -{ - gchar *new_str; - gsize length; - - if (str) { - length = strlen(str) + 1; - new_str = malloc(sizeof(char) * length); - memcpy(new_str, str, length); - } else - new_str = NULL; - - return new_str; -} - - /* Macros */ #define tinyglib_pclog(f, s, ...) pclog("TinyGLib " f "(): " s "\n", ##__VA_ARGS__) @@ -289,6 +271,7 @@ g_strdup(const gchar *str) #define g_rand_free free #define g_realloc realloc #define g_snprintf snprintf +#define g_strdup(str) str ? strdup(str) : NULL #define g_strerror strerror #define g_strfreev free #define g_string_append_printf sprintf /* unimplemented */ From 8e0a3187a52f353aa44c356ca39bbc70e0223a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Sun, 31 Jan 2021 20:19:42 +0100 Subject: [PATCH 13/14] workflows: adjust the vs2019 job - reduce the number of builds - more descriptive names for artifacts and builds - populate the package manually instead of using CPack, which results in double ZIPs being generated --- .github/workflows/cmake.yml | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index da50bb912..2ae0f9ec7 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -66,22 +66,31 @@ jobs: run: cmake --build build vs2019: - name: VS2019 ${{ matrix.toolset }} ${{ matrix.target-arch }} build (DEV_BUILD=${{ matrix.dev-build }}, NEW_DYNAREC=${{ matrix.new-dynarec }}) + name: VS2019 ${{ matrix.build.name }} ${{ matrix.target-arch }} build (${{ matrix.toolset }}) runs-on: windows-latest strategy: fail-fast: false matrix: - dev-build: ['ON', 'OFF'] - new-dynarec: ['ON', 'OFF'] + build: + - name: Regular + dev-build: off + new-dynarec: off + type: Debug + - name: Dev + dev-build: on + new-dynarec: on + type: Debug target-arch: ['Win32', 'x64', 'ARM', 'ARM64'] toolset: ['clangcl', 'v142'] exclude: - target-arch: 'ARM' - new-dynarec: 'OFF' + build: + new-dynarec: off - target-arch: 'ARM64' - new-dynarec: 'OFF' + build: + new-dynarec: off - target-arch: 'ARM' toolset: 'clangcl' @@ -96,15 +105,13 @@ jobs: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.target-arch }} -T ${{ matrix.toolset }} -D CMAKE_TOOLCHAIN_FILE=C:\vcpkg\scripts\buildsystems\vcpkg.cmake - -D CPACK_GENERATOR=ZIP - -D DEV_BRANCH=${{ matrix.dev-build }} - -D NEW_DYNAREC=${{ matrix.new-dynarec }} + -D CMAKE_INSTALL_PREFIX=${{ github.workspace }}/build/artifacts + -D DEV_BRANCH=${{ matrix.build.dev-build }} + -D NEW_DYNAREC=${{ matrix.build.new-dynarec }} -D VNC=OFF - name: Build - run: cmake --build build --config ${{ env.BUILD_TYPE }} - - name: Package - run: cmake --build build --config ${{ env.BUILD_TYPE }} --target package + run: cmake --build build --config ${{ matrix.build.type }} --target install - uses: actions/upload-artifact@v2 with: - name: '86Box-VS2019-${{ matrix.toolset }}-${{ matrix.target-arch}}-${{ matrix.dev-build }}-${{ matrix.new-dynarec }}-${{ github.run_number }}' - path: build/*.zip + name: '86Box-VS2019-${{ matrix.build.name }}-${{ matrix.target-arch }}-${{ matrix.toolset }}-${{ github.sha }}' + path: build/artifacts/bin/** From ccb52c4585942bfd27dab37509380824fa9b056f Mon Sep 17 00:00:00 2001 From: Panagiotis <58827426+tiseno100@users.noreply.github.com> Date: Wed, 3 Feb 2021 14:56:22 +0200 Subject: [PATCH 14/14] Sanitize some old chipset code (Part 2) Few fixes for both the ALi M1429 & OPTi 291 --- src/chipset/ali1429.c | 139 +++++++++++++++----------------- src/chipset/opti291.c | 183 +++++++++++++++++++++--------------------- 2 files changed, 156 insertions(+), 166 deletions(-) diff --git a/src/chipset/ali1429.c b/src/chipset/ali1429.c index 0326a1471..08cc6ff14 100644 --- a/src/chipset/ali1429.c +++ b/src/chipset/ali1429.c @@ -29,11 +29,13 @@ #include <86box/timer.h> #include <86box/io.h> #include <86box/device.h> -#include <86box/keyboard.h> + +#include <86box/apm.h> #include <86box/mem.h> #include <86box/fdd.h> #include <86box/fdc.h> #include <86box/port_92.h> +#include <86box/smram.h> #include <86box/chipset.h> #define disabled_shadow (MEM_READ_EXTANY | MEM_WRITE_EXTANY) @@ -45,122 +47,108 @@ ali1429_log(const char *fmt, ...) { va_list ap; - if (ali1429_do_log) { - va_start(ap, fmt); - pclog_ex(fmt, ap); - va_end(ap); + if (ali1429_do_log) + { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); } } #else #define ali1429_log(fmt, ...) #endif - typedef struct { - uint8_t index, cfg_locked, - regs[256]; + uint8_t index, cfg_locked, + regs[256]; + + smram_t *smram; } ali1429_t; static void ali1429_shadow_recalc(ali1429_t *dev) { -uint32_t base, i, can_write, can_read; + uint32_t base, i, can_write, can_read; -shadowbios = (dev->regs[0x13] & 0x40) && (dev->regs[0x14] & 0x01); -shadowbios_write = (dev->regs[0x13] & 0x40) && (dev->regs[0x14] & 0x02); + shadowbios = (dev->regs[0x13] & 0x40) && (dev->regs[0x14] & 0x01); + shadowbios_write = (dev->regs[0x13] & 0x40) && (dev->regs[0x14] & 0x02); -can_write = (dev->regs[0x14] & 0x02) ? MEM_WRITE_INTERNAL : MEM_WRITE_EXTANY; -can_read = (dev->regs[0x14] & 0x01) ? MEM_READ_INTERNAL : MEM_READ_EXTANY; + 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++) -{ -base = 0xc0000 + (i << 15); + for (i = 0; i < 8; i++) + { + base = 0xc0000 + (i << 15); -if(dev->regs[0x13] & (1 << i)) -mem_set_mem_state_both(base, 0x8000, can_read | can_write); -else -mem_set_mem_state_both(base, 0x8000, disabled_shadow); + if (dev->regs[0x13] & (1 << i)) + mem_set_mem_state_both(base, 0x8000, can_read | can_write); + else + mem_set_mem_state_both(base, 0x8000, disabled_shadow); + } -} - -flushmmucache(); + flushmmucache(); } static void ali1429_write(uint16_t addr, uint8_t val, void *priv) { - ali1429_t *dev = (ali1429_t *) priv; + ali1429_t *dev = (ali1429_t *)priv; - switch (addr) { - case 0x22: - dev->index = val; - break; - - case 0x23: + switch (addr) + { + case 0x22: + dev->index = val; + break; - /* Don't log register unlock patterns */ - if(dev->index != 0x03) - ali1429_log("M1429: dev->regs[%02x] = %02x\n", dev->index, val); + case 0x23: + if (dev->index != 0x03) + ali1429_log("M1429: dev->regs[%02x] = %02x\n", dev->index, val); - /* Unlock/Lock Registers */ - if(dev->index == 0x03) - dev->cfg_locked = !(val == 0xc5); + if (dev->index == 0x03) + dev->cfg_locked = !(val == 0xc5); - if(!dev->cfg_locked) + if (!dev->cfg_locked) { - dev->regs[dev->index] = val; + dev->regs[dev->index] = val; - switch(dev->index){ - /* Shadow RAM */ + switch (dev->index) + { case 0x13: case 0x14: - ali1429_shadow_recalc(dev); - break; + ali1429_shadow_recalc(dev); + break; - /* Cache */ case 0x18: - cpu_cache_ext_enabled = (val & 0x80); - break; - } + cpu_cache_ext_enabled = !!(val & 2); + cpu_update_waitstates(); + break; + } } - break; + break; } } - static uint8_t ali1429_read(uint16_t addr, void *priv) { - uint8_t ret = 0xff; - ali1429_t *dev = (ali1429_t *) priv; - - switch (addr) { - case 0x23: - /* Do not conflict with Cyrix configuration registers */ - if(!(((dev->index >= 0xc0) || (dev->index == 0x20)) && cpu_iscyrix)) - ret = dev->regs[dev->index]; - break; - } - - return ret; + ali1429_t *dev = (ali1429_t *)priv; + return (addr == 0x23) ? dev->regs[dev->index] : 0xff; } - static void ali1429_close(void *priv) { - ali1429_t *dev = (ali1429_t *) priv; + ali1429_t *dev = (ali1429_t *)priv; free(dev); } - static void * ali1429_init(const device_t *info) { - ali1429_t *dev = (ali1429_t *) malloc(sizeof(ali1429_t)); + ali1429_t *dev = (ali1429_t *)malloc(sizeof(ali1429_t)); memset(dev, 0, sizeof(ali1429_t)); /* @@ -168,26 +156,25 @@ ali1429_init(const device_t *info) 22h Index Port 23h Data Port */ - io_sethandler(0x022, 0x0001, ali1429_read, NULL, NULL, ali1429_write, NULL, NULL, dev); - io_sethandler(0x023, 0x0001, ali1429_read, NULL, NULL, ali1429_write, NULL, NULL, dev); - + io_sethandler(0x0022, 0x0002, ali1429_read, NULL, NULL, ali1429_write, NULL, NULL, dev); + dev->cfg_locked = 1; + device_add(&apm_device); device_add(&port_92_device); - - dev->regs[0x13] = 0x00; - dev->regs[0x14] = 0x00; - ali1429_shadow_recalc(dev); + /* dev->smram = smram_add(); */ return dev; } - const device_t ali1429_device = { "ALi M1429", 0, 0, - ali1429_init, ali1429_close, NULL, - { NULL }, NULL, NULL, - NULL -}; + ali1429_init, + ali1429_close, + NULL, + {NULL}, + NULL, + NULL, + NULL}; diff --git a/src/chipset/opti291.c b/src/chipset/opti291.c index b59b0b7b7..4bb4ac937 100644 --- a/src/chipset/opti291.c +++ b/src/chipset/opti291.c @@ -8,9 +8,10 @@ * * Implementation of the OPTi 82C291 chipset. - * Authors: plant/nerd73 + * Authors: plant/nerd73, Tiseno100 * * Copyright 2020 plant/nerd73. + * Copyright 2021 Tiseno100. */ #include #include @@ -24,133 +25,135 @@ #include <86box/timer.h> #include <86box/io.h> #include <86box/device.h> -#include <86box/keyboard.h> #include <86box/mem.h> -#include <86box/fdd.h> -#include <86box/fdc.h> #include <86box/port_92.h> #include <86box/chipset.h> +#ifdef ENABLE_OPTI291_LOG +int opti291_do_log = ENABLE_OPTI291_LOG; +static void +opti291_log(const char *fmt, ...) +{ + va_list ap; + + if (opti291_do_log) + { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +#define opti291_log(fmt, ...) +#endif + typedef struct { - uint8_t index, - regs[256]; - port_92_t *port_92; + uint8_t index, regs[256]; + port_92_t *port_92; } opti291_t; static void opti291_recalc(opti291_t *dev) { - uint32_t base; - uint32_t i, shflags, write, writef = 0; - - - writef = (dev->regs[0x27] & 0x80) ? MEM_WRITE_DISABLED : MEM_WRITE_INTERNAL; - if (!(dev->regs[0x23] & 0x40)) - mem_set_mem_state(0xf0000, 0x10000, MEM_READ_INTERNAL | writef); - else - mem_set_mem_state(0xf0000, 0x10000, MEM_READ_EXTANY | writef); - - for (i = 0; i < 4; i++) { - base = 0xe0000 + (i << 14); - shflags = (dev->regs[0x24] & (1 << (i+4))) ? MEM_READ_INTERNAL : MEM_READ_EXTANY; - write = (dev->regs[0x24] & (1 << i)) ? MEM_WRITE_INTERNAL : MEM_WRITE_EXTANY; - shflags |= (dev->regs[0x27] & 0x40) ? MEM_WRITE_DISABLED : write; - mem_set_mem_state(base, 0x4000, shflags); + mem_set_mem_state_both(0xf0000, 0x10000, (!(dev->regs[0x23] & 0x40) ? MEM_READ_INTERNAL : MEM_READ_EXTANY) | ((dev->regs[0x27] & 0x80) ? MEM_WRITE_DISABLED : MEM_WRITE_INTERNAL)); + + for (uint32_t i = 0; i < 4; i++) + { + mem_set_mem_state_both(0xc0000 + (i << 14), 0x4000, ((dev->regs[0x26] & (1 << (i + 4))) ? MEM_READ_INTERNAL : MEM_READ_EXTANY) | ((dev->regs[0x27] & 0x10) ? MEM_WRITE_DISABLED : ((dev->regs[0x26] & (1 << i)) ? MEM_WRITE_INTERNAL : MEM_WRITE_EXTANY))); + mem_set_mem_state_both(0xd0000 + (i << 14), 0x4000, ((dev->regs[0x25] & (1 << (i + 4))) ? MEM_READ_INTERNAL : MEM_READ_EXTANY) | ((dev->regs[0x27] & 0x20) ? MEM_WRITE_DISABLED : ((dev->regs[0x25] & (1 << i)) ? MEM_WRITE_INTERNAL : MEM_WRITE_EXTANY))); + mem_set_mem_state_both(0xe0000 + (i << 14), 0x4000, ((dev->regs[0x24] & (1 << (i + 4))) ? MEM_READ_INTERNAL : MEM_READ_EXTANY) | ((dev->regs[0x27] & 0x40) ? MEM_WRITE_DISABLED : ((dev->regs[0x24] & (1 << i)) ? MEM_WRITE_INTERNAL : MEM_WRITE_EXTANY))); } - for (i = 0; i < 4; i++) { - base = 0xd0000 + (i << 14); - shflags = (dev->regs[0x25] & (1 << (i+4))) ? MEM_READ_INTERNAL : MEM_READ_EXTANY; - write = (dev->regs[0x25] & (1 << i)) ? MEM_WRITE_INTERNAL : MEM_WRITE_EXTANY; - shflags |= (dev->regs[0x27] & 0x20) ? MEM_WRITE_DISABLED : write; - mem_set_mem_state(base, 0x4000, shflags); - } - - for (i = 0; i < 4; i++) { - base = 0xc0000 + (i << 14); - shflags = (dev->regs[0x26] & (1 << (i+4))) ? MEM_READ_INTERNAL : MEM_READ_EXTANY; - write = (dev->regs[0x26] & (1 << i)) ? MEM_WRITE_INTERNAL : MEM_WRITE_EXTANY; - shflags |= (dev->regs[0x27] & 0x10) ? MEM_WRITE_DISABLED : write; - mem_set_mem_state(base, 0x4000, shflags); - } - flushmmucache(); -} + flushmmucache(); +} static void opti291_write(uint16_t addr, uint8_t val, void *priv) { - opti291_t *dev = (opti291_t *) priv; + opti291_t *dev = (opti291_t *)priv; - switch (addr) { + switch (addr) + { case 0x22: dev->index = val; break; case 0x24: - pclog("OPTi 291: dev->regs[%02x] = %02x\n", dev->index, val); - dev->regs[dev->index] = val; - - switch(dev->index){ - case 0x21: - cpu_update_waitstates(); - break; - case 0x23: - case 0x24: - case 0x25: - case 0x26: - case 0x27: - opti291_recalc(dev); - break; - } + opti291_log("OPTi 291: dev->regs[%02x] = %02x\n", dev->index, val); + switch (dev->index) + { + case 0x20: + dev->regs[dev->index] = val & 0x3f; + break; + case 0x21: + dev->regs[dev->index] = val & 0xf3; + break; + case 0x22: + dev->regs[dev->index] = val; + break; + case 0x23: + case 0x24: + case 0x25: + case 0x26: + dev->regs[dev->index] = val; + opti291_recalc(dev); + break; + case 0x27: + case 0x28: + dev->regs[dev->index] = val; + break; + case 0x29: + dev->regs[dev->index] = val & 0x0f; + break; + case 0x2a: + case 0x2b: + case 0x2c: + dev->regs[dev->index] = val; + break; + } break; - } + } } - static uint8_t opti291_read(uint16_t addr, void *priv) { - uint8_t ret = 0xff; - opti291_t *dev = (opti291_t *) priv; + opti291_t *dev = (opti291_t *)priv; - switch (addr) { - case 0x24: -// pclog("OPTi 291: read from dev->regs[%02x]\n", dev->index); - ret = dev->regs[dev->index]; - break; - } - - return ret; + return (addr == 0x24) ? dev->regs[dev->index] : 0xff; } - static void opti291_close(void *priv) { - opti291_t *dev = (opti291_t *) priv; + opti291_t *dev = (opti291_t *)priv; - free(dev); + free(dev); } - static void * opti291_init(const device_t *info) { - opti291_t *dev = (opti291_t *) malloc(sizeof(opti291_t)); - memset(dev, 0, sizeof(opti291_t)); + opti291_t *dev = (opti291_t *)malloc(sizeof(opti291_t)); + memset(dev, 0, sizeof(opti291_t)); - io_sethandler(0x022, 0x0001, opti291_read, NULL, NULL, opti291_write, NULL, NULL, dev); - io_sethandler(0x024, 0x0001, opti291_read, NULL, NULL, opti291_write, NULL, NULL, dev); - dev->regs[0x23] = 0x40; - dev->port_92 = device_add(&port_92_device); - opti291_recalc(dev); - - return dev; + io_sethandler(0x022, 0x0001, opti291_read, NULL, NULL, opti291_write, NULL, NULL, dev); + io_sethandler(0x024, 0x0001, opti291_read, NULL, NULL, opti291_write, NULL, NULL, dev); + dev->regs[0x22] = 0xf0; + dev->regs[0x23] = 0x40; + dev->regs[0x28] = 0x08; + dev->regs[0x29] = 0xa0; + device_add(&port_92_device); + opti291_recalc(dev); + + return dev; } - const device_t opti291_device = { - "OPTi 82C291", - 0, - 0, - opti291_init, opti291_close, NULL, - { NULL }, NULL, NULL, - NULL -}; + "OPTi 82C291", + 0, + 0, + opti291_init, + opti291_close, + NULL, + {NULL}, + NULL, + NULL, + NULL};