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 "absl/strings/str_format.h"
10#include "app/emu/cpu/cpu.h"
11#include "app/gfx/core/bitmap.h"
12#include "app/gui/core/icons.h"
13#include "rom/rom.h"
14#include "imgui/imgui.h"
15
16namespace yaze {
17namespace emu {
18namespace debug {
19
24 uint32_t address; // Full 24-bit address (bank:offset)
25 uint8_t opcode; // The opcode byte
26 std::vector<uint8_t> operands; // Operand bytes (0-2 bytes)
27 std::string mnemonic; // Instruction mnemonic (e.g., "LDA", "STA")
28 std::string
29 operand_str; // Formatted operand string (e.g., "#$00", "($10),Y")
30 uint8_t size; // Total instruction size in bytes
31 uint64_t execution_count; // How many times this instruction was executed
32 bool is_breakpoint; // Whether a breakpoint is set at this address
33 bool is_current_pc; // Whether this is the current PC location
34
36 : address(0),
37 opcode(0),
38 size(1),
40 is_breakpoint(false),
41 is_current_pc(false) {}
42};
43
59 public:
60 DisassemblyViewer() = default;
61 ~DisassemblyViewer() = default;
62
71 void RecordInstruction(uint32_t address, uint8_t opcode,
72 const std::vector<uint8_t>& operands,
73 const std::string& mnemonic,
74 const std::string& operand_str);
75
81 void Render(uint32_t current_pc, const std::vector<uint32_t>& breakpoints);
82
86 void Clear();
87
91 size_t GetInstructionCount() const { return instructions_.size(); }
92
98 bool ExportToFile(const std::string& filepath) const;
99
104 void JumpToAddress(uint32_t address);
105
109 void SetAutoScroll(bool enabled) { auto_scroll_ = enabled; }
110
114 std::vector<uint32_t> GetSortedAddresses() const;
115
119 bool IsAvailable() const { return !instructions_.empty(); }
120
124 void SetRecording(bool enabled) { recording_enabled_ = enabled; }
125 bool IsRecording() const { return recording_enabled_; }
126
130 void SetMaxInstructions(size_t max) { max_instructions_ = max; }
131
135 void TrimToSize(size_t target_size);
136
137 private:
138 // Sparse storage: only store executed instructions
139 std::map<uint32_t, DisassemblyEntry> instructions_;
140
141 // Performance limits
143 size_t max_instructions_ = 10000; // Limit to prevent memory bloat
144
145 // UI state
146 char search_filter_[256] = "";
147 uint32_t selected_address_ = 0;
148 uint32_t scroll_to_address_ = 0;
149 bool auto_scroll_ = true;
151 bool show_hex_dump_ = true;
152
153 // Rendering helpers
154 void RenderToolbar();
155 void RenderDisassemblyTable(uint32_t current_pc,
156 const std::vector<uint32_t>& breakpoints);
157 void RenderContextMenu(uint32_t address);
158 void RenderSearchBar();
159
160 // Formatting helpers
161 ImVec4 GetAddressColor(const DisassemblyEntry& entry,
162 uint32_t current_pc) const;
163 ImVec4 GetMnemonicColor(const DisassemblyEntry& entry) const;
164 std::string FormatHexDump(const DisassemblyEntry& entry) const;
165
166 // Filter helper
167 bool PassesFilter(const DisassemblyEntry& entry) const;
168};
169
170} // namespace debug
171} // namespace emu
172} // namespace yaze
173
174#endif // YAZE_APP_EMU_DEBUG_DISASSEMBLY_VIEWER_H_
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.
Represents a single disassembled instruction with metadata.