Skip to content

Commit 437f208

Browse files
authored
Merge pull request #1645 from Giragast/goto_in_more_memory_editors
Open Assembly widget addresses in different Memory Editors
2 parents 6ab75e6 + 18a326e commit 437f208

File tree

4 files changed

+51
-10
lines changed

4 files changed

+51
-10
lines changed

src/core/system.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ struct JumpToPC {
8888
struct JumpToMemory {
8989
uint32_t address;
9090
unsigned size;
91+
unsigned editorNum;
92+
bool forceShowEditor;
9193
};
9294
struct SelectClut {
9395
unsigned x, y;

src/gui/gui.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,8 @@ void PCSX::GUI::init(std::function<void()> applyArguments) {
740740
const uint32_t base = (event.address >> 20) & 0xff8;
741741
const uint32_t real = event.address & 0x7fffff;
742742
const uint32_t size = event.size;
743+
const uint32_t editorNum = event.editorNum;
744+
const bool forceShowEditor = event.forceShowEditor;
743745
auto changeDataType = [](MemoryEditor* editor, int size) {
744746
bool isSigned = false;
745747
switch (editor->PreviewDataType) {
@@ -764,11 +766,13 @@ void PCSX::GUI::init(std::function<void()> applyArguments) {
764766
};
765767
if ((base == 0x000) || (base == 0x800) || (base == 0xa00)) {
766768
if (real < 0x00800000) {
767-
m_mainMemEditors[0].editor.GotoAddrAndHighlight(real, real + size);
768-
changeDataType(&m_mainMemEditors[0].editor, size);
769+
if (forceShowEditor) m_mainMemEditors[editorNum].m_show = true;
770+
m_mainMemEditors[editorNum].editor.GotoAddrAndHighlight(real, real + size);
771+
changeDataType(&m_mainMemEditors[editorNum].editor, size);
769772
}
770773
} else if (base == 0x1f8) {
771774
if (real >= 0x1000 && real < 0x3000) {
775+
if (forceShowEditor) m_hwrEditor.m_show = true;
772776
m_hwrEditor.editor.GotoAddrAndHighlight(real - 0x1000, real - 0x1000 + size);
773777
changeDataType(&m_hwrEditor.editor, size);
774778
}

src/gui/widgets/assembly.cc

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,32 @@ const uint8_t* PCSX::Widgets::Assembly::ptr(uint32_t addr) {
325325
return dummy;
326326
}
327327
}
328-
void PCSX::Widgets::Assembly::jumpToMemory(uint32_t addr, unsigned size) {
329-
g_system->m_eventBus->signal(PCSX::Events::GUI::JumpToMemory{addr, size});
328+
void PCSX::Widgets::Assembly::jumpToMemory(uint32_t addr, unsigned size, unsigned editorIndex /* = 0*/,
329+
bool forceShowEditor /* = false*/) {
330+
g_system->m_eventBus->signal(PCSX::Events::GUI::JumpToMemory{addr, size, editorIndex, forceShowEditor});
331+
}
332+
void PCSX::Widgets::Assembly::addMemoryEditorContext(uint32_t addr, int size) {
333+
if (ImGui::BeginPopupContextItem()) {
334+
if (ImGui::MenuItem(_("Go to in Memory Editor #1 (Default Click)"))) jumpToMemory(addr, size, 0, true);
335+
if (ImGui::MenuItem(_("Go to in Memory Editor #2 (Shift+Click)"))) jumpToMemory(addr, size, 1, true);
336+
if (ImGui::MenuItem(_("Go to in Memory Editor #3 (Ctrl+Click)"))) jumpToMemory(addr, size, 2, true);
337+
std::string itemLabel;
338+
for (unsigned i = 3; i < 8; ++i) {
339+
itemLabel = fmt::format(f_("Go to in Memory Editor #{}"), i + 1);
340+
if (ImGui::MenuItem(itemLabel.c_str())) jumpToMemory(addr, size, i, true);
341+
}
342+
ImGui::EndPopup();
343+
}
344+
}
345+
void PCSX::Widgets::Assembly::addMemoryEditorSubMenu(uint32_t addr, int size) {
346+
if (ImGui::BeginMenu(_("Go to in Memory Editor..."))) {
347+
std::string itemLabel;
348+
for (unsigned i = 0; i < 8; ++i) {
349+
itemLabel = fmt::format("#{}", i + 1);
350+
if (ImGui::MenuItem(itemLabel.c_str())) jumpToMemory(addr, size, i, true);
351+
}
352+
ImGui::EndMenu();
353+
}
330354
}
331355

332356
void PCSX::Widgets::Assembly::OfB(int16_t offset, uint8_t reg, int size) {
@@ -344,11 +368,15 @@ void PCSX::Widgets::Assembly::OfB(int16_t offset, uint8_t reg, int size) {
344368
auto symbols = findSymbol(addr);
345369
if (symbols.size() != 0) longLabel = *symbols.begin() + " ; ";
346370

371+
const auto& io = ImGui::GetIO();
372+
unsigned targetEditorIndex = io.KeyShift ? 1 : (io.KeyCtrl ? 2 : 0);
373+
347374
ImGui::TextUnformatted(" ");
348375
ImGui::SameLine(0.0f, 0.0f);
349376
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
350-
if (ImGui::Button(label)) jumpToMemory(addr, size);
377+
if (ImGui::Button(label)) jumpToMemory(addr, size, targetEditorIndex, false);
351378
ImGui::PopStyleVar();
379+
addMemoryEditorContext(addr, size);
352380
if (ImGui::IsItemHovered()) {
353381
ImGui::BeginTooltip();
354382
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
@@ -363,6 +391,7 @@ void PCSX::Widgets::Assembly::OfB(int16_t offset, uint8_t reg, int size) {
363391
ImGui::Text("%s[%8.8x] = %8.8x", longLabel.c_str(), addr, mem32(addr));
364392
break;
365393
}
394+
ImGui::Text(_("Go to in Memory Editor #%d"), targetEditorIndex + 1);
366395
ImGui::PopTextWrapPos();
367396
ImGui::EndTooltip();
368397
}
@@ -399,11 +428,16 @@ void PCSX::Widgets::Assembly::Offset(uint32_t addr, int size) {
399428
std::string longLabel = label;
400429
auto symbols = findSymbol(addr);
401430
if (symbols.size() != 0) longLabel = *symbols.begin() + " ;" + label;
431+
432+
const auto& io = ImGui::GetIO();
433+
unsigned targetEditorIndex = io.KeyShift ? 1 : (io.KeyCtrl ? 2 : 0);
434+
402435
ImGui::TextUnformatted(" ");
403436
sameLine();
404437
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
405-
if (ImGui::Button(longLabel.c_str())) jumpToMemory(addr, size);
438+
if (ImGui::Button(longLabel.c_str())) jumpToMemory(addr, size, targetEditorIndex, false);
406439
ImGui::PopStyleVar();
440+
addMemoryEditorContext(addr, size);
407441
if (ImGui::IsItemHovered()) {
408442
ImGui::BeginTooltip();
409443
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
@@ -418,6 +452,7 @@ void PCSX::Widgets::Assembly::Offset(uint32_t addr, int size) {
418452
ImGui::Text("[%8.8x] = %8.8x", addr, mem32(addr));
419453
break;
420454
}
455+
ImGui::Text(_("Go to in Memory Editor #%u"), targetEditorIndex + 1);
421456
ImGui::PopTextWrapPos();
422457
ImGui::EndTooltip();
423458
}
@@ -729,9 +764,7 @@ settings, otherwise debugging features may not work.)");
729764
std::snprintf(fmtAddr, sizeof(fmtAddr), "%8.8x", dispAddr);
730765
ImGui::SetClipboardText(fmtAddr);
731766
}
732-
if (ImGui::MenuItem(_("Go to in Memory Editor"))) {
733-
jumpToMemory(dispAddr, 4);
734-
}
767+
addMemoryEditorSubMenu(addr, 4);
735768
if (ImGui::MenuItem(_("Run to Cursor"), nullptr, false, !PCSX::g_system->running())) {
736769
g_emulator->m_debug->addBreakpoint(
737770
dispAddr, Debug::BreakpointType::Exec, 4, _("GUI"),

src/gui/widgets/assembly.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Assembly : private Disasm {
6767
void sameLine();
6868
void comma();
6969
const uint8_t* ptr(uint32_t addr);
70-
void jumpToMemory(uint32_t addr, unsigned size);
70+
void jumpToMemory(uint32_t addr, unsigned size, unsigned editorIndex = 0, bool forceShowEditor = false);
7171
uint8_t mem8(uint32_t addr);
7272
uint16_t mem16(uint32_t addr);
7373
uint32_t mem32(uint32_t addr);
@@ -111,6 +111,8 @@ class Assembly : private Disasm {
111111
bool m_symbolsCachesValid = false;
112112

113113
void rebuildSymbolsCaches();
114+
void addMemoryEditorContext(uint32_t addr, int size);
115+
void addMemoryEditorSubMenu(uint32_t addr, int size);
114116

115117
bool m_showSymbols = false;
116118
std::string m_symbolFilter;

0 commit comments

Comments
 (0)