yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
disassembly_viewer.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EMU_DEBUG_DISASSEMBLY_VIEWER_H_
2#define YAZE_APP_EMU_DEBUG_DISASSEMBLY_VIEWER_H_
3
4#include <cstdint>
5#include <map>
6#include <string>
7#include <vector>
8
9#include "app/emu/cpu/cpu.h"
10#include "app/gfx/bitmap.h"
11#include "app/gui/icons.h"
12#include "imgui/imgui.h"
13
14namespace yaze {
15namespace emu {
16namespace debug {
17
22 uint32_t address; // Full 24-bit address (bank:offset)
23 uint8_t opcode; // The opcode byte
24 std::vector<uint8_t> operands; // Operand bytes (0-2 bytes)
25 std::string mnemonic; // Instruction mnemonic (e.g., "LDA", "STA")
26 std::string operand_str; // Formatted operand string (e.g., "#$00", "($10),Y")
27 uint8_t size; // Total instruction size in bytes
28 uint64_t execution_count; // How many times this instruction was executed
29 bool is_breakpoint; // Whether a breakpoint is set at this address
30 bool is_current_pc; // Whether this is the current PC location
31
33 : address(0), opcode(0), size(1), execution_count(0),
34 is_breakpoint(false), is_current_pc(false) {}
35};
36
51 public:
52 DisassemblyViewer() = default;
53 ~DisassemblyViewer() = default;
54
63 void RecordInstruction(uint32_t address, uint8_t opcode,
64 const std::vector<uint8_t>& operands,
65 const std::string& mnemonic,
66 const std::string& operand_str);
67
73 void Render(uint32_t current_pc, const std::vector<uint32_t>& breakpoints);
74
78 void Clear();
79
83 size_t GetInstructionCount() const { return instructions_.size(); }
84
90 bool ExportToFile(const std::string& filepath) const;
91
96 void JumpToAddress(uint32_t address);
97
101 void SetAutoScroll(bool enabled) { auto_scroll_ = enabled; }
102
106 std::vector<uint32_t> GetSortedAddresses() const;
107
111 bool IsAvailable() const { return !instructions_.empty(); }
112
116 void SetRecording(bool enabled) { recording_enabled_ = enabled; }
117 bool IsRecording() const { return recording_enabled_; }
118
122 void SetMaxInstructions(size_t max) { max_instructions_ = max; }
123
127 void TrimToSize(size_t target_size);
128
129 private:
130 // Sparse storage: only store executed instructions
131 std::map<uint32_t, DisassemblyEntry> instructions_;
132
133 // Performance limits
135 size_t max_instructions_ = 10000; // Limit to prevent memory bloat
136
137 // UI state
138 char search_filter_[256] = "";
139 uint32_t selected_address_ = 0;
140 uint32_t scroll_to_address_ = 0;
141 bool auto_scroll_ = true;
143 bool show_hex_dump_ = true;
144
145 // Rendering helpers
146 void RenderToolbar();
147 void RenderDisassemblyTable(uint32_t current_pc,
148 const std::vector<uint32_t>& breakpoints);
149 void RenderContextMenu(uint32_t address);
150 void RenderSearchBar();
151
152 // Formatting helpers
153 ImVec4 GetAddressColor(const DisassemblyEntry& entry, uint32_t current_pc) const;
154 ImVec4 GetMnemonicColor(const DisassemblyEntry& entry) const;
155 std::string FormatHexDump(const DisassemblyEntry& entry) const;
156
157 // Filter helper
158 bool PassesFilter(const DisassemblyEntry& entry) const;
159};
160
161} // namespace debug
162} // namespace emu
163} // namespace yaze
164
165#endif // YAZE_APP_EMU_DEBUG_DISASSEMBLY_VIEWER_H_
166
Advanced disassembly viewer with sparse storage and interactive features.
void Clear()
Clear all recorded instructions.
bool IsAvailable() const
Check if the disassembly viewer is available.
std::vector< uint32_t > GetSortedAddresses() const
Get sorted list of addresses for rendering.
void JumpToAddress(uint32_t address)
Jump to a specific address in the viewer.
void SetRecording(bool enabled)
Enable/disable recording (for performance)
std::string FormatHexDump(const DisassemblyEntry &entry) const
std::map< uint32_t, DisassemblyEntry > instructions_
ImVec4 GetMnemonicColor(const DisassemblyEntry &entry) const
void TrimToSize(size_t target_size)
Clear old instructions to save memory.
void RecordInstruction(uint32_t address, uint8_t opcode, const std::vector< uint8_t > &operands, const std::string &mnemonic, const std::string &operand_str)
Record an instruction execution.
size_t GetInstructionCount() const
Get the number of unique instructions recorded.
bool PassesFilter(const DisassemblyEntry &entry) const
void SetAutoScroll(bool enabled)
Set whether to auto-scroll to current PC.
ImVec4 GetAddressColor(const DisassemblyEntry &entry, uint32_t current_pc) const
void RenderDisassemblyTable(uint32_t current_pc, const std::vector< uint32_t > &breakpoints)
bool ExportToFile(const std::string &filepath) const
Export disassembly to file.
void Render(uint32_t current_pc, const std::vector< uint32_t > &breakpoints)
Render the disassembly viewer UI.
void SetMaxInstructions(size_t max)
Set maximum number of instructions to keep.
Main namespace for the application.
Represents a single disassembled instruction with metadata.