From 4fb577f65d761504249d358c752e67751c34c2c8 Mon Sep 17 00:00:00 2001
From: Anonymus Raccoon
Date: Sat, 28 Mar 2020 22:51:28 +0100
Subject: [PATCH] Implementing auto scroll
---
sources/CPU/CPU.hpp | 4 +--
sources/Debugger/CPUDebug.cpp | 47 ++++++++++++++++++++++++-----------
sources/Debugger/CPUDebug.hpp | 5 +++-
3 files changed, 38 insertions(+), 18 deletions(-)
diff --git a/sources/CPU/CPU.hpp b/sources/CPU/CPU.hpp
index 3e45f77..1504737 100644
--- a/sources/CPU/CPU.hpp
+++ b/sources/CPU/CPU.hpp
@@ -476,7 +476,7 @@ namespace ComSquare::CPU
{&CPU::BRK, 7, "eor #-#", AddressingMode::Implied, 2}, // 5D
{&CPU::BRK, 7, "lsr #-#", AddressingMode::Implied, 2}, // 5E
{&CPU::BRK, 7, "eor #-#", AddressingMode::Implied, 2}, // 5F
- {&CPU::BRK, 7, "rtl #-#", AddressingMode::Implied, 2}, // 60
+ {&CPU::BRK, 7, "rtl #-#", AddressingMode::Implied, 1}, // 60
{&CPU::ADC, 6, "adc", AddressingMode::DirectPageIndirectIndexedByX, 2}, // 61
{&CPU::BRK, 7, "per #-#", AddressingMode::Implied, 2}, // 62
{&CPU::ADC, 4, "adc", AddressingMode::StackRelative, 2}, // 63
@@ -487,7 +487,7 @@ namespace ComSquare::CPU
{&CPU::PLA, 4, "pla", AddressingMode::Implied, 1}, // 68
{&CPU::ADC, 2, "adc", AddressingMode::ImmediateForA, 2}, // 69
{&CPU::BRK, 7, "ror #-#", AddressingMode::Implied, 2}, // 6A
- {&CPU::BRK, 7, "rts #-#", AddressingMode::Implied, 2}, // 6B
+ {&CPU::BRK, 7, "rts #-#", AddressingMode::Implied, 1}, // 6B
{&CPU::JMP, 5, "jmp", AddressingMode::AbsoluteIndirect, 3}, // 6C
{&CPU::ADC, 4, "adc", AddressingMode::Absolute, 3}, // 6D
{&CPU::BRK, 7, "ror #-#", AddressingMode::Implied, 2}, // 6E
diff --git a/sources/Debugger/CPUDebug.cpp b/sources/Debugger/CPUDebug.cpp
index 170fb23..1eb696d 100644
--- a/sources/Debugger/CPUDebug.cpp
+++ b/sources/Debugger/CPUDebug.cpp
@@ -29,7 +29,7 @@ namespace ComSquare::Debugger
this->_ui.setupUi(this->_window);
- this->_updateDisassembly(0xFFFF - this->_registers.pc); //Parse the first page of the ROM (the code can't reach the second page without a jump).
+ this->_updateDisassembly(this->_cartridgeHeader.emulationInterrupts.reset, 0xFFFF - this->_cartridgeHeader.emulationInterrupts.reset); //Parse the first page of the ROM (the code can't reach the second page without a jump).
this->_ui.disassembly->setModel(&this->_model);
this->_ui.disassembly->horizontalHeader()->setStretchLastSection(true);
this->_ui.disassembly->resizeColumnsToContents();
@@ -44,6 +44,7 @@ namespace ComSquare::Debugger
QMainWindow::connect(this->_ui.disassembly->verticalHeader(), &QHeaderView::sectionClicked, this, &CPUDebug::toggleBreakpoint);
this->_window->show();
this->_updateRegistersPanel();
+ this->_updateDisassembly(this->_registers.pac, 0);
}
bool CPUDebug::isDebugger()
@@ -65,7 +66,7 @@ namespace ComSquare::Debugger
return 0xFF;
if (this->_isStepping) {
cycles = this->_executeInstruction(this->readPC());
- this->_updateDisassembly();
+ this->_updateDisassembly(this->_registers.pac);
return cycles;
}
@@ -115,7 +116,7 @@ namespace ComSquare::Debugger
this->_ui.actionPause->setText("Resume");
else
this->_ui.actionPause->setText("Pause");
- this->_updateDisassembly();
+ this->_updateDisassembly(this->_registers.pac);
}
void CPUDebug::step()
@@ -190,25 +191,28 @@ namespace ComSquare::Debugger
this->_ui.logger->clear();
}
- void CPUDebug::_updateDisassembly(uint24_t refreshSize)
+ void CPUDebug::_updateDisassembly(uint24_t start, uint24_t refreshSize)
{
- auto first = std::find_if(this->disassembledInstructions.begin(), this->disassembledInstructions.end(), [this](DisassembledInstruction &i) {
- return i.address >= this->_registers.pac;
+ auto first = std::find_if(this->disassembledInstructions.begin(), this->disassembledInstructions.end(), [start](DisassembledInstruction &i) {
+ return i.address >= start;
});
- auto end = std::find_if(this->disassembledInstructions.begin(), this->disassembledInstructions.end(),[this, refreshSize](DisassembledInstruction &i) {
- return i.address >= this->_registers.pac + refreshSize;
+ auto end = std::find_if(this->disassembledInstructions.begin(), this->disassembledInstructions.end(),[start, refreshSize](DisassembledInstruction &i) {
+ return i.address >= start + refreshSize;
});
this->disassembledInstructions.erase(first, end);
- auto next = std::find_if(this->disassembledInstructions.begin(), this->disassembledInstructions.end(), [this](DisassembledInstruction &i) {
- return i.address >= this->_registers.pac;
+ auto next = std::find_if(this->disassembledInstructions.begin(), this->disassembledInstructions.end(), [start](DisassembledInstruction &i) {
+ return i.address >= start;
});
- int row = next - this->disassembledInstructions.begin();
DisassemblyContext ctx = this->_getDisassemblyContext();
- std::vector nextInstructions = this->_disassemble(this->_registers.pac, refreshSize, ctx);
+ std::vector nextInstructions = this->_disassemble(start, refreshSize, ctx);
this->disassembledInstructions.insert(next, nextInstructions.begin(), nextInstructions.end());
- if (this->_ui.disassembly->rowAt(0) > row || this->_ui.disassembly->rowAt(this->_ui.disassembly->height()) < row)
- this->_ui.disassembly->scrollTo(this->_model.index(row, 0), QAbstractItemView::PositionAtCenter);
+
+ int row = next - this->disassembledInstructions.begin();
+ if (this->_ui.disassembly->rowAt(0) > row || this->_ui.disassembly->rowAt(this->_ui.disassembly->height()) < row) {
+ auto index = this->_model.index(row, 0);
+ this->_ui.disassembly->scrollTo(index, QAbstractItemView::PositionAtCenter);
+ }
this->_ui.disassembly->viewport()->repaint();
}
@@ -347,6 +351,8 @@ namespace ComSquare::Debugger
int CPUDebug::RESB()
{
CPU::RESB();
+ this->disassembledInstructions.clear();
+ this->_updateDisassembly(0xFFFF - this->_cartridgeHeader.emulationInterrupts.reset);
this->_updateRegistersPanel();
return (0);
}
@@ -362,7 +368,7 @@ namespace ComSquare::Debugger
}
DisassembledInstruction::DisassembledInstruction(const CPU::Instruction &instruction, uint24_t addr, std::string arg, uint8_t op)
- : CPU::Instruction(instruction), address(addr), argument(std::move(arg)), opcode(op) {}
+ : CPU::Instruction(instruction), address(addr), argument(std::move(arg)), opcode(op), level(Safe) {}
std::string DisassembledInstruction::toString()
{
@@ -414,6 +420,17 @@ QVariant DisassemblyModel::headerData(int section, Qt::Orientation orientation,
return QString(ComSquare::Utility::to_hex(instruction.address, ComSquare::Utility::HexString::NoPrefix).c_str());
}
+void DisassemblyModel::beginReset()
+{
+ this->beginResetModel();
+}
+
+void DisassemblyModel::endReset()
+{
+ this->endResetModel();
+ emit this->dataChanged(this->index(0, 0), this->index(this->_cpu.disassembledInstructions.size(), this->columnCount(QModelIndex())));
+}
+
RowPainter::RowPainter(ComSquare::Debugger::CPUDebug &cpu, QObject *parent) : QStyledItemDelegate(parent), _cpu(cpu) { }
void RowPainter::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
diff --git a/sources/Debugger/CPUDebug.hpp b/sources/Debugger/CPUDebug.hpp
index fb04acb..6d7ab99 100644
--- a/sources/Debugger/CPUDebug.hpp
+++ b/sources/Debugger/CPUDebug.hpp
@@ -37,6 +37,9 @@ public:
QVariant data(const QModelIndex &index, int role) const override;
//! @brief Override the headers to use hex values.
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
+
+ void beginReset();
+ void endReset();
};
//! @brief The qt class that highlight breakpoints and the PC's position
@@ -128,7 +131,7 @@ namespace ComSquare::Debugger
//! @param ctx The initial context of the processor before the disassembly begin.
std::vector _disassemble(uint24_t startAddr, uint24_t size, DisassemblyContext &ctx);
//! @brief Update disassembly with the new state of the processor.
- void _updateDisassembly(uint24_t refreshSize = 0xFF);
+ void _updateDisassembly(uint24_t start, uint24_t refreshSize = 0xFF);
//! @brief Parse the instruction at the program counter given to have human readable information.
DisassembledInstruction _parseInstruction(uint24_t pc, DisassemblyContext &ctx);
//! @brief Get the parameter of the instruction as an hexadecimal string.