/[pcsx2_0.9.7]/trunk/plugins/dev9null/DEV9.cpp
ViewVC logotype

Contents of /trunk/plugins/dev9null/DEV9.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (10 years, 9 months ago) by william
File size: 7480 byte(s)
committing r3113 initial commit again...
1 /* DEV9null
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 // Note: I was using MegaDev9, dev9ghzdrk, and dev9linuz for reference on memory locations.
17 // The ones I included were just some of the more important ones, so you may want to look
18 // at the plugins I mentioned if trying to create your own dev9 plugin.
19
20 // Additionally, there is a lot of information in the ps2drv drivers by Marcus R. Brown, so
21 // looking through its code would be a good starting point.
22
23 // Look under tags/plugins in svn for any older plugins that aren't included in pcsx2 any more.
24 // --arcum42
25
26
27 #include <stdlib.h>
28 #include <string.h>
29 #include <errno.h>
30 #include <string>
31 using namespace std;
32
33 #include "DEV9.h"
34
35 const unsigned char version = PS2E_DEV9_VERSION;
36 const unsigned char revision = 0;
37 const unsigned char build = 5; // increase that with each version
38
39 const char *libraryName = "DEV9null Driver";
40
41 // Our IRQ call.
42 void (*DEV9irq)(int);
43
44 __aligned16 s8 dev9regs[0x10000];
45
46 string s_strIniPath = "inis/";
47 PluginLog Dev9Log;
48 Config conf;
49
50 EXPORT_C_(u32) PS2EgetLibType()
51 {
52 return PS2E_LT_DEV9;
53 }
54
55 EXPORT_C_(char*) PS2EgetLibName()
56 {
57 return (char *)libraryName;
58 }
59
60 EXPORT_C_(u32) PS2EgetLibVersion2(u32 type)
61 {
62 return (version<<16) | (revision<<8) | build;
63 }
64
65 EXPORT_C_(s32) DEV9init()
66 {
67 LoadConfig();
68 setLoggingState();
69
70 Dev9Log.Open("logs/dev9null.log");
71 Dev9Log.WriteLn("dev9null plugin version %d,%d", revision, build);
72 Dev9Log.WriteLn("Initializing dev9null");
73 // Initialize anything that needs to be initialized.
74 memset(dev9regs, 0, sizeof(dev9regs));
75 return 0;
76 }
77
78 EXPORT_C_(void) DEV9shutdown()
79 {
80 Dev9Log.WriteLn("Shutting down Dev9null.");
81 Dev9Log.Close();
82 }
83
84 EXPORT_C_(s32) DEV9open(void *pDsp)
85 {
86 Dev9Log.WriteLn("Opening Dev9null.");
87 // Get anything ready we need to. Opening and creating hard
88 // drive files, for example.
89 return 0;
90 }
91
92 EXPORT_C_(void) DEV9close()
93 {
94 Dev9Log.WriteLn("Closing Dev9null.");
95 // Close files opened.
96 }
97
98 EXPORT_C_(u8) DEV9read8(u32 addr)
99 {
100 u8 value = 0;
101
102 switch(addr)
103 {
104 // case 0x1F80146E: // DEV9 hardware type (0x32 for an expansion bay)
105 case 0x10000038: /*value = dev9Ru8(addr);*/ break; // We need to have at least one case to avoid warnings.
106 default:
107 //value = dev9Ru8(addr);
108 Dev9Log.WriteLn("*Unknown 8 bit read at address %lx", addr);
109 break;
110 }
111 return value;
112 }
113
114 EXPORT_C_(u16) DEV9read16(u32 addr)
115 {
116 u16 value = 0;
117
118 switch(addr)
119 {
120 // Addresses you may want to catch here include:
121 // case 0x1F80146E: // DEV9 hardware type (0x32 for an expansion bay)
122 // case 0x10000002: // The Smart Chip revision. Should be 0x11
123 // case 0x10000004: // More type info: bit 0 - smap; bit 1 - hd; bit 5 - flash
124 // case 0x1000000E: // Similar to the last; bit 1 should be set if a hd is hooked up.
125 // case 0x10000028: // intr_stat
126 // case 0x10000038: // hard drives seem to like reading and writing the max dma size per transfer here.
127 // case 0x1000002A: // intr_mask
128 // case 0x10000040: // pio_data
129 // case 0x10000044: // nsector
130 // case 0x10000046: // sector
131 // case 0x10000048: // lcyl
132 // case 0x1000004A: // hcyl
133 // case 0x1000004C: // select
134 // case 0x1000004E: // status
135 // case 0x1000005C: // status
136 // case 0x10000064: // if_ctrl
137 case 0x10000038: /*value = dev9Ru16(addr);*/ break;
138 default:
139 //value = dev9Ru16(addr);
140 Dev9Log.WriteLn("*Unknown 16 bit read at address %lx", addr);
141 break;
142 }
143
144 return value;
145 }
146
147 EXPORT_C_(u32 ) DEV9read32(u32 addr)
148 {
149 u32 value = 0;
150
151 switch(addr)
152 {
153 case 0x10000038: /*value = dev9Ru32(addr);*/ break;
154 default:
155 //value = dev9Ru32(addr);
156 Dev9Log.WriteLn("*Unknown 32 bit read at address %lx", addr);
157 break;
158 }
159
160 return value;
161 }
162
163 EXPORT_C_(void) DEV9write8(u32 addr, u8 value)
164 {
165 switch(addr)
166 {
167 case 0x10000038: /*dev9Ru8(addr) = value;*/ break;
168 default:
169 Dev9Log.WriteLn("*Unknown 8 bit write; address %lx = %x", addr, value);
170 //dev9Ru8(addr) = value;
171 break;
172 }
173 }
174
175 EXPORT_C_(void) DEV9write16(u32 addr, u16 value)
176 {
177 switch(addr)
178 {
179 // Remember that list on DEV9read16? You'll want to write to a
180 // lot of them, too.
181 case 0x10000038: /*dev9Ru16(addr) = value;*/ break;
182 default:
183 Dev9Log.WriteLn("*Unknown 16 bit write; address %lx = %x", addr, value);
184 //dev9Ru16(addr) = value;
185 break;
186 }
187 }
188
189 EXPORT_C_(void) DEV9write32(u32 addr, u32 value)
190 {
191 switch(addr)
192 {
193 case 0x10000038: /*dev9Ru32(addr) = value;*/ break;
194 default:
195 Dev9Log.WriteLn("*Unknown 32 bit write; address %lx = %x", addr, value);
196 //dev9Ru32(addr) = value;
197 break;
198 }
199 }
200
201 //#ifdef ENABLE_NEW_IOPDMA_DEV9
202 EXPORT_C_(s32) DEV9dmaRead(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed)
203 {
204 // You'll want to put your own DMA8 reading code here.
205 // Time to interact with your fake (or real) hardware.
206 Dev9Log.WriteLn("Reading DMA8 Mem.");
207 *bytesProcessed = bytesLeft;
208 return 0;
209 }
210
211 EXPORT_C_(s32) DEV9dmaWrite(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed)
212 {
213 // See above.
214 Dev9Log.WriteLn("Writing DMA8 Mem.");
215 *bytesProcessed = bytesLeft;
216 return 0;
217 }
218
219 EXPORT_C_(void) DEV9dmaInterrupt(s32 channel)
220 {
221 // See above.
222 }
223 //#else
224 EXPORT_C_(void) DEV9readDMA8Mem(u32 *pMem, int size)
225 {
226 // You'll want to put your own DMA8 reading code here.
227 // Time to interact with your fake (or real) hardware.
228 Dev9Log.WriteLn("Reading DMA8 Mem.");
229 }
230
231 EXPORT_C_(void) DEV9writeDMA8Mem(u32* pMem, int size)
232 {
233 // See above.
234 Dev9Log.WriteLn("Writing DMA8 Mem.");
235 }
236 //#endif
237
238 EXPORT_C_(void) DEV9irqCallback(DEV9callback callback)
239 {
240 // Setting our callback. You will call it with DEV9irq(cycles),
241 // Where cycles is the number of cycles till the irq is triggered.
242 DEV9irq = callback;
243 }
244
245 int _DEV9irqHandler(void)
246 {
247 // And this gets called when the irq is triggered.
248 return 0;
249 }
250
251 EXPORT_C_(DEV9handler) DEV9irqHandler(void)
252 {
253 // Pass it to pcsx2.
254 return (DEV9handler)_DEV9irqHandler;
255 }
256
257 EXPORT_C_(void) DEV9setSettingsDir(const char* dir)
258 {
259 // Grab the ini directory.
260 s_strIniPath = (dir == NULL) ? "inis/" : dir;
261 }
262
263 // extended funcs
264
265 EXPORT_C_(s32) DEV9test()
266 {
267 return 0;
268 }
269
270 EXPORT_C_(s32) DEV9freeze(int mode, freezeData *data)
271 {
272 // This should store or retrieve any information, for if emulation
273 // gets suspended, or for savestates.
274 switch(mode)
275 {
276 case FREEZE_LOAD:
277 // Load previously saved data.
278 break;
279 case FREEZE_SAVE:
280 // Save data.
281 break;
282 case FREEZE_SIZE:
283 // return the size of the data.
284 break;
285 }
286 return 0;
287 }
288
289 /* For operating systems that need an entry point for a dll/library, here it is. Defined in PS2Eext.h. */
290 ENTRY_POINT;

  ViewVC Help
Powered by ViewVC 1.1.22