Skip to content

Commit 0ee7e7f

Browse files
committed
show previous symbol at top of asm view
1 parent c30393d commit 0ee7e7f

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/gui/widgets/assembly.cc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,10 @@ settings, otherwise debugging features may not work.)");
598598
bool openAssembler = false;
599599
bool openSymbolAdder = false;
600600

601+
float lineHeight = ImGui::GetTextLineHeight();
602+
float previousSymbolY = topleft.y;
603+
std::optional<std::string> previousSymbol;
604+
601605
while (clipper.Step()) {
602606
bool skipNext = false;
603607
bool delaySlotNext = false;
@@ -681,6 +685,17 @@ settings, otherwise debugging features may not work.)");
681685
ImGui::PushStyleColor(ImGuiCol_Text, s_labelColor);
682686
ImGui::Text("%s:", symbols.begin()->c_str());
683687
ImGui::PopStyleColor();
688+
} else {
689+
// if the first visible line is not a symbol, show the previous symbol
690+
float y = ImGui::GetCursorScreenPos().y;
691+
if (y + lineHeight >= topleft.y && y <= topleft.y + lineHeight) {
692+
previousSymbol = findPreviousSymbol(dispAddr);
693+
// if the second line is a symbol, push the previous symbol display up
694+
auto secondLineSymbol = findSymbol(dispAddr + 4);
695+
if (secondLineSymbol.size() != 0 && y < previousSymbolY) {
696+
previousSymbolY = y;
697+
}
698+
}
684699
}
685700

686701
for (int i = 0; i < m_numColumns * ImGui::GetWindowDpiScale(); i++) {
@@ -938,6 +953,13 @@ settings, otherwise debugging features may not work.)");
938953
}
939954
}
940955
drawList->ChannelsMerge();
956+
if (previousSymbol) {
957+
ImVec2 pos(ImGui::GetCursorScreenPos().x, previousSymbolY);
958+
ImVec2 posEnd(pos.x + glyphWidth * 64, pos.y + ImGui::GetTextLineHeight());
959+
drawList->AddRectFilled(pos, posEnd, ImGui::GetColorU32(ImGuiCol_WindowBg));
960+
std::string text = "^ " + previousSymbol.value() + " ^";
961+
drawList->AddText(pos, ImGui::GetColorU32(s_labelColor), text.data(), text.data() + text.size());
962+
}
941963
ImGui::EndChild();
942964
ImGui::PopFont();
943965
if (m_jumpToPC.has_value()) {
@@ -1127,6 +1149,19 @@ std::list<std::string> PCSX::Widgets::Assembly::findSymbol(uint32_t addr) {
11271149
return ret;
11281150
}
11291151

1152+
std::optional<std::string> PCSX::Widgets::Assembly::findPreviousSymbol(uint32_t addr) {
1153+
std::optional<std::string> ret;
1154+
for (auto& symbol : g_emulator->m_cpu->m_symbols) {
1155+
if (symbol.first >= addr) {
1156+
break;
1157+
}
1158+
if (symbol.first >= m_ramBase) {
1159+
ret = symbol.second;
1160+
}
1161+
}
1162+
return ret;
1163+
}
1164+
11301165
void PCSX::Widgets::Assembly::rebuildSymbolsCaches() {
11311166
auto& cpu = g_emulator->m_cpu;
11321167
m_symbolsCache.clear();

src/gui/widgets/assembly.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class Assembly : private Disasm {
111111
};
112112

113113
std::list<std::string> findSymbol(uint32_t addr);
114+
std::optional<std::string> findPreviousSymbol(uint32_t addr);
114115
std::map<std::string, uint32_t> m_symbolsCache;
115116
std::map<uint32_t, std::string> m_elfSymbolsCache;
116117
bool m_symbolsCachesValid = false;

0 commit comments

Comments
 (0)