1 |
william |
31 |
/* PCSX2 - PS2 Emulator for PCs |
2 |
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team |
3 |
|
|
* |
4 |
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms |
5 |
|
|
* of the GNU Lesser General Public License as published by the Free Software Found- |
6 |
|
|
* ation, either version 3 of the License, or (at your option) any later version. |
7 |
|
|
* |
8 |
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
9 |
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
10 |
|
|
* PURPOSE. See the GNU General Public License for more details. |
11 |
|
|
* |
12 |
|
|
* You should have received a copy of the GNU General Public License along with PCSX2. |
13 |
|
|
* If not, see <http://www.gnu.org/licenses/>. |
14 |
|
|
*/ |
15 |
|
|
|
16 |
|
|
#include "PrecompiledHeader.h" |
17 |
|
|
#include "Common.h" |
18 |
|
|
#include "VUmicro.h" |
19 |
|
|
|
20 |
|
|
#define useDeltaTime 1 |
21 |
|
|
|
22 |
|
|
#if useDeltaTime |
23 |
|
|
|
24 |
|
|
// Executes a Block based on EE delta time |
25 |
|
|
void BaseVUmicroCPU::ExecuteBlock(bool startUp) { |
26 |
|
|
const u32& stat = VU0.VI[REG_VPU_STAT].UL; |
27 |
|
|
const int test = m_Idx ? 0x100 : 1; |
28 |
|
|
const int s = 1024*6; // Kick Start Cycles (Silver Surfer needs this amount) |
29 |
|
|
const int c = 1024*1; // Continue Cycles |
30 |
|
|
if (!(stat & test)) return; |
31 |
|
|
if (startUp) { // Start Executing a microprogram |
32 |
|
|
Execute(s); // Kick start VU |
33 |
|
|
|
34 |
|
|
// Let VUs run behind EE instead of ahead |
35 |
|
|
if (stat & test) { |
36 |
william |
62 |
cpuSetNextEventDelta((s+c)*2); |
37 |
william |
31 |
m_lastEEcycles = cpuRegs.cycle + (s*2); |
38 |
|
|
} |
39 |
|
|
} |
40 |
|
|
else { // Continue Executing (VU roughly half the mhz of EE) |
41 |
|
|
s32 delta = (s32)(u32)(cpuRegs.cycle - m_lastEEcycles) & ~1; |
42 |
|
|
if (delta > 0) { // Enough time has passed |
43 |
|
|
delta >>= 1; // Divide by 2 (unsigned) |
44 |
|
|
Execute(delta); // Execute the time since the last call |
45 |
|
|
if (stat & test) { |
46 |
william |
62 |
cpuSetNextEventDelta(c*2); |
47 |
william |
31 |
m_lastEEcycles = cpuRegs.cycle; |
48 |
|
|
} |
49 |
|
|
} |
50 |
william |
62 |
else cpuSetNextEventDelta(-delta); // Haven't caught-up from kick start |
51 |
william |
31 |
} |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
// This function is called by VU0 Macro (COP2) after transferring some |
55 |
|
|
// EE data to VU0's registers. We want to run VU0 Micro right after this |
56 |
|
|
// to ensure that the register is used at the correct time. |
57 |
|
|
// This fixes spinning/hanging in some games like Ratchet and Clank's Intro. |
58 |
|
|
void __fastcall BaseVUmicroCPU::ExecuteBlockJIT(BaseVUmicroCPU* cpu) { |
59 |
|
|
const u32& stat = VU0.VI[REG_VPU_STAT].UL; |
60 |
|
|
const int test = cpu->m_Idx ? 0x100 : 1; |
61 |
|
|
const int c = 128; // VU Execution Cycles |
62 |
|
|
if (stat & test) { // VU is running |
63 |
|
|
cpu->Execute(c); // Execute VU |
64 |
|
|
if (stat & test) { |
65 |
|
|
cpu->m_lastEEcycles+=(c*2); |
66 |
william |
62 |
cpuSetNextEventDelta(c*2); |
67 |
william |
31 |
} |
68 |
|
|
} |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
#else |
72 |
|
|
|
73 |
|
|
// Executes a Block based on static preset cycles |
74 |
|
|
void BaseVUmicroCPU::ExecuteBlock(bool startUp) { |
75 |
|
|
const int vuRunning = m_Idx ? 0x100 : 1; |
76 |
|
|
if (!(VU0.VI[REG_VPU_STAT].UL & vuRunning)) return; |
77 |
|
|
if (startUp) { // Start Executing a microprogram |
78 |
|
|
Execute(vu0RunCycles); // Kick start VU |
79 |
|
|
|
80 |
|
|
// If the VU0 program didn't finish then we'll want to finish it up |
81 |
|
|
// pretty soon. This fixes vmhacks in some games (Naruto Ultimate Ninja 2) |
82 |
|
|
if(VU0.VI[REG_VPU_STAT].UL & vuRunning) |
83 |
william |
62 |
cpuSetNextEventDelta( 192 ); // fixme : ideally this should be higher, like 512 or so. |
84 |
william |
31 |
} |
85 |
|
|
else { |
86 |
|
|
Execute(vu0RunCycles); |
87 |
|
|
//DevCon.Warning("VU0 running when in BranchTest"); |
88 |
|
|
|
89 |
|
|
// This helps keep the EE and VU0 in sync. |
90 |
|
|
// Check Silver Surfer. Currently has SPS varying with different branch deltas set below. |
91 |
|
|
if(VU0.VI[REG_VPU_STAT].UL & vuRunning) |
92 |
william |
62 |
cpuSetNextEventDelta( 768 ); |
93 |
william |
31 |
} |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
// This function is called by VU0 Macro (COP2) after transferring |
97 |
|
|
// EE data to a VU0 register... |
98 |
|
|
void __fastcall BaseVUmicroCPU::ExecuteBlockJIT(BaseVUmicroCPU* cpu) { |
99 |
|
|
cpu->Execute(128); |
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
#endif |