From 6fdf9c73d63844e5a6c8063fa2c5a2ea9a8cea24 Mon Sep 17 00:00:00 2001 From: Bernhard Schelling <14200249+schellingb@users.noreply.github.com> Date: Mon, 1 Feb 2021 05:24:23 +0900 Subject: [PATCH 01/58] Add build-static stage --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5ff62a691..dbc8ed9aa 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -59,6 +59,7 @@ include: stages: - build-prepare - build-shared + - build-static ############################################################################## #################################### STAGES ################################## From f50c621cc4556838ce84fb42d31feb81d457a185 Mon Sep 17 00:00:00 2001 From: Bernhard Schelling <14200249+schellingb@users.noreply.github.com> Date: Mon, 1 Feb 2021 05:36:44 +0900 Subject: [PATCH 02/58] Fix compiler setting for specific platforms --- Makefile | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index b910abc40..336251baa 100644 --- a/Makefile +++ b/Makefile @@ -41,10 +41,10 @@ else ifneq ($(ISMAC),) OUTNAME := dosbox_pure_libretro.dylib CXX ?= clang++ LDFLAGS := -Wl,-dead_strip -else ifeq ($(platform), vita) +else ifeq ($(platform),vita) OUTNAME := dosbox_pure_libretro_vita.a - CXX ?= arm-vita-eabi-g++ - AR ?= arm-vita-eabi-ar + CXX := arm-vita-eabi-g++ + AR := arm-vita-eabi-ar COMMONFLAGS += -DVITA COMMONFLAGS += -mthumb -mcpu=cortex-a9 -mfloat-abi=hard -ftree-vectorize -ffast-math -fsingle-precision-constant -funroll-loops COMMONFLAGS += -mword-relocations @@ -52,8 +52,8 @@ else ifeq ($(platform), vita) STATIC_LINKING = 1 else ifeq ($(platform),ctr) OUTNAME := dosbox_pure_libretro_ctr.a - CXX ?= $(DEVKITARM)/bin/arm-none-eabi-g++ - AR ?= $(DEVKITARM)/bin/arm-none-eabi-ar + CXX := $(DEVKITARM)/bin/arm-none-eabi-g++ + AR := $(DEVKITARM)/bin/arm-none-eabi-ar COMMONFLAGS += -DARM11 -D_3DS -Os -s -I$(CTRULIB)/include/ -DHAVE_MKDIR COMMONFLAGS += -march=armv6k -mtune=mpcore -mfloat-abi=hard -mword-relocations COMMONFLAGS += -fomit-frame-pointer -fstrict-aliasing -ffast-math -fpermissive @@ -61,21 +61,21 @@ else ifeq ($(platform),ctr) STATIC_LINKING = 1 else ifeq ($(platform),ngc) OUTNAME := dosbox_pure_libretro_ngc.a - CXX ?= $(DEVKITPPC)/bin/powerpc-eabi-g++ - AR ?= $(DEVKITPPC)/bin/powerpc-eabi-ar + CXX := $(DEVKITPPC)/bin/powerpc-eabi-g++ + AR := $(DEVKITPPC)/bin/powerpc-eabi-ar COMMONFLAGS += -DGEKKO -DHW_DOL -mrvl -mcpu=750 -meabi -mhard-float -D__POWERPC__ -D__ppc__ -DMSB_FIRST -DWORDS_BIGENDIAN=1 STATIC_LINKING = 1 else ifeq ($(platform),wii) OUTNAME := dosbox_pure_libretro_wii.a - CXX ?= $(DEVKITPPC)/bin/powerpc-eabi-g++ - AR ?= $(DEVKITPPC)/bin/powerpc-eabi-ar + CXX := $(DEVKITPPC)/bin/powerpc-eabi-g++ + AR := $(DEVKITPPC)/bin/powerpc-eabi-ar COMMONFLAGS += -DGEKKO -mrvl -mcpu=750 -meabi -mhard-float -fpermissive COMMONFLAGS += -U__INT32_TYPE__ -U __UINT32_TYPE__ -D__INT32_TYPE__=int -D__POWERPC__ -D__ppc__ -DMSB_FIRST -DWORDS_BIGENDIAN=1 STATIC_LINKING = 1 else ifeq ($(platform),wiiu) OUTNAME := dosbox_pure_libretro_wiiu.a - CXX ?= $(DEVKITPPC)/bin/powerpc-eabi-g++ - AR ?= $(DEVKITPPC)/bin/powerpc-eabi-ar + CXX := $(DEVKITPPC)/bin/powerpc-eabi-g++ + AR := $(DEVKITPPC)/bin/powerpc-eabi-ar COMMONFLAGS += -DGEKKO -DWIIU -DHW_RVL -mcpu=750 -meabi -mhard-float -I./deps/include/ COMMONFLAGS += -U__INT32_TYPE__ -U __UINT32_TYPE__ -D__INT32_TYPE__=int -D__POWERPC__ -D__ppc__ -DMSB_FIRST -DWORDS_BIGENDIAN=1 STATIC_LINKING = 1 @@ -89,7 +89,7 @@ else ifeq ($(platform),libnx) else ifeq ($(platform), gcw0) # You must used the toolchain built on or around 2014-08-20 OUTNAME := dosbox_pure_libretro.so - CXX ?= /opt/gcw0-toolchain/usr/bin/mipsel-linux-g++ + CXX := /opt/gcw0-toolchain/usr/bin/mipsel-linux-g++ LDFLAGS := -Wl,--gc-sections -fno-ident CPUFLAGS := -ffast-math -march=mips32r2 -mtune=mips32r2 -mhard-float -fexpensive-optimizations -frename-registers else From 5ee4419bbc3d7c3229cf0978b20458b3e851c3f2 Mon Sep 17 00:00:00 2001 From: Bernhard Schelling <14200249+schellingb@users.noreply.github.com> Date: Mon, 1 Feb 2021 20:00:44 +0900 Subject: [PATCH 03/58] Disable failing console stages for now --- .gitlab-ci.yml | 82 +++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index dbc8ed9aa..8430414fa 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -38,28 +38,28 @@ include: - project: 'libretro-infrastructure/ci-templates' file: '/android-jni.yml' - ################################## CONSOLES ################################ - # Nintendo 3DS - - project: 'libretro-infrastructure/ci-templates' - file: '/ctr-static.yml' - - # Nintendo WiiU - - project: 'libretro-infrastructure/ci-templates' - file: '/wiiu-static.yml' - - # Nintendo Switch - - project: 'libretro-infrastructure/ci-templates' - file: '/libnx-static.yml' - - # PlayStation Vita - - project: 'libretro-infrastructure/ci-templates' - file: '/vita-static.yml' +# ################################## CONSOLES ################################ +# # Nintendo 3DS +# - project: 'libretro-infrastructure/ci-templates' +# file: '/ctr-static.yml' +# +# # Nintendo WiiU +# - project: 'libretro-infrastructure/ci-templates' +# file: '/wiiu-static.yml' +# +# # Nintendo Switch +# - project: 'libretro-infrastructure/ci-templates' +# file: '/libnx-static.yml' +# +# # PlayStation Vita +# - project: 'libretro-infrastructure/ci-templates' +# file: '/vita-static.yml' # Stages for building stages: - build-prepare - build-shared - - build-static +# - build-static ############################################################################## #################################### STAGES ################################## @@ -127,27 +127,27 @@ android-x86: - .libretro-android-jni-x86 - .core-defs -################################### CONSOLES ################################# -# Nintendo 3DS -libretro-build-ctr: - extends: - - .libretro-ctr-static-retroarch-master - - .core-defs - -# Nintendo WiiU -libretro-build-wiiu: - extends: - - .libretro-wiiu-static-retroarch-master - - .core-defs - -# Nintendo Switch -libretro-build-libnx-aarch64: - extends: - - .libretro-libnx-static-retroarch-master - - .core-defs - -# PlayStation Vita -libretro-build-vita: - extends: - - .libretro-vita-static-retroarch-master - - .core-defs +#################################### CONSOLES ################################# +## Nintendo 3DS +#libretro-build-ctr: +# extends: +# - .libretro-ctr-static-retroarch-master +# - .core-defs +# +## Nintendo WiiU +#libretro-build-wiiu: +# extends: +# - .libretro-wiiu-static-retroarch-master +# - .core-defs +# +## Nintendo Switch +#libretro-build-libnx-aarch64: +# extends: +# - .libretro-libnx-static-retroarch-master +# - .core-defs +# +## PlayStation Vita +#libretro-build-vita: +# extends: +# - .libretro-vita-static-retroarch-master +# - .core-defs From 2372e20f835bd3ce1679413c7be224d667c82be9 Mon Sep 17 00:00:00 2001 From: Bernhard Schelling <14200249+schellingb@users.noreply.github.com> Date: Sat, 13 Feb 2021 21:25:36 +0900 Subject: [PATCH 04/58] Switch Android NDK app platform from 23 to 16 Disable strip for debug builds Fix Android compile warning --- Makefile | 2 ++ jni/Application.mk | 2 +- src/hardware/vga_paradise.cpp | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 336251baa..d86338917 100644 --- a/Makefile +++ b/Makefile @@ -174,10 +174,12 @@ ifeq ($(STATIC_LINKING), 1) else $(info Linking $@ ...) $(CXX) $(LDFLAGS) -o $@ $^ +ifneq ($(BUILD),DEBUG) @-/opt/gcw0-toolchain/usr/mipsel-gcw0-linux-uclibc/bin/strip --strip-all $@ $(PIPETONULL);true # gcw0 @-strip --strip-all $@ $(PIPETONULL);true # others @-strip -xS $@ $(PIPETONULL);true # mac endif +endif define COMPILE $(info Compiling $2 ...) diff --git a/jni/Application.mk b/jni/Application.mk index 2e86fea81..b72635769 100644 --- a/jni/Application.mk +++ b/jni/Application.mk @@ -1,4 +1,4 @@ -APP_PLATFORM := android-23 +APP_PLATFORM := android-16 APP_STL := c++_static APP_ABI := armeabi-v7a arm64-v8a NDK_TOOLCHAIN_VERSION := clang diff --git a/src/hardware/vga_paradise.cpp b/src/hardware/vga_paradise.cpp index 966ee4cff..5a02d1132 100644 --- a/src/hardware/vga_paradise.cpp +++ b/src/hardware/vga_paradise.cpp @@ -23,7 +23,8 @@ #include "inout.h" #include "mem.h" -typedef struct { +//DBP: Changed this to a C++ struct to avoid 'type is not C-compatible due to this member' warning +/*typedef*/ struct SVGA_PVGA1A_DATA { Bitu PR0A; Bitu PR0B; Bitu PR1; @@ -36,7 +37,7 @@ typedef struct { Bitu clockFreq[4]; Bitu biosMode; -} SVGA_PVGA1A_DATA; +} /*SVGA_PVGA1A_DATA*/; static SVGA_PVGA1A_DATA pvga1a = { 0,0, 0,0,0,0,0, {0,0,0,0}, 0 }; From 7437b070f46d14e5241eaced05b1edfcee878a5e Mon Sep 17 00:00:00 2001 From: Bernhard Schelling <14200249+schellingb@users.noreply.github.com> Date: Wed, 24 Feb 2021 04:08:06 +0900 Subject: [PATCH 05/58] Resync Increase version number Update DOSBox SVN Change "Disable extended memory" mode to still emulate 16 MB of RAM Show CPU overload warning only once per minute Add "Custom Keyboard + Mouse" input modes Don't let frontend render faster than the emulated monitor refresh rate --- dosbox_pure_libretro.cpp | 26 +++++++--- include/cpu.h | 12 ++++- src/cpu/core_dyn_x86.cpp | 2 +- src/cpu/core_dynrec.cpp | 2 +- src/cpu/core_normal.cpp | 2 +- src/cpu/core_prefetch.cpp | 2 +- src/cpu/core_simple.cpp | 2 +- src/cpu/cpu.cpp | 9 ++++ src/cpu/flags.cpp | 24 ++++----- src/fpu/fpu_instructions.h | 10 ++-- src/hardware/disney.cpp | 94 +++++++++++++++++------------------ src/hardware/vga_crtc.cpp | 25 +++++----- src/hardware/vga_gfx.cpp | 6 +-- src/hardware/vga_memory.cpp | 2 +- src/hardware/vga_misc.cpp | 12 ++--- src/hardware/vga_other.cpp | 28 +++++------ src/hardware/vga_paradise.cpp | 6 +-- src/hardware/vga_tseng.cpp | 25 +++++----- src/misc/setup.cpp | 6 ++- 19 files changed, 164 insertions(+), 131 deletions(-) diff --git a/dosbox_pure_libretro.cpp b/dosbox_pure_libretro.cpp index 443a87c33..076ca65b5 100644 --- a/dosbox_pure_libretro.cpp +++ b/dosbox_pure_libretro.cpp @@ -98,7 +98,7 @@ static bool dbp_timing_tamper; static bool dbp_fast_forward; static bool dbp_game_running; static bool dbp_lockthreadstate; -static void dbp_calculate_min_sleep() { dbp_min_sleep = 1 + (uint32_t)(700 / (render.src.fps > av_info.timing.fps ? render.src.fps : av_info.timing.fps)); } +static void dbp_calculate_min_sleep() { dbp_min_sleep = (uint32_t)(1000 / (render.src.fps > av_info.timing.fps ? render.src.fps : av_info.timing.fps)); } // DOSBOX GFX enum { DBP_BUFFER_COUNT = 2 }; @@ -141,6 +141,8 @@ enum DBP_Port_Device DBP_DEVICE_ThrustMasterFlightStick = RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 6), DBP_DEVICE_BothDOSJoysticks = RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 7), DBP_DEVICE_BindCustomKeyboard = RETRO_DEVICE_KEYBOARD, + DBP_DEVICE_KeyboardMouseLeftStick = RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_KEYBOARD, 1), + DBP_DEVICE_KeyboardMouseRightStick = RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_KEYBOARD, 2), }; enum { DBP_MAX_PORTS = 8 }; static const char* DBP_KBDNAMES[] = @@ -1774,7 +1776,7 @@ void retro_get_system_info(struct retro_system_info *info) // #1 { memset(info, 0, sizeof(*info)); info->library_name = "DOSBox-pure"; - info->library_version = "0.10"; + info->library_version = "0.11"; info->need_fullpath = true; info->block_extract = true; info->valid_extensions = "zip|dosz|exe|com|bat|iso|cue|ins|img|ima|vhd|m3u|m3u8"; @@ -1901,9 +1903,11 @@ static void refresh_input_binds(unsigned refresh_min_port = 0) case DBP_DEVICE_Disabled: continue; case DBP_DEVICE_MouseLeftAnalog: + case DBP_DEVICE_KeyboardMouseLeftStick: binds = BindsMouseLeftAnalog; break; case DBP_DEVICE_MouseRightAnalog: + case DBP_DEVICE_KeyboardMouseRightStick: binds = BindsMouseRightAnalog; break; case DBP_DEVICE_DefaultJoypad: @@ -2026,7 +2030,7 @@ static void refresh_input_binds(unsigned refresh_min_port = 0) dbp_input_binds.push_back({ port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "On Screen Keyboard", DBPET_ONSCREENKEYBOARD }); } - if (dbp_port_devices[port] == DBP_DEVICE_BindCustomKeyboard) + if ((dbp_port_devices[port] & RETRO_DEVICE_MASK) == RETRO_DEVICE_KEYBOARD) continue; if (port == 0 && dbp_auto_mapping && dbp_port_devices[0] == DBP_DEVICE_DefaultJoypad) @@ -2205,7 +2209,7 @@ static void check_variables() bool mem_use_extended = (atoi(mem) > 0); Variables::DosBoxSet("dos", "xms", (mem_use_extended ? "true" : "false"), true); Variables::DosBoxSet("dos", "ems", (mem_use_extended ? "true" : "false"), true); - Variables::DosBoxSet("dosbox", "memsize", (mem_use_extended ? mem : "4"), true); + Variables::DosBoxSet("dosbox", "memsize", (mem_use_extended ? mem : "16"), true); // handle setting strings like on/yes/true/savestate or rewind const char* savestate = Variables::RetroGet("dosbox_pure_savestate", "false"); @@ -2749,6 +2753,8 @@ bool retro_load_game(const struct retro_game_info *info) //#4 controller_descriptions.push_back({ "ThrustMaster Flight Stick (3 axes, 4 buttons, 1 hat)", DBP_DEVICE_ThrustMasterFlightStick }); controller_descriptions.push_back({ "Control both DOS joysticks (4 axes, 4 buttons)", DBP_DEVICE_BothDOSJoysticks }); controller_descriptions.push_back({ "Custom Keyboard Bindings", DBP_DEVICE_BindCustomKeyboard }); + controller_descriptions.push_back({ "Custom Keyboard + Mouse on Left Stick and B/A/X", DBP_DEVICE_KeyboardMouseLeftStick }); + controller_descriptions.push_back({ "Custom Keyboard + Mouse on Right Stick and L/R/X", DBP_DEVICE_KeyboardMouseRightStick }); ports[port].num_types = (unsigned)controller_descriptions.size() - port_first_cd[port]; } for (port = 0; port != 3; port++) ports[port].types = &controller_descriptions[port_first_cd[port]]; @@ -2877,13 +2883,17 @@ void retro_run(void) extern bool DBP_CPUOverload; if (DBP_CPUOverload) { - static uint32_t first_overload; + static Bit32u first_overload, last_overload_msg; if (!dbp_overload_count) first_overload = DBP_GetTicks(); if (dbp_retro_activity < 10 || dbp_timing_tamper || dbp_fast_forward) dbp_overload_count = 0; else if (dbp_overload_count++ >= 200) { - if ((DBP_GetTicks() - first_overload) < 10000) + Bit32u ticks = DBP_GetTicks(); + if ((ticks - first_overload) < 10000 && (!last_overload_msg || (ticks - last_overload_msg) >= 60000)) + { retro_notify(0, RETRO_LOG_WARN, "Emulated CPU is overloaded, try reducing the emulated performance in the core options"); + last_overload_msg = ticks; + } dbp_overload_count = 0; } } @@ -3050,8 +3060,8 @@ void retro_run(void) } // keep frontend UI thread from running at 100% cpu - uint32_t this_run = DBP_GetTicks(); - if (this_run - dbp_last_run < dbp_min_sleep) sleep_ms(dbp_min_sleep - (this_run - dbp_last_run)); + uint32_t this_run = DBP_GetTicks(), run_sleep = dbp_min_sleep - (this_run - dbp_last_run); + if (run_sleep < dbp_min_sleep) { sleep_ms(run_sleep); this_run += run_sleep; } dbp_last_run = this_run; } diff --git a/include/cpu.h b/include/cpu.h index fd0a08708..8d39d33ce 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -156,6 +156,7 @@ static INLINE void CPU_SW_Interrupt_NoIOPLCheck(Bitu num,Bitu oldeip) { bool CPU_PrepareException(Bitu which,Bitu error); void CPU_Exception(Bitu which,Bitu error=0); +void CPU_DebugException(Bit32u triggers,Bitu oldeip); bool CPU_SetSegGeneral(SegNames seg,Bitu value); bool CPU_PopSeg(SegNames seg,bool use32); @@ -168,7 +169,7 @@ void CPU_Push32(Bitu value); void CPU_SetFlags(Bitu word,Bitu mask); - +#define EXCEPTION_DB 1 #define EXCEPTION_UD 6 #define EXCEPTION_TS 10 #define EXCEPTION_NP 11 @@ -183,6 +184,14 @@ void CPU_SetFlags(Bitu word,Bitu mask); #define CR0_FPUPRESENT 0x00000010 #define CR0_PAGING 0x80000000 +// reasons for triggering a debug exception +#define DBINT_BP0 0x00000001 +#define DBINT_BP1 0x00000002 +#define DBINT_BP2 0x00000004 +#define DBINT_BP3 0x00000008 +#define DBINT_GD 0x00002000 +#define DBINT_STEP 0x00004000 +#define DBINT_TASKSWITCH 0x00008000 // ********************************************************************* // Descriptor @@ -488,5 +497,4 @@ static INLINE void CPU_SetFlagsw(Bitu word) { CPU_SetFlags(word,mask); } - #endif diff --git a/src/cpu/core_dyn_x86.cpp b/src/cpu/core_dyn_x86.cpp index 5187c99c1..59e55a76a 100644 --- a/src/cpu/core_dyn_x86.cpp +++ b/src/cpu/core_dyn_x86.cpp @@ -379,7 +379,7 @@ Bits CPU_Core_Dyn_X86_Trap_Run(void) { cpu.trap_skip = false; Bits ret=CPU_Core_Normal_Run(); - if (!cpu.trap_skip) CPU_HW_Interrupt(1); + if (!cpu.trap_skip) CPU_DebugException(DBINT_STEP,reg_eip); CPU_Cycles = oldCycles-1; cpudecoder = &CPU_Core_Dyn_X86_Run; diff --git a/src/cpu/core_dynrec.cpp b/src/cpu/core_dynrec.cpp index 0fe2b137f..1c11778c5 100644 --- a/src/cpu/core_dynrec.cpp +++ b/src/cpu/core_dynrec.cpp @@ -327,7 +327,7 @@ Bits CPU_Core_Dynrec_Trap_Run(void) { // trap to int1 unless the last instruction deferred this // (allows hardware interrupts to be served without interaction) - if (!cpu.trap_skip) CPU_HW_Interrupt(1); + if (!cpu.trap_skip) CPU_DebugException(DBINT_STEP,reg_eip); CPU_Cycles = oldCycles-1; // continue (either the trapflag was clear anyways, or the int1 cleared it) diff --git a/src/cpu/core_normal.cpp b/src/cpu/core_normal.cpp index cafac8705..355ac80aa 100644 --- a/src/cpu/core_normal.cpp +++ b/src/cpu/core_normal.cpp @@ -196,7 +196,7 @@ Bits CPU_Core_Normal_Trap_Run(void) { cpu.trap_skip = false; Bits ret=CPU_Core_Normal_Run(); - if (!cpu.trap_skip) CPU_HW_Interrupt(1); + if (!cpu.trap_skip) CPU_DebugException(DBINT_STEP,reg_eip); CPU_Cycles = oldCycles-1; cpudecoder = &CPU_Core_Normal_Run; diff --git a/src/cpu/core_prefetch.cpp b/src/cpu/core_prefetch.cpp index ca8476bbc..67fb99a0e 100644 --- a/src/cpu/core_prefetch.cpp +++ b/src/cpu/core_prefetch.cpp @@ -301,7 +301,7 @@ Bits CPU_Core_Prefetch_Trap_Run(void) { cpu.trap_skip = false; Bits ret=CPU_Core_Prefetch_Run(); - if (!cpu.trap_skip) CPU_HW_Interrupt(1); + if (!cpu.trap_skip) CPU_DebugException(DBINT_STEP,reg_eip); CPU_Cycles = oldCycles-1; cpudecoder = &CPU_Core_Prefetch_Run; diff --git a/src/cpu/core_simple.cpp b/src/cpu/core_simple.cpp index 139de7b5b..0da5f019a 100644 --- a/src/cpu/core_simple.cpp +++ b/src/cpu/core_simple.cpp @@ -193,7 +193,7 @@ Bits CPU_Core_Simple_Trap_Run(void) { cpu.trap_skip = false; Bits ret=CPU_Core_Simple_Run(); - if (!cpu.trap_skip) CPU_HW_Interrupt(1); + if (!cpu.trap_skip) CPU_DebugException(DBINT_STEP,reg_eip); CPU_Cycles = oldCycles-1; cpudecoder = &CPU_Core_Simple_Run; diff --git a/src/cpu/cpu.cpp b/src/cpu/cpu.cpp index 319974219..df8bdaccb 100644 --- a/src/cpu/cpu.cpp +++ b/src/cpu/cpu.cpp @@ -541,6 +541,11 @@ bool CPU_IO_Exception(Bitu port,Bitu size) { return CPU_PrepareException(EXCEPTION_GP,0); } +void CPU_DebugException(Bit32u triggers,Bitu oldeip) { + cpu.drx[6] = (cpu.drx[6] & 0xFFFF1FF0) | triggers; + CPU_Interrupt(EXCEPTION_DB,CPU_INT_EXCEPTION,oldeip); +} + void CPU_Exception(Bitu which,Bitu error ) { // LOG_MSG("Exception %d error %x",which,error); cpu.exception.error=error; @@ -549,6 +554,10 @@ void CPU_Exception(Bitu which,Bitu error ) { Bit8u lastint; void CPU_Interrupt(Bitu num,Bitu type,Bitu oldeip) { + if (num == EXCEPTION_DB && (type&CPU_INT_EXCEPTION) == 0) { + CPU_DebugException(0,oldeip); // DR6 bits need updating + return; + } lastint=num; FillFlags(); #if C_DEBUG diff --git a/src/cpu/flags.cpp b/src/cpu/flags.cpp index adaf799b3..de4ba53eb 100644 --- a/src/cpu/flags.cpp +++ b/src/cpu/flags.cpp @@ -117,9 +117,9 @@ Bit32u get_CF(void) { case t_TESTd: return false; /* Set to false */ case t_DIV: - return false; /* Unkown */ + return false; /* Unknown */ default: - LOG(LOG_CPU,LOG_ERROR)("get_CF Unknown %d",lflags.type); + LOG(LOG_CPU,LOG_ERROR)("get_CF Unknown %" sBitfs(d),lflags.type); } return 0; } @@ -199,9 +199,9 @@ Bit32u get_AF(void) { case t_DSHRd: case t_DIV: case t_MUL: - return false; /* Unkown */ + return false; /* Unknown */ default: - LOG(LOG_CPU,LOG_ERROR)("get_AF Unknown %d",lflags.type); + LOG(LOG_CPU,LOG_ERROR)("get_AF Unknown %" sBitfs(d),lflags.type); } return 0; } @@ -268,9 +268,9 @@ Bit32u get_ZF(void) { return (lf_resd==0); case t_DIV: case t_MUL: - return false; /* Unkown */ + return false; /* Unknown */ default: - LOG(LOG_CPU,LOG_ERROR)("get_ZF Unknown %d",lflags.type); + LOG(LOG_CPU,LOG_ERROR)("get_ZF Unknown %" sBitfs(d),lflags.type); } return false; } @@ -336,9 +336,9 @@ Bit32u get_SF(void) { return (lf_resd&0x80000000); case t_DIV: case t_MUL: - return false; /* Unkown */ + return false; /* Unknown */ default: - LOG(LOG_CPU,LOG_ERROR)("get_SF Unkown %d",lflags.type); + LOG(LOG_CPU,LOG_ERROR)("get_SF Unknown %" sBitfs(d),lflags.type); } return false; @@ -424,9 +424,9 @@ Bit32u get_OF(void) { case t_SARd: return false; /* Return false */ case t_DIV: - return false; /* Unkown */ + return false; /* Unknown */ default: - LOG(LOG_CPU,LOG_ERROR)("get_OF Unkown %d",lflags.type); + LOG(LOG_CPU,LOG_ERROR)("get_OF Unkown %" sBitfs(d),lflags.type); } return false; } @@ -874,7 +874,7 @@ Bitu FillFlags(void) { break; default: - LOG(LOG_CPU,LOG_ERROR)("Unhandled flag type %d",lflags.type); + LOG(LOG_CPU,LOG_ERROR)("Unhandled flag type %" sBitfs(d),lflags.type); return 0; } lflags.type=t_UNKNOWN; @@ -1175,7 +1175,7 @@ void FillFlagsNoCFOF(void) { break; default: - LOG(LOG_CPU,LOG_ERROR)("Unhandled flag type %d",lflags.type); + LOG(LOG_CPU,LOG_ERROR)("Unhandled flag type %" sBitfs(d),lflags.type); break; } lflags.type=t_UNKNOWN; diff --git a/src/fpu/fpu_instructions.h b/src/fpu/fpu_instructions.h index 22a5b504e..454a84785 100644 --- a/src/fpu/fpu_instructions.h +++ b/src/fpu/fpu_instructions.h @@ -266,16 +266,20 @@ static void FPU_FST_F80(PhysPt addr) { } static void FPU_FST_I16(PhysPt addr) { - mem_writew(addr,static_cast(FROUND(fpu.regs[TOP].d))); + double val = FROUND(fpu.regs[TOP].d); + mem_writew(addr,(val < 32768.0 && val >= -32768.0)?static_cast(val):0x8000); } static void FPU_FST_I32(PhysPt addr) { - mem_writed(addr,static_cast(FROUND(fpu.regs[TOP].d))); + double val = FROUND(fpu.regs[TOP].d); + mem_writed(addr,(val < 2147483648.0 && val >= -2147483648.0)?static_cast(val):0x80000000); } static void FPU_FST_I64(PhysPt addr) { + double val = FROUND(fpu.regs[TOP].d); FPU_Reg blah; - blah.ll = static_cast(FROUND(fpu.regs[TOP].d)); + blah.ll = (val < 9223372036854775808.0 && val >= -9223372036854775808.0)?static_cast(val):LONGTYPE(0x8000000000000000); + mem_writed(addr,blah.l.lower); mem_writed(addr+4,blah.l.upper); } diff --git a/src/hardware/disney.cpp b/src/hardware/disney.cpp index 697134086..e8bb8099b 100644 --- a/src/hardware/disney.cpp +++ b/src/hardware/disney.cpp @@ -52,7 +52,7 @@ static struct { // which channel do we use for mono output? // and the channel used for stereo dac_channel* leader; - + Bitu state; Bitu interface_det; Bitu interface_det_ext; @@ -66,7 +66,7 @@ static struct { static void DISNEY_CallBack(Bitu len); static void DISNEY_disable(Bitu) { - if(disney.mo) { + if (disney.mo) { disney.chan->AddSilence(); disney.chan->Enable(false); } @@ -79,7 +79,7 @@ static void DISNEY_disable(Bitu) { } static void DISNEY_enable(Bitu freq) { - if(freq < 500 || freq > 100000) { + if (freq < 500 || freq > 100000) { // try again.. disney.state = DS_IDLE; return; @@ -108,7 +108,7 @@ static void DISNEY_analyze(Bitu channel){ } disney.da[channel].speedcheck_last = PIC_FullIndex(); disney.da[channel].speedcheck_init = true; - + disney.state = DS_ANALYZING; break; @@ -116,29 +116,29 @@ static void DISNEY_analyze(Bitu channel){ { // detect stereo: if we have about the same data amount in both channels Bits st_diff = disney.da[0].used - disney.da[1].used; - + // find leader channel (the one with higher rate) [this good for the stereo case?] - if(disney.da[0].used > disney.da[1].used) { + if (disney.da[0].used > disney.da[1].used) { //disney.monochannel=0; disney.leader = &disney.da[0]; } else { //disney.monochannel=1; disney.leader = &disney.da[1]; } - - if((st_diff < 5) && (st_diff > -5)) disney.stereo = true; + + if ((st_diff < 5) && (st_diff > -5)) disney.stereo = true; else disney.stereo = false; // calculate rate for both channels Bitu ch_speed[2]; for(Bitu i = 0; i < 2; i++) { - if(disney.da[i].used > 1) { // avoid dividing by zero + if (disney.da[i].used > 1) { // avoid dividing by zero ch_speed[i] = (Bitu)(1.0/((disney.da[i].speedcheck_sum/1000.0) / (float)(((float)disney.da[i].used)-1.0))); // -1.75 } else ch_speed[i] = 0; } - + // choose the larger value DISNEY_enable(ch_speed[0] > ch_speed[1]? ch_speed[0]:ch_speed[1]); // TODO @@ -149,50 +149,50 @@ static void DISNEY_analyze(Bitu channel){ double current = PIC_FullIndex(); dac_channel* cch = &disney.da[channel]; - if(!cch->speedcheck_init) { + if (!cch->speedcheck_init) { cch->speedcheck_init = true; cch->speedcheck_last = current; break; } cch->speedcheck_sum += current - cch->speedcheck_last; //LOG_MSG("t=%f",current - cch->speedcheck_last); - + // sanity checks (printer...) - if((current - cch-> speedcheck_last) < 0.01 || + if ((current - cch-> speedcheck_last) < 0.01 || (current - cch-> speedcheck_last) > 2) cch->speedcheck_failed = true; - + // if both are failed we are back at start - if(disney.da[0].speedcheck_failed && disney.da[1].speedcheck_failed) { - disney.state=DS_IDLE; + if (disney.da[0].speedcheck_failed && disney.da[1].speedcheck_failed) { + disney.state = DS_IDLE; break; } cch->speedcheck_last = current; - + // analyze finish condition - if(disney.da[0].used > 30 || disney.da[1].used > 30) + if (disney.da[0].used > 30 || disney.da[1].used > 30) disney.state = DS_FINISH; break; } } } -static void disney_write(Bitu port,Bitu val,Bitu iolen) { +static void disney_write(Bitu port,Bitu val,Bitu /*iolen*/) { //LOG_MSG("write disney time %f addr%x val %x",PIC_FullIndex(),port,val); - disney.last_used=PIC_Ticks; + disney.last_used = PIC_Ticks; switch (port-DISNEY_BASE) { case 0: /* Data Port */ { disney.data=val; // if data is written here too often without using the stereo - // mechanism we use the simple DAC machanism. - if(disney.state != DS_RUNNING) { + // mechanism we use the simple DAC machanism. + if (disney.state != DS_RUNNING) { disney.interface_det++; if(disney.interface_det > 5) DISNEY_analyze(0); } - if(disney.interface_det > 5) { + if (disney.interface_det > 5) { if(disney.da[0].used < DISNEY_SIZE) { disney.da[0].buffer[disney.da[0].used] = disney.data; disney.da[0].used++; @@ -200,11 +200,11 @@ static void disney_write(Bitu port,Bitu val,Bitu iolen) { } break; } - case 1: /* Status Port */ - LOG(LOG_MISC,LOG_NORMAL)("DISNEY:Status write %x",val); + case 1: /* Status Port */ + LOG(LOG_MISC,LOG_NORMAL)("DISNEY:Status write %" sBitfs(X),val); break; case 2: /* Control Port */ - if((disney.control & 0x2) && !(val & 0x2)) { + if ((disney.control & 0x2) && !(val & 0x2)) { if(disney.state != DS_RUNNING) { disney.interface_det = 0; disney.interface_det_ext = 0; @@ -212,28 +212,28 @@ static void disney_write(Bitu port,Bitu val,Bitu iolen) { } // stereo channel latch - if(disney.da[1].used < DISNEY_SIZE) { + if (disney.da[1].used < DISNEY_SIZE) { disney.da[1].buffer[disney.da[1].used] = disney.data; disney.da[1].used++; } //else LOG_MSG("disney overflow 1"); } - if((disney.control & 0x1) && !(val & 0x1)) { + if ((disney.control & 0x1) && !(val & 0x1)) { if(disney.state != DS_RUNNING) { disney.interface_det = 0; disney.interface_det_ext = 0; DISNEY_analyze(0); } // stereo channel latch - if(disney.da[0].used < DISNEY_SIZE) { + if (disney.da[0].used < DISNEY_SIZE) { disney.da[0].buffer[disney.da[0].used] = disney.data; disney.da[0].used++; } //else LOG_MSG("disney overflow 0"); } - if((disney.control & 0x8) && !(val & 0x8)) { + if ((disney.control & 0x8) && !(val & 0x8)) { // emulate a device with 16-byte sound FIFO - if(disney.state != DS_RUNNING) { + if (disney.state != DS_RUNNING) { disney.interface_det_ext++; disney.interface_det = 0; if(disney.interface_det_ext > 5) { @@ -241,7 +241,7 @@ static void disney_write(Bitu port,Bitu val,Bitu iolen) { DISNEY_enable(7000); } } - if(disney.interface_det_ext > 5) { + if (disney.interface_det_ext > 5) { if(disney.da[0].used < DISNEY_SIZE) { disney.da[0].buffer[disney.da[0].used] = disney.data; disney.da[0].used++; @@ -256,23 +256,23 @@ static void disney_write(Bitu port,Bitu val,Bitu iolen) { } } -static Bitu disney_read(Bitu port,Bitu iolen) { +static Bitu disney_read(Bitu port,Bitu /*iolen*/){ Bitu retval; switch (port-DISNEY_BASE) { case 0: /* Data Port */ // LOG(LOG_MISC,LOG_NORMAL)("DISNEY:Read from data port"); return disney.data; break; - case 1: /* Status Port */ + case 1: /* Status Port */ // LOG(LOG_MISC,"DISNEY:Read from status port %X",disney.status); retval = 0x07;//0x40; // Stereo-on-1 and (or) New-Stereo DACs present - if(disney.interface_det_ext > 5) { + if (disney.interface_det_ext > 5) { if (disney.leader && disney.leader->used >= 16){ retval |= 0x40; // ack retval &= ~0x4; // interrupt } } - if(!(disney.data&0x80)) retval |= 0x80; // pin 9 is wired to pin 11 + if (!(disney.data&0x80)) retval |= 0x80; // pin 9 is wired to pin 11 return retval; break; case 2: /* Control Port */ @@ -297,14 +297,14 @@ static void DISNEY_CallBack(Bitu len) { // get the smaller used Bitu real_used; - if(disney.stereo) { + if (disney.stereo) { real_used = disney.da[0].used; if(disney.da[1].used < real_used) real_used = disney.da[1].used; } else real_used = disney.leader->used; if (real_used >= len) { // enough data for now - if(disney.stereo) DISNEY_PlayStereo(len, disney.da[0].buffer, disney.da[1].buffer); + if (disney.stereo) DISNEY_PlayStereo(len, disney.da[0].buffer, disney.da[1].buffer); else disney.chan->AddSamples_m8(len,disney.leader->buffer); // put the rest back to start @@ -316,9 +316,9 @@ static void DISNEY_CallBack(Bitu len) { // TODO: len > DISNEY } else { // not enough data if(disney.stereo) { - Bit8u gapfiller0 = 128; - Bit8u gapfiller1 = 128; - if(real_used) { + Bit8u gapfiller0 = 0x80; + Bit8u gapfiller1 = 0x80; + if (real_used) { gapfiller0 = disney.da[0].buffer[real_used-1]; gapfiller1 = disney.da[1].buffer[real_used-1]; }; @@ -332,8 +332,8 @@ static void DISNEY_CallBack(Bitu len) { len -= real_used; } else { // mono - Bit8u gapfiller = 128; //Keep the middle - if(real_used) { + Bit8u gapfiller = 0x80; //Keep the middle + if (real_used) { // fix for some stupid game; it outputs 0 at the end of the stream // causing a click. So if we have at least two bytes availible in the // buffer and the last one is a 0 then ignore that. @@ -341,7 +341,7 @@ static void DISNEY_CallBack(Bitu len) { real_used--; } // do it this way because AddSilence sounds like a gnawing mouse - if(real_used) + if (real_used) gapfiller = disney.leader->buffer[real_used-1]; //LOG_MSG("gapfiller %x, fill len %d, realused %d",gapfiller,len-real_used,real_used); memset(disney.leader->buffer+real_used, gapfiller, len-real_used); @@ -368,10 +368,10 @@ class DISNEY: public Module_base { DISNEY(Section* configuration):Module_base(configuration) { Section_prop * section=static_cast(configuration); if(!section->Get_bool("disney")) return; - + WriteHandler.Install(DISNEY_BASE,disney_write,IO_MB,3); ReadHandler.Install(DISNEY_BASE,disney_read,IO_MB,3); - + disney.status=0x84; disney.control=0; disney.last_used=0; @@ -393,7 +393,7 @@ class DISNEY: public Module_base { static DISNEY* test; -static void DISNEY_ShutDown(Section* sec){ +static void DISNEY_ShutDown(Section* /*sec*/){ delete test; } diff --git a/src/hardware/vga_crtc.cpp b/src/hardware/vga_crtc.cpp index 034dafc63..f8f10e67a 100644 --- a/src/hardware/vga_crtc.cpp +++ b/src/hardware/vga_crtc.cpp @@ -35,16 +35,16 @@ void VGA_UnmapMMIO(void); void vga_write_p3d5(Bitu port,Bitu val,Bitu iolen); Bitu DEBUG_EnableDebugger(void); -void vga_write_p3d4(Bitu port,Bitu val,Bitu iolen) { - crtc(index)=val; +void vga_write_p3d4(Bitu /*port*/,Bitu val,Bitu /*iolen*/) { + crtc(index) = val; } -Bitu vga_read_p3d4(Bitu port,Bitu iolen) { +Bitu vga_read_p3d4(Bitu /*port*/,Bitu /*iolen*/) { return crtc(index); } -void vga_write_p3d5(Bitu port,Bitu val,Bitu iolen) { -// if (crtc(index)>0x18) LOG_MSG("VGA CRCT write %X to reg %X",val,crtc(index)); +void vga_write_p3d5(Bitu /*port*/,Bitu val,Bitu iolen) { +// if (crtc(index) > 0x18) LOG_MSG("VGA CRCT write %" sBitfs(X) " to reg %X",val,crtc(index)); switch(crtc(index)) { case 0x00: /* Horizontal Total Register */ if (crtc(read_only)) break; @@ -90,12 +90,12 @@ void vga_write_p3d5(Bitu port,Bitu val,Bitu iolen) { 5-6 Number of character clocks to delay start of display after Horizontal Retrace. 7 bit 5 of the End Horizontal Blanking count (See 3d4h index 3 bit 0-4) - */ + */ break; case 0x06: /* Vertical Total Register */ if (crtc(read_only)) break; if (val != crtc(vertical_total)) { - crtc(vertical_total)=val; + crtc(vertical_total)=val; VGA_StartResize(); } /* 0-7 Lower 8 bits of the Vertical Total. Bit 8 is found in 3d4h index 7 @@ -214,7 +214,7 @@ void vga_write_p3d5(Bitu port,Bitu val,Bitu iolen) { break; case 0x10: /* Vertical Retrace Start Register */ crtc(vertical_retrace_start)=val; - /* + /* 0-7 Lower 8 bits of Vertical Retrace Start. Vertical Retrace starts when the line counter reaches this value. Bit 8 is found in 3d4h index 7 bit 2. Bit 9 is found in 3d4h index 7 bit 7. @@ -222,7 +222,7 @@ void vga_write_p3d5(Bitu port,Bitu val,Bitu iolen) { break; case 0x11: /* Vertical Retrace End Register */ crtc(vertical_retrace_end)=val; - + if (IS_EGAVGA_ARCH && !(val & 0x10)) { vga.draw.vret_triggered=false; if (GCC_UNLIKELY(machine==MCH_EGA)) PIC_DeActivateIRQ(9); @@ -294,7 +294,7 @@ void vga_write_p3d5(Bitu port,Bitu val,Bitu iolen) { crtc(start_vertical_blanking)=val; VGA_StartResize(); } - /* + /* 0-7 Lower 8 bits of Vertical Blank Start. Vertical blanking starts when the line counter reaches this value. Bit 8 is found in 3d4h index 7 bit 3. @@ -367,7 +367,7 @@ void vga_write_p3d5(Bitu port,Bitu val,Bitu iolen) { } } -Bitu vga_read_p3d5(Bitu port,Bitu iolen) { +Bitu vga_read_p3d5(Bitu /*port*/,Bitu iolen) { // LOG_MSG("VGA CRCT read from reg %X",crtc(index)); switch(crtc(index)) { case 0x00: /* Horizontal Total Register */ @@ -383,7 +383,7 @@ Bitu vga_read_p3d5(Bitu port,Bitu iolen) { case 0x05: /* End Horizontal Retrace Register */ return crtc(end_horizontal_retrace); case 0x06: /* Vertical Total Register */ - return crtc(vertical_total); + return crtc(vertical_total); case 0x07: /* Overflow Register */ return crtc(overflow); case 0x08: /* Preset Row Scan Register */ @@ -432,4 +432,3 @@ Bitu vga_read_p3d5(Bitu port,Bitu iolen) { - diff --git a/src/hardware/vga_gfx.cpp b/src/hardware/vga_gfx.cpp index a9b11fcb2..e514c2db7 100644 --- a/src/hardware/vga_gfx.cpp +++ b/src/hardware/vga_gfx.cpp @@ -24,15 +24,15 @@ #define gfx(blah) vga.gfx.blah static bool index9warned=false; -static void write_p3ce(Bitu port,Bitu val,Bitu iolen) { +static void write_p3ce(Bitu /*port*/,Bitu val,Bitu /*iolen*/) { gfx(index)=val & 0x0f; } -static Bitu read_p3ce(Bitu port,Bitu iolen) { +static Bitu read_p3ce(Bitu /*port*/,Bitu /*iolen*/) { return gfx(index); } -static void write_p3cf(Bitu port,Bitu val,Bitu iolen) { +static void write_p3cf(Bitu /*port*/,Bitu val,Bitu iolen) { switch (gfx(index)) { case 0: /* Set/Reset Register */ gfx(set_reset)=val & 0x0f; diff --git a/src/hardware/vga_memory.cpp b/src/hardware/vga_memory.cpp index 7ce8af48d..3254e5867 100644 --- a/src/hardware/vga_memory.cpp +++ b/src/hardware/vga_memory.cpp @@ -735,7 +735,7 @@ class VGA_HERC_Handler : public PageHandler { VGA_HERC_Handler() { flags=PFLAG_READABLE|PFLAG_WRITEABLE; } - HostPt GetHostReadPt(Bitu phys_page) { + HostPt GetHostReadPt(Bitu /*phys_page*/) { // The 4kB map area is repeated in the 32kB range return &vga.mem.linear[0]; } diff --git a/src/hardware/vga_misc.cpp b/src/hardware/vga_misc.cpp index 4be3ec920..56a115269 100644 --- a/src/hardware/vga_misc.cpp +++ b/src/hardware/vga_misc.cpp @@ -29,7 +29,7 @@ Bitu vga_read_p3d4(Bitu port,Bitu iolen); void vga_write_p3d5(Bitu port,Bitu val,Bitu iolen); Bitu vga_read_p3d5(Bitu port,Bitu iolen); -Bitu vga_read_p3da(Bitu port,Bitu iolen) { +Bitu vga_read_p3da(Bitu /*port*/,Bitu /*iolen*/) { Bit8u retval=4; // bit 2 set, needed by Blues Brothers double timeInFrame = PIC_FullIndex()-vga.draw.delay.framestart; @@ -55,7 +55,7 @@ Bitu vga_read_p3da(Bitu port,Bitu iolen) { return retval; } -static void write_p3c2(Bitu port,Bitu val,Bitu iolen) { +static void write_p3c2(Bitu /*port*/,Bitu val,Bitu /*iolen*/) { vga.misc_output=val; Bitu base=(val & 0x1) ? 0x3d0 : 0x3b0; @@ -91,20 +91,20 @@ static void write_p3c2(Bitu port,Bitu val,Bitu iolen) { } -static Bitu read_p3cc(Bitu port,Bitu iolen) { +static Bitu read_p3cc(Bitu /*port*/,Bitu /*iolen*/) { return vga.misc_output; } // VGA feature control register -static Bitu read_p3ca(Bitu port,Bitu iolen) { +static Bitu read_p3ca(Bitu /*port*/,Bitu /*iolen*/) { return 0; } -static Bitu read_p3c8(Bitu port,Bitu iolen) { +static Bitu read_p3c8(Bitu /*port*/,Bitu /*iolen*/) { return 0x10; } -static Bitu read_p3c2(Bitu port,Bitu iolen) { +static Bitu read_p3c2(Bitu /*port*/,Bitu /*iolen*/) { Bit8u retval=0; if (machine==MCH_EGA) retval = 0x0F; diff --git a/src/hardware/vga_other.cpp b/src/hardware/vga_other.cpp index 470671263..9ea4dfc8f 100644 --- a/src/hardware/vga_other.cpp +++ b/src/hardware/vga_other.cpp @@ -107,7 +107,7 @@ static void write_crtc_data_other(Bitu /*port*/,Bitu val,Bitu /*iolen*/) { vga.other.lightpen |= (Bit8u)val; break; default: - LOG(LOG_VGAMISC,LOG_NORMAL)("MC6845:Write %X to illegal index %x",val,vga.other.index); + LOG(LOG_VGAMISC,LOG_NORMAL)("MC6845:Write %" sBitfs(X) " to illegal index %x",val,vga.other.index); } } static Bitu read_crtc_data_other(Bitu /*port*/,Bitu /*iolen*/) { @@ -154,7 +154,7 @@ static Bitu read_crtc_data_other(Bitu /*port*/,Bitu /*iolen*/) { return (Bitu)(~0); } -static void write_lightpen(Bitu port,Bitu val,Bitu) { +static void write_lightpen(Bitu port,Bitu /*val*/,Bitu) { switch (port) { case 0x3db: // Clear lightpen latch vga.other.lightpen_triggered = false; @@ -162,11 +162,11 @@ static void write_lightpen(Bitu port,Bitu val,Bitu) { case 0x3dc: // Preset lightpen latch if (!vga.other.lightpen_triggered) { vga.other.lightpen_triggered = true; // TODO: this shows at port 3ba/3da bit 1 - + double timeInFrame = PIC_FullIndex()-vga.draw.delay.framestart; double timeInLine = fmod(timeInFrame,vga.draw.delay.htotal); Bitu current_scanline = (Bitu)(timeInFrame / vga.draw.delay.htotal); - + vga.other.lightpen = (Bit16u)((vga.draw.address_add/2) * (current_scanline/2)); vga.other.lightpen += (Bit16u)((timeInLine / vga.draw.delay.hdend) * ((float)(vga.draw.address_add/2))); @@ -390,7 +390,7 @@ static void write_cga(Bitu port,Bitu val,Bitu /*iolen*/) { switch (port) { case 0x3d8: vga.tandy.mode_control=(Bit8u)val; - vga.attr.disabled = (val&0x8)? 0: 1; + vga.attr.disabled = (val&0x8)? 0: 1; if (vga.tandy.mode_control & 0x2) { // graphics mode if (vga.tandy.mode_control & 0x10) {// highres mode if (cga_comp==1 || (cga_comp==0 && !(val&0x4))) { // composite display @@ -424,7 +424,7 @@ static void CGAModel(bool pressed) { update_cga16_color(); LOG_MSG("%s model CGA selected", new_cga ? "Late" : "Early"); } - + static void Composite(bool pressed) { if (!pressed) return; if (++cga_comp>2) cga_comp=0; @@ -454,7 +454,7 @@ static void tandy_update_palette() { if (vga.tandy.color_select & 0x10) color_set |= 8; // intensity if (vga.tandy.color_select & 0x20) color_set |= 1; // Cyan Mag. White if (vga.tandy.mode_control & 0x04) { // Cyan Red White - color_set |= 1; + color_set |= 1; r_mask &= ~1; } VGA_SetCGA4Table( @@ -647,20 +647,20 @@ static void write_pcjr(Bitu port,Bitu val,Bitu /*iolen*/) { break; case 0x3df: // CRT/processor page register - + // Bit 0-2: CRT page PG0-2 // In one- and two bank modes, bit 0-2 select the 16kB memory // area of system RAM that is displayed on the screen. // In 4-banked modes, bit 1-2 select the 32kB memory area. // Bit 2 only has effect when the PCJR upgrade to 128k is installed. - + // Bit 3-5: Processor page CPU_PG // Selects the 16kB area of system RAM that is mapped to - // the B8000h IBM PC video memory window. Since A14-A16 of the + // the B8000h IBM PC video memory window. Since A14-A16 of the // processor are unconditionally replaced with these bits when // B8000h is accessed, the 16kB area is mapped to the 32kB // range twice in a row. (Scuba Venture writes across the boundary) - + // Bit 6-7: Video Address mode // 0: CRTC addresses A0-12 directly, accessing 8k characters // (+8k attributes). Used in text modes (one bank). @@ -692,8 +692,8 @@ static void CycleHercPal(bool pressed) { Herc_Palette(); VGA_DAC_CombineColor(1,7); } - -void Herc_Palette(void) { + +void Herc_Palette(void) { switch (herc_pal) { case 0: // White VGA_DAC_SetEntry(0x7,0x2a,0x2a,0x2a); @@ -713,7 +713,7 @@ void Herc_Palette(void) { static void write_hercules(Bitu port,Bitu val,Bitu /*iolen*/) { switch (port) { case 0x3b8: { - // the protected bits can always be cleared but only be set if the + // the protected bits can always be cleared but only be set if the // protection bits are set if (vga.herc.mode_control&0x2) { // already set diff --git a/src/hardware/vga_paradise.cpp b/src/hardware/vga_paradise.cpp index 5a02d1132..448b04cda 100644 --- a/src/hardware/vga_paradise.cpp +++ b/src/hardware/vga_paradise.cpp @@ -104,7 +104,7 @@ void write_p3cf_pvga1a(Bitu reg,Bitu val,Bitu /*iolen*/) { pvga1a.PR5 = val; break; default: - LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:GFX:PVGA1A:Write to illegal index %2X", reg); + LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:GFX:PVGA1A:Write to illegal index %2" sBitfs(X), reg); break; } } @@ -129,7 +129,7 @@ Bitu read_p3cf_pvga1a(Bitu reg,Bitu /*iolen*/) { case 0x0f: return pvga1a.PR5; default: - LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:GFX:PVGA1A:Read from illegal index %2X", reg); + LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:GFX:PVGA1A:Read from illegal index %2" sBitfs(X), reg); break; } @@ -139,7 +139,7 @@ Bitu read_p3cf_pvga1a(Bitu reg,Bitu /*iolen*/) { void FinishSetMode_PVGA1A(Bitu /*crtc_base*/, VGA_ModeExtraData* modeData) { pvga1a.biosMode = modeData->modeNo; -// Reset to single bank and set it to 0. May need to unlock first (DPaint locks on exit) + // Reset to single bank and set it to 0. May need to unlock first (DPaint locks on exit) IO_Write(0x3ce, 0x0f); Bitu oldlock = IO_Read(0x3cf); IO_Write(0x3cf, 0x05); diff --git a/src/hardware/vga_tseng.cpp b/src/hardware/vga_tseng.cpp index 368f92484..344eece96 100644 --- a/src/hardware/vga_tseng.cpp +++ b/src/hardware/vga_tseng.cpp @@ -24,6 +24,7 @@ #include "inout.h" #include "mem.h" #include + // Tseng ET4K data typedef struct { Bit8u extensionsEnabled; @@ -171,7 +172,7 @@ void write_p3d5_et4k(Bitu reg,Bitu val,Bitu /*iolen*/) { } else vga.s3.ex_hor_overflow=(val&0x15); break; default: - LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:CRTC:ET4K:Write to illegal index %2X", reg); + LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:CRTC:ET4K:Write to illegal index %2" sBitfs(X), reg); break; } } @@ -189,7 +190,7 @@ Bitu read_p3d5_et4k(Bitu reg,Bitu /*iolen*/) { RESTORE_ET4K(3d4, 37); RESTORE_ET4K(3d4, 3f); default: - LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:CRTC:ET4K:Read from illegal index %2X", reg); + LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:CRTC:ET4K:Read from illegal index %2" sBitfs(X), reg); break; } return 0x0; @@ -212,7 +213,7 @@ void write_p3c5_et4k(Bitu reg,Bitu val,Bitu /*iolen*/) { // Unlikely to be used by games (things like ROM enable/disable and emulation of VGA vs EGA) STORE_ET4K(3c4, 07); default: - LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:SEQ:ET4K:Write to illegal index %2X", reg); + LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:SEQ:ET4K:Write to illegal index %2" sBitfs(X), reg); break; } } @@ -222,7 +223,7 @@ Bitu read_p3c5_et4k(Bitu reg,Bitu /*iolen*/) { RESTORE_ET4K(3c4, 06); RESTORE_ET4K(3c4, 07); default: - LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:SEQ:ET4K:Read from illegal index %2X", reg); + LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:SEQ:ET4K:Read from illegal index %2" sBitfs(X), reg); break; } return 0x0; @@ -275,7 +276,7 @@ void write_p3c0_et4k(Bitu reg,Bitu val,Bitu /*iolen*/) { // TODO: Figure out if this has any practical use STORE_ET4K(3c0, 17); default: - LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:ATTR:ET4K:Write to illegal index %2X", reg); + LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:ATTR:ET4K:Write to illegal index %2" sBitfs(X), reg); break; } } @@ -285,7 +286,7 @@ Bitu read_p3c1_et4k(Bitu reg,Bitu /*iolen*/) { RESTORE_ET4K(3c0, 16); RESTORE_ET4K(3c0, 17); default: - LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:ATTR:ET4K:Read from illegal index %2X", reg); + LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:ATTR:ET4K:Read from illegal index %2" sBitfs(X), reg); break; } return 0x0; @@ -572,7 +573,7 @@ void write_p3d5_et3k(Bitu reg,Bitu val,Bitu /*iolen*/) { break; default: - LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:CRTC:ET3K:Write to illegal index %2X", reg); + LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:CRTC:ET3K:Write to illegal index %2" sBitfs(X), reg); break; } } @@ -590,7 +591,7 @@ Bitu read_p3d5_et3k(Bitu reg,Bitu /*iolen*/) { RESTORE_ET3K(3d4, 24); RESTORE_ET3K(3d4, 25); default: - LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:CRTC:ET3K:Read from illegal index %2X", reg); + LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:CRTC:ET3K:Read from illegal index %2" sBitfs(X), reg); break; } return 0x0; @@ -603,7 +604,7 @@ void write_p3c5_et3k(Bitu reg,Bitu val,Bitu /*iolen*/) { STORE_ET3K(3c4, 06); STORE_ET3K(3c4, 07); default: - LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:SEQ:ET3K:Write to illegal index %2X", reg); + LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:SEQ:ET3K:Write to illegal index %2" sBitfs(X), reg); break; } } @@ -613,7 +614,7 @@ Bitu read_p3c5_et3k(Bitu reg,Bitu /*iolen*/) { RESTORE_ET3K(3c4, 06); RESTORE_ET3K(3c4, 07); default: - LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:SEQ:ET3K:Read from illegal index %2X", reg); + LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:SEQ:ET3K:Read from illegal index %2" sBitfs(X), reg); break; } return 0x0; @@ -646,7 +647,7 @@ void write_p3c0_et3k(Bitu reg,Bitu val,Bitu /*iolen*/) { STORE_ET3K(3c0, 16); STORE_ET3K(3c0, 17); default: - LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:ATTR:ET3K:Write to illegal index %2X", reg); + LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:ATTR:ET3K:Write to illegal index %2" sBitfs(X), reg); break; } } @@ -656,7 +657,7 @@ Bitu read_p3c1_et3k(Bitu reg,Bitu /*iolen*/) { RESTORE_ET3K(3c0, 16); RESTORE_ET3K(3c0, 17); default: - LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:ATTR:ET3K:Read from illegal index %2X", reg); + LOG(LOG_VGAMISC,LOG_NORMAL)("VGA:ATTR:ET3K:Read from illegal index %2" sBitfs(X), reg); break; } return 0x0; diff --git a/src/misc/setup.cpp b/src/misc/setup.cpp index d2145ad43..a8443a19f 100644 --- a/src/misc/setup.cpp +++ b/src/misc/setup.cpp @@ -745,8 +745,10 @@ string Section_line::GetPropValue(string const& /* _property*/) const { } #ifdef C_DBP_ENABLE_CONFIG_PROGRAM +#define HELPLINE_SIZE 256 bool Config::PrintConfig(char const * const configfilename) const { - char temp[50];char helpline[256]; + char temp[50]; + char helpline[HELPLINE_SIZE] = {0}; FILE* outfile = fopen(configfilename,"w+t"); if (outfile == NULL) return false; @@ -801,7 +803,7 @@ bool Config::PrintConfig(char const * const configfilename) const { const char * helpstr = MSG_Get(temp); const char * linestart = helpstr; char * helpwrite = helpline; - while (*helpstr && helpstr - linestart < sizeof(helpline)) { + while (*helpstr && helpstr - linestart < HELPLINE_SIZE - 2) { *helpwrite++ = *helpstr; if (*helpstr == '\n') { *helpwrite = 0; From ef4331b48e17f5fe70aa2756a1b01e4ab17ba2e7 Mon Sep 17 00:00:00 2001 From: Bernhard Schelling <14200249+schellingb@users.noreply.github.com> Date: Thu, 11 Mar 2021 01:34:10 +0900 Subject: [PATCH 06/58] sync libretro-common updates --- libretro-common/compat/fopen_utf8.c | 11 +- libretro-common/encodings/encoding_utf.c | 122 ++++++++++++----------- libretro-common/include/encodings/utf.h | 2 +- 3 files changed, 71 insertions(+), 64 deletions(-) diff --git a/libretro-common/compat/fopen_utf8.c b/libretro-common/compat/fopen_utf8.c index 87c0157a8..337ddc27c 100644 --- a/libretro-common/compat/fopen_utf8.c +++ b/libretro-common/compat/fopen_utf8.c @@ -49,9 +49,14 @@ void *fopen_utf8(const char * filename, const char * mode) #else wchar_t * filename_w = utf8_to_utf16_string_alloc(filename); wchar_t * mode_w = utf8_to_utf16_string_alloc(mode); - FILE* ret = _wfopen(filename_w, mode_w); - free(filename_w); - free(mode_w); + FILE* ret = NULL; + + if (filename_w && mode_w) + ret = _wfopen(filename_w, mode_w); + if (filename_w) + free(filename_w); + if (mode_w) + free(mode_w); return ret; #endif } diff --git a/libretro-common/encodings/encoding_utf.c b/libretro-common/encodings/encoding_utf.c index 884c40ead..b0bd1a223 100644 --- a/libretro-common/encodings/encoding_utf.c +++ b/libretro-common/encodings/encoding_utf.c @@ -37,6 +37,8 @@ #include #endif +#define UTF8_WALKBYTE(string) (*((*(string))++)) + static unsigned leading_ones(uint8_t c) { unsigned ones = 0; @@ -89,13 +91,14 @@ size_t utf8_conv_utf32(uint32_t *out, size_t out_chars, bool utf16_conv_utf8(uint8_t *out, size_t *out_chars, const uint16_t *in, size_t in_size) { - static uint8_t kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; - size_t out_pos = 0; - size_t in_pos = 0; + size_t out_pos = 0; + size_t in_pos = 0; + static const + uint8_t utf8_limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; for (;;) { - unsigned numAdds; + unsigned num_adds; uint32_t value; if (in_pos == in_size) @@ -124,21 +127,21 @@ bool utf16_conv_utf8(uint8_t *out, size_t *out_chars, value = (((value - 0xD800) << 10) | (c2 - 0xDC00)) + 0x10000; } - for (numAdds = 1; numAdds < 5; numAdds++) - if (value < (((uint32_t)1) << (numAdds * 5 + 6))) + for (num_adds = 1; num_adds < 5; num_adds++) + if (value < (((uint32_t)1) << (num_adds * 5 + 6))) break; if (out) - out[out_pos] = (char)(kUtf8Limits[numAdds - 1] - + (value >> (6 * numAdds))); + out[out_pos] = (char)(utf8_limits[num_adds - 1] + + (value >> (6 * num_adds))); out_pos++; do { - numAdds--; + num_adds--; if (out) out[out_pos] = (char)(0x80 - + ((value >> (6 * numAdds)) & 0x3F)); + + ((value >> (6 * num_adds)) & 0x3F)); out_pos++; - }while (numAdds != 0); + }while (num_adds != 0); } *out_chars = out_pos; @@ -166,13 +169,15 @@ size_t utf8cpy(char *d, size_t d_len, const char *s, size_t chars) while (*sb && chars-- > 0) { sb++; - while ((*sb & 0xC0) == 0x80) sb++; + while ((*sb & 0xC0) == 0x80) + sb++; } if ((size_t)(sb - sb_org) > d_len-1 /* NUL */) { sb = sb_org + d_len-1; - while ((*sb & 0xC0) == 0x80) sb--; + while ((*sb & 0xC0) == 0x80) + sb--; } memcpy(d, sb_org, sb-sb_org); @@ -184,14 +189,18 @@ size_t utf8cpy(char *d, size_t d_len, const char *s, size_t chars) const char *utf8skip(const char *str, size_t chars) { const uint8_t *strb = (const uint8_t*)str; + if (!chars) return str; + do { strb++; - while ((*strb & 0xC0)==0x80) strb++; + while ((*strb & 0xC0)==0x80) + strb++; chars--; - } while(chars); + }while (chars); + return (const char*)strb; } @@ -211,24 +220,22 @@ size_t utf8len(const char *string) return ret; } -#define utf8_walkbyte(string) (*((*(string))++)) - /* Does not validate the input, returns garbage if it's not UTF-8. */ uint32_t utf8_walk(const char **string) { - uint8_t first = utf8_walkbyte(string); + uint8_t first = UTF8_WALKBYTE(string); uint32_t ret = 0; if (first < 128) return first; - ret = (ret << 6) | (utf8_walkbyte(string) & 0x3F); + ret = (ret << 6) | (UTF8_WALKBYTE(string) & 0x3F); if (first >= 0xE0) { - ret = (ret << 6) | (utf8_walkbyte(string) & 0x3F); + ret = (ret << 6) | (UTF8_WALKBYTE(string) & 0x3F); if (first >= 0xF0) { - ret = (ret << 6) | (utf8_walkbyte(string) & 0x3F); + ret = (ret << 6) | (UTF8_WALKBYTE(string) & 0x3F); return ret | (first & 7) << 18; } return ret | (first & 15) << 12; @@ -277,9 +284,7 @@ bool utf16_to_char_string(const uint16_t *in, char *s, size_t len) static char *mb_to_mb_string_alloc(const char *str, enum CodePage cp_in, enum CodePage cp_out) { - char *path_buf = NULL; wchar_t *path_buf_wide = NULL; - int path_buf_len = 0; int path_buf_wide_len = MultiByteToWideChar(cp_in, 0, str, -1, NULL, 0); /* Windows 95 will return 0 from these functions with @@ -292,54 +297,51 @@ static char *mb_to_mb_string_alloc(const char *str, * MultiByteToWideChar also supports CP_UTF7 and CP_UTF8. */ - if (path_buf_wide_len) + if (!path_buf_wide_len) + return strdup(str); + + path_buf_wide = (wchar_t*) + calloc(path_buf_wide_len + sizeof(wchar_t), sizeof(wchar_t)); + + if (path_buf_wide) { - path_buf_wide = (wchar_t*) - calloc(path_buf_wide_len + sizeof(wchar_t), sizeof(wchar_t)); + MultiByteToWideChar(cp_in, 0, + str, -1, path_buf_wide, path_buf_wide_len); - if (path_buf_wide) + if (*path_buf_wide) { - MultiByteToWideChar(cp_in, 0, - str, -1, path_buf_wide, path_buf_wide_len); + int path_buf_len = WideCharToMultiByte(cp_out, 0, + path_buf_wide, -1, NULL, 0, NULL, NULL); - if (*path_buf_wide) + if (path_buf_len) { - path_buf_len = WideCharToMultiByte(cp_out, 0, - path_buf_wide, -1, NULL, 0, NULL, NULL); + char *path_buf = (char*) + calloc(path_buf_len + sizeof(char), sizeof(char)); - if (path_buf_len) + if (path_buf) { - path_buf = (char*) - calloc(path_buf_len + sizeof(char), sizeof(char)); + WideCharToMultiByte(cp_out, 0, + path_buf_wide, -1, path_buf, + path_buf_len, NULL, NULL); - if (path_buf) - { - WideCharToMultiByte(cp_out, 0, - path_buf_wide, -1, path_buf, - path_buf_len, NULL, NULL); - - free(path_buf_wide); + free(path_buf_wide); - if (*path_buf) - return path_buf; + if (*path_buf) + return path_buf; - free(path_buf); - return NULL; - } - } - else - { - free(path_buf_wide); - return strdup(str); + free(path_buf); + return NULL; } } + else + { + free(path_buf_wide); + return strdup(str); + } } - } - else - return strdup(str); - if (path_buf_wide) free(path_buf_wide); + } return NULL; } @@ -379,13 +381,13 @@ char* local_to_utf8_string_alloc(const char *str) wchar_t* utf8_to_utf16_string_alloc(const char *str) { #ifdef _WIN32 - int len = 0; - int out_len = 0; + int len = 0; + int out_len = 0; #else - size_t len = 0; + size_t len = 0; size_t out_len = 0; #endif - wchar_t *buf = NULL; + wchar_t *buf = NULL; if (!str || !*str) return NULL; diff --git a/libretro-common/include/encodings/utf.h b/libretro-common/include/encodings/utf.h index a040c711d..27033fffe 100644 --- a/libretro-common/include/encodings/utf.h +++ b/libretro-common/include/encodings/utf.h @@ -35,7 +35,7 @@ RETRO_BEGIN_DECLS enum CodePage { CODEPAGE_LOCAL = 0, /* CP_ACP */ - CODEPAGE_UTF8 = 65001 /* CP_UTF8 */ + CODEPAGE_UTF8 = 65001 /* CP_UTF8 */ }; size_t utf8_conv_utf32(uint32_t *out, size_t out_chars, From cc56814eec9840807f754f8106795f553a645dcf Mon Sep 17 00:00:00 2001 From: Bernhard Schelling <14200249+schellingb@users.noreply.github.com> Date: Thu, 11 Mar 2021 01:35:13 +0900 Subject: [PATCH 07/58] Enable console platforms --- .gitlab-ci.yml | 82 +++++++++++++++++++++++++------------------------- Makefile | 6 +++- 2 files changed, 46 insertions(+), 42 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8430414fa..dbc8ed9aa 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -38,28 +38,28 @@ include: - project: 'libretro-infrastructure/ci-templates' file: '/android-jni.yml' -# ################################## CONSOLES ################################ -# # Nintendo 3DS -# - project: 'libretro-infrastructure/ci-templates' -# file: '/ctr-static.yml' -# -# # Nintendo WiiU -# - project: 'libretro-infrastructure/ci-templates' -# file: '/wiiu-static.yml' -# -# # Nintendo Switch -# - project: 'libretro-infrastructure/ci-templates' -# file: '/libnx-static.yml' -# -# # PlayStation Vita -# - project: 'libretro-infrastructure/ci-templates' -# file: '/vita-static.yml' + ################################## CONSOLES ################################ + # Nintendo 3DS + - project: 'libretro-infrastructure/ci-templates' + file: '/ctr-static.yml' + + # Nintendo WiiU + - project: 'libretro-infrastructure/ci-templates' + file: '/wiiu-static.yml' + + # Nintendo Switch + - project: 'libretro-infrastructure/ci-templates' + file: '/libnx-static.yml' + + # PlayStation Vita + - project: 'libretro-infrastructure/ci-templates' + file: '/vita-static.yml' # Stages for building stages: - build-prepare - build-shared -# - build-static + - build-static ############################################################################## #################################### STAGES ################################## @@ -127,27 +127,27 @@ android-x86: - .libretro-android-jni-x86 - .core-defs -#################################### CONSOLES ################################# -## Nintendo 3DS -#libretro-build-ctr: -# extends: -# - .libretro-ctr-static-retroarch-master -# - .core-defs -# -## Nintendo WiiU -#libretro-build-wiiu: -# extends: -# - .libretro-wiiu-static-retroarch-master -# - .core-defs -# -## Nintendo Switch -#libretro-build-libnx-aarch64: -# extends: -# - .libretro-libnx-static-retroarch-master -# - .core-defs -# -## PlayStation Vita -#libretro-build-vita: -# extends: -# - .libretro-vita-static-retroarch-master -# - .core-defs +################################### CONSOLES ################################# +# Nintendo 3DS +libretro-build-ctr: + extends: + - .libretro-ctr-static-retroarch-master + - .core-defs + +# Nintendo WiiU +libretro-build-wiiu: + extends: + - .libretro-wiiu-static-retroarch-master + - .core-defs + +# Nintendo Switch +libretro-build-libnx-aarch64: + extends: + - .libretro-libnx-static-retroarch-master + - .core-defs + +# PlayStation Vita +libretro-build-vita: + extends: + - .libretro-vita-static-retroarch-master + - .core-defs diff --git a/Makefile b/Makefile index d86338917..8a2f36016 100644 --- a/Makefile +++ b/Makefile @@ -37,10 +37,12 @@ ifneq ($(ISWIN),) OUTNAME := dosbox_pure_libretro.dll CXX ?= g++ LDFLAGS := -Wl,--gc-sections -fno-ident + COMMONFLAGS += -pthread else ifneq ($(ISMAC),) OUTNAME := dosbox_pure_libretro.dylib CXX ?= clang++ LDFLAGS := -Wl,-dead_strip + COMMONFLAGS += -pthread else ifeq ($(platform),vita) OUTNAME := dosbox_pure_libretro_vita.a CXX := arm-vita-eabi-g++ @@ -92,10 +94,12 @@ else ifeq ($(platform), gcw0) CXX := /opt/gcw0-toolchain/usr/bin/mipsel-linux-g++ LDFLAGS := -Wl,--gc-sections -fno-ident CPUFLAGS := -ffast-math -march=mips32r2 -mtune=mips32r2 -mhard-float -fexpensive-optimizations -frename-registers + COMMONFLAGS += -pthread else OUTNAME := dosbox_pure_libretro.so CXX ?= g++ LDFLAGS := -Wl,--gc-sections -fno-ident + COMMONFLAGS += -pthread # ARM optimizations PROCCPU := $(shell cat /proc/cpuinfo)) ifneq ($(and $(filter ARMv7,$(PROCCPU)),$(filter neon,$(PROCCPU))),) @@ -144,7 +148,7 @@ endif CFLAGS += $(CPUFLAGS) -std=c++11 -fpic -fomit-frame-pointer -fno-exceptions -fno-non-call-exceptions -Wno-address-of-packed-member -Wno-format -Wno-switch CFLAGS += -fvisibility=hidden -ffunction-sections -CFLAGS += -pthread -D__LIBRETRO__ -Iinclude +CFLAGS += -D__LIBRETRO__ -Iinclude CFLAGS += $(COMMONFLAGS) #CFLAGS += -fdata-sections #saves around 32 bytes on most platforms but wrongfully adds up to 60MB on msys2 From 5633a4be6fc3e358d4ba02f0918c58ba9fef4801 Mon Sep 17 00:00:00 2001 From: Bernhard Schelling <14200249+schellingb@users.noreply.github.com> Date: Thu, 11 Mar 2021 03:58:32 +0900 Subject: [PATCH 08/58] Change language standard c++11 to gnu++11 On some platforms required for strdup in encoding_utf.c --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8a2f36016..f35b886ad 100644 --- a/Makefile +++ b/Makefile @@ -146,7 +146,7 @@ else LDFLAGS += -O2 endif -CFLAGS += $(CPUFLAGS) -std=c++11 -fpic -fomit-frame-pointer -fno-exceptions -fno-non-call-exceptions -Wno-address-of-packed-member -Wno-format -Wno-switch +CFLAGS += $(CPUFLAGS) -std=gnu++11 -fpic -fomit-frame-pointer -fno-exceptions -fno-non-call-exceptions -Wno-address-of-packed-member -Wno-format -Wno-switch CFLAGS += -fvisibility=hidden -ffunction-sections CFLAGS += -D__LIBRETRO__ -Iinclude CFLAGS += $(COMMONFLAGS) From a4cf92929e96861fb64168f892c4e57c8e523925 Mon Sep 17 00:00:00 2001 From: Bernhard Schelling <14200249+schellingb@users.noreply.github.com> Date: Thu, 11 Mar 2021 04:38:34 +0900 Subject: [PATCH 09/58] Add nxmmap --- src/cpu/dyn_cache.h | 50 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/src/cpu/dyn_cache.h b/src/cpu/dyn_cache.h index 52cbfe283..129a6f661 100644 --- a/src/cpu/dyn_cache.h +++ b/src/cpu/dyn_cache.h @@ -16,10 +16,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifdef HAVE_LIBNX -#include "../../../switch/mman.h" -#endif - #ifdef VITA #include static int sceBlock; @@ -31,6 +27,48 @@ int _newlib_vm_size_user = 0x1000000; extern "C" int getVMBlock(); #endif +#ifdef HAVE_LIBNX +#include +#include +#include +static Jit dynarec_jit; +static u_char *jit_dynrec; +static void *jit_rx_addr, *jit_rw_addr, *jit_rw_buffer, *jit_old_addr; +static size_t jit_len; +static bool jit_is_executable; +extern char __start__; +static inline void *nxmmap(void *addr, size_t len) +{ + jit_len = len; + if (R_SUCCEEDED(jitCreate(&dynarec_jit, jit_len))) + { + jit_len = dynarec_jit.size; + jit_rw_buffer = malloc(jit_len); + jit_rx_addr = (void*)(&__start__ - 0x1000 - jit_len); + jit_old_addr = dynarec_jit.rx_addr; + dynarec_jit.rx_addr = jit_rx_addr; + jit_rw_addr = jitGetRwAddr(&dynarec_jit); + jit_dynrec = (u_char*)jit_rw_addr; + printf("Jit Initialized: RX %p, RW %p\n", jit_rx_addr, jit_rw_addr); + jitTransitionToExecutable(&dynarec_jit); + jit_is_executable = true; + return jit_rx_addr; + } + printf("Jit failed!\n"); + return (void*)-1; +} +static inline int nxmunmap(void *addr, size_t) +{ + jitTransitionToWritable(&dynarec_jit); + if(jit_old_addr != 0) dynarec_jit.rx_addr = jit_old_addr; + jit_old_addr = 0; + jitClose(&dynarec_jit); + free(jit_rw_buffer); + jit_rw_buffer = 0; + return 0; +} +#endif + class CodePageHandlerDynRec; // forward // basic cache block representation @@ -672,7 +710,7 @@ static void cache_init(bool enable) { if (!cache_code_start_ptr) cache_code_start_ptr=(Bit8u*)malloc(CACHE_TOTAL+CACHE_MAXSIZE+PAGESIZE_TEMP-1+PAGESIZE_TEMP); #elif defined (HAVE_LIBNX) - cache_code_start_ptr=(Bit8u*)mmap(NULL, CACHE_TOTAL+CACHE_MAXSIZE+PAGESIZE_TEMP-1+PAGESIZE_TEMP, 0, 0, 0, 0); + cache_code_start_ptr=(Bit8u*)nxmmap(NULL, CACHE_TOTAL+CACHE_MAXSIZE+PAGESIZE_TEMP-1+PAGESIZE_TEMP); #elif defined (VITA) sceBlock = getVMBlock(); if (sceBlock >= 0) { @@ -752,7 +790,7 @@ static void cache_close(void) { if (!VirtualFree(cache_code_start_ptr, 0, MEM_RELEASE)) free(cache_code_start_ptr); #elif defined (HAVE_LIBNX) - munmap(cache_code_start_ptr, CACHE_TOTAL+CACHE_MAXSIZE+PAGESIZE_TEMP-1+PAGESIZE_TEMP); + nxmunmap(cache_code_start_ptr, CACHE_TOTAL+CACHE_MAXSIZE+PAGESIZE_TEMP-1+PAGESIZE_TEMP); #elif defined (VITA) sceKernelFreeMemBlock(sceBlock) sceBlock = 0; From ab2c592c459e5a2b9deb2003dc0ab64a8a56a6ac Mon Sep 17 00:00:00 2001 From: Bernhard Schelling <14200249+schellingb@users.noreply.github.com> Date: Thu, 11 Mar 2021 04:38:49 +0900 Subject: [PATCH 10/58] Use retro_sleep from retro_timers.h --- dosbox_pure_libretro.cpp | 4 +- libretro-common/include/retro_timers.h | 103 +++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 libretro-common/include/retro_timers.h diff --git a/dosbox_pure_libretro.cpp b/dosbox_pure_libretro.cpp index 076ca65b5..700446e25 100644 --- a/dosbox_pure_libretro.cpp +++ b/dosbox_pure_libretro.cpp @@ -52,14 +52,14 @@ #define THREAD_CC WINAPI struct Thread { typedef DWORD RET_t; typedef RET_t (THREAD_CC *FUNC_t)(LPVOID); static void StartDetached(FUNC_t f, void* p = NULL) { HANDLE h = CreateThread(0,0,f,p,0,0); CloseHandle(h); } }; struct Mutex { Mutex() : h(CreateMutexA(0,0,0)) {} ~Mutex() { CloseHandle(h); } __inline void Lock() { WaitForSingleObject(h,INFINITE); } __inline void Unlock() { ReleaseMutex(h); } private:HANDLE h;Mutex(const Mutex&);Mutex& operator=(const Mutex&);}; -static INLINE void sleep_ms(Bit32u ms) { Sleep(ms); } #else #include #define THREAD_CC struct Thread { typedef void* RET_t; typedef RET_t (THREAD_CC *FUNC_t)(void*); static void StartDetached(FUNC_t f, void* p = NULL) { pthread_t h = 0; pthread_create(&h, NULL, f, p); } }; struct Mutex { Mutex() { pthread_mutex_init(&h,0); } ~Mutex() { pthread_mutex_destroy(&h); } __inline void Lock() { pthread_mutex_lock(&h); } __inline void Unlock() { pthread_mutex_unlock(&h); } private:pthread_mutex_t h;Mutex(const Mutex&);Mutex& operator=(const Mutex&);}; -static void sleep_ms(Bit32u ms) { timespec req, rem; req.tv_sec = ms / 1000; req.tv_nsec = (ms % 1000) * 1000000ULL; while (nanosleep(&req, &rem)) req = rem; } #endif +#include "libretro-common/include/retro_timers.h" +static INLINE void sleep_ms(Bit32u ms) { retro_sleep(ms); } #endif // RETROARCH AUDIO/VIDEO diff --git a/libretro-common/include/retro_timers.h b/libretro-common/include/retro_timers.h new file mode 100644 index 000000000..6fd098035 --- /dev/null +++ b/libretro-common/include/retro_timers.h @@ -0,0 +1,103 @@ +/* Copyright (C) 2010-2020 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (retro_timers.h). + * --------------------------------------------------------------------------------------- + * + * Permission is hereby granted, free of charge, + * to any person obtaining a copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef __LIBRETRO_COMMON_TIMERS_H +#define __LIBRETRO_COMMON_TIMERS_H + +#if defined(XENON) +#include