summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorPierre Bourdon <delroth@gmail.com>2014-12-26 13:49:59 +0100
committerPierre Bourdon <delroth@gmail.com>2014-12-26 13:49:59 +0100
commitb3bae9eef7e2f4e4eca9a9e931d1e4584040a1aa (patch)
tree6429a92f8bb2c06e46b3c9e12800fbed5305dc88 /Source
parent7764a5ed9d506d87d6a457bc05c947463fe5288e (diff)
parent52d42bf330e8be12e37bf23be517f6f01406505e (diff)
Merge pull request #1473 from phire/cleanHLE
Clean up debug string functions in OS_HLE.
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/Core/HLE/HLE_OS.cpp46
-rw-r--r--Source/Core/Core/HW/Memmap.cpp3
2 files changed, 21 insertions, 28 deletions
diff --git a/Source/Core/Core/HLE/HLE_OS.cpp b/Source/Core/Core/HLE/HLE_OS.cpp
index 74743b5a57..b350872a2f 100644
--- a/Source/Core/Core/HLE/HLE_OS.cpp
+++ b/Source/Core/Core/HLE/HLE_OS.cpp
@@ -32,7 +32,7 @@ void HLE_OSPanic()
void HLE_GeneralDebugPrint()
{
std::string ReportMessage;
- if (*(u32*)Memory::GetPointer(GPR(3)) > 0x80000000)
+ if (Memory::Read_U32(GPR(3)) > 0x80000000)
{
GetStringVA(ReportMessage, 4);
}
@@ -60,33 +60,26 @@ void HLE_write_console()
void GetStringVA(std::string& _rOutBuffer, u32 strReg)
{
_rOutBuffer = "";
- char ArgumentBuffer[256];
+ std::string ArgumentBuffer = "";
u32 ParameterCounter = strReg+1;
u32 FloatingParameterCounter = 1;
- char *pString = (char*)Memory::GetPointer(GPR(strReg));
- if (!pString)
- {
- ERROR_LOG(OSREPORT, "r%i invalid", strReg);
- return;
- }
+ std::string string = Memory::GetString(GPR(strReg));
- while (*pString)
+ for(u32 i = 0; i < string.size(); i++)
{
- if (*pString == '%')
+ if (string[i] == '%')
{
- char* pArgument = ArgumentBuffer;
- *pArgument++ = *pString++;
- if (*pString == '%')
+ ArgumentBuffer = "%";
+ i++;
+ if (string[i] == '%')
{
_rOutBuffer += "%";
- pString++;
continue;
}
- while (*pString < 'A' || *pString > 'z' || *pString == 'l' || *pString == '-')
- *pArgument++ = *pString++;
+ while (string[i] < 'A' || string[i] > 'z' || string[i] == 'l' || string[i] == '-')
+ ArgumentBuffer += string[i++];
- *pArgument++ = *pString;
- *pArgument = 0;
+ ArgumentBuffer += string[i];
u64 Parameter;
if (ParameterCounter > 10)
@@ -95,7 +88,7 @@ void GetStringVA(std::string& _rOutBuffer, u32 strReg)
}
else
{
- if ((*(pString-2) == 'l') && (*(pString-1) == 'l')) // hax, just seen this on sysmenu osreport
+ if ((string[i-2] == 'l') && (string[i-1] == 'l')) // hax, just seen this on sysmenu osreport
{
Parameter = GPR(++ParameterCounter);
Parameter = (Parameter<<32)|GPR(++ParameterCounter);
@@ -105,23 +98,22 @@ void GetStringVA(std::string& _rOutBuffer, u32 strReg)
}
ParameterCounter++;
- switch (*pString)
+ switch (string[i])
{
case 's':
- _rOutBuffer += StringFromFormat(ArgumentBuffer, (char*)Memory::GetPointer((u32)Parameter));
+ _rOutBuffer += StringFromFormat(ArgumentBuffer.c_str(), Memory::GetString((u32)Parameter).c_str());
break;
case 'd':
case 'i':
{
- //u64 Double = Memory::Read_U64(Parameter);
- _rOutBuffer += StringFromFormat(ArgumentBuffer, Parameter);
+ _rOutBuffer += StringFromFormat(ArgumentBuffer.c_str(), Parameter);
break;
}
case 'f':
{
- _rOutBuffer += StringFromFormat(ArgumentBuffer,
+ _rOutBuffer += StringFromFormat(ArgumentBuffer.c_str(),
rPS0(FloatingParameterCounter));
FloatingParameterCounter++;
ParameterCounter--;
@@ -134,15 +126,13 @@ void GetStringVA(std::string& _rOutBuffer, u32 strReg)
break;
default:
- _rOutBuffer += StringFromFormat(ArgumentBuffer, Parameter);
+ _rOutBuffer += StringFromFormat(ArgumentBuffer.c_str(), Parameter);
break;
}
- pString++;
}
else
{
- _rOutBuffer += StringFromFormat("%c", *pString);
- pString++;
+ _rOutBuffer += string[i];
}
}
if (_rOutBuffer[_rOutBuffer.length() - 1] == '\n')
diff --git a/Source/Core/Core/HW/Memmap.cpp b/Source/Core/Core/HW/Memmap.cpp
index df1be370fb..fab79ba1bf 100644
--- a/Source/Core/Core/HW/Memmap.cpp
+++ b/Source/Core/Core/HW/Memmap.cpp
@@ -284,6 +284,9 @@ void DMA_MemoryToLC(const u32 _CacheAddr, const u32 _MemAddr, const u32 _iNumBlo
std::string GetString(u32 em_address, size_t size)
{
const char* ptr = reinterpret_cast<const char*>(GetPointer(em_address));
+ if (ptr == nullptr)
+ return "";
+
if (size == 0) // Null terminated string.
{
return std::string(ptr);