From 3cdd39170dc294757b564ddbdba210177b6a86e2 Mon Sep 17 00:00:00 2001 From: flyinghead Date: Thu, 7 Feb 2019 19:20:10 +0100 Subject: [PATCH] win32: call os_DoEvents on the emu/main thread and other fixes --- core/hw/mem/_vmem.cpp | 10 +++++++++- core/hw/sh4/dyna/ngen.h | 4 ++-- core/nullDC.cpp | 16 +++++++++------- core/rec-x86/rec_x86_driver.cpp | 4 ++-- core/rend/gui.cpp | 1 - core/stdclass.h | 1 - shell/linux/Makefile | 6 +++--- 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/core/hw/mem/_vmem.cpp b/core/hw/mem/_vmem.cpp index 10e75810e..2c02197c5 100644 --- a/core/hw/mem/_vmem.cpp +++ b/core/hw/mem/_vmem.cpp @@ -396,7 +396,9 @@ void _vmem_term() u8* virt_ram_base; void* malloc_pages(size_t size) { -#ifdef _ISOC11_SOURCE +#if HOST_OS == OS_WINDOWS + return _aligned_malloc(size, PAGE_SIZE); +#elif defined(_ISOC11_SOURCE) return aligned_alloc(PAGE_SIZE, size); #else void *data; @@ -794,10 +796,16 @@ void _vmem_release() { if (virt_ram_base != NULL) { +#if HOST_OS == OS_WINDOWS + VirtualFree(virt_ram_base, 0, MEM_RELEASE); +#else munmap(virt_ram_base, 0x20000000); +#endif virt_ram_base = NULL; } +#if HOST_OS != OS_WINDOWS close(fd); +#endif } } diff --git a/core/hw/sh4/dyna/ngen.h b/core/hw/sh4/dyna/ngen.h index c5814c4dc..0e7d9cd3b 100644 --- a/core/hw/sh4/dyna/ngen.h +++ b/core/hw/sh4/dyna/ngen.h @@ -53,7 +53,7 @@ extern u32* emit_ptr; extern u8* CodeCache; -#if HOST_OS==OS_LINUX || HOST_OS==OS_DARWIN +#ifdef __cplusplus extern "C" { #endif @@ -116,6 +116,6 @@ void ngen_CC_Finish(shil_opcode* op); RuntimeBlockInfo* ngen_AllocateBlock(); -#if HOST_OS==OS_LINUX || HOST_OS==OS_DARWIN +#ifdef __cplusplus } #endif diff --git a/core/nullDC.cpp b/core/nullDC.cpp index aaaebcccb..e8f71a0db 100755 --- a/core/nullDC.cpp +++ b/core/nullDC.cpp @@ -27,8 +27,8 @@ void dc_resume_emu(bool continue_running); settings_t settings; static bool continue_running = false; -static cMutex mtx_serialization ; static cMutex mtx_mainloop ; +static cResetEvent resume_mainloop(false, true); /* libndc @@ -426,6 +426,8 @@ bool dc_is_running() #ifndef TARGET_DISPFRAME void dc_run() { + resume_mainloop.Set(); + while ( true ) { bool dynarec_enabled = settings.dynarec.Enable; @@ -434,8 +436,8 @@ void dc_run() sh4_cpu.Run(); mtx_mainloop.Unlock() ; - mtx_serialization.Lock() ; - mtx_serialization.Unlock() ; + while (!resume_mainloop.Wait(20)) + os_DoEvents(); if (dynarec_enabled != settings.dynarec.Enable) { @@ -697,10 +699,10 @@ bool dc_pause_emu() if (sh4_cpu.IsCpuRunning()) { #ifndef TARGET_NO_THREADS - mtx_serialization.Lock(); + resume_mainloop.Reset(); if (!wait_until_dc_running()) { printf("Can't open settings - dc loop kept running\n"); - mtx_serialization.Unlock(); + resume_mainloop.Set(); return false; } @@ -710,7 +712,7 @@ bool dc_pause_emu() { printf("Can't open settings - could not acquire main loop lock\n"); continue_running = true; - mtx_serialization.Unlock(); + resume_mainloop.Set(); return false; } #else @@ -726,7 +728,7 @@ void dc_resume_emu(bool continue_running) { ::continue_running = continue_running; rend_cancel_emu_wait(); - mtx_serialization.Unlock(); + resume_mainloop.Set(); mtx_mainloop.Unlock(); } } diff --git a/core/rec-x86/rec_x86_driver.cpp b/core/rec-x86/rec_x86_driver.cpp index acb138266..9b9911f73 100644 --- a/core/rec-x86/rec_x86_driver.cpp +++ b/core/rec-x86/rec_x86_driver.cpp @@ -37,7 +37,7 @@ void DetectCpuFeatures() if (detected) return; detected=true; -#if HOST_OS==OS_WINDOWS +#ifdef _MSC_VER __try { __asm addps xmm0,xmm0 @@ -84,7 +84,7 @@ void DetectCpuFeatures() { mmx=false; } - #endif +#endif } diff --git a/core/rend/gui.cpp b/core/rend/gui.cpp index 1719474c0..bd1ebe7cf 100644 --- a/core/rend/gui.cpp +++ b/core/rend/gui.cpp @@ -130,7 +130,6 @@ static void ImGui_Impl_NewFrame() ImGuiIO& io = ImGui::GetIO(); - os_DoEvents(); UpdateInputState(0); // Read keyboard modifiers inputs diff --git a/core/stdclass.h b/core/stdclass.h index bcfb75200..628baa155 100644 --- a/core/stdclass.h +++ b/core/stdclass.h @@ -305,7 +305,6 @@ public: } }; -int ExeptionHandler(u32 dwCode, void* pExceptionPointers); int msgboxf(const wchar* text,unsigned int type,...); diff --git a/shell/linux/Makefile b/shell/linux/Makefile index 6307c8502..ed955aa4c 100644 --- a/shell/linux/Makefile +++ b/shell/linux/Makefile @@ -235,19 +235,19 @@ else ifneq (,$(findstring vero4k,$(platform))) # Windows else ifneq (,$(findstring win32,$(platform))) - X64_REC := 1 NOT_ARM := 1 - CFLAGS += -DTARGET_NO_WEBUI -fno-builtin-sqrtf -funroll-loops -DHAVE_FSEEKO + CFLAGS += -DTARGET_NO_WEBUI -fno-builtin-sqrtf -funroll-loops -DHAVE_FSEEKO -D TARGET_NO_AREC LDFLAGS += -static-libgcc -static-libstdc++ LIBS := -lopengl32 -lwinmm -lgdi32 -lwsock32 -ldsound -lcomctl32 -lcomdlg32 -lxinput -liphlpapi PLATFORM_EXT := exe CC = gcc CXX = g++ ifeq ($(WITH_DYNAREC), x86) + X86_REC := 1 LDFLAGS += -m32 CFLAGS += -m32 else - CFLAGS += -D TARGET_NO_AREC + X64_REC := 1 endif undefine USE_X11 undefine USE_ALSA