/[pcsx2_0.9.7]/trunk/pcsx2/Vif_Transfer.cpp
ViewVC logotype

Contents of /trunk/pcsx2/Vif_Transfer.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 62 - (show annotations) (download)
Tue Sep 7 11:08:22 2010 UTC (9 years, 5 months ago) by william
File size: 5008 byte(s)
Auto Commited Import of: pcsx2-0.9.7-r3738-debug in ./trunk
1 /* 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 "Vif_Dma.h"
19 #include "newVif.h"
20
21 //------------------------------------------------------------------
22 // VifCode Transfer Interpreter (Vif0/Vif1)
23 //------------------------------------------------------------------
24
25 // Doesn't stall if the next vifCode is the Mark command
26 _vifT bool runMark(u32* &data) {
27 if (((vifXRegs.code >> 24) & 0x7f) == 0x7) {
28 Console.WriteLn("Vif%d: Running Mark with I-bit", idx);
29 return 1; // No Stall?
30 }
31 return 1; // Stall
32 }
33
34 // Returns 1 if i-bit && finished vifcode && i-bit not masked
35 _vifT bool analyzeIbit(u32* &data, int iBit) {
36 vifStruct& vifX = GetVifX;
37 if (iBit && !vifX.cmd && !vifXRegs.err.MII) {
38 //DevCon.WriteLn("Vif I-Bit IRQ");
39 vifX.irq++;
40
41 // Okay did some testing with Max Payne, it does this:
42 // VifMark value = 0x666 (i know, evil!)
43 // NOP with I Bit
44 // VifMark value = 0
45 //
46 // If you break after the 2nd Mark has run, the game reports invalid mark 0 and the game dies.
47 // So it has to occur here, testing a theory that it only doesn't stall if the command with
48 // the iBit IS mark, but still sends the IRQ to let the cpu know the mark is there. (Refraction)
49 //
50 // --------------------------
51 //
52 // This is how it probably works: i-bit sets the IRQ flag, and VIF keeps running until it encounters
53 // a non-MARK instruction. This includes the *current* instruction. ie, execution only continues
54 // unimpeded if MARK[i] is specified, and keeps executing unimpeded until any non-MARK command.
55 // Any other command with an I bit should stall immediately.
56 // Example:
57 //
58 // VifMark[i] value = 0x321 (with I bit)
59 // VifMark value = 0
60 // VifMark value = 0x333
61 // NOP
62 //
63 // ... the VIF should not stall and raise the interrupt until after the NOP is processed.
64 // So the final value for MARK as the game sees it will be 0x333. --air
65
66 return runMark<idx>(data);
67 }
68 return 0;
69 }
70
71 // Interprets packet
72 _vifT void vifTransferLoop(u32* &data) {
73 vifStruct& vifX = GetVifX;
74
75 u32& pSize = vifX.vifpacketsize;
76 int iBit = vifX.cmd >> 7;
77
78 vifXRegs.stat.VPS |= VPS_TRANSFERRING;
79 vifXRegs.stat.ER1 = false;
80
81 while (pSize > 0 && !vifX.vifstalled) {
82
83 if(!vifX.cmd) { // Get new VifCode
84 vifX.lastcmd = (vifXRegs.code >> 24) & 0x7f;
85 vifXRegs.code = data[0];
86 vifX.cmd = data[0] >> 24;
87 iBit = data[0] >> 31;
88
89 vifCmdHandler[idx][vifX.cmd & 0x7f](0, data);
90 VIF_LOG("New VifCMD %x tagsize %x", vifX.cmd, vifX.tag.size);
91 data++; pSize--;
92 if (analyzeIbit<idx>(data, iBit)) break;
93 continue;
94 }
95
96 int ret = vifCmdHandler[idx][vifX.cmd & 0x7f](1, data);
97 data += ret;
98 pSize -= ret;
99 if (analyzeIbit<idx>(data, iBit)) break;
100 }
101
102 if (pSize) vifX.vifstalled = true;
103 }
104
105 _vifT static __fi bool vifTransfer(u32 *data, int size) {
106 vifStruct& vifX = GetVifX;
107
108 // irqoffset necessary to add up the right qws, or else will spin (spiderman)
109 int transferred = vifX.vifstalled ? vifX.irqoffset : 0;
110
111 vifX.irqoffset = 0;
112 vifX.vifstalled = false;
113 vifX.stallontag = false;
114 vifX.vifpacketsize = size;
115 g_packetsizeonvu = size;
116 vifTransferLoop<idx>(data);
117
118
119 transferred += size - vifX.vifpacketsize;
120
121 g_vifCycles +=((transferred * BIAS) >> 2) ; /* guessing */
122
123 if(!idx && g_vu0Cycles > 0)
124 {
125 if(g_vifCycles < g_vu0Cycles) g_vu0Cycles -= g_vifCycles;
126 else if(g_vifCycles >= g_vu0Cycles)g_vu0Cycles = 0;
127 }
128 else if(idx && g_vu1Cycles > 0)
129 {
130 if(g_vifCycles < g_vu1Cycles) g_vu1Cycles -= g_vifCycles;
131 else if(g_vifCycles >= g_vu1Cycles)g_vu1Cycles = 0;
132 }
133
134 vifX.irqoffset = transferred % 4; // cannot lose the offset
135
136 transferred = transferred >> 2;
137
138 vifXch.madr +=(transferred << 4);
139 vifXch.qwc -= transferred;
140
141 if (!vifXch.qwc && !vifX.irqoffset) vifX.inprogress &= ~0x1;
142
143 if (vifX.irq && vifX.cmd == 0) {
144 //DevCon.WriteLn("Vif IRQ!");
145 if(((vifXRegs.code >> 24) & 0x7f) != 0x7)
146 {
147 vifX.vifstalled = true;
148 vifXRegs.stat.VIS = true; // Note: commenting this out fixes WALL-E?
149 }
150
151 if (!vifXch.qwc && !vifX.irqoffset) vifX.inprogress &= ~1;
152 return false;
153 }
154
155 return !vifX.vifstalled;
156 }
157
158 bool VIF0transfer(u32 *data, int size) {
159 return vifTransfer<0>(data, size);
160 }
161 bool VIF1transfer(u32 *data, int size) {
162 return vifTransfer<1>(data, size);
163 }

  ViewVC Help
Powered by ViewVC 1.1.22