2009-12-19 18:30:56 +00:00
|
|
|
/* USBnull
|
2010-05-03 14:08:02 +00:00
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
2009-02-09 21:15:56 +00:00
|
|
|
*
|
2010-05-03 14:08:02 +00:00
|
|
|
* 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.
|
2009-02-09 21:15:56 +00:00
|
|
|
*
|
2010-05-03 14:08:02 +00:00
|
|
|
* 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.
|
2009-02-09 21:15:56 +00:00
|
|
|
*
|
2010-05-03 14:08:02 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
2009-02-09 21:15:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2009-05-02 02:29:48 +00:00
|
|
|
#include <string>
|
|
|
|
using namespace std;
|
2013-06-28 10:43:50 +00:00
|
|
|
#include "svnrev.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
#include "USB.h"
|
2018-05-23 18:59:17 +00:00
|
|
|
#include "null/config.inl"
|
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
string s_strIniPath = "inis";
|
|
|
|
string s_strLogPath = "logs";
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
const unsigned char version = PS2E_USB_VERSION;
|
2009-02-09 21:15:56 +00:00
|
|
|
const unsigned char revision = 0;
|
2016-10-16 19:39:56 +00:00
|
|
|
const unsigned char build = 7; // increase that with each version
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2012-06-18 21:16:25 +00:00
|
|
|
static char libraryName[256];
|
2009-12-19 18:30:56 +00:00
|
|
|
|
2009-05-02 02:29:48 +00:00
|
|
|
USBcallback USBirq;
|
2010-01-09 05:11:18 +00:00
|
|
|
|
|
|
|
s8 *usbregs, *ram;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2018-05-23 18:59:17 +00:00
|
|
|
EXPORT_C_(void)
|
|
|
|
USBconfigure()
|
|
|
|
{
|
|
|
|
const std::string ini_path = s_strIniPath + "/USBnull.ini";
|
|
|
|
LoadConfig(ini_path);
|
|
|
|
ConfigureLogging();
|
|
|
|
SaveConfig(ini_path);
|
|
|
|
}
|
|
|
|
|
2010-05-29 10:46:48 +00:00
|
|
|
void LogInit()
|
|
|
|
{
|
2016-08-24 21:11:25 +00:00
|
|
|
const std::string LogFile(s_strLogPath + "/USBnull.log");
|
2018-05-23 18:59:17 +00:00
|
|
|
g_plugin_log.Open(LogFile);
|
2010-05-29 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
EXPORT_C_(void)
|
2016-08-28 16:14:07 +00:00
|
|
|
USBsetLogDir(const char *dir)
|
2010-05-29 10:46:48 +00:00
|
|
|
{
|
2016-08-24 21:11:25 +00:00
|
|
|
// Get the path to the log directory.
|
|
|
|
s_strLogPath = (dir == NULL) ? "logs" : dir;
|
|
|
|
|
|
|
|
// Reload the log file after updated the path
|
2018-05-23 18:59:17 +00:00
|
|
|
g_plugin_log.Close();
|
2016-08-24 21:11:25 +00:00
|
|
|
LogInit();
|
2010-05-29 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
EXPORT_C_(u32)
|
|
|
|
PS2EgetLibType()
|
2009-05-02 02:29:48 +00:00
|
|
|
{
|
2016-08-24 21:11:25 +00:00
|
|
|
return PS2E_LT_USB;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 09:27:43 +00:00
|
|
|
EXPORT_C_(const char *)
|
2016-08-24 21:11:25 +00:00
|
|
|
PS2EgetLibName()
|
2009-05-02 02:29:48 +00:00
|
|
|
{
|
2016-08-24 21:11:25 +00:00
|
|
|
snprintf(libraryName, 255, "USBnull Driver %lld%s", SVN_REV, SVN_MODS ? "m" : "");
|
|
|
|
return libraryName;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
EXPORT_C_(u32)
|
|
|
|
PS2EgetLibVersion2(u32 type)
|
2009-05-02 02:29:48 +00:00
|
|
|
{
|
2016-08-24 21:11:25 +00:00
|
|
|
return (version << 16) | (revision << 8) | build;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
EXPORT_C_(s32)
|
|
|
|
USBinit()
|
2009-05-02 02:29:48 +00:00
|
|
|
{
|
2018-05-23 18:59:17 +00:00
|
|
|
LoadConfig(s_strIniPath + "/USBnull.ini");
|
2016-08-24 21:11:25 +00:00
|
|
|
LogInit();
|
2018-05-23 18:59:17 +00:00
|
|
|
g_plugin_log.WriteLn("USBnull plugin version %d,%d", revision, build);
|
|
|
|
g_plugin_log.WriteLn("Initializing USBnull");
|
2010-01-09 05:11:18 +00:00
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
// Initialize memory structures here.
|
2016-08-28 16:14:07 +00:00
|
|
|
usbregs = (s8 *)calloc(0x10000, 1);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
if (usbregs == NULL) {
|
2018-05-23 18:59:17 +00:00
|
|
|
g_plugin_log.Message("Error allocating memory");
|
2016-08-24 21:11:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
return 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
EXPORT_C_(void)
|
|
|
|
USBshutdown()
|
2009-05-02 02:29:48 +00:00
|
|
|
{
|
2016-08-24 21:11:25 +00:00
|
|
|
// Yes, we close things in the Shutdown routine, and
|
|
|
|
// don't do anything in the close routine.
|
2018-05-23 18:59:17 +00:00
|
|
|
g_plugin_log.Close();
|
2016-08-24 21:11:25 +00:00
|
|
|
|
|
|
|
free(usbregs);
|
|
|
|
usbregs = NULL;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
EXPORT_C_(s32)
|
2016-08-28 16:14:07 +00:00
|
|
|
USBopen(void *pDsp)
|
2009-05-02 02:29:48 +00:00
|
|
|
{
|
2018-05-23 18:59:17 +00:00
|
|
|
g_plugin_log.WriteLn("Opening USBnull.");
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
// Take care of anything else we need on opening, other then initialization.
|
|
|
|
return 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
EXPORT_C_(void)
|
|
|
|
USBclose()
|
2009-05-02 02:29:48 +00:00
|
|
|
{
|
2018-05-23 18:59:17 +00:00
|
|
|
g_plugin_log.WriteLn("Closing USBnull.");
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2010-01-09 05:11:18 +00:00
|
|
|
// Note: actually uncommenting the read/write functions I provided here
|
|
|
|
// caused uLauncher.elf to hang on startup, so careful when experimenting.
|
2016-08-24 21:11:25 +00:00
|
|
|
EXPORT_C_(u8)
|
|
|
|
USBread8(u32 addr)
|
2009-05-02 02:29:48 +00:00
|
|
|
{
|
2016-08-24 21:11:25 +00:00
|
|
|
u8 value = 0;
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
// Handle any appropriate addresses here.
|
|
|
|
case 0x1f801600:
|
2018-05-23 18:59:17 +00:00
|
|
|
g_plugin_log.WriteLn("(USBnull) 8 bit read at address %lx", addr);
|
2016-08-24 21:11:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
//value = usbRu8(addr);
|
2018-05-23 18:59:17 +00:00
|
|
|
g_plugin_log.WriteLn("*(USBnull) 8 bit read at address %lx", addr);
|
2016-08-24 21:11:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return value;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
EXPORT_C_(u16)
|
|
|
|
USBread16(u32 addr)
|
2009-05-02 02:29:48 +00:00
|
|
|
{
|
2016-08-24 21:11:25 +00:00
|
|
|
u16 value = 0;
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
// Handle any appropriate addresses here.
|
|
|
|
case 0x1f801600:
|
2018-05-23 18:59:17 +00:00
|
|
|
g_plugin_log.WriteLn("(USBnull) 16 bit read at address %lx", addr);
|
2016-08-24 21:11:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
//value = usbRu16(addr);
|
2018-05-23 18:59:17 +00:00
|
|
|
g_plugin_log.WriteLn("(USBnull) 16 bit read at address %lx", addr);
|
2016-08-24 21:11:25 +00:00
|
|
|
}
|
|
|
|
return value;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
EXPORT_C_(u32)
|
|
|
|
USBread32(u32 addr)
|
2009-05-02 02:29:48 +00:00
|
|
|
{
|
2016-08-24 21:11:25 +00:00
|
|
|
u32 value = 0;
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
// Handle any appropriate addresses here.
|
|
|
|
case 0x1f801600:
|
2018-05-23 18:59:17 +00:00
|
|
|
g_plugin_log.WriteLn("(USBnull) 32 bit read at address %lx", addr);
|
2016-08-24 21:11:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
//value = usbRu32(addr);
|
2018-05-23 18:59:17 +00:00
|
|
|
g_plugin_log.WriteLn("(USBnull) 32 bit read at address %lx", addr);
|
2016-08-24 21:11:25 +00:00
|
|
|
}
|
|
|
|
return value;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
EXPORT_C_(void)
|
|
|
|
USBwrite8(u32 addr, u8 value)
|
2009-05-02 02:29:48 +00:00
|
|
|
{
|
2016-08-24 21:11:25 +00:00
|
|
|
switch (addr) {
|
|
|
|
// Handle any appropriate addresses here.
|
|
|
|
case 0x1f801600:
|
2018-05-23 18:59:17 +00:00
|
|
|
g_plugin_log.WriteLn("(USBnull) 8 bit write at address %lx value %x", addr, value);
|
2016-08-24 21:11:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
//usbRu8(addr) = value;
|
2018-05-23 18:59:17 +00:00
|
|
|
g_plugin_log.WriteLn("(USBnull) 8 bit write at address %lx value %x", addr, value);
|
2016-08-24 21:11:25 +00:00
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
EXPORT_C_(void)
|
|
|
|
USBwrite16(u32 addr, u16 value)
|
2009-05-02 02:29:48 +00:00
|
|
|
{
|
2016-08-24 21:11:25 +00:00
|
|
|
switch (addr) {
|
|
|
|
// Handle any appropriate addresses here.
|
|
|
|
case 0x1f801600:
|
2018-05-23 18:59:17 +00:00
|
|
|
g_plugin_log.WriteLn("(USBnull) 16 bit write at address %lx value %x", addr, value);
|
2016-08-24 21:11:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
//usbRu16(addr) = value;
|
2018-05-23 18:59:17 +00:00
|
|
|
g_plugin_log.WriteLn("(USBnull) 16 bit write at address %lx value %x", addr, value);
|
2016-08-24 21:11:25 +00:00
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
EXPORT_C_(void)
|
|
|
|
USBwrite32(u32 addr, u32 value)
|
2009-05-02 02:29:48 +00:00
|
|
|
{
|
2016-08-24 21:11:25 +00:00
|
|
|
switch (addr) {
|
|
|
|
// Handle any appropriate addresses here.
|
|
|
|
case 0x1f801600:
|
2018-05-23 18:59:17 +00:00
|
|
|
g_plugin_log.WriteLn("(USBnull) 16 bit write at address %lx value %x", addr, value);
|
2016-08-24 21:11:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
//usbRu32(addr) = value;
|
2018-05-23 18:59:17 +00:00
|
|
|
g_plugin_log.WriteLn("(USBnull) 32 bit write at address %lx value %x", addr, value);
|
2016-08-24 21:11:25 +00:00
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
EXPORT_C_(void)
|
|
|
|
USBirqCallback(USBcallback callback)
|
2009-05-02 02:29:48 +00:00
|
|
|
{
|
2016-08-24 21:11:25 +00:00
|
|
|
// 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;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
EXPORT_C_(int)
|
|
|
|
_USBirqHandler(void)
|
2009-05-02 02:29:48 +00:00
|
|
|
{
|
2016-08-24 21:11:25 +00:00
|
|
|
// This is our USB irq handler, so if an interrupt gets triggered,
|
|
|
|
// deal with it here.
|
|
|
|
return 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
EXPORT_C_(USBhandler)
|
|
|
|
USBirqHandler(void)
|
2009-05-02 02:29:48 +00:00
|
|
|
{
|
2016-08-24 21:11:25 +00:00
|
|
|
// Pass our handler to pcsx2.
|
|
|
|
return (USBhandler)_USBirqHandler;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
EXPORT_C_(void)
|
2016-08-28 16:14:07 +00:00
|
|
|
USBsetRAM(void *mem)
|
2009-05-02 02:29:48 +00:00
|
|
|
{
|
2016-08-28 16:14:07 +00:00
|
|
|
ram = (s8 *)mem;
|
2018-05-23 18:59:17 +00:00
|
|
|
g_plugin_log.WriteLn("*Setting ram.");
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
EXPORT_C_(void)
|
2016-08-28 16:14:07 +00:00
|
|
|
USBsetSettingsDir(const char *dir)
|
2009-12-20 13:45:26 +00:00
|
|
|
{
|
2016-08-24 21:11:25 +00:00
|
|
|
// Get the path to the ini directory.
|
|
|
|
s_strIniPath = (dir == NULL) ? "inis" : dir;
|
2009-12-20 13:45:26 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
// extended funcs
|
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
EXPORT_C_(s32)
|
2016-08-28 16:14:07 +00:00
|
|
|
USBfreeze(int mode, freezeData *data)
|
2009-05-02 02:29:48 +00:00
|
|
|
{
|
2016-08-24 21:11:25 +00:00
|
|
|
// 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;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2010-01-09 05:11:18 +00:00
|
|
|
/*EXPORT_C_(void) USBasync(u32 cycles)
|
|
|
|
{
|
|
|
|
// Optional function: Called in IopCounter.cpp.
|
|
|
|
}*/
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2016-08-24 21:11:25 +00:00
|
|
|
EXPORT_C_(s32)
|
|
|
|
USBtest()
|
2009-05-02 02:29:48 +00:00
|
|
|
{
|
2016-08-24 21:11:25 +00:00
|
|
|
// 0 if the plugin works, non-0 if it doesn't.
|
|
|
|
return 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|