From 265afcec7e5017fb8fbced82ad489255af0e2f2c Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 1 Jan 2023 14:25:02 +1000 Subject: [PATCH] x86/microVU: Fix incorrect VI being backed up when uncached Fixes hang going ingame in Gitaroo Man. --- pcsx2/x86/microVU.cpp | 3 ++- pcsx2/x86/microVU_IR.h | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pcsx2/x86/microVU.cpp b/pcsx2/x86/microVU.cpp index fad13c1b8b..e8b5a9b082 100644 --- a/pcsx2/x86/microVU.cpp +++ b/pcsx2/x86/microVU.cpp @@ -484,6 +484,7 @@ void SaveStateBase::vuJITFreeze() void DumpVUState(u32 n, u32 pc) { const VURegs& r = vuRegs[n]; + const microVU& mVU = (n == 0) ? microVU0 : microVU1; static FILE* fp = nullptr; static bool fp_opened = false; static u32 counter = 0; @@ -509,7 +510,7 @@ void DumpVUState(u32 n, u32 pc) if (fp) { const microVU& m = (n == 0) ? microVU0 : microVU1; - fprintf(fp, "%08d VU%u SPC:%04X xPC:%04X", counter, n, r.start_pc, pc); + fprintf(fp, "%08d VU%u SPC:%04X xPC:%04X BRANCH:%04X VIBACKUP:%04X", counter, n, r.start_pc, pc, mVU.branch, mVU.VIbackup); #if 1 //fprintf(fp, " MEM:%08X", crc32(0, (Bytef*)r.Mem, (n == 0) ? VU0_MEMSIZE : VU1_MEMSIZE)); fprintf(fp, " MAC %08X %08X %08X %08X [%08X %08X %08X %08X]", r.micro_macflags[3], r.micro_macflags[2], r.micro_macflags[1], r.micro_macflags[0], m.macFlag[3], m.macFlag[2], m.macFlag[1], m.macFlag[0]); diff --git a/pcsx2/x86/microVU_IR.h b/pcsx2/x86/microVU_IR.h index 8371e10afd..361c62154b 100644 --- a/pcsx2/x86/microVU_IR.h +++ b/pcsx2/x86/microVU_IR.h @@ -1081,6 +1081,16 @@ public: const xRegister32& gprX = xRegister32::GetInstance(x); writeBackReg(gprX, true); + // Special case: we need to back up the destination register, but it might not have already + // been cached. If so, we need to load the old value from state and back it up. Otherwise, + // it's going to get lost when we eventually write this register back. + if (backup && viLoadReg >= 0 && viWriteReg > 0 && viLoadReg != viWriteReg) + { + xMOVZX(gprX, ptr16[&getVI(viWriteReg)]); + writeVIBackup(gprX); + backup = false; + } + if (viLoadReg > 0) xMOVZX(gprX, ptr16[&getVI(viLoadReg)]); else if (viLoadReg == 0)