My first proud commit

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4609 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
interdpth 2009-11-25 10:07:56 +00:00
parent 29774c35e8
commit 7118900d3b
4 changed files with 414 additions and 13 deletions

View File

@ -37,6 +37,7 @@ enum
IDM_TOGGLEMEMORY,
IDM_VIEWASFP,
IDM_VIEWASASCII,
IDM_VIEWASHEX,
};
@ -215,6 +216,10 @@ void CMemoryView::OnPopupMenu(wxCommandEvent& event)
viewAsType = VIEWAS_ASCII;
redraw();
break;
case IDM_VIEWASHEX:
viewAsType = VIEWAS_HEX;
redraw();
break;
}
#if wxUSE_CLIPBOARD
@ -235,14 +240,18 @@ void CMemoryView::OnMouseDownR(wxMouseEvent& event)
#endif
menu->Append(IDM_TOGGLEMEMORY, wxString::FromAscii("Toggle &memory (RAM/ARAM)"));
wxMenu* viewAsSubMenu = new wxMenu;
viewAsSubMenu->Append(IDM_VIEWASFP, wxString::FromAscii("FP value"));
viewAsSubMenu->Append(IDM_VIEWASASCII, wxString::FromAscii("ASCII"));
viewAsSubMenu->Append(IDM_VIEWASHEX, wxString::FromAscii("Hex"));
menu->AppendSubMenu(viewAsSubMenu, wxString::FromAscii("View As:"));
PopupMenu(menu);
event.Skip(true);
//event.Skip(true);
}
@ -251,6 +260,186 @@ void CMemoryView::OnErase(wxEraseEvent& event)
void CMemoryView::OnPaint(wxPaintEvent& event)
{
wxPaintDC dc(this);
wxRect rc = GetClientRect();
wxFont hFont(_T("Courier"));
if(viewAsType==VIEWAS_HEX){
hFont.SetFamily(wxFONTFAMILY_TELETYPE);
dc.SetFont(hFont);
}else{
dc.SetFont(DebuggerFont);
}
//wxFont tempFont(Lucida Console);
int fontSize =(viewAsType==VIEWAS_HEX?hFont.GetPointSize() : DebuggerFont.GetPointSize());
int textPlacement=77;
struct branch
{
int src, dst, srcAddr;
};
// TODO: Add any drawing code here...
int width = rc.width;
int numRows = (rc.height / rowHeight) / 2 + 2;
//numRows=(numRows&(~1)) + 1;
dc.SetBackgroundMode(wxTRANSPARENT);
const wxChar* bgColor = _T("#ffffff");
wxPen nullPen(bgColor);
wxPen currentPen(_T("#000000"));
wxPen selPen(_T("#808080")); // gray
nullPen.SetStyle(wxTRANSPARENT);
wxBrush currentBrush(_T("#FFEfE8")); // light gray
wxBrush pcBrush(_T("#70FF70")); // green
wxBrush mcBrush(_T("#1133FF")); // blue
wxBrush bgBrush(bgColor);
wxBrush nullBrush(bgColor);
nullBrush.SetStyle(wxTRANSPARENT);
dc.SetPen(nullPen);
dc.SetBrush(bgBrush);
dc.DrawRectangle(0, 0, 16, rc.height);
dc.DrawRectangle(0, 0, rc.width, 5+8);
// TODO - clean up this freaking mess!!!!!
int i;
for (i = -numRows; i <= numRows; i++)
{
unsigned int address = curAddress + i * align;
int rowY1 = rc.height / 2 + rowHeight * i - rowHeight / 2;
int rowY2 = rc.height / 2 + rowHeight * i + rowHeight / 2;
wxString temp = wxString::Format(_T("%08x"), address);
u32 col = debugger->getColor(address);
wxBrush rowBrush(wxColor(col >> 16, col >> 8, col));
dc.SetBrush(nullBrush);
dc.SetPen(nullPen);
dc.DrawRectangle(0, rowY1, 16, rowY2);
if (selecting && (address == selection))
{
dc.SetPen(selPen);
}
else
{
dc.SetPen(i == 0 ? currentPen : nullPen);
}
if (address == debugger->getPC())
{
dc.SetBrush(pcBrush);
}
else
{
dc.SetBrush(rowBrush);
}
dc.DrawRectangle(16, rowY1, width, rowY2 - 1);
dc.SetBrush(currentBrush);
dc.SetTextForeground(_T("#600000"));
dc.DrawText(temp, 17, rowY1);
if(viewAsType!=VIEWAS_HEX){
char mem[256];
debugger->getRawMemoryString(memory, address, mem, 256);
dc.SetTextForeground(_T("#000080"));
dc.DrawText(wxString::FromAscii(mem), 17+fontSize*(8), rowY1);
dc.SetTextForeground(_T("#000000"));
}
if (debugger->isAlive())
{
char dis[256] = {0};
u32 mem_data = debugger->readExtraMemory(memory, address);
if (viewAsType == VIEWAS_FP)
{
float flt = *(float *)(&mem_data);
sprintf(dis, "f: %f", flt);
}
else if (viewAsType == VIEWAS_ASCII)
{
char a[4] = {(mem_data&0xff000000)>>24, (mem_data&0xff0000)>>16, (mem_data&0xff00)>>8, mem_data&0xff};
for (size_t i = 0; i < 4; i++)
if (a[i] == '\0')
a[i] = ' ';
sprintf(dis, "%c%c%c%c", a[0], a[1], a[2], a[3]);
}
else if(viewAsType==VIEWAS_HEX){
dis[0]=0;dis[1]=0;
u32 mema[8]={
debugger->readExtraMemory(memory, address),
debugger->readExtraMemory(memory, address+4),
debugger->readExtraMemory(memory, address+8),
debugger->readExtraMemory(memory, address+12),
debugger->readExtraMemory(memory, address+16),
debugger->readExtraMemory(memory, address+20),
debugger->readExtraMemory(memory, address+24),
debugger->readExtraMemory(memory, address+28)
};
// for(size_t i=0;i<2;i++){
//sprintf(dis,"%s %x %x %x %x",((mems&0xff000000)>>24)&0xFF, ((mems&0xff0000)>>16)&0xFF, ((mems&0xff00)>>8)&0xFF, mems&0xff);
int i=0;
for(i=0;i<8;i++){
switch(dataType){
case 0:
sprintf(dis,"%s %02X %02X %02X %02X",dis,((mema[i]&0xff000000)>>24)&0xFF, ((mema[i]&0xff0000)>>16)&0xFF, ((mema[i]&0xff00)>>8)&0xFF, mema[i]&0xff);
break;
case 1:
sprintf(dis,"%s %02X%02X %02X%02X",dis,((mema[i]&0xff000000)>>24)&0xFF, ((mema[i]&0xff0000)>>16)&0xFF, ((mema[i]&0xff00)>>8)&0xFF, mema[i]&0xff);
break;
case 2:
sprintf(dis,"%s %02X%02X%02X%02X",dis,((mema[i]&0xff000000)>>24)&0xFF, ((mema[i]&0xff0000)>>16)&0xFF, ((mema[i]&0xff00)>>8)&0xFF, mema[i]&0xff);
break;
}
// sprintf(dis,"%s %08X",dis,mema[i]);
// while((strlen(dis))%9)strcat(dis," ");
}
size_t len=strlen(dis);
//if(strlen(dis)%2)strcat(dis," ");
strcat(dis,"\0");
curAddress+=32;
//textPlacement-=32;
}
else
sprintf(dis, "INVALID VIEWAS TYPE");
char desc[256] = "";
if(viewAsType!=VIEWAS_HEX){
dc.DrawText(wxString::FromAscii(dis), textPlacement + fontSize*(8 + 8), rowY1);
}else{
dc.DrawText(wxString::FromAscii(dis), textPlacement + 8+16, rowY1);
}
if (desc[0] == 0)
{
strcpy(desc, debugger->getDescription(address).c_str());
}
dc.SetTextForeground(_T("#0000FF"));
if (strlen(desc))
{
dc.DrawText(wxString::FromAscii(desc), 17+fontSize*((8+8+8+30)*2), rowY1);
}
// Show blue memory check dot
if (Memory::AreMemoryBreakpointsActivated() && PowerPC::memchecks.GetMemCheck(address))
{
dc.SetBrush(mcBrush);
dc.DrawRectangle(8, rowY1 + 1, 11, 11);
}
}
}
dc.SetPen(currentPen);
}
/*
void OnPaint2(wxPaintEvent& event)
{
wxPaintDC dc(this);
wxRect rc = GetClientRect();
@ -376,5 +565,4 @@ void CMemoryView::OnPaint(wxPaintEvent& event)
dc.SetPen(currentPen);
}
*/

