Clean up debug string functions in OS_HLE.

* Use GetString instead of GetPointer.
 * Use C++ strings instead of char* pointer math.
This commit is contained in:
Scott Mansell 2014-11-02 21:39:37 +13:00
parent 9daaf94f3c
commit 52d42bf330
2 changed files with 21 additions and 28 deletions

View File

@ -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')

View File

@ -310,6 +310,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);