Skip to content

Commit

Permalink
Merge branch 'master' into libretro
Browse files Browse the repository at this point in the history
  • Loading branch information
notaz committed Jan 25, 2025
2 parents cf0cd7c + 16b099b commit 0f620d5
Show file tree
Hide file tree
Showing 37 changed files with 903 additions and 595 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/ci-libretro.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI (libretro)
on: [push, pull_request]
jobs:
build-libretro:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: make
run: make -j$(getconf _NPROCESSORS_ONLN) -f Makefile.libretro

build-libretro-win32:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Install dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -y gcc-mingw-w64
- name: make
run: make -j$(getconf _NPROCESSORS_ONLN) -f Makefile.libretro platform=win32 CC=x86_64-w64-mingw32-gcc

build-libretro-android:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: ndk-build
run: ${ANDROID_NDK_HOME}/ndk-build -j$(getconf _NPROCESSORS_ONLN) --no-print-directory -C jni/
4 changes: 2 additions & 2 deletions .github/workflows/ci-linux-arm64.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: CI (Linux arm64)
on: [push, pull_request]
jobs:
build-linux:
build-linux-arm64:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
Expand All @@ -19,4 +19,4 @@ jobs:
- name: configure
run: DUMP_CONFIG_LOG=1 CROSS_COMPILE=aarch64-linux-gnu- SDL_CONFIG=usr/bin/sdl-config PATH=$PATH:usr/bin CFLAGS='-Iusr/include/ -Iusr/include/SDL' LDFLAGS='-Lusr/lib/aarch64-linux-gnu/ -Llib/aarch64-linux-gnu/ -Wl,-rpath-link=lib/aarch64-linux-gnu/,-rpath-link=usr/lib/aarch64-linux-gnu/,-rpath-link=usr/lib/aarch64-linux-gnu/pulseaudio/' ./configure
- name: make
run: make
run: make -j$(getconf _NPROCESSORS_ONLN)
4 changes: 2 additions & 2 deletions .github/workflows/ci-linux-armhf.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: CI (Linux armhf)
on: [push, pull_request]
jobs:
build-linux:
build-linux-armhf:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
Expand All @@ -19,4 +19,4 @@ jobs:
- name: configure
run: DUMP_CONFIG_LOG=1 CROSS_COMPILE=arm-linux-gnueabihf- SDL_CONFIG=usr/bin/sdl-config PATH=$PATH:usr/bin CFLAGS='-Iusr/include/ -Iusr/include/SDL' LDFLAGS='-Lusr/lib/arm-linux-gnueabihf/ -Llib/arm-linux-gnueabihf/ -Wl,-rpath-link=lib/arm-linux-gnueabihf/,-rpath-link=usr/lib/arm-linux-gnueabihf/,-rpath-link=usr/lib/arm-linux-gnueabihf/pulseaudio/' ./configure
- name: make
run: make
run: make -j$(getconf _NPROCESSORS_ONLN)
2 changes: 1 addition & 1 deletion .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
- name: configure
run: DUMP_CONFIG_LOG=1 ./configure
- name: make
run: make
run: make -j$(getconf _NPROCESSORS_ONLN)
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,23 @@ endif
ifeq "$(DYNAREC)" "lightrec"
CFLAGS += -Ideps/lightning/include -Ideps/lightrec -Iinclude/lightning -Iinclude/lightrec \
-DLIGHTREC -DLIGHTREC_STATIC
ifeq ($(LIGHTREC_DEBUG),1)
deps/lightrec/%.o: CFLAGS += -DLOG_LEVEL=DEBUG_L
libpcsxcore/lightrec/plugin.o: CFLAGS += -DLIGHTREC_DEBUG=1
frontend/main.o: CFLAGS += -DLIGHTREC_DEBUG=1
deps/lightning/%.o: CFLAGS += -DDISASSEMBLER=1 -DBINUTILS_2_38=1 -DBINUTILS_2_29=1 \
-DHAVE_DISASSEMBLE_INIT_FOR_TARGET=1 -DPACKAGE_VERSION=1
LDFLAGS += -lopcodes -lbfd
endif
LIGHTREC_CUSTOM_MAP ?= 0
LIGHTREC_CUSTOM_MAP_OBJ ?= libpcsxcore/lightrec/mem.o
LIGHTREC_THREADED_COMPILER ?= 0
LIGHTREC_CODE_INV ?= 0
CFLAGS += -DLIGHTREC_CUSTOM_MAP=$(LIGHTREC_CUSTOM_MAP) \
-DLIGHTREC_CODE_INV=$(LIGHTREC_CODE_INV) \
-DLIGHTREC_ENABLE_THREADED_COMPILER=$(LIGHTREC_THREADED_COMPILER)
-DLIGHTREC_ENABLE_THREADED_COMPILER=$(LIGHTREC_THREADED_COMPILER) \
-DLIGHTREC_ENABLE_DISASSEMBLER=$(or $(LIGHTREC_DEBUG),0) \
-DLIGHTREC_NO_DEBUG=$(if $(LIGHTREC_DEBUG),0,1)
ifeq ($(LIGHTREC_CUSTOM_MAP),1)
LDLIBS += -lrt
OBJS += $(LIGHTREC_CUSTOM_MAP_OBJ)
Expand Down
1 change: 0 additions & 1 deletion frontend/libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -2311,7 +2311,6 @@ static void update_variables(bool in_flight)
prev_cpu->Notify(R3000ACPU_NOTIFY_BEFORE_SAVE, NULL);
prev_cpu->Shutdown();
psxCpu->Init();
psxCpu->Reset();
psxCpu->Notify(R3000ACPU_NOTIFY_AFTER_LOAD, NULL);
}
}
Expand Down
2 changes: 2 additions & 0 deletions frontend/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,9 @@ int main(int argc, char *argv[])
else
menu_loop();

