diff --git a/.github/workflows/cmake_macos.yml b/.github/workflows/cmake_macos.yml index 62842dc26..647b1181c 100644 --- a/.github/workflows/cmake_macos.yml +++ b/.github/workflows/cmake_macos.yml @@ -69,7 +69,6 @@ jobs: - name: Install dependencies run: >- brew install - ninja sdl2 rtmidi openal-soft @@ -162,12 +161,12 @@ jobs: - name: Install dependencies run: >- brew install - ninja sdl2 rtmidi openal-soft fluidsynth libslirp + vde libserialport ${{ matrix.ui.packages }} diff --git a/.github/workflows/codeql_linux.yml b/.github/workflows/codeql_linux.yml index 57665d7c6..aecbc6dbb 100644 --- a/.github/workflows/codeql_linux.yml +++ b/.github/workflows/codeql_linux.yml @@ -3,9 +3,7 @@ name: CodeQL Analysis (Linux) on: push: - branches: - - main - + branches: [ "main" ] paths: - src/** - cmake/** @@ -16,6 +14,7 @@ on: - "!**/Makefile*" pull_request: + branches: [ "master" ] paths: - src/** - cmake/** @@ -26,6 +25,9 @@ on: - vcpkg.json - "!**/Makefile*" + schedule: + - cron: '22 11 * * 0' + jobs: analyze-linux: diff --git a/.github/workflows/codeql_macos.yml b/.github/workflows/codeql_macos.yml index 3a75ea9a7..f25559588 100644 --- a/.github/workflows/codeql_macos.yml +++ b/.github/workflows/codeql_macos.yml @@ -3,9 +3,7 @@ name: CodeQL Analysis (macos) on: push: - branches: - - main - + branches: [ "main" ] paths: - src/** - cmake/** @@ -16,6 +14,7 @@ on: - "!**/Makefile*" pull_request: + branches: [ "master" ] paths: - src/** - cmake/** @@ -26,6 +25,9 @@ on: - vcpkg.json - "!**/Makefile*" + schedule: + - cron: '22 11 * * 0' + jobs: analyze-macos13-x86_64: diff --git a/.github/workflows/codeql_windows_msys2.yml b/.github/workflows/codeql_windows_msys2.yml index ce6b2e74a..b8a0d662f 100644 --- a/.github/workflows/codeql_windows_msys2.yml +++ b/.github/workflows/codeql_windows_msys2.yml @@ -3,9 +3,7 @@ name: CodeQL Analysis (Windows, msys2) on: push: - branches: - - main - + branches: [ "main" ] paths: - src/** - cmake/** @@ -16,6 +14,7 @@ on: - "!**/Makefile*" pull_request: + branches: [ "main" ] paths: - src/** - cmake/** @@ -26,6 +25,9 @@ on: - vcpkg.json - "!**/Makefile*" + schedule: + - cron: '22 11 * * 0' + jobs: analyze-msys2: diff --git a/CMakeLists.txt b/CMakeLists.txt index 777ede9ca..4dd83523f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,6 +137,7 @@ option(GDBSTUB "Enable GDB stub server for debugging" option(DEV_BRANCH "Development branch" OFF) option(DISCORD "Discord Rich Presence support" ON) option(DEBUGREGS486 "Enable debug register opeartion on 486+ CPUs" OFF) +option(LIBASAN "Enable compilation with the addresss sanitizer" OFF) if((ARCH STREQUAL "arm64") OR (ARCH STREQUAL "arm")) set(NEW_DYNAREC ON) @@ -223,4 +224,10 @@ if(NOT EMU_COPYRIGHT_YEAR) set(EMU_COPYRIGHT_YEAR 2024) endif() +# Libasan +if(LIBASAN) + add_compile_options(-fsanitize=address) + add_link_options(-fsanitize=address) +endif() + add_subdirectory(src) diff --git a/src/86box.c b/src/86box.c index 92e2f0c24..ae58aca03 100644 --- a/src/86box.c +++ b/src/86box.c @@ -253,6 +253,8 @@ struct accelKey def_acc_keys[NUM_ACCELS] = { .seq="Ctrl+Alt+M" } }; +char vmm_path[1024] = { '\0'}; /* TEMPORARY - VM manager path to scan for VMs */ +int vmm_enabled = 0; /* Statistics. */ extern int mmuflush; @@ -600,8 +602,8 @@ pc_show_usage(char *s) #ifdef _WIN32 "-D or --debug\t\t\t- force debug output logging\n" #endif -#if 0 - "-E or --nographic\t\t- forces the old behavior\n" +#if 1 + "-E or --vmmpath\t\t- vm manager path\n" #endif "-F or --fullscreen\t\t- start in fullscreen mode\n" "-G or --lang langid\t\t- start with specified language\n" @@ -637,7 +639,7 @@ pc_show_usage(char *s) ui_msgbox(MBX_ANSI | ((s == NULL) ? MBX_INFO : MBX_WARNING), p); #else if (s == NULL) - pclog(p); + pclog("%s", p); else ui_msgbox(MBX_ANSI | MBX_WARNING, p); #endif @@ -734,13 +736,18 @@ usage: } else if (!strcasecmp(argv[c], "--debug") || !strcasecmp(argv[c], "-D")) { force_debug = 1; #endif -#ifdef ENABLE_NG - } else if (!strcasecmp(argv[c], "--nographic") || !strcasecmp(argv[c], "-E")) { - /* Currently does nothing, but if/when we implement a built-in manager, - it's going to force the manager not to run, allowing the old usage - without parameter. */ - ng = 1; -#endif +//#ifdef ENABLE_NG + } else if (!strcasecmp(argv[c], "--vmmpath") || + !strcasecmp(argv[c], "-E")) { + /* Using this variable for vm manager path + Temporary solution!*/ + if ((c+1) == argc) goto usage; + char *vp = argv[++c]; + if ((strlen(vp) + 1) >= sizeof(vmm_path)) + memcpy(vmm_path, vp, sizeof(vmm_path)); + else + memcpy(vmm_path, vp, strlen(vp) + 1); + //#endif } else if (!strcasecmp(argv[c], "--fullscreen") || !strcasecmp(argv[c], "-F")) { start_in_fullscreen = 1; } else if (!strcasecmp(argv[c], "--logfile") || !strcasecmp(argv[c], "-L")) { @@ -775,7 +782,11 @@ usage: goto usage; temp2 = (char *) calloc(2048, 1); - sscanf(argv[++c], "%c:%s", &drive, temp2); + if (sscanf(argv[++c], "%c:%2047s", &drive, temp2) != 2) { + fprintf(stderr, "Invalid input format for --image option.\n"); + free(temp2); + goto usage; + } if (drive > 0x40) drive = (drive & 0x1f) - 1; else @@ -1014,9 +1025,21 @@ usage: * This is where we start outputting to the log file, * if there is one. Create a little info header first. */ + struct tm time_buf; + (void) time(&now); - info = localtime(&now); - strftime(temp, sizeof(temp), "%Y/%m/%d %H:%M:%S", info); +#ifdef _WIN32 + if (localtime_s(&time_buf, &now) == 0) + info = &time_buf; +#else + info = localtime_r(&now, &time_buf); +#endif + + if (info) + strftime(temp, sizeof(temp), "%Y/%m/%d %H:%M:%S", info); + else + strcpy(temp, "unknown"); + pclog("#\n# %ls v%ls logfile, created %s\n#\n", EMU_NAME_W, EMU_VERSION_FULL_W, temp); pclog("# VM: %s\n#\n", vm_name); @@ -1027,6 +1050,10 @@ usage: } pclog("# Configuration file: %s\n#\n\n", cfg_path); + if (strlen(vmm_path) != 0) { + vmm_enabled = 1; + pclog("# VM Manager enabled. Path: %s\n", vmm_path); + } /* * We are about to read the configuration file, which MAY * put data into global variables (the hard- and floppy @@ -1645,6 +1672,10 @@ pc_close(UNUSED(thread_t *ptr)) scsi_disk_close(); gdbstub_close(); + +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) + mem_free(); +#endif } #ifdef __APPLE__ diff --git a/src/cdrom/cdrom_image_viso.c b/src/cdrom/cdrom_image_viso.c index cf132c560..3eec6d5a1 100644 --- a/src/cdrom/cdrom_image_viso.c +++ b/src/cdrom/cdrom_image_viso.c @@ -446,24 +446,36 @@ static int viso_fill_time(uint8_t *data, time_t time, int format, int longform) { uint8_t *p = data; - struct tm *time_s = localtime(&time); - if (!time_s) { - /* localtime will return NULL if the time_t is negative (Windows) - or way too far into 64-bit space (Linux). Fall back to epoch. */ - time_t epoch = 0; - time_s = localtime(&epoch); - if (UNLIKELY(!time_s)) - fatal("VISO: localtime(0) = NULL\n"); + struct tm time_s_buf; + struct tm *time_s = NULL; + time_t epoch = 0; - /* Force year clamping if the timestamp is known to be outside the supported ranges. */ +#ifdef _WIN32 + if (localtime_s(&time_s_buf, &time) == 0) + time_s = &time_s_buf; +#else + time_s = localtime_r(&time, &time_s_buf); +#endif + + if (!time_s) { + /* localtime may return NULL if time is negative or out of range */ +#ifdef _WIN32 + if (localtime_s(&time_s_buf, &epoch) == 0) + time_s = &time_s_buf; +#else + time_s = localtime_r(&epoch, &time_s_buf); +#endif + if (!time_s) + fatal("VISO: localtime fallback to epoch failed\n"); + + /* Force year clamping for out-of-range times */ if (time < (longform ? -62135596800LL : -2208988800LL)) /* 0001-01-01 00:00:00 : 1900-01-01 00:00:00 */ time_s->tm_year = -1901; else if (time > (longform ? 253402300799LL : 5869583999LL)) /* 9999-12-31 23:59:59 : 2155-12-31 23:59:59 */ time_s->tm_year = 8100; } - /* Clamp year to the supported ranges, and assume the - OS returns valid numbers in the other struct fields. */ + /* Clamp year within supported ranges */ if (time_s->tm_year < (longform ? -1900 : 0)) { time_s->tm_year = longform ? -1900 : 0; time_s->tm_mon = time_s->tm_hour = time_s->tm_min = time_s->tm_sec = 0; @@ -476,18 +488,18 @@ viso_fill_time(uint8_t *data, time_t time, int format, int longform) time_s->tm_min = time_s->tm_sec = 59; } - /* Convert timestamp. */ + /* Convert timestamp */ if (longform) { - p += sprintf((char *) p, "%04u%02u%02u%02u%02u%02u00", - 1900 + time_s->tm_year, 1 + time_s->tm_mon, time_s->tm_mday, + p += sprintf((char *)p, "%04u%02u%02u%02u%02u%02u00", + 1900 + (unsigned)time_s->tm_year, 1 + time_s->tm_mon, time_s->tm_mday, time_s->tm_hour, time_s->tm_min, time_s->tm_sec); } else { - *p++ = time_s->tm_year; /* year since 1900 */ - *p++ = 1 + time_s->tm_mon; /* month */ - *p++ = time_s->tm_mday; /* day */ - *p++ = time_s->tm_hour; /* hour */ - *p++ = time_s->tm_min; /* minute */ - *p++ = time_s->tm_sec; /* second */ + *p++ = (uint8_t)time_s->tm_year; /* year since 1900 */ + *p++ = (uint8_t)(1 + time_s->tm_mon); /* month */ + *p++ = (uint8_t)time_s->tm_mday; /* day */ + *p++ = (uint8_t)time_s->tm_hour; /* hour */ + *p++ = (uint8_t)time_s->tm_min; /* minute */ + *p++ = (uint8_t)time_s->tm_sec; /* second */ } if (format & VISO_FORMAT_ISO) *p++ = tz_offset; /* timezone (ISO only) */ @@ -1034,8 +1046,15 @@ next_dir: the timezone offset for descriptors and file times to use. */ tzset(); time_t now = time(NULL); - if (viso->format & VISO_FORMAT_ISO) /* timezones are ISO only */ - tz_offset = (now - mktime(gmtime(&now))) / (3600 / 4); + struct tm now_tm; + if (viso->format & VISO_FORMAT_ISO) { /* timezones are ISO only */ +#ifdef _WIN32 + gmtime_s(&now_tm, &now); // Windows: output first param, input second +#else + gmtime_r(&now, &now_tm); // POSIX: input first param, output second +#endif + tz_offset = (now - mktime(&now_tm)) / (3600 / 4); + } /* Get root directory basename for the volume ID. */ const char *basename = path_get_filename(viso->root_dir->path); diff --git a/src/chipset/CMakeLists.txt b/src/chipset/CMakeLists.txt index 7817ac052..d61b5c53d 100644 --- a/src/chipset/CMakeLists.txt +++ b/src/chipset/CMakeLists.txt @@ -17,6 +17,7 @@ add_library(chipset OBJECT 82c100.c + acc2036.c acc2168.c cs8220.c cs8230.c @@ -48,6 +49,7 @@ add_library(chipset OBJECT opti291.c opti391.c opti495.c + opti498.c opti499.c opti602.c opti822.c diff --git a/src/chipset/acc2036.c b/src/chipset/acc2036.c new file mode 100644 index 000000000..3984f82e0 --- /dev/null +++ b/src/chipset/acc2036.c @@ -0,0 +1,346 @@ +/* + * 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 2036 chipset. + * + * Authors: Miran Grca, + * + * Copyright 2025 Miran Grca. + */ +#include +#include +#include +#include +#include +#include +#include <86box/86box.h> +#include "cpu.h" +#include <86box/timer.h> +#include <86box/io.h> +#include <86box/device.h> +#include <86box/machine.h> +#include <86box/mem.h> +#include <86box/port_92.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> +#include <86box/fdd.h> +#include <86box/fdc.h> +#include <86box/chipset.h> + +typedef struct { + uint32_t virt; + uint32_t phys; + + mem_mapping_t mapping; +} ram_page_t; + +typedef struct { + uint8_t reg; + uint8_t regs[32]; + + ram_page_t ram_mid_pages[24]; + ram_page_t ems_pages[4]; +} acc2036_t; + +static uint8_t +acc2036_mem_read(uint32_t addr, void *priv) +{ + ram_page_t *dev = (ram_page_t *) priv; + uint8_t ret = 0xff; + + addr = (addr - dev->virt) + dev->phys; + + if (addr < (mem_size << 10)) + ret = ram[addr]; + + return ret; +} + +static uint16_t +acc2036_mem_readw(uint32_t addr, void *priv) +{ + ram_page_t *dev = (ram_page_t *) priv; + uint16_t ret = 0xffff; + + addr = (addr - dev->virt) + dev->phys; + + if (addr < (mem_size << 10)) + ret = *(uint16_t *) &(ram[addr]); + + return ret; +} + +static void +acc2036_mem_write(uint32_t addr, uint8_t val, void *priv) +{ + ram_page_t *dev = (ram_page_t *) priv; + + addr = (addr - dev->virt) + dev->phys; + + if (addr < (mem_size << 10)) + ram[addr] = val; +} + +static void +acc2036_mem_writew(uint32_t addr, uint16_t val, void *priv) +{ + ram_page_t *dev = (ram_page_t *) priv; + + addr = (addr - dev->virt) + dev->phys; + + if (addr < (mem_size << 10)) + *(uint16_t *) &(ram[addr]) = val; +} + +static void +acc2036_recalc(acc2036_t *dev) +{ + uint32_t ems_bases[4] = { 0x000c0000, 0x000c8000, 0x000d0000, 0x000e0000 }; + + int start_i = (ems_bases[dev->regs[0x0c] & 0x03] - 0x000a0000) >> 14; + int end_i = start_i + 3; + + for (int i = 0; i < 24; i++) { + ram_page_t *rp = &dev->ram_mid_pages[i]; + mem_mapping_disable(&rp->mapping); + } + + for (int i = 0; i < 4; i++) { + ram_page_t *ep = &dev->ems_pages[i]; + mem_mapping_disable(&ep->mapping); + } + + for (int i = 0; i < 24; i++) { + ram_page_t *rp = &dev->ram_mid_pages[i]; + + if ((dev->regs[0x03] & 0x08) && (i >= start_i) && (i <= end_i)) { + /* EMS */ + ram_page_t *ep = &dev->ems_pages[i - start_i]; + + mem_mapping_disable(&rp->mapping); + mem_mapping_set_addr(&ep->mapping, ep->virt, 0x000040000); + mem_mapping_set_exec(&ep->mapping, ram + ep->phys); + mem_set_mem_state_both(ep->virt, 0x00004000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + } else { + int master_write; + int master_read; + int bit; + int ew_flag; + int er_flag; + int flags; + uint8_t val; + + mem_mapping_set_addr(&rp->mapping, rp->virt, 0x000040000); + mem_mapping_set_exec(&rp->mapping, ram + rp->phys); + + if ((i >= 8) && (i <= 15)) { + /* 0C0000-0DFFFF */ + master_write = dev->regs[0x02] & 0x08; + master_read = dev->regs[0x02] & 0x04; + bit = ((i - 8) >> 1); + val = dev->regs[0x0d] & (1 << bit); + if (i >= 12) { + ew_flag = (dev->regs[0x07] & 0x80) ? MEM_WRITE_EXTANY : MEM_WRITE_EXTERNAL; + er_flag = (dev->regs[0x07] & 0x80) ? MEM_READ_EXTANY : MEM_READ_EXTERNAL; + } else { + ew_flag = (dev->regs[0x07] & 0x40) ? MEM_WRITE_EXTANY : MEM_WRITE_EXTERNAL; + er_flag = (dev->regs[0x07] & 0x40) ? MEM_READ_EXTANY : MEM_READ_EXTERNAL; + } + flags = (val && master_write) ? MEM_WRITE_INTERNAL : ew_flag; + flags |= (val && master_read) ? MEM_READ_INTERNAL : er_flag; + mem_set_mem_state_both(rp->virt, 0x00004000, flags); + } else if (i > 15) { + /* 0E0000-0FFFFF */ + master_write = dev->regs[0x02] & 0x02; + master_read = dev->regs[0x02] & 0x01; + bit = ((i - 8) >> 2); + val = dev->regs[0x0c] & (1 << bit); + if (i >= 20) { + ew_flag = MEM_WRITE_EXTANY; + er_flag = MEM_READ_EXTANY; + } else { + ew_flag = (dev->regs[0x0c] & 0x10) ? MEM_WRITE_EXTANY : MEM_WRITE_EXTERNAL; + er_flag = (dev->regs[0x0c] & 0x10) ? MEM_READ_EXTANY : MEM_READ_EXTERNAL; + } + flags = (val && master_write) ? MEM_WRITE_INTERNAL : ew_flag; + flags |= (val && master_read) ? MEM_READ_INTERNAL : er_flag; + mem_set_mem_state_both(rp->virt, 0x00004000, flags); + } + } + } + + if (dev->regs[0x00] & 0x40) + mem_set_mem_state_both(0x00fe0000, 0x00010000, MEM_READ_EXTANY | MEM_WRITE_EXTANY); + else + mem_set_mem_state_both(0x00fe0000, 0x00010000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + + for (int i = 0x01; i <= 0x06; i++) { + uint32_t base = 0x00fe0000 - (i * 0x00010000); + + if (dev->regs[i] & 0x40) + mem_set_mem_state_both(base, 0x00008000, MEM_READ_EXTANY | MEM_WRITE_EXTANY); + else + mem_set_mem_state_both(base, 0x00008000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + + if (dev->regs[i] & 0x80) + mem_set_mem_state_both(base + 0x00008000, 0x00008000, MEM_READ_EXTANY | MEM_WRITE_EXTANY); + else + mem_set_mem_state_both(base + 0x00008000, 0x00008000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + } + + mem_remap_top(0); + if (dev->regs[0x03] & 0x10) { + if (dev->regs[0x02] & 0x0c) + mem_remap_top(128); + else if (dev->regs[0x02] & 0x03) + mem_remap_top(256); + else + mem_remap_top(384); + } + + flushmmucache_nopc(); +} + +static uint8_t +acc2036_in(uint16_t port, void *priv) { + acc2036_t *dev = (acc2036_t *) priv; + uint8_t reg = dev->reg - 0x20; + uint8_t ret = 0xff; + + if (port & 0x0001) switch (dev->reg) { + default: + break; + case 0x20 ... 0x2e: + case 0x31 ... 0x3f: + ret = dev->regs[reg]; + break; + } else + ret = dev->reg; + + return ret; +} + +static void +acc2036_out(uint16_t port, uint8_t val, void *priv) { + acc2036_t *dev = (acc2036_t *) priv; + uint8_t reg = dev->reg - 0x20; + + if (port & 0x0001) switch (dev->reg) { + default: + break; + case 0x20 ... 0x23: + dev->regs[reg] = val; + acc2036_recalc(dev); + break; + case 0x24 ... 0x2b: + dev->regs[reg] = val; + dev->ems_pages[(reg - 0x04) >> 1].phys = ((dev->regs[reg & 0xfe] & 0x1f) << 19) | + ((dev->regs[reg | 0x01] & 0x1f) << 14); + acc2036_recalc(dev); + break; + case 0x2c: case 0x2d: + dev->regs[reg] = val; + acc2036_recalc(dev); + break; + case 0x2e: + dev->regs[reg] = val | 0x10; + break; + case 0x31: + dev->regs[reg] = val; + mem_a20_alt = (val & 0x01); + mem_a20_recalc(); + flushmmucache(); + if (val & 0x02) { + softresetx86(); /* Pulse reset! */ + cpu_set_edx(); + flushmmucache(); + } + break; + case 0x32 ... 0x3f: + dev->regs[reg] = val; + break; + } else + dev->reg = val; +} + +static void +acc2036_close(void *priv) +{ + acc2036_t *dev = (acc2036_t *) priv; + + free(dev); +} + +static void * +acc2036_init(UNUSED(const device_t *info)) +{ + acc2036_t *dev = (acc2036_t *) calloc(1, sizeof(acc2036_t)); + + for (int i = 0; i < 24; i++) { + ram_page_t *rp = &dev->ram_mid_pages[i]; + + rp->virt = 0x000a0000 + (i << 14); + rp->phys = 0x000a0000 + (i << 14); + mem_mapping_add(&rp->mapping, rp->virt, 0x00004000, + acc2036_mem_read, acc2036_mem_readw, NULL, + acc2036_mem_write, acc2036_mem_writew, NULL, + ram + rp->phys, MEM_MAPPING_INTERNAL, rp); + } + + for (int i = 0; i < 4; i++) { + ram_page_t *ep = &dev->ems_pages[i]; + + ep->virt = 0x000d0000 + (i << 14); + ep->phys = 0x00000000 + (i << 14); + mem_mapping_add(&ep->mapping, ep->virt, 0x00004000, + acc2036_mem_read, acc2036_mem_readw, NULL, + acc2036_mem_write, acc2036_mem_writew, NULL, + ram + ep->phys, MEM_MAPPING_INTERNAL, ep); + mem_mapping_disable(&ep->mapping); + } + + mem_mapping_disable(&ram_mid_mapping); + + dev->regs[0x00] = 0x02; + dev->regs[0x0e] = 0x10; + dev->regs[0x11] = 0x01; + dev->regs[0x13] = 0x40; + dev->regs[0x15] = 0x40; + dev->regs[0x17] = 0x40; + dev->regs[0x19] = 0x40; + dev->regs[0x1b] = 0x40; + dev->regs[0x1c] = 0x22; + dev->regs[0x1d] = 0xc4; + dev->regs[0x1f] = 0x30; + acc2036_recalc(dev); + + mem_a20_alt = 0x01; + mem_a20_recalc(); + flushmmucache(); + + io_sethandler(0x00f2, 0x0002, + acc2036_in, NULL, NULL, acc2036_out, NULL, NULL, dev); + + device_add(&port_92_device); + + return dev; +} + +const device_t acc2036_device = { + .name = "ACC 2036", + .internal_name = "acc2036", + .flags = 0, + .local = 0, + .init = acc2036_init, + .close = acc2036_close, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/chipset/opti283.c b/src/chipset/opti283.c index 395ad4212..81780cf10 100644 --- a/src/chipset/opti283.c +++ b/src/chipset/opti283.c @@ -16,6 +16,7 @@ * Copyright 2021 Tiseno100. * Copyright 2021 Miran Grca. */ +#include #include #include #include @@ -158,7 +159,20 @@ opti283_shadow_recalc(opti283_t *dev) rom = dev->regs[0x11] & (1 << ((i >> 2) + 4)); opti283_log("OPTI 283: %i/%08X: %i, %i, %i\n", i, base, (i >= 4) ? (1 << (i - 4)) : (1 << (i + 4)), (1 << (i >> 2)), (1 << ((i >> 2) + 4))); - if (sh_enable && rom) { + if (sh_copy) { + if (base >= 0x000e0000) + shadowbios_write |= 1; + if (base >= 0x000d0000) + dev->shadow_high |= 1; + + if (base >= 0xe0000) { + mem_set_mem_state_both(base, 0x4000, MEM_READ_EXTANY | MEM_WRITE_INTERNAL); + opti283_log("OPTI 283: %08X-%08X READ_EXTANY, WRITE_INTERNAL\n", base, base + 0x3fff); + } else { + mem_set_mem_state_both(base, 0x4000, MEM_READ_EXTERNAL | MEM_WRITE_INTERNAL); + opti283_log("OPTI 283: %08X-%08X READ_EXTERNAL, WRITE_INTERNAL\n", base, base + 0x3fff); + } + } else if (sh_enable && rom) { if (base >= 0x000e0000) shadowbios |= 1; if (base >= 0x000d0000) @@ -171,13 +185,8 @@ opti283_shadow_recalc(opti283_t *dev) if (base >= 0x000e0000) shadowbios_write |= 1; - if (sh_copy) { - mem_set_mem_state_both(base, 0x4000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); - opti283_log("OPTI 283: %08X-%08X READ_INTERNAL, WRITE_INTERNAL\n", base, base + 0x3fff); - } else { - mem_set_mem_state_both(base, 0x4000, MEM_READ_INTERNAL | MEM_WRITE_EXTERNAL); - opti283_log("OPTI 283: %08X-%08X READ_INTERNAL, WRITE_EXTERNAL\n", base, base + 0x3fff); - } + mem_set_mem_state_both(base, 0x4000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + opti283_log("OPTI 283: %08X-%08X READ_INTERNAL, WRITE_INTERNAL\n", base, base + 0x3fff); } } else { if (base >= 0xe0000) { @@ -239,9 +248,21 @@ opti283_write(uint16_t addr, uint8_t val, void *priv) dev->regs[dev->index] = (dev->regs[dev->index] & 0x80) | (val & 0x7f); break; - case 0x14: + case 0x14: { + double bus_clk; + switch (val & 0x01) { + default: + case 0x00: + bus_clk = cpu_busspeed / 6.0; + break; + case 0x01: + bus_clk = cpu_busspeed / 4.0; + break; + } + cpu_set_isa_speed((int) round(bus_clk)); reset_on_hlt = !!(val & 0x40); fallthrough; + } case 0x11: case 0x12: case 0x13: @@ -310,6 +331,8 @@ opti283_init(UNUSED(const device_t *info)) opti283_shadow_recalc(dev); + cpu_set_isa_speed((int) round(cpu_busspeed / 6.0)); + device_add(&port_92_device); return dev; diff --git a/src/chipset/opti495.c b/src/chipset/opti495.c index aa4e4b4c5..8521dbd17 100644 --- a/src/chipset/opti495.c +++ b/src/chipset/opti495.c @@ -8,14 +8,13 @@ * * Implementation of the OPTi 82C493/82C495 chipset. * - * - * * Authors: Tiseno100, * Miran Grca, * * Copyright 2008-2020 Tiseno100. * Copyright 2016-2020 Miran Grca. */ +#include #include #include #include @@ -28,6 +27,7 @@ #include <86box/io.h> #include <86box/device.h> #include <86box/mem.h> +#include <86box/plat_fallthrough.h> #include <86box/port_92.h> #include <86box/chipset.h> @@ -166,6 +166,27 @@ opti495_write(uint16_t addr, uint8_t val, void *priv) case 0x26: opti495_recalc(dev); break; + + case 0x25: { + double bus_clk; + switch (val & 0x03) { + default: + case 0x00: + bus_clk = cpu_busspeed / 6.0; + break; + case 0x01: + bus_clk = cpu_busspeed / 4.0; + break; + case 0x02: + bus_clk = cpu_busspeed / 3.0; + break; + case 0x03: + bus_clk = (cpu_busspeed * 2.0) / 5.0; + break; + } + cpu_set_isa_speed((int) round(bus_clk)); + break; + } } } @@ -259,6 +280,8 @@ opti495_init(const device_t *info) io_sethandler(0x00e1, 0x0002, opti495_read, NULL, NULL, opti495_write, NULL, NULL, dev); + cpu_set_isa_speed((int) round(cpu_busspeed / 6.0)); + return dev; } @@ -276,11 +299,25 @@ const device_t opti493_device = { .config = NULL }; -const device_t opti495_device = { +const device_t opti495slc_device = { .name = "OPTi 82C495", - .internal_name = "opti495", + .internal_name = "opti495slc", .flags = 0, - .local = OPTI495XLC, + .local = OPTI495SLC, + .init = opti495_init, + .close = opti495_close, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t opti495sx_device = { + .name = "OPTi 82C495SX", + .internal_name = "opti495sx", + .flags = 0, + .local = OPTI495SX, .init = opti495_init, .close = opti495_close, .reset = NULL, diff --git a/src/chipset/opti498.c b/src/chipset/opti498.c new file mode 100644 index 000000000..2d3dc6709 --- /dev/null +++ b/src/chipset/opti498.c @@ -0,0 +1,360 @@ +/* + * 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 OPTi 82C498 chipset. + * + * Authors: Miran Grca, + * + * Copyright 2025 Miran Grca. + */ +#include +#include +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include "cpu.h" +#include <86box/timer.h> +#include <86box/io.h> +#include <86box/device.h> +#include <86box/mem.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> +#include <86box/port_92.h> +#include <86box/chipset.h> + +#ifdef ENABLE_OPTI498_LOG +int opti498_do_log = ENABLE_OPTI498_LOG; + +static void +opti498_log(const char *fmt, ...) +{ + va_list ap; + + if (opti498_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define opti498_log(fmt, ...) +#endif + +typedef struct mem_remapping_t { + uint32_t phys; + uint32_t virt; +} mem_remapping_t; + +typedef struct opti498_t { + uint8_t index; + /* 0x30 for 496/497, 0x70 for 498. */ + uint8_t reg_base; + uint8_t shadow_high; + uint8_t regs[256]; + mem_remapping_t mem_remappings[2]; + mem_mapping_t mem_mappings[2]; +} opti498_t; + +static uint8_t +opti498_read_remapped_ram(uint32_t addr, void *priv) +{ + const mem_remapping_t *dev = (mem_remapping_t *) priv; + + return mem_read_ram((addr - dev->virt) + dev->phys, priv); +} + +static uint16_t +opti498_read_remapped_ramw(uint32_t addr, void *priv) +{ + const mem_remapping_t *dev = (mem_remapping_t *) priv; + + return mem_read_ramw((addr - dev->virt) + dev->phys, priv); +} + +static uint32_t +opti498_read_remapped_raml(uint32_t addr, void *priv) +{ + const mem_remapping_t *dev = (mem_remapping_t *) priv; + + return mem_read_raml((addr - dev->virt) + dev->phys, priv); +} + +static void +opti498_write_remapped_ram(uint32_t addr, uint8_t val, void *priv) +{ + const mem_remapping_t *dev = (mem_remapping_t *) priv; + + mem_write_ram((addr - dev->virt) + dev->phys, val, priv); +} + +static void +opti498_write_remapped_ramw(uint32_t addr, uint16_t val, void *priv) +{ + const mem_remapping_t *dev = (mem_remapping_t *) priv; + + mem_write_ramw((addr - dev->virt) + dev->phys, val, priv); +} + +static void +opti498_write_remapped_raml(uint32_t addr, uint32_t val, void *priv) +{ + const mem_remapping_t *dev = (mem_remapping_t *) priv; + + mem_write_raml((addr - dev->virt) + dev->phys, val, priv); +} + +static void +opti498_shadow_recalc(opti498_t *dev) +{ + uint32_t base; + uint32_t rbase; + uint8_t sh_enable; + uint8_t sh_mode; + uint8_t rom; + uint8_t sh_copy; + + shadowbios = shadowbios_write = 0; + dev->shadow_high = 0; + + opti498_log("OPTI 498: %02X %02X %02X %02X\n", dev->regs[0x02], dev->regs[0x03], dev->regs[0x04], dev->regs[0x05]); + + if (dev->regs[0x02] & 0x80) { + if (dev->regs[0x04] & 0x02) { + mem_set_mem_state_both(0xf0000, 0x10000, MEM_READ_EXTANY | MEM_WRITE_EXTANY); + opti498_log("OPTI 498: F0000-FFFFF READ_EXTANY, WRITE_EXTANY\n"); + } else { + shadowbios_write = 1; + mem_set_mem_state_both(0xf0000, 0x10000, MEM_READ_EXTANY | MEM_WRITE_INTERNAL); + opti498_log("OPTI 498: F0000-FFFFF READ_EXTANY, WRITE_INTERNAL\n"); + } + } else { + shadowbios = 1; + mem_set_mem_state_both(0xf0000, 0x10000, MEM_READ_INTERNAL | MEM_WRITE_DISABLED); + opti498_log("OPTI 498: F0000-FFFFF READ_INTERNAL, WRITE_DISABLED\n"); + } + + sh_copy = dev->regs[0x02] & 0x08; + for (uint8_t i = 0; i < 12; i++) { + base = 0xc0000 + (i << 14); + if (i >= 4) + sh_enable = dev->regs[0x03] & (1 << (i - 4)); + else + sh_enable = dev->regs[0x04] & (1 << (i + 4)); + sh_mode = dev->regs[0x02] & (1 << (i >> 2)); + rom = dev->regs[0x02] & (1 << ((i >> 2) + 4)); + opti498_log("OPTI 498: %i/%08X: %i, %i, %i\n", i, base, (i >= 4) ? (1 << (i - 4)) : (1 << (i + 4)), (1 << (i >> 2)), (1 << ((i >> 2) + 4))); + + if (sh_copy) { + if (base >= 0x000e0000) + shadowbios_write |= 1; + if (base >= 0x000d0000) + dev->shadow_high |= 1; + + if (base >= 0xe0000) { + mem_set_mem_state_both(base, 0x4000, MEM_READ_EXTANY | MEM_WRITE_INTERNAL); + opti498_log("OPTI 498: %08X-%08X READ_EXTANY, WRITE_INTERNAL\n", base, base + 0x3fff); + } else { + mem_set_mem_state_both(base, 0x4000, MEM_READ_EXTERNAL | MEM_WRITE_INTERNAL); + opti498_log("OPTI 498: %08X-%08X READ_EXTERNAL, WRITE_INTERNAL\n", base, base + 0x3fff); + } + } else if (sh_enable && rom) { + if (base >= 0x000e0000) + shadowbios |= 1; + if (base >= 0x000d0000) + dev->shadow_high |= 1; + + if (sh_mode) { + mem_set_mem_state_both(base, 0x4000, MEM_READ_INTERNAL | MEM_WRITE_DISABLED); + opti498_log("OPTI 498: %08X-%08X READ_INTERNAL, WRITE_DISABLED\n", base, base + 0x3fff); + } else { + if (base >= 0x000e0000) + shadowbios_write |= 1; + + mem_set_mem_state_both(base, 0x4000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); + opti498_log("OPTI 498: %08X-%08X READ_INTERNAL, WRITE_INTERNAL\n", base, base + 0x3fff); + } + } else { + if (base >= 0xe0000) { + mem_set_mem_state_both(base, 0x4000, MEM_READ_EXTANY | MEM_WRITE_DISABLED); + opti498_log("OPTI 498: %08X-%08X READ_EXTANY, WRITE_DISABLED\n", base, base + 0x3fff); + } else { + mem_set_mem_state_both(base, 0x4000, MEM_READ_EXTERNAL | MEM_WRITE_DISABLED); + opti498_log("OPTI 498: %08X-%08X READ_EXTERNAL, WRITE_DISABLED\n", base, base + 0x3fff); + } + } + } + + rbase = ((uint32_t) (dev->regs[0x05] & 0x3f)) << 20; + + if (rbase > 0) { + dev->mem_remappings[0].virt = rbase; + mem_mapping_set_addr(&dev->mem_mappings[0], rbase, 0x00020000); + + if (!dev->shadow_high) { + rbase += 0x00020000; + dev->mem_remappings[1].virt = rbase; + mem_mapping_set_addr(&dev->mem_mappings[1], rbase, 0x00020000); + } else + mem_mapping_disable(&dev->mem_mappings[1]); + } else { + mem_mapping_disable(&dev->mem_mappings[0]); + mem_mapping_disable(&dev->mem_mappings[1]); + } + + flushmmucache_nopc(); +} + +static void +opti498_write(uint16_t addr, uint8_t val, void *priv) +{ + opti498_t *dev = (opti498_t *) priv; + uint8_t reg = dev->index - dev->reg_base; + + switch (addr) { + default: + break; + + case 0x22: + dev->index = val; + break; + + case 0x24: + opti498_log("OPTi 498: dev->regs[%02x] = %02x\n", dev->index, val); + + if ((reg >= 0x00) && (reg <= 0x0b)) switch (reg) { + default: + break; + + case 0x00: + dev->regs[reg] = (dev->regs[reg] & 0xc0) | (val & 0x3f); + break; + + case 0x01: + case 0x07 ... 0x0b: + dev->regs[reg] = val; + break; + + case 0x02: + case 0x03: + case 0x04: + case 0x05: + dev->regs[reg] = val; + opti498_shadow_recalc(dev); + break; + + case 0x06: { + double bus_clk; + dev->regs[reg] = val; + switch (val & 0x03) { + default: + case 0x00: + bus_clk = cpu_busspeed / 8.0; + break; + case 0x01: + bus_clk = cpu_busspeed / 6.0; + break; + case 0x02: + bus_clk = cpu_busspeed / 5.0; + break; + case 0x03: + bus_clk = cpu_busspeed / 4.0; + break; + } + cpu_set_isa_speed((int) round(bus_clk)); + reset_on_hlt = !!(val & 0x40); + break; + } + } + + dev->index = 0xff; + break; + } +} + +static uint8_t +opti498_read(uint16_t addr, void *priv) +{ + opti498_t *dev = (opti498_t *) priv; + uint8_t reg = dev->index - dev->reg_base; + uint8_t ret = 0xff; + + if (addr == 0x24) { + if ((reg >= 0x00) && (reg <= 0x0b)) + ret = dev->regs[reg]; + + dev->index = 0xff; + } + + return ret; +} + +static void +opti498_close(void *priv) +{ + opti498_t *dev = (opti498_t *) priv; + + free(dev); +} + +static void * +opti498_init(UNUSED(const device_t *info)) +{ + opti498_t *dev = (opti498_t *) calloc(1, sizeof(opti498_t)); + + dev->reg_base = info->local & 0xff; + + io_sethandler(0x0022, 0x0001, opti498_read, NULL, NULL, opti498_write, NULL, NULL, dev); + io_sethandler(0x0024, 0x0001, opti498_read, NULL, NULL, opti498_write, NULL, NULL, dev); + + dev->regs[0x00] = 0x1f; + dev->regs[0x01] = 0x8f; + dev->regs[0x02] = 0xf0; + dev->regs[0x07] = 0x70; + dev->regs[0x09] = 0x70; + + dev->mem_remappings[0].phys = 0x000a0000; + dev->mem_remappings[1].phys = 0x000d0000; + + mem_mapping_add(&dev->mem_mappings[0], 0, 0x00020000, + opti498_read_remapped_ram, opti498_read_remapped_ramw, opti498_read_remapped_raml, + opti498_write_remapped_ram, opti498_write_remapped_ramw, opti498_write_remapped_raml, + &ram[dev->mem_remappings[0].phys], MEM_MAPPING_INTERNAL, &dev->mem_remappings[0]); + mem_mapping_disable(&dev->mem_mappings[0]); + + mem_mapping_add(&dev->mem_mappings[1], 0, 0x00020000, + opti498_read_remapped_ram, opti498_read_remapped_ramw, opti498_read_remapped_raml, + opti498_write_remapped_ram, opti498_write_remapped_ramw, opti498_write_remapped_raml, + &ram[dev->mem_remappings[1].phys], MEM_MAPPING_INTERNAL, &dev->mem_remappings[1]); + mem_mapping_disable(&dev->mem_mappings[1]); + + opti498_shadow_recalc(dev); + + cpu_set_isa_speed((int) round(cpu_busspeed / 8.0)); + + device_add(&port_92_device); + + return dev; +} + +const device_t opti498_device = { + .name = "OPTi 82C498", + .internal_name = "opti498", + .flags = 0, + .local = 0x70, + .init = opti498_init, + .close = opti498_close, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/chipset/opti499.c b/src/chipset/opti499.c index d54e8184e..383b8e3e2 100644 --- a/src/chipset/opti499.c +++ b/src/chipset/opti499.c @@ -16,6 +16,7 @@ * Copyright 2008-2020 Tiseno100. * Copyright 2016-2020 Miran Grca. */ +#include #include #include #include @@ -148,9 +149,28 @@ opti499_write(uint16_t addr, uint8_t val, void *priv) default: break; - case 0x20: + case 0x20: { + double coeff = (val & 0x10) ? 1.0 : 2.0; + double bus_clk; + switch (dev->regs[0x25] & 0x03) { + default: + case 0x00: + bus_clk = (cpu_busspeed * coeff) / 6.0; + break; + case 0x01: + bus_clk = (cpu_busspeed * coeff) / 5.0; + break; + case 0x02: + bus_clk = (cpu_busspeed * coeff) / 4.0; + break; + case 0x03: + bus_clk = (cpu_busspeed * coeff) / 3.0; + break; + } + cpu_set_isa_speed((int) round(bus_clk)); reset_on_hlt = !(val & 0x02); break; + } case 0x21: cpu_cache_ext_enabled = !!(dev->regs[0x21] & 0x10); @@ -163,6 +183,28 @@ opti499_write(uint16_t addr, uint8_t val, void *priv) case 0x2d: opti499_recalc(dev); break; + + case 0x25: { + double coeff = (dev->regs[0x20] & 0x10) ? 1.0 : 2.0; + double bus_clk; + switch (val & 0x03) { + default: + case 0x00: + bus_clk = (cpu_busspeed * coeff) / 8.0; + break; + case 0x01: + bus_clk = (cpu_busspeed * coeff) / 6.0; + break; + case 0x02: + bus_clk = (cpu_busspeed * coeff) / 5.0; + break; + case 0x03: + bus_clk = (cpu_busspeed * coeff) / 4.0; + break; + } + cpu_set_isa_speed((int) round(bus_clk)); + break; + } } } @@ -229,6 +271,8 @@ opti499_reset(void *priv) cpu_update_waitstates(); opti499_recalc(dev); + + cpu_set_isa_speed((int) round((cpu_busspeed * 2.0) / 6.0)); } static void diff --git a/src/chipset/opti895.c b/src/chipset/opti895.c index cb55ef2a7..16b324963 100644 --- a/src/chipset/opti895.c +++ b/src/chipset/opti895.c @@ -16,6 +16,7 @@ * Copyright 2008-2020 Tiseno100. * Copyright 2016-2020 Miran Grca. */ +#include #include #include #include @@ -182,6 +183,27 @@ opti895_write(uint16_t addr, uint8_t val, void *priv) smram_state_change(dev->smram, 0, !!(val & 0x80)); break; + case 0x25: { + double bus_clk; + switch (val & 0x03) { + default: + case 0x00: + bus_clk = cpu_busspeed / 6.0; + break; + case 0x01: + bus_clk = cpu_busspeed / 5.0; + break; + case 0x02: + bus_clk = cpu_busspeed / 4.0; + break; + case 0x03: + bus_clk = cpu_busspeed / 3.0; + break; + } + cpu_set_isa_speed((int) round(bus_clk)); + break; + } + case 0xe0: if (!(val & 0x01)) dev->forced_green = 0; @@ -294,6 +316,8 @@ opti895_init(const device_t *info) smram_enable(dev->smram, 0x00030000, 0x000b0000, 0x00010000, 0, 1); + cpu_set_isa_speed((int) round(cpu_busspeed / 6.0)); + return dev; } diff --git a/src/codegen_new/codegen_backend_x86-64_ops.c b/src/codegen_new/codegen_backend_x86-64_ops.c index 1569e693c..9ac8d2474 100644 --- a/src/codegen_new/codegen_backend_x86-64_ops.c +++ b/src/codegen_new/codegen_backend_x86-64_ops.c @@ -786,7 +786,7 @@ host_x86_MOV32_REG_ABS(codeblock_t *block, int dst_reg, void *p) codegen_addquad(block, (uintptr_t) p); codegen_addbyte3(block, 0x41, 0x8b, 0x01 | ((dst_reg & 7) << 3)); /*MOV dst_reg, [R9]*/ } else { - fatal("host_x86_MOV32_REG_ABS - RAM offset = %016" PRIX64 " (p - ram = %016" PRIX64 ")\n", ram_offset, (uintptr_t) p - (uintptr_t) ram); + fatal("host_x86_MOV32_REG_ABS - RAM offset = %016" PRIX64 " (p - ram = %016" PRIXPTR ")\n", ram_offset, (uintptr_t) p - (uintptr_t) ram); codegen_alloc_bytes(block, 6); codegen_addbyte(block, 0x8b); /*MOV [p], src_reg*/ codegen_addbyte(block, 0x05 | ((dst_reg & 7) << 3)); diff --git a/src/config.c b/src/config.c index 8039b9887..d33813e7d 100644 --- a/src/config.c +++ b/src/config.c @@ -660,6 +660,8 @@ load_network(void) nc->net_type = NET_TYPE_SLIRP; else if (!strcmp(p, "vde") || !strcmp(p, "2")) nc->net_type = NET_TYPE_VDE; + else if (!strcmp(p, "tap") || !strcmp(p, "3")) + nc->net_type = NET_TYPE_TAP; else nc->net_type = NET_TYPE_NONE; } else @@ -706,11 +708,12 @@ load_network(void) nc->net_type = NET_TYPE_SLIRP; else if (!strcmp(p, "vde") || !strcmp(p, "2")) nc->net_type = NET_TYPE_VDE; + else if (!strcmp(p, "tap") || !strcmp(p, "3")) + nc->net_type = NET_TYPE_TAP; else nc->net_type = NET_TYPE_NONE; } else nc->net_type = NET_TYPE_NONE; - sprintf(temp, "net_%02i_host_device", c + 1); p = ini_section_get_string(cat, temp, NULL); if (p != NULL) { @@ -2433,7 +2436,9 @@ save_network(void) case NET_TYPE_VDE: ini_section_set_string(cat, temp, "vde"); break; - + case NET_TYPE_TAP: + ini_section_set_string(cat, temp, "tap"); + break; default: break; } diff --git a/src/cpu/386_ops.h b/src/cpu/386_ops.h index 5113ca817..73626acd2 100644 --- a/src/cpu/386_ops.h +++ b/src/cpu/386_ops.h @@ -264,6 +264,7 @@ opVPCEXT(uint32_t fetchdat) uint8_t b2; uint16_t cent; time_t now; + struct tm tm_buf; struct tm *tm = NULL; if (!is_vpc) /* only emulate this on Virtual PC machines */ @@ -282,7 +283,16 @@ opVPCEXT(uint32_t fetchdat) /* 0f 3f 03 xx opcodes are mostly related to the host clock, so fetch it now */ if (b1 == 0x03) { (void) time(&now); - tm = localtime(&now); + +#ifdef _WIN32 + if (localtime_s(&tm_buf, &now) == 0) + tm = &tm_buf; +#else + tm = localtime_r(&now, &tm_buf); +#endif + + if (!tm) + fatal("localtime() failed for host clock\n"); } if ((b1 == 0x07) && (b2 == 0x0b)) { diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index b6f5f593c..47f3e7f5c 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -381,7 +381,7 @@ typedef struct { MMX_REG MM[8]; #ifdef USE_NEW_DYNAREC -# if defined(__APPLE__) && defined(__aarch64__) +# if (defined(__APPLE__) && defined(__aarch64__)) || defined(__aarch64__) uint64_t old_fp_control; uint64_t new_fp_control; # else diff --git a/src/cpu/softfloat3e/s_shiftRightJam256M.c b/src/cpu/softfloat3e/s_shiftRightJam256M.c index 654e01234..c92204c4d 100644 --- a/src/cpu/softfloat3e/s_shiftRightJam256M.c +++ b/src/cpu/softfloat3e/s_shiftRightJam256M.c @@ -33,6 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =============================================================================*/ +#include #include #include "primitiveTypes.h" @@ -64,7 +65,7 @@ void softfloat_shiftRightJam256M(const uint64_t *aPtr, uint32_t dist, uint64_t * { uint64_t wordJam; uint32_t wordDist; - uint64_t *ptr; + uint64_t *ptr = NULL; uint8_t i, innerDist; wordJam = 0; @@ -89,7 +90,7 @@ void softfloat_shiftRightJam256M(const uint64_t *aPtr, uint32_t dist, uint64_t * aPtr, innerDist, zPtr + indexMultiwordLoBut(4, wordDist) - ); + ); if (! wordDist) goto wordJam; } else { aPtr += indexWordLo(4 - wordDist); diff --git a/src/device/CMakeLists.txt b/src/device/CMakeLists.txt index 29fc0b9b4..999b83aeb 100644 --- a/src/device/CMakeLists.txt +++ b/src/device/CMakeLists.txt @@ -41,7 +41,7 @@ add_library(dev OBJECT keyboard.c keyboard_at.c keyboard_xt.c - ../lpt.c + lpt.c mouse.c mouse_bus.c mouse_microtouch_touchscreen.c diff --git a/src/device/hasp.c b/src/device/hasp.c index 3834af4cd..53228c2a0 100644 --- a/src/device/hasp.c +++ b/src/device/hasp.c @@ -27,6 +27,7 @@ #include #define HAVE_STDARG_H #include <86box/86box.h> +#include <86box/timer.h> #include <86box/lpt.h> #include <86box/device.h> @@ -334,13 +335,16 @@ hasp_close(void *priv) } const lpt_device_t lpt_hasp_savquest_device = { - .name = "Protection Dongle for Savage Quest", - .internal_name = "dongle_savquest", - .init = hasp_init_savquest, - .close = hasp_close, - .write_data = hasp_write_data, - .write_ctrl = NULL, - .read_data = NULL, - .read_status = hasp_read_status, - .read_ctrl = NULL + .name = "Protection Dongle for Savage Quest", + .internal_name = "dongle_savquest", + .init = hasp_init_savquest, + .close = hasp_close, + .write_data = hasp_write_data, + .write_ctrl = NULL, + .autofeed = NULL, + .strobe = NULL, + .read_status = hasp_read_status, + .read_ctrl = NULL, + .epp_write_data = NULL, + .epp_request_read = NULL }; diff --git a/src/device/isarom.c b/src/device/isarom.c index f742a9eae..cdf5a61c6 100644 --- a/src/device/isarom.c +++ b/src/device/isarom.c @@ -156,7 +156,7 @@ isarom_init(const device_t *info) snprintf(dev->socket[i].nvr_path, sizeof(dev->socket[i].nvr_path), "isarom_%i_%i.nvr", dev->inst, i + 1); FILE *fp = nvr_fopen(dev->socket[i].nvr_path, "rb"); if (fp != NULL) { - fread(dev->socket[i].rom.rom, 1, dev->socket[i].size, fp); + (void) !fread(dev->socket[i].rom.rom, 1, dev->socket[i].size, fp); fclose(fp); isarom_log("isarom[%u]: loaded %zu bytes from %s\n", dev->inst, read_bytes, dev->socket[i].nvr_path); } else diff --git a/src/device/kbc_at.c b/src/device/kbc_at.c index 1338b9555..d19b08f84 100644 --- a/src/device/kbc_at.c +++ b/src/device/kbc_at.c @@ -1817,8 +1817,6 @@ read_p1(atkbc_t *dev) Compaq: Reserved; NCR: DMA mode. */ - kbc_at_log("ATkbc: read P1\n"); - fixed_bits = 4; /* The SMM handlers of Intel AMI Pentium BIOS'es expect bit 6 to be set. */ @@ -2108,7 +2106,7 @@ kbc_at_process_cmd(void *priv) break; case 0xc0: /* read P1 */ - kbc_at_log("ATkbc: read P2\n"); + kbc_at_log("ATkbc: read P1\n"); kbc_delay_to_ob(dev, read_p1(dev), 0, 0x00); break; diff --git a/src/device/keyboard_xt.c b/src/device/keyboard_xt.c index 7e419b39d..5190de839 100644 --- a/src/device/keyboard_xt.c +++ b/src/device/keyboard_xt.c @@ -69,6 +69,7 @@ enum { KBD_TYPE_ZENITH, KBD_TYPE_PRAVETZ, KBD_TYPE_HYUNDAI, + KBD_TYPE_FE2010, KBD_TYPE_XTCLONE }; @@ -80,6 +81,7 @@ typedef struct xtkbd_t { uint8_t pa; uint8_t pb; uint8_t pd; + uint8_t cfg; uint8_t clock; uint8_t key_waiting; uint8_t type; @@ -832,12 +834,26 @@ kbd_write(uint16_t port, uint8_t val, void *priv) kbd_log("XTkbd: Cassette motor is %s\n", !(val & 0x08) ? "ON" : "OFF"); #endif break; -#ifdef ENABLE_KEYBOARD_XT_LOG + case 0x62: /* Switch Register (aka Port C) */ +#ifdef ENABLE_KEYBOARD_XT_LOG if ((kbd->type == KBD_TYPE_PC81) || (kbd->type == KBD_TYPE_PC82) || (kbd->type == KBD_TYPE_PRAVETZ)) kbd_log("XTkbd: Cassette IN is %i\n", !!(val & 0x10)); - break; #endif + if (kbd->type == KBD_TYPE_FE2010) { + kbd_log("XTkbd: Switch register in is %02X\n", val); + if (!(kbd->cfg & 0x08)) + kbd->pd = (kbd->pd & 0x30) | (val & 0xcf); + } + break; + + case 0x63: + if (kbd->type == KBD_TYPE_FE2010) { + kbd_log("XTkbd: Configuration register in is %02X\n", val); + if (!(kbd->cfg & 0x08)) + kbd->cfg = val; + } + break; case 0xc0 ... 0xcf: /* Pravetz Flags */ kbd_log("XTkbd: Port %02X out: %02X\n", port, val); @@ -912,7 +928,12 @@ kbd_read(uint16_t port, void *priv) break; case 0x62: /* Switch Register (aka Port C) */ - if ((kbd->type == KBD_TYPE_PC81) || (kbd->type == KBD_TYPE_PC82) || + if (kbd->type == KBD_TYPE_FE2010) { + if (kbd->pb & 0x04) /* PB2 */ + ret = (kbd->pd & 0x0d) | (hasfpu ? 0x02 : 0x00); + else + ret = kbd->pd >> 4; + } else if ((kbd->type == KBD_TYPE_PC81) || (kbd->type == KBD_TYPE_PC82) || (kbd->type == KBD_TYPE_PRAVETZ)) { if (kbd->pb & 0x04) /* PB2 */ switch (mem_size + isa_mem_size) { @@ -1037,7 +1058,7 @@ kbd_init(const device_t *info) (kbd->type <= KBD_TYPE_XT86) || (kbd->type == KBD_TYPE_XTCLONE) || (kbd->type == KBD_TYPE_COMPAQ) || (kbd->type == KBD_TYPE_TOSHIBA) || (kbd->type == KBD_TYPE_OLIVETTI) || (kbd->type == KBD_TYPE_HYUNDAI) || - (kbd->type == KBD_TYPE_VTECH)) { + (kbd->type == KBD_TYPE_VTECH) || (kbd->type == KBD_TYPE_FE2010)) { /* DIP switch readout: bit set = OFF, clear = ON. */ if (kbd->type == KBD_TYPE_OLIVETTI) /* Olivetti M19 @@ -1057,7 +1078,7 @@ kbd_init(const device_t *info) /* Switches 3, 4 - memory size. */ if ((kbd->type == KBD_TYPE_XT86) || (kbd->type == KBD_TYPE_XTCLONE) || (kbd->type == KBD_TYPE_HYUNDAI) || (kbd->type == KBD_TYPE_COMPAQ) || - (kbd->type == KBD_TYPE_TOSHIBA)) { + (kbd->type == KBD_TYPE_TOSHIBA) || (kbd->type == KBD_TYPE_FE2010)) { switch (mem_size) { case 256: kbd->pd |= 0x00; @@ -1356,7 +1377,7 @@ const device_t keyboard_xt_zenith_device = { const device_t keyboard_xt_hyundai_device = { .name = "Hyundai XT Keyboard", - .internal_name = "keyboard_x_hyundai", + .internal_name = "keyboard_xt_hyundai", .flags = 0, .local = KBD_TYPE_HYUNDAI, .init = kbd_init, @@ -1368,6 +1389,20 @@ const device_t keyboard_xt_hyundai_device = { .config = NULL }; +const device_t keyboard_xt_fe2010_device = { + .name = "Faraday FE2010 XT Keyboard", + .internal_name = "keyboard_xt_fe2010", + .flags = 0, + .local = KBD_TYPE_FE2010, + .init = kbd_init, + .close = kbd_close, + .reset = kbd_reset, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + const device_t keyboard_xtclone_device = { .name = "XT (Clone) Keyboard", .internal_name = "keyboard_xtclone", diff --git a/src/device/lpt.c b/src/device/lpt.c new file mode 100644 index 000000000..11afc04f9 --- /dev/null +++ b/src/device/lpt.c @@ -0,0 +1,839 @@ +/* Copyright holders: Sarah Walker + see COPYING for more details +*/ +#include +#include +#include +#include +#include +#define HAVE_STDARG_H +#include <86box/86box.h> +#include <86box/io.h> +#include <86box/fifo.h> +#include <86box/timer.h> +#include <86box/dma.h> +#include <86box/lpt.h> +#include <86box/pic.h> +#include <86box/sound.h> +#include <86box/prt_devs.h> +#include <86box/thread.h> +#include <86box/device.h> +#include <86box/machine.h> +#include <86box/network.h> + +lpt_port_t lpt_ports[PARALLEL_MAX]; + +const lpt_device_t lpt_none_device = { + .name = "None", + .internal_name = "none", + .init = NULL, + .close = NULL, + .write_data = NULL, + .write_ctrl = NULL, + .read_status = NULL, + .read_ctrl = NULL +}; + +static const struct { + const char *internal_name; + const lpt_device_t *device; +} lpt_devices[] = { + // clang-format off + {"none", &lpt_none_device }, + {"dss", &dss_device }, + {"lpt_dac", &lpt_dac_device }, + {"lpt_dac_stereo", &lpt_dac_stereo_device }, + {"text_prt", &lpt_prt_text_device }, + {"dot_matrix", &lpt_prt_escp_device }, + {"postscript", &lpt_prt_ps_device }, +#ifdef USE_PCL + {"pcl", &lpt_prt_pcl_device }, +#endif + {"plip", &lpt_plip_device }, + {"dongle_savquest", &lpt_hasp_savquest_device }, + {"", NULL } + // clang-format on +}; + +#ifdef ENABLE_LPT_LOG +int lpt_do_log = ENABLE_LPT_LOG; + +static void +lpt_log(const char *fmt, ...) +{ + va_list ap; + + if (lpt_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define lpt_log(fmt, ...) +#endif + +const char * +lpt_device_get_name(const int id) +{ + if (strlen(lpt_devices[id].internal_name) == 0) + return NULL; + if (lpt_devices[id].device == NULL) + return "None"; + return lpt_devices[id].device->name; +} + +const char * +lpt_device_get_internal_name(const int id) +{ + if (strlen(lpt_devices[id].internal_name) == 0) + return NULL; + return lpt_devices[id].internal_name; +} + +int +lpt_device_get_from_internal_name(const char *s) +{ + int c = 0; + + while (strlen(lpt_devices[c].internal_name) != 0) { + if (strcmp(lpt_devices[c].internal_name, s) == 0) + return c; + c++; + } + + return 0; +} + +void +lpt_devices_init(void) +{ + 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) + lpt_ports[i].priv = lpt_ports[i].dt->init(&lpt_ports[i]); + } +} + +void +lpt_devices_close(void) +{ + for (uint8_t i = 0; i < PARALLEL_MAX; i++) { + lpt_port_t *dev = &lpt_ports[i]; + + if (lpt_ports[i].dt && lpt_ports[i].dt->close) + dev->dt->close(dev->priv); + + dev->dt = NULL; + } +} + +static uint8_t +lpt_get_ctrl_raw(const lpt_port_t *dev) +{ + uint8_t ret; + + if (dev->dt && dev->dt->read_ctrl && dev->priv) + ret = (dev->dt->read_ctrl(dev->priv) & 0xef) | dev->enable_irq; + else + ret = 0xc0 | dev->ctrl | dev->enable_irq; + + return ret & 0xdf; +} + +static uint8_t +lpt_is_epp(const lpt_port_t *dev) +{ + return (dev->epp || ((dev->ecp) && ((dev->ecr & 0xe0) == 0x80))); +} + +static uint8_t +lpt_get_ctrl(const lpt_port_t *dev) +{ + uint8_t ret = lpt_get_ctrl_raw(dev); + + if (!dev->ecp && !dev->epp) + ret |= 0x20; + + return ret; +} + +static void +lpt_write_fifo(lpt_port_t *dev, const uint8_t val, const uint8_t tag) +{ + if (!fifo_get_full(dev->fifo)) { + fifo_write_evt_tagged(tag, val, dev->fifo); + + if (!timer_is_enabled(&dev->fifo_out_timer)) + timer_set_delay_u64(&dev->fifo_out_timer, (uint64_t) ((1000000.0 / 2500000.0) * (double) TIMER_USEC)); + } +} + +static void +lpt_ecp_update_irq(lpt_port_t *dev) +{ + if (!(dev->ecr & 0x04) && ((dev->fifo_stat | dev->dma_stat) & 0x04)) + picintlevel(1 << dev->irq, &dev->irq_state); + else + picintclevel(1 << dev->irq, &dev->irq_state); +} + +static void +lpt_autofeed(lpt_port_t *dev, const uint8_t val) +{ + if (dev->dt && dev->dt->autofeed && dev->priv) + dev->dt->autofeed(val, dev->priv); + + dev->autofeed = val; +} + +static void +lpt_strobe(lpt_port_t *dev, const uint8_t val) +{ + if (dev->dt && dev->dt->strobe && dev->priv) + dev->dt->strobe(dev->strobe, val, dev->priv); + + dev->strobe = val; +} + +static void +lpt_fifo_out_callback(void *priv) +{ + lpt_port_t *dev = (lpt_port_t *) priv; + + switch (dev->state) { + default: + break; + + case LPT_STATE_READ_DMA: + ; + int ret = 0xff; + + if (dev->dma == 0xff) + ret = DMA_NODATA; + else + ret = dma_channel_read(dev->dma); + + lpt_log("DMA %02X: %08X\n", dev->dma, ret); + + if (ret != DMA_NODATA) { + fifo_write_evt_tagged(0x01, (uint8_t) (ret & 0xff), dev->fifo); + + if (ret & DMA_OVER) + /* Internal flag to indicate we have finished the DMA reads. */ + dev->dma_stat = 0x08; + } + + timer_advance_u64(&dev->fifo_out_timer, + (uint64_t) ((1000000.0 / 2500000.0) * (double) TIMER_USEC)); + + if (dev->dma_stat || fifo_get_full(dev->fifo)) + dev->state = LPT_STATE_WRITE_FIFO; + break; + + case LPT_STATE_WRITE_FIFO: + if (!fifo_get_empty(dev->fifo)) { + uint8_t tag = 0x00; + const uint8_t val = fifo_read_evt_tagged(&tag, dev->fifo); + + lpt_log("FIFO: %02X, TAG = %02X\n", val, tag); + + /* We do not currently support sending commands. */ + if (tag == 0x01) { + if (dev->dt && dev->dt->write_data && dev->priv) + dev->dt->write_data(val, dev->priv); + + lpt_strobe(dev, 1); + lpt_strobe(dev, 0); + } + } + + if (dev->ecr & 0x08) { + if (fifo_get_empty(dev->fifo)) { + if (dev->dma_stat) { + /* Now actually set the external flag. */ + dev->dma_stat = 0x04; + dev->state = LPT_STATE_IDLE; + lpt_ecp_update_irq(dev); + lpt_autofeed(dev, 0); + } else { + dev->state = LPT_STATE_READ_DMA; + + timer_advance_u64(&dev->fifo_out_timer, + (uint64_t) ((1000000.0 / 2500000.0) * (double) TIMER_USEC)); + } + } else + timer_advance_u64(&dev->fifo_out_timer, + (uint64_t) ((1000000.0 / 2500000.0) * (double) TIMER_USEC)); + } else if (!fifo_get_empty(dev->fifo)) + timer_advance_u64(&dev->fifo_out_timer, + (uint64_t) ((1000000.0 / 2500000.0) * (double) TIMER_USEC)); + else + lpt_autofeed(dev, 0); + break; + } +} + +void +lpt_write(const uint16_t port, const uint8_t val, void *priv) +{ + lpt_port_t *dev = (lpt_port_t *) priv; + uint16_t mask = 0x0407; + + lpt_log("[W] %04X = %02X\n", port, val); + + /* This is needed so the parallel port at 3BC works. */ + if (dev->addr & 0x0004) + mask = 0x0403; + + switch (port & mask) { + case 0x0000: + if (dev->ecp) { + if ((dev->ecr & 0xe0) == 0x60) + /* AFIFO */ + lpt_write_fifo(dev, val, 0x00); + else if (!(dev->ecr & 0xc0) && (!(dev->ecr & 0x20) || !(lpt_get_ctrl_raw(dev) & 0x20)) && + dev->dt && dev->dt->write_data && dev->priv) + /* DATAR */ + dev->dt->write_data(val, dev->priv); + dev->dat = val; + } else { + /* DTR */ + if ((!dev->ext || !(lpt_get_ctrl_raw(dev) & 0x20)) && dev->dt && + dev->dt->write_data && dev->priv) + dev->dt->write_data(val, dev->priv); + dev->dat = val; + } + break; + + case 0x0001: + break; + + case 0x0002: + if (dev->dt && dev->dt->write_ctrl && dev->priv) { + if (dev->ecp) + dev->dt->write_ctrl((val & 0xfc) | dev->autofeed | dev->strobe, dev->priv); + else + dev->dt->write_ctrl(val, dev->priv); + } + dev->ctrl = val; + dev->enable_irq = val & 0x10; + if (!(val & 0x10) && (dev->irq != 0xff)) + picintc(1 << dev->irq); + dev->irq_state = 0; + break; + + case 0x0003: + if (lpt_is_epp(dev)) { + if (dev->dt && dev->dt->epp_write_data && dev->priv) + dev->dt->epp_write_data(1, val, dev->priv); + } + break; + + case 0x0004 ... 0x0007: + if (lpt_is_epp(dev)) { + if (dev->dt && dev->dt->epp_write_data && dev->priv) + dev->dt->epp_write_data(0, val, dev->priv); + } + break; + + case 0x0400: case 0x0404: + switch (dev->ecr >> 5) { + default: + break; + case 2: + lpt_write_fifo(dev, val, 0x01); + break; + case 3: + if (!(lpt_get_ctrl_raw(dev) & 0x20)) + lpt_write_fifo(dev, val, 0x01); + break; + case 6: + /* TFIFO */ + if (!fifo_get_full(dev->fifo)) + fifo_write_evt(val, dev->fifo); + break; + } + break; + + case 0x0402: case 0x0406: + if (!(val & 0x0c)) + lpt_autofeed(dev, 0x00); + else + lpt_autofeed(dev, 0x02); + + if ((dev->ecr & 0x04) && !(val & 0x04)) { + dev->dma_stat = 0x00; + fifo_reset(dev->fifo); + if (val & 0x08) { + dev->state = LPT_STATE_READ_DMA; + dev->fifo_stat = 0x00; + if (!timer_is_enabled(&dev->fifo_out_timer)) + timer_set_delay_u64(&dev->fifo_out_timer, (uint64_t) ((1000000.0 / 2500000.0) * (double) TIMER_USEC)); + } else { + dev->state = LPT_STATE_WRITE_FIFO; + if (lpt_get_ctrl_raw(dev) & 0x20) + dev->fifo_stat = fifo_get_ready(dev->fifo) ? 0x04 : 0x00; + else + dev->fifo_stat = fifo_get_ready(dev->fifo) ? 0x00 : 0x04; + } + } else if ((val & 0x04) && !(dev->ecr & 0x04)) { + if (timer_is_enabled(&dev->fifo_out_timer)) + timer_disable(&dev->fifo_out_timer); + + dev->state = LPT_STATE_IDLE; + } + dev->ecr = val; + lpt_ecp_update_irq(dev); + break; + + default: + break; + } +} + +static void +lpt_fifo_d_ready_evt(void *priv) +{ + lpt_port_t *dev = (lpt_port_t *) priv; + + if (!(dev->ecr & 0x08)) { + if (lpt_get_ctrl_raw(dev) & 0x20) + dev->fifo_stat = fifo_get_ready(dev->fifo) ? 0x04 : 0x00; + else + dev->fifo_stat = fifo_get_ready(dev->fifo) ? 0x00 : 0x04; + } + + lpt_ecp_update_irq(dev); +} + +void +lpt_write_to_fifo(void *priv, const uint8_t val) +{ + lpt_port_t *dev = (lpt_port_t *) priv; + + if (dev->ecp) { + if (((dev->ecr & 0xe0) == 0x20) && (lpt_get_ctrl_raw(dev) & 0x20)) + dev->dat = val; + else if (((dev->ecr & 0xe0) == 0x60) && (lpt_get_ctrl_raw(dev) & 0x20) && + !fifo_get_full(dev->fifo)) + fifo_write_evt_tagged(0x01, val, dev->fifo); + + if (((dev->ecr & 0x0c) == 0x08) && (dev->dma != 0xff)) { + const int ret = dma_channel_write(dev->dma, val); + + if (ret & DMA_OVER) + dev->dma_stat |= 0x04; + } + } else { + if (dev->ext && (lpt_get_ctrl_raw(dev) & 0x20)) + dev->dat = val; + } +} + +void +lpt_write_to_dat(void *priv, const uint8_t val) +{ + lpt_port_t *dev = (lpt_port_t *) priv; + + dev->dat = val; +} + +static uint8_t +lpt_read_fifo(const lpt_port_t *dev) +{ + uint8_t ret = 0xff; + + if (!fifo_get_empty(dev->fifo)) + ret = fifo_read(dev->fifo); + + return ret; +} + +uint8_t +lpt_read_status(const int port) +{ + lpt_port_t *dev = &lpt_ports[port]; + uint8_t low_bits = 0x07; + uint8_t ret; + + if (dev->ext) { + low_bits = 0x03 | (dev->irq_state ? 0x00 : 0x04); + if (dev->irq != 0xff) + picintclevel(1 << dev->irq, &dev->irq_state); + dev->irq_state = 0; + } + if (dev->epp || dev->ecp) { + low_bits = lpt_is_epp(dev) ? 0x02 : 0x03; + if (lpt_get_ctrl_raw(dev) & 0x10) + low_bits |= (dev->irq_state ? 0x00 : 0x04); + else + low_bits |= 0x04; + } + + if (dev->dt && dev->dt->read_status && dev->priv) + ret = (dev->dt->read_status(dev->priv) & 0xf8) | low_bits; + else + ret = 0xd8 | low_bits; + + return ret; +} + +uint8_t +lpt_read(const uint16_t port, void *priv) +{ + const lpt_port_t *dev = (lpt_port_t *) priv; + uint16_t mask = 0x0407; + uint8_t ret = 0xff; + + /* This is needed so the parallel port at 3BC works. */ + if (dev->addr & 0x0004) + mask = 0x0403; + + switch (port & mask) { + case 0x0000: + if (dev->ecp) { + if (!(dev->ecr & 0xc0)) + ret = dev->dat; + } else { + /* DTR */ + ret = dev->dat; + } + break; + + case 0x0001: + ret = lpt_read_status(dev->id); + break; + + case 0x0002: + ret = lpt_get_ctrl(dev); + if (dev->ecp) + ret = (ret & 0xfc) | (dev->ctrl & 0x03); + break; + + case 0x0003: + if (lpt_is_epp(dev)) { + if (dev->dt && dev->dt->epp_request_read && dev->priv) + dev->dt->epp_request_read(1, dev->priv); + ret = dev->dat; + } + break; + + case 0x0004 ... 0x0007: + if (lpt_is_epp(dev)) { + if (dev->dt && dev->dt->epp_request_read && dev->priv) + dev->dt->epp_request_read(0, dev->priv); + ret = dev->dat; + } + break; + + case 0x0400: case 0x0404: + switch (dev->ecr >> 5) { + default: + break; + case 3: + if (lpt_get_ctrl_raw(dev) & 0x20) + ret = lpt_read_fifo(dev); + break; + case 6: + /* TFIFO */ + if (!fifo_get_empty(dev->fifo)) + ret = fifo_read_evt(dev->fifo); + break; + case 7: + /* CNFGA */ + ret = 0x14; + break; + } + break; + + case 0x0401: case 0x0405: + if ((dev->ecr & 0xe0) == 0xe0) { + /* CNFGB */ + ret = 0x08; + ret |= (dev->irq_state ? 0x40 : 0x00); + ret |= ((dev->irq == 0x05) ? 0x30 : 0x00); + if ((dev->dma >= 1) && (dev->dma <= 3)) + ret |= dev->dma; + } + break; + + case 0x0402: case 0x0406: + ret = dev->ecr | dev->fifo_stat | (dev->dma_stat & 0x04); + ret |= (fifo_get_full(dev->fifo) ? 0x02 : 0x00); + ret |= (fifo_get_empty(dev->fifo) ? 0x01 : 0x00); + break; + + default: + break; + } + + lpt_log("[R] %04X = %02X\n", port, ret); + + return ret; +} + +uint8_t +lpt_read_port(const int port, const uint16_t reg) +{ + lpt_port_t *dev = &(lpt_ports[port]); + + return lpt_read(reg, dev); +} + +void +lpt_irq(void *priv, const int raise) +{ + lpt_port_t *dev = (lpt_port_t *) priv; + + if (dev->enable_irq) { + if (dev->irq != 0xff) { + if (dev->ext) { + if (raise) + picintlevel(1 << dev->irq, &dev->irq_state); + else + picintclevel(1 << dev->irq, &dev->irq_state); + } else { + if (raise) + picint(1 << dev->irq); + else + picintc(1 << dev->irq); + } + } + + if (!dev->ext || (dev->irq == 0xff)) + dev->irq_state = raise; + } else { + if (dev->irq != 0xff) { + if (dev->ext) + picintclevel(1 << dev->irq, &dev->irq_state); + else + picintc(1 << dev->irq); + } + + dev->irq_state = 0; + } +} + +void +lpt_set_ext(const int port, const uint8_t ext) +{ + if (lpt_ports[port].enabled) + lpt_ports[port].ext = ext; +} + +void +lpt_set_ecp(const int port, const uint8_t ecp) +{ + if (lpt_ports[port].enabled) { + const uint16_t addr = lpt_ports[port].addr; + lpt_port_setup(port, 0xfff); + lpt_ports[port].ecp = ecp; + lpt_port_setup(port, addr); + } +} + +void +lpt_set_epp(const int port, const uint8_t epp) +{ + if (lpt_ports[port].enabled) { + const uint16_t addr = lpt_ports[port].addr; + lpt_port_setup(port, 0xfff); + lpt_ports[port].epp = epp; + lpt_port_setup(port, addr); + } +} + +void +lpt_set_lv2(const int port, const uint8_t lv2) +{ + if (lpt_ports[port].enabled) { + const uint16_t addr = lpt_ports[port].addr; + lpt_port_setup(port, 0xfff); + lpt_ports[port].lv2 = lv2; + lpt_port_setup(port, addr); + } +} + +void +lpt_close(void) +{ + for (uint8_t i = 0; i < PARALLEL_MAX; i++) { + if (lpt_ports[i].enabled) { + fifo_close(lpt_ports[i].fifo); + lpt_ports[i].fifo = NULL; + + timer_disable(&lpt_ports[i].fifo_out_timer); + } + } +} + +void +lpt_port_zero(lpt_port_t *dev) +{ + lpt_port_t temp = { 0 }; + + temp.irq = dev->irq; + temp.id = dev->id; + temp.device = dev->device; + temp.dt = dev->dt; + temp.priv = dev->priv; + temp.enabled = dev->enabled; + temp.fifo = dev->fifo; + temp.fifo_out_timer = dev->fifo_out_timer; + + if (dev->enabled) + lpt_port_remove(dev->id); + + memset(dev, 0x00, sizeof(lpt_port_t)); + + dev->addr = 0xffff; + dev->irq = temp.irq; + dev->id = temp.id; + dev->device = temp.device; + dev->dt = temp.dt; + dev->priv = temp.priv; + dev->enabled = temp.enabled; + dev->fifo = temp.fifo; + dev->fifo_out_timer = temp.fifo_out_timer; + + if (machine_has_bus(machine, MACHINE_BUS_MCA)) + dev->ext = 1; +} + +void +lpt_reset(void) +{ + for (uint8_t i = 0; i < PARALLEL_MAX; i++) { + if (lpt_ports[i].enabled) + if (timer_is_enabled(&lpt_ports[i].fifo_out_timer)) + timer_disable(&lpt_ports[i].fifo_out_timer); + + lpt_port_zero(&(lpt_ports[i])); + + if (lpt_ports[i].enabled) { + if (lpt_ports[i].irq_state) { + if (lpt_ports[i].irq == 0xff) + lpt_ports[i].irq_state = 0x00; + else { + picintclevel(lpt_ports[i].irq, &lpt_ports[i].irq_state); + picintc(lpt_ports[i].irq); + } + } + + lpt_ports[i].enable_irq = 0x00; + lpt_ports[i].ext = !!(machine_has_bus(machine, MACHINE_BUS_MCA)); + lpt_ports[i].epp = 0; + lpt_ports[i].ecp = 0; + lpt_ports[i].ecr = 0x15; + lpt_ports[i].dat = 0xff; + lpt_ports[i].fifo_stat = 0x00; + lpt_ports[i].dma_stat = 0x00; + } + } +} + +void +lpt_init(void) +{ + const uint16_t default_ports[PARALLEL_MAX] = { LPT1_ADDR, LPT2_ADDR, LPT_MDA_ADDR, LPT4_ADDR }; + const uint8_t default_irqs[PARALLEL_MAX] = { LPT1_IRQ, LPT2_IRQ, LPT_MDA_IRQ, LPT4_IRQ }; + + for (uint8_t i = 0; i < PARALLEL_MAX; i++) { + lpt_ports[i].id = i; + lpt_ports[i].dt = NULL; + lpt_ports[i].priv = NULL; + lpt_ports[i].fifo = NULL; + memset(&lpt_ports[i].fifo_out_timer, 0x00, sizeof(pc_timer_t)); + + lpt_port_zero(&(lpt_ports[i])); + + lpt_ports[i].addr = 0xffff; + lpt_ports[i].irq = 0xff; + lpt_ports[i].dma = 0xff; + lpt_ports[i].enable_irq = 0x00; + lpt_ports[i].ext = 0; + lpt_ports[i].epp = 0; + lpt_ports[i].ecp = 0; + lpt_ports[i].ecr = 0x15; + + if (lpt_ports[i].enabled) { + lpt_port_setup(i, default_ports[i]); + lpt_port_irq(i, default_irqs[i]); + + lpt_ports[i].fifo = fifo16_init(); + + fifo_set_trigger_len(lpt_ports[i].fifo, 8); + + fifo_set_d_ready_evt(lpt_ports[i].fifo, lpt_fifo_d_ready_evt); + fifo_set_priv(lpt_ports[i].fifo, &lpt_ports[i]); + + timer_add(&lpt_ports[i].fifo_out_timer, lpt_fifo_out_callback, &lpt_ports[i], 0); + } + } +} + +void +lpt_port_setup(const int i, const uint16_t port) +{ + if (lpt_ports[i].enabled) { + if (lpt_ports[i].addr != 0xffff) { + io_removehandler(lpt_ports[i].addr, 0x0007, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[i]); + io_removehandler(lpt_ports[i].addr + 0x0400, 0x0007, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[i]); + } + if (port != 0xffff) { + lpt_log("Set handler: %04X-%04X\n", port, port + 0x0003); + io_sethandler(port, 0x0003, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[i]); + if (lpt_ports[i].epp) + io_sethandler(lpt_ports[i].addr + 0x0003, 0x0003, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[i]); + if (lpt_ports[i].ecp || lpt_ports[i].lv2) { + io_sethandler(port + 0x0400, 0x0003, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[i]); + if (lpt_ports[i].epp) + io_sethandler(lpt_ports[i].addr + 0x0403, 0x0003, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[i]); + } + } + lpt_ports[i].addr = port; + } else + lpt_ports[i].addr = 0xffff; +} + +void +lpt_port_irq(const int i, const uint8_t irq) +{ + if (lpt_ports[i].enabled) + lpt_ports[i].irq = irq; + else + lpt_ports[i].irq = 0xff; + + lpt_log("Port %i IRQ = %02X\n", i, irq); +} + +void +lpt_port_dma(const int i, const uint8_t dma) +{ + if (lpt_ports[i].enabled) + lpt_ports[i].dma = dma; + else + lpt_ports[i].dma = 0xff; + + lpt_log("Port %i DMA = %02X\n", i, dma); +} + +void +lpt_port_remove(const int i) +{ + if (lpt_ports[i].enabled && (lpt_ports[i].addr != 0xffff)) { + io_removehandler(lpt_ports[i].addr, 0x0007, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[i]); + io_removehandler(lpt_ports[i].addr + 0x0400, 0x0007, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[i]); + + lpt_ports[i].addr = 0xffff; + } +} + +void +lpt1_remove_ams(void) +{ + if (lpt_ports[0].enabled) + io_removehandler(lpt_ports[0].addr + 1, 0x0002, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[0]); +} diff --git a/src/device/serial_passthrough.c b/src/device/serial_passthrough.c index 25db29096..426bfbc7b 100644 --- a/src/device/serial_passthrough.c +++ b/src/device/serial_passthrough.c @@ -13,7 +13,7 @@ * Jasmine Iwanek * * Copyright 2021 Andreas J. Reichel. - * Copyright 2021-2022 Jasmine Iwanek. + * Copyright 2021-2025 Jasmine Iwanek. */ #include @@ -222,10 +222,15 @@ serial_passthrough_dev_init(const device_t *info) } const char *serpt_mode_names[SERPT_MODES_MAX] = { - [SERPT_MODE_VCON] = "vcon", - [SERPT_MODE_TCPSRV] = "tcpsrv", - [SERPT_MODE_TCPCLNT] = "tcpclnt", - [SERPT_MODE_HOSTSER] = "hostser", +#ifdef _WIN32 + [SERPT_MODE_NPIPE_SRV] = "npipesrv", + [SERPT_MODE_NPIPE_CLNT] = "npipeclnt", +#else + [SERPT_MODE_VCON] = "vcon", +#endif + [SERPT_MODE_TCP_SRV] = "tcpsrv", + [SERPT_MODE_TCP_CLNT] = "tcpclnt", + [SERPT_MODE_HOSTSER] = "hostser", }; // clang-format off @@ -240,19 +245,17 @@ static const device_config_t serial_passthrough_config[] = { .spinner = { 0 }, .selection = { #ifdef _WIN32 - { .description = "Named Pipe (Server)", .value = SERPT_MODE_VCON }, -#if 0 /* TODO */ - { .description = "Named Pipe (Client)", .value = SERPT_MODE_VCON }, -#endif + { .description = "Named Pipe (Server)", .value = SERPT_MODE_NPIPE_SRV }, + { .description = "Named Pipe (Client)", .value = SERPT_MODE_NPIPE_CLNT }, #else /* _WIN32 */ - { .description = "Pseudo Terminal/Virtual Console", .value = SERPT_MODE_VCON }, + { .description = "Pseudo Terminal/Virtual Console", .value = SERPT_MODE_VCON }, #endif /* _WIN32 */ #if 0 /* TODO */ - { .description = "TCP Server", .value = SERPT_MODE_TCPSRV }, - { .description = "TCP Client", .value = SERPT_MODE_TCPCLNT }, + { .description = "TCP Server", .value = SERPT_MODE_TCP_SRV }, + { .description = "TCP Client", .value = SERPT_MODE_TCP_CLNT }, #endif - { .description = "Host Serial Passthrough", .value = SERPT_MODE_HOSTSER }, - { .description = "" } + { .description = "Host Serial Passthrough", .value = SERPT_MODE_HOSTSER }, + { .description = "" } }, .bios = { { 0 } } }, diff --git a/src/disk/hdc.c b/src/disk/hdc.c index 582c33428..ecd609476 100644 --- a/src/disk/hdc.c +++ b/src/disk/hdc.c @@ -56,35 +56,40 @@ static const struct { // clang-format off { &device_none }, { &device_internal }, - { &st506_xt_xebec_device }, - { &st506_xt_wdxt_gen_device }, + /* ISA */ + { &xtide_acculogic_device }, { &st506_xt_dtc5150x_device }, + { &st506_xt_xebec_device }, + { &xtide_device }, { &st506_xt_st11_m_device }, - { &st506_xt_wd1002a_wx1_device }, - { &st506_xt_wd1004a_wx1_device }, - { &st506_at_wd1003_device }, { &st506_xt_st11_r_device }, + { &st506_xt_victor_v86p_device }, { &st506_xt_wd1002a_27x_device }, + { &st506_xt_wd1002a_wx1_device }, { &st506_xt_wd1004_27x_device }, { &st506_xt_wd1004a_27x_device }, - { &st506_xt_victor_v86p_device }, - { &esdi_at_wd1007vse1_device }, + { &st506_xt_wd1004a_wx1_device }, + { &xta_wdxt150_device }, + { &st506_xt_wdxt_gen_device }, + /* ISA16 */ { &ide_isa_device }, { &ide_isa_2ch_device }, { &xtide_at_device }, { &xtide_at_2ch_device }, { &xtide_at_ps2_device }, { &xtide_at_ps2_2ch_device }, - { &xta_wdxt150_device }, - { &xtide_acculogic_device }, - { &xtide_device }, + { &st506_at_wd1003_device }, + { &esdi_at_wd1007vse1_device }, + /* MCA */ { &esdi_ps2_device }, { &esdi_integrated_device }, - { &ide_pci_device }, - { &ide_pci_2ch_device }, + { &mcide_device }, + /* VLB */ { &ide_vlb_device }, { &ide_vlb_2ch_device }, - { &mcide_device }, + /* PCI */ + { &ide_pci_device }, + { &ide_pci_2ch_device }, { NULL } // clang-format on }; diff --git a/src/disk/hdc_xtide.c b/src/disk/hdc_xtide.c index 1c8e2c8da..9a122f595 100644 --- a/src/disk/hdc_xtide.c +++ b/src/disk/hdc_xtide.c @@ -154,7 +154,7 @@ xtide_init(const device_t *info) sprintf(xtide->nvr_path, "xtide_%i.nvr", device_get_instance()); FILE *fp = nvr_fopen(xtide->nvr_path, "rb"); if (fp != NULL) { - fread(xtide->bios_rom.rom, 1, 0x2000, fp); + (void) !fread(xtide->bios_rom.rom, 1, 0x2000, fp); fclose(fp); } } diff --git a/src/disk/hdd_image.c b/src/disk/hdd_image.c index 09f48ad50..75c27f4d1 100644 --- a/src/disk/hdd_image.c +++ b/src/disk/hdd_image.c @@ -56,7 +56,9 @@ typedef struct hdd_image_t { hdd_image_t hdd_images[HDD_NUM]; static char empty_sector[512]; +#ifndef __unix__ static char *empty_sector_1mb; +#endif #ifdef ENABLE_HDD_IMAGE_LOG int hdd_image_do_log = ENABLE_HDD_IMAGE_LOG; diff --git a/src/floppy/fdc.c b/src/floppy/fdc.c index 186d4c894..523ae6948 100644 --- a/src/floppy/fdc.c +++ b/src/floppy/fdc.c @@ -191,7 +191,7 @@ fdc_ctrl_reset(void *priv) fdc->step = 0; fdc->power_down = 0; - if (!fdc->lock) { + if (!fdc->lock && !fdc->fifointest) { fdc->fifo = 0; fdc->tfifo = 1; @@ -808,6 +808,9 @@ fdc_write(uint16_t addr, uint8_t val, void *priv) fdc->tfifo = 1; fdc->fifointest = 0; } + fifo_reset(fdc->fifo_p); + fifo_set_len(fdc->fifo_p, fdc->tfifo + 1); + fifo_set_trigger_len(fdc->fifo_p, fdc->tfifo + 1); } return; case 4: /* DSR */ diff --git a/src/include/86box/86box.h b/src/include/86box/86box.h index 8bf303961..e572d670b 100644 --- a/src/include/86box/86box.h +++ b/src/include/86box/86box.h @@ -177,6 +177,8 @@ extern char usr_path[1024]; /* path (dir) of user data */ extern char cfg_path[1024]; /* full path of config file */ extern int open_dir_usr_path; /* default file open dialog directory of usr_path */ extern char uuid[MAX_UUID_LEN]; /* UUID or machine identifier */ +extern char vmm_path[1024]; /* VM Manager path to scan (temporary) */ +extern int vmm_enabled; #ifndef USE_NEW_DYNAREC extern FILE *stdlog; /* file to log output to */ #endif diff --git a/src/include/86box/chipset.h b/src/include/86box/chipset.h index 1b5684414..7ee8182ea 100644 --- a/src/include/86box/chipset.h +++ b/src/include/86box/chipset.h @@ -18,6 +18,7 @@ #define EMU_CHIPSET_H /* ACC */ +extern const device_t acc2036_device; extern const device_t acc2168_device; /* ALi */ @@ -123,7 +124,9 @@ extern const device_t opti381_device; extern const device_t opti391_device; extern const device_t opti481_device; extern const device_t opti493_device; -extern const device_t opti495_device; +extern const device_t opti495slc_device; +extern const device_t opti495sx_device; +extern const device_t opti498_device; extern const device_t opti499_device; extern const device_t opti601_device; extern const device_t opti602_device; diff --git a/src/include/86box/flash.h b/src/include/86box/flash.h index 6f0e1ff15..bd9b7e505 100644 --- a/src/include/86box/flash.h +++ b/src/include/86box/flash.h @@ -20,6 +20,7 @@ #ifndef EMU_FLASH_H #define EMU_FLASH_H +extern const device_t amd_am28f010_flash_device; extern const device_t catalyst_flash_device; extern const device_t intel_flash_bxt_ami_device; diff --git a/src/include/86box/keyboard.h b/src/include/86box/keyboard.h index b9bac0821..62938fae4 100644 --- a/src/include/86box/keyboard.h +++ b/src/include/86box/keyboard.h @@ -228,6 +228,7 @@ extern const device_t keyboard_xt_lxt3_device; extern const device_t keyboard_xt_olivetti_device; extern const device_t keyboard_xt_zenith_device; extern const device_t keyboard_xt_hyundai_device; +extern const device_t keyboard_xt_fe2010_device; extern const device_t keyboard_xtclone_device; extern const device_t keyboard_at_device; extern const device_t keyboard_at_ami_device; diff --git a/src/include/86box/lpt.h b/src/include/86box/lpt.h index 674d6340f..c13d70291 100644 --- a/src/include/86box/lpt.h +++ b/src/include/86box/lpt.h @@ -25,14 +25,24 @@ typedef struct lpt_device_t { void (*close)(void *priv); void (*write_data)(uint8_t val, void *priv); void (*write_ctrl)(uint8_t val, void *priv); - uint8_t (*read_data)(void *priv); + void (*autofeed)(uint8_t val,void *priv); + void (*strobe)(uint8_t old, uint8_t val,void *priv); uint8_t (*read_status)(void *priv); uint8_t (*read_ctrl)(void *priv); + void (*epp_write_data)(uint8_t is_addr, uint8_t val, void *priv); + void (*epp_request_read)(uint8_t is_addr, void *priv); } lpt_device_t; +extern void lpt_set_ext(int port, uint8_t ext); +extern void lpt_set_ecp(int port, uint8_t ecp); +extern void lpt_set_epp(int port, uint8_t epp); +extern void lpt_set_lv2(int port, uint8_t lv2); +extern void lpt_reset(void); +extern void lpt_close(void); extern void lpt_init(void); extern void lpt_port_setup(int i, uint16_t port); extern void lpt_port_irq(int i, uint8_t irq); +extern void lpt_port_dma(int i, uint8_t dma); extern void lpt_port_remove(int i); extern void lpt1_remove_ams(void); @@ -68,31 +78,62 @@ void lpt_devices_close(void); typedef struct lpt_port_t { uint8_t enabled; uint8_t irq; + uint8_t irq_state; + uint8_t dma; uint8_t dat; uint8_t ctrl; + uint8_t ext; + uint8_t epp; + uint8_t ecp; + uint8_t ecr; + uint8_t in_dat; + uint8_t fifo_stat; + uint8_t dma_stat; + uint8_t state; + uint8_t autofeed; + uint8_t strobe; + uint8_t lv2; + uint8_t pad[7]; uint16_t addr; - uint16_t pad0; + uint16_t id; + uint16_t pad0[2]; int device; int enable_irq; lpt_device_t *dt; +#ifdef FIFO_H + fifo16_t *fifo; +#else + void *fifo; +#endif void *priv; + + pc_timer_t fifo_out_timer; } lpt_port_t; +typedef enum { + LPT_STATE_IDLE = 0, + LPT_STATE_READ_DMA, + LPT_STATE_WRITE_FIFO +} lpt_state_t; + extern lpt_port_t lpt_ports[PARALLEL_MAX]; -extern void lpt_write(uint16_t port, uint8_t val, void *priv); -extern uint8_t lpt_read(uint16_t port, void *priv); +extern void lpt_write(uint16_t port, uint8_t val, void *priv); -extern uint8_t lpt_read_port(int port, uint16_t reg); +extern void lpt_write_to_fifo(void *priv, uint8_t val); -extern uint8_t lpt_read_status(int port); -extern void lpt_irq(void *priv, int raise); +extern uint8_t lpt_read(uint16_t port, void *priv); + +extern uint8_t lpt_read_port(int port, uint16_t reg); + +extern uint8_t lpt_read_status(int port); +extern void lpt_irq(void *priv, int raise); + +extern int lpt_device_get_from_internal_name(const char *s); extern const char *lpt_device_get_name(int id); extern const char *lpt_device_get_internal_name(int id); -extern int lpt_device_get_from_internal_name(char *s); - extern const lpt_device_t lpt_dac_device; extern const lpt_device_t lpt_dac_stereo_device; diff --git a/src/include/86box/m_pcjr.h b/src/include/86box/m_pcjr.h index 7a137fb03..c6cb33588 100644 --- a/src/include/86box/m_pcjr.h +++ b/src/include/86box/m_pcjr.h @@ -17,8 +17,10 @@ #pragma once -#define PCJR_RGB 0 -#define PCJR_COMPOSITE 1 +#define PCJR_RGB 0 +#define PCJR_COMPOSITE 1 +#define PCJR_RGB_NO_BROWN 4 +#define PCJR_RGB_IBM_5153 5 typedef struct pcjr_s { diff --git a/src/include/86box/machine.h b/src/include/86box/machine.h index 7aec5db4f..93080538b 100644 --- a/src/include/86box/machine.h +++ b/src/include/86box/machine.h @@ -197,6 +197,7 @@ enum { MACHINE_CHIPSET_GC100A, MACHINE_CHIPSET_GC103, MACHINE_CHIPSET_HT18, + MACHINE_CHIPSET_ACC_2036, MACHINE_CHIPSET_ACC_2168, MACHINE_CHIPSET_ALI_M1217, MACHINE_CHIPSET_ALI_M6117, @@ -240,7 +241,9 @@ enum { MACHINE_CHIPSET_OPTI_391, MACHINE_CHIPSET_OPTI_481, MACHINE_CHIPSET_OPTI_493, - MACHINE_CHIPSET_OPTI_495, + MACHINE_CHIPSET_OPTI_495SLC, + MACHINE_CHIPSET_OPTI_495SX, + MACHINE_CHIPSET_OPTI_498, MACHINE_CHIPSET_OPTI_499, MACHINE_CHIPSET_OPTI_895_802G, MACHINE_CHIPSET_OPTI_547_597, @@ -456,6 +459,7 @@ extern int machine_at_px286_init(const machine_t *); extern int machine_at_quadt286_init(const machine_t *); extern int machine_at_mr286_init(const machine_t *); +extern int machine_at_pbl300sx_init(const machine_t *); extern int machine_at_neat_init(const machine_t *); extern int machine_at_neat_ami_init(const machine_t *); extern int machine_at_ataripc4_init(const machine_t *); @@ -465,6 +469,7 @@ extern int machine_at_quadt386sx_init(const machine_t *); extern int machine_at_award286_init(const machine_t *); extern int machine_at_gdc212m_init(const machine_t *); extern int machine_at_gw286ct_init(const machine_t *); +extern int machine_at_drsm35286_init(const machine_t *); extern int machine_at_senor_scat286_init(const machine_t *); extern int machine_at_super286c_init(const machine_t *); extern int machine_at_super286tr_init(const machine_t *); @@ -475,6 +480,7 @@ extern int machine_at_kmxc02_init(const machine_t *); extern int machine_at_deskmaster286_init(const machine_t *); extern int machine_at_dells200_init(const machine_t *); +extern int machine_at_at122_init(const machine_t *); extern int machine_at_tuliptc7_init(const machine_t *); extern int machine_at_pc8_init(const machine_t *); @@ -512,6 +518,7 @@ extern int machine_at_dataexpert386wb_init(const machine_t *); extern int machine_at_isa486c_init(const machine_t *); extern int machine_at_genoa486_init(const machine_t *); extern int machine_at_ga486l_init(const machine_t *); +extern int machine_at_cobalt_init(const machine_t *); extern int machine_at_cougar_init(const machine_t *); extern int machine_at_acc386_init(const machine_t *); @@ -544,6 +551,7 @@ extern int machine_at_winbios1429_init(const machine_t *); extern int machine_at_opti495_init(const machine_t *); extern int machine_at_opti495_ami_init(const machine_t *); extern int machine_at_opti495_mr_init(const machine_t *); +extern int machine_at_c747_init(const machine_t *); extern int machine_at_exp4349_init(const machine_t *); extern int machine_at_vect486vl_init(const machine_t *); @@ -564,6 +572,7 @@ extern int machine_at_dtk461_init(const machine_t *); extern int machine_at_sis401_init(const machine_t *); extern int machine_at_isa486_init(const machine_t *); extern int machine_at_av4_init(const machine_t *); +extern int machine_at_advantage40xxd_init(const machine_t *); extern int machine_at_valuepoint433_init(const machine_t *); extern int machine_at_vli486sv2g_init(const machine_t *); @@ -646,6 +655,7 @@ extern void machine_at_award_common_init(const machine_t *); extern void machine_at_sp4_common_init(const machine_t *model); +extern int machine_at_v12p_init(const machine_t *); extern int machine_at_excaliburpci_init(const machine_t *); extern int machine_at_p5mp3_init(const machine_t *); extern int machine_at_dellxp60_init(const machine_t *); @@ -973,6 +983,7 @@ extern int machine_xt_kaypropc_init(const machine_t *); extern int machine_xt_sansx16_init(const machine_t *); extern int machine_xt_bw230_init(const machine_t *); extern int machine_xt_pb8810_init(const machine_t *); +extern int machine_xt_tuliptc8_init(const machine_t *); extern int machine_xt_v20xt_init(const machine_t *); diff --git a/src/include/86box/mem.h b/src/include/86box/mem.h index 62cb493a5..53001b8db 100644 --- a/src/include/86box/mem.h +++ b/src/include/86box/mem.h @@ -265,12 +265,16 @@ extern uint32_t biosmask; extern uint32_t biosaddr; extern int readlookup[256]; +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) extern uintptr_t *readlookup2; +#endif extern uintptr_t old_rl2; extern uint8_t uncached; extern int readlnext; extern int writelookup[256]; +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) extern uintptr_t *writelookup2; +#endif extern int writelnext; extern uint32_t ram_mapped_addr[64]; extern uint8_t page_ff[4096]; @@ -288,7 +292,16 @@ extern mem_mapping_t bios_high_mapping; extern uint32_t mem_logical_addr; extern page_t *pages; +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) extern page_t **page_lookup; +#endif + +#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) +/* The lookup tables. */ +extern page_t *page_lookup[1048576]; +extern uintptr_t readlookup2[1048576]; +extern uintptr_t writelookup2[1048576]; +#endif extern uint32_t get_phys_virt; extern uint32_t get_phys_phys; @@ -457,6 +470,9 @@ extern void mem_a20_init(void); extern void mem_a20_recalc(void); extern void mem_init(void); +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) +extern void mem_free(void); +#endif extern void mem_close(void); extern void mem_zero(void); extern void mem_reset(void); diff --git a/src/include/86box/network.h b/src/include/86box/network.h index ef9f291ad..a0d1bc3cb 100644 --- a/src/include/86box/network.h +++ b/src/include/86box/network.h @@ -52,6 +52,7 @@ #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 */ +#define NET_TYPE_TAP 4 /* use a linux TAP device */ #define NET_MAX_FRAME 1518 /* Queue size must be a power of 2 */ @@ -126,6 +127,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_tap_drv; extern const netdrv_t net_null_drv; struct _netcard_t { @@ -155,10 +157,11 @@ typedef struct { int has_slirp; int has_pcap; int has_vde; + int has_tap; } network_devmap_t; -#define HAS_NOSLIRP_NET(x) (x.has_pcap || x.has_vde) +#define HAS_NOSLIRP_NET(x) (x.has_pcap || x.has_vde || x.has_tap) #ifdef __cplusplus extern "C" { diff --git a/src/include/86box/renderdefs.h b/src/include/86box/renderdefs.h new file mode 100644 index 000000000..36c3d9f74 --- /dev/null +++ b/src/include/86box/renderdefs.h @@ -0,0 +1,40 @@ +/* + * 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. + * + * definitions for renderers + * + * Authors: Jasmine Iwanek, + * + * Copyright 2025 Jasmine Iwanek. + */ +#ifndef EMU_RENDERDEFS_H +#define EMU_RENDERDEFS_H + +#define RENDERER_NAME_DEFAULT "default" +#define RENDERER_NAME_SYSTEM "system" +#define RENDERER_NAME_QT_SOFTWARE "qt_software" +#define RENDERER_NAME_QT_OPENGL "qt_opengl" +#define RENDERER_NAME_QT_OPENGLES "qt_opengles" +#define RENDERER_NAME_QT_OPENGL3 "qt_opengl3" +#define RENDERER_NAME_QT_VULKAN "qt_vulkan" +#define RENDERER_NAME_VNC "vnc" + +#define RENDERER_SOFTWARE 0 +#define RENDERER_OPENGL3 1 +#define RENDERER_VULKAN 2 +#define RENDERER_VNC 3 + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /*EMU_RENDERDEFS_H*/ diff --git a/src/include/86box/serial_passthrough.h b/src/include/86box/serial_passthrough.h index c5454194a..a5fa0013a 100644 --- a/src/include/86box/serial_passthrough.h +++ b/src/include/86box/serial_passthrough.h @@ -13,7 +13,7 @@ * Jasmine Iwanek * * Copyright 2021 Andreas J. Reichel. - * Copyright 2021-2022 Jasmine Iwanek. + * Copyright 2021-2025 Jasmine Iwanek. */ #ifndef SERIAL_PASSTHROUGH_H @@ -28,10 +28,15 @@ #include <86box/serial.h> enum serial_passthrough_mode { - SERPT_MODE_VCON, /*Named Pipe (Server) / Pseudo Terminal/Virtual Console */ - SERPT_MODE_TCPSRV, /* TCP Server (TODO) */ - SERPT_MODE_TCPCLNT, /* TCP Client (TODO) */ - SERPT_MODE_HOSTSER, /* Host Serial Passthrough */ +#ifdef _WIN32 + SERPT_MODE_NPIPE_SRV, /* Named Pipe (Server) */ + SERPT_MODE_NPIPE_CLNT, /* Named Pipe (Client) */ +#else + SERPT_MODE_VCON, /* Pseudo Terminal/Virtual Console */ +#endif + SERPT_MODE_TCP_SRV, /* TCP Server (TODO) */ + SERPT_MODE_TCP_CLNT, /* TCP Client (TODO) */ + SERPT_MODE_HOSTSER, /* Host Serial Passthrough */ SERPT_MODES_MAX, }; diff --git a/src/include/86box/sio.h b/src/include/86box/sio.h index 358cd8c9a..72878ff46 100644 --- a/src/include/86box/sio.h +++ b/src/include/86box/sio.h @@ -20,8 +20,6 @@ extern const device_t acc3221_device; /* Acer / ALi */ -extern const device_t ali5105_device; - extern const device_t ali5123_device; /* Chips & Technologies */ @@ -79,10 +77,13 @@ extern const device_t i82091aa_398_device; extern const device_t i82091aa_ide_pri_device; extern const device_t i82091aa_ide_device; -/* National Semiconductors */ -extern const device_t pc87310_device; -extern const device_t pc87310_ide_device; +/* National Semiconductors PC87310 / ALi M5105 */ +#define PC87310_IDE 0x0001 +#define PC87310_ALI 0x0002 +extern const device_t pc87310_device; + +/* National Semiconductors */ extern const device_t pc87306_device; extern const device_t pc87311_device; extern const device_t pc87311_ide_device; @@ -92,6 +93,7 @@ extern const device_t pc87332_398_ide_device; extern const device_t pc87332_398_ide_sec_device; extern const device_t pc87332_398_ide_fdcon_device; +/* National Semiconductors PC87307 / PC87309 */ #define PCX7307_PC87307 0x00c0 #define PCX7307_PC97307 0x00cf @@ -125,6 +127,10 @@ extern const device_t sio_detect_device; #endif /* USE_SIO_DETECT */ /* UMC */ +extern const device_t um82c862f_device; +extern const device_t um82c862f_ide_device; +extern const device_t um82c863f_device; +extern const device_t um82c863f_ide_device; extern const device_t um8663af_device; extern const device_t um8663af_ide_device; extern const device_t um8663af_sec_device; diff --git a/src/include/86box/snd_resid.h b/src/include/86box/snd_resid.h index c7e97ac0f..c6a616a3e 100644 --- a/src/include/86box/snd_resid.h +++ b/src/include/86box/snd_resid.h @@ -4,7 +4,7 @@ #ifdef __cplusplus extern "C" { #endif -void *sid_init(uint8_t type); +void *sid_init(uint8_t type, double range); void sid_close(void *priv); void sid_reset(void *priv); uint8_t sid_read(uint16_t addr, void *priv); diff --git a/src/include/86box/vid_8514a.h b/src/include/86box/vid_8514a.h index 9d19d916c..5aa8927e0 100644 --- a/src/include/86box/vid_8514a.h +++ b/src/include/86box/vid_8514a.h @@ -37,6 +37,13 @@ typedef enum { EXTENSIONS_MAX } ibm8514_extensions_t; +typedef enum { + VGA_MODE = 0, + IBM_MODE, + ATI_MODE, + MODE_MAX +} ibm8514_mode_t; + typedef struct hwcursor8514_t { int ena; int x; @@ -202,6 +209,7 @@ typedef struct ibm8514_t { int split; int h_disp; int h_total; + int h_sync_start; int h_sync_width; int h_disp_time; int rowoffset; @@ -260,6 +268,7 @@ typedef struct ibm8514_t { int ext_pitch; int ext_crt_pitch; ibm8514_extensions_t extensions; + ibm8514_mode_t mode; int onboard; int linear; uint32_t vram_amount; diff --git a/src/include/86box/vid_ati_mach8.h b/src/include/86box/vid_ati_mach8.h index e999c7087..ad5281ac3 100644 --- a/src/include/86box/vid_ati_mach8.h +++ b/src/include/86box/vid_ati_mach8.h @@ -18,6 +18,12 @@ #ifndef VIDEO_ATI_MACH8_H #define VIDEO_ATI_MACH8_H +typedef enum { + ATI_68875 = 0, + ATI_68860, + RAMDAC_MAX +} mach_ramdac_type; + typedef struct mach_t { ati_eeprom_t eeprom; svga_t svga; @@ -39,7 +45,7 @@ typedef struct mach_t { uint8_t irq_state; int index; - int ramdac_type; + mach_ramdac_type ramdac_type; int old_mode; uint16_t config1; diff --git a/src/include/86box/vid_svga.h b/src/include/86box/vid_svga.h index ad9170ad3..8a18f0865 100644 --- a/src/include/86box/vid_svga.h +++ b/src/include/86box/vid_svga.h @@ -136,6 +136,7 @@ typedef struct svga_t { int packed_4bpp; int ps_bit_bug; int ati_4color; + int vblankend; /*The three variables below allow us to implement memory maps like that seen on a 1MB Trio64 : 0MB-1MB - VRAM @@ -281,6 +282,10 @@ typedef struct svga_t { you should set this flag when entering that mode*/ int disable_blink; + /*Force special shifter bypass logic for 8-bpp lowres modes. + Needed if the screen is squished on certain S3 cards.*/ + int force_shifter_bypass; + /*Force CRTC to dword mode, regardless of CR14/CR17. Required for S3 enhanced mode*/ int force_dword_mode; @@ -404,15 +409,15 @@ uint32_t svga_lookup_lut_ram(svga_t* svga, uint32_t val); /* We need a way to add a device with a pointer to a parent device so it can attach itself to it, and possibly also a second ATi 68860 RAM DAC type that auto-sets SVGA render on RAM DAC render change. */ -extern void ati68860_ramdac_out(uint16_t addr, uint8_t val, void *priv, svga_t *svga); -extern uint8_t ati68860_ramdac_in(uint16_t addr, void *priv, svga_t *svga); +extern void ati68860_ramdac_out(uint16_t addr, uint8_t val, int is_8514, void *priv, svga_t *svga); +extern uint8_t ati68860_ramdac_in(uint16_t addr, int is_8514, void *priv, svga_t *svga); extern void ati68860_set_ramdac_type(void *priv, int type); extern void ati68860_ramdac_set_render(void *priv, svga_t *svga); extern void ati68860_ramdac_set_pallook(void *priv, int i, uint32_t col); extern void ati68860_hwcursor_draw(svga_t *svga, int displine); -extern void ati68875_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *priv, svga_t *svga); -extern uint8_t ati68875_ramdac_in(uint16_t addr, int rs2, int rs3, void *priv, svga_t *svga); +extern void ati68875_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, int is_8514, void *priv, svga_t *svga); +extern uint8_t ati68875_ramdac_in(uint16_t addr, int rs2, int rs3, int is_8514, void *priv, svga_t *svga); extern void att49x_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *priv, svga_t *svga); extern uint8_t att49x_ramdac_in(uint16_t addr, int rs2, void *priv, svga_t *svga); diff --git a/src/include/86box/vid_svga_render.h b/src/include/86box/vid_svga_render.h index 097bb4509..226ab8a18 100644 --- a/src/include/86box/vid_svga_render.h +++ b/src/include/86box/vid_svga_render.h @@ -58,10 +58,6 @@ extern void svga_render_8bpp_highres(svga_t *svga); extern void svga_render_8bpp_clone_highres(svga_t *svga); extern void svga_render_8bpp_tseng_lowres(svga_t *svga); extern void svga_render_8bpp_tseng_highres(svga_t *svga); -extern void svga_render_8bpp_gs_lowres(svga_t *svga); -extern void svga_render_8bpp_gs_highres(svga_t *svga); -extern void svga_render_8bpp_rgb_lowres(svga_t *svga); -extern void svga_render_8bpp_rgb_highres(svga_t *svga); extern void svga_render_15bpp_lowres(svga_t *svga); extern void svga_render_15bpp_highres(svga_t *svga); extern void svga_render_15bpp_mix_lowres(svga_t *svga); diff --git a/src/include/86box/video.h b/src/include/86box/video.h index db7d5bfa0..986529d6f 100644 --- a/src/include/86box/video.h +++ b/src/include/86box/video.h @@ -75,6 +75,7 @@ enum { #define FONT_IBM_MDA_437_NORDIC_PATH "roms/video/mda/4733197.bin" #define FONT_KAM_PATH "roms/video/mda/kam.bin" #define FONT_KAMCL16_PATH "roms/video/mda/kamcl16.bin" +#define FONT_TULIP_DGA_PATH "roms/video/mda/tulip-dga-bios.bin" typedef struct video_timings_t { int type; @@ -357,12 +358,14 @@ extern const device_t chips_69000_onboard_device; /* Cirrus Logic GD54xx */ extern const device_t gd5401_isa_device; +extern const device_t gd5401_onboard_device; extern const device_t gd5402_isa_device; extern const device_t gd5402_onboard_device; extern const device_t gd5420_isa_device; extern const device_t gd5420_onboard_device; extern const device_t gd5422_isa_device; extern const device_t gd5424_vlb_device; +extern const device_t gd5424_onboard_device; extern const device_t gd5426_isa_device; extern const device_t gd5426_diamond_speedstar_pro_a1_isa_device; extern const device_t gd5426_vlb_device; @@ -472,6 +475,7 @@ extern const device_t if386jega_device; /* Oak OTI-0x7 */ extern const device_t oti037c_device; +extern const device_t oti037_pbl300sx_device; extern const device_t oti067_device; extern const device_t oti067_acer386_device; extern const device_t oti067_ama932j_device; diff --git a/src/lpt.c b/src/lpt.c deleted file mode 100644 index 072f4a34c..000000000 --- a/src/lpt.c +++ /dev/null @@ -1,264 +0,0 @@ -/* Copyright holders: Sarah Walker - see COPYING for more details -*/ -#include -#include -#include -#include -#include <86box/86box.h> -#include <86box/io.h> -#include <86box/lpt.h> -#include <86box/pic.h> -#include <86box/sound.h> -#include <86box/prt_devs.h> -#include <86box/thread.h> -#include <86box/timer.h> -#include <86box/device.h> -#include <86box/network.h> - -lpt_port_t lpt_ports[PARALLEL_MAX]; - -const lpt_device_t lpt_none_device = { - .name = "None", - .internal_name = "none", - .init = NULL, - .close = NULL, - .write_data = NULL, - .write_ctrl = NULL, - .read_data = NULL, - .read_status = NULL, - .read_ctrl = NULL -}; - -static const struct { - const char *internal_name; - const lpt_device_t *device; -} lpt_devices[] = { - // clang-format off - {"none", &lpt_none_device }, - {"dss", &dss_device }, - {"lpt_dac", &lpt_dac_device }, - {"lpt_dac_stereo", &lpt_dac_stereo_device }, - {"text_prt", &lpt_prt_text_device }, - {"dot_matrix", &lpt_prt_escp_device }, - {"postscript", &lpt_prt_ps_device }, -#ifdef USE_PCL - {"pcl", &lpt_prt_pcl_device }, -#endif - {"plip", &lpt_plip_device }, - {"dongle_savquest", &lpt_hasp_savquest_device }, - {"", NULL } - // clang-format on -}; - -const char * -lpt_device_get_name(int id) -{ - if (strlen(lpt_devices[id].internal_name) == 0) - return NULL; - if (!lpt_devices[id].device) - return "None"; - return lpt_devices[id].device->name; -} - -const char * -lpt_device_get_internal_name(int id) -{ - if (strlen(lpt_devices[id].internal_name) == 0) - return NULL; - return lpt_devices[id].internal_name; -} - -int -lpt_device_get_from_internal_name(char *s) -{ - int c = 0; - - while (strlen(lpt_devices[c].internal_name) != 0) { - if (strcmp(lpt_devices[c].internal_name, s) == 0) - return c; - c++; - } - - return 0; -} - -void -lpt_devices_init(void) -{ - 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) - lpt_ports[i].priv = lpt_ports[i].dt->init(&lpt_ports[i]); - } -} - -void -lpt_devices_close(void) -{ - lpt_port_t *dev; - - for (uint8_t i = 0; i < PARALLEL_MAX; i++) { - dev = &lpt_ports[i]; - - if (lpt_ports[i].dt && lpt_ports[i].dt->close) - dev->dt->close(dev->priv); - - dev->dt = NULL; - } -} - -void -lpt_write(uint16_t port, uint8_t val, void *priv) -{ - lpt_port_t *dev = (lpt_port_t *) priv; - - switch (port & 3) { - case 0: - if (dev->dt && dev->dt->write_data && dev->priv) - dev->dt->write_data(val, dev->priv); - dev->dat = val; - break; - - case 1: - break; - - case 2: - if (dev->dt && dev->dt->write_ctrl && dev->priv) - dev->dt->write_ctrl(val, dev->priv); - dev->ctrl = val; - dev->enable_irq = val & 0x10; - break; - - default: - break; - } -} - -uint8_t -lpt_read(uint16_t port, void *priv) -{ - uint8_t ret = 0xff; - lpt_port_t *dev = (lpt_port_t *) priv; - - switch (port & 3) { - case 0: - if (dev->dt && dev->dt->read_data && dev->priv) - ret = dev->dt->read_data(dev->priv); - else - ret = dev->dat; - break; - - case 1: - if (dev->dt && dev->dt->read_status && dev->priv) - ret = dev->dt->read_status(dev->priv) | 0x07; - else - ret = 0xdf; - break; - - case 2: - if (dev->dt && dev->dt->read_ctrl && dev->priv) - ret = (dev->dt->read_ctrl(dev->priv) & 0xef) | dev->enable_irq; - else - ret = 0xe0 | dev->ctrl | dev->enable_irq; - break; - - default: - break; - } - - return ret; -} - -uint8_t -lpt_read_port(int port, uint16_t reg) -{ - lpt_port_t *dev = &(lpt_ports[port]); - uint8_t ret = lpt_read(reg, dev); - - return ret; -} - -uint8_t -lpt_read_status(int port) -{ - lpt_port_t *dev = &(lpt_ports[port]); - uint8_t ret = 0xff; - - if (dev->dt && dev->dt->read_status && dev->priv) - ret = dev->dt->read_status(dev->priv) | 0x07; - else - ret = 0xdf; - - return ret; -} - -void -lpt_irq(void *priv, int raise) -{ - const lpt_port_t *dev = (lpt_port_t *) priv; - - if (dev->enable_irq && (dev->irq != 0xff)) { - if (raise) - picint(1 << dev->irq); - else - picintc(1 << dev->irq); - } -} - -void -lpt_init(void) -{ - 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 (uint8_t i = 0; i < PARALLEL_MAX; i++) { - lpt_ports[i].addr = 0xffff; - lpt_ports[i].irq = 0xff; - lpt_ports[i].enable_irq = 0x10; - - if (lpt_ports[i].enabled) { - lpt_port_setup(i, default_ports[i]); - lpt_port_irq(i, default_irqs[i]); - } - } -} - -void -lpt_port_setup(int i, uint16_t port) -{ - if (lpt_ports[i].enabled) { - if ((lpt_ports[i].addr != 0xffff) && (lpt_ports[i].addr != 0x0000)) - io_removehandler(lpt_ports[i].addr, 0x0003, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[i]); - if ((port != 0xffff) && (port != 0x0000)) - io_sethandler(port, 0x0003, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[i]); - lpt_ports[i].addr = port; - } else - lpt_ports[i].addr = 0xffff; -} - -void -lpt_port_irq(int i, uint8_t irq) -{ - if (lpt_ports[i].enabled) - lpt_ports[i].irq = irq; - else - lpt_ports[i].irq = 0xff; -} - -void -lpt_port_remove(int i) -{ - if (lpt_ports[i].enabled && (lpt_ports[i].addr != 0xffff)) { - io_removehandler(lpt_ports[i].addr, 0x0003, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[i]); - lpt_ports[i].addr = 0xffff; - } -} - -void -lpt1_remove_ams(void) -{ - if (lpt_ports[0].enabled) - io_removehandler(lpt_ports[0].addr + 1, 0x0002, lpt_read, NULL, NULL, lpt_write, NULL, NULL, &lpt_ports[0]); -} diff --git a/src/machine/m_at_286_386sx.c b/src/machine/m_at_286_386sx.c index a295f305a..e91b9bcf5 100644 --- a/src/machine/m_at_286_386sx.c +++ b/src/machine/m_at_286_386sx.c @@ -118,7 +118,7 @@ machine_at_ama932j_init(const machine_t *model) machine_at_headland_common_init(model, 2); - device_add(&ali5105_device); + device_add_params(&pc87310_device, (void *) (PC87310_ALI)); return ret; } @@ -169,6 +169,72 @@ machine_at_quadt386sx_init(const machine_t *model) return ret; } +static const device_config_t pbl300sx_config[] = { + // clang-format off + { + .name = "bios", + .description = "BIOS Version", + .type = CONFIG_BIOS, + .default_string = "pbl300sx", + .default_int = 0, + .file_filter = "", + .spinner = { 0 }, + .bios = { + { .name = "1991", .internal_name = "pbl300sx_1991", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/pbl300sx/V1.10_1113_910723.bin", "" } }, + { .name = "1992", .internal_name = "pbl300sx", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/pbl300sx/pb_l300sx_1992.bin", "" } }, + { .files_no = 0 } + }, + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + +const device_t pbl300sx_device = { + .name = "Packard Bell Legend 300SX", + .internal_name = "pbl300sx_device", + .flags = 0, + .local = 0, + .init = NULL, + .close = NULL, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = pbl300sx_config +}; + +int +machine_at_pbl300sx_init(const machine_t *model) +{ + int ret = 0; + const char* fn; + + /* No ROMs available */ + if (!device_available(model->device)) + return ret; + + device_context(model->device); + fn = device_get_bios_file(machine_get_device(machine), device_get_config_bios("bios"), 0); + ret = bios_load_linear(fn, 0x000e0000, 131072, 0); + device_context_restore(); + + if (bios_only || !ret) + return ret; + + machine_at_common_init(model); + device_add(&acc2036_device); + + device_add(&keyboard_ps2_phoenix_device); + device_add(&um82c862f_ide_device); + + if (gfxcard[0] == VID_INTERNAL) + device_add(machine_get_vid_device(machine)); + + return ret; +} + int machine_at_neat_init(const machine_t *model) { @@ -292,6 +358,22 @@ machine_at_dells200_init(const machine_t *model) return ret; } +int +machine_at_at122_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/at122/FINAL.BIN", + 0x000f0000, 65536, 0); + + if (bios_only || !ret) + return ret; + + machine_at_ctat_common_init(model); + + return ret; +} + int machine_at_tuliptc7_init(const machine_t *model) { @@ -447,6 +529,28 @@ machine_at_gw286ct_init(const machine_t *model) return ret; } +int +machine_at_drsm35286_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/drsm35286/syab04-665821fb81363428830424.bin", + 0x000f0000, 65536, 0); + + if (bios_only || !ret) + return ret; + + device_add(&ide_isa_device); + device_add(&fdc37c651_ide_device); + + machine_at_scat_init(model, 1, 0); + + if (gfxcard[0] == VID_INTERNAL) + device_add(machine_get_vid_device(machine)); + + return ret; +} + int machine_at_senor_scat286_init(const machine_t *model) { @@ -776,7 +880,7 @@ machine_at_cmdsl386sx25_init(const machine_t *model) device_add(&ide_isa_device); - device_add(&ali5105_device); /* The FDC is part of the ALi M5105. */ + device_add_params(&pc87310_device, (void *) (PC87310_ALI)); device_add(&vl82c113_device); /* The keyboard controller is part of the VL82c113. */ device_add(&vlsi_scamp_device); @@ -926,7 +1030,7 @@ machine_at_acer100t_init(const machine_t *model) if (gfxcard[0] == VID_INTERNAL) device_add(&oti077_acer100t_device); - device_add(&ali5105_device); + device_add_params(&pc87310_device, (void *) (PC87310_ALI)); return ret; } diff --git a/src/machine/m_at_386dx_486.c b/src/machine/m_at_386dx_486.c index 0becae2b8..eb91f300c 100644 --- a/src/machine/m_at_386dx_486.c +++ b/src/machine/m_at_386dx_486.c @@ -535,7 +535,7 @@ machine_at_acera1g_init(const machine_t *model) device_add(&keyboard_ps2_acer_pci_device); - device_add(&ali5105_device); + device_add_params(&pc87310_device, (void *) (PC87310_ALI)); device_add(&ide_ali5213_device); return ret; @@ -682,7 +682,7 @@ machine_at_opti495_init(const machine_t *model) machine_at_common_init(model); - device_add(&opti495_device); + device_add(&opti495slc_device); device_add(&keyboard_at_device); @@ -697,7 +697,7 @@ machine_at_opti495_ami_common_init(const machine_t *model) { machine_at_common_init(model); - device_add(&opti495_device); + device_add(&opti495sx_device); device_add(&keyboard_at_ami_device); @@ -737,6 +737,32 @@ machine_at_opti495_mr_init(const machine_t *model) return ret; } +int +machine_at_c747_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/c747/486-C747 Tandon.BIN", + 0x000f0000, 65536, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init(model); + + /* The EFAR chipset is a rebrand of the OPTi 495SX. */ + device_add(&opti495sx_device); + + /* + No idea what KBC it actually has but this produces the + desired behavior: command A9 does absolutely nothing. + */ + device_add(&keyboard_at_siemens_device); + device_add(&um82c862f_ide_device); + + return ret; +} + int machine_at_exp4349_init(const machine_t *model) { @@ -822,6 +848,7 @@ machine_at_403tg_d_mr_init(const machine_t *model) return ret; } + static const device_config_t pb450_config[] = { // clang-format off { @@ -974,7 +1001,8 @@ machine_at_mvi486_init(const machine_t *model) machine_at_common_init(model); - device_add(&opti495_device); + device_add(&opti498_device); + device_add(&keyboard_at_device); device_add(&pc87311_ide_device); @@ -1009,6 +1037,31 @@ machine_at_ami471_init(const machine_t *model) return ret; } +int +machine_at_advantage40xxd_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/advantage40xxd/AST101.09A", + 0x000e0000, 131072, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init(model); + device_add(&sis_85c471_device); + + if (gfxcard[0] == VID_INTERNAL) + device_add(machine_get_vid_device(machine)); + + device_add(&keyboard_ps2_phoenix_device); + device_add(&um82c863f_ide_device); + + device_add(&intel_flash_bxt_device); + + return ret; +} + int machine_at_vli486sv2g_init(const machine_t *model) { @@ -2816,6 +2869,32 @@ machine_at_ga486l_init(const machine_t *model) return ret; } +int +machine_at_cobalt_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/cobalt/Cobalt_2.3.BIN", + 0x000e0000, 131072, 0); + + if (bios_only || !ret) + return ret; + + machine_at_common_init(model); + + device_add(&opti499_device); + device_add(&ide_opti611_vlb_device); + device_add(&ide_isa_sec_device); + device_add(&fdc37c665_device); + + device_add(&keyboard_ps2_ami_device); + + if (gfxcard[0] == VID_INTERNAL) + device_add(machine_get_vid_device(machine)); + + return ret; +} + int machine_at_cougar_init(const machine_t *model) { diff --git a/src/machine/m_at_socket4.c b/src/machine/m_at_socket4.c index 2d4e1a51a..3de3bc871 100644 --- a/src/machine/m_at_socket4.c +++ b/src/machine/m_at_socket4.c @@ -41,6 +41,79 @@ #include <86box/video.h> #include <86box/machine.h> +int +machine_at_v12p_init(const machine_t *model) + +{ + int ret = 0; + const char* fn; + + /* No ROMs available */ + if (!device_available(model->device)) + return ret; + + device_context(model->device); + fn = device_get_bios_file(machine_get_device(machine), device_get_config_bios("bios_versions"), 0); + ret = bios_load_linear(fn, 0x000e0000, 131072, 0); + device_context_restore(); + + machine_at_common_init(model); + + device_add(&ide_isa_device); + pci_init(PCI_CONFIG_TYPE_2 | PCI_NO_IRQ_STEERING); + pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x01, PCI_CARD_SCSI, 1, 4, 3, 2); + pci_register_slot(0x02, PCI_CARD_SOUTHBRIDGE, 2, 1, 4, 3); + pci_register_slot(0x03, PCI_CARD_NORMAL, 3, 2, 1, 4); + pci_register_slot(0x04, PCI_CARD_NORMAL, 4, 0, 0, 0); + pci_register_slot(0x05, PCI_CARD_NORMAL, 0, 0, 0, 0); + device_add(&i430lx_device); + device_add(&keyboard_ps2_acer_pci_device); + device_add(&sio_zb_device); + device_add_params(&pc87310_device, (void *) (PC87310_ALI)); + device_add(&amd_am28f010_flash_device); + + return ret; +} + +static const device_config_t v12p_config[] = { + // clang-format off + { + .name = "bios_versions", + .description = "BIOS Versions", + .type = CONFIG_BIOS, + .default_string = "v12p_14", + .default_int = 0, + .file_filter = "", + .spinner = { 0 }, /*W1*/ + .bios = { + { .name = "Core Version 1.2 Version R1.4", .internal_name = "v12p_14", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/v12p/v12p_14.bin", "" } }, + { .name = "Core Version 1.2 Version R1.6", .internal_name = "v12p_16", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/v12p/v12p_16.bin", "" } }, + + }, + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + + + +const device_t v12p_device = { + .name = "Acer V12P", + .internal_name = "v12p", + .flags = 0, + .local = 0, + .init = NULL, + .close = NULL, + .reset = NULL, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = &v12p_config[0] +}; + void machine_at_premiere_common_init(const machine_t *model, int pci_switch) { diff --git a/src/machine/m_at_socket5.c b/src/machine/m_at_socket5.c index 3ed2bd2c7..b2d3c46f3 100644 --- a/src/machine/m_at_socket5.c +++ b/src/machine/m_at_socket5.c @@ -96,21 +96,21 @@ machine_at_d842_init(const machine_t *model) ret = bios_load_linear(fn, 0x000e0000, 131072, 0); device_context_restore(); - machine_at_common_init(model); + machine_at_common_init(model); device_add(&ide_pci_2ch_device); pci_init(PCI_CONFIG_TYPE_2 | PCI_NO_IRQ_STEERING); - pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); - pci_register_slot(0x01, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); /* Onboard */ - pci_register_slot(0x03, PCI_CARD_VIDEO, 4, 0, 0, 0); /* Onboard */ - pci_register_slot(0x0C, PCI_CARD_NORMAL, 1, 3, 2, 4); /* Slot 01 */ - pci_register_slot(0x0E, PCI_CARD_NORMAL, 2, 1, 3, 4); /* Slot 02 */ + pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x01, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); /* Onboard */ + pci_register_slot(0x03, PCI_CARD_VIDEO, 4, 0, 0, 0); /* Onboard */ + pci_register_slot(0x0C, PCI_CARD_NORMAL, 1, 3, 2, 4); /* Slot 01 */ + pci_register_slot(0x0E, PCI_CARD_NORMAL, 2, 1, 3, 4); /* Slot 02 */ device_add(&keyboard_ps2_pci_device); device_add(&i430nx_device); device_add(&sio_zb_device); device_add(&fdc37c665_device); - device_add(&intel_flash_bxt_device); + device_add(&intel_flash_bxt_device); return ret; } @@ -127,18 +127,17 @@ static const device_config_t d842_config[] = { .spinner = { 0 }, /*W1*/ .bios = { { .name = "Version 1.03 Revision 1.03.842 (11/24/1994)", .internal_name = "d842", .bios_type = BIOS_NORMAL, - .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d842/d842.bin", "" } }, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d842/d842.BIN", "" } }, { .name = "Version 4.04 Revision 1.05.842 (03/15/1996)", .internal_name = "d842_mar96", .bios_type = BIOS_NORMAL, .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d842/d842_mar96.bin", "" } }, { .name = "Version 4.04 Revision 1.06.842 (04/03/1998)", .internal_name = "d842_apr98", .bios_type = BIOS_NORMAL, .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d842/d842_apr98.bin", "" } }, - { .name = "Version 4.04 Revision 1.07.842 (06/02/1998)", .internal_name = "d842_jun98", .bios_type = BIOS_NORMAL, - .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d842/d842_jun98.bin", "" } }, - { .name = "Version 1.03 Revision 1.09.842 (07/08/1996)", .internal_name = "d842_jul96", .bios_type = BIOS_NORMAL, + { .name = "Version 4.04 Revision 1.07.842 (06/02/1998)", .internal_name = "d842_jun98", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d842/d842_jun98.BIN", "" } }, + { .name = "Version 1.03 Revision 1.09.842 (07/08/1996)", .internal_name = "d842_jul96", .bios_type = BIOS_NORMAL, .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d842/d842_jul96.bin", "" } }, - { .name = "Version 1.03 Revision 1.10.842 (06/04/1998)", .internal_name = "d842_jun98_1", .bios_type = BIOS_NORMAL, - .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d842/d842_jun98_1.bin", "" } }, - + { .name = "Version 1.03 Revision 1.10.842 (06/04/1998)", .internal_name = "d842_jun98_1", .bios_type = BIOS_NORMAL, + .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d842/d842_jun98_1.bin", "" } }, }, }, { .name = "", .description = "", .type = CONFIG_END } @@ -155,7 +154,7 @@ const device_t d842_device = { .init = NULL, .close = NULL, .reset = NULL, - .available = NULL, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = &d842_config[0] diff --git a/src/machine/m_at_socket7_3v.c b/src/machine/m_at_socket7_3v.c index 7dd1f9bf0..7d29a6f3a 100644 --- a/src/machine/m_at_socket7_3v.c +++ b/src/machine/m_at_socket7_3v.c @@ -628,25 +628,24 @@ machine_at_d943_init(const machine_t *model) ret = bios_load_linear(fn, 0x000e0000, 131072, 0); device_context_restore(); - machine_at_common_init_ex(model, 2); - device_add(&amstrad_megapc_nvr_device); + machine_at_common_init_ex(model, 2); + device_add(&amstrad_megapc_nvr_device); pci_init(PCI_CONFIG_TYPE_1); - pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); - pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); - pci_register_slot(0x08, PCI_CARD_VIDEO, 4, 0, 0, 0); - pci_register_slot(0x11, PCI_CARD_NORMAL, 3, 2, 4, 1); - pci_register_slot(0x12, PCI_CARD_NORMAL, 2, 1, 3, 4); - pci_register_slot(0x13, PCI_CARD_NORMAL, 1, 3, 2, 4); + pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x07, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0); + pci_register_slot(0x08, PCI_CARD_VIDEO, 4, 0, 0, 0); + pci_register_slot(0x11, PCI_CARD_NORMAL, 3, 2, 4, 1); + pci_register_slot(0x12, PCI_CARD_NORMAL, 2, 1, 3, 4); + pci_register_slot(0x13, PCI_CARD_NORMAL, 1, 3, 2, 4); device_add(&i430hx_device); device_add(&piix3_device); device_add(&keyboard_ps2_pci_device); device_add(&fdc37c665_device); device_add(&intel_flash_bxt_device); - spd_register(SPD_TYPE_EDO, 0x7, 256); - - - if (gfxcard[0] == VID_INTERNAL) + spd_register(SPD_TYPE_EDO, 0x7, 256); + + if (gfxcard[0] == VID_INTERNAL) device_add(machine_get_vid_device(machine)); if (sound_card_current[0] == SOUND_INTERNAL) @@ -670,11 +669,10 @@ static const device_config_t d943_config[] = { .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d943/d943_oct96.bin", "" } }, { .name = "Version 4.05 Revision 1.03.943 (12/12/1996)", .internal_name = "d943_dec96", .bios_type = BIOS_NORMAL, .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d943/d943_dec96.bin", "" } }, - { .name = "Version 4.05 Revision 1.05.943 (09/04/1997)", .internal_name = "d943_sept97", .bios_type = BIOS_NORMAL, + { .name = "Version 4.05 Revision 1.05.943 (09/04/1997)", .internal_name = "d943_sept97", .bios_type = BIOS_NORMAL, .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d943/d943_sept97.bin", "" } }, { .name = "Version 4.05 Revision 1.06.943 (10/29/1997)", .internal_name = "d943_oct97", .bios_type = BIOS_NORMAL, .files_no = 1, .local = 0, .size = 131072, .files = { "roms/machines/d943/d943_oct97.bin", "" } }, - }, }, { .name = "", .description = "", .type = CONFIG_END } @@ -691,7 +689,7 @@ const device_t d943_device = { .init = NULL, .close = NULL, .reset = NULL, - .available = NULL, + .available = NULL, .speed_changed = NULL, .force_redraw = NULL, .config = &d943_config[0] diff --git a/src/machine/m_pcjr.c b/src/machine/m_pcjr.c index e76889d93..30a5e609a 100644 --- a/src/machine/m_pcjr.c +++ b/src/machine/m_pcjr.c @@ -782,9 +782,11 @@ static const device_config_t pcjr_config[] = { .file_filter = "", .spinner = { 0 }, .selection = { - { .description = "RGB", .value = PCJR_RGB }, - { .description = "Composite", .value = PCJR_COMPOSITE }, - { .description = "" } + { .description = "RGB", .value = PCJR_RGB }, + { .description = "Composite", .value = PCJR_COMPOSITE }, + { .description = "RGB (no brown)", .value = PCJR_RGB_NO_BROWN }, + { .description = "RGB (IBM 5153)", .value = PCJR_RGB_IBM_5153 }, + { .description = "" } } }, { diff --git a/src/machine/m_xt.c b/src/machine/m_xt.c index d71d16c15..c94549463 100644 --- a/src/machine/m_xt.c +++ b/src/machine/m_xt.c @@ -39,6 +39,7 @@ #include <86box/keyboard.h> #include <86box/rom.h> #include <86box/machine.h> +#include <86box/nvr.h> #include <86box/chipset.h> #include <86box/port_6x.h> #include <86box/video.h> @@ -668,6 +669,34 @@ machine_xt_amixt_init(const machine_t *model) return ret; } +int +machine_xt_tuliptc8_init(const machine_t *model) +{ + int ret; + + ret = bios_load_linear("roms/machines/tuliptc8/tulip-bios_xt_compact_2.bin", + 0x000fc000, 16384, 0); + + if (bios_only || !ret) + return ret; + + device_add(&keyboard_xt_fe2010_device); + + if (fdc_current[0] == FDC_INTERNAL) + device_add(&fdc_at_device); + + machine_common_init(model); + + pit_devs[0].set_out_func(pit_devs[0].data, 1, pit_refresh_timer_xt); + + nmi_init(); + standalone_gameport_type = &gameport_device; + + device_add(&amstrad_megapc_nvr_device); + + return ret; +} + // TODO // Onboard EGA Graphics (NSI Logic EVC315-S on early boards STMicroelectronics EGA on later revisions) // RTC diff --git a/src/machine/machine_table.c b/src/machine/machine_table.c index 28d4a9a6a..d5e2af58b 100644 --- a/src/machine/machine_table.c +++ b/src/machine/machine_table.c @@ -71,6 +71,8 @@ extern const device_t d842_device; extern const device_t d943_device; extern const device_t dells333sl_device; extern const device_t hot433a_device; +extern const device_t pbl300sx_device; +extern const device_t v12p_device; const machine_filter_t machine_types[] = { { "None", MACHINE_TYPE_NONE }, @@ -107,6 +109,7 @@ const machine_filter_t machine_chipsets[] = { { "Headland GC100A", MACHINE_CHIPSET_GC100A }, { "Headland GC103", MACHINE_CHIPSET_GC103 }, { "Headland HT18", MACHINE_CHIPSET_HT18 }, + { "ACC 2036", MACHINE_CHIPSET_ACC_2036 }, { "ACC 2168", MACHINE_CHIPSET_ACC_2168 }, { "ALi M1217", MACHINE_CHIPSET_ALI_M1217 }, { "ALi M6117", MACHINE_CHIPSET_ALI_M6117 }, @@ -150,7 +153,9 @@ const machine_filter_t machine_chipsets[] = { { "OPTi 391", MACHINE_CHIPSET_OPTI_391 }, { "OPTi 481", MACHINE_CHIPSET_OPTI_481 }, { "OPTi 493", MACHINE_CHIPSET_OPTI_493 }, - { "OPTi 495", MACHINE_CHIPSET_OPTI_495 }, + { "OPTi 495SLC", MACHINE_CHIPSET_OPTI_495SLC }, + { "OPTi 495SX", MACHINE_CHIPSET_OPTI_495SX }, + { "OPTi 498", MACHINE_CHIPSET_OPTI_498 }, { "OPTi 499", MACHINE_CHIPSET_OPTI_499 }, { "OPTi 895/802G", MACHINE_CHIPSET_OPTI_895_802G }, { "OPTi 547/597", MACHINE_CHIPSET_OPTI_547_597 }, @@ -2026,6 +2031,45 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + { + .name = "[V20] Tulip PC Compact 2", + .internal_name = "tuliptc8", + .type = MACHINE_TYPE_8088, + .chipset = MACHINE_CHIPSET_DISCRETE, + .init = machine_xt_tuliptc8_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_8088, + .block = CPU_BLOCK(CPU_8088), + .min_bus = 0, + .max_bus = 0, + .min_voltage = 0, + .max_voltage = 0, + .min_multi = 0, + .max_multi = 0 + }, + .bus_flags = MACHINE_PC, + .flags = MACHINE_FLAGS_NONE, + .ram = { + .min = 64, + .max = 640, + .step = 64 + }, + .nvrmask = 63, + .kbc_device = &keyboard_xtclone_device, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* 8086 Machines */ { @@ -3098,7 +3142,7 @@ const machine_t machines[] = { }, /* Has Olivetti KBC firmware. */ { - .name = "[ISA] Olivetti M290", + .name = "[ISA] Olivetti M290/AT&T 6286 WGS", .internal_name = "m290", .type = MACHINE_TYPE_286, .chipset = MACHINE_CHIPSET_PROPRIETARY, @@ -3120,7 +3164,7 @@ const machine_t machines[] = { .bus_flags = MACHINE_AT, .flags = MACHINE_FLAGS_NONE, .ram = { - .min = 640, + .min = 1024, .max = 16384, .step = 128 }, @@ -3417,6 +3461,47 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + /* No proper pictures of the KBC exist, though it seems to have the IBM AT KBC + firmware. */ + { + .name = "[C&T PC/AT] PC's Limited (Dell) 28608L/AT122", + .internal_name = "at122", + .type = MACHINE_TYPE_286, + .chipset = MACHINE_CHIPSET_CT_AT, + .init = machine_at_at122_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_286, + .block = CPU_BLOCK_NONE, + .min_bus = 6000000, + .max_bus = 12000000, + .min_voltage = 0, + .max_voltage = 0, + .min_multi = 0, + .max_multi = 0 + }, + .bus_flags = MACHINE_AT, + .flags = MACHINE_FLAGS_NONE, + .ram = { + .min = 640, + .max = 16384, + .step = 128 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* No proper pictures of the KBC exist, though it seems to have the IBM AT KBC firmware. */ { @@ -3897,6 +3982,45 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + { + .name = "[SCAT] ICL DRS M35/286", + .internal_name = "drsm35286", + .type = MACHINE_TYPE_286, + .chipset = MACHINE_CHIPSET_SCAT, + .init = machine_at_drsm35286_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_286, + .block = CPU_BLOCK_NONE, + .min_bus = 0, + .max_bus = 0, + .min_voltage = 0, + .max_voltage = 0, + .min_multi = 0, + .max_multi = 0 + }, + .bus_flags = MACHINE_PS2, + .flags = MACHINE_IDE | MACHINE_VIDEO, + .ram = { + .min = 512, + .max = 5120, + .step = 128 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = &gd5401_onboard_device, + .snd_device = NULL, + .net_device = NULL + }, /* Has IBM PS/2 Type 1 KBC firmware. */ { .name = "[SCAT] Samsung SPC-4200P", @@ -4301,6 +4425,46 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + /* Most likely has Phonenix KBC firmware. */ + { + .name = "[ACC 2036] Packard Bell Legend 300SX", + .internal_name = "pbl300sx", + .type = MACHINE_TYPE_386SX, + .chipset = MACHINE_CHIPSET_ACC_2036, + .init = machine_at_pbl300sx_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_386SX, + .block = CPU_BLOCK_NONE, + .min_bus = 0, + .max_bus = 0, + .min_voltage = 0, + .max_voltage = 0, + .min_multi = 0, + .max_multi = 0 + }, + .bus_flags = MACHINE_PS2, + .flags = MACHINE_IDE | MACHINE_VIDEO, + .ram = { + .min = 1024, + .max = 16384, + .step = 1024 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = &pbl300sx_device, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = &oti037_pbl300sx_device, + .snd_device = NULL, + .net_device = NULL + }, /* This has an AMIKey-2, which is an updated version of type 'H'. */ { .name = "[ALi M1217] Acrosser AR-B1374", @@ -5717,10 +5881,10 @@ const machine_t machines[] = { but the BIOS sends commands C9 without a parameter and D5, both of which are Phoenix MultiKey commands. */ { - .name = "[OPTi 495] U-Board OPTi 495SLC", + .name = "[OPTi 495SLC] U-Board OPTi 495SLC", .internal_name = "award495", .type = MACHINE_TYPE_386DX, - .chipset = MACHINE_CHIPSET_OPTI_495, + .chipset = MACHINE_CHIPSET_OPTI_495SLC, .init = machine_at_opti495_init, .p1_handler = NULL, .gpio_handler = NULL, @@ -5959,12 +6123,52 @@ const machine_t machines[] = { }, /* 386DX/486 machines */ + /* Has AMIKey F KBC firmware. The EFAR chipst is a rebrand of OPTi 495SX. */ + { + .name = "[OPTi 495SX] CAF Technology C747", + .internal_name = "c747", + .type = MACHINE_TYPE_386DX_486, + .chipset = MACHINE_CHIPSET_OPTI_495SX, + .init = machine_at_c747_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_386DX | CPU_PKG_SOCKET1, + .block = CPU_BLOCK_NONE, + .min_bus = 0, + .max_bus = 0, + .min_voltage = 0, + .max_voltage = 0, + .min_multi = 0, + .max_multi = 0 + }, + .bus_flags = MACHINE_AT, + .flags = MACHINE_APM | MACHINE_IDE, + .ram = { + .min = 1024, + .max = 32768, + .step = 1024 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* Has AMIKey F KBC firmware. */ { - .name = "[OPTi 495] DataExpert SX495", + .name = "[OPTi 495SX] DataExpert SX495", .internal_name = "ami495", .type = MACHINE_TYPE_386DX_486, - .chipset = MACHINE_CHIPSET_OPTI_495, + .chipset = MACHINE_CHIPSET_OPTI_495SX, .init = machine_at_opti495_ami_init, .p1_handler = NULL, .gpio_handler = NULL, @@ -6001,10 +6205,10 @@ const machine_t machines[] = { }, /* Has AMIKey F KBC firmware (it's just the MR BIOS for the above machine). */ { - .name = "[OPTi 495] DataExpert SX495 (MR BIOS)", + .name = "[OPTi 495SX] DataExpert SX495 (MR BIOS)", .internal_name = "mr495", .type = MACHINE_TYPE_386DX_486, - .chipset = MACHINE_CHIPSET_OPTI_495, + .chipset = MACHINE_CHIPSET_OPTI_495SX, .init = machine_at_opti495_mr_init, .p1_handler = NULL, .gpio_handler = NULL, @@ -6326,10 +6530,10 @@ const machine_t machines[] = { /* Uses some variant of Phoenix MultiKey/42 as the Intel 8242 chip has a Phoenix copyright. */ { - .name = "[OPTi 495] Mylex MVI486", + .name = "[OPTi 498] Mylex MVI486", .internal_name = "mvi486", .type = MACHINE_TYPE_486, - .chipset = MACHINE_CHIPSET_OPTI_495, + .chipset = MACHINE_CHIPSET_OPTI_498, .init = machine_at_mvi486_init, .p1_handler = NULL, .gpio_handler = NULL, @@ -6485,6 +6689,46 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + /* Has Phoenix KBC firmware. */ + { + .name = "[SiS 471] AST Advantage! 40xxd", + .internal_name = "advantage40xxd", + .type = MACHINE_TYPE_486, + .chipset = MACHINE_CHIPSET_SIS_471, + .init = machine_at_advantage40xxd_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET1, + .block = CPU_BLOCK_NONE, + .min_bus = 0, + .max_bus = 0, + .min_voltage = 0, + .max_voltage = 0, + .min_multi = 0, + .max_multi = 2 + }, + .bus_flags = MACHINE_PS2_VLB, + .flags = MACHINE_IDE | MACHINE_VIDEO | MACHINE_APM, + .ram = { + .min = 4096, + .max = 36864, + .step = 4096 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = &gd5424_onboard_device, + .snd_device = NULL, + .net_device = NULL + }, /* Has AMIKey F KBC firmware. */ { .name = "[Symphony SL42C460] DTK PKM-0031Y", @@ -6975,6 +7219,45 @@ const machine_t machines[] = { .snd_device = NULL, .net_device = NULL }, + { + .name = "[OPTi 499] Alaris Cobalt LPX", + .internal_name = "cobalt", + .type = MACHINE_TYPE_486_S2, + .chipset = MACHINE_CHIPSET_OPTI_499, + .init = machine_at_cobalt_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET3 | CPU_PKG_486BL, + .block = CPU_BLOCK(CPU_P24T), + .min_bus = 0, + .max_bus = 0, + .min_voltage = 0, + .max_voltage = 0, + .min_multi = 0, + .max_multi = 0 + }, + .bus_flags = MACHINE_PS2_VLB, + .flags = MACHINE_APM | MACHINE_VIDEO | MACHINE_IDE_DUAL, + .ram = { + .min = 1024, + .max = 65536, + .step = 1024 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = NULL, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = &gd5428_vlb_onboard_device, + .snd_device = NULL, + .net_device = NULL + }, /* Has AMIKey-2 'H' KBC firmware. */ { .name = "[OPTi 499] Alaris COUGAR 486BL", @@ -9775,6 +10058,45 @@ const machine_t machines[] = { /* Socket 4 machines */ /* 430LX */ + { + .name = "[i430LX] Acer V12P", + .internal_name = "v12p", + .type = MACHINE_TYPE_SOCKET4, + .chipset = MACHINE_CHIPSET_INTEL_430LX, + .init = machine_at_v12p_init, + .p1_handler = NULL, + .gpio_handler = NULL, + .available_flag = MACHINE_AVAILABLE, + .gpio_acpi_handler = NULL, + .cpu = { + .package = CPU_PKG_SOCKET4, + .block = CPU_BLOCK_NONE, + .min_bus = 60000000, + .max_bus = 66666667, + .min_voltage = 5000, + .max_voltage = 5000, + .min_multi = MACHINE_MULTIPLIER_FIXED, + .max_multi = MACHINE_MULTIPLIER_FIXED + }, + .bus_flags = MACHINE_PS2_PCI, + .flags = MACHINE_IDE | MACHINE_APM, + .ram = { + .min = 2048, + .max = 196608, + .step = 2048 + }, + .nvrmask = 127, + .kbc_device = NULL, + .kbc_p1 = 0xff, + .gpio = 0xffffffff, + .gpio_acpi = 0xffffffff, + .device = &v12p_device, + .fdc_device = NULL, + .sio_device = NULL, + .vid_device = NULL, + .snd_device = NULL, + .net_device = NULL + }, /* Has AMIKey H KBC firmware (AMIKey-2), per POST screen with BIOS string shown in the manual. Has PS/2 mouse support with serial-style (DB9) connector. @@ -11968,7 +12290,7 @@ const machine_t machines[] = { .ram = { .min = 8192, .max = 131072, - .step = 8192 + .step = 4096 }, .nvrmask = 511, .kbc_device = NULL, diff --git a/src/mem/catalyst_flash.c b/src/mem/catalyst_flash.c index 00e2422a3..5c8812464 100644 --- a/src/mem/catalyst_flash.c +++ b/src/mem/catalyst_flash.c @@ -29,6 +29,7 @@ #include <86box/timer.h> #include <86box/nvr.h> #include <86box/plat.h> +#include <86box/plat_fallthrough.h> #define FLAG_WORD 4 #define FLAG_BXB 2 @@ -44,21 +45,22 @@ enum { }; enum { - CMD_SET_READ = 0x00, - CMD_READ_SIGNATURE = 0x90, - CMD_ERASE = 0x20, - CMD_ERASE_CONFIRM = 0x20, - CMD_ERASE_VERIFY = 0xA0, - CMD_PROGRAM = 0x40, - CMD_PROGRAM_VERIFY = 0xC0, - CMD_RESET = 0xFF + CMD_SET_READ = 0x00, + CMD_READ_AUTO_SELECT = 0x80, + CMD_READ_SIGNATURE = 0x90, + CMD_ERASE = 0x20, + CMD_ERASE_CONFIRM = 0x20, + CMD_ERASE_VERIFY = 0xA0, + CMD_PROGRAM = 0x40, + CMD_PROGRAM_VERIFY = 0xC0, + CMD_RESET = 0xFF }; typedef struct flash_t { uint8_t command; + uint8_t is_amd; uint8_t pad; uint8_t pad0; - uint8_t pad1; uint8_t *array; mem_mapping_t mapping; @@ -83,11 +85,22 @@ flash_read(uint32_t addr, void *priv) ret = dev->array[addr]; break; + case CMD_READ_AUTO_SELECT: + if (!dev->is_amd) + break; + fallthrough; case CMD_READ_SIGNATURE: - if (addr == 0x00000) - ret = 0x31; /* CATALYST */ - else if (addr == 0x00001) - ret = 0xB4; /* 28F010 */ + if (dev->is_amd) { + if (addr == 0x00000) + ret = 0x01; /* AMD */ + else if (addr == 0x00001) + ret = 0xa7; /* Am28F010 */ + } else { + if (addr == 0x00000) + ret = 0x31; /* CATALYST */ + else if (addr == 0x00001) + ret = 0xb4; /* 28F010 */ + } break; default: @@ -205,6 +218,7 @@ catalyst_flash_init(UNUSED(const device_t *info)) catalyst_flash_add_mappings(dev); dev->command = CMD_RESET; + dev->is_amd = info->local; fp = nvr_fopen(flash_path, "rb"); if (fp) { @@ -244,3 +258,17 @@ const device_t catalyst_flash_device = { .force_redraw = NULL, .config = NULL }; + +const device_t amd_am28f010_flash_device = { + .name = "AMD Am28F010-D Flash BIOS", + .internal_name = "amd_am28f010_flash", + .flags = DEVICE_PCI, + .local = 1, + .init = catalyst_flash_init, + .close = catalyst_flash_close, + .reset = catalyst_flash_reset, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/mem/mem.c b/src/mem/mem.c index d365ecffb..fa749002c 100644 --- a/src/mem/mem.c +++ b/src/mem/mem.c @@ -67,7 +67,9 @@ mem_mapping_t bios_mapping; mem_mapping_t bios_high_mapping; page_t *pages; /* RAM page table */ +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) page_t **page_lookup; /* pagetable lookup */ +#endif uint32_t pages_sz; /* #pages in table */ uint8_t *ram; /* the virtual RAM */ @@ -85,12 +87,23 @@ uint8_t *pccache2; int readlnext; int readlookup[256]; +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) uintptr_t *readlookup2; +#endif uintptr_t old_rl2; uint8_t uncached = 0; int writelnext; int writelookup[256]; +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) uintptr_t *writelookup2; +#endif + +#if (defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64) +/* The lookup tables. */ +page_t *page_lookup[1048576] = { 0 }; +uintptr_t readlookup2[1048576] = { 0 }; +uintptr_t writelookup2[1048576] = { 0 }; +#endif uint32_t mem_logical_addr; @@ -2987,12 +3000,25 @@ mem_init(void) ram2 = NULL; pages = NULL; +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) /* Allocate the lookup tables. */ page_lookup = (page_t **) malloc((1 << 20) * sizeof(page_t *)); readlookup2 = malloc((1 << 20) * sizeof(uintptr_t)); writelookup2 = malloc((1 << 20) * sizeof(uintptr_t)); +#endif } +#if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) +void +mem_free(void) +{ + free(page_lookup); + free(readlookup2); + free(writelookup2); +} +#endif + + static void umc_page_recalc(uint32_t c, uint32_t phys, int set) { diff --git a/src/network/CMakeLists.txt b/src/network/CMakeLists.txt index 71f41f059..9d6b2efeb 100644 --- a/src/network/CMakeLists.txt +++ b/src/network/CMakeLists.txt @@ -70,5 +70,14 @@ if (UNIX) endif() endif() endif() +if (UNIX AND NOT APPLE) # Support for TAP on Linux and BSD, supposedly. + find_path(HAS_TAP "linux/if_tun.h" PATHS ${TAP_INCLUDE_DIR} "/usr/include /usr/local/include" "/opt/homebrew/include" ) + if(HAS_TAP) + add_compile_definitions(HAS_TAP) + list(APPEND net_sources net_tap.c) + else() + message(WARNING "TAP support not available. Are you on some BSD?") + endif() +endif() add_library(net OBJECT ${net_sources}) diff --git a/src/network/net_plip.c b/src/network/net_plip.c index 8c46213c6..ac8ab2850 100644 --- a/src/network/net_plip.c +++ b/src/network/net_plip.c @@ -488,15 +488,18 @@ plip_close(void *priv) } const lpt_device_t lpt_plip_device = { - .name = "Parallel Line Internet Protocol", - .internal_name = "plip", - .init = plip_lpt_init, - .close = plip_close, - .write_data = plip_write_data, - .write_ctrl = plip_write_ctrl, - .read_data = NULL, - .read_status = plip_read_status, - .read_ctrl = NULL + .name = "Parallel Line Internet Protocol", + .internal_name = "plip", + .init = plip_lpt_init, + .close = plip_close, + .write_data = plip_write_data, + .write_ctrl = plip_write_ctrl, + .autofeed = NULL, + .strobe = NULL, + .read_status = plip_read_status, + .read_ctrl = NULL, + .epp_write_data = NULL, + .epp_request_read = NULL }; const device_t plip_device = { diff --git a/src/network/net_tap.c b/src/network/net_tap.c new file mode 100644 index 000000000..762f68b60 --- /dev/null +++ b/src/network/net_tap.c @@ -0,0 +1,353 @@ +/* + * 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. + * + * Linux TAP network interface for 86box. + * + * This file was created by looking at the VDE network backend + * as a reference, credit to jguillaumes. + * + * Authors: Doug Johnson + * + * + * Copyright 2023 Doug Johnson + * + * 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. + * + * 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. + * + * 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 + * 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 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef _WIN32 +# error TAP networking is only supported on Linux +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define HAVE_STDARG_H + +#include <86box/86box.h> +#include <86box/device.h> +#include <86box/plat.h> +#include <86box/plat_dynld.h> +#include <86box/thread.h> +#include <86box/timer.h> +#include <86box/network.h> +#include <86box/net_event.h> + +typedef struct net_tap_t { + int fd; // tap device file descriptor + netcard_t *card; + thread_t *poll_tid; + net_evt_t tx_event; + net_evt_t stop_event; + netpkt_t pkt_rx; + netpkt_t pkts_tx[NET_QUEUE_LEN]; +} net_tap_t; + +#ifdef ENABLE_TAP_LOG +int tap_do_log = ENABLE_TAP_LOG; + + +static void tap_logv(const char *fmt, va_list ap) +{ + if (tap_do_log) { + pclog_ex(fmt, ap); + } +} + +static void tap_log(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + if (tap_do_log) { + va_start(ap, fmt); + tap_logv(fmt, ap); + va_end(ap); + } + va_end(ap); +} + +#else +# define tap_log(...) \ + do { \ + } while (0) +# define tap_logv(...) \ + do { \ + } while (0) +#endif + +static void net_tap_thread(void *priv) { + enum { + NET_EVENT_STOP = 0, + NET_EVENT_TX, + NET_EVENT_RX, + NET_EVENT_TAP, + NET_EVENT_MAX, + }; + net_tap_t *tap = priv; + tap_log("TAP: poll thread started.\n"); + struct pollfd pfd[NET_EVENT_MAX]; + pfd[NET_EVENT_STOP].fd = net_event_get_fd(&tap->stop_event); + pfd[NET_EVENT_STOP].events = POLLIN | POLLPRI; + + pfd[NET_EVENT_TX].fd = net_event_get_fd(&tap->tx_event); + pfd[NET_EVENT_TX].events = POLLIN | POLLPRI; + + pfd[NET_EVENT_RX].fd = tap->fd; + pfd[NET_EVENT_RX].events = POLLIN | POLLPRI; + + pfd[NET_EVENT_TAP].fd = tap->fd; + pfd[NET_EVENT_TAP].events = POLLERR | POLLHUP | POLLPRI; + fcntl(tap->fd, F_SETFL, O_NONBLOCK); + while(1) { + ssize_t ret = poll(pfd, NET_EVENT_MAX, -1); + if (ret < 0) { + tap_log("TAP: poll error: %s\n", strerror(errno)); + net_event_set(&tap->stop_event); + break; + } + if (pfd[NET_EVENT_TAP].revents) { + tap_log("TAP: tap close/error event received.\n"); + net_event_set(&tap->stop_event); + } + if (pfd[NET_EVENT_TX].revents & POLLIN) { + net_event_clear(&tap->tx_event); + int packets = network_tx_popv(tap->card, tap->pkts_tx, + NET_QUEUE_LEN); + for(int i = 0; i < packets; i++) { + netpkt_t *pkt = &tap->pkts_tx[i]; + ssize_t ret = write(tap->fd, pkt->data, pkt->len); + if (ret < 0) { + tap_log("TAP: write error: %s\n", strerror(errno)); + } + } + } + if (pfd[NET_EVENT_RX].revents & POLLIN) { + ssize_t len = read(tap->fd, tap->pkt_rx.data, NET_MAX_FRAME); + if (len < 0) { + tap_log("TAP: read error: %s\n", strerror(errno)); + continue; + } + tap->pkt_rx.len = len; + network_rx_put_pkt(tap->card, &tap->pkt_rx); + } + if (pfd[NET_EVENT_STOP].revents & POLLIN) { + net_event_clear(&tap->stop_event); + break; + } + } +} + +void net_tap_close(void *priv) +{ + if (!priv) { + return; + } + net_tap_t *tap = priv; + tap_log("TAP: closing.\n"); + net_event_set(&tap->stop_event); + tap_log("TAP: waiting for poll thread to exit.\n"); + thread_wait(tap->poll_tid); + tap_log("TAP: poll thread exited.\n"); + for(int i = 0; i < NET_QUEUE_LEN; i++) { + free(tap->pkts_tx[i].data); + } + free(tap->pkt_rx.data); + if (tap->fd >= 0) { + close(tap->fd); + } + free(tap); +} + +void net_tap_error(char *errbuf, const char* format, ...) +{ + va_list ap; + va_start(ap, format); + vsnprintf(errbuf, NET_DRV_ERRBUF_SIZE, format, ap); + tap_log("TAP: %s", errbuf); + va_end(ap); +} + +// Error handling macro for the many ioctl calls we use in net_tap_alloc +#define ioctl_or_fail(fd, request, argp) \ + do { \ + if ((err = ioctl(fd, request, argp)) < 0) { \ + tap_log("TAP: ioctl " #request " error: %s\n", strerror(errno)); \ + goto fail; \ + } \ + } while (0) + +// Returns -ERRNO so we can get an idea what's wrong +int net_tap_alloc(const uint8_t *mac_addr, const char* bridge_dev) +{ + int fd; + struct ifreq ifr = {0}; + if ((fd = open("/dev/net/tun", O_RDWR)) < 0) { + tap_log("TAP: open error: %s\n", strerror(errno)); + return -errno; + } + ifr.ifr_flags = IFF_TAP | IFF_NO_PI; + int err; + if ((err = ioctl(fd, TUNSETIFF, &ifr)) < 0) { + tap_log("TAP: ioctl TUNSETIFF error: %s\n", strerror(errno)); + close(fd); + return -errno; + } + // Create a socket for ioctl operations + int sock; + if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + tap_log("TAP: socket error: %s\n", strerror(errno)); + close(fd); + return -errno; + } + // Bring the interface up + tap_log("TAP: Bringing interface '%s' up.\n", ifr.ifr_name); + ifr.ifr_flags = IFF_UP; + ioctl_or_fail(sock, SIOCSIFFLAGS, &ifr); + // Add interface to bridge, if specified + if (bridge_dev && bridge_dev[0] != '\0') { + // First see if the bridge exists + struct ifreq ifr_bridge; + //NOTE strncpy does not null terminate if the string is too long, I use + // snprintf or strlcpy instead + //strncpy(ifr_bridge.ifr_name, bridge_dev, IFNAMSIZ); + snprintf(ifr_bridge.ifr_name, IFNAMSIZ, "%s", bridge_dev); + if ((err = ioctl(sock, SIOCGIFINDEX, &ifr_bridge)) < 0) { + if (errno != ENODEV) { + tap_log("TAP: ioctl SIOCGIFINDEX error: %s\n", strerror(errno)); + goto fail; + } else { + // Create the bridge + ioctl_or_fail(sock, SIOCBRADDBR, &ifr_bridge); + // Set the bridge up + ifr_bridge.ifr_flags = IFF_UP; + ioctl_or_fail(sock, SIOCSIFFLAGS, &ifr_bridge); + } + } + // Get TAP index + ioctl_or_fail(sock, SIOCGIFINDEX, &ifr); + // Add the tap device to the bridge + ifr_bridge.ifr_ifindex = ifr.ifr_ifindex; + ioctl_or_fail(sock, SIOCBRADDIF, &ifr_bridge); + } + // close the socket we used for ioctl operations + close(sock); + tap_log("Allocated tap device %s\n", ifr.ifr_name); + return fd; + // cleanup point used by ioctl_or_fail macro +fail: + close(sock); + close(fd); + return -errno; +} + +void net_tap_in_available(void *priv) +{ + net_tap_t *tap = priv; + net_event_set(&tap->tx_event); +} + +void * +net_tap_init( + const netcard_t *card, + const uint8_t *mac_addr, + void *priv, + char *netdrv_errbuf) +{ + const char *bridge_dev = (void *) priv; + int tap_fd = net_tap_alloc(mac_addr, bridge_dev); + if (tap_fd < 0) { + if (tap_fd == -EPERM) { + net_tap_error( + netdrv_errbuf, + "No permissions to allocate tap device. " + "Try adding NET_CAP_ADMIN,NET_CAP_RAW to 86box (" + "sudo setcap 'CAP_NET_RAW,CAP_NET_ADMIN=eip')"); + } else { + net_tap_error( + netdrv_errbuf, + "Unable to allocate TAP device: %s", + strerror(-tap_fd)); + } + return NULL; + } + if (bridge_dev && bridge_dev[0] != '\0') { + } + net_tap_t *tap = calloc(1, sizeof(net_tap_t)); + if (!tap) { + goto alloc_fail; + } + tap->pkt_rx.data = calloc(1, NET_MAX_FRAME); + if (!tap->pkt_rx.data) { + goto alloc_fail; + } + for(int i = 0; i < NET_QUEUE_LEN; i++) { + tap->pkts_tx[i].data = calloc(1, NET_MAX_FRAME); + if (!tap->pkts_tx[i].data) { + goto alloc_fail; + } + } + tap->fd = tap_fd; + tap->card = (netcard_t *) card; + net_event_init(&tap->tx_event); + net_event_init(&tap->stop_event); + tap->poll_tid = thread_create(net_tap_thread, tap); + return tap; +alloc_fail: + net_tap_error(netdrv_errbuf, "Failed to allocate memory"); + close(tap_fd); + free(tap); + return NULL; +} + +const netdrv_t net_tap_drv = { + &net_tap_in_available, + &net_tap_init, + &net_tap_close, + NULL +}; diff --git a/src/network/network.c b/src/network/network.c index 239178a5d..0372a57fc 100644 --- a/src/network/network.c +++ b/src/network/network.c @@ -85,36 +85,43 @@ static const NETWORK_CARD net_cards[] = { // clang-format off { &device_none }, { &device_internal }, + /* ISA */ { &threec501_device }, { &threec503_device }, - { &pcnet_am79c960_device }, - { &pcnet_am79c961_device }, - { &de220p_device }, { &ne1000_compat_device }, - { &ne2000_compat_device }, { &ne2000_compat_8bit_device }, { &ne1000_device }, - { &ne2000_device }, - { &pcnet_am79c960_eb_device }, - { &rtl8019as_pnp_device }, { &wd8003e_device }, { &wd8003eb_device }, { &wd8013ebt_device }, + /* COM */ + { &modem_device }, + /* LPT */ { &plip_device }, + /* ISA16 */ + { &pcnet_am79c960_device }, + { &pcnet_am79c961_device }, + { &de220p_device }, + { &ne2000_compat_device }, + { &ne2000_device }, + { &pcnet_am79c960_eb_device }, + { &rtl8019as_pnp_device }, + /* MCA */ { ðernext_mc_device }, { &wd8003eta_device }, { &wd8003ea_device }, { &wd8013epa_device }, + /* VLB */ + { &pcnet_am79c960_vlb_device }, + /* PCI */ { &pcnet_am79c973_device }, { &pcnet_am79c970a_device }, + { &dec_tulip_21140_device }, + { &dec_tulip_21040_device }, { &dec_tulip_device }, + { &dec_tulip_21140_vpc_device }, { &rtl8029as_device }, { &rtl8139c_plus_device }, - { &dec_tulip_21140_device }, - { &dec_tulip_21140_vpc_device }, - { &dec_tulip_21040_device }, - { &pcnet_am79c960_vlb_device }, - { &modem_device }, { NULL } // clang-format on }; @@ -489,6 +496,12 @@ network_attach(void *card_drv, uint8_t *mac, NETRXCB rx, NETSETLINKSTATE set_lin card->host_drv = net_vde_drv; card->host_drv.priv = card->host_drv.init(card, mac, net_cards_conf[net_card_current].host_dev_name, net_drv_error); break; +#endif +#ifdef HAS_TAP + case NET_TYPE_TAP: + card->host_drv = net_tap_drv; + card->host_drv.priv = card->host_drv.init(card, mac, net_cards_conf[net_card_current].host_dev_name, net_drv_error); + break; #endif default: card->host_drv.priv = NULL; diff --git a/src/nvr.c b/src/nvr.c index 7f43a76c1..b6bf2a5a5 100644 --- a/src/nvr.c +++ b/src/nvr.c @@ -310,18 +310,25 @@ nvr_close(void) void nvr_time_sync(void) { - struct tm *tm; - time_t now; + struct tm tm; + time_t now; /* Get the current time of day, and convert to local time. */ (void) time(&now); - if (time_sync & TIME_SYNC_UTC) - tm = gmtime(&now); - else - tm = localtime(&now); - /* Set the internal clock. */ - nvr_time_set(tm); +#ifdef _WIN32 + if (time_sync & TIME_SYNC_UTC) + gmtime_s(&tm, &now); + else + localtime_s(&tm, &now); +#else + if (time_sync & TIME_SYNC_UTC) + gmtime_r(&now, &tm); + else + localtime_r(&now, &tm); +#endif + + nvr_time_set(&tm); } /* Get current time from internal clock. */ diff --git a/src/printer/prt_escp.c b/src/printer/prt_escp.c index f238341c5..41c81e696 100644 --- a/src/printer/prt_escp.c +++ b/src/printer/prt_escp.c @@ -1881,6 +1881,39 @@ write_data(uint8_t val, void *priv) dev->data = val; } +static void +autofeed(uint8_t val, void *priv) +{ + escp_t *dev = (escp_t *) priv; + + if (dev == NULL) + return; + + dev->autofeed = ((val & 0x02) > 0); +} + +static void +strobe(uint8_t old, uint8_t val, void *priv) +{ + escp_t *dev = (escp_t *) priv; + + if (dev == NULL) + return; + + /* Data is strobed to the parallel printer on the falling edge of the + strobe bit. */ + if (!(val & 0x01) && (old & 0x01)) { + /* Process incoming character. */ + handle_char(dev, dev->data); + + /* ACK it, will be read on next READ STATUS. */ + dev->ack = 1; + timer_set_delay_u64(&dev->pulse_timer, ISACONST); + + timer_set_delay_u64(&dev->timeout_timer, 5000000 * TIMER_USEC); + } +} + static void write_ctrl(uint8_t val, void *priv) { @@ -1919,14 +1952,6 @@ write_ctrl(uint8_t val, void *priv) dev->autofeed = ((val & 0x02) > 0); } -static uint8_t -read_data(void *priv) -{ - const escp_t *dev = (escp_t *) priv; - - return dev->data; -} - static uint8_t read_ctrl(void *priv) { @@ -2058,13 +2083,16 @@ escp_close(void *priv) } const lpt_device_t lpt_prt_escp_device = { - .name = "Generic ESC/P Dot-Matrix Printer", - .internal_name = "dot_matrix", - .init = escp_init, - .close = escp_close, - .write_data = write_data, - .write_ctrl = write_ctrl, - .read_data = read_data, - .read_status = read_status, - .read_ctrl = read_ctrl + .name = "Generic ESC/P Dot-Matrix", + .internal_name = "dot_matrix", + .init = escp_init, + .close = escp_close, + .write_data = write_data, + .write_ctrl = write_ctrl, + .autofeed = autofeed, + .strobe = strobe, + .read_status = read_status, + .read_ctrl = read_ctrl, + .epp_write_data = NULL, + .epp_request_read = NULL }; diff --git a/src/printer/prt_ps.c b/src/printer/prt_ps.c index 1298018ee..904ff34ad 100644 --- a/src/printer/prt_ps.c +++ b/src/printer/prt_ps.c @@ -319,6 +319,35 @@ process_data(ps_t *dev) dev->buffer[dev->buffer_pos] = 0; } +static void +ps_autofeed(uint8_t val, void *priv) +{ + ps_t *dev = (ps_t *) priv; + + if (dev == NULL) + return; + + dev->autofeed = val & 0x02 ? true : false; +} + +static void +ps_strobe(uint8_t old, uint8_t val, void *priv) +{ + ps_t *dev = (ps_t *) priv; + + if (dev == NULL) + return; + + if (!(val & 0x01) && (old & 0x01)) { + process_data(dev); + + dev->ack = true; + + timer_set_delay_u64(&dev->pulse_timer, ISACONST); + timer_set_delay_u64(&dev->timeout_timer, 5000000 * TIMER_USEC); + } +} + static void ps_write_ctrl(uint8_t val, void *priv) { @@ -479,27 +508,33 @@ ps_close(void *priv) } const lpt_device_t lpt_prt_ps_device = { - .name = "Generic PostScript Printer", - .internal_name = "postscript", - .init = ps_init, - .close = ps_close, - .write_data = ps_write_data, - .write_ctrl = ps_write_ctrl, - .read_data = NULL, - .read_status = ps_read_status, - .read_ctrl = NULL + .name = "Generic PostScript Printer", + .internal_name = "postscript", + .init = ps_init, + .close = ps_close, + .write_data = ps_write_data, + .write_ctrl = ps_write_ctrl, + .autofeed = ps_autofeed, + .strobe = ps_strobe, + .read_status = ps_read_status, + .read_ctrl = NULL, + .epp_write_data = NULL, + .epp_request_read = NULL }; #ifdef USE_PCL const lpt_device_t lpt_prt_pcl_device = { - .name = "Generic PCL5e Printer", - .internal_name = "pcl", - .init = pcl_init, - .close = ps_close, - .write_data = ps_write_data, - .write_ctrl = ps_write_ctrl, - .read_data = NULL, - .read_status = ps_read_status, - .read_ctrl = NULL + .name = "Generic PCL5e Printer", + .internal_name = "pcl", + .init = pcl_init, + .close = ps_close, + .write_data = ps_write_data, + .write_ctrl = ps_write_ctrl, + .autofeed = ps_autofeed, + .strobe = ps_strobe, + .read_status = ps_read_status, + .read_ctrl = NULL, + .epp_write_data = NULL, + .epp_request_read = NULL }; #endif diff --git a/src/printer/prt_text.c b/src/printer/prt_text.c index e04ef9680..7604d023e 100644 --- a/src/printer/prt_text.c +++ b/src/printer/prt_text.c @@ -367,6 +367,38 @@ write_data(uint8_t val, void *priv) dev->data = val; } +static void +autofeed(uint8_t val, void *priv) +{ + prnt_t *dev = (prnt_t *) priv; + + if (dev == NULL) + return; + + /* set autofeed value */ + dev->autofeed = val & 0x02 ? 1 : 0; +} + +static void +strobe(uint8_t old, uint8_t val, void *priv) +{ + prnt_t *dev = (prnt_t *) priv; + + if (dev == NULL) + return; + + if (!(val & 0x01) && (old & 0x01)) { /* STROBE */ + /* Process incoming character. */ + handle_char(dev); + + /* ACK it, will be read on next READ STATUS. */ + dev->ack = 1; + + timer_set_delay_u64(&dev->pulse_timer, ISACONST); + timer_set_delay_u64(&dev->timeout_timer, 5000000 * TIMER_USEC); + } +} + static void write_ctrl(uint8_t val, void *priv) { @@ -465,13 +497,16 @@ prnt_close(void *priv) } const lpt_device_t lpt_prt_text_device = { - .name = "Generic Text Printer", - .internal_name = "text_prt", - .init = prnt_init, - .close = prnt_close, - .write_data = write_data, - .write_ctrl = write_ctrl, - .read_data = NULL, - .read_status = read_status, - .read_ctrl = NULL + .name = "Generic Text Printer", + .internal_name = "text_prt", + .init = prnt_init, + .close = prnt_close, + .write_data = write_data, + .write_ctrl = write_ctrl, + .autofeed = autofeed, + .strobe = strobe, + .read_status = read_status, + .read_ctrl = NULL, + .epp_write_data = NULL, + .epp_request_read = NULL }; diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index df13d42e2..076d5cc42 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -85,8 +85,6 @@ add_library(ui STATIC qt_renderercommon.hpp qt_softwarerenderer.cpp qt_softwarerenderer.hpp - qt_hardwarerenderer.cpp - qt_hardwarerenderer.hpp qt_openglrenderer.cpp qt_openglrenderer.hpp qt_glsl_parser.cpp @@ -189,6 +187,49 @@ add_library(ui STATIC qt_mediahistorymanager.cpp qt_mediahistorymanager.hpp + qt_updatecheck.cpp + qt_updatecheck.hpp + qt_updatecheckdialog.cpp + qt_updatecheckdialog.hpp + qt_updatecheckdialog.ui + qt_updatedetails.cpp + qt_updatedetails.hpp + qt_updatedetails.ui + qt_downloader.cpp + qt_downloader.hpp + + qt_vmmanager_clientsocket.cpp + qt_vmmanager_clientsocket.hpp + qt_vmmanager_serversocket.cpp + qt_vmmanager_serversocket.hpp + qt_vmmanager_protocol.cpp + qt_vmmanager_protocol.hpp + qt_vmmanager_details.hpp + qt_vmmanager_details.cpp + qt_vmmanager_details.ui + qt_vmmanager_addmachine.cpp + qt_vmmanager_addmachine.hpp + qt_vmmanager_detailsection.cpp + qt_vmmanager_detailsection.hpp + qt_vmmanager_detailsection.ui + qt_vmmanager_listviewdelegate.hpp + qt_vmmanager_listviewdelegate.cpp + qt_vmmanager_preferences.cpp + qt_vmmanager_preferences.hpp + qt_vmmanager_preferences.ui + qt_vmmanager_main.hpp + qt_vmmanager_main.cpp + qt_vmmanager_main.ui + qt_vmmanager_model.cpp + qt_vmmanager_model.hpp + qt_vmmanager_system.cpp + qt_vmmanager_system.hpp + qt_vmmanager_config.cpp + qt_vmmanager_config.hpp + qt_vmmanager_mainwindow.cpp + qt_vmmanager_mainwindow.hpp + qt_vmmanager_mainwindow.ui + ../qt_resources.qrc ./qdarkstyle/dark/darkstyle.qrc diff --git a/src/qt/assets/86box-wizard.png b/src/qt/assets/86box-wizard.png new file mode 100644 index 000000000..19ecda8c7 Binary files /dev/null and b/src/qt/assets/86box-wizard.png differ diff --git a/src/qt/assets/systemicons/cpq_deskpro.png b/src/qt/assets/systemicons/cpq_deskpro.png new file mode 100644 index 000000000..1bbca68a3 Binary files /dev/null and b/src/qt/assets/systemicons/cpq_deskpro.png differ diff --git a/src/qt/assets/systemicons/cpq_port_386.png b/src/qt/assets/systemicons/cpq_port_386.png new file mode 100644 index 000000000..4c55b3559 Binary files /dev/null and b/src/qt/assets/systemicons/cpq_port_386.png differ diff --git a/src/qt/assets/systemicons/cpq_port_II.png b/src/qt/assets/systemicons/cpq_port_II.png new file mode 100644 index 000000000..3254d9b5e Binary files /dev/null and b/src/qt/assets/systemicons/cpq_port_II.png differ diff --git a/src/qt/assets/systemicons/cpq_port_III.png b/src/qt/assets/systemicons/cpq_port_III.png new file mode 100644 index 000000000..65d2f714e Binary files /dev/null and b/src/qt/assets/systemicons/cpq_port_III.png differ diff --git a/src/qt/assets/systemicons/cpq_portable.png b/src/qt/assets/systemicons/cpq_portable.png new file mode 100644 index 000000000..d3dc381e4 Binary files /dev/null and b/src/qt/assets/systemicons/cpq_portable.png differ diff --git a/src/qt/assets/systemicons/cpq_pres_2240.png b/src/qt/assets/systemicons/cpq_pres_2240.png new file mode 100644 index 000000000..c50043cdd Binary files /dev/null and b/src/qt/assets/systemicons/cpq_pres_2240.png differ diff --git a/src/qt/assets/systemicons/cpq_pres_4500.png b/src/qt/assets/systemicons/cpq_pres_4500.png new file mode 100644 index 000000000..edd955b5a Binary files /dev/null and b/src/qt/assets/systemicons/cpq_pres_4500.png differ diff --git a/src/qt/assets/systemicons/ibm330.png b/src/qt/assets/systemicons/ibm330.png new file mode 100644 index 000000000..90637dc4c Binary files /dev/null and b/src/qt/assets/systemicons/ibm330.png differ diff --git a/src/qt/assets/systemicons/ibm_at.png b/src/qt/assets/systemicons/ibm_at.png new file mode 100644 index 000000000..e6710180e Binary files /dev/null and b/src/qt/assets/systemicons/ibm_at.png differ diff --git a/src/qt/assets/systemicons/ibm_pc_81.png b/src/qt/assets/systemicons/ibm_pc_81.png new file mode 100644 index 000000000..4f398d468 Binary files /dev/null and b/src/qt/assets/systemicons/ibm_pc_81.png differ diff --git a/src/qt/assets/systemicons/ibm_pc_82.png b/src/qt/assets/systemicons/ibm_pc_82.png new file mode 100644 index 000000000..4f398d468 Binary files /dev/null and b/src/qt/assets/systemicons/ibm_pc_82.png differ diff --git a/src/qt/assets/systemicons/ibm_pcjr.png b/src/qt/assets/systemicons/ibm_pcjr.png new file mode 100644 index 000000000..1f3014bb4 Binary files /dev/null and b/src/qt/assets/systemicons/ibm_pcjr.png differ diff --git a/src/qt/assets/systemicons/ibm_ps2_m70.png b/src/qt/assets/systemicons/ibm_ps2_m70.png new file mode 100644 index 000000000..af433ebb3 Binary files /dev/null and b/src/qt/assets/systemicons/ibm_ps2_m70.png differ diff --git a/src/qt/assets/systemicons/ibm_ps2_m80.png b/src/qt/assets/systemicons/ibm_ps2_m80.png new file mode 100644 index 000000000..9df02adff Binary files /dev/null and b/src/qt/assets/systemicons/ibm_ps2_m80.png differ diff --git a/src/qt/assets/systemicons/ibm_psvp_486.png b/src/qt/assets/systemicons/ibm_psvp_486.png new file mode 100644 index 000000000..af5a95675 Binary files /dev/null and b/src/qt/assets/systemicons/ibm_psvp_486.png differ diff --git a/src/qt/assets/systemicons/ibm_psvp_p60.png b/src/qt/assets/systemicons/ibm_psvp_p60.png new file mode 100644 index 000000000..af5a95675 Binary files /dev/null and b/src/qt/assets/systemicons/ibm_psvp_p60.png differ diff --git a/src/qt/assets/systemicons/ibm_xt_82.png b/src/qt/assets/systemicons/ibm_xt_82.png new file mode 100644 index 000000000..4f398d468 Binary files /dev/null and b/src/qt/assets/systemicons/ibm_xt_82.png differ diff --git a/src/qt/assets/systemicons/ibm_xt_86.png b/src/qt/assets/systemicons/ibm_xt_86.png new file mode 100644 index 000000000..4f398d468 Binary files /dev/null and b/src/qt/assets/systemicons/ibm_xt_86.png differ diff --git a/src/qt/assets/systemicons/olivetti_m19.png b/src/qt/assets/systemicons/olivetti_m19.png new file mode 100644 index 000000000..766e335f7 Binary files /dev/null and b/src/qt/assets/systemicons/olivetti_m19.png differ diff --git a/src/qt/assets/systemicons/olivetti_m21.png b/src/qt/assets/systemicons/olivetti_m21.png new file mode 100644 index 000000000..5e0ee4b52 Binary files /dev/null and b/src/qt/assets/systemicons/olivetti_m21.png differ diff --git a/src/qt/assets/systemicons/olivetti_m24.png b/src/qt/assets/systemicons/olivetti_m24.png new file mode 100644 index 000000000..e48356c32 Binary files /dev/null and b/src/qt/assets/systemicons/olivetti_m24.png differ diff --git a/src/qt/assets/systemicons/olivetti_m24sp.png b/src/qt/assets/systemicons/olivetti_m24sp.png new file mode 100644 index 000000000..e48356c32 Binary files /dev/null and b/src/qt/assets/systemicons/olivetti_m24sp.png differ diff --git a/src/qt/assets/systemicons/os_archlinux_x2.png b/src/qt/assets/systemicons/os_archlinux_x2.png new file mode 100644 index 000000000..1b218a76f Binary files /dev/null and b/src/qt/assets/systemicons/os_archlinux_x2.png differ diff --git a/src/qt/assets/systemicons/os_cloud_x2.png b/src/qt/assets/systemicons/os_cloud_x2.png new file mode 100644 index 000000000..9bd42f9ac Binary files /dev/null and b/src/qt/assets/systemicons/os_cloud_x2.png differ diff --git a/src/qt/assets/systemicons/os_debian_x2.png b/src/qt/assets/systemicons/os_debian_x2.png new file mode 100644 index 000000000..a6644c33d Binary files /dev/null and b/src/qt/assets/systemicons/os_debian_x2.png differ diff --git a/src/qt/assets/systemicons/os_dos_x2.png b/src/qt/assets/systemicons/os_dos_x2.png new file mode 100644 index 000000000..b6df56ef5 Binary files /dev/null and b/src/qt/assets/systemicons/os_dos_x2.png differ diff --git a/src/qt/assets/systemicons/os_fedora_x2.png b/src/qt/assets/systemicons/os_fedora_x2.png new file mode 100644 index 000000000..120d247a8 Binary files /dev/null and b/src/qt/assets/systemicons/os_fedora_x2.png differ diff --git a/src/qt/assets/systemicons/os_freebsd_x2.png b/src/qt/assets/systemicons/os_freebsd_x2.png new file mode 100644 index 000000000..dd6f88d41 Binary files /dev/null and b/src/qt/assets/systemicons/os_freebsd_x2.png differ diff --git a/src/qt/assets/systemicons/os_gentoo_x2.png b/src/qt/assets/systemicons/os_gentoo_x2.png new file mode 100644 index 000000000..f27afa5fc Binary files /dev/null and b/src/qt/assets/systemicons/os_gentoo_x2.png differ diff --git a/src/qt/assets/systemicons/os_jrockitve_x2.png b/src/qt/assets/systemicons/os_jrockitve_x2.png new file mode 100644 index 000000000..4283cad5e Binary files /dev/null and b/src/qt/assets/systemicons/os_jrockitve_x2.png differ diff --git a/src/qt/assets/systemicons/os_l4_x2.png b/src/qt/assets/systemicons/os_l4_x2.png new file mode 100644 index 000000000..9fbbaa183 Binary files /dev/null and b/src/qt/assets/systemicons/os_l4_x2.png differ diff --git a/src/qt/assets/systemicons/os_linux22_x2.png b/src/qt/assets/systemicons/os_linux22_x2.png new file mode 100644 index 000000000..0de56653a Binary files /dev/null and b/src/qt/assets/systemicons/os_linux22_x2.png differ diff --git a/src/qt/assets/systemicons/os_linux24_x2.png b/src/qt/assets/systemicons/os_linux24_x2.png new file mode 100644 index 000000000..b3df83b7f Binary files /dev/null and b/src/qt/assets/systemicons/os_linux24_x2.png differ diff --git a/src/qt/assets/systemicons/os_linux26_x2.png b/src/qt/assets/systemicons/os_linux26_x2.png new file mode 100644 index 000000000..8fdf52df7 Binary files /dev/null and b/src/qt/assets/systemicons/os_linux26_x2.png differ diff --git a/src/qt/assets/systemicons/os_linux_x2.png b/src/qt/assets/systemicons/os_linux_x2.png new file mode 100644 index 000000000..d4c2eeebe Binary files /dev/null and b/src/qt/assets/systemicons/os_linux_x2.png differ diff --git a/src/qt/assets/systemicons/os_macosx_x2.png b/src/qt/assets/systemicons/os_macosx_x2.png new file mode 100644 index 000000000..38eb2e5a7 Binary files /dev/null and b/src/qt/assets/systemicons/os_macosx_x2.png differ diff --git a/src/qt/assets/systemicons/os_mandriva_x2.png b/src/qt/assets/systemicons/os_mandriva_x2.png new file mode 100644 index 000000000..a09e9c170 Binary files /dev/null and b/src/qt/assets/systemicons/os_mandriva_x2.png differ diff --git a/src/qt/assets/systemicons/os_netbsd_x2.png b/src/qt/assets/systemicons/os_netbsd_x2.png new file mode 100644 index 000000000..9fa38a7a6 Binary files /dev/null and b/src/qt/assets/systemicons/os_netbsd_x2.png differ diff --git a/src/qt/assets/systemicons/os_netware_x2.png b/src/qt/assets/systemicons/os_netware_x2.png new file mode 100644 index 000000000..4bcc96521 Binary files /dev/null and b/src/qt/assets/systemicons/os_netware_x2.png differ diff --git a/src/qt/assets/systemicons/os_openbsd_x2.png b/src/qt/assets/systemicons/os_openbsd_x2.png new file mode 100644 index 000000000..13ae3a0db Binary files /dev/null and b/src/qt/assets/systemicons/os_openbsd_x2.png differ diff --git a/src/qt/assets/systemicons/os_opensuse_x2.png b/src/qt/assets/systemicons/os_opensuse_x2.png new file mode 100644 index 000000000..4d1696d9b Binary files /dev/null and b/src/qt/assets/systemicons/os_opensuse_x2.png differ diff --git a/src/qt/assets/systemicons/os_oracle_x2.png b/src/qt/assets/systemicons/os_oracle_x2.png new file mode 100644 index 000000000..545e885cb Binary files /dev/null and b/src/qt/assets/systemicons/os_oracle_x2.png differ diff --git a/src/qt/assets/systemicons/os_oraclesolaris_x2.png b/src/qt/assets/systemicons/os_oraclesolaris_x2.png new file mode 100644 index 000000000..8db66abe3 Binary files /dev/null and b/src/qt/assets/systemicons/os_oraclesolaris_x2.png differ diff --git a/src/qt/assets/systemicons/os_os2_other_x2.png b/src/qt/assets/systemicons/os_os2_other_x2.png new file mode 100644 index 000000000..2d37846a0 Binary files /dev/null and b/src/qt/assets/systemicons/os_os2_other_x2.png differ diff --git a/src/qt/assets/systemicons/os_os2ecs_x2.png b/src/qt/assets/systemicons/os_os2ecs_x2.png new file mode 100644 index 000000000..261f9f56c Binary files /dev/null and b/src/qt/assets/systemicons/os_os2ecs_x2.png differ diff --git a/src/qt/assets/systemicons/os_os2warp3_x2.png b/src/qt/assets/systemicons/os_os2warp3_x2.png new file mode 100644 index 000000000..1be5a696c Binary files /dev/null and b/src/qt/assets/systemicons/os_os2warp3_x2.png differ diff --git a/src/qt/assets/systemicons/os_os2warp45_x2.png b/src/qt/assets/systemicons/os_os2warp45_x2.png new file mode 100644 index 000000000..d1a4df0c2 Binary files /dev/null and b/src/qt/assets/systemicons/os_os2warp45_x2.png differ diff --git a/src/qt/assets/systemicons/os_os2warp4_x2.png b/src/qt/assets/systemicons/os_os2warp4_x2.png new file mode 100644 index 000000000..0a81c8759 Binary files /dev/null and b/src/qt/assets/systemicons/os_os2warp4_x2.png differ diff --git a/src/qt/assets/systemicons/os_other_x2.png b/src/qt/assets/systemicons/os_other_x2.png new file mode 100644 index 000000000..9602353c0 Binary files /dev/null and b/src/qt/assets/systemicons/os_other_x2.png differ diff --git a/src/qt/assets/systemicons/os_qnx_x2.png b/src/qt/assets/systemicons/os_qnx_x2.png new file mode 100644 index 000000000..b124cfa6e Binary files /dev/null and b/src/qt/assets/systemicons/os_qnx_x2.png differ diff --git a/src/qt/assets/systemicons/os_redhat_x2.png b/src/qt/assets/systemicons/os_redhat_x2.png new file mode 100644 index 000000000..a756e8aac Binary files /dev/null and b/src/qt/assets/systemicons/os_redhat_x2.png differ diff --git a/src/qt/assets/systemicons/os_solaris_x2.png b/src/qt/assets/systemicons/os_solaris_x2.png new file mode 100644 index 000000000..2dfd2ac74 Binary files /dev/null and b/src/qt/assets/systemicons/os_solaris_x2.png differ diff --git a/src/qt/assets/systemicons/os_turbolinux_x2.png b/src/qt/assets/systemicons/os_turbolinux_x2.png new file mode 100644 index 000000000..4d5ee4ab1 Binary files /dev/null and b/src/qt/assets/systemicons/os_turbolinux_x2.png differ diff --git a/src/qt/assets/systemicons/os_ubuntu_x2.png b/src/qt/assets/systemicons/os_ubuntu_x2.png new file mode 100644 index 000000000..9b6302b37 Binary files /dev/null and b/src/qt/assets/systemicons/os_ubuntu_x2.png differ diff --git a/src/qt/assets/systemicons/os_win10_x2.png b/src/qt/assets/systemicons/os_win10_x2.png new file mode 100644 index 000000000..1d6e81392 Binary files /dev/null and b/src/qt/assets/systemicons/os_win10_x2.png differ diff --git a/src/qt/assets/systemicons/os_win2k3_x2.png b/src/qt/assets/systemicons/os_win2k3_x2.png new file mode 100644 index 000000000..45bec005d Binary files /dev/null and b/src/qt/assets/systemicons/os_win2k3_x2.png differ diff --git a/src/qt/assets/systemicons/os_win2k8_x2.png b/src/qt/assets/systemicons/os_win2k8_x2.png new file mode 100644 index 000000000..d97a2789d Binary files /dev/null and b/src/qt/assets/systemicons/os_win2k8_x2.png differ diff --git a/src/qt/assets/systemicons/os_win2k_x2.png b/src/qt/assets/systemicons/os_win2k_x2.png new file mode 100644 index 000000000..a773288ed Binary files /dev/null and b/src/qt/assets/systemicons/os_win2k_x2.png differ diff --git a/src/qt/assets/systemicons/os_win31_x2.png b/src/qt/assets/systemicons/os_win31_x2.png new file mode 100644 index 000000000..5ca2005d6 Binary files /dev/null and b/src/qt/assets/systemicons/os_win31_x2.png differ diff --git a/src/qt/assets/systemicons/os_win7_x2.png b/src/qt/assets/systemicons/os_win7_x2.png new file mode 100644 index 000000000..c8ce57a2b Binary files /dev/null and b/src/qt/assets/systemicons/os_win7_x2.png differ diff --git a/src/qt/assets/systemicons/os_win81_x2.png b/src/qt/assets/systemicons/os_win81_x2.png new file mode 100644 index 000000000..07131ed6c Binary files /dev/null and b/src/qt/assets/systemicons/os_win81_x2.png differ diff --git a/src/qt/assets/systemicons/os_win8_x2.png b/src/qt/assets/systemicons/os_win8_x2.png new file mode 100644 index 000000000..ff94c2dd1 Binary files /dev/null and b/src/qt/assets/systemicons/os_win8_x2.png differ diff --git a/src/qt/assets/systemicons/os_win95_x2.png b/src/qt/assets/systemicons/os_win95_x2.png new file mode 100644 index 000000000..efd62799e Binary files /dev/null and b/src/qt/assets/systemicons/os_win95_x2.png differ diff --git a/src/qt/assets/systemicons/os_win98_x2.png b/src/qt/assets/systemicons/os_win98_x2.png new file mode 100644 index 000000000..c8fa4e7bb Binary files /dev/null and b/src/qt/assets/systemicons/os_win98_x2.png differ diff --git a/src/qt/assets/systemicons/os_win_other_x2.png b/src/qt/assets/systemicons/os_win_other_x2.png new file mode 100644 index 000000000..fac95889f Binary files /dev/null and b/src/qt/assets/systemicons/os_win_other_x2.png differ diff --git a/src/qt/assets/systemicons/os_winme_x2.png b/src/qt/assets/systemicons/os_winme_x2.png new file mode 100644 index 000000000..1c268c84b Binary files /dev/null and b/src/qt/assets/systemicons/os_winme_x2.png differ diff --git a/src/qt/assets/systemicons/os_winnt4_x2.png b/src/qt/assets/systemicons/os_winnt4_x2.png new file mode 100644 index 000000000..c3352abcd Binary files /dev/null and b/src/qt/assets/systemicons/os_winnt4_x2.png differ diff --git a/src/qt/assets/systemicons/os_winvista_x2.png b/src/qt/assets/systemicons/os_winvista_x2.png new file mode 100644 index 000000000..7b633b79f Binary files /dev/null and b/src/qt/assets/systemicons/os_winvista_x2.png differ diff --git a/src/qt/assets/systemicons/os_winxp_x2.png b/src/qt/assets/systemicons/os_winxp_x2.png new file mode 100644 index 000000000..b97e6b51d Binary files /dev/null and b/src/qt/assets/systemicons/os_winxp_x2.png differ diff --git a/src/qt/assets/systemicons/os_xandros_x2.png b/src/qt/assets/systemicons/os_xandros_x2.png new file mode 100644 index 000000000..23de5ca91 Binary files /dev/null and b/src/qt/assets/systemicons/os_xandros_x2.png differ diff --git a/src/qt/assets/systemicons/pb_bora_pro.png b/src/qt/assets/systemicons/pb_bora_pro.png new file mode 100644 index 000000000..6aaaf9d26 Binary files /dev/null and b/src/qt/assets/systemicons/pb_bora_pro.png differ diff --git a/src/qt/assets/systemicons/pb_pb410.png b/src/qt/assets/systemicons/pb_pb410.png new file mode 100644 index 000000000..c78c0496b Binary files /dev/null and b/src/qt/assets/systemicons/pb_pb410.png differ diff --git a/src/qt/assets/systemicons/pb_pb640.png b/src/qt/assets/systemicons/pb_pb640.png new file mode 100644 index 000000000..d0be550f1 Binary files /dev/null and b/src/qt/assets/systemicons/pb_pb640.png differ diff --git a/src/qt/assets/systemicons/pb_pb680.png b/src/qt/assets/systemicons/pb_pb680.png new file mode 100644 index 000000000..a697d5dd0 Binary files /dev/null and b/src/qt/assets/systemicons/pb_pb680.png differ diff --git a/src/qt/assets/systemicons/tandy_1000.png b/src/qt/assets/systemicons/tandy_1000.png new file mode 100644 index 000000000..b50f2c1e6 Binary files /dev/null and b/src/qt/assets/systemicons/tandy_1000.png differ diff --git a/src/qt/assets/systemicons/tandy_1000_hx.png b/src/qt/assets/systemicons/tandy_1000_hx.png new file mode 100644 index 000000000..b770a6b7c Binary files /dev/null and b/src/qt/assets/systemicons/tandy_1000_hx.png differ diff --git a/src/qt/assets/systemicons/tandy_1000_sl2.png b/src/qt/assets/systemicons/tandy_1000_sl2.png new file mode 100644 index 000000000..b7feae92a Binary files /dev/null and b/src/qt/assets/systemicons/tandy_1000_sl2.png differ diff --git a/src/qt/assets/systemicons/toshiba_t1000.png b/src/qt/assets/systemicons/toshiba_t1000.png new file mode 100644 index 000000000..a2dbfc382 Binary files /dev/null and b/src/qt/assets/systemicons/toshiba_t1000.png differ diff --git a/src/qt/assets/systemicons/toshiba_t1200.png b/src/qt/assets/systemicons/toshiba_t1200.png new file mode 100644 index 000000000..8c3cf0c37 Binary files /dev/null and b/src/qt/assets/systemicons/toshiba_t1200.png differ diff --git a/src/qt/assets/systemicons/toshiba_t1200_hdd.png b/src/qt/assets/systemicons/toshiba_t1200_hdd.png new file mode 100644 index 000000000..8c3cf0c37 Binary files /dev/null and b/src/qt/assets/systemicons/toshiba_t1200_hdd.png differ diff --git a/src/qt/dummy_cdrom_ioctl.c b/src/qt/dummy_cdrom_ioctl.c index bddfabb5b..8dffc6758 100644 --- a/src/qt/dummy_cdrom_ioctl.c +++ b/src/qt/dummy_cdrom_ioctl.c @@ -162,6 +162,7 @@ ioctl_is_empty(const void *local) return 1; } +#if 0 static int ioctl_ext_medium_changed(UNUSED(void *local)) { @@ -174,6 +175,7 @@ ioctl_ext_medium_changed(UNUSED(void *local)) return ret; } +#endif static void ioctl_close(void *local) diff --git a/src/qt/icons/green-square-16.png b/src/qt/icons/green-square-16.png new file mode 100644 index 000000000..cb42c38eb Binary files /dev/null and b/src/qt/icons/green-square-16.png differ diff --git a/src/qt/icons/pause-16.png b/src/qt/icons/pause-16.png new file mode 100644 index 000000000..375780232 Binary files /dev/null and b/src/qt/icons/pause-16.png differ diff --git a/src/qt/icons/play-16.png b/src/qt/icons/play-16.png new file mode 100644 index 000000000..bde40f503 Binary files /dev/null and b/src/qt/icons/play-16.png differ diff --git a/src/qt/icons/red-power-16.png b/src/qt/icons/red-power-16.png new file mode 100644 index 000000000..c90ef491f Binary files /dev/null and b/src/qt/icons/red-power-16.png differ diff --git a/src/qt/icons/red-square-16.png b/src/qt/icons/red-square-16.png new file mode 100644 index 000000000..32faa7cdc Binary files /dev/null and b/src/qt/icons/red-square-16.png differ diff --git a/src/qt/icons/stop-16.png b/src/qt/icons/stop-16.png new file mode 100644 index 000000000..d73cad140 Binary files /dev/null and b/src/qt/icons/stop-16.png differ diff --git a/src/qt/icons/yellow-square-16.png b/src/qt/icons/yellow-square-16.png new file mode 100644 index 000000000..197cf394e Binary files /dev/null and b/src/qt/icons/yellow-square-16.png differ diff --git a/src/qt/languages/pl-PL.po b/src/qt/languages/pl-PL.po index 7433c1d65..b161370ed 100644 --- a/src/qt/languages/pl-PL.po +++ b/src/qt/languages/pl-PL.po @@ -13,7 +13,7 @@ msgid "&Keyboard requires capture" msgstr "&Klawaitura wymaga przechwytu myszy" msgid "&Right CTRL is left ALT" -msgstr "&Prawy CTRL to lewy Alt" +msgstr "&Prawy CTRL to lewy ALT" msgid "&Hard Reset..." msgstr "&Twardy reset..." @@ -49,7 +49,7 @@ msgid "Re&nderer" msgstr "Re&nderer" msgid "&Qt (Software)" -msgstr "&Qt (Software)" +msgstr "&Qt (programowy)" msgid "Qt (&OpenGL)" msgstr "Qt (&OpenGL)" @@ -61,13 +61,13 @@ msgid "&VNC" msgstr "&VNC" msgid "Specify dimensions..." -msgstr "Określ rozmiary..." +msgstr "Określ wymiary..." msgid "F&orce 4:3 display ratio" msgstr "&Wymuś proporcje wyświetlania 4:3" msgid "&Window scale factor" -msgstr "&Czynnik skalowania okna" +msgstr "Współ&czynnik skalowania okna" msgid "&0.5x" msgstr "&0.5x" @@ -103,10 +103,10 @@ msgid "Filter method" msgstr "Metoda filtrowania" msgid "&Nearest" -msgstr "&Nearest" +msgstr "&Najbliższa" msgid "&Linear" -msgstr "&Linear" +msgstr "&Liniowa" msgid "Hi&DPI scaling" msgstr "Skalowanie Hi&DPI" @@ -145,7 +145,7 @@ msgid "RGB &Color" msgstr "RGB - &Kolorowy" msgid "&RGB Grayscale" -msgstr "&RGB - Skala szarości" +msgstr "&RGB - Skala odcieni szarości" msgid "&Amber monitor" msgstr "&Bursztynowy monitor" @@ -157,7 +157,7 @@ msgid "&White monitor" msgstr "&Biały monitor" msgid "Grayscale &conversion type" -msgstr "Typ konwersji &w skali szarości" +msgstr "Typ konwersji &w skali odcieni szarości" msgid "BT&601 (NTSC/PAL)" msgstr "BT&601 (NTSC/PAL)" @@ -166,13 +166,13 @@ msgid "BT&709 (HDTV)" msgstr "BT&709 (HDTV)" msgid "&Average" -msgstr "&Średni" +msgstr "&Średnia" msgid "CGA/PCjr/Tandy/E&GA/(S)VGA overscan" msgstr "Overscan dla CGA/PCjr/Tandy/E&GA/(S)VGA" msgid "Change contrast for &monochrome display" -msgstr "Zmień kontrast dla &monochromatycznego ekranu" +msgstr "Zmień kontrast dla ekranu &monochromatycznego" msgid "&Media" msgstr "&Nośnik" @@ -196,7 +196,7 @@ msgid "&Preferences..." msgstr "&Preferencje..." msgid "Enable &Discord integration" -msgstr "Włącz integrację z &Discord" +msgstr "Włącz integrację z &Discordem" msgid "Sound &gain..." msgstr "Wzmocnienie &dźwięku..." @@ -214,7 +214,7 @@ msgid "&Documentation..." msgstr "&Dokumentacja..." msgid "&About 86Box..." -msgstr "&O 86Box..." +msgstr "&O 86Boxie..." msgid "&New image..." msgstr "&Nowy obraz..." @@ -247,7 +247,7 @@ msgid "E&xport to 86F..." msgstr "E&ksportuj do 86F..." msgid "&Mute" -msgstr "&Ścisz" +msgstr "&Wycisz" msgid "E&mpty" msgstr "P&usty" @@ -256,13 +256,13 @@ msgid "Reload previous image" msgstr "Przeładuj poprzedni obraz" msgid "&Folder..." -msgstr "&Teczka..." +msgstr "&Folder..." msgid "Target &framerate" msgstr "Docelowa &liczba klatek na sekundę" msgid "&Sync with video" -msgstr "&Zsynchronizuj z wideo" +msgstr "&Zsynchronizuj z obrazem" msgid "&25 fps" msgstr "&25 fps" @@ -355,7 +355,7 @@ msgid "Speed:" msgstr "Szybkość:" msgid "Frequency:" -msgstr "Częstotliwość:" +msgstr "Taktowanie:" msgid "FPU:" msgstr "Jednostka FPU:" @@ -391,7 +391,7 @@ msgid "Video #2:" msgstr "Wideo 2:" msgid "Voodoo 1 or 2 Graphics" -msgstr "Grafika Voodoo 1 czy 2" +msgstr "Grafika Voodoo 1 lub 2" msgid "IBM 8514/A Graphics" msgstr "Grafika IBM 8514/A" @@ -505,10 +505,10 @@ msgid "FD Controller:" msgstr "Kontroler dyskietek:" msgid "Tertiary IDE Controller" -msgstr "Trzeciorzędowy kontroler IDE" +msgstr "Trzeciorzędny kontroler IDE" msgid "Quaternary IDE Controller" -msgstr "Czwartorzędowy kontroler IDE" +msgstr "Czwartorzędny kontroler IDE" msgid "SCSI" msgstr "SCSI" @@ -577,7 +577,7 @@ msgid "Floppy drives:" msgstr "Napędy dyskietek:" msgid "Turbo timings" -msgstr "Rozrządy Turbo" +msgstr "Timing Turbo" msgid "Check BPB" msgstr "Sprawdzaj BPB" @@ -628,7 +628,7 @@ msgid "Fatal error" msgstr "Fatalny błąd" msgid " - PAUSED" -msgstr " - PAUSED" +msgstr " - PAUZA" msgid "Speed" msgstr "Szybkość" @@ -664,19 +664,19 @@ msgid "Basic sector images" msgstr "Podstawowe obrazy sektorów" msgid "Surface images" -msgstr "Obrazy powierzchniowe" +msgstr "Obrazy powierzchni" msgid "Machine \"%hs\" is not available due to missing ROMs in the roms/machines directory. Switching to an available machine." -msgstr "Maszyna \"%hs\" nie jest dostępna, ponieważ brakuje obrazów ROM w katalogu roms/machines. Przełączanie na dostępną maszynę." +msgstr "Maszyna \"%hs\" nie jest dostępna, ponieważ brakuje ROM-ów w katalogu roms/machines. Przełączanie na dostępną maszynę." msgid "Video card \"%hs\" is not available due to missing ROMs in the roms/video directory. Switching to an available video card." -msgstr "Karta wideo \"%hs\" nie jest dostępna, ponieważ brakuje obrazów ROM w katalogu roms/video. Przełączanie na dostępną kartę wideo." +msgstr "Karta wideo \"%hs\" nie jest dostępna, ponieważ brakuje ROM-ów w katalogu roms/video. Przełączanie na dostępną kartę graficzną." msgid "Video card #2 \"%hs\" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." -msgstr "Karta wideo 2 \"%hs\" nie jest dostępna, ponieważ brakuje obrazów ROM w katalogu roms/video. Wyłączenie drugiej karty graficznej." +msgstr "Karta wideo 2 \"%hs\" nie jest dostępna, ponieważ brakuje ROM-ów w katalogu roms/video. Wyłączenie drugiej karty graficznej." msgid "Device \"%hs\" is not available due to missing ROMs. Ignoring the device." -msgstr "Urządzenie \"%hs\" nie jest dostępne, ponieważ brakuje obrazów ROM. Ignorowanie urządzenia." +msgstr "Urządzenie \"%hs\" nie jest dostępne, ponieważ brakuje ROM-ów. Ignorowanie urządzenia." msgid "Machine" msgstr "Maszyna" @@ -697,7 +697,7 @@ msgid "Ports (COM & LPT)" msgstr "Porty (COM & LPT)" msgid "Storage controllers" -msgstr "Kontrolery pamięci" +msgstr "Kontrolery pamięci masowej" msgid "Hard disks" msgstr "Dyski twarde" @@ -712,13 +712,13 @@ msgid "Other peripherals" msgstr "Inne urządzenia peryferyjne" msgid "Click to capture mouse" -msgstr "Kliknij w celu przechwycenia myszy" +msgstr "Kliknij, by przechwycić mysz" msgid "Press %1 to release mouse" -msgstr "Naciśnij klawisze %1 w celu uwolnienia myszy" +msgstr "Naciśnij %1 w celu uwolnienia myszy" msgid "Press %1 or middle button to release mouse" -msgstr "Naciśnij klawisze %1 lub środkowy przycisk w celu uwolnienia myszy" +msgstr "Naciśnij %1 lub środkowy przycisk w celu uwolnienia myszy" msgid "Bus" msgstr "Magistrala" @@ -742,7 +742,7 @@ msgid "Default" msgstr "Domyślny" msgid "%1 Wait state(s)" -msgstr "%1 Stany oczekiwania" +msgstr "%1 stan(y/ów) oczekiwania" msgid "Type" msgstr "Rodzaj" @@ -796,16 +796,16 @@ msgid "Advanced sector images" msgstr "Zaawansowane obrazy sektorów" msgid "Flux images" -msgstr "Flux images" +msgstr "Obrazy flux" msgid "Are you sure you want to hard reset the emulated machine?" -msgstr "Jesteś pewien że chcesz wykonać twardy reset emulowanej maszyny?" +msgstr "Czy na pewno chcesz wykonać twardy reset emulowanej maszyny?" msgid "Are you sure you want to exit 86Box?" -msgstr "Jesteś pewien że chcesz zakończyć 86Box?" +msgstr "Czy na pewno chcesz zakończyć 86Box?" msgid "Unable to initialize Ghostscript" -msgstr "Nie można zainicjować Ghostscript" +msgstr "Nie można zainicjować Ghostscriptu" msgid "Unable to initialize GhostPCL" msgstr "Nie można zainicjować GhostPCL" @@ -817,7 +817,7 @@ msgid "MO images" msgstr "Obrazy MO" msgid "Welcome to 86Box!" -msgstr "Witamy w 86Box!" +msgstr "Witamy w 86Boxie!" msgid "Internal device" msgstr "Urządzenie wewnętrzne" @@ -826,7 +826,7 @@ msgid "Exit" msgstr "Zakończ" msgid "No ROMs found" -msgstr "Nie znaleziono obrazów ROM" +msgstr "Nie znaleziono ROM-ów" msgid "Do you want to save the settings?" msgstr "Czy chcesz zapisać ustawienia?" @@ -844,7 +844,7 @@ msgid "86Box v" msgstr "86Box v" msgid "An emulator of old computers\n\nAuthors: Miran Grča (OBattler), RichardG867, Jasmine Iwanek, TC1995, coldbrewed, Teemu Korhonen (Manaatti), Joakim L. Gilje, Adrien Moulin (elyosh), Daniel Balsom (gloriouscow), Cacodemon345, Fred N. van Kempen (waltje), Tiseno100, reenigne, and others.\n\nWith previous core contributions from Sarah Walker, leilei, JohnElliott, greatpsycho, and others.\n\nReleased under the GNU General Public License version 2 or later. See LICENSE for more information." -msgstr "Emulator starych komputerów\n\nAutorzy: Miran Grča (OBattler), RichardG867, Jasmine Iwanek, TC1995, coldbrewed, Teemu Korhonen (Manaatti), Joakim L. Gilje, Adrien Moulin (elyosh), Daniel Balsom (gloriouscow), Cacodemon345, Fred N. van Kempen (waltje), Tiseno100, reenigne, i inni.\n\nZ wcześniejszym wkładem od Sarah Walker, leilei, JohnElliott, greatpsycho i innych.\n\nPrzetłumaczony przez: Fanta-Shokata\n\nWydany na licencji GNU General Public License w wersji 2 lub nowszej. Zobacz LICENSE aby uzyskać więcej informacji." +msgstr "Emulator starych komputerów\n\nAutorzy: Miran Grča (OBattler), RichardG867, Jasmine Iwanek, TC1995, coldbrewed, Teemu Korhonen (Manaatti), Joakim L. Gilje, Adrien Moulin (elyosh), Daniel Balsom (gloriouscow), Cacodemon345, Fred N. van Kempen (waltje), Tiseno100, reenigne, i inni.\n\nZ wcześniejszym wkładem od Sarah Walker, leilei, JohnElliott, greatpsycho i innych.\n\nPrzetłumaczony przez: Fanta-Shokata, Lili1228\n\nWydany na licencji GNU General Public License w wersji 2 lub nowszej. Zobacz LICENSE aby uzyskać więcej informacji." msgid "Hardware not available" msgstr "Sprzęt niedostępny" @@ -886,10 +886,10 @@ msgid "GLSL shaders" msgstr "Shadery GLSL" msgid "You are loading an unsupported configuration" -msgstr "Ładujesz nieobsługiwaną konfigurację" +msgstr "Wczytujesz nieobsługiwaną konfigurację" msgid "CPU type filtering based on selected machine is disabled for this emulated machine.\n\nThis makes it possible to choose a CPU that is otherwise incompatible with the selected machine. However, you may run into incompatibilities with the machine BIOS or other software.\n\nEnabling this setting is not officially supported and any bug reports filed may be closed as invalid." -msgstr "Wybór rodzaju procesora oparty na wybranej maszynie jest wyłączony dla tej emulowanej maszyny.\n\nPozwala to na wybór procesora który jest niekompatybilny z wybraną maszyną. Jednak możesz napotkać niezgodności z BIOS-em maszyny lub innym oprogramowaniem.\n\nAktywacja tego ustawienia nie jest wspierana i każde zgłoszenie błędu może zostać zamknięte jako nieważne." +msgstr "Filtrowanie rodzaju procesora na podstawie wybranej maszyny jest wyłączone dla tej emulowanej maszyny.\n\nPozwala to na wybór procesora, który jest niekompatybilny z wybraną maszyną, jednak możesz napotkać niezgodności z BIOS-em maszyny lub innym oprogramowaniem.\n\nAktywacja tego ustawienia nie jest wspierana i każde zgłoszenie błędu może zostać zamknięte jako nieprawidłowe." msgid "Continue" msgstr "Kontynuuj" @@ -901,10 +901,10 @@ msgid "Cassette images" msgstr "Obrazy kaset" msgid "Cartridge %1: %2" -msgstr "Kartrydż %1: %2" +msgstr "Kartridż %1: %2" msgid "Cartridge images" -msgstr "Obrazy kartrydżu" +msgstr "Obrazy kartridżów" msgid "Resume execution" msgstr "Wznów wykonywanie" @@ -994,7 +994,7 @@ msgid "Don't overwrite" msgstr "Nie nadpisuj" msgid "Raw image" -msgstr "Obraz surowy" +msgstr "Surowy obraz" msgid "HDI image" msgstr "Obraz HDI" @@ -1012,10 +1012,10 @@ msgid "Differencing VHD" msgstr "VHD różnicujący" msgid "(N/A)" -msgstr "(Bez)" +msgstr "(nd.)" msgid "Raw image (.img)" -msgstr "Obraz surowy (.img)" +msgstr "Surowy obraz (.img)" msgid "HDI image (.hdi)" msgstr "Obraz HDI (.hdi)" @@ -1030,7 +1030,7 @@ msgid "Dynamic-size VHD (.vhd)" msgstr "VHD o dynamicznym rozmiarze (.vhd)" msgid "Differencing VHD (.vhd)" -msgstr "VHD różnicujący (.vhd)" +msgstr "VHD różnicowy (.vhd)" msgid "Large blocks (2 MB)" msgstr "Duże bloki (2 MB)" @@ -1045,7 +1045,7 @@ msgid "Select the parent VHD" msgstr "Wybierz nadrzędny plik VHD" msgid "This could mean that the parent image was modified after the differencing image was created.\n\nIt can also happen if the image files were moved or copied, or by a bug in the program that created this disk.\n\nDo you want to fix the timestamps?" -msgstr "Może to oznaczać, że obraz nadrzędny został zmodyfikowany po utworzeniu obrazu różnicującego.\n\nMoże się to również zdarzyć, jeśli pliki obrazów zostały przeniesione lub skopiowane, lub wystąpił błąd w programie, który utworzył ten dysk\n\nCzy chcesz naprawić sygnatury czasowe?" +msgstr "Może to oznaczać, że obraz nadrzędny został zmodyfikowany po utworzeniu obrazu różnicowego.\n\nMoże się to również zdarzyć, jeśli pliki obrazów zostały przeniesione lub skopiowane, lub wystąpił błąd w programie, który utworzył ten dysk.\n\nCzy chcesz naprawić sygnatury czasowe?" msgid "Parent and child disk timestamps do not match" msgstr "Sygnatury czasowe dysku nadrzędnego i podrzędnego nie zgadzają się" @@ -1162,10 +1162,10 @@ msgid "The network configuration will be switched to the null driver" msgstr "Konfiguracja sieci zostanie przełączona na sterownik null" msgid "Mouse sensitivity:" -msgstr "Wrażliwość myszy:" +msgstr "Czułość myszy:" msgid "Select media images from program working directory" -msgstr "Wybór obrazów multimedialnych z katalogu roboczego programu" +msgstr "Wybór obrazów nośników z katalogu roboczego programu" msgid "PIT mode:" msgstr "Tryb PIT:" @@ -1186,7 +1186,7 @@ msgid "WinBox is no longer supported" msgstr "WinBox nie jest już wspierany" msgid "Development of the WinBox manager stopped in 2022 due to a lack of maintainers. As we direct our efforts towards making 86Box even better, we have made the decision to no longer support WinBox as a manager.\n\nNo further updates will be provided through WinBox, and you may encounter incorrect behavior should you continue using it with newer versions of 86Box. Any bug reports related to WinBox behavior will be closed as invalid.\n\nGo to 86box.net for a list of other managers you can use." -msgstr "Rozwój menedżera WinBox został zatrzymany w 2022 roku z powodu braku opiekunów. Ponieważ kierujemy nasze wysiłki na uczynienie 86Box jeszcze lepszym, podjęliśmy decyzję o zaprzestaniu wspierania WinBox jako menedżera.\n\nŻadne dalsze aktualizacje nie będą dostarczane za pośrednictwem WinBox i możesz napotkać nieprawidłowe zachowanie, jeśli będziesz go nadal używać z nowszymi wersjami 86Box. Wszelkie zgłoszenia błędów związane z działaniem WinBox zostaną zamknięte jako nieważne.\n\nLista innych menedżerów, z których można korzystać, znajduje się na stronie 86box.net." +msgstr "Menedżer WinBox przestał być rozwijany w 2022 roku z powodu braku opiekunów. Ponieważ kierujemy nasze wysiłki na uczynienie 86Box jeszcze lepszym, podjęliśmy decyzję o zaprzestaniu wspierania WinBox jako menedżera.\n\nŻadne dalsze aktualizacje nie będą dostarczane za pośrednictwem WinBoxa i możesz napotkać nieprawidłowe zachowanie, jeśli będziesz go nadal używać z nowszymi wersjami 86Box. Wszelkie zgłoszenia błędów związane z działaniem WinBox zostaną zamknięte jako nieważne.\n\nLista innych menedżerów, z których można korzystać, znajduje się na stronie 86box.net." msgid "Generate" msgstr "Generuj" @@ -1273,7 +1273,7 @@ msgid "VSync" msgstr "VSync" msgid "Synchronize with video" -msgstr "Zsynchronizuj z wideo" +msgstr "Synchronizuj z obrazem" msgid "Shaders" msgstr "Shadery" @@ -1297,10 +1297,10 @@ msgid "Error initializing OpenGL" msgstr "Błąd inicjalizacji OpenGL" msgid "\nFalling back to software rendering." -msgstr "\nPowrót do renderowania oprogramowania." +msgstr "\nPowrót do renderowania programowego." msgid "

When selecting media images (CD-ROM, floppy, etc.) the open dialog will start in the same directory as the 86Box configuration file. This setting will likely only make a difference on macOS.

" -msgstr "

Podczas wybierania obrazów nośników (CD-ROM, dyskietka itp.) otwarte okno dialogowe rozpocznie się w tym samym katalogu, co plik konfiguracyjny 86Box. To ustawienie prawdopodobnie będzie miało znaczenie tylko na macOS.

" +msgstr "

Podczas wybierania obrazów nośników (CD-ROM, dyskietka itd.), otwarte okno dialogowe rozpocznie się w tym samym katalogu, co plik konfiguracyjny 86Box. To ustawienie prawdopodobnie będzie miało znaczenie tylko na macOS.

" msgid "This machine might have been moved or copied." msgstr "To urządzenie mogło zostać przeniesione lub skopiowane." @@ -1354,25 +1354,25 @@ msgid "Novell NetWare 2.x Key Card" msgstr "Karta klucza Novell NetWare 2.x" msgid "Serial port passthrough 1" -msgstr "Przełączanie portu szeregowego 1" +msgstr "Przelotka portu szeregowego 1" msgid "Serial port passthrough 2" -msgstr "Przełączanie portu szeregowego 2" +msgstr "Przelotka portu szeregowego 2" msgid "Serial port passthrough 3" -msgstr "Przełączanie portu szeregowego 3" +msgstr "Przelotka portu szeregowego 3" msgid "Serial port passthrough 4" -msgstr "Przełączanie portu szeregowego 4" +msgstr "Przelotka portu szeregowego 4" msgid "Renderer options..." msgstr "Opcje renderowania..." msgid "Logitech/Microsoft Bus Mouse" -msgstr "Mysz magistralna Logitech/Microsoft" +msgstr "Mysz magistralowa Logitech/Microsoft" msgid "Microsoft Bus Mouse (InPort)" -msgstr "Mysz magistralna Microsoft (InPort)" +msgstr "Mysz magistralowa Microsoft (InPort)" msgid "Mouse Systems Serial Mouse" msgstr "Mysz szeregowa Mouse Systems" @@ -1387,7 +1387,7 @@ msgid "PS/2 Mouse" msgstr "Mysz PS/2" msgid "3M MicroTouch (Serial)" -msgstr "3M MicroTouch (szeregowa)" +msgstr "3M MicroTouch (szeregowy)" msgid "[COM] Standard Hayes-compliant Modem" msgstr "[COM] Standardowy modem zgodny z Hayes" @@ -1396,7 +1396,7 @@ msgid "Roland MT-32 Emulation" msgstr "Emulacja Roland MT-32" msgid "Roland MT-32 (New) Emulation" -msgstr "Emulacja Roland MT-32 (nowego)" +msgstr "(Nowa) emulacja Roland MT-32" msgid "Roland CM-32L Emulation" msgstr "Emulacja Roland CM-32L" @@ -1405,7 +1405,7 @@ msgid "Roland CM-32LN Emulation" msgstr "Emulacja Roland CM-32LN" msgid "OPL4-ML Daughterboard" -msgstr "Płyta córka OPL4-ML" +msgstr "Płyta-córka OPL4-ML" msgid "System MIDI" msgstr "System MIDI" @@ -1612,7 +1612,7 @@ msgid "CODEC" msgstr "CODEC" msgid "Raise CODEC interrupt on CODEC setup (needed by some drivers)" -msgstr "Podniesienie przerwania CODEC przy konfiguracji CODEC (wymagane przez niektóre sterowniki)" +msgstr "Podnieś przerwanie CODEC podczas konfiguracji CODEC-a (wymagane przez niektóre sterowniki)" msgid "SB Address" msgstr "Adres SB" @@ -1630,7 +1630,7 @@ msgid "Receive MIDI input (MPU-401)" msgstr "Odbiór wejścia MIDI (MPU-401)" msgid "SB low DMA" -msgstr "SB low DMA" +msgstr "Low DMA SB" msgid "6CH variant (6-channel)" msgstr "Wariant 6CH (6-kanałowy)" @@ -1645,7 +1645,7 @@ msgid "High DMA" msgstr "Wysokie DMA" msgid "Control PC speaker" -msgstr "Głośnik komputera sterującego" +msgstr "Kontroluj PC speaker" msgid "Memory size" msgstr "Rozmiar pamięci" @@ -1663,10 +1663,10 @@ msgid "GUS type" msgstr "Typ GUS" msgid "Enable 0x04 \"Exit 86Box\" command" -msgstr "Włącz polecenie 0x04 \"Wyjdź z 86Box\"" +msgstr "Włącz polecenie 0x04 \"Wyjdź z 86Boxa\"" msgid "Display type" -msgstr "Typ wyświetlacza" +msgstr "Typ ekranu" msgid "Composite type" msgstr "Typ kompozytowy" @@ -1777,7 +1777,7 @@ msgid "Triangle" msgstr "Trójkątny" msgid "Linear" -msgstr "Liniowa" +msgstr "Liniowy" msgid "4th Order" msgstr "4. rzędu" @@ -1798,13 +1798,13 @@ msgid "Three" msgstr "Trzy" msgid "Wheel" -msgstr "Koło" +msgstr "Rolka" msgid "Five + Wheel" -msgstr "" +msgstr "Pięć + rolka" msgid "Five + 2 Wheels" -msgstr "" +msgstr "Pięć + dwie rolki" msgid "A3 - SMT2 Serial / SMT3(R)V" msgstr "A3 - SMT2 szeregowa / SMT3(R)V" @@ -1876,7 +1876,7 @@ msgid "New" msgstr "Nowość" msgid "Color (generic)" -msgstr "Kolor (generyczny)" +msgstr "Kolorowy (generyczny)" msgid "Green Monochrome" msgstr "Zielony monochromatyczny" @@ -1888,10 +1888,10 @@ msgid "Gray Monochrome" msgstr "Szary monochromatyczny" msgid "Color (no brown)" -msgstr "Kolor (bez brązowego)" +msgstr "Kolorowy (bez brązowego)" msgid "Color (IBM 5153)" -msgstr "Kolor (IBM 5153)" +msgstr "Kolorowy (IBM 5153)" msgid "Simple doubling" msgstr "Proste podwojenie" @@ -1921,7 +1921,7 @@ msgid "Color 80x25 (5153/CGA)" msgstr "Kolor 80x25 (5153/CGA)" msgid "Enhanced Color - Normal Mode (5154/ECD)" -msgstr "Rozszerzone kolory - tryb normalny (5154/ECD)" +msgstr "Rozszerzony kolor - tryb zwykły (5154/ECD)" msgid "Enhanced Color - Enhanced Mode (5154/ECD)" msgstr "Rozszerzony kolor - tryb rozszerzony (5154/ECD)" @@ -1936,10 +1936,10 @@ msgid "Gray" msgstr "Szary" msgid "Color" -msgstr "Kolor" +msgstr "Kolorowy" msgid "U.S. English" -msgstr "Amerykański angielski" +msgstr "Angielski (USA)" msgid "Scandinavian" msgstr "Skandynawski" @@ -1948,13 +1948,13 @@ msgid "Other languages" msgstr "Inne języki" msgid "Bochs latest" -msgstr "Bochs najnowsze" +msgstr "Najnowszy Bochs" msgid "Mono Non-Interlaced" -msgstr "Mono bez przeplotu" +msgstr "Monochromatyczny bez przeplotu" msgid "Color Interlaced" -msgstr "Kolor z przeplotem" +msgstr "Kolorowy z przeplotem" msgid "Color Non-Interlaced" msgstr "Kolor bez przeplotu" @@ -1963,7 +1963,7 @@ msgid "3Dfx Voodoo Graphics" msgstr "Grafika 3Dfx Voodoo" msgid "Obsidian SB50 + Amethyst (2 TMUs)" -msgstr "Obsydian SB50 + Ametyst (2 jednostki TMU)" +msgstr "Obsydian SB50 + Amethyst (2 jednostki TMU)" msgid "8-bit" msgstr "8-bitowy" @@ -1987,7 +1987,7 @@ msgid "High-Speed" msgstr "Wysoka prędkość" msgid "Stereo LPT DAC" -msgstr "Stereofoniczny przetwornik cyfrowo-analogowy LPT" +msgstr "Stereo LPT DAC" msgid "Generic Text Printer" msgstr "Generyczna drukarka tekstowa" @@ -2002,7 +2002,7 @@ msgid "Generic PCL5e Printer" msgstr "Generyczna drukarka PCL5e" msgid "Parallel Line Internet Protocol" -msgstr "Protokół internetowy linii równoległej" +msgstr "Parallel Line Internet Protocol" msgid "Protection Dongle for Savage Quest" msgstr "Klucz ochronny dla Savage Quest" @@ -2017,7 +2017,7 @@ msgid "Host Serial Device" msgstr "Urządzenie szeregowe hosta" msgid "Name of pipe" -msgstr "Nazwa rury" +msgstr "Nazwa potoku" msgid "Data bits" msgstr "Bity danych" @@ -2026,19 +2026,19 @@ msgid "Stop bits" msgstr "Bity stopu" msgid "Baud Rate of Passthrough" -msgstr "Szybkość transmisji Passthrough" +msgstr "Szybkość transmisji przelotowej" msgid "Named Pipe (Server)" -msgstr "Nazwana rura (serwer)" +msgstr "Nazwany potok (serwer)" msgid "Host Serial Passthrough" -msgstr "Przejście przez port szeregowy hosta" +msgstr "Przelot przez port szeregowy hosta" msgid "E&ject %1" msgstr "W&yjmij %1" msgid "&Unmute" -msgstr "&Wycisz" +msgstr "O&dcisz" msgid "Softfloat FPU" msgstr "FPU Softfloat" @@ -2047,28 +2047,28 @@ msgid "High performance impact" msgstr "Wysoki wpływ na wydajność" msgid "[Generic] RAM Disk (max. speed)" -msgstr "[Generic] Dysk RAM (maks. prędkość)" +msgstr "[generyczny] Dysk RAM (maks. prędkość)" msgid "[Generic] 1989 (3500 RPM)" -msgstr "" +msgstr "[generyczny] 1989 (3500 RPM)" msgid "[Generic] 1992 (3600 RPM)" -msgstr "" +msgstr "[generyczny] 1992 (3600 RPM)" msgid "[Generic] 1994 (4500 RPM)" -msgstr "" +msgstr "[generyczny] 1994 (4500 RPM)" msgid "[Generic] 1996 (5400 RPM)" -msgstr "" +msgstr "[generyczny] 1996 (5400 RPM)" msgid "[Generic] 1997 (5400 RPM)" -msgstr "" +msgstr "[generyczny] 1997 (5400 RPM)" msgid "[Generic] 1998 (5400 RPM)" -msgstr "" +msgstr "[generyczny] 1998 (5400 RPM)" msgid "[Generic] 2000 (7200 RPM)" -msgstr "" +msgstr "[generyczny] 2000 (7200 RPM)" msgid "IBM 8514/A clone (ISA)" msgstr "Klon IBM 8514/A (ISA)" @@ -2083,67 +2083,67 @@ msgid "Generic PC/AT Memory Expansion" msgstr "Generyczne rozszerzenie pamięci PC/AT" msgid "Unable to find Dot-Matrix fonts" -msgstr "Nie można znaleźć czcionek igłowych" +msgstr "Nie można znaleźć fontów igłowych" msgid "TrueType fonts in the \"roms/printer/fonts\" directory are required for the emulation of the Generic ESC/P Dot-Matrix Printer." -msgstr "Czcionki TrueType w katalogu \"roms/printer/fonts\" są wymagane do emulacji generyczniej drukarki igłowej ESC/P." +msgstr "Fonty TrueType w katalogu \"roms/printer/fonts\" są wymagane do emulacji generycznej drukarki igłowej ESC/P." msgid "Inhibit multimedia keys" -msgstr "" +msgstr "Przejmij klawisze multimedialne" msgid "Ask for confirmation before saving settings" -msgstr "" +msgstr "Pytaj o potwierdzenie przed zapisaniem ustawień" msgid "Ask for confirmation before hard resetting" -msgstr "" +msgstr "Pytaj o potwierdzenie przed twardym resetem" msgid "Ask for confirmation before quitting" -msgstr "" +msgstr "Pytaj o potwierdzenie przed wyjściem" msgid "Options" -msgstr "" +msgstr "Opcje" msgid "Model" -msgstr "" +msgstr "Model" msgid "Model:" -msgstr "" +msgstr "Model:" msgid "Failed to initialize Vulkan renderer." -msgstr "" +msgstr "Nie udało się zainicjować renderera Vulkan." msgid "GLSL Error" -msgstr "" +msgstr "Błąd GLSL" msgid "Could not load shader: %1" -msgstr "" +msgstr "Nie udało się wczytać shadera: %1" msgid "OpenGL version 3.0 or greater is required. Current GLSL version is %1.%2" -msgstr "" +msgstr "Wymagana jest wersja OpenGL 3.0 lub wyższa. Aktualna wersja GLSL to %1.%2" msgid "Could not load texture: %1" -msgstr "" +msgstr "Nie udało się wczytać tekstury: %1" msgid "Could not compile shader:\n\n%1" -msgstr "" +msgstr "Nie udało się skompilować shadera:\n\n%1" msgid "Program not linked:\n\n%1" -msgstr "" +msgstr "Program niezalinkowany:\n\n%1" msgid "Shader Manager" -msgstr "" +msgstr "Menedżer shaderów" msgid "Shader Configuration" -msgstr "" +msgstr "Konfiguracja shadera" msgid "Add" -msgstr "" +msgstr "Dodaj" msgid "Move up" -msgstr "" +msgstr "Przesuń w górę" msgid "Move down" -msgstr "" +msgstr "Przesuń w dół" msgid "Could not load file %1" -msgstr "" +msgstr "Nie można wczytać pliku %1" diff --git a/src/qt/languages/ru-RU.po b/src/qt/languages/ru-RU.po index bb8a9caf5..b721d6f29 100644 --- a/src/qt/languages/ru-RU.po +++ b/src/qt/languages/ru-RU.po @@ -147,6 +147,12 @@ msgstr "RGB &цветной" msgid "&RGB Grayscale" msgstr "&RGB монохромный" +msgid "RGB (no brown)" +msgstr "RGB (без коричневого)" + +msgid "Generic RGBI color monitor" +msgstr "Стандартный цветной монитор RGBI" + msgid "&Amber monitor" msgstr "&Янтарный оттенок" @@ -1789,7 +1795,7 @@ msgid "Dithering" msgstr "Дизеринг" msgid "Enable NMI for CGA emulation" -msgstr "Включение NMI для эмуляции CGA" +msgstr "Включить NMI для эмуляции CGA" msgid "Voodoo type" msgstr "Тип Voodoo" diff --git a/src/qt/qt.c b/src/qt/qt.c index 9ec907f33..e19cf1aac 100644 --- a/src/qt/qt.c +++ b/src/qt/qt.c @@ -28,6 +28,7 @@ #include <86box/plat.h> #include <86box/timer.h> #include <86box/nvr.h> +#include <86box/renderdefs.h> int qt_nvr_save(void) @@ -38,21 +39,16 @@ qt_nvr_save(void) int plat_vidapi(const char *api) { - if (!strcasecmp(api, "default") || !strcasecmp(api, "system")) { - return 0; - } else if (!strcasecmp(api, "qt_software")) { - return 0; - } else if (!strcasecmp(api, "qt_opengl")) { - return 1; - } else if (!strcasecmp(api, "qt_opengles")) { - return 2; - } else if (!strcasecmp(api, "qt_opengl3")) { - return 3; - } else if (!strcasecmp(api, "qt_vulkan")) { - return 4; - } else if (!strcasecmp(api, "vnc")) { - return 5; - } + if (!strcasecmp(api, RENDERER_NAME_DEFAULT) || !strcasecmp(api, RENDERER_NAME_SYSTEM)) + return RENDERER_SOFTWARE; + else if (!strcasecmp(api, RENDERER_NAME_QT_SOFTWARE)) + return RENDERER_SOFTWARE; + else if (!strcasecmp(api, RENDERER_NAME_QT_OPENGL) || !strcasecmp(api, RENDERER_NAME_QT_OPENGLES) || !strcasecmp(api, RENDERER_NAME_QT_OPENGL3)) + return RENDERER_OPENGL3; + else if (!strcasecmp(api, RENDERER_NAME_QT_VULKAN)) + return RENDERER_VULKAN; + else if (!strcasecmp(api, RENDERER_NAME_VNC)) + return RENDERER_VNC; return 0; } @@ -60,26 +56,20 @@ plat_vidapi(const char *api) char * plat_vidapi_name(int api) { - char *name = "default"; + char *name = RENDERER_NAME_DEFAULT; switch (api) { - case 0: - name = "qt_software"; + case RENDERER_SOFTWARE: + name = RENDERER_NAME_QT_SOFTWARE; break; - case 1: - name = "qt_opengl"; + case RENDERER_OPENGL3: + name = RENDERER_NAME_QT_OPENGL3; break; - case 2: - name = "qt_opengles"; + case RENDERER_VULKAN: + name = RENDERER_NAME_QT_VULKAN; break; - case 3: - name = "qt_opengl3"; - break; - case 4: - name = "qt_vulkan"; - break; - case 5: - name = "vnc"; + case RENDERER_VNC: + name = RENDERER_NAME_VNC; break; default: fatal("Unknown renderer: %i\n", api); @@ -87,4 +77,4 @@ plat_vidapi_name(int api) } return name; -} \ No newline at end of file +} diff --git a/src/qt/qt_downloader.cpp b/src/qt/qt_downloader.cpp new file mode 100644 index 000000000..329aeeafb --- /dev/null +++ b/src/qt/qt_downloader.cpp @@ -0,0 +1,95 @@ +/* + * 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. + * + * Downloader module + * + * + * + * Authors: cold-brewed + * + * Copyright 2024 cold-brewed + */ + +#include +#include +#include +#include + +#include "qt_downloader.hpp" + +extern "C" { +#include <86box/plat.h> +} + +Downloader:: +Downloader(const DownloadLocation downloadLocation, QObject *parent) + : QObject(parent) + , file(nullptr) + , reply(nullptr) + , variantData(QVariant::Invalid) +{ + char PATHBUF[256]; + switch (downloadLocation) { + case DownloadLocation::Data: + plat_get_global_data_dir(PATHBUF, 255); + break; + case DownloadLocation::Config: + plat_get_global_config_dir(PATHBUF, 255); + break; + case DownloadLocation::Temp: + plat_get_temp_dir(PATHBUF, 255); + break; + } + downloadDirectory = QDir(PATHBUF); +} + +Downloader::~Downloader() { delete file; } + +void Downloader::download(const QUrl &url, const QString &filepath, const QVariant &varData) { + + variantData = varData; + // temporary until I get the plat stuff fixed + // const auto global_dir = temporaryGetGlobalDataDir(); + // qDebug() << "I was passed filepath " << filepath; + // Join with filename to create final file + // const auto final_path = QDir(global_dir).filePath(filepath); + const auto final_path = downloadDirectory.filePath(filepath); + + file = new QFile(final_path); + if(!file->open(QIODevice::WriteOnly)) { + qWarning() << "Unable to open file " << final_path; + return; + } + + const auto nam = new QNetworkAccessManager(this); + // Create the network request and execute + const auto request = QNetworkRequest(url); + reply = nam->get(request); + // Connect to the finished signal + connect(reply, &QNetworkReply::finished, this, &Downloader::onResult); +} + +void +Downloader::onResult() +{ + if (reply->error()) { + qWarning() << "Error returned from QNetworkRequest: " << reply->errorString(); + emit errorOccurred(reply->errorString()); + reply->deleteLater(); + return; + } + + file->write(reply->readAll()); + file->flush(); + file->close(); + + reply->deleteLater(); + qDebug() << Q_FUNC_INFO << "Downloaded complete: file written to " << file->fileName(); + emit downloadCompleted(file->fileName(), variantData); +} + diff --git a/src/qt/qt_downloader.hpp b/src/qt/qt_downloader.hpp new file mode 100644 index 000000000..2164ba59c --- /dev/null +++ b/src/qt/qt_downloader.hpp @@ -0,0 +1,57 @@ +/* + * 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. + * + * Header for the downloader module + * + * + * + * Authors: cold-brewed + * + * Copyright 2024 cold-brewed + */ + +#ifndef QT_DOWNLOADER_HPP +#define QT_DOWNLOADER_HPP + +#include +#include +#include +#include + + +class Downloader final : public QObject { + Q_OBJECT +public: + enum class DownloadLocation { + Data, // AppDataLocation via plat_get_global_data_dir() + Config, // AppConfigLocation via plat_get_global_config_dir() + Temp // TempLocation via plat_get_temp_dir() + }; + explicit Downloader(DownloadLocation downloadLocation = DownloadLocation::Data, QObject *parent = nullptr); + ~Downloader() final; + + void download(const QUrl &url, const QString &filepath, const QVariant &varData = QVariant::Invalid); + +signals: + // Signal emitted when the download is successful + void downloadCompleted(QString filename, QVariant varData); + // Signal emitted when an error occurs + void errorOccurred(const QString&); + +private slots: + void onResult(); + +private: + QFile *file; + QNetworkAccessManager nam; + QNetworkReply *reply; + QVariant variantData; + QDir downloadDirectory; +}; + +#endif diff --git a/src/qt/qt_glsl_parser.cpp b/src/qt/qt_glsl_parser.cpp index 9efeb430b..934dd2052 100644 --- a/src/qt/qt_glsl_parser.cpp +++ b/src/qt/qt_glsl_parser.cpp @@ -69,13 +69,12 @@ static inline int wx_config_has_entry(void *config, const char *name) { return i static inline void wx_config_free(void *config) { ini_close(config); }; static int endswith(const char *str, const char *ext) { - int i; const char *p; int elen = strlen(ext); int slen = strlen(str); if (slen >= elen) { p = &str[slen - elen]; - for (i = 0; i < elen; ++i) { + for (int i = 0; i < elen; ++i) { if (tolower(p[i]) != tolower(ext[i])) return 0; } @@ -118,12 +117,18 @@ static char *load_file(const char *fn) { char *data = (char*)malloc(fsize + 1); - (void) fread(data, fsize, 1, fp); - fclose(fp); + size_t read_bytes = fread(data, fsize, 1, fp); + if (read_bytes != 1) { + fclose(fp); + free(data); + return nullptr; + } else { + fclose(fp); - data[fsize] = 0; + data[fsize] = 0; - return data; + return data; + } } static void strip_lines(const char *program, const char *starts_with) { @@ -147,17 +152,15 @@ static void strip_defines(const char *program) { } static int has_parameter(glslp_t *glsl, char *id) { - int i; - for (i = 0; i < glsl->num_parameters; ++i) + for (int i = 0; i < glsl->num_parameters; ++i) if (!strcmp(glsl->parameters[i].id, id)) return 1; return 0; } static int get_parameters(glslp_t *glsl) { - int i; struct parameter p; - for (i = 0; i < glsl->num_shaders; ++i) { + for (int i = 0; i < glsl->num_shaders; ++i) { size_t size = 0; char* line = NULL; struct shader *shader = &glsl->shaders[i]; @@ -197,8 +200,7 @@ static int get_parameters(glslp_t *glsl) { } static struct parameter *get_parameter(glslp_t *glslp, const char *id) { - int i; - for (i = 0; i < glslp->num_parameters; ++i) { + for (int i = 0; i < glslp->num_parameters; ++i) { if (!strcmp(glslp->parameters[i].id, id)) { return &glslp->parameters[i]; } @@ -207,8 +209,7 @@ static struct parameter *get_parameter(glslp_t *glslp, const char *id) { } static glslp_t *glsl_parse(const char *f) { - glslp_t *glslp = (glslp_t*)malloc(sizeof(glslp_t)); - memset(glslp, 0, sizeof(glslp_t)); + glslp_t *glslp = (glslp_t*) calloc(1, sizeof(glslp_t)); glslp->num_shaders = 1; struct shader *shader = &glslp->shaders[0]; strcpy(shader->shader_fn, f); @@ -233,7 +234,9 @@ extern "C" { void get_glslp_name(const char *f, char *s, int size) { safe_strncpy(s, path_get_filename((char *)f), size); } glslp_t *glslp_parse(const char *f) { - int i, j, len, sublen; + int j; + int len; + int sublen; char s[513], t[513], z[540]; memset(s, 0, sizeof(s)); @@ -247,8 +250,7 @@ glslp_t *glslp_parse(const char *f) { return 0; } - glslp_t *glslp = (glslp_t*)malloc(sizeof(glslp_t)); - memset(glslp, 0, sizeof(glslp_t)); + glslp_t *glslp = (glslp_t*) calloc(1, sizeof(glslp_t)); get_glslp_name(f, glslp->name, sizeof(glslp->name)); @@ -256,7 +258,7 @@ glslp_t *glslp_parse(const char *f) { wx_config_get_bool(cfg, "filter_linear0", &glslp->input_filter_linear, -1); - for (i = 0; i < glslp->num_shaders; ++i) { + for (int i = 0; i < glslp->num_shaders; ++i) { struct shader *shader = &glslp->shaders[i]; snprintf(s, sizeof(s) - 1, "shader%d", i); @@ -267,12 +269,31 @@ glslp_t *glslp_parse(const char *f) { } strcpy(s, f); *path_get_filename(s) = 0; - snprintf(shader->shader_fn, sizeof(shader->shader_fn) - 1, "%s%s", s, t); + + size_t max_len = sizeof(shader->shader_fn); + size_t s_len = strlen(s); + + if (s_len >= max_len) { + // s alone fills or overflows the buffer, truncate and null-terminate + size_t copy_len = max_len - 1 < s_len ? max_len - 1 : s_len; + memcpy(shader->shader_fn, s, copy_len); + shader->shader_fn[copy_len] = '\0'; + } else { + // Copy s fully + memcpy(shader->shader_fn, s, s_len); + // Copy as much of t as fits after s + size_t avail = max_len - 1 - s_len; // space left for t + null terminator + // Copy as much of t as fits into the remaining space + memcpy(shader->shader_fn + s_len, t, avail); + // Null-terminate + shader->shader_fn[s_len + avail] = '\0'; + } + shader->shader_program = load_file(shader->shader_fn); if (!shader->shader_program) { - fprintf(stderr, "GLSLP Error: Could not load shader %s\n", shader->shader_fn); - glslp_free(glslp); - return 0; + fprintf(stderr, "GLSLP Error: Could not load shader %s\n", shader->shader_fn); + glslp_free(glslp); + return 0; } strip_parameters(shader->shader_program); strip_defines(shader->shader_program); @@ -327,7 +348,7 @@ glslp_t *glslp_parse(const char *f) { len = strlen(t); j = 0; sublen = 0; - for (i = 0; i < len; ++i) { + for (int i = 0; i < len; ++i) { if (t[i] == ';' || i == len - 1) { sublen = (i - j) + ((i == len - 1) ? 1 : 0) + 1; safe_strncpy(s, t + j, sublen); @@ -361,7 +382,7 @@ glslp_t *glslp_parse(const char *f) { len = strlen(t); j = 0; sublen = 0; - for (i = 0; i < len; ++i) { + for (int i = 0; i < len; ++i) { if (t[i] == ';' || i == len - 1) { sublen = (i - j) + ((i == len - 1) ? 1 : 0) + 1; safe_strncpy(s, t + j, sublen); @@ -382,8 +403,7 @@ glslp_t *glslp_parse(const char *f) { } void glslp_free(glslp_t *p) { - int i; - for (i = 0; i < p->num_shaders; ++i) + for (int i = 0; i < p->num_shaders; ++i) if (p->shaders[i].shader_program) free(p->shaders[i].shader_program); free(p); @@ -391,10 +411,9 @@ void glslp_free(glslp_t *p) { void glslp_read_shader_config(glslp_t *shader) { char s[512]; - int i; char *name = shader->name; - sprintf(s, "GL3 Shaders - %s", name); - for (i = 0; i < shader->num_parameters; ++i) { + snprintf(s, sizeof(s) -1, "GL3 Shaders - %s", name); + for (int i = 0; i < shader->num_parameters; ++i) { struct parameter *param = &shader->parameters[i]; param->value = config_get_double(s, param->id, param->default_value); } @@ -402,12 +421,11 @@ void glslp_read_shader_config(glslp_t *shader) { void glslp_write_shader_config(glslp_t *shader) { char s[512]; - int i; char *name = shader->name; startblit(); - sprintf(s, "GL3 Shaders - %s", name); - for (i = 0; i < shader->num_parameters; ++i) { + snprintf(s, sizeof(s) - 1, "GL3 Shaders - %s", name); + for (int i = 0; i < shader->num_parameters; ++i) { struct parameter *param = &shader->parameters[i]; config_set_double(s, param->id, param->value); } diff --git a/src/qt/qt_hardwarerenderer.cpp b/src/qt/qt_hardwarerenderer.cpp deleted file mode 100644 index fb84606b0..000000000 --- a/src/qt/qt_hardwarerenderer.cpp +++ /dev/null @@ -1,257 +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. - * - * Hardware renderer module. - * - * - * - * Authors: Joakim L. Gilje - * Cacodemon345 - * Teemu Korhonen - * - * Copyright 2021 Joakim L. Gilje - * Copyright 2021-2022 Cacodemon345 - * Copyright 2021-2022 Teemu Korhonen - */ -#include "qt_hardwarerenderer.hpp" -#include -#include -#include - -#include -#include -#include - -extern "C" { -#include <86box/86box.h> -#include <86box/plat.h> -#include <86box/video.h> -} - -void -HardwareRenderer::resizeGL(int w, int h) -{ - m_context->makeCurrent(this); - glViewport(0, 0, qRound(w * devicePixelRatioF()), qRound(h * devicePixelRatioF())); -} - -#define PROGRAM_VERTEX_ATTRIBUTE 0 -#define PROGRAM_TEXCOORD_ATTRIBUTE 1 - -void -HardwareRenderer::initializeGL() -{ - m_context->makeCurrent(this); - initializeOpenGLFunctions(); - auto image = QImage(2048, 2048, QImage::Format_RGB32); - image.fill(0xff000000); - m_texture = new QOpenGLTexture(image); - m_blt = new QOpenGLTextureBlitter; - m_blt->setRedBlueSwizzle(true); - m_blt->create(); - QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this); - const char *vsrc = "attribute highp vec4 VertexCoord;\n" - "attribute mediump vec4 TexCoord;\n" - "varying mediump vec4 texc;\n" - "uniform mediump mat4 MVPMatrix;\n" - "void main(void)\n" - "{\n" - " gl_Position = MVPMatrix * VertexCoord;\n" - " texc = TexCoord;\n" - "}\n"; - QString vsrccore = "in highp vec4 VertexCoord;\n" - "in mediump vec4 TexCoord;\n" - "out mediump vec4 texc;\n" - "uniform mediump mat4 MVPMatrix;\n" - "void main(void)\n" - "{\n" - " gl_Position = MVPMatrix * VertexCoord;\n" - " texc = TexCoord;\n" - "}\n"; - if (m_context->isOpenGLES() && m_context->format().version() >= qMakePair(3, 0)) { - vsrccore.prepend("#version 300 es\n"); - vshader->compileSourceCode(vsrccore); - } else if (m_context->format().version() >= qMakePair(3, 0) && m_context->format().profile() == QSurfaceFormat::CoreProfile) { - vsrccore.prepend("#version 130\n"); - vshader->compileSourceCode(vsrccore); - } else - vshader->compileSourceCode(vsrc); - - QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, this); - const char *fsrc = "uniform sampler2D texture;\n" - "varying mediump vec4 texc;\n" - "void main(void)\n" - "{\n" - " gl_FragColor = texture2D(texture, texc.st).bgra;\n" - "}\n"; - QString fsrccore = "uniform sampler2D texture;\n" - "in mediump vec4 texc;\n" - "out highp vec4 FragColor;\n" - "void main(void)\n" - "{\n" - " FragColor = texture2D(texture, texc.st).bgra;\n" - "}\n"; - if (m_context->isOpenGLES() && m_context->format().version() >= qMakePair(3, 0)) { - fsrccore.prepend("#version 300 es\n"); - fshader->compileSourceCode(fsrccore); - } else if (m_context->format().version() >= qMakePair(3, 0) && m_context->format().profile() == QSurfaceFormat::CoreProfile) { - fsrccore.prepend("#version 130\n"); - fshader->compileSourceCode(fsrccore); - } else - fshader->compileSourceCode(fsrc); - - m_prog = new QOpenGLShaderProgram; - m_prog->addShader(vshader); - m_prog->addShader(fshader); - m_prog->bindAttributeLocation("VertexCoord", PROGRAM_VERTEX_ATTRIBUTE); - m_prog->bindAttributeLocation("TexCoord", PROGRAM_TEXCOORD_ATTRIBUTE); - m_prog->link(); - - m_prog->bind(); - m_prog->setUniformValue("texture", 0); - - if (m_context->format().version() >= qMakePair(3, 0) && m_vao.create()) { - m_vao.bind(); - } - - m_vbo[PROGRAM_VERTEX_ATTRIBUTE].create(); - m_vbo[PROGRAM_VERTEX_ATTRIBUTE].bind(); - m_vbo[PROGRAM_VERTEX_ATTRIBUTE].allocate(sizeof(QVector2D) * 4); - m_vbo[PROGRAM_TEXCOORD_ATTRIBUTE].create(); - m_vbo[PROGRAM_TEXCOORD_ATTRIBUTE].bind(); - m_vbo[PROGRAM_TEXCOORD_ATTRIBUTE].allocate(sizeof(QVector2D) * 4); - - pclog("OpenGL vendor: %s\n", glGetString(GL_VENDOR)); - pclog("OpenGL renderer: %s\n", glGetString(GL_RENDERER)); - pclog("OpenGL version: %s\n", glGetString(GL_VERSION)); - pclog("OpenGL shader language version: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION)); - glClearColor(0, 0, 0, 1); - m_texture->setWrapMode(QOpenGLTexture::ClampToEdge); - glClear(GL_COLOR_BUFFER_BIT); - m_context->swapBuffers(this); -} - -void -HardwareRenderer::paintGL() -{ - m_context->makeCurrent(this); - glClear(GL_COLOR_BUFFER_BIT); - QVector verts; - QVector texcoords; - QMatrix4x4 mat; - mat.setToIdentity(); - mat.ortho(QRectF(0, 0, (qreal) width() * (qreal) devicePixelRatioF(), (qreal) height() * (qreal) devicePixelRatioF())); - verts.push_back(QVector2D((float) destination.x(), (float) destination.y())); - verts.push_back(QVector2D((float) destination.x(), (float) destination.y() + (float) destination.height())); - verts.push_back(QVector2D((float) destination.x() + (float) destination.width(), (float) destination.y() + (float) destination.height())); - verts.push_back(QVector2D((float) destination.x() + (float) destination.width(), (float) destination.y())); - texcoords.push_back(QVector2D((float) source.x() / 2048.f, (float) (source.y()) / 2048.f)); - texcoords.push_back(QVector2D((float) source.x() / 2048.f, (float) (source.y() + source.height()) / 2048.f)); - texcoords.push_back(QVector2D((float) (source.x() + source.width()) / 2048.f, (float) (source.y() + source.height()) / 2048.f)); - texcoords.push_back(QVector2D((float) (source.x() + source.width()) / 2048.f, (float) (source.y()) / 2048.f)); - - m_vbo[PROGRAM_VERTEX_ATTRIBUTE].bind(); - m_vbo[PROGRAM_VERTEX_ATTRIBUTE].write(0, verts.data(), sizeof(QVector2D) * 4); - m_vbo[PROGRAM_VERTEX_ATTRIBUTE].release(); - m_vbo[PROGRAM_TEXCOORD_ATTRIBUTE].bind(); - m_vbo[PROGRAM_TEXCOORD_ATTRIBUTE].write(0, texcoords.data(), sizeof(QVector2D) * 4); - m_vbo[PROGRAM_TEXCOORD_ATTRIBUTE].release(); - - m_prog->setUniformValue("MVPMatrix", mat); - m_prog->enableAttributeArray(PROGRAM_VERTEX_ATTRIBUTE); - m_prog->enableAttributeArray(PROGRAM_TEXCOORD_ATTRIBUTE); - - m_vbo[PROGRAM_VERTEX_ATTRIBUTE].bind(); - m_prog->setAttributeBuffer(PROGRAM_VERTEX_ATTRIBUTE, GL_FLOAT, 0, 2, 0); - m_vbo[PROGRAM_VERTEX_ATTRIBUTE].release(); - m_vbo[PROGRAM_TEXCOORD_ATTRIBUTE].bind(); - m_prog->setAttributeBuffer(PROGRAM_TEXCOORD_ATTRIBUTE, GL_FLOAT, 0, 2, 0); - m_vbo[PROGRAM_TEXCOORD_ATTRIBUTE].release(); - m_texture->bind(); - m_texture->setMinMagFilters(video_filter_method ? QOpenGLTexture::Linear : QOpenGLTexture::Nearest, video_filter_method ? QOpenGLTexture::Linear : QOpenGLTexture::Nearest); - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); -} - -void -HardwareRenderer::setRenderType(RenderType type) -{ - QSurfaceFormat format; - switch (type) { - case RenderType::OpenGL3: - format.setVersion(3, 0); - format.setProfile(QSurfaceFormat::CoreProfile); - case RenderType::OpenGL: - format.setRenderableType(QSurfaceFormat::OpenGL); - break; - case RenderType::OpenGLES: - format.setRenderableType(QSurfaceFormat::OpenGLES); - break; - } - format.setSwapInterval(0); - setFormat(format); -} - -void -HardwareRenderer::onBlit(int buf_idx, int x, int y, int w, int h) -{ - auto tval = this; - void *nuldata = 0; - if (memcmp(&tval, &nuldata, sizeof(void *)) == 0) - return; - auto origSource = source; - if (!m_texture || !m_texture->isCreated()) { - buf_usage[buf_idx].clear(); - source.setRect(x, y, w, h); - return; - } - m_context->makeCurrent(this); -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - m_texture->setData(x, y, 0, w, h, 0, QOpenGLTexture::PixelFormat::RGBA, QOpenGLTexture::PixelType::UInt8, (const void *) ((uintptr_t) imagebufs[buf_idx].get() + (uintptr_t) (2048 * 4 * y + x * 4)), &m_transferOptions); -#else - m_texture->bind(); - glPixelStorei(GL_UNPACK_ROW_LENGTH, 2048); - glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, QOpenGLTexture::PixelFormat::RGBA, QOpenGLTexture::PixelType::UInt8, (const void *) ((uintptr_t) imagebufs[buf_idx].get() + (uintptr_t) (2048 * 4 * y + x * 4))); - m_texture->release(); -#endif - buf_usage[buf_idx].clear(); - source.setRect(x, y, w, h); - if (origSource != source) { - this->pixelRatio = devicePixelRatioF(); - onResize(this->width(), this->height()); - } - update(); -} - -void -HardwareRenderer::resizeEvent(QResizeEvent *event) -{ - this->pixelRatio = devicePixelRatioF(); - onResize(width(), height()); - - QOpenGLWindow::resizeEvent(event); -} - -bool -HardwareRenderer::event(QEvent *event) -{ - bool res = false; - if (!eventDelegate(event, res)) - return QOpenGLWindow::event(event); - return res; -} - -std::vector> -HardwareRenderer::getBuffers() -{ - std::vector> buffers; - - buffers.push_back(std::make_tuple(imagebufs[0].get(), &buf_usage[0])); - buffers.push_back(std::make_tuple(imagebufs[1].get(), &buf_usage[1])); - - return buffers; -} diff --git a/src/qt/qt_hardwarerenderer.hpp b/src/qt/qt_hardwarerenderer.hpp deleted file mode 100644 index f7861d2bd..000000000 --- a/src/qt/qt_hardwarerenderer.hpp +++ /dev/null @@ -1,103 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "qt_renderercommon.hpp" - -#ifdef WAYLAND -# include "wl_mouse.hpp" -#endif - -class HardwareRenderer : public QOpenGLWindow, protected QOpenGLFunctions, public RendererCommon { - Q_OBJECT - -private: - bool wayland = false; - QOpenGLContext *m_context; - QOpenGLTexture *m_texture { nullptr }; - QOpenGLShaderProgram *m_prog { nullptr }; - QOpenGLTextureBlitter *m_blt { nullptr }; - QOpenGLBuffer m_vbo[2]; - QOpenGLVertexArrayObject m_vao; - QOpenGLPixelTransferOptions m_transferOptions; - -public: - enum class RenderType { - OpenGL, - OpenGLES, - OpenGL3, - }; - void resizeGL(int w, int h) override; - void initializeGL() override; - void paintGL() override; - void exposeEvent(QExposeEvent *event) override - { - onResize(size().width(), size().height()); - } - - std::vector> getBuffers() override; - HardwareRenderer(QWidget *parent = nullptr, RenderType rtype = RenderType::OpenGL) - : QOpenGLWindow(QOpenGLWindow::NoPartialUpdate, parent->windowHandle()) - , QOpenGLFunctions() - { - imagebufs[0] = std::unique_ptr(new uint8_t[2048 * 2048 * 4]); - imagebufs[1] = std::unique_ptr(new uint8_t[2048 * 2048 * 4]); - - buf_usage = std::vector(2); - buf_usage[0].clear(); - buf_usage[1].clear(); - - setMinimumSize(QSize(16, 16)); - setFlags(Qt::FramelessWindowHint); - parentWidget = parent; - setRenderType(rtype); - - m_transferOptions.setRowLength(2048); - - m_context = new QOpenGLContext(); - m_context->setFormat(format()); - m_context->create(); - update(); - } - ~HardwareRenderer() - { - m_context->makeCurrent(this); - if (m_blt) - m_blt->destroy(); - m_prog->release(); - delete m_prog; - m_prog = nullptr; - m_context->doneCurrent(); - delete m_context; - } - - void setRenderType(RenderType type); - -public slots: - void onBlit(int buf_idx, int x, int y, int w, int h); - -protected: - std::array, 2> imagebufs; - - void resizeEvent(QResizeEvent *event) override; - bool event(QEvent *event) override; -}; diff --git a/src/qt/qt_keybind.hpp b/src/qt/qt_keybind.hpp index 393ee0f5c..25f4a9168 100644 --- a/src/qt/qt_keybind.hpp +++ b/src/qt/qt_keybind.hpp @@ -26,8 +26,8 @@ public: private: Ui::KeyBinder *ui; - bool eventFilter(QObject *obj, QEvent *event); - void showEvent( QShowEvent* event ); + bool eventFilter(QObject *obj, QEvent *event) override; + void showEvent( QShowEvent* event ) override; }; #endif // QT_KeyBinder_HPP diff --git a/src/qt/qt_main.cpp b/src/qt/qt_main.cpp index 72c892af7..afb5fcc1d 100644 --- a/src/qt/qt_main.cpp +++ b/src/qt/qt_main.cpp @@ -55,6 +55,7 @@ extern "C" { #endif #include <86box/gdbstub.h> #include <86box/version.h> +#include <86box/renderdefs.h> } #ifdef Q_OS_WINDOWS @@ -77,6 +78,8 @@ extern "C" { #include "qt_styleoverride.hpp" #include "qt_unixmanagerfilter.hpp" #include "qt_util.hpp" +#include "qt_vmmanager_clientsocket.hpp" +#include "qt_vmmanager_mainwindow.hpp" // Void Cast #define VC(x) const_cast(x) @@ -662,6 +665,19 @@ main(int argc, char *argv[]) return 0; } + if (vmm_enabled) { + // VMManagerMain vmm; + // // Hackish until there is a proper solution + // QApplication::setApplicationName("86Box VM Manager"); + // QApplication::setApplicationDisplayName("86Box VM Manager"); + // vmm.show(); + // vmm.exec(); + const auto vmm_main_window = new VMManagerMainWindow(); + vmm_main_window->show(); + QApplication::exec(); + return 0; + } + #ifdef DISCORD discord_load(); #endif @@ -758,6 +774,36 @@ main(int argc, char *argv[]) socket.connectToServer(qgetenv("86BOX_MANAGER_SOCKET")); } + VMManagerClientSocket manager_socket; + if (qgetenv("VMM_86BOX_SOCKET").size()) { + manager_socket.IPCConnect(qgetenv("VMM_86BOX_SOCKET")); + QObject::connect(&manager_socket, &VMManagerClientSocket::pause, main_window, &MainWindow::togglePause); + QObject::connect(&manager_socket, &VMManagerClientSocket::resetVM, main_window, &MainWindow::hardReset); + QObject::connect(&manager_socket, &VMManagerClientSocket::showsettings, main_window, &MainWindow::showSettings); + QObject::connect(&manager_socket, &VMManagerClientSocket::ctrlaltdel, []() { pc_send_cad(); }); + QObject::connect(&manager_socket, &VMManagerClientSocket::request_shutdown, main_window, &MainWindow::close); + QObject::connect(&manager_socket, &VMManagerClientSocket::force_shutdown, []() { + do_stop(); + emit main_window->close(); + }); + QObject::connect(main_window, &MainWindow::vmmRunningStateChanged, &manager_socket, &VMManagerClientSocket::clientRunningStateChanged); + main_window->installEventFilter(&manager_socket); + } + + /* Warn the user about unsupported configs */ + if (cpu_override) { + QMessageBox warningbox(QMessageBox::Icon::Warning, QObject::tr("You are loading an unsupported configuration"), + QObject::tr("CPU type filtering based on selected machine is disabled for this emulated machine.\n\nThis makes it possible to choose a CPU that is otherwise incompatible with the selected machine. However, you may run into incompatibilities with the machine BIOS or other software.\n\nEnabling this setting is not officially supported and any bug reports filed may be closed as invalid."), + QMessageBox::NoButton, main_window); + warningbox.addButton(QObject::tr("Continue"), QMessageBox::AcceptRole); + warningbox.addButton(QObject::tr("Exit"), QMessageBox::RejectRole); + warningbox.exec(); + if (warningbox.result() == QDialog::Accepted) { + confirm_exit_cmdl = 0; /* skip the confirmation prompt without touching the config */ + emit main_window->close(); + } + } + // pc_reset_hard_init(); QTimer onesec; @@ -790,7 +836,7 @@ main(int argc, char *argv[]) /* Set the PAUSE mode depending on the renderer. */ #ifdef USE_VNC - if (vid_api == 5) + if (vid_api == RENDERER_VNC) plat_pause(1); else #endif diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 4594ee5be..6f87c3ce0 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -52,6 +52,7 @@ extern "C" { #include <86box/apm.h> #include <86box/nvr.h> #include <86box/acpi.h> +#include <86box/renderdefs.h> #ifdef USE_VNC # include <86box/vnc.h> @@ -420,29 +421,17 @@ MainWindow::MainWindow(QWidget *parent) ui->actionEnable_Discord_integration->setEnabled(discord_loaded); #endif -#if defined Q_OS_WINDOWS || defined Q_OS_MACOS - /* Make the option visible only if ANGLE is loaded. */ - ui->actionHardware_Renderer_OpenGL_ES->setVisible(QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES); - if (QOpenGLContext::openGLModuleType() != QOpenGLContext::LibGLES && vid_api == 2) - vid_api = 1; -#endif - ui->actionHardware_Renderer_OpenGL->setVisible(QOpenGLContext::openGLModuleType() != QOpenGLContext::LibGLES); - if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES && vid_api == 1) - vid_api = 0; - if ((QApplication::platformName().contains("eglfs") || QApplication::platformName() == "haiku")) { - if (vid_api >= 1) + if ((vid_api == RENDERER_OPENGL3) || (vid_api == RENDERER_VULKAN)) fprintf(stderr, "OpenGL renderers are unsupported on %s.\n", QApplication::platformName().toUtf8().data()); - vid_api = 0; - ui->actionHardware_Renderer_OpenGL->setVisible(false); - ui->actionHardware_Renderer_OpenGL_ES->setVisible(false); + vid_api = RENDERER_SOFTWARE; ui->actionVulkan->setVisible(false); ui->actionOpenGL_3_0_Core->setVisible(false); } #ifndef USE_VNC - if (vid_api == 5) - vid_api = 0; + if (vid_api == RENDERER_VNC) + vid_api = RENDERER_SOFTWARE; ui->actionVNC->setVisible(false); #endif @@ -462,15 +451,13 @@ MainWindow::MainWindow(QWidget *parent) if (!vulkanAvailable) #endif { - if (vid_api == 4) - vid_api = 0; + if (vid_api == RENDERER_VULKAN) + vid_api = RENDERER_SOFTWARE; ui->actionVulkan->setVisible(false); } auto actGroup = new QActionGroup(this); actGroup->addAction(ui->actionSoftware_Renderer); - actGroup->addAction(ui->actionHardware_Renderer_OpenGL); - actGroup->addAction(ui->actionHardware_Renderer_OpenGL_ES); actGroup->addAction(ui->actionOpenGL_3_0_Core); actGroup->addAction(ui->actionVulkan); actGroup->addAction(ui->actionVNC); @@ -479,7 +466,7 @@ MainWindow::MainWindow(QWidget *parent) connect(actGroup, &QActionGroup::triggered, [this](QAction *action) { vid_api = action->property("vid_api").toInt(); #ifdef USE_VNC - if (vnc_enabled && vid_api != 5) { + if (vnc_enabled && vid_api != RENDERER_VNC) { startblit(); vnc_enabled = 0; vnc_close(); @@ -491,23 +478,17 @@ MainWindow::MainWindow(QWidget *parent) switch (vid_api) { default: break; - case 0: + case RENDERER_SOFTWARE: newVidApi = RendererStack::Renderer::Software; break; - case 1: - newVidApi = RendererStack::Renderer::OpenGL; - break; - case 2: - newVidApi = RendererStack::Renderer::OpenGLES; - break; - case 3: + case RENDERER_OPENGL3: newVidApi = RendererStack::Renderer::OpenGL3; break; - case 4: + case RENDERER_VULKAN: newVidApi = RendererStack::Renderer::Vulkan; break; #ifdef USE_VNC - case 5: + case RENDERER_VNC: { newVidApi = RendererStack::Renderer::Software; startblit(); @@ -2131,6 +2112,7 @@ MainWindow::updateUiPauseState() QString(tr("Pause execution")); ui->actionPause->setIcon(pause_icon); ui->actionPause->setToolTip(tooltip_text); + emit vmmRunningStateChanged(static_cast(dopause)); } void diff --git a/src/qt/qt_mainwindow.hpp b/src/qt/qt_mainwindow.hpp index 917fd43f5..54a04a975 100644 --- a/src/qt/qt_mainwindow.hpp +++ b/src/qt/qt_mainwindow.hpp @@ -13,6 +13,8 @@ #include #include +#include "qt_vmmanager_protocol.hpp" + class MediaMenu; class RendererStack; @@ -63,6 +65,8 @@ signals: void showMessageForNonQtThread(int flags, const QString &header, const QString &message, bool richText, std::atomic_bool* done); void getTitleForNonQtThread(wchar_t *title); + + void vmmRunningStateChanged(VMManagerProtocol::RunningState state); public slots: void showSettings(); void hardReset(); diff --git a/src/qt/qt_mainwindow.ui b/src/qt/qt_mainwindow.ui index 83a80342b..63bc0b01b 100644 --- a/src/qt/qt_mainwindow.ui +++ b/src/qt/qt_mainwindow.ui @@ -121,8 +121,6 @@ Re&nderer - - @@ -399,28 +397,6 @@ 0 - - - true - - - Qt (&OpenGL) - - - 1 - - - - - true - - - Qt (OpenGL &ES) - - - 2 - - true @@ -751,7 +727,7 @@ Open&GL (3.0 Core) - 3 + 1 @@ -843,7 +819,7 @@ &Vulkan - 4 + 2 @@ -867,7 +843,7 @@ VNC - 5 + 3 diff --git a/src/qt/qt_mediamenu.cpp b/src/qt/qt_mediamenu.cpp index 351012d1e..11fac2a70 100644 --- a/src/qt/qt_mediamenu.cpp +++ b/src/qt/qt_mediamenu.cpp @@ -1081,6 +1081,9 @@ MediaMenu::nicUpdateMenu(int i) case NET_TYPE_VDE: netType = "VDE"; break; + case NET_TYPE_TAP: + netType = "TAP"; + break; } QString devName = DeviceConfig::DeviceName(network_card_getdevice(net_cards_conf[i].device_num), network_card_get_internal_name(net_cards_conf[i].device_num), 1); diff --git a/src/qt/qt_openglrenderer.cpp b/src/qt/qt_openglrenderer.cpp index 9ca2d887e..f1fa5eecf 100644 --- a/src/qt/qt_openglrenderer.cpp +++ b/src/qt/qt_openglrenderer.cpp @@ -303,27 +303,27 @@ OpenGLRenderer::find_uniforms(struct glsl_shader *glsl, int num_pass) u->orig.texture_size = get_uniform(p, "OrigTextureSize"); for (i = 0; i < glsl->num_passes; ++i) { - sprintf(s, "Pass%dTexture", (i + 1)); + snprintf(s, sizeof(s) -1, "Pass%dTexture", (i + 1)); u->pass[i].texture = get_uniform(p, s); - sprintf(s, "Pass%dInputSize", (i + 1)); + snprintf(s, sizeof(s) -1, "Pass%dInputSize", (i + 1)); u->pass[i].input_size = get_uniform(p, s); - sprintf(s, "Pass%dTextureSize", (i + 1)); + snprintf(s, sizeof(s) -1, "Pass%dTextureSize", (i + 1)); u->pass[i].texture_size = get_uniform(p, s); - sprintf(s, "PassPrev%dTexture", num_pass - i); + snprintf(s, sizeof(s) -1, "PassPrev%dTexture", num_pass - i); u->prev_pass[i].texture = get_uniform(p, s); - sprintf(s, "PassPrev%dInputSize", num_pass - i); + snprintf(s, sizeof(s) -1, "PassPrev%dInputSize", num_pass - i); u->prev_pass[i].input_size = get_uniform(p, s); - sprintf(s, "PassPrev%dTextureSize", num_pass - i); + snprintf(s, sizeof(s) -1, "PassPrev%dTextureSize", num_pass - i); u->prev_pass[i].texture_size = get_uniform(p, s); } u->prev[0].texture = get_uniform(p, "PrevTexture"); u->prev[0].tex_coord = get_attrib(p, "PrevTexCoord"); for (i = 1; i < MAX_PREV; ++i) { - sprintf(s, "Prev%dTexture", i); + snprintf(s, sizeof(s) -1, "Prev%dTexture", i); u->prev[i].texture = get_uniform(p, s); - sprintf(s, "Prev%dTexCoord", i); + snprintf(s, sizeof(s) -1, "Prev%dTexCoord", i); u->prev[i].tex_coord = get_attrib(p, s); } for (i = 0; i < MAX_PREV; ++i) @@ -434,23 +434,21 @@ OpenGLRenderer::delete_prev(struct shader_prev *prev) void OpenGLRenderer::delete_shader(struct glsl_shader *glsl) { - int i; - for (i = 0; i < glsl->num_passes; ++i) + for (int i = 0; i < glsl->num_passes; ++i) delete_pass(&glsl->passes[i]); if (glsl->has_prev) { delete_pass(&glsl->prev_scene); - for (i = 0; i < MAX_PREV; ++i) + for (int i = 0; i < MAX_PREV; ++i) delete_prev(&glsl->prev[i]); } - for (i = 0; i < glsl->num_lut_textures; ++i) + for (int i = 0; i < glsl->num_lut_textures; ++i) delete_texture(&glsl->lut_textures[i].texture); } void OpenGLRenderer::delete_glsl(glsl_t *glsl) { - int i; - for (i = 0; i < glsl->num_shaders; ++i) + for (int i = 0; i < glsl->num_shaders; ++i) delete_shader(&glsl->shaders[i]); delete_pass(&glsl->scene); delete_pass(&glsl->fs_color); @@ -622,7 +620,6 @@ load_texture(const char *f, struct shader_texture *tex) glsl_t * OpenGLRenderer::load_glslp(glsl_t *glsl, int num_shader, const char *f) { - int i, j; glslp_t *p = glslp_parse(f); if (p) { @@ -639,10 +636,10 @@ OpenGLRenderer::load_glslp(glsl_t *glsl, int num_shader, const char *f) gshader->num_lut_textures = p->num_textures; - for (i = 0; i < p->num_textures; ++i) { + for (int i = 0; i < p->num_textures; ++i) { struct texture *texture = &p->textures[i]; - sprintf(file, "%s%s", path, texture->path); + snprintf(file, sizeof(file) - 1, "%s%s", path, texture->path); struct shader_lut_texture *tex = &gshader->lut_textures[i]; strcpy(tex->name, texture->name); @@ -681,18 +678,18 @@ OpenGLRenderer::load_glslp(glsl_t *glsl, int num_shader, const char *f) gshader->input_filter_linear = p->input_filter_linear; gshader->num_parameters = p->num_parameters; - for (j = 0; j < gshader->num_parameters; ++j) + for (int j = 0; j < gshader->num_parameters; ++j) memcpy(&gshader->parameters[j], &p->parameters[j], sizeof(struct shader_parameter)); gshader->num_passes = p->num_shaders; - for (i = 0; i < p->num_shaders; ++i) { + for (int i = 0; i < p->num_shaders; ++i) { struct shader *shader = &p->shaders[i]; struct shader_pass *pass = &gshader->passes[i]; strcpy(pass->alias, shader->alias); if (!strlen(pass->alias)) - sprintf(pass->alias, "Pass %u", (i + 1)); + snprintf(pass->alias, sizeof(pass->alias) - 1, "Pass %u", (i + 1)); ogl3_log("Creating pass %u (%s)\n", (i + 1), pass->alias); ogl3_log("Loading shader %s...\n", shader->shader_fn); @@ -726,7 +723,7 @@ OpenGLRenderer::load_glslp(glsl_t *glsl, int num_shader, const char *f) if (num_shader == glsl->num_shaders - 1) { pass->fbo.id = -1; - for (j = 0; j < 2; ++j) { + for (uint8_t j = 0; j < 2; ++j) { if (pass->scale.mode[j] != SCALE_SOURCE || pass->scale.value[j] != 1) { setup_fbo(shader, &pass->fbo); break; @@ -755,7 +752,7 @@ OpenGLRenderer::load_glslp(glsl_t *glsl, int num_shader, const char *f) if (gshader->has_prev) { struct shader scene_shader_conf; memset(&scene_shader_conf, 0, sizeof(struct shader)); - for (i = 0; i < MAX_PREV; ++i) { + for (int i = 0; i < MAX_PREV; ++i) { setup_fbo(&scene_shader_conf, &gshader->prev[i].fbo); } } @@ -772,7 +769,6 @@ OpenGLRenderer::load_glslp(glsl_t *glsl, int num_shader, const char *f) glsl_t * OpenGLRenderer::load_shaders(int num, char shaders[MAX_USER_SHADERS][512]) { - int i; glsl_t *glsl; glsl = (glsl_t *) malloc(sizeof(glsl_t)); @@ -780,7 +776,7 @@ OpenGLRenderer::load_shaders(int num, char shaders[MAX_USER_SHADERS][512]) glsl->num_shaders = num; int failed = 0; - for (i = num - 1; i >= 0; --i) { + for (int i = num - 1; i >= 0; --i) { const char *f = shaders[i]; if (f && strlen(f)) { if (!load_glslp(glsl, i, f)) { @@ -800,13 +796,12 @@ void OpenGLRenderer::read_shader_config() { char s[512]; - int i, j; - for (i = 0; i < active_shader->num_shaders; ++i) { + for (int i = 0; i < active_shader->num_shaders; ++i) { struct glsl_shader *shader = &active_shader->shaders[i]; char *name = shader->name; - sprintf(s, "GL3 Shaders - %s", name); + snprintf(s, sizeof(s) -1, "GL3 Shaders - %s", name); // shader->shader_refresh_rate = config_get_float(CFG_MACHINE, s, "shader_refresh_rate", -1); - for (j = 0; j < shader->num_parameters; ++j) { + for (int j = 0; j < shader->num_parameters; ++j) { struct shader_parameter *param = &shader->parameters[j]; param->value = config_get_double(s, param->id, param->default_value); } @@ -1233,7 +1228,6 @@ OpenGLRenderer::resizeEvent(QResizeEvent *event) void OpenGLRenderer::render_pass(struct render_data *data) { - int i; GLuint texture_unit = 0; // ogl3_log("pass %d: %gx%g, %gx%g -> %gx%g, %gx%g, %gx%g\n", num_pass, pass->state.input_size[0], @@ -1278,7 +1272,7 @@ OpenGLRenderer::render_pass(struct render_data *data) if (data->shader) { /* parameters */ - for (i = 0; i < data->shader->num_parameters; ++i) + for (int i = 0; i < data->shader->num_parameters; ++i) if (u->parameters[i] >= 0) glw.glUniform1f(u->parameters[i], data->shader->parameters[i].value); @@ -1296,7 +1290,7 @@ OpenGLRenderer::render_pass(struct render_data *data) if (u->orig.texture_size >= 0) glw.glUniform2fv(u->orig.texture_size, 1, orig->state.input_texture_size); - for (i = 0; i < data->pass; ++i) { + for (int i = 0; i < data->pass; ++i) { if (u->pass[i].texture >= 0) { glw.glActiveTexture(GL_TEXTURE0 + texture_unit); glw.glBindTexture(GL_TEXTURE_2D, passes[i].fbo.texture.id); @@ -1323,7 +1317,7 @@ OpenGLRenderer::render_pass(struct render_data *data) if (data->shader->has_prev) { /* loop through each previous frame */ - for (i = 0; i < MAX_PREV; ++i) { + for (int i = 0; i < MAX_PREV; ++i) { if (u->prev[i].texture >= 0) { glw.glActiveTexture(GL_TEXTURE0 + texture_unit); glw.glBindTexture(GL_TEXTURE_2D, data->shader->prev[i].fbo.texture.id); @@ -1340,7 +1334,7 @@ OpenGLRenderer::render_pass(struct render_data *data) } } - for (i = 0; i < data->shader->num_lut_textures; ++i) { + for (int i = 0; i < data->shader->num_lut_textures; ++i) { if (u->lut_textures[i] >= 0) { glw.glActiveTexture(GL_TEXTURE0 + texture_unit); glw.glBindTexture(GL_TEXTURE_2D, data->shader->lut_textures[i].texture.id); @@ -1364,7 +1358,7 @@ OpenGLRenderer::render_pass(struct render_data *data) glw.glDisableVertexAttribArray(data->shader_pass->uniforms.color); if (data->shader && data->shader->has_prev) { - for (i = 0; i < MAX_PREV; ++i) { + for (int i = 0; i < MAX_PREV; ++i) { if (u->prev[i].tex_coord >= 0) glw.glDisableVertexAttribArray(u->prev[i].tex_coord); } @@ -1401,10 +1395,11 @@ OpenGLRenderer::render() if (notReady()) return; - int s, i, j; - struct { - uint32_t x, y, w, h; + uint32_t x; + uint32_t y; + uint32_t w; + uint32_t h; } window_rect; window_rect.x = destination.x(); @@ -1434,7 +1429,10 @@ OpenGLRenderer::render() struct shader_pass *pass = &active_shader->scene; struct { - uint32_t x, y, w, h; + uint32_t x; + uint32_t y; + uint32_t w; + uint32_t h; } rect; rect.x = 0; rect.y = 0; @@ -1496,20 +1494,20 @@ OpenGLRenderer::render() struct shader_pass *orig = &active_shader->scene; struct shader_pass *input = &active_shader->scene; - for (s = 0; s < active_shader->num_shaders; ++s) { + for (int s = 0; s < active_shader->num_shaders; ++s) { struct glsl_shader *shader = &active_shader->shaders[s]; int frame_count = frameCounter; /* loop through each pass */ - for (i = 0; i < shader->num_passes; ++i) { + for (int i = 0; i < shader->num_passes; ++i) { bool resetFiltering = false; struct shader_pass *pass = &shader->passes[i]; memcpy(pass->state.input_size, input->state.output_size, 2 * sizeof(GLfloat)); memcpy(pass->state.input_texture_size, input->state.output_texture_size, 2 * sizeof(GLfloat)); - for (j = 0; j < 2; ++j) { + for (uint8_t j = 0; j < 2; ++j) { if (pass->scale.mode[j] == SCALE_VIEWPORT) pass->state.output_size[j] = orig_output_size[j] * pass->scale.value[j]; else if (pass->scale.mode[j] == SCALE_ABSOLUTE) @@ -1640,7 +1638,7 @@ OpenGLRenderer::render() memcpy(pass->state.input_size, input->state.output_size, 2 * sizeof(GLfloat)); memcpy(pass->state.input_texture_size, input->state.output_texture_size, 2 * sizeof(GLfloat)); - for (j = 0; j < 2; ++j) { + for (uint8_t j = 0; j < 2; ++j) { if (pass->scale.mode[j] == SCALE_VIEWPORT) pass->state.output_size[j] = orig_output_size[j] * pass->scale.value[j]; else if (pass->scale.mode[j] == SCALE_ABSOLUTE) diff --git a/src/qt/qt_openglrenderer.hpp b/src/qt/qt_openglrenderer.hpp index 4d1f68acb..776a2f53e 100644 --- a/src/qt/qt_openglrenderer.hpp +++ b/src/qt/qt_openglrenderer.hpp @@ -34,6 +34,7 @@ # include #endif +#include #include #include #include diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index a8c25bc2d..8677a6a91 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -341,9 +341,25 @@ path_get_slash(char *path) void path_append_filename(char *dest, const char *s1, const char *s2) { - strcpy(dest, s1); - path_slash(dest); - strcat(dest, s2); + size_t dest_size = 260; + size_t len; + + if (!dest || !s1 || !s2) + return; + + snprintf(dest, dest_size, "%s", s1); + len = strlen(dest); + + if (len > 0 && dest[len - 1] != '/' && dest[len - 1] != '\\') { + if (len + 1 < dest_size) { + dest[len++] = '/'; + dest[len] = '\0'; + } + } + + if (len < dest_size - 1) { + strncat(dest, s2, dest_size - len - 1); + } } void @@ -776,8 +792,8 @@ plat_set_thread_name(void *thread, const char *name) if (pSetThreadDescription) { size_t len = strlen(name) + 1; - wchar_t wname[len + 1]; - mbstowcs(wname, name, len); + wchar_t wname[2048]; + mbstowcs(wname, name, (len >= 1024) ? 1024 : len); pSetThreadDescription(thread ? (HANDLE) thread : GetCurrentThread(), wname); } #else diff --git a/src/qt/qt_rendererstack.cpp b/src/qt/qt_rendererstack.cpp index 31cc495b0..5256de3d6 100644 --- a/src/qt/qt_rendererstack.cpp +++ b/src/qt/qt_rendererstack.cpp @@ -21,7 +21,6 @@ #include "qt_rendererstack.hpp" #include "ui_qt_rendererstack.h" -#include "qt_hardwarerenderer.hpp" #include "qt_openglrenderer.hpp" #include "qt_softwarerenderer.hpp" #include "qt_vulkanwindowrenderer.hpp" @@ -41,6 +40,22 @@ #include #include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#ifdef WAYLAND +# include "wl_mouse.hpp" +#endif + #ifdef __APPLE__ # include #endif @@ -336,24 +351,6 @@ RendererStack::createRenderer(Renderer renderer) #endif } break; - case Renderer::OpenGL: - { - this->createWinId(); - auto hw = new HardwareRenderer(this); - rendererWindow = hw; - connect(this, &RendererStack::blitToRenderer, hw, &HardwareRenderer::onBlit, Qt::QueuedConnection); - current.reset(this->createWindowContainer(hw, this)); - break; - } - case Renderer::OpenGLES: - { - this->createWinId(); - auto hw = new HardwareRenderer(this, HardwareRenderer::RenderType::OpenGLES); - rendererWindow = hw; - connect(this, &RendererStack::blitToRenderer, hw, &HardwareRenderer::onBlit, Qt::QueuedConnection); - current.reset(this->createWindowContainer(hw, this)); - break; - } case Renderer::OpenGL3: { this->createWinId(); diff --git a/src/qt/qt_rendererstack.hpp b/src/qt/qt_rendererstack.hpp index 3a76f3ada..99de85c99 100644 --- a/src/qt/qt_rendererstack.hpp +++ b/src/qt/qt_rendererstack.hpp @@ -80,8 +80,6 @@ public: enum class Renderer { Software, - OpenGL, - OpenGLES, OpenGL3, Vulkan, None = -1 diff --git a/src/qt/qt_settingsnetwork.cpp b/src/qt/qt_settingsnetwork.cpp index 2e64175eb..9f97bacd6 100644 --- a/src/qt/qt_settingsnetwork.cpp +++ b/src/qt/qt_settingsnetwork.cpp @@ -36,18 +36,22 @@ SettingsNetwork::enableElements(Ui::SettingsNetwork *ui) auto *nic_cbox = findChild(QString("comboBoxNIC%1").arg(i + 1)); auto *net_type_cbox = findChild(QString("comboBoxNet%1").arg(i + 1)); - auto *intf_label = findChild(QString("labelIntf%1").arg(i + 1)); - auto *intf_cbox = findChild(QString("comboBoxIntf%1").arg(i + 1)); + auto *intf_label = findChild(QString("labelIntf%1").arg(i + 1)); + auto *intf_cbox = findChild(QString("comboBoxIntf%1").arg(i + 1)); auto *conf_btn = findChild(QString("pushButtonConf%1").arg(i + 1)); // auto *net_type_conf_btn = findChild(QString("pushButtonNetTypeConf%1").arg(i + 1)); auto *vde_socket_label = findChild(QString("labelSocketVDENIC%1").arg(i + 1)); - auto *socket_line = findChild(QString("socketVDENIC%1").arg(i + 1)); + auto *socket_line = findChild(QString("socketVDENIC%1").arg(i + 1)); + + auto *bridge_label = findChild(QString("labelBridgeTAPNIC%1").arg(i + 1)); + auto *bridge_line = findChild(QString("bridgeTAPNIC%1").arg(i + 1)); auto *option_list_label = findChild(QString("labelOptionList%1").arg(i + 1)); - auto *option_list_line = findChild(QString("lineOptionList%1").arg(i + 1)); + auto *option_list_line = findChild(QString("lineOptionList%1").arg(i + 1)); + bridge_line->setEnabled(net_type_cbox->currentData().toInt() == NET_TYPE_TAP); intf_cbox->setEnabled(net_type_cbox->currentData().toInt() == NET_TYPE_PCAP); conf_btn->setEnabled(network_card_has_config(nic_cbox->currentData().toInt())); // net_type_conf_btn->setEnabled(network_type_has_config(netType)); @@ -60,6 +64,10 @@ SettingsNetwork::enableElements(Ui::SettingsNetwork *ui) vde_socket_label->setVisible(false); socket_line->setVisible(false); + // TAP + bridge_label->setVisible(false); + bridge_line->setVisible(false); + // PCAP intf_cbox->setVisible(false); intf_label->setVisible(false); @@ -86,6 +94,14 @@ SettingsNetwork::enableElements(Ui::SettingsNetwork *ui) intf_label->setVisible(true); break; + case NET_TYPE_TAP: + // option_list_label->setText("TAP Options"); + option_list_label->setVisible(true); + option_list_line->setVisible(true); + + bridge_label->setVisible(true); + bridge_line->setVisible(true); + case NET_TYPE_SLIRP: default: break; @@ -123,6 +139,7 @@ SettingsNetwork::save() for (int i = 0; i < NET_CARD_MAX; ++i) { auto *cbox = findChild(QString("comboBoxNIC%1").arg(i + 1)); auto *socket_line = findChild(QString("socketVDENIC%1").arg(i + 1)); + auto *bridge_line = findChild(QString("bridgeTAPNIC%1").arg(i + 1)); net_cards_conf[i].device_num = cbox->currentData().toInt(); cbox = findChild(QString("comboBoxNet%1").arg(i + 1)); net_cards_conf[i].net_type = cbox->currentData().toInt(); @@ -132,6 +149,8 @@ SettingsNetwork::save() strncpy(net_cards_conf[i].host_dev_name, network_devs[cbox->currentData().toInt()].device, sizeof(net_cards_conf[i].host_dev_name) - 1); else if (net_cards_conf[i].net_type == NET_TYPE_VDE) strncpy(net_cards_conf[i].host_dev_name, socket_line->text().toUtf8().constData(), sizeof(net_cards_conf[i].host_dev_name)); + else if (net_cards_conf[i].net_type == NET_TYPE_TAP) + strncpy(net_cards_conf[i].host_dev_name, bridge_line->text().toUtf8().constData(), sizeof(net_cards_conf[i].host_dev_name)); } } @@ -198,6 +217,8 @@ SettingsNetwork::onCurrentMachineChanged(int machineId) if (network_devmap.has_vde) Models::AddEntry(model, "VDE", NET_TYPE_VDE); + Models::AddEntry(model, "TAP", NET_TYPE_TAP); + model->removeRows(0, removeRows); cbox->setCurrentIndex(cbox->findData(net_cards_conf[i].net_type)); @@ -216,12 +237,16 @@ SettingsNetwork::onCurrentMachineChanged(int machineId) } model->removeRows(0, removeRows); cbox->setCurrentIndex(selectedRow); - } + } if (net_cards_conf[i].net_type == NET_TYPE_VDE) { QString currentVdeSocket = net_cards_conf[i].host_dev_name; auto editline = findChild(QString("socketVDENIC%1").arg(i+1)); editline->setText(currentVdeSocket); + } else if (net_cards_conf[i].net_type == NET_TYPE_TAP) { + QString currentTapDevice = net_cards_conf[i].host_dev_name; + auto editline = findChild(QString("bridgeTAPNIC%1").arg(i+1)); + editline->setText(currentTapDevice); } } } diff --git a/src/qt/qt_settingsnetwork.ui b/src/qt/qt_settingsnetwork.ui index 0c0979c46..7aff676d6 100644 --- a/src/qt/qt_settingsnetwork.ui +++ b/src/qt/qt_settingsnetwork.ui @@ -31,7 +31,6 @@ 0 - Network Card #1 @@ -156,7 +155,21 @@ - + + + + TAP Bridge Device + + + + + + + 127 + + + + Qt::Vertical @@ -171,7 +184,6 @@ - Network Card #2 @@ -296,7 +308,21 @@ - + + + + TAP Bridge Device + + + + + + + 127 + + + + Qt::Vertical @@ -311,7 +337,6 @@ - Network Card #3 @@ -436,7 +461,21 @@ - + + + + TAP Bridge Device + + + + + + + 127 + + + + Qt::Vertical @@ -451,7 +490,6 @@ - Network Card #4 @@ -576,7 +614,21 @@ - + + + + TAP Bridge Device + + + + + + + 127 + + + + Qt::Vertical @@ -591,7 +643,6 @@ - diff --git a/src/qt/qt_settingsstoragecontrollers.cpp b/src/qt/qt_settingsstoragecontrollers.cpp index b3d827fa2..d282bcb8b 100644 --- a/src/qt/qt_settingsstoragecontrollers.cpp +++ b/src/qt/qt_settingsstoragecontrollers.cpp @@ -243,7 +243,7 @@ SettingsStorageControllers::on_comboBoxFD_currentIndexChanged(int index) if (index < 0) return; - ui->pushButtonFD->setEnabled(hdc_has_config(ui->comboBoxFD->currentData().toInt()) > 0); + ui->pushButtonFD->setEnabled(fdc_card_has_config(ui->comboBoxFD->currentData().toInt()) > 0); } void diff --git a/src/qt/qt_updatecheck.cpp b/src/qt/qt_updatecheck.cpp new file mode 100644 index 000000000..83e2b34d9 --- /dev/null +++ b/src/qt/qt_updatecheck.cpp @@ -0,0 +1,360 @@ +/* + * 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. + * + * Update check module + * + * + * + * Authors: cold-brewed + * + * Copyright 2024 cold-brewed + */ + +#include +#include +#include +#include +#include + +#include "qt_updatecheck.hpp" +#include "qt_downloader.hpp" +#include "qt_updatedetails.hpp" + +extern "C" { +#include <86box/version.h> +} + +UpdateCheck:: +UpdateCheck(const UpdateChannel channel, QObject *parent) : QObject(parent) +{ + updateChannel = channel; + currentVersion = getCurrentVersion(channel); +} + +UpdateCheck::~ +UpdateCheck() + = default; + +void +UpdateCheck::checkForUpdates() +{ + if (updateChannel == UpdateChannel::Stable) { + const auto githubDownloader = new Downloader(Downloader::DownloadLocation::Temp); + connect(githubDownloader, &Downloader::downloadCompleted, this, &UpdateCheck::githubDownloadComplete); + connect(githubDownloader, &Downloader::errorOccurred, this, &UpdateCheck::generalDownloadError); + githubDownloader->download(QUrl(githubReleaseApi), "github_releases.json"); + } else { + const auto jenkinsDownloader = new Downloader(Downloader::DownloadLocation::Temp); + connect(jenkinsDownloader, &Downloader::downloadCompleted, this, &UpdateCheck::jenkinsDownloadComplete); + connect(jenkinsDownloader, &Downloader::errorOccurred, this, &UpdateCheck::generalDownloadError); + jenkinsDownloader->download(jenkinsLatestNReleasesUrl(10), "jenkins_list.json"); + } +} + +void +UpdateCheck::jenkinsDownloadComplete(const QString &filename, const QVariant &varData) +{ + auto generalError = tr("Unable to determine release information"); + auto jenkinsReleaseListResult = parseJenkinsJson(filename); + auto latestVersion = 0; // NOLINT (Default value as a fallback) + + if(!jenkinsReleaseListResult.has_value() || jenkinsReleaseListResult.value().isEmpty()) { + generalDownloadError(generalError); + return; + } + const auto jenkinsReleaseList = jenkinsReleaseListResult.value(); + latestVersion = jenkinsReleaseListResult->first().buildNumber; + + // If we can't determine the local build (blank current version), always show an update as available. + // Callers can adjust accordingly. + // Otherwise, do a comparison with EMU_BUILD_NUM + bool updateAvailable = false; + bool upToDate = true; + if(currentVersion.isEmpty() || EMU_BUILD_NUM < latestVersion) { + updateAvailable = true; + upToDate = false; + } + + const auto updateResult = UpdateResult { + .channel = updateChannel, + .updateAvailable = updateAvailable, + .upToDate = upToDate, + .currentVersion = currentVersion, + .latestVersion = QString::number(latestVersion), + .githubInfo = {}, + .jenkinsInfo = jenkinsReleaseList, + }; + + emit updateCheckComplete(updateResult); +} + +void +UpdateCheck::generalDownloadError(const QString &error) +{ + emit updateCheckError(error); +} + +void +UpdateCheck::githubDownloadComplete(const QString &filename, const QVariant &varData) +{ + const auto generalError = tr("Unable to determine release information"); + const auto githubReleaseListResult = parseGithubJson(filename); + QString latestVersion = "0.0"; + if(!githubReleaseListResult.has_value() || githubReleaseListResult.value().isEmpty()) { + generalDownloadError(generalError); + } + auto githubReleaseList = githubReleaseListResult.value(); + // Warning: this check (using the tag name) relies on a consistent naming scheme: "v" + // where is the release number. For example, 4.2 from v4.2 as the tag name. + // Another option would be parsing the name field which is generally "86Box " but + // either option requires a consistent naming scheme. + latestVersion = githubReleaseList.first().tag_name.replace("v", ""); + for (const auto &release: githubReleaseList) { + qDebug().noquote().nospace() << release.name << ": " << release.html_url << " (" << release.created_at << ")"; + } + + // const auto updateDetails = new UpdateDetails(githubReleaseList, currentVersion); + bool updateAvailable = false; + bool upToDate = true; + if(currentVersion.isEmpty() || (versionCompare(currentVersion, latestVersion) < 0)) { + updateAvailable = true; + upToDate = false; + } + + const auto updateResult = UpdateResult { + .channel = updateChannel, + .updateAvailable = updateAvailable, + .upToDate = upToDate, + .currentVersion = currentVersion, + .latestVersion = latestVersion, + .githubInfo = githubReleaseList, + .jenkinsInfo = {}, + }; + + emit updateCheckComplete(updateResult); + +} + +QUrl +UpdateCheck::jenkinsLatestNReleasesUrl(const int &count) +{ + const auto urlPath = QString("https://ci.86box.net/job/86box/api/json?tree=builds[number,result,timestamp,changeSets[items[commitId,affectedPaths,author[fullName],msg,id]]]{0,%1}").arg(count); + return { urlPath }; +} + +QString +UpdateCheck::getCurrentVersion(const UpdateChannel &updateChannel) +{ + if (updateChannel == UpdateChannel::Stable) { + return {EMU_VERSION}; + } + // If EMU_BUILD_NUM is anything other than the default of zero it was set by the build process + if constexpr (EMU_BUILD_NUM != 0) { + return QString::number(EMU_BUILD_NUM); // NOLINT because EMU_BUILD_NUM is defined as 0 by default and is set at build time + } + // EMU_BUILD_NUM is not set, most likely a local build + return {}; // NOLINT (Having EMU_BUILD_NUM assigned to a default number throws off the linter) +} + +std::optional> +UpdateCheck::parseJenkinsJson(const QString &filename) +{ + QList releaseInfoList; + QFile json_file(filename); + if (!json_file.open(QIODevice::ReadOnly | QIODevice::Text)) { + qWarning() << "Couldn't open the json file: error" << json_file.error(); + return std::nullopt; + } + + const QString read_file = json_file.readAll(); + json_file.close(); + + const auto json_doc = QJsonDocument::fromJson(read_file.toUtf8()); + + if (json_doc.isNull()) { + qWarning("Failed to create QJsonDocument, possibly invalid JSON"); + return std::nullopt; + } + + if (!json_doc.isObject()) { + qWarning("JSON does not have the expected format (object in root), cannot continue"); + return std::nullopt; + } + + auto json_object = json_doc.object(); + + // The json contains multiple release + if(json_object.contains("builds") && json_object["builds"].isArray()) { + + QJsonArray builds = json_object["builds"].toArray(); + for (const auto &each_build: builds) { + if (auto build = parseJenkinsRelease(each_build.toObject()); build.has_value() && build.value().result == "SUCCESS") { + releaseInfoList.append(build.value()); + } + } + } else if(json_object.contains("changeSets") && json_object["changeSets"].isArray()) { + // The json contains only one release, as obtained by the lastSuccessfulBuild api + if (const auto build = parseJenkinsRelease(json_object); build.has_value()) { + releaseInfoList.append(build.value()); + } + } else { + qWarning("JSON is missing data or has invalid data, cannot continue"); + qDebug() << json_object; + return std::nullopt; + } + + return releaseInfoList; +} + +std::optional +UpdateCheck::parseJenkinsRelease(const QJsonObject &json) +{ + // The root should contain number, result, and timestamp. + if (!json.contains("number") || !json.contains("result") || !json.contains("timestamp")) { + return std::nullopt; + } + + auto releaseInfo = JenkinsReleaseInfo { + .buildNumber = json["number"].toInt(), + .result = json["result"].toString(), + .timestamp = static_cast(json["timestamp"].toDouble()) + }; + + // Overview + // Each build should contain a changeSets object with an array. Only the first element is needed. + // The first element should be an object containing an items object with an array. + // Each array element in the items object has information releated to the build. More or less: commit data + // In jq parlance it would be similar to `builds[].changeSets[0].items[]` + + // To break down the somewhat complicated if-init statement below: + // * Get the object for `changeSets` + // * Convert the value to array + // * Grab the first element in the array + // Proceed if + // * the element (first in changeSets) is an object that contains the key `items` + if (const auto changeSet = json["changeSets"].toArray().first(); changeSet.isObject() && changeSet.toObject().contains("items")) { + // Then proceed to process each `items` array element + for (const auto &item : changeSet.toObject()["items"].toArray()) { + auto itemObject = item.toObject(); + // Basic validation + if (!itemObject.contains("commitId") || !itemObject.contains("msg") || !itemObject.contains("affectedPaths")) { + return std::nullopt; + } + // Convert the paths for each commit to a string list + QStringList paths; + for (const auto &each_path : itemObject["affectedPaths"].toArray().toVariantList()) { + if (each_path.type() == QVariant::String) { + paths.append(each_path.toString()); + } + } + // Build the structure + const auto releaseItem = JenkinsChangeSetItem { + .buildId = itemObject["commitId"].toString(), + .author = itemObject["author"].toObject()["fullName"].toString(), + .message = itemObject["msg"].toString(), + .affectedPaths = paths, + }; + releaseInfo.changeSetItems.append(releaseItem); + } + } else { + qWarning("Could not parse release information, possibly invalid JSON"); + } + return releaseInfo; +} + +std::optional> +UpdateCheck::parseGithubJson(const QString &filename) +{ + QList releaseInfoList; + QFile json_file(filename); + if (!json_file.open(QIODevice::ReadOnly | QIODevice::Text)) { + qWarning("Couldn't open the json file: error %d", json_file.error()); + return std::nullopt; + } + + const QString read_file = json_file.readAll(); + json_file.close(); + + const auto json_doc = QJsonDocument::fromJson(read_file.toUtf8()); + + if (json_doc.isNull()) { + qWarning("Failed to create QJsonDocument, possibly invalid JSON"); + return std::nullopt; + } + + if (!json_doc.isArray()) { + qWarning("JSON does not have the expected format (array in root), cannot continue"); + return std::nullopt; + } + + auto release_array = json_doc.array(); + + for (const auto &each_release: release_array) { + if (auto release = parseGithubRelease(each_release.toObject()); release.has_value()) { + releaseInfoList.append(release.value()); + } + } + return releaseInfoList; +} +std::optional +UpdateCheck::parseGithubRelease(const QJsonObject &json) +{ + // Perform some basic validation + if (!json.contains("name") || !json.contains("tag_name") || !json.contains("html_url")) { + return std::nullopt; + } + + auto githubRelease = GithubReleaseInfo { + .name = json["name"].toString(), + .tag_name = json["tag_name"].toString(), + .html_url = json["html_url"].toString(), + .target_commitish = json["target_commitish"].toString(), + .created_at = json["created_at"].toString(), + .published_at = json["published_at"].toString(), + .body = json["body"].toString(), + }; + + return githubRelease; +} + +// A simple method to compare version numbers +// Should work for comparing x.y.z and x.y. Missing +// values (parts) will be treated as zeroes +int +UpdateCheck::versionCompare(const QString &version1, const QString &version2) +{ + // Split both + QStringList v1List = version1.split('.'); + QStringList v2List = version2.split('.'); + + // Out of the two versions get the maximum amount of "parts" + const int maxParts = std::max(v1List.size(), v2List.size()); + + // Initialize both with zeros + QVector v1Parts(maxParts, 0); + QVector v2Parts(maxParts, 0); + + for (int i = 0; i < v1List.size(); ++i) { + v1Parts[i] = v1List[i].toInt(); + } + + for (int i = 0; i < v2List.size(); ++i) { + v2Parts[i] = v2List[i].toInt(); + } + + for (int i = 0; i < maxParts; ++i) { + // First version is greater + if (v1Parts[i] > v2Parts[i]) + return 1; + // First version is less + if (v1Parts[i] < v2Parts[i]) + return -1; + } + // They are equal + return 0; +} diff --git a/src/qt/qt_updatecheck.hpp b/src/qt/qt_updatecheck.hpp new file mode 100644 index 000000000..2c04993fc --- /dev/null +++ b/src/qt/qt_updatecheck.hpp @@ -0,0 +1,104 @@ +/* + * 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. + * + * Header for the update check module + * + * + * + * Authors: cold-brewed + * + * Copyright 2024 cold-brewed + */ + +#ifndef QT_UPDATECHECK_HPP +#define QT_UPDATECHECK_HPP + +#include +#include +#include +#include + +#include + +class UpdateCheck final : public QObject { + Q_OBJECT +public: + enum class UpdateChannel { + Stable, + CI, + }; + + struct JenkinsChangeSetItem { + QString buildId; // sha hash + QString author; // github username + QString message; // commit message + QStringList affectedPaths; // list of files in the change + }; + + struct JenkinsReleaseInfo { + int buildNumber = 0; + QString result; + qint64 timestamp = 0; + QList changeSetItems; + }; + + struct GithubReleaseInfo { + QString name; + QString tag_name; + QString html_url; + QString target_commitish; + QString created_at; + QString published_at; + QString body; + }; + + struct UpdateResult { + UpdateChannel channel; + bool updateAvailable = false; + bool upToDate = false; + QString currentVersion; + QString latestVersion; + QList githubInfo; + QList jenkinsInfo; + }; + + explicit UpdateCheck(UpdateChannel channel, QObject *parent = nullptr); + ~UpdateCheck() override; + void checkForUpdates(); + static int versionCompare(const QString &version1, const QString &version2); + [[nodiscard]] static QString getCurrentVersion(const UpdateChannel &updateChannel = UpdateChannel::Stable); + +signals: + // void updateCheckComplete(const UpdateCheck::UpdateChannel &channel, const QVariant &updateData); + void updateCheckComplete(const UpdateCheck::UpdateResult &result); + void updateCheckError(const QString &errorMsg); + +private: + UpdateChannel updateChannel = UpdateChannel::Stable; + + const QUrl githubReleaseApi = QUrl("https://api.github.com/repos/86box/86Box/releases"); + const QUrl jenkinsLatestApi = QUrl("https://ci.86box.net/job/86box/lastSuccessfulBuild/api/json"); + QString jenkinsLatestVersion; + QString currentVersion; + + static QUrl jenkinsLatestNReleasesUrl(const int &count); + + static std::optional> parseJenkinsJson(const QString &filename); + static std::optional parseJenkinsRelease(const QJsonObject &json); + + static std::optional> parseGithubJson(const QString &filename); + static std::optional parseGithubRelease(const QJsonObject &json); + + +private slots: + void jenkinsDownloadComplete(const QString &filename, const QVariant& varData); + void githubDownloadComplete(const QString &filename, const QVariant& varData); + void generalDownloadError(const QString &error); +}; + +#endif // QT_UPDATECHECK_HPP diff --git a/src/qt/qt_updatecheckdialog.cpp b/src/qt/qt_updatecheckdialog.cpp new file mode 100644 index 000000000..d0cb6941d --- /dev/null +++ b/src/qt/qt_updatecheckdialog.cpp @@ -0,0 +1,90 @@ +/* + * 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. + * + * Update check dialog module + * + * + * + * Authors: cold-brewed + * + * Copyright 2024 cold-brewed + */ + +#include +#include + +#include "qt_updatecheckdialog.hpp" +#include "ui_qt_updatecheckdialog.h" +#include "qt_updatedetails.hpp" + +extern "C" { +#include <86box/version.h> +} + +UpdateCheckDialog:: +UpdateCheckDialog(const UpdateCheck::UpdateChannel channel, QWidget *parent) : QDialog(parent), ui(new Ui::UpdateCheckDialog), updateCheck(new UpdateCheck(channel)) +{ + ui->setupUi(this); + setWindowTitle(tr("Update check")); + ui->statusLabel->setHidden(true); + updateChannel = channel; + currentVersion = UpdateCheck::getCurrentVersion(updateChannel); + connect(updateCheck, &UpdateCheck::updateCheckError, [=](const QString &errorMsg) { + generalDownloadError(errorMsg); + }); + connect(updateCheck, &UpdateCheck::updateCheckComplete, this, &UpdateCheckDialog::downloadComplete); + + QTimer::singleShot(0, [this] { + updateCheck->checkForUpdates(); + }); +} + +UpdateCheckDialog::~ +UpdateCheckDialog() + = default; + +void +UpdateCheckDialog::generalDownloadError(const QString &error) const +{ + ui->progressBar->setMaximum(100); + ui->progressBar->setValue(100); + ui->statusLabel->setVisible(true); + const auto statusText = tr("There was an error checking for updates:\n\n%1\n\nPlease try again later.").arg(error); + ui->statusLabel->setText(statusText); + ui->buttonBox->setStandardButtons(QDialogButtonBox::Ok); +} + +void +UpdateCheckDialog::downloadComplete(const UpdateCheck::UpdateResult &result) +{ + if (result.upToDate) { + upToDate(); + return; + } + + const auto updateDetails = new UpdateDetails(result); + connect(updateDetails, &QDialog::accepted, [this] { + accept(); + }); + connect(updateDetails, &QDialog::rejected, [this] { + reject(); + }); + updateDetails->exec(); +} + +void +UpdateCheckDialog::upToDate() +{ + ui->titleLabel->setText(tr("Update check complete")); + ui->progressBar->setMaximum(100); + ui->progressBar->setValue(100); + ui->statusLabel->setVisible(true); + const auto statusText = tr("You are running the latest %1 version of 86Box: %2").arg(updateChannel == UpdateCheck::UpdateChannel::Stable ? "stable" : "beta", currentVersion); + ui->statusLabel->setText(statusText); + ui->buttonBox->setStandardButtons(QDialogButtonBox::Ok); +} diff --git a/src/qt/qt_updatecheckdialog.hpp b/src/qt/qt_updatecheckdialog.hpp new file mode 100644 index 000000000..0f1c0dfa8 --- /dev/null +++ b/src/qt/qt_updatecheckdialog.hpp @@ -0,0 +1,47 @@ +/* + * 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. + * + * Header for the update check dialog module + * + * + * + * Authors: cold-brewed + * + * Copyright 2024 cold-brewed + */ + +#ifndef QT_UPDATECHECKDIALOG_HPP +#define QT_UPDATECHECKDIALOG_HPP + +#include + +#include + +namespace Ui { +class UpdateCheckDialog; +} + +class UpdateCheckDialog final : public QDialog { + Q_OBJECT +public: + explicit UpdateCheckDialog(UpdateCheck::UpdateChannel channel, QWidget *parent = nullptr); + ~UpdateCheckDialog() override; + +private: + Ui::UpdateCheckDialog *ui; + UpdateCheck::UpdateChannel updateChannel = UpdateCheck::UpdateChannel::Stable; + UpdateCheck *updateCheck; + QString currentVersion; + void upToDate(); + +private slots: + void downloadComplete(const UpdateCheck::UpdateResult &result); + void generalDownloadError(const QString &error) const; +}; + +#endif // QT_UPDATECHECKDIALOG_HPP diff --git a/src/qt/qt_updatecheckdialog.ui b/src/qt/qt_updatecheckdialog.ui new file mode 100644 index 000000000..e50a541bb --- /dev/null +++ b/src/qt/qt_updatecheckdialog.ui @@ -0,0 +1,106 @@ + + + UpdateCheckDialog + + + + 0 + 0 + 350 + 134 + + + + + 0 + 0 + + + + Dialog + + + + + + + 0 + 0 + + + + Checking for updates.. + + + Qt::AlignCenter + + + + + + + 0 + + + -1 + + + + + + + Status text here + + + + + + + true + + + Qt::Horizontal + + + QDialogButtonBox::Cancel + + + + + + + + + buttonBox + accepted() + UpdateCheckDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + UpdateCheckDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/qt/qt_updatedetails.cpp b/src/qt/qt_updatedetails.cpp new file mode 100644 index 000000000..1d6846dd6 --- /dev/null +++ b/src/qt/qt_updatedetails.cpp @@ -0,0 +1,111 @@ +/* + * 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. + * + * Update details module + * + * + * + * Authors: cold-brewed + * + * Copyright 2024 cold-brewed + */ + +#include "qt_updatedetails.hpp" +#include "ui_qt_updatedetails.h" + +#include +#include + + +UpdateDetails:: +UpdateDetails(const UpdateCheck::UpdateResult &updateResult, QWidget *parent) : ui(new Ui::UpdateDetails) +{ + ui->setupUi(this); + setWindowTitle("86Box Update"); + ui->updateTitle->setText("An update to 86Box is available!"); + QString currentVersionText; + QString releaseType = updateResult.channel == UpdateCheck::UpdateChannel::Stable ? tr("version") : tr("build"); + if(!updateResult.currentVersion.isEmpty()) { + currentVersionText = tr("You are currently running %1 %2. ").arg(releaseType, updateResult.currentVersion); + } + + const auto updateDetailsText = tr("%1 %2 is now available. %3Would you like to visit the download page?").arg(releaseType[0].toUpper() + releaseType.mid(1), updateResult.latestVersion, currentVersionText); + ui->updateDetails->setText(updateDetailsText); + + if(updateResult.channel == UpdateCheck::UpdateChannel::Stable) { + ui->updateText->setMarkdown(githubUpdateToMarkdown(updateResult.githubInfo)); + } else { + ui->updateText->setMarkdown(jenkinsUpdateToMarkdown(updateResult.jenkinsInfo)); + } + + const auto downloadButton = new QPushButton(tr("Visit download page")); + ui->buttonBox->addButton(downloadButton, QDialogButtonBox::AcceptRole); + // Override accepted to mean "I want to visit the download page" + connect(ui->buttonBox, &QDialogButtonBox::accepted, [updateResult] { + visitDownloadPage(updateResult.channel); + }); + const auto logo = QPixmap(":/assets/86box.png").scaled(QSize(64, 64), Qt::KeepAspectRatio, Qt::SmoothTransformation); + + ui->icon->setPixmap(logo); +} + +UpdateDetails::~ +UpdateDetails() + = default; + +QString +UpdateDetails::jenkinsUpdateToMarkdown(const QList &releaseInfoList) +{ + QStringList fullText; + for (const auto &update : releaseInfoList) { + fullText.append(QString("### Build %1").arg(update.buildNumber)); + fullText.append("Changes:"); + for (const auto &item : update.changeSetItems) { + fullText.append(QString("* %1").arg(item.message)); + } + fullText.append("\n\n\n---\n\n\n"); + } + // pop off the last hr + fullText.removeLast(); + // return fullText.join("\n\n---\n\n"); + return fullText.join("\n"); +} + +QString +UpdateDetails::githubUpdateToMarkdown(const QList &releaseInfoList) +{ + // The github release info can be rather large so we'll only + // display the most recent one + QList singleRelease; + if (!releaseInfoList.isEmpty()) { + singleRelease.append(releaseInfoList.first()); + } + QStringList fullText; + for (const auto &release : singleRelease) { + fullText.append(QString("#### %1").arg(release.name)); + // Github body text should already be in markdown and can just + // be placed here as-is + fullText.append(release.body); + fullText.append("\n\n\n---\n\n\n"); + } + // pop off the last hr + fullText.removeLast(); + return fullText.join("\n"); +} +void +UpdateDetails::visitDownloadPage(const UpdateCheck::UpdateChannel &channel) +{ + switch (channel) { + case UpdateCheck::UpdateChannel::Stable: + QDesktopServices::openUrl(QUrl("https://ci.86box.net/job/86Box/lastSuccessfulBuild/artifact/")); + break; + case UpdateCheck::UpdateChannel::CI: + QDesktopServices::openUrl(QUrl("https://github.com/86Box/86Box/releases/latest")); + break; + } +} diff --git a/src/qt/qt_updatedetails.hpp b/src/qt/qt_updatedetails.hpp new file mode 100644 index 000000000..8c3528e11 --- /dev/null +++ b/src/qt/qt_updatedetails.hpp @@ -0,0 +1,43 @@ +/* + * 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. + * + * Header for the update details module + * + * + * + * Authors: cold-brewed + * + * Copyright 2024 cold-brewed + */ + +#ifndef QT_UPDATEDETAILS_HPP +#define QT_UPDATEDETAILS_HPP + +#include +#include +#include "qt_updatecheck.hpp" + +namespace Ui { +class UpdateDetails; +} + +class UpdateDetails final : public QDialog { + Q_OBJECT +public: + explicit UpdateDetails(const UpdateCheck::UpdateResult &updateResult, QWidget *parent = nullptr); + ~UpdateDetails() override; +private: + Ui::UpdateDetails *ui; + static QString jenkinsUpdateToMarkdown(const QList &releaseInfoList); + static QString githubUpdateToMarkdown(const QList &releaseInfoList); +private slots: + static void visitDownloadPage(const UpdateCheck::UpdateChannel &channel); +}; + + +#endif // QT_UPDATEDETAILS_HPP diff --git a/src/qt/qt_updatedetails.ui b/src/qt/qt_updatedetails.ui new file mode 100644 index 000000000..7b9c0aa2a --- /dev/null +++ b/src/qt/qt_updatedetails.ui @@ -0,0 +1,192 @@ + + + UpdateDetails + + + + 0 + 0 + 700 + 500 + + + + + 600 + 400 + + + + Dialog + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 12 + + + 12 + + + 12 + + + 0 + + + + + + 0 + 0 + + + + + 32 + 0 + + + + + 64 + 16777215 + + + + + + + false + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Title + + + + + + + Details + + + true + + + + + + + Release notes: + + + + + + + true + + + true + + + false + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel + + + + + + + + + buttonBox + accepted() + UpdateDetails + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + UpdateDetails + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/qt/qt_vmmanager_addmachine.cpp b/src/qt/qt_vmmanager_addmachine.cpp new file mode 100644 index 000000000..db40972a1 --- /dev/null +++ b/src/qt/qt_vmmanager_addmachine.cpp @@ -0,0 +1,361 @@ +/* +* 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. +* +* 86Box VM manager add machine wizard +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#include +#include +#include +#include +#include +#include +#include + +#include "qt_vmmanager_addmachine.hpp" + +extern "C" { +#include <86box/86box.h> +} + +// Implementation note: There are several classes in this file: +// One for the main Wizard class and one for each page of the wizard + +VMManagerAddMachine:: +VMManagerAddMachine(QWidget *parent) : QWizard(parent) +{ + setPage(Page_Intro, new IntroPage); + setPage(Page_WithExistingConfig, new WithExistingConfigPage); + setPage(Page_NameAndLocation, new NameAndLocationPage); + setPage(Page_Conclusion, new ConclusionPage); + + // Need to create a better image + // QPixmap originalPixmap(":/assets/86box.png"); + // QPixmap scaledPixmap = originalPixmap.scaled(150, 150, Qt::KeepAspectRatio); + QPixmap wizardPixmap(":/assets/86box-wizard.png"); + +#ifndef Q_OS_MACOS + setWizardStyle(ModernStyle); + // setPixmap(LogoPixmap, scaledPixmap); + // setPixmap(LogoPixmap, wizardPixmap); + // setPixmap(WatermarkPixmap, scaledPixmap); + setPixmap(WatermarkPixmap, wizardPixmap); +#else + // macos + // setPixmap(BackgroundPixmap, scaledPixmap); + setPixmap(BackgroundPixmap, wizardPixmap); +#endif + + // Wizard wants to resize based on image. This keeps the size + setMinimumSize(size()); + setOption(HaveHelpButton, true); + // setPixmap(LogoPixmap, QPixmap(":/settings/qt/icons/86Box-gray.ico")); + + connect(this, &QWizard::helpRequested, this, &VMManagerAddMachine::showHelp); + + setWindowTitle(tr("Add new system wizard")); +} + +void +VMManagerAddMachine::showHelp() +{ + // TBD + static QString lastHelpMessage; + + QString message; + + // Help will depend on the current page + switch (currentId()) { + case Page_Intro: + message = tr("This is the into page."); + break; + default: + message = tr("No help has been added yet, you're on your own."); + break; + } + + if (lastHelpMessage == message) { + message = tr("Did you click help twice?"); + } + + QMessageBox::information(this, tr("Add new system wizard help"), message); + lastHelpMessage = message; +} + +IntroPage:: +IntroPage(QWidget *parent) +{ + setTitle(tr("Introduction")); + + setPixmap(QWizard::WatermarkPixmap, QPixmap(":/assets/qt/assets/86box.png")); + + topLabel = new QLabel(tr("This will help you add a new system to 86Box.")); + // topLabel = new QLabel(tr("This will help you add a new system to 86Box.\n\n Choose \"New configuration\" if you'd like to create a new machine.\n\nChoose \"Use existing configuration\" if you'd like to paste in an existing configuration from elsewhere.")); + topLabel->setWordWrap(true); + + newConfigRadioButton = new QRadioButton(tr("New configuration")); + // auto newDescription = new QLabel(tr("Choose this option to start with a fresh configuration.")); + existingConfigRadioButton = new QRadioButton(tr("Use existing configuraion")); + // auto existingDescription = new QLabel(tr("Use this option if you'd like to paste in the configuration file from an existing system.")); + newConfigRadioButton->setChecked(true); + + const auto layout = new QVBoxLayout(); + layout->addWidget(topLabel); + layout->addWidget(newConfigRadioButton); + // layout->addWidget(newDescription); + layout->addWidget(existingConfigRadioButton); + // layout->addWidget(existingDescription); + + setLayout(layout); +} + +int +IntroPage::nextId() const +{ + if (newConfigRadioButton->isChecked()) { + return VMManagerAddMachine::Page_NameAndLocation; + } else { + return VMManagerAddMachine::Page_WithExistingConfig; + } +} + +WithExistingConfigPage:: +WithExistingConfigPage(QWidget *parent) +{ + setTitle(tr("Use existing configuration")); + + const auto topLabel = new QLabel(tr("Paste the contents of the existing configuration file into the box below.")); + topLabel->setWordWrap(true); + + existingConfiguration = new QPlainTextEdit(); + connect(existingConfiguration, &QPlainTextEdit::textChanged, this, &WithExistingConfigPage::completeChanged); + registerField("existingConfiguration*", this, "configuration"); + + const auto layout = new QVBoxLayout(); + layout->addWidget(topLabel); + layout->addWidget(existingConfiguration); + const auto loadFileButton = new QPushButton(); + const auto loadFileLabel = new QLabel(tr("Load configuration from file")); + const auto hLayout = new QHBoxLayout(); + loadFileButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_FileIcon)); + loadFileButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); + connect(loadFileButton, &QPushButton::clicked, this, &WithExistingConfigPage::chooseExistingConfigFile); + hLayout->addWidget(loadFileButton); + hLayout->addWidget(loadFileLabel); + layout->addLayout(hLayout); + setLayout(layout); +} + +void +WithExistingConfigPage::chooseExistingConfigFile() +{ + // TODO: FIXME: This is using the CLI arg and needs to instead use a proper variable + const auto startDirectory = QString(vmm_path); + const auto selectedConfigFile = QFileDialog::getOpenFileName(this, tr("Choose configuration file"), + startDirectory, + tr("86Box configuration files (86box.cfg)")); + // Empty value means the dialog was canceled + if (!selectedConfigFile.isEmpty()) { + QFile configFile(selectedConfigFile); + if (!configFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + QMessageBox::critical(this, tr("Configuration read failed"), tr("Unable to open the selected configuration file for reading: %1").arg(configFile.errorString())); + return; + } + const QString configFileContents = configFile.readAll(); + existingConfiguration->setPlainText(configFileContents); + configFile.close(); + emit completeChanged(); + } +} + +QString +WithExistingConfigPage::configuration() const +{ + return existingConfiguration->toPlainText(); +} +void +WithExistingConfigPage::setConfiguration(const QString &configuration) +{ + if (configuration != existingConfiguration->toPlainText()) { + existingConfiguration->setPlainText(configuration); + emit configurationChanged(configuration); + } +} + +int +WithExistingConfigPage::nextId() const +{ + return VMManagerAddMachine::Page_NameAndLocation; +} + +bool +WithExistingConfigPage::isComplete() const +{ + return !existingConfiguration->toPlainText().isEmpty(); +} + +NameAndLocationPage:: +NameAndLocationPage(QWidget *parent) +{ + setTitle(tr("System name and location")); + + dirValidate = QRegularExpression(R"(^[^\\/:*?"<>|\s]+$)"); + + const auto topLabel = new QLabel(tr("Enter the name of the system and choose the location")); + topLabel->setWordWrap(true); + + const auto chooseDirectoryButton = new QPushButton(); + chooseDirectoryButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_DirIcon)); + + const auto systemNameLabel = new QLabel(tr("System Name")); + systemName = new QLineEdit(); + // Special event filter to override enter key + systemName->installEventFilter(this); + registerField("systemName*", systemName); + systemNameValidation = new QLabel(); + + const auto systemLocationLabel = new QLabel(tr("System Location")); + systemLocation = new QLineEdit(); + // TODO: FIXME: This is using the CLI arg and needs to instead use a proper variable + systemLocation->setText(QDir::toNativeSeparators(vmm_path)); + registerField("systemLocation*", systemLocation); + systemLocationValidation = new QLabel(); + systemLocationValidation->setWordWrap(true); + + const auto layout = new QGridLayout(); + layout->addWidget(topLabel, 0, 0, 1, -1); + // Spacer row + layout->setRowMinimumHeight(1, 20); + layout->addWidget(systemNameLabel, 2, 0); + layout->addWidget(systemName, 2, 1); + // Validation text, appears only as necessary + layout->addWidget(systemNameValidation, 3, 0, 1, -1); + // Set height on validation because it may not always be present + layout->setRowMinimumHeight(3, 20); + + // Another spacer + layout->setRowMinimumHeight(4, 20); + layout->addWidget(systemLocationLabel, 5, 0); + layout->addWidget(systemLocation, 5, 1); + layout->addWidget(chooseDirectoryButton, 5, 2); + // Validation text + layout->addWidget(systemLocationValidation, 6, 0, 1, -1); + layout->setRowMinimumHeight(6, 20); + + setLayout(layout); + + + connect(chooseDirectoryButton, &QPushButton::clicked, this, &NameAndLocationPage::chooseDirectoryLocation); +} + +int +NameAndLocationPage::nextId() const +{ + return VMManagerAddMachine::Page_Conclusion; +} + +void +NameAndLocationPage::chooseDirectoryLocation() +{ + // TODO: FIXME: This is pulling in the CLI directory! Needs to be set properly elsewhere + const auto directory = QFileDialog::getExistingDirectory(this, "Choose directory", QDir(vmm_path).path()); + systemLocation->setText(QDir::toNativeSeparators(directory)); + emit completeChanged(); +} +bool +NameAndLocationPage::isComplete() const +{ + bool nameValid = false; + bool locationValid = false; + // return true if complete + if (systemName->text().isEmpty()) { + systemNameValidation->setText(tr("Please enter a system name")); + } else if (!systemName->text().contains(dirValidate)) { + systemNameValidation->setText(tr("System name cannot contain a space or certain characters")); + } else if (const QDir newDir = QDir::cleanPath(systemLocation->text() + "/" + systemName->text()); newDir.exists()) { + systemNameValidation->setText(tr("System name already exists")); + } else { + systemNameValidation->clear(); + nameValid = true; + } + + if (systemLocation->text().isEmpty()) { + systemLocationValidation->setText(tr("Please enter a directory for the system")); + } else if (const auto dir = QDir(systemLocation->text()); !dir.exists()) { + systemLocationValidation->setText(tr("Directory does not exist")); + } else { + systemLocationValidation->setText("A new directory for the system will be created in the selected directory above"); + locationValid = true; + } + + return nameValid && locationValid; +} +bool +NameAndLocationPage::eventFilter(QObject *watched, QEvent *event) +{ + // Override the enter key to hit the next wizard button + // if the validator (isComplete) is satisfied + if (event->type() == QEvent::KeyPress) { + const auto keyEvent = dynamic_cast(event); + if (keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return) { + // Only advance if the validator is satisfied (isComplete) + if(const auto wizard = qobject_cast(this->wizard())) { + if (wizard->currentPage()->isComplete()) { + wizard->next(); + } + } + // Discard the key event + return true; + } + } + return QWizardPage::eventFilter(watched, event); +} + +ConclusionPage:: +ConclusionPage(QWidget *parent) +{ + setTitle(tr("Complete")); + + topLabel = new QLabel(tr("The wizard will now launch the configuration for the new system.")); + topLabel->setWordWrap(true); + + const auto systemNameLabel = new QLabel(tr("System name:")); + systemNameLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); + systemName = new QLabel(); + const auto systemLocationLabel = new QLabel(tr("System location:")); + systemLocationLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); + systemLocation = new QLabel(); + + const auto layout = new QGridLayout(); + layout->addWidget(topLabel, 0, 0, 1, -1); + layout->setRowMinimumHeight(1, 20); + layout->addWidget(systemNameLabel, 2, 0); + layout->addWidget(systemName, 2, 1); + layout->addWidget(systemLocationLabel, 3, 0); + layout->addWidget(systemLocation, 3, 1); + + setLayout(layout); +} + +// initializePage() runs after the page has been created with the constructor +void +ConclusionPage::initializePage() +{ + const auto finalPath = QDir::cleanPath(field("systemLocation").toString() + "/" + field("systemName").toString()); + const auto nativePath = QDir::toNativeSeparators(finalPath); + const auto systemNameDisplay = field("systemName").toString(); + + systemName->setText(systemNameDisplay); + systemLocation->setText(nativePath); +} diff --git a/src/qt/qt_vmmanager_addmachine.hpp b/src/qt/qt_vmmanager_addmachine.hpp new file mode 100644 index 000000000..c1355b471 --- /dev/null +++ b/src/qt/qt_vmmanager_addmachine.hpp @@ -0,0 +1,115 @@ +/* +* 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. +* +* Header for 86Box VM manager add machine wizard +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#ifndef QT_VMMANAGER_ADDMACHINE_H +#define QT_VMMANAGER_ADDMACHINE_H + +#include +#include +#include +#include +#include +#include + +// Implementation note: There are several classes in this header: +// One for the main Wizard class and one for each page of the wizard + +class VMManagerAddMachine final : public QWizard { + Q_OBJECT + +public: + enum { + Page_Intro, + Page_Fresh, + Page_WithExistingConfig, + Page_NameAndLocation, + Page_Conclusion + }; + + explicit VMManagerAddMachine(QWidget *parent = nullptr); + +private slots: + void showHelp(); +}; + +class IntroPage : public QWizardPage { + Q_OBJECT + +public: + explicit IntroPage(QWidget *parent = nullptr); + [[nodiscard]] int nextId() const override; + +private: + QLabel *topLabel; + QRadioButton *newConfigRadioButton; + QRadioButton *existingConfigRadioButton; +}; + +class WithExistingConfigPage final : public QWizardPage { + Q_OBJECT + Q_PROPERTY(QString configuration READ configuration WRITE setConfiguration NOTIFY configurationChanged) + +public: + explicit WithExistingConfigPage(QWidget *parent = nullptr); + // These extra functions are required to register QPlainTextEdit fields + [[nodiscard]] QString configuration() const; + void setConfiguration(const QString &configuration); +signals: + void configurationChanged(const QString &configuration); +private: + QPlainTextEdit *existingConfiguration; +private slots: + void chooseExistingConfigFile(); +protected: + [[nodiscard]] int nextId() const override; + [[nodiscard]] bool isComplete() const override; + +}; + +class NameAndLocationPage final : public QWizardPage { + Q_OBJECT + +public: + explicit NameAndLocationPage(QWidget *parent = nullptr); + [[nodiscard]] int nextId() const override; +private: + QLineEdit *systemName; + QLineEdit *systemLocation; + QLabel *systemNameValidation; + QLabel *systemLocationValidation; + QRegularExpression dirValidate; +private slots: + void chooseDirectoryLocation(); +protected: + [[nodiscard]] bool isComplete() const override; + bool eventFilter(QObject *watched, QEvent *event) override; + +}; + +class ConclusionPage final : public QWizardPage { + Q_OBJECT +public: + explicit ConclusionPage(QWidget *parent = nullptr); +private: + QLabel *topLabel; + QLabel *systemName; + QLabel *systemLocation; +protected: + void initializePage() override; +}; + +#endif // QT_VMMANAGER_ADDMACHINE_H \ No newline at end of file diff --git a/src/qt/qt_vmmanager_clientsocket.cpp b/src/qt/qt_vmmanager_clientsocket.cpp new file mode 100644 index 000000000..1035a846c --- /dev/null +++ b/src/qt/qt_vmmanager_clientsocket.cpp @@ -0,0 +1,236 @@ +/* +* 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. +* +* 86Box VM manager client socket module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#include "qt_vmmanager_clientsocket.hpp" +#include "qt_vmmanager_protocol.hpp" +#include +#include +#include + +extern "C" { +#include "86box/plat.h" +} + +VMManagerClientSocket::VMManagerClientSocket(QObject* obj) : server_connected(false) +{ + socket = new QLocalSocket; + +} + +void +VMManagerClientSocket::dataReady() +{ + // emit signal? + QDataStream stream(socket); + stream.setVersion(QDataStream::Qt_5_7); + QByteArray jsonData; + for (;;) { + // start a transaction + stream.startTransaction(); + // try to read the data + stream >> jsonData; + if (stream.commitTransaction()) { + // first try to successfully read some data + // need to also make sure it's valid json + QJsonParseError parse_error{}; + // try to create a document with the data received + const QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData, &parse_error); + if (parse_error.error == QJsonParseError::NoError) { + // the data received was valid json + if (jsonDoc.isObject()) { + // and is a valid json object + // parse the json + jsonReceived(jsonDoc.object()); + } + } + // If the received data isn't valid json, + // loop and try to read more if available + } else { + // read failed, socket is reverted to its previous state (before the transaction) + // Exit the loop and wait for more data to become available + break; + } + } + +} + +bool +VMManagerClientSocket::IPCConnect(const QString &server) +{ + server_name = server; + connect(socket, &QLocalSocket::connected, this, &VMManagerClientSocket::connected); + connect(socket, &QLocalSocket::disconnected, this, &VMManagerClientSocket::disconnected); + connect(socket, &QLocalSocket::errorOccurred, this, &VMManagerClientSocket::connectionError); + connect(socket, &QLocalSocket::readyRead, this, &VMManagerClientSocket::dataReady); + + socket->connectToServer(server_name); + + if(!socket->isValid()) { + qInfo("Could not connect to server: %s", qPrintable(socket->errorString())); + return false; + } + + qInfo("Connection Successful"); + return true; +} + +void +VMManagerClientSocket::connected() const +{ + // TODO: signal + qDebug("Connected to %s", qPrintable(server_name)); +} + +void +VMManagerClientSocket::disconnected() const +{ + // TODO: signal + qDebug("Disconnected from %s", qPrintable(server_name)); +} + +void +VMManagerClientSocket::sendMessage(const VMManagerProtocol::ClientMessage protocol_message) const +{ + sendMessageFull(protocol_message, QStringList(), QJsonObject()); +} + +void +VMManagerClientSocket::sendMessageWithList(const VMManagerProtocol::ClientMessage protocol_message, const QStringList &list) const +{ + sendMessageFull(protocol_message, list, QJsonObject()); +} + +void +VMManagerClientSocket::sendMessageWithObject(const VMManagerProtocol::ClientMessage protocol_message, const QJsonObject &json) const +{ + sendMessageFull(protocol_message, QStringList(), json); +} + +void +VMManagerClientSocket::sendMessageFull(const VMManagerProtocol::ClientMessage protocol_message, const QStringList &list, const QJsonObject &json) const +{ + QDataStream clientStream(socket); + clientStream.setVersion(QDataStream::Qt_5_7); + auto packet = new VMManagerProtocol(VMManagerProtocol::Sender::Client); + auto jsonMessage = packet->protocolClientMessage(protocol_message); + if (!list.isEmpty()) { + jsonMessage["list"] = QJsonArray::fromStringList(list); + } + // TODO: Add the logic for including objects + if(!json.isEmpty()) { + jsonMessage["params"] = json; + } + clientStream << QJsonDocument(jsonMessage).toJson(QJsonDocument::Compact); +} + +void +VMManagerClientSocket::jsonReceived(const QJsonObject &json) +{ + // The serialization portion has already validated the message as json. + // Ensure it has the required fields + if (!VMManagerProtocol::hasRequiredFields(json)) { + // TODO: Error handling of some sort, emit signals + qDebug("Invalid message received from client: required fields missing. Object:"); + qDebug() << json; + return; + } + // qDebug() << Q_FUNC_INFO << json; + + // Parsing happens here. When adding new types, make sure to first add them + // to VMManagerProtocol::ManagerMessage and then add it to the list here. + // If a signal needs to be emitted, add that as well and connect to slots + // as appropriate. + + switch (VMManagerProtocol::getManagerMessageType(json)) { + case VMManagerProtocol::ManagerMessage::Pause: + qDebug("Pause command received from manager"); + emit pause(); + break; + case VMManagerProtocol::ManagerMessage::ResetVM: + qDebug("Reset VM command received from manager"); + emit resetVM(); + break; + case VMManagerProtocol::ManagerMessage::ShowSettings: + qDebug("Show settings command received from manager"); + emit showsettings(); + break; + case VMManagerProtocol::ManagerMessage::CtrlAltDel: + qDebug("CtrlAltDel command received from manager"); + emit ctrlaltdel(); + break; + case VMManagerProtocol::ManagerMessage::RequestShutdown: + qDebug("RequestShutdown command received from manager"); + emit request_shutdown(); + break; + case VMManagerProtocol::ManagerMessage::ForceShutdown: + qDebug("ForceShutdown command received from manager"); + emit force_shutdown(); + break; + case VMManagerProtocol::ManagerMessage::RequestStatus: + qDebug("Status request command received from manager"); + break; + default: + qDebug("Unknown client message type received:"); + qDebug() << json; + break; + } +} + +void +VMManagerClientSocket::connectionError(const QLocalSocket::LocalSocketError socketError) +{ + qInfo("A connection error has occurred: "); + switch (socketError) { + case QLocalSocket::ServerNotFoundError: + qInfo("Server not found"); + break; + case QLocalSocket::ConnectionRefusedError: + qInfo("Connection refused"); + break; + case QLocalSocket::PeerClosedError: + qInfo("Peer closed"); + break; + default: + qInfo() << "QLocalSocket::LocalSocketError " << socketError; + break; + } +} + +bool +VMManagerClientSocket::eventFilter(QObject *obj, QEvent *event) +{ + if (socket->state() == QLocalSocket::ConnectedState) { + VMManagerProtocol::RunningState running_state; + if (event->type() == QEvent::WindowBlocked) { + running_state = dopause ? VMManagerProtocol::RunningState::PausedWaiting : VMManagerProtocol::RunningState::RunningWaiting; + clientRunningStateChanged(running_state); + } else if (event->type() == QEvent::WindowUnblocked) { + running_state = dopause ? VMManagerProtocol::RunningState::Paused : VMManagerProtocol::RunningState::Running; + clientRunningStateChanged(running_state); + } + } + return QObject::eventFilter(obj, event); +} + +void +VMManagerClientSocket::clientRunningStateChanged(VMManagerProtocol::RunningState state) const +{ + QJsonObject extra_object; + extra_object["status"] = static_cast(state); + sendMessageWithObject(VMManagerProtocol::ClientMessage::RunningStateChanged, extra_object); + +} diff --git a/src/qt/qt_vmmanager_clientsocket.hpp b/src/qt/qt_vmmanager_clientsocket.hpp new file mode 100644 index 000000000..10a053347 --- /dev/null +++ b/src/qt/qt_vmmanager_clientsocket.hpp @@ -0,0 +1,71 @@ +/* +* 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. +* +* Header file for 86Box VM manager client socket module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#ifndef QT_VMMANAGER_CLIENTSOCKET_HPP +#define QT_VMMANAGER_CLIENTSOCKET_HPP + +#include "qt_vmmanager_protocol.hpp" +#include +#include +#include +#include + +class VMManagerClientSocket final : public QObject { + Q_OBJECT + +public: + explicit VMManagerClientSocket(QObject* object = nullptr); + bool IPCConnect(const QString &server); + +signals: + void pause(); + void ctrlaltdel(); + void showsettings(); + void resetVM(); + void request_shutdown(); + void force_shutdown(); + void dialogstatus(bool open); + +public slots: + void clientRunningStateChanged(VMManagerProtocol::RunningState state) const; + +private: + QString server_name; + QLocalSocket *socket; + bool server_connected; + void connected() const; + void disconnected() const; + static void connectionError(QLocalSocket::LocalSocketError socketError); + + // Main convenience send function + void sendMessage(VMManagerProtocol::ClientMessage protocol_message) const; + // Send message with optional params array convenience function + void sendMessageWithList(VMManagerProtocol::ClientMessage protocol_message, const QStringList &list) const; + // Send message with optional json object convenience function + void sendMessageWithObject(VMManagerProtocol::ClientMessage protocol_message, const QJsonObject &json) const; + // Full send message function called by all convenience functions + void sendMessageFull(VMManagerProtocol::ClientMessage protocol_message, const QStringList &list, const QJsonObject &json) const; + void jsonReceived(const QJsonObject &json); + + void dataReady(); + +protected: + bool eventFilter(QObject *obj, QEvent *event) override; + +}; + +#endif // QT_VMMANAGER_CLIENTSOCKET_HPP diff --git a/src/qt/qt_vmmanager_config.cpp b/src/qt/qt_vmmanager_config.cpp new file mode 100644 index 000000000..08bf4e7c4 --- /dev/null +++ b/src/qt/qt_vmmanager_config.cpp @@ -0,0 +1,76 @@ +/* +* 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. +* +* 86Box VM manager configuration module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#include +#include +#include "qt_vmmanager_config.hpp" + +extern "C" { +#include <86box/plat.h> +} + +VMManagerConfig::VMManagerConfig(const ConfigType type, const QString& section) +{ + char BUF[256]; + plat_get_global_config_dir(BUF, 255); + const auto configDir = QString(BUF); + const auto configFile = QDir::cleanPath(configDir + "/" + "vmm.ini"); + + config_type = type; + + settings = new QSettings(configFile, QSettings::IniFormat, this); + settings->setFallbacksEnabled(false); + if(type == ConfigType::System && !section.isEmpty()) { + settings->beginGroup(section); + } +} + +VMManagerConfig::~VMManagerConfig() { + settings->endGroup(); +} + +QString +VMManagerConfig::getStringValue(const QString& key) const +{ + const auto value = settings->value(key); + // An invalid QVariant with toString will give a default QString value which is blank. + // Therefore any variables that do not exist will return blank strings + return value.toString(); +} + +void +VMManagerConfig::setStringValue(const QString &key, const QString &value) const +{ + if (value.isEmpty()) { + remove(key); + return; + } + settings->setValue(key, value); +} + +void +VMManagerConfig::remove(const QString &key) const +{ + settings->remove(key); +} + +void +VMManagerConfig::sync() const +{ + settings->sync(); +} + diff --git a/src/qt/qt_vmmanager_config.hpp b/src/qt/qt_vmmanager_config.hpp new file mode 100644 index 000000000..bc63aaa03 --- /dev/null +++ b/src/qt/qt_vmmanager_config.hpp @@ -0,0 +1,46 @@ +/* +* 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. +* +* Header for the 86Box VM manager configuration module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#ifndef QT_VMMANAGER_CONFIG_H +#define QT_VMMANAGER_CONFIG_H + +#include + +class VMManagerConfig : QObject { + Q_OBJECT + +public: + enum class ConfigType { + General, + System, + }; + Q_ENUM(ConfigType); + + explicit VMManagerConfig(ConfigType type, const QString& section = {}); + ~VMManagerConfig() override; + [[nodiscard]] QString getStringValue(const QString& key) const; + void setStringValue(const QString& key, const QString& value) const; + void remove(const QString &key) const; + + void sync() const; + + QSettings *settings; + ConfigType config_type; + QString system_name; +}; + +#endif // QT_VMMANAGER_CONFIG_H \ No newline at end of file diff --git a/src/qt/qt_vmmanager_details.cpp b/src/qt/qt_vmmanager_details.cpp new file mode 100644 index 000000000..a834e35f8 --- /dev/null +++ b/src/qt/qt_vmmanager_details.cpp @@ -0,0 +1,400 @@ +/* +* 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. +* +* 86Box VM manager system details module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#include +#include +#include + +#include "qt_vmmanager_details.hpp" +#include "ui_qt_vmmanager_details.h" + +#ifdef Q_OS_WINDOWS +extern bool windows_is_light_theme(); +#endif + +using namespace VMManager; + +VMManagerDetails::VMManagerDetails(QWidget *parent) : + QWidget(parent), ui(new Ui::VMManagerDetails) { + ui->setupUi(this); + + const auto leftColumnLayout = qobject_cast(ui->leftColumn->layout()); + + // Each section here gets its own VMManagerDetailSection, named in the constructor. + // When a system is selected in the list view it is updated through this object + // See updateData() for the implementation + + systemSection = new VMManagerDetailSection(tr("System", "Header for System section in VM Manager Details")); + ui->leftColumn->layout()->addWidget(systemSection); + // These horizontal lines are used for the alternate layout which may possibly + // be a preference one day. + // ui->leftColumn->layout()->addWidget(createHorizontalLine()); + + videoSection = new VMManagerDetailSection(tr("Display", "Header for Display section in VM Manager Details")); + ui->leftColumn->layout()->addWidget(videoSection); + // ui->leftColumn->layout()->addWidget(createHorizontalLine()); + + storageSection = new VMManagerDetailSection(tr("Storage", "Header for Storage section in VM Manager Details")); + ui->leftColumn->layout()->addWidget(storageSection); + // ui->leftColumn->layout()->addWidget(createHorizontalLine()); + + audioSection = new VMManagerDetailSection(tr("Audio", "Header for Audio section in VM Manager Details")); + ui->leftColumn->layout()->addWidget(audioSection); + // ui->leftColumn->layout()->addWidget(createHorizontalLine()); + + networkSection = new VMManagerDetailSection(tr("Network", "Header for Network section in VM Manager Details")); + ui->leftColumn->layout()->addWidget(networkSection); + // ui->leftColumn->layout()->addWidget(createHorizontalLine()); + + inputSection = new VMManagerDetailSection(tr("Input Devices", "Header for Input section in VM Manager Details")); + ui->leftColumn->layout()->addWidget(inputSection); + // ui->leftColumn->layout()->addWidget(createHorizontalLine()); + + portsSection = new VMManagerDetailSection(tr("Ports", "Header for Input section in VM Manager Details")); + ui->leftColumn->layout()->addWidget(portsSection); + + // This is like adding a spacer + leftColumnLayout->addStretch(); + + // Event filter for the notes to save when it loses focus + ui->notesTextEdit->installEventFilter(this); + + // Default screenshot label and thumbnail (image inside the label) sizes + screenshotThumbnailSize = QSize(240, 160); + + // Set the icons for the screenshot navigation buttons + ui->screenshotNext->setIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowRight)); + ui->screenshotPrevious->setIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowLeft)); + ui->screenshotNextTB->setIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowRight)); + ui->screenshotPreviousTB->setIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowLeft)); + // Disabled by default + ui->screenshotNext->setEnabled(false); + ui->screenshotPrevious->setEnabled(false); + ui->screenshotNextTB->setEnabled(false); + ui->screenshotPreviousTB->setEnabled(false); + // Connect their signals + connect(ui->screenshotNext, &QPushButton::clicked, this, &VMManagerDetails::nextScreenshot); + connect(ui->screenshotNextTB, &QToolButton::clicked, this, &VMManagerDetails::nextScreenshot); + connect(ui->screenshotPreviousTB, &QToolButton::clicked, this, &VMManagerDetails::previousScreenshot); + connect(ui->screenshotPrevious, &QPushButton::clicked, this, &VMManagerDetails::previousScreenshot); + // These push buttons can be taken out if the tool buttons stay + ui->screenshotNext->setVisible(false); + ui->screenshotPrevious->setVisible(false); + QString toolButtonStyleSheet; + // Simple method to try and determine if light mode is enabled +#ifdef Q_OS_WINDOWS + const bool lightMode = windows_is_light_theme(); +#else + const bool lightMode = QApplication::palette().window().color().value() > QApplication::palette().windowText().color().value(); +#endif + if (lightMode) { + toolButtonStyleSheet = "QToolButton {background: transparent; border: none; padding: 5px} QToolButton:hover {background: palette(midlight)} QToolButton:pressed {background: palette(mid)}"; + } else { +#ifndef Q_OS_WINDOWS + toolButtonStyleSheet = "QToolButton {background: transparent; border: none; padding: 5px} QToolButton:hover {background: palette(dark)} QToolButton:pressed {background: palette(mid)}"; +#else + toolButtonStyleSheet = "QToolButton {padding: 5px}"; +#endif + } + ui->ssNavTBHolder->setStyleSheet(toolButtonStyleSheet); + + // Experimenting + startPauseButton = new QToolButton(); + startPauseButton->setIcon(QIcon(":/menuicons/qt/icons/run.ico")); + startPauseButton->setAutoRaise(true); + startPauseButton->setEnabled(false); + startPauseButton->setToolTip(tr("Start")); + ui->toolButtonHolder->setStyleSheet(toolButtonStyleSheet); + resetButton = new QToolButton(); + resetButton->setIcon(QIcon(":/menuicons/qt/icons/hard_reset.ico")); + resetButton->setEnabled(false); + resetButton->setToolTip(tr("Hard reset")); + stopButton = new QToolButton(); + stopButton->setIcon(QIcon(":/menuicons/qt/icons/acpi_shutdown.ico")); + stopButton->setEnabled(false); + stopButton->setToolTip(tr("Force shutdown")); + configureButton = new QToolButton(); + configureButton->setIcon(QIcon(":/menuicons/qt/icons/settings.ico")); + configureButton->setEnabled(false); + configureButton->setToolTip(tr("Settings...")); + cadButton = new QToolButton(); + cadButton->setIcon(QIcon(":menuicons/qt/icons/send_cad.ico")); + cadButton->setEnabled(false); + cadButton->setToolTip(tr("Ctrl+Alt+Del")); + + ui->toolButtonHolder->layout()->addWidget(configureButton); + ui->toolButtonHolder->layout()->addWidget(resetButton); + ui->toolButtonHolder->layout()->addWidget(stopButton); + ui->toolButtonHolder->layout()->addWidget(startPauseButton); + ui->toolButtonHolder->layout()->addWidget(cadButton); + + ui->notesTextEdit->setEnabled(false); + + sysconfig = new VMManagerSystem(); +} + +VMManagerDetails::~VMManagerDetails() { + delete ui; +} + +void +VMManagerDetails::updateData(VMManagerSystem *passed_sysconfig) { + + // Set the scrollarea background but also set the scroll bar to none. Otherwise it will also + // set the scrollbar background to the same. +#ifdef Q_OS_WINDOWS + extern bool windows_is_light_theme(); + if (windows_is_light_theme()) +#endif + { + ui->scrollArea->setStyleSheet("QWidget {background-color: palette(light)} QScrollBar{ background-color: none }"); + ui->systemLabel->setStyleSheet("background-color: palette(midlight);"); + } + // Margins are a little different on macos +#ifdef Q_OS_MACOS + ui->systemLabel->setMargin(15); +#else + ui->systemLabel->setMargin(10); +#endif + + // disconnect old signals before assigning the passed systemconfig object + disconnect(startPauseButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::startButtonPressed); + disconnect(startPauseButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::pauseButtonPressed); + disconnect(resetButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::restartButtonPressed); + disconnect(stopButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::shutdownForceButtonPressed); + disconnect(configureButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::launchSettings); + disconnect(cadButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::cadButtonPressed); + + sysconfig = passed_sysconfig; + connect(resetButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::restartButtonPressed); + connect(stopButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::shutdownForceButtonPressed); + connect(configureButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::launchSettings); + connect(cadButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::cadButtonPressed); + cadButton->setEnabled(true); + + bool running = sysconfig->getProcessStatus() == VMManagerSystem::ProcessStatus::Running || + sysconfig->getProcessStatus() == VMManagerSystem::ProcessStatus::RunningWaiting; + if(running) { + startPauseButton->setIcon(QIcon(":/menuicons/qt/icons/pause.ico")); + connect(startPauseButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::pauseButtonPressed); + } else { + startPauseButton->setIcon(QIcon(":/menuicons/qt/icons/run.ico")); + connect(startPauseButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::startButtonPressed); + } + startPauseButton->setEnabled(true); + configureButton->setEnabled(true); + + // Each detail section here has its own VMManagerDetailSection. + // When a system is selected in the list view it is updated here, through this object: + // * First you clear it with VMManagerDetailSection::clear() + // * Then you add each line with VMManagerDetailSection::addSection() + + // System + systemSection->clear(); + systemSection->addSection("Machine", passed_sysconfig->getDisplayValue(Display::Name::Machine)); + systemSection->addSection("CPU", passed_sysconfig->getDisplayValue(Display::Name::CPU)); + systemSection->addSection("Memory", passed_sysconfig->getDisplayValue(Display::Name::Memory)); + + // Video + videoSection->clear(); + videoSection->addSection("Video", passed_sysconfig->getDisplayValue(Display::Name::Video)); + if(!passed_sysconfig->getDisplayValue(Display::Name::Voodoo).isEmpty()) { + videoSection->addSection("Voodoo", passed_sysconfig->getDisplayValue(Display::Name::Voodoo)); + } + + // Disks + storageSection->clear(); + storageSection->addSection("Disks", passed_sysconfig->getDisplayValue(Display::Name::Disks)); + storageSection->addSection("Floppy", passed_sysconfig->getDisplayValue(Display::Name::Floppy)); + storageSection->addSection("CD-ROM", passed_sysconfig->getDisplayValue(Display::Name::CD)); + storageSection->addSection("SCSI", passed_sysconfig->getDisplayValue(Display::Name::SCSIController)); + + // Audio + audioSection->clear(); + audioSection->addSection("Audio", passed_sysconfig->getDisplayValue(Display::Name::Audio)); + audioSection->addSection("MIDI Out", passed_sysconfig->getDisplayValue(Display::Name::MidiOut)); + + // Network + networkSection->clear(); + networkSection->addSection("NIC", passed_sysconfig->getDisplayValue(Display::Name::NIC)); + + // Input + inputSection->clear(); + inputSection->addSection(tr("Mouse"), passed_sysconfig->getDisplayValue(Display::Name::Mouse)); + inputSection->addSection(tr("Joystick"), passed_sysconfig->getDisplayValue(Display::Name::Joystick)); + + // Ports + portsSection->clear(); + portsSection->addSection(tr("Serial Ports"), passed_sysconfig->getDisplayValue(Display::Name::Serial)); + portsSection->addSection(tr("Parallel Ports"), passed_sysconfig->getDisplayValue(Display::Name::Parallel)); + + // Disable screenshot navigation buttons by default + ui->screenshotNext->setEnabled(false); + ui->screenshotPrevious->setEnabled(false); + ui->screenshotNextTB->setEnabled(false); + ui->screenshotPreviousTB->setEnabled(false); + + // Different actions are taken depending on the existence and number of screenshots + screenshots = passed_sysconfig->getScreenshots(); + if (!screenshots.empty()) { + ui->screenshot->setFrameStyle(QFrame::NoFrame); + ui->screenshot->setEnabled(true); + if(screenshots.size() > 1) { + ui->screenshotNext->setEnabled(true); + ui->screenshotPrevious->setEnabled(true); + ui->screenshotNextTB->setEnabled(true); + ui->screenshotPreviousTB->setEnabled(true); + } +#ifdef Q_OS_WINDOWS + ui->screenshot->setStyleSheet(""); +#endif + if(QFileInfo::exists(screenshots.last().filePath())) { + screenshotIndex = screenshots.size() - 1; + const QPixmap pic(screenshots.at(screenshotIndex).filePath()); + ui->screenshot->setPixmap(pic.scaled(240, 160, Qt::KeepAspectRatio, Qt::SmoothTransformation)); + } + } else { + ui->screenshotNext->setEnabled(false); + ui->screenshotPrevious->setEnabled(false); + ui->screenshotNextTB->setEnabled(false); + ui->screenshotPreviousTB->setEnabled(false); + ui->screenshot->setPixmap(QString()); + ui->screenshot->setFixedSize(240, 160); + ui->screenshot->setFrameStyle(QFrame::Box | QFrame::Sunken); + ui->screenshot->setText(tr("No screenshot")); + ui->screenshot->setEnabled(false); + ui->screenshot->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); +#ifdef Q_OS_WINDOWS + if (!windows_is_light_theme()) { + ui->screenshot->setStyleSheet("QLabel { border: 1px solid gray }"); + } else { + ui->screenshot->setStyleSheet(""); + } +#endif + } + + ui->systemLabel->setText(passed_sysconfig->displayName); + ui->statusLabel->setText(sysconfig->process->processId() == 0 ? + tr("Not running") : + QString("%1: PID %2").arg(tr("Running"), QString::number(sysconfig->process->processId()))); + ui->notesTextEdit->setPlainText(passed_sysconfig->notes); + ui->notesTextEdit->setEnabled(true); + + disconnect(sysconfig->process, &QProcess::stateChanged, this, &VMManagerDetails::updateProcessStatus); + connect(sysconfig->process, &QProcess::stateChanged, this, &VMManagerDetails::updateProcessStatus); + + disconnect(sysconfig, &VMManagerSystem::windowStatusChanged, this, &VMManagerDetails::updateWindowStatus); + connect(sysconfig, &VMManagerSystem::windowStatusChanged, this, &VMManagerDetails::updateWindowStatus); + + disconnect(sysconfig, &VMManagerSystem::clientProcessStatusChanged, this, &VMManagerDetails::updateProcessStatus); + connect(sysconfig, &VMManagerSystem::clientProcessStatusChanged, this, &VMManagerDetails::updateProcessStatus); + + updateProcessStatus(); +} + +void +VMManagerDetails::updateProcessStatus() { + const bool running = sysconfig->process->state() == QProcess::ProcessState::Running; + QString status_text = running ? + QString("%1: PID %2").arg(tr("Running"), QString::number(sysconfig->process->processId())) : + tr("Not running"); + status_text.append(sysconfig->window_obscured ? QString(" (%1)").arg(tr("waiting")) : ""); + ui->statusLabel->setText(status_text); + resetButton->setEnabled(running); + stopButton->setEnabled(running); + cadButton->setEnabled(running); + if(running) { + if(sysconfig->getProcessStatus() == VMManagerSystem::ProcessStatus::Running) { + startPauseButton->setIcon(QIcon(":/menuicons/qt/icons/pause.ico")); + startPauseButton->setToolTip(tr("Pause")); + } else { + startPauseButton->setIcon(QIcon(":/menuicons/qt/icons/run.ico")); + startPauseButton->setToolTip(tr("Continue")); + } + + disconnect(startPauseButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::pauseButtonPressed); + disconnect(startPauseButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::startButtonPressed); + connect(startPauseButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::pauseButtonPressed); + } else { + startPauseButton->setIcon(QIcon(":/menuicons/qt/icons/run.ico")); + disconnect(startPauseButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::pauseButtonPressed); + disconnect(startPauseButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::startButtonPressed); + connect(startPauseButton, &QToolButton::clicked, sysconfig, &VMManagerSystem::startButtonPressed); + startPauseButton->setToolTip(tr("Start")); + } +} + +void +VMManagerDetails::updateWindowStatus() +{ + qInfo("Window status changed: %i", sysconfig->window_obscured); + updateProcessStatus(); +} + +QWidget * +VMManagerDetails::createHorizontalLine(const int leftSpacing, const int rightSpacing) +{ + const auto container = new QWidget; + const auto hLayout = new QHBoxLayout(container); + + hLayout->addSpacing(leftSpacing); + + const auto line = new QFrame(); + line->setFrameShape(QFrame::HLine); + line->setFrameShadow(QFrame::Sunken); + + hLayout->addWidget(line); + hLayout->addSpacing(rightSpacing); + hLayout->setContentsMargins(0, 5, 0, 5); + + return container; +} + +void +VMManagerDetails::saveNotes() const +{ + sysconfig->setNotes(ui->notesTextEdit->toPlainText()); +} + +void +VMManagerDetails::nextScreenshot() +{ + screenshotIndex = (screenshotIndex + 1) % screenshots.size(); + const QPixmap pic(screenshots.at(screenshotIndex).filePath()); + ui->screenshot->setPixmap(pic.scaled(240, 160, Qt::KeepAspectRatio, Qt::SmoothTransformation)); +} + +void +VMManagerDetails::previousScreenshot() +{ + screenshotIndex = screenshotIndex == 0 ? screenshots.size() - 1 : screenshotIndex - 1; + const QPixmap pic(screenshots.at(screenshotIndex).filePath()); + ui->screenshot->setPixmap(pic.scaled(240, 160, Qt::KeepAspectRatio, Qt::SmoothTransformation)); +} + +bool +VMManagerDetails::eventFilter(QObject *watched, QEvent *event) +{ + if (watched->isWidgetType() && event->type() == QEvent::FocusOut) { + // Make sure it's the textedit + if (const auto *textEdit = qobject_cast(watched); textEdit) { + saveNotes(); + } + } + return QWidget::eventFilter(watched, event); +} + diff --git a/src/qt/qt_vmmanager_details.hpp b/src/qt/qt_vmmanager_details.hpp new file mode 100644 index 000000000..5d3bfa8a4 --- /dev/null +++ b/src/qt/qt_vmmanager_details.hpp @@ -0,0 +1,90 @@ +/* +* 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. +* +* Header for 86Box VM manager system details module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#ifndef QT_VMMANAGER_DETAILS_H +#define QT_VMMANAGER_DETAILS_H + +#include +#include "qt_vmmanager_system.hpp" +// #include "qt_vmmanager_details_section.hpp" +#include "qt_vmmanager_detailsection.hpp" + + +QT_BEGIN_NAMESPACE +//namespace Ui { class VMManagerDetails; class CollapseButton;} +namespace Ui { class VMManagerDetails;} +QT_END_NAMESPACE + +class VMManagerDetails : public QWidget { + Q_OBJECT + +public: + explicit VMManagerDetails(QWidget *parent = nullptr); + + ~VMManagerDetails() override; + + void updateData(VMManagerSystem *passed_sysconfig); + + void updateProcessStatus(); + + void updateWindowStatus(); +// CollapseButton *systemCollapseButton; + +private: + Ui::VMManagerDetails *ui; + VMManagerSystem *sysconfig; + + VMManagerDetailSection *systemSection; + VMManagerDetailSection *videoSection; + VMManagerDetailSection *storageSection; + VMManagerDetailSection *audioSection; + VMManagerDetailSection *networkSection; + VMManagerDetailSection *inputSection; + VMManagerDetailSection *portsSection; + + QFileInfoList screenshots; + int screenshotIndex = 0; + QSize screenshotLabelSize; + QSize screenshotThumbnailSize; + + QToolButton *startPauseButton; + QToolButton *resetButton; + QToolButton *stopButton; + QToolButton *configureButton; + QToolButton *cadButton; + + static QWidget* createHorizontalLine(int leftSpacing = 25, int rightSpacing = 25); + // QVBoxLayout *detailsLayout; +private slots: + void saveNotes() const; + void nextScreenshot(); + void previousScreenshot(); + +protected: + bool eventFilter(QObject *watched, QEvent *event) override; + +// CollapseButton *systemCollapseButton; +// QFrame *systemFrame; +// CollapseButton *displayCollapseButton; +// QFrame *displayFrame; +// CollapseButton *storageCollapseButton; +// QFrame *storageFrame; +}; + + + +#endif //QT_VMMANAGER_DETAILS_H diff --git a/src/qt/qt_vmmanager_details.ui b/src/qt/qt_vmmanager_details.ui new file mode 100644 index 000000000..9b4fbbe8b --- /dev/null +++ b/src/qt/qt_vmmanager_details.ui @@ -0,0 +1,293 @@ + + + VMManagerDetails + + + + 0 + 0 + 497 + 444 + + + + VMManagerDetails + + + + 0 + + + 0 + + + + + + 18 + + + + No Machines Found! + + + Qt::AlignCenter + + + + + + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + true + + + + + 0 + 0 + 139 + 388 + + + + + 0 + + + 12 + + + 12 + + + 12 + + + 12 + + + + + + + + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 240 + 160 + + + + + 240 + 160 + + + + + + + Qt::AlignCenter + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + + + false + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + ... + + + + + + + ... + + + true + + + + + + + + + + + 0 + 0 + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Type some notes here + + + + + + + Qt::Vertical + + + + 20 + 0 + + + + + + + + + 0 + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + Qt::AlignCenter + + + + + + + + + + + + + + diff --git a/src/qt/qt_vmmanager_detailsection.cpp b/src/qt/qt_vmmanager_detailsection.cpp new file mode 100644 index 000000000..ce42ae281 --- /dev/null +++ b/src/qt/qt_vmmanager_detailsection.cpp @@ -0,0 +1,309 @@ +/* +* 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. +* +* 86Box VM manager system details section module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#include "qt_vmmanager_detailsection.hpp" +#include "ui_qt_vmmanager_detailsection.h" + +#include + +const QString VMManagerDetailSection::sectionSeparator = ";"; +using namespace VMManager; + +VMManagerDetailSection:: +VMManagerDetailSection(const QString §ionName) + : mainLayout(new QVBoxLayout()) + , buttonLayout(new QHBoxLayout()) + , frame(new QFrame()) + , ui(new Ui::DetailSection) +{ + ui->setupUi(this); + + frameGridLayout = new QGridLayout(); + // Create the collapse button, set the name and add it to the layout + collapseButton = new CollapseButton(); + setSectionName(sectionName); + ui->collapseButtonHolder->setContentsMargins(getMargins(MarginSection::ToolButton)); + + // Simple method to try and determine if light mode is enabled on the host +#ifdef Q_OS_WINDOWS + extern bool windows_is_light_theme(); + const bool lightMode = windows_is_light_theme(); +#else + const bool lightMode = QApplication::palette().window().color().value() > QApplication::palette().windowText().color().value(); +#endif + // Alternate layout + if ( lightMode) { + ui->collapseButtonHolder->setStyleSheet("background-color: palette(midlight);"); + } else { +#ifdef Q_OS_WINDOWS + ui->outerFrame->setStyleSheet("background-color: #272727;"); + ui->collapseButtonHolder->setStyleSheet("background-color: #616161;"); +#else + ui->collapseButtonHolder->setStyleSheet("background-color: palette(mid);"); +#endif + } + const auto sectionLabel = new QLabel(sectionName); + sectionLabel->setStyleSheet(sectionLabel->styleSheet().append("font-weight: bold;")); + ui->collapseButtonHolder->setContentsMargins(QMargins(3, 2, 0, 2)); + ui->collapseButtonHolder->layout()->addWidget(sectionLabel); + + // ui->collapseButtonHolder->layout()->addWidget(collapseButton); + collapseButton->setContent(ui->detailFrame); + // Horizontal line added after the section name / button + // const auto hLine = new QFrame(); + // hLine->setFrameShape(QFrame::HLine); + // hLine->setFrameShadow(QFrame::Sunken); + // hLine->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); + // ui->collapseButtonHolder->layout()->addWidget(hLine); + const auto hSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); + ui->collapseButtonHolder->layout()->addItem(hSpacer); + // collapseButton->setContent(frame); + // ui->sectionName->setVisible(false); + setVisible(false); +} + +VMManagerDetailSection:: +VMManagerDetailSection(const QVariant &varSectionName) : ui(new Ui::DetailSection) +{ + const auto sectionName = varSectionName.toString(); + + // Initialize even though they will get wiped out + // (to keep clang-tidy happy) + frameGridLayout = new QGridLayout(); + const auto outerFrame = new QFrame(); + // for the CSS + outerFrame->setObjectName("outer_frame"); + outerFrame->setContentsMargins(QMargins(0, 0, 0, 0)); + const auto innerFrameLayout = new QVBoxLayout(); + + outerFrame->setLayout(innerFrameLayout); + auto *outerFrameLayout = new QVBoxLayout(); + outerFrameLayout->addWidget(outerFrame); + outerFrameLayout->setContentsMargins(QMargins(0, 0, 0, 0)); + + const auto buttonWidget = new QWidget(this); + + mainLayout = new QVBoxLayout(); + buttonLayout = new QHBoxLayout(); + buttonWidget->setLayout(buttonLayout); + + collapseButton = new CollapseButton(); + setSectionName(sectionName); + buttonLayout->setContentsMargins(getMargins(MarginSection::ToolButton)); + buttonLayout->addWidget(collapseButton); + + // buttonLayout->addStretch(); + auto *hLine = new QFrame(); + hLine->setFrameShape(QFrame::HLine); + hLine->setFrameShadow(QFrame::Sunken); + hLine->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); + buttonLayout->addWidget(hLine); + + mainLayout->addLayout(buttonLayout); + + frame = new QFrame(); + frame->setFrameShape(QFrame::Box); + frame->setFrameStyle(QFrame::NoFrame); + collapseButton->setContent(frame); + + mainLayout->addWidget(frame); + innerFrameLayout->addWidget(buttonWidget); + innerFrameLayout->addWidget(frame); + setLayout(outerFrameLayout); +} + +VMManagerDetailSection::~VMManagerDetailSection() += default; + +void +VMManagerDetailSection::setSectionName(const QString &name) +{ + sectionName = name; + collapseButton->setButtonText(" " + sectionName); + // Bold the section headers + collapseButton->setStyleSheet(collapseButton->styleSheet().append("font-weight: bold;")); +} + +void +VMManagerDetailSection::addSection(const QString &name, const QString &value, Display::Name displayField) +{ + const auto new_section = DetailSection { name, value}; + sections.push_back(new_section); + setSections(); +} + +void +VMManagerDetailSection::setupMainLayout() +{ + // clang-tidy says I don't need to check before deleting + delete mainLayout; + mainLayout = new QVBoxLayout; +} +void +VMManagerDetailSection::clearContentsSetupGrid() +{ + // Clear everything out + if(frameGridLayout) { + while(frameGridLayout->count()) { + QLayoutItem * cur_item = frameGridLayout->takeAt(0); + if(cur_item->widget()) + delete cur_item->widget(); + delete cur_item; + } + } + + delete frameGridLayout; + frameGridLayout = new QGridLayout(); + qint32 *left = nullptr, *top = nullptr, *right = nullptr, *bottom = nullptr; + frameGridLayout->getContentsMargins(left, top, right, bottom); + frameGridLayout->setContentsMargins(getMargins(MarginSection::DisplayGrid)); + ui->detailFrame->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); + ui->detailFrame->setLayout(frameGridLayout); +} +void +VMManagerDetailSection::setSections() +{ + clearContentsSetupGrid(); + int row = 0; + + + for ( const auto& section : sections) { + // if the string contains the separator (defined elsewhere) then split and + // add each entry on a new line. Otherwise, just add the one. + QStringList sectionsToAdd; + if(section.value.contains(sectionSeparator)) { + sectionsToAdd = section.value.split(sectionSeparator); + } else { + sectionsToAdd.push_back(section.value); + } + bool keyAdded = false; + for(const auto&line : sectionsToAdd) { + if(line.isEmpty()) { + // Don't bother adding entries if the values are blank + continue; + } + const auto labelKey = new QLabel(); + labelKey->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); + const auto labelValue = new QLabel(); + labelKey->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); + labelValue->setTextInteractionFlags(labelValue->textInteractionFlags() | Qt::TextSelectableByMouse); + labelKey->setTextInteractionFlags(labelValue->textInteractionFlags() | Qt::TextSelectableByMouse); + + // Reduce the text size for the label + // First, get the existing font + auto smaller_font = labelValue->font(); + // Get a smaller size + // Not sure if I like the smaller size, back to regular for now + // auto smaller_size = 0.85 * smaller_font.pointSize(); + const auto smaller_size = 1 * smaller_font.pointSize(); + // Set the font to the smaller size + smaller_font.setPointSizeF(smaller_size); + // Assign that new, smaller font to the label + labelKey->setFont(smaller_font); + labelValue->setFont(smaller_font); + + labelKey->setText(section.name + ":"); + labelValue->setText(line); + if(!keyAdded) { + frameGridLayout->addWidget(labelKey, row, 0, Qt::AlignLeft); + keyAdded = true; + } + frameGridLayout->addWidget(labelValue, row, 1, Qt::AlignLeft); + const auto hSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); + frameGridLayout->addItem(hSpacer, row, 2); + row++; + } + } + collapseButton->setContent(ui->detailFrame); + if (sections.size()) + setVisible(true); +} +void +VMManagerDetailSection::clear() +{ + sections.clear(); + setVisible(false); +} + +// QT for Linux and Windows doesn't have the same default margins as QT on MacOS. +// For consistency in appearance we'll have to return the margins on a per-OS basis +QMargins +VMManagerDetailSection::getMargins(const MarginSection section) +{ + switch (section) { + case MarginSection::ToolButton: +#if defined(Q_OS_WINDOWS) or defined(Q_OS_LINUX) + return {10, 0, 5, 0}; +#else + return {0, 0, 5, 0}; +#endif + case MarginSection::DisplayGrid: +#if defined(Q_OS_WINDOWS) or defined(Q_OS_LINUX) + return {10, 0, 0, 10}; +#else + return {0, 0, 0, 10}; +#endif + default: + return {}; + } +} + +// CollapseButton Class + +CollapseButton::CollapseButton(QWidget *parent) : QToolButton(parent), content_(nullptr) { + setCheckable(true); + setStyleSheet("background:none; border:none;"); + setIconSize(QSize(8, 8)); + setFont(QApplication::font()); + setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + connect(this, &QToolButton::toggled, [=](const bool checked) { + setArrowType(checked ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow); + content_ != nullptr && checked ? showContent() : hideContent(); + }); + setChecked(true); +} + +void CollapseButton::setButtonText(const QString &text) { + setText(" " + text); +} + +void CollapseButton::setContent(QWidget *content) { + assert(content != nullptr); + content_ = content; + const auto animation_ = new QPropertyAnimation(content_, "maximumHeight"); // QObject with auto delete + animation_->setStartValue(0); + animation_->setEasingCurve(QEasingCurve::InOutQuad); + animation_->setDuration(300); + animation_->setEndValue(content->geometry().height() + 50); + // qDebug() << "section" << text() << "has a height of" << content->geometry().height(); + animator_.clear(); + animator_.addAnimation(animation_); + if (!isChecked()) { + content->setMaximumHeight(0); + } +} + +void CollapseButton::hideContent() { + animator_.setDirection(QAbstractAnimation::Backward); + animator_.start(); +} + +void CollapseButton::showContent() { + animator_.setDirection(QAbstractAnimation::Forward); + animator_.start(); +} + diff --git a/src/qt/qt_vmmanager_detailsection.hpp b/src/qt/qt_vmmanager_detailsection.hpp new file mode 100644 index 000000000..7619a476c --- /dev/null +++ b/src/qt/qt_vmmanager_detailsection.hpp @@ -0,0 +1,101 @@ +/* +* 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. +* +* 86Box VM manager system details section module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed + */ + +#ifndef QT_VMMANAGER_DETAILSECTION_H +#define QT_VMMANAGER_DETAILSECTION_H + +#include +#include +#include +#include +#include +#include +#include "qt_vmmanager_system.hpp" + +QT_BEGIN_NAMESPACE +namespace Ui { class DetailSection; } +QT_END_NAMESPACE + +class CollapseButton final : public QToolButton { + Q_OBJECT + +public: + explicit CollapseButton(QWidget *parent = nullptr); + + void setButtonText(const QString &text); + + void setContent(QWidget *content); + + void hideContent(); + + void showContent(); + +private: + QWidget *content_; + QString text_; + QParallelAnimationGroup animator_; +}; + +class VMManagerDetailSection final : public QWidget { + Q_OBJECT + +public: + explicit VMManagerDetailSection(const QString §ionName); + explicit VMManagerDetailSection(const QVariant &varSectionName); + // explicit VMManagerDetailSection(); + + ~VMManagerDetailSection() override; + + void addSection(const QString &name, const QString &value, VMManager::Display::Name displayField = VMManager::Display::Name::Unknown); + void clear(); + + CollapseButton *collapseButton; +// QGridLayout *buttonGridLayout; + QGridLayout *frameGridLayout; + QVBoxLayout *mainLayout; + QHBoxLayout *buttonLayout; + QFrame *frame; + + static const QString sectionSeparator; + + +private: + enum class MarginSection { + ToolButton, + DisplayGrid, + }; + + void setSectionName(const QString &name); + void setupMainLayout(); + void clearContentsSetupGrid(); + void setSections(); + + static QMargins getMargins(MarginSection section); + + QString sectionName; + + struct DetailSection { + QString name; + QString value; + }; + + QVector sections; + Ui::DetailSection *ui; + +}; + +#endif // QT_VMMANAGER_DETAILSECTION_H diff --git a/src/qt/qt_vmmanager_detailsection.ui b/src/qt/qt_vmmanager_detailsection.ui new file mode 100644 index 000000000..18e89ee65 --- /dev/null +++ b/src/qt/qt_vmmanager_detailsection.ui @@ -0,0 +1,91 @@ + + + DetailSection + + + + 0 + 0 + 348 + 151 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + + + + + + + + diff --git a/src/qt/qt_vmmanager_listviewdelegate.cpp b/src/qt/qt_vmmanager_listviewdelegate.cpp new file mode 100644 index 000000000..28820a044 --- /dev/null +++ b/src/qt/qt_vmmanager_listviewdelegate.cpp @@ -0,0 +1,249 @@ +/* +* 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. +* +* 86Box VM manager list view delegate module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + + +#include + +#include "qt_vmmanager_listviewdelegate.hpp" +#include "qt_vmmanager_model.hpp" + +#ifdef Q_OS_WINDOWS +extern bool windows_is_light_theme(); +#endif + + +// Thanks to scopchanov https://github.com/scopchanov/SO-MessageLog +// from https://stackoverflow.com/questions/53105343/is-it-possible-to-add-a-custom-widget-into-a-qlistview + + +VMManagerListViewDelegate::VMManagerListViewDelegate(QObject *parent) + : QStyledItemDelegate(parent), + m_ptr(new VMManagerListViewDelegateStyle) +{ +} + +VMManagerListViewDelegate::~VMManagerListViewDelegate() += default; + +void VMManagerListViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const { + bool windows_light_mode = true; +#ifdef Q_OS_WINDOWS + windows_light_mode = windows_is_light_theme(); +#endif + QStyleOptionViewItem opt(option); + initStyleOption(&opt, index); + const QPalette &palette(opt.palette); + // opt.rect = opt.rect.adjusted(0, 0, 0, 20); + const QRect &rect(opt.rect); + const QRect &contentRect(rect.adjusted(m_ptr->margins.left(), + m_ptr->margins.top(), + -m_ptr->margins.right(), + -m_ptr->margins.bottom())); + + // The status icon represents the current state of the vm. Initially set to a default state. + QIcon status_icon = QApplication::style()->standardIcon(QStyle::SP_MediaStop); + auto process_variant = index.data(VMManagerModel::Roles::ProcessStatus); + auto process_status = process_variant.value(); + // The main icon, configurable. Falls back to default if it cannot be loaded. + auto customIcom = index.data(VMManagerModel::Roles::Icon).toString(); + opt.icon = QIcon(":/settings/qt/icons/86Box-gray.ico"); + if(!customIcom.isEmpty()) { + if (const auto customPixmap = QPixmap(customIcom); !customPixmap.isNull()) { + opt.icon = customPixmap; + } + } + // opt.icon = QIcon(":/settings/qt/icons/86Box-gray.ico"); + + // Set the status icon based on the process status + switch(process_status) { + case VMManagerSystem::ProcessStatus::Running: + status_icon = QIcon(":/menuicons/qt/icons/run.ico"); + break; + case VMManagerSystem::ProcessStatus::Stopped: + status_icon = QIcon(":/menuicons/qt/icons/acpi_shutdown.ico"); + break; + case VMManagerSystem::ProcessStatus::PausedWaiting: + case VMManagerSystem::ProcessStatus::RunningWaiting: + case VMManagerSystem::ProcessStatus::Paused: + status_icon = QIcon(":/menuicons/qt/icons/pause.ico"); + break; + default: + status_icon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxQuestion); + } + + + // Used to determine if the horizontal separator should be drawn + const bool lastIndex = (index.model()->rowCount() - 1) == index.row(); + const bool hasIcon = !opt.icon.isNull(); + const int bottomEdge = rect.bottom(); + QFont f(opt.font); + + f.setPointSizeF(m_ptr->statusFontPointSize(opt.font)); + + painter->save(); + painter->setClipping(true); + painter->setClipRect(rect); + painter->setFont(opt.font); + + // Draw the background + if (opt.state & QStyle::State_Selected) { + // When selected, only draw the highlighted part until the horizontal separator + int offset = 2; + auto highlightRect = rect.adjusted(0, 0, 0, -offset); + painter->fillRect(highlightRect, windows_light_mode ? palette.highlight().color() : QColor("#616161")); + // Then fill the remainder with the normal color + auto regularRect = rect.adjusted(0, rect.height()-offset, 0, 0); + painter->fillRect(regularRect, windows_light_mode ? palette.light().color() : QColor("#272727")); + } else { + // Otherwise just draw the background color as usual + painter->fillRect(rect, windows_light_mode ? palette.light().color() : QColor("#272727")); + } + + // Draw bottom line. Last line gets a different color + painter->setPen(lastIndex ? palette.dark().color() + : palette.mid().color()); + painter->drawLine(lastIndex ? rect.left() : m_ptr->margins.left(), + bottomEdge, rect.right(), bottomEdge); + + // Draw system icon + if (hasIcon) { + painter->drawPixmap(contentRect.left(), contentRect.top(), + opt.icon.pixmap(m_ptr->iconSize)); + } + + // System name + QRect systemNameRect(m_ptr->systemNameBox(opt, index)); + + systemNameRect.moveTo(m_ptr->margins.left() + m_ptr->iconSize.width() + + m_ptr->spacingHorizontal, contentRect.top()); + // If desired, font can be changed here +// painter->setFont(f); + painter->setFont(opt.font); + painter->setPen(palette.text().color()); + painter->drawText(systemNameRect, Qt::TextSingleLine, opt.text); + + // Draw status icon + painter->drawPixmap(systemNameRect.left(), systemNameRect.bottom() + + m_ptr->spacingVertical, + status_icon.pixmap(m_ptr->smallIconSize)); + + // This rectangle is around the status icon + // auto point = QPoint(systemNameRect.left(), systemNameRect.bottom() + // + m_ptr->spacingVertical); + // auto point2 = QPoint(point.x() + m_ptr->smallIconSize.width(), point.y() + m_ptr->smallIconSize.height()); + // auto arect = QRect(point, point2); + // painter->drawRect(arect); + + // Draw status text + QRect statusRect(m_ptr->statusBox(opt, index)); + int extraaa = 2; + statusRect.moveTo(systemNameRect.left() + m_ptr->margins.left() + m_ptr->smallIconSize.width(), + systemNameRect.bottom() + m_ptr->spacingVertical + extraaa + (m_ptr->smallIconSize.height() - systemNameRect.height() )); + +// painter->setFont(opt.font); + painter->setFont(f); + painter->setPen(palette.windowText().color()); + painter->drawText(statusRect, Qt::TextSingleLine, + index.data(VMManagerModel::Roles::ProcessStatusString).toString()); + + painter->restore(); + +} + +QMargins VMManagerListViewDelegate::contentsMargins() const +{ + return m_ptr->margins; +} + +void VMManagerListViewDelegate::setContentsMargins(const int left, const int top, const int right, const int bottom) const +{ + m_ptr->margins = QMargins(left, top, right, bottom); +} + +int VMManagerListViewDelegate::horizontalSpacing() const +{ + return m_ptr->spacingHorizontal; +} + +void VMManagerListViewDelegate::setHorizontalSpacing(const int spacing) const +{ + m_ptr->spacingHorizontal = spacing; +} + +int VMManagerListViewDelegate::verticalSpacing() const +{ + return m_ptr->spacingVertical; +} + +void VMManagerListViewDelegate::setVerticalSpacing(const int spacing) const +{ + m_ptr->spacingVertical = spacing; +} + + +QSize VMManagerListViewDelegate::sizeHint(const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + QStyleOptionViewItem opt(option); + initStyleOption(&opt, index); + + const int textHeight = m_ptr->systemNameBox(opt, index).height() + + m_ptr->spacingVertical + m_ptr->statusBox(opt, index).height(); + const int iconHeight = m_ptr->iconSize.height(); + const int h = textHeight > iconHeight ? textHeight : iconHeight; + + // return the same width + // for height, add margins on top and bottom *plus* either the text or icon height, whichever is greater + // Note: text height is the combined value of the system name and the status just below the name + return {opt.rect.width(), m_ptr->margins.top() + h + + m_ptr->margins.bottom()}; +} + +VMManagerListViewDelegateStyle::VMManagerListViewDelegateStyle() : + iconSize(32, 32), + smallIconSize(16, 16), + // bottom gets a little more than the top because of the custom separator + margins(4, 10, 8, 12), + // Spacing between icon and text + spacingHorizontal(8), + spacingVertical(4) +{ + +} + +QRect VMManagerListViewDelegateStyle::statusBox(const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + QFont f(option.font); + + f.setPointSizeF(statusFontPointSize(option.font)); + + return QFontMetrics(f).boundingRect(index.data(VMManagerModel::Roles::ProcessStatusString).toString()) + .adjusted(0, 0, 1, 1); +} + +qreal VMManagerListViewDelegateStyle::statusFontPointSize(const QFont &f) const +{ + return 0.75*f.pointSize(); +// return 1*f.pointSize(); +} + +QRect VMManagerListViewDelegateStyle::systemNameBox(const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + return option.fontMetrics.boundingRect(option.text).adjusted(0, 0, 1, 1); +} diff --git a/src/qt/qt_vmmanager_listviewdelegate.hpp b/src/qt/qt_vmmanager_listviewdelegate.hpp new file mode 100644 index 000000000..84325086d --- /dev/null +++ b/src/qt/qt_vmmanager_listviewdelegate.hpp @@ -0,0 +1,67 @@ +/* +* 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. +* +* Header for 86Box VM manager list view delegate module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#ifndef QT_VMMANAGER_LISTVIEWDELEGATE_H +#define QT_VMMANAGER_LISTVIEWDELEGATE_H + +#include +#include +#include "qt_vmmanager_system.hpp" + +class VMManagerListViewDelegateStyle +{ + VMManagerListViewDelegateStyle(); + + [[nodiscard]] inline QRect systemNameBox(const QStyleOptionViewItem &option, + const QModelIndex &index) const; + [[nodiscard]] inline qreal statusFontPointSize(const QFont &f) const; + [[nodiscard]] inline QRect statusBox(const QStyleOptionViewItem &option, const QModelIndex &index) const; + + QSize iconSize; + QSize smallIconSize; + QMargins margins; + int spacingHorizontal; + int spacingVertical; + + friend class VMManagerListViewDelegate; +}; + +class VMManagerListViewDelegate final : public QStyledItemDelegate { + Q_OBJECT + +public: + explicit VMManagerListViewDelegate(QObject *parent = nullptr); + ~VMManagerListViewDelegate() override; + using QStyledItemDelegate::QStyledItemDelegate; + + [[nodiscard]] QMargins contentsMargins() const; + void setContentsMargins(int left, int top, int right, int bottom) const; + + [[nodiscard]] int horizontalSpacing() const; + void setHorizontalSpacing(int spacing) const; + + [[nodiscard]] int verticalSpacing() const; + void setVerticalSpacing(int spacing) const; + + void paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const override; + [[nodiscard]] QSize sizeHint(const QStyleOptionViewItem &option, + const QModelIndex &index) const override; +private: + VMManagerListViewDelegateStyle *m_ptr; +}; +#endif // QT_VMMANAGER_LISTVIEWDELEGATE_H \ No newline at end of file diff --git a/src/qt/qt_vmmanager_main.cpp b/src/qt/qt_vmmanager_main.cpp new file mode 100644 index 000000000..88b9456cc --- /dev/null +++ b/src/qt/qt_vmmanager_main.cpp @@ -0,0 +1,521 @@ +/* +* 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. +* +* 86Box VM manager main module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "qt_vmmanager_main.hpp" +#include "ui_qt_vmmanager_main.h" +#include "qt_vmmanager_model.hpp" +#include "qt_vmmanager_addmachine.hpp" + +VMManagerMain::VMManagerMain(QWidget *parent) : + QWidget(parent), ui(new Ui::VMManagerMain), selected_sysconfig(new VMManagerSystem) { + ui->setupUi(this); + this->setWindowTitle("86Box VM Manager"); + + // Set up the main listView + ui->listView->setItemDelegate(new VMManagerListViewDelegate); + vm_model = new VMManagerModel; + proxy_model = new StringListProxyModel(this); + proxy_model->setSourceModel(vm_model); + ui->listView->setModel(proxy_model); + proxy_model->setSortCaseSensitivity(Qt::CaseInsensitive); + ui->listView->model()->sort(0, Qt::AscendingOrder); + + // Connect the model signal + connect(vm_model, &VMManagerModel::systemDataChanged, this, &VMManagerMain::modelDataChange); + + // Set up the context menu for the list view + ui->listView->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->listView, &QListView::customContextMenuRequested, [this](const QPoint &pos) { + const auto indexAt = ui->listView->indexAt(pos); + if (indexAt.isValid()) { + QMenu contextMenu(tr("Context Menu"), ui->listView); + + QAction nameChangeAction(tr("Change display name")); + contextMenu.addAction(&nameChangeAction); + // Use a lambda to call a function so indexAt can be passed + connect(&nameChangeAction, &QAction::triggered, ui->listView, [this, indexAt] { + updateDisplayName(indexAt); + }); + + QAction openSystemFolderAction(tr("Open folder")); + contextMenu.addAction(&openSystemFolderAction); + connect(&openSystemFolderAction, &QAction::triggered, [indexAt] { + if (const auto configDir = indexAt.data(VMManagerModel::Roles::ConfigDir).toString(); !configDir.isEmpty()) { + QDir dir(configDir); + if (!dir.exists()) + dir.mkpath("."); + + QDesktopServices::openUrl(QUrl(QString("file:///") + dir.canonicalPath())); + } + }); + + QAction convertToP3(tr("Convert system to PIII")); + contextMenu.addAction(&convertToP3); + convertToP3.setEnabled(false); + + QAction setSystemIcon(tr("Set icon")); + contextMenu.addAction(&setSystemIcon); + connect(&setSystemIcon, &QAction::triggered, [this] { + IconSelectionDialog dialog(":/systemicons/"); + if(dialog.exec() == QDialog::Accepted) { + const QString iconName = dialog.getSelectedIconName(); + // A Blank iconName will cause setIcon to reset to the default + selected_sysconfig->setIcon(iconName); + } + }); + + contextMenu.addSeparator(); + + QAction showRawConfigFile(tr("Show config file")); + contextMenu.addAction(&showRawConfigFile); + connect(&showRawConfigFile, &QAction::triggered, [this, indexAt] { + if (const auto configFile = indexAt.data(VMManagerModel::Roles::ConfigFile).toString(); !configFile.isEmpty()) { + showTextFileContents(indexAt.data(Qt::DisplayRole).toString(), configFile); + } + }); + + contextMenu.exec(ui->listView->viewport()->mapToGlobal(pos)); + } + }); + + // Initial default details view + vm_details = new VMManagerDetails(); + ui->detailsArea->layout()->addWidget(vm_details); + const QItemSelectionModel *selection_model = ui->listView->selectionModel(); + + connect(selection_model, &QItemSelectionModel::currentChanged, this, &VMManagerMain::currentSelectionChanged); + // If there are items in the model, make sure to select the first item by default. + // When settings are loaded, the last selected item will be selected (if available) + if (proxy_model->rowCount(QModelIndex()) > 0) { + const QModelIndex first_index = proxy_model->index(0, 0); + ui->listView->setCurrentIndex(first_index); + } + + // Load and apply settings + loadSettings(); + + // Set up search bar + connect(ui->searchBar, &QLineEdit::textChanged, this, &VMManagerMain::searchSystems); + // Create the completer + auto *completer = new QCompleter(this); + completer->setCaseSensitivity(Qt::CaseInsensitive); + completer->setFilterMode(Qt::MatchContains); + // Get the completer list + const auto allStrings = getSearchCompletionList(); + // Set up the completer + auto *completerModel = new QStringListModel(allStrings, completer); + completer->setModel(completerModel); + ui->searchBar->setCompleter(completer); + + // Set initial status bar after the event loop starts + QTimer::singleShot(0, this, [this] { + emit updateStatusRight(totalCountString()); + }); + + // Start update check after a slight delay + QTimer::singleShot(1000, this, [this] { + if(updateCheck) { + backgroundUpdateCheckStart(); + } + }); +} + +VMManagerMain::~VMManagerMain() { + delete ui; + delete vm_model; +} + +void +VMManagerMain::currentSelectionChanged(const QModelIndex ¤t, + const QModelIndex &previous) +{ + if(!current.isValid()) { + return; + } + + const auto mapped_index = proxy_model->mapToSource(current); + selected_sysconfig = vm_model->getConfigObjectForIndex(mapped_index); + vm_details->updateData(selected_sysconfig); + + // Emit that the selection changed, include with the process state + emit selectionChanged(current, selected_sysconfig->process->state()); + +} + +void +VMManagerMain::settingsButtonPressed() { + if(!currentSelectionIsValid()) { + return; + } + selected_sysconfig->launchSettings(); + // If the process is already running, the system will be instructed to open its settings window. + // Otherwise the process will be launched and will need to be tracked here. + if (!selected_sysconfig->isProcessRunning()) { + connect(selected_sysconfig->process, QOverload::of(&QProcess::finished), + [=](const int exitCode, const QProcess::ExitStatus exitStatus){ + if (exitCode != 0 || exitStatus != QProcess::NormalExit) { + qInfo().nospace().noquote() << "Abnormal program termination while launching settings: exit code " << exitCode << ", exit status " << exitStatus; + return; + } + selected_sysconfig->reloadConfig(); + vm_details->updateData(selected_sysconfig); + }); + } +} + +void +VMManagerMain::startButtonPressed() const +{ + if(!currentSelectionIsValid()) { + return; + } + selected_sysconfig->startButtonPressed(); +} + +void +VMManagerMain::restartButtonPressed() const +{ + if(!currentSelectionIsValid()) { + return; + } + selected_sysconfig->restartButtonPressed(); + +} + +void +VMManagerMain::pauseButtonPressed() const +{ + if(!currentSelectionIsValid()) { + return; + } + selected_sysconfig->pauseButtonPressed(); +} + +void +VMManagerMain::shutdownRequestButtonPressed() const +{ + if (!currentSelectionIsValid()) { + return; + } + selected_sysconfig->shutdownRequestButtonPressed(); +} + +void +VMManagerMain::shutdownForceButtonPressed() const +{ + if (!currentSelectionIsValid()) { + return; + } + selected_sysconfig->shutdownForceButtonPressed(); +} + +// This function doesn't appear to be needed any longer +void +VMManagerMain::refresh() +{ + const auto current_index = ui->listView->currentIndex(); + emit selectionChanged(current_index, selected_sysconfig->process->state()); + + // if(!selected_sysconfig->config_file.path().isEmpty()) { + if(!selected_sysconfig->isValid()) { + // what was happening here? + } +} + +void +VMManagerMain::updateDisplayName(const QModelIndex &index) +{ + QDialog dialog; + dialog.setMinimumWidth(400); + dialog.setWindowTitle(tr("Set display name")); + const auto layout = new QVBoxLayout(&dialog); + const auto label = new QLabel(tr("Enter the new display name (blank to reset)")); + label->setAlignment(Qt::AlignHCenter); + label->setContentsMargins(QMargins(0, 0, 0, 5)); + layout->addWidget(label); + const auto lineEdit = new QLineEdit(index.data().toString(), &dialog); + layout->addWidget(lineEdit); + lineEdit->selectAll(); + + const auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &dialog); + layout->addWidget(buttonBox); + + connect(buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept); + connect(buttonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject); + + if (const bool accepted = dialog.exec() == QDialog::Accepted; accepted) { + const auto mapped_index = proxy_model->mapToSource(index); + vm_model->updateDisplayName(mapped_index, lineEdit->text()); + selected_sysconfig = vm_model->getConfigObjectForIndex(mapped_index); + vm_details->updateData(selected_sysconfig); + ui->listView->scrollTo(ui->listView->currentIndex(), QAbstractItemView::PositionAtCenter); + } +} + +void +VMManagerMain::loadSettings() +{ + const auto config = new VMManagerConfig(VMManagerConfig::ConfigType::General); + const auto lastSelection = config->getStringValue("last_selection"); + updateCheck = config->getStringValue("update_check").toInt(); + regexSearch = config->getStringValue("regex_search").toInt(); + + const auto matches = ui->listView->model()->match(vm_model->index(0, 0), VMManagerModel::Roles::ConfigName, QVariant::fromValue(lastSelection)); + if (!matches.empty()) { + ui->listView->setCurrentIndex(matches.first()); + ui->listView->scrollTo(ui->listView->currentIndex(), QAbstractItemView::PositionAtCenter); + } +} +bool +VMManagerMain::currentSelectionIsValid() const +{ + return ui->listView->currentIndex().isValid() && selected_sysconfig->isValid(); +} + +// Used from MainWindow during app exit to obtain and persist the current selection +QString +VMManagerMain::getCurrentSelection() const +{ + return ui->listView->currentIndex().data(VMManagerModel::Roles::ConfigName).toString(); +} + +void +VMManagerMain::searchSystems(const QString &text) const +{ + // Escape the search text string unless regular expression searching is enabled. + // When escaped, the search string functions as a plain text match. + const auto searchText = regexSearch ? text : QRegularExpression::escape(text); + const QRegularExpression regex(searchText, QRegularExpression::CaseInsensitiveOption); + if (!regex.isValid()) { + qDebug() << "Skipping, invalid regex"; + return; + } + proxy_model->setFilterRegularExpression(regex); + // Searching (filtering) can cause the list view to change. If there is still a valid selection, + // make sure to scroll to it + if (ui->listView->currentIndex().isValid()) { + ui->listView->scrollTo(ui->listView->currentIndex(), QAbstractItemView::PositionAtCenter); + } +} + +void +VMManagerMain::newMachineWizard() +{ + const auto wizard = new VMManagerAddMachine(this); + if (wizard->exec() == QDialog::Accepted) { + const auto newName = wizard->field("systemName").toString(); + const auto systemDir = wizard->field("systemLocation").toString(); + const auto existingConfiguration = wizard->field("existingConfiguration").toString(); + addNewSystem(newName, systemDir, existingConfiguration); + } +} + +void +VMManagerMain::addNewSystem(const QString &name, const QString &dir, const QString &configFile) +{ + const auto newSytemDirectory = QDir(QDir::cleanPath(dir + "/" + name)); + + // qt replaces `/` with native separators + const auto newSystemConfigFile = QFileInfo(newSytemDirectory.path() + "/" + "86box.cfg"); + if (newSystemConfigFile.exists() || newSytemDirectory.exists()) { + QMessageBox::critical(this, tr("Directory in use"), tr("The selected directory is already in use. Please select a different directory.")); + return; + } + // Create the directory + const QDir qmkdir; + if (const bool mkdirResult = qmkdir.mkdir(newSytemDirectory.path()); !mkdirResult) { + QMessageBox::critical(this, tr("Create directory failed"), tr("Unable to create the directory for the new system")); + return; + } + // If specified, write the contents of the configuration file before starting + if (!configFile.isEmpty()) { + const auto configPath = newSystemConfigFile.absoluteFilePath(); + const auto file = new QFile(configPath); + if (!file->open(QIODevice::WriteOnly)) { + qWarning() << "Unable to open file " << configPath; + QMessageBox::critical(this, tr("Configuration write failed"), tr("Unable to open the configuration file at %1 for writing").arg(configPath)); + return; + } + file->write(configFile.toUtf8()); + file->flush(); + file->close(); + } + + const auto new_system = new VMManagerSystem(newSystemConfigFile.absoluteFilePath()); + new_system->launchSettings(); + // Handle this in a closure so we can capture the temporary new_system object + connect(new_system->process, QOverload::of(&QProcess::finished), + [=](const int exitCode, const QProcess::ExitStatus exitStatus) { + if (exitCode != 0 || exitStatus != QProcess::NormalExit) { + qInfo().nospace().noquote() << "Abnormal program termination while creating new system: exit code " << exitCode << ", exit status " << exitStatus; + qInfo() << "Not adding system due to errors"; + QMessageBox::critical(this, tr("Error adding system"), + tr("Abnormal program termination while creating new system: exit code %1, exit status %2.\n\nThe system will not be added.").arg(QString::number(exitCode), exitStatus)); + delete new_system; + return; + } + // Create a new QFileInfo because the info from the old one may be cached + if (const auto fi = QFileInfo(new_system->config_file.absoluteFilePath()); !fi.exists()) { + // No config file which means the cancel button was pressed in the settings dialog + // Attempt to clean up the directory that was created + const QDir qrmdir; + if (const bool result = qrmdir.rmdir(newSytemDirectory.path()); !result) { + qWarning() << "Error cleaning up the old directory for canceled operation. Continuing anyway."; + } + delete new_system; + return; + } + const auto current_index = ui->listView->currentIndex(); + vm_model->reload(this); + const auto created_object = vm_model->getIndexForConfigFile(new_system->config_file); + if (created_object.row() < 0) { + // For some reason the index of the new object couldn't be determined. Fall back to the old index. + ui->listView->setCurrentIndex(current_index); + delete new_system; + return; + } + // Get the index of the newly-created system and select it + const QModelIndex mapped_index = proxy_model->mapFromSource(created_object); + ui->listView->setCurrentIndex(mapped_index); + delete new_system; + }); +} + +QStringList +VMManagerMain::getSearchCompletionList() const +{ + QSet uniqueStrings; + for (int row = 0; row < vm_model->rowCount(QModelIndex()); ++row) { + QModelIndex index = vm_model->index(row, 0); + auto fullList = vm_model->data(index, VMManagerModel::Roles::SearchList).toStringList(); + QSet uniqueSet(fullList.begin(), fullList.end()); + uniqueStrings.unite(uniqueSet); + } + // Convert the set back to a QStringList + QStringList allStrings = uniqueStrings.values(); + return allStrings; +} + +QString +VMManagerMain::totalCountString() const +{ + const auto count = vm_model->rowCount(QModelIndex()); + return QString("%1 %2").arg(QString::number(count), tr("total")); +} + +void +VMManagerMain::modelDataChange() +{ + // Model data has changed. This includes process status. + // Update the counts / totals accordingly + auto modelStats = vm_model->getProcessStats(); + QStringList stats; + for (auto it = modelStats.constBegin(); it != modelStats.constEnd(); ++it) { + const auto &key = it.key(); + stats.append(QString("%1 %2").arg(QString::number(modelStats[key]), key)); + } + auto states = stats.join(", "); + if (!modelStats.isEmpty()) { + states.append(", "); + } + + emit updateStatusRight(states + totalCountString()); +} + +void +VMManagerMain::onPreferencesUpdated() +{ + // Only reload values that we care about + const auto config = new VMManagerConfig(VMManagerConfig::ConfigType::General); + const auto oldRegexSearch = regexSearch; + regexSearch = config->getStringValue("regex_search").toInt(); + if (oldRegexSearch != regexSearch) { + ui->searchBar->clear(); + } +} + +void +VMManagerMain::backgroundUpdateCheckStart() const +{ + auto updateChannel = UpdateCheck::UpdateChannel::CI; +#ifdef RELEASE_BUILD + updateChannel = UpdateCheck::UpdateChannel::Stable; +#endif + const auto updateCheck = new UpdateCheck(updateChannel); + connect(updateCheck, &UpdateCheck::updateCheckComplete, this, &VMManagerMain::backgroundUpdateCheckComplete); + connect(updateCheck, &UpdateCheck::updateCheckError, this, &VMManagerMain::backgroundUpdateCheckError); + updateCheck->checkForUpdates(); +} + +void +VMManagerMain::backgroundUpdateCheckComplete(const UpdateCheck::UpdateResult &result) +{ + qDebug() << "Check complete: update available?" << result.updateAvailable; + auto type = result.channel == UpdateCheck::UpdateChannel::CI ? tr("Build") : tr("Version"); + const auto updateMessage = QString("%1: %2 %3").arg( tr("An update to 86Box is available"), type, result.latestVersion); + emit updateStatusLeft(updateMessage); +} + +void +VMManagerMain::backgroundUpdateCheckError(const QString &errorMsg) +{ + qDebug() << "Update check failed with the following error:" << errorMsg; + // TODO: Update the status bar +} + +void +VMManagerMain::showTextFileContents(const QString &title, const QString &path) +{ + // Make sure we can open the file + const auto fi = QFileInfo(path); + if(!fi.exists()) { + qWarning("Requested file does not exist: %s", path.toUtf8().constData()); + return; + } + // Read the file + QFile displayFile(path); + if (!displayFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + qWarning("Couldn't open the file: error %d", displayFile.error()); + return; + } + const QString configFileContents = displayFile.readAll(); + displayFile.close(); + + const auto textDisplayDialog = new QDialog(this); + textDisplayDialog->setFixedSize(QSize(540, 360)); + textDisplayDialog->setWindowTitle(QString("%1 - %2").arg(title, fi.fileName())); + + const auto textEdit = new QPlainTextEdit(); + textEdit->setReadOnly(true); + textEdit->setPlainText(configFileContents); + const auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok); + connect(buttonBox, &QDialogButtonBox::accepted, textDisplayDialog, &QDialog::accept); + const auto layout = new QVBoxLayout(); + textDisplayDialog->setLayout(layout); + textDisplayDialog->layout()->addWidget(textEdit); + textDisplayDialog->layout()->addWidget(buttonBox); + textDisplayDialog->exec(); +} diff --git a/src/qt/qt_vmmanager_main.hpp b/src/qt/qt_vmmanager_main.hpp new file mode 100644 index 000000000..c3c541b4f --- /dev/null +++ b/src/qt/qt_vmmanager_main.hpp @@ -0,0 +1,167 @@ +/* +* 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. +* +* Header for 86Box VM manager main module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#ifndef QT_VMMANAGER_MAIN_H +#define QT_VMMANAGER_MAIN_H + +#include "qt_updatecheck.hpp" + +#include +#include "qt_vmmanager_model.hpp" +#include "qt_vmmanager_details.hpp" +#include "qt_vmmanager_listviewdelegate.hpp" + +#include + +extern "C" { +#include <86box/86box.h> // for vmm_path +} + + +QT_BEGIN_NAMESPACE +namespace Ui { class VMManagerMain; } +QT_END_NAMESPACE + +class VMManagerMain final : public QWidget { + Q_OBJECT + +public: + explicit VMManagerMain(QWidget *parent = nullptr); + ~VMManagerMain() override; + // Used to save the current selection + [[nodiscard]] QString getCurrentSelection() const; + + enum class ToolbarButton { + Start, + Pause, + StartPause, + Shutdown, + Reset, + CtrlAltDel, + Settings, + }; +signals: + void selectionChanged(const QModelIndex ¤tSelection, QProcess::ProcessState processState); + void updateStatusLeft(const QString &text); + void updateStatusRight(const QString &text); + +public slots: + void startButtonPressed() const; + void settingsButtonPressed(); + void restartButtonPressed() const; + void pauseButtonPressed() const; + void shutdownRequestButtonPressed() const; + void shutdownForceButtonPressed() const; + void searchSystems(const QString &text) const; + void newMachineWizard(); + void addNewSystem(const QString &name, const QString &dir, const QString &configFile = {}); + [[nodiscard]] QStringList getSearchCompletionList() const; + void modelDataChange(); + void onPreferencesUpdated(); + +private: + Ui::VMManagerMain *ui; + + VMManagerModel *vm_model; + VMManagerDetails *vm_details; + VMManagerSystem *selected_sysconfig; + // VMManagerConfig *config; + QSortFilterProxyModel *proxy_model; + bool updateCheck = false; + bool regexSearch = false; + + // void updateSelection(const QItemSelection &selected, + // const QItemSelection &deselected); + void currentSelectionChanged(const QModelIndex ¤t, + const QModelIndex &previous); + void refresh(); + void updateDisplayName(const QModelIndex &index); + void loadSettings(); + [[nodiscard]] bool currentSelectionIsValid() const; + [[nodiscard]] QString totalCountString() const; + void backgroundUpdateCheckStart() const; + void showTextFileContents(const QString &title, const QString &path); +private slots: + void backgroundUpdateCheckComplete(const UpdateCheck::UpdateResult &result); + void backgroundUpdateCheckError(const QString &errorMsg); +}; + +#include +#include +#include +#include + +class IconSelectionDialog final : public QDialog { + Q_OBJECT + +public: + explicit IconSelectionDialog(QString assetPath, QWidget *parent = nullptr) : QDialog(parent), listWidget(new QListWidget) { + // Set the list widget to icon mode + listWidget->setViewMode(QListWidget::IconMode); + setFixedSize(QSize(540, 360)); + listWidget->setGridSize(QSize(96, 96)); + listWidget->setIconSize(QSize(64, 64)); + // Read in all the assets from the given path + const QDir iconsDir(assetPath); + if (!assetPath.endsWith("/")) { + assetPath.append("/"); + } + setWindowTitle(tr("Select an icon")); + + // Loop on all files and add them as items (icons) in QListWidget + for(const QString& iconName : iconsDir.entryList()) { + const auto item = new QListWidgetItem(QIcon(assetPath + iconName), iconName); + // Set the UserRole to the resource bundle path + item->setData(Qt::UserRole, assetPath + iconName); + listWidget->addItem(item); + } + + // Dialog buttons + const auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Reset); + // Use the reset button for resetting the icon to the default + const QPushButton* resetButton = buttonBox->button(QDialogButtonBox::Reset); + + // Connect the buttons signals + connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); + connect(listWidget, &QListWidget::doubleClicked, this, &QDialog::accept); + connect(resetButton, &QPushButton::clicked, [this] { + // For reset, set the index to invalid so the caller will receive a blank string + listWidget->setCurrentIndex(QModelIndex()); + // Then accept + QDialog::accept(); + }); + + const auto layout = new QVBoxLayout(this); + layout->addWidget(listWidget); + layout->addWidget(buttonBox); + } + + public slots: + [[nodiscard]] QString getSelectedIconName() const { + if (listWidget->currentIndex().isValid()) { + return listWidget->currentItem()->data(Qt::UserRole).toString(); + } + // Index is invalid because the reset button was pressed + return {}; + } + +private: + QListWidget* listWidget; +}; + +#endif //QT_VMMANAGER_MAIN_H diff --git a/src/qt/qt_vmmanager_main.ui b/src/qt/qt_vmmanager_main.ui new file mode 100644 index 000000000..c19094345 --- /dev/null +++ b/src/qt/qt_vmmanager_main.ui @@ -0,0 +1,119 @@ + + + VMManagerMain + + + + 0 + 0 + 815 + 472 + + + + + 0 + 0 + + + + VMManagerMain + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 200 + 0 + + + + + 200 + 16777215 + + + + + + + + Qt::ClickFocus + + + Search + + + true + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + diff --git a/src/qt/qt_vmmanager_mainwindow.cpp b/src/qt/qt_vmmanager_mainwindow.cpp new file mode 100644 index 000000000..767bbcef2 --- /dev/null +++ b/src/qt/qt_vmmanager_mainwindow.cpp @@ -0,0 +1,178 @@ +/* +* 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. +* +* 86Box VM manager main window +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#include "qt_vmmanager_mainwindow.hpp" +#include "qt_vmmanager_main.hpp" +#include "qt_vmmanager_preferences.hpp" +#include "ui_qt_vmmanager_mainwindow.h" +#include "qt_updatecheckdialog.hpp" + +#include +#include +#include + +VMManagerMainWindow:: +VMManagerMainWindow(QWidget *parent) + : ui(new Ui::VMManagerMainWindow) + , vmm(new VMManagerMain(this)) + , statusLeft(new QLabel) + , statusRight(new QLabel) +{ + ui->setupUi(this); + + // Connect signals from the VMManagerMain widget + connect(vmm, &VMManagerMain::selectionChanged, this, &VMManagerMainWindow::vmmSelectionChanged); + + setWindowTitle(tr("86Box VM Manager")); + setCentralWidget(vmm); + + // Set up the buttons + connect(ui->actionStartPause, &QAction::triggered, vmm, &VMManagerMain::startButtonPressed); + connect(ui->actionSettings, &QAction::triggered, vmm, &VMManagerMain::settingsButtonPressed); + connect(ui->actionHard_Reset, &QAction::triggered, vmm, &VMManagerMain::restartButtonPressed); + connect(ui->actionForce_Shutdown, &QAction::triggered, vmm, &VMManagerMain::shutdownForceButtonPressed); + connect(ui->actionNew_Machine, &QAction::triggered, vmm, &VMManagerMain::newMachineWizard); + + // Set up menu actions + connect(ui->actionCheck_for_updates, &QAction::triggered, this, &VMManagerMainWindow::checkForUpdatesTriggered); + + // TODO: Remove all of this (all the way to END REMOVE) once certain the search will no longer be in the toolbar. + // BEGIN REMOVE + // Everything is still setup here for it but it is all hidden. None of it will be + // needed if the search stays in VMManagerMain + ui->actionStartPause->setEnabled(true); + ui->actionStartPause->setIcon(QIcon(":/menuicons/qt/icons/run.ico")); + ui->actionStartPause->setText(tr("Start")); + ui->actionStartPause->setToolTip(tr("Start")); + ui->actionHard_Reset->setEnabled(false); + ui->actionForce_Shutdown->setEnabled(false); + ui->actionCtrl_Alt_Del->setEnabled(false); + + const auto searchBar = new QLineEdit(); + searchBar->setMinimumWidth(150); + searchBar->setPlaceholderText(" " + tr("Search")); + searchBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); + searchBar->setClearButtonEnabled(true); + // Spacer to make the search go all the way to the right + const auto spacer = new QWidget(); + spacer->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); + ui->toolBar->addWidget(spacer); + ui->toolBar->addWidget(searchBar); + // Connect signal for search + connect(searchBar, &QLineEdit::textChanged, vmm, &VMManagerMain::searchSystems); + // Preferences + connect(ui->actionPreferences, &QAction::triggered, this, &VMManagerMainWindow::preferencesTriggered); + + // Create a completer for the search bar + auto *completer = new QCompleter(this); + completer->setCaseSensitivity(Qt::CaseInsensitive); + completer->setFilterMode(Qt::MatchContains); + // Get the completer list + const auto allStrings = vmm->getSearchCompletionList(); + // Set up the completer + auto *completerModel = new QStringListModel(allStrings, completer); + completer->setModel(completerModel); + searchBar->setCompleter(completer); + ui->toolBar->setVisible(false); + // END REMOVE + + // Status bar widgets + statusLeft->setAlignment(Qt::AlignLeft); + statusRight->setAlignment(Qt::AlignRight); + ui->statusbar->addPermanentWidget(statusLeft, 1); + ui->statusbar->addPermanentWidget(statusRight, 1); + connect(vmm, &VMManagerMain::updateStatusLeft, this, &VMManagerMainWindow::setStatusLeft); + connect(vmm, &VMManagerMain::updateStatusRight, this, &VMManagerMainWindow::setStatusRight); + + // Inform the main view when preferences are updated + connect(this, &VMManagerMainWindow::preferencesUpdated, vmm, &VMManagerMain::onPreferencesUpdated); + +} + +VMManagerMainWindow::~ +VMManagerMainWindow() + = default; + +void +VMManagerMainWindow::vmmSelectionChanged(const QModelIndex ¤tSelection, const QProcess::ProcessState processState) const +{ + if (processState == QProcess::Running) { + ui->actionStartPause->setEnabled(true); + ui->actionStartPause->setIcon(QIcon(":/menuicons/qt/icons/pause.ico")); + ui->actionStartPause->setText(tr("Pause")); + ui->actionStartPause->setToolTip(tr("Pause")); + ui->actionHard_Reset->setEnabled(true); + ui->actionForce_Shutdown->setEnabled(true); + ui->actionCtrl_Alt_Del->setEnabled(true); + } else { + ui->actionStartPause->setEnabled(true); + ui->actionStartPause->setIcon(QIcon(":/menuicons/qt/icons/run.ico")); + ui->actionStartPause->setText(tr("Start")); + ui->actionStartPause->setToolTip(tr("Start")); + ui->actionHard_Reset->setEnabled(false); + ui->actionForce_Shutdown->setEnabled(false); + ui->actionCtrl_Alt_Del->setEnabled(false); + } +} +void +VMManagerMainWindow::preferencesTriggered() +{ + const auto prefs = new VMManagerPreferences(); + if (prefs->exec() == QDialog::Accepted) { + emit preferencesUpdated(); + } +} + +void +VMManagerMainWindow::saveSettings() const +{ + const auto currentSelection = vmm->getCurrentSelection(); + const auto config = new VMManagerConfig(VMManagerConfig::ConfigType::General); + config->setStringValue("last_selection", currentSelection); + // Sometimes required to ensure the settings save before the app exits + config->sync(); +} + +void +VMManagerMainWindow::closeEvent(QCloseEvent *event) +{ + saveSettings(); + QMainWindow::closeEvent(event); +} + +void +VMManagerMainWindow::setStatusLeft(const QString &text) const +{ + statusLeft->setText(text); +} + +void +VMManagerMainWindow::setStatusRight(const QString &text) const +{ + statusRight->setText(text); +} + +void +VMManagerMainWindow::checkForUpdatesTriggered() +{ + auto updateChannel = UpdateCheck::UpdateChannel::CI; +#ifdef RELEASE_BUILD + updateChannel = UpdateCheck::UpdateChannel::Stable; +#endif + const auto updateCheck = new UpdateCheckDialog(updateChannel); + updateCheck->exec(); +} diff --git a/src/qt/qt_vmmanager_mainwindow.hpp b/src/qt/qt_vmmanager_mainwindow.hpp new file mode 100644 index 000000000..764ed5ef8 --- /dev/null +++ b/src/qt/qt_vmmanager_mainwindow.hpp @@ -0,0 +1,59 @@ +/* +* 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. +* +* Header for 86Box VM manager main window +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#ifndef VMM_MAINWINDOW_H +#define VMM_MAINWINDOW_H + +#include "qt_vmmanager_main.hpp" + +#include +#include +#include + +namespace Ui { +class VMManagerMainWindow; +} + +class VMManagerMainWindow final : public QMainWindow +{ + Q_OBJECT +public: + explicit VMManagerMainWindow(QWidget *parent = nullptr); + ~VMManagerMainWindow() override; +signals: + void preferencesUpdated(); + +private: + Ui::VMManagerMainWindow *ui; + VMManagerMain *vmm; + void saveSettings() const; + QLabel *statusLeft; + QLabel *statusRight; +public slots: + void setStatusLeft(const QString &text) const; + void setStatusRight(const QString &text) const; + +private slots: + void vmmSelectionChanged(const QModelIndex ¤tSelection, QProcess::ProcessState processState) const; + void preferencesTriggered(); + static void checkForUpdatesTriggered(); + +protected: + void closeEvent(QCloseEvent *event) override; +}; + +#endif // VMM_MAINWINDOW_H diff --git a/src/qt/qt_vmmanager_mainwindow.ui b/src/qt/qt_vmmanager_mainwindow.ui new file mode 100644 index 000000000..e3e0a242d --- /dev/null +++ b/src/qt/qt_vmmanager_mainwindow.ui @@ -0,0 +1,212 @@ + + + VMManagerMainWindow + + + + 0 + 0 + 900 + 600 + + + + MainWindow + + + + + + 0 + 0 + 900 + 21 + + + + + Tools + + + + + + + File + + + + + + + + + + toolBar + + + false + + + + 16 + 16 + + + + Qt::ToolButtonStyle::ToolButtonIconOnly + + + TopToolBarArea + + + false + + + + + + + + + + + Do something + + + + + true + + + + :/menuicons/qt/icons/run.ico:/menuicons/qt/icons/run.ico + + + Start + + + false + + + + + + :/menuicons/qt/icons/hard_reset.ico:/menuicons/qt/icons/hard_reset.ico + + + &Hard Reset... + + + false + + + + + true + + + + :/menuicons/qt/icons/acpi_shutdown.ico:/menuicons/qt/icons/acpi_shutdown.ico + + + Force shutdown + + + Force shutdown + + + true + + + false + + + + + false + + + + :/menuicons/qt/icons/send_cad.ico:/menuicons/qt/icons/send_cad.ico + + + &Ctrl+Alt+Del + + + Ctrl+Alt+Del + + + false + + + false + + + false + + + + + + :/menuicons/qt/icons/settings.ico:/menuicons/qt/icons/settings.ico + + + &Settings... + + + QAction::MenuRole::NoRole + + + false + + + + + + :/settings/qt/icons/86Box-yellow.ico:/settings/qt/icons/86Box-yellow.ico + + + New Machine + + + New Machine + + + + + Preferences + + + Preferences + + + QAction::MenuRole::PreferencesRole + + + + + true + + + + :/menuicons/qt/icons/run.ico:/menuicons/qt/icons/run.ico + + + Start + + + false + + + + + Check for updates + + + + + + + + diff --git a/src/qt/qt_vmmanager_model.cpp b/src/qt/qt_vmmanager_model.cpp new file mode 100644 index 000000000..848970f80 --- /dev/null +++ b/src/qt/qt_vmmanager_model.cpp @@ -0,0 +1,163 @@ +/* +* 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. +* +* 86Box VM manager model module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed + */ + +#include +#include "qt_vmmanager_model.hpp" + +VMManagerModel::VMManagerModel() { + auto machines_vec = VMManagerSystem::scanForConfigs(); + for ( const auto& each_config : machines_vec) { + machines.append(each_config); + connect(each_config, &VMManagerSystem::itemDataChanged, this, &VMManagerModel::modelDataChanged); + } +} + +VMManagerModel::~VMManagerModel() { + for ( auto machine : machines) { + delete machine; + } +} + +int +VMManagerModel::rowCount(const QModelIndex &parent) const { + return machines.size(); +} + +QVariant +VMManagerModel::data(const QModelIndex &index, int role) const { + if (!index.isValid()) + return {}; + + if (index.row() >= machines.size()) + return {}; + + switch (role) { + case Qt::DisplayRole: + return machines.at(index.row())->displayName; + case ConfigName: + return machines.at(index.row())->config_name; + case ConfigDir: + return machines.at(index.row())->config_dir; + case ConfigFile: + return machines.at(index.row())->config_file.canonicalFilePath(); + case UUID: + return machines.at(index.row())->uuid; + case Notes: + return machines.at(index.row())->notes; + case SearchList: + return machines.at(index.row())->searchTerms; + case LastUsed: + return machines.at(index.row())->timestamp(); + case Icon: + return machines.at(index.row())->icon; + case Qt::ToolTipRole: + return machines.at(index.row())->shortened_dir; + case Qt::UserRole: + return machines.at(index.row())->getAll("General"); + case ProcessStatusString: + return machines.at(index.row())->getProcessStatusString(); + case ProcessStatus: + return QVariant::fromValue(machines.at(index.row())->getProcessStatus()); + default: + return {}; + } +} + +QVariant +VMManagerModel::headerData(int section, Qt::Orientation orientation, int role) const { + + if (role != Qt::DisplayRole) + return {}; + + if (orientation == Qt::Horizontal) + return QStringLiteral("Column %1").arg(section); + else + return QStringLiteral("Row %1").arg(section); +} + +VMManagerSystem * +VMManagerModel::getConfigObjectForIndex(const QModelIndex &index) const +{ + return machines.at(index.row()); +} +void +VMManagerModel::reload(QWidget* parent) +{ + // Scan for configs + auto machines_vec = VMManagerSystem::scanForConfigs(parent); + for (const auto &scanned_config : machines_vec) { + int found = 0; + for (const auto &existing_config : machines) { + if (*scanned_config == *existing_config) { + found = 1; + } + } + if (!found) { + addConfigToModel(scanned_config); + } + } + // TODO: Remove missing configs +} + +QModelIndex +VMManagerModel::getIndexForConfigFile(const QFileInfo& config_file) +{ + int object_index = 0; + for (const auto& config_object: machines) { + if (config_object->config_file == config_file) { + return this->index(object_index); + } + object_index++; + } + return {}; +} + +void +VMManagerModel::addConfigToModel(VMManagerSystem *system_config) +{ + beginInsertRows(QModelIndex(), this->rowCount(QModelIndex()), this->rowCount(QModelIndex())); + machines.append(system_config); + connect(system_config, &VMManagerSystem::itemDataChanged, this, &VMManagerModel::modelDataChanged); + endInsertRows(); +} +void +VMManagerModel::modelDataChanged() +{ + // Inform the model + emit dataChanged(this->index(0), this->index(machines.size()-1)); + // Inform any interested observers + emit systemDataChanged(); +} + +void +VMManagerModel::updateDisplayName(const QModelIndex &index, const QString &newDisplayName) +{ + machines.at(index.row())->setDisplayName(newDisplayName); + modelDataChanged(); +} +QHash +VMManagerModel::getProcessStats() +{ + QHash stats; + for (const auto& system: machines) { + if (system->getProcessStatus() != VMManagerSystem::ProcessStatus::Stopped) { + auto statusString = system->getProcessStatusString(); + stats[statusString] += 1; + } + } + return stats; +} \ No newline at end of file diff --git a/src/qt/qt_vmmanager_model.hpp b/src/qt/qt_vmmanager_model.hpp new file mode 100644 index 000000000..bc13cc16f --- /dev/null +++ b/src/qt/qt_vmmanager_model.hpp @@ -0,0 +1,91 @@ +/* +* 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. +* +* Header for 86Box VM manager model module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed + */ + +#ifndef QT_VMMANAGER_MODEL_H +#define QT_VMMANAGER_MODEL_H + + +#include "qt_vmmanager_system.hpp" + +#include + +class VMManagerModel final : public QAbstractListModel { + + Q_OBJECT + +public: + // VMManagerModel(const QStringList &strings, QObject *parent = nullptr) + // : QAbstractListModel(parent), machines(strings) {} + VMManagerModel(); + ~VMManagerModel() override; + enum Roles { + ProcessStatusString = Qt::UserRole + 1, + ProcessStatus, + DisplayName, + ConfigName, + ConfigDir, + ConfigFile, + LastUsed, + UUID, + Notes, + SearchList, + Icon + }; + + [[nodiscard]] int rowCount(const QModelIndex &parent) const override; + [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override; + [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, + int role) const override; + void addConfigToModel(VMManagerSystem *system_config); + + [[nodiscard]] VMManagerSystem * getConfigObjectForIndex(const QModelIndex &index) const; + QModelIndex getIndexForConfigFile(const QFileInfo& config_file); + void reload(QWidget* parent = nullptr); + void updateDisplayName(const QModelIndex &index, const QString &newDisplayName); + QHash getProcessStats(); +signals: + void systemDataChanged(); + +private: + QVector machines; + void modelDataChanged(); + +}; + +// Note: Custom QSortFilterProxyModel is included here instead of its own file as +// its only use is in this model + +class StringListProxyModel final : public QSortFilterProxyModel { +public: + explicit StringListProxyModel(QObject *parent = nullptr) : QSortFilterProxyModel(parent) {} + +protected: + [[nodiscard]] bool filterAcceptsRow(const int sourceRow, const QModelIndex &sourceParent) const override { + const QModelIndex index = sourceModel()->index(sourceRow, filterKeyColumn(), sourceParent); + + QStringList stringList = sourceModel()->data(index, VMManagerModel::Roles::SearchList).toStringList(); + + const QRegularExpression regex = filterRegularExpression(); + + const auto result = std::any_of(stringList.begin(), stringList.end(), [®ex](const QString &string) { + return regex.match(string).hasMatch(); + }); + return result; + } +}; + +#endif //QT_VMMANAGER_MODEL_H diff --git a/src/qt/qt_vmmanager_preferences.cpp b/src/qt/qt_vmmanager_preferences.cpp new file mode 100644 index 000000000..0730f875b --- /dev/null +++ b/src/qt/qt_vmmanager_preferences.cpp @@ -0,0 +1,82 @@ +/* +* 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. +* +* 86Box VM manager preferences module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#include +#include + +#include "qt_vmmanager_preferences.hpp" +#include "qt_vmmanager_config.hpp" +#include "ui_qt_vmmanager_preferences.h" + +extern "C" { +#include <86box/86box.h> +} + +VMManagerPreferences:: +VMManagerPreferences(QWidget *parent) : ui(new Ui::VMManagerPreferences) +{ + ui->setupUi(this); + ui->dirSelectButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_DirIcon)); + connect(ui->dirSelectButton, &QPushButton::clicked, this, &VMManagerPreferences::chooseDirectoryLocation); + + const auto config = new VMManagerConfig(VMManagerConfig::ConfigType::General); + const auto configSystemDir = config->getStringValue("system_directory"); + if(!configSystemDir.isEmpty()) { + // Prefer this one + ui->systemDirectory->setText(configSystemDir); + } else if(!QString(vmm_path).isEmpty()) { + // If specified on command line + ui->systemDirectory->setText(QDir(vmm_path).path()); + } + + // TODO: Defaults + const auto configUpdateCheck = config->getStringValue("update_check").toInt(); + ui->updateCheckBox->setChecked(configUpdateCheck); + const auto useRegexSearch = config->getStringValue("regex_search").toInt(); + ui->regexSearchCheckBox->setChecked(useRegexSearch); + + +} + +VMManagerPreferences::~ +VMManagerPreferences() + = default; + +// Bad copy pasta from machine add +void +VMManagerPreferences::chooseDirectoryLocation() +{ + // TODO: FIXME: This is pulling in the CLI directory! Needs to be set properly elsewhere + const auto directory = QFileDialog::getExistingDirectory(this, "Choose directory", QDir(vmm_path).path()); + ui->systemDirectory->setText(QDir::toNativeSeparators(directory)); +} + +void +VMManagerPreferences::accept() +{ + const auto config = new VMManagerConfig(VMManagerConfig::ConfigType::General); + config->setStringValue("system_directory", ui->systemDirectory->text()); + config->setStringValue("update_check", ui->updateCheckBox->isChecked() ? "1" : "0"); + config->setStringValue("regex_search", ui->regexSearchCheckBox->isChecked() ? "1" : "0"); + QDialog::accept(); +} + +void +VMManagerPreferences::reject() +{ + QDialog::reject(); +} \ No newline at end of file diff --git a/src/qt/qt_vmmanager_preferences.hpp b/src/qt/qt_vmmanager_preferences.hpp new file mode 100644 index 000000000..aedba862a --- /dev/null +++ b/src/qt/qt_vmmanager_preferences.hpp @@ -0,0 +1,46 @@ +/* +* 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. +* +* Header for 86Box VM manager preferences module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#ifndef VMMANAGER_PREFERENCES_H +#define VMMANAGER_PREFERENCES_H + +#include + +QT_BEGIN_NAMESPACE +namespace Ui { class VMManagerPreferences; } +QT_END_NAMESPACE + + +class VMManagerPreferences final : public QDialog +{ + Q_OBJECT +public: + explicit VMManagerPreferences(QWidget *parent = nullptr); + ~VMManagerPreferences() override; + +private: + Ui::VMManagerPreferences *ui; + QString settingsFile; +private slots: + void chooseDirectoryLocation(); +protected: + void accept() override; + void reject() override; + +}; + +#endif // VMMANAGER_PREFERENCES_H diff --git a/src/qt/qt_vmmanager_preferences.ui b/src/qt/qt_vmmanager_preferences.ui new file mode 100644 index 000000000..1743a0bfb --- /dev/null +++ b/src/qt/qt_vmmanager_preferences.ui @@ -0,0 +1,130 @@ + + + VMManagerPreferences + + + + 0 + 0 + 400 + 300 + + + + Preferences + + + + + + System Directory: + + + + + + + + 0 + + + 0 + + + + + + + + + + + + + 0 + 0 + + + + + + + + + + + + + + Check for updates on startup + + + + + + + Use regular expressions in search box + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + VMManagerPreferences + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + VMManagerPreferences + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/qt/qt_vmmanager_protocol.cpp b/src/qt/qt_vmmanager_protocol.cpp new file mode 100644 index 000000000..26f8a1f93 --- /dev/null +++ b/src/qt/qt_vmmanager_protocol.cpp @@ -0,0 +1,131 @@ +/* +* 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. +* +* 86Box VM manager protocol module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed + */ + +#include "qt_vmmanager_protocol.hpp" +#include +#include +VMManagerProtocol::VMManagerProtocol(VMManagerProtocol::Sender sender) +{ + message_class = sender; +} + +VMManagerProtocol::~VMManagerProtocol() += default; + +QJsonObject +VMManagerProtocol::protocolManagerMessage(VMManagerProtocol::ManagerMessage message_type) +{ + auto json_message = constructDefaultObject(VMManagerProtocol::Sender::Manager); + json_message["message"] = managerMessageTypeToString(message_type); + return json_message; +} + +QJsonObject +VMManagerProtocol::protocolClientMessage(VMManagerProtocol::ClientMessage message_type) +{ + auto json_message = constructDefaultObject(VMManagerProtocol::Sender::Client); + json_message["message"] = clientMessageTypeToString(message_type); + return json_message; +} + +QString +VMManagerProtocol::managerMessageTypeToString(VMManagerProtocol::ManagerMessage message) +{ + QMetaEnum qme = QMetaEnum::fromType(); + return qme.valueToKey(static_cast(message)); +} + +QString +VMManagerProtocol::clientMessageTypeToString(VMManagerProtocol::ClientMessage message) +{ + QMetaEnum qme = QMetaEnum::fromType(); + return qme.valueToKey(static_cast(message)); +} + +QJsonObject +VMManagerProtocol::constructDefaultObject(VMManagerProtocol::Sender type) +{ + QJsonObject json_message; + QString sender_type = ( type == VMManagerProtocol::Sender::Client ) ? "Client" : "VMManager"; + json_message["type"] = QString(sender_type); + json_message["version"] = QStringLiteral(EMU_VERSION); + return json_message; +} +bool +VMManagerProtocol::hasRequiredFields(const QJsonObject& json_document) +{ + for (const auto& field : ProtocolRequiredFields) { + if (!json_document.contains(field)) { + qDebug("Received json missing field \"%s\"", qPrintable(field)); + return false; + } + } + return true; +} +VMManagerProtocol::ClientMessage +VMManagerProtocol::getClientMessageType(const QJsonObject &json_document) +{ + // FIXME: This key ("message") is hardcoded here. Make a hash which maps these + // required values. + QString message_type = json_document.value("message").toString(); + // Can't use switch with strings, manual compare + if (message_type == "Status") { + return VMManagerProtocol::ClientMessage::Status; + } else if (message_type == "WindowBlocked") { + return VMManagerProtocol::ClientMessage::WindowBlocked; + } else if (message_type == "WindowUnblocked") { + return VMManagerProtocol::ClientMessage::WindowUnblocked; + } else if (message_type == "RunningStateChanged") { + return VMManagerProtocol::ClientMessage::RunningStateChanged; + } + return VMManagerProtocol::ClientMessage::UnknownMessage; +} +VMManagerProtocol::ManagerMessage +VMManagerProtocol::getManagerMessageType(const QJsonObject &json_document) +{ + // FIXME: This key ("message") is hardcoded here. Make a hash which maps these + // required values. + QString message_type = json_document.value("message").toString(); + // Can't use switch with strings, manual compare + if (message_type == "RequestStatus") { + return VMManagerProtocol::ManagerMessage::RequestStatus; + } else if (message_type == "Pause") { + return VMManagerProtocol::ManagerMessage::Pause; + } if (message_type == "CtrlAltDel") { + return VMManagerProtocol::ManagerMessage::CtrlAltDel; + } if (message_type == "ShowSettings") { + return VMManagerProtocol::ManagerMessage::ShowSettings; + } if (message_type == "ResetVM") { + return VMManagerProtocol::ManagerMessage::ResetVM; + } if (message_type == "RequestShutdown") { + return VMManagerProtocol::ManagerMessage::RequestShutdown; + } if (message_type == "ForceShutdown") { + return VMManagerProtocol::ManagerMessage::ForceShutdown; + } + return VMManagerProtocol::ManagerMessage::UnknownMessage; +} +QJsonObject +VMManagerProtocol::getParams(const QJsonObject &json_document) +{ + // FIXME: This key ("params") is hardcoded here. Make a hash which maps these + // required values. + auto params_object = json_document.value("params"); + if (params_object.type() != QJsonValue::Object) { + return {}; + } + return params_object.toObject(); +} diff --git a/src/qt/qt_vmmanager_protocol.hpp b/src/qt/qt_vmmanager_protocol.hpp new file mode 100644 index 000000000..48f0a2d8f --- /dev/null +++ b/src/qt/qt_vmmanager_protocol.hpp @@ -0,0 +1,93 @@ +/* +* 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. +* +* Header for 86Box VM manager protocol module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed + */ + +#ifndef QT_VMMANAGER_PROTOCOL_H +#define QT_VMMANAGER_PROTOCOL_H + +#include +extern "C" { +#include <86box/version.h> +} + +static QVector ProtocolRequiredFields = { "type", "message" }; + +class VMManagerProtocol : QObject { + Q_OBJECT + +public: + enum class Sender { + Manager, + Client, + }; + Q_ENUM(Sender); + + enum class ManagerMessage { + RequestStatus, + Pause, + CtrlAltDel, + ShowSettings, + ResetVM, + RequestShutdown, + ForceShutdown, + UnknownMessage, + }; + + // This macro allows us to do a reverse lookup of the enum with `QMetaEnum` + Q_ENUM(ManagerMessage); + + enum class ClientMessage { + Status, + WindowBlocked, + WindowUnblocked, + RunningStateChanged, + UnknownMessage, + }; + Q_ENUM(ClientMessage); + + enum class WindowStatus { + WindowUnblocked = 0, + WindowBlocked, + }; + + enum class RunningState { + Running = 0, + Paused, + RunningWaiting, + PausedWaiting, + Unknown, + }; + Q_ENUM(RunningState); + + explicit VMManagerProtocol(Sender sender); + ~VMManagerProtocol(); + + QJsonObject protocolManagerMessage(ManagerMessage message_type); + QJsonObject protocolClientMessage(ClientMessage message_type); + static QString managerMessageTypeToString(ManagerMessage message); + static QString clientMessageTypeToString(ClientMessage message); + + static bool hasRequiredFields(const QJsonObject &json_document); + static QJsonObject getParams(const QJsonObject &json_document); + static ClientMessage getClientMessageType(const QJsonObject &json_document); + static ManagerMessage getManagerMessageType(const QJsonObject &json_document); + +private: + Sender message_class; + static QJsonObject constructDefaultObject(VMManagerProtocol::Sender type); +}; + +#endif // QT_VMMANAGER_PROTOCOL_H diff --git a/src/qt/qt_vmmanager_serversocket.cpp b/src/qt/qt_vmmanager_serversocket.cpp new file mode 100644 index 000000000..50ff352d6 --- /dev/null +++ b/src/qt/qt_vmmanager_serversocket.cpp @@ -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. +* +* 86Box VM manager server socket module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed + */ + +#include "qt_vmmanager_serversocket.hpp" +#include +#include +#include +#include +#include +#include + +VMManagerServerSocket::VMManagerServerSocket(const QFileInfo &config_path, const ServerType type) +{ + server_type = type; + config_file = config_path; + serverIsRunning = false; + socket = nullptr; + server = new QLocalServer; + setupVars(); +} + +VMManagerServerSocket::~VMManagerServerSocket() +{ + delete server; +} + +bool +VMManagerServerSocket::startServer() { + + // Remove socket file (if it exists) in order to start a new one + qInfo("Socket path is %s", qPrintable(socket_path.filePath())); + if (socket_path.exists() and !socket_path.isDir()) { + auto socket_file = new QFile(socket_path.filePath()); + if (!socket_file->remove()) { + qInfo("Failed to remove the old socket file (Error %i): %s", socket_file->error(), qPrintable(socket_file->errorString())); + return false; + } + } + + if (server->listen(socket_path.fileName())) { + serverIsRunning = true; + connect(server, &QLocalServer::newConnection, this, &VMManagerServerSocket::serverConnectionReceived); + return true; + } else { + qInfo("Failed to start server: %s", qPrintable(server->errorString())); + serverIsRunning = false; + return false; + } +} + +void +VMManagerServerSocket::serverConnectionReceived() { + qDebug("Connection received on %s", qPrintable(socket_path.fileName())); + socket = server->nextPendingConnection(); + if(!socket) { + qInfo("Invalid socket when trying to receive the connection"); + return; + } + connect(socket, &QLocalSocket::readyRead, this, &VMManagerServerSocket::serverReceivedMessage); + connect(socket, &QLocalSocket::disconnected, this, &VMManagerServerSocket::serverDisconnected); +} + +void +VMManagerServerSocket::serverReceivedMessage() { + + // Handle legacy socket connections first. These connections only receive + // information on window status + if(server_type == VMManagerServerSocket::ServerType::Legacy) { + QByteArray tempString = socket->read(1); + int window_obscured = tempString.toInt(); + emit windowStatusChanged(window_obscured); + return; + } + + // Normal connections here + QDataStream stream(socket); + stream.setVersion(QDataStream::Qt_5_7); + QByteArray jsonData; + for (;;) { + // Start a transaction + stream.startTransaction(); + // Try to read the data + stream >> jsonData; + if (stream.commitTransaction()) { + QJsonParseError parse_error{}; + // Validate the received data to make sure it's valid json + const QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData, &parse_error); + if (parse_error.error == QJsonParseError::NoError) { + // The data received was valid json + if (jsonDoc.isObject()) { + // The data is a valid json object + emit dataReceived(); + jsonReceived(jsonDoc.object()); + } + } + // The data was not valid json. + // Loop and try to read more data + } else { + // read failed, socket is reverted to its previous state (before the transaction) + // exit the loop and wait for more data to become available + break; + } + } +} + +void +VMManagerServerSocket::serverSendMessage(VMManagerProtocol::ManagerMessage protocol_message, const QStringList& arguments) const { + if(!socket) { + qInfo("Cannot send message: Invalid socket"); + return; + } + + // Regular connection + QDataStream stream(socket); + stream.setVersion(QDataStream::Qt_5_7); + auto packet = new VMManagerProtocol(VMManagerProtocol::Sender::Manager); + auto jsonMessage = packet->protocolManagerMessage(protocol_message); + stream << QJsonDocument(jsonMessage).toJson(QJsonDocument::Compact); +} + +void +VMManagerServerSocket::serverDisconnected() +{ + qInfo("Connection disconnected"); +} +void +VMManagerServerSocket::jsonReceived(const QJsonObject &json) +{ + // The serialization portion has already validated the message as json. + // Now ensure it has the required fields. + if (!VMManagerProtocol::hasRequiredFields(json)) { + // TODO: Error handling of some sort, emit signals + qDebug("Invalid message received from client: required fields missing. Object:"); + qDebug() << json; + return; + } +// qDebug().noquote() << Q_FUNC_INFO << json; + QJsonObject params_object; + + auto message_type = VMManagerProtocol::getClientMessageType(json); + switch (message_type) { + case VMManagerProtocol::ClientMessage::Status: + qDebug("Status message received from client"); + break; + case VMManagerProtocol::ClientMessage::WindowBlocked: + qDebug("Window blocked message received from client"); + emit windowStatusChanged(static_cast(VMManagerProtocol::WindowStatus::WindowBlocked)); + break; + case VMManagerProtocol::ClientMessage::WindowUnblocked: + qDebug("Window unblocked received from client"); + emit windowStatusChanged(static_cast(VMManagerProtocol::WindowStatus::WindowUnblocked)); + break; + case VMManagerProtocol::ClientMessage::RunningStateChanged: + qDebug("Running state change received from client"); + params_object = VMManagerProtocol::getParams(json); + if (!params_object.isEmpty()) { + // valid object + if(params_object.value("status").type() == QJsonValue::Double) { + // has status key, value is an int (qt assigns it as Double) + emit runningStatusChanged(static_cast(params_object.value("status").toInt())); + } + } + break; + default: + qDebug("Unknown client message type received:"); + qDebug() << json; + return; + } +} + +void +VMManagerServerSocket::setupVars() +{ + QString unique_name = QCryptographicHash::hash(config_file.path().toUtf8().constData(), QCryptographicHash::Algorithm::Sha256).toHex().right(6); + socket_path.setFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/" + QApplication::applicationName() + ".socket." + unique_name); +} + +QString +VMManagerServerSocket::getSocketPath() const +{ + if (server) { + return server->fullServerName(); + } + return {}; +} + +QString +VMManagerServerSocket::serverTypeToString(VMManagerServerSocket::ServerType server_type_lookup) +{ + QMetaEnum qme = QMetaEnum::fromType(); + return qme.valueToKey(static_cast(server_type_lookup)); + +} diff --git a/src/qt/qt_vmmanager_serversocket.hpp b/src/qt/qt_vmmanager_serversocket.hpp new file mode 100644 index 000000000..3e6e43a80 --- /dev/null +++ b/src/qt/qt_vmmanager_serversocket.hpp @@ -0,0 +1,82 @@ +/* +* 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. +* +* Header for 86Box VM manager server socket module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed + */ + +#ifndef QT_VMMANAGER_SERVERSOCKET_H +#define QT_VMMANAGER_SERVERSOCKET_H + +#include +#include +#include +#include +#include +#include "qt_vmmanager_protocol.hpp" + +// This macro helps give us the required `qHash()` function in order to use the +// enum as a hash key +#define QHASH_FOR_CLASS_ENUM(T) \ +inline uint qHash(const T &t, uint seed) { \ + return ::qHash(static_cast::type>(t), seed); \ +} + +class VMManagerServerSocket : public QWidget { + + Q_OBJECT + +public: + + enum class ServerType { + Standard, + Legacy, + }; + // This macro allows us to do a reverse lookup of the enum with `QMetaEnum` + Q_ENUM(ServerType) + + QHASH_FOR_CLASS_ENUM(ServerType) + + explicit VMManagerServerSocket(const QFileInfo &config_path, ServerType type = ServerType::Standard); + ~VMManagerServerSocket() override; + + QFileInfo socket_path; + QFileInfo config_file; + + QLocalServer *server; + QLocalSocket *socket; + ServerType server_type; + bool serverIsRunning; + + // Server functions + bool startServer(); + void serverConnectionReceived(); + void serverReceivedMessage(); + void serverSendMessage(VMManagerProtocol::ManagerMessage protocol_message, const QStringList& arguments = QStringList()) const; + static void serverDisconnected(); + void jsonReceived(const QJsonObject &json); + QString getSocketPath() const; + + static QString serverTypeToString(ServerType server_type_lookup); + + void setupVars(); + +signals: + void dataReceived(); + void windowStatusChanged(int status); + void runningStatusChanged(VMManagerProtocol::RunningState state); + + +}; + +#endif // QT_VMMANAGER_SERVERSOCKET_H diff --git a/src/qt/qt_vmmanager_system.cpp b/src/qt/qt_vmmanager_system.cpp new file mode 100644 index 000000000..0a7382094 --- /dev/null +++ b/src/qt/qt_vmmanager_system.cpp @@ -0,0 +1,924 @@ +/* +* 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. +* +* 86Box VM manager system module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "qt_vmmanager_system.hpp" +// #include "qt_vmmanager_details_section.hpp" +#include "qt_vmmanager_detailsection.hpp" + + +extern "C" { +#include <86box/86box.h> +#include <86box/device.h> +#include <86box/video.h> +// #include <86box/vid_xga_device.h> +#include <86box/machine.h> +#include <86box/plat.h> +#include <86box/sound.h> +#include +#include <86box/thread.h> // required for network.h +#include <86box/timer.h> // required for network.h and fdd.h +#include <86box/cdrom.h> +#include <86box/scsi.h> +#include <86box/fdd.h> +#include <86box/gameport.h> +#include <86box/midi.h> +#include <86box/network.h> +#include <86box/mouse.h> +} + +using namespace VMManager; + +VMManagerSystem::VMManagerSystem(const QString &sysconfig_file) { + + // The 86Box configuration file + config_file = QFileInfo(sysconfig_file); + // The default name of the system. This is the name of the directory + // that contains the 86box configuration file + config_name = config_file.dir().dirName(); + // The full path of the directory that contains the 86box configuration file + config_dir = shortened_dir = config_file.dir().path(); + process_status = ProcessStatus::Stopped; + // Main 86Box uses usr_path for UUID which includes the trailing slash. + // Make sure to append the slash here so the UUIDs will match + auto uuid_path = config_dir; + if (!uuid_path.endsWith("/")) { + uuid_path.append("/"); + } + // In the configuration file the UUID is used as a unique value + uuid = QUuid::createUuidV5(QUuid{}, uuid_path).toString(QUuid::WithoutBraces); + // That unique value is used to map the information to each individual system. + config_settings = new VMManagerConfig(VMManagerConfig::ConfigType::System, uuid); + + // On non-windows platforms, shortened_dir will replace the home directory path with ~ + // and be used as the tool tip in the list view +#if not defined(Q_OS_WINDOWS) + if (config_dir.startsWith(QDir::homePath())) { + shortened_dir.replace(QDir::homePath(), "~"); + } +#endif + loadSettings(); + setupPaths(); + // Paths must be setup before vars! + setupVars(); + + serverIsRunning = false; + window_obscured = false; + + find86BoxBinary(); + platform = QApplication::platformName(); + process = new QProcess(); + connect(process, &QProcess::stateChanged, this, &VMManagerSystem::processStatusChanged); + + // Server type for this instance (Standard should always be used instead of Legacy) + socket_server_type = VMManagerServerSocket::ServerType::Standard; + socket_server = new VMManagerServerSocket(config_file, socket_server_type); + + // NOTE: When unique names or UUIDs are written to the individual VM config file, use that + // here instead of the auto-generated unique_name + // Save settings once everything is initialized + saveSettings(); +} + +VMManagerSystem::~VMManagerSystem() { + delete socket_server; +} + +QVector +VMManagerSystem::scanForConfigs(QWidget* parent, const QString &searchPath) +{ + QProgressDialog progDialog(parent); + unsigned int found = 0; + progDialog.setCancelButton(nullptr); + progDialog.setWindowTitle(tr("Searching for VMs...")); + progDialog.setMinimumDuration(0); + progDialog.setValue(0); + progDialog.setMinimum(0); + progDialog.setMaximum(0); + progDialog.setWindowFlags(progDialog.windowFlags() & ~Qt::WindowCloseButtonHint); + QElapsedTimer scanTimer; + scanTimer.start(); + QVector system_configs; + + const auto config = new VMManagerConfig(VMManagerConfig::ConfigType::General); + auto systemDirConfig = config->getStringValue("system_directory"); + + const auto config_file_name = QString("86box.cfg"); + const QStringList filters = {config_file_name}; + QStringList matches; + // TODO: Preferences. Once I get the CLI args worked out. + // For now it just takes vmm_path from the CLI + QString search_directory; + // if(searchPath.isEmpty()) { + // // If the location isn't specified in function call, use the one loaded + // // from the config file + // search_directory = systemDirConfig; + // } else { + // search_directory = searchPath; + // } + + search_directory = searchPath.isEmpty()? vmm_path : searchPath; + + if(!QDir(search_directory).exists()) { + //qWarning() << "Path" << search_directory << "does not exist. Cannot continue"; + QDir(search_directory).mkpath("."); + //return {}; + } + + QDirIterator dir_iterator(search_directory, filters, QDir::Files, QDirIterator::Subdirectories); + + qInfo("Searching %s for %s", qPrintable(search_directory), qPrintable(config_file_name)); + + QElapsedTimer timer; + timer.start(); + while (dir_iterator.hasNext()) { + found++; + progDialog.setLabelText(tr("Found %1").arg(QString::number(found))); + QApplication::processEvents(); + QString filename = dir_iterator.next(); + matches.append(filename); + } + + const auto scanElapsed = timer.elapsed(); + qDebug().noquote().nospace() << "Found " << matches.size() << " configs in " << search_directory <<". Scan took " << scanElapsed << " ms"; + + timer.restart(); + // foreach (QFileInfo hit, matches) { + // system_configs.append(new VMManagerSystem(hit)); + // } + progDialog.setMaximum(found); + progDialog.setValue(0); + unsigned int appended = 0; + for (const auto &filename : matches) { + system_configs.append(new VMManagerSystem(filename)); + appended++; + progDialog.setLabelText(system_configs.last()->displayName); + progDialog.setValue(appended); + QApplication::processEvents(); + } + if (matches.size()) { + auto elapsed = timer.elapsed(); + qDebug() << "Load loop took" << elapsed << "ms for" << matches.size() << "loads"; + qDebug() << "Overall scan time was" << scanTimer.elapsed() << "ms, average" << elapsed / matches.size() << "ms / load"; + } + return system_configs; +} + +QString +VMManagerSystem::generateTemporaryFilename() +{ + QTemporaryFile tempFile; + // File will be closed once the QTemporaryFile object goes out of scope + tempFile.setAutoRemove(true); + tempFile.open(); + return tempFile.fileName(); +} + +QFileInfoList +VMManagerSystem::getScreenshots() { + + // Don't bother unless the directory exists + if(!screenshot_directory.exists()) { + return {}; + } + + auto screen_scan_dir = QDir(screenshot_directory.path(), "Monitor_1*", QDir::SortFlag::LocaleAware | QDir::SortFlag::IgnoreCase, QDir::Files); + auto screenshot_files = screen_scan_dir.entryInfoList(); + return screenshot_files; +} + +void +VMManagerSystem::loadSettings() +{ + // First, load the information from the 86box.cfg + QSettings settings(config_file.filePath(), QSettings::IniFormat); + if (settings.status() != QSettings::NoError) { + qWarning() << "Error loading" << config_file.path() << " status:" << settings.status(); + } + // qInfo() << "Loaded "<< config_file.filePath() << "status:" << settings.status(); + + // Clear out the config hash in case the config is reloaded + for (const auto &outer_key : config_hash.keys()) { + config_hash[outer_key].clear(); + } + + // General + for (const auto &key_name : settings.childKeys()) { + config_hash["General"][key_name] = settings.value(key_name).toString(); + } + + for (auto &group_name : settings.childGroups()) { + settings.beginGroup(group_name); + for (const auto &key_name : settings.allKeys()) { + QString setting_value; + // QSettings will interpret lines with commas as QStringList. + // Check for it and join them back to a string. + if (settings.value(key_name).type() == QVariant::StringList) { + setting_value = settings.value(key_name).toStringList().join(", "); + } else { + setting_value = settings.value(key_name).toString(); + } + config_hash[group_name][key_name] = setting_value; + } + settings.endGroup(); + } + + // Next, load the information from the vmm config for this system + // Display name + auto loadedDisplayName = config_settings->getStringValue("display_name"); + if (!loadedDisplayName.isEmpty()) { + displayName = loadedDisplayName; + } else { + displayName = config_name; + } + // Notes + auto loadedNotes = config_settings->getStringValue("notes"); + if (!loadedNotes.isEmpty()) { + notes = loadedNotes; + } + // Timestamp + auto loadedTimestamp = config_settings->getStringValue("timestamp"); + if (!loadedTimestamp.isEmpty()) { + // Make sure it is valid + if (auto newTimestamp = QDateTime::fromString(loadedTimestamp, Qt::ISODate); newTimestamp.isValid()) { + lastUsedTimestamp = newTimestamp; + } + } + // Icon + auto loadedIcon = config_settings->getStringValue("icon"); + if (!loadedIcon.isEmpty()) { + icon = loadedIcon; + } +} +void +VMManagerSystem::saveSettings() +{ + if(!isValid()) { + return; + } + config_settings->setStringValue("system_name", config_name); + config_settings->setStringValue("config_file", config_file.canonicalFilePath()); + config_settings->setStringValue("config_dir", config_file.canonicalPath()); + if (displayName != config_name) { + config_settings->setStringValue("display_name", displayName); + } else { + config_settings->remove("display_name"); + } + + config_settings->setStringValue("notes", notes); + if(lastUsedTimestamp.isValid()) { + config_settings->setStringValue("timestamp", lastUsedTimestamp.toString(Qt::ISODate)); + } + config_settings->setStringValue("icon", icon); + generateSearchTerms(); +} +void +VMManagerSystem::generateSearchTerms() +{ + searchTerms.clear(); + for (const auto &config_key : config_hash.keys()) { + // searchTerms.append(config_hash[config_key].values()); + // brute force temporarily don't add paths + for(const auto &value: config_hash[config_key].values()) { + if(!value.startsWith("/")) { + searchTerms.append(value); + } + } + } + searchTerms.append(display_table.values()); + searchTerms.append(displayName); + searchTerms.append(config_name); + QRegularExpression whitespaceRegex("\\s+"); + searchTerms.append(notes.split(whitespaceRegex)); +} +void +VMManagerSystem::updateTimestamp() +{ + lastUsedTimestamp = QDateTime::currentDateTimeUtc(); + saveSettings(); +} + +QString +VMManagerSystem::getAll(const QString& category) const { + auto value = config_hash[category].keys().join(", "); + return value; +} + +QHash> +VMManagerSystem::getConfigHash() const +{ + return config_hash; +} + +void +VMManagerSystem::setDisplayName(const QString &newDisplayName) +{ + // If blank, reset to the default + if (newDisplayName.isEmpty()) { + displayName = config_name; + } else { + displayName = newDisplayName; + } + saveSettings(); +} +void +VMManagerSystem::setNotes(const QString &newNotes) +{ + notes = newNotes; + saveSettings(); +} +bool +VMManagerSystem::isValid() const +{ + return config_file.exists() && config_file.isFile() && config_file.size() != 0; +} + +bool +VMManagerSystem::isProcessRunning() const +{ + return process->processId() != 0; +} + +qint64 +VMManagerSystem::processId() const +{ + return process->processId(); +} + +QHash +VMManagerSystem::getCategory(const QString &category) const { + return config_hash[category]; +} + +void +VMManagerSystem::find86BoxBinary() { + // We'll use our own self to launch the VMs + main_binary = QFileInfo(QCoreApplication::applicationFilePath()); +} + +bool +VMManagerSystem::has86BoxBinary() { + return main_binary.exists(); +} + +void +VMManagerSystem::launchMainProcess() { + + if(!has86BoxBinary()) { + qWarning("No binary found! returning"); + return; + } + + // start the server first to get the socket name + if (!serverIsRunning) { + if(!startServer()) { + // FIXME: Better error handling + qInfo("Failed to start VM Manager server"); + return; + } + } + setProcessEnvVars(); + QString program = main_binary.filePath(); + QStringList args; + args << "-P" << config_dir; + args << "--vmname" << displayName; + process->setProgram(program); + process->setArguments(args); + qDebug() << Q_FUNC_INFO << " Full Command:" << process->program() << " " << process->arguments(); + process->start(); + updateTimestamp(); +} + +void +VMManagerSystem::startButtonPressed() { + launchMainProcess(); +} + +void +VMManagerSystem::launchSettings() { + if(!has86BoxBinary()) { + qWarning("No binary found! returning"); + return; + } + + // If the system is already running, instruct it to show settings + if (process->processId() != 0) { + socket_server->serverSendMessage(VMManagerProtocol::ManagerMessage::ShowSettings); + return; + } + + // Otherwise, launch the system with the settings parameter + setProcessEnvVars(); + QString program = main_binary.filePath(); + QStringList open_command_args; + QStringList args; + args << "-P" << config_dir << "-S"; + process->setProgram(program); + process->setArguments(args); + qDebug() << Q_FUNC_INFO << " Full Command:" << process->program() << " " << process->arguments(); + process->start(); +} + +void +VMManagerSystem::setupPaths() { + // application_temp_directory.setPath(QStandardPaths::writableLocation(QStandardPaths::TempLocation)); + // standard_temp_directory.setPath(QStandardPaths::writableLocation(QStandardPaths::TempLocation)); + // QString temp_subdir = QApplication::applicationName(); + // if (!application_temp_directory.exists(temp_subdir)) { + // // FIXME: error checking + // application_temp_directory.mkdir(temp_subdir); + // } + // // QT always replaces `/` with native separators, so it is safe to use here for all platforms + // application_temp_directory.setPath(application_temp_directory.path() + "/" + temp_subdir); + // app_data_directory.setPath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); + // // TODO: come back here and update with the new plat_get_global_* + // if (!app_data_directory.exists()) { + // // FIXME: Error checking + // app_data_directory.mkpath(app_data_directory.path()); + // } + screenshot_directory.setPath(config_dir + "/" + "screenshots"); +} + +void +VMManagerSystem::setupVars() { + unique_name = QCryptographicHash::hash(config_file.path().toUtf8().constData(), QCryptographicHash::Algorithm::Sha256).toHex().right(9); + // unique_name = "aaaaaa"; + // Set up the display vars + // This will likely get moved out to its own class + // This will likely get moved out to its own class + auto machine_config = getCategory("Machine"); + auto video_config = getCategory("Video"); + auto disk_config = getCategory("Hard disks"); + auto audio_config = getCategory("Sound"); + auto network_config = getCategory("Network"); + auto input_config = getCategory("Input devices"); + auto floppy_cdrom_config = getCategory("Floppy and CD-ROM drives"); + auto scsi_config = getCategory("Storage controllers"); + auto ports_config = getCategory("Ports (COM & LPT)"); + // auto general_config = getCategory("General"); + // auto config_uuid = QString("Not set"); + // if(!general_config["uuid"].isEmpty()) { + // config_uuid = general_config["uuid"]; + // qDebug() << "btw config dir:" << config_dir; + // } + // qDebug() << "Generated UUID:" << uuid; + // qDebug() << "Config file UUID:" << config_uuid; + auto machine_name = QString(); + int i = 0; + int ram_granularity = 0; + // Machine + for (int ci = 0; ci < machine_count(); ++ci) { + if (machine_available(ci)) { + if (machines[ci].internal_name == machine_config["machine"]) { + machine_name = machines[ci].name; + ram_granularity = machines[ci].ram.step; + } + } + } + display_table[Display::Name::Machine] = machine_name; + + // CPU: Combine name with speed + auto cpu_name = QString(); + while (cpu_families[i].package != 0) { + if (cpu_families[i].internal_name == machine_config["cpu_family"]) { + cpu_name = QString("%1 %2").arg(cpu_families[i].manufacturer, cpu_families[i].name); + } + i++; + } + int speed_display = machine_config["cpu_speed"].toInt() / 1000000; + cpu_name.append(QString::number(speed_display).prepend(" / ")); + cpu_name.append(QCoreApplication::translate("", "MHz").prepend(' ')); + display_table[Display::Name::CPU] = cpu_name; + + // Memory + int divisor = (ram_granularity < 1024) ? 1 : 1024; + QString display_unit = (divisor == 1) ? "KB" : "MB"; + auto mem_display = QString::number(machine_config["mem_size"].toInt() / divisor); + mem_display.append(QCoreApplication::translate("", display_unit.toUtf8().constData()).prepend(' ')); + display_table[Display::Name::Memory] = mem_display; + + // Video card + int video_int = video_get_video_from_internal_name(video_config["gfxcard"].toUtf8().data()); + const device_t* video_dev = video_card_getdevice(video_int); + display_table[Display::Name::Video] = DeviceConfig::DeviceName(video_dev, video_get_internal_name(video_int), 1); + if (!video_config["voodoo"].isEmpty()) { + // FIXME: Come back to this later to add more for secondary video +// display_table[Display::Name::Video].append(" (with voodoo)"); + display_table[Display::Name::Voodoo] = "Voodoo enabled"; + } + + // Drives + // First the number of disks + QMap disks; + for(const auto& key: disk_config.keys()) { + // Assuming the format hdd_NN_* + QStringList pieces = key.split('_'); + QString disk = QString("%1_%2").arg(pieces.at(0), pieces.at(1)); + if(!disk.isEmpty()) { + disks[disk] = 1; + } + } + // Next, the types + QHash bus_types; + for (const auto& key: disks.keys()) { + auto disk_parameter_key = QString("%1_parameters").arg(key); + QStringList pieces = disk_config[disk_parameter_key].split(","); + QString bus_type = pieces.value(pieces.length() - 1).trimmed(); + bus_types[bus_type] = 1; + } + QString disks_display = tr("%n disk(s)", "", disks.count()); + if (disks.count()) { + disks_display.append(" / ").append(bus_types.keys().join(", ").toUpper()); + } +// display_table[Display::Name::Disks] = disks_display; + + // Drives + QString new_disk_display; + for (const auto& key: disks.keys()) { + auto disk_parameter_key = QString("%1_parameters").arg(key); + // Converting a string to an int back to a string to remove the zero (e.g. 01 to 1) + auto disk_number = QString::number(key.split("_").last().toInt()); + QStringList pieces = disk_config[disk_parameter_key].split(","); + QString sectors = pieces.value(0).trimmed(); + QString heads = pieces.value(1).trimmed(); + QString cylinders = pieces.value(2).trimmed(); + QString bus_type = pieces.value(pieces.length() - 1).trimmed(); + // Add separator for each subsequent value, skipping the first + if(!new_disk_display.isEmpty()) { + new_disk_display.append(QString("%1").arg(VMManagerDetailSection::sectionSeparator)); + } + int diskSizeRaw = (cylinders.toInt() * heads.toInt() * sectors.toInt()) >> 11; + QString diskSizeFinal; + QString unit = "MiB"; + if(diskSizeRaw > 1000) { + unit = "GiB"; + diskSizeFinal = QString::number(diskSizeRaw * 1.0 / 1000, 'f', 1); + } else { + diskSizeFinal = QString::number(diskSizeRaw); + } + // Only prefix each disk when there are multiple disks + QString diskNumberDisplay = disks.count() > 1 ? QString("Disk %1: ").arg(disk_number) : ""; + new_disk_display.append(QString("%1%2 %3 (%4)").arg(diskNumberDisplay, diskSizeFinal, unit, bus_type.toUpper())); + } + if(new_disk_display.isEmpty()) { + new_disk_display = "No disks"; + } + display_table[Display::Name::Disks] = new_disk_display; + + // Floppy & CD-ROM + QStringList floppyDevices; + QStringList cdromDevices; + static auto floppy_match = QRegularExpression("fdd_\\d\\d_type", QRegularExpression::CaseInsensitiveOption); + static auto cdrom_match = QRegularExpression("cdrom_\\d\\d_type", QRegularExpression::CaseInsensitiveOption); + for(const auto& key: floppy_cdrom_config.keys()) { + if(key.contains(floppy_match)) { + // auto device_number = key.split("_").at(1); + auto floppy_internal_name = QString(floppy_cdrom_config[key]); + // Not interested in the nones + if(floppy_internal_name == "none") { + continue; + } + auto floppy_type = fdd_get_from_internal_name(floppy_internal_name.toUtf8().data()); + if(auto fddName = QString(fdd_getname(floppy_type)); !fddName.isEmpty()) { + floppyDevices.append(fddName); + } + } + if(key.contains(cdrom_match)) { + auto device_number = key.split("_").at(1); + auto cdrom_internal_name = QString(floppy_cdrom_config[key]); + auto cdrom_type = cdrom_get_from_internal_name(cdrom_internal_name.toUtf8().data()); + + auto cdrom_speed_key = QString("cdrom_%1_speed").arg(device_number); + auto cdrom_parameters_key = QString("cdrom_%1_parameters").arg(device_number); + auto cdrom_speed = QString(floppy_cdrom_config[cdrom_speed_key]); + auto cdrom_parameters = QString(floppy_cdrom_config[cdrom_parameters_key]); + auto cdrom_bus = cdrom_parameters.split(",").at(1).trimmed().toUpper(); + + if(cdrom_type != -1) { + if(!cdrom_speed.isEmpty()) { + cdrom_speed = QString("%1x ").arg(cdrom_speed); + } + if(!cdrom_bus.isEmpty()) { + cdrom_bus = QString(" (%1)").arg(cdrom_bus); + } + cdromDevices.append(QString("%1%2 %3 %4%5").arg(cdrom_speed, cdrom_drive_types[cdrom_type].vendor, cdrom_drive_types[cdrom_type].model, cdrom_drive_types[cdrom_type].revision, cdrom_bus)); + } + } + } + + display_table[Display::Name::Floppy] = floppyDevices.join(VMManagerDetailSection::sectionSeparator); + display_table[Display::Name::CD] = cdromDevices.join(VMManagerDetailSection::sectionSeparator); + + // SCSI controllers + QStringList scsiControllers; + static auto scsi_match = QRegularExpression("scsicard_\\d", QRegularExpression::CaseInsensitiveOption); + for(const auto& key: scsi_config.keys()) { + if(key.contains(scsi_match)) { + auto device_number = key.split("_").at(1); + auto scsi_internal_name = QString(scsi_config[key]); + auto scsi_id = scsi_card_get_from_internal_name(scsi_internal_name.toUtf8().data()); + auto scsi_device = scsi_card_getdevice(scsi_id); + auto scsi_name = QString(scsi_device->name); + if(!scsi_name.isEmpty()) { + scsiControllers.append(scsi_name); + } + } + } + display_table[Display::Name::SCSIController] = scsiControllers.join(VMManagerDetailSection::sectionSeparator); + + // Audio + int sound_int = sound_card_get_from_internal_name(audio_config["sndcard"].toUtf8().data()); + const device_t* audio_dev = sound_card_getdevice(sound_int); + display_table[Display::Name::Audio] = DeviceConfig::DeviceName(audio_dev, sound_card_get_internal_name(sound_int), 1); + + // MIDI + QString midiOutDev; + if(auto midi_out_device = QString(audio_config["midi_device"]); !midi_out_device.isEmpty()) { + auto midi_device_int = midi_out_device_get_from_internal_name(midi_out_device.toUtf8().data()); + auto midi_out = midi_out_device_getdevice(midi_device_int); + if(auto midiDevName = QString(midi_out->name); !midiDevName.isEmpty()) { + midiOutDev = midiDevName; + } + } + display_table[Display::Name::MidiOut] = midiOutDev; + + // midi_device = mt32 (output) + // mpu401_standalone = 1 + // midi_in_device (input) + + // Network + QString nicList; + static auto nic_match = QRegularExpression("net_\\d\\d_card", QRegularExpression::CaseInsensitiveOption); + for(const auto& key: network_config.keys()) { + if(key.contains(nic_match)) { + auto device_number = key.split("_").at(1); + auto nic_internal_name = QString(network_config[key]); + auto nic_id = network_card_get_from_internal_name(nic_internal_name.toUtf8().data()); + auto nic = network_card_getdevice(nic_id); + auto nic_name = QString(nic->name); + // Add separator for each subsequent value, skipping the first + if(!nicList.isEmpty()) { + nicList.append(QString("%1").arg(VMManagerDetailSection::sectionSeparator)); + } + auto net_type_key = QString("net_%1_net_type").arg(device_number); + auto net_type = network_config[net_type_key]; + if (!net_type.isEmpty()) { + nicList.append(nic_name + " (" + net_type + ")"); + } else { + nicList.append(nic_name); + } + + } + } + if(nicList.isEmpty()) { + nicList = "None"; + } + display_table[Display::Name::NIC] = nicList; + + // Input (Mouse) + auto mouse_internal_name = input_config["mouse_type"]; + auto mouse_dev = mouse_get_from_internal_name(mouse_internal_name.toUtf8().data()); + auto mouse_dev_name = mouse_get_name(mouse_dev); + display_table[Display::Name::Mouse] = mouse_dev_name; + + // Input (joystick) + QString joystickDevice; + if(auto joystick_internal = QString(input_config["joystick_type"]); !joystick_internal.isEmpty()) { + auto joystick_dev = joystick_get_from_internal_name(joystick_internal.toUtf8().data()); + if (auto joystickName = QString(joystick_get_name(joystick_dev)); !joystickName.isEmpty()) { + joystickDevice = joystickName; + } + } + display_table[Display::Name::Joystick] = joystickDevice; + + // # Ports + // Serial + // By default serial 1 and 2 are enabled unless otherwise specified + static auto serial_match = QRegularExpression("serial\\d_enabled", QRegularExpression::CaseInsensitiveOption); + QList serial_enabled = {true, true, false, false, false, false, false, false}; + // Parallel + // By default lpt 1 is enabled unless otherwise specified + static auto lpt_match = QRegularExpression("lpt\\d_enabled", QRegularExpression::CaseInsensitiveOption); + QList lpt_enabled = {true, false, false, false}; + for (const auto &key: ports_config.keys()) { + if (key.contains(serial_match)) { + if (auto serial_dev = key.split("_").at(0); !serial_dev.isEmpty()) { + auto serial_num = serial_dev.at(serial_dev.size() - 1); + // qDebug() << "serial is set" << key << ":" << ports_config[key]; + if(serial_num.isDigit() && serial_num.digitValue() >= 1 && serial_num.digitValue() <= 4) { + // Already verified that it is a digit with isDigit() + serial_enabled[serial_num.digitValue() - 1] = ports_config[key].toInt() == 1; + } + } + } + if (key.contains(lpt_match)) { + if (auto lpt_dev = key.split("_").at(0); !lpt_dev.isEmpty()) { + auto lpt_num = lpt_dev.at(lpt_dev.size() - 1); + // qDebug() << "lpt is set" << key << ":" << ports_config[key]; + if (lpt_num.isDigit() && lpt_num.digitValue() >= 1 && lpt_num.digitValue() <= 4) { + lpt_enabled[lpt_num.digitValue() - 1] = ports_config[key].toInt() == 1; + } + } + } + } + // qDebug() << "ports final" << serial_enabled << lpt_enabled; + QStringList serialFinal; + QStringList lptFinal; + int portIndex = 0; + while (true) { + if (serial_enabled[portIndex]) + serialFinal.append(QString("COM%1").arg(portIndex + 1)); + ++portIndex; + if (portIndex == SERIAL_MAX) + break; + } + portIndex = 0; + while (true) { + if (lpt_enabled[portIndex]) + lptFinal.append(QString("LPT%1").arg(portIndex + 1)); + ++portIndex; + if (portIndex == PARALLEL_MAX) + break; + } + display_table[Display::Name::Serial] = serialFinal.empty() ? tr("None") : serialFinal.join(", "); + display_table[Display::Name::Parallel] = lptFinal.empty() ? tr("None") : lptFinal.join(", "); + +} + +bool +VMManagerSystem::startServer() { + if (socket_server->startServer()) { + serverIsRunning = true; + connect(socket_server, &VMManagerServerSocket::dataReceived, this, &VMManagerSystem::dataReceived); + connect(socket_server, &VMManagerServerSocket::windowStatusChanged, this, &VMManagerSystem::windowStatusChangeReceived); + connect(socket_server, &VMManagerServerSocket::runningStatusChanged, this, &VMManagerSystem::runningStatusChangeReceived); + return true; + } else { + return false; + } +} + +void +VMManagerSystem::setProcessEnvVars() { + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); + QString env_var_name = (socket_server_type == VMManagerServerSocket::ServerType::Standard) ? "VMM_86BOX_SOCKET" : "86BOX_MANAGER_SOCKET"; + env.insert(env_var_name, socket_server->getSocketPath()); + process->setProcessEnvironment(env); +} + +void +VMManagerSystem::restartButtonPressed() { + socket_server->serverSendMessage(VMManagerProtocol::ManagerMessage::ResetVM); + +} + +void +VMManagerSystem::pauseButtonPressed() { + socket_server->serverSendMessage(VMManagerProtocol::ManagerMessage::Pause); +} +void +VMManagerSystem::dataReceived() +{ + qInfo() << Q_FUNC_INFO << "Note: Respond to data received events here."; +} +void +VMManagerSystem::windowStatusChangeReceived(int status) +{ + window_obscured = status; + emit windowStatusChanged(); + processStatusChanged(); +} +QString +VMManagerSystem::getDisplayValue(Display::Name key) +{ + return (display_table.contains(key)) ? display_table[key] : ""; +} + +void +VMManagerSystem::shutdownRequestButtonPressed() +{ + socket_server->serverSendMessage(VMManagerProtocol::ManagerMessage::RequestShutdown); +} + +void +VMManagerSystem::shutdownForceButtonPressed() +{ + socket_server->serverSendMessage(VMManagerProtocol::ManagerMessage::ForceShutdown); +} + +void +VMManagerSystem::cadButtonPressed() +{ + socket_server->serverSendMessage(VMManagerProtocol::ManagerMessage::CtrlAltDel); +} + +void +VMManagerSystem::processStatusChanged() +{ + // set to running if the process is running and the state is stopped + if (process->state() == QProcess::ProcessState::Running) { + if (process_status == VMManagerSystem::ProcessStatus::Stopped) { + process_status = VMManagerSystem::ProcessStatus::Running; + } + } else if (process->state() == QProcess::ProcessState::NotRunning) { + process_status = VMManagerSystem::ProcessStatus::Stopped; + } + emit itemDataChanged(); + emit clientProcessStatusChanged(); +} +void +VMManagerSystem::statusRefresh() +{ + processStatusChanged(); +} +QString +VMManagerSystem::processStatusToString(VMManagerSystem::ProcessStatus status) +{ +// QMetaEnum qme = QMetaEnum::fromType(); +// return qme.valueToKey(static_cast(status)); + switch (status) { + case VMManagerSystem::ProcessStatus::Stopped: + return tr("Powered Off"); + case VMManagerSystem::ProcessStatus::Running: + return tr("Running"); + case VMManagerSystem::ProcessStatus::Paused: + return tr("Paused"); + case VMManagerSystem::ProcessStatus::PausedWaiting: + case VMManagerSystem::ProcessStatus::RunningWaiting: + return tr("Paused (Waiting)"); + default: + return tr("Unknown Status"); + } +} + +QString +VMManagerSystem::getProcessStatusString() const +{ + return processStatusToString(process_status); +} + +VMManagerSystem::ProcessStatus +VMManagerSystem::getProcessStatus() const +{ + return process_status; +} +// Maps VMManagerProtocol::RunningState to VMManagerSystem::ProcessStatus +void +VMManagerSystem::runningStatusChangeReceived(VMManagerProtocol::RunningState state) +{ + if(state == VMManagerProtocol::RunningState::Running) { + process_status = VMManagerSystem::ProcessStatus::Running; + } else if(state == VMManagerProtocol::RunningState::Paused) { + process_status = VMManagerSystem::ProcessStatus::Paused; + } else if(state == VMManagerProtocol::RunningState::RunningWaiting) { + process_status = VMManagerSystem::ProcessStatus::RunningWaiting; + } else if(state == VMManagerProtocol::RunningState::PausedWaiting) { + process_status = VMManagerSystem::ProcessStatus::PausedWaiting; + } else { + process_status = VMManagerSystem::ProcessStatus::Unknown; + } + processStatusChanged(); +} +void +VMManagerSystem::reloadConfig() +{ + loadSettings(); + setupVars(); +} + +QDateTime +VMManagerSystem::timestamp() +{ + return lastUsedTimestamp; +} +void +VMManagerSystem::setIcon(const QString &newIcon) +{ + icon = newIcon; + saveSettings(); + emit itemDataChanged(); +} diff --git a/src/qt/qt_vmmanager_system.hpp b/src/qt/qt_vmmanager_system.hpp new file mode 100644 index 000000000..6ac0a7635 --- /dev/null +++ b/src/qt/qt_vmmanager_system.hpp @@ -0,0 +1,194 @@ +/* +* 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. +* +* Header for 86Box VM manager system module +* +* +* +* Authors: cold-brewed +* +* Copyright 2024 cold-brewed +*/ + +#ifndef QT_VMMANAGER_SYSTEM_H +#define QT_VMMANAGER_SYSTEM_H + +#include +#include +#include +#include +#include +#include "qt_vmmanager_serversocket.hpp" +#include "qt_vmmanager_config.hpp" +#include "qt_deviceconfig.hpp" + +// This macro helps give us the required `qHash()` function in order to use the +// enum as a hash key +#define QHASH_FOR_CLASS_ENUM(T) \ +inline uint qHash(const T &t, uint seed) { \ + return ::qHash(static_cast::type>(t), seed); \ +} + +namespace VMManager { +Q_NAMESPACE +namespace Display { +Q_NAMESPACE +enum class Name { + Machine, + CPU, + Memory, + Video, + Disks, + Floppy, + CD, + SCSIController, + MidiOut, + Joystick, + Serial, + Parallel, + Audio, + Voodoo, + NIC, + Mouse, + Unknown +}; +Q_ENUM_NS(Name) +QHASH_FOR_CLASS_ENUM(Name) +} +} + +class VMManagerSystem : public QWidget { + Q_OBJECT + + typedef QHash display_table_t; + typedef QHash > config_hash_t; + +public: + + enum class ProcessStatus { + Stopped, + Running, + Paused, + PausedWaiting, + RunningWaiting, + Unknown, + }; + Q_ENUM(ProcessStatus); + + explicit VMManagerSystem(const QString &sysconfig_file); + // Default constructor will generate a temporary filename as the config file + // but it will not be valid (isValid() will return false) + VMManagerSystem() : VMManagerSystem(generateTemporaryFilename()) {} + + ~VMManagerSystem() override; + + static QVector scanForConfigs(QWidget* parent = nullptr, const QString &searchPath = {}); + static QString generateTemporaryFilename(); + + QFileInfo config_file; + QString config_name; + QString config_dir; + QString shortened_dir; + QString uuid; + QString displayName; + QString notes; + QString icon; + QStringList searchTerms; + + config_hash_t config_hash; + + [[nodiscard]] QString getAll(const QString& category) const; + [[nodiscard]] QHash getCategory(const QString& category) const; + [[nodiscard]] QHash > getConfigHash() const; + + void setDisplayName(const QString& newDisplayName); + void setNotes(const QString& newNotes); + + [[nodiscard]] bool isValid() const; + [[nodiscard]] bool isProcessRunning() const; + [[nodiscard]] qint64 processId() const; +public slots: + void launchMainProcess(); + void launchSettings(); + void startButtonPressed(); + void restartButtonPressed(); + void pauseButtonPressed(); + void shutdownRequestButtonPressed(); + void shutdownForceButtonPressed(); + void cadButtonPressed(); + void reloadConfig(); +public: + QDateTime timestamp(); + void setIcon(const QString &newIcon); + + QProcess *process = new QProcess(); + + bool window_obscured; + + QString getDisplayValue(VMManager::Display::Name key); + QFileInfoList getScreenshots(); + + inline bool operator==(const VMManagerSystem &rhs) const + { + return config_file.filePath() == rhs.config_file.filePath(); + } + + static QString + processStatusToString(VMManagerSystem::ProcessStatus status) ; + ProcessStatus process_status; + [[nodiscard]] QString getProcessStatusString() const; + [[nodiscard]] ProcessStatus getProcessStatus() const; + +signals: + void windowStatusChanged(); + void itemDataChanged(); + void clientProcessStatusChanged(); + +private: + void loadSettings(); + void saveSettings(); + void generateSearchTerms(); + void updateTimestamp(); + + display_table_t display_table; + + QFileInfo main_binary; + QString platform; + + // QDir application_temp_directory; + // QDir standard_temp_directory; + // QDir app_data_directory; + QDir screenshot_directory; + + QString unique_name; + QDateTime lastUsedTimestamp; + + VMManagerServerSocket *socket_server; + VMManagerServerSocket::ServerType socket_server_type; + + // Configuration file settings + VMManagerConfig *config_settings; + + bool serverIsRunning; + bool startServer(); + + bool has86BoxBinary(); + void find86BoxBinary(); + void setupPaths(); + void setupVars(); + void setProcessEnvVars(); + + void dataReceived(); + void windowStatusChangeReceived(int status); + void runningStatusChangeReceived(VMManagerProtocol::RunningState state); + void processStatusChanged(); + void statusRefresh(); +}; + + +#endif //QT_VMMANAGER_SYSTEM_H diff --git a/src/qt/win_serial_passthrough.c b/src/qt/win_serial_passthrough.c index c1802ce73..4ea6a1875 100644 --- a/src/qt/win_serial_passthrough.c +++ b/src/qt/win_serial_passthrough.c @@ -13,7 +13,7 @@ * Jasmine Iwanek * * Copyright 2021 Andreas J. Reichel - * Copyright 2021-2023 Jasmine Iwanek + * Copyright 2021-2025 Jasmine Iwanek */ #define _XOPEN_SOURCE 500 @@ -46,9 +46,9 @@ plat_serpt_close(void *priv) fclose(dev->master_fd); #endif FlushFileBuffers((HANDLE) dev->master_fd); - if (dev->mode == SERPT_MODE_VCON) + if (dev->mode == SERPT_MODE_NPIPE_SRV) DisconnectNamedPipe((HANDLE) dev->master_fd); - if (dev->mode == SERPT_MODE_HOSTSER) { + else if (dev->mode == SERPT_MODE_HOSTSER) { SetCommState((HANDLE) dev->master_fd, (DCB *) dev->backend_priv); free(dev->backend_priv); } @@ -133,7 +133,8 @@ plat_serpt_write(void *priv, uint8_t data) serial_passthrough_t *dev = (serial_passthrough_t *) priv; switch (dev->mode) { - case SERPT_MODE_VCON: + case SERPT_MODE_NPIPE_SRV: + case SERPT_MODE_NPIPE_CLNT: case SERPT_MODE_HOSTSER: plat_serpt_write_vcon(dev, data); break; @@ -157,7 +158,8 @@ plat_serpt_read(void *priv, uint8_t *data) int res = 0; switch (dev->mode) { - case SERPT_MODE_VCON: + case SERPT_MODE_NPIPE_SRV: + case SERPT_MODE_NPIPE_CLNT: case SERPT_MODE_HOSTSER: res = plat_serpt_read_vcon(dev, data); break; @@ -187,6 +189,42 @@ open_pseudo_terminal(serial_passthrough_t *dev) return 1; } +static int +connect_named_pipe_client(serial_passthrough_t *dev) +{ + char ascii_pipe_name[1024] = { 0 }; + size_t len = strlen(dev->named_pipe); + if ((len + 1) >= sizeof(ascii_pipe_name)) + memcpy(ascii_pipe_name, dev->named_pipe, sizeof(ascii_pipe_name)); + else + memcpy(ascii_pipe_name, dev->named_pipe, len + 1); + + HANDLE hPipe = CreateFileA( + ascii_pipe_name, // pipe name + GENERIC_READ | GENERIC_WRITE, + 0, // no sharing + NULL, // default security attributes + OPEN_EXISTING, // open existing pipe + 0, // default attributes + NULL); // no template file + + if (hPipe == INVALID_HANDLE_VALUE) { + DWORD error = GetLastError(); + wchar_t errorMsg[1024] = { 0 }; + wchar_t finalMsg[1024] = { 0 }; + FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), errorMsg, 1024, NULL); + swprintf(finalMsg, 1024, L"Named Pipe (client, named_pipe=\"%hs\", port=COM%d): %ls\n", ascii_pipe_name, dev->port + 1, errorMsg); + ui_msgbox(MBX_ERROR | MBX_FATAL, finalMsg); + return 0; + } + + DWORD mode = PIPE_READMODE_BYTE | PIPE_NOWAIT; + SetNamedPipeHandleState(hPipe, &mode, NULL, NULL); + dev->master_fd = (intptr_t) hPipe; + pclog("Named Pipe client connected to %s\n", ascii_pipe_name); + return 1; +} + static int open_host_serial_port(serial_passthrough_t *dev) { @@ -222,15 +260,18 @@ plat_serpt_open_device(void *priv) serial_passthrough_t *dev = (serial_passthrough_t *) priv; switch (dev->mode) { - case SERPT_MODE_VCON: - if (open_pseudo_terminal(dev)) { + case SERPT_MODE_NPIPE_SRV: + if (open_pseudo_terminal(dev)) + return 0; + break; + case SERPT_MODE_NPIPE_CLNT: + if (connect_named_pipe_client(dev)) return 0; - } break; case SERPT_MODE_HOSTSER: - if (open_host_serial_port(dev)) { + if (open_host_serial_port(dev)) return 0; - } + break; default: break; } diff --git a/src/qt/wl_mouse.cpp b/src/qt/wl_mouse.cpp index 9201c4ec8..6f90bac18 100644 --- a/src/qt/wl_mouse.cpp +++ b/src/qt/wl_mouse.cpp @@ -50,12 +50,6 @@ static struct zwp_relative_pointer_v1_listener rel_listener = { rel_mouse_event }; -static struct zwp_keyboard_shortcuts_inhibitor_v1_listener kbd_listener -{ - [](void *data, struct zwp_keyboard_shortcuts_inhibitor_v1 *zwp_keyboard_shortcuts_inhibitor_v1) -> void {}, - [](void *data, struct zwp_keyboard_shortcuts_inhibitor_v1 *zwp_keyboard_shortcuts_inhibitor_v1) -> void {} -}; - static void display_handle_global(void *data, struct wl_registry *registry, uint32_t id, const char *interface, uint32_t version) diff --git a/src/qt_resources.qrc b/src/qt_resources.qrc index a5963c152..51518b8f6 100644 --- a/src/qt_resources.qrc +++ b/src/qt_resources.qrc @@ -59,4 +59,95 @@ qt/texture_vert.spv qt/texture_frag.spv + + qt/assets/86Box-green.png + qt/assets/86box-rb.png + qt/assets/86box-red.png + qt/assets/86box-yellow.png + qt/assets/86box.png + qt/assets/86box-wizard.png + + + qt/assets/systemicons/cpq_deskpro.png + qt/assets/systemicons/cpq_port_386.png + qt/assets/systemicons/cpq_port_II.png + qt/assets/systemicons/cpq_port_III.png + qt/assets/systemicons/cpq_portable.png + qt/assets/systemicons/cpq_pres_2240.png + qt/assets/systemicons/cpq_pres_4500.png + qt/assets/systemicons/ibm330.png + qt/assets/systemicons/ibm_at.png + qt/assets/systemicons/ibm_pc_81.png + qt/assets/systemicons/ibm_pc_82.png + qt/assets/systemicons/ibm_pcjr.png + qt/assets/systemicons/ibm_ps2_m70.png + qt/assets/systemicons/ibm_ps2_m80.png + qt/assets/systemicons/ibm_psvp_486.png + qt/assets/systemicons/ibm_psvp_p60.png + qt/assets/systemicons/ibm_xt_82.png + qt/assets/systemicons/ibm_xt_86.png + qt/assets/systemicons/olivetti_m19.png + qt/assets/systemicons/olivetti_m21.png + qt/assets/systemicons/olivetti_m24.png + qt/assets/systemicons/olivetti_m24sp.png + qt/assets/systemicons/os_archlinux_x2.png + qt/assets/systemicons/os_cloud_x2.png + qt/assets/systemicons/os_debian_x2.png + qt/assets/systemicons/os_dos_x2.png + qt/assets/systemicons/os_fedora_x2.png + qt/assets/systemicons/os_freebsd_x2.png + qt/assets/systemicons/os_gentoo_x2.png + qt/assets/systemicons/os_jrockitve_x2.png + qt/assets/systemicons/os_l4_x2.png + qt/assets/systemicons/os_linux22_x2.png + qt/assets/systemicons/os_linux24_x2.png + qt/assets/systemicons/os_linux26_x2.png + qt/assets/systemicons/os_linux_x2.png + qt/assets/systemicons/os_macosx_x2.png + qt/assets/systemicons/os_mandriva_x2.png + qt/assets/systemicons/os_netbsd_x2.png + qt/assets/systemicons/os_netware_x2.png + qt/assets/systemicons/os_openbsd_x2.png + qt/assets/systemicons/os_opensuse_x2.png + qt/assets/systemicons/os_oracle_x2.png + qt/assets/systemicons/os_oraclesolaris_x2.png + qt/assets/systemicons/os_os2_other_x2.png + qt/assets/systemicons/os_os2ecs_x2.png + qt/assets/systemicons/os_os2warp3_x2.png + qt/assets/systemicons/os_os2warp45_x2.png + qt/assets/systemicons/os_os2warp4_x2.png + qt/assets/systemicons/os_other_x2.png + qt/assets/systemicons/os_qnx_x2.png + qt/assets/systemicons/os_redhat_x2.png + qt/assets/systemicons/os_solaris_x2.png + qt/assets/systemicons/os_turbolinux_x2.png + qt/assets/systemicons/os_ubuntu_x2.png + qt/assets/systemicons/os_win10_x2.png + qt/assets/systemicons/os_win2k3_x2.png + qt/assets/systemicons/os_win2k8_x2.png + qt/assets/systemicons/os_win2k_x2.png + qt/assets/systemicons/os_win31_x2.png + qt/assets/systemicons/os_win7_x2.png + qt/assets/systemicons/os_win81_x2.png + qt/assets/systemicons/os_win8_x2.png + qt/assets/systemicons/os_win95_x2.png + qt/assets/systemicons/os_win98_x2.png + qt/assets/systemicons/os_win_other_x2.png + qt/assets/systemicons/os_winme_x2.png + qt/assets/systemicons/os_winnt4_x2.png + qt/assets/systemicons/os_winvista_x2.png + qt/assets/systemicons/os_winxp_x2.png + qt/assets/systemicons/os_xandros_x2.png + qt/assets/systemicons/pb_bora_pro.png + qt/assets/systemicons/pb_pb410.png + qt/assets/systemicons/pb_pb640.png + qt/assets/systemicons/pb_pb680.png + qt/assets/systemicons/tandy_1000.png + qt/assets/systemicons/tandy_1000_hx.png + qt/assets/systemicons/tandy_1000_sl2.png + qt/assets/systemicons/toshiba_t1000.png + qt/assets/systemicons/toshiba_t1200.png + qt/assets/systemicons/toshiba_t1200_hdd.png + + diff --git a/src/scsi/scsi.c b/src/scsi/scsi.c index bbce63651..0b0ca7211 100644 --- a/src/scsi/scsi.c +++ b/src/scsi/scsi.c @@ -54,6 +54,14 @@ typedef const struct { static SCSI_CARD scsi_cards[] = { // clang-format off { &device_none, }, + /* ISA/Sidecar */ + { &scsi_ls2000_device, }, + /* ISA */ + { &scsi_lcs6821n_device, }, + { &scsi_rt1000b_device, }, + { &scsi_t128_device, }, + { &scsi_t130b_device, }, + /* ISA16 */ { &aha154xa_device, }, { &aha154xb_device, }, { &aha154xc_device, }, @@ -63,18 +71,19 @@ static SCSI_CARD scsi_cards[] = { { &buslogic_542bh_device, }, { &buslogic_545s_device, }, { &buslogic_545c_device, }, - { &scsi_ls2000_device, }, - { &scsi_lcs6821n_device, }, - { &scsi_rt1000b_device, }, - { &scsi_rt1000mc_device, }, - { &scsi_t128_device, }, - { &scsi_t228_device, }, - { &scsi_t130b_device, }, + /* MCA */ { &aha1640_device, }, { &buslogic_640a_device, }, - { &ncr53c90a_mca_device, }, { &spock_device, }, { &tribble_device, }, + { &ncr53c90a_mca_device, }, + { &scsi_rt1000mc_device, }, + { &scsi_t228_device, }, + /* VLB */ + { &buslogic_445s_device, }, + { &buslogic_445c_device, }, + /* PCI */ + { &am53c974_pci_device, }, { &buslogic_958d_pci_device, }, { &ncr53c810_pci_device, }, { &ncr53c815_pci_device, }, @@ -82,10 +91,7 @@ static SCSI_CARD scsi_cards[] = { { &ncr53c825a_pci_device, }, { &ncr53c860_pci_device, }, { &ncr53c875_pci_device, }, - { &am53c974_pci_device, }, { &dc390_pci_device, }, - { &buslogic_445s_device, }, - { &buslogic_445c_device, }, { NULL, }, // clang-format on }; diff --git a/src/sio/sio_ali5123.c b/src/sio/sio_ali5123.c index 398d00839..436e425d2 100644 --- a/src/sio/sio_ali5123.c +++ b/src/sio/sio_ali5123.c @@ -85,11 +85,18 @@ ali5123_lpt_handler(ali5123_t *dev) uint8_t global_enable = !(dev->regs[0x22] & (1 << 3)); uint8_t local_enable = !!dev->ld_regs[3][0x30]; uint8_t lpt_irq = dev->ld_regs[3][0x70]; + uint8_t lpt_dma = dev->ld_regs[3][0x74]; if (lpt_irq > 15) lpt_irq = 0xff; + if (lpt_dma == 4) + lpt_dma = 0xff; + lpt1_remove(); + lpt_set_epp(0, !!(dev->ld_regs[3][0xf0] & 0x01)); + lpt_set_ecp(0, !!(dev->ld_regs[3][0xf0] & 0x02)); + lpt_set_ext(0, !(dev->ld_regs[3][0xf0] & 0x04) || !!(dev->ld_regs[3][0xf1] & 0x80)); if (global_enable && local_enable) { ld_port = make_port(dev, 3) & 0xFFFC; if ((ld_port >= 0x0100) && (ld_port <= 0x0FFC)) @@ -247,7 +254,7 @@ ali5123_write(uint16_t port, uint8_t val, void *priv) dev->regs[dev->cur_reg] = val; } else { valxor = val ^ dev->ld_regs[cur_ld][dev->cur_reg]; - if (((dev->cur_reg & 0xf0) == 0x70) && (cur_ld < 4)) + if (((dev->cur_reg & 0xf0) == 0x70) && (cur_ld < 4) && (cur_ld != 3)) return; /* Block writes to some logical devices. */ if (cur_ld > 0x0c) @@ -357,6 +364,9 @@ ali5123_write(uint16_t port, uint8_t val, void *priv) case 0x60: case 0x61: case 0x70: + case 0x74: + case 0xf0: + case 0xf1: if ((dev->cur_reg == 0x30) && (val & 0x01)) dev->regs[0x22] &= ~0x08; if (valxor) diff --git a/src/sio/sio_pc87306.c b/src/sio/sio_pc87306.c index 41d69b0cc..e42c48ab4 100644 --- a/src/sio/sio_pc87306.c +++ b/src/sio/sio_pc87306.c @@ -121,6 +121,10 @@ lpt1_handler(pc87306_t *dev) uint16_t lptba; uint16_t lpt_port = LPT1_ADDR; uint8_t lpt_irq = LPT2_IRQ; + uint8_t lpt_dma = ((dev->regs[0x18] & 0x06) >> 1); + + if (lpt_dma == 0x00) + lpt_dma = 0xff; temp = dev->regs[0x01] & 3; lptba = ((uint16_t) dev->regs[0x19]) << 2; @@ -157,6 +161,13 @@ lpt1_handler(pc87306_t *dev) lpt1_setup(lpt_port); lpt1_irq(lpt_irq); + + lpt_port_dma(0, lpt_dma); + + lpt_set_ext(0, !!(dev->regs[0x02] & 0x80)); + + lpt_set_epp(0, !!(dev->regs[0x04] & 0x01)); + lpt_set_ecp(0, !!(dev->regs[0x04] & 0x04)); } static void @@ -169,7 +180,7 @@ serial_handler(pc87306_t *dev, int uart) uint8_t pnp_shift; uint8_t irq; - temp = (dev->regs[1] >> (2 << uart)) & 3; + temp = (dev->regs[0x01] >> (2 << uart)) & 3; fer_shift = 2 << uart; /* 2 for UART 1, 4 for UART 2 */ pnp_shift = 2 + (uart << 2); /* 2 for UART 1, 6 for UART 2 */ @@ -188,7 +199,7 @@ serial_handler(pc87306_t *dev, int uart) serial_setup(dev->uart[uart], COM2_ADDR, irq); break; case 2: - switch ((dev->regs[1] >> 6) & 3) { + switch ((dev->regs[0x01] >> 6) & 3) { case 0: serial_setup(dev->uart[uart], COM3_ADDR, irq); break; @@ -207,7 +218,7 @@ serial_handler(pc87306_t *dev, int uart) } break; case 3: - switch ((dev->regs[1] >> 6) & 3) { + switch ((dev->regs[0x01] >> 6) & 3) { case 0: serial_setup(dev->uart[uart], COM4_ADDR, irq); break; @@ -264,41 +275,41 @@ pc87306_write(uint16_t port, uint8_t val, void *priv) switch (dev->cur_reg) { case 0x00: - if (valxor & 1) { + if (valxor & 0x01) { lpt1_remove(); - if ((val & 1) && !(dev->regs[2] & 1)) + if ((val & 1) && !(dev->regs[0x02] & 1)) lpt1_handler(dev); } - if (valxor & 2) { - serial_remove(dev->uart[0]); - if ((val & 2) && !(dev->regs[2] & 1)) + if (valxor & 0x02) { + serial_remove(dev->uart[0x00]); + if ((val & 2) && !(dev->regs[0x02] & 1)) serial_handler(dev, 0); } - if (valxor & 4) { - serial_remove(dev->uart[1]); - if ((val & 4) && !(dev->regs[2] & 1)) + if (valxor & 0x04) { + serial_remove(dev->uart[0x01]); + if ((val & 4) && !(dev->regs[0x02] & 1)) serial_handler(dev, 1); } if (valxor & 0x28) { fdc_remove(dev->fdc); - if ((val & 8) && !(dev->regs[2] & 1)) + if ((val & 8) && !(dev->regs[0x02] & 1)) fdc_set_base(dev->fdc, (val & 0x20) ? FDC_SECONDARY_ADDR : FDC_PRIMARY_ADDR); } break; case 0x01: - if (valxor & 3) { + if (valxor & 0x03) { lpt1_remove(); - if ((dev->regs[0] & 1) && !(dev->regs[2] & 1)) + if ((dev->regs[0x00] & 1) && !(dev->regs[0x02] & 1)) lpt1_handler(dev); } if (valxor & 0xcc) { - serial_remove(dev->uart[0]); - if ((dev->regs[0] & 2) && !(dev->regs[2] & 1)) + serial_remove(dev->uart[0x00]); + if ((dev->regs[0x00] & 2) && !(dev->regs[0x02] & 1)) serial_handler(dev, 0); } if (valxor & 0xf0) { - serial_remove(dev->uart[1]); - if ((dev->regs[0] & 4) && !(dev->regs[2] & 1)) + serial_remove(dev->uart[0x01]); + if ((dev->regs[0x00] & 4) && !(dev->regs[0x02] & 1)) serial_handler(dev, 1); } break; @@ -327,6 +338,11 @@ pc87306_write(uint16_t port, uint8_t val, void *priv) } break; case 0x04: + if (valxor & (0x05)) { + lpt1_remove(); + if ((dev->regs[0x00] & 0x01) && !(dev->regs[0x02] & 0x01)) + lpt1_handler(dev); + } if (valxor & 0x80) nvr_lock_set(0x00, 256, !!(val & 0x80), dev->nvr); break; @@ -352,10 +368,17 @@ pc87306_write(uint16_t port, uint8_t val, void *priv) if (valxor & 0x30) pc87306_gpio_handler(dev); break; + case 0x18: + if (valxor & (0x06)) { + lpt1_remove(); + if ((dev->regs[0x00] & 0x01) && !(dev->regs[0x02] & 0x01)) + lpt1_handler(dev); + } + break; case 0x19: if (valxor) { lpt1_remove(); - if ((dev->regs[0] & 1) && !(dev->regs[2] & 1)) + if ((dev->regs[0x00] & 1) && !(dev->regs[0x02] & 1)) lpt1_handler(dev); } break; @@ -364,18 +387,18 @@ pc87306_write(uint16_t port, uint8_t val, void *priv) lpt1_remove(); if (!(val & 0x40)) dev->regs[0x19] = 0xEF; - if ((dev->regs[0] & 1) && !(dev->regs[2] & 1)) + if ((dev->regs[0x00] & 1) && !(dev->regs[0x02] & 1)) lpt1_handler(dev); } break; case 0x1c: if (valxor) { - serial_remove(dev->uart[0]); - serial_remove(dev->uart[1]); + serial_remove(dev->uart[0x00]); + serial_remove(dev->uart[0x01]); - if ((dev->regs[0] & 2) && !(dev->regs[2] & 1)) + if ((dev->regs[0x00] & 2) && !(dev->regs[0x02] & 1)) serial_handler(dev, 0); - if ((dev->regs[0] & 4) && !(dev->regs[2] & 1)) + if ((dev->regs[0x00] & 4) && !(dev->regs[0x02] & 1)) serial_handler(dev, 1); } break; @@ -432,8 +455,8 @@ pc87306_reset_common(void *priv) */ lpt1_remove(); lpt1_handler(dev); - serial_remove(dev->uart[0]); - serial_remove(dev->uart[1]); + serial_remove(dev->uart[0x00]); + serial_remove(dev->uart[0x01]); serial_handler(dev, 0); serial_handler(dev, 1); fdc_reset(dev->fdc); @@ -471,8 +494,8 @@ pc87306_init(UNUSED(const device_t *info)) dev->fdc = device_add(&fdc_at_nsc_device); - dev->uart[0] = device_add_inst(&ns16550_device, 1); - dev->uart[1] = device_add_inst(&ns16550_device, 2); + dev->uart[0x00] = device_add_inst(&ns16550_device, 1); + dev->uart[0x01] = device_add_inst(&ns16550_device, 2); dev->nvr = device_add(&at_mb_nvr_device); diff --git a/src/sio/sio_pc87310.c b/src/sio/sio_pc87310.c index 5bd595f05..ae0f5d977 100644 --- a/src/sio/sio_pc87310.c +++ b/src/sio/sio_pc87310.c @@ -40,9 +40,6 @@ #include <86box/sio.h> #include <86box/plat_unused.h> -#define FLAG_IDE 0x00000001 -#define FLAG_ALI 0x00000002 - #ifdef ENABLE_PC87310_LOG int pc87310_do_log = ENABLE_PC87310_LOG; @@ -137,7 +134,7 @@ serial_handler(pc87310_t *dev) * Then they become simple toggle bits. * Therefore, we do this for easier operation. */ - if (dev->flags & FLAG_ALI) { + if (dev->flags & PC87310_ALI) { temp2 = dev->regs[0] & 0x03; temp2 ^= ((temp2 & 0x02) >> 1); } @@ -197,7 +194,7 @@ pc87310_write(UNUSED(uint16_t port), uint8_t val, void *priv) serial_handler(dev); /* Reconfigure IDE controller. */ - if ((dev->flags & FLAG_IDE) && (valxor & 0x20)) { + if ((dev->flags & PC87310_IDE) && (valxor & 0x20)) { pc87310_log("SIO: HDC disabled\n"); ide_pri_disable(); /* Bit 5: 1 = Disable IDE controller. */ @@ -258,7 +255,7 @@ pc87310_reset(pc87310_t *dev) lpt1_handler(dev); serial_handler(dev); - if (dev->flags & FLAG_IDE) { + if (dev->flags & PC87310_IDE) { ide_pri_disable(); ide_pri_enable(); } @@ -286,21 +283,22 @@ pc87310_init(const device_t *info) dev->uart[0] = device_add_inst(&ns16450_device, 1); dev->uart[1] = device_add_inst(&ns16450_device, 2); - if (dev->flags & FLAG_IDE) - device_add((dev->flags & FLAG_ALI) ? &ide_vlb_device : &ide_isa_device); + if (dev->flags & PC87310_IDE) + device_add((dev->flags & PC87310_ALI) ? &ide_vlb_device : &ide_isa_device); pc87310_reset(dev); io_sethandler(0x3f3, 0x0001, pc87310_read, NULL, NULL, pc87310_write, NULL, NULL, dev); - if (dev->flags & FLAG_ALI) + if (dev->flags & PC87310_ALI) io_sethandler(0x3f1, 0x0001, pc87310_read, NULL, NULL, pc87310_write, NULL, NULL, dev); return dev; } +/* The ALi M5105 is an extended clone of this. */ const device_t pc87310_device = { .name = "National Semiconductor PC87310 Super I/O", .internal_name = "pc87310", @@ -314,31 +312,3 @@ const device_t pc87310_device = { .force_redraw = NULL, .config = NULL }; - -const device_t pc87310_ide_device = { - .name = "National Semiconductor PC87310 Super I/O with IDE functionality", - .internal_name = "pc87310_ide", - .flags = 0, - .local = FLAG_IDE, - .init = pc87310_init, - .close = pc87310_close, - .reset = NULL, - .available = NULL, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; - -const device_t ali5105_device = { - .name = "ALi M5105 Super I/O", - .internal_name = "ali5105", - .flags = 0, - .local = FLAG_ALI, - .init = pc87310_init, - .close = pc87310_close, - .reset = NULL, - .available = NULL, - .speed_changed = NULL, - .force_redraw = NULL, - .config = NULL -}; diff --git a/src/sio/sio_um8663f.c b/src/sio/sio_um8663f.c index 54f12dda6..6075fe3e7 100644 --- a/src/sio/sio_um8663f.c +++ b/src/sio/sio_um8663f.c @@ -274,13 +274,70 @@ um8663f_init(UNUSED(const device_t *info)) dev->max_reg = info->local >> 8; - io_sethandler(0x0108, 0x0002, um8663f_read, NULL, NULL, um8663f_write, NULL, NULL, dev); + if (dev->max_reg != 0x00) + io_sethandler(0x0108, 0x0002, um8663f_read, NULL, NULL, um8663f_write, NULL, NULL, dev); um8663f_reset(dev); return dev; } +const device_t um82c862f_device = { + .name = "UMC UM82C862F Super I/O", + .internal_name = "um82c862f", + .flags = 0, + .local = 0x0000, + .init = um8663f_init, + .close = um8663f_close, + .reset = um8663f_reset, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t um82c862f_ide_device = { + .name = "UMC UM82C862F Super I/O (With IDE)", + .internal_name = "um82c862f_ide", + .flags = 0, + .local = 0x0001, + .init = um8663f_init, + .close = um8663f_close, + .reset = um8663f_reset, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t um82c863f_device = { + .name = "UMC UM82C863F Super I/O", + .internal_name = "um82c863f", + .flags = 0, + .local = 0xc100, + .init = um8663f_init, + .close = um8663f_close, + .reset = um8663f_reset, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t um82c863f_ide_device = { + .name = "UMC UM82C863F Super I/O (With IDE)", + .internal_name = "um82c863f_ide", + .flags = 0, + .local = 0xc101, + .init = um8663f_init, + .close = um8663f_close, + .reset = um8663f_reset, + .available = NULL, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + const device_t um8663af_device = { .name = "UMC UM8663AF Super I/O", .internal_name = "um8663af", diff --git a/src/sound/snd_lpt_dac.c b/src/sound/snd_lpt_dac.c index 0462818a0..13a430c91 100644 --- a/src/sound/snd_lpt_dac.c +++ b/src/sound/snd_lpt_dac.c @@ -50,6 +50,14 @@ dac_write_data(uint8_t val, void *priv) dac_update(lpt_dac); } +static void +dac_strobe(uint8_t old, uint8_t val, void *priv) +{ + lpt_dac_t *lpt_dac = (lpt_dac_t *) priv; + + lpt_dac->channel = val; +} + static void dac_write_ctrl(uint8_t val, void *priv) { @@ -109,25 +117,31 @@ dac_close(void *priv) } const lpt_device_t lpt_dac_device = { - .name = "LPT DAC / Covox Speech Thing", - .internal_name = "lpt_dac", - .init = dac_init, - .close = dac_close, - .write_data = dac_write_data, - .write_ctrl = dac_write_ctrl, - .read_data = NULL, - .read_status = dac_read_status, - .read_ctrl = NULL + .name = "LPT DAC / Covox Speech Thing", + .internal_name = "lpt_dac", + .init = dac_init, + .close = dac_close, + .write_data = dac_write_data, + .write_ctrl = dac_write_ctrl, + .autofeed = NULL, + .strobe = dac_strobe, + .read_status = dac_read_status, + .read_ctrl = NULL, + .epp_write_data = NULL, + .epp_request_read = NULL }; const lpt_device_t lpt_dac_stereo_device = { - .name = "Stereo LPT DAC", - .internal_name = "lpt_dac_stereo", - .init = dac_stereo_init, - .close = dac_close, - .write_data = dac_write_data, - .write_ctrl = dac_write_ctrl, - .read_data = NULL, - .read_status = dac_read_status, - .read_ctrl = NULL + .name = "Stereo LPT DAC", + .internal_name = "lpt_dac_stereo", + .init = dac_stereo_init, + .close = dac_close, + .write_data = dac_write_data, + .write_ctrl = dac_write_ctrl, + .autofeed = NULL, + .strobe = dac_strobe, + .read_status = dac_read_status, + .read_ctrl = NULL, + .epp_write_data = NULL, + .epp_request_read = NULL }; diff --git a/src/sound/snd_lpt_dss.c b/src/sound/snd_lpt_dss.c index 875230518..b609e3add 100644 --- a/src/sound/snd_lpt_dss.c +++ b/src/sound/snd_lpt_dss.c @@ -133,13 +133,16 @@ dss_close(void *priv) } const lpt_device_t dss_device = { - .name = "Disney Sound Source", - .internal_name = "dss", - .init = dss_init, - .close = dss_close, - .write_data = dss_write_data, - .write_ctrl = dss_write_ctrl, - .read_data = NULL, - .read_status = dss_read_status, - .read_ctrl = NULL + .name = "Disney Sound Source", + .internal_name = "dss", + .init = dss_init, + .close = dss_close, + .write_data = dss_write_data, + .autofeed = NULL, + .strobe = NULL, + .write_ctrl = dss_write_ctrl, + .read_status = dss_read_status, + .read_ctrl = NULL, + .epp_write_data = NULL, + .epp_request_read = NULL }; diff --git a/src/sound/snd_resid.cpp b/src/sound/snd_resid.cpp index b0503cac2..3dda5363b 100644 --- a/src/sound/snd_resid.cpp +++ b/src/sound/snd_resid.cpp @@ -20,23 +20,28 @@ typedef struct psid_t { psid_t *psid; void * -sid_init(uint8_t type) +sid_init(uint8_t type, double range) { reSIDfp::SamplingMethod method = reSIDfp::RESAMPLE; float cycles_per_sec = 14318180.0 / 16.0; psid = new psid_t; psid->sid = new SID; - + psid->sid->setFilter6581Range(range); + psid->sid->reset(); switch (type) { default: + psid->sid->setChipModel(reSIDfp::MOS6581); + break; case 0: psid->sid->setChipModel(reSIDfp::MOS6581); + break; case 1: psid->sid->setChipModel(reSIDfp::MOS8580); + break; } - psid->sid->reset(); + for (uint8_t c = 0; c < 32; c++) psid->sid->write(c, 0); @@ -101,4 +106,4 @@ sid_fillbuf(int16_t *buf, int len, UNUSED(void *priv)) int x = CLOCK_DELTA(len); fillbuf2(x, buf, len); -} +} \ No newline at end of file diff --git a/src/sound/snd_ssi2001.c b/src/sound/snd_ssi2001.c index f1620b817..9cc41c504 100644 --- a/src/sound/snd_ssi2001.c +++ b/src/sound/snd_ssi2001.c @@ -72,7 +72,7 @@ ssi2001_init(UNUSED(const device_t *info)) { ssi2001_t *ssi2001 = calloc(1, sizeof(ssi2001_t)); - ssi2001->psid = sid_init(0); + ssi2001->psid = sid_init(device_get_config_int("sid_config"),device_get_config_int("sid_adjustment")); sid_reset(ssi2001->psid); uint16_t addr = device_get_config_hex16("base"); ssi2001->gameport_enabled = device_get_config_int("gameport"); @@ -112,7 +112,7 @@ entertainer_init(UNUSED(const device_t *info)) ssi2001_t *ssi2001 = calloc(1, sizeof(ssi2001_t)); entertainer_t *entertainer = calloc(1, sizeof(entertainer_t)); - ssi2001->psid = sid_init(0); + ssi2001->psid = sid_init(0, 0.5); sid_reset(ssi2001->psid); ssi2001->gameport_enabled = device_get_config_int("gameport"); io_sethandler(0x200, 0x0001, entertainer_read, NULL, NULL, entertainer_write, NULL, NULL, entertainer); @@ -163,6 +163,33 @@ static const device_config_t ssi2001_config[] = { .selection = { { 0 } }, .bios = { { 0 } } }, + + { + .name = "sid_config", + .description = "SID Model", + .type = CONFIG_HEX16, + .default_string = NULL, + .default_int = 0x000, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "8580", .value = 0x001 }, + { .description = "6581", .value = 0x000 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { + .name = "sid_adjustment", + .description = "SID Filter Strength", + .type = CONFIG_STRING, + .default_string = "0.5", + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = {{"0.5"}}, + .bios = { { 0 } } + }, { .name = "", .description = "", .type = CONFIG_END } // clang-format off }; diff --git a/src/sound/sound.c b/src/sound/sound.c index 7bf27a136..615df88bc 100644 --- a/src/sound/sound.c +++ b/src/sound/sound.c @@ -100,31 +100,45 @@ static const SOUND_CARD sound_cards[] = { // clang-format off { &device_none }, { &device_internal }, - { &acermagic_s20_device }, - { &mirosound_pcm10_device }, - { &adlib_device }, + /* ISA */ { &adgold_device }, - { &azt2316a_device }, - { &azt1605_device }, { &cms_device }, - { &cs4235_device }, - { &cs4236b_device }, { &ess_688_device }, { &ess_ess0100_pnp_device }, { &ess_1688_device }, { &ess_ess0102_pnp_device }, { &ess_ess0968_pnp_device }, - { &gus_device }, - { &gus_max_device }, + { &ssi2001_device }, + { &mmb_device }, + { &pasplus_device }, { &sb_1_device }, { &sb_15_device }, { &sb_2_device }, { &sb_pro_v1_device }, { &sb_pro_v2_device }, + { &entertainer_device }, + { &pssj_isa_device }, + { &tndy_device }, +#ifdef USE_LIBSERIALPORT /*The following devices required LIBSERIALPORT*/ + { &opl2board_device }, +#endif + /* ISA/Sidecar */ + { &adlib_device }, + /* ISA16 */ + { &acermagic_s20_device }, + { &azt2316a_device }, + { &azt1605_device }, + { &sb_goldfinch_device }, + { &cs4235_device }, + { &cs4236b_device }, + { &gus_device }, + { &gus_max_device }, + { &mirosound_pcm10_device }, + { &pas16_device }, + { &pas16d_device }, { &sb_16_device }, { &sb_16_pnp_device }, { &sb_16_pnp_ide_device }, - { &sb_goldfinch_device }, { &sb_32_pnp_device }, { &sb_awe32_device }, { &sb_awe32_pnp_device }, @@ -136,15 +150,8 @@ static const SOUND_CARD sound_cards[] = { { &sb_vibra16cl_device }, { &sb_vibra16s_device }, { &sb_vibra16xv_device }, - { &ssi2001_device }, - { &entertainer_device }, - { &mmb_device }, - { &pasplus_device }, - { &pas16_device }, - { &pas16d_device }, - { &pssj_isa_device }, - { &tndy_device }, { &wss_device }, + /* MCA */ { &adlib_mca_device }, { &ess_chipchat_16_mca_device }, { &ncr_business_audio_device }, @@ -153,17 +160,16 @@ static const SOUND_CARD sound_cards[] = { { &sb_16_reply_mca_device }, { &ess_soundpiper_16_mca_device }, { &ess_soundpiper_32_mca_device }, + /* PCI */ { &cmi8338_device }, { &cmi8738_device }, { &es1370_device }, { &es1371_device }, { &es1373_device }, { &ct5880_device }, + /* AC97 */ { &ad1881_device }, { &cs4297a_device }, -#ifdef USE_LIBSERIALPORT /*The following devices required LIBSERIALPORT*/ - { &opl2board_device }, -#endif { NULL } // clang-format on }; diff --git a/src/unix/dummy_cdrom_ioctl.c b/src/unix/dummy_cdrom_ioctl.c index bddfabb5b..8dffc6758 100644 --- a/src/unix/dummy_cdrom_ioctl.c +++ b/src/unix/dummy_cdrom_ioctl.c @@ -162,6 +162,7 @@ ioctl_is_empty(const void *local) return 1; } +#if 0 static int ioctl_ext_medium_changed(UNUSED(void *local)) { @@ -174,6 +175,7 @@ ioctl_ext_medium_changed(UNUSED(void *local)) return ret; } +#endif static void ioctl_close(void *local) diff --git a/src/unix/unix.c b/src/unix/unix.c index 2e92a90d3..2bbbda067 100644 --- a/src/unix/unix.c +++ b/src/unix/unix.c @@ -208,22 +208,33 @@ dynld_module(const char *name, dllimp_t *table) return modhandle; } +#define TMPFILE_BUFSIZE 1024 // Assumed max buffer size void plat_tempfile(char *bufp, char *prefix, char *suffix) { struct tm *calendertime; struct timeval t; time_t curtime; + size_t used = 0; if (prefix != NULL) - sprintf(bufp, "%s-", prefix); - else - strcpy(bufp, ""); + used = snprintf(bufp, TMPFILE_BUFSIZE, "%s-", prefix); + else if (TMPFILE_BUFSIZE > 0) + bufp[0] = '\0'; + gettimeofday(&t, NULL); curtime = time(NULL); calendertime = localtime(&curtime); - sprintf(&bufp[strlen(bufp)], "%d%02d%02d-%02d%02d%02d-%03ld%s", calendertime->tm_year, calendertime->tm_mon, calendertime->tm_mday, calendertime->tm_hour, calendertime->tm_min, calendertime->tm_sec, t.tv_usec / 1000, suffix); + + if (used < TMPFILE_BUFSIZE) { + snprintf(bufp + used, TMPFILE_BUFSIZE - used, + "%d%02d%02d-%02d%02d%02d-%03" PRId32 "%s", + calendertime->tm_year, calendertime->tm_mon, calendertime->tm_mday, + calendertime->tm_hour, calendertime->tm_min, calendertime->tm_sec, + (int32_t)(t.tv_usec / 1000), suffix); + } } +#undef TMPFILE_BUFSIZE int plat_getcwd(char *bufp, int max) @@ -783,65 +794,83 @@ plat_pause(int p) } } +#define TMP_PATH_BUFSIZE 1024 void plat_init_rom_paths(void) { #ifndef __APPLE__ - if (getenv("XDG_DATA_HOME")) { - char xdg_rom_path[1024] = { 0 }; - - strncpy(xdg_rom_path, getenv("XDG_DATA_HOME"), 1024); - path_slash(xdg_rom_path); - strncat(xdg_rom_path, "86Box/", 1023); - - if (!plat_dir_check(xdg_rom_path)) + const char *xdg_data_home = getenv("XDG_DATA_HOME"); + if (xdg_data_home) { + char xdg_rom_path[TMP_PATH_BUFSIZE] = {0}; + size_t used = snprintf(xdg_rom_path, sizeof(xdg_rom_path), "%s/", xdg_data_home); + if (used < sizeof(xdg_rom_path)) + used += snprintf(xdg_rom_path + used, sizeof(xdg_rom_path) - used, "86Box/"); + if (used < sizeof(xdg_rom_path) && !plat_dir_check(xdg_rom_path)) plat_dir_create(xdg_rom_path); - strcat(xdg_rom_path, "roms/"); - - if (!plat_dir_check(xdg_rom_path)) + if (used < sizeof(xdg_rom_path)) + used += snprintf(xdg_rom_path + used, sizeof(xdg_rom_path) - used, "roms/"); + if (used < sizeof(xdg_rom_path) && !plat_dir_check(xdg_rom_path)) plat_dir_create(xdg_rom_path); - rom_add_path(xdg_rom_path); + if (used < sizeof(xdg_rom_path)) + rom_add_path(xdg_rom_path); } else { - char home_rom_path[1024] = { 0 }; - - snprintf(home_rom_path, 1024, "%s/.local/share/86Box/", getenv("HOME") ? getenv("HOME") : getpwuid(getuid())->pw_dir); - - if (!plat_dir_check(home_rom_path)) - plat_dir_create(home_rom_path); - strcat(home_rom_path, "roms/"); - - if (!plat_dir_check(home_rom_path)) - plat_dir_create(home_rom_path); - rom_add_path(home_rom_path); - } - if (getenv("XDG_DATA_DIRS")) { - char *xdg_rom_paths = strdup(getenv("XDG_DATA_DIRS")); - char *xdg_rom_paths_orig = xdg_rom_paths; - char *cur_xdg_rom_path = NULL; - - if (xdg_rom_paths) { - while (xdg_rom_paths[strlen(xdg_rom_paths) - 1] == ':') { - xdg_rom_paths[strlen(xdg_rom_paths) - 1] = '\0'; - } - while ((cur_xdg_rom_path = local_strsep(&xdg_rom_paths, ":")) != NULL) { - char real_xdg_rom_path[1024] = { '\0' }; - strcat(real_xdg_rom_path, cur_xdg_rom_path); - path_slash(real_xdg_rom_path); - strcat(real_xdg_rom_path, "86Box/roms/"); - rom_add_path(real_xdg_rom_path); - } + const char *home = getenv("HOME"); + if (!home) { + struct passwd *pw = getpwuid(getuid()); + if (pw) + home = pw->pw_dir; + } + + if (home) { + char home_rom_path[TMP_PATH_BUFSIZE] = {0}; + size_t used = snprintf(home_rom_path, sizeof(home_rom_path), + "%s/.local/share/86Box/", home); + if (used < sizeof(home_rom_path) && !plat_dir_check(home_rom_path)) + plat_dir_create(home_rom_path); + if (used < sizeof(home_rom_path)) + used += snprintf(home_rom_path + used, + sizeof(home_rom_path) - used, "roms/"); + if (used < sizeof(home_rom_path) && !plat_dir_check(home_rom_path)) + plat_dir_create(home_rom_path); + if (used < sizeof(home_rom_path)) + rom_add_path(home_rom_path); + } + } + + const char *xdg_data_dirs = getenv("XDG_DATA_DIRS"); + if (xdg_data_dirs) { + char *xdg_rom_paths = strdup(xdg_data_dirs); + if (xdg_rom_paths) { + // Trim trailing colons + size_t len = strlen(xdg_rom_paths); + while (len > 0 && xdg_rom_paths[len - 1] == ':') + xdg_rom_paths[--len] = '\0'; + + char *saveptr = NULL; + char *cur_xdg = strtok_r(xdg_rom_paths, ":", &saveptr); + while (cur_xdg) { + char real_xdg_rom_path[TMP_PATH_BUFSIZE] = {0}; + size_t used = snprintf(real_xdg_rom_path, + sizeof(real_xdg_rom_path), + "%s/86Box/roms/", cur_xdg); + if (used < sizeof(real_xdg_rom_path)) + rom_add_path(real_xdg_rom_path); + cur_xdg = strtok_r(NULL, ":", &saveptr); + } + + free(xdg_rom_paths); } - free(xdg_rom_paths_orig); } else { rom_add_path("/usr/local/share/86Box/roms/"); rom_add_path("/usr/share/86Box/roms/"); } #else - char default_rom_path[1024] = { '\0' }; + char default_rom_path[TMP_PATH_BUFSIZE] = {0}; getDefaultROMPath(default_rom_path); rom_add_path(default_rom_path); #endif } +#undef TMP_PATH_BUFSIZE void plat_get_global_config_dir(char *outbuf, const uint8_t len) diff --git a/src/unix/unix_serial_passthrough.c b/src/unix/unix_serial_passthrough.c index 9929f3298..873c706b9 100644 --- a/src/unix/unix_serial_passthrough.c +++ b/src/unix/unix_serial_passthrough.c @@ -13,7 +13,7 @@ * Jasmine Iwanek * * Copyright 2021 Andreas J. Reichel. - * Copyright 2021-2022 Jasmine Iwanek. + * Copyright 2021-2025 Jasmine Iwanek. */ #ifndef __APPLE__ @@ -310,14 +310,12 @@ plat_serpt_open_device(void *priv) switch (dev->mode) { case SERPT_MODE_VCON: - if (!open_pseudo_terminal(dev)) { + if (!open_pseudo_terminal(dev)) return 1; - } break; case SERPT_MODE_HOSTSER: - if (!open_host_serial_port(dev)) { + if (!open_host_serial_port(dev)) return 1; - } break; default: break; diff --git a/src/utils/log.c b/src/utils/log.c index 257029b51..f10dff56b 100644 --- a/src/utils/log.c +++ b/src/utils/log.c @@ -106,7 +106,6 @@ log_out(void *priv, const char *fmt, va_list ap) { log_t *log = (log_t *) priv; char temp[1024]; - char fmt2[1024]; if (log == NULL) pclog("WARNING: Logging called with a NULL log pointer\n"); @@ -115,18 +114,20 @@ log_out(void *priv, const char *fmt, va_list ap) else if (fmt[0] != '\0') { log_ensure_stdlog_open(); - vsprintf(temp, fmt, ap); + vsnprintf(temp, sizeof(temp), fmt, ap); + if (log->suppr_seen && !strcmp(log->buff, temp)) log->seen++; else { if (log->suppr_seen && log->seen) { - log_copy(log, fmt2, "*** %d repeats ***\n", 1024); - fprintf(stdlog, fmt2, log->seen); + fprintf(stdlog, "*** %d repeats ***\n", log->seen); } log->seen = 0; - strcpy(log->buff, temp); - log_copy(log, fmt2, temp, 1024); - fprintf(stdlog, fmt2, ap); + + strncpy(log->buff, temp, sizeof(log->buff) - 1); + log->buff[sizeof(log->buff) - 1] = '\0'; + + fprintf(stdlog, "%s", temp); } fflush(stdlog); diff --git a/src/video/ramdac/vid_ramdac_ati68860.c b/src/video/ramdac/vid_ramdac_ati68860.c index e3e486d57..4411f2ee2 100644 --- a/src/video/ramdac/vid_ramdac_ati68860.c +++ b/src/video/ramdac/vid_ramdac_ati68860.c @@ -67,22 +67,22 @@ typedef struct ati68860_ramdac_t { } ati68860_ramdac_t; void -ati68860_ramdac_out(uint16_t addr, uint8_t val, void *priv, svga_t *svga) +ati68860_ramdac_out(uint16_t addr, uint8_t val, int is_8514, void *priv, svga_t *svga) { ati68860_ramdac_t *ramdac = (ati68860_ramdac_t *) priv; switch (addr) { case 0: - svga_out(0x3c8, val, svga); + svga_out(is_8514 ? 0x2ec : 0x3c8, val, svga); break; case 1: - svga_out(0x3c9, val, svga); + svga_out(is_8514 ? 0x2ed : 0x3c9, val, svga); break; case 2: - svga_out(0x3c6, val, svga); + svga_out(is_8514 ? 0x2ea : 0x3c6, val, svga); break; case 3: - svga_out(0x3c7, val, svga); + svga_out(is_8514 ? 0x2eb : 0x3c7, val, svga); break; default: ramdac->regs[addr & 0xf] = val; @@ -172,23 +172,23 @@ ati68860_ramdac_out(uint16_t addr, uint8_t val, void *priv, svga_t *svga) } uint8_t -ati68860_ramdac_in(uint16_t addr, void *priv, svga_t *svga) +ati68860_ramdac_in(uint16_t addr, int is_8514, void *priv, svga_t *svga) { const ati68860_ramdac_t *ramdac = (ati68860_ramdac_t *) priv; uint8_t temp = 0; switch (addr) { case 0: - temp = svga_in(0x3c8, svga); + temp = svga_in(is_8514 ? 0x2ec : 0x3c8, svga); break; case 1: - temp = svga_in(0x3c9, svga); + temp = svga_in(is_8514 ? 0x2ed : 0x3c9, svga); break; case 2: - temp = svga_in(0x3c6, svga); + temp = svga_in(is_8514 ? 0x2ea : 0x3c6, svga); break; case 3: - temp = svga_in(0x3c7, svga); + temp = svga_in(is_8514 ? 0x2eb : 0x3c7, svga); break; case 4: case 8: diff --git a/src/video/ramdac/vid_ramdac_ati68875.c b/src/video/ramdac/vid_ramdac_ati68875.c index 5d573a282..4de0ed3d9 100644 --- a/src/video/ramdac/vid_ramdac_ati68875.c +++ b/src/video/ramdac/vid_ramdac_ati68875.c @@ -38,7 +38,7 @@ typedef struct ati68875_ramdac_t { } ati68875_ramdac_t; void -ati68875_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *priv, svga_t *svga) +ati68875_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, int is_8514, void *priv, svga_t *svga) { ati68875_ramdac_t *ramdac = (ati68875_ramdac_t *) priv; uint8_t rs = (addr & 0x03); @@ -48,10 +48,16 @@ ati68875_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *priv, sv switch (rs) { case 0x00: /* Palette Write Index Register (RS value = 0000) */ + svga_out(is_8514 ? 0x2ec : 0x3c8, val, svga); + break; case 0x01: /* Palette Data Register (RS value = 0001) */ + svga_out(is_8514 ? 0x2ed : 0x3c9, val, svga); + break; case 0x02: /* Pixel Read Mask Register (RS value = 0010) */ - case 0x03: - svga_out(addr, val, svga); + svga_out(is_8514 ? 0x2ea : 0x3c6, val, svga); + break; + case 0x03: /* Palette Read Index Register (RS value = 0011) */ + svga_out(is_8514 ? 0x2eb : 0x3c7, val, svga); break; case 0x08: /* General Control Register (RS value = 1000) */ ramdac->gen_cntl = val; @@ -83,7 +89,7 @@ ati68875_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *priv, sv } uint8_t -ati68875_ramdac_in(uint16_t addr, int rs2, int rs3, void *priv, svga_t *svga) +ati68875_ramdac_in(uint16_t addr, int rs2, int rs3, int is_8514, void *priv, svga_t *svga) { const ati68875_ramdac_t *ramdac = (ati68875_ramdac_t *) priv; uint8_t rs = (addr & 0x03); @@ -94,10 +100,16 @@ ati68875_ramdac_in(uint16_t addr, int rs2, int rs3, void *priv, svga_t *svga) switch (rs) { case 0x00: /* Palette Write Index Register (RS value = 0000) */ + temp = svga_in(is_8514 ? 0x2ec : 0x3c8, svga); + break; case 0x01: /* Palette Data Register (RS value = 0001) */ + temp = svga_in(is_8514 ? 0x2ed : 0x3c9, svga); + break; case 0x02: /* Pixel Read Mask Register (RS value = 0010) */ - case 0x03: - temp = svga_in(addr, svga); + temp = svga_in(is_8514 ? 0x2ea : 0x3c6, svga); + break; + case 0x03: /* Palette Read Index Register (RS value = 0011) */ + temp = svga_in(is_8514 ? 0x2eb : 0x3c7, svga); break; case 0x08: /* General Control Register (RS value = 1000) */ temp = ramdac->gen_cntl; diff --git a/src/video/vid_8514a.c b/src/video/vid_8514a.c index 97202340d..b1e38fef7 100644 --- a/src/video/vid_8514a.c +++ b/src/video/vid_8514a.c @@ -911,8 +911,10 @@ ibm8514_accel_in(uint16_t port, svga_t *svga) switch (port) { case 0x2e8: - if (dev->vc == dev->v_syncstart) - temp |= 0x02; + if (dev->vc == dev->v_syncstart) { + if (dev->accel.advfunc_cntl & 0x04) + temp |= 0x02; + } ibm8514_log("Read: Display Status1=%02x.\n", temp); break; @@ -3817,7 +3819,7 @@ ibm8514_recalctimings(svga_t *svga) } else { if (dev->on) { dev->hdisp = (dev->hdisped + 1) << 3; - dev->h_total = dev->htotal + 1; + dev->h_total = (dev->htotal + 1) << 3; if (dev->h_total == 1) /*Default to 1024x768 87hz 8514/A htotal timings if it goes to 0.*/ dev->h_total = 0x9e; @@ -3827,10 +3829,14 @@ ibm8514_recalctimings(svga_t *svga) dev->vdisp += 2; dev->v_total = dev->v_total_reg + 1; + if (dev->v_total == 1) + dev->v_total = 0x0669; if (dev->interlace) dev->v_total >>= 1; dev->v_syncstart = dev->v_sync_start + 1; + if (dev->v_syncstart == 1) + dev->v_syncstart = 0x0601; if (dev->interlace) dev->v_syncstart >>= 1; diff --git a/src/video/vid_ati_mach64.c b/src/video/vid_ati_mach64.c index 74086dab1..2b89bddf4 100644 --- a/src/video/vid_ati_mach64.c +++ b/src/video/vid_ati_mach64.c @@ -94,6 +94,7 @@ typedef struct mach64_t { int type; int pci; + int vlb; uint8_t pci_slot; uint8_t irq_state; @@ -424,7 +425,7 @@ mach64_out(uint16_t addr, uint8_t val, void *priv) case 0x3C8: case 0x3C9: if (mach64->type == MACH64_GX) - ati68860_ramdac_out((addr & 3) | ((mach64->dac_cntl & 3) << 2), val, svga->ramdac, svga); + ati68860_ramdac_out((addr & 3) | ((mach64->dac_cntl & 3) << 2), val, 0, svga->ramdac, svga); else svga_out(addr, val, svga); return; @@ -491,7 +492,7 @@ mach64_in(uint16_t addr, void *priv) case 0x3C8: case 0x3C9: if (mach64->type == MACH64_GX) - return ati68860_ramdac_in((addr & 3) | ((mach64->dac_cntl & 3) << 2), svga->ramdac, svga); + return ati68860_ramdac_in((addr & 3) | ((mach64->dac_cntl & 3) << 2), 0, svga->ramdac, svga); return svga_in(addr, svga); case 0x3D4: @@ -2529,7 +2530,7 @@ mach64_ext_readb(uint32_t addr, void *priv) case 0xc2: case 0xc3: if (mach64->type == MACH64_GX) - ret = ati68860_ramdac_in((addr & 3) | ((mach64->dac_cntl & 3) << 2), mach64->svga.ramdac, &mach64->svga); + ret = ati68860_ramdac_in((addr & 3) | ((mach64->dac_cntl & 3) << 2), 0, mach64->svga.ramdac, &mach64->svga); else { switch (addr & 3) { case 0: @@ -3312,7 +3313,7 @@ mach64_ext_writeb(uint32_t addr, uint8_t val, void *priv) case 0xc2: case 0xc3: if (mach64->type == MACH64_GX) - ati68860_ramdac_out((addr & 3) | ((mach64->dac_cntl & 3) << 2), val, svga->ramdac, svga); + ati68860_ramdac_out((addr & 3) | ((mach64->dac_cntl & 3) << 2), val, 0, svga->ramdac, svga); else { switch (addr & 3) { case 0: @@ -3573,7 +3574,7 @@ mach64_ext_inb(uint16_t port, void *priv) case 0x5eee: case 0x5eef: if (mach64->type == MACH64_GX) - ret = ati68860_ramdac_in((port & 3) | ((mach64->dac_cntl & 3) << 2), mach64->svga.ramdac, &mach64->svga); + ret = ati68860_ramdac_in((port & 3) | ((mach64->dac_cntl & 3) << 2), 0, mach64->svga.ramdac, &mach64->svga); else { switch (port & 3) { case 0: @@ -3819,7 +3820,7 @@ mach64_ext_outb(uint16_t port, uint8_t val, void *priv) case 0x5eee: case 0x5eef: if (mach64->type == MACH64_GX) - ati68860_ramdac_out((port & 3) | ((mach64->dac_cntl & 3) << 2), val, svga->ramdac, svga); + ati68860_ramdac_out((port & 3) | ((mach64->dac_cntl & 3) << 2), val, 0, svga->ramdac, svga); else { switch (port & 3) { case 0: @@ -3857,7 +3858,7 @@ mach64_ext_outb(uint16_t port, uint8_t val, void *priv) case 0x6aee: case 0x6aef: WRITE8(port, mach64->config_cntl, val); - if (!mach64->pci) + if (mach64->vlb) mach64->linear_base = (mach64->config_cntl & 0x3ff0) << 18; mach64_updatemapping(mach64); @@ -4764,6 +4765,7 @@ mach64gx_init(const device_t *info) video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_mach64_vlb); mach64->pci = !!(info->flags & DEVICE_PCI); + mach64->vlb = !!(info->flags & DEVICE_VLB); mach64->pci_id = 'X' | ('G' << 8); mach64->config_chip_id = 0x000000d7; mach64->dac_cntl = 5 << 16; /*ATI 68860 RAMDAC*/ @@ -4799,6 +4801,7 @@ mach64vt2_init(const device_t *info) video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_mach64_pci); mach64->pci = 1; + mach64->vlb = 0; mach64->pci_id = 0x5654; mach64->config_chip_id = 0x40005654; mach64->dac_cntl = 1 << 16; /*Internal 24-bit DAC*/ diff --git a/src/video/vid_ati_mach8.c b/src/video/vid_ati_mach8.c index 4133b730e..c5cb2ccca 100644 --- a/src/video/vid_ati_mach8.c +++ b/src/video/vid_ati_mach8.c @@ -2422,11 +2422,11 @@ mach_out(uint16_t addr, uint8_t val, void *priv) rs2 = !!(mach->accel.ext_ge_config & 0x1000); rs3 = !!(mach->accel.ext_ge_config & 0x2000); mach_log("8514/A Extended mode=%02x.\n", mach->regs[0xb0] & 0x20); - if (ATI_MACH32 && !dev->on) { - if (mach->pci_bus && !mach->ramdac_type) - ati68860_ramdac_out((addr & 0x03) | (rs2 << 2) | (rs3 << 3), val, svga->ramdac, svga); + if (ATI_MACH32) { + if (mach->pci_bus && (mach->ramdac_type == ATI_68860)) + ati68860_ramdac_out((addr & 0x03) | (rs2 << 2) | (rs3 << 3), val, 1, svga->ramdac, svga); else - ati68875_ramdac_out(addr, rs2, rs3, val, svga->ramdac, svga); + ati68875_ramdac_out(addr, rs2, rs3, val, 1, svga->ramdac, svga); } else svga_out(addr, val, svga); return; @@ -2438,11 +2438,11 @@ mach_out(uint16_t addr, uint8_t val, void *priv) rs2 = !!(mach->regs[0xa0] & 0x20); rs3 = !!(mach->regs[0xa0] & 0x40); mach_log("VGA Extended mode=%02x.\n", mach->regs[0xb0] & 0x20); - if (ATI_MACH32 && !dev->on) { - if (mach->pci_bus && !mach->ramdac_type) - ati68860_ramdac_out((addr & 0x03) | (rs2 << 2) | (rs3 << 3), val, svga->ramdac, svga); + if (ATI_MACH32) { + if (mach->pci_bus && (mach->ramdac_type == ATI_68860)) + ati68860_ramdac_out((addr & 0x03) | (rs2 << 2) | (rs3 << 3), val, 0, svga->ramdac, svga); else - ati68875_ramdac_out(addr, rs2, rs3, val, svga->ramdac, svga); + ati68875_ramdac_out(addr, rs2, rs3, val, 0, svga->ramdac, svga); } else svga_out(addr, val, svga); return; @@ -2563,11 +2563,11 @@ mach_in(uint16_t addr, void *priv) case 0x2ed: rs2 = !!(mach->accel.ext_ge_config & 0x1000); rs3 = !!(mach->accel.ext_ge_config & 0x2000); - if (ATI_MACH32 && !dev->on) { - if (mach->pci_bus && !mach->ramdac_type) - temp = ati68860_ramdac_in((addr & 3) | (rs2 << 2) | (rs3 << 3), svga->ramdac, svga); + if (ATI_MACH32) { + if (mach->pci_bus && (mach->ramdac_type == ATI_68860)) + temp = ati68860_ramdac_in((addr & 3) | (rs2 << 2) | (rs3 << 3), 1, svga->ramdac, svga); else - temp = ati68875_ramdac_in(addr, rs2, rs3, svga->ramdac, svga); + temp = ati68875_ramdac_in(addr, rs2, rs3, 1, svga->ramdac, svga); } else temp = svga_in(addr, svga); break; @@ -2699,93 +2699,80 @@ ati_render_32bpp(svga_t *svga) } /*The situation is the following: - When ATI mode is selected, allow complete auto-detection. - But when 8514/A mode is selected, allow detection based on the shadow register sets. + When ATI (0x4aee) mode is selected, allow complete auto-detection. + When 8514/A (0x4ae8) mode is selected, allow detection based on the shadow register sets. */ static void mach_set_resolution(mach_t *mach, svga_t *svga) { - ibm8514_t *dev = (ibm8514_t *) svga->dev8514; - int ret = 0; + ibm8514_t *dev = (ibm8514_t *) svga->dev8514; - dev->h_total = dev->htotal + 1; - - if (dev->h_total == 1) /*Default to 1024x768 87hz 8514/A htotal timings if it goes to 0.*/ - dev->h_total = 0x9e; + dev->h_total = (dev->htotal + 1) << 3; + if (dev->h_total == 8) /*Default to 1024x768 87hz 8514/A htotal timings if it goes to 0.*/ + dev->h_total = 0x9e << 3; dev->hdisp = (dev->hdisped + 1) << 3; dev->vdisp = (dev->v_disp + 1) >> 1; - if ((dev->vdisp == 478) || (dev->vdisp == 598) || (dev->vdisp == 766) || (dev->vdisp == 1022)) + if ((dev->vdisp == 478) || (dev->vdisp == 598) || (dev->vdisp == 766) || (dev->vdisp == 898) || (dev->vdisp == 1022)) dev->vdisp += 2; dev->v_total = dev->v_total_reg + 1; + if (dev->v_total == 1) + dev->v_total = 0x0669; dev->v_syncstart = dev->v_sync_start + 1; + if (dev->v_syncstart == 1) + dev->v_syncstart = 0x0601; - mach_log("VSYNCSTART=%d, VTOTAL=%d, interlace=%02x, vdisp=%d.\n", dev->v_syncstart, dev->v_total, dev->interlace, dev->vdisp); + mach_log("ATI Mode: set=%02x, dispcntl=%02x, h_total=%d, hdisp=%d, vdisp=%d, v_total=%04x, v_syncstart=%04x, hsync_start=%d, hsync_width=%d, clocksel=%02x, advancedcntl=%02x.\n", mach->shadow_set & 0x03, dev->disp_cntl, dev->h_total, dev->hdisp, dev->vdisp, dev->v_total, dev->v_syncstart, dev->hsync_start, dev->hsync_width, mach->accel.clock_sel & 0xff, dev->accel.advfunc_cntl & 0x05); + if ((dev->disp_cntl >> 5) == 1) { /*Enable the 8514/A subsystem and set modes according to the shadow sets if needed.*/ + switch (mach->shadow_set & 0x03) { + case 0x01: + if (!(dev->accel.advfunc_cntl & 0x04)) { + dev->h_total = 0x64 << 3; + dev->hdisp = 640; + dev->vdisp = 480; + dev->v_total = 0x0419; + dev->v_syncstart = 0x03d7; + } + break; + case 0x02: + if (dev->accel.advfunc_cntl & 0x04) { + dev->h_total = 0x9e << 3; + dev->hdisp = 1024; + dev->vdisp = 768; + dev->v_total = 0x0669; + dev->v_syncstart = 0x0601; + } + break; - if (!ATI_MACH32) { - if ((mach->accel.clock_sel & 0x01) && - !(dev->accel.advfunc_cntl & 0x01)) - ret = 2; - else if ((dev->accel.advfunc_cntl & 0x01) && - !(mach->accel.clock_sel & 0x01)) - ret = 1; - else if ((!(dev->accel.advfunc_cntl & 0x01) && (mach->old_on1 & 0x01)) || - (!(mach->accel.clock_sel & 0x01) && (mach->old_on2 & 0x01))) - ret = 0; - } else { - if ((mach->accel.clock_sel & 0x01) && !(mach->old_on2 & 0x01) && - !(dev->accel.advfunc_cntl & 0x01)) - ret = 2; - else if ((dev->accel.advfunc_cntl & 0x01) && !(mach->old_on1 & 0x01) && - !(mach->accel.clock_sel & 0x01)) - ret = 1; - else if ((!(dev->accel.advfunc_cntl & 0x01) && (mach->old_on1 & 0x01)) || - (!(mach->accel.clock_sel & 0x01) && (mach->old_on2 & 0x01))) - ret = 0; - } - - if (ret) { - if (ret == 2) - svga_recalctimings(svga); - else { - switch (mach->shadow_set & 0x03) { - case 0x00: - if (mach->crt_resolution) - svga_recalctimings(svga); - else { - if (dev->accel.advfunc_cntl & 0x04) { - if (dev->hdisp == 640) { - dev->hdisp = 1024; - dev->vdisp = 768; - mach_log("1024x768.\n"); - } - } else { - if (dev->hdisp == 1024) { - dev->hdisp = 640; - dev->vdisp = 480; - mach_log("640x480.\n"); - } - } - svga_recalctimings(svga); - } - break; - case 0x01: - mach->crt_resolution = 0x01; - break; - case 0x02: - mach->crt_resolution = 0x02; - break; - default: - break; + default: + break; + } + svga_recalctimings(svga); + } else if ((dev->disp_cntl >> 5) == 2) { /*Reset 8514/A to defaults if needed.*/ + if (dev->accel.advfunc_cntl & 0x04) { + if (dev->hdisp == 640) { + dev->h_total = 0x9e << 3; + dev->hdisp = 1024; + dev->vdisp = 768; + dev->v_total = 0x0669; + dev->v_syncstart = 0x0601; + svga_recalctimings(svga); + } + } else { + if (dev->hdisp == 1024) { + dev->h_total = 0x64 << 3; + dev->hdisp = 640; + dev->vdisp = 480; + dev->v_total = 0x0419; + dev->v_syncstart = 0x03d7; + svga_recalctimings(svga); } } - } else + } else /*No change (type 0) or reset type 3.*/ svga_recalctimings(svga); - - mach_log("Shadow set ATI=%x, shadow set 8514/A and on1=%x, on2=%x, resolution h=%d, v=%d, vtotal=%d, vsyncstart=%d, crtres=%d, ret=%d, actual passthrough=%x.\n", mach->shadow_set & 0x03, dev->accel.advfunc_cntl & 0x05, mach->accel.clock_sel & 0x01, dev->hdisp, dev->vdisp, dev->v_total, dev->v_syncstart, mach->crt_resolution, ret, dev->on); } void @@ -2845,7 +2832,7 @@ ati8514_recalctimings(svga_t *svga) svga->render8514 = ibm8514_render_8bpp; } else - mach->crt_resolution = 0; + dev->mode = VGA_MODE; } static void @@ -2899,9 +2886,9 @@ mach_recalctimings(svga_t *svga) svga->ati_4color = 0; } - mach_log("ON=%d, override=%d, gelo=%04x, gehi=%04x, vgahdisp=%d.\n", dev->on, svga->override, mach->accel.ge_offset_lo, mach->accel.ge_offset_hi, svga->hdisp); + mach_log("ON=%d, override=%d, gelo=%04x, gehi=%04x, crtlo=%04x, crthi=%04x, vgahdisp=%d.\n", dev->on, svga->override, mach->accel.ge_offset_lo, mach->accel.ge_offset_hi, mach->accel.crt_offset_lo, mach->accel.crt_offset_hi, svga->hdisp); if (dev->on) { - dev->memaddr_latch = 0; /*(mach->accel.crt_offset_lo | (mach->accel.crt_offset_hi << 16)) << 2;*/ + dev->memaddr_latch = 0; /*(mach->accel.crt_offset_lo | (mach->accel.crt_offset_hi << 16)) << 2;*/ dev->interlace = !!(dev->disp_cntl & 0x10); dev->pitch = dev->ext_pitch; dev->rowoffset = dev->ext_crt_pitch; @@ -2949,8 +2936,8 @@ mach_recalctimings(svga_t *svga) if (ATI_MACH32) { switch ((mach->shadow_set >> 8) & 0x03) { case 0x00: - mach->accel.src_pitch = ((mach->accel.ge_pitch & 0xff) << 3); - mach->accel.dst_pitch = ((mach->accel.ge_pitch & 0xff) << 3); + mach->accel.src_pitch = dev->pitch; + mach->accel.dst_pitch = dev->pitch; mach->accel.src_ge_offset = (mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16)); mach->accel.dst_ge_offset = (mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16)); if (dev->bpp) { @@ -2972,7 +2959,7 @@ mach_recalctimings(svga_t *svga) dev->accel.dst_ge_offset = mach->accel.dst_ge_offset; break; case 0x01: - mach->accel.dst_pitch = ((mach->accel.ge_pitch & 0xff) << 3); + mach->accel.dst_pitch = dev->pitch; mach->accel.dst_ge_offset = (mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16)); if (dev->bpp) mach->accel.dst_ge_offset <<= 1; @@ -2987,7 +2974,7 @@ mach_recalctimings(svga_t *svga) dev->accel.dst_ge_offset = mach->accel.dst_ge_offset; break; case 0x02: - mach->accel.src_pitch = ((mach->accel.ge_pitch & 0xff) << 3); + mach->accel.src_pitch = dev->pitch; mach->accel.src_ge_offset = (mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16)); if (dev->bpp) mach->accel.src_ge_offset <<= 1; @@ -3007,6 +2994,7 @@ mach_recalctimings(svga_t *svga) mach_log("cntl=%d, clksel=%x, hv(%d,%d), pitch=%d, rowoffset=%d, gextconfig=%03x, shadow=%x interlace=%d, vgahdisp=%d.\n", dev->accel.advfunc_cntl & 0x04, mach->accel.clock_sel & 0x01, dev->h_disp, dev->dispend, dev->pitch, dev->rowoffset, mach->accel.ext_ge_config & 0xcec0, mach->shadow_set & 3, dev->interlace, svga->hdisp); + mach_log("EXTGECONFIG bits 11-15=%04x.\n", mach->accel.ext_ge_config & 0x8800); if ((mach->accel.ext_ge_config & 0x800) || (!(mach->accel.ext_ge_config & 0x8000) && !(mach->accel.ext_ge_config & 0x800))) { mach_log("hv=%d,%d, pitch=%d, rowoffset=%d, gextconfig=%03x, bpp=%d, shadow=%x, vgahdisp=%d.\n", dev->h_disp, dev->dispend, dev->pitch, dev->ext_crt_pitch, mach->accel.ext_ge_config & 0xcec0, @@ -3066,7 +3054,7 @@ mach_recalctimings(svga_t *svga) svga->render8514 = ibm8514_render_8bpp; } } else { - mach->crt_resolution = 0; + dev->mode = VGA_MODE; if (!svga->scrblank && (svga->crtc[0x17] & 0x80) && svga->attr_palette_enable) { mach_log("GDCREG5=%02x, ATTR10=%02x, ATI B0 bit 5=%02x, ON=%d.\n", svga->gdcreg[5] & 0x60, svga->attrregs[0x10] & 0x40, mach->regs[0xb0] & 0x20, dev->on); @@ -3239,7 +3227,7 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u mach_log("ATI 8514/A: V_DISP write 16E8=%d, vdisp2=%d.\n", dev->v_disp, dev->v_disp2); mach_log("ATI 8514/A: (0x%04x): vdisp=0x%02x.\n", port, val); } else { - if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { /*For 8514/A mode, take the shadow sets into account.*/ + if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { /*For 8514/A mode, take the shadow sets into account.*/ if (!(mach->shadow_cntl & 0x20)) { WRITE8(port, dev->v_disp, val); dev->v_disp &= 0x1fff; @@ -3264,7 +3252,7 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u case 0x1ae8: if (len == 2) { - if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { /*For 8514/A mode, take the shadow sets into account.*/ + if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { /*For 8514/A mode, take the shadow sets into account.*/ if (!(mach->shadow_cntl & 0x10) && val) { dev->v_sync_start = val; dev->v_sync_start &= 0x1fff; @@ -3273,7 +3261,7 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u mach_log("ATI 8514/A: V_SYNCSTART write 1AE8 = %d\n", dev->v_syncstart); mach_log("ATI 8514/A: (0x%04x): vsyncstart=0x%02x.\n", port, val); } else { - if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { /*For 8514/A mode, take the shadow sets into account.*/ + if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { /*For 8514/A mode, take the shadow sets into account.*/ if (!(mach->shadow_cntl & 0x10)) { WRITE8(port, dev->v_sync_start, val); dev->v_sync_start &= 0x1fff; @@ -3284,7 +3272,7 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u break; case 0x1ae9: if (len == 1) { - if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { /*For 8514/A mode, take the shadow sets into account.*/ + if ((mach->accel.clock_sel & 0x01) || (!(mach->accel.clock_sel & 0x01) && (mach->shadow_set & 0x03))) { /*For 8514/A mode, take the shadow sets into account.*/ if (!(mach->shadow_cntl & 0x10)) { WRITE8(port, dev->v_sync_start, val >> 8); dev->v_sync_start &= 0x1fff; @@ -3333,7 +3321,6 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u case 0x4ae8: case 0x4ae9: - mach->old_on1 = dev->accel.advfunc_cntl & 0x01; WRITE8(port, dev->accel.advfunc_cntl, val); if (len == 2) { WRITE8(port + 1, dev->accel.advfunc_cntl, val >> 8); @@ -3347,6 +3334,7 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u } } + dev->mode = IBM_MODE; mach_log("[%04X:%08X]: ATI 8514/A: (0x%04x): ON=%d, valxor=%x, shadow crt=%x, hdisp=%d, vdisp=%d, extmode=%02x, accelbpp=%d, crt=%d, crtres=%d.\n", CS, cpu_state.pc, port, val & 0x01, dev->on, dev->accel.advfunc_cntl & 0x04, dev->hdisp, dev->vdisp, mach->regs[0xb0] & 0x20, dev->accel_bpp, dev->_8514crt, mach->crt_resolution); @@ -3685,7 +3673,11 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u } else dev->_8514crt = 1; - mach_set_resolution(mach, svga); + if (dev->mode != VGA_MODE) + mach_set_resolution(mach, svga); + else + svga_recalctimings(svga); + if (ATI_GRAPHICS_ULTRA || ATI_MACH32) mach32_updatemapping(mach, svga); @@ -3778,13 +3770,15 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u case 0x4aee: case 0x4aef: - mach->old_on2 = mach->accel.clock_sel & 0x01; WRITE8(port, mach->accel.clock_sel, val); if (len == 2) { WRITE8(port + 1, mach->accel.clock_sel, val >> 8); } - dev->on = mach->accel.clock_sel & 0x01; + if (!(dev->accel.advfunc_cntl & 0x01)) + dev->on = mach->accel.clock_sel & 0x01; + dev->vendor_mode = 1; + dev->mode = ATI_MODE; mach_log("[%04X:%08X]: ATI 8514/A: (0x%04x): ON=%d, val=%04x, xor=%d, hdisp=%d, vdisp=%d, accelbpp=%d.\n", CS, cpu_state.pc, port, mach->accel.clock_sel & 0x01, val, dev->on, dev->hdisp, dev->vdisp, dev->accel_bpp); @@ -3936,7 +3930,11 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u } svga_set_ramdac_type(svga, !!(mach->accel.ext_ge_config & 0x4000)); mach_log("ATI 8514/A: (0x%04x) Extended Configuration=%04x, val=%04x.\n", port, mach->accel.ext_ge_config, val); - mach_set_resolution(mach, svga); + if (dev->mode != VGA_MODE) + mach_set_resolution(mach, svga); + else + svga_recalctimings(svga); + mach32_updatemapping(mach, svga); } else ati_eeprom_write(&mach->eeprom, !!(mach->accel.ext_ge_config & 0x04), !!(mach->accel.ext_ge_config & 0x02), !!(mach->accel.ext_ge_config & 0x01)); @@ -4759,7 +4757,6 @@ mach_accel_in_call(uint16_t port, mach_t *mach, svga_t *svga, ibm8514_t *dev) } } else { switch (mach->accel.cmd_type) { - case 1: case 2: case 5: if ((dev->subsys_cntl & INT_GE_BSY) && @@ -4770,6 +4767,7 @@ mach_accel_in_call(uint16_t port, mach_t *mach, svga_t *svga, ibm8514_t *dev) (dev->accel.dy <= clip_b)) temp |= INT_GE_BSY; break; + case 1: case 3: case 4: if ((dev->subsys_cntl & INT_GE_BSY) && @@ -7068,7 +7066,7 @@ mach8_init(const device_t *info) dev->type = info->flags; dev->local = info->local & 0xff; mach->has_bios = !(info->local & 0xff00); - mach->ramdac_type = mach->pci_bus ? device_get_config_int("ramdac") : 1; + mach->ramdac_type = mach->pci_bus ? device_get_config_int("ramdac") : ATI_68875; dev->vram_amount = device_get_config_int("memory"); dev->vram_512k_8514 = dev->vram_amount == 512; @@ -7119,7 +7117,7 @@ mach8_init(const device_t *info) dev->vram_mask = dev->vram_size - 1; dev->hwcursor.cur_ysize = 64; mach->config1 = 0x20; - if (mach->pci_bus && !mach->ramdac_type) + if (mach->pci_bus && (mach->ramdac_type == ATI_68860)) svga->ramdac = device_add(&ati68860_ramdac_device); else svga->ramdac = device_add(&ati68875_ramdac_device); @@ -7142,10 +7140,10 @@ mach8_init(const device_t *info) } else if (mach->pci_bus) { video_inform(VIDEO_FLAG_TYPE_8514, &timing_mach32_pci); mach->config1 |= 0x0e; - if (mach->ramdac_type) - mach->config1 |= 0x0400; - else + if (mach->ramdac_type == ATI_68860) mach->config1 |= 0x0a00; + else + mach->config1 |= 0x0400; mach->config2 |= 0x2000; svga->clock_gen = device_add(&ati18811_1_device); } else { @@ -7180,6 +7178,7 @@ mach8_init(const device_t *info) dev->on = 0; dev->pitch = 1024; + dev->ext_pitch = 1024; dev->ext_crt_pitch = 0x80; dev->accel_bpp = 8; svga->force_old_addr = 1; @@ -7193,6 +7192,7 @@ mach8_init(const device_t *info) mach_io_set(mach); mach->accel.cmd_type = -2; dev->accel.cmd_back = 1; + dev->mode = IBM_MODE; if (ATI_MACH32) { svga->decode_mask = (4 << 20) - 1; @@ -7242,6 +7242,7 @@ ati8514_init(svga_t *svga, void *ext8514, void *dev8514) /*Init as 1024x768 87hz interlaced first, per 8514/A.*/ dev->on = 0; dev->pitch = 1024; + dev->ext_pitch = 1024; dev->ext_crt_pitch = 0x80; dev->accel_bpp = 8; dev->rowoffset = 0x80; @@ -7253,6 +7254,7 @@ ati8514_init(svga_t *svga, void *ext8514, void *dev8514) dev->disp_cntl = 0x33; mach->accel.clock_sel = 0x1c; dev->accel.cmd_back = 1; + dev->mode = IBM_MODE; io_sethandler(0x02ea, 4, ati8514_in, NULL, NULL, ati8514_out, NULL, NULL, svga); ati8514_io_set(svga); @@ -7390,12 +7392,12 @@ static const device_config_t mach32_pci_config[] = { .description = "RAMDAC type", .type = CONFIG_SELECTION, .default_string = NULL, - .default_int = 0, + .default_int = ATI_68860, .file_filter = NULL, .spinner = { 0 }, .selection = { - { .description = "ATI 68860", .value = 0 }, - { .description = "ATI 68875", .value = 1 }, + { .description = "ATI 68860", .value = ATI_68860 }, + { .description = "ATI 68875", .value = ATI_68875 }, { .description = "" } }, .bios = { { 0 } } diff --git a/src/video/vid_cga.c b/src/video/vid_cga.c index 72389d219..2abfe6a5c 100644 --- a/src/video/vid_cga.c +++ b/src/video/vid_cga.c @@ -48,8 +48,10 @@ #define DOUBLE_INTERPOLATE_SRGB 2 #define DOUBLE_INTERPOLATE_LINEAR 3 -typedef union -{ +#define DEVICE_VRAM 0x4000 +#define DEVICE_VRAM_MASK 0x3fff + +typedef union { uint32_t color; struct { uint8_t b; @@ -206,11 +208,11 @@ cga_write(uint32_t addr, uint8_t val, void *priv) { cga_t *cga = (cga_t *) priv; - cga->vram[addr & 0x3fff] = val; + cga->vram[addr & DEVICE_VRAM_MASK] = val; if (cga->snow_enabled) { int offset = ((timer_get_remaining_u64(&cga->timer) / CGACONST) * 2) & 0xfc; - cga->charbuffer[offset] = cga->vram[addr & 0x3fff]; - cga->charbuffer[offset | 1] = cga->vram[addr & 0x3fff]; + cga->charbuffer[offset] = cga->vram[addr & DEVICE_VRAM_MASK]; + cga->charbuffer[offset | 1] = cga->vram[addr & DEVICE_VRAM_MASK]; } cga_waitstates(cga); } @@ -223,10 +225,10 @@ cga_read(uint32_t addr, void *priv) cga_waitstates(cga); if (cga->snow_enabled) { int offset = ((timer_get_remaining_u64(&cga->timer) / CGACONST) * 2) & 0xfc; - cga->charbuffer[offset] = cga->vram[addr & 0x3fff]; - cga->charbuffer[offset | 1] = cga->vram[addr & 0x3fff]; + cga->charbuffer[offset] = cga->vram[addr & DEVICE_VRAM_MASK]; + cga->charbuffer[offset | 1] = cga->vram[addr & DEVICE_VRAM_MASK]; } - return cga->vram[addr & 0x3fff]; + return cga->vram[addr & DEVICE_VRAM_MASK]; } void @@ -253,7 +255,7 @@ cga_recalctimings(cga_t *cga) static void cga_render(cga_t *cga, int line) { - uint16_t cursoraddr = (cga->crtc[CGA_CRTC_CURSOR_ADDR_LOW] | (cga->crtc[CGA_CRTC_CURSOR_ADDR_HIGH] << 8)) & 0x3fff; + uint16_t cursoraddr = (cga->crtc[CGA_CRTC_CURSOR_ADDR_LOW] | (cga->crtc[CGA_CRTC_CURSOR_ADDR_HIGH] << 8)) & DEVICE_VRAM_MASK; int drawcursor; int x; int column; @@ -313,8 +315,8 @@ cga_render(cga_t *cga, int line) } else if (!(cga->cgamode & CGA_MODE_FLAG_GRAPHICS)) { for (x = 0; x < cga->crtc[CGA_CRTC_HDISP]; x++) { if (cga->cgamode & CGA_MODE_FLAG_VIDEO_ENABLE) { - chr = cga->vram[(cga->memaddr << 1) & 0x3fff]; - attr = cga->vram[((cga->memaddr << 1) + 1) & 0x3fff]; + chr = cga->vram[(cga->memaddr << 1) & DEVICE_VRAM_MASK]; + attr = cga->vram[((cga->memaddr << 1) + 1) & DEVICE_VRAM_MASK]; } else chr = attr = 0; drawcursor = ((cga->memaddr == cursoraddr) && cga->cursorvisible && cga->cursoron); @@ -605,7 +607,7 @@ cga_poll(void *priv) cga->vadj--; if (!cga->vadj) { cga->cgadispon = 1; - cga->memaddr = cga->memaddr_backup = (cga->crtc[CGA_CRTC_START_ADDR_LOW] | (cga->crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; + cga->memaddr = cga->memaddr_backup = (cga->crtc[CGA_CRTC_START_ADDR_LOW] | (cga->crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & DEVICE_VRAM_MASK; cga->scanline = 0; } } else if (cga->scanline == cga->crtc[CGA_CRTC_MAX_SCANLINE_ADDR]) { @@ -623,7 +625,7 @@ cga_poll(void *priv) cga->vadj = cga->crtc[CGA_CRTC_VTOTAL_ADJUST]; if (!cga->vadj) { cga->cgadispon = 1; - cga->memaddr = cga->memaddr_backup = (cga->crtc[CGA_CRTC_START_ADDR_LOW] | (cga->crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & 0x3fff; + cga->memaddr = cga->memaddr_backup = (cga->crtc[CGA_CRTC_START_ADDR_LOW] | (cga->crtc[CGA_CRTC_START_ADDR_HIGH] << 8)) & DEVICE_VRAM_MASK; } switch (cga->crtc[CGA_CRTC_CURSOR_START] & 0x60) { @@ -728,7 +730,7 @@ cga_poll(void *priv) cga->cursorvisible = 1; if (cga->cgadispon && (cga->cgamode & CGA_MODE_FLAG_HIGHRES)) { for (x = 0; x < (cga->crtc[CGA_CRTC_HDISP] << 1); x++) - cga->charbuffer[x] = cga->vram[((cga->memaddr << 1) + x) & 0x3fff]; + cga->charbuffer[x] = cga->vram[((cga->memaddr << 1) + x) & DEVICE_VRAM_MASK]; } } } @@ -754,7 +756,7 @@ cga_standalone_init(UNUSED(const device_t *info)) cga->revision = device_get_config_int("composite_type"); cga->snow_enabled = device_get_config_int("snow_enabled"); - cga->vram = malloc(0x4000); + cga->vram = malloc(DEVICE_VRAM); cga_comp_init(cga->revision); timer_add(&cga->timer, cga_poll, cga, 1); @@ -777,6 +779,18 @@ cga_standalone_init(UNUSED(const device_t *info)) } } + switch(device_get_config_int("font")) { + case 0: + loadfont(FONT_IBM_MDA_437_PATH, 0); + break; + case 1: + loadfont(FONT_IBM_MDA_437_NORDIC_PATH, 0); + break; + case 4: + loadfont(FONT_TULIP_DGA_PATH, 0); + break; + } + return cga; } @@ -880,6 +894,22 @@ const device_config_t cga_config[] = { }, .bios = { { 0 } } }, + { + .name = "font", + .description = "Font", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "US (CP 437)", .value = 0 }, + { .description = "IBM Nordic (CP 437-Nordic)", .value = 1 }, + { .description = "Tulip DGA", .value = 4 }, + { .description = "" } + }, + .bios = { { 0 } } + }, { .name = "snow_enabled", .description = "Snow emulation", diff --git a/src/video/vid_cl54xx.c b/src/video/vid_cl54xx.c index e1c02f5a9..fff344f3a 100644 --- a/src/video/vid_cl54xx.c +++ b/src/video/vid_cl54xx.c @@ -45,6 +45,7 @@ #include <86box/plat_unused.h> #define BIOS_GD5401_PATH "roms/video/cirruslogic/avga1.rom" +#define BIOS_GD5401_ONBOARD_PATH "roms/machines/drsm35286/qpaw01-6658237d5e3c2611427518.bin" #define BIOS_GD5402_PATH "roms/video/cirruslogic/avga2.rom" #define BIOS_GD5402_ONBOARD_PATH "roms/machines/cmdsl386sx25/c000.rom" #define BIOS_GD5420_PATH "roms/video/cirruslogic/5420.vbi" @@ -4236,8 +4237,11 @@ gd54xx_init(const device_t *info) switch (id) { case CIRRUS_ID_CLGD5401: - romfn = BIOS_GD5401_PATH; - break; + if (info->local & 0x100) + romfn = BIOS_GD5401_ONBOARD_PATH; + else + romfn = BIOS_GD5401_PATH; + break; case CIRRUS_ID_CLGD5402: if (info->local & 0x200) @@ -4254,10 +4258,16 @@ gd54xx_init(const device_t *info) break; case CIRRUS_ID_CLGD5422: - case CIRRUS_ID_CLGD5424: romfn = BIOS_GD5422_PATH; break; + case CIRRUS_ID_CLGD5424: + if (info->local & 0x200) + romfn = /*NULL*/ "roms/machines/advantage40xxd/AST101.09A"; + else + romfn = BIOS_GD5422_PATH; + break; + case CIRRUS_ID_CLGD5426: if (info->local & 0x200) romfn = NULL; @@ -4939,6 +4949,20 @@ const device_t gd5401_isa_device = { .config = NULL, }; +const device_t gd5401_onboard_device = { + .name = "Cirrus Logic GD5401 (ISA) (ACUMOS AVGA1) (On-Board)", + .internal_name = "cl_gd5402_onboard", + .flags = DEVICE_ISA16, + .local = CIRRUS_ID_CLGD5401 | 0x100, + .init = gd54xx_init, + .close = gd54xx_close, + .reset = gd54xx_reset, + .available = NULL, + .speed_changed = gd54xx_speed_changed, + .force_redraw = gd54xx_force_redraw, + .config = NULL, +}; + const device_t gd5402_isa_device = { .name = "Cirrus Logic GD5402 (ISA) (ACUMOS AVGA2)", .internal_name = "cl_gd5402_isa", @@ -5023,6 +5047,20 @@ const device_t gd5424_vlb_device = { .config = gd542x_config, }; +const device_t gd5424_onboard_device = { + .name = "Cirrus Logic GD5424 (VLB) (On-Board)", + .internal_name = "cl_gd5424_onboard", + .flags = DEVICE_VLB, + .local = CIRRUS_ID_CLGD5424 | 0x200, + .init = gd54xx_init, + .close = gd54xx_close, + .reset = gd54xx_reset, + .available = NULL, + .speed_changed = gd54xx_speed_changed, + .force_redraw = gd54xx_force_redraw, + .config = gd542x_config, +}; + const device_t gd5426_isa_device = { .name = "Cirrus Logic GD5426 (ISA)", .internal_name = "cl_gd5426_isa", diff --git a/src/video/vid_ega.c b/src/video/vid_ega.c index 1cfea782c..21671f4b3 100644 --- a/src/video/vid_ega.c +++ b/src/video/vid_ega.c @@ -158,9 +158,11 @@ ega_out(uint16_t addr, uint8_t val, void *priv) if (ega->alt_addr == 1) base_addr = 0x02a0; #endif - io_removehandler(base_addr, 0x0020, ega_in, NULL, NULL, ega_out, NULL, NULL, ega); - if (!(val & 1)) - io_sethandler(base_addr, 0x0020, ega_in, NULL, NULL, ega_out, NULL, NULL, ega); + if (ega->priv_parent == NULL) { + io_removehandler(base_addr, 0x0020, ega_in, NULL, NULL, ega_out, NULL, NULL, ega); + if (!(val & 1)) + io_sethandler(base_addr, 0x0020, ega_in, NULL, NULL, ega_out, NULL, NULL, ega); + } ega_recalctimings(ega); if ((type == EGA_TYPE_COMPAQ) && !(val & 0x02)) mem_mapping_disable(&ega->mapping); diff --git a/src/video/vid_hercules.c b/src/video/vid_hercules.c index 5e0ac1bc9..229ddcca8 100644 --- a/src/video/vid_hercules.c +++ b/src/video/vid_hercules.c @@ -555,6 +555,9 @@ hercules_init(UNUSED(const device_t *info)) case 3: loadfont(FONT_KAMCL16_PATH, 0); break; + case 4: + loadfont(FONT_TULIP_DGA_PATH, 0); + break; } timer_add(&dev->timer, hercules_poll, dev, 1); @@ -649,17 +652,6 @@ static const device_config_t hercules_config[] = { }, .bios = { { 0 } } }, - { - .name = "blend", - .description = "Blend", - .type = CONFIG_BINARY, - .default_string = NULL, - .default_int = 1, - .file_filter = NULL, - .spinner = { 0 }, - .selection = { { 0 } }, - .bios = { { 0 } } - }, { .name = "font", .description = "Font", @@ -673,10 +665,22 @@ static const device_config_t hercules_config[] = { { .description = "IBM Nordic (CP 437-Nordic)", .value = 1 }, { .description = "Czech Kamenicky (CP 895) #1", .value = 2 }, { .description = "Czech Kamenicky (CP 895) #2", .value = 3 }, + { .description = "Tulip DGA", .value = 4 }, { .description = "" } }, .bios = { { 0 } } }, + { + .name = "blend", + .description = "Blend", + .type = CONFIG_BINARY, + .default_string = NULL, + .default_int = 1, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { { 0 } }, + .bios = { { 0 } } + }, { .name = "", .description = "", .type = CONFIG_END } // clang-format on }; diff --git a/src/video/vid_hercules_incolor.c b/src/video/vid_hercules_incolor.c index c4751e8fa..eceb440f9 100644 --- a/src/video/vid_hercules_incolor.c +++ b/src/video/vid_hercules_incolor.c @@ -992,6 +992,24 @@ incolor_init(UNUSED(const device_t *info)) dev->vram = (uint8_t *) malloc(0x40000); /* 4 planes of 64k */ + switch(device_get_config_int("font")) { + case 0: + loadfont(FONT_IBM_MDA_437_PATH, 0); + break; + case 1: + loadfont(FONT_IBM_MDA_437_NORDIC_PATH, 0); + break; + case 2: + loadfont(FONT_KAM_PATH, 0); + break; + case 3: + loadfont(FONT_KAMCL16_PATH, 0); + break; + case 4: + loadfont(FONT_TULIP_DGA_PATH, 0); + break; + } + timer_add(&dev->timer, incolor_poll, dev, 1); mem_mapping_add(&dev->mapping, 0xb0000, 0x08000, @@ -1044,6 +1062,30 @@ speed_changed(void *priv) recalc_timings(dev); } +static const device_config_t incolor_config[] = { + // clang-format off + { + .name = "font", + .description = "Font", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "US (CP 437)", .value = 0 }, + { .description = "IBM Nordic (CP 437-Nordic)", .value = 1 }, + { .description = "Czech Kamenicky (CP 895) #1", .value = 2 }, + { .description = "Czech Kamenicky (CP 895) #2", .value = 3 }, + { .description = "Tulip DGA", .value = 4 }, + { .description = "" } + }, + .bios = { { 0 } } + }, + { .name = "", .description = "", .type = CONFIG_END } + // clang-format on +}; + const device_t incolor_device = { .name = "Hercules InColor", .internal_name = "incolor", @@ -1055,5 +1097,5 @@ const device_t incolor_device = { .available = NULL, .speed_changed = speed_changed, .force_redraw = NULL, - .config = NULL + .config = incolor_config }; diff --git a/src/video/vid_hercules_plus.c b/src/video/vid_hercules_plus.c index 0c6125d0b..7e1aec943 100644 --- a/src/video/vid_hercules_plus.c +++ b/src/video/vid_hercules_plus.c @@ -629,6 +629,24 @@ herculesplus_init(UNUSED(const device_t *info)) dev->vram = (uint8_t *) malloc(0x10000); /* 64k VRAM */ dev->monitor_index = monitor_index_global; + switch(device_get_config_int("font")) { + case 0: + loadfont(FONT_IBM_MDA_437_PATH, 0); + break; + case 1: + loadfont(FONT_IBM_MDA_437_NORDIC_PATH, 0); + break; + case 2: + loadfont(FONT_KAM_PATH, 0); + break; + case 3: + loadfont(FONT_KAMCL16_PATH, 0); + break; + case 4: + loadfont(FONT_TULIP_DGA_PATH, 0); + break; + } + timer_add(&dev->timer, herculesplus_poll, dev, 1); mem_mapping_add(&dev->mapping, 0xb0000, 0x08000, @@ -715,6 +733,24 @@ static const device_config_t herculesplus_config[] = { }, .bios = { { 0 } } }, + { + .name = "font", + .description = "Font", + .type = CONFIG_SELECTION, + .default_string = NULL, + .default_int = 0, + .file_filter = NULL, + .spinner = { 0 }, + .selection = { + { .description = "US (CP 437)", .value = 0 }, + { .description = "IBM Nordic (CP 437-Nordic)", .value = 1 }, + { .description = "Czech Kamenicky (CP 895) #1", .value = 2 }, + { .description = "Czech Kamenicky (CP 895) #2", .value = 3 }, + { .description = "Tulip DGA", .value = 4 }, + { .description = "" } + }, + .bios = { { 0 } } + }, { .name = "blend", .description = "Blend", diff --git a/src/video/vid_jega.c b/src/video/vid_jega.c index 257acfff0..eafdceb9c 100644 --- a/src/video/vid_jega.c +++ b/src/video/vid_jega.c @@ -123,7 +123,7 @@ typedef struct jega_t { int start_scan_lower; int start_scan_upper; int start_scan_count; - uint8_t * vram; + uint8_t *vram; uint8_t jfont_sbcs_19[SBCS19_FILESIZE]; /* 8 x 19 font */ uint8_t jfont_dbcs_16[DBCS16_FILESIZE]; /* 16 x 16 font. Use dbcs_read/write to access it. */ } jega_t; @@ -134,28 +134,30 @@ static void jega_recalctimings(void *priv); #define FONTX_LEN_FN 8 typedef struct { - char id[FONTX_LEN_ID]; - char name[FONTX_LEN_FN]; - uint8_t width; - uint8_t height; - uint8_t type; + char id[FONTX_LEN_ID]; + char name[FONTX_LEN_FN]; + uint8_t width; + uint8_t height; + uint8_t type; } fontx_h; typedef struct { - uint16_t start; - uint16_t end; + uint16_t start; + uint16_t end; } fontx_tbl; -extern uint32_t pallook16[256]; -extern uint32_t pallook64[256]; -static bool is_SJIS_1(uint8_t chr) { return (chr >= 0x81 && chr <= 0x9f) || (chr >= 0xe0 && chr <= 0xfc); } -static bool is_SJIS_2(uint8_t chr) { return (chr >= 0x40 && chr <= 0x7e) || (chr >= 0x80 && chr <= 0xfc); } +extern uint32_t pallook16[256]; +extern uint32_t pallook64[256]; +static bool is_SJIS_1(uint8_t chr) { return (chr >= 0x81 && chr <= 0x9f) || (chr >= 0xe0 && chr <= 0xfc); } +static bool is_SJIS_2(uint8_t chr) { return (chr >= 0x40 && chr <= 0x7e) || (chr >= 0x80 && chr <= 0xfc); } + +static uint8_t jega_in(uint16_t addr, void *priv); static uint16_t SJIS_to_SEQ(uint16_t sjis) { uint32_t chr1 = (sjis >> 8) & 0xff; - uint32_t chr2 = sjis & 0xff; + uint32_t chr2 = sjis & 0xff; if (!is_SJIS_1(chr1) || !is_SJIS_2(chr2)) return INVALIDACCESS16; @@ -177,8 +179,8 @@ SJIS_to_SEQ(uint16_t sjis) static uint8_t dbcs_read(uint16_t sjis, int index, void *priv) { - jega_t *jega = (jega_t *) priv; - int seq = SJIS_to_SEQ(sjis); + jega_t *jega = (jega_t *) priv; + int seq = SJIS_to_SEQ(sjis); if ((seq >= DBCS16_CHARS) || (index >= 32)) return INVALIDACCESS8; return jega->jfont_dbcs_16[seq * 32 + index]; @@ -186,8 +188,8 @@ dbcs_read(uint16_t sjis, int index, void *priv) { static void dbcs_write(uint16_t sjis, int index, uint8_t val, void *priv) { - jega_t *jega = (jega_t *) priv; - int seq = SJIS_to_SEQ(sjis); + jega_t *jega = (jega_t *) priv; + int seq = SJIS_to_SEQ(sjis); if ((seq >= DBCS16_CHARS) || (index >= 32)) return; jega->jfont_dbcs_16[seq * 32 + index] = val; @@ -197,38 +199,38 @@ dbcs_write(uint16_t sjis, int index, uint8_t val, void *priv) { void jega_render_text(void *priv) { - jega_t * jega = (jega_t *) priv; + jega_t *jega = (jega_t *) priv; #ifdef USE_DOUBLE_WIDTH_AND_LINE_CHARS - uint8_t * seqregs = jega->is_vga ? jega->vga.svga.seqregs : + uint8_t *seqregs = jega->is_vga ? jega->vga.svga.seqregs : jega->ega.seqregs; - uint8_t * attrregs = jega->is_vga ? jega->vga.svga.attrregs : + uint8_t *attrregs = jega->is_vga ? jega->vga.svga.attrregs : jega->ega.attrregs; #endif - uint8_t * crtc = jega->is_vga ? jega->vga.svga.crtc : + uint8_t *crtc = jega->is_vga ? jega->vga.svga.crtc : jega->ega.crtc; - uint8_t * vram = jega->is_vga ? jega->vga.svga.vram : + uint8_t *vram = jega->is_vga ? jega->vga.svga.vram : jega->ega.vram; - int * firstline_draw = jega->is_vga ? &jega->vga.svga.firstline_draw : + int *firstline_draw = jega->is_vga ? &jega->vga.svga.firstline_draw : &jega->ega.firstline_draw; - int * lastline_draw = jega->is_vga ? &jega->vga.svga.lastline_draw : + int *lastline_draw = jega->is_vga ? &jega->vga.svga.lastline_draw : &jega->ega.lastline_draw; - int * displine = jega->is_vga ? &jega->vga.svga.displine : + int *displine = jega->is_vga ? &jega->vga.svga.displine : &jega->ega.displine; - int * fullchange = jega->is_vga ? &jega->vga.svga.fullchange : + int *fullchange = jega->is_vga ? &jega->vga.svga.fullchange : &jega->ega.fullchange; - int * blink = jega->is_vga ? &jega->vga.svga.blink : + int *blink = jega->is_vga ? &jega->vga.svga.blink : &jega->ega.blink; - int * x_add = jega->is_vga ? &jega->vga.svga.x_add : + int *x_add = jega->is_vga ? &jega->vga.svga.x_add : &jega->ega.x_add; - int * y_add = jega->is_vga ? &jega->vga.svga.y_add : + int *y_add = jega->is_vga ? &jega->vga.svga.y_add : &jega->ega.y_add; - int * sc = jega->is_vga ? &jega->vga.svga.scanline : + int *sc = jega->is_vga ? &jega->vga.svga.scanline : &jega->ega.scanline; - int * hdisp = jega->is_vga ? &jega->vga.svga.hdisp : + int *hdisp = jega->is_vga ? &jega->vga.svga.hdisp : &jega->ega.hdisp; - int * scrollcache = jega->is_vga ? &jega->vga.svga.scrollcache : + int *scrollcache = jega->is_vga ? &jega->vga.svga.scrollcache : &jega->ega.scrollcache; - uint32_t *memaddr = jega->is_vga ? &jega->vga.svga.memaddr : + uint32_t *memaddr = jega->is_vga ? &jega->vga.svga.memaddr : &jega->ega.memaddr; uint8_t mask = jega->is_vga ? jega->vga.svga.dac_mask : 0xff; @@ -253,7 +255,7 @@ jega_render_text(void *priv) uint32_t attr_basic = 0; uint32_t chr_first; int fg = 0; - int bg; + int bg = 0; for (int x = 0; x < (*hdisp + *scrollcache); x += charwidth) { uint32_t addr = 0; @@ -389,9 +391,9 @@ jega_render_text(void *priv) for (int xx = 0; xx < charwidth; xx++) p[xx] = (dat & (0x80 >> xx)) ? fg : bg; - if (attr_basic & 0x20) { /* vertical line */ + if (attr_basic & 0x20) /* vertical line */ p[0] = fg; - } + if ((*sc == jega->regs[RPULP]) && (attr_basic & 0x10)) { /* underline */ for (int xx = 0; xx < charwidth; xx++) p[xx] = fg; @@ -422,7 +424,10 @@ jega_out(uint16_t addr, uint8_t val, void *priv) if (!jega->attrff) { jega->attraddr = val & 31; if ((val & 0x20) != jega->attr_palette_enable) { - jega->ega.fullchange = 3; + if (jega->is_vga) + jega->vga.svga.fullchange = 3; + else + jega->ega.fullchange = 3; jega->attr_palette_enable = val & 0x20; jega_recalctimings(jega); } @@ -449,6 +454,13 @@ jega_out(uint16_t addr, uint8_t val, void *priv) } jega->attrff ^= 1; break; + case 0x3c2: + if (jega->regs[RMOD1] & 0x0c) { + io_removehandler(0x03a0, 0x0020, jega_in, NULL, NULL, jega_out, NULL, NULL, jega); + if (!(val & 1)) + io_sethandler(0x03a0, 0x0020, jega_in, NULL, NULL, jega_out, NULL, NULL, jega); + } + break; case 0x3b4: case 0x3d4: /* Index 0x00-0x1F (write only), 0xB8-0xDF (write and read) */ @@ -643,11 +655,11 @@ jega_in(uint16_t addr, void *priv) static int getfontx2header(FILE *fp, fontx_h *header) { - fread(header->id, FONTX_LEN_ID, 1, fp); - if (strncmp(header->id, "FONTX2", FONTX_LEN_ID) != 0) { + (void) !fread(header->id, FONTX_LEN_ID, 1, fp); + if (strncmp(header->id, "FONTX2", FONTX_LEN_ID) != 0) return 1; - } - fread(header->name, FONTX_LEN_FN, 1, fp); + + (void) !fread(header->name, FONTX_LEN_FN, 1, fp); header->width = (uint8_t) getc(fp); header->height = (uint8_t) getc(fp); header->type = (uint8_t) getc(fp); @@ -657,9 +669,8 @@ getfontx2header(FILE *fp, fontx_h *header) static uint16_t chrtosht(FILE *fp) { - uint16_t i, j; - i = (uint16_t) getc(fp); - j = (uint16_t) getc(fp) << 8; + uint16_t i = (uint16_t) getc(fp); + uint16_t j = (uint16_t) getc(fp) << 8; return (i | j); } @@ -683,7 +694,6 @@ LoadFontxFile(const char *fn, void *priv) uint16_t scode; uint8_t size; uint8_t buf; - int line; jega_t *jega = (jega_t *) priv; FILE *fp = rom_fopen(fn, "rb"); jega_log("JEGA: Loading font\n"); @@ -706,10 +716,10 @@ LoadFontxFile(const char *fn, void *priv) for (code = ftbl[i].start; code <= ftbl[i].end; code++) { scode = SJIS_to_SEQ(code); if (scode != INVALIDACCESS16) { - for (line = 0; line < 16; line++) { - fread(&buf, sizeof(uint8_t), 1, fp); + for (uint8_t line = 0; line < 16; line++) { + (void) !fread(&buf, sizeof(uint8_t), 1, fp); jega->jfont_dbcs_16[(int) (scode * 32) + line] = buf; - fread(&buf, sizeof(uint8_t), 1, fp); + (void) !fread(&buf, sizeof(uint8_t), 1, fp); jega->jfont_dbcs_16[(int) (scode * 32) + line + 16] = buf; } } else { @@ -723,9 +733,9 @@ LoadFontxFile(const char *fn, void *priv) return 1; } } else { - if (fhead.width == 8 && fhead.height == 19) { - fread(jega->jfont_sbcs_19, sizeof(uint8_t), SBCS19_FILESIZE, fp); - } else { + if (fhead.width == 8 && fhead.height == 19) + (void) !fread(jega->jfont_sbcs_19, sizeof(uint8_t), SBCS19_FILESIZE, fp); + else { fclose(fp); jega_log("JEGA: Width or height of SBCS font doesn't match.\n"); return 1; @@ -742,11 +752,21 @@ jega_commoninit(const device_t *info, void *priv, int vga) jega->is_vga = vga; if (vga) { video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_vga); - vga_init(info, &jega->vga, 1); + svga_init(info, &jega->vga.svga, &jega->vga, 1 << 18, /*256kb*/ + NULL, + jega_in, jega_out, + NULL, + NULL); + + jega->vga.svga.bpp = 8; + jega->vga.svga.miscout = 1; + + jega->vga.svga.vga_enabled = 0; jega->vga.svga.priv_parent = jega; jega->pallook = jega->vga.svga.pallook; + io_sethandler(0x03c0, 0x0020, jega_in, NULL, NULL, jega_out, NULL, NULL, jega); } else { - for (int c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { pallook64[c] = makecol32(((c >> 2) & 1) * 0xaa, ((c >> 1) & 1) * 0xaa, (c & 1) * 0xaa); pallook64[c] += makecol32(((c >> 5) & 1) * 0x55, ((c >> 4) & 1) * 0x55, ((c >> 3) & 1) * 0x55); } @@ -758,9 +778,11 @@ jega_commoninit(const device_t *info, void *priv, int vga) mem_mapping_add(&jega->ega.mapping, 0xa0000, 0x20000, ega_read, NULL, NULL, ega_write, NULL, NULL, NULL, MEM_MAPPING_EXTERNAL, &jega->ega); + /* I/O 3DD and 3DE are used by Oki if386 */ + io_sethandler(0x03c0, 0x001c, jega_in, NULL, NULL, jega_out, NULL, NULL, jega); } /* I/O 3DD and 3DE are used by Oki if386 */ - io_sethandler(0x03b0, 0x002c, jega_in, NULL, NULL, jega_out, NULL, NULL, jega); + // io_sethandler(0x03b0, 0x002c, jega_in, NULL, NULL, jega_out, NULL, NULL, jega); jega->regs[RMOD1] = 0x48; } @@ -797,40 +819,44 @@ jega_close(void *priv) { jega_t *jega = (jega_t *) priv; #ifdef ENABLE_JEGA_LOG - FILE *f; - // f = fopen("jega_font16.dmp", "wb"); - // if (f != NULL) { - // fwrite(jega->jfont_dbcs_16, DBCS16_FILESIZE, 1, f); - // fclose(f); - // } - // f = fopen("jega_font19.dmp", "wb"); - // if (f != NULL) { - // fwrite(jega->jfont_sbcs_19, SBCS19_FILESIZE, 1, f); - // fclose(f); - // } - f = fopen("jega_regs.txt", "wb"); - if (f != NULL) { - for (int i = 0; i < 49; i++) - fprintf(f, "Regs %02X: %4X\n", i, jega->regs[i]); - for (int i = 0; i < 32; i++) - fprintf(f, "Attr %02X: %4X\n", i, jega->attrregs[i]); - for (int i = 0; i < 16; i++) - fprintf(f, "JEGAPal %02X: %4X\n", i, jega->egapal[i]); - for (int i = 0; i < 16; i++) - fprintf(f, "EGAPal %02X: %4X\n", i, jega->ega.egapal[i]); - for (int i = 0; i < 64; i++) - fprintf(f, "RealPal %02X: %4X\n", i, jega->pallook[i]); + FILE *fp; +#if 0 + fp = fopen("jega_font16.dmp", "wb"); + if (fp != NULL) { + fwrite(jega->jfont_dbcs_16, DBCS16_FILESIZE, 1, fp); fclose(f); } - // f = fopen("ega_vram.dmp", "wb"); - // if (f != NULL) { - // fwrite(jega->ega.vram, 256 * 1024, 1, f); - // fclose(f); - // } - f = fopen("ram_bda.dmp", "wb"); + fp = fopen("jega_font19.dmp", "wb"); + if (fp != NULL) { + fwrite(jega->jfont_sbcs_19, SBCS19_FILESIZE, 1, fp); + fclose(fp); + } +#endif + f = fopen("jega_regs.txt", "wb"); if (f != NULL) { - fwrite(&ram[0x0], 0x500, 1, f); - fclose(f); + for (uint8_t i = 0; i < 49; i++) + fprintf(fp, "Regs %02X: %4X\n", i, jega->regs[i]); + for (uint8_t i = 0; i < 32; i++) + fprintf(fp, "Attr %02X: %4X\n", i, jega->attrregs[i]); + for (uint8_t i = 0; i < 16; i++) + fprintf(fp, "JEGAPal %02X: %4X\n", i, jega->egapal[i]); + for (uint8_t i = 0; i < 16; i++) + fprintf(fp, "EGAPal %02X: %4X\n", i, jega->ega.egapal[i]); + for (uint8_t i = 0; i < 64; i++) + fprintf(fp, "RealPal %02X: %4X\n", i, jega->pallook[i]); + fclose(fp); + } +#if 0 + fp = fopen("ega_vram.dmp", "wb"); + if (fp != NULL) { + fwrite(jega->ega.vram, 256 * 1024, 1, fp); + fclose(fp); + } +#endif + fp = fopen("ram_bda.dmp", "wb"); + if (fp != NULL) { + fwrite(&ram[0x0], 0x500, 1, fp); + fclose(fp); } pclog("jeclosed %04X:%04X DS %04X\n", cs >> 4, cpu_state.pc, DS); #endif @@ -950,7 +976,7 @@ if386_p6x_write(uint16_t port, uint8_t val, void *priv) p65[p65idx] = val; if (p65idx == 0x03) { if (val & 0x04) { /* Color monitor */ - for (int c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { pallook64[c] = makecol32(((c >> 2) & 1) * 0xaa, ((c >> 1) & 1) * 0xaa, (c & 1) * 0xaa); pallook64[c] += makecol32(((c >> 5) & 1) * 0x55, ((c >> 4) & 1) * 0x55, ((c >> 3) & 1) * 0x55); pallook16[c] = makecol32(((c >> 2) & 1) * 0xaa, ((c >> 1) & 1) * 0xaa, (c & 1) * 0xaa); @@ -959,7 +985,7 @@ if386_p6x_write(uint16_t port, uint8_t val, void *priv) pallook16[c] = makecol32(0xaa, 0x55, 0); } } else { /* Monochrome LCD */ - for (int c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { int cval = 0; #ifdef SIMPLE_BW if (c & 0x0f) diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index b0cbd203e..5330e2ab3 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -186,7 +186,7 @@ mda_poll(void *priv) // turn off bright bg colours in blink mode if ((mda->mode & MDA_MODE_BLINK) && (color_bg & 0x8)) - color_bg & ~(0x8); + color_bg &= ~(0x8); // black-on-non black or white colours forced to white // grey-on-colours forced to bright white @@ -429,13 +429,15 @@ mda_standalone_init(UNUSED(const device_t *info)) case 1: loadfont(FONT_IBM_MDA_437_NORDIC_PATH, 0); break; - case 2: loadfont(FONT_KAM_PATH, 0); break; case 3: loadfont(FONT_KAMCL16_PATH, 0); break; + case 4: + loadfont(FONT_TULIP_DGA_PATH, 0); + break; } mem_mapping_add(&mda->mapping, 0xb0000, 0x08000, @@ -514,6 +516,7 @@ static const device_config_t mda_config[] = { { .description = "IBM Nordic (CP 437-Nordic)", .value = 1 }, { .description = "Czech Kamenicky (CP 895) #1", .value = 2 }, { .description = "Czech Kamenicky (CP 895) #2", .value = 3 }, + { .description = "Tulip DGA", .value = 4 }, { .description = "" } }, .bios = { { 0 } } @@ -535,3 +538,4 @@ const device_t mda_device = { .force_redraw = NULL, .config = mda_config }; + diff --git a/src/video/vid_oak_oti.c b/src/video/vid_oak_oti.c index 70bac6425..3ea935b06 100644 --- a/src/video/vid_oak_oti.c +++ b/src/video/vid_oak_oti.c @@ -30,6 +30,7 @@ #include <86box/vid_svga.h> #include <86box/vid_svga_render.h> #include <86box/plat_unused.h> +#include "cpu.h" #define BIOS_037C_PATH "roms/video/oti/bios.bin" #define BIOS_067_AMA932J_PATH "roms/machines/ama932j/OTI067.BIN" @@ -38,13 +39,13 @@ #define BIOS_077_PATH "roms/video/oti/oti077.vbi" #define BIOS_077_ACER100T_PATH "roms/machines/acer100t/oti077_acer100t.BIN" - enum { - OTI_037C = 0, - OTI_067 = 2, - OTI_067_AMA932J = 3, - OTI_067_M300 = 4, - OTI_077 = 5, + OTI_037C = 0, + OTI_037_PBL300SX = 1, + OTI_067 = 2, + OTI_067_AMA932J = 3, + OTI_067_M300 = 4, + OTI_077 = 5, OTI_077_ACER100T = 6 }; @@ -54,6 +55,7 @@ typedef struct { rom_t bios_rom; int index; + int en_map; uint8_t regs[32]; uint8_t chip_id; @@ -76,16 +78,23 @@ oti_out(uint16_t addr, uint8_t val, void *priv) uint8_t idx; uint8_t enable; - if (!oti->chip_id && !(oti->enable_register & 1) && (addr != 0x3C3)) + if (!oti->chip_id && !(oti->enable_register & 1) && (addr != 0x3c3)) return; - if ((((addr & 0xFFF0) == 0x3D0 || (addr & 0xFFF0) == 0x3B0) && addr < 0x3de) && !(svga->miscout & 1)) + if (((((addr & 0xfff0) == 0x3d0) || ((addr & 0xfff0) == 0x3b0)) && (addr < 0x3de)) && + !(svga->miscout & 1)) addr ^= 0x60; switch (addr) { - case 0x3C3: + case 0x3c3: if (!oti->chip_id) { oti->enable_register = val & 1; + if ((val & 0x01) && oti->en_map) + mem_mapping_enable(&svga->mapping); + else if (!(val & 0x01)) { + oti->en_map = svga->mapping.enable; + mem_mapping_disable(&svga->mapping); + } return; } svga_out(addr, val, svga); @@ -95,20 +104,20 @@ oti_out(uint16_t addr, uint8_t val, void *priv) case 0x3c7: case 0x3c8: case 0x3c9: - if (oti->chip_id == OTI_077 || oti->chip_id == OTI_077_ACER100T) + if ((oti->chip_id == OTI_077) || (oti->chip_id == OTI_077_ACER100T)) sc1148x_ramdac_out(addr, 0, val, svga->ramdac, svga); else svga_out(addr, val, svga); return; - case 0x3D4: + case 0x3d4: if (oti->chip_id) svga->crtcreg = val & 0x3f; else svga->crtcreg = val; /* FIXME: The BIOS wants to set the test bit? */ return; - case 0x3D5: + case 0x3d5: if (oti->chip_id && (svga->crtcreg & 0x20)) return; idx = svga->crtcreg; @@ -124,7 +133,8 @@ oti_out(uint16_t addr, uint8_t val, void *priv) if ((idx < 0x0e) || (idx > 0x10)) { if (idx == 0x0c || idx == 0x0d) { svga->fullchange = 3; - svga->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + ((svga->crtc[8] & 0x60) >> 5); + svga->memaddr_latch = ((svga->crtc[0xc] << 8) | svga->crtc[0xd]) + + ((svga->crtc[8] & 0x60) >> 5); } else { svga->fullchange = changeframecount; svga_recalctimings(svga); @@ -133,14 +143,14 @@ oti_out(uint16_t addr, uint8_t val, void *priv) } break; - case 0x3DE: + case 0x3de: if (oti->chip_id) oti->index = val & 0x1f; else oti->index = val; return; - case 0x3DF: + case 0x3df: idx = oti->index; if (!oti->chip_id) idx &= 0x1f; @@ -223,14 +233,14 @@ oti_in(uint16_t addr, void *priv) addr ^= 0x60; switch (addr) { - case 0x3C2: + case 0x3c2: if ((svga->vgapal[0].r + svga->vgapal[0].g + svga->vgapal[0].b) >= 0x50) temp = 0; else temp = 0x10; break; - case 0x3C3: + case 0x3c3: if (oti->chip_id) temp = svga_in(addr, svga); else @@ -242,17 +252,20 @@ oti_in(uint16_t addr, void *priv) case 0x3c8: case 0x3c9: if (oti->chip_id == OTI_077 || oti->chip_id == OTI_077_ACER100T) - return sc1148x_ramdac_in(addr, 0, svga->ramdac, svga); - return svga_in(addr, svga); + temp = sc1148x_ramdac_in(addr, 0, svga->ramdac, svga); + else + temp = svga_in(addr, svga); + break; case 0x3CF: - return svga->gdcreg[svga->gdcaddr & 0xf]; + temp = svga->gdcreg[svga->gdcaddr & 0xf]; + break; - case 0x3D4: + case 0x3d4: temp = svga->crtcreg; break; - case 0x3D5: + case 0x3d5: if (oti->chip_id) { if (svga->crtcreg & 0x20) temp = 0xff; @@ -262,17 +275,19 @@ oti_in(uint16_t addr, void *priv) temp = svga->crtc[svga->crtcreg & 0x1f]; break; - case 0x3DA: + case 0x3da: if (oti->chip_id) { temp = svga_in(addr, svga); break; } svga->attrff = 0; - /*The OTI-037C BIOS waits for bits 0 and 3 in 0x3da to go low, then reads 0x3da again - and expects the diagnostic bits to equal the current border colour. As I understand - it, the 0x3da active enable status does not include the border time, so this may be - an area where OTI-037C is not entirely VGA compatible.*/ + /* + The OTI-037C BIOS waits for bits 0 and 3 in 0x3da to go low, then reads 0x3da again + and expects the diagnostic bits to equal the current border colour. As I understand + it, the 0x3da active enable status does not include the border time, so this may be + an area where OTI-037C is not entirely VGA compatible. + */ svga->cgastat &= ~0x30; /* copy color diagnostic info from the overscan color register */ switch (svga->attrregs[0x12] & 0x30) { @@ -307,13 +322,13 @@ oti_in(uint16_t addr, void *priv) temp = svga->cgastat; break; - case 0x3DE: + case 0x3de: temp = oti->index; if (oti->chip_id) temp |= (oti->chip_id << 5); break; - case 0x3DF: + case 0x3df: idx = oti->index; if (!oti->chip_id) idx &= 0x1f; @@ -441,6 +456,13 @@ oti_init(const device_t *info) #endif break; + case OTI_037_PBL300SX: + romfn = NULL; + oti->chip_id = 0; + oti->vram_size = 256; + oti->regs[0] = 0x08; /* FIXME: The BIOS wants to read this at index 0? This index is undocumented. */ + break; + case OTI_067_AMA932J: romfn = BIOS_067_AMA932J_PATH; oti->chip_id = 2; @@ -478,26 +500,25 @@ oti_init(const device_t *info) break; } - if (romfn != NULL) { + if (romfn != NULL) rom_init(&oti->bios_rom, romfn, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); - } oti->vram_mask = (oti->vram_size << 10) - 1; - if (oti->chip_id == OTI_077_ACER100T){ - /* josephillips: Required to show all BIOS - information on Acer 100T only + if (oti->chip_id == OTI_077_ACER100T) { + /* + josephillips: Required to show all BIOS + information on Acer 100T only */ - video_inform(0x1,&timing_oti); - }else{ + video_inform(0x1, &timing_oti); + } else video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_oti); - } svga_init(info, &oti->svga, oti, oti->vram_size << 10, oti_recalctimings, oti_in, oti_out, NULL, NULL); - if (oti->chip_id == OTI_077 || oti->chip_id == OTI_077_ACER100T) + if ((oti->chip_id == OTI_077) || (oti->chip_id == OTI_077_ACER100T)) oti->svga.ramdac = device_add(&sc11487_ramdac_device); /*Actually a 82c487, probably a clone.*/ io_sethandler(0x03c0, 32, @@ -662,6 +683,20 @@ const device_t oti037c_device = { .config = NULL }; +const device_t oti037_pbl300sx_device = { + .name = "Oak OTI-037 (Packard Bell Legend 300SX)", + .internal_name = "oti037_pbl300sx", + .flags = DEVICE_ISA, + .local = 1, + .init = oti_init, + .close = oti_close, + .reset = NULL, + .available = NULL, + .speed_changed = oti_speed_changed, + .force_redraw = oti_force_redraw, + .config = NULL +}; + const device_t oti067_device = { .name = "Oak OTI-067", .internal_name = "oti067", @@ -676,20 +711,6 @@ const device_t oti067_device = { .config = oti067_config }; -const device_t oti067_m300_device = { - .name = "Oak OTI-067 (Olivetti M300-08/15)", - .internal_name = "oti067_m300", - .flags = DEVICE_ISA, - .local = 4, - .init = oti_init, - .close = oti_close, - .reset = NULL, - .available = oti067_m300_available, - .speed_changed = oti_speed_changed, - .force_redraw = oti_force_redraw, - .config = oti067_config -}; - const device_t oti067_ama932j_device = { .name = "Oak OTI-067 (AMA-932J)", .internal_name = "oti067_ama932j", @@ -704,21 +725,20 @@ const device_t oti067_ama932j_device = { .config = oti067_ama932j_config }; -const device_t oti077_acer100t_device = { - .name = "Oak OTI-077 (Acer 100T)", - .internal_name = "oti077_acer100t", +const device_t oti067_m300_device = { + .name = "Oak OTI-067 (Olivetti M300-08/15)", + .internal_name = "oti067_m300", .flags = DEVICE_ISA, - .local = 6, + .local = 4, .init = oti_init, .close = oti_close, .reset = NULL, - .available = oti077_acer100t_available, + .available = oti067_m300_available, .speed_changed = oti_speed_changed, .force_redraw = oti_force_redraw, - .config = oti077_acer100t_config + .config = oti067_config }; - const device_t oti077_device = { .name = "Oak OTI-077", .internal_name = "oti077", @@ -732,3 +752,17 @@ const device_t oti077_device = { .force_redraw = oti_force_redraw, .config = oti077_config }; + +const device_t oti077_acer100t_device = { + .name = "Oak OTI-077 (Acer 100T)", + .internal_name = "oti077_acer100t", + .flags = DEVICE_ISA, + .local = 6, + .init = oti_init, + .close = oti_close, + .reset = NULL, + .available = oti077_acer100t_available, + .speed_changed = oti_speed_changed, + .force_redraw = oti_force_redraw, + .config = oti077_acer100t_config +}; diff --git a/src/video/vid_pcjr.c b/src/video/vid_pcjr.c index 17a43fb40..2b3eb730a 100644 --- a/src/video/vid_pcjr.c +++ b/src/video/vid_pcjr.c @@ -686,7 +686,7 @@ pcjr_vid_init(pcjr_t *pcjr) pcjr->memctrl &= ~0x24; display_type = device_get_config_int("display_type"); - pcjr->composite = (display_type != PCJR_RGB); + pcjr->composite = (display_type == PCJR_COMPOSITE); pcjr->apply_hd = device_get_config_int("apply_hd"); overscan_x = 256; overscan_y = 32; @@ -698,6 +698,9 @@ pcjr_vid_init(pcjr_t *pcjr) vid_in, NULL, NULL, vid_out, NULL, NULL, pcjr); timer_add(&pcjr->timer, vid_poll, pcjr, 1); - cga_palette = 0; + if (pcjr->composite) + cga_palette = 0; + else + cga_palette = (display_type << 1); cgapal_rebuild(); } diff --git a/src/video/vid_s3_virge.c b/src/video/vid_s3_virge.c index 9422f69bf..774b0d4b7 100644 --- a/src/video/vid_s3_virge.c +++ b/src/video/vid_s3_virge.c @@ -211,6 +211,7 @@ typedef struct virge_t { uint8_t pci_regs[256]; uint8_t pci_slot; + uint8_t type; int chip; int bilinear_enabled; @@ -5140,9 +5141,11 @@ s3_virge_init(const device_t *info) virge_t *virge = (virge_t *) calloc(1, sizeof(virge_t)); reset_state = calloc(1, sizeof(virge_t)); + virge->type = (info->local & 0xff); + virge->bilinear_enabled = device_get_config_int("bilinear"); virge->dithering_enabled = device_get_config_int("dithering"); - if (info->local >= S3_VIRGE_GX2) + if (virge->type >= S3_VIRGE_GX2) virge->memory_size = 4; else virge->memory_size = device_get_config_int("memory"); @@ -5150,7 +5153,7 @@ s3_virge_init(const device_t *info) virge->onboard = !!(info->local & 0x100); if (!virge->onboard) - switch (info->local) { + switch (virge->type) { case S3_VIRGE_325: bios_fn = ROM_VIRGE_325; break; @@ -5197,7 +5200,7 @@ s3_virge_init(const device_t *info) virge->svga.hwcursor.cur_ysize = 64; if (bios_fn != NULL) { - if (info->local == S3_VIRGE_GX2) + if (virge->type == S3_VIRGE_GX2) rom_init(&virge->bios_rom, bios_fn, 0xc0000, 0x10000, 0xffff, 0, MEM_MAPPING_EXTERNAL); else rom_init(&virge->bios_rom, bios_fn, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); @@ -5251,7 +5254,7 @@ s3_virge_init(const device_t *info) virge->virge_id = 0xe1; virge->is_agp = !!(info->flags & DEVICE_AGP); - switch (info->local) { + switch (virge->type) { case S3_VIRGE_325: case S3_DIAMOND_STEALTH3D_2000: case S3_MIROCRYSTAL_3D: @@ -5356,7 +5359,7 @@ s3_virge_init(const device_t *info) default: break; } - if (info->local == S3_VIRGE_GX) + if (virge->type == S3_VIRGE_GX) virge->svga.crtc[0x36] |= (1 << 2); } diff --git a/src/video/vid_svga.c b/src/video/vid_svga.c index b0d9765da..2073fb8c0 100644 --- a/src/video/vid_svga.c +++ b/src/video/vid_svga.c @@ -280,9 +280,11 @@ svga_out(uint16_t addr, uint8_t val, void *priv) case 0x3c2: svga->miscout = val; svga->vidclock = val & 4; - io_removehandler(0x03a0, 0x0020, svga->video_in, NULL, NULL, svga->video_out, NULL, NULL, svga->priv); - if (!(val & 1)) - io_sethandler(0x03a0, 0x0020, svga->video_in, NULL, NULL, svga->video_out, NULL, NULL, svga->priv); + if (svga->priv_parent == NULL) { + io_removehandler(0x03a0, 0x0020, svga->video_in, NULL, NULL, svga->video_out, NULL, NULL, svga->priv); + if (!(val & 1)) + io_sethandler(0x03a0, 0x0020, svga->video_in, NULL, NULL, svga->video_out, NULL, NULL, svga->priv); + } svga_recalctimings(svga); break; case 0x3c3: @@ -691,7 +693,6 @@ svga_recalctimings(svga_t *svga) double _dispontime_xga = 0.0; double _dispofftime_xga = 0.0; double disptime_xga = 0.0; - int vblankend; #ifdef ENABLE_SVGA_LOG int vsyncend; int hdispend; @@ -911,9 +912,9 @@ svga_recalctimings(svga_t *svga) if (xga_active && (svga->xga != NULL)) xga_recalctimings(svga); - vblankend = (svga->vblankstart & 0xffffff80) | (svga->crtc[0x16] & 0x7f); - if (vblankend <= svga->vblankstart) - vblankend += 0x00000080; + svga->vblankend = (svga->vblankstart & 0xffffff80) | (svga->crtc[0x16] & 0x7f); + if (svga->vblankend <= svga->vblankstart) + svga->vblankend += 0x00000080; if (svga->hoverride || svga->override) { if (svga->hdisp >= 2048) @@ -967,7 +968,7 @@ svga_recalctimings(svga_t *svga) } /* - 1 because + 1 but also - 2 to compensate for the + 2 added to vtotal above. */ - svga->y_add = svga->vtotal - vblankend - 1; + svga->y_add = svga->vtotal - svga->vblankend - 1; svga->monitor->mon_overscan_y = svga->y_add + abs(svga->vblankstart - svga->dispend); if ((svga->dispend >= 2048) || (svga->y_add < 0)) { @@ -976,29 +977,57 @@ svga_recalctimings(svga_t *svga) } } -#ifdef TBD +#if TBD if (ibm8514_active && (svga->dev8514 != NULL)) { if (dev->on) { - uint32_t dot8514 = dev->h_blankstart; - uint32_t adj_dot8514 = dev->h_blankstart; - uint32_t eff_mask8514 = 0x0000001f; - dev->hblank_sub = 0; + uint32_t _8514_dot = dev->h_sync_start; + uint32_t _8514_adj_dot = dev->h_sync_start; + uint32_t _8514_eff_mask = (dev->h_blank_end_val & ~0x0000001f) ? dev->h_blank_end_mask : 0x0000001f; + dev->h_blank_sub = 0; - while (adj_dot8514 < (dev->h_total << 1)) { - if (dot8514 == dev->h_total) - dot8514 = 0; + mach_log("8514/A: HDISP=%d, HDISPED=%d, Blank: %04i-%04i, Total: %04i, " + "Mask: %02X, ADJ_DOT=%04i.\n", dev->hdisp, (dev->hdisped + 1) << 3, + dev->h_sync_start, dev->h_blank_end_val, + dev->h_total, _8514_eff_mask, _8514_adj_dot); - if (adj_dot8514 >= dev->h_total) - dev->hblank_sub++; + while (_8514_adj_dot < (dev->h_total << 1)) { + if (_8514_dot == dev->h_total) + _8514_dot = 0; - if ((dot8514 & eff_mask8514) == (dev->h_blank_end_val & eff_mask8514)) + if (_8514_adj_dot >= dev->h_total) + dev->h_blank_sub++; + + mach_log("8514/A: Loop: adjdot=%d, htotal=%d, dotmask=%02x, " + "hblankendvalmask=%02x, blankendval=%02x.\n", adj_dot, + dev->h_total, _8514_dot & _8514_eff_mask, dev->h_blank_end_val & _8514_eff_mask, + dev->h_blank_end_val); + if ((_8514_dot & _8514_eff_mask) == (dev->h_blank_end_val & _8514_eff_mask)) break; - dot8514++; - adj_dot8514++; + _8514_dot++; + _8514_adj_dot++; } - dev->h_disp -= dev->hblank_sub; + uint32_t _8514_hd = dev->hdisp; + dev->hdisp -= dev->h_blank_sub; + + svga->left_overscan = svga->x_add = (dev->h_total - _8514_adj_dot - 1) << 3; + svga->monitor->mon_overscan_x = svga->x_add + (dev->h_sync_start << 3) - _8514_hd + 8; + svga->monitor->mon_overscan_x++; + + if ((dev->hdisp >= 2048) || (svga->left_overscan < 0)) { + svga->left_overscan = svga->x_add = 0; + svga->monitor->mon_overscan_x = 0; + } + + /* - 1 because + 1 but also - 2 to compensate for the + 2 added to vtotal above. */ + svga->y_add = svga->vtotal - svga->vblankend - 1; + svga->monitor->mon_overscan_y = svga->y_add + abs(svga->vblankstart - svga->dispend); + + if ((svga->dispend >= 2048) || (svga->y_add < 0)) { + svga->y_add = 0; + svga->monitor->mon_overscan_y = 0; + } } } #endif @@ -1048,7 +1077,7 @@ svga_recalctimings(svga_t *svga) "\n" "\n", svga->vtotal, svga->dispend, svga->vsyncstart, vsyncend, - svga->vblankstart, vblankend, + svga->vblankstart, svga->vblankend, svga->htotal, hdispstart, hdispend, hsyncstart, hsyncend, svga->hblankstart, svga->hblankend); @@ -1191,6 +1220,27 @@ svga_recalctimings(svga_t *svga) if (enable_overscan && (svga->monitor->mon_overscan_x != old_monitor_overscan_x || svga->monitor->mon_overscan_y != old_monitor_overscan_y)) video_force_resize_set_monitor(1, svga->monitor_index); + + svga->force_shifter_bypass = 0; + if ((svga->hdisp == 320) && (svga->dispend >= 400) && !svga->override && (svga->render != svga_render_8bpp_clone_highres)) { + svga->hdisp <<= 1; + if (svga->render == svga_render_16bpp_highres) + svga->render = svga_render_16bpp_lowres; + else if (svga->render == svga_render_15bpp_highres) + svga->render = svga_render_15bpp_lowres; + else if (svga->render == svga_render_15bpp_mix_highres) + svga->render = svga_render_15bpp_mix_lowres; + else if (svga->render == svga_render_24bpp_highres) + svga->render = svga_render_24bpp_lowres; + else if (svga->render == svga_render_32bpp_highres) + svga->render = svga_render_32bpp_lowres; + else if (svga->render == svga_render_8bpp_highres) { + svga->render = svga_render_8bpp_lowres; + svga->force_shifter_bypass = 1; + } + else + svga->hdisp >>= 1; + } } static void @@ -1548,6 +1598,7 @@ svga_init(const device_t *info, svga_t *svga, void *priv, int memsize, svga->monitor->mon_overscan_y = 32; svga->x_add = 8; svga->y_add = 16; + svga->force_shifter_bypass = 1; svga->crtc[0] = 63; svga->crtc[6] = 255; diff --git a/src/video/vid_svga_render.c b/src/video/vid_svga_render.c index bdb496686..0f9a4a253 100644 --- a/src/video/vid_svga_render.c +++ b/src/video/vid_svga_render.c @@ -118,7 +118,7 @@ svga_render_overscan_right(svga_t *svga) return; uint32_t *line_ptr = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add + svga->hdisp]; - right = (overscan_x >> 1); + right = overscan_x - svga->left_overscan; for (int i = 0; i < right; i++) *line_ptr++ = svga->overscan_color; } @@ -694,7 +694,7 @@ svga_render_indexed_gfx(svga_t *svga, bool highres, bool combine8bits) - HT-216 (+ other Video7 chipsets?) has 0x3C4.0xC8 bit 4 which, when set to 1, loads bytes directly, bypassing the shifters. */ - const bool highres8bpp = combine8bits && highres; + const bool highres8bpp = (combine8bits && highres) || svga->force_shifter_bypass; const bool dwordload = ((svga->seqregs[0x01] & 0x10) != 0); const bool wordload = ((svga->seqregs[0x01] & 0x04) != 0) && !dwordload; diff --git a/src/video/vid_table.c b/src/video/vid_table.c index 33a7f30ca..b97defe8c 100644 --- a/src/video/vid_table.c +++ b/src/video/vid_table.c @@ -52,10 +52,10 @@ video_cards[] = { // clang-format off { .device = &device_none, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &device_internal, .flags = VIDEO_FLAG_TYPE_NONE }, + /* ISA */ { .device = &atiega800p_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &mach8_vga_isa_device, .flags = VIDEO_FLAG_TYPE_8514 }, { .device = &mach32_isa_device, .flags = VIDEO_FLAG_TYPE_8514 }, - { .device = &mach64gx_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &ati28800k_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &ati18800_vga88_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &ati28800_device, .flags = VIDEO_FLAG_TYPE_NONE }, @@ -71,15 +71,6 @@ video_cards[] = { { .device = &jega_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &gd5401_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &gd5402_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &gd5420_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &gd5422_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &gd5426_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &gd5426_diamond_speedstar_pro_a1_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &gd5428_boca_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &gd5428_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &gd5429_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &gd5434_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &gd5434_diamond_speedstar_64_a3_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &compaq_cga_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &compaq_cga_2_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &cpqega_device, .flags = VIDEO_FLAG_TYPE_NONE }, @@ -88,7 +79,6 @@ video_cards[] = { { .device = &hercules_device, .flags = VIDEO_FLAG_TYPE_MDA }, { .device = &herculesplus_device, .flags = VIDEO_FLAG_TYPE_MDA }, { .device = &incolor_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &inmos_isa_device, .flags = VIDEO_FLAG_TYPE_XGA }, { .device = &im1024_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &iskra_ega_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &et4000_kasan_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, @@ -106,16 +96,8 @@ video_cards[] = { { .device = &colorplus_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &pgc_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &cga_pravetz_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &radius_svga_multiview_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &realtek_rtg3105_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &realtek_rtg3106_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_diamond_stealth_vram_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_orchid_86c911_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_ami_86c924_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_metheus_86c928_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_phoenix_86c801_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_spea_mirage_86c801_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_winner1000_805_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &sigma_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &tvga8900b_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &tvga8900d_device, .flags = VIDEO_FLAG_TYPE_NONE }, @@ -127,16 +109,76 @@ video_cards[] = { { .device = &et3000_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &et4000_tc6058af_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &et4000_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &et4000w32_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &et4000w32i_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &vga_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &v7_vga_1024i_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &wy700_device, .flags = VIDEO_FLAG_TYPE_NONE }, + /* ISA16 */ + { .device = &mach64gx_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5420_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5422_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5426_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5426_diamond_speedstar_pro_a1_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5428_boca_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5428_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5429_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5434_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5434_diamond_speedstar_64_a3_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &inmos_isa_device, .flags = VIDEO_FLAG_TYPE_XGA }, + { .device = &radius_svga_multiview_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth_vram_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_orchid_86c911_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_ami_86c924_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_metheus_86c928_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_86c801_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_spea_mirage_86c801_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_winner1000_805_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32i_isa_device, .flags = VIDEO_FLAG_TYPE_NONE }, + /* MCA */ { .device = &mach32_mca_device, .flags = VIDEO_FLAG_TYPE_8514 }, { .device = &gd5426_mca_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &gd5428_mca_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &et4000_mca_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &radius_svga_multiview_mca_device, .flags = VIDEO_FLAG_TYPE_NONE }, + /* VLB */ + { .device = &mach32_vlb_device, .flags = VIDEO_FLAG_TYPE_8514 }, + { .device = &mach64gx_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32i_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_videomagic_revb_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_revc_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_cardex_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &et4000w32p_noncardex_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5424_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5426_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5428_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5428_diamond_speedstar_pro_b1_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5429_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5430_diamond_speedstar_pro_se_a8_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5430_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &gd5434_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_metheus_86c928_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_mirocrystal_8s_805_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_mirocrystal_10sd_805_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_86c805_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_spea_mirage_86c805_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth64_964_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_mirocrystal_20sv_964_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_mirocrystal_20sd_864_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_bahamas64_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_vision864_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth_se_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_trio32_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth64_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_9fx_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_phoenix_trio64_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_spea_mirage_p64_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_diamond_stealth64_968_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &s3_stb_powergraph_64_video_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &ht216_32_standalone_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &tgui9400cxi_device, .flags = VIDEO_FLAG_TYPE_NONE }, + { .device = &tgui9440_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + /* PCI */ { .device = &mach32_pci_device, .flags = VIDEO_FLAG_TYPE_8514 }, { .device = &mach64gx_pci_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &mach64vt2_device, .flags = VIDEO_FLAG_TYPE_NONE }, @@ -200,43 +242,7 @@ video_cards[] = { { .device = &voodoo_3_1000_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &voodoo_3_2000_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &voodoo_3_3000_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &mach32_vlb_device, .flags = VIDEO_FLAG_TYPE_8514 }, - { .device = &mach64gx_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &et4000w32i_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &et4000w32p_videomagic_revb_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &et4000w32p_revc_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &et4000w32p_cardex_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &et4000w32p_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &et4000w32p_noncardex_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &gd5424_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &gd5426_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &gd5428_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &gd5428_diamond_speedstar_pro_b1_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &gd5429_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &gd5430_diamond_speedstar_pro_se_a8_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &gd5430_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &gd5434_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_metheus_86c928_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_mirocrystal_8s_805_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_mirocrystal_10sd_805_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_phoenix_86c805_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_spea_mirage_86c805_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_diamond_stealth64_964_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_mirocrystal_20sv_964_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_mirocrystal_20sd_864_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_bahamas64_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_phoenix_vision864_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_diamond_stealth_se_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_phoenix_trio32_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_diamond_stealth64_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_9fx_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_phoenix_trio64_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_spea_mirage_p64_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_diamond_stealth64_968_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &s3_stb_powergraph_64_video_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &ht216_32_standalone_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &tgui9400cxi_device, .flags = VIDEO_FLAG_TYPE_NONE }, - { .device = &tgui9440_vlb_device, .flags = VIDEO_FLAG_TYPE_NONE }, + /* AGP */ { .device = &s3_virge_357_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &s3_diamond_stealth_4000_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, { .device = &s3_trio3d2x_agp_device, .flags = VIDEO_FLAG_TYPE_NONE }, diff --git a/src/video/vid_tandy.c b/src/video/vid_tandy.c index 0609ca378..7d9b5af1a 100644 --- a/src/video/vid_tandy.c +++ b/src/video/vid_tandy.c @@ -447,7 +447,7 @@ vid_poll(void *priv) } if (vid->scanline & 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] = ((chr >= 0xb3) && (chr <= 0xdf)) ? cols[(fontdat[chr][7] & (1 << (c ^ 7))) ? 1 : 0] : cols[0]; } } else { for (c = 0; c < 8; c++) { @@ -483,7 +483,7 @@ vid_poll(void *priv) vid->memaddr++; if (vid->scanline & 8) { for (c = 0; c < 8; c++) - buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 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) + 1 + 8] = cols[0]; + buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 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) + 1 + 8] = ((chr >= 0xb3) && (chr <= 0xdf)) ? cols[(fontdat[chr][7] & (1 << (c ^ 7))) ? 1 : 0] : cols[0]; } else { for (c = 0; c < 8; c++) { if (vid->scanline == 8) {