Implementing auto scroll

This commit is contained in:
Anonymus Raccoon
2020-03-28 22:51:28 +01:00
parent 686b70dbfd
commit 4fb577f65d
3 changed files with 38 additions and 18 deletions
+2 -2
View File
@@ -476,7 +476,7 @@ namespace ComSquare::CPU
{&CPU::BRK, 7, "eor #-#", AddressingMode::Implied, 2}, // 5D {&CPU::BRK, 7, "eor #-#", AddressingMode::Implied, 2}, // 5D
{&CPU::BRK, 7, "lsr #-#", AddressingMode::Implied, 2}, // 5E {&CPU::BRK, 7, "lsr #-#", AddressingMode::Implied, 2}, // 5E
{&CPU::BRK, 7, "eor #-#", AddressingMode::Implied, 2}, // 5F {&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::ADC, 6, "adc", AddressingMode::DirectPageIndirectIndexedByX, 2}, // 61
{&CPU::BRK, 7, "per #-#", AddressingMode::Implied, 2}, // 62 {&CPU::BRK, 7, "per #-#", AddressingMode::Implied, 2}, // 62
{&CPU::ADC, 4, "adc", AddressingMode::StackRelative, 2}, // 63 {&CPU::ADC, 4, "adc", AddressingMode::StackRelative, 2}, // 63
@@ -487,7 +487,7 @@ namespace ComSquare::CPU
{&CPU::PLA, 4, "pla", AddressingMode::Implied, 1}, // 68 {&CPU::PLA, 4, "pla", AddressingMode::Implied, 1}, // 68
{&CPU::ADC, 2, "adc", AddressingMode::ImmediateForA, 2}, // 69 {&CPU::ADC, 2, "adc", AddressingMode::ImmediateForA, 2}, // 69
{&CPU::BRK, 7, "ror #-#", AddressingMode::Implied, 2}, // 6A {&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::JMP, 5, "jmp", AddressingMode::AbsoluteIndirect, 3}, // 6C
{&CPU::ADC, 4, "adc", AddressingMode::Absolute, 3}, // 6D {&CPU::ADC, 4, "adc", AddressingMode::Absolute, 3}, // 6D
{&CPU::BRK, 7, "ror #-#", AddressingMode::Implied, 2}, // 6E {&CPU::BRK, 7, "ror #-#", AddressingMode::Implied, 2}, // 6E
+32 -15
View File
@@ -29,7 +29,7 @@ namespace ComSquare::Debugger
this->_ui.setupUi(this->_window); 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->setModel(&this->_model);
this->_ui.disassembly->horizontalHeader()->setStretchLastSection(true); this->_ui.disassembly->horizontalHeader()->setStretchLastSection(true);
this->_ui.disassembly->resizeColumnsToContents(); this->_ui.disassembly->resizeColumnsToContents();
@@ -44,6 +44,7 @@ namespace ComSquare::Debugger
QMainWindow::connect(this->_ui.disassembly->verticalHeader(), &QHeaderView::sectionClicked, this, &CPUDebug::toggleBreakpoint); QMainWindow::connect(this->_ui.disassembly->verticalHeader(), &QHeaderView::sectionClicked, this, &CPUDebug::toggleBreakpoint);
this->_window->show(); this->_window->show();
this->_updateRegistersPanel(); this->_updateRegistersPanel();
this->_updateDisassembly(this->_registers.pac, 0);
} }
bool CPUDebug::isDebugger() bool CPUDebug::isDebugger()
@@ -65,7 +66,7 @@ namespace ComSquare::Debugger
return 0xFF; return 0xFF;
if (this->_isStepping) { if (this->_isStepping) {
cycles = this->_executeInstruction(this->readPC()); cycles = this->_executeInstruction(this->readPC());
this->_updateDisassembly(); this->_updateDisassembly(this->_registers.pac);
return cycles; return cycles;
} }
@@ -115,7 +116,7 @@ namespace ComSquare::Debugger
this->_ui.actionPause->setText("Resume"); this->_ui.actionPause->setText("Resume");
else else
this->_ui.actionPause->setText("Pause"); this->_ui.actionPause->setText("Pause");
this->_updateDisassembly(); this->_updateDisassembly(this->_registers.pac);
} }
void CPUDebug::step() void CPUDebug::step()
@@ -190,25 +191,28 @@ namespace ComSquare::Debugger
this->_ui.logger->clear(); 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) { auto first = std::find_if(this->disassembledInstructions.begin(), this->disassembledInstructions.end(), [start](DisassembledInstruction &i) {
return i.address >= this->_registers.pac; return i.address >= start;
}); });
auto end = std::find_if(this->disassembledInstructions.begin(), this->disassembledInstructions.end(),[this, refreshSize](DisassembledInstruction &i) { auto end = std::find_if(this->disassembledInstructions.begin(), this->disassembledInstructions.end(),[start, refreshSize](DisassembledInstruction &i) {
return i.address >= this->_registers.pac + refreshSize; return i.address >= start + refreshSize;
}); });
this->disassembledInstructions.erase(first, end); this->disassembledInstructions.erase(first, end);
auto next = std::find_if(this->disassembledInstructions.begin(), this->disassembledInstructions.end(), [this](DisassembledInstruction &i) { auto next = std::find_if(this->disassembledInstructions.begin(), this->disassembledInstructions.end(), [start](DisassembledInstruction &i) {
return i.address >= this->_registers.pac; return i.address >= start;
}); });
int row = next - this->disassembledInstructions.begin();
DisassemblyContext ctx = this->_getDisassemblyContext(); DisassemblyContext ctx = this->_getDisassemblyContext();
std::vector<DisassembledInstruction> nextInstructions = this->_disassemble(this->_registers.pac, refreshSize, ctx); std::vector<DisassembledInstruction> nextInstructions = this->_disassemble(start, refreshSize, ctx);
this->disassembledInstructions.insert(next, nextInstructions.begin(), nextInstructions.end()); 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(); this->_ui.disassembly->viewport()->repaint();
} }
@@ -347,6 +351,8 @@ namespace ComSquare::Debugger
int CPUDebug::RESB() int CPUDebug::RESB()
{ {
CPU::RESB(); CPU::RESB();
this->disassembledInstructions.clear();
this->_updateDisassembly(0xFFFF - this->_cartridgeHeader.emulationInterrupts.reset);
this->_updateRegistersPanel(); this->_updateRegistersPanel();
return (0); return (0);
} }
@@ -362,7 +368,7 @@ namespace ComSquare::Debugger
} }
DisassembledInstruction::DisassembledInstruction(const CPU::Instruction &instruction, uint24_t addr, std::string arg, uint8_t op) 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() 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()); 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) { } RowPainter::RowPainter(ComSquare::Debugger::CPUDebug &cpu, QObject *parent) : QStyledItemDelegate(parent), _cpu(cpu) { }
void RowPainter::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const void RowPainter::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
+4 -1
View File
@@ -37,6 +37,9 @@ public:
QVariant data(const QModelIndex &index, int role) const override; QVariant data(const QModelIndex &index, int role) const override;
//! @brief Override the headers to use hex values. //! @brief Override the headers to use hex values.
QVariant headerData(int section, Qt::Orientation orientation, int role) const override; 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 //! @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. //! @param ctx The initial context of the processor before the disassembly begin.
std::vector<DisassembledInstruction> _disassemble(uint24_t startAddr, uint24_t size, DisassemblyContext &ctx); std::vector<DisassembledInstruction> _disassemble(uint24_t startAddr, uint24_t size, DisassemblyContext &ctx);
//! @brief Update disassembly with the new state of the processor. //! @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. //! @brief Parse the instruction at the program counter given to have human readable information.
DisassembledInstruction _parseInstruction(uint24_t pc, DisassemblyContext &ctx); DisassembledInstruction _parseInstruction(uint24_t pc, DisassemblyContext &ctx);
//! @brief Get the parameter of the instruction as an hexadecimal string. //! @brief Get the parameter of the instruction as an hexadecimal string.