File: USB.cpp

package info (click to toggle)
pcsx2 1.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 22,172 kB
  • ctags: 40,348
  • sloc: cpp: 232,892; ansic: 22,912; asm: 2,273; lisp: 1,346; sh: 561; perl: 253; makefile: 113; xml: 69
file content (282 lines) | stat: -rw-r--r-- 6,198 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/*  USBnull
 *  Copyright (C) 2002-2010  PCSX2 Dev Team
 *
 *  PCSX2 is free software: you can redistribute it and/or modify it under the terms
 *  of the GNU Lesser General Public License as published by the Free Software Found-
 *  ation, either version 3 of the License, or (at your option) any later version.
 *
 *  PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 *  PURPOSE.  See the GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along with PCSX2.
 *  If not, see <http://www.gnu.org/licenses/>.
 */

#include <stdlib.h>
#include <string>
using namespace std;
#include "svnrev.h"
#include "USB.h"
string s_strIniPath="inis";
string s_strLogPath="logs";

const unsigned char version  = PS2E_USB_VERSION;
const unsigned char revision = 0;
const unsigned char build    = 7;    // increase that with each version

#ifdef _MSC_VER
#define snprintf sprintf_s
#endif
static char libraryName[256];

USBcallback USBirq;
Config conf;
PluginLog USBLog;

s8 *usbregs, *ram;

void LogInit()
{
	const std::string LogFile(s_strLogPath + "/USBnull.log");
	setLoggingState();
	USBLog.Open(LogFile);
}

EXPORT_C_(void)  USBsetLogDir(const char* dir)
{
	// Get the path to the log directory.
	s_strLogPath = (dir==NULL) ? "logs" : dir;
	
	// Reload the log file after updated the path
	USBLog.Close();
	LogInit();
}

EXPORT_C_(u32) PS2EgetLibType()
{
	return PS2E_LT_USB;
}

EXPORT_C_(char*) PS2EgetLibName()
{
	snprintf( libraryName, 255, "USBnull Driver %lld%s",SVN_REV,	SVN_MODS ? "m" : "");
	return libraryName;	
}

EXPORT_C_(u32) PS2EgetLibVersion2(u32 type)
{
	return (version << 16) | (revision << 8) | build;
}

EXPORT_C_(s32) USBinit()
{
	LoadConfig();
	LogInit();
	USBLog.WriteLn("USBnull plugin version %d,%d", revision, build);
	USBLog.WriteLn("Initializing USBnull");

	// Initialize memory structures here.
	usbregs = (s8*)calloc(0x10000, 1);

	if (usbregs == NULL)
	{
		USBLog.Message("Error allocating memory");
		return -1;
	}

	return 0;
}

EXPORT_C_(void) USBshutdown()
{
	// Yes, we close things in the Shutdown routine, and
	// don't do anything in the close routine.
	USBLog.Close();
	
	free(usbregs);
	usbregs = NULL;
}

EXPORT_C_(s32) USBopen(void *pDsp)
{
	USBLog.WriteLn("Opening USBnull.");

	// Take care of anything else we need on opening, other then initialization.
	return 0;
}

EXPORT_C_(void) USBclose()
{
	USBLog.WriteLn("Closing USBnull.");
}

// Note: actually uncommenting the read/write functions I provided here
// caused uLauncher.elf to hang on startup, so careful when experimenting.
EXPORT_C_(u8) USBread8(u32 addr)
{
	u8 value = 0;

	switch(addr)
	{
		// Handle any appropriate addresses here.
		case 0x1f801600:
			USBLog.WriteLn("(USBnull) 8 bit read at address %lx", addr);
		break;

		default:
			//value = usbRu8(addr);
			USBLog.WriteLn("*(USBnull) 8 bit read at address %lx", addr);
			break;
	}
	return value;
}

