/[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 280 - (show annotations) (download)
Thu Dec 23 12:02:12 2010 UTC (9 years, 1 month ago) by william
File size: 5423 byte(s)
re-commit (had local access denied errors when committing)
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 //DevCon.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 //VIF_LOG("New VifCMD %x tagsize %x", vifX.cmd, vifX.tag.size);
90 if (IsDevBuild && SysTrace.EE.VIFcode.IsActive())
91 {
92 // Pass 2 means "log it"
93 vifCmdHandler[idx][vifX.cmd & 0x7f](2, data);
94 }
95
96 vifCmdHandler[idx][vifX.cmd & 0x7f](0, data);
97 data++; pSize--;
98 if (analyzeIbit<idx>(data, iBit)) break;
99 continue;
100 }
101
102 int ret = vifCmdHandler[idx][vifX.cmd & 0x7f](1, data);
103 data += ret;
104 pSize -= ret;
105 if (analyzeIbit<idx>(data, iBit)) break;
106 }
107
108 if (pSize) vifX.vifstalled = true;
109 }
110
111 _vifT static __fi bool vifTransfer(u32 *data, int size, bool TTE) {
112 vifStruct& vifX = GetVifX;
113
114 // irqoffset necessary to add up the right qws, or else will spin (spiderman)
115 int transferred = vifX.irqoffset;
116
117 vifX.irqoffset = 0;
118 vifX.vifstalled = false;
119 vifX.stallontag = false;
120 vifX.vifpacketsize = size;
121 g_packetsizeonvu = size;
122 vifTransferLoop<idx>(data);
123
124
125 transferred += size - vifX.vifpacketsize;
126
127 g_vifCycles +=((transferred * BIAS) >> 2) ; /* guessing */
128
129 if(!idx && g_vu0Cycles > 0)
130 {
131 if(g_vifCycles < g_vu0Cycles) g_vu0Cycles -= g_vifCycles;
132 else if(g_vifCycles >= g_vu0Cycles)g_vu0Cycles = 0;
133 }
134 else if(idx && g_vu1Cycles > 0)
135 {
136 if(g_vifCycles < g_vu1Cycles) g_vu1Cycles -= g_vifCycles;
137 else if(g_vifCycles >= g_vu1Cycles)g_vu1Cycles = 0;
138 }
139
140 vifX.irqoffset = transferred % 4; // cannot lose the offset
141
142 if (!TTE) // *WARNING* - Tags CAN have interrupts! so lets just ignore the dma modifying stuffs (GT4)
143 {
144 transferred = transferred >> 2;
145
146 vifXch.madr +=(transferred << 4);
147 vifXch.qwc -= transferred;
148 if(vifXch.chcr.STR)hwDmacSrcTadrInc(vifXch);
149
150 if (!vifXch.qwc)
151 {
152 vifX.inprogress &= ~0x1;
153 vifX.vifstalled = false;
154 }
155 }
156 else
157 {
158
159 if(!vifX.irqoffset)
160 {
161 vifX.vifstalled = false;
162 }
163 }
164
165 if (vifX.irq && vifX.cmd == 0) {
166 //DevCon.WriteLn("Vif IRQ!");
167 if(((vifXRegs.code >> 24) & 0x7f) != 0x7)
168 {
169 vifXRegs.stat.VIS = true; // Note: commenting this out fixes WALL-E?
170 vifX.vifstalled = true;
171 }
172 }
173
174 return !vifX.vifstalled;
175 }
176
177 // When TTE is set to 1, MADR and QWC are not updated as part of the transfer.
178 bool VIF0transfer(u32 *data, int size, bool TTE) {
179 return vifTransfer<0>(data, size, TTE);
180 }
181 bool VIF1transfer(u32 *data, int size, bool TTE) {
182 return vifTransfer<1>(data, size, TTE);
183 }

  ViewVC Help
Powered by ViewVC 1.1.22