diff --git a/pcsx2/Utilities/BitCast.h b/common/BitCast.h similarity index 98% rename from pcsx2/Utilities/BitCast.h rename to common/BitCast.h index 6d612ec5b9..d4c79bf2f0 100644 --- a/pcsx2/Utilities/BitCast.h +++ b/common/BitCast.h @@ -13,6 +13,8 @@ * If not, see . */ +#pragma once + // An implementation of bit_cast until we get c++20 template @@ -24,4 +26,4 @@ T2 bit_cast(const T1& src) T2 dst; memcpy(&dst, &src, sizeof(T2)); return dst; -} \ No newline at end of file +} diff --git a/common/common.vcxproj b/common/common.vcxproj index 117e444fe0..345f319914 100644 --- a/common/common.vcxproj +++ b/common/common.vcxproj @@ -100,6 +100,7 @@ + diff --git a/common/common.vcxproj.filters b/common/common.vcxproj.filters index 7e2bee12cf..4010e56ed7 100644 --- a/common/common.vcxproj.filters +++ b/common/common.vcxproj.filters @@ -291,6 +291,9 @@ Header Files + + Header Files + Header Files\GL diff --git a/pcsx2/CMakeLists.txt b/pcsx2/CMakeLists.txt index 8209021c2d..c6a8d6059c 100644 --- a/pcsx2/CMakeLists.txt +++ b/pcsx2/CMakeLists.txt @@ -1232,8 +1232,7 @@ set(pcsx2UtilitiesSources # Utilities headers set(pcsx2UtilitiesHeaders - Utilities/AsciiFile.h - Utilities/BitCast.h) + Utilities/AsciiFile.h) # Windows sources diff --git a/pcsx2/gui/Debugger/CtrlMemSearch.cpp b/pcsx2/gui/Debugger/CtrlMemSearch.cpp index 85761767d1..e038faa539 100644 --- a/pcsx2/gui/Debugger/CtrlMemSearch.cpp +++ b/pcsx2/gui/Debugger/CtrlMemSearch.cpp @@ -17,8 +17,10 @@ #include "CtrlMemSearch.h" #include "DebugTools/Debug.h" #include "gui/AppConfig.h" -#include "Utilities/BitCast.h" -#include "../Patch.h" // Required for SwapEndian :( +#include "common/BitCast.h" +#include "common/StringUtil.h" +#include "Patch.h" // Required for SwapEndian :( + #include "BreakpointWindow.h" #include "DebugEvents.h" @@ -63,6 +65,14 @@ const wxString wxStringTypes[] = "String"}; const wxArrayString SearchTypes = wxArrayString(7, wxStringTypes); +// StringUtils::FromChars doesn't appreciate the leading 0x. +__fi wxString CheckHexadecimalString(wxString s) +{ + if(s.StartsWith("0x")) + return s.Remove(0, 2); + return s; +} + CtrlMemSearch::CtrlMemSearch(wxWindow* parent, DebugInterface* _cpu) : wxWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize) , cpu(_cpu) @@ -102,7 +112,7 @@ CtrlMemSearch::CtrlMemSearch(wxWindow* parent, DebugInterface* _cpu) txtMemoryEnd->SetValue(L"0x20000"); lblSearchHits = new wxStaticText(this, wxID_ANY, L"Hits: 0"); - lblSearchHitSelected = new wxStaticText(this, wxID_ANY, L"Selected: 0"); + lblSearchHitSelected = new wxStaticText(this, wxID_ANY, L"Cur: 0"); btnNext = new wxButton(this, wxID_ANY, L"Next", wxDefaultPosition); btnNext->Enable(false); @@ -194,17 +204,22 @@ void CtrlMemSearch::Search(wxCommandEvent& evt) u64 startAddress = 0; u64 endAddress = 0; - if (!txtMemoryStart->GetValue().ToULong(&startAddress, 16)) + const auto resStart = StringUtil::FromChars(CheckHexadecimalString(txtMemoryStart->GetValue()).ToStdString(), 16); + if (!resStart.has_value()) { wxMessageBox(L"Invalid start address", L"Error", wxOK | wxICON_ERROR); return; } + startAddress = resStart.value(); - if (!txtMemoryEnd->GetValue().ToULong(&endAddress, 16)) + const auto resEnd = StringUtil::FromChars(CheckHexadecimalString(txtMemoryEnd->GetValue()).ToStdString(), 16); + if (!resStart.has_value()) { wxMessageBox(L"Invalid end address", L"Error", wxOK | wxICON_ERROR); return; } + endAddress = resEnd.value(); + m_SearchThread->m_start = startAddress; m_SearchThread->m_end = endAddress; m_SearchThread->m_type = static_cast(cmbSearchType->GetSelection()); @@ -212,19 +227,19 @@ void CtrlMemSearch::Search(wxCommandEvent& evt) // Prepare the search value for the thread wxString searchString = txtSearch->GetValue(); - if (cmbSearchType->GetSelection() == SEARCHTYPE::STRING) + if (m_SearchThread->m_type == SEARCHTYPE::STRING) { m_SearchThread->m_value_string = searchString; } else if (chkHexadecimal->IsChecked()) { - u64 searchValue = 0; - if (!searchString.ToULong(&searchValue, 16)) + const auto res = StringUtil::FromChars(CheckHexadecimalString(txtSearch->GetValue()).ToStdString(), 16); + if (!res.has_value()) { wxMessageBox(L"Invalid hexadecimal value", L"Error", wxOK | wxICON_ERROR); return; } - m_SearchThread->m_value = radBigEndian->GetValue() ? SwapEndian(searchValue, SEARCHTYPEBITS[m_SearchThread->m_type]) : searchValue; + m_SearchThread->m_value = radBigEndian->GetValue() ? SwapEndian(res.value(), SEARCHTYPEBITS[cmbSearchType->GetSelection()]) : res.value(); } else { @@ -237,11 +252,11 @@ void CtrlMemSearch::Search(wxCommandEvent& evt) // Now we can convert the string to a number - if (cmbSearchType->GetSelection() == SEARCHTYPE::FLOAT || cmbSearchType->GetSelection() == SEARCHTYPE::DOUBLE) + if (m_SearchThread->m_type == SEARCHTYPE::FLOAT || m_SearchThread->m_type == SEARCHTYPE::DOUBLE) { // We're searching for a float or double, so we need to convert the string to a double - double searchValue = 0; - if (!searchString.ToDouble(&searchValue)) + const auto res = StringUtil::FromChars(txtSearch->GetValue().ToStdString()); + if (!res.has_value()) { wxMessageBox(L"Invalid floating point value", L"Error", wxOK | wxICON_ERROR); return; @@ -249,27 +264,28 @@ void CtrlMemSearch::Search(wxCommandEvent& evt) if (m_SearchThread->m_type == SEARCHTYPE::FLOAT) { - const u32 u32SearchValue = bit_cast(searchValue); + const u32 u32SearchValue = bit_cast(res.value()); m_SearchThread->m_value = u32SearchValue; } else { - const u64 u64SearchValue = bit_cast(searchValue); + const u64 u64SearchValue = bit_cast(res.value()); m_SearchThread->m_value = u64SearchValue; } } else { // We're searching for either a BYTE, WORD, DWORD or QWORD - u64 searchValue = 0; - if (!searchString.ToULong(&searchValue, 10)) + + const auto res = StringUtil::FromChars(txtSearch->GetValue().ToStdString()); + if(!res.has_value()) { wxMessageBox(L"Invalid decimal search value", L"Error", wxOK | wxICON_ERROR); return; } // We don't need to bitcast here, because the thread already has the correct value type of u64 - m_SearchThread->m_value = radBigEndian->GetValue() ? SwapEndian(searchValue, SEARCHTYPEBITS[m_SearchThread->m_type]) : searchValue; + m_SearchThread->m_value = radBigEndian->GetValue() ? SwapEndian(res.value(), SEARCHTYPEBITS[cmbSearchType->GetSelection()]) : res.value(); } } @@ -326,7 +342,7 @@ void CtrlMemSearch::onSearchPrev(wxCommandEvent& evt) void CtrlMemSearch::onSearchTypeChanged(wxCommandEvent& evt) { // Update the search value text box to match the search type - switch (cmbSearchType->GetSelection()) + switch (static_cast(cmbSearchType->GetSelection())) { case SEARCHTYPE::BYTE: case SEARCHTYPE::WORD: @@ -492,4 +508,4 @@ void SearchThread::ExecuteTaskInThread() wxCommandEvent done(pxEvt_SearchFinished); m_parent->GetEventHandler()->AddPendingEvent(done); -} \ No newline at end of file +} diff --git a/pcsx2/gui/Debugger/CtrlMemSearch.h b/pcsx2/gui/Debugger/CtrlMemSearch.h index ef5a1a735a..c8f3193d97 100644 --- a/pcsx2/gui/Debugger/CtrlMemSearch.h +++ b/pcsx2/gui/Debugger/CtrlMemSearch.h @@ -19,7 +19,7 @@ #include "DebugTools/DebugInterface.h" #include "DebugTools/DisassemblyManager.h" -enum SEARCHTYPE +enum class SEARCHTYPE { BYTE, WORD, diff --git a/pcsx2/gui/Debugger/CtrlRegisterList.cpp b/pcsx2/gui/Debugger/CtrlRegisterList.cpp index 26ffe955dc..2231134da5 100644 --- a/pcsx2/gui/Debugger/CtrlRegisterList.cpp +++ b/pcsx2/gui/Debugger/CtrlRegisterList.cpp @@ -16,7 +16,7 @@ #include "PrecompiledHeader.h" #include "CtrlRegisterList.h" #include "DebugTools/Debug.h" -#include "Utilities/BitCast.h" +#include "common/BitCast.h" #include "DebugEvents.h" #include "gui/AppConfig.h"