From 273f904d7d250fe0a1709141ade73bd3059e821d Mon Sep 17 00:00:00 2001 From: zanac <21194919+zanac@users.noreply.github.com> Date: Sat, 31 Oct 2026 02:57:04 +0100 Subject: [PATCH] Sega ST-V: driver, VDP1/VDP2 video and SCU from current MAME, optional SH-2 recompiler and threaded video (#2124) - Driver, SCU (DMA, interrupts, timers, DSP), SMPC, MINIT/SINIT, EEPROM and the protection chips as current MAME; the current MAME sets. - VDP1/VDP2 video as current MAME's (one stvvid.c), with exact speedups: partial redraw of the rotation plane cache, rotation copy, sprite passes, window evaluation once per line. - SH-2 recompiler on the bundled sljit (x86, x86-64, ARM32, ARM64; the "SH-2 Dynarec" core option, off by default): blocks with chaining, page tables for direct memory access, memory handlers called from the blocks; the SGL idle loop is skipped exactly; context switch by pointer. Same output as the interpreter on all the sets. - "ST-V Threaded Video" core option (off by default): the screen drawn in strips by 2-4 threads (libretro-common rthreads, where thread-local storage is native), same output. Two more sets of Zen Nippon Pro-Wrestling Featuring Virtua, both on the Taiwan BIOS (the core selects it): - znpwfvt: All Japan Pro-Wrestling Featuring Virtua (Taiwan), as in current MAME. - znpwfve: English translation (bootleg) on the Taiwan program, with the graphics the English mode left in Japanese redrawn; the ROMs are built from the original ones by https://github.com/zanac/znpwfvt Claude-Session: https://claude.ai/code/session_013Vje3pEtpLHubqCGwCgoQX Co-authored-by: Claude Opus 5.5 --- Makefile | 18 + Makefile.common | 8 +- jni/Android.mk | 3 + metadata/mame2003-plus.xml | 1433 ++++- src/cpu/sh2/sh2.c | 257 +- src/cpu/sh2/sh2.h | 11 + src/cpu/sh2/sh2jit.c | 2126 +++++++ src/driver.c | 16 +- src/drivers/stv.c | 2945 +++++---- src/drivers/stvhacks.c | 58 +- src/includes/stv.h | 40 + src/machine/scudsp.c | 18 +- src/machine/scudsp.h | 3 + src/machine/sega315_5838.c | 39 +- src/machine/sega315_5838.h | 7 +- src/machine/sega315_5881.c | 25 + src/machine/sega315_5881.h | 7 + src/mame.h | 5 +- src/mame2003/core_options.c | 100 +- src/mame2003/mame2003.h | 2 + src/sound/scsp.c | 51 +- src/vidhrdw/stvvdp1_vidhrdw.c | 1123 ---- src/vidhrdw/stvvdp2_vidhrdw.c | 3127 ---------- src/vidhrdw/stvvid.c | 10555 ++++++++++++++++++++++++++++++++ 24 files changed, 16280 insertions(+), 5697 deletions(-) create mode 100644 src/cpu/sh2/sh2jit.c create mode 100644 src/includes/stv.h delete mode 100644 src/vidhrdw/stvvdp1_vidhrdw.c delete mode 100644 src/vidhrdw/stvvdp2_vidhrdw.c create mode 100644 src/vidhrdw/stvvid.c diff --git a/Makefile b/Makefile index 90ba4945..8b70c763 100644 --- a/Makefile +++ b/Makefile @@ -872,6 +872,24 @@ ifeq ($(HAVE_ARMv6),1) CFLAGS += -DHAVE_ARMv6 endif +# threads (libretro-common rthreads), as the other libretro cores do (beetle-psx): +# on by default, off where there is no thread library, and on the MSVC builds +# (the ST-V threaded video needs MSVC 2015's thread-local storage, the +# buildbot's MSVC lanes are 2005 and 2010: nothing would use the threads) +HAVE_THREADS ?= 1 +ifneq (,$(filter $(platform), emscripten linux-portable ngc wii wiiu ps2 ps3 psl1ght psp1 ctr vita)) + HAVE_THREADS = 0 +endif +ifneq (,$(findstring msvc,$(platform))) + HAVE_THREADS = 0 +endif +ifeq ($(HAVE_THREADS),1) + # pthreads are in the C library on Darwin and Android, Windows uses its own threads + ifeq (,$(findstring msvc,$(platform))$(findstring android,$(platform))$(findstring ios,$(platform))$(findstring tvos,$(platform))$(filter osx win,$(platform))) + LIBS += -lpthread + endif +endif + # include the various .mak files ifneq (,$(filter $(INCLUDE_DRV),all)) include Makefile.common diff --git a/Makefile.common b/Makefile.common index eda6b7a9..70849af0 100644 --- a/Makefile.common +++ b/Makefile.common @@ -532,7 +532,7 @@ SOURCES_C += \ $(CORE_DIR)/vidhrdw/segavdp.c $(CORE_DIR)/vidhrdw/segac2_vidhrdw.c $(CORE_DIR)/machine/megadriv.c $(CORE_DIR)/drivers/segac2.c $(CORE_DIR)/drivers/megaplay.c $(CORE_DIR)/drivers/megatech.c $(CORE_DIR)/drivers/megadriv_acbl.c $(CORE_DIR)/drivers/megadriv_ybox.c $(CORE_DIR)/drivers/megadriv_sunmix.c \ $(CORE_DIR)/drivers/stv.c $(CORE_DIR)/drivers/stvhacks.c $(CORE_DIR)/machine/stvcd.c \ $(CORE_DIR)/machine/scudsp.c \ - $(CORE_DIR)/vidhrdw/stvvdp1_vidhrdw.c $(CORE_DIR)/vidhrdw/stvvdp2_vidhrdw.c \ + $(CORE_DIR)/vidhrdw/stvvid.c \ $(CORE_DIR)/vidhrdw/deniam_vidhrdw.c $(CORE_DIR)/drivers/deniam.c \ $(CORE_DIR)/machine/btime_machine.c $(CORE_DIR)/vidhrdw/btime_vidhrdw.c $(CORE_DIR)/drivers/btime.c \ $(CORE_DIR)/machine/decocass_machine.c $(CORE_DIR)/vidhrdw/decocass_vidhrdw.c $(CORE_DIR)/drivers/decocass.c \ @@ -2852,6 +2852,12 @@ SOURCES_C += \ # sljit: run-time code generator of the MIPS recompilers (empty where they are not supported) SOURCES_C += $(CORE_DIR)/lib/sljit/sljit_mame.c +# threads (libretro-common rthreads, set by the platform: see Makefile): the ST-V threaded video option +ifeq ($(HAVE_THREADS),1) +COREDEFINES += -DHAVE_THREADS +SOURCES_C += $(LIBRETRO_COMM_DIR)/rthreads/rthreads.c +endif + ifeq ($(STATIC_LINKING),1) else SOURCES_C += \ diff --git a/jni/Android.mk b/jni/Android.mk index 4e65a9b2..3099ed9b 100644 --- a/jni/Android.mk +++ b/jni/Android.mk @@ -3,6 +3,9 @@ LOCAL_PATH := $(call my-dir) ROOT_DIR := $(LOCAL_PATH)/.. CORE_DIR := $(ROOT_DIR)/src +# threads: in bionic's C library +HAVE_THREADS := 1 + include $(ROOT_DIR)/Makefile.common COREFLAGS := $(DEFS) $(COREDEFINES) $(CPUDEFS) $(SOUNDDEFS) $(ASMDEFS) $(DBGDEFS) -ffast-math -funroll-loops -DANDROID -DHAVE_ZLIB $(INCFLAGS) diff --git a/metadata/mame2003-plus.xml b/metadata/mame2003-plus.xml index 1267a0e7..27c0fb1f 100644 --- a/metadata/mame2003-plus.xml +++ b/metadata/mame2003-plus.xml @@ -204980,7 +204980,7 @@ - + @@ -204993,7 +204993,7 @@ -