/[pcsx2_0.9.7]/trunk/pcsx2/IPU/IPU_Fifo.cpp
ViewVC logotype

Contents of /trunk/pcsx2/IPU/IPU_Fifo.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10 - (show annotations) (download)
Mon Sep 6 11:40:06 2010 UTC (9 years, 5 months ago) by william
File size: 3676 byte(s)
exported r3113 from ./upstream/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 "IPU_Fifo.h"
20 #include "IPU.h"
21
22 IPU_Fifo ipu_fifo;
23
24 void IPU_Fifo::init()
25 {
26 out.readpos = 0;
27 out.writepos = 0;
28 in.readpos = 0;
29 in.writepos = 0;
30 memzero(in.data);
31 memzero(out.data);
32 }
33
34 void IPU_Fifo_Input::clear()
35 {
36 memzero(data);
37 g_BP.IFC = 0;
38 ipuRegs->ctrl.IFC = 0;
39 readpos = 0;
40 writepos = 0;
41 }
42
43 void IPU_Fifo_Output::clear()
44 {
45 memzero(data);
46 ipuRegs->ctrl.OFC = 0;
47 readpos = 0;
48 writepos = 0;
49 }
50
51 void IPU_Fifo::clear()
52 {
53 in.clear();
54 out.clear();
55 }
56
57 wxString IPU_Fifo_Input::desc() const
58 {
59 return wxsFormat(L"IPU Fifo Input: readpos = 0x%x, writepos = 0x%x, data = 0x%x", readpos, writepos, data);
60 }
61
62 wxString IPU_Fifo_Output::desc() const
63 {
64 return wxsFormat(L"IPU Fifo Output: readpos = 0x%x, writepos = 0x%x, data = 0x%x", readpos, writepos, data);
65 }
66
67 int IPU_Fifo_Input::write(u32* pMem, int size)
68 {
69 int transsize;
70 int firsttrans = min(size, 8 - (int)g_BP.IFC);
71
72 g_BP.IFC += firsttrans;
73 transsize = firsttrans;
74
75 while (transsize-- > 0)
76 {
77 for (int i = 0; i <= 3; i++)
78 {
79 data[writepos + i] = pMem[i];
80 }
81 writepos = (writepos + 4) & 31;
82 pMem += 4;
83 }
84
85 return firsttrans;
86 }
87
88 int IPU_Fifo_Output::write(const u32 *value, int size)
89 {
90 int transsize, firsttrans;
91
92 if ((int)ipuRegs->ctrl.OFC >= 8) IPU0dma();
93
94 transsize = min(size, 8 - (int)ipuRegs->ctrl.OFC);
95 firsttrans = transsize;
96
97 while (transsize-- > 0)
98 {
99 for (int i = 0; i <= 3; i++)
100 {
101 data[writepos + i] = ((u32*)value)[i];
102 }
103 writepos = (writepos + 4) & 31;
104 value += 4;
105 }
106
107 ipuRegs->ctrl.OFC += firsttrans;
108 IPU0dma();
109 //Console.WriteLn("Written %d qwords, %d", firsttrans,ipuRegs->ctrl.OFC);
110
111 return firsttrans;
112 }
113
114 int IPU_Fifo_Input::read(void *value)
115 {
116 // wait until enough data
117 if (g_BP.IFC < 8)
118 {
119 // IPU FIFO is empty and DMA is waiting so lets tell the DMA we are ready to put data in the FIFO
120 if(cpuRegs.eCycle[4] == 0x9999)
121 {
122 //DevCon.Warning("Setting ECycle");
123 CPU_INT( DMAC_TO_IPU, 4 );
124 }
125
126 if (g_BP.IFC == 0) return 0;
127 pxAssert(g_BP.IFC > 0);
128 }
129
130 // transfer 1 qword, split into two transfers
131 for (int i = 0; i <= 3; i++)
132 {
133 ((u32*)value)[i] = data[readpos + i];
134 data[readpos + i] = 0;
135 }
136
137 readpos = (readpos + 4) & 31;
138 g_BP.IFC--;
139 return 1;
140 }
141
142 void IPU_Fifo_Output::_readsingle(void *value)
143 {
144 // transfer 1 qword, split into two transfers
145 for (int i = 0; i <= 3; i++)
146 {
147 ((u32*)value)[i] = data[readpos + i];
148 data[readpos + i] = 0;
149 }
150 readpos = (readpos + 4) & 31;
151 }
152
153 void IPU_Fifo_Output::read(void *value, int size)
154 {
155 ipuRegs->ctrl.OFC -= size;
156 while (size > 0)
157 {
158 _readsingle(value);
159 value = (u32*)value + 4;
160 size--;
161 }
162 }
163
164 void IPU_Fifo_Output::readsingle(void *value)
165 {
166 if (ipuRegs->ctrl.OFC > 0)
167 {
168 ipuRegs->ctrl.OFC--;
169 _readsingle(value);
170 }
171 }

  ViewVC Help
Powered by ViewVC 1.1.22