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
This commit is contained in:
arcum42 2011-10-30 01:39:43 +00:00
parent 5306b13472
commit d398e19b4d
12 changed files with 185 additions and 94 deletions

View File

@ -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)

View File

@ -1 +0,0 @@
RunWizard=0

View File

@ -41,6 +41,7 @@ endif(CMAKE_BUILD_TYPE STREQUAL Release)
set(GSnullSources
GifTransfer.cpp
GS.cpp
GSLog.cpp
Registers.cpp)
# GSnull headers

View File

@ -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)

View File

@ -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();

123
plugins/GSnull/GSLog.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <string>
#include <stdio.h>
#include <assert.h>
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);
}
};

View File

@ -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);

View File

@ -74,6 +74,7 @@
<ClCompile Include="Config.cpp" />
<ClCompile Include="..\GifTransfer.cpp" />
<ClCompile Include="..\GS.cpp" />
<ClCompile Include="..\GSLog.cpp" />
<ClCompile Include="..\Registers.cpp" />
<ClCompile Include="..\Linux\GSLinux.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>

View File

@ -24,6 +24,9 @@
<ClCompile Include="..\GS.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\GSLog.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Linux\GSLinux.cpp">
<Filter>Source Files</Filter>
</ClCompile>

View File

@ -160,6 +160,10 @@
RelativePath="..\GS.cpp"
>
</File>
<File
RelativePath="..\GSLog.cpp"
>
</File>
<File
RelativePath="..\Linux\GSLinux.cpp"
>

View File

@ -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;
}

View File

@ -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!");
}