diff --git a/platforms/desktop-shared/application.cpp b/platforms/desktop-shared/application.cpp index 9acdcdae..196d68d6 100644 --- a/platforms/desktop-shared/application.cpp +++ b/platforms/desktop-shared/application.cpp @@ -448,6 +448,12 @@ static void sdl_shortcuts_gui(const SDL_Event* event) switch (key) { + case SDL_SCANCODE_C: + gui_shortcut(gui_ShortcutDebugCopy); + break; + case SDL_SCANCODE_V: + gui_shortcut(gui_ShortcutDebugPaste); + break; case SDL_SCANCODE_O: gui_shortcut(gui_ShortcutOpenROM); break; diff --git a/platforms/desktop-shared/gui.cpp b/platforms/desktop-shared/gui.cpp index 34261ce3..0681d661 100644 --- a/platforms/desktop-shared/gui.cpp +++ b/platforms/desktop-shared/gui.cpp @@ -28,7 +28,7 @@ #include "license.h" #include "backers.h" #include "gui_debug.h" -#include "gui_colors.h" +#include "imgui/colors.h" #define GUI_IMPORT #include "gui.h" @@ -217,6 +217,12 @@ void gui_shortcut(gui_ShortCutEvent event) if (config_debug.debug) gui_debug_go_back(); break; + case gui_ShortcutDebugCopy: + gui_debug_copy_memory(); + break; + case gui_ShortcutDebugPaste: + gui_debug_paste_memory(); + break; case gui_ShortcutShowMainMenu: config_emulator.show_menu = !config_emulator.show_menu; break; diff --git a/platforms/desktop-shared/gui.h b/platforms/desktop-shared/gui.h index a1299379..a0d7c753 100644 --- a/platforms/desktop-shared/gui.h +++ b/platforms/desktop-shared/gui.h @@ -55,6 +55,8 @@ enum gui_ShortCutEvent gui_ShortcutDebugBreakpoint, gui_ShortcutDebugRuntocursor, gui_ShortcutDebugGoBack, + gui_ShortcutDebugCopy, + gui_ShortcutDebugPaste, gui_ShortcutShowMainMenu }; diff --git a/platforms/desktop-shared/gui_colors.h b/platforms/desktop-shared/gui_colors.h deleted file mode 100644 index 48a51dd8..00000000 --- a/platforms/desktop-shared/gui_colors.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Gearboy - Nintendo Game Boy Emulator - * Copyright (C) 2012 Ignacio Sanchez - - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://www.gnu.org/licenses/ - * - */ - -#ifndef GUI_COLORS_H -#define GUI_COLORS_H - -#include "imgui/imgui.h" - -static const ImVec4 cyan = ImVec4(0.10f, 0.90f, 0.90f, 1.0f); -static const ImVec4 dark_cyan = ImVec4(0.00f, 0.30f, 0.30f, 1.0f); -static const ImVec4 magenta = ImVec4(1.00f, 0.50f, 0.96f, 1.0f); -static const ImVec4 dark_magenta = ImVec4(0.30f, 0.18f, 0.27f, 1.0f); -static const ImVec4 yellow = ImVec4(1.00f, 0.90f, 0.05f, 1.0f); -static const ImVec4 dark_yellow = ImVec4(0.30f, 0.25f, 0.00f, 1.0f); -static const ImVec4 orange = ImVec4(0.99f, 0.59f, 0.12f, 1.0f); -static const ImVec4 dark_orange = ImVec4(0.30f, 0.20f, 0.03f, 1.0f); -static const ImVec4 red = ImVec4(0.98f, 0.15f, 0.45f, 1.0f); -static const ImVec4 dark_red = ImVec4(0.30f, 0.04f, 0.16f, 1.0f); -static const ImVec4 green = ImVec4(0.10f, 0.90f, 0.10f, 1.0f); -static const ImVec4 dark_green = ImVec4(0.03f, 0.20f, 0.02f, 1.0f); -static const ImVec4 violet = ImVec4(0.68f, 0.51f, 1.00f, 1.0f); -static const ImVec4 dark_violet = ImVec4(0.24f, 0.15f, 0.30f, 1.0f); -static const ImVec4 blue = ImVec4(0.20f, 0.40f, 1.00f, 1.0f); -static const ImVec4 dark_blue = ImVec4(0.07f, 0.10f, 0.30f, 1.0f); -static const ImVec4 white = ImVec4(1.00f, 1.00f, 1.00f, 1.0f); -static const ImVec4 gray = ImVec4(0.50f, 0.50f, 0.50f, 1.0f); -static const ImVec4 mid_gray = ImVec4(0.40f, 0.40f, 0.40f, 1.0f); -static const ImVec4 dark_gray = ImVec4(0.10f, 0.10f, 0.10f, 1.0f); -static const ImVec4 black = ImVec4(0.00f, 0.00f, 0.00f, 1.0f); - -#endif /* GUI_COLORS_H */ \ No newline at end of file diff --git a/platforms/desktop-shared/gui_debug.cpp b/platforms/desktop-shared/gui_debug.cpp index 29bc8589..960b554b 100644 --- a/platforms/desktop-shared/gui_debug.cpp +++ b/platforms/desktop-shared/gui_debug.cpp @@ -20,12 +20,13 @@ #include #include "imgui/imgui.h" #include "imgui/memory_editor.h" +#include "nfd/nfd.h" #include "config.h" #include "emu.h" #include "renderer.h" #include "../../src/gearboy.h" #include "gui.h" -#include "gui_colors.h" +#include "imgui/colors.h" #include "gui_debug_constants.h" #define GUI_DEBUG_IMPORT @@ -60,11 +61,13 @@ static bool goto_address_requested = false; static u16 goto_address_target = 0; static bool goto_back_requested = false; static int goto_back = 0; +static char set_value_buffer[5] = {0}; static void debug_window_processor(void); static void debug_window_io(void); static void debug_window_audio(void); static void debug_window_memory(void); +static void memory_editor_menu(void); static void debug_window_disassembler(void); static void debug_window_vram(void); static void debug_window_vram_background(void); @@ -202,12 +205,145 @@ void gui_debug_go_back(void) goto_back_requested = true; } +void gui_debug_copy_memory(void) +{ + mem_edit[current_mem_edit].Copy(); +} + +void gui_debug_paste_memory(void) +{ + mem_edit[current_mem_edit].Paste(); +} + + +static void memory_editor_menu(void) +{ + ImGui::BeginMenuBar(); + + if (ImGui::BeginMenu("File")) + { + if (ImGui::MenuItem("Save Memory As...")) + { + nfdchar_t *outPath; + nfdfilteritem_t filterItem[1] = { { "Memory Dump Files", "txt" } }; + nfdresult_t result = NFD_SaveDialog(&outPath, filterItem, 1, NULL, NULL); + if (result == NFD_OKAY) + { + mem_edit[current_mem_edit].SaveToFile(outPath); + NFD_FreePath(outPath); + } + else if (result != NFD_CANCEL) + { + Log("Save Memory Dump Error: %s", NFD_GetError()); + } + } + + ImGui::EndMenu(); + } + + if (ImGui::BeginMenu("Edit")) + { + if (ImGui::MenuItem("Copy", "Ctrl+C")) + { + gui_debug_copy_memory(); + } + + if (ImGui::MenuItem("Paste", "Ctrl+V")) + { + gui_debug_paste_memory(); + } + + ImGui::EndMenu(); + } + + if (ImGui::BeginMenu("Selection")) + { + if (ImGui::MenuItem("Select All", "Ctrl+A")) + { + mem_edit[current_mem_edit].SelectAll(); + } + + if (ImGui::MenuItem("Clear Selection")) + { + mem_edit[current_mem_edit].ClearSelection(); + } + + if (ImGui::BeginMenu("Set value")) + { + ImGui::SetNextItemWidth(50); + if (ImGui::InputTextWithHint("##set_value", "XXXX", set_value_buffer, IM_ARRAYSIZE(set_value_buffer), ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase)) + { + try + { + mem_edit[current_mem_edit].SetValueToSelection((int)std::stoul(set_value_buffer, 0, 16)); + set_value_buffer[0] = 0; + } + catch(const std::invalid_argument&) + { + } + } + ImGui::SameLine(); + if (ImGui::Button("Set!", ImVec2(40, 0))) + { + try + { + mem_edit[current_mem_edit].SetValueToSelection((int)std::stoul(set_value_buffer, 0, 16)); + set_value_buffer[0] = 0; + } + catch(const std::invalid_argument&) + { + } + } + ImGui::EndMenu(); + } + + ImGui::EndMenu(); + } + + if (ImGui::BeginMenu("Bookmarks")) + { + if (ImGui::MenuItem("Clear All")) + { + mem_edit[current_mem_edit].RemoveBookmarks(); + } + + if (ImGui::MenuItem("Add Bookmark")) + { + mem_edit[current_mem_edit].AddBookmark(); + } + + std::vector* bookmarks = mem_edit[current_mem_edit].GetBookmarks(); + + if (bookmarks->size() > 0) + ImGui::Separator(); + + for (long unsigned int i = 0; i < bookmarks->size(); i++) + { + MemEditor::Bookmark* bookmark = &(*bookmarks)[i]; + + char label[80]; + snprintf(label, 80, "$%04X: %s", bookmark->address, bookmark->name); + + if (ImGui::MenuItem(label)) + { + mem_edit[current_mem_edit].JumpToAddress(bookmark->address); + } + } + + ImGui::EndMenu(); + } + + ImGui::EndMenuBar(); +} + static void debug_window_memory(void) { ImGui::SetNextWindowPos(ImVec2(180, 382), ImGuiCond_FirstUseEver); ImGui::SetNextWindowSize(ImVec2(482, 308), ImGuiCond_FirstUseEver); - ImGui::Begin("Memory Editor", &config_debug.show_memory); + ImGui::Begin("Memory Editor", &config_debug.show_memory, ImGuiWindowFlags_MenuBar); + + memory_editor_menu(); GearboyCore* core = emu_get_core(); Memory* memory = core->GetMemory(); diff --git a/platforms/desktop-shared/gui_debug.h b/platforms/desktop-shared/gui_debug.h index df8715ee..e3369889 100644 --- a/platforms/desktop-shared/gui_debug.h +++ b/platforms/desktop-shared/gui_debug.h @@ -47,6 +47,8 @@ EXTERN void gui_debug_reset_breakpoints_cpu(void); EXTERN void gui_debug_reset_breakpoints_mem(void); EXTERN void gui_debug_runtocursor(void); EXTERN void gui_debug_go_back(void); +EXTERN void gui_debug_copy_memory(void); +EXTERN void gui_debug_paste_memory(void); #undef GUI_DEBUG_IMPORT #undef EXTERN