From 4a8a4a98f3e9c7c9d61d204d58f6758396d5b725 Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Sat, 28 Mar 2020 16:06:33 +0100
Subject: [PATCH] Implementing an indicator of the trust level
---
resources/appResources.qrc | 1 +
resources/icons/continue.svg | 1 +
sources/Debugger/CPUDebug.cpp | 16 ++++++++++++----
sources/Debugger/CPUDebug.hpp | 13 ++++++++++++-
ui/cpu.ui | 20 ++++++++++++++++++--
5 files changed, 44 insertions(+), 7 deletions(-)
create mode 100644 resources/icons/continue.svg
diff --git a/resources/appResources.qrc b/resources/appResources.qrc
index 8e8574c..52163e6 100644
--- a/resources/appResources.qrc
+++ b/resources/appResources.qrc
@@ -1,5 +1,6 @@
+ icons/continue.svg
icons/step.svg
Logo.png
icons/play.svg
diff --git a/resources/icons/continue.svg b/resources/icons/continue.svg
new file mode 100644
index 0000000..9af8782
--- /dev/null
+++ b/resources/icons/continue.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/sources/Debugger/CPUDebug.cpp b/sources/Debugger/CPUDebug.cpp
index 3c180c8..cb8392f 100644
--- a/sources/Debugger/CPUDebug.cpp
+++ b/sources/Debugger/CPUDebug.cpp
@@ -183,6 +183,7 @@ namespace ComSquare::Debugger
while (pc < endAddr) {
DisassembledInstruction instruction = this->_parseInstruction(pc, ctx);
+ instruction.level = ctx.level;
map.push_back(instruction);
pc += instruction.size;
if (instruction.addressingMode == ImmediateForA && !ctx.mFlag)
@@ -214,10 +215,10 @@ namespace ComSquare::Debugger
ctx.mFlag = true;
ctx.xFlag = true;
} else
- ctx.compromised = true;
+ ctx.level = Compromised;
}
if (instruction.opcode == 0xFB) {// XCE
- ctx.compromised = true;
+ ctx.level = Unsafe;
ctx.isEmulationMode = false; // The most common use of the XCE is to enable native mode at the start of the ROM so we guess that it has done that.
}
}
@@ -332,7 +333,7 @@ DisassemblyModel::DisassemblyModel(ComSquare::Debugger::CPUDebug &cpu) : QAbstra
int DisassemblyModel::columnCount(const QModelIndex &) const
{
- return 3;
+ return 4;
}
int DisassemblyModel::rowCount(const QModelIndex &) const
@@ -342,9 +343,16 @@ int DisassemblyModel::rowCount(const QModelIndex &) const
QVariant DisassemblyModel::data(const QModelIndex &index, int role) const
{
- if (role != Qt::DisplayRole)
+ if (role != Qt::DisplayRole && role != Qt::DecorationRole)
return QVariant();
ComSquare::Debugger::DisassembledInstruction instruction = this->_cpu.disassembledInstructions[index.row()];
+ if (role == Qt::DecorationRole) {
+ if (index.column() == 3 && instruction.level == ComSquare::Debugger::TrustLevel::Unsafe)
+ return QColor(Qt::yellow);
+ if (index.column() == 3 && instruction.level == ComSquare::Debugger::TrustLevel::Compromised)
+ return QColor(Qt::red);
+ return QVariant();
+ }
switch (index.column()) {
case 0:
return QString(instruction.name.c_str());
diff --git a/sources/Debugger/CPUDebug.hpp b/sources/Debugger/CPUDebug.hpp
index 4839ee7..2ee125b 100644
--- a/sources/Debugger/CPUDebug.hpp
+++ b/sources/Debugger/CPUDebug.hpp
@@ -56,6 +56,12 @@ protected:
namespace ComSquare::Debugger
{
+ enum TrustLevel {
+ Safe,
+ Unsafe,
+ Compromised
+ };
+
//! @brief Struct used to emulate the state of the processor during the disassembly since instructions take a different amount of space depending on some flags.
struct DisassemblyContext {
//! @brief The accumulator and Memory width flag (in native mode only) - 0 = 16 bits mode, 1 = 8 bits mode.
@@ -67,14 +73,19 @@ namespace ComSquare::Debugger
//! @brief Is the CPU emulating a 6502? If yes, some instructions don't change flags the same way.
bool isEmulationMode = true;
//! @brief Sometimes, the flags can't be tracked correctly after an instruction so the next instructions may not be correctly disassembled.
- bool compromised = false;
+ TrustLevel level = Safe;
};
//! @brief Struct representing an instruction in an human readable way (created by disassembling the rom).
struct DisassembledInstruction : public CPU::Instruction {
+ //! @brief The address of the instruction
uint24_t address;
+ //! @brief A string representing the argument with the right addressing mode.
std::string argument;
+ //! @brief The opcode of the instruction
uint8_t opcode;
+ //! @brief Are we sure that this instruction has been correctly disassembled?
+ TrustLevel level;
DisassembledInstruction(const CPU::Instruction &instruction, uint24_t address, std::string argument, uint8_t opcode);
DisassembledInstruction(const DisassembledInstruction &) = default;
diff --git a/ui/cpu.ui b/ui/cpu.ui
index eada993..bbaf550 100644
--- a/ui/cpu.ui
+++ b/ui/cpu.ui
@@ -220,6 +220,7 @@
false
+
@@ -228,13 +229,13 @@
:/resources/icons/play.svg:/resources/icons/play.svg
- Resume
+ Continue
Pause or Resume instruction execution.
- P
+ C
@@ -252,6 +253,21 @@
S
+
+
+
+ :/resources/icons/continue.svg:/resources/icons/continue.svg
+
+
+ Next
+
+
+ Continue execution to the next line.
+
+
+ N
+
+