From 03dd94f361259b102fad8cfce2592fa81b801ee8 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Thu, 27 Feb 2025 13:50:45 +0600 Subject: [PATCH 01/10] x87: Fix Final Reality discolored screen for all dynarecs --- src/codegen/codegen_ops_x86-64.h | 14 +++++++++ src/codegen/codegen_ops_x86.h | 7 +++++ src/codegen_new/codegen_ops_helpers.h | 3 ++ src/cpu/386_dynarec.c | 45 +++++++++++++++++++++++++++ src/cpu/cpu.h | 6 ++++ 5 files changed, 75 insertions(+) diff --git a/src/codegen/codegen_ops_x86-64.h b/src/codegen/codegen_ops_x86-64.h index e46f55a05..01fb292cf 100644 --- a/src/codegen/codegen_ops_x86-64.h +++ b/src/codegen/codegen_ops_x86-64.h @@ -3571,6 +3571,8 @@ FP_FLD(int reg) addbyte(0x89); /*MOV [TOP], EBX*/ addbyte(0x5d); addbyte((uint8_t) cpu_state_offset(TOP)); + + CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void @@ -3688,6 +3690,8 @@ FP_LOAD_S(void) addbyte(0x44); addbyte(0x1d); addbyte((uint8_t) cpu_state_offset(tag)); + + CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void FP_LOAD_D(void) @@ -3717,6 +3721,8 @@ FP_LOAD_D(void) addbyte(0x44); addbyte(0x1d); addbyte((uint8_t) cpu_state_offset(tag)); + + CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void @@ -3754,6 +3760,8 @@ FP_LOAD_IW(void) addbyte(0x44); addbyte(0x1d); addbyte((uint8_t) cpu_state_offset(tag)); + + CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void FP_LOAD_IL(void) @@ -3787,6 +3795,8 @@ FP_LOAD_IL(void) addbyte(0x44); addbyte(0x1d); addbyte((uint8_t) cpu_state_offset(tag)); + + CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void FP_LOAD_IQ(void) @@ -3831,6 +3841,8 @@ FP_LOAD_IQ(void) addbyte(0x44); addbyte(0x1d); addbyte((uint8_t) cpu_state_offset(tag)); + + CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void @@ -3863,6 +3875,8 @@ FP_LOAD_IMM_Q(uint64_t v) addbyte(0x1d); addbyte((uint8_t) cpu_state_offset(tag)); addbyte(v ? 0 : 1); + + CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void diff --git a/src/codegen/codegen_ops_x86.h b/src/codegen/codegen_ops_x86.h index c48324c2a..3b47d81a9 100644 --- a/src/codegen/codegen_ops_x86.h +++ b/src/codegen/codegen_ops_x86.h @@ -1794,6 +1794,7 @@ FP_FLD(int reg) addbyte(0x5d); addbyte((uint8_t) cpu_state_offset(TOP)); } + CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void @@ -2037,6 +2038,7 @@ FP_LOAD_S(void) addbyte(0x1d); addbyte((uint8_t) cpu_state_offset(tag[0])); } + CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void FP_LOAD_D(void) @@ -2096,6 +2098,7 @@ FP_LOAD_D(void) addbyte(0x1d); addbyte((uint8_t) cpu_state_offset(tag[0])); } + CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void FP_LOAD_IW(void) @@ -2154,6 +2157,7 @@ FP_LOAD_IW(void) addbyte(0x1d); addbyte((uint8_t) cpu_state_offset(tag[0])); } + CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void FP_LOAD_IL(void) @@ -2210,6 +2214,7 @@ FP_LOAD_IL(void) addbyte(0x1d); addbyte((uint8_t) cpu_state_offset(tag[0])); } + CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void FP_LOAD_IQ(void) @@ -2285,6 +2290,7 @@ FP_LOAD_IQ(void) addbyte(0x1d); addbyte((uint8_t) cpu_state_offset(tag[0])); } + CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void @@ -2336,6 +2342,7 @@ FP_LOAD_IMM_Q(uint64_t v) addbyte(0x5d); addbyte((uint8_t) cpu_state_offset(TOP)); } + CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline int diff --git a/src/codegen_new/codegen_ops_helpers.h b/src/codegen_new/codegen_ops_helpers.h index 92b721099..2304aa542 100644 --- a/src/codegen_new/codegen_ops_helpers.h +++ b/src/codegen_new/codegen_ops_helpers.h @@ -64,6 +64,9 @@ fpu_POP2(codeblock_t *block, ir_data_t *ir) static inline void fpu_PUSH(codeblock_t *block, ir_data_t *ir) { + uop_LOAD_FUNC_ARG_IMM(ir, 0, ((uint16_t)cpu_state.TOP - 1)); + uop_CALL_FUNC(ir, x87_to_mmxreg); + if (block->flags & CODEBLOCK_STATIC_TOP) uop_MOV_IMM(ir, IREG_FPU_TOP, cpu_state.TOP - 1); else diff --git a/src/cpu/386_dynarec.c b/src/cpu/386_dynarec.c index 5f41c416a..5cb385122 100644 --- a/src/cpu/386_dynarec.c +++ b/src/cpu/386_dynarec.c @@ -74,6 +74,51 @@ x386_dynarec_log(const char *fmt, ...) # define x386_dynarec_log(fmt, ...) #endif +/* Deliberately stashed here; this function is only relevant for dynamic recompilers. */ +#if defined(_MSC_VER) && !defined(__clang__) +# if defined i386 || defined __i386 || defined __i386__ || defined _X86_ || defined _M_IX86 +# define X87_INLINE_ASM +# endif +#else +# if defined i386 || defined __i386 || defined __i386__ || defined _X86_ || defined _M_IX86 || defined _M_X64 || defined __amd64__ +# define X87_INLINE_ASM +# endif +#endif + +#ifdef USE_NEW_DYNAREC +void +x87_to_mmxreg(uint16_t reg) +#else +void +x87_to_mmxreg(void) +#endif +{ +#ifndef USE_NEW_DYNAREC + uint32_t reg = cpu_state.TOP & 7; +#endif + double val = cpu_state.ST[reg & 7]; +#ifdef X87_INLINE_ASM + unsigned char buffer[10]; +#else + x87_conv_t test; +#endif + +#ifdef X87_INLINE_ASM + __asm volatile("" + : + : + : "memory"); + + __asm volatile("fldl %1\n" + "fstpt %0\n" : "=m"(buffer) : "m"(val)); + + cpu_state.MM[reg & 7].q = (*(uint64_t*)buffer); +#else + x87_to80(val, &test); + cpu_state.MM[reg & 7].q = test.eind.ll; +#endif +} + static __inline void fetch_ea_32_long(uint32_t rmdat) { diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index 1d003ddc9..98c6f4938 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -829,6 +829,12 @@ extern uint16_t prefetch_queue_get_ip(void); extern int prefetch_queue_get_prefetching(void); extern int prefetch_queue_get_size(void); +#ifdef USE_NEW_DYNAREC +extern void x87_to_mmxreg(uint16_t reg); +#else +extern void x87_to_mmxreg(void); +#endif + #define prefetch_queue_set_suspended(s) prefetch_queue_set_prefetching(!s) #define prefetch_queue_get_suspended !prefetch_queue_get_prefetching From c7153916eb21c67647e4df2512cda9b8776e5653 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Thu, 27 Feb 2025 14:33:44 +0600 Subject: [PATCH 02/10] Fix compile on ARM64 --- src/cpu/386_dynarec.c | 70 +++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/cpu/386_dynarec.c b/src/cpu/386_dynarec.c index 5cb385122..04681c9dc 100644 --- a/src/cpu/386_dynarec.c +++ b/src/cpu/386_dynarec.c @@ -74,7 +74,6 @@ x386_dynarec_log(const char *fmt, ...) # define x386_dynarec_log(fmt, ...) #endif -/* Deliberately stashed here; this function is only relevant for dynamic recompilers. */ #if defined(_MSC_VER) && !defined(__clang__) # if defined i386 || defined __i386 || defined __i386__ || defined _X86_ || defined _M_IX86 # define X87_INLINE_ASM @@ -85,40 +84,6 @@ x386_dynarec_log(const char *fmt, ...) # endif #endif -#ifdef USE_NEW_DYNAREC -void -x87_to_mmxreg(uint16_t reg) -#else -void -x87_to_mmxreg(void) -#endif -{ -#ifndef USE_NEW_DYNAREC - uint32_t reg = cpu_state.TOP & 7; -#endif - double val = cpu_state.ST[reg & 7]; -#ifdef X87_INLINE_ASM - unsigned char buffer[10]; -#else - x87_conv_t test; -#endif - -#ifdef X87_INLINE_ASM - __asm volatile("" - : - : - : "memory"); - - __asm volatile("fldl %1\n" - "fstpt %0\n" : "=m"(buffer) : "m"(val)); - - cpu_state.MM[reg & 7].q = (*(uint64_t*)buffer); -#else - x87_to80(val, &test); - cpu_state.MM[reg & 7].q = test.eind.ll; -#endif -} - static __inline void fetch_ea_32_long(uint32_t rmdat) { @@ -278,6 +243,41 @@ fetch_ea_16_long(uint32_t rmdat) # define CACHE_ON() (!(cr0 & (1 << 30)) && !(cpu_state.flags & T_FLAG)) #endif +/* Deliberately stashed here; this function is only relevant for dynamic recompilers. */ +#ifdef USE_NEW_DYNAREC +void +x87_to_mmxreg(uint16_t reg) +#else +void +x87_to_mmxreg(void) +#endif +{ +#ifndef USE_NEW_DYNAREC + uint32_t reg = cpu_state.TOP & 7; +#endif + double val = cpu_state.ST[reg & 7]; +#ifdef X87_INLINE_ASM + unsigned char buffer[10]; +#else + x87_conv_t test; +#endif + +#ifdef X87_INLINE_ASM + __asm volatile("" + : + : + : "memory"); + + __asm volatile("fldl %1\n" + "fstpt %0\n" : "=m"(buffer) : "m"(val)); + + cpu_state.MM[reg & 7].q = (*(uint64_t*)buffer); +#else + x87_to80(val, &test); + cpu_state.MM[reg & 7].q = test.eind.ll; +#endif +} + #ifdef USE_DYNAREC int32_t cycles_main = 0; static int32_t cycles_old = 0; From fc656cbe0519b1a108aef25a333bf61cd5131cf8 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Thu, 27 Feb 2025 16:31:27 +0600 Subject: [PATCH 03/10] Mouse cursor now properly appears after uncapture --- src/qt/qt_mainwindow.cpp | 4 +++- src/qt/qt_rendererstack.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 62ac94f30..89d17a07c 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -262,8 +262,10 @@ MainWindow::MainWindow(QWidget *parent) ui->stackedWidget->mouse_capture_func(this->windowHandle()); } else { this->releaseKeyboard(); - if (ui->stackedWidget->mouse_uncapture_func) + if (ui->stackedWidget->mouse_uncapture_func) { ui->stackedWidget->mouse_uncapture_func(); + } + ui->stackedWidget->unsetCursor(); } }); diff --git a/src/qt/qt_rendererstack.cpp b/src/qt/qt_rendererstack.cpp index a8bd47a79..8c31da2b2 100644 --- a/src/qt/qt_rendererstack.cpp +++ b/src/qt/qt_rendererstack.cpp @@ -155,7 +155,7 @@ RendererStack::mouseReleaseEvent(QMouseEvent *event) } if (mouse_capture && (event->button() == Qt::MiddleButton) && (mouse_get_buttons() < 3)) { plat_mouse_capture(0); - this->setCursor(Qt::ArrowCursor); + this->unsetCursor(); isMouseDown &= ~1; return; } From 95f30192e5cb7b20755c1235625c107a3391fe93 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Thu, 27 Feb 2025 22:09:55 +0600 Subject: [PATCH 04/10] USB multimedia keys now work on Windows --- src/qt/qt_main.cpp | 115 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 1 deletion(-) diff --git a/src/qt/qt_main.cpp b/src/qt/qt_main.cpp index 72b0eef53..7723261b4 100644 --- a/src/qt/qt_main.cpp +++ b/src/qt/qt_main.cpp @@ -211,8 +211,121 @@ emu_LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) (GetForegroundWindow() == ((HWND) secondaryRenderer->winId()))); } - if ((nCode < 0) || (nCode != HC_ACTION) || !is_over_window) + bool skip = ((nCode < 0) || (nCode != HC_ACTION) || !is_over_window); + + if (skip) return CallNextHookEx(NULL, nCode, wParam, lParam); + + /* USB keyboards send a scancode of 0x00 for multimedia keys. */ + if (lpKdhs->scanCode == 0x00) { + /* Handle USB keyboard multimedia keys where possible. + Only a handful of keys can be handled via Virtual Key + detection; rest can't be reliably detected. */ + DWORD vkCode = lpKdhs->vkCode; + bool up = !!(lpKdhs->flags & LLKHF_UP); + ret = CallNextHookEx(NULL, nCode, wParam, lParam);; + + switch (vkCode) + { + case VK_MEDIA_PLAY_PAUSE: + { + win_keyboard_handle(0x22, up, 1, 0); + break; + } + case VK_MEDIA_STOP: + { + win_keyboard_handle(0x24, up, 1, 0); + break; + } + case VK_VOLUME_UP: + { + win_keyboard_handle(0x30, up, 1, 0); + break; + } + case VK_VOLUME_DOWN: + { + win_keyboard_handle(0x2E, up, 1, 0); + break; + } + case VK_VOLUME_MUTE: + { + win_keyboard_handle(0x20, up, 1, 0); + break; + } + case VK_MEDIA_NEXT_TRACK: + { + win_keyboard_handle(0x19, up, 1, 0); + break; + } + case VK_MEDIA_PREV_TRACK: + { + win_keyboard_handle(0x10, up, 1, 0); + break; + } + case VK_LAUNCH_MEDIA_SELECT: + { + win_keyboard_handle(0x6D, up, 1, 0); + break; + } + case VK_LAUNCH_MAIL: + { + win_keyboard_handle(0x6C, up, 1, 0); + break; + } + case VK_LAUNCH_APP1: + { + win_keyboard_handle(0x6B, up, 1, 0); + break; + } + case VK_LAUNCH_APP2: + { + win_keyboard_handle(0x21, up, 1, 0); + break; + } + case VK_BROWSER_BACK: + { + win_keyboard_handle(0x6A, up, 1, 0); + break; + } + case VK_BROWSER_FORWARD: + { + win_keyboard_handle(0x69, up, 1, 0); + break; + } + case VK_BROWSER_STOP: + { + win_keyboard_handle(0x68, up, 1, 0); + break; + } + case VK_BROWSER_HOME: + { + win_keyboard_handle(0x32, up, 1, 0); + break; + } + case VK_BROWSER_SEARCH: + { + win_keyboard_handle(0x65, up, 1, 0); + break; + } + case VK_BROWSER_REFRESH: + { + win_keyboard_handle(0x67, up, 1, 0); + break; + } + case VK_BROWSER_FAVORITES: + { + win_keyboard_handle(0x66, up, 1, 0); + break; + } + case VK_HELP: + { + win_keyboard_handle(0x3b, up, 1, 0); + break; + } + } + + return ret; + } else if ((lpKdhs->scanCode == 0x01) && (lpKdhs->flags & LLKHF_ALTDOWN) && !(lpKdhs->flags & (LLKHF_UP | LLKHF_EXTENDED))) ret = TRUE; From 86342bfffe057d4ff01b18b05cd89816228c636c Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Thu, 27 Feb 2025 23:26:42 +0600 Subject: [PATCH 05/10] OS/2 3.0 icon backgrounds are now drawn properly --- src/video/vid_mga.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/video/vid_mga.c b/src/video/vid_mga.c index 3937c2a7d..f11983a20 100644 --- a/src/video/vid_mga.c +++ b/src/video/vid_mga.c @@ -4677,6 +4677,7 @@ blit_trap(mystique_t *mystique) int err_l = (int32_t)mystique->dwgreg.ar[1]; int err_r = (int32_t)mystique->dwgreg.ar[4]; const int trans_sel = (mystique->dwgreg.dwgctrl_running & DWGCTRL_TRANS_MASK) >> DWGCTRL_TRANS_SHIFT; + bool transc = !!(mystique->dwgreg.dwgctrl_running & DWGCTRL_TRANSC); switch (mystique->dwgreg.dwgctrl_running & DWGCTRL_ATYPE_MASK) { case DWGCTRL_ATYPE_BLK: @@ -4699,6 +4700,7 @@ blit_trap(mystique_t *mystique) int pattern = mystique->dwgreg.pattern[yoff][xoff]; uint32_t dst; + if (!transc || (transc && pattern)) switch (mystique->maccess_running & MACCESS_PWIDTH_MASK) { case MACCESS_PWIDTH_8: svga->vram[(mystique->dwgreg.ydst_lin + x_l) & mystique->vram_mask] = (pattern ? mystique->dwgreg.fcol : mystique->dwgreg.bcol) & 0xff; @@ -4770,6 +4772,7 @@ blit_trap(mystique_t *mystique) uint32_t dst; uint32_t old_dst; + if (!transc || (transc && pattern)) switch (mystique->maccess_running & MACCESS_PWIDTH_MASK) { case MACCESS_PWIDTH_8: dst = svga->vram[(mystique->dwgreg.ydst_lin + x_l) & mystique->vram_mask]; From 0bb89be0ad0e718841ca99ef2405cb42f9666f6f Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Fri, 28 Feb 2025 16:51:13 +0600 Subject: [PATCH 06/10] Revert "Fix compile on ARM64" This reverts commit c7153916eb21c67647e4df2512cda9b8776e5653. --- src/cpu/386_dynarec.c | 70 +++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/cpu/386_dynarec.c b/src/cpu/386_dynarec.c index 04681c9dc..5cb385122 100644 --- a/src/cpu/386_dynarec.c +++ b/src/cpu/386_dynarec.c @@ -74,6 +74,7 @@ x386_dynarec_log(const char *fmt, ...) # define x386_dynarec_log(fmt, ...) #endif +/* Deliberately stashed here; this function is only relevant for dynamic recompilers. */ #if defined(_MSC_VER) && !defined(__clang__) # if defined i386 || defined __i386 || defined __i386__ || defined _X86_ || defined _M_IX86 # define X87_INLINE_ASM @@ -84,6 +85,40 @@ x386_dynarec_log(const char *fmt, ...) # endif #endif +#ifdef USE_NEW_DYNAREC +void +x87_to_mmxreg(uint16_t reg) +#else +void +x87_to_mmxreg(void) +#endif +{ +#ifndef USE_NEW_DYNAREC + uint32_t reg = cpu_state.TOP & 7; +#endif + double val = cpu_state.ST[reg & 7]; +#ifdef X87_INLINE_ASM + unsigned char buffer[10]; +#else + x87_conv_t test; +#endif + +#ifdef X87_INLINE_ASM + __asm volatile("" + : + : + : "memory"); + + __asm volatile("fldl %1\n" + "fstpt %0\n" : "=m"(buffer) : "m"(val)); + + cpu_state.MM[reg & 7].q = (*(uint64_t*)buffer); +#else + x87_to80(val, &test); + cpu_state.MM[reg & 7].q = test.eind.ll; +#endif +} + static __inline void fetch_ea_32_long(uint32_t rmdat) { @@ -243,41 +278,6 @@ fetch_ea_16_long(uint32_t rmdat) # define CACHE_ON() (!(cr0 & (1 << 30)) && !(cpu_state.flags & T_FLAG)) #endif -/* Deliberately stashed here; this function is only relevant for dynamic recompilers. */ -#ifdef USE_NEW_DYNAREC -void -x87_to_mmxreg(uint16_t reg) -#else -void -x87_to_mmxreg(void) -#endif -{ -#ifndef USE_NEW_DYNAREC - uint32_t reg = cpu_state.TOP & 7; -#endif - double val = cpu_state.ST[reg & 7]; -#ifdef X87_INLINE_ASM - unsigned char buffer[10]; -#else - x87_conv_t test; -#endif - -#ifdef X87_INLINE_ASM - __asm volatile("" - : - : - : "memory"); - - __asm volatile("fldl %1\n" - "fstpt %0\n" : "=m"(buffer) : "m"(val)); - - cpu_state.MM[reg & 7].q = (*(uint64_t*)buffer); -#else - x87_to80(val, &test); - cpu_state.MM[reg & 7].q = test.eind.ll; -#endif -} - #ifdef USE_DYNAREC int32_t cycles_main = 0; static int32_t cycles_old = 0; From 6bb2b447fda8011e992472fa0959d3ee4cd8deed Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Fri, 28 Feb 2025 16:51:33 +0600 Subject: [PATCH 07/10] Revert "x87: Fix Final Reality discolored screen for all dynarecs" This reverts commit 03dd94f361259b102fad8cfce2592fa81b801ee8. --- src/codegen/codegen_ops_x86-64.h | 14 --------- src/codegen/codegen_ops_x86.h | 7 ----- src/codegen_new/codegen_ops_helpers.h | 3 -- src/cpu/386_dynarec.c | 45 --------------------------- src/cpu/cpu.h | 6 ---- 5 files changed, 75 deletions(-) diff --git a/src/codegen/codegen_ops_x86-64.h b/src/codegen/codegen_ops_x86-64.h index 01fb292cf..e46f55a05 100644 --- a/src/codegen/codegen_ops_x86-64.h +++ b/src/codegen/codegen_ops_x86-64.h @@ -3571,8 +3571,6 @@ FP_FLD(int reg) addbyte(0x89); /*MOV [TOP], EBX*/ addbyte(0x5d); addbyte((uint8_t) cpu_state_offset(TOP)); - - CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void @@ -3690,8 +3688,6 @@ FP_LOAD_S(void) addbyte(0x44); addbyte(0x1d); addbyte((uint8_t) cpu_state_offset(tag)); - - CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void FP_LOAD_D(void) @@ -3721,8 +3717,6 @@ FP_LOAD_D(void) addbyte(0x44); addbyte(0x1d); addbyte((uint8_t) cpu_state_offset(tag)); - - CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void @@ -3760,8 +3754,6 @@ FP_LOAD_IW(void) addbyte(0x44); addbyte(0x1d); addbyte((uint8_t) cpu_state_offset(tag)); - - CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void FP_LOAD_IL(void) @@ -3795,8 +3787,6 @@ FP_LOAD_IL(void) addbyte(0x44); addbyte(0x1d); addbyte((uint8_t) cpu_state_offset(tag)); - - CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void FP_LOAD_IQ(void) @@ -3841,8 +3831,6 @@ FP_LOAD_IQ(void) addbyte(0x44); addbyte(0x1d); addbyte((uint8_t) cpu_state_offset(tag)); - - CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void @@ -3875,8 +3863,6 @@ FP_LOAD_IMM_Q(uint64_t v) addbyte(0x1d); addbyte((uint8_t) cpu_state_offset(tag)); addbyte(v ? 0 : 1); - - CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void diff --git a/src/codegen/codegen_ops_x86.h b/src/codegen/codegen_ops_x86.h index 3b47d81a9..c48324c2a 100644 --- a/src/codegen/codegen_ops_x86.h +++ b/src/codegen/codegen_ops_x86.h @@ -1794,7 +1794,6 @@ FP_FLD(int reg) addbyte(0x5d); addbyte((uint8_t) cpu_state_offset(TOP)); } - CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void @@ -2038,7 +2037,6 @@ FP_LOAD_S(void) addbyte(0x1d); addbyte((uint8_t) cpu_state_offset(tag[0])); } - CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void FP_LOAD_D(void) @@ -2098,7 +2096,6 @@ FP_LOAD_D(void) addbyte(0x1d); addbyte((uint8_t) cpu_state_offset(tag[0])); } - CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void FP_LOAD_IW(void) @@ -2157,7 +2154,6 @@ FP_LOAD_IW(void) addbyte(0x1d); addbyte((uint8_t) cpu_state_offset(tag[0])); } - CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void FP_LOAD_IL(void) @@ -2214,7 +2210,6 @@ FP_LOAD_IL(void) addbyte(0x1d); addbyte((uint8_t) cpu_state_offset(tag[0])); } - CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void FP_LOAD_IQ(void) @@ -2290,7 +2285,6 @@ FP_LOAD_IQ(void) addbyte(0x1d); addbyte((uint8_t) cpu_state_offset(tag[0])); } - CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline void @@ -2342,7 +2336,6 @@ FP_LOAD_IMM_Q(uint64_t v) addbyte(0x5d); addbyte((uint8_t) cpu_state_offset(TOP)); } - CALL_FUNC((uintptr_t) x87_to_mmxreg); } static __inline int diff --git a/src/codegen_new/codegen_ops_helpers.h b/src/codegen_new/codegen_ops_helpers.h index 2304aa542..92b721099 100644 --- a/src/codegen_new/codegen_ops_helpers.h +++ b/src/codegen_new/codegen_ops_helpers.h @@ -64,9 +64,6 @@ fpu_POP2(codeblock_t *block, ir_data_t *ir) static inline void fpu_PUSH(codeblock_t *block, ir_data_t *ir) { - uop_LOAD_FUNC_ARG_IMM(ir, 0, ((uint16_t)cpu_state.TOP - 1)); - uop_CALL_FUNC(ir, x87_to_mmxreg); - if (block->flags & CODEBLOCK_STATIC_TOP) uop_MOV_IMM(ir, IREG_FPU_TOP, cpu_state.TOP - 1); else diff --git a/src/cpu/386_dynarec.c b/src/cpu/386_dynarec.c index 5cb385122..5f41c416a 100644 --- a/src/cpu/386_dynarec.c +++ b/src/cpu/386_dynarec.c @@ -74,51 +74,6 @@ x386_dynarec_log(const char *fmt, ...) # define x386_dynarec_log(fmt, ...) #endif -/* Deliberately stashed here; this function is only relevant for dynamic recompilers. */ -#if defined(_MSC_VER) && !defined(__clang__) -# if defined i386 || defined __i386 || defined __i386__ || defined _X86_ || defined _M_IX86 -# define X87_INLINE_ASM -# endif -#else -# if defined i386 || defined __i386 || defined __i386__ || defined _X86_ || defined _M_IX86 || defined _M_X64 || defined __amd64__ -# define X87_INLINE_ASM -# endif -#endif - -#ifdef USE_NEW_DYNAREC -void -x87_to_mmxreg(uint16_t reg) -#else -void -x87_to_mmxreg(void) -#endif -{ -#ifndef USE_NEW_DYNAREC - uint32_t reg = cpu_state.TOP & 7; -#endif - double val = cpu_state.ST[reg & 7]; -#ifdef X87_INLINE_ASM - unsigned char buffer[10]; -#else - x87_conv_t test; -#endif - -#ifdef X87_INLINE_ASM - __asm volatile("" - : - : - : "memory"); - - __asm volatile("fldl %1\n" - "fstpt %0\n" : "=m"(buffer) : "m"(val)); - - cpu_state.MM[reg & 7].q = (*(uint64_t*)buffer); -#else - x87_to80(val, &test); - cpu_state.MM[reg & 7].q = test.eind.ll; -#endif -} - static __inline void fetch_ea_32_long(uint32_t rmdat) { diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index 98c6f4938..1d003ddc9 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -829,12 +829,6 @@ extern uint16_t prefetch_queue_get_ip(void); extern int prefetch_queue_get_prefetching(void); extern int prefetch_queue_get_size(void); -#ifdef USE_NEW_DYNAREC -extern void x87_to_mmxreg(uint16_t reg); -#else -extern void x87_to_mmxreg(void); -#endif - #define prefetch_queue_set_suspended(s) prefetch_queue_set_prefetching(!s) #define prefetch_queue_get_suspended !prefetch_queue_get_prefetching From 23b89d88c4e4fee4914d4c20b92a741e25e7c0ca Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Fri, 28 Feb 2025 16:51:48 +0600 Subject: [PATCH 08/10] Revert "x87: Fix Final Reality discolored screen for interpreter" This reverts commit 6d3816df64aac6cb0e604bab30239c3b4b888265. --- src/cpu/x87_ops.h | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/src/cpu/x87_ops.h b/src/cpu/x87_ops.h index 276c32876..f1362bf76 100644 --- a/src/cpu/x87_ops.h +++ b/src/cpu/x87_ops.h @@ -113,33 +113,12 @@ typedef union { static __inline void x87_push(double i) { -#ifdef X87_INLINE_ASM - unsigned char buffer[10]; -#else - x87_conv_t test; -#endif #ifdef USE_NEW_DYNAREC cpu_state.TOP--; #else cpu_state.TOP = (cpu_state.TOP - 1) & 7; #endif cpu_state.ST[cpu_state.TOP & 7] = i; - -#ifdef X87_INLINE_ASM - __asm volatile("" - : - : - : "memory"); - - __asm volatile("fldl %1\n" - "fstpt %0\n" : "=m"(buffer) : "m"(i)); - - cpu_state.MM[cpu_state.TOP & 7].q = (*(uint64_t*)buffer); -#else - x87_to80(i, &test); - cpu_state.MM[cpu_state.TOP & 7].q = test.eind.ll; -#endif - #ifdef USE_NEW_DYNAREC cpu_state.tag[cpu_state.TOP & 7] = TAG_VALID; #else @@ -150,11 +129,6 @@ x87_push(double i) static __inline void x87_push_u64(uint64_t i) { -#ifdef X87_INLINE_ASM - unsigned char buffer[10]; -#else - x87_conv_t test; -#endif union { double d; uint64_t ll; @@ -168,21 +142,6 @@ x87_push_u64(uint64_t i) cpu_state.TOP = (cpu_state.TOP - 1) & 7; #endif cpu_state.ST[cpu_state.TOP & 7] = td.d; - -#ifdef X87_INLINE_ASM - __asm volatile("" - : - : - : "memory"); - - __asm volatile("fldl %1\n" - "fstpt %0\n" : "=m"(buffer) : "m"(td.d)); - - cpu_state.MM[cpu_state.TOP & 7].q = (*(uint64_t*)buffer); -#else - x87_to80(td.d, &test); - cpu_state.MM[cpu_state.TOP & 7].q = test.eind.ll; -#endif #ifdef USE_NEW_DYNAREC cpu_state.tag[cpu_state.TOP & 7] = TAG_VALID; #else From 843dee57076a28d4028b9105c87ead95e64d7933 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Sat, 1 Mar 2025 15:05:39 +0600 Subject: [PATCH 09/10] x64 NDR: Properly address the entire cpu_state struct All missing edge cases are now handled where possible --- src/codegen_new/codegen_backend_x86-64_ops.c | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/codegen_new/codegen_backend_x86-64_ops.c b/src/codegen_new/codegen_backend_x86-64_ops.c index 236a86ce7..2f65b46e3 100644 --- a/src/codegen_new/codegen_backend_x86-64_ops.c +++ b/src/codegen_new/codegen_backend_x86-64_ops.c @@ -509,6 +509,11 @@ host_x86_MOV8_ABS_IMM(codeblock_t *block, void *p, uint32_t imm_data) codegen_alloc_bytes(block, 4); codegen_addbyte3(block, 0xc6, 0x45, offset); /*MOVB offset[RBP], imm_data*/ codegen_addbyte(block, imm_data); + } else if (offset < (1ULL << 32)) { + codegen_alloc_bytes(block, 7); + codegen_addbyte2(block, 0xc6, 0x85); /*MOVB offset[RBP], imm_data*/ + codegen_addlong(block, offset); + codegen_addbyte(block, imm_data); } else { if ((uintptr_t) p >> 32) fatal("host_x86_MOV8_ABS_IMM - out of range %p\n", p); @@ -527,6 +532,11 @@ host_x86_MOV16_ABS_IMM(codeblock_t *block, void *p, uint16_t imm_data) codegen_alloc_bytes(block, 6); codegen_addbyte4(block, 0x66, 0xc7, 0x45, offset); /*MOV offset[RBP], imm_data*/ codegen_addword(block, imm_data); + } else if (offset < (1ULL << 32)) { + codegen_alloc_bytes(block, 8); + codegen_addbyte3(block, 0x66, 0xc7, 0x85); /*MOV offset[RBP], imm_data*/ + codegen_addlong(block, offset); + codegen_addword(block, imm_data); } else { if ((uintptr_t) p >> 32) fatal("host_x86_MOV32_ABS_IMM - out of range %p\n", p); @@ -545,6 +555,11 @@ host_x86_MOV32_ABS_IMM(codeblock_t *block, void *p, uint32_t imm_data) codegen_alloc_bytes(block, 7); codegen_addbyte3(block, 0xc7, 0x45, offset); /*MOV offset[RBP], imm_data*/ codegen_addlong(block, imm_data); + } else if (offset < (1ULL << 32)) { + codegen_alloc_bytes(block, 10); + codegen_addbyte2(block, 0xc7, 0x85); /*MOV offset[RBP], imm_data*/ + codegen_addlong(block, offset); + codegen_addlong(block, imm_data); } else { if ((uintptr_t) p >> 32) fatal("host_x86_MOV32_ABS_IMM - out of range %p\n", p); @@ -566,6 +581,10 @@ host_x86_MOV8_ABS_REG(codeblock_t *block, void *p, int src_reg) if (offset >= -128 && offset < 127) { codegen_alloc_bytes(block, 3); codegen_addbyte3(block, 0x88, 0x45 | ((src_reg & 7) << 3), offset); /*MOVB offset[RBP], src_reg*/ + } else if (offset < (1ULL << 32)) { + codegen_alloc_bytes(block, 6); + codegen_addbyte2(block, 0x88, 0x85 | ((src_reg & 7) << 3)); /*MOVB offset[RBP], src_reg*/ + codegen_addlong(block, offset); } else { if ((uintptr_t) p >> 32) fatal("host_x86_MOV8_ABS_REG - out of range %p\n", p); @@ -630,6 +649,10 @@ host_x86_MOV64_ABS_REG(codeblock_t *block, void *p, int src_reg) if (offset >= -128 && offset < 127) { codegen_alloc_bytes(block, 4); codegen_addbyte4(block, 0x48, 0x89, 0x45 | ((src_reg & 7) << 3), offset); /*MOV offset[RBP], src_reg*/ + } else if (offset < (1ULL << 32)) { + codegen_alloc_bytes(block, 7); + codegen_addbyte3(block, 0x48, 0x89, 0x85 | ((src_reg & 7) << 3)); /*MOV offset[RBP], src_reg*/ + codegen_addlong(block, offset); } else { if ((uintptr_t) p >> 32) fatal("host_x86_MOV64_ABS_REG - out of range %p\n", p); From d15def050aba3e2652355c718918fb78e9c79b53 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 1 Mar 2025 10:11:45 +0100 Subject: [PATCH 10/10] Fix an unclosed comment in device/keyboard_at.c. --- src/device/keyboard_at.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/device/keyboard_at.c b/src/device/keyboard_at.c index d04ab07e9..e61b8547a 100644 --- a/src/device/keyboard_at.c +++ b/src/device/keyboard_at.c @@ -2526,7 +2526,7 @@ static const scancode scancode_set82[512] = { { .mk = {0xe0, 0x17, 0 }, .brk = { 0xe0, 0xF0, 0x17, 0 } }, /* 15a */ { .mk = { 0x67, 0 }, .brk = { 0xf0, 0x67, 0 } }, /* 15b 0x33 LGUI->Muhenkan (in emulator only) */ { .mk = { 0x64, 0 }, .brk = { 0xf0, 0x64, 0 } }, /* 15c 0x35 RGUI->Henkan (in emulator only) */ - { .mk = {0xe0, 0x11, 0 }, .brk = { 0xe0, 0xf0, 0x11, 0 } }, /* 15d 0x36 APPLICATION->Kana (in emulator + { .mk = {0xe0, 0x11, 0 }, .brk = { 0xe0, 0xf0, 0x11, 0 } }, /* 15d 0x36 APPLICATION->Kana (in emulator only) */ { .mk = {0xe0, 0x37, 0 }, .brk = { 0xe0, 0xF0, 0x37, 0 } }, /* 15e */ { .mk = {0xe0, 0x3F, 0 }, .brk = { 0xe0, 0xF0, 0x3F, 0 } }, /* 15f */ { .mk = { 0 }, .brk = { 0 } }, /* 160 */