yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
memory_editor.cc
Go to the documentation of this file.
2
3#include "absl/strings/str_format.h"
6#include "imgui/imgui.h"
7
8namespace yaze {
9namespace editor {
10
11void MemoryEditor::Update(bool& show_memory_editor) {
13 ImGui::Separator();
14
15 ImGui::Begin("Hex Editor", &show_memory_editor);
16 if (ImGui::Button("Compare Rom")) {
19 show_compare_rom_ = true;
20 }
21
22 static uint64_t convert_address = 0;
23 gui::InputHex("SNES to PC", (int*)&convert_address, 6, 200.f);
24 SameLine();
25 Text("%x", SnesToPc(convert_address));
26
27 BEGIN_TABLE("Memory Comparison", 2, ImGuiTableFlags_Resizable);
28 SETUP_COLUMN("Source")
29 SETUP_COLUMN("Dest")
30
32 Text("%s", rom()->filename().data());
33 memory_widget_.DrawContents((void*)&(*rom()), rom()->size());
34
38 ImGui::BeginGroup();
39 ImGui::BeginChild("Comparison ROM");
40 Text("%s", comparison_rom_.filename().data());
43 ImGui::EndChild();
44 ImGui::EndGroup();
45 }
46 END_TABLE()
47
48 ImGui::End();
49}
50
52 // Modern compact toolbar with icon-only buttons
53 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(6, 4));
54 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4, 4));
55
56 if (ImGui::Button(ICON_MD_LOCATION_SEARCHING " Jump")) {
57 ImGui::OpenPopup("JumpToAddress");
58 }
59 if (ImGui::IsItemHovered()) {
60 ImGui::SetTooltip("Jump to specific address");
61 }
62
63 ImGui::SameLine();
64 if (ImGui::Button(ICON_MD_SEARCH " Search")) {
65 ImGui::OpenPopup("SearchPattern");
66 }
67 if (ImGui::IsItemHovered()) {
68 ImGui::SetTooltip("Search for hex pattern");
69 }
70
71 ImGui::SameLine();
72 if (ImGui::Button(ICON_MD_BOOKMARK " Bookmarks")) {
73 ImGui::OpenPopup("Bookmarks");
74 }
75 if (ImGui::IsItemHovered()) {
76 ImGui::SetTooltip("Manage address bookmarks");
77 }
78
79 ImGui::SameLine();
80 ImGui::Text(ICON_MD_MORE_VERT);
81 ImGui::SameLine();
82
83 // Show current address
84 if (current_address_ != 0) {
85 ImGui::TextColored(ImVec4(0.4f, 0.8f, 1.0f, 1.0f),
87 }
88
89 ImGui::PopStyleVar(2);
90 ImGui::Separator();
91
95}
96
98 if (ImGui::BeginPopupModal("JumpToAddress", nullptr,
99 ImGuiWindowFlags_AlwaysAutoResize)) {
100 ImGui::TextColored(ImVec4(0.4f, 0.8f, 1.0f, 1.0f),
101 ICON_MD_LOCATION_SEARCHING " Jump to Address");
102 ImGui::Separator();
103 ImGui::Spacing();
104
105 ImGui::SetNextItemWidth(200);
106 if (ImGui::InputText("##jump_addr", jump_address_,
107 IM_ARRAYSIZE(jump_address_),
108 ImGuiInputTextFlags_CharsHexadecimal |
109 ImGuiInputTextFlags_EnterReturnsTrue)) {
110 // Parse and jump on Enter key
111 unsigned int addr;
112 if (sscanf(jump_address_, "%X", &addr) == 1) {
113 current_address_ = addr;
114 memory_widget_.GotoAddrAndHighlight(addr, addr + 1);
115 ImGui::CloseCurrentPopup();
116 }
117 }
118 ImGui::TextDisabled("Format: 0x1C800 or 1C800");
119
120 ImGui::Spacing();
121 ImGui::Separator();
122 ImGui::Spacing();
123
124 if (ImGui::Button(ICON_MD_CHECK " Go", ImVec2(120, 0))) {
125 unsigned int addr;
126 if (sscanf(jump_address_, "%X", &addr) == 1) {
127 current_address_ = addr;
128 memory_widget_.GotoAddrAndHighlight(addr, addr + 1);
129 }
130 ImGui::CloseCurrentPopup();
131 }
132 ImGui::SameLine();
133 if (ImGui::Button(ICON_MD_CANCEL " Cancel", ImVec2(120, 0))) {
134 ImGui::CloseCurrentPopup();
135 }
136 ImGui::EndPopup();
137 }
138}
139
141 if (ImGui::BeginPopupModal("SearchPattern", nullptr,
142 ImGuiWindowFlags_AlwaysAutoResize)) {
143 ImGui::TextColored(ImVec4(0.4f, 0.8f, 0.4f, 1.0f),
144 ICON_MD_SEARCH " Search Hex Pattern");
145 ImGui::Separator();
146 ImGui::Spacing();
147
148 ImGui::SetNextItemWidth(300);
149 if (ImGui::InputText("##search_pattern", search_pattern_,
150 IM_ARRAYSIZE(search_pattern_),
151 ImGuiInputTextFlags_EnterReturnsTrue)) {
152 // TODO: Implement search
153 ImGui::CloseCurrentPopup();
154 }
155 ImGui::TextDisabled("Use ?? for wildcard (e.g. FF 00 ?? 12)");
156 ImGui::Spacing();
157
158 // Quick preset patterns
159 ImGui::Text(ICON_MD_LIST " Quick Patterns:");
160 if (ImGui::SmallButton("LDA")) {
161 snprintf(search_pattern_, sizeof(search_pattern_), "A9 ??");
162 }
163 ImGui::SameLine();
164 if (ImGui::SmallButton("STA")) {
165 snprintf(search_pattern_, sizeof(search_pattern_), "8D ?? ??");
166 }
167 ImGui::SameLine();
168 if (ImGui::SmallButton("JSR")) {
169 snprintf(search_pattern_, sizeof(search_pattern_), "20 ?? ??");
170 }
171
172 ImGui::Spacing();
173 ImGui::Separator();
174 ImGui::Spacing();
175
176 if (ImGui::Button(ICON_MD_SEARCH " Search", ImVec2(120, 0))) {
177 // TODO: Implement search using hex-search handler
178 ImGui::CloseCurrentPopup();
179 }
180 ImGui::SameLine();
181 if (ImGui::Button(ICON_MD_CANCEL " Cancel", ImVec2(120, 0))) {
182 ImGui::CloseCurrentPopup();
183 }
184 ImGui::EndPopup();
185 }
186}
187
189 if (ImGui::BeginPopupModal("Bookmarks", nullptr,
190 ImGuiWindowFlags_AlwaysAutoResize)) {
191 ImGui::TextColored(ImVec4(1.0f, 0.843f, 0.0f, 1.0f),
192 ICON_MD_BOOKMARK " Memory Bookmarks");
193 ImGui::Separator();
194 ImGui::Spacing();
195
196 if (bookmarks_.empty()) {
197 ImGui::TextDisabled(ICON_MD_INFO " No bookmarks yet");
198 ImGui::Spacing();
199 ImGui::Separator();
200 ImGui::Spacing();
201
202 if (ImGui::Button(ICON_MD_ADD " Add Current Address", ImVec2(250, 0))) {
203 Bookmark new_bookmark;
204 new_bookmark.address = current_address_;
205 new_bookmark.name =
206 absl::StrFormat("Bookmark %zu", bookmarks_.size() + 1);
207 new_bookmark.description = "User-defined bookmark";
208 bookmarks_.push_back(new_bookmark);
209 }
210 } else {
211 // Bookmarks table
212 ImGui::BeginChild("##bookmarks_list", ImVec2(500, 300), true);
213 if (ImGui::BeginTable("##bookmarks_table", 3,
214 ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg |
215 ImGuiTableFlags_Resizable)) {
216 ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, 150);
217 ImGui::TableSetupColumn("Address", ImGuiTableColumnFlags_WidthFixed,
218 100);
219 ImGui::TableSetupColumn("Description",
220 ImGuiTableColumnFlags_WidthStretch);
221 ImGui::TableHeadersRow();
222
223 for (size_t i = 0; i < bookmarks_.size(); ++i) {
224 const auto& bm = bookmarks_[i];
225 ImGui::PushID(static_cast<int>(i));
226
227 ImGui::TableNextRow();
228 ImGui::TableNextColumn();
229 if (ImGui::Selectable(bm.name.c_str(), false,
230 ImGuiSelectableFlags_SpanAllColumns)) {
231 current_address_ = bm.address;
232 memory_widget_.GotoAddrAndHighlight(bm.address, bm.address + 1);
233 ImGui::CloseCurrentPopup();
234 }
235
236 ImGui::TableNextColumn();
237 ImGui::TextColored(ImVec4(0.4f, 0.8f, 1.0f, 1.0f), "0x%06X",
238 bm.address);
239
240 ImGui::TableNextColumn();
241 ImGui::TextDisabled("%s", bm.description.c_str());
242
243 ImGui::PopID();
244 }
245 ImGui::EndTable();
246 }
247 ImGui::EndChild();
248
249 ImGui::Spacing();
250 if (ImGui::Button(ICON_MD_ADD " Add Bookmark", ImVec2(150, 0))) {
251 Bookmark new_bookmark;
252 new_bookmark.address = current_address_;
253 new_bookmark.name =
254 absl::StrFormat("Bookmark %zu", bookmarks_.size() + 1);
255 new_bookmark.description = "User-defined bookmark";
256 bookmarks_.push_back(new_bookmark);
257 }
258 ImGui::SameLine();
259 if (ImGui::Button(ICON_MD_CLEAR_ALL " Clear All", ImVec2(150, 0))) {
260 bookmarks_.clear();
261 }
262 }
263
264 ImGui::Spacing();
265 ImGui::Separator();
266 ImGui::Spacing();
267
268 if (ImGui::Button(ICON_MD_CLOSE " Close", ImVec2(250, 0))) {
269 ImGui::CloseCurrentPopup();
270 }
271
272 ImGui::EndPopup();
273 }
274}
275
276} // namespace editor
277} // namespace yaze
absl::Status LoadFromFile(const std::string &filename, const LoadOptions &options=LoadOptions::Defaults())
Definition rom.cc:75
auto filename() const
Definition rom.h:141
auto size() const
Definition rom.h:134
static std::string ShowOpenFileDialog()
ShowOpenFileDialog opens a file dialog and returns the selected filepath. Uses global feature flag to...
#define ICON_MD_LOCATION_ON
Definition icons.h:1137
#define ICON_MD_LOCATION_SEARCHING
Definition icons.h:1139
#define ICON_MD_INFO
Definition icons.h:993
#define ICON_MD_CANCEL
Definition icons.h:364
#define ICON_MD_MORE_VERT
Definition icons.h:1243
#define ICON_MD_SEARCH
Definition icons.h:1673
#define ICON_MD_CHECK
Definition icons.h:397
#define ICON_MD_LIST
Definition icons.h:1094
#define ICON_MD_CLEAR_ALL
Definition icons.h:417
#define ICON_MD_ADD
Definition icons.h:86
#define ICON_MD_BOOKMARK
Definition icons.h:285
#define ICON_MD_CLOSE
Definition icons.h:418
#define SETUP_COLUMN(l)
Definition macro.h:12
#define END_TABLE()
Definition macro.h:20
#define BEGIN_TABLE(l, n, f)
Definition macro.h:11
#define PRINT_IF_ERROR(expression)
Definition macro.h:28
#define NEXT_COLUMN()
Definition macro.h:18
bool InputHex(const char *label, uint64_t *data)
Definition input.cc:325
uint32_t SnesToPc(uint32_t addr) noexcept
Definition snes.h:8
void Update(bool &show_memory_editor)
std::vector< Bookmark > bookmarks_
gui::MemoryEditorWidget memory_widget_
gui::MemoryEditorWidget comparison_widget_
void GotoAddrAndHighlight(size_t addr_min, size_t addr_max)
void DrawContents(void *mem_data_void, size_t mem_size, size_t base_display_addr=0x0000)