2012-11-15 00:39:56 +01:00
|
|
|
#include "stdafx.h"
|
2014-06-02 19:27:24 +02:00
|
|
|
#include "Emu/ConLog.h"
|
|
|
|
|
#include "Emu/Memory/Memory.h"
|
|
|
|
|
#include "Emu/System.h"
|
2012-11-15 00:39:56 +01:00
|
|
|
#include "DbgConsole.h"
|
|
|
|
|
|
2014-05-02 08:30:32 +02:00
|
|
|
LogWriter ConLog;
|
|
|
|
|
class LogFrame;
|
|
|
|
|
extern LogFrame* ConLogFrame;
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2014-05-02 08:30:32 +02:00
|
|
|
_LogBuffer LogBuffer;
|
2014-02-27 04:21:08 +01:00
|
|
|
|
2014-05-02 08:30:32 +02:00
|
|
|
std::mutex g_cs_conlog;
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2014-05-02 08:30:32 +02:00
|
|
|
const uint max_item_count = 500;
|
|
|
|
|
const uint buffer_size = 1024 * 64;
|
|
|
|
|
|
|
|
|
|
static const std::string g_log_colors[] =
|
2012-11-15 00:39:56 +01:00
|
|
|
{
|
2014-05-02 08:30:32 +02:00
|
|
|
"Black", "Green", "White", "Yellow", "Red",
|
|
|
|
|
};
|
2014-04-15 16:12:15 +02:00
|
|
|
|
2014-05-02 08:30:32 +02:00
|
|
|
LogWriter::LogWriter()
|
|
|
|
|
{
|
|
|
|
|
if (!m_logfile.Open(_PRGNAME_ ".log", rFile::write))
|
|
|
|
|
{
|
|
|
|
|
rMessageBox("Can't create log file! (" _PRGNAME_ ".log)", rMessageBoxCaptionStr, rICON_ERROR);
|
|
|
|
|
}
|
2012-11-15 00:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
2014-05-02 08:30:32 +02:00
|
|
|
void LogWriter::WriteToLog(const std::string& prefix, const std::string& value, u8 lvl/*, wxColour bgcolour*/)
|
2012-11-15 00:39:56 +01:00
|
|
|
{
|
2014-05-02 08:30:32 +02:00
|
|
|
std::string new_prefix = prefix;
|
|
|
|
|
if (!prefix.empty())
|
2014-02-26 15:06:13 +01:00
|
|
|
{
|
2014-05-02 08:30:32 +02:00
|
|
|
if (NamedThreadBase* thr = GetCurrentNamedThread())
|
2014-02-26 15:06:13 +01:00
|
|
|
{
|
2014-05-02 08:30:32 +02:00
|
|
|
new_prefix += " : " + thr->GetThreadName();
|
2014-02-26 15:06:13 +01:00
|
|
|
}
|
|
|
|
|
}
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2014-05-02 08:30:32 +02:00
|
|
|
if (m_logfile.IsOpened() && !new_prefix.empty())
|
|
|
|
|
m_logfile.Write("[" + new_prefix + "]: " + value + "\n");
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2014-05-02 08:30:32 +02:00
|
|
|
if (!ConLogFrame || Ini.HLELogLvl.GetValue() == 4 || (lvl != 0 && lvl <= Ini.HLELogLvl.GetValue()))
|
|
|
|
|
return;
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2014-05-02 08:30:32 +02:00
|
|
|
std::lock_guard<std::mutex> lock(g_cs_conlog);
|
|
|
|
|
|
|
|
|
|
// TODO: Use ThreadBase instead, track main thread id
|
|
|
|
|
if (rThread::IsMain())
|
|
|
|
|
{
|
|
|
|
|
while (LogBuffer.IsBusy())
|
|
|
|
|
{
|
|
|
|
|
// need extra break condition?
|
|
|
|
|
rYieldIfNeeded();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2012-11-15 00:39:56 +01:00
|
|
|
{
|
2014-05-02 08:30:32 +02:00
|
|
|
while (LogBuffer.IsBusy())
|
2014-01-31 19:40:18 +01:00
|
|
|
{
|
2014-02-26 12:27:06 +01:00
|
|
|
if (Emu.IsStopped())
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-02-26 15:06:13 +01:00
|
|
|
Sleep(1);
|
2014-01-31 19:40:18 +01:00
|
|
|
}
|
2014-05-02 08:30:32 +02:00
|
|
|
}
|
2014-01-31 19:40:18 +01:00
|
|
|
|
2014-05-02 08:30:32 +02:00
|
|
|
//if(LogBuffer.put == LogBuffer.get) LogBuffer.Flush();
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2014-05-02 08:30:32 +02:00
|
|
|
LogBuffer.Push(LogPacket(new_prefix, value, g_log_colors[lvl]));
|
|
|
|
|
}
|
2014-02-27 04:21:08 +01:00
|
|
|
|
2014-05-02 08:30:32 +02:00
|
|
|
|
|
|
|
|
void LogWriter::SkipLn()
|
|
|
|
|
{
|
|
|
|
|
WriteToLog("", "", 0);
|
2012-11-15 00:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
2014-05-02 08:30:32 +02:00
|
|
|
void DbgConsole::Close()
|
2012-11-15 00:39:56 +01:00
|
|
|
{
|
2014-05-02 08:30:32 +02:00
|
|
|
i = 1;
|
|
|
|
|
}
|
2014-02-27 04:21:08 +01:00
|
|
|
|
2014-05-02 08:30:32 +02:00
|
|
|
void DbgConsole::Clear()
|
|
|
|
|
{
|
|
|
|
|
i = 2;
|
|
|
|
|
}
|
2014-02-27 04:21:08 +01:00
|
|
|
|
2014-05-02 08:30:32 +02:00
|
|
|
void DbgConsole::Write(int ch, const std::string &msg)
|
|
|
|
|
{
|
2014-05-25 10:00:54 +02:00
|
|
|
}
|