1
// Copyright 2013 Dolphin Emulator Project
2
// Licensed under GPLv2
3
// Refer to the license.txt file included.
5
#include "DebuggerUIUtil.h"
6
#include "RegisterView.h"
7
#include "PowerPC/PowerPC.h"
8
#include "HW/ProcessorInterface.h"
10
#include "../WxUtils.h"
12
// F-zero 80005e60 wtf??
14
extern const char* GetGPRName(unsigned int index);
15
extern const char* GetFPRName(unsigned int index);
17
static const char *special_reg_names[] = {
18
"PC", "LR", "CTR", "CR", "FPSCR", "MSR", "SRR0", "SRR1", "Exceptions", "Int Mask", "Int Cause",
21
static u32 GetSpecialRegValue(int reg)
25
case 0: return PowerPC::ppcState.pc;
26
case 1: return PowerPC::ppcState.spr[SPR_LR];
27
case 2: return PowerPC::ppcState.spr[SPR_CTR];
28
case 3: return GetCR();
29
case 4: return PowerPC::ppcState.fpscr;
30
case 5: return PowerPC::ppcState.msr;
31
case 6: return PowerPC::ppcState.spr[SPR_SRR0];
32
case 7: return PowerPC::ppcState.spr[SPR_SRR1];
33
case 8: return PowerPC::ppcState.Exceptions;
34
case 9: return ProcessorInterface::GetMask();
35
case 10: return ProcessorInterface::GetCause();
40
wxString CRegTable::GetValue(int row, int col)
46
case 0: return StrToWxStr(GetGPRName(row));
47
case 1: return wxString::Format(wxT("%08x"), GPR(row));
48
case 2: return StrToWxStr(GetFPRName(row));
49
case 3: return wxString::Format(wxT("%016llx"), riPS0(row));
50
case 4: return wxString::Format(wxT("%016llx"), riPS1(row));
51
default: return wxEmptyString;
56
if (row - 32 < NUM_SPECIALS)
60
case 0: return StrToWxStr(special_reg_names[row - 32]);
61
case 1: return wxString::Format(wxT("%08x"), GetSpecialRegValue(row - 32));
62
default: return wxEmptyString;
69
static void SetSpecialRegValue(int reg, u32 value)
73
case 0: PowerPC::ppcState.pc = value; break;
74
case 1: PowerPC::ppcState.spr[SPR_LR] = value; break;
75
case 2: PowerPC::ppcState.spr[SPR_CTR] = value; break;
76
case 3: SetCR(value); break;
77
case 4: PowerPC::ppcState.fpscr = value; break;
78
case 5: PowerPC::ppcState.msr = value; break;
79
case 6: PowerPC::ppcState.spr[SPR_SRR0] = value; break;
80
case 7: PowerPC::ppcState.spr[SPR_SRR1] = value; break;
81
case 8: PowerPC::ppcState.Exceptions = value; break;
82
// Should we just change the value, or use ProcessorInterface::SetInterrupt() to make the system aware?
83
// case 9: return ProcessorInterface::GetMask();
84
// case 10: return ProcessorInterface::GetCause();
89
void CRegTable::SetValue(int row, int col, const wxString& strNewVal)
92
if (TryParse(WxStrToStr(strNewVal), &newVal))
105
if ((row - 32 < NUM_SPECIALS) && (col == 1))
107
SetSpecialRegValue(row - 32, newVal);
113
void CRegTable::UpdateCachedRegs()
115
for (int i = 0; i < 32; ++i)
117
m_CachedRegHasChanged[i] = (m_CachedRegs[i] != GPR(i));
118
m_CachedRegs[i] = GPR(i);
120
m_CachedFRegHasChanged[i][0] = (m_CachedFRegs[i][0] != riPS0(i));
121
m_CachedFRegs[i][0] = riPS0(i);
122
m_CachedFRegHasChanged[i][1] = (m_CachedFRegs[i][1] != riPS1(i));
123
m_CachedFRegs[i][1] = riPS1(i);
125
for (int i = 0; i < NUM_SPECIALS; ++i)
127
m_CachedSpecialRegHasChanged[i] = (m_CachedSpecialRegs[i] != GetSpecialRegValue(i));
128
m_CachedSpecialRegs[i] = GetSpecialRegValue(i);
132
wxGridCellAttr *CRegTable::GetAttr(int row, int col, wxGridCellAttr::wxAttrKind)
134
wxGridCellAttr *attr = new wxGridCellAttr();
136
attr->SetBackgroundColour(wxColour(wxT("#FFFFFF"))); //wxWHITE
137
attr->SetFont(DebuggerFont);
142
attr->SetAlignment(wxALIGN_CENTER, wxALIGN_CENTER);
146
attr->SetAlignment(wxALIGN_RIGHT, wxALIGN_CENTER);
149
attr->SetAlignment(wxALIGN_LEFT, wxALIGN_CENTER);
156
case 1: red = row < 32 ? m_CachedRegHasChanged[row] : m_CachedSpecialRegHasChanged[row-32]; break;
158
case 4: red = row < 32 ? m_CachedFRegHasChanged[row][col-3] : false; break;
161
attr->SetTextColour(red ? wxColor(wxT("#FF0000")) : wxColor(wxT("#000000")));
166
CRegisterView::CRegisterView(wxWindow *parent, wxWindowID id)
169
SetTable(new CRegTable(), true);
172
DisableDragRowSize();
177
void CRegisterView::Update()
180
((CRegTable *)GetTable())->UpdateCachedRegs();