From 256fea8955687bf83eeb127dceb48e5d3ca6b3e2 Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Tue, 24 Mar 2020 19:25:33 +0100
Subject: [PATCH] Making the CPU debugger's bus read silent
---
sources/Debugger/CPUDebug.cpp | 34 ++++++++++++++---------------
sources/Debugger/MemoryBusDebug.cpp | 20 +++++++++--------
sources/Debugger/MemoryBusDebug.hpp | 2 +-
sources/Memory/MemoryBus.cpp | 2 +-
sources/Memory/MemoryBus.hpp | 3 ++-
5 files changed, 31 insertions(+), 30 deletions(-)
diff --git a/sources/Debugger/CPUDebug.cpp b/sources/Debugger/CPUDebug.cpp
index 30a86ad..df2108a 100644
--- a/sources/Debugger/CPUDebug.cpp
+++ b/sources/Debugger/CPUDebug.cpp
@@ -45,6 +45,8 @@ namespace ComSquare::Debugger
try {
if (this->_isPaused)
return 0xFF;
+ if (this->_isStepping)
+ return this->_executeInstruction(this->_bus->read(this->_registers.pac++));
return CPU::update();
} catch (InvalidOpcode &e) {
if (!this->_isPaused)
@@ -55,10 +57,6 @@ namespace ComSquare::Debugger
unsigned CPUDebug::_executeInstruction(uint8_t opcode)
{
- if (this->_isPaused) {
- this->_registers.pac--;
- return 0;
- }
if (this->_isStepping) {
this->_isStepping = false;
this->_isPaused = true;
@@ -130,10 +128,10 @@ namespace ComSquare::Debugger
std::string CPUDebug::_getImmediateValueForA(uint24_t pc)
{
- unsigned value = this->_bus->read(pc);
+ unsigned value = this->_bus->read(pc, true);
if (!this->_registers.p.m)
- value += this->_bus->read(pc + 1) << 8u;
+ value += this->_bus->read(pc + 1, true) << 8u;
std::stringstream ss;
ss << "#$" << std::hex << value;
return ss.str();
@@ -141,10 +139,10 @@ namespace ComSquare::Debugger
std::string CPUDebug::_getImmediateValueForX(uint24_t pc)
{
- unsigned value = this->_bus->read(pc);
+ unsigned value = this->_bus->read(pc, true);
if (!this->_registers.p.x_b)
- value += this->_bus->read(pc + 1) << 8u;
+ value += this->_bus->read(pc + 1, true) << 8u;
std::stringstream ss;
ss << "#$" << std::hex << value;
return ss.str();
@@ -153,14 +151,14 @@ namespace ComSquare::Debugger
std::string CPUDebug::_getImmediateValue8Bits(uint24_t pc)
{
std::stringstream ss;
- ss << "#$" << std::hex << static_cast(this->_bus->read(pc));
+ ss << "#$" << std::hex << static_cast(this->_bus->read(pc), true);
return ss.str();
}
std::string CPUDebug::_getImmediateValue16Bits(uint24_t pc)
{
- unsigned value = this->_bus->read(pc);
- value += this->_bus->read(pc + 1) << 8u;
+ unsigned value = this->_bus->read(pc, true);
+ value += this->_bus->read(pc + 1, true) << 8u;
std::stringstream ss;
ss << "#$" << std::hex << value;
@@ -170,22 +168,22 @@ namespace ComSquare::Debugger
std::string CPUDebug::_getDirectValue(uint24_t pc)
{
std::stringstream ss;
- ss << "$" << std::hex << static_cast(this->_bus->read(pc));
+ ss << "$" << std::hex << static_cast(this->_bus->read(pc), true);
return ss.str();
}
std::string CPUDebug::_getAbsoluteValue(uint24_t pc)
{
std::stringstream ss;
- ss << "$" << std::hex << (this->_bus->read(pc) + (this->_bus->read(pc + 1) << 8u));
+ ss << "$" << std::hex << (this->_bus->read(pc) + (this->_bus->read(pc + 1) << 8u), true);
return ss.str();
}
std::string CPUDebug::_getAbsoluteLongValue(uint24_t pc)
{
- unsigned value = this->_bus->read(pc++);
- value += this->_bus->read(pc++) << 8u;
- value += this->_bus->read(pc) << 16u;
+ unsigned value = this->_bus->read(pc++, true);
+ value += this->_bus->read(pc++, true) << 8u;
+ value += this->_bus->read(pc, true) << 16u;
std::stringstream ss;
ss << "$" << std::hex << value;
@@ -194,7 +192,7 @@ namespace ComSquare::Debugger
std::string CPUDebug::_getDirectIndexedByXValue(uint24_t pc)
{
- unsigned value = this->_bus->read(pc);
+ unsigned value = this->_bus->read(pc, true);
std::stringstream ss;
ss << "$" << std::hex << value << ", x";
@@ -203,7 +201,7 @@ namespace ComSquare::Debugger
std::string CPUDebug::_getInstructionString(uint24_t pc)
{
- uint8_t opcode = this->_bus->read(pc++);
+ uint8_t opcode = this->_bus->read(pc++, true);
switch (opcode) {
case Instructions::BRK: return "BRK";
diff --git a/sources/Debugger/MemoryBusDebug.cpp b/sources/Debugger/MemoryBusDebug.cpp
index fa02651..18bad54 100644
--- a/sources/Debugger/MemoryBusDebug.cpp
+++ b/sources/Debugger/MemoryBusDebug.cpp
@@ -48,12 +48,13 @@ namespace ComSquare::Debugger
return true;
}
- uint8_t MemoryBusDebug::read(uint24_t addr)
+ uint8_t MemoryBusDebug::read(uint24_t addr, bool silence)
{
- auto accessor = this->getAccessor(addr);
- uint8_t value = accessor->read(addr - accessor->getStart());
- this->_model.log(BusLog(false, addr, accessor, value, value));
-
+ if (!silence) {
+ auto accessor = this->getAccessor(addr);
+ uint8_t value = accessor->read(addr - accessor->getStart());
+ this->_model.log(BusLog(false, addr, accessor, value, value));
+ }
return MemoryBus::read(addr);
}
@@ -134,10 +135,11 @@ QVariant BusLogModel::headerData(int section, Qt::Orientation orientation, int r
void BusLogModel::log(ComSquare::Debugger::BusLog log)
{
- this->_logs.push_back(log);
int row = this->_logs.size();
+ this->beginInsertRows(QModelIndex(), row, row);
+ this->_logs.push_back(log);
this->insertRow(row);
- emit this->layoutChanged();
+ this->endInsertRows();
}
ComSquare::Debugger::BusLog BusLogModel::getLogAt(int index)
@@ -151,7 +153,7 @@ bool BusLoggerProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourcePa
{
ComSquare::Debugger::BusLog log = this->_parent.getLogAt(sourceRow);
- if (log.accessor && log.accessor->getName() == "Cartridge")
- return false;
+// if (log.accessor && log.accessor->getName() == "Cartridge")
+// return false;
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
diff --git a/sources/Debugger/MemoryBusDebug.hpp b/sources/Debugger/MemoryBusDebug.hpp
index c90baf6..61a74d9 100644
--- a/sources/Debugger/MemoryBusDebug.hpp
+++ b/sources/Debugger/MemoryBusDebug.hpp
@@ -120,7 +120,7 @@ namespace ComSquare::Debugger
//! @brief Read data at a global address and log it to the debugger.
//! @param addr The address to read from.
//! @return The value that the component returned for this address. If the address was mapped to ram, it simply returned the value. If the address was mapped to a register the component returned the register.
- uint8_t read(uint24_t addr) override;
+ uint8_t read(uint24_t addr, bool silence = false) override;
//! @brief Write a data to a global address and log it to the debugger.
//! @param addr The address to write to.
diff --git a/sources/Memory/MemoryBus.cpp b/sources/Memory/MemoryBus.cpp
index 5f8a252..12a0391 100644
--- a/sources/Memory/MemoryBus.cpp
+++ b/sources/Memory/MemoryBus.cpp
@@ -22,7 +22,7 @@ namespace ComSquare::Memory
return *it;
}
- uint8_t MemoryBus::read(uint24_t addr)
+ uint8_t MemoryBus::read(uint24_t addr, bool)
{
std::shared_ptr handler = this->getAccessor(addr);
diff --git a/sources/Memory/MemoryBus.hpp b/sources/Memory/MemoryBus.hpp
index 5647ac4..983ebfd 100644
--- a/sources/Memory/MemoryBus.hpp
+++ b/sources/Memory/MemoryBus.hpp
@@ -38,8 +38,9 @@ namespace ComSquare
//! @brief Read data at a global address.
//! @param addr The address to read from.
+ //! @param silence Disable login to the memory bus's debugger (if enabled). Should only be used by other debuggers.
//! @return The value that the component returned for this address. If the address was mapped to ram, it simply returned the value. If the address was mapped to a register the component returned the register.
- virtual uint8_t read(uint24_t addr);
+ virtual uint8_t read(uint24_t addr, bool silence = false);
//! @brief Write a data to a global address.
//! @param addr The address to write to.