add memory_editor.h for hex editor and rom diff checker

This commit is contained in:
scawful
2024-07-19 16:34:37 -04:00
parent afbf0d888b
commit d73a970e57
3 changed files with 94 additions and 39 deletions

View File

@@ -0,0 +1,90 @@
#ifndef YAZE_APP_EDITOR_CODE_MEMORY_EDITOR_H
#define YAZE_APP_EDITOR_CODE_MEMORY_EDITOR_H
#include <imgui/imgui.h>
#include <imgui/misc/cpp/imgui_stdlib.h>
#include <imgui_memory_editor.h>
#include "absl/status/status.h"
#include "app/core/common.h"
#include "app/core/constants.h"
#include "app/core/platform/file_dialog.h"
#include "app/core/project.h"
#include "app/editor/code/assembly_editor.h"
#include "app/editor/code/memory_editor.h"
#include "app/editor/context/gfx_context.h"
#include "app/editor/dungeon_editor.h"
#include "app/editor/graphics/graphics_editor.h"
#include "app/editor/graphics/palette_editor.h"
#include "app/editor/graphics/screen_editor.h"
#include "app/editor/music/music_editor.h"
#include "app/editor/overworld_editor.h"
#include "app/editor/sprite/sprite_editor.h"
#include "app/editor/utils/editor.h"
#include "app/editor/utils/recent_files.h"
#include "app/emu/emulator.h"
#include "app/gfx/snes_palette.h"
#include "app/gfx/snes_tile.h"
#include "app/gui/canvas.h"
#include "app/gui/icons.h"
#include "app/gui/input.h"
#include "app/gui/pipeline.h"
#include "app/gui/style.h"
#include "app/gui/widgets.h"
#include "app/rom.h"
namespace yaze {
namespace app {
namespace editor {
using ImGui::SameLine;
using ImGui::Text;
struct MemoryEditorWithDiffChecker : public SharedRom {
void Update(bool &show_memory_editor) {
static MemoryEditor mem_edit;
static MemoryEditor comp_edit;
static bool show_compare_rom = false;
static Rom comparison_rom;
ImGui::Begin("Hex Editor", &show_memory_editor);
if (ImGui::Button("Compare Rom")) {
auto file_name = FileDialogWrapper::ShowOpenFileDialog();
PRINT_IF_ERROR(comparison_rom.LoadFromFile(file_name));
show_compare_rom = true;
}
static uint64_t convert_address = 0;
gui::InputHex("SNES to PC", (int *)&convert_address, 6, 200.f);
SameLine();
Text("%x", core::SnesToPc(convert_address));
// mem_edit.DrawWindow("Memory Editor", (void*)&(*rom()), rom()->size());
BEGIN_TABLE("Memory Comparison", 2, ImGuiTableFlags_Resizable);
SETUP_COLUMN("Source")
SETUP_COLUMN("Dest")
NEXT_COLUMN()
Text("%s", rom()->filename().data());
mem_edit.DrawContents((void *)&(*rom()), rom()->size());
NEXT_COLUMN()
if (show_compare_rom) {
comp_edit.SetComparisonData((void *)&(*rom()));
ImGui::BeginGroup();
ImGui::BeginChild("Comparison ROM");
Text("%s", comparison_rom.filename().data());
comp_edit.DrawContents((void *)&(comparison_rom), comparison_rom.size());
ImGui::EndChild();
ImGui::EndGroup();
}
END_TABLE()
ImGui::End();
}
};
} // namespace editor
} // namespace app
} // namespace yaze
#endif // YAZE_APP_EDITOR_CODE_MEMORY_EDITOR_H

View File

@@ -618,44 +618,7 @@ void MasterEditor::DrawViewMenu() {
} }
if (show_memory_editor) { if (show_memory_editor) {
static MemoryEditor mem_edit; memory_editor_.Update(show_memory_editor);
static MemoryEditor comp_edit;
static bool show_compare_rom = false;
static Rom comparison_rom;
ImGui::Begin("Hex Editor", &show_memory_editor);
if (ImGui::Button("Compare Rom")) {
auto file_name = FileDialogWrapper::ShowOpenFileDialog();
PRINT_IF_ERROR(comparison_rom.LoadFromFile(file_name));
show_compare_rom = true;
}
static uint64_t convert_address = 0;
gui::InputHex("SNES to PC", (int*)&convert_address, 6, 200.f);
SameLine();
Text("%x", core::SnesToPc(convert_address));
// mem_edit.DrawWindow("Memory Editor", (void*)&(*rom()), rom()->size());
BEGIN_TABLE("Memory Comparison", 2, ImGuiTableFlags_Resizable);
SETUP_COLUMN("Source")
SETUP_COLUMN("Dest")
NEXT_COLUMN()
Text("%s", rom()->filename().data());
mem_edit.DrawContents((void*)&(*rom()), rom()->size());
NEXT_COLUMN()
if (show_compare_rom) {
comp_edit.SetComparisonData((void*)&(*rom()));
ImGui::BeginGroup();
ImGui::BeginChild("Comparison ROM");
Text("%s", comparison_rom.filename().data());
comp_edit.DrawContents((void*)&(comparison_rom), comparison_rom.size());
ImGui::EndChild();
ImGui::EndGroup();
}
END_TABLE()
ImGui::End();
} }
if (show_imgui_demo) { if (show_imgui_demo) {
@@ -675,7 +638,7 @@ void MasterEditor::DrawViewMenu() {
if (BeginMenu("View")) { if (BeginMenu("View")) {
MenuItem("Emulator", nullptr, &show_emulator); MenuItem("Emulator", nullptr, &show_emulator);
Separator(); Separator();
MenuItem("Hex Editor", nullptr, &show_memory_editor); MenuItem("Memory Editor", nullptr, &show_memory_editor);
MenuItem("Assembly Editor", nullptr, &show_asm_editor); MenuItem("Assembly Editor", nullptr, &show_asm_editor);
MenuItem("Palette Editor", nullptr, &show_palette_editor); MenuItem("Palette Editor", nullptr, &show_palette_editor);
Separator(); Separator();

View File

@@ -14,6 +14,7 @@
#include "app/core/constants.h" #include "app/core/constants.h"
#include "app/core/project.h" #include "app/core/project.h"
#include "app/editor/code/assembly_editor.h" #include "app/editor/code/assembly_editor.h"
#include "app/editor/code/memory_editor.h"
#include "app/editor/context/gfx_context.h" #include "app/editor/context/gfx_context.h"
#include "app/editor/dungeon_editor.h" #include "app/editor/dungeon_editor.h"
#include "app/editor/graphics/graphics_editor.h" #include "app/editor/graphics/graphics_editor.h"
@@ -118,6 +119,7 @@ class MasterEditor : public SharedRom,
PaletteEditor palette_editor_; PaletteEditor palette_editor_;
ScreenEditor screen_editor_; ScreenEditor screen_editor_;
SpriteEditor sprite_editor_; SpriteEditor sprite_editor_;
MemoryEditorWithDiffChecker memory_editor_;
ImVector<int> active_tabs_; ImVector<int> active_tabs_;
std::vector<Editor*> active_editors_; std::vector<Editor*> active_editors_;