~registry/dolphin-emu/triforce

« back to all changes in this revision

Viewing changes to Source/Core/DolphinWX/Src/Debugger/RegisterView.cpp

  • Committer: Sérgio Benjamim
  • Date: 2015-02-13 05:54:40 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20150213055440-ey2rt3sjpy27km78
Dolphin Triforce branch from code.google, commit b957980 (4.0-315).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Dolphin Emulator Project
 
2
// Licensed under GPLv2
 
3
// Refer to the license.txt file included.
 
4
 
 
5
#include "DebuggerUIUtil.h"
 
6
#include "RegisterView.h"
 
7
#include "PowerPC/PowerPC.h"
 
8
#include "HW/ProcessorInterface.h"
 
9
#include "IniFile.h"
 
10
#include "../WxUtils.h"
 
11
 
 
12
// F-zero 80005e60 wtf??
 
13
 
 
14
extern const char* GetGPRName(unsigned int index);
 
15
extern const char* GetFPRName(unsigned int index);
 
16
 
 
17
static const char *special_reg_names[] = {
 
18
        "PC", "LR", "CTR", "CR", "FPSCR", "MSR", "SRR0", "SRR1", "Exceptions", "Int Mask", "Int Cause",
 
19
};
 
20
 
 
21
static u32 GetSpecialRegValue(int reg)
 
22
{
 
23
        switch (reg)
 
24
        {
 
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();
 
36
        default: return 0;      
 
37
        }
 
38
}
 
39
 
 
40
wxString CRegTable::GetValue(int row, int col)
 
41
{
 
42
        if (row < 32)
 
43
        {
 
44
                switch (col)
 
45
                {
 
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;
 
52
                }
 
53
        }
 
54
        else
 
55
        {
 
56
                if (row - 32 < NUM_SPECIALS)
 
57
                {
 
58
                        switch (col)
 
59
                        {
 
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;
 
63
                        }
 
64
                }
 
65
        }
 
66
        return wxEmptyString;
 
67
}
 
68
 
 
69
static void SetSpecialRegValue(int reg, u32 value)
 
70
{
 
71
        switch (reg)
 
72
        {
 
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();
 
85
        default: return;
 
86
        }
 
87
}
 
88
 
 
89
void CRegTable::SetValue(int row, int col, const wxString& strNewVal)
 
90
{
 
91
        u32 newVal = 0;
 
92
        if (TryParse(WxStrToStr(strNewVal), &newVal))
 
93
        {
 
94
                if (row < 32)
 
95
                {
 
96
                        if (col == 1)
 
97
                                GPR(row) = newVal;
 
98
                        else if (col == 3)
 
99
                                riPS0(row) = newVal;
 
100
                        else if (col == 4)
 
101
                                riPS1(row) = newVal;
 
102
                }
 
103
                else
 
104
                {
 
105
                        if ((row - 32 < NUM_SPECIALS) && (col == 1))
 
106
                        {
 
107
                                SetSpecialRegValue(row - 32, newVal);
 
108
                        }
 
109
                }
 
110
        }
 
111
}
 
112
 
 
113
void CRegTable::UpdateCachedRegs()
 
114
{
 
115
        for (int i = 0; i < 32; ++i)
 
116
        {
 
117
                m_CachedRegHasChanged[i] = (m_CachedRegs[i] != GPR(i));
 
118
                m_CachedRegs[i] = GPR(i);
 
119
 
 
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);
 
124
        }
 
125
        for (int i = 0; i < NUM_SPECIALS; ++i)
 
126
        {
 
127
                m_CachedSpecialRegHasChanged[i] = (m_CachedSpecialRegs[i] != GetSpecialRegValue(i));
 
128
                m_CachedSpecialRegs[i] = GetSpecialRegValue(i);
 
129
        }
 
130
}
 
131
 
 
132
wxGridCellAttr *CRegTable::GetAttr(int row, int col, wxGridCellAttr::wxAttrKind)
 
133
{
 
134
        wxGridCellAttr *attr = new wxGridCellAttr();
 
135
 
 
136
        attr->SetBackgroundColour(wxColour(wxT("#FFFFFF")));  //wxWHITE
 
137
        attr->SetFont(DebuggerFont);
 
138
 
 
139
        switch (col)
 
140
        {
 
141
        case 1:
 
142
                attr->SetAlignment(wxALIGN_CENTER, wxALIGN_CENTER);
 
143
                break;
 
144
        case 3:
 
145
        case 4:
 
146
                attr->SetAlignment(wxALIGN_RIGHT, wxALIGN_CENTER);
 
147
                break;
 
148
        default:
 
149
                attr->SetAlignment(wxALIGN_LEFT, wxALIGN_CENTER);
 
150
                break;
 
151
        }
 
152
 
 
153
        bool red = false;
 
154
        switch (col)
 
155
        {
 
156
        case 1: red = row < 32 ? m_CachedRegHasChanged[row] : m_CachedSpecialRegHasChanged[row-32]; break;
 
157
        case 3: 
 
158
        case 4: red = row < 32 ? m_CachedFRegHasChanged[row][col-3] : false; break;
 
159
        }
 
160
 
 
161
        attr->SetTextColour(red ? wxColor(wxT("#FF0000")) : wxColor(wxT("#000000")));
 
162
        attr->IncRef();
 
163
        return attr;
 
164
}
 
165
 
 
166
CRegisterView::CRegisterView(wxWindow *parent, wxWindowID id)
 
167
        : wxGrid(parent, id)
 
168
{
 
169
        SetTable(new CRegTable(), true);
 
170
        SetRowLabelSize(0);
 
171
        SetColLabelSize(0);
 
172
        DisableDragRowSize();
 
173
 
 
174
        AutoSizeColumns();
 
175
}
 
176
 
 
177
void CRegisterView::Update()
 
178
{
 
179
        ForceRefresh();
 
180
        ((CRegTable *)GetTable())->UpdateCachedRegs();
 
181
}