From 15fde029a79fb39e991f880fc8a560c6e692747e Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 4 Jul 2021 22:57:58 +0200 Subject: [PATCH] Starting to reenable debuggers --- .clang-format | 66 --- CMakeLists.txt | 55 +- sources/CPU/CPU.cpp | 2 +- sources/CPU/CPU.hpp | 9 +- sources/Debugger/CPU/CPUDebug.cpp | 546 +++++++++---------- sources/Debugger/CPU/CPUDebug.hpp | 228 ++++---- sources/Debugger/CPU/Disassembly.cpp | 90 +-- sources/Debugger/ClosableWindow.hpp | 27 +- sources/Debugger/HeaderViewer.cpp | 21 +- sources/Debugger/HeaderViewer.hpp | 19 +- sources/Debugger/MemoryViewer.cpp | 140 +++-- sources/Debugger/MemoryViewer.hpp | 85 ++- sources/Debugger/RegisterViewer.cpp | 322 ++++++----- sources/Debugger/RegisterViewer.hpp | 109 ++-- sources/PPU/Background.cpp | 49 +- sources/PPU/Background.hpp | 22 +- sources/PPU/PPU.cpp | 30 +- sources/PPU/PPU.hpp | 8 +- sources/PPU/PpuDebug.cpp | 61 ++- sources/PPU/PpuDebug.hpp | 2 + sources/PPU/TileRenderer.cpp | 26 +- sources/PPU/TileRenderer.hpp | 16 +- sources/Renderer/QtRenderer/QtSFML.cpp | 10 +- sources/Renderer/QtRenderer/QtWidgetSFML.hpp | 2 +- sources/SNES.cpp | 148 +++-- sources/SNES.hpp | 48 +- sources/main.cpp | 29 +- tests/CPU/testInternal.cpp | 12 +- tests/my_cartridge | 0 29 files changed, 1014 insertions(+), 1168 deletions(-) delete mode 100644 .clang-format delete mode 100644 tests/my_cartridge diff --git a/.clang-format b/.clang-format deleted file mode 100644 index ac5eb82..0000000 --- a/.clang-format +++ /dev/null @@ -1,66 +0,0 @@ -BasedOnStyle: LLVM -AccessModifierOffset: -4 -AlignAfterOpenBracket: Align -AlignConsecutiveAssignments: None -AlignOperands: DontAlign -AllowAllArgumentsOnNextLine: false -AllowAllConstructorInitializersOnNextLine: false -AllowAllParametersOfDeclarationOnNextLine: false -AllowShortBlocksOnASingleLine: Always -AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: Always -AllowShortLambdasOnASingleLine: All -AllowShortLoopsOnASingleLine: true -AlwaysBreakAfterReturnType: None -AlwaysBreakTemplateDeclarations: Yes -BreakBeforeBraces: Custom -BraceWrapping: - AfterCaseLabel: false - AfterClass: true - AfterStruct: true - AfterControlStatement: Never - AfterEnum: true - AfterFunction: true - AfterNamespace: true - AfterUnion: true - BeforeCatch: false - BeforeElse: false - IndentBraces: false - SplitEmptyFunction: false - SplitEmptyRecord: true -BreakBeforeBinaryOperators: None -BreakBeforeTernaryOperators: true -BreakConstructorInitializers: BeforeColon -BreakInheritanceList: BeforeColon -ColumnLimit: 0 -CompactNamespaces: false -ContinuationIndentWidth: 4 -IndentCaseLabels: false -IndentPPDirectives: None -IndentWidth: 4 -KeepEmptyLinesAtTheStartOfBlocks: true -MaxEmptyLinesToKeep: 2 -NamespaceIndentation: All -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: true -PointerAlignment: Right -ReflowComments: false -SpaceAfterCStyleCast: false -SpaceAfterLogicalNot: false -SpaceAfterTemplateKeyword: false -SpaceBeforeAssignmentOperators: true -SpaceBeforeCpp11BracedList: true -SpaceBeforeCtorInitializerColon: true -SpaceBeforeInheritanceColon: true -SpaceBeforeParens: ControlStatements -SpaceBeforeRangeBasedForLoopColon: true -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 0 -SpacesInAngles: false -SpacesInCStyleCastParentheses: false -SpacesInContainerLiterals: false -SpacesInParentheses: false -SpacesInSquareBrackets: false -TabWidth: 4 -UseTab: ForIndentation diff --git a/CMakeLists.txt b/CMakeLists.txt index d29a4c4..331197d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,7 +96,8 @@ set(SOURCES sources/PPU/TileRenderer.cpp sources/PPU/TileRenderer.hpp sources/PPU/Tile.hpp - sources/CPU/Registers.hpp) + sources/CPU/Registers.hpp + ) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) @@ -116,32 +117,30 @@ add_executable(comsquare sources/Renderer/QtRenderer/QtSfmlTileRenderer.hpp sources/Renderer/QtRenderer/QtSfmlTileRenderer.cpp sources/Renderer/QtRenderer/QtSfmlTileRenderer.hpp - # sources/PPU/PpuDebug.cpp - # sources/PPU/PpuDebug.hpp - # sources/Debugger/CPU/CPUDebug.cpp - # sources/Debugger/CPU/CPUDebug.hpp - # sources/Debugger/MemoryViewer.cpp - # sources/Debugger/MemoryViewer.hpp - # sources/Debugger/HeaderViewer.cpp - # sources/Debugger/HeaderViewer.hpp - # sources/Debugger/HeaderViewer.cpp - # sources/Debugger/HeaderViewer.hpp - # sources/Debugger/APUDebug.hpp - # sources/Debugger/APUDebug.cpp - # sources/Debugger/MemoryBusDebug.cpp - # sources/Debugger/MemoryBusDebug.hpp - # sources/Debugger/ClosableWindow.hpp - # sources/Debugger/CPU/Disassembly.cpp - # sources/Debugger/CGramDebug.cpp - # sources/Debugger/CGramDebug.hpp - # sources/Debugger/RegisterViewer.cpp - # sources/Debugger/RegisterViewer.hpp - # sources/Debugger/CPU/SymbolLoaders/WlaDx.cpp - # sources/Debugger/CPU/SymbolLoaders/WlaDx.hpp - # sources/Debugger/TileViewer/TileViewer.cpp - # sources/Debugger/TileViewer/TileViewer.hpp - # sources/Debugger/TileViewer/RAMTileRenderer.cpp - # sources/Debugger/TileViewer/RAMTileRenderer.hpp + sources/PPU/PpuDebug.cpp + sources/PPU/PpuDebug.hpp + sources/Debugger/ClosableWindow.hpp +# sources/Debugger/CPU/CPUDebug.cpp +# sources/Debugger/CPU/CPUDebug.hpp +# sources/Debugger/CPU/Disassembly.cpp +# sources/Debugger/CPU/SymbolLoaders/WlaDx.cpp +# sources/Debugger/CPU/SymbolLoaders/WlaDx.hpp + sources/Debugger/MemoryViewer.cpp + sources/Debugger/MemoryViewer.hpp + sources/Debugger/HeaderViewer.cpp + sources/Debugger/HeaderViewer.hpp +# sources/Debugger/APUDebug.hpp +# sources/Debugger/APUDebug.cpp +# sources/Debugger/MemoryBusDebug.cpp +# sources/Debugger/MemoryBusDebug.hpp +# sources/Debugger/CGramDebug.cpp +# sources/Debugger/CGramDebug.hpp + sources/Debugger/RegisterViewer.cpp + sources/Debugger/RegisterViewer.hpp +# sources/Debugger/TileViewer/TileViewer.cpp +# sources/Debugger/TileViewer/TileViewer.hpp +# sources/Debugger/TileViewer/RAMTileRenderer.cpp +# sources/Debugger/TileViewer/RAMTileRenderer.hpp ui/tileView.ui ui/registersView.ui ui/cpuView.ui @@ -152,7 +151,7 @@ add_executable(comsquare resources/appResources.qrc ) target_include_directories(comsquare PRIVATE ./) -#target_compile_definitions(comsquare PUBLIC DEBUGGER_ENABLED) +target_compile_definitions(comsquare PUBLIC DEBUGGER_ENABLED) find_package(Qt5 COMPONENTS Widgets REQUIRED) target_link_libraries(comsquare diff --git a/sources/CPU/CPU.cpp b/sources/CPU/CPU.cpp index 71c7967..9fceaa3 100644 --- a/sources/CPU/CPU.cpp +++ b/sources/CPU/CPU.cpp @@ -313,7 +313,7 @@ namespace ComSquare::CPU unsigned CPU::_executeInstruction(uint8_t opcode) { - Instruction instruction = this->_instructions[opcode]; + Instruction instruction = this->instructions[opcode]; this->_hasIndexCrossedPageBoundary = false; uint24_t valueAddr = this->_getValueAddr(instruction); diff --git a/sources/CPU/CPU.hpp b/sources/CPU/CPU.hpp index 9ff9827..9cf2cdb 100644 --- a/sources/CPU/CPU.hpp +++ b/sources/CPU/CPU.hpp @@ -13,6 +13,7 @@ #include "DMA/DMA.hpp" #include "CPU/Registers.hpp" #ifdef DEBUGGER_ENABLED +//#include "Debugger/CPU/CPUDebug.hpp" #include "Debugger/RegisterViewer.hpp" #endif @@ -21,7 +22,7 @@ namespace ComSquare::CPU //! @brief The main CPU class CPU : public Memory::AMemory { - protected: + private: //! @brief All the registers of the CPU Registers _registers {}; //! @brief Internal registers of the CPU (accessible from the bus via addr $4200 to $421F). @@ -116,6 +117,7 @@ namespace ComSquare::CPU //! @return The address of the data to read on the instruction. uint24_t _getValueAddr(Instruction &instruction); + public: //! @brief Break instruction - Causes a software break. The PC is loaded from a vector table. int BRK(uint24_t, AddressingMode); //! @brief Co-Processor Enable instruction - Causes a software break. The PC is loaded from a vector table. @@ -309,7 +311,7 @@ namespace ComSquare::CPU //! @brief All the instructions of the CPU. //! @info Instructions are indexed by their opcode - const Instruction _instructions[0x100] = { + const Instruction instructions[0x100] = { {&CPU::BRK, 7, "brk", AddressingMode::Immediate8bits, 2}, // 00 {&CPU::ORA, 6, "ora", AddressingMode::DirectPageIndirectIndexedByX, 2}, // 01 {&CPU::COP, 7, "cop", AddressingMode::Immediate8bits, 2}, // 02 @@ -567,7 +569,7 @@ namespace ComSquare::CPU {&CPU::INC, 7, "inc", AddressingMode::AbsoluteIndexedByX, 3}, // FE {&CPU::SBC, 5, "sbc", AddressingMode::AbsoluteIndexedByXLong, 4}, // FF }; - public: + //! @brief Construct a new generic CPU. //! @param bus The memory bus to use to transfer data. //! @param cartridgeHeader The header used to know interrupts, main entry point etc... @@ -618,6 +620,7 @@ namespace ComSquare::CPU bool IsAbortRequested = false; #ifdef DEBUGGER_ENABLED +// friend Debugger::CPUDebug; friend Debugger::RegisterViewer; #endif }; diff --git a/sources/Debugger/CPU/CPUDebug.cpp b/sources/Debugger/CPU/CPUDebug.cpp index 99fc106..4e2dcfa 100644 --- a/sources/Debugger/CPU/CPUDebug.cpp +++ b/sources/Debugger/CPU/CPUDebug.cpp @@ -3,37 +3,36 @@ // #include "CPUDebug.hpp" -#include "Utility/Utility.hpp" #include "Exceptions/InvalidOpcode.hpp" #include "SymbolLoaders/WlaDx.hpp" -#include +#include "Utility/Utility.hpp" +#include #include +#include +#include #include #include -#include -#include using namespace ComSquare::CPU; namespace ComSquare::Debugger { - CPUDebug::CPUDebug(const CPU &basicCPU, SNES &snes) - : CPU(basicCPU), - _window(new ClosableWindow(*this, &CPUDebug::disableDebugger)), - _ui(), - _model(*this), - _painter(*this), - _stackModel(this->_bus, *this), - _snes(snes), - _labels(this->_loadLabels(snes.cartridge.getRomPath())) + CPUDebug::CPUDebug(CPU::CPU &basicCPU, SNES &snes) + : _cpu(basicCPU), + _window(new ClosableWindow([&snes] { snes.disableCPUDebugging(); })), + _ui(), + _model(*this), + _painter(*this), + _stackModel(snes.bus, *this), + _snes(snes), + _labels(this->_loadLabels(snes.cartridge.getRomPath())) { - this->_window->setContextMenuPolicy(Qt::NoContextMenu); - this->_window->setAttribute(Qt::WA_QuitOnClose, false); - this->_window->setAttribute(Qt::WA_DeleteOnClose); - this->_ui.setupUi(this->_window); - 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). + //Parse the first page of the ROM (the code can't reach the second page without a jump). + uint16_t reset = snes.cartridge.header.emulationInterrupts.reset; + this->_updateDisassembly(reset, 0xFFFF - reset); + this->_ui.disassembly->setModel(&this->_model); this->_ui.disassembly->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); this->_ui.disassembly->horizontalHeader()->setStretchLastSection(true); @@ -43,7 +42,7 @@ namespace ComSquare::Debugger this->_ui.stackView->setModel(&this->_stackModel); this->_ui.stackView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); - this->_ui.stackView->verticalHeader()->setSectionResizeMode (QHeaderView::Fixed); + this->_ui.stackView->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed); this->_ui.stackView->verticalHeader()->setHighlightSections(false); @@ -60,23 +59,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() const - { - return true; - } - - void CPUDebug::disableDebugger() - { - this->_snes.disableCPUDebugging(); - } - - void CPUDebug::setMemoryBus(std::shared_ptr bus) - { - this->_stackModel.setMemoryBus(bus); - CPU::setMemoryBus(bus); + this->_updateDisassembly(this->_cpu._registers.pac, 0); } unsigned CPUDebug::update() @@ -93,13 +76,13 @@ namespace ComSquare::Debugger return 0xFF; if (this->_isStepping) { cycles = this->_executeInstruction(this->readPC()); - this->_updateDisassembly(this->_registers.pac); + this->_updateDisassembly(this->_cpu._registers.pac); return cycles; } for (int i = 0; i < 0xFF; i++) { auto breakpoint = std::find_if(this->breakpoints.begin(), this->breakpoints.end(), [this](Breakpoint &brk) { - return brk.address == this->_registers.pac; + return brk.address == this->_cpu._registers.pac; }); if (i != 0 && breakpoint != this->breakpoints.end()) { if (breakpoint->oneTime) @@ -127,13 +110,13 @@ namespace ComSquare::Debugger this->_isStepping = false; this->_isPaused = true; } - uint24_t pc = (this->_registers.pbr << 16u) | (this->_registers.pc - 1u); + uint24_t pc = (this->_cpu._registers.pbr << 16u) | (this->_cpu._registers.pc - 1u); DisassemblyContext ctx = this->_getDisassemblyContext(); DisassembledInstruction instruction = this->_parseInstruction(pc, ctx); - this->_registers.pc--; + this->_cpu._registers.pc--; this->_historyModel.log({opcode, instruction.name, instruction.argument, this->getProceededParameters()}); this->_ui.history->scrollToBottom(); - this->_registers.pc++; + this->_cpu._registers.pc++; unsigned ret = CPU::_executeInstruction(opcode); this->_updateRegistersPanel(); return ret; @@ -157,7 +140,7 @@ namespace ComSquare::Debugger this->_ui.actionPause->setText("Continue"); else this->_ui.actionPause->setText("Pause"); - this->_updateDisassembly(this->_registers.pac); + this->_updateDisassembly(this->_cpu._registers.pac); } void CPUDebug::step() @@ -168,8 +151,8 @@ namespace ComSquare::Debugger void CPUDebug::next() { - 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->disassembled.begin(), this->disassembled.end(), [this](auto &i) { + return i.address > this->_cpu._cpu._registers.pac; }); this->breakpoints.push_back({next->address, true}); this->_isPaused = false; @@ -177,8 +160,8 @@ namespace ComSquare::Debugger void CPUDebug::toggleBreakpoint(int logicalIndex) { - DisassembledInstruction instruction = this->disassembledInstructions[logicalIndex]; - auto existing = std::find_if(this->breakpoints.begin(), this->breakpoints.end(), [instruction](Breakpoint &i) { + DisassembledInstruction instruction = this->disassembled[logicalIndex]; + auto existing = std::find_if(this->breakpoints.begin(), this->breakpoints.end(), [instruction](auto &i) { return i.address == instruction.address; }); if (existing == this->breakpoints.end()) @@ -190,55 +173,38 @@ namespace ComSquare::Debugger void CPUDebug::_updateRegistersPanel() { - if (!this->_registers.p.m) - this->_ui.accumulatorLineEdit->setText(Utility::to_hex(this->_registers.a).c_str()); + if (!this->_cpu._registers.p.m) + this->_ui.accumulatorLineEdit->setText(Utility::to_hex(this->_cpu._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()); + this->_ui.accumulatorLineEdit->setText(Utility::to_hex(this->_cpu._registers.al).c_str()); + this->_ui.programBankRegisterLineEdit->setText(Utility::to_hex(this->_cpu._registers.pbr).c_str()); + this->_ui.programCounterLineEdit->setText(Utility::to_hex(this->_cpu._registers.pc).c_str()); + this->_ui.directBankLineEdit->setText(Utility::to_hex(this->_cpu._registers.dbr).c_str()); + this->_ui.directPageLineEdit->setText(Utility::to_hex(this->_cpu._registers.d).c_str()); + this->_ui.stackPointerLineEdit->setText(Utility::to_hex(this->_cpu._registers.s).c_str()); + if (!this->_cpu._registers.p.x_b) { + this->_ui.xIndexLineEdit->setText(Utility::to_hex(this->_cpu._registers.x).c_str()); + this->_ui.yIndexLineEdit->setText(Utility::to_hex(this->_cpu._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.xIndexLineEdit->setText(Utility::to_hex(this->_cpu._registers.xl).c_str()); + this->_ui.yIndexLineEdit->setText(Utility::to_hex(this->_cpu._registers.yl).c_str()); } this->_ui.emulationModeCheckBox->setCheckState(this->_isEmulationMode ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); - this->_ui.mCheckbox->setCheckState(this->_registers.p.m ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); - this->_ui.xCheckbox->setCheckState(this->_registers.p.x_b ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); - this->_ui.bCheckbox->setCheckState(this->_registers.p.x_b ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); - this->_ui.iCheckbox->setCheckState(this->_registers.p.i ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); - this->_ui.vCheckbox->setCheckState(this->_registers.p.v ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); - this->_ui.dCheckbox->setCheckState(this->_registers.p.d ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); - this->_ui.cCheckbox->setCheckState(this->_registers.p.c ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); - this->_ui.zCheckbox->setCheckState(this->_registers.p.z ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); - this->_ui.nCheckbox->setCheckState(this->_registers.p.n ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); + this->_ui.mCheckbox->setCheckState(this->_cpu._registers.p.m ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); + this->_ui.xCheckbox->setCheckState(this->_cpu._registers.p.x_b ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); + this->_ui.bCheckbox->setCheckState(this->_cpu._registers.p.x_b ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); + this->_ui.iCheckbox->setCheckState(this->_cpu._registers.p.i ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); + this->_ui.vCheckbox->setCheckState(this->_cpu._registers.p.v ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); + this->_ui.dCheckbox->setCheckState(this->_cpu._registers.p.d ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); + this->_ui.cCheckbox->setCheckState(this->_cpu._registers.p.c ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); + this->_ui.zCheckbox->setCheckState(this->_cpu._registers.p.z ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); + this->_ui.nCheckbox->setCheckState(this->_cpu._registers.p.n ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); - auto index = this->_stackModel.index(this->_registers.s / 2, 0); + auto index = this->_stackModel.index(this->_cpu._registers.s / 2, 0); this->_ui.stackView->scrollTo(index, QAbstractItemView::PositionAtCenter); } - 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; - } - void CPUDebug::clearHistory() { this->_historyModel.clear(); @@ -246,22 +212,22 @@ namespace ComSquare::Debugger void CPUDebug::_updateDisassembly(uint24_t start, uint24_t refreshSize) { - auto first = std::find_if(this->disassembledInstructions.begin(), this->disassembledInstructions.end(), [start](DisassembledInstruction &i) { + auto first = std::find_if(this->disassembled.begin(), this->disassembled.end(), [start](DisassembledInstruction &i) { return i.address >= start; }); - 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 end = std::find_if(this->disassembled.begin(), this->disassembled.end(), [start, refreshSize](DisassembledInstruction &i) { + return i.address >= start + refreshSize; + }); + this->disassembled.erase(first, end); - auto next = std::find_if(this->disassembledInstructions.begin(), this->disassembledInstructions.end(), [start](DisassembledInstruction &i) { + auto next = std::find_if(this->disassembled.begin(), this->disassembled.end(), [start](DisassembledInstruction &i) { return i.address >= start; }); DisassemblyContext ctx = this->_getDisassemblyContext(); std::vector nextInstructions = this->_disassemble(start, refreshSize, ctx); - this->disassembledInstructions.insert(next, nextInstructions.begin(), nextInstructions.end()); + this->disassembled.insert(next, nextInstructions.begin(), nextInstructions.end()); - int row = next - this->disassembledInstructions.begin(); + int row = static_cast(next - this->disassembled.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); @@ -271,13 +237,13 @@ namespace ComSquare::Debugger DisassemblyContext CPUDebug::_getDisassemblyContext() { - return {this->_registers.p.m, this->_registers.p.x_b, this->_isEmulationMode}; + return {this->_cpu._registers.p.m, this->_cpu._registers.p.x_b, this->_isEmulationMode}; } int CPUDebug::RESB() { CPU::RESB(); - this->disassembledInstructions.clear(); + this->disassembled.clear(); this->_updateDisassembly(0xFFFF - this->_cartridgeHeader.emulationInterrupts.reset); this->_updateRegistersPanel(); return (0); @@ -290,21 +256,21 @@ namespace ComSquare::Debugger uint24_t CPUDebug::getPC() { - return this->_registers.pac; + return this->_cpu._registers.pac; } uint16_t CPUDebug::getStackPointer() { - return this->_registers.s; + return this->_cpu._registers.s; } std::string CPUDebug::getProceededParameters() { - uint24_t pac = this->_registers.pac; + uint24_t pac = this->_cpu._registers.pac; this->_bus.forceSilence = true; Instruction instruction = this->_instructions[this->readPC()]; uint24_t valueAddr = this->_getValueAddr(instruction); - this->_registers.pac = pac; + this->_cpu._registers.pac = pac; this->_bus.forceSilence = false; if (instruction.size == 1) return ""; @@ -317,222 +283,222 @@ namespace ComSquare::Debugger std::string symbolPath = romPath.replace_extension(".sym"); std::ifstream sym(symbolPath); -// if (sym) { -// std::vector