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-06-08 23:02:20 +02:00
|
|
|
BEGIN_EVENT_TABLE(DbgConsole, FrameBase)
|
|
|
|
|
EVT_CLOSE(DbgConsole::OnQuit)
|
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
|
DbgConsole::DbgConsole()
|
|
|
|
|
: FrameBase(nullptr, wxID_ANY, "Debug Console", "", wxDefaultSize, wxDefaultPosition, wxDEFAULT_FRAME_STYLE, true)
|
|
|
|
|
, ThreadBase("DbgConsole thread")
|
|
|
|
|
, m_output(nullptr)
|
|
|
|
|
{
|
|
|
|
|
m_console = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition,
|
|
|
|
|
wxSize(500, 500), wxTE_MULTILINE | wxTE_READONLY | wxTE_RICH2);
|
|
|
|
|
m_console->SetBackgroundColour(wxColor("Black"));
|
|
|
|
|
m_console->SetFont(wxFont(8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
|
2014-02-27 04:21:08 +01:00
|
|
|
|
2014-06-08 23:02:20 +02:00
|
|
|
m_color_white = new wxTextAttr(wxColour(255, 255, 255));
|
|
|
|
|
m_color_red = new wxTextAttr(wxColour(255, 0, 0));
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2014-06-08 23:02:20 +02:00
|
|
|
if (Ini.HLESaveTTY.GetValue())
|
|
|
|
|
m_output = new wxFile("tty.log", wxFile::write);
|
|
|
|
|
}
|
2014-05-02 08:30:32 +02:00
|
|
|
|
2014-06-08 23:02:20 +02:00
|
|
|
DbgConsole::~DbgConsole()
|
2012-11-15 00:39:56 +01:00
|
|
|
{
|
2014-06-08 23:02:20 +02:00
|
|
|
ThreadBase::Stop();
|
|
|
|
|
m_dbg_buffer.Flush();
|
2014-04-15 16:12:15 +02:00
|
|
|
|
2014-06-08 23:02:20 +02:00
|
|
|
safe_delete(m_console);
|
|
|
|
|
safe_delete(m_color_white);
|
|
|
|
|
safe_delete(m_color_red);
|
|
|
|
|
safe_delete(m_output);
|
2012-11-15 00:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
2014-06-08 23:02:20 +02:00
|
|
|
void DbgConsole::Write(int ch, const std::string& text)
|
2012-11-15 00:39:56 +01:00
|
|
|
{
|
2014-06-08 23:02:20 +02:00
|
|
|
while (m_dbg_buffer.IsBusy())
|
2014-02-26 15:06:13 +01:00
|
|
|
{
|
2014-06-08 23:02:20 +02:00
|
|
|
if (Emu.IsStopped())
|
2014-02-26 15:06:13 +01:00
|
|
|
{
|
2014-06-08 23:02:20 +02:00
|
|
|
return;
|
2014-02-26 15:06:13 +01:00
|
|
|
}
|
2014-06-08 23:02:20 +02:00
|
|
|
Sleep(1);
|
2014-02-26 15:06:13 +01:00
|
|
|
}
|
2014-06-08 23:02:20 +02:00
|
|
|
m_dbg_buffer.Push(DbgPacket(ch, text));
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2014-06-08 23:02:20 +02:00
|
|
|
if (!IsAlive()) Start();
|
|
|
|
|
}
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2014-06-08 23:02:20 +02:00
|
|
|
void DbgConsole::Clear()
|
|
|
|
|
{
|
|
|
|
|
m_console->Clear();
|
|
|
|
|
}
|
2014-05-02 08:30:32 +02:00
|
|
|
|
2014-06-08 23:02:20 +02:00
|
|
|
void DbgConsole::Task()
|
|
|
|
|
{
|
|
|
|
|
while (!TestDestroy())
|
2012-11-15 00:39:56 +01:00
|
|
|
{
|
2014-06-08 23:02:20 +02:00
|
|
|
if (!m_dbg_buffer.HasNewPacket())
|
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-06-08 23:02:20 +02:00
|
|
|
continue;
|
2014-01-31 19:40:18 +01:00
|
|
|
}
|
|
|
|
|
|
2014-06-08 23:02:20 +02:00
|
|
|
DbgPacket packet = m_dbg_buffer.Pop();
|
|
|
|
|
m_console->SetDefaultStyle(packet.m_ch == 1 ? *m_color_red : *m_color_white);
|
|
|
|
|
m_console->SetInsertionPointEnd();
|
|
|
|
|
m_console->WriteText(fmt::FromUTF8(packet.m_text));
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2014-06-08 23:02:20 +02:00
|
|
|
if (m_output && Ini.HLESaveTTY.GetValue())
|
|
|
|
|
m_output->Write(fmt::FromUTF8(packet.m_text));
|
2014-02-27 04:21:08 +01:00
|
|
|
|
2014-06-08 23:02:20 +02:00
|
|
|
if (!DbgConsole::IsShown()) Show();
|
|
|
|
|
}
|
2012-11-15 00:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
2014-06-08 23:02:20 +02:00
|
|
|
void DbgConsole::OnQuit(wxCloseEvent& event)
|
2012-11-15 00:39:56 +01:00
|
|
|
{
|
2014-06-08 23:02:20 +02:00
|
|
|
ThreadBase::Stop(false);
|
|
|
|
|
Hide();
|
2014-02-27 04:21:08 +01:00
|
|
|
|
2014-06-08 23:02:20 +02:00
|
|
|
if (m_output)
|
|
|
|
|
{
|
|
|
|
|
m_output->Close();
|
|
|
|
|
m_output = nullptr;
|
|
|
|
|
}
|
2014-02-27 04:21:08 +01:00
|
|
|
|
2014-06-08 23:02:20 +02:00
|
|
|
//event.Skip();
|
2014-05-25 10:00:54 +02:00
|
|
|
}
|