Go to the documentation of this file.
9 #include "ui/ui_cpuView.h"
13 #include <QtWidgets/QStyledItemDelegate>
59 [[nodiscard]]
int rowCount(
const QModelIndex &parent)
const override;
61 [[nodiscard]]
int columnCount(
const QModelIndex &parent)
const override;
63 [[nodiscard]] QVariant
data(
const QModelIndex &index,
int role)
const override;
65 [[nodiscard]] QVariant
headerData(
int section, Qt::Orientation orientation,
int role)
const override;
87 [[nodiscard]]
int rowCount(
const QModelIndex &parent)
const override;
89 [[nodiscard]]
int columnCount(
const QModelIndex &parent)
const override;
91 [[nodiscard]] QVariant
data(
const QModelIndex &index,
int role)
const override;
93 [[nodiscard]] QVariant
headerData(
int section, Qt::Orientation orientation,
int role)
const override;
110 [[nodiscard]]
int rowCount(
const QModelIndex &parent)
const override;
112 [[nodiscard]]
int columnCount(
const QModelIndex &parent)
const override;
114 [[nodiscard]] QVariant
data(
const QModelIndex &index,
int role)
const override;
116 [[nodiscard]] QVariant
headerData(
int section, Qt::Orientation orientation,
int role)
const override;
133 [[nodiscard]] QSize
sizeHint(
const QStyleOptionViewItem &options,
const QModelIndex &index)
const override;
134 void paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index)
const override;
301 void pause(
bool forcePause =
false);
std::string _getDirectIndexedByYValue(uint24_t pc) const
Return a printable string corresponding to the value of a direct index by y addressing mode.
Definition: Disassembly.cpp:181
std::vector< DisassembledInstruction > _disassemble(uint24_t startAddr, uint24_t size, DisassemblyContext &ctx)
Disassemble part of the memory (using the bus) and parse it to a map of address and disassembled inst...
Definition: Disassembly.cpp:25
uint24_t address
The address of the instruction.
Definition: CPUDebug.hpp:163
std::string _getAbsoluteLongValue(uint24_t pc) const
Return a printable string corresponding to the value of an absolute long addressing mode.
Definition: Disassembly.cpp:163
uint24_t getPC() const
Return the current program counter of this CPU.
Definition: CPUDebug.cpp:256
Struct representing a label.
Definition: CPUDebug.hpp:190
int rowCount(const QModelIndex &parent) const override
The number of row the table has.
Definition: CPUDebug.cpp:303
void clearHistory()
Clear the history panel.
Definition: CPUDebug.cpp:216
Ui::CPUView _ui
A widget that contain the whole UI.
Definition: CPUDebug.hpp:212
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Override the headers to use hex values.
Definition: CPUDebug.cpp:426
@ Unsafe
Definition: CPUDebug.hpp:140
void next()
Next - Continue running instructions until the next line is reached.
Definition: CPUDebug.cpp:160
std::string _getAbsoluteValue(uint24_t pc) const
Return a printable string corresponding to the value of an absolute addressing mode.
Definition: Disassembly.cpp:157
std::vector< Breakpoint > breakpoints
The list of breakpoints the user has set.
Definition: CPUDebug.hpp:313
The main CPU.
Definition: CPU.hpp:26
std::string name
The name of the instruction.
Definition: CPUDebug.hpp:37
The qt model that show the stack.
Definition: CPUDebug.hpp:45
@ Safe
Definition: CPUDebug.hpp:139
ClosableWindow * _window
The QT window for this debugger.
Definition: CPUDebug.hpp:208
std::string _getAbsoluteIndirectValue(uint24_t pc) const
Return a printable string corresponding to the value of a absolute indirect addressing mode.
Definition: Disassembly.cpp:258
void _logInstruction()
Add the instruction under the PC to the history log.
Definition: CPUDebug.cpp:125
QVariant data(const QModelIndex &index, int role) const override
Return a data representing the table cell.
Definition: CPUDebug.cpp:308
std::string _getAbsoluteIndirectLongValue(uint24_t pc) const
Return a printable string corresponding to the value of a absolute indirect long addressing mode.
Definition: Disassembly.cpp:264
Struct representing an instruction in an human readable way (created by disassembling the rom).
Definition: CPUDebug.hpp:160
QVariant data(const QModelIndex &index, int role) const override
Return a data representing the table cell.
Definition: CPUDebug.cpp:405
std::string _getImmediateValue(uint24_t pc, bool dual) const
Return a printable string corresponding to the value of a 8 or 16 bits immediate addressing mode.
Definition: Disassembly.cpp:141
TrustLevel
Definition: CPUDebug.hpp:137
void _updateRegistersPanel()
Update the register's panel (accumulator, stack pointer...)
Definition: CPUDebug.cpp:182
bool mFlag
The accumulator and Memory width flag (in native mode only) - 0 = 16 bits mode, 1 = 8 bits mode....
Definition: CPUDebug.hpp:149
void log(const ExecutedInstruction &)
Log a new instruction.
Definition: CPUDebug.cpp:488
bool isEmulationMode
Is the CPU emulating a 6502? If yes, some instructions don't change flags the same way.
Definition: CPUDebug.hpp:154
QVariant data(const QModelIndex &index, int role) const override
Return a data representing the table cell.
Definition: CPUDebug.cpp:448
RowPainter _painter
A custom painter that highlight breakpoints and the PC's position.
Definition: CPUDebug.hpp:216
Definition: ClosableWindow.hpp:12
void focus()
Focus the debugger's window.
Definition: CPUDebug.cpp:251
HistoryModel _historyModel
The history model.
Definition: CPUDebug.hpp:220
std::string _getDirectIndirectLongValue(uint24_t pc) const
Return a printable string corresponding to the value of a direct indirect long addressing mode.
Definition: Disassembly.cpp:195
Memory::IMemoryBus & _bus
Definition: CPUDebug.hpp:49
int rowCount(const QModelIndex &parent) const override
The number of row the table has.
Definition: CPUDebug.cpp:395
const HistoryModel & operator=(const HistoryModel &)=delete
std::vector< ExecutedInstruction > _instructions
Definition: CPUDebug.hpp:73
~DisassemblyModel() override=default
Struct containing basic information about instructions.
Definition: Instruction.hpp:51
void clear()
Remove every instructions of the history.
Definition: CPUDebug.cpp:497
std::vector< Label > _labels
A list of labels and their size.
Definition: CPUDebug.hpp:228
~StackModel() override=default
unsigned uint24_t
Definition: Ints.hpp:10
DisassembledInstruction & operator=(const DisassembledInstruction &)=default
TrustLevel level
Sometimes, the flags can't be tracked correctly after an instruction so the next instructions may not...
Definition: CPUDebug.hpp:156
uint8_t opcode
Opcode of the instruction.
Definition: CPUDebug.hpp:35
std::string _getInstructionParameter(const ComSquare::CPU::Instruction &instruction, uint24_t pc, DisassemblyContext &ctx) const
Get the parameter of the instruction as an hexadecimal string.
Definition: Disassembly.cpp:84
DisassemblyModel(CPUDebug &cpu)
Definition: CPUDebug.cpp:294
The qt model that show the history.
Definition: CPUDebug.hpp:69
uint8_t opcode
The opcode of the instruction.
Definition: CPUDebug.hpp:167
std::string name
The name of this label.
Definition: CPUDebug.hpp:195
StackModel _stackModel
The stack viewer's model.
Definition: CPUDebug.hpp:218
bool oneTime
If this is true, the breakpoint will be deleted on first hit and won't be shown on the disassembly vi...
Definition: CPUDebug.hpp:186
bool xFlag
The indeX register width flag (in native mode only) - 0 = 16 bits mode, 1 = 8 bits mode OR the Break ...
Definition: CPUDebug.hpp:152
DisassembledInstruction _parseInstruction(uint24_t pc, DisassemblyContext &ctx) const
Parse the instruction at the program counter given to have human readable information.
Definition: Disassembly.cpp:76
void pause(bool forcePause=false)
Pause/Resume the CPU.
Definition: CPUDebug.cpp:142
Container of all the components of the SNES.
Definition: SNES.hpp:32
std::vector< DisassembledInstruction > disassembled
The list of disassembled instructions to show on the debugger.
Definition: CPUDebug.hpp:311
std::string _getStackRelativeValue(uint24_t pc) const
Return a printable string corresponding to the value of a stack relative addressing mode.
Definition: Disassembly.cpp:248
std::string params
Readable parameters (disassembly style)
Definition: CPUDebug.hpp:39
@ Compromised
Definition: CPUDebug.hpp:141
CPUDebug & operator=(const CPUDebug &)=delete
QSize sizeHint(const QStyleOptionViewItem &options, const QModelIndex &index) const override
Definition: CPUDebug.cpp:385
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: CPUDebug.cpp:363
std::optional< unsigned > size
The size of the definition related to this label.
Definition: CPUDebug.hpp:197
QTimer _timer
Internal timer used for update intervals.
Definition: CPUDebug.hpp:210
std::string _getAbsoluteIndexByXLongValue(uint24_t pc) const
Return a printable string corresponding to the value of a absolute indexed by x long addressing mode.
Definition: Disassembly.cpp:212
~DisassembledInstruction()=default
The memory bus is the component responsible of mapping addresses to components address and transmitti...
Definition: IMemoryBus.hpp:19
TrustLevel level
Are we sure that this instruction has been correctly disassembled?
Definition: CPUDebug.hpp:169
void _updateDisassembly(uint24_t start, uint24_t refreshSize=0xFF)
Update disassembly with the new state of the processor.
Definition: CPUDebug.cpp:221
CPUDebug & _cpu
Definition: CPUDebug.hpp:50
std::string _getAbsoluteIndexByXValue(uint24_t pc) const
Return a printable string corresponding to the value of a absolute indexed by x addressing mode.
Definition: Disassembly.cpp:200
std::string _getAbsoluteIndexByYValue(uint24_t pc) const
Return a printable string corresponding to the value of a absolute indexed by y addressing mode.
Definition: Disassembly.cpp:206
bool _isStepping
If this is set to true, the CPU will execute one instruction and pause itself.
Definition: CPUDebug.hpp:224
~CPUDebug() override
Definition: CPUDebug.cpp:81
const StackModel & operator=(const StackModel &)=delete
A window that show registers and the disassembly of a CPU.
Definition: CPUDebug.hpp:201
Struct representing a breakpoint set by the user or by the app.
Definition: CPUDebug.hpp:181
~RowPainter() override=default
unsigned update()
Update the current debugger and the underlying CPU.
Definition: CPUDebug.cpp:87
CPUDebug & _cpu
Definition: CPUDebug.hpp:101
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Override the headers to use hex values.
Definition: CPUDebug.cpp:337
std::string getProceededParameters() const
Get a string representing the actual value of the arguments of the next instruction to execute.
Definition: CPUDebug.cpp:266
StackModel(Memory::IMemoryBus &bus, CPUDebug &cpu)
Definition: CPUDebug.cpp:390
std::string _getDirectIndirectIndexedByYValue(uint24_t pc) const
Return a printable string corresponding to the value of a direct indirect index by y addressing mode.
Definition: Disassembly.cpp:230
uint24_t address
The address of the breakpoint.
Definition: CPUDebug.hpp:184
Definition: DebuggableError.hpp:11
uint24_t address
The address of this label.
Definition: CPUDebug.hpp:193
SNES & _snes
A reference to the snes (to disable the debugger).
Definition: CPUDebug.hpp:226
void toggleBreakpoint(int logicalIndex)
Called when the user clicks on a section header. It enable/disable a breakpoint for this address.
Definition: CPUDebug.cpp:169
uint16_t initialStackPointer
The stack pointer before the execution of any instructions.
Definition: CPUDebug.hpp:321
void step()
Step - Execute a single instruction.
Definition: CPUDebug.cpp:154
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Override the headers to use hex values.
Definition: CPUDebug.cpp:470
std::string _getAbsoluteIndirectIndexedByXValue(uint24_t pc) const
Return a printable string corresponding to the value of a absolute indirect indexed by x addressing m...
Definition: Disassembly.cpp:273
ComSquare::CPU::CPU & _cpu
The basic CPU to debug.
Definition: CPUDebug.hpp:206
uint16_t getStackPointer() const
Return the current stack pointer.
Definition: CPUDebug.cpp:261
DisassemblyContext _getDisassemblyContext()
Return a disassembly context representing the current state of the processor.
Definition: CPUDebug.cpp:246
An instruction that has already been executed. Used for the history viewer.
Definition: CPUDebug.hpp:32
int rowCount(const QModelIndex &parent) const override
The number of row the table has.
Definition: CPUDebug.cpp:438
int _callback
The callback ID for the on reset of the CPU.
Definition: CPUDebug.hpp:230
std::string argument
A string representing the argument with the right addressing mode.
Definition: CPUDebug.hpp:165
std::string _getDirectIndexedByXValue(uint24_t pc) const
Return a printable string corresponding to the value of a direct index by x addressing mode.
Definition: Disassembly.cpp:172
void _loadLabels(std::filesystem::path romPath)
Load labels from a symbol file.
Definition: CPUDebug.cpp:280
const DisassemblyModel & operator=(const DisassemblyModel &)=delete
RowPainter(CPUDebug &cpu, QObject *parent=nullptr)
Definition: CPUDebug.cpp:359
std::string _getDirectIndirectValue(uint24_t pc) const
Return a printable string corresponding to the value of a direct indirect addressing mode.
Definition: Disassembly.cpp:190
std::string _getStackRelativeIndirectIndexedByYValue(uint24_t pc) const
Return a printable string corresponding to the value of a stack relative indirect indexed by y addres...
Definition: Disassembly.cpp:253
static void showError(const DebuggableError &error)
Show an error dialog related to an exception.
Definition: CPUDebug.cpp:133
std::string _getDirectValue(uint24_t pc) const
Return a printable string corresponding to the value of a direct addressing mode.
Definition: Disassembly.cpp:152
std::string proceededParams
The address to read from after processing the parameter.
Definition: CPUDebug.hpp:41
std::string _getDirectIndirectIndexedByYLongValue(uint24_t pc) const
Return a printable string corresponding to the value of a direct indirect index by y long addressing ...
Definition: Disassembly.cpp:239
Struct used to emulate the state of the processor during the disassembly since instructions take a di...
Definition: CPUDebug.hpp:145
int columnCount(const QModelIndex &parent) const override
The number of column the table has.
Definition: CPUDebug.cpp:298
~HistoryModel() override=default
RowPainter & operator=(const RowPainter &)=delete
DisassembledInstruction(const ComSquare::CPU::Instruction &instruction, uint24_t address, std::string argument, uint8_t opcode)
Definition: Disassembly.cpp:14
CPUDebug & _cpu
The CPU to get PC and breakpoints from.
Definition: CPUDebug.hpp:125
The qt model that show the disassembly.
Definition: CPUDebug.hpp:97
int columnCount(const QModelIndex &parent) const override
The number of column the table has.
Definition: CPUDebug.cpp:400
bool _isPaused
If this is set to true, the execution of the CPU will be paused.
Definition: CPUDebug.hpp:222
CPUDebug(ComSquare::CPU::CPU &cpu, SNES &snes)
Convert a basic CPU to a debugging CPU.
Definition: CPUDebug.cpp:19
std::string _getDirectIndexedByXIndirectValue(uint24_t pc) const
Return a printable string corresponding to the value of a direct indirect index by x addressing mode.
Definition: Disassembly.cpp:221
int columnCount(const QModelIndex &parent) const override
The number of column the table has.
Definition: CPUDebug.cpp:443
The qt class that highlight breakpoints and the PC's position.
Definition: CPUDebug.hpp:120
DisassemblyModel _model
The disassembly viewer's model.
Definition: CPUDebug.hpp:214