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 "app/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 operand_str; // Formatted operand string (e.g., "#$00", "($10),Y")
29 uint8_t size; // Total instruction size in bytes
30 uint64_t execution_count; // How many times this instruction was executed
31 bool is_breakpoint; // Whether a breakpoint is set at this address
32 bool is_current_pc; // Whether this is the current PC location
33
35 : address(0), opcode(0), size(1), execution_count(0),
36 is_breakpoint(false), is_current_pc(false) {}
37};
38
53 public:
54 DisassemblyViewer() = default;
55 ~DisassemblyViewer() = default;
56
65 void RecordInstruction(uint32_t address, uint8_t opcode,
66 const std::vector<uint8_t>& operands,
67 const std::string& mnemonic,
68 const std::string& operand_str);
69
75 void Render(uint32_t current_pc, const std::vector<uint32_t>& breakpoints);
76
80 void Clear();
81
85 size_t GetInstructionCount() const { return instructions_.size(); }
86
92 bool ExportToFile(const std::string& filepath) const;
93
98 void JumpToAddress(uint32_t address);
99
103 void SetAutoScroll(bool enabled) { auto_scroll_ = enabled; }
104
108 std::vector<uint32_t> GetSortedAddresses() const;
109
113 bool IsAvailable() const { return !instructions_.empty(); }
114
118 void SetRecording(bool enabled) { recording_enabled_ = enabled; }
119 bool IsRecording() const { return recording_enabled_; }
120
124 void SetMaxInstructions(size_t max) { max_instructions_ = max; }
125
129 void TrimToSize(size_t target_size);
130
131 private:
132 // Sparse storage: only store executed instructions
133 std::map<uint32_t, DisassemblyEntry> instructions_;
134
135 // Performance limits
137 size_t max_instructions_ = 10000; // Limit to prevent memory bloat
138
139 // UI state
140 char search_filter_[256] = "";
141 uint32_t selected_address_ = 0;
142 uint32_t scroll_to_address_ = 0;
143 bool auto_scroll_ = true;
145 bool show_hex_dump_ = true;
146
147 // Rendering helpers
148 void RenderToolbar();
149 void RenderDisassemblyTable(uint32_t current_pc,
150 const std::vector<uint32_t>& breakpoints);
151 void RenderContextMenu(uint32_t address);
152 void RenderSearchBar();
153
154 // Formatting helpers
155 ImVec4 GetAddressColor(const DisassemblyEntry& entry, uint32_t current_pc) const;
156 ImVec4 GetMnemonicColor(const DisassemblyEntry& entry) const;
157 std::string FormatHexDump(const DisassemblyEntry& entry) const;
158
159 // Filter helper
160 bool PassesFilter(const DisassemblyEntry& entry) const;
161};
162
163} // namespace debug
164} // namespace emu
165} // namespace yaze
166
167#endif // YAZE_APP_EMU_DEBUG_DISASSEMBLY_VIEWER_H_
168
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.
Definition controller.cc:20
Represents a single disassembled instruction with metadata.