View File

@ -43,14 +43,15 @@ public:
curAddress = addr;
redraw();
}
int dataType;//u8,u16,u32
int curAddress;//Will be accessed by parent
private:
int YToAddress(int y);
void redraw() {Refresh();}
DebugInterface* debugger;
int curAddress;
int align;
int rowHeight;
@ -67,7 +68,9 @@ private:
{
VIEWAS_ASCII = 0,
VIEWAS_FP,
VIEWAS_HEX,
};
EViewAsType viewAsType;
DECLARE_EVENT_TABLE()

View File

@ -48,6 +48,12 @@ enum
IDM_SETVALBUTTON,
IDM_DUMP_MEMORY,
IDM_VALBOX,
IDM_U8,//Feel free to rename these
IDM_U16,
IDM_U32,
IDM_SEARCH,
IDM_ASCII,
IDM_HEX
};
BEGIN_EVENT_TABLE(CMemoryWindow, wxPanel)
@ -56,6 +62,12 @@ BEGIN_EVENT_TABLE(CMemoryWindow, wxPanel)
EVT_HOST_COMMAND(wxID_ANY, CMemoryWindow::OnHostMessage)
EVT_BUTTON(IDM_SETVALBUTTON, CMemoryWindow::SetMemoryValue)
EVT_BUTTON(IDM_DUMP_MEMORY, CMemoryWindow::OnDumpMemory)
EVT_CHECKBOX(IDM_U8 , CMemoryWindow::U8)
EVT_CHECKBOX(IDM_U16 , CMemoryWindow::U16)
EVT_CHECKBOX(IDM_U32 , CMemoryWindow::U32)
EVT_BUTTON(IDM_SEARCH , CMemoryWindow::onSearch)
EVT_CHECKBOX(IDM_ASCII , CMemoryWindow::onAscii)
EVT_CHECKBOX(IDM_HEX , CMemoryWindow::onHex)
END_EVENT_TABLE()
CMemoryWindow::CMemoryWindow(wxWindow* parent, wxWindowID id,
@ -71,6 +83,7 @@ CMemoryWindow::CMemoryWindow(wxWindow* parent, wxWindowID id,
//sizerLeft->Add(symbols = new wxListBox(this, IDM_SYMBOLLIST, wxDefaultPosition, wxSize(20, 100), 0, NULL, wxLB_SORT), 1, wxEXPAND);
memview = new CMemoryView(di, this, wxID_ANY);
memview->dataType=0;
//sizerBig->Add(sizerLeft, 1, wxEXPAND);
sizerBig->Add(memview, 20, wxEXPAND);
sizerBig->Add(sizerRight, 0, wxEXPAND | wxALL, 3);
@ -81,7 +94,21 @@ CMemoryWindow::CMemoryWindow(wxWindow* parent, wxWindowID id,
sizerRight->AddSpacer(5);
sizerRight->Add(new wxButton(this, IDM_DUMP_MEMORY, _T("&Dump Memory")));
wxStaticBoxSizer* sizerSearchType = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Search"));
sizerSearchType->Add(btnSearch=new wxButton(this,IDM_SEARCH,_T("Search")));
sizerSearchType->Add(chkAscii=new wxCheckBox(this,IDM_ASCII,_T("&Ascii ")));
sizerSearchType->Add(chkHex=new wxCheckBox(this,IDM_HEX,_T("&Hex")));
sizerRight->Add(sizerSearchType);
wxStaticBoxSizer* sizerDataTypes = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Data Type"));
sizerDataTypes->Add(chk8=new wxCheckBox(this,IDM_U8,_T("&U8 ")));//Excesss spaces are to get the DataType to show properly
sizerDataTypes->Add(chk16=new wxCheckBox(this,IDM_U16,_T("&U16 ")));
sizerDataTypes->Add(chk32=new wxCheckBox(this,IDM_U32,_T("&U32 ")));
sizerRight->Add(sizerDataTypes);
SetSizer(sizerBig);
chkHex->SetValue(1);//Set defaults
chk8->SetValue(1);
//sizerLeft->SetSizeHints(this);
//sizerLeft->Fit(this);
@ -247,3 +274,174 @@ void CMemoryWindow::OnDumpMemory( wxCommandEvent& event )
break;
}
}
void CMemoryWindow::U8(wxCommandEvent& event){
chk16->SetValue(0);
chk32->SetValue(0);
memview->dataType =0;
memview->Refresh();
}
void CMemoryWindow::U16(wxCommandEvent& event){
chk8->SetValue(0);
chk32->SetValue(0);
memview->dataType =1;
memview->Refresh();
}
void CMemoryWindow::U32(wxCommandEvent& event){
chk16->SetValue(0);
chk8->SetValue(0);
memview->dataType =2;
memview->Refresh();
}
void CMemoryWindow::onSearch(wxCommandEvent& event){
u8* TheRAM=0;
u32 szRAM=0;
switch (memview->GetMemoryType())
{
case 0:
default:
{
if (Memory::m_pRAM)
{
TheRAM=Memory::m_pRAM;
szRAM=Memory::REALRAM_SIZE;
}
}
break;
case 1:
{
u8* aram = DSP::GetARAMPtr();
if (aram)
{
TheRAM=aram;
szRAM=DSP::ARAM_SIZE;
}
}
break;
}
//Now we have memory to look in
//Are we looking for ASCII string, or hex?
//memview->cu
wxString rawData=valbox->GetValue();
std::vector<u8> Dest;//May need a better name
u32 size=0;
int pad=rawData.size()%2;//If it's uneven
unsigned long i=0;
long count=0;
char copy[3]={0};
long newsize=0;
unsigned char *tmp2=0;
char* tmpstr=0;
switch(chkHex->GetValue()){
case 1://We are looking for hex
//If it's uneven
size=(rawData.size()/2) + pad;
Dest.resize(size+32);
newsize=rawData.size();
if(pad){
tmpstr=new char[newsize+2];
memset(tmpstr,0,newsize+2);
tmpstr[0]='0';
}else{
tmpstr=new char[newsize+1];
memset(tmpstr,0,newsize+1);
}
//sprintf(tmpstr,"%s%s",tmpstr,rawData.c_str());
//strcpy(&tmpstr[1],rawData.ToAscii());
//memcpy(&tmpstr[1],&rawData.c_str()[0],rawData.size());
sprintf(tmpstr,"%s%s",tmpstr,rawData.To8BitData());
tmp2=&Dest.front();
count=0;
for(i=0;i<strlen(tmpstr);i++){
copy[0]=tmpstr[i];
copy[1]=tmpstr[i+1];
copy[2]=0;
int tmpint;
sscanf(copy, "%02x", &tmpint);
tmp2[count++] = tmpint;
//sscanf(copy,"%02x",&tmp2[count++]);//Dest[count] should now be the hex of what the two chars were! Also should add a check to make sure it's A-F only
i+=1;//
}
delete[] tmpstr;
break;
case 0://Looking for an ascii string
size=rawData.size();
Dest.resize(size+1);
tmpstr=new char[size+1];
tmp2=&Dest.front();
sprintf(tmpstr,"%s",rawData.To8BitData());
for(i=0;i<size;i++){
tmp2[i]=tmpstr[i];
}
delete[] tmpstr;
break;
}
if(size){
unsigned char* pnt=&Dest.front();
int k=0;
//grab
wxString txt = addrbox->GetValue();
u32 addr=0;
if (txt.size())
{
sscanf(txt.mb_str(), "%08x", &addr);
}
i=addr+4;
for(;szRAM;i++){
for(k=0;k<size;k++){
if(i+k>szRAM) break;
if(k>size) break;
if(pnt[k]!=TheRAM[i+k]){
k=0;
break;
}
}
if(k==size){
//Match was found
wxMessageBox(_T("A match was found. Placing viewer at the offset."));
wxChar tmpstr[128]={0};
wxSprintf(tmpstr,_T("%08x"),i);
wxString tmpwx(tmpstr);
addrbox->SetValue(tmpwx);
//memview->curAddress=i;
//memview->Refresh();
OnAddrBoxChange(event);
return;
}
}
wxMessageBox(_T("No match was found."));
}
}
void CMemoryWindow::onAscii(wxCommandEvent& event){
chkHex->SetValue(0);
}
void CMemoryWindow::onHex(wxCommandEvent& event){
chkAscii->SetValue(0);
}

View File

@ -44,7 +44,12 @@ class CMemoryWindow
long style = wxNO_BORDER);
~CMemoryWindow();
wxCheckBox* chk8;
wxCheckBox* chk16;
wxCheckBox* chk32;
wxButton* btnSearch;
wxCheckBox* chkAscii;
wxCheckBox* chkHex;
void Save(IniFile& _IniFile) const;
void Load(IniFile& _IniFile);
@ -61,8 +66,15 @@ class CMemoryWindow
wxTextCtrl* addrbox;
wxTextCtrl* valbox;
DECLARE_EVENT_TABLE()
DECLARE_EVENT_TABLE()
void U8(wxCommandEvent& event);
void U16(wxCommandEvent& event);
void U32(wxCommandEvent& event);
void onSearch(wxCommandEvent& event);
void onAscii(wxCommandEvent& event);
void onHex(wxCommandEvent& event);
void OnSymbolListChange(wxCommandEvent& event);
void OnCallstackListChange(wxCommandEvent& event);
void OnAddrBoxChange(wxCommandEvent& event);