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

@ -48,14 +48,26 @@ 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)
EVT_TEXT(IDM_MEM_ADDRBOX, CMemoryWindow::OnAddrBoxChange)
EVT_LISTBOX(IDM_SYMBOLLIST, CMemoryWindow::OnSymbolListChange)
EVT_HOST_COMMAND(wxID_ANY, CMemoryWindow::OnHostMessage)
EVT_BUTTON(IDM_SETVALBUTTON, CMemoryWindow::SetMemoryValue)
EVT_BUTTON(IDM_DUMP_MEMORY, CMemoryWindow::OnDumpMemory)
EVT_LISTBOX(IDM_SYMBOLLIST, CMemoryWindow::OnSymbolListChange)
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);
}