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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22