EXPORT_C_(u16) USBread16(u32 addr)
{
	u16 value = 0;

	switch(addr)
	{
		// Handle any appropriate addresses here.
		case 0x1f801600:
			USBLog.WriteLn("(USBnull) 16 bit read at address %lx", addr);
		break;

		default:
			//value = usbRu16(addr);
			USBLog.WriteLn("(USBnull) 16 bit read at address %lx", addr);
	}
	return value;
}

EXPORT_C_(u32) USBread32(u32 addr)
{
	u32 value = 0;

	switch(addr)
	{
		// Handle any appropriate addresses here.
		case 0x1f801600:
			USBLog.WriteLn("(USBnull) 32 bit read at address %lx", addr);
		break;

		default:
			//value = usbRu32(addr);
			USBLog.WriteLn("(USBnull) 32 bit read at address %lx", addr);
	}
	return value;
}

EXPORT_C_(void) USBwrite8(u32 addr,  u8 value)
{
	switch(addr)
	{
		// Handle any appropriate addresses here.
		case 0x1f801600:
			USBLog.WriteLn("(USBnull) 8 bit write at address %lx value %x", addr, value);
		break;

		default:
			//usbRu8(addr) = value;
			USBLog.WriteLn("(USBnull) 8 bit write at address %lx value %x", addr, value);
	}
}

EXPORT_C_(void) USBwrite16(u32 addr, u16 value)
{
	switch(addr)
	{
		// Handle any appropriate addresses here.
		case 0x1f801600:
			USBLog.WriteLn("(USBnull) 16 bit write at address %lx value %x", addr, value);
		break;

		default:
			//usbRu16(addr) = value;
			USBLog.WriteLn("(USBnull) 16 bit write at address %lx value %x", addr, value);
	}
}

EXPORT_C_(void) USBwrite32(u32 addr, u32 value)
{
	switch(addr)
	{
		// Handle any appropriate addresses here.
		case 0x1f801600:
			USBLog.WriteLn("(USBnull) 16 bit write at address %lx value %x", addr, value);
		break;

		default:
			//usbRu32(addr) = value;
			USBLog.WriteLn("(USBnull) 32 bit write at address %lx value %x", addr, value);
	}
}

EXPORT_C_(void) USBirqCallback(USBcallback callback)
{
	// Register USBirq, so we can trigger an interrupt with it later.
	// It will be called as USBirq(cycles); where cycles is the number
	// of cycles before the irq is triggered.
	USBirq = callback;
}

EXPORT_C_(int) _USBirqHandler(void)
{
	// This is our USB irq handler, so if an interrupt gets triggered,
	// deal with it here.
	return 0;
}

EXPORT_C_(USBhandler) USBirqHandler(void)
{
	// Pass our handler to pcsx2.
	return (USBhandler)_USBirqHandler;
}

EXPORT_C_(void) USBsetRAM(void *mem)
{
	ram = (s8*)mem;
	USBLog.WriteLn("*Setting ram.");
}

EXPORT_C_(void) USBsetSettingsDir(const char* dir)
{
	// Get the path to the ini directory.
    s_strIniPath = (dir==NULL) ? "inis" : dir;
}

// extended funcs

EXPORT_C_(s32) USBfreeze(int mode, freezeData *data)
{
	// This should store or retrieve any information, for if emulation
	// gets suspended, or for savestates.
	switch(mode)
	{
		case FREEZE_LOAD:
			// Load previously saved data.
			break;
		case FREEZE_SAVE:
			// Save data.
			break;
		case FREEZE_SIZE:
			// return the size of the data.
			break;
	}
	return 0;
}

/*EXPORT_C_(void) USBasync(u32 cycles)
{
	// Optional function: Called in IopCounter.cpp.
}*/

EXPORT_C_(s32) USBtest()
{
	// 0 if the plugin works, non-0 if it doesn't.
	return 0;
}

/* For operating systems that need an entry point for a dll/library, here it is. Defined in PS2Eext.h. */
ENTRY_POINT;