18
18
***************************************************************************/
19
19
20
20
#include " gui/widgets/breakpoints.h"
21
+
21
22
#include " core/psxmem.h"
22
23
#include " core/r3000a.h"
23
24
#include " fmt/format.h"
24
25
#include " imgui.h"
26
+ #include " mips/common/util/decoder.hh"
25
27
#include " support/imgui-helpers.h"
26
28
27
- // Note: We ignore SWL and SWR
28
- static uint32_t getValueAboutToWrite () {
29
- uint32_t opcode = PCSX::g_emulator->m_mem ->read32 (PCSX::g_emulator->m_cpu ->m_regs .pc );
30
- uint32_t storeType = opcode >> 26 ;
31
- uint32_t reg = ((opcode >> 16 ) & 0x1F );
32
- uint32_t mask = (storeType == 0x28 ) ? 0xff : (storeType == 0x29 ) ? 0xffff : 0xffffffff ;
33
- return PCSX::g_emulator->m_cpu ->m_regs .GPR .r [reg] & mask;
29
+ static uint32_t getValueAboutToWrite (PCSX::R3000Acpu& cpu) {
30
+ Mips::Decoder::Instruction instr (cpu.m_regs .code );
31
+ if (instr.isStore ()) {
32
+ return instr.getValueToStore (cpu.m_regs .GPR , cpu.m_regs .CP2D .r );
33
+ }
34
+ return 0 ;
34
35
}
35
36
36
37
static const char * getBreakpointConditionName (PCSX::Debug::BreakpointCondition condition) {
@@ -50,43 +51,33 @@ static const char* getBreakpointConditionName(PCSX::Debug::BreakpointCondition c
50
51
}
51
52
52
53
static uint32_t getMemoryValue (uint32_t addr, int width, bool isSigned) {
54
+ PCSX::IO<PCSX::File> mem = PCSX::g_emulator->m_mem ->getMemoryAsFile ();
53
55
54
- union MemVal {
55
- uint32_t uVal;
56
- int32_t sVal ;
57
- };
58
-
59
- MemVal final = {};
60
56
switch (width) {
61
57
case 1 : {
62
- uint8_t val = PCSX::g_emulator->m_mem ->read8 (addr);
63
58
if (isSigned) {
64
- final .uVal = val << 24 ;
65
- final .sVal = final .sVal >> 24 ;
59
+ return mem->readAt <int8_t >(addr);
66
60
} else {
67
- final . uVal = val ;
61
+ return mem-> readAt < uint8_t >(addr) ;
68
62
}
69
- }
70
- break ;
63
+ } break ;
71
64
case 2 : {
72
- uint16_t val = PCSX::g_emulator->m_mem ->read16 (addr);
73
65
if (isSigned) {
74
- final .uVal = val << 16 ;
75
- final .sVal = final .sVal >> 16 ;
66
+ return mem->readAt <int16_t >(addr);
76
67
} else {
77
- final . uVal = val ;
68
+ return mem-> readAt < uint16_t >(addr) ;
78
69
}
79
- }
80
- break ;
81
- case 4 :
82
- final .uVal = PCSX::g_emulator->m_mem ->read32 (addr);
70
+ } break ;
71
+ case 4 : {
72
+ return mem->readAt <uint32_t >(addr);
83
73
break ;
74
+ }
84
75
}
85
- return final . uVal ;
76
+ return 0 ;
86
77
}
87
78
88
- static ImVec4 s_normalColor = ImColor(0xff , 0xff , 0xff );
89
- static ImVec4 s_hitColor = ImColor(0xff , 0x00 , 0x00 );
79
+ static const ImVec4 s_normalColor = ImColor(0xff , 0xff , 0xff );
80
+ static const ImVec4 s_hitColor = ImColor(0xff , 0x00 , 0x00 );
90
81
91
82
void PCSX::Widgets::Breakpoints::draw (const char * title) {
92
83
ImGui::SetNextWindowPos (ImVec2 (520 , 30 ), ImGuiCond_FirstUseEver);
@@ -99,6 +90,7 @@ void PCSX::Widgets::Breakpoints::draw(const char* title) {
99
90
100
91
const Debug::Breakpoint* toErase = nullptr ;
101
92
auto & tree = debugger->getTree ();
93
+ auto & cpu = PCSX::g_emulator->m_cpu ;
102
94
103
95
int counter = 0 ;
104
96
if (!tree.empty ()) {
@@ -114,7 +106,7 @@ void PCSX::Widgets::Breakpoints::draw(const char* title) {
114
106
ImGui::TableSetupColumn (" Label" );
115
107
ImGui::TableHeadersRow ();
116
108
117
- const uint32_t pc = PCSX::g_emulator-> m_cpu ->m_regs .pc ;
109
+ const uint32_t pc = cpu ->m_regs .pc ;
118
110
119
111
int row = 0 ;
120
112
for (auto bp = tree.begin (); bp != tree.end (); bp++, row++) {
@@ -161,7 +153,8 @@ void PCSX::Widgets::Breakpoints::draw(const char* title) {
161
153
fmt::format (" {} {}" , Debug::s_breakpoint_type_names[(unsigned )bp->type ()](), bp->source ());
162
154
} else {
163
155
textStr = fmt::format (" {}:{} {} {} {}" , Debug::s_breakpoint_type_names[(unsigned )bp->type ()](),
164
- bp->width (), bp->source (), getBreakpointConditionName (bp->condition ()), bp->conditionData ());
156
+ bp->width (), bp->source (), getBreakpointConditionName (bp->condition ()),
157
+ bp->conditionData ());
165
158
}
166
159
ImGui::TextUnformatted (textStr.c_str ());
167
160
@@ -186,7 +179,7 @@ void PCSX::Widgets::Breakpoints::draw(const char* title) {
186
179
187
180
if (ImGui::BeginPopupContextItem (" BreakpointPopup" )) {
188
181
ImGui::InputText (_ (" Address" ), m_bpAddressString, sizeof (m_bpAddressString),
189
- ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_AutoSelectAll);
182
+ ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_AutoSelectAll);
190
183
if (ImGui::BeginCombo (_ (" Type" ), Debug::s_breakpoint_type_names[m_breakpointType]())) {
191
184
for (int i = 0 ; i < 3 ; i++) {
192
185
if (ImGui::Selectable (Debug::s_breakpoint_type_names[i](), m_breakpointType == i)) {
@@ -217,7 +210,7 @@ void PCSX::Widgets::Breakpoints::draw(const char* title) {
217
210
static int breakConditionImguiValue = 0 ;
218
211
static int conditionVal = 0 ;
219
212
220
- Debug::BreakpointCondition breakCondition = Debug::BreakpointCondition::Always;
213
+ Debug::BreakpointCondition breakCondition = Debug::BreakpointCondition::Always;
221
214
Debug::BreakpointType type = (Debug::BreakpointType)m_breakpointType;
222
215
if (type != Debug::BreakpointType::Exec) {
223
216
ImGui::Combo (_ (" Break Condition" ), &breakConditionImguiValue, _ (" Always\0 Change\0 Greater\0 Less\0 Equal\0 " ));
@@ -252,17 +245,16 @@ void PCSX::Widgets::Breakpoints::draw(const char* title) {
252
245
253
246
Debug::BreakpointInvoker invoker = [](Debug::Breakpoint* self, uint32_t address, unsigned width,
254
247
const char * cause) {
255
-
256
- switch (self->type ())
257
- {
248
+ auto & cpu = PCSX::g_emulator->m_cpu ;
249
+ switch (self->type ()) {
258
250
case Debug::BreakpointType::Exec:
259
251
g_system->pause ();
260
252
break ;
261
253
262
254
case Debug::BreakpointType::Write: {
263
255
// We can't rely on data in memory since the bp triggers before the instruction executes
264
256
// So we grab the value to be written directly from the instruction itself
265
- uint32_t curVal = getValueAboutToWrite ();
257
+ uint32_t curVal = getValueAboutToWrite (*cpu );
266
258
bool doBreak = true ;
267
259
switch (self->condition ()) {
268
260
default :
@@ -342,9 +334,9 @@ void PCSX::Widgets::Breakpoints::draw(const char* title) {
342
334
break ;
343
335
}
344
336
345
- Debug::Breakpoint* bp = debugger->addBreakpoint (breakpointAddress, bpType,
346
- (bpType == Debug::BreakpointType::Exec) ? 4 : actualWidth, _ (" GUI" ),
347
- m_bpLabelString, invoker);
337
+ Debug::Breakpoint* bp = debugger->addBreakpoint (
338
+ breakpointAddress, bpType, (bpType == Debug::BreakpointType::Exec) ? 4 : actualWidth, _ (" GUI" ),
339
+ m_bpLabelString, invoker);
348
340
349
341
bp->setCondition (breakCondition);
350
342
bp->setConditionData (conditionData);
0 commit comments