diff --git a/plugins/USBnull/Config.cpp b/plugins/USBnull/Config.cpp index 8858d6da14..cccc1a839f 100644 --- a/plugins/USBnull/Config.cpp +++ b/plugins/USBnull/Config.cpp @@ -25,55 +25,51 @@ PluginConf Ini; void setLoggingState() { - if (conf.Log) - { - USBLog.WriteToConsole = true; - USBLog.WriteToFile = true; - } - else - { - USBLog.WriteToConsole = false; - USBLog.WriteToFile = false; - } + if (conf.Log) { + USBLog.WriteToConsole = true; + USBLog.WriteToFile = true; + } else { + USBLog.WriteToConsole = false; + USBLog.WriteToFile = false; + } } -EXPORT_C_(void) USBabout() +EXPORT_C_(void) +USBabout() { - SysMessage("USBnull: A simple null plugin."); + SysMessage("USBnull: A simple null plugin."); } -EXPORT_C_(void) USBconfigure() +EXPORT_C_(void) +USBconfigure() { - LoadConfig(); - PluginNullConfigure("Since this is a null plugin, all that is really configurable is logging.", conf.Log); - SaveConfig(); + LoadConfig(); + PluginNullConfigure("Since this is a null plugin, all that is really configurable is logging.", conf.Log); + SaveConfig(); } void LoadConfig() { - string IniPath = s_strIniPath + "/USBnull.ini"; - if (!Ini.Open(IniPath, READ_FILE)) - { - USBLog.WriteLn("Failed to open %s", IniPath.c_str()); - SaveConfig(); - return; - } + string IniPath = s_strIniPath + "/USBnull.ini"; + if (!Ini.Open(IniPath, READ_FILE)) { + USBLog.WriteLn("Failed to open %s", IniPath.c_str()); + SaveConfig(); + return; + } - conf.Log = Ini.ReadInt("logging", 0); - setLoggingState(); - Ini.Close(); + conf.Log = Ini.ReadInt("logging", 0); + setLoggingState(); + Ini.Close(); } void SaveConfig() { - string IniPath = s_strIniPath + "/USBnull.ini"; - if (!Ini.Open(IniPath, WRITE_FILE)) - { - USBLog.WriteLn("Failed to open %s", IniPath.c_str()); - return; - } + string IniPath = s_strIniPath + "/USBnull.ini"; + if (!Ini.Open(IniPath, WRITE_FILE)) { + USBLog.WriteLn("Failed to open %s", IniPath.c_str()); + return; + } - Ini.WriteInt("logging", conf.Log); - Ini.Close(); + Ini.WriteInt("logging", conf.Log); + Ini.Close(); } - diff --git a/plugins/USBnull/USB.cpp b/plugins/USBnull/USB.cpp index 58ea4d6960..590a642be0 100644 --- a/plugins/USBnull/USB.cpp +++ b/plugins/USBnull/USB.cpp @@ -18,12 +18,12 @@ using namespace std; #include "svnrev.h" #include "USB.h" -string s_strIniPath="inis"; -string s_strLogPath="logs"; +string s_strIniPath = "inis"; +string s_strLogPath = "logs"; -const unsigned char version = PS2E_USB_VERSION; +const unsigned char version = PS2E_USB_VERSION; const unsigned char revision = 0; -const unsigned char build = 7; // increase that with each version +const unsigned char build = 7; // increase that with each version #ifdef _MSC_VER #define snprintf sprintf_s @@ -38,233 +38,245 @@ s8 *usbregs, *ram; void LogInit() { - const std::string LogFile(s_strLogPath + "/USBnull.log"); - setLoggingState(); - USBLog.Open(LogFile); + const std::string LogFile(s_strLogPath + "/USBnull.log"); + setLoggingState(); + USBLog.Open(LogFile); } -EXPORT_C_(void) USBsetLogDir(const char* dir) +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(); + // 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() +EXPORT_C_(u32) +PS2EgetLibType() { - return PS2E_LT_USB; + return PS2E_LT_USB; } -EXPORT_C_(char*) PS2EgetLibName() +EXPORT_C_(char*) +PS2EgetLibName() { - snprintf( libraryName, 255, "USBnull Driver %lld%s",SVN_REV, SVN_MODS ? "m" : ""); - return libraryName; + snprintf(libraryName, 255, "USBnull Driver %lld%s", SVN_REV, SVN_MODS ? "m" : ""); + return libraryName; } -EXPORT_C_(u32) PS2EgetLibVersion2(u32 type) +EXPORT_C_(u32) +PS2EgetLibVersion2(u32 type) { - return (version << 16) | (revision << 8) | build; + return (version << 16) | (revision << 8) | build; } -EXPORT_C_(s32) USBinit() +EXPORT_C_(s32) +USBinit() { - LoadConfig(); - LogInit(); - USBLog.WriteLn("USBnull plugin version %d,%d", revision, build); - USBLog.WriteLn("Initializing USBnull"); + LoadConfig(); + LogInit(); + USBLog.WriteLn("USBnull plugin version %d,%d", revision, build); + USBLog.WriteLn("Initializing USBnull"); - // Initialize memory structures here. - usbregs = (s8*)calloc(0x10000, 1); + // Initialize memory structures here. + usbregs = (s8*)calloc(0x10000, 1); - if (usbregs == NULL) - { - USBLog.Message("Error allocating memory"); - return -1; - } + if (usbregs == NULL) { + USBLog.Message("Error allocating memory"); + return -1; + } - return 0; + return 0; } -EXPORT_C_(void) USBshutdown() +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; + // 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) +EXPORT_C_(s32) +USBopen(void* pDsp) { - USBLog.WriteLn("Opening USBnull."); + USBLog.WriteLn("Opening USBnull."); - // Take care of anything else we need on opening, other then initialization. - return 0; + // Take care of anything else we need on opening, other then initialization. + return 0; } -EXPORT_C_(void) USBclose() +EXPORT_C_(void) +USBclose() { - USBLog.WriteLn("Closing USBnull."); + 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) +EXPORT_C_(u8) +USBread8(u32 addr) { - u8 value = 0; + u8 value = 0; - switch(addr) - { - // Handle any appropriate addresses here. - case 0x1f801600: - USBLog.WriteLn("(USBnull) 8 bit read at address %lx", addr); - break; + 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; + default: + //value = usbRu8(addr); + USBLog.WriteLn("*(USBnull) 8 bit read at address %lx", addr); + break; + } + return value; } -EXPORT_C_(u16) USBread16(u32 addr) +EXPORT_C_(u16) +USBread16(u32 addr) { - u16 value = 0; + u16 value = 0; - switch(addr) - { - // Handle any appropriate addresses here. - case 0x1f801600: - USBLog.WriteLn("(USBnull) 16 bit read at address %lx", addr); - break; + 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; + default: + //value = usbRu16(addr); + USBLog.WriteLn("(USBnull) 16 bit read at address %lx", addr); + } + return value; } -EXPORT_C_(u32) USBread32(u32 addr) +EXPORT_C_(u32) +USBread32(u32 addr) { - u32 value = 0; + u32 value = 0; - switch(addr) - { - // Handle any appropriate addresses here. - case 0x1f801600: - USBLog.WriteLn("(USBnull) 32 bit read at address %lx", addr); - break; + 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; + default: + //value = usbRu32(addr); + USBLog.WriteLn("(USBnull) 32 bit read at address %lx", addr); + } + return value; } -EXPORT_C_(void) USBwrite8(u32 addr, u8 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; + 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); - } + 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) +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; + 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); - } + 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) +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; + 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); - } + default: + //usbRu32(addr) = value; + USBLog.WriteLn("(USBnull) 32 bit write at address %lx value %x", addr, value); + } } -EXPORT_C_(void) USBirqCallback(USBcallback callback) +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; + // 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) +EXPORT_C_(int) +_USBirqHandler(void) { - // This is our USB irq handler, so if an interrupt gets triggered, - // deal with it here. - return 0; + // This is our USB irq handler, so if an interrupt gets triggered, + // deal with it here. + return 0; } -EXPORT_C_(USBhandler) USBirqHandler(void) +EXPORT_C_(USBhandler) +USBirqHandler(void) { - // Pass our handler to pcsx2. - return (USBhandler)_USBirqHandler; + // Pass our handler to pcsx2. + return (USBhandler)_USBirqHandler; } -EXPORT_C_(void) USBsetRAM(void *mem) +EXPORT_C_(void) +USBsetRAM(void* mem) { - ram = (s8*)mem; - USBLog.WriteLn("*Setting ram."); + ram = (s8*)mem; + USBLog.WriteLn("*Setting ram."); } -EXPORT_C_(void) USBsetSettingsDir(const char* dir) +EXPORT_C_(void) +USBsetSettingsDir(const char* dir) { - // Get the path to the ini directory. - s_strIniPath = (dir==NULL) ? "inis" : dir; + // Get the path to the ini directory. + s_strIniPath = (dir == NULL) ? "inis" : dir; } // extended funcs -EXPORT_C_(s32) USBfreeze(int mode, freezeData *data) +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; + // 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) @@ -272,10 +284,11 @@ EXPORT_C_(s32) USBfreeze(int mode, freezeData *data) // Optional function: Called in IopCounter.cpp. }*/ -EXPORT_C_(s32) USBtest() +EXPORT_C_(s32) +USBtest() { - // 0 if the plugin works, non-0 if it doesn't. - return 0; + // 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. */ diff --git a/plugins/USBnull/USB.h b/plugins/USBnull/USB.h index cd260734ca..4bd6d633b2 100644 --- a/plugins/USBnull/USB.h +++ b/plugins/USBnull/USB.h @@ -22,24 +22,25 @@ #include "PS2Edefs.h" #include "PS2Eext.h" -typedef struct { - int Log; +typedef struct +{ + int Log; } Config; extern USBcallback USBirq; extern Config conf; // Previous USB plugins have needed this in ohci. -static const s64 PSXCLK = 36864000; /* 36.864 Mhz */ +static const s64 PSXCLK = 36864000; /* 36.864 Mhz */ extern s8 *usbregs, *ram; -#define usbRs8(mem) usbregs[(mem) & 0xffff] -#define usbRs16(mem) (*(s16*)&usbregs[(mem) & 0xffff]) -#define usbRs32(mem) (*(s32*)&usbregs[(mem) & 0xffff]) -#define usbRu8(mem) (*(u8*) &usbregs[(mem) & 0xffff]) -#define usbRu16(mem) (*(u16*)&usbregs[(mem) & 0xffff]) -#define usbRu32(mem) (*(u32*)&usbregs[(mem) & 0xffff]) +#define usbRs8(mem) usbregs[(mem)&0xffff] +#define usbRs16(mem) (*(s16*)&usbregs[(mem)&0xffff]) +#define usbRs32(mem) (*(s32*)&usbregs[(mem)&0xffff]) +#define usbRu8(mem) (*(u8*)&usbregs[(mem)&0xffff]) +#define usbRu16(mem) (*(u16*)&usbregs[(mem)&0xffff]) +#define usbRu32(mem) (*(u32*)&usbregs[(mem)&0xffff]) extern void SaveConfig(); extern void LoadConfig(); diff --git a/plugins/USBnull/Windows/Config.cpp b/plugins/USBnull/Windows/Config.cpp index 6c210ec2c9..437b233f71 100644 --- a/plugins/USBnull/Windows/Config.cpp +++ b/plugins/USBnull/Windows/Config.cpp @@ -21,46 +21,45 @@ extern HINSTANCE hInst; void SaveConfig() { - Config *Conf1 = &conf; - char *szTemp; - char szIniFile[256], szValue[256]; + Config* Conf1 = &conf; + char* szTemp; + char szIniFile[256], szValue[256]; - GetModuleFileName(GetModuleHandle((LPCSTR)hInst), szIniFile, 256); - szTemp = strrchr(szIniFile, '\\'); - - if(!szTemp) return; - strcpy(szTemp, "\\inis\\usbnull.ini"); - sprintf(szValue,"%u",Conf1->Log); - WritePrivateProfileString("Interface", "Logging",szValue,szIniFile); + GetModuleFileName(GetModuleHandle((LPCSTR)hInst), szIniFile, 256); + szTemp = strrchr(szIniFile, '\\'); + if (!szTemp) + return; + strcpy(szTemp, "\\inis\\usbnull.ini"); + sprintf(szValue, "%u", Conf1->Log); + WritePrivateProfileString("Interface", "Logging", szValue, szIniFile); } -void LoadConfig() { - FILE *fp; +void LoadConfig() +{ + FILE* fp; - Config *Conf1 = &conf; - char *szTemp; - char szIniFile[256], szValue[256]; + Config* Conf1 = &conf; + char* szTemp; + char szIniFile[256], szValue[256]; - GetModuleFileName(GetModuleHandle((LPCSTR)hInst), szIniFile, 256); - szTemp = strrchr(szIniFile, '\\'); + GetModuleFileName(GetModuleHandle((LPCSTR)hInst), szIniFile, 256); + szTemp = strrchr(szIniFile, '\\'); - if(!szTemp) return ; - strcpy(szTemp, "\\inis\\usbnull.ini"); - fp=fopen("inis\\usbnull.ini","rt");//check if usbnull.ini really exists - if (!fp) - { - CreateDirectory("inis",NULL); + if (!szTemp) + return; + strcpy(szTemp, "\\inis\\usbnull.ini"); + fp = fopen("inis\\usbnull.ini", "rt"); //check if usbnull.ini really exists + if (!fp) { + CreateDirectory("inis", NULL); memset(&conf, 0, sizeof(conf)); - conf.Log = 0;//default value - SaveConfig();//save and return - return ; - } - fclose(fp); - GetPrivateProfileString("Interface", "Logging", NULL, szValue, 20, szIniFile); - Conf1->Log = strtoul(szValue, NULL, 10); - return ; - + conf.Log = 0; //default value + SaveConfig(); //save and return + return; + } + fclose(fp); + GetPrivateProfileString("Interface", "Logging", NULL, szValue, 20, szIniFile); + Conf1->Log = strtoul(szValue, NULL, 10); + return; } - diff --git a/plugins/USBnull/Windows/Win32.cpp b/plugins/USBnull/Windows/Win32.cpp index 5d4c54be31..806126587d 100644 --- a/plugins/USBnull/Windows/Win32.cpp +++ b/plugins/USBnull/Windows/Win32.cpp @@ -22,75 +22,81 @@ HINSTANCE hInst; -void SysMessage(char *fmt, ...) { - va_list list; - char tmp[512]; +void SysMessage(char* fmt, ...) +{ + va_list list; + char tmp[512]; - va_start(list,fmt); - vsprintf(tmp,fmt,list); - va_end(list); - MessageBox(GetActiveWindow(), tmp, "USBnull Msg", MB_SETFOREGROUND | MB_OK); + va_start(list, fmt); + vsprintf(tmp, fmt, list); + va_end(list); + MessageBox(GetActiveWindow(), tmp, "USBnull Msg", MB_SETFOREGROUND | MB_OK); } -BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { +BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ - switch(uMsg) { - case WM_INITDIALOG: - LoadConfig(); - if (conf.Log) CheckDlgButton(hW, IDC_LOGGING, TRUE); - return TRUE; + switch (uMsg) { + case WM_INITDIALOG: + LoadConfig(); + if (conf.Log) + CheckDlgButton(hW, IDC_LOGGING, TRUE); + return TRUE; - case WM_COMMAND: - switch(LOWORD(wParam)) { - case IDCANCEL: - EndDialog(hW, TRUE); - return TRUE; - case IDOK: - if (IsDlgButtonChecked(hW, IDC_LOGGING)) - conf.Log = 1; - else conf.Log = 0; - SaveConfig(); - EndDialog(hW, FALSE); - return TRUE; - } - } - return FALSE; + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDCANCEL: + EndDialog(hW, TRUE); + return TRUE; + case IDOK: + if (IsDlgButtonChecked(hW, IDC_LOGGING)) + conf.Log = 1; + else + conf.Log = 0; + SaveConfig(); + EndDialog(hW, FALSE); + return TRUE; + } + } + return FALSE; } -BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { - switch(uMsg) { - case WM_INITDIALOG: - return TRUE; +BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (uMsg) { + case WM_INITDIALOG: + return TRUE; - case WM_COMMAND: - switch(LOWORD(wParam)) { - case IDOK: - EndDialog(hW, FALSE); - return TRUE; - } - } - return FALSE; + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDOK: + EndDialog(hW, FALSE); + return TRUE; + } + } + return FALSE; } -void CALLBACK USBconfigure() { +void CALLBACK USBconfigure() +{ DialogBox(hInst, MAKEINTRESOURCE(IDD_CONFIG), GetActiveWindow(), (DLGPROC)ConfigureDlgProc); - } -void CALLBACK USBabout() { +void CALLBACK USBabout() +{ DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), GetActiveWindow(), (DLGPROC)AboutDlgProc); } -BOOL APIENTRY DllMain(HANDLE hModule, // DLL INIT - DWORD dwReason, - LPVOID lpReserved) { - hInst = (HINSTANCE)hModule; - return TRUE; // very quick :) +BOOL APIENTRY DllMain(HANDLE hModule, // DLL INIT + DWORD dwReason, + LPVOID lpReserved) +{ + hInst = (HINSTANCE)hModule; + return TRUE; // very quick :) } -