aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/citra_qt
diff options
context:
space:
mode:
Diffstat (limited to 'src/citra_qt')
-rw-r--r--src/citra_qt/bootmanager.cpp104
-rw-r--r--src/citra_qt/bootmanager.h69
-rw-r--r--src/citra_qt/config.cpp13
-rw-r--r--src/citra_qt/debugger/callstack.cpp5
-rw-r--r--src/citra_qt/debugger/disassembler.cpp89
-rw-r--r--src/citra_qt/debugger/disassembler.h9
-rw-r--r--src/citra_qt/debugger/graphics_breakpoints.cpp2
-rw-r--r--src/citra_qt/debugger/graphics_breakpoints_p.h2
-rw-r--r--src/citra_qt/debugger/graphics_cmdlists.cpp4
-rw-r--r--src/citra_qt/debugger/graphics_framebuffer.cpp4
-rw-r--r--src/citra_qt/debugger/profiler.cpp4
-rw-r--r--src/citra_qt/debugger/profiler.h2
-rw-r--r--src/citra_qt/debugger/ramview.cpp3
-rw-r--r--src/citra_qt/debugger/registers.cpp33
-rw-r--r--src/citra_qt/debugger/registers.h4
-rw-r--r--src/citra_qt/main.cpp132
-rw-r--r--src/citra_qt/main.h23
-rw-r--r--src/citra_qt/main.ui3
-rw-r--r--src/citra_qt/util/spinbox.cpp3
19 files changed, 271 insertions, 237 deletions
diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp
index b81bd616..d3df289f 100644
--- a/src/citra_qt/bootmanager.cpp
+++ b/src/citra_qt/bootmanager.cpp
@@ -8,8 +8,8 @@
#include <QWindow>
#endif
-#include "common/common.h"
#include "bootmanager.h"
+#include "main.h"
#include "core/core.h"
#include "core/settings.h"
@@ -27,43 +27,33 @@
#define COPYRIGHT "Copyright (C) 2013-2014 Citra Team"
EmuThread::EmuThread(GRenderWindow* render_window) :
- filename(""), exec_cpu_step(false), cpu_running(false),
- stop_run(false), render_window(render_window)
-{
-}
+ exec_step(false), running(false), stop_run(false), render_window(render_window) {
-void EmuThread::SetFilename(std::string filename)
-{
- this->filename = filename;
+ connect(this, SIGNAL(started()), render_window, SLOT(moveContext()));
}
-void EmuThread::run()
-{
+void EmuThread::run() {
stop_run = false;
// holds whether the cpu was running during the last iteration,
// so that the DebugModeLeft signal can be emitted before the
// next execution step
bool was_active = false;
- while (!stop_run)
- {
- if (cpu_running)
- {
+ while (!stop_run) {
+ if (running) {
if (!was_active)
emit DebugModeLeft();
Core::RunLoop();
- was_active = cpu_running || exec_cpu_step;
- if (!was_active)
+ was_active = running || exec_step;
+ if (!was_active && !stop_run)
emit DebugModeEntered();
- }
- else if (exec_cpu_step)
- {
+ } else if (exec_step) {
if (!was_active)
emit DebugModeLeft();
- exec_cpu_step = false;
+ exec_step = false;
Core::SingleStep();
emit DebugModeEntered();
yieldCurrentThread();
@@ -71,47 +61,10 @@ void EmuThread::run()
was_active = false;
}
}
- render_window->moveContext();
-
- Core::Stop();
-}
-
-void EmuThread::Stop()
-{
- if (!isRunning())
- {
- LOG_WARNING(Frontend, "EmuThread::Stop called while emu thread wasn't running, returning...");
- return;
- }
- stop_run = true;
- // Release emu threads from any breakpoints, so that this doesn't hang forever.
- Pica::g_debug_context->ClearBreakpoints();
-
- //core::g_state = core::SYS_DIE;
-
- // TODO: Waiting here is just a bad workaround for retarded shutdown logic.
- wait(1000);
- if (isRunning())
- {
- LOG_WARNING(Frontend, "EmuThread still running, terminating...");
- quit();
-
- // TODO: Waiting 50 seconds can be necessary if the logging subsystem has a lot of spam
- // queued... This should be fixed.
- wait(50000);
- if (isRunning())
- {
- LOG_CRITICAL(Frontend, "EmuThread STILL running, something is wrong here...");
- terminate();
- }
- }
- LOG_INFO(Frontend, "EmuThread stopped");
-
- System::Shutdown();
+ render_window->moveContext();
}
-
// This class overrides paintEvent and resizeEvent to prevent the GUI thread from stealing GL context.
// The corresponding functionality is handled in EmuThread instead
class GGLWidgetInternal : public QGLWidget
@@ -133,13 +86,9 @@ private:
GRenderWindow* parent;
};
-EmuThread& GRenderWindow::GetEmuThread()
-{
- return emu_thread;
-}
+GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread) :
+ QWidget(parent), emu_thread(emu_thread), keyboard_id(0) {
-GRenderWindow::GRenderWindow(QWidget* parent) : QWidget(parent), emu_thread(this), keyboard_id(0)
-{
std::string window_title = Common::StringFromFormat("Citra | %s-%s", Common::g_scm_branch, Common::g_scm_desc);
setWindowTitle(QString::fromStdString(window_title));
@@ -160,7 +109,6 @@ GRenderWindow::GRenderWindow(QWidget* parent) : QWidget(parent), emu_thread(this
layout->addWidget(child);
layout->setMargin(0);
setLayout(layout);
- connect(&emu_thread, SIGNAL(started()), this, SLOT(moveContext()));
OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size);
@@ -180,29 +128,17 @@ void GRenderWindow::moveContext()
// We need to move GL context to the swapping thread in Qt5
#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
// If the thread started running, move the GL Context to the new thread. Otherwise, move it back.
- child->context()->moveToThread((QThread::currentThread() == qApp->thread()) ? &emu_thread : qApp->thread());
+ auto thread = (QThread::currentThread() == qApp->thread() && emu_thread != nullptr) ? emu_thread : qApp->thread();
+ child->context()->moveToThread(thread);
#endif
}
-GRenderWindow::~GRenderWindow()
-{
- if (emu_thread.isRunning())
- emu_thread.Stop();
-}
-
void GRenderWindow::SwapBuffers()
{
// MakeCurrent is already called in renderer_opengl
child->swapBuffers();
}
-void GRenderWindow::closeEvent(QCloseEvent* event)
-{
- if (emu_thread.isRunning())
- emu_thread.Stop();
- QWidget::closeEvent(event);
-}
-
void GRenderWindow::MakeCurrent()
{
child->makeCurrent();
@@ -288,7 +224,7 @@ void GRenderWindow::mousePressEvent(QMouseEvent *event)
void GRenderWindow::mouseMoveEvent(QMouseEvent *event)
{
auto pos = event->pos();
- this->TouchMoved(static_cast<unsigned>(pos.x()), static_cast<unsigned>(pos.y()));
+ this->TouchMoved(static_cast<unsigned>(std::max(pos.x(), 0)), static_cast<unsigned>(std::max(pos.y(), 0)));
}
void GRenderWindow::mouseReleaseEvent(QMouseEvent *event)
@@ -335,3 +271,11 @@ void GRenderWindow::OnClientAreaResized(unsigned width, unsigned height)
void GRenderWindow::OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) {
setMinimumSize(minimal_size.first, minimal_size.second);
}
+
+void GRenderWindow::OnEmulationStarting(EmuThread* emu_thread) {
+ this->emu_thread = emu_thread;
+}
+
+void GRenderWindow::OnEmulationStopping() {
+ emu_thread = nullptr;
+}
diff --git a/src/citra_qt/bootmanager.h b/src/citra_qt/bootmanager.h
index 288da45a..d5d74c94 100644
--- a/src/citra_qt/bootmanager.h
+++ b/src/citra_qt/bootmanager.h
@@ -7,74 +7,59 @@
#include <QThread>
#include <QGLWidget>
-#include "common/common.h"
#include "common/emu_window.h"
+#include "common/thread.h"
class QScreen;
class QKeyEvent;
class GRenderWindow;
+class GMainWindow;
class EmuThread : public QThread
{
Q_OBJECT
public:
- /**
- * Set image filename
- *
- * @param filename
- * @warning Only call when not running!
- */
- void SetFilename(std::string filename);
+ EmuThread(GRenderWindow* render_window);
/**
* Start emulation (on new thread)
- *
* @warning Only call when not running!
*/
void run() override;
/**
- * Allow the CPU to process a single instruction (if cpu is not running)
- *
+ * Steps the emulation thread by a single CPU instruction (if the CPU is not already running)
* @note This function is thread-safe
*/
- void ExecStep() { exec_cpu_step = true; }
+ void ExecStep() { exec_step = true; }
/**
- * Allow the CPU to continue processing instructions without interruption
- *
+ * Sets whether the emulation thread is running or not
+ * @param running Boolean value, set the emulation thread to running if true
* @note This function is thread-safe
*/
- void SetCpuRunning(bool running) { cpu_running = running; }
+ void SetRunning(bool running) { this->running = running; }
/**
- * Allow the CPU to continue processing instructions without interruption
- *
- * @note This function is thread-safe
- */
- bool IsCpuRunning() { return cpu_running; }
-
+ * Check if the emulation thread is running or not
+ * @return True if the emulation thread is running, otherwise false
+ * @note This function is thread-safe
+ */
+ bool IsRunning() { return running; }
-public slots:
/**
- * Stop emulation and wait for the thread to finish.
- *
- * @details: This function will wait a second for the thread to finish; if it hasn't finished until then, we'll terminate() it and wait another second, hoping that it will be terminated by then.
- * @note: This function is thread-safe.
+ * Requests for the emulation thread to stop running
*/
- void Stop();
+ void RequestStop() {
+ stop_run = true;
+ running = false;
+ };
private:
- friend class GRenderWindow;
-
- EmuThread(GRenderWindow* render_window);
-
- std::string filename;
-
- bool exec_cpu_step;
- bool cpu_running;
+ bool exec_step;
+ bool running;
std::atomic<bool> stop_run;
GRenderWindow* render_window;
@@ -100,10 +85,7 @@ class GRenderWindow : public QWidget, public EmuWindow
Q_OBJECT
public:
- GRenderWindow(QWidget* parent = NULL);
- ~GRenderWindow();
-
- void closeEvent(QCloseEvent*) override;
+ GRenderWindow(QWidget* parent, EmuThread* emu_thread);
// EmuWindow implementation
void SwapBuffers() override;
@@ -116,8 +98,6 @@ public:
void restoreGeometry(const QByteArray& geometry); // overridden
QByteArray saveGeometry(); // overridden
- EmuThread& GetEmuThread();
-
void keyPressEvent(QKeyEvent* event) override;
void keyReleaseEvent(QKeyEvent* event) override;
@@ -134,15 +114,18 @@ public:
public slots:
void moveContext(); // overridden
+ void OnEmulationStarting(EmuThread* emu_thread);
+ void OnEmulationStopping();
+
private:
void OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) override;
QGLWidget* child;
- EmuThread emu_thread;
-
QByteArray geometry;
/// Device id of keyboard for use with KeyMap
int keyboard_id;
+
+ EmuThread* emu_thread;
};
diff --git a/src/citra_qt/config.cpp b/src/citra_qt/config.cpp
index ac250e0a..fb85121b 100644
--- a/src/citra_qt/config.cpp
+++ b/src/citra_qt/config.cpp
@@ -53,6 +53,12 @@ void Config::ReadValues() {
Settings::values.frame_skip = qt_config->value("frame_skip", 0).toInt();
qt_config->endGroup();
+ qt_config->beginGroup("Renderer");
+ Settings::values.bg_red = qt_config->value("bg_red", 1.0).toFloat();
+ Settings::values.bg_green = qt_config->value("bg_green", 1.0).toFloat();
+ Settings::values.bg_blue = qt_config->value("bg_blue", 1.0).toFloat();
+ qt_config->endGroup();
+
qt_config->beginGroup("Data Storage");
Settings::values.use_virtual_sd = qt_config->value("use_virtual_sd", true).toBool();
qt_config->endGroup();
@@ -98,6 +104,13 @@ void Config::SaveValues() {
qt_config->setValue("frame_skip", Settings::values.frame_skip);
qt_config->endGroup();
+ qt_config->beginGroup("Renderer");
+ // Cast to double because Qt's written float values are not human-readable
+ qt_config->setValue("bg_red", (double)Settings::values.bg_red);
+ qt_config->setValue("bg_green", (double)Settings::values.bg_green);
+ qt_config->setValue("bg_blue", (double)Settings::values.bg_blue);
+ qt_config->endGroup();
+
qt_config->beginGroup("Data Storage");
qt_config->setValue("use_virtual_sd", Settings::values.use_virtual_sd);
qt_config->endGroup();
diff --git a/src/citra_qt/debugger/callstack.cpp b/src/citra_qt/debugger/callstack.cpp
index 9bb22ca2..94e20471 100644
--- a/src/citra_qt/debugger/callstack.cpp
+++ b/src/citra_qt/debugger/callstack.cpp
@@ -8,7 +8,7 @@
#include "core/core.h"
#include "core/arm/arm_interface.h"
-#include "core/mem_map.h"
+#include "core/memory.h"
#include "common/symbols.h"
#include "core/arm/disassembler/arm_disasm.h"
@@ -27,7 +27,6 @@ CallstackWidget::CallstackWidget(QWidget* parent): QDockWidget(parent)
void CallstackWidget::OnDebugModeEntered()
{
- ARM_Disasm* disasm = new ARM_Disasm();
ARM_Interface* app_core = Core::g_app_core;
u32 sp = app_core->GetReg(13); //stack pointer
@@ -46,7 +45,7 @@ void CallstackWidget::OnDebugModeEntered()
/* TODO (mattvail) clean me, move to debugger interface */
u32 insn = Memory::Read32(call_addr);
- if (disasm->Decode(insn) == OP_BL)
+ if (ARM_Disasm::Decode(insn) == OP_BL)
{
std::string name;
// ripped from disasm
diff --git a/src/citra_qt/debugger/disassembler.cpp b/src/citra_qt/debugger/disassembler.cpp
index 54d21dc9..e99ec1b3 100644
--- a/src/citra_qt/debugger/disassembler.cpp
+++ b/src/citra_qt/debugger/disassembler.cpp
@@ -7,8 +7,7 @@
#include "../bootmanager.h"
#include "../hotkeys.h"
-#include "common/common.h"
-#include "core/mem_map.h"
+#include "core/memory.h"
#include "core/core.h"
#include "common/break_points.h"
@@ -18,8 +17,8 @@
#include "core/arm/disassembler/arm_disasm.h"
-DisassemblerModel::DisassemblerModel(QObject* parent) : QAbstractListModel(parent), base_address(0), code_size(0), program_counter(0), selection(QModelIndex()) {
-
+DisassemblerModel::DisassemblerModel(QObject* parent) :
+ QAbstractListModel(parent), base_address(0), code_size(0), program_counter(0), selection(QModelIndex()) {
}
int DisassemblerModel::columnCount(const QModelIndex& parent) const {
@@ -158,34 +157,28 @@ void DisassemblerModel::SetNextInstruction(unsigned int address) {
emit dataChanged(prev_index, prev_index);
}
-DisassemblerWidget::DisassemblerWidget(QWidget* parent, EmuThread& emu_thread) : QDockWidget(parent), base_addr(0), emu_thread(emu_thread)
-{
- disasm_ui.setupUi(this);
+DisassemblerWidget::DisassemblerWidget(QWidget* parent, EmuThread* emu_thread) :
+ QDockWidget(parent), emu_thread(emu_thread), base_addr(0) {
- model = new DisassemblerModel(this);
- disasm_ui.treeView->setModel(model);
+ disasm_ui.setupUi(this);
RegisterHotkey("Disassembler", "Start/Stop", QKeySequence(Qt::Key_F5), Qt::ApplicationShortcut);
RegisterHotkey("Disassembler", "Step", QKeySequence(Qt::Key_F10), Qt::ApplicationShortcut);
RegisterHotkey("Disassembler", "Step into", QKeySequence(Qt::Key_F11), Qt::ApplicationShortcut);
RegisterHotkey("Disassembler", "Set Breakpoint", QKeySequence(Qt::Key_F9), Qt::ApplicationShortcut);
- connect(disasm_ui.button_breakpoint, SIGNAL(clicked()), model, SLOT(OnSetOrUnsetBreakpoint()));
connect(disasm_ui.button_step, SIGNAL(clicked()), this, SLOT(OnStep()));
connect(disasm_ui.button_pause, SIGNAL(clicked()), this, SLOT(OnPause()));
connect(disasm_ui.button_continue, SIGNAL(clicked()), this, SLOT(OnContinue()));
- connect(disasm_ui.treeView->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)),
- model, SLOT(OnSelectionChanged(const QModelIndex&)));
-
connect(GetHotkey("Disassembler", "Start/Stop", this), SIGNAL(activated()), this, SLOT(OnToggleStartStop()));
connect(GetHotkey("Disassembler", "Step", this), SIGNAL(activated()), this, SLOT(OnStep()));
connect(GetHotkey("Disassembler", "Step into", this), SIGNAL(activated()), this, SLOT(OnStepInto()));
- connect(GetHotkey("Disassembler", "Set Breakpoint", this), SIGNAL(activated()), model, SLOT(OnSetOrUnsetBreakpoint()));
+
+ setEnabled(false);
}
-void DisassemblerWidget::Init()
-{
+void DisassemblerWidget::Init() {
model->ParseFromAddress(Core::g_app_core->GetPC());
disasm_ui.treeView->resizeColumnToContents(0);
@@ -197,25 +190,21 @@ void DisassemblerWidget::Init()
disasm_ui.treeView->selectionModel()->setCurrentIndex(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
}
-void DisassemblerWidget::OnContinue()
-{
- emu_thread.SetCpuRunning(true);
+void DisassemblerWidget::OnContinue() {
+ emu_thread->SetRunning(true);
}
-void DisassemblerWidget::OnStep()
-{
+void DisassemblerWidget::OnStep() {
OnStepInto(); // change later
}
-void DisassemblerWidget::OnStepInto()
-{
- emu_thread.SetCpuRunning(false);
- emu_thread.ExecStep();
+void DisassemblerWidget::OnStepInto() {
+ emu_thread->SetRunning(false);
+ emu_thread->ExecStep();
}
-void DisassemblerWidget::OnPause()
-{
- emu_thread.SetCpuRunning(false);
+void DisassemblerWidget::OnPause() {
+ emu_thread->SetRunning(false);
// TODO: By now, the CPU might not have actually stopped...
if (Core::g_app_core) {
@@ -223,20 +212,15 @@ void DisassemblerWidget::OnPause()
}
}
-void DisassemblerWidget::OnToggleStartStop()
-{
- emu_thread.SetCpuRunning(!emu_thread.IsCpuRunning());
+void DisassemblerWidget::OnToggleStartStop() {
+ emu_thread->SetRunning(!emu_thread->IsRunning());
}
-void DisassemblerWidget::OnDebugModeEntered()
-{
+void DisassemblerWidget::OnDebugModeEntered() {
ARMword next_instr = Core::g_app_core->GetPC();
- // TODO: Make BreakPoints less crappy (i.e. const-correct) so that this doesn't need a const_cast.
- if (const_cast<BreakPoints&>(model->GetBreakPoints()).IsAddressBreakPoint(next_instr))
- {
- emu_thread.SetCpuRunning(false);
- }
+ if (model->GetBreakPoints().IsAddressBreakPoint(next_instr))
+ emu_thread->SetRunning(false);
model->SetNextInstruction(next_instr);
@@ -245,16 +229,35 @@ void DisassemblerWidget::OnDebugModeEntered()
disasm_ui.treeView->selectionModel()->setCurrentIndex(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
}
-void DisassemblerWidget::OnDebugModeLeft()
-{
-
+void DisassemblerWidget::OnDebugModeLeft() {
}
-int DisassemblerWidget::SelectedRow()
-{
+int DisassemblerWidget::SelectedRow() {
QModelIndex index = disasm_ui.treeView->selectionModel()->currentIndex();
if (!index.isValid())
return -1;
return disasm_ui.treeView->selectionModel()->currentIndex().row();
}
+
+void DisassemblerWidget::OnEmulationStarting(EmuThread* emu_thread) {
+ this->emu_thread = emu_thread;
+
+ model = new DisassemblerModel(this);
+ disasm_ui.treeView->setModel(model);
+
+ connect(disasm_ui.treeView->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)),
+ model, SLOT(OnSelectionChanged(const QModelIndex&)));
+ connect(disasm_ui.button_breakpoint, SIGNAL(clicked()), model, SLOT(OnSetOrUnsetBreakpoint()));
+ connect(GetHotkey("Disassembler", "Set Breakpoint", this), SIGNAL(activated()), model, SLOT(OnSetOrUnsetBreakpoint()));
+
+ Init();
+ setEnabled(true);
+}
+
+void DisassemblerWidget::OnEmulationStopping() {
+ disasm_ui.treeView->setModel(nullptr);
+ delete model;
+ emu_thread = nullptr;
+ setEnabled(false);
+}
diff --git a/src/citra_qt/debugger/disassembler.h b/src/citra_qt/debugger/disassembler.h
index 5e19d7c5..340fb993 100644
--- a/src/citra_qt/debugger/disassembler.h
+++ b/src/citra_qt/debugger/disassembler.h
@@ -9,8 +9,8 @@
#include "ui_disassembler.h"
-#include "common/common.h"
#include "common/break_points.h"
+#include "common/common_types.h"
class QAction;
class EmuThread;
@@ -51,7 +51,7 @@ class DisassemblerWidget : public QDockWidget
Q_OBJECT
public:
- DisassemblerWidget(QWidget* parent, EmuThread& emu_thread);
+ DisassemblerWidget(QWidget* parent, EmuThread* emu_thread);
void Init();
@@ -65,6 +65,9 @@ public slots:
void OnDebugModeEntered();
void OnDebugModeLeft();
+ void OnEmulationStarting(EmuThread* emu_thread);
+ void OnEmulationStopping();
+
private:
// returns -1 if no row is selected
int SelectedRow();
@@ -75,5 +78,5 @@ private:
u32 base_addr;
- EmuThread& emu_thread;
+ EmuThread* emu_thread;
};
diff --git a/src/citra_qt/debugger/graphics_breakpoints.cpp b/src/citra_qt/debugger/graphics_breakpoints.cpp
index 92348be3..1da64f61 100644
--- a/src/citra_qt/debugger/graphics_breakpoints.cpp
+++ b/src/citra_qt/debugger/graphics_breakpoints.cpp
@@ -8,6 +8,8 @@
#include <QVBoxLayout>
#include <QLabel>
+#include "common/assert.h"
+
#include "graphics_breakpoints.h"
#include "graphics_breakpoints_p.h"
diff --git a/src/citra_qt/debugger/graphics_breakpoints_p.h b/src/citra_qt/debugger/graphics_breakpoints_p.h
index 232bfc86..34e72e85 100644
--- a/src/citra_qt/debugger/graphics_breakpoints_p.h
+++ b/src/citra_qt/debugger/graphics_breakpoints_p.h
@@ -25,7 +25,7 @@ public:
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
- bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
+ bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
public slots:
void OnBreakPointHit(Pica::DebugContext::Event event);
diff --git a/src/citra_qt/debugger/graphics_cmdlists.cpp b/src/citra_qt/debugger/graphics_cmdlists.cpp
index 9bcd2582..66e11dd5 100644
--- a/src/citra_qt/debugger/graphics_cmdlists.cpp
+++ b/src/citra_qt/debugger/graphics_cmdlists.cpp
@@ -159,7 +159,7 @@ void TextureInfoDockWidget::OnStrideChanged(int value) {
}
QPixmap TextureInfoDockWidget::ReloadPixmap() const {
- u8* src = Memory::GetPointer(Pica::PAddrToVAddr(info.physical_address));
+ u8* src = Memory::GetPhysicalPointer(info.physical_address);
return QPixmap::fromImage(LoadTexture(src, info));
}
@@ -274,7 +274,7 @@ void GPUCommandListWidget::SetCommandInfo(const QModelIndex& index) {
auto format = Pica::registers.GetTextures()[index].format;
auto info = Pica::DebugUtils::TextureInfo::FromPicaRegister(config, format);
- u8* src = Memory::GetPointer(Pica::PAddrToVAddr(config.GetPhysicalAddress()));
+ u8* src = Memory::GetPhysicalPointer(config.GetPhysicalAddress());
new_info_widget = new TextureInfoWidget(src, info);
} else {
new_info_widget = new QWidget;
diff --git a/src/citra_qt/debugger/graphics_framebuffer.cpp b/src/citra_qt/debugger/graphics_framebuffer.cpp
index d621d720..0c1a3f47 100644
--- a/src/citra_qt/debugger/graphics_framebuffer.cpp
+++ b/src/citra_qt/debugger/graphics_framebuffer.cpp
@@ -10,6 +10,8 @@
#include <QSpinBox>
#include "core/hw/gpu.h"
+#include "core/memory.h"
+
#include "video_core/color.h"
#include "video_core/pica.h"
#include "video_core/utils.h"
@@ -215,7 +217,7 @@ void GraphicsFramebufferWidget::OnUpdate()
u32 bytes_per_pixel = GraphicsFramebufferWidget::BytesPerPixel(framebuffer_format);
QImage decoded_image(framebuffer_width, framebuffer_height, QImage::Format_ARGB32);
- u8* buffer = Memory::GetPointer(Pica::PAddrToVAddr(framebuffer_address));
+ u8* buffer = Memory::GetPhysicalPointer(framebuffer_address);
for (unsigned int y = 0; y < framebuffer_height; ++y) {
for (unsigned int x = 0; x < framebuffer_width; ++x) {
diff --git a/src/citra_qt/debugger/profiler.cpp b/src/citra_qt/debugger/profiler.cpp
index ae0568b6..2ac1748b 100644
--- a/src/citra_qt/debugger/profiler.cpp
+++ b/src/citra_qt/debugger/profiler.cpp
@@ -26,7 +26,7 @@ static QVariant GetDataForColumn(int col, const AggregatedDuration& duration)
static const TimingCategoryInfo* GetCategoryInfo(int id)
{
const auto& categories = GetProfilingManager().GetTimingCategoriesInfo();
- if (id >= categories.size()) {
+ if ((size_t)id >= categories.size()) {
return nullptr;
} else {
return &categories[id];
@@ -98,7 +98,7 @@ QVariant ProfilerModel::data(const QModelIndex& index, int role) const
const TimingCategoryInfo* info = GetCategoryInfo(index.row() - 2);
return info != nullptr ? QString(info->name) : QVariant();
} else {
- if (index.row() - 2 < results.time_per_category.size()) {
+ if (index.row() - 2 < (int)results.time_per_category.size()) {
return GetDataForColumn(index.column(), results.time_per_category[index.row() - 2]);
} else {
return QVariant();
diff --git a/src/citra_qt/debugger/profiler.h b/src/citra_qt/debugger/profiler.h
index a6d87aa0..fabf279b 100644
--- a/src/citra_qt/debugger/profiler.h
+++ b/src/citra_qt/debugger/profiler.h
@@ -18,7 +18,7 @@ class ProfilerModel : public QAbstractItemModel
public:
ProfilerModel(QObject* parent);
- QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
+ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex& child) const override;
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
diff --git a/src/citra_qt/debugger/ramview.cpp b/src/citra_qt/debugger/ramview.cpp
index 88570f2c..b6ebc7fc 100644
--- a/src/citra_qt/debugger/ramview.cpp
+++ b/src/citra_qt/debugger/ramview.cpp
@@ -4,8 +4,7 @@
#include "ramview.h"
-#include "common/common.h"
-#include "core/mem_map.h"
+
GRamView::GRamView(QWidget* parent) : QHexEdit(parent)
{
}
diff --git a/src/citra_qt/debugger/registers.cpp b/src/citra_qt/debugger/registers.cpp
index ab366615..5527a2af 100644
--- a/src/citra_qt/debugger/registers.cpp
+++ b/src/citra_qt/debugger/registers.cpp
@@ -7,8 +7,7 @@
#include "core/core.h"
#include "core/arm/arm_interface.h"
-RegistersWidget::RegistersWidget(QWidget* parent) : QDockWidget(parent)
-{
+RegistersWidget::RegistersWidget(QWidget* parent) : QDockWidget(parent) {
cpu_regs_ui.setupUi(this);
tree = cpu_regs_ui.treeWidget;
@@ -18,8 +17,7 @@ RegistersWidget::RegistersWidget(QWidget* parent) : QDockWidget(parent)
registers->setExpanded(true);
CSPR->setExpanded(true);
- for (int i = 0; i < 16; ++i)
- {
+ for (int i = 0; i < 16; ++i) {
QTreeWidgetItem* child = new QTreeWidgetItem(QStringList(QString("R[%1]").arg(i, 2, 10, QLatin1Char('0'))));
registers->addChild(child);
}
@@ -39,12 +37,16 @@ RegistersWidget::RegistersWidget(QWidget* parent) : QDockWidget(parent)
CSPR->addChild(new QTreeWidgetItem(QStringList("C")));
CSPR->addChild(new QTreeWidgetItem(QStringList("Z")));
CSPR->addChild(new QTreeWidgetItem(QStringList("N")));
+
+ setEnabled(false);
}
-void RegistersWidget::OnDebugModeEntered()
-{
+void RegistersWidget::OnDebugModeEntered() {
ARM_Interface* app_core = Core::g_app_core;
+ if (app_core == nullptr)
+ return;
+
for (int i = 0; i < 16; ++i)
registers->child(i)->setText(1, QString("0x%1").arg(app_core->GetReg(i), 8, 16, QLatin1Char('0')));
@@ -66,7 +68,22 @@ void RegistersWidget::OnDebugModeEntered()
CSPR->child(14)->setText(1, QString("%1").arg((app_core->GetCPSR() >> 31) & 0x1)); // N - Negative/Less than
}
-void RegistersWidget::OnDebugModeLeft()
-{
+void RegistersWidget::OnDebugModeLeft() {
+}
+
+void RegistersWidget::OnEmulationStarting(EmuThread* emu_thread) {
+ setEnabled(true);
+}
+
+void RegistersWidget::OnEmulationStopping() {
+ // Reset widget text
+ for (int i = 0; i < 16; ++i)
+ registers->child(i)->setText(1, QString(""));
+
+ for (int i = 0; i < 15; ++i)
+ CSPR->child(i)->setText(1, QString(""));
+
+ CSPR->setText(1, QString(""));
+ setEnabled(false);
}
diff --git a/src/citra_qt/debugger/registers.h b/src/citra_qt/debugger/registers.h
index bf895562..68e3fb90 100644
--- a/src/citra_qt/debugger/registers.h
+++ b/src/citra_qt/debugger/registers.h
@@ -8,6 +8,7 @@
#include <QTreeWidgetItem>
class QTreeWidget;
+class EmuThread;
class RegistersWidget : public QDockWidget
{
@@ -20,6 +21,9 @@ public slots:
void OnDebugModeEntered();
void OnDebugModeLeft();
+ void OnEmulationStarting(EmuThread* emu_thread);
+ void OnEmulationStopping();
+
private:
Ui::ARMRegisters cpu_regs_ui;
diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp
index e5ca0412..7b028e32 100644
--- a/src/citra_qt/main.cpp
+++ b/src/citra_qt/main.cpp
@@ -10,11 +10,11 @@
#include "qhexedit.h"
#include "main.h"
-#include "common/common.h"
#include "common/logging/text_formatter.h"
#include "common/logging/log.h"
#include "common/logging/backend.h"
#include "common/logging/filter.h"
+#include "common/make_unique.h"
#include "common/platform.h"
#include "common/scope_exit.h"
@@ -46,7 +46,7 @@
#include "version.h"
-GMainWindow::GMainWindow()
+GMainWindow::GMainWindow() : emu_thread(nullptr)
{
Pica::g_debug_context = Pica::DebugContext::Construct();
@@ -55,14 +55,14 @@ GMainWindow::GMainWindow()
ui.setupUi(this);
statusBar()->hide();
- render_window = new GRenderWindow;
+ render_window = new GRenderWindow(this, emu_thread.get());
render_window->hide();
profilerWidget = new ProfilerWidget(this);
addDockWidget(Qt::BottomDockWidgetArea, profilerWidget);
profilerWidget->hide();
- disasmWidget = new DisassemblerWidget(this, render_window->GetEmuThread());
+ disasmWidget = new DisassemblerWidget(this, emu_thread.get());
addDockWidget(Qt::BottomDockWidgetArea, disasmWidget);
disasmWidget->hide();
@@ -138,14 +138,12 @@ GMainWindow::GMainWindow()
connect(ui.action_Single_Window_Mode, SIGNAL(triggered(bool)), this, SLOT(ToggleWindowMode()));
connect(ui.action_Hotkeys, SIGNAL(triggered()), this, SLOT(OnOpenHotkeysDialog()));
- // BlockingQueuedConnection is important here, it makes sure we've finished refreshing our views before the CPU continues
- connect(&render_window->GetEmuThread(), SIGNAL(DebugModeEntered()), disasmWidget, SLOT(OnDebugModeEntered()), Qt::BlockingQueuedConnection);
- connect(&render_window->GetEmuThread(), SIGNAL(DebugModeEntered()), registersWidget, SLOT(OnDebugModeEntered()), Qt::BlockingQueuedConnection);
- connect(&render_window->GetEmuThread(), SIGNAL(DebugModeEntered()), callstackWidget, SLOT(OnDebugModeEntered()), Qt::BlockingQueuedConnection);
-
- connect(&render_window->GetEmuThread(), SIGNAL(DebugModeLeft()), disasmWidget, SLOT(OnDebugModeLeft()), Qt::BlockingQueuedConnection);
- connect(&render_window->GetEmuThread(), SIGNAL(DebugModeLeft()), registersWidget, SLOT(OnDebugModeLeft()), Qt::BlockingQueuedConnection);
- connect(&render_window->GetEmuThread(), SIGNAL(DebugModeLeft()), callstackWidget, SLOT(OnDebugModeLeft()), Qt::BlockingQueuedConnection);
+ connect(this, SIGNAL(EmulationStarting(EmuThread*)), disasmWidget, SLOT(OnEmulationStarting(EmuThread*)));
+ connect(this, SIGNAL(EmulationStopping()), disasmWidget, SLOT(OnEmulationStopping()));
+ connect(this, SIGNAL(EmulationStarting(EmuThread*)), registersWidget, SLOT(OnEmulationStarting(EmuThread*)));
+ connect(this, SIGNAL(EmulationStopping()), registersWidget, SLOT(OnEmulationStopping()));
+ connect(this, SIGNAL(EmulationStarting(EmuThread*)), render_window, SLOT(OnEmulationStarting(EmuThread*)));
+ connect(this, SIGNAL(EmulationStopping()), render_window, SLOT(OnEmulationStopping()));
// Setup hotkeys
RegisterHotkey("Main Window", "Load File", QKeySequence::Open);
@@ -196,32 +194,76 @@ void GMainWindow::OnDisplayTitleBars(bool show)
}
}
-void GMainWindow::BootGame(std::string filename)
-{
+void GMainWindow::BootGame(std::string filename) {
LOG_INFO(Frontend, "Citra starting...\n");
+
+ // Initialize the core emulation
System::Init(render_window);
- // Load a game or die...
+ // Load the game
if (Loader::ResultStatus::Success != Loader::LoadFile(filename)) {
LOG_CRITICAL(Frontend, "Failed to load ROM!");
+ System::Shutdown();
+ return;
}
- disasmWidget->Init();
+ // Create and start the emulation thread
+ emu_thread = Common::make_unique<EmuThread>(render_window);
+ emit EmulationStarting(emu_thread.get());
+ emu_thread->start();
+
+ // BlockingQueuedConnection is important here, it makes sure we've finished refreshing our views before the CPU continues
+ connect(emu_thread.get(), SIGNAL(DebugModeEntered()), disasmWidget, SLOT(OnDebugModeEntered()), Qt::BlockingQueuedConnection);
+ connect(emu_thread.get(), SIGNAL(DebugModeEntered()), registersWidget, SLOT(OnDebugModeEntered()), Qt::BlockingQueuedConnection);
+ connect(emu_thread.get(), SIGNAL(DebugModeEntered()), callstackWidget, SLOT(OnDebugModeEntered()), Qt::BlockingQueuedConnection);
+ connect(emu_thread.get(), SIGNAL(DebugModeLeft()), disasmWidget, SLOT(OnDebugModeLeft()), Qt::BlockingQueuedConnection);
+ connect(emu_thread.get(), SIGNAL(DebugModeLeft()), registersWidget, SLOT(OnDebugModeLeft()), Qt::BlockingQueuedConnection);
+ connect(emu_thread.get(), SIGNAL(DebugModeLeft()), callstackWidget, SLOT(OnDebugModeLeft()), Qt::BlockingQueuedConnection);
+
+ // Update the GUI
registersWidget->OnDebugModeEntered();
callstackWidget->OnDebugModeEntered();
-
- render_window->GetEmuThread().SetFilename(filename);
- render_window->GetEmuThread().start();
-
render_window->show();
+
OnStartGame();
}
+void GMainWindow::ShutdownGame() {
+ emu_thread->RequestStop();
+
+ // Release emu threads from any breakpoints
+ // This belongs after RequestStop() and before wait() because if emulation stops on a GPU
+ // breakpoint after (or before) RequestStop() is called, the emulation would never be able
+ // to continue out to the main loop and terminate. Thus wait() would hang forever.
+ // TODO(bunnei): This function is not thread safe, but it's being used as if it were
+ Pica::g_debug_context->ClearBreakpoints();
+
+ emit EmulationStopping();
+
+ // Wait for emulation thread to complete and delete it
+ emu_thread->wait();
+ emu_thread = nullptr;
+
+ // Shutdown the core emulation
+ System::Shutdown();
+
+ // Update the GUI
+ ui.action_Start->setEnabled(false);
+ ui.action_Pause->setEnabled(false);
+ ui.action_Stop->setEnabled(false);
+ render_window->hide();
+}
+
void GMainWindow::OnMenuLoadFile()
{
- QString filename = QFileDialog::getOpenFileName(this, tr("Load File"), QString(), tr("3DS executable (*.3ds *.3dsx *.elf *.axf *.bin *.cci *.cxi)"));
- if (filename.size())
- BootGame(filename.toLatin1().data());
+ QString filename = QFileDialog::getOpenFileName(this, tr("Load File"), QString(), tr("3DS executable (*.3ds *.3dsx *.elf *.axf *.cci *.cxi)"));
+ if (filename.size()) {
+ // Shutdown previous session if the emu thread is still active...
+ if (emu_thread != nullptr)
+ ShutdownGame();
+
+ BootGame(filename.toLatin1().data());
+ }
}
void GMainWindow::OnMenuLoadSymbolMap() {
@@ -232,7 +274,7 @@ void GMainWindow::OnMenuLoadSymbolMap() {
void GMainWindow::OnStartGame()
{
- render_window->GetEmuThread().SetCpuRunning(true);
+ emu_thread->SetRunning(true);
ui.action_Start->setEnabled(false);
ui.action_Pause->setEnabled(true);
@@ -241,21 +283,15 @@ void GMainWindow::OnStartGame()
void GMainWindow::OnPauseGame()
{
- render_window->GetEmuThread().SetCpuRunning(false);
+ emu_thread->SetRunning(false);
ui.action_Start->setEnabled(true);
ui.action_Pause->setEnabled(false);
ui.action_Stop->setEnabled(true);
}
-void GMainWindow::OnStopGame()
-{
- render_window->GetEmuThread().SetCpuRunning(false);
- // TODO: Shutdown core
-
- ui.action_Start->setEnabled(true);
- ui.action_Pause->setEnabled(false);
- ui.action_Stop->setEnabled(false);
+void GMainWindow::OnStopGame() {
+ ShutdownGame();
}
void GMainWindow::OnOpenHotkeysDialog()
@@ -265,24 +301,22 @@ void GMainWindow::OnOpenHotkeysDialog()
}
-void GMainWindow::ToggleWindowMode()
-{
- bool enable = ui.action_Single_Window_Mode->isChecked();
- if (!enable && render_window->parent() != nullptr)
- {
- ui.horizontalLayout->removeWidget(render_window);
- render_window->setParent(nullptr);
- render_window->setVisible(true);
- render_window->RestoreGeometry();
- render_window->setFocusPolicy(Qt::NoFocus);
- }
- else if (enable && render_window->parent() == nullptr)
- {
+void GMainWindow::ToggleWindowMode() {
+ if (ui.action_Single_Window_Mode->isChecked()) {
+ // Render in the main window...
render_window->BackupGeometry();
ui.horizontalLayout->addWidget(render_window);
render_window->setVisible(true);
render_window->setFocusPolicy(Qt::ClickFocus);
render_window->setFocus();
+
+ } else {
+ // Render in a separate window...
+ ui.horizontalLayout->removeWidget(render_window);
+ render_window->setParent(nullptr);
+ render_window->setVisible(true);
+ render_window->RestoreGeometry();
+ render_window->setFocusPolicy(Qt::NoFocus);
}
}
@@ -303,6 +337,10 @@ void GMainWindow::closeEvent(QCloseEvent* event)
settings.setValue("firstStart", false);
SaveHotkeys(settings);
+ // Shutdown session if the emu thread is active...
+ if (emu_thread != nullptr)
+ ShutdownGame();
+
render_window->close();
QWidget::closeEvent(event);
@@ -312,7 +350,7 @@ void GMainWindow::closeEvent(QCloseEvent* event)
#undef main
#endif
-int __cdecl main(int argc, char* argv[])
+int main(int argc, char* argv[])
{
std::shared_ptr<Log::Logger> logger = Log::InitGlobalLogger();
Log::Filter log_filter(Log::Level::Info);
diff --git a/src/citra_qt/main.h b/src/citra_qt/main.h
index 9b57c577..3e29534f 100644
--- a/src/citra_qt/main.h
+++ b/src/citra_qt/main.h
@@ -5,12 +5,14 @@
#ifndef _CITRA_QT_MAIN_HXX_
#define _CITRA_QT_MAIN_HXX_
+#include <memory>
#include <QMainWindow>
#include "ui_main.h"
class GImageInfo;
class GRenderWindow;
+class EmuThread;
class ProfilerWidget;
class DisassemblerWidget;
class RegistersWidget;
@@ -34,8 +36,27 @@ public:
GMainWindow();
~GMainWindow();
+signals:
+
+ /**
+ * Signal that is emitted when a new EmuThread has been created and an emulation session is
+ * about to start. At this time, the core system emulation has been initialized, and all
+ * emulation handles and memory should be valid.
+ *
+ * @param emu_thread Pointer to the newly created EmuThread (to be used by widgets that need to
+ * access/change emulation state).
+ */
+ void EmulationStarting(EmuThread* emu_thread);
+
+ /**
+ * Signal that is emitted when emulation is about to stop. At this time, the EmuThread and core
+ * system emulation handles and memory are still valid, but are about become invalid.
+ */
+ void EmulationStopping();
+
private:
void BootGame(std::string filename);
+ void ShutdownGame();
void closeEvent(QCloseEvent* event) override;
@@ -55,6 +76,8 @@ private:
GRenderWindow* render_window;
+ std::unique_ptr<EmuThread> emu_thread;
+
ProfilerWidget* profilerWidget;
DisassemblerWidget* disasmWidget;
RegistersWidget* registersWidget;
diff --git a/src/citra_qt/main.ui b/src/citra_qt/main.ui
index a3752ac1..68980646 100644
--- a/src/citra_qt/main.ui
+++ b/src/citra_qt/main.ui
@@ -90,6 +90,9 @@
</property>
</action>
<action name="action_Start">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
<property name="text">
<string>&amp;Start</string>
</property>
diff --git a/src/citra_qt/util/spinbox.cpp b/src/citra_qt/util/spinbox.cpp
index 2e2076a2..de406011 100644
--- a/src/citra_qt/util/spinbox.cpp
+++ b/src/citra_qt/util/spinbox.cpp
@@ -29,6 +29,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#include <cstdlib>
#include <QLineEdit>
#include <QRegExpValidator>
@@ -206,7 +207,7 @@ QString CSpinBox::TextFromValue()
{
return prefix
+ QString(HasSign() ? ((value < 0) ? "-" : "+") : "")
- + QString("%1").arg(abs(value), num_digits, base, QLatin1Char('0')).toUpper()
+ + QString("%1").arg(std::abs(value), num_digits, base, QLatin1Char('0')).toUpper()
+ suffix;
}