From fc832333fca5c8aa5369b1c08efc5da4cfeb2a83 Mon Sep 17 00:00:00 2001 From: TC1995 Date: Mon, 19 Jul 2021 00:11:45 +0200 Subject: [PATCH 01/10] Fixed S3 Trio32 PCI ID. --- src/video/vid_s3.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/video/vid_s3.c b/src/video/vid_s3.c index cb1c4043a..1730358ff 100644 --- a/src/video/vid_s3.c +++ b/src/video/vid_s3.c @@ -6148,7 +6148,8 @@ static void *s3_init(const device_t *info) case S3_DIAMOND_STEALTH_SE: svga->decode_mask = (4 << 20) - 1; s3->id = 0xe1; /*Trio32*/ - s3->id_ext = s3->id_ext_pci = 0x10; + s3->id_ext = 0x10; + s3->id_ext_pci = 0x11; s3->packed_mmio = 1; svga->clock_gen = s3; From faee9c85edd8acde67c6a4f45d1dc1aad7e121ac Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 19 Jul 2021 02:07:47 +0200 Subject: [PATCH 02/10] A newly created configuration is now instantly marked as changed - fixes the status bar in such circumstances. --- src/config.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/config.c b/src/config.c index d412e1553..d7ed15b3c 100644 --- a/src/config.c +++ b/src/config.c @@ -1804,6 +1804,8 @@ config_load(void) memset(zip_drives, 0, sizeof(zip_drive_t)); if (! config_read(cfg_path)) { + config_changed = 1; + cpu_f = (cpu_family_t *) &cpu_families[0]; cpu = 0; #ifdef USE_LANGUAGE From 9adf0fdcc437830de6245de568eaabdd4501cdd5 Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 19 Jul 2021 02:27:22 +0200 Subject: [PATCH 03/10] Added the ability for keyboard to require capture, in order for 86Box keyboard input to operate like VMWare, closes #829. --- src/config.c | 7 ++ src/include/86box/plat.h | 2 + src/include/86box/resource.h | 21 ++--- src/win/86Box.rc | 1 + src/win/win_keyboard.c | 153 ++++++++++++++++++----------------- src/win/win_ui.c | 22 +++-- 6 files changed, 114 insertions(+), 92 deletions(-) diff --git a/src/config.c b/src/config.c index d7ed15b3c..0d4490025 100644 --- a/src/config.c +++ b/src/config.c @@ -513,6 +513,7 @@ load_general(void) } sound_gain = config_get_int(cat, "sound_gain", 0); + kbd_req_capture = config_get_int(cat, "kbd_req_capture", 0); confirm_reset = config_get_int(cat, "confirm_reset", 1); confirm_exit = config_get_int(cat, "confirm_exit", 1); @@ -1811,6 +1812,7 @@ config_load(void) #ifdef USE_LANGUAGE plat_langid = 0x0409; #endif + kbd_req_capture = 0; scale = 1; machine = machine_get_machine_from_internal_name("ibmpc"); fpu_type = fpu_get_type(cpu_f, cpu, "none"); @@ -1970,6 +1972,11 @@ save_general(void) else config_delete_var(cat, "sound_gain"); + if (kbd_req_capture != 0) + config_set_int(cat, "kbd_req_capture", kbd_req_capture); + else + config_delete_var(cat, "kbd_req_capture"); + if (confirm_reset != 1) config_set_int(cat, "confirm_reset", confirm_reset); else diff --git a/src/include/86box/plat.h b/src/include/86box/plat.h index a44f4924c..4eb6d6a80 100644 --- a/src/include/86box/plat.h +++ b/src/include/86box/plat.h @@ -80,6 +80,8 @@ extern int update_icons; extern int unscaled_size_x, /* current unscaled size X */ unscaled_size_y; /* current unscaled size Y */ +extern int kbd_req_capture; + /* System-related functions. */ extern char *fix_exe_path(char *str); extern FILE *plat_fopen(const char *path, const char *mode); diff --git a/src/include/86box/resource.h b/src/include/86box/resource.h index c02e1d7ac..64ea4690a 100644 --- a/src/include/86box/resource.h +++ b/src/include/86box/resource.h @@ -285,17 +285,18 @@ #define IDM_ABOUT 40001 #define IDC_ABOUT_ICON 65535 -#define IDM_ACTION_RCTRL_IS_LALT 40010 -#define IDM_ACTION_SCREENSHOT 40011 -#define IDM_ACTION_HRESET 40012 -#define IDM_ACTION_RESET_CAD 40013 -#define IDM_ACTION_EXIT 40014 -#define IDM_ACTION_CTRL_ALT_ESC 40015 -#define IDM_ACTION_PAUSE 40016 +#define IDM_ACTION_KBD_REQ_CAPTURE 40010 +#define IDM_ACTION_RCTRL_IS_LALT 40011 +#define IDM_ACTION_SCREENSHOT 40012 +#define IDM_ACTION_HRESET 40013 +#define IDM_ACTION_RESET_CAD 40014 +#define IDM_ACTION_EXIT 40015 +#define IDM_ACTION_CTRL_ALT_ESC 40016 +#define IDM_ACTION_PAUSE 40017 #ifdef MTR_ENABLED -#define IDM_ACTION_BEGIN_TRACE 40017 -#define IDM_ACTION_END_TRACE 40018 -#define IDM_ACTION_TRACE 40019 +#define IDM_ACTION_BEGIN_TRACE 40018 +#define IDM_ACTION_END_TRACE 40019 +#define IDM_ACTION_TRACE 40020 #endif #define IDM_CONFIG 40020 #define IDM_CONFIG_LOAD 40021 diff --git a/src/win/86Box.rc b/src/win/86Box.rc index 145c90f5a..8ba956285 100644 --- a/src/win/86Box.rc +++ b/src/win/86Box.rc @@ -45,6 +45,7 @@ MainMenu MENU DISCARDABLE BEGIN POPUP "&Action" BEGIN + MENUITEM "&Keyboard requires capture", IDM_ACTION_KBD_REQ_CAPTURE MENUITEM "&Right CTRL is left ALT", IDM_ACTION_RCTRL_IS_LALT MENUITEM SEPARATOR MENUITEM "&Hard Reset", IDM_ACTION_HRESET diff --git a/src/win/win_keyboard.c b/src/win/win_keyboard.c index 8d286e297..e60da87d4 100644 --- a/src/win/win_keyboard.c +++ b/src/win/win_keyboard.c @@ -114,89 +114,92 @@ keyboard_handle(PRAWINPUT raw) static int recv_lalt = 0, recv_ralt = 0, recv_tab = 0; RAWKEYBOARD rawKB = raw->data.keyboard; - scancode = rawKB.MakeCode; + scancode = rawKB.MakeCode; - /* If it's not a scan code that starts with 0xE1 */ - if (!(rawKB.Flags & RI_KEY_E1)) { - if (rawKB.Flags & RI_KEY_E0) - scancode |= 0x100; + if (kbd_req_capture && !mouse_capture && !video_fullscreen) + return; - /* Translate the scan code to 9-bit */ - scancode = convert_scan_code(scancode); + /* If it's not a scan code that starts with 0xE1 */ + if (!(rawKB.Flags & RI_KEY_E1)) { + if (rawKB.Flags & RI_KEY_E0) + scancode |= 0x100; - /* Remap it according to the list from the Registry */ - if (scancode != scancode_map[scancode]) - pclog("Scan code remap: %03X -> %03X\n", scancode, scancode); - scancode = scancode_map[scancode]; + /* Translate the scan code to 9-bit */ + scancode = convert_scan_code(scancode); - /* If it's not 0xFFFF, send it to the emulated - keyboard. - We use scan code 0xFFFF to mean a mapping that - has a prefix other than E0 and that is not E1 1D, - which is, for our purposes, invalid. */ - if ((scancode == 0x00F) && - !(rawKB.Flags & RI_KEY_BREAK) && - (recv_lalt || recv_ralt) && - !mouse_capture) { - /* We received a TAB while ALT was pressed, while the mouse - is not captured, suppress the TAB and send an ALT key up. */ - if (recv_lalt) { - keyboard_input(0, 0x038); - /* Extra key press and release so the guest is not stuck in the - menu bar. */ - keyboard_input(1, 0x038); - keyboard_input(0, 0x038); - recv_lalt = 0; - } - if (recv_ralt) { - keyboard_input(0, 0x138); - /* Extra key press and release so the guest is not stuck in the - menu bar. */ - keyboard_input(1, 0x138); - keyboard_input(0, 0x138); - recv_ralt = 0; - } - } else if (((scancode == 0x038) || (scancode == 0x138)) && - !(rawKB.Flags & RI_KEY_BREAK) && - recv_tab && - !mouse_capture) { - /* We received an ALT while TAB was pressed, while the mouse - is not captured, suppress the ALT and send a TAB key up. */ - keyboard_input(0, 0x00F); - recv_tab = 0; - } else { - switch(scancode) { - case 0x00F: - recv_tab = !(rawKB.Flags & RI_KEY_BREAK); - break; - case 0x038: - recv_lalt = !(rawKB.Flags & RI_KEY_BREAK); - break; - case 0x138: - recv_ralt = !(rawKB.Flags & RI_KEY_BREAK); - break; - } + /* Remap it according to the list from the Registry */ + if (scancode != scancode_map[scancode]) + pclog("Scan code remap: %03X -> %03X\n", scancode, scancode); + scancode = scancode_map[scancode]; - /* Translate right CTRL to left ALT if the user has so - chosen. */ - if ((scancode == 0x11D) && rctrl_is_lalt) - scancode = 0x038; - - /* Normal scan code pass through, pass it through as is if - it's not an invalid scan code. */ - if (scancode != 0xFFFF) - keyboard_input(!(rawKB.Flags & RI_KEY_BREAK), scancode); + /* If it's not 0xFFFF, send it to the emulated + keyboard. + We use scan code 0xFFFF to mean a mapping that + has a prefix other than E0 and that is not E1 1D, + which is, for our purposes, invalid. */ + if ((scancode == 0x00F) && + !(rawKB.Flags & RI_KEY_BREAK) && + (recv_lalt || recv_ralt) && + !mouse_capture) { + /* We received a TAB while ALT was pressed, while the mouse + is not captured, suppress the TAB and send an ALT key up. */ + if (recv_lalt) { + keyboard_input(0, 0x038); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x038); + keyboard_input(0, 0x038); + recv_lalt = 0; } + if (recv_ralt) { + keyboard_input(0, 0x138); + /* Extra key press and release so the guest is not stuck in the + menu bar. */ + keyboard_input(1, 0x138); + keyboard_input(0, 0x138); + recv_ralt = 0; + } + } else if (((scancode == 0x038) || (scancode == 0x138)) && + !(rawKB.Flags & RI_KEY_BREAK) && + recv_tab && + !mouse_capture) { + /* We received an ALT while TAB was pressed, while the mouse + is not captured, suppress the ALT and send a TAB key up. */ + keyboard_input(0, 0x00F); + recv_tab = 0; } else { - if (rawKB.MakeCode == 0x1D) { - scancode = scancode_map[0x100]; /* Translate E1 1D to 0x100 (which would - otherwise be E0 00 but that is invalid - anyway). - Also, take a potential mapping into - account. */ - } else - scancode = 0xFFFF; + switch(scancode) { + case 0x00F: + recv_tab = !(rawKB.Flags & RI_KEY_BREAK); + break; + case 0x038: + recv_lalt = !(rawKB.Flags & RI_KEY_BREAK); + break; + case 0x138: + recv_ralt = !(rawKB.Flags & RI_KEY_BREAK); + break; + } + + /* Translate right CTRL to left ALT if the user has so + chosen. */ + if ((scancode == 0x11D) && rctrl_is_lalt) + scancode = 0x038; + + /* Normal scan code pass through, pass it through as is if + it's not an invalid scan code. */ if (scancode != 0xFFFF) keyboard_input(!(rawKB.Flags & RI_KEY_BREAK), scancode); } + } else { + if (rawKB.MakeCode == 0x1D) { + scancode = scancode_map[0x100]; /* Translate E1 1D to 0x100 (which would + otherwise be E0 00 but that is invalid + anyway). + Also, take a potential mapping into + account. */ + } else + scancode = 0xFFFF; + if (scancode != 0xFFFF) + keyboard_input(!(rawKB.Flags & RI_KEY_BREAK), scancode); + } } diff --git a/src/win/win_ui.c b/src/win/win_ui.c index 3773d369c..85595fe62 100644 --- a/src/win/win_ui.c +++ b/src/win/win_ui.c @@ -67,6 +67,7 @@ int infocus = 1, button_down = 0; int rctrl_is_lalt = 0; int user_resize = 0; int fixed_size_x = 0, fixed_size_y = 0; +int kbd_req_capture = 0; extern char openfilestring[512]; extern WCHAR wopenfilestring[512]; @@ -80,11 +81,9 @@ static int hook_enabled = 0; #endif static int manager_wm = 0; static int save_window_pos = 0, pause_state = 0; -static int dpi = 96; -static int padded_frame = 0; - - -static int vis = -1; +static int dpi = 96; +static int padded_frame = 0; +static int vis = -1; /* Per Monitor DPI Aware v2 APIs, Windows 10 v1703+ */ void* user32_handle = NULL; @@ -263,6 +262,7 @@ ResetAllMenus(void) #endif CheckMenuItem(menuMain, IDM_ACTION_RCTRL_IS_LALT, MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_ACTION_KBD_REQ_CAPTURE, MF_UNCHECKED); CheckMenuItem(menuMain, IDM_UPDATE_ICONS, MF_UNCHECKED); @@ -328,6 +328,7 @@ ResetAllMenus(void) CheckMenuItem(menuMain, IDM_VID_GRAY_RGB+4, MF_UNCHECKED); CheckMenuItem(menuMain, IDM_ACTION_RCTRL_IS_LALT, rctrl_is_lalt ? MF_CHECKED : MF_UNCHECKED); + CheckMenuItem(menuMain, IDM_ACTION_KBD_REQ_CAPTURE, kbd_req_capture ? MF_CHECKED : MF_UNCHECKED); CheckMenuItem(menuMain, IDM_UPDATE_ICONS, update_icons ? MF_CHECKED : MF_UNCHECKED); @@ -406,7 +407,8 @@ LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) BOOL bControlKeyDown; KBDLLHOOKSTRUCT *p; - if (nCode < 0 || nCode != HC_ACTION || (!mouse_capture && !video_fullscreen)) + if (nCode < 0 || nCode != HC_ACTION || + (!mouse_capture && !video_fullscreen) || (kbd_req_capture && !mouse_capture && !video_fullscreen)) return(CallNextHookEx(hKeyboardHook, nCode, wParam, lParam)); p = (KBDLLHOOKSTRUCT*)lParam; @@ -671,6 +673,12 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) config_save(); break; + case IDM_ACTION_KBD_REQ_CAPTURE: + kbd_req_capture ^= 1; + CheckMenuItem(hmenu, IDM_ACTION_KBD_REQ_CAPTURE, kbd_req_capture ? MF_CHECKED : MF_UNCHECKED); + config_save(); + break; + case IDM_ACTION_PAUSE: plat_pause(dopause ^ 1); CheckMenuItem(menuMain, IDM_ACTION_PAUSE, dopause ? MF_CHECKED : MF_UNCHECKED); @@ -1688,7 +1696,7 @@ plat_mouse_capture(int on) { RECT rect; - if (mouse_type == MOUSE_TYPE_NONE) + if (!kbd_req_capture && (mouse_type == MOUSE_TYPE_NONE)) return; if (on && !mouse_capture) { From 4a2e46b9ccecd73c39a315ac6f0715aa1bae8ab2 Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 19 Jul 2021 02:33:46 +0200 Subject: [PATCH 04/10] Added the ability for the Toshiba T1000 and T1200 to disable the backlight, closes #798. --- src/machine/m_xt_t1000_vid.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/machine/m_xt_t1000_vid.c b/src/machine/m_xt_t1000_vid.c index 667b0416f..b0c81eb01 100644 --- a/src/machine/m_xt_t1000_vid.c +++ b/src/machine/m_xt_t1000_vid.c @@ -118,7 +118,7 @@ typedef struct t1000_t int vc; int dispon; int vsynctime; - uint8_t video_options; + uint8_t video_options, backlight; uint8_t *vram; } t1000_t; @@ -588,8 +588,13 @@ static void t1000_recalcattrs(t1000_t *t1000) * are bold */ /* Set up colours */ - blue = makecol(0x2D, 0x39, 0x5A); - grey = makecol(0x85, 0xa0, 0xD6); + if (t1000->backlight) { + blue = makecol(0x2D, 0x39, 0x5A); + grey = makecol(0x85, 0xa0, 0xD6); + } else { + blue = makecol(0x0f, 0x21, 0x3f); + grey = makecol(0x1C, 0x71, 0x31); + } /* Initialise the attribute mapping. Start by defaulting everything * to grey on blue, and with bold set by bit 3 */ @@ -681,6 +686,7 @@ static void *t1000_init(const device_t *info) video_inform(VIDEO_FLAG_TYPE_CGA, &timing_t1000); t1000->internal = 1; + t1000->backlight = device_get_config_int("backlight"); /* 16k video RAM */ t1000->vram = malloc(0x4000); @@ -740,6 +746,9 @@ static const device_config_t t1000_config[] = }, .default_int = 0 }, + { + "backlight", "Enable backlight", CONFIG_BINARY, "", 1 + }, { .type = -1 } From 4b25a22adabbe27cec9b81d0fb812f7ec6371e1a Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 19 Jul 2021 02:41:43 +0200 Subject: [PATCH 05/10] Added the ability to invert LCD colors for the Toshiba T1000 and T1200, and the Amstrad PPC512/640. --- src/machine/m_amstrad.c | 19 ++++++++++++++++--- src/machine/m_xt_t1000_vid.c | 28 ++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/machine/m_amstrad.c b/src/machine/m_amstrad.c index c4ace48f0..be44fa734 100644 --- a/src/machine/m_amstrad.c +++ b/src/machine/m_amstrad.c @@ -108,7 +108,8 @@ typedef struct { stat; uint8_t plane_write, /* 1512/200 */ plane_read, /* 1512/200 */ - border; /* 1512/200 */ + border, /* 1512/200 */ + invert; /* 512/640 */ int fontbase; /* 1512/200 */ int linepos, displine; @@ -1695,8 +1696,17 @@ vid_init_200(amstrad_t *ams) overscan_x = overscan_y = 16; - green = makecol(0x1C, 0x71, 0x31); - blue = makecol(0x0f, 0x21, 0x3f); + if (ams->type == AMS_PC200) + vid->invert = 0; + else + vid->invert = device_get_config_int("invert"); + if (vid->invert) { + blue = makecol(0x1C, 0x71, 0x31); + green = makecol(0x0f, 0x21, 0x3f); + } else { + green = makecol(0x1C, 0x71, 0x31); + blue = makecol(0x0f, 0x21, 0x3f); + } cgapal_rebuild(); set_lcd_cols(0); @@ -1954,6 +1964,9 @@ device_config_t vid_ppc512_config[] = } } }, + { + "invert", "Invert LCD colors", CONFIG_BINARY, "", 0 + }, { "", "", -1 } diff --git a/src/machine/m_xt_t1000_vid.c b/src/machine/m_xt_t1000_vid.c index b0c81eb01..c3930d29e 100644 --- a/src/machine/m_xt_t1000_vid.c +++ b/src/machine/m_xt_t1000_vid.c @@ -118,7 +118,8 @@ typedef struct t1000_t int vc; int dispon; int vsynctime; - uint8_t video_options, backlight; + uint8_t video_options; + uint8_t backlight, invert; uint8_t *vram; } t1000_t; @@ -588,12 +589,22 @@ static void t1000_recalcattrs(t1000_t *t1000) * are bold */ /* Set up colours */ - if (t1000->backlight) { - blue = makecol(0x2D, 0x39, 0x5A); - grey = makecol(0x85, 0xa0, 0xD6); + if (t1000->invert) { + if (t1000->backlight) { + grey = makecol(0x2D, 0x39, 0x5A); + blue = makecol(0x85, 0xa0, 0xD6); + } else { + grey = makecol(0x0f, 0x21, 0x3f); + blue = makecol(0x1C, 0x71, 0x31); + } } else { - blue = makecol(0x0f, 0x21, 0x3f); - grey = makecol(0x1C, 0x71, 0x31); + if (t1000->backlight) { + blue = makecol(0x2D, 0x39, 0x5A); + grey = makecol(0x85, 0xa0, 0xD6); + } else { + blue = makecol(0x0f, 0x21, 0x3f); + grey = makecol(0x1C, 0x71, 0x31); + } } /* Initialise the attribute mapping. Start by defaulting everything @@ -686,7 +697,9 @@ static void *t1000_init(const device_t *info) video_inform(VIDEO_FLAG_TYPE_CGA, &timing_t1000); t1000->internal = 1; + t1000->backlight = device_get_config_int("backlight"); + t1000->invert = device_get_config_int("invert"); /* 16k video RAM */ t1000->vram = malloc(0x4000); @@ -749,6 +762,9 @@ static const device_config_t t1000_config[] = { "backlight", "Enable backlight", CONFIG_BINARY, "", 1 }, + { + "invert", "Invert colors", CONFIG_BINARY, "", 0 + }, { .type = -1 } From e1837929f0250bf937d4f5bb316cd1befb5f596d Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 19 Jul 2021 08:49:14 +0200 Subject: [PATCH 06/10] IDE no longer pulls down status bit 7 when nothing is attached - fixes delays on most AMI BIOS'es. --- src/disk/hdc_ide.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/disk/hdc_ide.c b/src/disk/hdc_ide.c index 6953bda83..f7740fab8 100644 --- a/src/disk/hdc_ide.c +++ b/src/disk/hdc_ide.c @@ -1882,7 +1882,11 @@ static uint8_t ide_status(ide_t *ide, ide_t *ide_other, int ch) { if ((ide->type == IDE_NONE) && ((ide_other->type == IDE_NONE) || !(ch & 1))) +#ifdef STATUS_BIT_7_PULLDOWN return 0x7F; /* Bit 7 pulled down, all other bits pulled up, per the spec. */ +#else + return 0xFF; +#endif else if ((ide->type == IDE_NONE) && (ch & 1)) return 0x00; /* On real hardware, a slave with a present master always returns a status of 0x00. */ else if (ide->type == IDE_ATAPI) From 803ae780ac7dcac5ac73672fd1e4d1c9feda9f26 Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 20 Jul 2021 05:54:37 +0200 Subject: [PATCH 07/10] Removed excess ACPI logging and reverted a test AT NVR change that was never supposed to be committed, fixes OS/2 2.x. --- src/acpi.c | 1 - src/nvr_at.c | 4 ---- 2 files changed, 5 deletions(-) diff --git a/src/acpi.c b/src/acpi.c index 0f28bd8af..ef336105f 100644 --- a/src/acpi.c +++ b/src/acpi.c @@ -1070,7 +1070,6 @@ acpi_reg_write_via_596b(int size, uint16_t addr, uint8_t val, void *p) break; case 0x4c: case 0x4d: case 0x4e: case 0x4f: /* GPO Port Output Value */ - pclog("Write %02X to %02X\n", val, addr); dev->regs.gpo_val = ((dev->regs.gpo_val & ~(0xff << shift32)) | (val << shift32)) & 0x7fffffff; break; default: diff --git a/src/nvr_at.c b/src/nvr_at.c index 3b4fc7957..733eac250 100644 --- a/src/nvr_at.c +++ b/src/nvr_at.c @@ -691,10 +691,6 @@ nvr_read(uint16_t addr, void *priv) ret = (nvr->regs[RTC_REGA] & 0x7f) | local->stat; break; - case RTC_REGB: - ret = nvr->regs[local->addr[addr_id]] | 0x40; - break; - case RTC_REGC: picintc(1 << nvr->irq); ret = nvr->regs[RTC_REGC]; From 706ad0e8962a588baaee3b02421dc2d36fd563cb Mon Sep 17 00:00:00 2001 From: OBattler Date: Wed, 21 Jul 2021 04:05:40 +0200 Subject: [PATCH 08/10] Changed the way the emulator is shut down, fixes #1555. --- src/86box.c | 12 +++--------- src/include/86box/86box.h | 2 ++ src/include/86box/plat.h | 2 +- src/win/win.c | 18 +++++++++++------- src/win/win_ui.c | 13 +++++++------ 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/86box.c b/src/86box.c index 3f9517e04..de6bebfcd 100644 --- a/src/86box.c +++ b/src/86box.c @@ -85,7 +85,7 @@ and declared here instead. */ int dopause; /* system is paused */ int doresize; /* screen resize requested */ -int is_quit; /* system exit requested */ +volatile int is_quit; /* system exit requested */ uint64_t timer_freq; char emu_version[200]; /* version ID string */ @@ -919,14 +919,8 @@ pc_close(thread_t *ptr) /* Claim the video blitter. */ startblit(); - /* Terminate the main thread. */ - if (ptr != NULL) { + /* Terminate the UI thread. */ is_quit = 1; - thread_wait(ptr, -1); - - /* Wait some more. */ - plat_delay_ms(200); - } #if (defined(USE_DYNAREC) && defined(USE_NEW_DYNAREC)) codegen_close(); @@ -953,7 +947,7 @@ pc_close(thread_t *ptr) #ifdef ENABLE_808X_LOG if (dump_on_exit) - dumpregs(0); + dumpregs(0); #endif video_close(); diff --git a/src/include/86box/86box.h b/src/include/86box/86box.h index 20e5b151b..5879a632e 100644 --- a/src/include/86box/86box.h +++ b/src/include/86box/86box.h @@ -189,6 +189,8 @@ extern void resub_cycles(int old_cycles); extern double isa_timing; extern int io_delay, framecountx; +extern volatile int cpu_thread_run; + #ifdef __cplusplus } #endif diff --git a/src/include/86box/plat.h b/src/include/86box/plat.h index 4eb6d6a80..14f6db2db 100644 --- a/src/include/86box/plat.h +++ b/src/include/86box/plat.h @@ -64,8 +64,8 @@ extern "C" { /* Global variables residing in the platform module. */ extern int dopause, /* system is paused */ doresize, /* screen resize requested */ - is_quit, /* system exit requested */ mouse_capture; /* mouse is captured in app */ +extern volatile int is_quit; /* system exit requested */ #ifdef MTR_ENABLED extern int tracing_on; diff --git a/src/win/win.c b/src/win/win.c index 0854dac64..5a32b3772 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -69,6 +69,7 @@ HANDLE ghMutex; LCID lang_id; /* current language ID used */ DWORD dwSubLangID; int acp_utf8; /* Windows supports UTF-8 codepage */ +volatile int cpu_thread_run = 1; /* Local data. */ @@ -487,7 +488,7 @@ main_thread(void *param) title_update = 1; old_time = GetTickCount(); drawits = frames = 0; - while (!is_quit) { + while (!is_quit && cpu_thread_run) { /* See if it is time to run a frame of code. */ new_time = GetTickCount(); drawits += (new_time - old_time); @@ -511,7 +512,7 @@ main_thread(void *param) Sleep(1); /* If needed, handle a screen resize. */ - if (doresize && !video_fullscreen) { + if (doresize && !video_fullscreen && !is_quit) { if (vid_resize & 2) plat_resize(fixed_size_x, fixed_size_y); else @@ -519,6 +520,8 @@ main_thread(void *param) doresize = 0; } } + + is_quit = 1; } @@ -551,16 +554,17 @@ do_start(void) void do_stop(void) { - is_quit = 1; + /* Claim the video blitter. */ + startblit(); - plat_delay_ms(100); - - if (source_hwnd) - PostMessage((HWND) (uintptr_t) source_hwnd, WM_HAS_SHUTDOWN, (WPARAM) 0, (LPARAM) hwndMain); + vid_apis[vid_api].close(); pc_close(thMain); thMain = NULL; + + if (source_hwnd) + PostMessage((HWND) (uintptr_t) source_hwnd, WM_HAS_SHUTDOWN, (WPARAM) 0, (LPARAM) hwndMain); } diff --git a/src/win/win_ui.c b/src/win/win_ui.c index 85595fe62..92e790dd3 100644 --- a/src/win/win_ui.c +++ b/src/win/win_ui.c @@ -477,9 +477,10 @@ plat_power_off(void) /* Cleanly terminate all of the emulator's components so as to avoid things like threads getting stuck. */ - do_stop(); + // do_stop(); + cpu_thread_run = 0; - exit(-1); + // exit(-1); } #ifdef MTR_ENABLED @@ -1547,10 +1548,10 @@ ui_init(int nCmdShow) fatal("bRet is -1\n"); } - if (messages.message == WM_QUIT) { - is_quit = 1; - break; - } + /* On WM_QUIT, tell the CPU thread to stop running. That will then tell us + to stop running as well. */ + if (messages.message == WM_QUIT) + cpu_thread_run = 0; if (! TranslateAccelerator(hwnd, haccel, &messages)) { From 323a961f22e4fa3537ecf2b1b5966916ce99871b Mon Sep 17 00:00:00 2001 From: OBattler Date: Wed, 21 Jul 2021 16:54:07 +0200 Subject: [PATCH 09/10] Fixed some keyboard controller bugs, including making IRQ's on direct transmissions to the front of the controller queue no longer erroneously resulting in stuck IRQ's, fixes the Acer M3A. --- src/device/keyboard_at.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/device/keyboard_at.c b/src/device/keyboard_at.c index c3fb5b93e..581f55f30 100644 --- a/src/device/keyboard_at.c +++ b/src/device/keyboard_at.c @@ -681,16 +681,17 @@ add_to_kbc_queue_front(atkbd_t *dev, uint8_t val, uint8_t channel, uint8_t stat_ if (channel == 2) { if (dev->mem[0] & 0x02) picint(0x1000); + dev->last_irq = 0x1000; } else { if (dev->mem[0] & 0x01) picint(2); + dev->last_irq = 2; } dev->out = val; if (channel == 2) dev->status = (dev->status & ~STAT_IFULL) | (STAT_OFULL | STAT_MFULL) | stat_hi; else dev->status = (dev->status & ~(STAT_IFULL | STAT_MFULL)) | STAT_OFULL | stat_hi; - dev->last_irq = 0x0000; } @@ -1055,8 +1056,8 @@ write_output(atkbd_t *dev, uint8_t val) uint8_t kbc_ven = dev->flags & KBC_VEN_MASK; kbd_log("ATkbc: write output port: %02X (old: %02X)\n", val, dev->output_port); - if ((kbc_ven == KBC_VEN_AMI) || ((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF)) - val |= ((dev->mem[0] << 4) & 0x30); + if ((kbc_ven == KBC_VEN_AMI) || ((dev->flags & KBC_TYPE_MASK) < KBC_TYPE_PS2_NOREF)) + val |= ((dev->mem[0] << 4) & 0x10); if ((dev->output_port ^ val) & 0x20) { /*IRQ 12*/ if (val & 0x20) @@ -2070,10 +2071,8 @@ kbd_write(uint16_t port, uint8_t val, void *priv) case 0xd0: /* read output port */ kbd_log("ATkbc: read output port\n"); mask = 0xff; - if (dev->mem[0] & 0x10) + if (((dev->flags & KBC_TYPE_MASK) < KBC_TYPE_PS2_NOREF) && (dev->mem[0] & 0x10)) mask &= 0xbf; - if (((dev->flags & KBC_TYPE_MASK) >= KBC_TYPE_PS2_NOREF) && (dev->mem[0] & 0x20)) - mask &= 0xf7; add_to_kbc_queue_front(dev, dev->output_port & mask, 0, 0x00); break; From f31e8b27d5a2cd589044621ac0fe38f06519881b Mon Sep 17 00:00:00 2001 From: OBattler Date: Wed, 21 Jul 2021 16:55:03 +0200 Subject: [PATCH 10/10] Fixed a warning in win/win.c . --- src/win/win.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/win/win.c b/src/win/win.c index 5a32b3772..12655373e 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -545,7 +545,7 @@ do_start(void) win_log("Main timer precision: %llu\n", timer_freq); /* Start the emulator, really. */ - thMain = thread_create(main_thread, &is_quit); + thMain = thread_create(main_thread, NULL); SetThreadPriority(thMain, THREAD_PRIORITY_HIGHEST); }