Skip to content

Commit 085afc0

Browse files
committed
fix input scalar in typed debugger window
1 parent 7730d21 commit 085afc0

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

src/gui/widgets/typed_debugger.cc

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,7 @@ void PCSX::Widgets::TypedDebugger::displayNode(WatchTreeNode* node, const uint32
490490
printValue(nodeType, node->size, value);
491491
ImGui::TableNextColumn(); // New value.
492492
memFile->wSeek(startAddress, SEEK_SET);
493-
displayNewValueInput(nodeType, node->size, value, memFile);
494-
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyle().Colors[ImGuiCol_TextDisabled]);
495-
ImGui::TextUnformatted("--");
496-
ImGui::PopStyleColor();
493+
displayNewValueInput(nodeType, node->size, value, memFile, currentAddress);
497494
ImGui::TableNextColumn(); // Breakpoints.
498495
if (watchView) {
499496
displayBreakpointOptions(node, currentAddress);
@@ -551,56 +548,61 @@ void PCSX::Widgets::TypedDebugger::printValue(const char* type, size_t type_size
551548
// Make an input widget for the value at the given address of the given type. If
552549
// type is not a known primitive, it'll try to allow editing of the value
553550
// anyway.
554-
void PCSX::Widgets::TypedDebugger::displayNewValueInput(const char* type, size_t type_size, Slice value,
555-
IO<File> memFile) {
556-
static char s[64];
551+
void PCSX::Widgets::TypedDebugger::displayNewValueInput(const char* type, size_t type_size, const Slice& value,
552+
IO<File>& memFile, uint32_t address) {
557553
static const int8_t step = 1;
558554
static const int8_t stepFast = 100;
559555
const auto signedFormat = m_hex ? "%x" : "%d";
560556
const auto unsignedFormat = m_hex ? "%x" : "%u";
561557
const auto inputFlags = m_hex ? ImGuiInputTextFlags_CharsHexadecimal : ImGuiInputTextFlags_CharsDecimal;
562-
const uint32_t address = memFile->rTell();
563558

564559
switch (type_size) {
565560
case 1:
566561
if (equals(type, "char")) {
567-
if (ImGui::InputScalar(fmt::format(f_("New value##{}"), address).c_str(), ImGuiDataType_S8, &m_newValue,
568-
&step, &stepFast, signedFormat, inputFlags)) {
569-
memFile->write<int8_t>(m_newValue);
562+
m_newValues[address] = *value.data<int8_t>();
563+
if (ImGui::InputScalar(fmt::format(f_("##{}"), address).c_str(), ImGuiDataType_S8,
564+
&m_newValues[address], &step, &stepFast, signedFormat, inputFlags)) {
565+
memFile->write<int8_t>(m_newValues[address]);
570566
}
571567
} else {
572568
// We have a uchar or something of size 1.
573-
if (ImGui::InputScalar(fmt::format(f_("New value##{}"), address).c_str(), ImGuiDataType_U8, &m_newValue,
574-
&step, &stepFast, unsignedFormat, inputFlags)) {
575-
memFile->write<uint8_t>(m_newValue);
569+
570+
m_newValues[address] = *value.data<uint8_t>();
571+
if (ImGui::InputScalar(fmt::format(f_("##{}"), address).c_str(), ImGuiDataType_U8,
572+
&m_newValues[address], &step, &stepFast, signedFormat, inputFlags)) {
573+
memFile->write<uint8_t>(m_newValues[address]);
576574
}
577575
}
578576
break;
579577
case 2:
580578
if (equals(type, "short")) {
581-
if (ImGui::InputScalar(fmt::format(f_("New value##{}"), address).c_str(), ImGuiDataType_S16,
582-
&m_newValue, &step, &stepFast, signedFormat, inputFlags)) {
583-
memFile->write<int16_t>(m_newValue);
579+
m_newValues[address] = *value.data<int16_t>();
580+
if (ImGui::InputScalar(fmt::format(f_("##{}"), address).c_str(), ImGuiDataType_S16,
581+
&m_newValues[address], &step, &stepFast, signedFormat, inputFlags)) {
582+
memFile->write<int16_t>(m_newValues[address]);
584583
}
585584
} else {
586585
// We have a ushort or something of size 2.
587-
if (ImGui::InputScalar(fmt::format(f_("New value##{}"), address).c_str(), ImGuiDataType_U16,
588-
&m_newValue, &step, &stepFast, unsignedFormat, inputFlags)) {
589-
memFile->write<uint16_t>(m_newValue);
586+
m_newValues[address] = *value.data<uint16_t>();
587+
if (ImGui::InputScalar(fmt::format(f_("##{}"), address).c_str(), ImGuiDataType_U16,
588+
&m_newValues[address], &step, &stepFast, unsignedFormat, inputFlags)) {
589+
memFile->write<uint16_t>(m_newValues[address]);
590590
}
591591
}
592592
break;
593593
case 4:
594594
if (equals(type, "int") || equals(type, "long")) {
595-
if (ImGui::InputScalar(fmt::format(f_("New value##{}"), address).c_str(), ImGuiDataType_S32,
596-
&m_newValue, &step, &stepFast, signedFormat, inputFlags)) {
597-
memFile->write<int32_t>(m_newValue);
595+
m_newValues[address] = *value.data<int32_t>();
596+
if (ImGui::InputScalar(fmt::format(f_("##{}"), address).c_str(), ImGuiDataType_S32,
597+
&m_newValues[address], &step, &stepFast, signedFormat, inputFlags)) {
598+
memFile->write<int32_t>(m_newValues[address]);
598599
}
599600
} else {
600601
// We have uint or something of size 4.
601-
if (ImGui::InputScalar(fmt::format(f_("New value##{}"), address).c_str(), ImGuiDataType_U32,
602-
&m_newValue, &step, &stepFast, unsignedFormat, inputFlags)) {
603-
memFile->write<uint32_t>(m_newValue);
602+
m_newValues[address] = *value.data<uint32_t>();
603+
if (ImGui::InputScalar(fmt::format(f_("##{}"), address).c_str(), ImGuiDataType_U32,
604+
&m_newValues[address], &step, &stepFast, unsignedFormat, inputFlags)) {
605+
memFile->write<uint32_t>(m_newValues[address]);
604606
}
605607
}
606608
break;

src/gui/widgets/typed_debugger.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class TypedDebugger {
119119
std::vector<PCSX::Debug::Breakpoint*> m_watchBreakpoints;
120120
std::unordered_map<uint32_t, std::array<uint8_t, 4>> m_disabledInstructions;
121121
bool m_hex = false;
122-
uint32_t m_newValue = 0;
122+
std::unordered_map<uint32_t, uint64_t> m_newValues;
123123

124124
/**
125125
* Functions.
@@ -156,7 +156,7 @@ class TypedDebugger {
156156
uint32_t extraImGuiId = 0);
157157
void printValue(const char* type, size_t type_size, void* value);
158158
void printValue(const char* type, size_t type_size, Slice value);
159-
void displayNewValueInput(const char* type, size_t size_type, Slice value, IO<File> memFile);
159+
void displayNewValueInput(const char* type, size_t size_type, const Slice& value, IO<File>& memFile, uint32_t address);
160160
void displayBreakpointOptions(WatchTreeNode* node, const uint32_t address);
161161

162162
/**

0 commit comments

Comments
 (0)