mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-06-04 18:46:11 +00:00
Displaying CPU registers
This commit is contained in:
+2
-2
@@ -63,7 +63,7 @@ add_executable(unit_tests
|
||||
tests/CPU/testInternal.cpp
|
||||
sources/Ram/ExtendedRam.cpp
|
||||
sources/Ram/ExtendedRam.hpp
|
||||
)
|
||||
sources/Utility/Utility.hpp)
|
||||
|
||||
# include criterion & coverage
|
||||
target_link_libraries(unit_tests criterion -lgcov)
|
||||
@@ -133,7 +133,7 @@ add_executable(ComSquare
|
||||
resources/appResources.qrc
|
||||
sources/Renderer/QtRenderer/QtWindow.cpp
|
||||
sources/Renderer/QtRenderer/QtWindow.hpp
|
||||
)
|
||||
sources/Utility/Utility.hpp)
|
||||
|
||||
target_compile_definitions(ComSquare PUBLIC DEBUGGER_ENABLED)
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ namespace ComSquare::CPU
|
||||
|
||||
void CPU::PLA()
|
||||
{
|
||||
// TODO this register should be poped by 8 if the m flag is 1
|
||||
this->_registers.a = this->_pop16();
|
||||
this->_registers.p.z = this->_registers.a == 0;
|
||||
this->_registers.p.n = this->_registers.a & 0x8000u;
|
||||
@@ -101,6 +102,7 @@ namespace ComSquare::CPU
|
||||
|
||||
void CPU::PLX()
|
||||
{
|
||||
// TODO this register should be poped by 8 if the x_b is 1
|
||||
this->_registers.x = this->_pop16();
|
||||
this->_registers.p.z = this->_registers.x == 0;
|
||||
this->_registers.p.n = this->_registers.x & 0x8000u;
|
||||
@@ -108,6 +110,7 @@ namespace ComSquare::CPU
|
||||
|
||||
void CPU::PLY()
|
||||
{
|
||||
// TODO this register should be poped by 8 if the x_b is 1
|
||||
this->_registers.y = this->_pop16();
|
||||
this->_registers.p.z = this->_registers.y == 0;
|
||||
this->_registers.p.n = this->_registers.y & 0x8000u;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
//
|
||||
|
||||
#include "DebugCpu.hpp"
|
||||
#include "../Utility/Utility.hpp"
|
||||
|
||||
using namespace ComSquare::CPU;
|
||||
|
||||
@@ -18,6 +19,7 @@ namespace ComSquare::Debugger
|
||||
QMainWindow::connect(this->_ui.actionPause, &QAction::triggered, this, &CPUDebug::pause);
|
||||
QMainWindow::connect(this->_ui.actionStep, &QAction::triggered, this, &CPUDebug::step);
|
||||
this->show();
|
||||
this->_updateRegistersPanel();
|
||||
}
|
||||
|
||||
unsigned CPUDebug::update()
|
||||
@@ -41,6 +43,7 @@ namespace ComSquare::Debugger
|
||||
this->_isPaused = true;
|
||||
}
|
||||
this->_ui.logger->append(CPUDebug::_getInstructionString(opcode).c_str());
|
||||
this->_updateRegistersPanel();
|
||||
return CPU::_executeInstruction(opcode);
|
||||
}
|
||||
|
||||
@@ -59,6 +62,45 @@ namespace ComSquare::Debugger
|
||||
this->_isPaused = false;
|
||||
}
|
||||
|
||||
void CPUDebug::_updateRegistersPanel()
|
||||
{
|
||||
if (!this->_registers.p.m)
|
||||
this->_ui.accumulatorLineEdit->setText(Utility::to_hex(this->_registers.a).c_str());
|
||||
else
|
||||
this->_ui.accumulatorLineEdit->setText(Utility::to_hex(this->_registers.al).c_str());
|
||||
this->_ui.programBankRegisterLineEdit->setText(Utility::to_hex(this->_registers.pbr).c_str());
|
||||
this->_ui.programCounterLineEdit->setText(Utility::to_hex(this->_registers.pc).c_str());
|
||||
this->_ui.directBankLineEdit->setText(Utility::to_hex(this->_registers.dbr).c_str());
|
||||
this->_ui.directPageLineEdit->setText(Utility::to_hex(this->_registers.d).c_str());
|
||||
this->_ui.stackPointerLineEdit->setText(Utility::to_hex(this->_registers.s).c_str());
|
||||
if (this->_registers.p.x_b) {
|
||||
this->_ui.xIndexLineEdit->setText(Utility::to_hex(this->_registers.x).c_str());
|
||||
this->_ui.yIndexLineEdit->setText(Utility::to_hex(this->_registers.y).c_str());
|
||||
} else {
|
||||
this->_ui.xIndexLineEdit->setText(Utility::to_hex(this->_registers.xl).c_str());
|
||||
this->_ui.yIndexLineEdit->setText(Utility::to_hex(this->_registers.yl).c_str());
|
||||
}
|
||||
this->_ui.flagsLineEdit->setText(this->_getFlagsString().c_str());
|
||||
this->_ui.emulationModeCheckBox->setCheckState(this->_isEmulationMode ? Qt::CheckState::Checked : Qt::CheckState::Unchecked);
|
||||
}
|
||||
|
||||
std::string CPUDebug::_getFlagsString()
|
||||
{
|
||||
std::string str;
|
||||
str += this->_registers.p.n ? "n" : "-";
|
||||
str += this->_registers.p.v ? "v" : "-";
|
||||
str += this->_registers.p.m ? "m" : "-";
|
||||
if (this->_isEmulationMode)
|
||||
str += this->_registers.p.x_b ? "b" : "-";
|
||||
else
|
||||
str += this->_registers.p.x_b ? "x" : "-";
|
||||
str += this->_registers.p.d ? "d" : "-";
|
||||
str += this->_registers.p.i ? "i" : "-";
|
||||
str += this->_registers.p.z ? "z" : "-";
|
||||
str += this->_registers.p.c ? "c" : "-";
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string CPUDebug::_getInstructionString(uint8_t opcode)
|
||||
{
|
||||
switch (opcode) {
|
||||
|
||||
@@ -28,6 +28,10 @@ namespace ComSquare::Debugger
|
||||
unsigned _executeInstruction(uint8_t opcode) override;
|
||||
//! @brief Get a printable string representing an instruction.
|
||||
static std::string _getInstructionString(uint8_t opcode);
|
||||
//! @brief Get a printable string representing the flags.
|
||||
std::string _getFlagsString();
|
||||
//! @brief Update the register's panel (accumulator, stack pointer...)
|
||||
void _updateRegistersPanel();
|
||||
public slots:
|
||||
//! @brief Pause/Resume the CPU.
|
||||
void pause();
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// Created by anonymus-raccoon on 2/16/20.
|
||||
//
|
||||
|
||||
#ifndef COMSQUARE_UTILITY_HPP
|
||||
#define COMSQUARE_UTILITY_HPP
|
||||
|
||||
#include <string>
|
||||
#include <ios>
|
||||
#include <sstream>
|
||||
#include "../Models/Int24.hpp"
|
||||
|
||||
namespace ComSquare::Utility
|
||||
{
|
||||
std::string to_hex(uint8_t i)
|
||||
{
|
||||
char buf[5];
|
||||
sprintf(buf, "0x%02X", i);
|
||||
return buf;
|
||||
}
|
||||
|
||||
std::string to_hex(uint16_t i)
|
||||
{
|
||||
char buf[7];
|
||||
sprintf(buf, "0x%04X", i);
|
||||
return buf;
|
||||
}
|
||||
|
||||
std::string to_hex(uint24_t i)
|
||||
{
|
||||
char buf[9];
|
||||
sprintf(buf, "0x%06X", i);
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
#endif //COMSQUARE_UTILITY_HPP
|
||||
@@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>600</width>
|
||||
<height>400</height>
|
||||
<height>399</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -27,7 +27,7 @@
|
||||
<x>0</x>
|
||||
<y>25</y>
|
||||
<width>200</width>
|
||||
<height>375</height>
|
||||
<height>305</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -47,6 +47,126 @@
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QWidget" name="formLayoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>390</x>
|
||||
<y>0</y>
|
||||
<width>201</width>
|
||||
<height>291</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="accumulatorLabel">
|
||||
<property name="text">
|
||||
<string>Accumulator</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="accumulatorLineEdit">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="programBankRegisterLabel">
|
||||
<property name="text">
|
||||
<string>Program Bank</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="programBankRegisterLineEdit"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="programCounterLabel">
|
||||
<property name="text">
|
||||
<string>Program Counter</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="programCounterLineEdit"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="directBankLabel">
|
||||
<property name="text">
|
||||
<string>Direct Bank</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="directBankLineEdit"/>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="directPageLabel">
|
||||
<property name="text">
|
||||
<string>Direct Page</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLineEdit" name="directPageLineEdit"/>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="stackPointerLabel">
|
||||
<property name="text">
|
||||
<string>Stack Pointer</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLineEdit" name="stackPointerLineEdit"/>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="xIndexLabel">
|
||||
<property name="text">
|
||||
<string>X Index</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QLineEdit" name="xIndexLineEdit"/>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="yIndexLabel">
|
||||
<property name="text">
|
||||
<string>Y Index</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QLineEdit" name="yIndexLineEdit"/>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="flagsLabel">
|
||||
<property name="text">
|
||||
<string>Flags</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<widget class="QLineEdit" name="flagsLineEdit"/>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<widget class="QLabel" name="emulationModeLabel">
|
||||
<property name="text">
|
||||
<string>Emulation mode</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="1">
|
||||
<widget class="QCheckBox" name="emulationModeCheckBox">
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::RightToLeft</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
|
||||
Reference in New Issue
Block a user