From e1b07f2feef2fd53e0675084b312e0d05c99338c Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sat, 25 Jul 2020 12:28:13 -0300 Subject: [PATCH 1/7] Change special 440BX VPC behavior to is_vpc --- src/chipset/intel_4x0.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/chipset/intel_4x0.c b/src/chipset/intel_4x0.c index 0fb6e17d9..32025b1b7 100644 --- a/src/chipset/intel_4x0.c +++ b/src/chipset/intel_4x0.c @@ -443,10 +443,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) break; case INTEL_440BX: case INTEL_440ZX: regs[0x51] = (regs[0x50] & 0x70) | (val & 0x8f); -#if defined(DEV_BRANCH) && defined(USE_VIRTUALPC) - if (!strcmp(machines[machine].internal_name, "vpc2007")) + if (is_vpc) regs[0x51] |= 0x10; /* Virtual PC 2007 BIOS requires a reserved bus speed bit to be set */ -#endif break; case INTEL_440GX: regs[0x51] = (regs[0x50] & 0x88) | (val & 0x08); @@ -1556,10 +1554,8 @@ static void regs[0x51] |= 0x20; else if ((cpu_busspeed > 66666667) && (cpu_busspeed <= 100000000)) regs[0x51] |= 0x00; -#if defined(DEV_BRANCH) && defined(USE_VIRTUALPC) - if (!strcmp(machines[machine].internal_name, "vpc2007")) + if (is_vpc) regs[0x51] |= 0x10; /* Virtual PC 2007 BIOS requires a reserved bus speed bit to be set */ -#endif regs[0x57] = 0x28; /* 4 DIMMs, SDRAM */ regs[0x58] = 0x03; regs[0x60] = regs[0x61] = regs[0x62] = regs[0x63] = regs[0x64] = regs[0x65] = regs[0x66] = regs[0x67] = 0x01; From fea4abeae86c29857a1c86f019bebe3fcc5a6347 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sat, 25 Jul 2020 12:30:15 -0300 Subject: [PATCH 2/7] Change VPC flash type to 29ee020 (the BIOS specifies 29C020) --- src/machine/m_at_slot1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/machine/m_at_slot1.c b/src/machine/m_at_slot1.c index 1a172536f..2bf0cabac 100644 --- a/src/machine/m_at_slot1.c +++ b/src/machine/m_at_slot1.c @@ -561,7 +561,7 @@ machine_at_vpc2007_init(const machine_t *model) device_add(&w83977tf_device); device_add(&keyboard_ps2_ami_pci_device); device_add(&intel_flash_bxt_device); - device_add(&vpc2007_device); + device_add(&sst_flash_29ee020_device); spd_register(SPD_TYPE_SDRAM, 0xF, 256); /* real VPC provides invalid SPD data */ return ret; From 6e7508edb429377334a51171c593f9d00d1056fa Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sat, 25 Jul 2020 12:46:05 -0300 Subject: [PATCH 3/7] Undo the flash change (it doesn't like SST) --- src/machine/m_at_slot1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/machine/m_at_slot1.c b/src/machine/m_at_slot1.c index 2bf0cabac..1a172536f 100644 --- a/src/machine/m_at_slot1.c +++ b/src/machine/m_at_slot1.c @@ -561,7 +561,7 @@ machine_at_vpc2007_init(const machine_t *model) device_add(&w83977tf_device); device_add(&keyboard_ps2_ami_pci_device); device_add(&intel_flash_bxt_device); - device_add(&sst_flash_29ee020_device); + device_add(&vpc2007_device); spd_register(SPD_TYPE_SDRAM, 0xF, 256); /* real VPC provides invalid SPD data */ return ret; From 4d621e2f4f6c3b3bea59913bc452399c798e6384 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sat, 25 Jul 2020 12:48:20 -0300 Subject: [PATCH 4/7] Fix crashes caused by an invalid CPU index --- src/config.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index da58b02e8..9aead9a0f 100644 --- a/src/config.c +++ b/src/config.c @@ -531,7 +531,18 @@ load_machine(void) machine = machine_count() - 1; cpu_manufacturer = config_get_int(cat, "cpu_manufacturer", 0); + if ((cpu_manufacturer >= (sizeof(machines[machine].cpu) / sizeof(machines[machine].cpu[0]))) || + (machines[machine].cpu[cpu_manufacturer].cpus == NULL)) + cpu_manufacturer = 0; + cpu = config_get_int(cat, "cpu", 0); + for (int i = 0; i != cpu; i++) { + if (machines[machine].cpu[cpu_manufacturer].cpus[i].cpu_type == -1) { + cpu = 0; + break; + } + } + cpu_waitstates = config_get_int(cat, "cpu_waitstates", 0); p = (char *)config_get_string(cat, "fpu_type", "none"); @@ -543,7 +554,7 @@ load_machine(void) if (mem_size < (((machines[machine].flags & MACHINE_AT) && (machines[machine].ram_granularity < 128)) ? machines[machine].min_ram*1024 : machines[machine].min_ram)) mem_size = (((machines[machine].flags & MACHINE_AT) && (machines[machine].ram_granularity < 128)) ? machines[machine].min_ram*1024 : machines[machine].min_ram); -#endif +#endif if (mem_size > 2097152) mem_size = 2097152; From 01b6662809e69335aaee8e9e7e3c8e42ee2ab773 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sat, 25 Jul 2020 13:19:24 -0300 Subject: [PATCH 5/7] Add unified BCD macros for SPD and (in the future) VPCEXT --- src/include/86box/86box.h | 7 +++++-- src/mem/spd.c | 9 ++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/include/86box/86box.h b/src/include/86box/86box.h index 11c250201..885f81011 100644 --- a/src/include/86box/86box.h +++ b/src/include/86box/86box.h @@ -45,8 +45,11 @@ # define ENABLE_LOG_COMMANDS 1 #endif -#define MIN(a, b) ((a) < (b) ? (a) : (b)) -#define ABS(x) ((x) > 0 ? (x) : -(x)) +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#define ABS(x) ((x) > 0 ? (x) : -(x)) +#define BCD8(x) ((((x) / 10) << 4) | ((x) % 10)) +#define BCD16(x) ((((x) / 1000) << 12) | (((x) / 100) << 8) | BCD8(x)) +#define BCD32(x) ((((x) / 10000000) << 28) | (((x) / 1000000) << 24) | (((x) / 100000) << 20) | (((x) / 10000) << 16) | BCD16(x)) #ifdef __cplusplus extern "C" { diff --git a/src/mem/spd.c b/src/mem/spd.c index f65417f9f..0268c1d5a 100644 --- a/src/mem/spd.c +++ b/src/mem/spd.c @@ -29,7 +29,6 @@ #include <86box/machine.h> -#define MIN(a, b) ((a) < (b) ? (a) : (b)) #define SPD_ROLLUP(x) ((x) >= 16 ? ((x) - 15) : (x)) @@ -328,8 +327,8 @@ spd_register(uint8_t ram_type, uint8_t slot_mask, uint16_t max_module_size) sprintf(edo_data->part_no, EMU_NAME "-%s-%03dM", (ram_type == SPD_TYPE_FPM) ? "FPM" : "EDO", vslots[vslot]); for (i = strlen(edo_data->part_no); i < sizeof(edo_data->part_no); i++) edo_data->part_no[i] = ' '; /* part number should be space-padded */ - edo_data->rev_code[0] = EMU_VERSION_MAJ; - edo_data->rev_code[1] = (((EMU_VERSION_MIN / 10) << 4) | (EMU_VERSION_MIN % 10)); + edo_data->rev_code[0] = BCD8(EMU_VERSION_MAJ); + edo_data->rev_code[1] = BCD8(EMU_VERSION_MIN); edo_data->mfg_year = 20; edo_data->mfg_week = 17; @@ -383,8 +382,8 @@ spd_register(uint8_t ram_type, uint8_t slot_mask, uint16_t max_module_size) sprintf(sdram_data->part_no, EMU_NAME "-SDR-%03dM", vslots[vslot]); for (i = strlen(sdram_data->part_no); i < sizeof(sdram_data->part_no); i++) sdram_data->part_no[i] = ' '; /* part number should be space-padded */ - sdram_data->rev_code[0] = EMU_VERSION_MAJ; - sdram_data->rev_code[1] = (((EMU_VERSION_MIN / 10) << 4) | (EMU_VERSION_MIN % 10)); + sdram_data->rev_code[0] = BCD8(EMU_VERSION_MAJ); + sdram_data->rev_code[1] = BCD8(EMU_VERSION_MIN); sdram_data->mfg_year = 20; sdram_data->mfg_week = 13; From 739ba81eb4389a84b6b5e52821ddbdb2b943ceb4 Mon Sep 17 00:00:00 2001 From: Agetian Date: Sun, 26 Jul 2020 20:07:13 +0300 Subject: [PATCH 6/7] Avoid SDL crash when starting 86Box in initial fullscreen mode (#946) --- src/win/win_ui.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/win/win_ui.c b/src/win/win_ui.c index 304aa246f..ff5f01875 100644 --- a/src/win/win_ui.c +++ b/src/win/win_ui.c @@ -1027,10 +1027,6 @@ ui_init(int nCmdShow) return(5); } - /* Initialize the rendering window, or fullscreen. */ - if (start_in_fullscreen) - plat_setfullscreen(1); - /* Set up the current window size. */ plat_resize(scrnsz_x, scrnsz_y); @@ -1040,6 +1036,10 @@ ui_init(int nCmdShow) /* Set the PAUSE mode depending on the renderer. */ plat_pause(0); + /* Initialize the rendering window, or fullscreen. */ + if (start_in_fullscreen) + plat_setfullscreen(1); + /* If so requested via the command line, inform the * application that started us of our HWND, using the * the hWnd and unique ID the application has given From a8855733ec7c18c9f4e8096e73199d65c2e781a7 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Sun, 26 Jul 2020 17:49:12 -0300 Subject: [PATCH 7/7] Implement more VPCEXT opcodes --- src/cpu/386_ops.h | 71 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/src/cpu/386_ops.h b/src/cpu/386_ops.h index 33f7365dd..2b6be6aa9 100644 --- a/src/cpu/386_ops.h +++ b/src/cpu/386_ops.h @@ -204,11 +204,15 @@ extern void x386_dynarec_log(const char *fmt, ...); #include "x86_ops_shift.h" #include "x86_ops_amd.h" #include "x86_ops_3dnow.h" +#include static int opVPCEXT(uint32_t fetchdat) { uint8_t b1, b2; + uint16_t cent; + time_t now; + struct tm *tm; if (!is_vpc) return ILLEGAL(fetchdat); @@ -222,23 +226,68 @@ static int opVPCEXT(uint32_t fetchdat) CLOCK_CYCLES(1); + if (b1 == 0x03) { + (void)time(&now); + tm = localtime(&now); + } + if ((b1 == 0x07) && (b2 == 0x0b)) { - EBX = 0x00000000; - EDX = 0x00000003; + switch (EAX) { + case 0x00000000: + EDX = 0x00000003; + break; + + case 0x00000001: + EDX = 0x00000012; + break; + + case 0x00000002: + case 0x00000003: + case 0x00000004: + case 0x00000005: + EDX = 0x00000001; + break; + + case 0x00000007: + EDX = 0x0000009c; + break; + + default: + EDX = 0x00000000; + if (EAX > 0x00000012) + cpu_state.flags &= ~(Z_FLAG); + } } else if ((b1 == 0x03) && (b2 == 0x00)) { - /* TODO: Return host BCD time in DX/CX/AX */ - EDX = 0x00000000; - ECX = 0x00000000; - EAX = 0x00000000; + EDX = BCD8(tm->tm_hour); + ECX = BCD8(tm->tm_min); + EAX = BCD8(tm->tm_sec); } else if ((b1 == 0x03) && (b2 == 0x01)) { - /* TODO: Return host BCD date in DX/CX/AX */ - EDX = 0x00000001; - ECX = 0x00000001; - EAX = 0x00001980; + EDX = BCD8(tm->tm_year % 100); + ECX = BCD8(tm->tm_mon + 1); + EAX = BCD8(tm->tm_mday); + cent = (((tm->tm_year - (tm->tm_year % 100)) / 100) % 4); + EBX = ((tm->tm_mday + tm->tm_mon + (tm->tm_year % 100) + cent + 3) % 7); + } else if ((b1 == 0x03) && (b2 == 0x03)) { + EDX = tm->tm_hour; + ECX = tm->tm_min; + EAX = tm->tm_sec; + } else if ((b1 == 0x03) && (b2 == 0x04)) { + EDX = 1900 + tm->tm_year; + ECX = tm->tm_mon + 1; + EBX = tm->tm_mday; + } else if ((b1 == 0x03) && (b2 == 0x05)) { + EBX = 0x0000000F; + ECX = 0x0000000A; + } else if ((b1 == 0x03) && (b2 == 0x06)) { + /* Some kind of timestamp. BX jumps around very quickly, CX not so much. */ + EBX = 0x00000000; + ECX = 0x00000000; + } else if ((b1 == 0x03) && (b2 >= 0x07)) { + cpu_state.flags &= ~(Z_FLAG); } else if ((b1 == 0x0a) && (b2 == 0x00)) { EAX = mem_size; } else if ((b1 == 0x11) && (b2 == 0x00)) - ; /* Do nothing */ + EAX = 0x00000000; else if ((b1 == 0x11) && (b2 == 0x01)) { EAX = 0x00000000; cpu_state.flags &= ~(Z_FLAG);