project64/Source/Project64-core/N64System/Recompiler/RecompilerCodeLog.cpp

67 lines
2.0 KiB
C++

/****************************************************************************
* *
* Project64 - A Nintendo 64 emulator. *
* http://www.pj64-emu.com/ *
* Copyright (C) 2012 Project64. All rights reserved. *
* *
* License: *
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
* *
****************************************************************************/
#include "stdafx.h"
#include "RecompilerCodeLog.h"
#include <Common/path.h>
#include <Common/Platform.h>
static CLog * g_CPULogFile = NULL;
bool g_bRecompilerLogging = false;
void Recompiler_Log_Message(const char * strFormat, ...)
{
va_list args;
va_start(args, strFormat);
size_t nlen = _vscprintf(strFormat, args) + 3;
char * buffer = (char *)alloca(nlen * sizeof(char));
if (buffer != NULL)
{
buffer[nlen - 1] = 0;
vsprintf(buffer, strFormat, args);
strcat(buffer, "\r\n");
g_CPULogFile->Log(buffer);
}
va_end(args);
}
void Start_Recompiler_Log (void)
{
CPath LogFileName(g_Settings->LoadStringVal(Directory_Log).c_str(), "CPUoutput.log");
if (g_CPULogFile != NULL)
{
Stop_Recompiler_Log();
}
g_CPULogFile = new CLog();
if (g_CPULogFile)
{
if (g_CPULogFile->Open(LogFileName))
{
g_CPULogFile->SetMaxFileSize(300 * CLog::MB);
g_bRecompilerLogging = true;
}
else
{
delete g_CPULogFile;
g_CPULogFile = NULL;
}
}
}
void Stop_Recompiler_Log (void)
{
g_bRecompilerLogging = false;
if (g_CPULogFile != NULL)
{
delete g_CPULogFile;
g_CPULogFile = NULL;
}
}