From d398e19b4de33900631d5b213059629ec01d1061 Mon Sep 17 00:00:00 2001 From: arcum42 Date: Sun, 30 Oct 2011 01:39:43 +0000 Subject: [PATCH] GSnull: Rework the logging code a bit. (The logging actually prints to the screen now, for one thing.) git-svn-id: http://pcsx2.googlecode.com/svn/trunk@4950 96395faa-99c1-11dd-bbfe-3dabce05a288 --- CMakeLists.txt | 10 +- bin/portable.ini | 1 - plugins/GSnull/CMakeLists.txt | 1 + plugins/GSnull/GS.cpp | 97 ++++---------- plugins/GSnull/GS.h | 20 ++- plugins/GSnull/GSLog.cpp | 123 ++++++++++++++++++ plugins/GSnull/Windows/Config.cpp | 9 +- plugins/GSnull/Windows/GSnull.vcxproj | 1 + plugins/GSnull/Windows/GSnull.vcxproj.filters | 3 + plugins/GSnull/Windows/GSnull_vc2008.vcproj | 4 + plugins/GSnull/Windows/GSwin.cpp | 2 +- plugins/GSnull/null/GSnull.cpp | 8 +- 12 files changed, 185 insertions(+), 94 deletions(-) create mode 100644 plugins/GSnull/GSLog.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 13645f4a14..d9fd4f5f48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,12 +19,12 @@ if(NOT PACKAGE_MODE) See http://code.google.com/p/pcsx2/wiki/ChrootAnd64bStatusLinux for more details.") else (EXISTS /etc/fedora-release) message(FATAL_ERROR " - PCSX2 does not support 64bits environment. Please install a 32bits chroot or a 32bits OS. - PCSX2 have neither no plan to support the 64bits architecture in the future. - It will need a complete rewrite of the core emulator and a lots of time + PCSX2 does not support a 64-bit environment. Please install a 32-bit chroot or a 32-bit OS. + PCSX2 has no plan to support a 64-bit architecture in the future. + It would need a complete rewrite of the core emulator and a lot of time. - However when linux distribution will support properly multi-arch package, it will - be at least possible to easily compile and install PCSX2 witout too much hassle (the chroot environment)") + However, when linux distribution properly supports multi-arch packages, it will + be at least possible to easily compile and install PCSX2 without too much hassle (the chroot environment).") endif (EXISTS /etc/fedora-release) endif(CMAKE_SIZEOF_VOID_P MATCHES "8") endif(NOT PACKAGE_MODE) diff --git a/bin/portable.ini b/bin/portable.ini index ccb32ee0b2..e69de29bb2 100644 --- a/bin/portable.ini +++ b/bin/portable.ini @@ -1 +0,0 @@ -RunWizard=0 diff --git a/plugins/GSnull/CMakeLists.txt b/plugins/GSnull/CMakeLists.txt index ea00dc1d52..3ca4b35ffb 100644 --- a/plugins/GSnull/CMakeLists.txt +++ b/plugins/GSnull/CMakeLists.txt @@ -41,6 +41,7 @@ endif(CMAKE_BUILD_TYPE STREQUAL Release) set(GSnullSources GifTransfer.cpp GS.cpp + GSLog.cpp Registers.cpp) # GSnull headers diff --git a/plugins/GSnull/GS.cpp b/plugins/GSnull/GS.cpp index f4135e0690..173b8297a1 100644 --- a/plugins/GSnull/GS.cpp +++ b/plugins/GSnull/GS.cpp @@ -33,13 +33,12 @@ const unsigned char revision = 0; const unsigned char build = 1; // increase that with each version static char *libraryName = "GSnull Driver"; -FILE *gsLog; Config conf; u32 GSKeyEvent = 0; bool GSShift = false, GSAlt = false; string s_strIniPath="inis"; -std::string s_strLogPath("logs"); +extern std::string s_strLogPath; const char* s_iniFilename = "GSnull.ini"; GSVars gs; @@ -69,35 +68,6 @@ EXPORT_C_(u32) PS2EgetLibVersion2(u32 type) return (version<<16) | (revision<<8) | build; } -bool OpenLog() { - bool result = true; -#ifdef GS_LOG - const std::string LogFile(s_strLogPath + "/GSnull.log"); - - gsLog = fopen(LogFile.c_str(), "w"); - if (gsLog != NULL) - setvbuf(gsLog, NULL, _IONBF, 0); - else { - SysMessage("Can't create log file %s\n", LogFile.c_str()); - result = false; - } - GS_LOG("GSnull plugin version %d,%d\n",revision,build); - GS_LOG("GS init\n"); -#endif - return result; -} - -void __Log(char *fmt, ...) -{ - va_list list; - - if (!conf.Log || gsLog == NULL) return; - - va_start(list, fmt); - vfprintf(gsLog, fmt, list); - va_end(list); -} - EXPORT_C_(void) GSprintf(int timeout, char *fmt, ...) { va_list list; @@ -107,21 +77,7 @@ EXPORT_C_(void) GSprintf(int timeout, char *fmt, ...) vsprintf(msg, fmt, list); va_end(list); - GS_LOG("GSprintf:%s", msg); - printf("GSprintf:%s", msg); -} - -void SysPrintf(const char *fmt, ...) -{ - va_list list; - char msg[512]; - - va_start(list, fmt); - vsprintf(msg, fmt, list); - va_end(list); - - GS_LOG(msg); - printf("GSnull:%s", msg); + GSLog::Print("GSprintf:%s", msg); } // basic funcs @@ -136,40 +92,31 @@ EXPORT_C_(void) GSsetLogDir(const char* dir) s_strLogPath = (dir==NULL) ? "logs" : dir; // Reload the log file after updated the path - if (gsLog) { - fclose(gsLog); - gsLog = NULL; - } - OpenLog(); + GSLog::Close(); + GSLog::Open(); } EXPORT_C_(s32) GSinit() { LoadConfig(); - OpenLog(); + GSLog::Open(); - SysPrintf("Initializing GSnull\n"); + GSLog::WriteLn("Initializing GSnull."); return 0; } EXPORT_C_(void) GSshutdown() { - SysPrintf("Shutting down GSnull\n"); + GSLog::WriteLn("Shutting down GSnull."); GSCloseWindow(); - -#ifdef GS_LOG - if (gsLog) { - fclose(gsLog); - gsLog = NULL; - } -#endif + GSLog::Close(); } EXPORT_C_(s32) GSopen(void *pDsp, char *Title, int multithread) { int err = 0; - GS_LOG("GS open\n"); + GSLog::WriteLn("GS open."); //assert( GSirq != NULL ); err = GSOpenWindow(pDsp, Title); @@ -178,14 +125,14 @@ EXPORT_C_(s32) GSopen(void *pDsp, char *Title, int multithread) ResetRegs(); SetMultithreaded(); InitPath(); - SysPrintf("Opening GSnull\n"); + GSLog::WriteLn("Opening GSnull."); return err; } #ifdef USE_GSOPEN2 EXPORT_C_(s32) GSopen2( void *pDsp, u32 flags ) { - GS_LOG("GS open2\n"); + GSLog::WriteLn("GS open2."); GSOpenWindow2(pDsp, flags); @@ -194,14 +141,14 @@ EXPORT_C_(s32) GSopen2( void *pDsp, u32 flags ) ResetRegs(); SetMultithreaded(); InitPath(); - SysPrintf("Opening GSnull (2)\n"); + GSLog::WriteLn("Opening GSnull (2)."); return 0; } #endif EXPORT_C_(void) GSclose() { - SysPrintf("Closing GSnull\n"); + GSLog::WriteLn("Closing GSnull."); // Better to only close the window on Shutdown. All the other plugins // pretty much worked that way, and all old PCSX2 versions expect it as well. @@ -220,7 +167,7 @@ EXPORT_C_(s32) GSfreeze(int mode, freezeData *data) EXPORT_C_(s32) GStest() { - SysPrintf("Testing GSnull\n"); + GSLog::WriteLn("Testing GSnull."); return 0; } @@ -238,7 +185,7 @@ EXPORT_C_(void) GSgetLastTag(u64* ptag) EXPORT_C_(void) GSgifSoftReset(u32 mask) { - SysPrintf("Doing a soft reset of the GS plugin.\n"); + GSLog::WriteLn("Doing a soft reset of the GS plugin."); } EXPORT_C_(void) GSreadFIFO(u64 *mem) @@ -264,12 +211,12 @@ EXPORT_C_(void) GSchangeSaveState(int, const char* filename) EXPORT_C_(void) GSmakeSnapshot(char *path) { - SysPrintf("Taking a snapshot.\n"); + GSLog::WriteLn("Taking a snapshot."); } EXPORT_C_(void) GSmakeSnapshot2(char *pathname, int* snapdone, int savejpg) { - SysPrintf("Taking a snapshot to %s.\n", pathname); + GSLog::WriteLn("Taking a snapshot to %s.", pathname); } EXPORT_C_(void) GSsetBaseMem(void*) @@ -278,14 +225,14 @@ EXPORT_C_(void) GSsetBaseMem(void*) EXPORT_C_(void) GSsetGameCRC(int crc, int gameoptions) { - SysPrintf("Setting the crc to '%x' with 0x%x for options.\n", crc, gameoptions); + GSLog::WriteLn("Setting the crc to '%x' with 0x%x for options.", crc, gameoptions); } // controls frame skipping in the GS, if this routine isn't present, frame skipping won't be done EXPORT_C_(void) GSsetFrameSkip(int frameskip) { SetFrameSkip(frameskip != 0); - SysPrintf("Frameskip set to %d.\n", frameskip); + GSLog::WriteLn("Frameskip set to %d.", frameskip); } // if start is 1, starts recording spu2 data, else stops @@ -294,16 +241,16 @@ EXPORT_C_(void) GSsetFrameSkip(int frameskip) EXPORT_C_(int) GSsetupRecording(int start, void* pData) { if (start) - SysPrintf("Pretending to record.\n"); + GSLog::WriteLn("Pretending to record."); else - SysPrintf("Pretending to stop recording.\n"); + GSLog::WriteLn("Pretending to stop recording."); return 1; } EXPORT_C_(void) GSreset() { - SysPrintf("Doing a reset of the GS plugin."); + GSLog::WriteLn("Doing a reset of the GS plugin."); } EXPORT_C_(void) GSwriteCSR(u32 value) diff --git a/plugins/GSnull/GS.h b/plugins/GSnull/GS.h index b64328577f..2259dd29d5 100644 --- a/plugins/GSnull/GS.h +++ b/plugins/GSnull/GS.h @@ -43,7 +43,11 @@ typedef struct _keyEvent keyEvent; #define EXPORT_C_(type) extern "C" __attribute__((externally_visible,visibility("default"))) type #endif -#define GS_LOG __Log +#define GS_LOG GSLog::Log + +extern const unsigned char version; +extern const unsigned char revision; +extern const unsigned char build; typedef struct { @@ -68,15 +72,21 @@ typedef struct extern GSVars gs; extern Config conf; -extern FILE *gsLog; extern u32 GSKeyEvent; extern bool GSShift, GSAlt; extern void (*GSirq)(); -extern void __Log(char *fmt, ...); -extern void SysMessage(char *fmt, ...); -extern void SysPrintf(const char *fmt, ...); +namespace GSLog +{ + extern bool Open(); + extern void Close(); + extern void Log(char *fmt, ...); + extern void Message(char *fmt, ...); + extern void Print(const char *fmt, ...); + extern void WriteLn(const char *fmt, ...); +}; + extern void SaveConfig(); extern void LoadConfig(); diff --git a/plugins/GSnull/GSLog.cpp b/plugins/GSnull/GSLog.cpp new file mode 100644 index 0000000000..5ead971454 --- /dev/null +++ b/plugins/GSnull/GSLog.cpp @@ -0,0 +1,123 @@ +/* GSnull + * 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 . + */ + + +#include +#include +#include +#include + +#include +#include + +using namespace std; + +#include "GS.h" +#include "GifTransfer.h" +#include "null/GSnull.h" + +std::string s_strLogPath("logs"); + +namespace GSLog +{ + FILE *gsLog; + + bool Open() + { + bool result = true; + + #ifdef GS_LOG + const std::string LogFile(s_strLogPath + "/GSnull.log"); + + gsLog = fopen(LogFile.c_str(), "w"); + + if (gsLog != NULL) + { + setvbuf(gsLog, NULL, _IONBF, 0); + } + else + { + Message("Can't create log file %s.", LogFile.c_str()); + result = false; + } + + WriteLn("GSnull plugin version %d,%d",revision,build); + WriteLn("GS init."); + #endif + + return result; + } + + void Close() + { + #ifdef GS_LOG + if (gsLog) + { + fclose(gsLog); + gsLog = NULL; + } + #endif + } + + void Log(char *fmt, ...) + { + va_list list; + + if (!conf.Log || gsLog == NULL) return; + + va_start(list, fmt); + vfprintf(gsLog, fmt, list); + va_end(list); + } + + void Message(char *fmt, ...) + { + va_list list; + char msg[512]; + + va_start(list, fmt); + vsprintf(msg, fmt, list); + va_end(list); + + SysMessage("%s\n",msg); + } + + void Print(const char *fmt, ...) + { + va_list list; + char msg[512]; + + va_start(list, fmt); + vsprintf(msg, fmt, list); + va_end(list); + + GS_LOG(msg); + fprintf(stderr, "GSnull:%s", msg); + } + + + void WriteLn(const char *fmt, ...) + { + va_list list; + char msg[512]; + + va_start(list, fmt); + vsprintf(msg, fmt, list); + va_end(list); + + GS_LOG(msg); + fprintf(stderr, "GSnull:%s\n", msg); + } +}; diff --git a/plugins/GSnull/Windows/Config.cpp b/plugins/GSnull/Windows/Config.cpp index 428c9bc7d7..110e23e485 100644 --- a/plugins/GSnull/Windows/Config.cpp +++ b/plugins/GSnull/Windows/Config.cpp @@ -31,11 +31,12 @@ void SaveConfig() if(!szTemp) return; strcpy(szTemp, "\\inis\\gsnull.ini"); sprintf(szValue,"%u",Conf1->Log); - WritePrivateProfileString("Interface", "Logging",szValue,szIniFile); + WritePrivateProfileString("Interface", "Logging",szValue,szIniFile); } -void LoadConfig() { +void LoadConfig() +{ FILE *fp; @@ -48,7 +49,8 @@ void LoadConfig() { if(!szTemp) return ; strcpy(szTemp, "\\inis\\gsnull.ini"); - fp=fopen("inis\\gsnull.ini","rt");//check if gsnull.ini really exists + fp=fopen("inis\\gsnull.ini","rt");//check if gsnull.ini really exists + if (!fp) { CreateDirectory("inis",NULL); @@ -57,6 +59,7 @@ void LoadConfig() { SaveConfig();//save and return return ; } + fclose(fp); GetPrivateProfileString("Interface", "Logging", NULL, szValue, 20, szIniFile); Conf1->Log = strtoul(szValue, NULL, 10); diff --git a/plugins/GSnull/Windows/GSnull.vcxproj b/plugins/GSnull/Windows/GSnull.vcxproj index e26ba20db6..09f91f748f 100644 --- a/plugins/GSnull/Windows/GSnull.vcxproj +++ b/plugins/GSnull/Windows/GSnull.vcxproj @@ -74,6 +74,7 @@ + true diff --git a/plugins/GSnull/Windows/GSnull.vcxproj.filters b/plugins/GSnull/Windows/GSnull.vcxproj.filters index 50b6441761..72c50de3ea 100644 --- a/plugins/GSnull/Windows/GSnull.vcxproj.filters +++ b/plugins/GSnull/Windows/GSnull.vcxproj.filters @@ -24,6 +24,9 @@ Source Files + + Source Files + Source Files diff --git a/plugins/GSnull/Windows/GSnull_vc2008.vcproj b/plugins/GSnull/Windows/GSnull_vc2008.vcproj index cee39ef0b4..0f0b230234 100644 --- a/plugins/GSnull/Windows/GSnull_vc2008.vcproj +++ b/plugins/GSnull/Windows/GSnull_vc2008.vcproj @@ -160,6 +160,10 @@ RelativePath="..\GS.cpp" > + + diff --git a/plugins/GSnull/Windows/GSwin.cpp b/plugins/GSnull/Windows/GSwin.cpp index ef2ef33fe1..079b11000b 100644 --- a/plugins/GSnull/Windows/GSwin.cpp +++ b/plugins/GSnull/Windows/GSwin.cpp @@ -46,7 +46,7 @@ int GSOpenWindow(void *pDsp, char *Title) if(GShwnd == NULL) { - GS_LOG("Failed to create window. Exiting..."); + GSLog::WriteLn("Failed to create window. Exiting..."); return -1; } diff --git a/plugins/GSnull/null/GSnull.cpp b/plugins/GSnull/null/GSnull.cpp index 1cce9e410e..bb7649a681 100644 --- a/plugins/GSnull/null/GSnull.cpp +++ b/plugins/GSnull/null/GSnull.cpp @@ -17,20 +17,20 @@ void OnKeyboardF5(int myShift) { - SysPrintf("F5 pressed!\n"); + GSLog::WriteLn("F5 pressed!"); } void OnKeyboardF6(int myShift) { - SysPrintf("F6 pressed!\n"); + GSLog::WriteLn("F6 pressed!"); } void OnKeyboardF7(int myShift) { - SysPrintf("F7 pressed!\n"); + GSLog::WriteLn("F7 pressed!"); } void OnKeyboardF9(int myShift) { - SysPrintf("F9 pressed!\n"); + GSLog::WriteLn("F9 pressed!"); }