From 44c6e94f8ba529e74690633844ed251f73c7c206 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sun, 31 Dec 2017 21:42:51 -0500 Subject: [PATCH] Qt: Add unused RegisterView class --- src/platform/qt/CMakeLists.txt | 1 + src/platform/qt/RegisterView.cpp | 144 +++++++++++++++++++++++++++++++ src/platform/qt/RegisterView.h | 40 +++++++++ 3 files changed, 185 insertions(+) create mode 100644 src/platform/qt/RegisterView.cpp create mode 100644 src/platform/qt/RegisterView.h diff --git a/src/platform/qt/CMakeLists.txt b/src/platform/qt/CMakeLists.txt index 8588f3b38..340a823cd 100644 --- a/src/platform/qt/CMakeLists.txt +++ b/src/platform/qt/CMakeLists.txt @@ -99,6 +99,7 @@ set(SOURCE_FILES OverrideView.cpp PaletteView.cpp PrinterView.cpp + RegisterView.cpp ROMInfo.cpp SavestateButton.cpp SensorView.cpp diff --git a/src/platform/qt/RegisterView.cpp b/src/platform/qt/RegisterView.cpp new file mode 100644 index 000000000..0211f13cb --- /dev/null +++ b/src/platform/qt/RegisterView.cpp @@ -0,0 +1,144 @@ +/* Copyright (c) 2013-2017 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "RegisterView.h" + +#include "CoreController.h" + +#ifdef M_CORE_GBA +#include +#endif +#ifdef M_CORE_GB +#include +#endif + +#include +#include +#include + +using namespace QGBA; + +RegisterView::RegisterView(std::shared_ptr controller, QWidget* parent) + : QWidget(parent) + , m_controller(controller) +{ + QFormLayout* layout = new QFormLayout; + setLayout(layout); + + switch (controller->platform()) { +#ifdef M_CORE_GBA + case PLATFORM_GBA: + addRegisters({ + "r0", + "r1", + "r2", + "r3", + "r4", + "r5", + "r6", + "r7", + "r8", + "r9", + "r10", + "r11", + "r12", + "sp", + "lr", + "pc", + "cpsr", + }); + break; +#endif +#ifdef M_CORE_GB + case PLATFORM_GB: + addRegisters({ + "a", + "f", + "b", + "c", + "d", + "e", + "h", + "l", + "sp", + "pc" + }); + break; +#endif + default: + break; + } +} + +void RegisterView::addRegisters(const QStringList& names) { + QFormLayout* form = static_cast(layout()); + const QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont); + for (const auto& reg : names) { + QLabel* value = new QLabel; + value->setTextInteractionFlags(Qt::TextSelectableByMouse); + value->setFont(font); + form->addWidget(value); + m_registers[reg] = value; + form->addRow(reg, value); + } +} + +void RegisterView::updateRegisters() { + switch (m_controller->platform()) { +#ifdef M_CORE_GBA + case PLATFORM_GBA: + updateRegistersARM(); + break; +#endif +#ifdef M_CORE_GB + case PLATFORM_GB: + updateRegistersLR35902(); + break; +#endif + default: + break; + } +} + +#ifdef M_CORE_GBA +void RegisterView::updateRegistersARM() { + CoreController::Interrupter interrupter(m_controller); + struct ARMCore* core = static_cast(m_controller->thread()->core->cpu); + m_registers["r0"]->setText(QString("%1").arg((uint32_t) core->gprs[0], 8, 16, QChar('0')).toUpper()); + m_registers["r1"]->setText(QString("%1").arg((uint32_t) core->gprs[1], 8, 16, QChar('0')).toUpper()); + m_registers["r2"]->setText(QString("%1").arg((uint32_t) core->gprs[2], 8, 16, QChar('0')).toUpper()); + m_registers["r3"]->setText(QString("%1").arg((uint32_t) core->gprs[3], 8, 16, QChar('0')).toUpper()); + m_registers["r4"]->setText(QString("%1").arg((uint32_t) core->gprs[4], 8, 16, QChar('0')).toUpper()); + m_registers["r5"]->setText(QString("%1").arg((uint32_t) core->gprs[5], 8, 16, QChar('0')).toUpper()); + m_registers["r6"]->setText(QString("%1").arg((uint32_t) core->gprs[6], 8, 16, QChar('0')).toUpper()); + m_registers["r7"]->setText(QString("%1").arg((uint32_t) core->gprs[7], 8, 16, QChar('0')).toUpper()); + m_registers["r8"]->setText(QString("%1").arg((uint32_t) core->gprs[8], 8, 16, QChar('0')).toUpper()); + m_registers["r9"]->setText(QString("%1").arg((uint32_t) core->gprs[9], 8, 16, QChar('0')).toUpper()); + m_registers["r10"]->setText(QString("%1").arg((uint32_t) core->gprs[10], 8, 16, QChar('0')).toUpper()); + m_registers["r11"]->setText(QString("%1").arg((uint32_t) core->gprs[11], 8, 16, QChar('0')).toUpper()); + m_registers["r12"]->setText(QString("%1").arg((uint32_t) core->gprs[12], 8, 16, QChar('0')).toUpper()); + m_registers["sp"]->setText(QString("%1").arg((uint32_t) core->gprs[ARM_SP], 8, 16, QChar('0')).toUpper()); + m_registers["lr"]->setText(QString("%1").arg((uint32_t) core->gprs[ARM_LR], 8, 16, QChar('0')).toUpper()); + m_registers["pc"]->setText(QString("%1").arg((uint32_t) core->gprs[ARM_PC], 8, 16, QChar('0')).toUpper()); + m_registers["cpsr"]->setText(QString("%1").arg((uint32_t) core->cpsr.packed, 8, 16, QChar('0')).toUpper()); +} +#endif + +#ifdef M_CORE_GB +void RegisterView::updateRegistersLR35902() { + CoreController::Interrupter interrupter(m_controller); + struct LR35902Core* core = static_cast(m_controller->thread()->core->cpu); + m_registers["a"]->setText(QString("%1").arg((uint8_t) core->a, 2, 16, QChar('0')).toUpper()); + m_registers["f"]->setText(QString("%1").arg((uint8_t) core->f.packed, 2, 16, QChar('0')).toUpper()); + m_registers["b"]->setText(QString("%1").arg((uint8_t) core->b, 2, 16, QChar('0')).toUpper()); + m_registers["c"]->setText(QString("%1").arg((uint8_t) core->c, 2, 16, QChar('0')).toUpper()); + m_registers["d"]->setText(QString("%1").arg((uint8_t) core->d, 2, 16, QChar('0')).toUpper()); + m_registers["e"]->setText(QString("%1").arg((uint8_t) core->e, 2, 16, QChar('0')).toUpper()); + m_registers["h"]->setText(QString("%1").arg((uint8_t) core->h, 2, 16, QChar('0')).toUpper()); + m_registers["l"]->setText(QString("%1").arg((uint8_t) core->l, 2, 16, QChar('0')).toUpper()); + m_registers["sp"]->setText(QString("%1").arg((uint8_t) core->sp, 4, 16, QChar('0')).toUpper()); + m_registers["pc"]->setText(QString("%1").arg((uint8_t) core->pc, 4, 16, QChar('0')).toUpper()); +} +#endif diff --git a/src/platform/qt/RegisterView.h b/src/platform/qt/RegisterView.h new file mode 100644 index 000000000..03762a044 --- /dev/null +++ b/src/platform/qt/RegisterView.h @@ -0,0 +1,40 @@ +/* Copyright (c) 2013-2017 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#pragma once + +#include +#include + +class QLabel; + +namespace QGBA { + +class CoreController; + +class RegisterView : public QWidget { +Q_OBJECT + +public: + RegisterView(std::shared_ptr controller, QWidget* parent = nullptr); + +public slots: + void updateRegisters(); + +private: + void addRegisters(const QStringList& names); +#ifdef M_CORE_GBA + void updateRegistersARM(); +#endif +#ifdef M_CORE_GB + void updateRegistersLR35902(); +#endif + + QMap m_registers; + + std::shared_ptr m_controller; +}; + +}