Skip to content

Commit

Permalink
Add mem editor window menu
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Dec 14, 2024
1 parent acc5b64 commit 925742e
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 50 deletions.
6 changes: 6 additions & 0 deletions platforms/desktop-shared/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion platforms/desktop-shared/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions platforms/desktop-shared/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ enum gui_ShortCutEvent
gui_ShortcutDebugBreakpoint,
gui_ShortcutDebugRuntocursor,
gui_ShortcutDebugGoBack,
gui_ShortcutDebugCopy,
gui_ShortcutDebugPaste,
gui_ShortcutShowMainMenu
};

Expand Down
47 changes: 0 additions & 47 deletions platforms/desktop-shared/gui_colors.h

This file was deleted.

140 changes: 138 additions & 2 deletions platforms/desktop-shared/gui_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
#include <math.h>
#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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<MemEditor::Bookmark>* 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();
Expand Down
2 changes: 2 additions & 0 deletions platforms/desktop-shared/gui_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 925742e

Please sign in to comment.