Skip to content

Commit e2096cd

Browse files
committed
Fixing the last few details.
1 parent 602bda9 commit e2096cd

File tree

7 files changed

+647
-63
lines changed

7 files changed

+647
-63
lines changed

src/core/r3000a.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "core/psxmem.h"
3535
#include "support/file.h"
3636
#include "support/hashtable.h"
37+
#include "mips/common/util/mips.hh"
3738

3839
#if defined(__i386__) || defined(_M_IX86)
3940
#define DYNAREC_NONE // Hahano
@@ -89,20 +90,7 @@ typedef union {
8990
int32_t sd;
9091
} PAIR;
9192

92-
typedef union {
93-
struct {
94-
uint32_t r0, at, v0, v1, a0, a1, a2, a3;
95-
uint32_t t0, t1, t2, t3, t4, t5, t6, t7;
96-
uint32_t s0, s1, s2, s3, s4, s5, s6, s7;
97-
uint32_t t8, t9, k0, k1, gp, sp, s8, ra;
98-
uint32_t lo, hi;
99-
} n;
100-
uint32_t r[34]; /* Lo, Hi in r[32] and r[33] */
101-
PAIR p[34];
102-
} psxGPRRegs;
103-
104-
// Make sure no packing is inserted anywhere
105-
static_assert(sizeof(psxGPRRegs) == 34 * sizeof(uint32_t));
93+
using psxGPRRegs = Mips::GPRRegs;
10694

10795
typedef union {
10896
struct {

src/gui/widgets/breakpoints.cc

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@
1818
***************************************************************************/
1919

2020
#include "gui/widgets/breakpoints.h"
21+
2122
#include "core/psxmem.h"
2223
#include "core/r3000a.h"
2324
#include "fmt/format.h"
2425
#include "imgui.h"
26+
#include "mips/common/util/decoder.hh"
2527
#include "support/imgui-helpers.h"
2628

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;
3435
}
3536

3637
static const char* getBreakpointConditionName(PCSX::Debug::BreakpointCondition condition) {
@@ -50,43 +51,33 @@ static const char* getBreakpointConditionName(PCSX::Debug::BreakpointCondition c
5051
}
5152

5253
static uint32_t getMemoryValue(uint32_t addr, int width, bool isSigned) {
54+
PCSX::IO<PCSX::File> mem = PCSX::g_emulator->m_mem->getMemoryAsFile();
5355

54-
union MemVal {
55-
uint32_t uVal;
56-
int32_t sVal;
57-
};
58-
59-
MemVal final = {};
6056
switch (width) {
6157
case 1: {
62-
uint8_t val = PCSX::g_emulator->m_mem->read8(addr);
6358
if (isSigned) {
64-
final.uVal = val << 24;
65-
final.sVal = final.sVal >> 24;
59+
return mem->readAt<int8_t>(addr);
6660
} else {
67-
final.uVal = val;
61+
return mem->readAt<uint8_t>(addr);
6862
}
69-
}
70-
break;
63+
} break;
7164
case 2: {
72-
uint16_t val = PCSX::g_emulator->m_mem->read16(addr);
7365
if (isSigned) {
74-
final.uVal = val << 16;
75-
final.sVal = final.sVal >> 16;
66+
return mem->readAt<int16_t>(addr);
7667
} else {
77-
final.uVal = val;
68+
return mem->readAt<uint16_t>(addr);
7869
}
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);
8373
break;
74+
}
8475
}
85-
return final.uVal;
76+
return 0;
8677
}
8778

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);
9081

9182
void PCSX::Widgets::Breakpoints::draw(const char* title) {
9283
ImGui::SetNextWindowPos(ImVec2(520, 30), ImGuiCond_FirstUseEver);
@@ -99,6 +90,7 @@ void PCSX::Widgets::Breakpoints::draw(const char* title) {
9990

10091
const Debug::Breakpoint* toErase = nullptr;
10192
auto& tree = debugger->getTree();
93+
auto& cpu = PCSX::g_emulator->m_cpu;
10294

10395
int counter = 0;
10496
if (!tree.empty()) {
@@ -114,7 +106,7 @@ void PCSX::Widgets::Breakpoints::draw(const char* title) {
114106
ImGui::TableSetupColumn("Label");
115107
ImGui::TableHeadersRow();
116108

117-
const uint32_t pc = PCSX::g_emulator->m_cpu->m_regs.pc;
109+
const uint32_t pc = cpu->m_regs.pc;
118110

119111
int row = 0;
120112
for (auto bp = tree.begin(); bp != tree.end(); bp++, row++) {
@@ -161,7 +153,8 @@ void PCSX::Widgets::Breakpoints::draw(const char* title) {
161153
fmt::format("{} {}", Debug::s_breakpoint_type_names[(unsigned)bp->type()](), bp->source());
162154
} else {
163155
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());
165158
}
166159
ImGui::TextUnformatted(textStr.c_str());
167160

@@ -186,7 +179,7 @@ void PCSX::Widgets::Breakpoints::draw(const char* title) {
186179

187180
if (ImGui::BeginPopupContextItem("BreakpointPopup")) {
188181
ImGui::InputText(_("Address"), m_bpAddressString, sizeof(m_bpAddressString),
189-
ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_AutoSelectAll);
182+
ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_AutoSelectAll);
190183
if (ImGui::BeginCombo(_("Type"), Debug::s_breakpoint_type_names[m_breakpointType]())) {
191184
for (int i = 0; i < 3; i++) {
192185
if (ImGui::Selectable(Debug::s_breakpoint_type_names[i](), m_breakpointType == i)) {
@@ -217,7 +210,7 @@ void PCSX::Widgets::Breakpoints::draw(const char* title) {
217210
static int breakConditionImguiValue = 0;
218211
static int conditionVal = 0;
219212

220-
Debug::BreakpointCondition breakCondition = Debug::BreakpointCondition::Always;
213+
Debug::BreakpointCondition breakCondition = Debug::BreakpointCondition::Always;
221214
Debug::BreakpointType type = (Debug::BreakpointType)m_breakpointType;
222215
if (type != Debug::BreakpointType::Exec) {
223216
ImGui::Combo(_("Break Condition"), &breakConditionImguiValue, _("Always\0Change\0Greater\0Less\0Equal\0"));
@@ -252,17 +245,16 @@ void PCSX::Widgets::Breakpoints::draw(const char* title) {
252245

253246
Debug::BreakpointInvoker invoker = [](Debug::Breakpoint* self, uint32_t address, unsigned width,
254247
const char* cause) {
255-
256-
switch (self->type())
257-
{
248+
auto& cpu = PCSX::g_emulator->m_cpu;
249+
switch (self->type()) {
258250
case Debug::BreakpointType::Exec:
259251
g_system->pause();
260252
break;
261253

262254
case Debug::BreakpointType::Write: {
263255
// We can't rely on data in memory since the bp triggers before the instruction executes
264256
// So we grab the value to be written directly from the instruction itself
265-
uint32_t curVal = getValueAboutToWrite();
257+
uint32_t curVal = getValueAboutToWrite(*cpu);
266258
bool doBreak = true;
267259
switch (self->condition()) {
268260
default:
@@ -342,9 +334,9 @@ void PCSX::Widgets::Breakpoints::draw(const char* title) {
342334
break;
343335
}
344336

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);
348340

349341
bp->setCondition(breakCondition);
350342
bp->setConditionData(conditionData);

0 commit comments

Comments
 (0)