From 980f7a58b47fefd3424bf8d55f6345128dc3774c Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 9 Jul 2023 22:50:47 +0300 Subject: [PATCH] clean up switching between dynarec and interpreter alternative to libretro/pcsx_rearmed#727 --- frontend/libretro.c | 4 +++- frontend/main.c | 2 -- frontend/menu.c | 3 ++- frontend/plugin.c | 1 - libpcsxcore/misc.c | 9 ++++----- libpcsxcore/new_dynarec/emu_if.c | 20 +++++--------------- libpcsxcore/plugins.c | 7 ------- libpcsxcore/plugins.h | 4 ---- libpcsxcore/psxinterpreter.c | 13 ++++++++----- libpcsxcore/r3000a.h | 8 ++++---- 10 files changed, 26 insertions(+), 45 deletions(-) diff --git a/frontend/libretro.c b/frontend/libretro.c index f4b23cdf..84baeda8 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -1966,9 +1966,11 @@ static void update_variables(bool in_flight) psxCpu = (Config.Cpu == CPU_INTERPRETER) ? &psxInt : &psxRec; if (psxCpu != prev_cpu) { + prev_cpu->Notify(R3000ACPU_NOTIFY_BEFORE_SAVE, NULL); prev_cpu->Shutdown(); psxCpu->Init(); - psxCpu->Reset(); // not really a reset.. + psxCpu->Reset(); + psxCpu->Notify(R3000ACPU_NOTIFY_AFTER_LOAD, NULL); } } #endif /* !DRC_DISABLE */ diff --git a/frontend/main.c b/frontend/main.c index e0635ef4..7d140f82 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -889,8 +889,6 @@ static int _OpenPlugins(void) { signal(SIGPIPE, SignalExit); #endif - GPU_clearDynarec(clearDynarec); - ret = CDR_open(); if (ret < 0) { SysMessage(_("Error opening CD-ROM plugin!")); return -1; } ret = SPU_open(); diff --git a/frontend/menu.c b/frontend/menu.c index 3a772d0e..9ca87c60 100644 --- a/frontend/menu.c +++ b/frontend/menu.c @@ -2652,10 +2652,11 @@ void menu_prepare_emu(void) psxCpu = &psxInt; #endif if (psxCpu != prev_cpu) { + prev_cpu->Notify(R3000ACPU_NOTIFY_BEFORE_SAVE, NULL); prev_cpu->Shutdown(); psxCpu->Init(); - // note that this does not really reset, just clears drc caches psxCpu->Reset(); + psxCpu->Notify(R3000ACPU_NOTIFY_AFTER_LOAD, NULL); } menu_sync_config(); diff --git a/frontend/plugin.c b/frontend/plugin.c index 7f3b8a46..d2d3dbab 100644 --- a/frontend/plugin.c +++ b/frontend/plugin.c @@ -187,7 +187,6 @@ static const struct { DIRECT_GPU(GPUgetScreenPic), DIRECT_GPU(GPUshowScreenPic), */ -// DIRECT_GPU(GPUclearDynarec), }; void *plugin_link(enum builtint_plugins_e id, const char *sym) diff --git a/libpcsxcore/misc.c b/libpcsxcore/misc.c index 8010d7a5..d52a931c 100644 --- a/libpcsxcore/misc.c +++ b/libpcsxcore/misc.c @@ -608,7 +608,7 @@ int SaveState(const char *file) { f = SaveFuncs.open(file, "wb"); if (f == NULL) return -1; - new_dyna_before_save(); + psxCpu->Notify(R3000ACPU_NOTIFY_BEFORE_SAVE, NULL); SaveFuncs.write(f, (void *)PcsxHeader, 32); SaveFuncs.write(f, (void *)&SaveVersion, sizeof(u32)); @@ -655,8 +655,6 @@ int SaveState(const char *file) { SaveFuncs.close(f); - new_dyna_after_save(); - return 0; } @@ -685,15 +683,15 @@ int LoadState(const char *file) { if (Config.HLE) psxBiosInit(); - psxCpu->Reset(); SaveFuncs.seek(f, 128 * 96 * 3, SEEK_CUR); - SaveFuncs.read(f, psxM, 0x00200000); SaveFuncs.read(f, psxR, 0x00080000); SaveFuncs.read(f, psxH, 0x00010000); SaveFuncs.read(f, &psxRegs, offsetof(psxRegisters, gteBusyCycle)); psxRegs.gteBusyCycle = psxRegs.cycle; + psxCpu->Notify(R3000ACPU_NOTIFY_AFTER_LOAD, NULL); + if (Config.HLE) psxBiosFreeze(0); @@ -795,6 +793,7 @@ int RecvPcsxInfo() { SysClose(); return -1; } psxCpu->Reset(); + psxCpu->Notify(R3000ACPU_NOTIFY_AFTER_LOAD, NULL); } return 0; diff --git a/libpcsxcore/new_dynarec/emu_if.c b/libpcsxcore/new_dynarec/emu_if.c index aac9f78c..c1dab56d 100644 --- a/libpcsxcore/new_dynarec/emu_if.c +++ b/libpcsxcore/new_dynarec/emu_if.c @@ -120,18 +120,6 @@ void pcsx_mtc0_ds(u32 reg, u32 val) MTC0(&psxRegs, reg, val); } -void new_dyna_before_save(void) -{ - psxRegs.interrupt &= ~(1 << PSXINT_RCNT); // old savestate compat - - // psxRegs.intCycle is always maintained, no need to convert -} - -void new_dyna_after_save(void) -{ - psxRegs.interrupt |= 1 << PSXINT_RCNT; -} - static void new_dyna_restore(void) { int i; @@ -330,7 +318,6 @@ static int ari64_init() static void ari64_reset() { - printf("ari64_reset\n"); new_dyna_pcsx_mem_reset(); new_dynarec_invalidate_all_pages(); new_dyna_restore(); @@ -369,14 +356,17 @@ static void ari64_clear(u32 addr, u32 size) new_dynarec_invalidate_range(addr, addr + size); } -static void ari64_notify(int note, void *data) { +static void ari64_notify(enum R3000Anote note, void *data) { switch (note) { case R3000ACPU_NOTIFY_CACHE_UNISOLATED: case R3000ACPU_NOTIFY_CACHE_ISOLATED: new_dyna_pcsx_mem_isolate(note == R3000ACPU_NOTIFY_CACHE_ISOLATED); break; - default: + case R3000ACPU_NOTIFY_BEFORE_SAVE: + break; + case R3000ACPU_NOTIFY_AFTER_LOAD: + ari64_reset(); break; } } diff --git a/libpcsxcore/plugins.c b/libpcsxcore/plugins.c index c70ed67f..23474f1b 100644 --- a/libpcsxcore/plugins.c +++ b/libpcsxcore/plugins.c @@ -48,7 +48,6 @@ GPUmakeSnapshot GPU_makeSnapshot; GPUfreeze GPU_freeze; GPUgetScreenPic GPU_getScreenPic; GPUshowScreenPic GPU_showScreenPic; -GPUclearDynarec GPU_clearDynarec; GPUvBlank GPU_vBlank; CDRinit CDR_init; @@ -200,7 +199,6 @@ void CALLBACK GPU__makeSnapshot(void) {} void CALLBACK GPU__keypressed(int key) {} long CALLBACK GPU__getScreenPic(unsigned char *pMem) { return -1; } long CALLBACK GPU__showScreenPic(unsigned char *pMem) { return -1; } -void CALLBACK GPU__clearDynarec(void (CALLBACK *callback)(void)) {} void CALLBACK GPU__vBlank(int val) {} #define LoadGpuSym1(dest, name) \ @@ -240,7 +238,6 @@ static int LoadGPUplugin(const char *GPUdll) { LoadGpuSym1(freeze, "GPUfreeze"); LoadGpuSym0(getScreenPic, "GPUgetScreenPic"); LoadGpuSym0(showScreenPic, "GPUshowScreenPic"); - LoadGpuSym0(clearDynarec, "GPUclearDynarec"); LoadGpuSym0(vBlank, "GPUvBlank"); LoadGpuSym0(configure, "GPUconfigure"); LoadGpuSym0(test, "GPUtest"); @@ -696,10 +693,6 @@ static int LoadSIO1plugin(const char *SIO1dll) { #endif -void CALLBACK clearDynarec(void) { - psxCpu->Reset(); -} - int LoadPlugins() { int ret; char Plugin[MAXPATHLEN * 2]; diff --git a/libpcsxcore/plugins.h b/libpcsxcore/plugins.h index c997c611..ced14cff 100644 --- a/libpcsxcore/plugins.h +++ b/libpcsxcore/plugins.h @@ -75,7 +75,6 @@ typedef struct { typedef long (CALLBACK* GPUfreeze)(uint32_t, GPUFreeze_t *); typedef long (CALLBACK* GPUgetScreenPic)(unsigned char *); typedef long (CALLBACK* GPUshowScreenPic)(unsigned char *); -typedef void (CALLBACK* GPUclearDynarec)(void (CALLBACK *callback)(void)); typedef void (CALLBACK* GPUvBlank)(int, int); // GPU function pointers @@ -100,7 +99,6 @@ extern GPUmakeSnapshot GPU_makeSnapshot; extern GPUfreeze GPU_freeze; extern GPUgetScreenPic GPU_getScreenPic; extern GPUshowScreenPic GPU_showScreenPic; -extern GPUclearDynarec GPU_clearDynarec; extern GPUvBlank GPU_vBlank; // CD-ROM Functions @@ -383,8 +381,6 @@ extern SIO1registerCallback SIO1_registerCallback; #endif -void CALLBACK clearDynarec(void); - void SetIsoFile(const char *filename); const char *GetIsoFile(void); boolean UsingIso(void); diff --git a/libpcsxcore/psxinterpreter.c b/libpcsxcore/psxinterpreter.c index 9ece259c..036b062f 100644 --- a/libpcsxcore/psxinterpreter.c +++ b/libpcsxcore/psxinterpreter.c @@ -1078,7 +1078,6 @@ static int intInit() { } static void intReset() { - memset(&ICache, 0xff, sizeof(ICache)); } static inline void execI_(u8 **memRLUT, psxRegisters *regs_) { @@ -1115,11 +1114,15 @@ void intExecuteBlock() { static void intClear(u32 Addr, u32 Size) { } -void intNotify (int note, void *data) { - /* Armored Core won't boot without this */ - if (note == R3000ACPU_NOTIFY_CACHE_ISOLATED) - { +static void intNotify(enum R3000Anote note, void *data) { + switch (note) { + case R3000ACPU_NOTIFY_CACHE_ISOLATED: // Armored Core? + case R3000ACPU_NOTIFY_AFTER_LOAD: memset(&ICache, 0xff, sizeof(ICache)); + break; + case R3000ACPU_NOTIFY_CACHE_UNISOLATED: + case R3000ACPU_NOTIFY_BEFORE_SAVE: + break; } } diff --git a/libpcsxcore/r3000a.h b/libpcsxcore/r3000a.h index 6973afe8..be0e3368 100644 --- a/libpcsxcore/r3000a.h +++ b/libpcsxcore/r3000a.h @@ -29,9 +29,11 @@ extern "C" { #include "psxcounters.h" #include "psxbios.h" -enum { +enum R3000Anote { R3000ACPU_NOTIFY_CACHE_ISOLATED = 0, R3000ACPU_NOTIFY_CACHE_UNISOLATED = 1, + R3000ACPU_NOTIFY_BEFORE_SAVE, + R3000ACPU_NOTIFY_AFTER_LOAD, }; typedef struct { @@ -40,7 +42,7 @@ typedef struct { void (*Execute)(); /* executes up to a break */ void (*ExecuteBlock)(); /* executes up to a jump */ void (*Clear)(u32 Addr, u32 Size); - void (*Notify)(int note, void *data); + void (*Notify)(enum R3000Anote note, void *data); void (*ApplyConfig)(); void (*Shutdown)(); } R3000Acpu; @@ -204,8 +206,6 @@ extern psxRegisters psxRegs; extern u32 event_cycles[PSXINT_COUNT]; extern u32 next_interupt; -void new_dyna_before_save(void); -void new_dyna_after_save(void); void new_dyna_freeze(void *f, int mode); #define new_dyna_set_event_abs(e, abs) { \ -- 2.39.5