Пример #1
0
void CMemoryWindow::OnSetMemoryValue(wxCommandEvent& event)
{
  if (!Memory::IsInitialized())
  {
    WxUtils::ShowErrorDialog(_("Cannot set uninitialized memory."));
    return;
  }

  std::string str_addr = WxStrToStr(m_address_search_ctrl->GetValue());
  u32 addr;
  if (!TryParse("0x" + str_addr, &addr))
  {
    WxUtils::ShowErrorDialog(wxString::Format(_("Invalid address: %s"), str_addr.c_str()));
    return;
  }

  std::string str_val = WxStrToStr(m_value_text_ctrl->GetValue());
  u32 val;
  if (!TryParse("0x" + str_val, &val))
  {
    WxUtils::ShowErrorDialog(wxString::Format(_("Invalid value: %s"), str_val.c_str()));
    return;
  }

  PowerPC::HostWrite_U32(val, addr);
  m_memory_view->Refresh();
}
Пример #2
0
// Update the local perspectives array
void CFrame::LoadIniPerspectives()
{
	Perspectives.clear();
	std::vector<std::string> VPerspectives;
	std::string _Perspectives;

	IniFile ini;
	ini.Load(File::GetUserPath(F_DEBUGGERCONFIG_IDX));

	IniFile::Section* perspectives = ini.GetOrCreateSection("Perspectives");
	perspectives->Get("Perspectives", &_Perspectives, "Perspective 1");
	perspectives->Get("Active", &ActivePerspective, 0);
	SplitString(_Perspectives, ',', VPerspectives);

	for (auto& VPerspective : VPerspectives)
	{
		SPerspectives Tmp;
		std::string _Section, _Perspective, _Widths, _Heights;
		std::vector<std::string> _SWidth, _SHeight;
		Tmp.Name = VPerspective;

		// Don't save a blank perspective
		if (Tmp.Name.empty())
		{
			continue;
		}

		_Section = StringFromFormat("P - %s", Tmp.Name.c_str());

		IniFile::Section* perspec_section = ini.GetOrCreateSection(_Section);
		perspec_section->Get("Perspective", &_Perspective,
		                     "layout2|"
		                     "name=Pane 0;caption=Pane 0;state=768;dir=5;prop=100000;|"
		                     "name=Pane 1;caption=Pane 1;state=31458108;dir=4;prop=100000;|"
		                     "dock_size(5,0,0)=22|dock_size(4,0,0)=333|");
		perspec_section->Get("Width", &_Widths, "70,25");
		perspec_section->Get("Height", &_Heights, "80,80");

		Tmp.Perspective = StrToWxStr(_Perspective);

		SplitString(_Widths, ',', _SWidth);
		SplitString(_Heights, ',', _SHeight);
		for (auto& Width : _SWidth)
		{
			int _Tmp;
			if (TryParse(Width, &_Tmp))
				Tmp.Width.push_back(_Tmp);
		}
		for (auto& Height : _SHeight)
		{
			int _Tmp;
			if (TryParse(Height, &_Tmp))
				Tmp.Height.push_back(_Tmp);
		}
		Perspectives.push_back(Tmp);
	}
}
Пример #3
0
void LoadPatchSection(const char *section, std::vector<Patch> &patches, IniFile &ini)
{
	std::vector<std::string> lines;

	if (!ini.GetLines(section, lines))
		return;

	Patch currentPatch;

	for (std::vector<std::string>::const_iterator iter = lines.begin(); iter != lines.end(); ++iter)
	{
		std::string line = *iter;

		if (line.size())
		{
			if (line[0] == '+' || line[0] == '$')
			{
				// Take care of the previous code
				if (currentPatch.name.size())
					patches.push_back(currentPatch);
				currentPatch.entries.clear();

				// Set active and name
				currentPatch.active = (line[0] == '+') ? true : false;
				if (currentPatch.active)
					currentPatch.name = line.substr(2, line.size() - 2);
				else
					currentPatch.name = line.substr(1, line.size() - 1);
				continue;
			}

			std::string::size_type loc = line.find_first_of('=', 0);

			if (loc != std::string::npos)
				line[loc] = ':';

			std::vector<std::string> items;
			SplitString(line, ':', items);

			if (items.size() >= 3)
			{
				PatchEntry pE;
				bool success = true;
				success &= TryParse(items[0], &pE.address);
				success &= TryParse(items[2], &pE.value);

				pE.type = PatchType(std::find(PatchTypeStrings, PatchTypeStrings + 3, items[1]) - PatchTypeStrings);
				success &= (pE.type != (PatchType)3);
				if (success)
					currentPatch.entries.push_back(pE);
			}
		}
	}

	if (currentPatch.name.size() && currentPatch.entries.size())
		patches.push_back(currentPatch);
}
Пример #4
0
bool TryParse( wxRect& dest, const wxString& src, const wxRect& defval, const wxString& separators )
{
	dest = defval;

	wxStringTokenizer parts( src, separators );

	wxPoint point;
	wxSize size;

	if( !TryParse( point, parts ) ) return false;
	if( !TryParse( size, parts ) ) return false;

	dest = wxRect( point, size );
	return true;
}
Пример #5
0
short NShort::Parse(const Text &text)
{
	short s = 0;
	if (!TryParse(text, s))
		throw new Exception("Number out of limits", __FILE__, __LINE__, __func__);
	return s;
}
Пример #6
0
void CRegTable::SetValue(int row, int col, const wxString& strNewVal)
{
  if (row < 32)
  {
    if (col == 1)
    {
      u32 new_val = 0;
      if (TryParseGPR(strNewVal, m_formatRegs[row], &new_val))
        GPR(row) = new_val;
    }
    else if (col == 3)
    {
      unsigned long long new_val = 0;
      if (TryParseFPR(strNewVal, m_formatFRegs[row][0], &new_val))
        riPS0(row) = new_val;
    }
    else if (col == 4)
    {
      unsigned long long new_val = 0;
      if (TryParseFPR(strNewVal, m_formatFRegs[row][1], &new_val))
        riPS1(row) = new_val;
    }
  }
  else
  {
    if ((static_cast<size_t>(row - 32) < NUM_SPECIALS) && col == 1)
    {
      u32 new_val = 0;
      if (TryParse("0x" + WxStrToStr(strNewVal), &new_val))
        SetSpecialRegValue(row - 32, new_val);
    }
  }
}
Пример #7
0
void CRegisterView::OnMouseDownR(wxGridEvent& event)
{
  // popup menu
  m_selectedRow = event.GetRow();
  m_selectedColumn = event.GetCol();

  wxString strNewVal = m_register_table->GetValue(m_selectedRow, m_selectedColumn);
  TryParse("0x" + WxStrToStr(strNewVal), &m_selectedAddress);

  wxMenu menu;
  menu.Append(IDM_WATCHADDRESS, _("Add to &watch"));
  menu.Append(IDM_VIEWMEMORY, _("View &memory"));
  menu.Append(IDM_VIEWCODE, _("View &code"));
  if (m_selectedRow < 32 &&
      (m_selectedColumn == 1 || m_selectedColumn == 3 || m_selectedColumn == 4))
  {
    menu.AppendSeparator();
    if (m_selectedColumn == 1)
    {
      menu.Append(IDM_VIEW_HEX8, _("View as hexadecimal"));
      menu.Append(IDM_VIEW_INT, _("View as signed integer"));
      menu.Append(IDM_VIEW_UINT, _("View as unsigned integer"));
      menu.Append(IDM_VIEW_FLOAT, _("View as float"));
    }
    else
    {
      menu.Append(IDM_VIEW_HEX16, _("View as hexadecimal"));
      menu.Append(IDM_VIEW_DOUBLE, _("View as double"));
    }
  }
  PopupMenu(&menu);
}
Пример #8
0
unsigned char NUChar::Parse(const Text &text)
{
	unsigned char n = 0;
	if (!TryParse(text, n))
		throw new Exception("Number out of limits", __FILE__, __LINE__, __func__);
	return n;
}
Пример #9
0
T Parse( const wxString& src, const wxString& separators=L",")
{
	T retval;
	if( !TryParse( retval, src, separators ) )
		throw Exception::ParseError( "Parse failure on call to " + fromUTF8(__WXFUNCTION__) + ": " + src );
	return retval;
}
Пример #10
0
void CWatchView::OnMouseDownR(wxGridEvent& event)
{
  // popup menu
  int row = event.GetRow();
  int col = event.GetCol();

  m_selectedRow = row;

  if (col == 1 || col == 2)
  {
    wxString strNewVal = GetValueByRowCol(row, col);
    TryParse("0x" + WxStrToStr(strNewVal), &m_selectedAddress);
  }

  wxMenu menu;
  if (row != 0 && row != static_cast<int>(PowerPC::debug_interface.GetWatches().size() + 1))
  {
    // i18n: This kind of "watch" is used for watching emulated memory.
    // It's not related to timekeeping devices.
    menu.Append(IDM_DELETEWATCH, _("&Delete watch"));
  }

  if (row != 0 && row != static_cast<int>(PowerPC::debug_interface.GetWatches().size() + 1) &&
      (col == 1 || col == 2))
  {
    menu.Append(IDM_ADDMEMCHECK, _("Add memory &breakpoint"));
    menu.Append(IDM_VIEWMEMORY, _("View &memory"));
  }
  PopupMenu(&menu);
}
Пример #11
0
static std::optional<PartitionType> ParsePartitionDirectoryName(const std::string& name)
{
  if (name.size() < 2)
    return {};

  if (!strcasecmp(name.c_str(), "DATA"))
    return PartitionType::Game;
  if (!strcasecmp(name.c_str(), "UPDATE"))
    return PartitionType::Update;
  if (!strcasecmp(name.c_str(), "CHANNEL"))
    return PartitionType::Channel;

  if (name[0] == 'P' || name[0] == 'p')
  {
    // e.g. "P-HA8E" (normally only used for Super Smash Bros. Brawl's VC partitions)
    if (name[1] == '-' && name.size() == 6)
    {
      const u32 result = Common::swap32(reinterpret_cast<const u8*>(name.data() + 2));
      return static_cast<PartitionType>(result);
    }

    // e.g. "P0"
    if (std::all_of(name.cbegin() + 1, name.cend(), [](char c) { return c >= '0' && c <= '9'; }))
    {
      u32 result;
      if (TryParse(name.substr(1), &result))
        return static_cast<PartitionType>(result);
    }
  }

  return {};
}
Пример #12
0
void CWatchView::OnMouseDownR(wxGridEvent& event)
{
  // popup menu
  int row = event.GetRow();
  int col = event.GetCol();

  m_selectedRow = row;

  if (col == 1 || col == 2)
  {
    wxString strNewVal = GetValueByRowCol(row, col);
    TryParse("0x" + WxStrToStr(strNewVal), &m_selectedAddress);
  }

  wxMenu menu;
  if (row != 0 && row != (int)(PowerPC::watches.GetWatches().size() + 1))
    menu.Append(IDM_DELETEWATCH, _("&Delete watch"));

  if (row != 0 && row != (int)(PowerPC::watches.GetWatches().size() + 1) && (col == 1 || col == 2))
  {
    menu.Append(IDM_ADDMEMCHECK, _("Add memory &breakpoint"));
    menu.Append(IDM_VIEWMEMORY, _("View &memory"));
  }
  PopupMenu(&menu);
}
Пример #13
0
// Update the local perspectives array
void CFrame::LoadIniPerspectives()
{
	Perspectives.clear();
	std::vector<std::string> VPerspectives;
	std::string _Perspectives;

	IniFile ini;
	ini.Load(File::GetUserPath(F_DEBUGGERCONFIG_IDX));
	ini.Get("Perspectives", "Perspectives", &_Perspectives, "Perspective 1");
	ini.Get("Perspectives", "Active", &ActivePerspective, 0);
	SplitString(_Perspectives, ',', VPerspectives);

	for (u32 i = 0; i < VPerspectives.size(); i++)
	{
		SPerspectives Tmp;
		std::string _Section, _Perspective, _Width, _Height;
		std::vector<std::string> _SWidth, _SHeight;
		Tmp.Name = VPerspectives[i];
		// Don't save a blank perspective
		if (Tmp.Name.empty()) continue;

		_Section = StringFromFormat("P - %s", Tmp.Name.c_str());
		ini.Get(_Section.c_str(), "Perspective", &_Perspective,
				"layout2|"
				"name=Pane 0;caption=Pane 0;state=768;dir=5;prop=100000;|"
				"name=Pane 1;caption=Pane 1;state=31458108;dir=4;prop=100000;|"
				"dock_size(5,0,0)=22|dock_size(4,0,0)=333|");
		ini.Get(_Section.c_str(), "Width", &_Width, "70,25");
		ini.Get(_Section.c_str(), "Height", &_Height, "80,80");

		Tmp.Perspective = wxString::FromAscii(_Perspective.c_str());

		SplitString(_Width, ',', _SWidth);
		SplitString(_Height, ',', _SHeight);
		for (u32 j = 0; j < _SWidth.size(); j++)
		{
			int _Tmp;
			if (TryParse(_SWidth[j].c_str(), &_Tmp)) Tmp.Width.push_back(_Tmp);
		}
		for (u32 j = 0; j < _SHeight.size(); j++)
		{
			int _Tmp;
			if (TryParse(_SHeight[j].c_str(), &_Tmp)) Tmp.Height.push_back(_Tmp);
		}
		Perspectives.push_back(Tmp);
	}
}
Пример #14
0
void IniLoader::Entry( const wxString& var, wxRect& value, const wxRect defvalue )
{
	if( !m_Config )
	{
		value = defvalue; return;
	}
	TryParse( value, m_Config->Read( var, ToString( defvalue ) ), defvalue );
}
Пример #15
0
bool IniFile::Section::Get(const std::string& key, double* value, double defaultValue)
{
	std::string temp;
	bool retval = Get(key, &temp);
	if (retval && TryParse(temp, value))
		return true;
	*value = defaultValue;
	return false;
}
Пример #16
0
bool IniFile::Section::Get(const char* key, float* value, float defaultValue)
{
	std::string temp;
	bool retval = Get(key, &temp, 0);
	if (retval && TryParse(temp.c_str(), value))
		return true;
	*value = defaultValue;
	return false;
}
Пример #17
0
bool TryParse(const std::string& str, u32* const output)
{
  u64 value;
  if (!TryParse(str, &value))
    return false;

  if (value >= 0x100000000ull && value <= 0xFFFFFFFF00000000ull)
    return false;

  *output = static_cast<u32>(value);
  return true;
}
Пример #18
0
VersionNumber
VersionNumber::Parse (/*[in]*/ const char * lpsz)
{
  VersionNumber versionNumber;
  if (! TryParse(lpsz, versionNumber))
    {
      FATAL_MIKTEX_ERROR ("VersionNumber::Parse",
			  T_("A version number could not be parsed."),
			  lpsz);
    }
  return (versionNumber);
}
Пример #19
0
static void LoadSpeedhacks(const char *section, std::map<u32, int> &hacks, IniFile &ini) {
	std::vector<std::string> keys;
	ini.GetKeys(section, keys);
	for (std::vector<std::string>::const_iterator iter = keys.begin(); iter != keys.end(); ++iter)
	{
		std::string key = *iter;
		std::string value;
		ini.Get(section, key.c_str(), &value, "BOGUS");
		if (value != "BOGUS")
		{
			u32 address;
			u32 cycles;
			bool success = true;
			success &= TryParse(key, &address);
			success &= TryParse(value, &cycles);
			if (success) {
				speedHacks[address] = (int)cycles;
			}
		}
	}
}
Пример #20
0
static void LoadSpeedhacks(const std::string& section, IniFile& ini)
{
  std::vector<std::string> keys;
  ini.GetKeys(section, &keys);
  for (const std::string& key : keys)
  {
    std::string value;
    ini.GetOrCreateSection(section)->Get(key, &value, "BOGUS");
    if (value != "BOGUS")
    {
      u32 address;
      u32 cycles;
      bool success = true;
      success &= TryParse(key, &address);
      success &= TryParse(value, &cycles);
      if (success)
      {
        s_speed_hacks[address] = static_cast<int>(cycles);
      }
    }
  }
}
Пример #21
0
void CMemoryWindow::SetMemoryValue(wxCommandEvent& event)
{
	std::string str_addr = WxStrToStr(addrbox->GetValue());
	std::string str_val = WxStrToStr(valbox->GetValue());
	u32 addr;
	u32 val;

	if (!TryParse(std::string("0x") + str_addr, &addr))
	{
		PanicAlertT("Invalid Address: %s", str_addr.c_str());
		return;
	}

	if (!TryParse(std::string("0x") + str_val, &val))
	{
		PanicAlertT("Invalid Value: %s", str_val.c_str());
		return;
	}

	Memory::Write_U32(val, addr);
	memview->Refresh();
}
Пример #22
0
bool TryParse(const std::string& str, bool* const output)
{
  float value;
  const bool is_valid_float = TryParse(str, &value);
  if ((is_valid_float && value == 1) || !strcasecmp("true", str.c_str()))
    *output = true;
  else if ((is_valid_float && value == 0) || !strcasecmp("false", str.c_str()))
    *output = false;
  else
    return false;

  return true;
}
Пример #23
0
void CRegisterView::OnMouseDownR(wxGridEvent& event)
{
	// popup menu
	int row = event.GetRow();
	int col = event.GetCol();

	wxString strNewVal = GetValueByRowCol(row, col);
	TryParse("0x" + WxStrToStr(strNewVal), &m_selectedAddress);

	wxMenu menu;
	menu.Append(IDM_WATCHADDRESS, _("Add to &watch"));
	menu.Append(IDM_VIEWMEMORY, _("View &memory"));
	PopupMenu(&menu);
}
Пример #24
0
void CWatchView::OnPopupMenu(wxCommandEvent& event)
{
  // FIXME: This is terrible. Generate events instead.
  CFrame* cframe = wxGetApp().GetCFrame();
  CCodeWindow* code_window = cframe->m_code_window;
  CWatchWindow* watch_window = code_window->GetPanel<CWatchWindow>();
  CMemoryWindow* memory_window = code_window->GetPanel<CMemoryWindow>();
  CBreakPointWindow* breakpoint_window = code_window->GetPanel<CBreakPointWindow>();

  switch (event.GetId())
  {
  case IDM_DELETEWATCH:
  {
    wxString strNewVal = GetValueByRowCol(m_selectedRow, 1);
    if (TryParse("0x" + WxStrToStr(strNewVal), &m_selectedAddress))
    {
      PowerPC::debug_interface.UnsetWatch(m_selectedAddress);
      if (watch_window)
        watch_window->NotifyUpdate();
      Refresh();
    }
    break;
  }
  case IDM_ADDMEMCHECK:
  {
    TMemCheck MemCheck;
    MemCheck.start_address = m_selectedAddress;
    MemCheck.end_address = m_selectedAddress;
    MemCheck.is_ranged = false;
    MemCheck.is_break_on_read = true;
    MemCheck.is_break_on_write = true;
    MemCheck.log_on_hit = true;
    MemCheck.break_on_hit = true;
    PowerPC::memchecks.Add(MemCheck);

    if (breakpoint_window)
      breakpoint_window->NotifyUpdate();
    Refresh();
    break;
  }
  case IDM_VIEWMEMORY:
    if (memory_window)
      memory_window->JumpToAddress(m_selectedAddress);
    Refresh();
    break;
  }
  event.Skip();
}
Пример #25
0
wxString Language::FormatForRoundtrip() const
{
    // TODO: Can't show variants nicely yet, not standardized
    if (!Variant().empty())
        return m_code;

    wxString disp = DisplayName();
    // ICU isn't 100% reliable, some of the display names it produces
    // (e.g. "Chinese (China)" aren't in the list of known locale names
    // (here because zh-Trans is preferred to zh_CN). So make sure it can
    // be parsed back first.
    if (TryParse(disp).IsValid())
        return disp;
    else
        return m_code;
}
Пример #26
0
int main() {
    bool succes;
    int number;
    char num[20];
    scanf("%s", num);

    number = TryParse(num, &succes);

    if (succes) {
        printf("Your number: %d", number);
    }
    else {
        printf("You haven't entered the number!");
    }
    return 0;
}
Пример #27
0
void CWatchView::OnPopupMenu(wxCommandEvent& event)
{
  CFrame* main_frame = static_cast<CFrame*>(GetGrandParent()->GetParent());
  CCodeWindow* code_window = main_frame->g_pCodeWindow;
  CWatchWindow* watch_window = code_window->m_WatchWindow;
  CMemoryWindow* memory_window = code_window->m_MemoryWindow;
  CBreakPointWindow* breakpoint_window = code_window->m_BreakpointWindow;

  wxString strNewVal;
  TMemCheck MemCheck;

  switch (event.GetId())
  {
  case IDM_DELETEWATCH:
    strNewVal = GetValueByRowCol(m_selectedRow, 1);
    if (TryParse("0x" + WxStrToStr(strNewVal), &m_selectedAddress))
    {
      PowerPC::watches.Remove(m_selectedAddress);
      if (watch_window)
        watch_window->NotifyUpdate();
      Refresh();
    }
    break;
  case IDM_ADDMEMCHECK:
    MemCheck.StartAddress = m_selectedAddress;
    MemCheck.EndAddress = m_selectedAddress;
    MemCheck.bRange = false;
    MemCheck.OnRead = true;
    MemCheck.OnWrite = true;
    MemCheck.Log = true;
    MemCheck.Break = true;
    PowerPC::memchecks.Add(MemCheck);

    if (breakpoint_window)
      breakpoint_window->NotifyUpdate();
    Refresh();
    break;
  case IDM_VIEWMEMORY:
    if (memory_window)
      memory_window->JumpToAddress(m_selectedAddress);
    Refresh();
    break;
  }
  event.Skip();
}
Пример #28
0
void CRegTable::SetValue(int row, int col, const wxString& strNewVal)
{
	u32 newVal = 0;
	if (TryParse(std::string(strNewVal.mb_str()), &newVal))
	{
		if (row < 32) {
			if (col == 1)
				GPR(row) = newVal;
			else if (col == 3)
				riPS0(row) = newVal;
			else if (col == 4)
				riPS1(row) = newVal;
		} else {
			if ((row - 32 < NUM_SPECIALS) && (col == 1)) {
				SetSpecialRegValue(row - 32, newVal);
			}
		}
	}
}
Пример #29
0
void CWatchTable::SetValue(int row, int col, const wxString& strNewVal)
{
  u32 newVal = 0;
  if (col == 0 || TryParse("0x" + WxStrToStr(strNewVal), &newVal))
  {
    if (row > 0)
    {
      switch (col)
      {
      case 0:
      {
        SetWatchName(row, std::string(WxStrToStr(strNewVal)));
        break;
      }
      case 1:
      {
        if (row > (int)PowerPC::watches.GetWatches().size())
        {
          AddWatchAddr(row, newVal);
          row = (int)PowerPC::watches.GetWatches().size();
        }
        else
        {
          UpdateWatchAddr(row, newVal);
        }
        break;
      }
      case 2:
      {
        SetWatchValue(row, newVal);
        break;
      }
      default:
        break;
      }
    }
  }
}
Пример #30
-1
void TextureReplacer::ParseHashRange(const std::string &key, const std::string &value) {
	std::vector<std::string> keyParts;
	SplitString(key, ',', keyParts);
	std::vector<std::string> valueParts;
	SplitString(value, ',', valueParts);

	if (keyParts.size() != 3 || valueParts.size() != 2) {
		ERROR_LOG(G3D, "Ignoring invalid hashrange %s = %s, expecting addr,w,h = w,h", key.c_str(), value.c_str());
		return;
	}

	u32 addr;
	u32 fromW;
	u32 fromH;
	if (!TryParse(keyParts[0], &addr) || !TryParse(keyParts[1], &fromW) || !TryParse(keyParts[2], &fromH)) {
		ERROR_LOG(G3D, "Ignoring invalid hashrange %s = %s, key format is 0x12345678,512,512", key.c_str(), value.c_str());
		return;
	}

	u32 toW;
	u32 toH;
	if (!TryParse(valueParts[0], &toW) || !TryParse(valueParts[1], &toH)) {
		ERROR_LOG(G3D, "Ignoring invalid hashrange %s = %s, value format is 512,512", key.c_str(), value.c_str());
		return;
	}

	if (toW > fromW || toH > fromH) {
		ERROR_LOG(G3D, "Ignoring invalid hashrange %s = %s, range bigger than source", key.c_str(), value.c_str());
		return;
	}

	const u64 rangeKey = ((u64)addr << 32) | (fromW << 16) | fromH;
	hashranges_[rangeKey] = WidthHeightPair(toW, toH);
}