diff --git a/pcsx2/VUmicro.cpp b/pcsx2/VUmicro.cpp
new file mode 100644
index 0000000000..193fec65f4
--- /dev/null
+++ b/pcsx2/VUmicro.cpp
@@ -0,0 +1,102 @@
+/* PCSX2 - PS2 Emulator for PCs
+ * Copyright (C) 2002-2009 PCSX2 Dev Team
+ *
+ * PCSX2 is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU Lesser General Public License as published by the Free Software Found-
+ * ation, either version 3 of the License, or (at your option) any later version.
+ *
+ * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with PCSX2.
+ * If not, see .
+ */
+
+#include "PrecompiledHeader.h"
+#include "Common.h"
+#include "VUmicro.h"
+
+#define useDeltaTime 1
+
+#if useDeltaTime
+
+// Executes a Block based on EE delta time
+void BaseVUmicroCPU::ExecuteBlock(bool startUp) {
+ const u32& stat = VU0.VI[REG_VPU_STAT].UL;
+ const int test = m_Idx ? 0x100 : 1;
+ const int s = 1024*6; // Kick Start Cycles (Silver Surfer needs this amount)
+ const int c = 1024*1; // Continue Cycles
+ if (!(stat & test)) return;
+ if (startUp) { // Start Executing a microprogram
+ Execute(s); // Kick start VU
+
+ // Let VUs run behind EE instead of ahead
+ if (stat & test) {
+ cpuSetNextBranchDelta((s+c)*2);
+ m_lastEEcycles = cpuRegs.cycle + (s*2);
+ }
+ }
+ else { // Continue Executing (VU roughly half the mhz of EE)
+ s32 delta = (s32)(u32)(cpuRegs.cycle - m_lastEEcycles) & ~1;
+ if (delta > 0) { // Enough time has passed
+ delta >>= 1; // Divide by 2 (unsigned)
+ Execute(delta); // Execute the time since the last call
+ if (stat & test) {
+ cpuSetNextBranchDelta(c*2);
+ m_lastEEcycles = cpuRegs.cycle;
+ }
+ }
+ else cpuSetNextBranchDelta(-delta); // Haven't caught-up from kick start
+ }
+}
+
+// This function is called by VU0 Macro (COP2) after transferring some
+// EE data to VU0's registers. We want to run VU0 Micro right after this
+// to ensure that the register is used at the correct time.
+// This fixes spinning/hanging in some games like Ratchet and Clank's Intro.
+void __fastcall BaseVUmicroCPU::ExecuteBlockJIT(BaseVUmicroCPU* cpu) {
+ const u32& stat = VU0.VI[REG_VPU_STAT].UL;
+ const int test = cpu->m_Idx ? 0x100 : 1;
+ const int c = 1024*1; // VU Execution Cycles
+ if (stat & test) { // VU is running
+ cpu->Execute(c); // Execute VU
+ if (stat & test) {
+ cpu->m_lastEEcycles+=(c*2);
+ cpuSetNextBranchDelta(c*2);
+ }
+ }
+}
+
+#else
+
+// Executes a Block based on static preset cycles
+void BaseVUmicroCPU::ExecuteBlock(bool startUp) {
+ const int vuRunning = m_Idx ? 0x100 : 1;
+ if (!(VU0.VI[REG_VPU_STAT].UL & vuRunning)) return;
+ if (startUp) { // Start Executing a microprogram
+ Execute(vu0RunCycles); // Kick start VU
+
+ // If the VU0 program didn't finish then we'll want to finish it up
+ // pretty soon. This fixes vmhacks in some games (Naruto Ultimate Ninja 2)
+ if(VU0.VI[REG_VPU_STAT].UL & vuRunning)
+ cpuSetNextBranchDelta( 192 ); // fixme : ideally this should be higher, like 512 or so.
+ }
+ else {
+ Execute(vu0RunCycles);
+ //DevCon.Warning("VU0 running when in BranchTest");
+
+ // This helps keep the EE and VU0 in sync.
+ // Check Silver Surfer. Currently has SPS varying with different branch deltas set below.
+ if(VU0.VI[REG_VPU_STAT].UL & vuRunning)
+ cpuSetNextBranchDelta( 768 );
+ }
+}
+
+// This function is called by VU0 Macro (COP2) after transferring
+// EE data to a VU0 register...
+void __fastcall BaseVUmicroCPU::ExecuteBlockJIT(BaseVUmicroCPU* cpu) {
+ cpu->Execute(1024);
+}
+
+#endif
diff --git a/pcsx2/VUmicro.h b/pcsx2/VUmicro.h
index ee4e60534c..db3ea4cb69 100644
--- a/pcsx2/VUmicro.h
+++ b/pcsx2/VUmicro.h
@@ -74,7 +74,7 @@ public:
// recompiled code.
static void __fastcall ExecuteBlockJIT( BaseCpuProvider* cpu )
{
- cpu->Execute(vuRunCycles);
+ cpu->Execute(1024);
}
};
@@ -85,15 +85,15 @@ public:
// type define).
//
class BaseVUmicroCPU : public BaseCpuProvider {
-protected:
- u32 m_lastEEcycles;
+public:
int m_Idx;
+ u32 m_lastEEcycles;
+
BaseVUmicroCPU() {
m_Idx = 0;
m_lastEEcycles = 0;
}
virtual ~BaseVUmicroCPU() throw() {}
-public:
// Called by the PS2 VM's event manager for every internal vertical sync (occurs at either
// 50hz (pal) or 59.94hz (NTSC).
@@ -115,56 +115,13 @@ public:
}
// Execute VU for the number of VU cycles (recs might go over 0~30 cycles)
- //virtual void Execute(u32 cycles)=0;
-
- // Executes a Block based on static preset cycles
- virtual void ExecuteBlock(bool startUp=0) {
- const int vuRunning = m_Idx ? 0x100 : 1;
- if (!(VU0.VI[REG_VPU_STAT].UL & vuRunning)) return;
- if (startUp) { // Start Executing a microprogram
- Execute(vu0RunCycles); // Kick start VU
- // If the VU0 program didn't finish then we'll want to finish it up
- // pretty soon. This fixes vmhacks in some games (Naruto Ultimate Ninja 2)
- if(VU0.VI[REG_VPU_STAT].UL & vuRunning)
- cpuSetNextBranchDelta( 192 ); // fixme : ideally this should be higher, like 512 or so.
- }
- else {
- Execute(vu0RunCycles);
- DevCon.Warning("VU0 running when in BranchTest");
- // This helps keep the EE and VU0 in sync.
- // Check Silver Surfer. Currently has SPS varying with different branch deltas set below.
- if(VU0.VI[REG_VPU_STAT].UL & vuRunning)
- cpuSetNextBranchDelta( 768 );
- }
- }
+ // virtual void Execute(u32 cycles)=0;
- // Executes a Block based on EE delta time
- /*virtual void ExecuteBlock(bool startUp=0) {
- const int vuRunning = m_Idx ? 0x100 : 1;
- const int c = 1024;
- if (!(VU0.VI[REG_VPU_STAT].UL & vuRunning)) return;
- if (startUp) { // Start Executing a microprogram
- Execute(c); // Kick start VU
- m_lastEEcycles = cpuRegs.cycle + (c*2);
- if (VU0.VI[REG_VPU_STAT].UL & vuRunning)
- cpuSetNextBranchDelta(c*4); // Let VUs run behind EE instead of ahead
- }
- else { // Continue Executing (VU roughly half the mhz of EE)
- s32 delta = (s32)(u32)(cpuRegs.cycle - m_lastEEcycles);
- if (delta > 0) {
- delta>>=1;
- DevCon.WriteLn("Event Test1: Running VU0 for %d cycles", delta);
- Execute(delta);
- m_lastEEcycles = cpuRegs.cycle;
- if (VU0.VI[REG_VPU_STAT].UL & vuRunning)
- cpuSetNextBranchDelta(c*2); // Let VUs run behind EE instead of in front
- }
- else {
- cpuSetNextBranchDelta(-delta);
- DevCon.WriteLn("Event Test2: Running VU0 for %d cycles", delta/2);
- }
- }
- }*/
+ // Executes a Block based on static preset cycles OR
+ // Executes a Block based on EE delta time (see VUmicro.cpp)
+ virtual void ExecuteBlock(bool startUp=0);
+
+ static void __fastcall ExecuteBlockJIT(BaseVUmicroCPU* cpu);
};
diff --git a/pcsx2/windows/VCprojects/pcsx2_2008.vcproj b/pcsx2/windows/VCprojects/pcsx2_2008.vcproj
index e9337bac3d..63cb7dec17 100644
--- a/pcsx2/windows/VCprojects/pcsx2_2008.vcproj
+++ b/pcsx2/windows/VCprojects/pcsx2_2008.vcproj
@@ -609,6 +609,10 @@
RelativePath="..\..\VU.h"
>
+
+
diff --git a/pcsx2/x86/microVU_Macro.inl b/pcsx2/x86/microVU_Macro.inl
index b9657492bd..666d9c0b57 100644
--- a/pcsx2/x86/microVU_Macro.inl
+++ b/pcsx2/x86/microVU_Macro.inl
@@ -330,11 +330,11 @@ static void recCTC2() {
MOV32RtoM((uptr)µVU0.regs->VI[REG_FBRST].UL, EAX);
break;
default:
- // Executing vu0 block here fixes the intro of Rachet and Clank
+ // Executing vu0 block here fixes the intro of Ratchet and Clank
// sVU's COP2 has a comment that "Donald Duck" needs this too...
if (_Rd_) _eeMoveGPRtoM((uptr)µVU0.regs->VI[_Rd_].UL, _Rt_);
xMOV(ecx, (uptr)CpuVU0);
- xCALL(BaseCpuProvider::ExecuteBlockJIT);
+ xCALL(BaseVUmicroCPU::ExecuteBlockJIT);
break;
}
}