Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 3 additions & 170 deletions src/RA_Defs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace ra {

_Use_decl_annotations_
std::string ByteAddressToString(ByteAddress nAddr)
std::string ByteAddressToString(ra::data::ByteAddress nAddr)
{
#ifndef RA_UTEST
const auto& pEmulatorContext = ra::services::ServiceLocator::Get<ra::data::context::EmulatorContext>();
Expand All @@ -21,9 +21,9 @@ std::string ByteAddressToString(ByteAddress nAddr)
}

_Use_decl_annotations_
ByteAddress ByteAddressFromString(const std::string& sByteAddress)
ra::data::ByteAddress ByteAddressFromString(const std::string& sByteAddress)
{
ra::ByteAddress address{};
ra::data::ByteAddress address{};

if (!ra::StringStartsWith(sByteAddress, "-")) // negative addresses not supported
{
Expand All @@ -42,69 +42,6 @@ ByteAddress ByteAddressFromString(const std::string& sByteAddress)

namespace data {

static std::wstring U32ToFloatString(unsigned nValue, char nFloatType)
{
rc_typed_value_t value;
value.type = RC_VALUE_TYPE_UNSIGNED;
value.value.u32 = nValue;
rc_transform_memref_value(&value, nFloatType);

if (value.value.f32 < 0.000001)
{
if (value.value.f32 > 0.0)
return ra::StringPrintf(L"%e", value.value.f32);

if (value.value.f32 < 0.0 && value.value.f32 > -0.000001)
return ra::StringPrintf(L"%e", value.value.f32);
}

std::wstring sValue = ra::StringPrintf(L"%f", value.value.f32);
while (sValue.back() == L'0')
sValue.pop_back();
if (sValue.back() == L'.')
sValue.push_back(L'0');

return sValue;
}

std::wstring MemSizeFormat(unsigned nValue, MemSize nSize, MemFormat nFormat)
{
switch (nSize)
{
case MemSize::Float:
return U32ToFloatString(nValue, RC_MEMSIZE_FLOAT);

case MemSize::FloatBigEndian:
return U32ToFloatString(nValue, RC_MEMSIZE_FLOAT_BE);

case MemSize::Double32:
return U32ToFloatString(nValue, RC_MEMSIZE_DOUBLE32);

case MemSize::Double32BigEndian:
return U32ToFloatString(nValue, RC_MEMSIZE_DOUBLE32_BE);

case MemSize::MBF32:
return U32ToFloatString(nValue, RC_MEMSIZE_MBF32);

case MemSize::MBF32LE:
return U32ToFloatString(nValue, RC_MEMSIZE_MBF32_LE);

default:
if (nFormat == MemFormat::Dec)
return std::to_wstring(nValue);

const auto nBits = MemSizeBits(nSize);
switch (nBits / 8)
{
default: return ra::StringPrintf(L"%x", nValue);
case 1: return ra::StringPrintf(L"%02x", nValue);
case 2: return ra::StringPrintf(L"%04x", nValue);
case 3: return ra::StringPrintf(L"%06x", nValue);
case 4: return ra::StringPrintf(L"%08x", nValue);
}
}
}

const char* ValueFormatToString(ValueFormat nFormat) noexcept
{
switch (nFormat)
Expand Down Expand Up @@ -138,109 +75,5 @@ ValueFormat ValueFormatFromString(const std::string& sFormat) noexcept
return ra::itoe<ValueFormat>(rc_parse_format(sFormat.c_str()));
}

unsigned FloatToU32(float fValue, MemSize nFloatType) noexcept
{
// this leverages the fact that Windows uses IEE754 floats
union u
{
float fValue;
unsigned nValue;
} uUnion;

uUnion.fValue = fValue;

switch (nFloatType)
{
case MemSize::Float:
return uUnion.nValue;

case MemSize::FloatBigEndian:
return ReverseBytes(uUnion.nValue);

case MemSize::Double32:
case MemSize::Double32BigEndian:
{
// double has 3 extra bits for the exponent
const int32_t exponent = ra::to_signed((uUnion.nValue >> 23) & 0xFF) - 127 + 1023; // change exponent base from 127 to 1023
const unsigned nValue = ((uUnion.nValue & 0x007FFFFF) >> 3) | // mantissa is shifted three bits right
((ra::to_unsigned(exponent) & 0x7FF) << 20) | // adjusted exponent
((uUnion.nValue & 0x80000000)); // sign is unmoved

return (nFloatType == MemSize::Double32) ? nValue : ReverseBytes(nValue);
}

case MemSize::MBF32:
case MemSize::MBF32LE:
{
// MBF32 puts the sign after the exponent, uses a 129 base instead of 127, and stores in big endian
unsigned nValue = ((uUnion.nValue & 0x007FFFFF)) | // mantissa is unmoved
((uUnion.nValue & 0x7F800000) << 1) | // exponent is shifted one bit left
((uUnion.nValue & 0x80000000) >> 8); // sign is shifted eight bits right

nValue += 0x02000000; // adjust to 129 base
return (nFloatType == MemSize::MBF32LE) ? nValue : ReverseBytes(nValue);
}

default:
return 0;
}
}

float U32ToFloat(unsigned nValue, MemSize nFloatType) noexcept
{
// this leverages the fact that Windows uses IEE754 floats
union u
{
float fValue;
unsigned nValue;
} uUnion{};

switch (nFloatType)
{
case MemSize::FloatBigEndian:
nValue = ReverseBytes(nValue);
__fallthrough; // to MemSize::Float

case MemSize::Float:
uUnion.nValue = nValue;
break;

case MemSize::Double32BigEndian:
nValue = ReverseBytes(nValue);
__fallthrough; // to MemSize::Double32

case MemSize::Double32:
{
// double has 3 extra bits for the exponent, and uses a 1023 base instead of a 127 base
const int32_t exponent = ra::to_signed((uUnion.nValue >> 20) & 0x7FF) - 1023 + 127; // change exponent base from 1023 to 127
nValue = ((uUnion.nValue & 0x000FFFFF) << 3) | // mantissa is shifted three bits left
((ra::to_unsigned(exponent) & 0xFF) << 23) | // adjusted exponent
((uUnion.nValue & 0x80000000)); // sign is unmoved

uUnion.nValue = nValue;
break;
}

case MemSize::MBF32:
nValue = ReverseBytes(nValue);
__fallthrough; // to MemSize::MBF32LE

case MemSize::MBF32LE:
// MBF32 puts the sign after the exponent, uses a 129 base instead of 127, and stores in big endian
nValue -= 0x02000000; // adjust to 129 base
nValue = ((nValue & 0x007FFFFF)) | // mantissa is unmoved
((nValue & 0xFF000000) >> 1) | // exponent is shifted one bit right
((nValue & 0x00800000) << 8); // sign is shifted eight bits left

uUnion.nValue = nValue;
break;

default:
return 0.0f;
}

return uUnion.fValue;
}

} /* namespace data */
} /* namespace ra */
5 changes: 3 additions & 2 deletions src/RA_Defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ using namespace std::string_literals;
#endif // RA_EXPORTS

#include "data\Types.hh"
#include "data\Memory.hh"

#define RA_DIR_OVERLAY L"Overlay\\"
#define RA_DIR_BASE L"RACache\\"
Expand Down Expand Up @@ -165,8 +166,8 @@ class ResizeContent
#endif

namespace ra {
_NODISCARD std::string ByteAddressToString(_In_ ByteAddress nAddr);
_NODISCARD ByteAddress ByteAddressFromString(_In_ const std::string& sByteAddress);
_NODISCARD std::string ByteAddressToString(_In_ ra::data::ByteAddress nAddr);
_NODISCARD ra::data::ByteAddress ByteAddressFromString(_In_ const std::string& sByteAddress);
} // namespace ra

#endif // !RA_DEFS_H
2 changes: 1 addition & 1 deletion src/RA_Integration.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="data\context\ConsoleContext.cpp" />
<ClCompile Include="data\context\GameAssets.cpp" />
<ClCompile Include="api\ApiCall.cpp" />
<ClCompile Include="api\impl\ConnectedServer.cpp" />
<ClCompile Include="api\impl\DisconnectedServer.cpp" />
<ClCompile Include="api\impl\OfflineServer.cpp" />
<ClCompile Include="data\context\ConsoleContext.cpp" />
<ClCompile Include="data\context\EmulatorContext.cpp" />
<ClCompile Include="data\context\GameContext.cpp" />
<ClCompile Include="data\context\SessionTracker.cpp" />
Expand Down
12 changes: 6 additions & 6 deletions src/RA_Integration.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,6 @@
<ClCompile Include="services\FrameEventQueue.cpp">
<Filter>Services</Filter>
</ClCompile>
<ClCompile Include="data\context\ConsoleContext.cpp">
<Filter>Data\Context</Filter>
</ClCompile>
<ClCompile Include="data\context\EmulatorContext.cpp">
<Filter>Data\Context</Filter>
</ClCompile>
Expand Down Expand Up @@ -423,6 +420,9 @@
<ClCompile Include="services\impl\OfflineRcClient.cpp">
<Filter>Services\Impl</Filter>
</ClCompile>
<ClCompile Include="data\context\ConsoleContext.cpp">
<Filter>Data\Context</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="RA_Resource.h">
Expand Down Expand Up @@ -842,9 +842,6 @@
<ClInclude Include="services\FrameEventQueue.hh">
<Filter>Services</Filter>
</ClInclude>
<ClInclude Include="data\context\ConsoleContext.hh">
<Filter>Data\Context</Filter>
</ClInclude>
<ClInclude Include="data\context\EmulatorContext.hh">
<Filter>Data\Context</Filter>
</ClInclude>
Expand Down Expand Up @@ -1040,6 +1037,9 @@
<ClInclude Include="services\impl\OfflineRcClient.hh">
<Filter>Services\Impl</Filter>
</ClInclude>
<ClInclude Include="data\context\ConsoleContext.hh">
<Filter>Data\Context</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="RA_Shared.rc">
Expand Down
4 changes: 2 additions & 2 deletions src/api/DeleteCodeNote.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "ApiCall.hh"

#include "data\Types.hh"
#include "data\Memory.hh"

namespace ra {
namespace api {
Expand All @@ -22,7 +22,7 @@ public:
struct Request : ApiRequestBase
{
unsigned int GameId{ 0U };
ra::ByteAddress Address{ 0U };
ra::data::ByteAddress Address{ 0U };

using Callback = std::function<void(const Response& response)>;

Expand Down
4 changes: 2 additions & 2 deletions src/api/FetchCodeNotes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "ApiCall.hh"

#include "data\Types.hh"
#include "data\Memory.hh"

namespace ra {
namespace api {
Expand All @@ -18,7 +18,7 @@ public:
{
struct CodeNote
{
ra::ByteAddress Address{ 0U };
ra::data::ByteAddress Address{ 0U };
std::wstring Note;
std::string Author;
};
Expand Down
2 changes: 1 addition & 1 deletion src/api/UpdateCodeNote.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public:
struct Request : ApiRequestBase
{
unsigned int GameId{ 0U };
ra::ByteAddress Address{ 0U };
ra::data::ByteAddress Address{ 0U };
std::wstring Note;

using Callback = std::function<void(const Response& response)>;
Expand Down
2 changes: 1 addition & 1 deletion src/api/impl/ConnectedServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ void ConnectedServer::ProcessCodeNotes(FetchCodeNotes::Response& response, const
#pragma warning(pop)

static void SetCodeNote(ApiResponseBase& response, const char* sApiName,
unsigned nGameId, ra::ByteAddress nAddress, const char* sNote)
unsigned nGameId, ra::data::ByteAddress nAddress, const char* sNote)
{
rc_api_update_code_note_request_t api_params;
memset(&api_params, 0, sizeof(api_params));
Expand Down
Loading
Loading