#ifndef LIGHTREC_DEBUG
pl_start_watchdog();
#endif

while (!g_emu_want_quit)
{
Expand Down
2 changes: 1 addition & 1 deletion frontend/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ static const struct {
CE_CONFIG_VAL(FractionalFramerate),
CE_CONFIG_VAL(PreciseExceptions),
CE_CONFIG_VAL(TurboCD),
CE_CONFIG_VAL(SlowBoot),
CE_INTVAL(region),
CE_INTVAL_V(g_scaler, 3),
CE_INTVAL(g_gamma),
Expand Down Expand Up @@ -2738,7 +2739,6 @@ void menu_prepare_emu(void)
prev_cpu->Notify(R3000ACPU_NOTIFY_BEFORE_SAVE, NULL);
prev_cpu->Shutdown();
psxCpu->Init();
psxCpu->Reset();
psxCpu->Notify(R3000ACPU_NOTIFY_AFTER_LOAD, NULL);
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/plugin_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ static void pl_vout_flip(const void *vram, int stride, int bgr24,

// offset
xoffs = x * pl_vout_scale_w;
doffs = xoffs + y * dstride;
doffs = xoffs + y * pl_vout_scale_h * dstride;

if (dims_changed)
flip_clear_counter = 3;
Expand Down
6 changes: 3 additions & 3 deletions include/lightrec/lightrec-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@

#define ENABLE_THREADED_COMPILER LIGHTREC_ENABLE_THREADED_COMPILER
#define ENABLE_FIRST_PASS 1
#define ENABLE_DISASSEMBLER 0
#define ENABLE_DISASSEMBLER LIGHTREC_ENABLE_DISASSEMBLER
#define ENABLE_CODE_BUFFER 1

#define HAS_DEFAULT_ELM 1

#define OPT_REMOVE_DIV_BY_ZERO_SEQ 1
#define OPT_REPLACE_MEMSET 1
#define OPT_REPLACE_MEMSET LIGHTREC_NO_DEBUG
#define OPT_DETECT_IMPOSSIBLE_BRANCHES 1
#define OPT_HANDLE_LOAD_DELAYS 1
#define OPT_TRANSFORM_OPS 1
#define OPT_LOCAL_BRANCHES 1
#define OPT_SWITCH_DELAY_SLOTS 1
#define OPT_FLAG_IO 1
#define OPT_FLAG_MULT_DIV 1
#define OPT_FLAG_MULT_DIV LIGHTREC_NO_DEBUG
#define OPT_EARLY_UNLOAD 1
#define OPT_PRELOAD_PC 1

Expand Down
9 changes: 6 additions & 3 deletions jni/Android.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

$(shell cd "$(LOCAL_PATH)" && ((git describe --always || echo) | sed -e 's/.*/#define REV "\0"/' > ../frontend/revision.h_))
$(shell cd "$(LOCAL_PATH)" && (diff -q ../frontend/revision.h_ ../frontend/revision.h > /dev/null 2>&1 || cp ../frontend/revision.h_ ../frontend/revision.h))
Expand All @@ -22,6 +23,8 @@ DYNAREC_DIR := $(ROOT_DIR)/libpcsxcore/new_dynarec
DEPS_DIR := $(ROOT_DIR)/deps
LIBRETRO_COMMON := $(DEPS_DIR)/libretro-common
EXTRA_INCLUDES :=
COREFLAGS :=
SOURCES_ASM :=

# core
SOURCES_C := $(CORE_DIR)/cdriso.c \
Expand Down Expand Up @@ -98,7 +101,6 @@ SOURCES_C += \
$(LCHDR_ZSTD)/decompress/zstd_ddict.c \
$(LCHDR_ZSTD)/decompress/zstd_decompress_block.c \
$(LCHDR_ZSTD)/decompress/zstd_decompress.c
SOURCES_ASM :=
EXTRA_INCLUDES += $(LCHDR)/include $(LCHDR_LZMA)/include $(LCHDR_ZSTD)
COREFLAGS += -DHAVE_CHD -DZ7_ST -DZSTD_DISABLE_ASM
ifeq (,$(call gte,$(APP_PLATFORM_LEVEL),18))
Expand Down Expand Up @@ -152,6 +154,8 @@ else
endif
COREFLAGS += -DLIGHTREC_CUSTOM_MAP=$(LIGHTREC_CUSTOM_MAP)
COREFLAGS += -DLIGHTREC_ENABLE_THREADED_COMPILER=$(LIGHTREC_THREADED_COMPILER)
COREFLAGS += -DLIGHTREC_ENABLE_DISASSEMBLER=$(or $(LIGHTREC_DEBUG),0)
COREFLAGS += -DLIGHTREC_NO_DEBUG=$(if $(LIGHTREC_DEBUG),0,1)

ifeq ($(HAVE_ARI64),1)
SOURCES_C += $(DYNAREC_DIR)/new_dynarec.c \
Expand Down Expand Up @@ -245,14 +249,13 @@ ifneq ($(GIT_VERSION)," unknown")
COREFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
endif

include $(CLEAR_VARS)
LOCAL_MODULE := retro
LOCAL_SRC_FILES := $(SOURCES_C) $(SOURCES_ASM)
LOCAL_CFLAGS := $(COREFLAGS)
LOCAL_C_INCLUDES := $(ROOT_DIR)/include
LOCAL_C_INCLUDES += $(DEPS_DIR)/crypto
LOCAL_C_INCLUDES += $(EXTRA_INCLUDES)
LOCAL_LDFLAGS += -Wl,-version-script=$(FRONTEND_DIR)/libretro-version-script
LOCAL_LDFLAGS := -Wl,-version-script=$(FRONTEND_DIR)/libretro-version-script
LOCAL_LDFLAGS += -Wl,--script=$(FRONTEND_DIR)/libretro-extern.T
LOCAL_LDFLAGS += -Wl,--gc-sections
LOCAL_LDLIBS := -lz -llog
Expand Down
23 changes: 17 additions & 6 deletions libpcsxcore/cdrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,18 +580,26 @@ static boolean canDoTurbo(void)

static int cdrSeekTime(unsigned char *target)
{
int diff = msf2sec(cdr.SetSectorPlay) - msf2sec(target);
int seekTime = abs(diff) * (cdReadTime / 2000);
int diff = abs((int)msf2sec(cdr.SetSectorPlay) - (int)msf2sec(target));
int seekTime = diff * (cdReadTime / 2000);
int cyclesSinceRS = psxRegs.cycle - cdr.LastReadSeekCycles;
seekTime = MAX_VALUE(seekTime, 20000);

// sled seek?
if (diff >= 7200)
seekTime = PSXCLK / 7 + diff * 64;
// add *something* as rotation time until the target sector
if (cyclesSinceRS >= cdReadTime)
seekTime += (8 - ((cyclesSinceRS >> 18) & 7)) * (cdReadTime / 2);

// Transformers Beast Wars Transmetals does Setloc(x),SeekL,Setloc(x),ReadN
// and then wants some slack time
if (cdr.DriveState == DRIVESTATE_PAUSED || cyclesSinceRS < cdReadTime *3/2)
seekTime += cdReadTime;

seekTime = MIN_VALUE(seekTime, PSXCLK * 2 / 3);
CDR_LOG("seek: %.2f %.2f (%.2f) st %d di %d\n", (float)seekTime / PSXCLK,
//seekTime = MIN_VALUE(seekTime, PSXCLK * 2 / 3);
CDR_LOG("seek: %02d:%02d:%02d %.2f %.2f (%.2f) st %d di %d\n",
target[0], target[1], target[2], (float)seekTime / PSXCLK,
(float)seekTime / cdReadTime, (float)cyclesSinceRS / cdReadTime,
cdr.DriveState, diff);
return seekTime;
Expand Down Expand Up @@ -663,14 +671,16 @@ static int msfiEq(const u8 *a, const u8 *b)

void cdrPlayReadInterrupt(void)
{
// this works but causes instability for timing sensitive games
#if 0
int hit = cdra_prefetch(cdr.SetSectorPlay[0], cdr.SetSectorPlay[1], cdr.SetSectorPlay[2]);
if (!hit && cdr.PhysCdPropagations < 75/2) {
// this propagates the real cdrom delays to the emulated game
CDRPLAYREAD_INT(cdReadTime / 2, 0);
cdr.PhysCdPropagations++;
return;
}

#endif
cdr.LastReadSeekCycles = psxRegs.cycle;

if (cdr.Reading) {
Expand Down Expand Up @@ -1323,7 +1333,8 @@ static void cdrReadInterruptSetResult(unsigned char result)
cdr.Irq1Pending = result;
// F1 2000 timing hack :(
// compensate for some csum func @80014380 taking too long
psxRegs.intCycle[PSXINT_CDREAD].sCycle += cdReadTime / 10;
if (!cdr.AdpcmActive)
psxRegs.intCycle[PSXINT_CDREAD].sCycle += cdReadTime / 10;
return;
}
SetResultSize(1);
Expand Down
3 changes: 3 additions & 0 deletions libpcsxcore/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ cycle_multiplier_overrides[] =
{ 153, { "SLUS00943" } },
/* Sol Divide: FMV timing */
{ 200, { "SLUS01519", "SCPS45260", "SLPS01463" } },
/* Legend of Legaia - some attack moves lag and cause a/v desync */
{ 160, { "SCUS94254", "SCUS94366", "SCES01752" } },
{ 160, { "SCES01944", "SCES01945", "SCES01946", "SCES01947" } },
};

static const struct
Expand Down
4 changes: 2 additions & 2 deletions libpcsxcore/gte.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ const unsigned char gte_cycletab[64] = {
23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 39,
};

// warning: called by the dynarec
int gteCheckStallRaw(u32 op_cycles, psxRegisters *regs) {
// warning: ari64 drc stores it's negative cycles in gteBusyCycle
static int gteCheckStallRaw(u32 op_cycles, psxRegisters *regs) {
u32 left = regs->gteBusyCycle - regs->cycle;
int stall = 0;

Expand Down
1 change: 0 additions & 1 deletion libpcsxcore/gte.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ struct psxCP2Regs;

extern const unsigned char gte_cycletab[64];

int gteCheckStallRaw(u32 op_cycles, psxRegisters *regs);
void gteCheckStall(u32 op);

u32 MFC2(struct psxCP2Regs *regs, int reg);
Expand Down
Loading

0 comments on commit 0f620d5

Please sign in to comment.