|
20 | 20 | #define GUI_DEBUG_IMPORT |
21 | 21 | #include "gui_debug.h" |
22 | 22 |
|
| 23 | +#include <fstream> |
23 | 24 | #include "geargrafx.h" |
24 | 25 | #include "imgui.h" |
25 | 26 | #include "gui_debug_disassembler.h" |
@@ -125,3 +126,119 @@ void gui_debug_windows(void) |
125 | 126 | gui_debug_memory_search_window(); |
126 | 127 | } |
127 | 128 | } |
| 129 | + |
| 130 | +static const char* GGDEBUG_MAGIC = "GGDEBUG1"; |
| 131 | +static const int GGDEBUG_MAGIC_LEN = 8; |
| 132 | + |
| 133 | +void gui_debug_save_settings(const char* file_path) |
| 134 | +{ |
| 135 | + std::ofstream file(file_path, std::ios::binary); |
| 136 | + if (!file.is_open()) |
| 137 | + { |
| 138 | + Log("Failed to open debug settings file for writing: %s", file_path); |
| 139 | + return; |
| 140 | + } |
| 141 | + |
| 142 | + file.write(GGDEBUG_MAGIC, GGDEBUG_MAGIC_LEN); |
| 143 | + |
| 144 | + GeargrafxCore* core = emu_get_core(); |
| 145 | + HuC6280* processor = core->GetHuC6280(); |
| 146 | + |
| 147 | + std::vector<HuC6280::GG_Breakpoint>* breakpoints = processor->GetBreakpoints(); |
| 148 | + int bp_count = (int)breakpoints->size(); |
| 149 | + file.write((const char*)&bp_count, sizeof(int)); |
| 150 | + for (int i = 0; i < bp_count; i++) |
| 151 | + { |
| 152 | + HuC6280::GG_Breakpoint& bp = (*breakpoints)[i]; |
| 153 | + file.write((const char*)&bp.enabled, sizeof(bool)); |
| 154 | + file.write((const char*)&bp.type, sizeof(int)); |
| 155 | + file.write((const char*)&bp.address1, sizeof(u16)); |
| 156 | + file.write((const char*)&bp.address2, sizeof(u16)); |
| 157 | + file.write((const char*)&bp.read, sizeof(bool)); |
| 158 | + file.write((const char*)&bp.write, sizeof(bool)); |
| 159 | + file.write((const char*)&bp.execute, sizeof(bool)); |
| 160 | + file.write((const char*)&bp.range, sizeof(bool)); |
| 161 | + } |
| 162 | + |
| 163 | + file.write((const char*)&emu_debug_irq_breakpoints, sizeof(bool)); |
| 164 | + |
| 165 | + void* bookmarks_ptr = NULL; |
| 166 | + int bookmark_count = gui_debug_get_disassembler_bookmarks(&bookmarks_ptr); |
| 167 | + file.write((const char*)&bookmark_count, sizeof(int)); |
| 168 | + if (bookmark_count > 0 && bookmarks_ptr != NULL) |
| 169 | + { |
| 170 | + struct DasmBookmark { u16 address; char name[32]; }; |
| 171 | + std::vector<DasmBookmark>* bm_vec = (std::vector<DasmBookmark>*)bookmarks_ptr; |
| 172 | + for (int i = 0; i < bookmark_count; i++) |
| 173 | + { |
| 174 | + file.write((const char*)&(*bm_vec)[i].address, sizeof(u16)); |
| 175 | + file.write((*bm_vec)[i].name, 32); |
| 176 | + } |
| 177 | + } |
| 178 | + |
| 179 | + gui_debug_memory_save_settings(file); |
| 180 | + |
| 181 | + file.close(); |
| 182 | + |
| 183 | + Log("Debug settings saved to: %s", file_path); |
| 184 | +} |
| 185 | + |
| 186 | +void gui_debug_load_settings(const char* file_path) |
| 187 | +{ |
| 188 | + std::ifstream file(file_path, std::ios::binary); |
| 189 | + if (!file.is_open()) |
| 190 | + { |
| 191 | + Log("Failed to open debug settings file for reading: %s", file_path); |
| 192 | + return; |
| 193 | + } |
| 194 | + |
| 195 | + char magic[8]; |
| 196 | + file.read(magic, GGDEBUG_MAGIC_LEN); |
| 197 | + if (memcmp(magic, GGDEBUG_MAGIC, GGDEBUG_MAGIC_LEN) != 0) |
| 198 | + { |
| 199 | + Log("Invalid debug settings file: %s", file_path); |
| 200 | + file.close(); |
| 201 | + return; |
| 202 | + } |
| 203 | + |
| 204 | + GeargrafxCore* core = emu_get_core(); |
| 205 | + HuC6280* processor = core->GetHuC6280(); |
| 206 | + |
| 207 | + processor->ResetBreakpoints(); |
| 208 | + int bp_count = 0; |
| 209 | + file.read((char*)&bp_count, sizeof(int)); |
| 210 | + std::vector<HuC6280::GG_Breakpoint>* breakpoints = processor->GetBreakpoints(); |
| 211 | + for (int i = 0; i < bp_count; i++) |
| 212 | + { |
| 213 | + HuC6280::GG_Breakpoint bp; |
| 214 | + file.read((char*)&bp.enabled, sizeof(bool)); |
| 215 | + file.read((char*)&bp.type, sizeof(int)); |
| 216 | + file.read((char*)&bp.address1, sizeof(u16)); |
| 217 | + file.read((char*)&bp.address2, sizeof(u16)); |
| 218 | + file.read((char*)&bp.read, sizeof(bool)); |
| 219 | + file.read((char*)&bp.write, sizeof(bool)); |
| 220 | + file.read((char*)&bp.execute, sizeof(bool)); |
| 221 | + file.read((char*)&bp.range, sizeof(bool)); |
| 222 | + breakpoints->push_back(bp); |
| 223 | + } |
| 224 | + |
| 225 | + file.read((char*)&emu_debug_irq_breakpoints, sizeof(bool)); |
| 226 | + |
| 227 | + gui_debug_reset_disassembler_bookmarks(); |
| 228 | + int bookmark_count = 0; |
| 229 | + file.read((char*)&bookmark_count, sizeof(int)); |
| 230 | + for (int i = 0; i < bookmark_count; i++) |
| 231 | + { |
| 232 | + u16 address; |
| 233 | + char name[32]; |
| 234 | + file.read((char*)&address, sizeof(u16)); |
| 235 | + file.read(name, 32); |
| 236 | + gui_debug_add_disassembler_bookmark(address, name); |
| 237 | + } |
| 238 | + |
| 239 | + gui_debug_memory_load_settings(file); |
| 240 | + |
| 241 | + file.close(); |
| 242 | + |
| 243 | + Log("Debug settings loaded from: %s", file_path); |
| 244 | +} |
0 commit comments