From c307caffdc5a9569aae862c51d23a0e1491017f0 Mon Sep 17 00:00:00 2001 From: arcum42 Date: Sat, 9 Jan 2010 02:04:07 +0000 Subject: [PATCH] Convert DEV9null over to use the new header, as a test case. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2418 96395faa-99c1-11dd-bbfe-3dabce05a288 --- plugins/dev9null/Config.cpp | 67 +++ plugins/dev9null/{Linux => }/Config.h | 6 +- plugins/dev9null/DEV9.cpp | 221 +++++--- plugins/dev9null/DEV9.h | 37 +- plugins/dev9null/Linux/Config.cpp | 169 ------ plugins/dev9null/Linux/Dev9null.cbp | 15 +- plugins/dev9null/Linux/callbacks.c | 34 -- plugins/dev9null/Linux/callbacks.h | 14 - plugins/dev9null/Linux/dev9.glade | 509 ------------------ plugins/dev9null/Linux/interface.c | 271 ---------- plugins/dev9null/Linux/interface.h | 6 - plugins/dev9null/Linux/support.c | 144 ----- plugins/dev9null/Linux/support.h | 69 --- .../dev9null/Windows/DEV9null_vc2008.vcproj | 8 + 14 files changed, 243 insertions(+), 1327 deletions(-) create mode 100644 plugins/dev9null/Config.cpp rename plugins/dev9null/{Linux => }/Config.h (71%) delete mode 100644 plugins/dev9null/Linux/Config.cpp delete mode 100644 plugins/dev9null/Linux/callbacks.c delete mode 100644 plugins/dev9null/Linux/callbacks.h delete mode 100644 plugins/dev9null/Linux/dev9.glade delete mode 100644 plugins/dev9null/Linux/interface.c delete mode 100644 plugins/dev9null/Linux/interface.h delete mode 100644 plugins/dev9null/Linux/support.c delete mode 100644 plugins/dev9null/Linux/support.h diff --git a/plugins/dev9null/Config.cpp b/plugins/dev9null/Config.cpp new file mode 100644 index 0000000000..dcd72ba2d1 --- /dev/null +++ b/plugins/dev9null/Config.cpp @@ -0,0 +1,67 @@ +/* DEV9null + * Copyright (C) 2002-2010 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 +using namespace std; + +#include "Config.h" +#include "DEV9.h" + +extern string s_strIniPath; +extern PluginLog Dev9Log; +PluginConf Ini; + +EXPORT_C_(void) DEV9about() +{ + SysMessage("Dev9null: A simple null plugin."); +} + +EXPORT_C_(void) DEV9configure() +{ + LoadConfig(); + PluginNullConfigure("Since this is a null plugin, all that is really configurable is logging.", conf.Log); + SaveConfig(); +} + +void LoadConfig() +{ + string IniPath = s_strIniPath + "/Dev9null.ini"; + if (!Ini.Open(IniPath, READ_FILE)) + { + Dev9Log.WriteLn("Failed to open %s\n", IniPath.c_str()); + SaveConfig(); + return; + } + + conf.Log = Ini.ReadInt("logging"); + Ini.Close(); +} + +void SaveConfig() +{ + string IniPath = s_strIniPath + "/Dev9null.ini"; + if (!Ini.Open(IniPath, WRITE_FILE)) + { + Dev9Log.WriteLn("Failed to open %s\n", IniPath.c_str()); + return; + } + + Ini.WriteInt("logging", conf.Log); + Ini.Close(); +} + diff --git a/plugins/dev9null/Linux/Config.h b/plugins/dev9null/Config.h similarity index 71% rename from plugins/dev9null/Linux/Config.h rename to plugins/dev9null/Config.h index a5de746902..44732301a6 100644 --- a/plugins/dev9null/Linux/Config.h +++ b/plugins/dev9null/Config.h @@ -1,5 +1,5 @@ /* dev9null - * Copyright (C) 2004-2009 PCSX2 Team + * Copyright (C) 2002-2010 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 @@ -20,5 +20,5 @@ void SaveConfig(); void LoadConfig(); void SysMessage(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) +//#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/dev9null/DEV9.cpp b/plugins/dev9null/DEV9.cpp index 8f00f29c8c..55c769d94d 100644 --- a/plugins/dev9null/DEV9.cpp +++ b/plugins/dev9null/DEV9.cpp @@ -1,5 +1,5 @@ /* DEV9null - * Copyright (C) 2002-2009 PCSX2 Dev Team + * 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- @@ -13,6 +13,17 @@ * If not, see . */ +// Note: I was using MegaDev9, dev9ghzdrk, and dev9linuz for reference on memory locations. +// The ones I included were just some of the more important ones, so you may want to look +// at the plugins I mentioned if trying to create your own dev9 plugin. + +// Additionally, there is a lot of information in the ps2drv drivers by Marcus R. Brown, so +// looking through its code would be a good starting point. + +// Look under tags/plugins in svn for any older plugins that aren't included in pcsx2 any more. +// --arcum42 + + #include #include #include @@ -23,14 +34,18 @@ using namespace std; const unsigned char version = PS2E_DEV9_VERSION; const unsigned char revision = 0; -const unsigned char build = 4; // increase that with each version +const unsigned char build = 5; // increase that with each version const char *libraryName = "DEV9null Driver"; +// Our IRQ call. void (*DEV9irq)(int); -FILE *dev9Log; + +__aligned16 s8 dev9regs[0x10000]; + +string s_strIniPath = "inis/"; +PluginLog Dev9Log; Config conf; -string s_strIniPath="inis/"; EXPORT_C_(u32) PS2EgetLibType() { @@ -47,106 +62,183 @@ EXPORT_C_(u32) PS2EgetLibVersion2(u32 type) return (version<<16) | (revision<<8) | build; } -void __Log(char *fmt, ...) -{ - va_list list; - - if (!conf.Log || dev9Log == NULL) return; - - va_start(list, fmt); - vfprintf(dev9Log, fmt, list); - va_end(list); -} - EXPORT_C_(s32) DEV9init() { -#ifdef __LINUX__ // for until we get a win32 version sorted out / implemented... + // We don't have a Windows version of LoadConfig. That needs correcting. +#ifdef __LINUX__ LoadConfig(); #endif - -#ifdef DEV9_LOG - dev9Log = fopen("logs/dev9Log.txt", "w"); - if (dev9Log) setvbuf(dev9Log, NULL, _IONBF, 0); - DEV9_LOG("dev9null plugin version %d,%d\n", revision, build); - DEV9_LOG("DEV9init\n"); -#endif - + + Dev9Log.WriteToConsole = true; + Dev9Log.WriteToFile = true; + + Dev9Log.Open("logs/dev9null.log"); + Dev9Log.WriteLn("dev9null plugin version %d,%d", revision, build); + Dev9Log.WriteLn("Initializing dev9null"); + // Initialize anything that needs to be initialized. + memset(dev9regs, 0, sizeof(dev9regs)); return 0; } EXPORT_C_(void) DEV9shutdown() { -#ifdef DEV9_LOG - if (dev9Log) fclose(dev9Log); -#endif + Dev9Log.WriteLn("Shutting down Dev9null."); + Dev9Log.Close(); } EXPORT_C_(s32) DEV9open(void *pDsp) { + Dev9Log.WriteLn("Opening Dev9null."); + // Get anything ready we need to. Opening and creating hard + // drive files, for example. return 0; } EXPORT_C_(void) DEV9close() { - + Dev9Log.WriteLn("Closing Dev9null."); + // Close files opened. } EXPORT_C_(u8) DEV9read8(u32 addr) { - DEV9_LOG("*Unknown 8bit read at address %lx ", addr); - return 0; + u8 value = 0; + + switch(addr) + { +// case 0x1F80146E: // DEV9 hardware type (0x32 for an expansion bay) + case 0x10000038: value = dev9Ru8(addr); break; // We need to have at least one case to avoid warnings. + default: + value = dev9Ru8(addr); + Dev9Log.WriteLn("*Unknown 8 bit read at address %lx", addr); + break; + } + return value; } -EXPORT_C_(u16 ) DEV9read16(u32 addr) +EXPORT_C_(u16) DEV9read16(u32 addr) { - DEV9_LOG("*Unknown 16bit read at address %lx ", addr); - return 0; + u16 value = 0; + + switch(addr) + { + // Addresses you may want to catch here include: +// case 0x1F80146E: // DEV9 hardware type (0x32 for an expansion bay) +// case 0x10000002: // The Smart Chip revision. Should be 0x11 +// case 0x10000004: // More type info: bit 0 - smap; bit 1 - hd; bit 5 - flash +// case 0x1000000E: // Similar to the last; bit 1 should be set if a hd is hooked up. +// case 0x10000028: // intr_stat +// case 0x10000038: // hard drives seem to like reading and writing the max dma size per transfer here. +// case 0x1000002A: // intr_mask +// case 0x10000040: // pio_data +// case 0x10000044: // nsector +// case 0x10000046: // sector +// case 0x10000048: // lcyl +// case 0x1000004A: // hcyl +// case 0x1000004C: // select +// case 0x1000004E: // status +// case 0x1000005C: // status +// case 0x10000064: // if_ctrl + case 0x10000038: value = dev9Ru16(addr); break; + default: + value = dev9Ru16(addr); + Dev9Log.WriteLn("*Unknown 16 bit read at address %lx", addr); + break; + } + + return value; } EXPORT_C_(u32 ) DEV9read32(u32 addr) { - DEV9_LOG("*Unknown 32bit read at address %lx ", addr); - return 0; + u32 value = 0; + + switch(addr) + { + case 0x10000038: value = dev9Ru32(addr); break; + default: + value = dev9Ru32(addr); + Dev9Log.WriteLn("*Unknown 32 bit read at address %lx", addr); + break; + } + + return value; } EXPORT_C_(void) DEV9write8(u32 addr, u8 value) { - DEV9_LOG("*Unknown 8bit write at address %lx value %x\n", addr, value); + switch(addr) + { + case 0x10000038: dev9Ru8(addr) = value; break; + default: + Dev9Log.WriteLn("*Unknown 8 bit write; address %lx = %x", addr, value); + dev9Ru8(addr) = value; + break; + } } EXPORT_C_(void) DEV9write16(u32 addr, u16 value) { - DEV9_LOG("*Unknown 16bit write at address %lx value %x\n", addr, value); + switch(addr) + { + // Remember that list on DEV9read16? You'll want to write to a + // lot of them, too. + case 0x10000038: dev9Ru16(addr) = value; break; + default: + Dev9Log.WriteLn("*Unknown 16 bit write; address %lx = %x", addr, value); + dev9Ru16(addr) = value; + break; + } } EXPORT_C_(void) DEV9write32(u32 addr, u32 value) { - DEV9_LOG("*Unknown 32bit write at address %lx value %x\n", addr, value); + switch(addr) + { + case 0x10000038: dev9Ru32(addr) = value; break; + default: + Dev9Log.WriteLn("*Unknown 32 bit write; address %lx = %x", addr, value); + dev9Ru32(addr) = value; + break; + } } EXPORT_C_(void) DEV9readDMA8Mem(u32 *pMem, int size) { - DEV9_LOG("Reading DMA8 Mem."); + // You'll want to but your own DMA8 reading code here. + // Time to interact with your fake (or real) hardware. + Dev9Log.WriteLn("Reading DMA8 Mem."); } EXPORT_C_(void) DEV9writeDMA8Mem(u32* pMem, int size) { - DEV9_LOG("Writing DMA8 Mem."); + // See above. + Dev9Log.WriteLn("Writing DMA8 Mem."); } EXPORT_C_(void) DEV9irqCallback(DEV9callback callback) { + // Setting our callback. You will call it with DEV9irq(cycles), + // Where cycles is the number of cycles till the irq is triggered. DEV9irq = callback; } +int _DEV9irqHandler(void) +{ + // And this gets called when the irq is triggered. + return 0; +} + EXPORT_C_(DEV9handler) DEV9irqHandler(void) { - return NULL; + // Pass it to pcsx2. + return (DEV9handler)_DEV9irqHandler; } EXPORT_C_(void) DEV9setSettingsDir(const char* dir) { - s_strIniPath = (dir==NULL) ? "inis/" : dir; + // Grab the ini directory. + s_strIniPath = (dir == NULL) ? "inis/" : dir; } // extended funcs @@ -156,33 +248,24 @@ EXPORT_C_(s32) DEV9test() return 0; } -#ifdef _WIN32 -EXPORT_C_(void) DEV9configure() +EXPORT_C_(s32) DEV9freeze(int mode, freezeData *data) { - SysMessage("Nothing to Configure?!"); + // 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) DEV9about() -{ -} - -HINSTANCE hInst; - -void SysMessage(const char *fmt, ...) -{ - va_list list; - char tmp[512]; - va_start(list,fmt); - vsprintf(tmp,fmt,list); - va_end(list); - MessageBox( GetActiveWindow(), tmp, "DEV9null Msg", MB_SETFOREGROUND | MB_OK ); -} - -BOOL APIENTRY DllMain(HANDLE hModule, // DLL INIT - DWORD dwReason, - LPVOID lpReserved) { - hInst = (HINSTANCE)hModule; - return TRUE; // very quick :) -} - -#endif +/* For operating systems that need an entry point for a dll/library, here it is. Defined in PS2Eext.h. */ +ENTRY_POINT; diff --git a/plugins/dev9null/DEV9.h b/plugins/dev9null/DEV9.h index e735a94398..c7c6503908 100644 --- a/plugins/dev9null/DEV9.h +++ b/plugins/dev9null/DEV9.h @@ -1,5 +1,5 @@ /* dev9null - * Copyright (C) 2002-2009 pcsx2 Team + * Copyright (C) 2002-2010 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 @@ -23,33 +23,13 @@ #define DEV9defs #include "PS2Edefs.h" - -#ifdef __LINUX__ -#include -#else -#include -#include -#include -#endif +#include "PS2Eext.h" typedef struct { - int Log; + s32 Log; } Config; extern Config conf; -#define DEV9_LOG __Log - -/*#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 extern const unsigned char version; extern const unsigned char revision; @@ -61,10 +41,13 @@ void SaveConfig(); void LoadConfig(); extern void (*DEV9irq)(int); -extern void SysMessage(const char *fmt, ...); - -extern FILE *dev9Log; -void __Log(char *fmt, ...); +extern __aligned16 s8 dev9regs[0x10000]; +#define dev9Rs8(mem) dev9regs[(mem) & 0xffff] +#define dev9Rs16(mem) (*(s16*)&dev9regs[(mem) & 0xffff]) +#define dev9Rs32(mem) (*(s32*)&dev9regs[(mem) & 0xffff]) +#define dev9Ru8(mem) (*(u8*) &dev9regs[(mem) & 0xffff]) +#define dev9Ru16(mem) (*(u16*)&dev9regs[(mem) & 0xffff]) +#define dev9Ru32(mem) (*(u32*)&dev9regs[(mem) & 0xffff]) #endif diff --git a/plugins/dev9null/Linux/Config.cpp b/plugins/dev9null/Linux/Config.cpp deleted file mode 100644 index fb99c4381d..0000000000 --- a/plugins/dev9null/Linux/Config.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/* DEV9null - * Copyright (C) 2002-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 "Config.h" -#include "DEV9.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(const 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), "SPU2null 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) DEV9about() -{ - 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) DEV9configure() -{ - 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/dev9null/Linux/Dev9null.cbp b/plugins/dev9null/Linux/Dev9null.cbp index 903c44369d..783a35278f 100644 --- a/plugins/dev9null/Linux/Dev9null.cbp +++ b/plugins/dev9null/Linux/Dev9null.cbp @@ -7,7 +7,7 @@