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
|
|
|
|
2016-10-03 07:29:50 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <array>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdio>
|
|
|
|
#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>
|
2016-10-03 07:29:50 +00:00
|
|
|
#include <wx/radiobox.h>
|
2016-08-18 20:08:26 +00:00
|
|
|
#include <wx/radiobut.h>
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <wx/sizer.h>
|
2015-08-03 08:39:06 +00:00
|
|
|
#include <wx/srchctrl.h>
|
2016-10-03 07:29:50 +00:00
|
|
|
#include <wx/stattext.h>
|
2014-02-19 01:56:29 +00:00
|
|
|
#include <wx/textctrl.h>
|
2016-10-03 07:29:50 +00:00
|
|
|
#include <wx/utils.h>
|
2013-02-28 04:37:38 +00:00
|
|
|
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2017-01-15 20:46:32 +00:00
|
|
|
#include "Common/File.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"
|
2016-08-11 18:24:10 +00:00
|
|
|
#include "DolphinWX/Debugger/BreakpointWindow.h"
|
|
|
|
#include "DolphinWX/Debugger/CodeWindow.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"
|
2016-06-24 08:43:46 +00:00
|
|
|
#include "DolphinWX/Globals.h"
|
|
|
|
#include "DolphinWX/WxUtils.h"
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2017-04-30 06:44:27 +00:00
|
|
|
IDM_ADDRESS_SEARCH_CTRL,
|
|
|
|
IDM_SYMBOL_LIST,
|
|
|
|
IDM_SET_VALUE_BUTTON,
|
2016-06-24 08:43:46 +00:00
|
|
|
IDM_DUMP_MEMORY,
|
|
|
|
IDM_DUMP_MEM2,
|
|
|
|
IDM_DUMP_FAKEVMEM,
|
2017-04-30 06:44:27 +00:00
|
|
|
IDM_VALUE_TEXT_CTRL,
|
2016-10-03 07:29:50 +00:00
|
|
|
IDM_DATA_TYPE_RBOX,
|
2017-04-18 18:08:44 +00:00
|
|
|
IDM_FIND_NEXT,
|
2017-04-18 20:12:15 +00:00
|
|
|
IDM_FIND_PREVIOUS,
|
2016-06-24 08:43:46 +00:00
|
|
|
IDM_ASCII,
|
2016-08-18 20:08:26 +00:00
|
|
|
IDM_HEX,
|
|
|
|
IDM_MEMCHECK_OPTIONS_CHANGE
|
2008-12-08 05:30:24 +00:00
|
|
|
};
|
|
|
|
|
2016-10-03 07:29:50 +00:00
|
|
|
CMemoryWindow::CMemoryWindow(wxWindow* parent, wxWindowID id, 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
|
|
|
{
|
2017-04-30 07:55:55 +00:00
|
|
|
CreateGUI();
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-04-30 07:55:55 +00:00
|
|
|
void CMemoryWindow::CreateGUI()
|
|
|
|
{
|
|
|
|
m_memory_view = new CMemoryView(&PowerPC::debug_interface, this);
|
2017-04-30 06:44:27 +00:00
|
|
|
m_memory_view->Bind(DOLPHIN_EVT_MEMORY_VIEW_DATA_TYPE_CHANGED, &CMemoryWindow::OnDataTypeChanged,
|
|
|
|
this);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-04-30 07:55:55 +00:00
|
|
|
const int space3 = FromDIP(3);
|
|
|
|
|
|
|
|
wxBoxSizer* const main_sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
main_sizer->Add(m_memory_view, 20, wxEXPAND);
|
|
|
|
main_sizer->AddSpacer(space3);
|
|
|
|
main_sizer->Add(CreateRightHandSideSizer(), 0, wxEXPAND | wxTOP | wxBOTTOM, space3);
|
|
|
|
main_sizer->AddSpacer(space3);
|
|
|
|
|
|
|
|
SetSizerAndFit(main_sizer);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxSizer* CMemoryWindow::CreateRightHandSideSizer()
|
|
|
|
{
|
|
|
|
wxArrayString data_type_options;
|
|
|
|
data_type_options.Add("U8");
|
|
|
|
data_type_options.Add("U16");
|
|
|
|
data_type_options.Add("U32");
|
|
|
|
data_type_options.Add("ASCII");
|
|
|
|
data_type_options.Add("Float32");
|
|
|
|
m_rbox_data_type = new wxRadioBox(this, IDM_DATA_TYPE_RBOX, _("Data Type"), wxDefaultPosition,
|
|
|
|
wxDefaultSize, data_type_options, 1);
|
2017-04-30 08:43:55 +00:00
|
|
|
m_rbox_data_type->Bind(wxEVT_RADIOBOX, &CMemoryWindow::OnDataTypeChanged, this);
|
2017-04-30 07:55:55 +00:00
|
|
|
m_rbox_data_type->SetSelection(static_cast<int>(m_memory_view->GetDataType()));
|
|
|
|
|
|
|
|
const int space5 = FromDIP(5);
|
|
|
|
|
|
|
|
auto* const right_sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
right_sizer->Add(CreateSearchSizer(), 0, wxEXPAND);
|
|
|
|
right_sizer->AddSpacer(space5);
|
|
|
|
right_sizer->Add(CreateDumpSizer(), 0, wxEXPAND);
|
|
|
|
right_sizer->Add(CreateSearchTypeSizer(), 0, wxEXPAND);
|
|
|
|
right_sizer->Add(m_rbox_data_type, 0, wxEXPAND);
|
|
|
|
right_sizer->Add(CreateMemcheckOptionSizer(), 0, wxEXPAND);
|
|
|
|
|
|
|
|
return right_sizer;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxSizer* CMemoryWindow::CreateSearchSizer()
|
|
|
|
{
|
2017-04-30 06:44:27 +00:00
|
|
|
m_address_search_ctrl = new wxSearchCtrl(this, IDM_ADDRESS_SEARCH_CTRL);
|
|
|
|
m_address_search_ctrl->Bind(wxEVT_TEXT, &CMemoryWindow::OnSearchAddressChanged, this);
|
|
|
|
m_address_search_ctrl->SetDescriptiveText(_("Search Address"));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-04-30 06:44:27 +00:00
|
|
|
m_value_text_ctrl = new wxTextCtrl(this, IDM_VALUE_TEXT_CTRL, "", wxDefaultPosition,
|
|
|
|
wxDefaultSize, wxTE_PROCESS_ENTER);
|
|
|
|
m_value_text_ctrl->Bind(wxEVT_TEXT_ENTER, &CMemoryWindow::OnSetMemoryValueFromValBox, this);
|
|
|
|
m_value_text_ctrl->Bind(wxEVT_TEXT, &CMemoryWindow::OnValueChanged, this);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-04-30 07:55:55 +00:00
|
|
|
auto* const set_value_button = new wxButton(this, IDM_SET_VALUE_BUTTON, _("Set Value"));
|
2017-04-30 08:43:55 +00:00
|
|
|
set_value_button->Bind(wxEVT_BUTTON, &CMemoryWindow::OnSetMemoryValue, this);
|
2016-10-03 07:29:50 +00:00
|
|
|
|
2017-04-30 07:55:55 +00:00
|
|
|
auto* const search_sizer = new wxBoxSizer(wxVERTICAL);
|
2017-04-30 06:44:27 +00:00
|
|
|
search_sizer->Add(m_address_search_ctrl, 0, wxEXPAND);
|
|
|
|
search_sizer->Add(m_value_text_ctrl, 0, wxEXPAND);
|
2017-04-30 07:55:55 +00:00
|
|
|
search_sizer->Add(set_value_button);
|
|
|
|
|
|
|
|
return search_sizer;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxSizer* CMemoryWindow::CreateDumpSizer()
|
|
|
|
{
|
|
|
|
auto* const dump_mram_button = new wxButton(this, IDM_DUMP_MEMORY, _("Dump MRAM"));
|
2017-04-30 08:43:55 +00:00
|
|
|
dump_mram_button->Bind(wxEVT_BUTTON, &CMemoryWindow::OnDumpMemory, this);
|
|
|
|
|
2017-04-30 07:55:55 +00:00
|
|
|
auto* const dump_exram_button = new wxButton(this, IDM_DUMP_MEM2, _("Dump EXRAM"));
|
2017-04-30 08:43:55 +00:00
|
|
|
dump_exram_button->Bind(wxEVT_BUTTON, &CMemoryWindow::OnDumpMem2, this);
|
2017-04-30 07:55:55 +00:00
|
|
|
|
|
|
|
auto* const dump_sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
dump_sizer->Add(dump_mram_button, 0, wxEXPAND);
|
|
|
|
dump_sizer->Add(dump_exram_button, 0, wxEXPAND);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
if (!SConfig::GetInstance().bMMU)
|
2017-04-30 07:55:55 +00:00
|
|
|
{
|
|
|
|
auto* const dump_fake_vmem_button = new wxButton(this, IDM_DUMP_FAKEVMEM, _("Dump FakeVMEM"));
|
2017-04-30 08:43:55 +00:00
|
|
|
dump_fake_vmem_button->Bind(wxEVT_BUTTON, &CMemoryWindow::OnDumpFakeVMEM, this);
|
2017-04-30 07:55:55 +00:00
|
|
|
|
|
|
|
dump_sizer->Add(dump_fake_vmem_button, 0, wxEXPAND);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dump_sizer;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxSizer* CMemoryWindow::CreateSearchTypeSizer()
|
|
|
|
{
|
|
|
|
m_btn_find_next = new wxButton(this, IDM_FIND_NEXT, _("Find Next"));
|
2017-04-30 08:43:55 +00:00
|
|
|
m_btn_find_next->Bind(wxEVT_BUTTON, &CMemoryWindow::OnFindNext, this);
|
|
|
|
|
2017-04-30 07:55:55 +00:00
|
|
|
m_btn_find_previous = new wxButton(this, IDM_FIND_PREVIOUS, _("Find Previous"));
|
2017-04-30 08:43:55 +00:00
|
|
|
m_btn_find_previous->Bind(wxEVT_BUTTON, &CMemoryWindow::OnFindPrevious, this);
|
2017-04-30 07:55:55 +00:00
|
|
|
|
|
|
|
m_rb_ascii =
|
|
|
|
new wxRadioButton(this, IDM_ASCII, "Ascii", wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
|
|
|
|
m_rb_hex = new wxRadioButton(this, IDM_HEX, _("Hex"));
|
|
|
|
m_rb_hex->SetValue(true);
|
|
|
|
|
2016-10-03 07:29:50 +00:00
|
|
|
m_search_result_msg =
|
|
|
|
new wxStaticText(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxST_NO_AUTORESIZE | wxALIGN_CENTER_HORIZONTAL);
|
|
|
|
|
2017-04-30 07:55:55 +00:00
|
|
|
auto* const search_type_sizer = new wxStaticBoxSizer(wxVERTICAL, this, _("Search"));
|
|
|
|
search_type_sizer->Add(m_btn_find_next);
|
|
|
|
search_type_sizer->Add(m_btn_find_previous);
|
|
|
|
search_type_sizer->Add(m_rb_ascii);
|
|
|
|
search_type_sizer->Add(m_rb_hex);
|
|
|
|
search_type_sizer->Add(m_search_result_msg, 0, wxEXPAND);
|
2016-10-03 07:29:50 +00:00
|
|
|
|
2017-04-30 07:55:55 +00:00
|
|
|
return search_type_sizer;
|
|
|
|
}
|
2017-04-30 06:44:27 +00:00
|
|
|
|
2017-04-30 07:55:55 +00:00
|
|
|
wxSizer* CMemoryWindow::CreateMemcheckOptionSizer()
|
|
|
|
{
|
2017-05-06 13:38:53 +00:00
|
|
|
// i18n: This string is used for a radio button that represents the type of
|
|
|
|
// memory breakpoint that gets triggered when a read operation or write operation occurs.
|
|
|
|
// The string is not a command to read and write something or to allow reading and writing.
|
|
|
|
m_read_write_radio_btn = new wxRadioButton(this, IDM_MEMCHECK_OPTIONS_CHANGE, _("Read and write"),
|
2017-04-30 07:55:55 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
|
2017-04-30 08:43:55 +00:00
|
|
|
m_read_write_radio_btn->Bind(wxEVT_RADIOBUTTON, &CMemoryWindow::OnMemCheckOptionChange, this);
|
|
|
|
|
2017-05-06 13:38:53 +00:00
|
|
|
// i18n: This string is used for a radio button that represents the type of
|
|
|
|
// memory breakpoint that gets triggered when a read operation occurs.
|
|
|
|
// The string does not mean "read-only" in the sense that something cannot be written to.
|
2017-04-30 07:55:55 +00:00
|
|
|
m_read_radio_btn = new wxRadioButton(this, IDM_MEMCHECK_OPTIONS_CHANGE, _("Read only"));
|
2017-04-30 08:43:55 +00:00
|
|
|
m_read_radio_btn->Bind(wxEVT_RADIOBUTTON, &CMemoryWindow::OnMemCheckOptionChange, this);
|
|
|
|
|
2017-05-06 13:38:53 +00:00
|
|
|
// i18n: This string is used for a radio button that represents the type of
|
|
|
|
// memory breakpoint that gets triggered when a write operation occurs.
|
|
|
|
// The string does not mean "write-only" in the sense that something cannot be read from.
|
2017-04-30 07:55:55 +00:00
|
|
|
m_write_radio_btn = new wxRadioButton(this, IDM_MEMCHECK_OPTIONS_CHANGE, _("Write only"));
|
2017-04-30 08:43:55 +00:00
|
|
|
m_write_radio_btn->Bind(wxEVT_RADIOBUTTON, &CMemoryWindow::OnMemCheckOptionChange, this);
|
2017-04-30 06:44:27 +00:00
|
|
|
|
2017-04-30 07:55:55 +00:00
|
|
|
m_log_checkbox = new wxCheckBox(this, IDM_MEMCHECK_OPTIONS_CHANGE, _("Log"));
|
2017-04-30 08:43:55 +00:00
|
|
|
m_log_checkbox->Bind(wxEVT_CHECKBOX, &CMemoryWindow::OnMemCheckOptionChange, this);
|
2017-04-30 06:44:27 +00:00
|
|
|
m_log_checkbox->SetValue(true);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-04-30 07:55:55 +00:00
|
|
|
auto* const memcheck_options_sizer =
|
|
|
|
new wxStaticBoxSizer(wxVERTICAL, this, _("Memory breakpoint options"));
|
|
|
|
memcheck_options_sizer->Add(m_read_write_radio_btn);
|
|
|
|
memcheck_options_sizer->Add(m_read_radio_btn);
|
|
|
|
memcheck_options_sizer->Add(m_write_radio_btn);
|
|
|
|
memcheck_options_sizer->Add(m_log_checkbox);
|
|
|
|
|
|
|
|
return memcheck_options_sizer;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2017-04-30 06:44:27 +00:00
|
|
|
void CMemoryWindow::JumpToAddress(u32 address)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2017-04-30 06:44:27 +00:00
|
|
|
m_memory_view->Center(address);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2017-04-30 06:44:27 +00:00
|
|
|
void CMemoryWindow::OnSetMemoryValueFromValBox(wxCommandEvent& event)
|
2015-04-25 02:19:21 +00:00
|
|
|
{
|
2017-04-30 06:44:27 +00:00
|
|
|
OnSetMemoryValue(event);
|
|
|
|
m_value_text_ctrl->SetFocus();
|
2015-04-25 02:19:21 +00:00
|
|
|
}
|
|
|
|
|
2017-04-30 06:44:27 +00:00
|
|
|
void CMemoryWindow::OnSetMemoryValue(wxCommandEvent& event)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (!Memory::IsInitialized())
|
|
|
|
{
|
|
|
|
WxUtils::ShowErrorDialog(_("Cannot set uninitialized memory."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-30 06:44:27 +00:00
|
|
|
std::string str_addr = WxStrToStr(m_address_search_ctrl->GetValue());
|
2016-06-24 08:43:46 +00:00
|
|
|
u32 addr;
|
2017-04-30 07:04:50 +00:00
|
|
|
if (!TryParse("0x" + str_addr, &addr))
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
WxUtils::ShowErrorDialog(wxString::Format(_("Invalid address: %s"), str_addr.c_str()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-30 07:04:50 +00:00
|
|
|
std::string str_val = WxStrToStr(m_value_text_ctrl->GetValue());
|
|
|
|
u32 val;
|
|
|
|
if (!TryParse("0x" + str_val, &val))
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
WxUtils::ShowErrorDialog(wxString::Format(_("Invalid value: %s"), str_val.c_str()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PowerPC::HostWrite_U32(val, addr);
|
2017-04-30 06:44:27 +00:00
|
|
|
m_memory_view->Refresh();
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
2009-06-17 19:50:59 +00:00
|
|
|
|
2017-04-30 06:44:27 +00:00
|
|
|
void CMemoryWindow::OnSearchAddressChanged(wxCommandEvent& event)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2017-04-30 06:44:27 +00:00
|
|
|
wxString txt = m_address_search_ctrl->GetValue();
|
2016-06-24 08:43:46 +00:00
|
|
|
if (txt.size())
|
|
|
|
{
|
|
|
|
u32 addr;
|
|
|
|
sscanf(WxStrToStr(txt).c_str(), "%08x", &addr);
|
2017-04-30 06:44:27 +00:00
|
|
|
m_memory_view->Center(addr & ~3);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip();
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 07:29:50 +00:00
|
|
|
void CMemoryWindow::Repopulate()
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2017-04-30 06:44:27 +00:00
|
|
|
m_memory_view->Center(PC);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 07:29:50 +00:00
|
|
|
void CMemoryWindow::OnValueChanged(wxCommandEvent&)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-10-03 07:29:50 +00:00
|
|
|
m_continue_search = false;
|
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
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
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
|
2016-06-24 08:43:46 +00:00
|
|
|
void CMemoryWindow::OnDumpMemory(wxCommandEvent& event)
|
2011-03-11 10:21:46 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
DumpArray(File::GetUserPath(F_RAMDUMP_IDX), Memory::m_pRAM, Memory::REALRAM_SIZE);
|
2011-03-11 10:21:46 +00:00
|
|
|
}
|
|
|
|
|
2010-10-14 04:07:04 +00:00
|
|
|
// Write exram (aram or mem2) to file
|
2016-06-24 08:43:46 +00:00
|
|
|
void CMemoryWindow::OnDumpMem2(wxCommandEvent& event)
|
2013-10-29 05:23:17 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (SConfig::GetInstance().bWii)
|
|
|
|
{
|
|
|
|
DumpArray(File::GetUserPath(F_ARAMDUMP_IDX), Memory::m_pEXRAM, Memory::EXRAM_SIZE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DumpArray(File::GetUserPath(F_ARAMDUMP_IDX), DSP::GetARAMPtr(), DSP::ARAM_SIZE);
|
|
|
|
}
|
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
|
2016-06-24 08:43:46 +00:00
|
|
|
void CMemoryWindow::OnDumpFakeVMEM(wxCommandEvent& event)
|
2012-06-19 11:51:29 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
DumpArray(File::GetUserPath(F_FAKEVMEMDUMP_IDX), Memory::m_pFakeVMEM, Memory::FAKEVMEM_SIZE);
|
2012-06-19 11:51:29 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 07:29:50 +00:00
|
|
|
void CMemoryWindow::OnDataTypeChanged(wxCommandEvent& ev)
|
2010-07-24 02:36:22 +00:00
|
|
|
{
|
2016-10-03 07:29:50 +00:00
|
|
|
static constexpr std::array<MemoryDataType, 5> map{{MemoryDataType::U8, MemoryDataType::U16,
|
|
|
|
MemoryDataType::U32, MemoryDataType::ASCII,
|
|
|
|
MemoryDataType::FloatingPoint}};
|
|
|
|
if (ev.GetId() == IDM_DATA_TYPE_RBOX)
|
|
|
|
{
|
2017-04-30 06:44:27 +00:00
|
|
|
m_memory_view->SetDataType(map.at(ev.GetSelection()));
|
2016-10-03 07:29:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Event from the CMemoryView indicating type was changed.
|
|
|
|
auto itr = std::find(map.begin(), map.end(), static_cast<MemoryDataType>(ev.GetInt()));
|
|
|
|
int idx = -1;
|
|
|
|
if (itr != map.end())
|
|
|
|
idx = static_cast<int>(itr - map.begin());
|
|
|
|
m_rbox_data_type->SetSelection(idx);
|
|
|
|
}
|
2009-11-25 10:07:56 +00:00
|
|
|
}
|
|
|
|
|
2017-04-18 18:08:44 +00:00
|
|
|
void CMemoryWindow::OnFindNext(wxCommandEvent& event)
|
2010-07-24 02:36:22 +00:00
|
|
|
{
|
2016-10-03 07:29:50 +00:00
|
|
|
wxBusyCursor hourglass_cursor;
|
2017-04-18 20:12:15 +00:00
|
|
|
Search(SearchType::FindNext);
|
2017-04-18 18:08:44 +00:00
|
|
|
}
|
|
|
|
|
2017-04-18 20:12:15 +00:00
|
|
|
void CMemoryWindow::OnFindPrevious(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
wxBusyCursor hourglass_cursor;
|
|
|
|
Search(SearchType::FindPrevious);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMemoryWindow::Search(SearchType search_type)
|
2017-04-18 18:08:44 +00:00
|
|
|
{
|
2016-10-03 07:29:50 +00:00
|
|
|
u8* ram_ptr = nullptr;
|
2017-04-18 20:12:15 +00:00
|
|
|
std::size_t ram_size = 0;
|
2017-08-12 17:21:22 +00:00
|
|
|
u32 base_address = 0;
|
2017-04-30 06:44:27 +00:00
|
|
|
switch (m_memory_view->GetMemoryType())
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
default:
|
|
|
|
if (Memory::m_pRAM)
|
|
|
|
{
|
2016-10-03 07:29:50 +00:00
|
|
|
ram_ptr = Memory::m_pRAM;
|
|
|
|
ram_size = Memory::REALRAM_SIZE;
|
2017-08-12 17:21:22 +00:00
|
|
|
base_address = 0x80000000;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
u8* aram = DSP::GetARAMPtr();
|
|
|
|
if (aram)
|
|
|
|
{
|
2016-10-03 07:29:50 +00:00
|
|
|
ram_ptr = aram;
|
|
|
|
ram_size = DSP::ARAM_SIZE;
|
2017-08-12 17:21:22 +00:00
|
|
|
base_address = 0x0c005000;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-10-03 07:29:50 +00:00
|
|
|
if (!ram_ptr)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2016-10-03 07:29:50 +00:00
|
|
|
m_search_result_msg->SetLabel(_("Memory Not Ready"));
|
|
|
|
return;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-10-03 07:29:50 +00:00
|
|
|
std::vector<u8> search_bytes;
|
2017-04-30 06:44:27 +00:00
|
|
|
wxString search_val = m_value_text_ctrl->GetValue();
|
2016-10-03 07:29:50 +00:00
|
|
|
|
|
|
|
if (m_rb_hex->GetValue())
|
|
|
|
{
|
|
|
|
search_val.Trim(true).Trim(false);
|
|
|
|
// If there's a trailing nybble, stick a zero in front to make it a byte
|
|
|
|
if (search_val.size() & 1)
|
|
|
|
search_val.insert(0, 1, '0');
|
|
|
|
search_bytes.reserve(search_val.size() / 2);
|
|
|
|
|
|
|
|
wxString conversion_buffer(2, ' ');
|
|
|
|
for (std::size_t i = 0; i < search_val.size(); i += 2)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2016-10-03 07:29:50 +00:00
|
|
|
unsigned long byte = 0;
|
|
|
|
conversion_buffer[0] = search_val[i];
|
|
|
|
conversion_buffer[1] = search_val[i + 1];
|
|
|
|
if (!conversion_buffer.ToULong(&byte, 16))
|
|
|
|
{
|
|
|
|
m_search_result_msg->SetLabel(_("Not Valid Hex"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
search_bytes.push_back(static_cast<u8>(byte));
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-03 07:29:50 +00:00
|
|
|
const auto& bytes = search_val.ToUTF8();
|
|
|
|
search_bytes.assign(bytes.data(), bytes.data() + bytes.length());
|
|
|
|
}
|
|
|
|
search_val.Clear();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-10-03 07:29:50 +00:00
|
|
|
// For completeness
|
|
|
|
if (search_bytes.size() > ram_size)
|
|
|
|
{
|
|
|
|
m_search_result_msg->SetLabel(_("Value Too Large"));
|
|
|
|
return;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-10-03 07:29:50 +00:00
|
|
|
if (search_bytes.empty())
|
|
|
|
{
|
|
|
|
m_search_result_msg->SetLabel(_("No Value Given"));
|
|
|
|
return;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 07:29:50 +00:00
|
|
|
// Search starting from specified address if there is one.
|
2017-08-12 17:21:22 +00:00
|
|
|
u32 addr = 0; // Physical address
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2017-04-30 06:44:27 +00:00
|
|
|
wxString addr_val = m_address_search_ctrl->GetValue();
|
2016-10-03 07:29:50 +00:00
|
|
|
addr_val.Trim(true).Trim(false);
|
|
|
|
if (!addr_val.empty())
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2016-10-03 07:29:50 +00:00
|
|
|
unsigned long addr_ul = 0;
|
|
|
|
if (addr_val.ToULong(&addr_ul, 16))
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2016-10-03 07:29:50 +00:00
|
|
|
addr = static_cast<u32>(addr_ul);
|
2017-08-12 17:21:22 +00:00
|
|
|
// Get physical address
|
|
|
|
if (addr >= base_address)
|
|
|
|
addr -= base_address;
|
2016-10-03 07:29:50 +00:00
|
|
|
// Don't find the result we're already looking at
|
2017-04-18 20:12:15 +00:00
|
|
|
if (m_continue_search && addr == m_last_search_address &&
|
|
|
|
search_type == SearchType::FindNext)
|
|
|
|
{
|
2016-10-03 07:29:50 +00:00
|
|
|
addr += 1;
|
2017-04-18 20:12:15 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-25 10:07:56 +00:00
|
|
|
|
2016-10-03 07:29:50 +00:00
|
|
|
// If the current address doesn't leave enough bytes to search then we're done.
|
|
|
|
if (addr >= ram_size - search_bytes.size())
|
|
|
|
{
|
|
|
|
m_search_result_msg->SetLabel(_("Address Out of Range"));
|
|
|
|
return;
|
|
|
|
}
|
2009-11-25 10:07:56 +00:00
|
|
|
|
2017-04-18 20:12:15 +00:00
|
|
|
const u8* ptr;
|
|
|
|
const u8* end;
|
|
|
|
if (search_type == SearchType::FindNext)
|
2016-10-03 07:29:50 +00:00
|
|
|
{
|
2017-04-18 20:12:15 +00:00
|
|
|
const u8* begin = &ram_ptr[addr];
|
|
|
|
end = &ram_ptr[ram_size - search_bytes.size() + 1];
|
|
|
|
ptr = std::search(begin, end, search_bytes.begin(), search_bytes.end());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const u8* begin = ram_ptr;
|
|
|
|
end = &ram_ptr[addr + search_bytes.size() - 1];
|
|
|
|
ptr = std::find_end(begin, end, search_bytes.begin(), search_bytes.end());
|
|
|
|
}
|
2016-10-03 07:29:50 +00:00
|
|
|
|
2017-04-18 20:12:15 +00:00
|
|
|
if (ptr != end)
|
|
|
|
{
|
|
|
|
m_search_result_msg->SetLabel(_("Match Found"));
|
|
|
|
u32 offset = static_cast<u32>(ptr - ram_ptr);
|
|
|
|
// NOTE: SetValue() generates a synthetic wxEVT_TEXT
|
2017-08-12 17:21:22 +00:00
|
|
|
m_address_search_ctrl->SetValue(wxString::Format("%08x", base_address + offset));
|
2017-04-18 20:12:15 +00:00
|
|
|
m_last_search_address = offset;
|
|
|
|
m_continue_search = true;
|
|
|
|
return;
|
2016-10-03 07:29:50 +00:00
|
|
|
}
|
2017-04-18 20:12:15 +00:00
|
|
|
|
|
|
|
m_search_result_msg->SetLabel(_("No Match"));
|
2009-12-15 14:40:03 +00:00
|
|
|
}
|
2016-08-18 20:08:26 +00:00
|
|
|
|
2016-10-03 07:29:50 +00:00
|
|
|
void CMemoryWindow::OnMemCheckOptionChange(wxCommandEvent& event)
|
2016-08-18 20:08:26 +00:00
|
|
|
{
|
2017-04-30 06:44:27 +00:00
|
|
|
if (m_read_write_radio_btn->GetValue())
|
|
|
|
{
|
|
|
|
m_memory_view->SetMemCheckOptions(true, true, m_log_checkbox->GetValue());
|
|
|
|
}
|
2016-08-18 20:08:26 +00:00
|
|
|
else
|
2017-04-30 06:44:27 +00:00
|
|
|
{
|
|
|
|
m_memory_view->SetMemCheckOptions(m_read_radio_btn->GetValue(), m_write_radio_btn->GetValue(),
|
|
|
|
m_log_checkbox->GetValue());
|
|
|
|
}
|
2016-08-18 20:08:26 +00:00
|
|
|
}
|