From 20f5dbde3d17c6a823a6814e06a619b7d6cfca5f Mon Sep 17 00:00:00 2001 From: arcum42 Date: Sat, 9 Jan 2010 05:11:18 +0000 Subject: [PATCH] FWnull & USBnull have been converted to use PS2Enull.h as well. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2420 96395faa-99c1-11dd-bbfe-3dabce05a288 --- plugins/FWnull/Config.cpp | 89 +++++++ plugins/FWnull/{Linux => }/Config.h | 2 +- plugins/FWnull/FW.cpp | 91 ++++--- plugins/FWnull/FW.h | 33 +-- plugins/FWnull/Linux/Config.cpp | 168 ------------ plugins/FWnull/Linux/FWnull.cbp | 11 +- plugins/FWnull/Linux/callbacks.c | 34 --- plugins/FWnull/Linux/callbacks.h | 14 - plugins/FWnull/Linux/firewire.glade | 241 ------------------ plugins/FWnull/Linux/interface.c | 173 ------------- plugins/FWnull/Linux/interface.h | 6 - plugins/FWnull/Linux/support.c | 144 ----------- plugins/FWnull/Linux/support.h | 69 ----- plugins/FWnull/Windows/FWnull_vc2008.vcproj | 12 +- plugins/USBnull/Config.cpp | 82 ++++++ plugins/USBnull/{Linux/Linux.h => Config.h} | 3 + plugins/USBnull/Linux/Config.cpp | 169 ------------ plugins/USBnull/Linux/Config.h | 24 -- plugins/USBnull/Linux/Linux.cpp | 53 ---- plugins/USBnull/Linux/USBnull.cbp | 20 +- plugins/USBnull/Linux/callbacks.c | 34 --- plugins/USBnull/Linux/callbacks.h | 14 - plugins/USBnull/Linux/interface.c | 172 ------------- plugins/USBnull/Linux/interface.h | 6 - plugins/USBnull/Linux/support.c | 144 ----------- plugins/USBnull/Linux/support.h | 69 ----- plugins/USBnull/Linux/usbnull.glade | 241 ------------------ plugins/USBnull/USB.cpp | 157 +++++++++--- plugins/USBnull/USB.h | 50 +--- plugins/USBnull/Windows/USBnull_vc2008.vcproj | 14 +- plugins/dev9null/Config.cpp | 18 +- plugins/dev9null/DEV9.cpp | 4 +- plugins/dev9null/DEV9.h | 2 + 33 files changed, 391 insertions(+), 1972 deletions(-) create mode 100644 plugins/FWnull/Config.cpp rename plugins/FWnull/{Linux => }/Config.h (96%) delete mode 100644 plugins/FWnull/Linux/Config.cpp delete mode 100644 plugins/FWnull/Linux/callbacks.c delete mode 100644 plugins/FWnull/Linux/callbacks.h delete mode 100644 plugins/FWnull/Linux/firewire.glade delete mode 100644 plugins/FWnull/Linux/interface.c delete mode 100644 plugins/FWnull/Linux/interface.h delete mode 100644 plugins/FWnull/Linux/support.c delete mode 100644 plugins/FWnull/Linux/support.h create mode 100644 plugins/USBnull/Config.cpp rename plugins/USBnull/{Linux/Linux.h => Config.h} (95%) delete mode 100644 plugins/USBnull/Linux/Config.cpp delete mode 100644 plugins/USBnull/Linux/Config.h delete mode 100644 plugins/USBnull/Linux/Linux.cpp delete mode 100644 plugins/USBnull/Linux/callbacks.c delete mode 100644 plugins/USBnull/Linux/callbacks.h delete mode 100644 plugins/USBnull/Linux/interface.c delete mode 100644 plugins/USBnull/Linux/interface.h delete mode 100644 plugins/USBnull/Linux/support.c delete mode 100644 plugins/USBnull/Linux/support.h delete mode 100644 plugins/USBnull/Linux/usbnull.glade diff --git a/plugins/FWnull/Config.cpp b/plugins/FWnull/Config.cpp new file mode 100644 index 0000000000..341192d52c --- /dev/null +++ b/plugins/FWnull/Config.cpp @@ -0,0 +1,89 @@ +/* FWnull + * Copyright (C) 2004-2009 PCSX2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +#include "FW.h" +#include "Config.h" + +extern string s_strIniPath; +extern PluginLog FWLog; +PluginConf Ini; + +void setLoggingState() +{ + if (conf.Log) + { + FWLog.WriteToConsole = true; + FWLog.WriteToFile = true; + } + else + { + FWLog.WriteToConsole = false; + FWLog.WriteToFile = false; + } +} + +EXPORT_C_(void) FWabout() +{ + SysMessage("FWnull: A simple null plugin."); +} + +EXPORT_C_(void) FWconfigure() +{ + LoadConfig(); + PluginNullConfigure("Since this is a null plugin, all that is really configurable is logging.", conf.Log); + SaveConfig(); +} + +void LoadConfig() +{ + string IniPath = s_strIniPath + "/FWnull.ini"; + if (!Ini.Open(IniPath, READ_FILE)) + { + FWLog.WriteLn("Failed to open %s", IniPath.c_str()); + SaveConfig(); + return; + } + + conf.Log = Ini.ReadInt("logging"); + setLoggingState(); + Ini.Close(); +} + +void SaveConfig() +{ + string IniPath = s_strIniPath + "/FWnull.ini"; + if (!Ini.Open(IniPath, WRITE_FILE)) + { + FWLog.WriteLn("Failed to open %s\n", IniPath.c_str()); + return; + } + + Ini.WriteInt("logging", conf.Log); + Ini.Close(); +} + diff --git a/plugins/FWnull/Linux/Config.h b/plugins/FWnull/Config.h similarity index 96% rename from plugins/FWnull/Linux/Config.h rename to plugins/FWnull/Config.h index 7251ed01eb..7147aed80c 100644 --- a/plugins/FWnull/Linux/Config.h +++ b/plugins/FWnull/Config.h @@ -18,7 +18,7 @@ void SaveConf(); void LoadConf(); -void SysMessage(char *fmt, ...); +void SysMessage(const char *fmt, ...); #define is_checked(main_widget, widget_name) (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(main_widget, widget_name)))) #define set_checked(main_widget,widget_name, state) gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(lookup_widget(main_widget, widget_name)), state) diff --git a/plugins/FWnull/FW.cpp b/plugins/FWnull/FW.cpp index c8a4067313..3fa7667e5b 100644 --- a/plugins/FWnull/FW.cpp +++ b/plugins/FWnull/FW.cpp @@ -17,25 +17,23 @@ */ #include -#include -#include #include using namespace std; - #include "FW.h" const u8 version = PS2E_FW_VERSION; const u8 revision = 0; -const u8 build = 5; // increase that with each version +const u8 build = 6; // increase that with each version static char *libraryName = "FWnull Driver"; -s8 *fwregs; -FILE *fwLog; -Config conf; string s_strIniPath="inis/"; +s8 *fwregs; +Config conf; +PluginLog FWLog; + void (*FWirq)(); EXPORT_C_(u32) PS2EgetLibType() @@ -53,58 +51,43 @@ EXPORT_C_(u32) PS2EgetLibVersion2(u32 type) return (version<<16) | (revision<<8) | build; } -void __Log(char *fmt, ...) -{ - va_list list; - - if (!conf.Log || fwLog == NULL) return; - - va_start(list, fmt); - vfprintf(fwLog, fmt, list); - va_end(list); -} - EXPORT_C_(s32) FWinit() { LoadConfig(); - -#ifdef FW_LOG - fwLog = fopen("logs/fwLog.txt", "w"); - if (fwLog) setvbuf(fwLog, NULL, _IONBF, 0); - FW_LOG("FWnull plugin version %d,%d\n",revision,build); - FW_LOG("FW init\n"); -#endif + setLoggingState(); + FWLog.Open("logs/FWnull.log"); + FWLog.WriteLn("FWnull plugin version %d,%d", revision, build); + FWLog.WriteLn("Initializing FWnull"); + // Initializing our registers. fwregs = (s8*)malloc(0x10000); if (fwregs == NULL) { - SysMessage("Error allocating Memory\n"); + FWLog.Message("Error allocating Memory"); return -1; } - + memset(fwregs, 0, 0x10000); return 0; } EXPORT_C_(void) FWshutdown() { + // Freeing the registers. free(fwregs); - -#ifdef FW_LOG - if (fwLog) fclose(fwLog); -#endif + FWLog.Close(); } EXPORT_C_(s32) FWopen(void *pDsp) { -#ifdef FW_LOG - FW_LOG("FW open\n"); -#endif + FWLog.WriteLn("Opening FWnull."); return 0; } EXPORT_C_(void) FWclose() { + // Close the plugin. + FWLog.WriteLn("Closing FWnull."); } EXPORT_C_(u32) FWread32(u32 addr) @@ -113,16 +96,19 @@ EXPORT_C_(u32) FWread32(u32 addr) switch (addr) { + // We should document what this location is. case 0x1f808410: ret = 0x8; break; - + + // Include other relevant 32 bit addresses we need to catch here. default: + // By default, read fwregs. ret = fwRu32(addr); break; } - FW_LOG("FW read mem 0x%x: 0x%x\n", addr, ret); + FWLog.WriteLn("FW read mem 0x%x: 0x%x", addr, ret); return ret; } @@ -131,29 +117,58 @@ EXPORT_C_(void) FWwrite32(u32 addr, u32 value) { switch (addr) { +// Include other memory locations we want to catch here. +// For example: +// +// case 0x1f808400: +// case 0x1f808414: +// case 0x1f808420: +// case 0x1f808428: +// case 0x1f808430: +// +// Are addresses to look at. + case 0x1f808410: fwRu32(addr) = value; break; default: + // By default, just write it to fwregs. fwRu32(addr) = value; break; } - FW_LOG("FW write mem 0x%x: 0x%x\n", addr, value); + FWLog.WriteLn("FW write mem 0x%x: 0x%x", addr, value); } EXPORT_C_(void) FWirqCallback(void (*callback)()) { + // Register FWirq, so we can trigger an interrupt with it later. FWirq = callback; } EXPORT_C_(void) FWsetSettingsDir(const char* dir) { - s_strIniPath = (dir==NULL) ? "inis/" : dir; + // Find out from pcsx2 where we are supposed to put our ini file. + s_strIniPath = (dir == NULL) ? "inis/" : dir; } EXPORT_C_(s32) FWfreeze(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_(s32) FWtest() { + // 0 if the plugin works, non-0 if it doesn't. return 0; } diff --git a/plugins/FWnull/FW.h b/plugins/FWnull/FW.h index 9539852eb1..b8788eceac 100644 --- a/plugins/FWnull/FW.h +++ b/plugins/FWnull/FW.h @@ -23,33 +23,10 @@ #define FWdefs #include "PS2Edefs.h" +#include "PS2Eext.h" -#ifdef _WIN32 - -#include -#include - -#else - -#include -#include - -#endif - -/*#ifdef _MSC_VER -#define EXPORT_C_(type) extern "C" __declspec(dllexport) type CALLBACK -#else -#define EXPORT_C_(type) extern "C" type -#endif*/ - -#ifdef _MSC_VER -#define EXPORT_C_(type) extern "C" type CALLBACK -#else -#define EXPORT_C_(type) extern "C" type -#endif - -#define FW_LOG __Log - +// Our main memory storage, and defines for accessing it. +extern s8 *fwregs; #define fwRs32(mem) (*(s32*)&fwregs[(mem) & 0xffff]) #define fwRu32(mem) (*(u32*)&fwregs[(mem) & 0xffff]) @@ -59,13 +36,11 @@ typedef struct } Config; extern Config conf; -extern FILE *fwLog; extern void (*FWirq)(); -extern void __Log(char *fmt, ...); -extern void SysMessage(char *fmt, ...); extern void SaveConfig(); extern void LoadConfig(); +extern void setLoggingState(); #endif diff --git a/plugins/FWnull/Linux/Config.cpp b/plugins/FWnull/Linux/Config.cpp deleted file mode 100644 index c40b4055e8..0000000000 --- a/plugins/FWnull/Linux/Config.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* FWnull - * Copyright (C) 2004-2009 PCSX2 Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -#include "FW.h" -#include "Config.h" - - #ifdef __cplusplus -extern "C" -{ -#endif - -#include "support.h" -#include "callbacks.h" -#include "interface.h" - -#ifdef __cplusplus -} -#endif - -GtkWidget *MsgDlg, *About, *Conf; -extern string s_strIniPath; - -void OnMsg_Ok() -{ - gtk_widget_destroy(MsgDlg); - gtk_main_quit(); -} - -void SysMessage(char *fmt, ...) -{ - GtkWidget *Ok,*Txt; - GtkWidget *Box,*Box1; - va_list list; - char msg[512]; - - va_start(list, fmt); - vsprintf(msg, fmt, list); - va_end(list); - - if (msg[strlen(msg) - 1] == '\n') msg[strlen(msg)-1] = 0; - - MsgDlg = gtk_window_new (GTK_WINDOW_POPUP); - gtk_window_set_position(GTK_WINDOW(MsgDlg), GTK_WIN_POS_CENTER); - gtk_window_set_title(GTK_WINDOW(MsgDlg), "FireWire Msg"); - gtk_container_set_border_width(GTK_CONTAINER(MsgDlg), 5); - - Box = gtk_vbox_new(5, 0); - gtk_container_add(GTK_CONTAINER(MsgDlg), Box); - gtk_widget_show(Box); - - Txt = gtk_label_new(msg); - - gtk_box_pack_start(GTK_BOX(Box), Txt, FALSE, FALSE, 5); - gtk_widget_show(Txt); - - Box1 = gtk_hbutton_box_new(); - gtk_box_pack_start(GTK_BOX(Box), Box1, FALSE, FALSE, 0); - gtk_widget_show(Box1); - - Ok = gtk_button_new_with_label("Ok"); - gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnMsg_Ok), NULL); - gtk_container_add(GTK_CONTAINER(Box1), Ok); - GTK_WIDGET_SET_FLAGS(Ok, GTK_CAN_DEFAULT); - gtk_widget_show(Ok); - - gtk_widget_show(MsgDlg); - - gtk_main(); -} - -void OnAbout_Ok(GtkButton *button, gpointer user_data) -{ - gtk_widget_destroy(About); - gtk_main_quit(); -} - -EXPORT_C_(void) FWabout() -{ - About = create_About(); - gtk_widget_show_all(About); - gtk_main(); -} - -void OnConf_Ok(GtkButton *button, gpointer user_data) -{ - conf.Log = is_checked(Conf, "check_logging"); - SaveConfig(); - - gtk_widget_destroy(Conf); - gtk_main_quit(); -} - -void OnConf_Cancel(GtkButton *button, gpointer user_data) -{ - gtk_widget_destroy(Conf); - gtk_main_quit(); -} - -EXPORT_C_(void) FWconfigure() -{ - LoadConfig(); - Conf = create_Config(); - - set_checked(Conf, "check_logging", conf.Log); - gtk_widget_show_all(Conf); - gtk_main(); -} - -void LoadConfig() -{ - FILE *f; - char cfg[255]; - - strcpy(cfg, s_strIniPath.c_str()); - f = fopen(cfg, "r"); - if (f == NULL) - { - printf("failed to open %s\n", s_strIniPath.c_str()); - SaveConfig();//save and return - return; - } - fscanf(f, "logging = %hhx\n", &conf.Log); - //fscanf(f, "options = %hhx\n", &confOptions); - fclose(f); -} - -void SaveConfig() -{ - FILE *f; - char cfg[255]; - - strcpy(cfg, s_strIniPath.c_str()); - f = fopen(cfg,"w"); - if (f == NULL) - { - printf("failed to open '%s'\n", s_strIniPath.c_str()); - return; - } - fprintf(f, "logging = %hhx\n", conf.Log); - //fprintf(f, "options = %hhx\n", confOptions); - fclose(f); -} - diff --git a/plugins/FWnull/Linux/FWnull.cbp b/plugins/FWnull/Linux/FWnull.cbp index 7f08234eef..94387a5a64 100644 --- a/plugins/FWnull/Linux/FWnull.cbp +++ b/plugins/FWnull/Linux/FWnull.cbp @@ -7,7 +7,7 @@