2013-04-18 03:43:35 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <wx/colour.h>
|
|
|
|
#include <wx/grid.h>
|
2014-10-23 13:47:00 +00:00
|
|
|
#include <wx/menu.h>
|
2014-02-22 22:36:30 +00:00
|
|
|
|
|
|
|
#include "Common/CommonTypes.h"
|
2014-07-18 01:33:51 +00:00
|
|
|
#include "Common/GekkoDisassembler.h"
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "Common/StringUtil.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/HW/ProcessorInterface.h"
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "Core/PowerPC/Gekko.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/PowerPC/PowerPC.h"
|
2014-10-23 13:47:00 +00:00
|
|
|
#include "DolphinWX/Frame.h"
|
|
|
|
#include "DolphinWX/Globals.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "DolphinWX/WxUtils.h"
|
2014-10-23 13:47:00 +00:00
|
|
|
#include "DolphinWX/Debugger/CodeWindow.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "DolphinWX/Debugger/DebuggerUIUtil.h"
|
2014-10-23 13:47:00 +00:00
|
|
|
#include "DolphinWX/Debugger/MemoryWindow.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "DolphinWX/Debugger/RegisterView.h"
|
2014-10-23 13:47:00 +00:00
|
|
|
#include "DolphinWX/Debugger/WatchWindow.h"
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2009-01-20 19:15:33 +00:00
|
|
|
// F-zero 80005e60 wtf??
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-10-23 13:47:00 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
IDM_WATCHADDRESS,
|
|
|
|
IDM_VIEWMEMORY,
|
|
|
|
};
|
|
|
|
|
2009-01-20 19:15:33 +00:00
|
|
|
static const char *special_reg_names[] = {
|
2014-10-12 09:03:29 +00:00
|
|
|
"PC", "LR", "CTR", "CR", "FPSCR", "MSR", "SRR0", "SRR1", "Exceptions", "Int Mask", "Int Cause", "DSISR", "DAR", "PT hashmask"
|
2009-01-20 19:15:33 +00:00
|
|
|
};
|
|
|
|
|
2013-04-08 05:16:50 +00:00
|
|
|
static u32 GetSpecialRegValue(int reg)
|
|
|
|
{
|
|
|
|
switch (reg)
|
|
|
|
{
|
2009-01-20 19:15:33 +00:00
|
|
|
case 0: return PowerPC::ppcState.pc;
|
|
|
|
case 1: return PowerPC::ppcState.spr[SPR_LR];
|
|
|
|
case 2: return PowerPC::ppcState.spr[SPR_CTR];
|
|
|
|
case 3: return GetCR();
|
|
|
|
case 4: return PowerPC::ppcState.fpscr;
|
2009-10-17 07:17:49 +00:00
|
|
|
case 5: return PowerPC::ppcState.msr;
|
|
|
|
case 6: return PowerPC::ppcState.spr[SPR_SRR0];
|
|
|
|
case 7: return PowerPC::ppcState.spr[SPR_SRR1];
|
|
|
|
case 8: return PowerPC::ppcState.Exceptions;
|
|
|
|
case 9: return ProcessorInterface::GetMask();
|
|
|
|
case 10: return ProcessorInterface::GetCause();
|
2014-10-12 09:03:29 +00:00
|
|
|
case 11: return PowerPC::ppcState.spr[SPR_DSISR];
|
|
|
|
case 12: return PowerPC::ppcState.spr[SPR_DAR];
|
|
|
|
case 13: return (PowerPC::ppcState.pagetable_hashmask << 6) | PowerPC::ppcState.pagetable_base;
|
2013-10-29 05:23:17 +00:00
|
|
|
default: return 0;
|
2009-01-20 19:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-10-23 13:47:00 +00:00
|
|
|
static wxString GetValueByRowCol(int row, int col)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2013-04-08 05:16:50 +00:00
|
|
|
if (row < 32)
|
|
|
|
{
|
|
|
|
switch (col)
|
|
|
|
{
|
2014-07-18 01:33:51 +00:00
|
|
|
case 0: return StrToWxStr(GekkoDisassembler::GetGPRName(row));
|
2014-05-17 17:17:28 +00:00
|
|
|
case 1: return wxString::Format("%08x", GPR(row));
|
2014-07-18 01:33:51 +00:00
|
|
|
case 2: return StrToWxStr(GekkoDisassembler::GetFPRName(row));
|
2014-05-17 17:17:28 +00:00
|
|
|
case 3: return wxString::Format("%016llx", riPS0(row));
|
|
|
|
case 4: return wxString::Format("%016llx", riPS1(row));
|
2014-10-12 09:03:29 +00:00
|
|
|
case 5:
|
|
|
|
{
|
|
|
|
if (row < 4)
|
|
|
|
return wxString::Format("DBAT%01d", row);
|
2015-05-24 02:14:31 +00:00
|
|
|
|
2014-10-12 09:03:29 +00:00
|
|
|
if (row < 8)
|
|
|
|
return wxString::Format("IBAT%01d", row - 4);
|
2015-05-24 02:14:31 +00:00
|
|
|
|
2014-10-12 09:03:29 +00:00
|
|
|
if (row < 12)
|
|
|
|
return wxString::Format("DBAT%01d", row - 4);
|
2015-05-24 02:14:31 +00:00
|
|
|
|
2014-10-12 09:03:29 +00:00
|
|
|
if (row < 16)
|
|
|
|
return wxString::Format("IBAT%01d", row - 8);
|
2015-05-24 02:14:31 +00:00
|
|
|
|
|
|
|
break;
|
2014-10-12 09:03:29 +00:00
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
if (row < 4)
|
|
|
|
return wxString::Format("%016llx", (u64)PowerPC::ppcState.spr[SPR_DBAT0U + row * 2] << 32 | PowerPC::ppcState.spr[SPR_DBAT0L + row * 2]);
|
2015-05-24 02:14:31 +00:00
|
|
|
|
2014-10-12 09:03:29 +00:00
|
|
|
if (row < 8)
|
|
|
|
return wxString::Format("%016llx", (u64)PowerPC::ppcState.spr[SPR_IBAT0U + (row - 4) * 2] << 32 | PowerPC::ppcState.spr[SPR_IBAT0L + (row - 4) * 2]);
|
2015-05-24 02:14:31 +00:00
|
|
|
|
2014-10-12 09:03:29 +00:00
|
|
|
if (row < 12)
|
|
|
|
return wxString::Format("%016llx", (u64)PowerPC::ppcState.spr[SPR_DBAT4U + (row - 12) * 2] << 32 | PowerPC::ppcState.spr[SPR_DBAT4L + (row - 12) * 2]);
|
2015-05-24 02:14:31 +00:00
|
|
|
|
2014-10-12 09:03:29 +00:00
|
|
|
if (row < 16)
|
|
|
|
return wxString::Format("%016llx", (u64)PowerPC::ppcState.spr[SPR_IBAT4U + (row - 16) * 2] << 32 | PowerPC::ppcState.spr[SPR_IBAT4L + (row - 16) * 2]);
|
2015-05-24 02:14:31 +00:00
|
|
|
|
|
|
|
break;
|
2014-10-12 09:03:29 +00:00
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
|
|
|
if (row < 16)
|
|
|
|
return wxString::Format("SR%02d", row);
|
2015-05-24 02:14:31 +00:00
|
|
|
|
|
|
|
break;
|
2014-10-12 09:03:29 +00:00
|
|
|
}
|
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
if (row < 16)
|
|
|
|
return wxString::Format("%08x", PowerPC::ppcState.sr[row]);
|
2015-05-24 02:14:31 +00:00
|
|
|
|
|
|
|
break;
|
2014-10-12 09:03:29 +00:00
|
|
|
}
|
2011-12-22 22:28:12 +00:00
|
|
|
default: return wxEmptyString;
|
2009-01-20 19:15:33 +00:00
|
|
|
}
|
2013-04-08 05:16:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (row - 32 < NUM_SPECIALS)
|
|
|
|
{
|
|
|
|
switch (col)
|
|
|
|
{
|
2014-02-17 04:51:41 +00:00
|
|
|
case 0: return StrToWxStr(special_reg_names[row - 32]);
|
2014-05-17 17:17:28 +00:00
|
|
|
case 1: return wxString::Format("%08x", GetSpecialRegValue(row - 32));
|
2011-12-22 22:28:12 +00:00
|
|
|
default: return wxEmptyString;
|
2013-04-08 05:16:50 +00:00
|
|
|
}
|
2009-01-20 19:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-08 05:16:50 +00:00
|
|
|
return wxEmptyString;
|
2008-12-09 05:29:14 +00:00
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-10-23 13:47:00 +00:00
|
|
|
wxString CRegTable::GetValue(int row, int col)
|
|
|
|
{
|
|
|
|
return GetValueByRowCol(row, col);
|
|
|
|
}
|
|
|
|
|
2013-04-08 05:16:50 +00:00
|
|
|
static void SetSpecialRegValue(int reg, u32 value)
|
|
|
|
{
|
|
|
|
switch (reg)
|
|
|
|
{
|
2009-10-17 07:17:49 +00:00
|
|
|
case 0: PowerPC::ppcState.pc = value; break;
|
|
|
|
case 1: PowerPC::ppcState.spr[SPR_LR] = value; break;
|
|
|
|
case 2: PowerPC::ppcState.spr[SPR_CTR] = value; break;
|
|
|
|
case 3: SetCR(value); break;
|
|
|
|
case 4: PowerPC::ppcState.fpscr = value; break;
|
|
|
|
case 5: PowerPC::ppcState.msr = value; break;
|
|
|
|
case 6: PowerPC::ppcState.spr[SPR_SRR0] = value; break;
|
|
|
|
case 7: PowerPC::ppcState.spr[SPR_SRR1] = value; break;
|
|
|
|
case 8: PowerPC::ppcState.Exceptions = value; break;
|
2014-02-17 04:51:41 +00:00
|
|
|
// Should we just change the value, or use ProcessorInterface::SetInterrupt() to make the system aware?
|
|
|
|
// case 9: return ProcessorInterface::GetMask();
|
|
|
|
// case 10: return ProcessorInterface::GetCause();
|
2014-10-12 09:03:29 +00:00
|
|
|
case 11: PowerPC::ppcState.spr[SPR_DSISR] = value; break;
|
|
|
|
case 12: PowerPC::ppcState.spr[SPR_DAR] = value; break;
|
|
|
|
//case 13: (PowerPC::ppcState.pagetable_hashmask << 6) | PowerPC::ppcState.pagetable_base;
|
2009-10-17 07:17:49 +00:00
|
|
|
default: return;
|
2009-10-17 00:10:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CRegTable::SetValue(int row, int col, const wxString& strNewVal)
|
2008-12-09 05:29:14 +00:00
|
|
|
{
|
2009-10-17 00:10:22 +00:00
|
|
|
u32 newVal = 0;
|
2014-09-12 04:20:26 +00:00
|
|
|
if (TryParse("0x" + WxStrToStr(strNewVal), &newVal))
|
2009-10-17 00:10:22 +00:00
|
|
|
{
|
2013-04-08 05:16:50 +00:00
|
|
|
if (row < 32)
|
|
|
|
{
|
2009-10-17 00:10:22 +00:00
|
|
|
if (col == 1)
|
|
|
|
GPR(row) = newVal;
|
2010-10-19 13:35:25 +00:00
|
|
|
else if (col == 3)
|
|
|
|
riPS0(row) = newVal;
|
|
|
|
else if (col == 4)
|
|
|
|
riPS1(row) = newVal;
|
2013-04-08 05:16:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((row - 32 < NUM_SPECIALS) && (col == 1))
|
|
|
|
{
|
2009-10-17 00:10:22 +00:00
|
|
|
SetSpecialRegValue(row - 32, newVal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-09 05:29:14 +00:00
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2009-01-20 19:15:33 +00:00
|
|
|
void CRegTable::UpdateCachedRegs()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 32; ++i)
|
|
|
|
{
|
|
|
|
m_CachedRegHasChanged[i] = (m_CachedRegs[i] != GPR(i));
|
|
|
|
m_CachedRegs[i] = GPR(i);
|
|
|
|
|
2010-10-19 13:35:25 +00:00
|
|
|
m_CachedFRegHasChanged[i][0] = (m_CachedFRegs[i][0] != riPS0(i));
|
|
|
|
m_CachedFRegs[i][0] = riPS0(i);
|
|
|
|
m_CachedFRegHasChanged[i][1] = (m_CachedFRegs[i][1] != riPS1(i));
|
|
|
|
m_CachedFRegs[i][1] = riPS1(i);
|
2009-01-20 19:15:33 +00:00
|
|
|
}
|
2009-10-17 07:17:49 +00:00
|
|
|
for (int i = 0; i < NUM_SPECIALS; ++i)
|
2009-01-20 19:15:33 +00:00
|
|
|
{
|
|
|
|
m_CachedSpecialRegHasChanged[i] = (m_CachedSpecialRegs[i] != GetSpecialRegValue(i));
|
|
|
|
m_CachedSpecialRegs[i] = GetSpecialRegValue(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-09 05:29:14 +00:00
|
|
|
wxGridCellAttr *CRegTable::GetAttr(int row, int col, wxGridCellAttr::wxAttrKind)
|
|
|
|
{
|
|
|
|
wxGridCellAttr *attr = new wxGridCellAttr();
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-05-17 17:17:28 +00:00
|
|
|
attr->SetBackgroundColour(*wxWHITE);
|
2009-02-06 18:18:20 +00:00
|
|
|
attr->SetFont(DebuggerFont);
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2013-04-08 05:16:50 +00:00
|
|
|
switch (col)
|
|
|
|
{
|
2009-01-20 19:41:45 +00:00
|
|
|
case 1:
|
2009-10-17 00:10:22 +00:00
|
|
|
attr->SetAlignment(wxALIGN_CENTER, wxALIGN_CENTER);
|
|
|
|
break;
|
2009-01-20 19:41:45 +00:00
|
|
|
case 3:
|
|
|
|
case 4:
|
2009-10-17 00:10:22 +00:00
|
|
|
attr->SetAlignment(wxALIGN_RIGHT, wxALIGN_CENTER);
|
2009-01-20 19:41:45 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
attr->SetAlignment(wxALIGN_LEFT, wxALIGN_CENTER);
|
|
|
|
break;
|
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2009-01-20 19:41:45 +00:00
|
|
|
bool red = false;
|
2013-04-08 05:16:50 +00:00
|
|
|
switch (col)
|
|
|
|
{
|
2009-01-20 19:41:45 +00:00
|
|
|
case 1: red = row < 32 ? m_CachedRegHasChanged[row] : m_CachedSpecialRegHasChanged[row-32]; break;
|
2013-10-29 05:23:17 +00:00
|
|
|
case 3:
|
2009-01-20 19:41:45 +00:00
|
|
|
case 4: red = row < 32 ? m_CachedFRegHasChanged[row][col-3] : false; break;
|
|
|
|
}
|
2013-04-08 05:16:50 +00:00
|
|
|
|
2014-05-17 17:17:28 +00:00
|
|
|
attr->SetTextColour(red ? *wxRED : *wxBLACK);
|
2008-12-09 05:29:14 +00:00
|
|
|
return attr;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2008-12-09 05:29:14 +00:00
|
|
|
CRegisterView::CRegisterView(wxWindow *parent, wxWindowID id)
|
|
|
|
: wxGrid(parent, id)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2015-03-24 13:37:20 +00:00
|
|
|
m_register_table = new CRegTable();
|
|
|
|
|
|
|
|
SetTable(m_register_table, true);
|
2008-12-09 05:29:14 +00:00
|
|
|
SetRowLabelSize(0);
|
|
|
|
SetColLabelSize(0);
|
2009-02-06 18:18:20 +00:00
|
|
|
DisableDragRowSize();
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-11-06 03:19:52 +00:00
|
|
|
Bind(wxEVT_GRID_CELL_RIGHT_CLICK, &CRegisterView::OnMouseDownR, this);
|
|
|
|
Bind(wxEVT_MENU, &CRegisterView::OnPopupMenu, this);
|
|
|
|
|
2008-12-09 05:29:14 +00:00
|
|
|
AutoSizeColumns();
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2008-12-09 05:29:14 +00:00
|
|
|
void CRegisterView::Update()
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2015-03-24 13:37:20 +00:00
|
|
|
m_register_table->UpdateCachedRegs();
|
2015-04-15 04:11:57 +00:00
|
|
|
ForceRefresh();
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
2014-10-23 13:47:00 +00:00
|
|
|
|
|
|
|
void CRegisterView::OnMouseDownR(wxGridEvent& event)
|
|
|
|
{
|
|
|
|
// popup menu
|
|
|
|
int row = event.GetRow();
|
|
|
|
int col = event.GetCol();
|
|
|
|
|
|
|
|
wxString strNewVal = GetValueByRowCol(row, col);
|
2014-10-24 06:16:54 +00:00
|
|
|
TryParse("0x" + WxStrToStr(strNewVal), &m_selectedAddress);
|
2014-10-23 13:47:00 +00:00
|
|
|
|
2014-11-11 14:50:11 +00:00
|
|
|
wxMenu menu;
|
|
|
|
menu.Append(IDM_WATCHADDRESS, _("Add to &watch"));
|
|
|
|
menu.Append(IDM_VIEWMEMORY, _("View &memory"));
|
|
|
|
PopupMenu(&menu);
|
2014-10-23 13:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CRegisterView::OnPopupMenu(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
CFrame* main_frame = (CFrame*)(GetParent()->GetParent());
|
|
|
|
CCodeWindow* code_window = main_frame->g_pCodeWindow;
|
|
|
|
CWatchWindow* watch_window = code_window->m_WatchWindow;
|
|
|
|
CMemoryWindow* memory_window = code_window->m_MemoryWindow;
|
|
|
|
|
|
|
|
switch (event.GetId())
|
|
|
|
{
|
|
|
|
case IDM_WATCHADDRESS:
|
2014-10-24 06:16:54 +00:00
|
|
|
PowerPC::watches.Add(m_selectedAddress);
|
2014-10-23 13:47:00 +00:00
|
|
|
if (watch_window)
|
|
|
|
watch_window->NotifyUpdate();
|
|
|
|
Refresh();
|
|
|
|
break;
|
|
|
|
case IDM_VIEWMEMORY:
|
|
|
|
if (memory_window)
|
2014-10-24 06:16:54 +00:00
|
|
|
memory_window->JumpToAddress(m_selectedAddress);
|
2014-10-23 13:47:00 +00:00
|
|
|
Refresh();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
event.Skip();
|
|
|
|
}
|