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

Contents of /trunk/pcsx2/HwRead.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: 8117 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
17 #include "PrecompiledHeader.h"
18 #include "Common.h"
19 #include "Hardware.h"
20
21 #include "ps2/HwInternal.h"
22 #include "ps2/eeHwTraceLog.inl"
23
24 using namespace R5900;
25
26 static __fi void IntCHackCheck()
27 {
28 // Sanity check: To protect from accidentally "rewinding" the cyclecount
29 // on the few times nextBranchCycle can be behind our current cycle.
30 s32 diff = g_nextEventCycle - cpuRegs.cycle;
31 if( diff > 0 ) cpuRegs.cycle = g_nextEventCycle;
32 }
33
34 static const uint HwF_VerboseConLog = 1<<0;
35 static const uint HwF_IntcStatHack = 1<<1; // used for Reads only.
36
37 template< uint page > void __fastcall _hwRead128(u32 mem, mem128_t* result );
38
39 template< uint page, bool intcstathack >
40 mem32_t __fastcall _hwRead32(u32 mem)
41 {
42 pxAssume( (mem & 0x03) == 0 );
43
44 switch( page )
45 {
46 case 0x00: return rcntRead32<0x00>( mem );
47 case 0x01: return rcntRead32<0x01>( mem );
48
49 case 0x02: return ipuRead32( mem );
50
51 case 0x03: return dmacRead32<0x03>( mem );
52
53 case 0x04:
54 case 0x05:
55 case 0x06:
56 case 0x07:
57 {
58 // [Ps2Confirm] Reading from FIFOs using non-128 bit reads is a complete mystery.
59 // No game is known to attempt such a thing (yay!), so probably nothing for us to
60 // worry about. Chances are, though, doing so is "legal" and yields some sort
61 // of reproducible behavior. Candidate for real hardware testing.
62
63 // Current assumption: Reads 128 bits and discards the unused portion.
64
65 DevCon.WriteLn( Color_Cyan, "Reading 32-bit FIFO data" );
66
67 u128 out128;
68 _hwRead128<page>(mem & ~0x0f, &out128);
69 return out128._u32[(mem >> 2) & 0x3];
70 }
71 break;
72
73 case 0x0f:
74 {
75 // INTC_STAT shortcut for heavy spinning.
76 // Performance Note: Visual Studio handles this best if we just manually check for it here,
77 // outside the context of the switch statement below. This is likely fixed by PGO also,
78 // but it's an easy enough conditional to account for anyways.
79
80 if (mem == INTC_STAT)
81 {
82 if (intcstathack) IntCHackCheck();
83 return psHu32(INTC_STAT);
84 }
85
86 //if ((mem & 0x1000f200) == 0x1000f200)
87 // Console.Error("SBUS");
88
89 switch( mem )
90 {
91 case SIO_ISR:
92 case SBUS_F260:
93 case 0x1000f410:
94 case MCH_RICM:
95 return 0;
96
97 case SBUS_F240:
98 return psHu32(SBUS_F240) | 0xF0000102;
99
100 case MCH_DRD:
101 if( !((psHu32(MCH_RICM) >> 6) & 0xF) )
102 {
103 switch ((psHu32(MCH_RICM)>>16) & 0xFFF)
104 {
105 //MCH_RICM: x:4|SA:12|x:5|SDEV:1|SOP:4|SBC:1|SDEV:5
106
107 case 0x21://INIT
108 if(rdram_sdevid < rdram_devices)
109 {
110 rdram_sdevid++;
111 return 0x1F;
112 }
113 return 0;
114
115 case 0x23://CNFGA
116 return 0x0D0D; //PVER=3 | MVER=16 | DBL=1 | REFBIT=5
117
118 case 0x24://CNFGB
119 //0x0110 for PSX SVER=0 | CORG=8(5x9x7) | SPT=1 | DEVTYP=0 | BYTE=0
120 return 0x0090; //SVER=0 | CORG=4(5x9x6) | SPT=1 | DEVTYP=0 | BYTE=0
121
122 case 0x40://DEVID
123 return psHu32(MCH_RICM) & 0x1F; // =SDEV
124 }
125 }
126 return 0;
127 }
128 }
129 break;
130 }
131
132 return psHu32(mem);
133 }
134
135 template< uint page >
136 mem32_t __fastcall hwRead32(u32 mem)
137 {
138 mem32_t retval = _hwRead32<page,false>(mem);
139 eeHwTraceLog( mem, retval, true );
140 return retval;
141 }
142
143 mem32_t __fastcall hwRead32_page_0F_INTC_HACK(u32 mem)
144 {
145 mem32_t retval = _hwRead32<0x0f,true>(mem);
146 eeHwTraceLog( mem, retval, true );
147 return retval;
148 }
149
150 // --------------------------------------------------------------------------------------
151 // hwRead8 / hwRead16 / hwRead64 / hwRead128
152 // --------------------------------------------------------------------------------------
153
154 template< uint page >
155 mem8_t __fastcall _hwRead8(u32 mem)
156 {
157 u32 ret32 = _hwRead32<page, false>(mem & ~0x03);
158 return ((u8*)&ret32)[mem & 0x03];
159 }
160
161 template< uint page >
162 mem8_t __fastcall hwRead8(u32 mem)
163 {
164 mem8_t ret8 = _hwRead8<0x0f>(mem);
165 eeHwTraceLog( mem, ret8, true );
166 return ret8;
167 }
168
169 template< uint page >
170 mem16_t __fastcall _hwRead16(u32 mem)
171 {
172 pxAssume( (mem & 0x01) == 0 );
173
174 u32 ret32 = _hwRead32<page, false>(mem & ~0x03);
175 return ((u16*)&ret32)[(mem>>1) & 0x01];
176 }
177
178 template< uint page >
179 mem16_t __fastcall hwRead16(u32 mem)
180 {
181 u16 ret16 = _hwRead16<page>(mem);
182 eeHwTraceLog( mem, ret16, true );
183 return ret16;
184 }
185
186 mem16_t __fastcall hwRead16_page_0F_INTC_HACK(u32 mem)
187 {
188 pxAssume( (mem & 0x01) == 0 );
189
190 u32 ret32 = _hwRead32<0x0f, true>(mem & ~0x03);
191 u16 ret16 = ((u16*)&ret32)[(mem>>1) & 0x01];
192
193 eeHwTraceLog( mem, ret16, "Read" );
194 return ret16;
195 }
196
197 template< uint page >
198 static void _hwRead64(u32 mem, mem64_t* result )
199 {
200 pxAssume( (mem & 0x07) == 0 );
201
202 switch (page)
203 {
204 case 0x02:
205 *result = ipuRead64(mem);
206 return;
207
208 case 0x04:
209 case 0x05:
210 case 0x06:
211 case 0x07:
212 {
213 // [Ps2Confirm] Reading from FIFOs using non-128 bit reads is a complete mystery.
214 // No game is known to attempt such a thing (yay!), so probably nothing for us to
215 // worry about. Chances are, though, doing so is "legal" and yields some sort
216 // of reproducible behavior. Candidate for real hardware testing.
217
218 // Current assumption: Reads 128 bits and discards the unused portion.
219
220 uint wordpart = (mem >> 3) & 0x1;
221 DevCon.WriteLn( Color_Cyan, "Reading 64-bit FIFO data (%s 64 bits discarded)", wordpart ? "upper" : "lower" );
222
223 u128 out128;
224 _hwRead128<page>(mem & ~0x0f, &out128);
225 *result = out128._u64[wordpart];
226 }
227 return;
228 }
229
230 *result = _hwRead32<page,false>( mem );
231 }
232
233 template< uint page >
234 void __fastcall hwRead64(u32 mem, mem64_t* result )
235 {
236 _hwRead64<page>( mem, result );
237 eeHwTraceLog( mem, *result, true );
238 }
239
240 template< uint page >
241 void __fastcall _hwRead128(u32 mem, mem128_t* result )
242 {
243 pxAssume( (mem & 0x0f) == 0 );
244
245 // FIFOs are the only "legal" 128 bit registers, so we Handle them first.
246 // All other registers fall back on the 64-bit handler (and from there
247 // all non-IPU reads fall back to the 32-bit handler).
248
249 switch (page)
250 {
251 case 0x05:
252 ReadFIFO_VIF1( result );
253 break;
254
255 case 0x07:
256 if (mem & 0x10)
257 ZeroQWC( result ); // IPUin is write-only
258 else
259 ReadFIFO_IPUout( result );
260 break;
261
262 case 0x04:
263 case 0x06:
264 // VIF0 and GIF are write-only.
265 // [Ps2Confirm] Reads from these FIFOs (and IPUin) do one of the following:
266 // return zero, leave contents of the dest register unchanged, or in some
267 // indeterminate state. The actual behavior probably isn't important.
268 ZeroQWC( result );
269 break;
270
271 default:
272 _hwRead64<page>( mem, &result->lo );
273 result->hi = 0;
274 break;
275 }
276 }
277
278 template< uint page >
279 void __fastcall hwRead128(u32 mem, mem128_t* result )
280 {
281 _hwRead128<page>( mem, result );
282 eeHwTraceLog( mem, *result, true );
283 }
284
285 #define InstantizeHwRead(pageidx) \
286 template mem8_t __fastcall hwRead8<pageidx>(u32 mem); \
287 template mem16_t __fastcall hwRead16<pageidx>(u32 mem); \
288 template mem32_t __fastcall hwRead32<pageidx>(u32 mem); \
289 template void __fastcall hwRead64<pageidx>(u32 mem, mem64_t* result ); \
290 template void __fastcall hwRead128<pageidx>(u32 mem, mem128_t* result ); \
291 template mem32_t __fastcall _hwRead32<pageidx, false>(u32 mem);
292
293 InstantizeHwRead(0x00); InstantizeHwRead(0x08);
294 InstantizeHwRead(0x01); InstantizeHwRead(0x09);
295 InstantizeHwRead(0x02); InstantizeHwRead(0x0a);
296 InstantizeHwRead(0x03); InstantizeHwRead(0x0b);
297 InstantizeHwRead(0x04); InstantizeHwRead(0x0c);
298 InstantizeHwRead(0x05); InstantizeHwRead(0x0d);
299 InstantizeHwRead(0x06); InstantizeHwRead(0x0e);
300 InstantizeHwRead(0x07); InstantizeHwRead(0x0f);

  ViewVC Help
Powered by ViewVC 1.1.22