From: notaz Date: Sun, 9 Jul 2023 19:50:47 +0000 (+0300) Subject: clean up switching between dynarec and interpreter X-Git-Tag: r24l~317 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=20196899e40390c7f43be2bc02d99c55062c310f;p=pcsx_rearmed.git clean up switching between dynarec and interpreter alternative to libretro/pcsx_rearmed#727 --- diff --git a/frontend/libretro.c b/frontend/libretro.c index 52fc6e3a..fe3b5f10 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 ecfffeb4..3a51bff8 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -894,8 +894,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 eda6ed18..c9949ee0 100644 --- a/frontend/menu.c +++ b/frontend/menu.c @@ -2656,10 +2656,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 a2739858..1eac5798 100644 --- a/frontend/plugin.c +++ b/frontend/plugin.c @@ -229,7 +229,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/lightrec/plugin.c b/libpcsxcore/lightrec/plugin.c index a3eb7763..dd1f40c9 100644 --- a/libpcsxcore/lightrec/plugin.c +++ b/libpcsxcore/lightrec/plugin.c @@ -496,13 +496,8 @@ static void lightrec_plugin_execute(void) { extern int stop; - if (!booting) - lightrec_plugin_sync_regs_from_pcsx(); - while (!stop) lightrec_plugin_execute_internal(false); - - lightrec_plugin_sync_regs_to_pcsx(); } static void lightrec_plugin_execute_block(void) @@ -519,21 +514,24 @@ static void lightrec_plugin_clear(u32 addr, u32 size) lightrec_invalidate(lightrec_state, addr, size * 4); } -static void lightrec_plugin_notify(int note, void *data) +static void lightrec_plugin_sync_regs_to_pcsx(void); +static void lightrec_plugin_sync_regs_from_pcsx(void); + +static void lightrec_plugin_notify(enum R3000Anote note, void *data) { - /* - To change once proper icache emulation is emulated switch (note) { - case R3000ACPU_NOTIFY_CACHE_UNISOLATED: - lightrec_plugin_clear(0, 0x200000/4); - break; - case R3000ACPU_NOTIFY_CACHE_ISOLATED: - // Sent from psxDma3(). - case R3000ACPU_NOTIFY_DMA3_EXE_LOAD: - default: - break; - }*/ + case R3000ACPU_NOTIFY_CACHE_ISOLATED: + case R3000ACPU_NOTIFY_CACHE_UNISOLATED: + /* not used, lightrec calls lightrec_enable_ram() instead */ + break; + case R3000ACPU_NOTIFY_BEFORE_SAVE: + lightrec_plugin_sync_regs_to_pcsx(); + break; + case R3000ACPU_NOTIFY_AFTER_LOAD: + lightrec_plugin_sync_regs_from_pcsx(); + break; + } } static void lightrec_plugin_apply_config() @@ -561,7 +559,7 @@ static void lightrec_plugin_reset(void) regs->cp0[15] = 0x00000002; // PRevID = Revision ID, same as R3000A } -void lightrec_plugin_sync_regs_from_pcsx(void) +static void lightrec_plugin_sync_regs_from_pcsx(void) { struct lightrec_registers *regs; @@ -573,7 +571,7 @@ void lightrec_plugin_sync_regs_from_pcsx(void) lightrec_invalidate_all(lightrec_state); } -void lightrec_plugin_sync_regs_to_pcsx(void) +static void lightrec_plugin_sync_regs_to_pcsx(void) { struct lightrec_registers *regs; diff --git a/libpcsxcore/lightrec/plugin.h b/libpcsxcore/lightrec/plugin.h index 1846c81a..a228a6f0 100644 --- a/libpcsxcore/lightrec/plugin.h +++ b/libpcsxcore/lightrec/plugin.h @@ -9,14 +9,10 @@ #ifdef LIGHTREC #define drc_is_lightrec() 1 -void lightrec_plugin_sync_regs_to_pcsx(void); -void lightrec_plugin_sync_regs_from_pcsx(void); #else /* if !LIGHTREC */ #define drc_is_lightrec() 0 -#define lightrec_plugin_sync_regs_to_pcsx() -#define lightrec_plugin_sync_regs_from_pcsx() #endif diff --git a/libpcsxcore/misc.c b/libpcsxcore/misc.c index 7929dc76..d52a931c 100644 --- a/libpcsxcore/misc.c +++ b/libpcsxcore/misc.c @@ -28,7 +28,6 @@ #include "gpu.h" #include "ppf.h" #include "database.h" -#include "lightrec/plugin.h" #include char CdromId[10] = ""; @@ -609,10 +608,7 @@ int SaveState(const char *file) { f = SaveFuncs.open(file, "wb"); if (f == NULL) return -1; - new_dyna_before_save(); - - if (drc_is_lightrec() && Config.Cpu != CPU_INTERPRETER) - lightrec_plugin_sync_regs_to_pcsx(); + psxCpu->Notify(R3000ACPU_NOTIFY_BEFORE_SAVE, NULL); SaveFuncs.write(f, (void *)PcsxHeader, 32); SaveFuncs.write(f, (void *)&SaveVersion, sizeof(u32)); @@ -659,8 +655,6 @@ int SaveState(const char *file) { SaveFuncs.close(f); - new_dyna_after_save(); - return 0; } @@ -689,18 +683,14 @@ int LoadState(const char *file) { if (Config.HLE) psxBiosInit(); - if (!drc_is_lightrec() || Config.Cpu == CPU_INTERPRETER) - 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; - if (drc_is_lightrec() && Config.Cpu != CPU_INTERPRETER) - lightrec_plugin_sync_regs_from_pcsx(); + psxCpu->Notify(R3000ACPU_NOTIFY_AFTER_LOAD, NULL); if (Config.HLE) psxBiosFreeze(0); @@ -803,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 13ab2972..4f0897e2 100644 --- a/libpcsxcore/plugins.c +++ b/libpcsxcore/plugins.c @@ -49,7 +49,6 @@ GPUmakeSnapshot GPU_makeSnapshot; GPUfreeze GPU_freeze; GPUgetScreenPic GPU_getScreenPic; GPUshowScreenPic GPU_showScreenPic; -GPUclearDynarec GPU_clearDynarec; GPUvBlank GPU_vBlank; CDRinit CDR_init; @@ -201,7 +200,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) \ @@ -241,7 +239,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"); @@ -1120,10 +1117,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) { \