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());
42 ImGui::EndChild();
43 ImGui::EndGroup();
44 }
45 END_TABLE()
46
47 ImGui::End();
48}
49
51 // Modern compact toolbar with icon-only buttons
52 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(6, 4));
53 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4, 4));
54
55 if (ImGui::Button(ICON_MD_LOCATION_SEARCHING " Jump")) {
56 ImGui::OpenPopup("JumpToAddress");
57 }
58 if (ImGui::IsItemHovered()) {
59 ImGui::SetTooltip("Jump to specific address");
60 }
61
62 ImGui::SameLine();
63 if (ImGui::Button(ICON_MD_SEARCH " Search")) {
64 ImGui::OpenPopup("SearchPattern");
65 }
66 if (ImGui::IsItemHovered()) {
67 ImGui::SetTooltip("Search for hex pattern");
68 }
69
70 ImGui::SameLine();
71 if (ImGui::Button(ICON_MD_BOOKMARK " Bookmarks")) {
72 ImGui::OpenPopup("Bookmarks");
73 }
74 if (ImGui::IsItemHovered()) {
75 ImGui::SetTooltip("Manage address bookmarks");
76 }
77
78 ImGui::SameLine();
79 ImGui::Text(ICON_MD_MORE_VERT);
80 ImGui::SameLine();
81
82 // Show current address
83 if (current_address_ != 0) {
84 ImGui::TextColored(ImVec4(0.4f, 0.8f, 1.0f, 1.0f),
86 }
87
88 ImGui::PopStyleVar(2);
89 ImGui::Separator();
90
94}
95
97 if (ImGui::BeginPopupModal("JumpToAddress", nullptr,
98 ImGuiWindowFlags_AlwaysAutoResize)) {
99 ImGui::TextColored(ImVec4(0.4f, 0.8f, 1.0f, 1.0f),
100 ICON_MD_LOCATION_SEARCHING " Jump to Address");
101 ImGui::Separator();
102 ImGui::Spacing();
103
104 ImGui::SetNextItemWidth(200);
105 if (ImGui::InputText("##jump_addr", jump_address_,
106 IM_ARRAYSIZE(jump_address_),
107 ImGuiInputTextFlags_CharsHexadecimal |
108 ImGuiInputTextFlags_EnterReturnsTrue)) {
109 // Parse and jump on Enter key
110 unsigned int addr;
111 if (sscanf(jump_address_, "%X", &addr) == 1) {
112 current_address_ = addr;
113 memory_widget_.GotoAddrAndHighlight(addr, addr + 1);
114 ImGui::CloseCurrentPopup();
115 }
116 }
117 ImGui::TextDisabled("Format: 0x1C800 or 1C800");
118
119 ImGui::Spacing();
120 ImGui::Separator();
121 ImGui::Spacing();
122
123 if (ImGui::Button(ICON_MD_CHECK " Go", ImVec2(120, 0))) {
124 unsigned int addr;
125 if (sscanf(jump_address_, "%X", &addr) == 1) {
126 current_address_ = addr;
127 memory_widget_.GotoAddrAndHighlight(addr, addr + 1);
128 }
129 ImGui::CloseCurrentPopup();
130 }
131 ImGui::SameLine();
132 if (ImGui::Button(ICON_MD_CANCEL " Cancel", ImVec2(120, 0))) {
133 ImGui::CloseCurrentPopup();
134 }
135 ImGui::EndPopup();
136 }
137}
138
140 if (ImGui::BeginPopupModal("SearchPattern", nullptr,
141 ImGuiWindowFlags_AlwaysAutoResize)) {
142 ImGui::TextColored(ImVec4(0.4f, 0.8f, 0.4f, 1.0f),
143 ICON_MD_SEARCH " Search Hex Pattern");
144 ImGui::Separator();
145 ImGui::Spacing();
146
147 ImGui::SetNextItemWidth(300);
148 if (ImGui::InputText("##search_pattern", search_pattern_,
149 IM_ARRAYSIZE(search_pattern_),
150 ImGuiInputTextFlags_EnterReturnsTrue)) {
151 // TODO: Implement search
152 ImGui::CloseCurrentPopup();
153 }
154 ImGui::TextDisabled("Use ?? for wildcard (e.g. FF 00 ?? 12)");
155 ImGui::Spacing();
156
157 // Quick preset patterns
158 ImGui::Text(ICON_MD_LIST " Quick Patterns:");
159 if (ImGui::SmallButton("LDA")) {
160 snprintf(search_pattern_, sizeof(search_pattern_), "A9 ??");
161 }
162 ImGui::SameLine();
163 if (ImGui::SmallButton("STA")) {
164 snprintf(search_pattern_, sizeof(search_pattern_), "8D ?? ??");
165 }
166 ImGui::SameLine();
167 if (ImGui::SmallButton("JSR")) {
168 snprintf(search_pattern_, sizeof(search_pattern_), "20 ?? ??");
169 }
170
171 ImGui::Spacing();
172 ImGui::Separator();
173 ImGui::Spacing();
174
175 if (ImGui::Button(ICON_MD_SEARCH " Search", ImVec2(120, 0))) {
176 // TODO: Implement search using hex-search handler
177 ImGui::CloseCurrentPopup();
178 }
179 ImGui::SameLine();
180 if (ImGui::Button(ICON_MD_CANCEL " Cancel", ImVec2(120, 0))) {
181 ImGui::CloseCurrentPopup();
182 }
183 ImGui::EndPopup();
184 }
185}
186
188 if (ImGui::BeginPopupModal("Bookmarks", nullptr,
189 ImGuiWindowFlags_AlwaysAutoResize)) {
190 ImGui::TextColored(ImVec4(1.0f, 0.843f, 0.0f, 1.0f),
191 ICON_MD_BOOKMARK " Memory Bookmarks");
192 ImGui::Separator();
193 ImGui::Spacing();
194
195 if (bookmarks_.empty()) {
196 ImGui::TextDisabled(ICON_MD_INFO " No bookmarks yet");
197 ImGui::Spacing();
198 ImGui::Separator();
199 ImGui::Spacing();
200
201 if (ImGui::Button(ICON_MD_ADD " Add Current Address", ImVec2(250, 0))) {
202 Bookmark new_bookmark;
203 new_bookmark.address = current_address_;
204 new_bookmark.name =
205 absl::StrFormat("Bookmark %zu", bookmarks_.size() + 1);
206 new_bookmark.description = "User-defined bookmark";
207 bookmarks_.push_back(new_bookmark);
208 }
209 } else {
210 // Bookmarks table
211 ImGui::BeginChild("##bookmarks_list", ImVec2(500, 300), true);
212 if (ImGui::BeginTable("##bookmarks_table", 3,
213 ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg |
214 ImGuiTableFlags_Resizable)) {
215 ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, 150);
216 ImGui::TableSetupColumn("Address", ImGuiTableColumnFlags_WidthFixed,
217 100);
218 ImGui::TableSetupColumn("Description",
219 ImGuiTableColumnFlags_WidthStretch);
220 ImGui::TableHeadersRow();
221
222 for (size_t i = 0; i < bookmarks_.size(); ++i) {
223 const auto& bm = bookmarks_[i];
224 ImGui::PushID(static_cast<int>(i));
225
226 ImGui::TableNextRow();
227 ImGui::TableNextColumn();
228 if (ImGui::Selectable(bm.name.c_str(), false,
229 ImGuiSelectableFlags_SpanAllColumns)) {
230 current_address_ = bm.address;
231 memory_widget_.GotoAddrAndHighlight(bm.address, bm.address + 1);
232 ImGui::CloseCurrentPopup();
233 }
234
235 ImGui::TableNextColumn();
236 ImGui::TextColored(ImVec4(0.4f, 0.8f, 1.0f, 1.0f), "0x%06X",
237 bm.address);
238
239 ImGui::TableNextColumn();
240 ImGui::TextDisabled("%s", bm.description.c_str());
241
242 ImGui::PopID();
243 }
244 ImGui::EndTable();
245 }
246 ImGui::EndChild();
247
248 ImGui::Spacing();
249 if (ImGui::Button(ICON_MD_ADD " Add Bookmark", ImVec2(150, 0))) {
250 Bookmark new_bookmark;
251 new_bookmark.address = current_address_;
252 new_bookmark.name =
253 absl::StrFormat("Bookmark %zu", bookmarks_.size() + 1);
254 new_bookmark.description = "User-defined bookmark";
255 bookmarks_.push_back(new_bookmark);
256 }
257 ImGui::SameLine();
258 if (ImGui::Button(ICON_MD_CLEAR_ALL " Clear All", ImVec2(150, 0))) {
259 bookmarks_.clear();
260 }
261 }
262
263 ImGui::Spacing();
264 ImGui::Separator();
265 ImGui::Spacing();
266
267 if (ImGui::Button(ICON_MD_CLOSE " Close", ImVec2(250, 0))) {
268 ImGui::CloseCurrentPopup();
269 }
270
271 ImGui::EndPopup();
272 }
273}
274
275} // namespace editor
276} // namespace yaze
absl::Status LoadFromFile(const std::string &filename, const LoadOptions &options=LoadOptions::Defaults())
Definition rom.cc:74
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)