Skip to content

Commit 02dd50e

Browse files
authored
move MemSize and related functions to ra::data::Memory static class (#1273)
1 parent 43dba7d commit 02dd50e

File tree

116 files changed

+2598
-2490
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+2598
-2490
lines changed

src/RA_Defs.cpp

Lines changed: 3 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace ra {
1111

1212
_Use_decl_annotations_
13-
std::string ByteAddressToString(ByteAddress nAddr)
13+
std::string ByteAddressToString(ra::data::ByteAddress nAddr)
1414
{
1515
#ifndef RA_UTEST
1616
const auto& pEmulatorContext = ra::services::ServiceLocator::Get<ra::data::context::EmulatorContext>();
@@ -21,9 +21,9 @@ std::string ByteAddressToString(ByteAddress nAddr)
2121
}
2222

2323
_Use_decl_annotations_
24-
ByteAddress ByteAddressFromString(const std::string& sByteAddress)
24+
ra::data::ByteAddress ByteAddressFromString(const std::string& sByteAddress)
2525
{
26-
ra::ByteAddress address{};
26+
ra::data::ByteAddress address{};
2727

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

4343
namespace data {
4444

45-
static std::wstring U32ToFloatString(unsigned nValue, char nFloatType)
46-
{
47-
rc_typed_value_t value;
48-
value.type = RC_VALUE_TYPE_UNSIGNED;
49-
value.value.u32 = nValue;
50-
rc_transform_memref_value(&value, nFloatType);
51-
52-
if (value.value.f32 < 0.000001)
53-
{
54-
if (value.value.f32 > 0.0)
55-
return ra::StringPrintf(L"%e", value.value.f32);
56-
57-
if (value.value.f32 < 0.0 && value.value.f32 > -0.000001)
58-
return ra::StringPrintf(L"%e", value.value.f32);
59-
}
60-
61-
std::wstring sValue = ra::StringPrintf(L"%f", value.value.f32);
62-
while (sValue.back() == L'0')
63-
sValue.pop_back();
64-
if (sValue.back() == L'.')
65-
sValue.push_back(L'0');
66-
67-
return sValue;
68-
}
69-
70-
std::wstring MemSizeFormat(unsigned nValue, MemSize nSize, MemFormat nFormat)
71-
{
72-
switch (nSize)
73-
{
74-
case MemSize::Float:
75-
return U32ToFloatString(nValue, RC_MEMSIZE_FLOAT);
76-
77-
case MemSize::FloatBigEndian:
78-
return U32ToFloatString(nValue, RC_MEMSIZE_FLOAT_BE);
79-
80-
case MemSize::Double32:
81-
return U32ToFloatString(nValue, RC_MEMSIZE_DOUBLE32);
82-
83-
case MemSize::Double32BigEndian:
84-
return U32ToFloatString(nValue, RC_MEMSIZE_DOUBLE32_BE);
85-
86-
case MemSize::MBF32:
87-
return U32ToFloatString(nValue, RC_MEMSIZE_MBF32);
88-
89-
case MemSize::MBF32LE:
90-
return U32ToFloatString(nValue, RC_MEMSIZE_MBF32_LE);
91-
92-
default:
93-
if (nFormat == MemFormat::Dec)
94-
return std::to_wstring(nValue);
95-
96-
const auto nBits = MemSizeBits(nSize);
97-
switch (nBits / 8)
98-
{
99-
default: return ra::StringPrintf(L"%x", nValue);
100-
case 1: return ra::StringPrintf(L"%02x", nValue);
101-
case 2: return ra::StringPrintf(L"%04x", nValue);
102-
case 3: return ra::StringPrintf(L"%06x", nValue);
103-
case 4: return ra::StringPrintf(L"%08x", nValue);
104-
}
105-
}
106-
}
107-
10845
const char* ValueFormatToString(ValueFormat nFormat) noexcept
10946
{
11047
switch (nFormat)
@@ -138,109 +75,5 @@ ValueFormat ValueFormatFromString(const std::string& sFormat) noexcept
13875
return ra::itoe<ValueFormat>(rc_parse_format(sFormat.c_str()));
13976
}
14077

141-
unsigned FloatToU32(float fValue, MemSize nFloatType) noexcept
142-
{
143-
// this leverages the fact that Windows uses IEE754 floats
144-
union u
145-
{
146-
float fValue;
147-
unsigned nValue;
148-
} uUnion;
149-
150-
uUnion.fValue = fValue;
151-
152-
switch (nFloatType)
153-
{
154-
case MemSize::Float:
155-
return uUnion.nValue;
156-
157-
case MemSize::FloatBigEndian:
158-
return ReverseBytes(uUnion.nValue);
159-
160-
case MemSize::Double32:
161-
case MemSize::Double32BigEndian:
162-
{
163-
// double has 3 extra bits for the exponent
164-
const int32_t exponent = ra::to_signed((uUnion.nValue >> 23) & 0xFF) - 127 + 1023; // change exponent base from 127 to 1023
165-
const unsigned nValue = ((uUnion.nValue & 0x007FFFFF) >> 3) | // mantissa is shifted three bits right
166-
((ra::to_unsigned(exponent) & 0x7FF) << 20) | // adjusted exponent
167-
((uUnion.nValue & 0x80000000)); // sign is unmoved
168-
169-
return (nFloatType == MemSize::Double32) ? nValue : ReverseBytes(nValue);
170-
}
171-
172-
case MemSize::MBF32:
173-
case MemSize::MBF32LE:
174-
{
175-
// MBF32 puts the sign after the exponent, uses a 129 base instead of 127, and stores in big endian
176-
unsigned nValue = ((uUnion.nValue & 0x007FFFFF)) | // mantissa is unmoved
177-
((uUnion.nValue & 0x7F800000) << 1) | // exponent is shifted one bit left
178-
((uUnion.nValue & 0x80000000) >> 8); // sign is shifted eight bits right
179-
180-
nValue += 0x02000000; // adjust to 129 base
181-
return (nFloatType == MemSize::MBF32LE) ? nValue : ReverseBytes(nValue);
182-
}
183-
184-
default:
185-
return 0;
186-
}
187-
}
188-
189-
float U32ToFloat(unsigned nValue, MemSize nFloatType) noexcept
190-
{
191-
// this leverages the fact that Windows uses IEE754 floats
192-
union u
193-
{
194-
float fValue;
195-
unsigned nValue;
196-
} uUnion{};
197-
198-
switch (nFloatType)
199-
{
200-
case MemSize::FloatBigEndian:
201-
nValue = ReverseBytes(nValue);
202-
__fallthrough; // to MemSize::Float
203-
204-
case MemSize::Float:
205-
uUnion.nValue = nValue;
206-
break;
207-
208-
case MemSize::Double32BigEndian:
209-
nValue = ReverseBytes(nValue);
210-
__fallthrough; // to MemSize::Double32
211-
212-
case MemSize::Double32:
213-
{
214-
// double has 3 extra bits for the exponent, and uses a 1023 base instead of a 127 base
215-
const int32_t exponent = ra::to_signed((uUnion.nValue >> 20) & 0x7FF) - 1023 + 127; // change exponent base from 1023 to 127
216-
nValue = ((uUnion.nValue & 0x000FFFFF) << 3) | // mantissa is shifted three bits left
217-
((ra::to_unsigned(exponent) & 0xFF) << 23) | // adjusted exponent
218-
((uUnion.nValue & 0x80000000)); // sign is unmoved
219-
220-
uUnion.nValue = nValue;
221-
break;
222-
}
223-
224-
case MemSize::MBF32:
225-
nValue = ReverseBytes(nValue);
226-
__fallthrough; // to MemSize::MBF32LE
227-
228-
case MemSize::MBF32LE:
229-
// MBF32 puts the sign after the exponent, uses a 129 base instead of 127, and stores in big endian
230-
nValue -= 0x02000000; // adjust to 129 base
231-
nValue = ((nValue & 0x007FFFFF)) | // mantissa is unmoved
232-
((nValue & 0xFF000000) >> 1) | // exponent is shifted one bit right
233-
((nValue & 0x00800000) << 8); // sign is shifted eight bits left
234-
235-
uUnion.nValue = nValue;
236-
break;
237-
238-
default:
239-
return 0.0f;
240-
}
241-
242-
return uUnion.fValue;
243-
}
244-
24578
} /* namespace data */
24679
} /* namespace ra */

src/RA_Defs.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ using namespace std::string_literals;
3434
#endif // RA_EXPORTS
3535

3636
#include "data\Types.hh"
37+
#include "data\Memory.hh"
3738

3839
#define RA_DIR_OVERLAY L"Overlay\\"
3940
#define RA_DIR_BASE L"RACache\\"
@@ -165,8 +166,8 @@ class ResizeContent
165166
#endif
166167

167168
namespace ra {
168-
_NODISCARD std::string ByteAddressToString(_In_ ByteAddress nAddr);
169-
_NODISCARD ByteAddress ByteAddressFromString(_In_ const std::string& sByteAddress);
169+
_NODISCARD std::string ByteAddressToString(_In_ ra::data::ByteAddress nAddr);
170+
_NODISCARD ra::data::ByteAddress ByteAddressFromString(_In_ const std::string& sByteAddress);
170171
} // namespace ra
171172

172173
#endif // !RA_DEFS_H

src/RA_Integration.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@
7373
</Link>
7474
</ItemDefinitionGroup>
7575
<ItemGroup>
76+
<ClCompile Include="data\context\ConsoleContext.cpp" />
7677
<ClCompile Include="data\context\GameAssets.cpp" />
7778
<ClCompile Include="api\ApiCall.cpp" />
7879
<ClCompile Include="api\impl\ConnectedServer.cpp" />
7980
<ClCompile Include="api\impl\DisconnectedServer.cpp" />
8081
<ClCompile Include="api\impl\OfflineServer.cpp" />
81-
<ClCompile Include="data\context\ConsoleContext.cpp" />
8282
<ClCompile Include="data\context\EmulatorContext.cpp" />
8383
<ClCompile Include="data\context\GameContext.cpp" />
8484
<ClCompile Include="data\context\SessionTracker.cpp" />

src/RA_Integration.vcxproj.filters

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,6 @@
309309
<ClCompile Include="services\FrameEventQueue.cpp">
310310
<Filter>Services</Filter>
311311
</ClCompile>
312-
<ClCompile Include="data\context\ConsoleContext.cpp">
313-
<Filter>Data\Context</Filter>
314-
</ClCompile>
315312
<ClCompile Include="data\context\EmulatorContext.cpp">
316313
<Filter>Data\Context</Filter>
317314
</ClCompile>
@@ -423,6 +420,9 @@
423420
<ClCompile Include="services\impl\OfflineRcClient.cpp">
424421
<Filter>Services\Impl</Filter>
425422
</ClCompile>
423+
<ClCompile Include="data\context\ConsoleContext.cpp">
424+
<Filter>Data\Context</Filter>
425+
</ClCompile>
426426
</ItemGroup>
427427
<ItemGroup>
428428
<ClInclude Include="RA_Resource.h">
@@ -842,9 +842,6 @@
842842
<ClInclude Include="services\FrameEventQueue.hh">
843843
<Filter>Services</Filter>
844844
</ClInclude>
845-
<ClInclude Include="data\context\ConsoleContext.hh">
846-
<Filter>Data\Context</Filter>
847-
</ClInclude>
848845
<ClInclude Include="data\context\EmulatorContext.hh">
849846
<Filter>Data\Context</Filter>
850847
</ClInclude>
@@ -1040,6 +1037,9 @@
10401037
<ClInclude Include="services\impl\OfflineRcClient.hh">
10411038
<Filter>Services\Impl</Filter>
10421039
</ClInclude>
1040+
<ClInclude Include="data\context\ConsoleContext.hh">
1041+
<Filter>Data\Context</Filter>
1042+
</ClInclude>
10431043
</ItemGroup>
10441044
<ItemGroup>
10451045
<ResourceCompile Include="RA_Shared.rc">

src/api/DeleteCodeNote.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include "ApiCall.hh"
66

7-
#include "data\Types.hh"
7+
#include "data\Memory.hh"
88

99
namespace ra {
1010
namespace api {
@@ -22,7 +22,7 @@ public:
2222
struct Request : ApiRequestBase
2323
{
2424
unsigned int GameId{ 0U };
25-
ra::ByteAddress Address{ 0U };
25+
ra::data::ByteAddress Address{ 0U };
2626

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

src/api/FetchCodeNotes.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include "ApiCall.hh"
66

7-
#include "data\Types.hh"
7+
#include "data\Memory.hh"
88

99
namespace ra {
1010
namespace api {
@@ -18,7 +18,7 @@ public:
1818
{
1919
struct CodeNote
2020
{
21-
ra::ByteAddress Address{ 0U };
21+
ra::data::ByteAddress Address{ 0U };
2222
std::wstring Note;
2323
std::string Author;
2424
};

src/api/UpdateCodeNote.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public:
2222
struct Request : ApiRequestBase
2323
{
2424
unsigned int GameId{ 0U };
25-
ra::ByteAddress Address{ 0U };
25+
ra::data::ByteAddress Address{ 0U };
2626
std::wstring Note;
2727

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

src/api/impl/ConnectedServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ void ConnectedServer::ProcessCodeNotes(FetchCodeNotes::Response& response, const
610610
#pragma warning(pop)
611611

612612
static void SetCodeNote(ApiResponseBase& response, const char* sApiName,
613-
unsigned nGameId, ra::ByteAddress nAddress, const char* sNote)
613+
unsigned nGameId, ra::data::ByteAddress nAddress, const char* sNote)
614614
{
615615
rc_api_update_code_note_request_t api_params;
616616
memset(&api_params, 0, sizeof(api_params));

0 commit comments

Comments
 (0)