2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:43:35 +00:00
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2008-12-08 05:30:24 +00:00
|
|
|
#include <wx/button.h>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <wx/checkbox.h>
|
|
|
|
#include <wx/listbox.h>
|
|
|
|
#include <wx/msgdlg.h>
|
|
|
|
#include <wx/panel.h>
|
|
|
|
#include <wx/sizer.h>
|
2015-08-03 08:39:06 +00:00
|
|
|
#include <wx/srchctrl.h>
|
2014-02-19 01:56:29 +00:00
|
|
|
#include <wx/textctrl.h>
|
2013-02-28 04:37:38 +00:00
|
|
|
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/FileUtil.h"
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "Common/IniFile.h"
|
|
|
|
#include "Common/StringUtil.h"
|
|
|
|
#include "Common/SymbolDB.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "Core/Debugger/PPCDebugInterface.h"
|
|
|
|
#include "Core/HW/DSP.h"
|
|
|
|
#include "Core/HW/Memmap.h"
|
|
|
|
#include "Core/PowerPC/PowerPC.h"
|
|
|
|
#include "DolphinWX/Globals.h"
|
|
|
|
#include "DolphinWX/WxUtils.h"
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "DolphinWX/Debugger/MemoryView.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "DolphinWX/Debugger/MemoryWindow.h"
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2014-09-21 17:59:20 +00:00
|
|
|
IDM_MEM_ADDRBOX,
|
2008-12-08 05:30:24 +00:00
|
|
|
IDM_SYMBOLLIST,
|
2009-01-21 17:02:01 +00:00
|
|
|
IDM_SETVALBUTTON,
|
|
|
|
IDM_DUMP_MEMORY,
|
2010-10-14 04:07:04 +00:00
|
|
|
IDM_DUMP_MEM2,
|
2012-06-19 11:51:29 +00:00
|
|
|
IDM_DUMP_FAKEVMEM,
|
2009-06-17 19:50:59 +00:00
|
|
|
IDM_VALBOX,
|
2010-07-24 02:36:22 +00:00
|
|
|
IDM_U8,
|
2009-11-25 10:07:56 +00:00
|
|
|
IDM_U16,
|
|
|
|
IDM_U32,
|
|
|
|
IDM_SEARCH,
|
|
|
|
IDM_ASCII,
|
|
|
|
IDM_HEX
|
2008-12-08 05:30:24 +00:00
|
|
|
};
|
|
|
|
|
2009-09-07 20:51:02 +00:00
|
|
|
BEGIN_EVENT_TABLE(CMemoryWindow, wxPanel)
|
2014-02-17 04:51:41 +00:00
|
|
|
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_BUTTON(IDM_DUMP_MEM2, CMemoryWindow::OnDumpMem2)
|
|
|
|
EVT_BUTTON(IDM_DUMP_FAKEVMEM, CMemoryWindow::OnDumpFakeVMEM)
|
|
|
|
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)
|
2008-12-08 05:30:24 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
CMemoryWindow::CMemoryWindow(wxWindow* parent, wxWindowID id,
|
2010-07-22 02:05:28 +00:00
|
|
|
const wxPoint& pos, const wxSize& size, long style, const wxString& name)
|
|
|
|
: wxPanel(parent, id, pos, size, style, name)
|
2010-07-24 02:36:22 +00:00
|
|
|
{
|
2009-06-28 12:15:31 +00:00
|
|
|
DebugInterface* di = &PowerPC::debug_interface;
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2011-02-24 05:05:25 +00:00
|
|
|
memview = new CMemoryView(di, this);
|
2015-07-09 11:47:51 +00:00
|
|
|
|
2015-08-03 08:39:06 +00:00
|
|
|
addrbox = new wxSearchCtrl(this, IDM_MEM_ADDRBOX);
|
|
|
|
addrbox->Bind(wxEVT_TEXT, &CMemoryWindow::OnAddrBoxChange, this);
|
|
|
|
addrbox->SetDescriptiveText(_("Search Address"));
|
|
|
|
|
|
|
|
valbox = new wxTextCtrl(this, IDM_VALBOX, "", wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
|
|
|
|
valbox->Bind(wxEVT_TEXT_ENTER, &CMemoryWindow::SetMemoryValueFromValBox, this);
|
|
|
|
|
2015-08-03 08:56:21 +00:00
|
|
|
wxGridSizer* const search_sizer = new wxGridSizer(1);
|
|
|
|
search_sizer->Add(addrbox);
|
|
|
|
search_sizer->Add(valbox, 0, wxEXPAND);
|
|
|
|
search_sizer->Add(new wxButton(this, IDM_SETVALBUTTON, _("Set Value")));
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2015-08-03 08:56:21 +00:00
|
|
|
wxGridSizer* const dump_sizer = new wxGridSizer(1);
|
|
|
|
dump_sizer->Add(new wxButton(this, IDM_DUMP_MEMORY, _("Dump MRAM")), 0, wxEXPAND);
|
|
|
|
dump_sizer->Add(new wxButton(this, IDM_DUMP_MEM2, _("Dump EXRAM")), 0, wxEXPAND);
|
2015-06-12 11:56:53 +00:00
|
|
|
if (!SConfig::GetInstance().bMMU)
|
2015-08-03 08:56:21 +00:00
|
|
|
dump_sizer->Add(new wxButton(this, IDM_DUMP_FAKEVMEM, _("Dump FakeVMEM")), 0, wxEXPAND);
|
2009-11-25 10:07:56 +00:00
|
|
|
|
2015-08-03 08:56:21 +00:00
|
|
|
wxStaticBoxSizer* const sizerSearchType = new wxStaticBoxSizer(wxVERTICAL, this, _("Search"));
|
2011-01-05 04:35:46 +00:00
|
|
|
sizerSearchType->Add(btnSearch = new wxButton(this, IDM_SEARCH, _("Search")));
|
2015-04-23 03:40:00 +00:00
|
|
|
sizerSearchType->Add(chkAscii = new wxCheckBox(this, IDM_ASCII, "Ascii "));
|
|
|
|
sizerSearchType->Add(chkHex = new wxCheckBox(this, IDM_HEX, _("Hex")));
|
2010-01-16 19:01:00 +00:00
|
|
|
|
2015-08-03 08:56:21 +00:00
|
|
|
wxStaticBoxSizer* const sizerDataTypes = new wxStaticBoxSizer(wxVERTICAL, this, _("Data Type"));
|
2010-07-24 02:36:22 +00:00
|
|
|
sizerDataTypes->SetMinSize(74, 40);
|
2015-04-23 03:40:00 +00:00
|
|
|
sizerDataTypes->Add(chk8 = new wxCheckBox(this, IDM_U8, "U8"));
|
|
|
|
sizerDataTypes->Add(chk16 = new wxCheckBox(this, IDM_U16, "U16"));
|
|
|
|
sizerDataTypes->Add(chk32 = new wxCheckBox(this, IDM_U32, "U32"));
|
2015-08-03 08:56:21 +00:00
|
|
|
|
|
|
|
wxBoxSizer* const sizerRight = new wxBoxSizer(wxVERTICAL);
|
|
|
|
sizerRight->Add(search_sizer);
|
|
|
|
sizerRight->AddSpacer(5);
|
|
|
|
sizerRight->Add(dump_sizer);
|
|
|
|
sizerRight->Add(sizerSearchType);
|
2010-01-16 19:01:00 +00:00
|
|
|
sizerRight->Add(sizerDataTypes);
|
2015-08-03 08:56:21 +00:00
|
|
|
|
|
|
|
wxBoxSizer* const sizerBig = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
sizerBig->Add(memview, 20, wxEXPAND);
|
|
|
|
sizerBig->Add(sizerRight, 0, wxEXPAND | wxALL, 3);
|
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
SetSizer(sizerBig);
|
2010-07-24 02:36:22 +00:00
|
|
|
chkHex->SetValue(1); //Set defaults
|
2009-11-25 10:07:56 +00:00
|
|
|
chk8->SetValue(1);
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
sizerRight->Fit(this);
|
|
|
|
sizerBig->Fit(this);
|
|
|
|
}
|
|
|
|
|
2014-06-16 05:12:43 +00:00
|
|
|
void CMemoryWindow::Save(IniFile& ini) const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
|
|
|
// Prevent these bad values that can happen after a crash or hanging
|
2014-03-10 11:30:55 +00:00
|
|
|
if (GetPosition().x != -32000 && GetPosition().y != -32000)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2014-06-16 05:12:43 +00:00
|
|
|
IniFile::Section* mem_window = ini.GetOrCreateSection("MemoryWindow");
|
|
|
|
mem_window->Set("x", GetPosition().x);
|
|
|
|
mem_window->Set("y", GetPosition().y);
|
|
|
|
mem_window->Set("w", GetSize().GetWidth());
|
|
|
|
mem_window->Set("h", GetSize().GetHeight());
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-16 05:12:43 +00:00
|
|
|
void CMemoryWindow::Load(IniFile& ini)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2010-07-24 02:36:22 +00:00
|
|
|
int x, y, w, h;
|
2014-06-16 05:12:43 +00:00
|
|
|
|
|
|
|
IniFile::Section* mem_window = ini.GetOrCreateSection("MemoryWindow");
|
|
|
|
mem_window->Get("x", &x, GetPosition().x);
|
|
|
|
mem_window->Get("y", &y, GetPosition().y);
|
|
|
|
mem_window->Get("w", &w, GetSize().GetWidth());
|
|
|
|
mem_window->Get("h", &h, GetSize().GetHeight());
|
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
SetSize(x, y, w, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMemoryWindow::JumpToAddress(u32 _Address)
|
|
|
|
{
|
2010-01-16 19:01:00 +00:00
|
|
|
memview->Center(_Address);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2015-04-25 02:19:21 +00:00
|
|
|
void CMemoryWindow::SetMemoryValueFromValBox(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
SetMemoryValue(event);
|
|
|
|
valbox->SetFocus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
void CMemoryWindow::SetMemoryValue(wxCommandEvent& event)
|
|
|
|
{
|
2014-07-19 23:59:44 +00:00
|
|
|
if (!Memory::IsInitialized())
|
|
|
|
{
|
2014-07-25 01:46:46 +00:00
|
|
|
WxUtils::ShowErrorDialog(_("Cannot set uninitialized memory."));
|
2014-07-19 23:59:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-28 04:37:38 +00:00
|
|
|
std::string str_addr = WxStrToStr(addrbox->GetValue());
|
|
|
|
std::string str_val = WxStrToStr(valbox->GetValue());
|
2008-12-08 05:30:24 +00:00
|
|
|
u32 addr;
|
|
|
|
u32 val;
|
|
|
|
|
2010-11-10 04:12:31 +00:00
|
|
|
if (!TryParse(std::string("0x") + str_addr, &addr))
|
2010-07-26 03:46:14 +00:00
|
|
|
{
|
2014-07-25 01:46:46 +00:00
|
|
|
WxUtils::ShowErrorDialog(wxString::Format(_("Invalid address: %s"), str_addr.c_str()));
|
2010-01-16 19:01:00 +00:00
|
|
|
return;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2010-11-10 04:12:31 +00:00
|
|
|
if (!TryParse(std::string("0x") + str_val, &val))
|
2010-07-26 03:46:14 +00:00
|
|
|
{
|
2014-07-25 01:46:46 +00:00
|
|
|
WxUtils::ShowErrorDialog(wxString::Format(_("Invalid value: %s"), str_val.c_str()));
|
2010-01-16 19:01:00 +00:00
|
|
|
return;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2015-01-17 21:17:36 +00:00
|
|
|
PowerPC::HostWrite_U32(val, addr);
|
2008-12-08 05:30:24 +00:00
|
|
|
memview->Refresh();
|
|
|
|
}
|
2009-06-17 19:50:59 +00:00
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
void CMemoryWindow::OnAddrBoxChange(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
wxString txt = addrbox->GetValue();
|
2009-06-17 19:50:59 +00:00
|
|
|
if (txt.size())
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
|
|
|
u32 addr;
|
2013-02-28 04:37:38 +00:00
|
|
|
sscanf(WxStrToStr(txt).c_str(), "%08x", &addr);
|
2009-06-17 19:50:59 +00:00
|
|
|
memview->Center(addr & ~3);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2014-07-11 00:39:26 +00:00
|
|
|
event.Skip();
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMemoryWindow::Update()
|
|
|
|
{
|
|
|
|
memview->Refresh();
|
|
|
|
memview->Center(PC);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMemoryWindow::NotifyMapLoaded()
|
|
|
|
{
|
|
|
|
symbols->Show(false); // hide it for faster filling
|
|
|
|
symbols->Clear();
|
2010-07-24 02:36:22 +00:00
|
|
|
#if 0
|
2010-01-16 19:01:00 +00:00
|
|
|
#ifdef _WIN32
|
2008-12-08 05:30:24 +00:00
|
|
|
const FunctionDB::XFuncMap &syms = g_symbolDB.Symbols();
|
|
|
|
for (FuntionDB::XFuncMap::iterator iter = syms.begin(); iter != syms.end(); ++iter)
|
|
|
|
{
|
2010-01-16 19:01:00 +00:00
|
|
|
int idx = symbols->Append(iter->second.name.c_str());
|
|
|
|
symbols->SetClientData(idx, (void*)&iter->second);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
2010-01-16 19:01:00 +00:00
|
|
|
#endif
|
2010-07-24 02:36:22 +00:00
|
|
|
#endif
|
2008-12-08 05:30:24 +00:00
|
|
|
symbols->Show(true);
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMemoryWindow::OnSymbolListChange(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
int index = symbols->GetSelection();
|
2010-07-24 02:36:22 +00:00
|
|
|
if (index >= 0)
|
2010-07-26 03:46:14 +00:00
|
|
|
{
|
2008-12-08 05:30:24 +00:00
|
|
|
Symbol* pSymbol = static_cast<Symbol *>(symbols->GetClientData(index));
|
2014-03-09 20:14:26 +00:00
|
|
|
if (pSymbol != nullptr)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
|
|
|
memview->Center(pSymbol->address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMemoryWindow::OnHostMessage(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
switch (event.GetId())
|
|
|
|
{
|
2014-12-21 01:36:26 +00:00
|
|
|
case IDM_NOTIFY_MAP_LOADED:
|
2010-07-24 02:36:22 +00:00
|
|
|
NotifyMapLoaded();
|
|
|
|
break;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-08 12:29:26 +00:00
|
|
|
static void DumpArray(const std::string& filename, const u8* data, size_t length)
|
2009-01-21 17:02:01 +00:00
|
|
|
{
|
2011-03-11 10:21:46 +00:00
|
|
|
if (data)
|
2009-01-21 17:02:01 +00:00
|
|
|
{
|
2011-03-11 10:21:46 +00:00
|
|
|
File::IOFile f(filename, "wb");
|
|
|
|
f.WriteBytes(data, length);
|
2010-10-14 04:07:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-11 10:21:46 +00:00
|
|
|
// Write mram to file
|
|
|
|
void CMemoryWindow::OnDumpMemory( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
DumpArray(File::GetUserPath(F_RAMDUMP_IDX), Memory::m_pRAM, Memory::REALRAM_SIZE);
|
|
|
|
}
|
|
|
|
|
2010-10-14 04:07:04 +00:00
|
|
|
// Write exram (aram or mem2) to file
|
|
|
|
void CMemoryWindow::OnDumpMem2( wxCommandEvent& event )
|
2013-10-29 05:23:17 +00:00
|
|
|
{
|
2015-06-12 11:56:53 +00:00
|
|
|
if (SConfig::GetInstance().bWii)
|
2010-10-14 04:07:04 +00:00
|
|
|
{
|
2011-03-11 10:21:46 +00:00
|
|
|
DumpArray(File::GetUserPath(F_ARAMDUMP_IDX), Memory::m_pEXRAM, Memory::EXRAM_SIZE);
|
2010-10-14 04:07:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-11 10:21:46 +00:00
|
|
|
DumpArray(File::GetUserPath(F_ARAMDUMP_IDX), DSP::GetARAMPtr(), DSP::ARAM_SIZE);
|
2010-07-24 02:36:22 +00:00
|
|
|
}
|
2009-06-30 21:11:39 +00:00
|
|
|
}
|
2009-11-25 10:07:56 +00:00
|
|
|
|
2012-06-19 11:51:29 +00:00
|
|
|
// Write fake vmem to file
|
|
|
|
void CMemoryWindow::OnDumpFakeVMEM( wxCommandEvent& event )
|
|
|
|
{
|
2014-10-28 10:57:28 +00:00
|
|
|
DumpArray(File::GetUserPath(F_FAKEVMEMDUMP_IDX), Memory::m_pFakeVMEM, Memory::FAKEVMEM_SIZE);
|
2012-06-19 11:51:29 +00:00
|
|
|
}
|
|
|
|
|
2010-07-24 02:36:22 +00:00
|
|
|
void CMemoryWindow::U8(wxCommandEvent& event)
|
|
|
|
{
|
2010-01-16 19:01:00 +00:00
|
|
|
chk16->SetValue(0);
|
|
|
|
chk32->SetValue(0);
|
2015-07-09 11:47:51 +00:00
|
|
|
memview->SetDataType(MemoryDataType::U8);
|
2009-11-25 10:07:56 +00:00
|
|
|
}
|
2010-07-24 02:36:22 +00:00
|
|
|
|
|
|
|
void CMemoryWindow::U16(wxCommandEvent& event)
|
|
|
|
{
|
2010-01-16 19:01:00 +00:00
|
|
|
chk8->SetValue(0);
|
|
|
|
chk32->SetValue(0);
|
2015-07-09 11:47:51 +00:00
|
|
|
memview->SetDataType(MemoryDataType::U16);
|
2009-11-25 10:07:56 +00:00
|
|
|
}
|
2010-07-24 02:36:22 +00:00
|
|
|
|
|
|
|
void CMemoryWindow::U32(wxCommandEvent& event)
|
|
|
|
{
|
2010-01-16 19:01:00 +00:00
|
|
|
chk16->SetValue(0);
|
|
|
|
chk8->SetValue(0);
|
2015-07-09 11:47:51 +00:00
|
|
|
memview->SetDataType(MemoryDataType::U32);
|
2009-11-25 10:07:56 +00:00
|
|
|
}
|
|
|
|
|
2010-07-24 02:36:22 +00:00
|
|
|
void CMemoryWindow::onSearch(wxCommandEvent& event)
|
|
|
|
{
|
2014-03-09 20:14:26 +00:00
|
|
|
u8* TheRAM = nullptr;
|
2010-07-24 02:36:22 +00:00
|
|
|
u32 szRAM = 0;
|
2009-11-25 10:07:56 +00:00
|
|
|
switch (memview->GetMemoryType())
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
default:
|
2010-01-16 19:01:00 +00:00
|
|
|
if (Memory::m_pRAM)
|
2009-11-25 10:07:56 +00:00
|
|
|
{
|
2010-07-24 02:36:22 +00:00
|
|
|
TheRAM = Memory::m_pRAM;
|
|
|
|
szRAM = Memory::REALRAM_SIZE;
|
2009-11-25 10:07:56 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
{
|
2010-01-16 19:01:00 +00:00
|
|
|
u8* aram = DSP::GetARAMPtr();
|
|
|
|
if (aram)
|
|
|
|
{
|
2010-07-24 02:36:22 +00:00
|
|
|
TheRAM = aram;
|
|
|
|
szRAM = DSP::ARAM_SIZE;
|
2010-01-16 19:01:00 +00:00
|
|
|
}
|
2009-11-25 10:07:56 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
//Now we have memory to look in
|
|
|
|
//Are we looking for ASCII string, or hex?
|
|
|
|
//memview->cu
|
2010-07-24 02:36:22 +00:00
|
|
|
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 int i = 0;
|
|
|
|
long count = 0;
|
|
|
|
char copy[3] = {0};
|
|
|
|
long newsize = 0;
|
2014-03-09 20:14:26 +00:00
|
|
|
unsigned char *tmp2 = nullptr;
|
|
|
|
char* tmpstr = nullptr;
|
2011-01-27 05:01:00 +00:00
|
|
|
|
|
|
|
if (chkHex->GetValue())
|
2010-07-24 02:36:22 +00:00
|
|
|
{
|
2011-01-27 05:01:00 +00:00
|
|
|
//We are looking for hex
|
2010-01-16 19:01:00 +00:00
|
|
|
//If it's uneven
|
2010-07-24 02:36:22 +00:00
|
|
|
size = (rawData.size()/2) + pad;
|
2010-01-16 19:01:00 +00:00
|
|
|
Dest.resize(size+32);
|
2010-07-24 02:36:22 +00:00
|
|
|
newsize = rawData.size();
|
2010-01-16 19:01:00 +00:00
|
|
|
|
2010-07-24 02:36:22 +00:00
|
|
|
if (pad)
|
2013-04-08 05:16:50 +00:00
|
|
|
{
|
2010-01-16 19:01:00 +00:00
|
|
|
tmpstr = new char[newsize + 2];
|
|
|
|
memset(tmpstr, 0, newsize + 2);
|
2010-07-24 02:36:22 +00:00
|
|
|
tmpstr[0] = '0';
|
|
|
|
}
|
2013-04-08 05:16:50 +00:00
|
|
|
else
|
|
|
|
{
|
2010-01-16 19:01:00 +00:00
|
|
|
tmpstr = new char[newsize + 1];
|
|
|
|
memset(tmpstr, 0, newsize + 1);
|
2009-11-25 10:07:56 +00:00
|
|
|
}
|
2014-02-12 15:00:34 +00:00
|
|
|
strcat(tmpstr, WxStrToStr(rawData).c_str());
|
2010-07-24 02:36:22 +00:00
|
|
|
tmp2 = &Dest.front();
|
|
|
|
count = 0;
|
2014-03-10 11:30:55 +00:00
|
|
|
for (i = 0; i < strlen(tmpstr); i++)
|
2010-07-24 02:36:22 +00:00
|
|
|
{
|
|
|
|
copy[0] = tmpstr[i];
|
|
|
|
copy[1] = tmpstr[i+1];
|
|
|
|
copy[2] = 0;
|
2010-01-16 19:01:00 +00:00
|
|
|
int tmpint;
|
|
|
|
sscanf(copy, "%02x", &tmpint);
|
|
|
|
tmp2[count++] = tmpint;
|
2010-07-24 02:36:22 +00:00
|
|
|
// 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
|
|
|
|
//sscanf(copy, "%02x", &tmp2[count++]);
|
|
|
|
i += 1;
|
2010-01-16 19:01:00 +00:00
|
|
|
}
|
|
|
|
delete[] tmpstr;
|
2013-04-08 05:16:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-27 05:01:00 +00:00
|
|
|
//Looking for an ascii string
|
2010-07-24 02:36:22 +00:00
|
|
|
size = rawData.size();
|
2010-01-16 19:01:00 +00:00
|
|
|
Dest.resize(size+1);
|
2010-07-24 02:36:22 +00:00
|
|
|
tmpstr = new char[size+1];
|
2009-11-25 10:07:56 +00:00
|
|
|
|
2010-07-24 02:36:22 +00:00
|
|
|
tmp2 = &Dest.front();
|
2013-02-28 04:37:38 +00:00
|
|
|
sprintf(tmpstr, "%s", WxStrToStr(rawData).c_str());
|
2010-07-24 02:36:22 +00:00
|
|
|
|
2014-03-10 11:30:55 +00:00
|
|
|
for (i = 0; i < size; i++)
|
2010-07-24 02:36:22 +00:00
|
|
|
tmp2[i] = tmpstr[i];
|
2010-01-16 19:01:00 +00:00
|
|
|
|
|
|
|
delete[] tmpstr;
|
2009-11-25 10:07:56 +00:00
|
|
|
}
|
2011-01-27 05:01:00 +00:00
|
|
|
|
2014-03-10 11:30:55 +00:00
|
|
|
if (size)
|
2010-07-24 02:36:22 +00:00
|
|
|
{
|
|
|
|
unsigned char* pnt = &Dest.front();
|
|
|
|
unsigned int k = 0;
|
|
|
|
//grab
|
2010-01-16 19:01:00 +00:00
|
|
|
wxString txt = addrbox->GetValue();
|
2010-07-24 02:36:22 +00:00
|
|
|
u32 addr = 0;
|
2010-01-16 19:01:00 +00:00
|
|
|
if (txt.size())
|
|
|
|
{
|
2013-02-28 04:37:38 +00:00
|
|
|
sscanf(WxStrToStr(txt).c_str(), "%08x", &addr);
|
2010-01-16 19:01:00 +00:00
|
|
|
}
|
2010-07-24 02:36:22 +00:00
|
|
|
i = addr+4;
|
2014-03-10 11:30:55 +00:00
|
|
|
for ( ; i < szRAM; ++i)
|
2010-07-24 02:36:22 +00:00
|
|
|
{
|
2014-03-10 11:30:55 +00:00
|
|
|
for (k = 0; k < size; ++k)
|
2010-07-24 02:36:22 +00:00
|
|
|
{
|
2014-03-10 11:30:55 +00:00
|
|
|
if (i + k > szRAM) break;
|
|
|
|
if (k > size) break;
|
|
|
|
if (pnt[k] != TheRAM[i+k])
|
2010-07-24 02:36:22 +00:00
|
|
|
{
|
|
|
|
k = 0;
|
2009-11-25 10:07:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-03-10 11:30:55 +00:00
|
|
|
if (k == size)
|
2010-07-24 02:36:22 +00:00
|
|
|
{
|
2009-11-25 10:07:56 +00:00
|
|
|
//Match was found
|
2011-01-05 04:35:46 +00:00
|
|
|
wxMessageBox(_("A match was found. Placing viewer at the offset."));
|
2014-12-12 15:29:07 +00:00
|
|
|
addrbox->SetValue(wxString::Format("%08x", i));
|
2010-07-24 02:36:22 +00:00
|
|
|
//memview->curAddress = i;
|
2009-11-25 10:07:56 +00:00
|
|
|
//memview->Refresh();
|
|
|
|
OnAddrBoxChange(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-01-05 04:35:46 +00:00
|
|
|
wxMessageBox(_("No match was found."));
|
2009-11-25 10:07:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-24 02:36:22 +00:00
|
|
|
void CMemoryWindow::onAscii(wxCommandEvent& event)
|
|
|
|
{
|
2010-01-16 19:01:00 +00:00
|
|
|
chkHex->SetValue(0);
|
2009-11-25 10:07:56 +00:00
|
|
|
}
|
|
|
|
|
2010-07-24 02:36:22 +00:00
|
|
|
void CMemoryWindow::onHex(wxCommandEvent& event)
|
|
|
|
{
|
2010-01-16 19:01:00 +00:00
|
|
|
chkAscii->SetValue(0);
|
2009-12-15 14:40:03 +00:00
|
|
|
}
|