mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-18 03:13:55 +00:00
Small cleanup and utils
This commit is contained in:
@@ -79,6 +79,29 @@ namespace utils::string
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename Integer>
|
||||
requires(std::is_integral_v<Integer>)
|
||||
std::string to_hex_number(const Integer& i, const bool uppercase = false)
|
||||
{
|
||||
std::string res{};
|
||||
res.reserve(sizeof(i) * 2);
|
||||
|
||||
const std::span data{reinterpret_cast<const std::byte*>(&i), sizeof(i)};
|
||||
|
||||
for (const auto value : data)
|
||||
{
|
||||
const auto [high, low] = to_hex(value, uppercase);
|
||||
res.insert(res.begin(), {high, low});
|
||||
}
|
||||
|
||||
while (res.size() > 1 && res.front() == '0')
|
||||
{
|
||||
res.erase(res.begin());
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
template <typename Integer>
|
||||
requires(std::is_integral_v<Integer>)
|
||||
std::string to_hex_string(const Integer& i, const bool uppercase = false)
|
||||
|
||||
@@ -242,13 +242,7 @@ namespace gdb_stub
|
||||
const auto res = register_size <= data.size() && //
|
||||
handler.write_register(register_index, data.data(), register_size);
|
||||
|
||||
if (!res)
|
||||
{
|
||||
connection.send_reply("E01");
|
||||
return;
|
||||
}
|
||||
|
||||
connection.send_reply("OK");
|
||||
connection.send_reply(res ? "OK" : "E01");
|
||||
}
|
||||
|
||||
void read_memory(const connection_handler& connection, debugging_handler& handler, const std::string& payload)
|
||||
@@ -295,13 +289,7 @@ namespace gdb_stub
|
||||
data.resize(size);
|
||||
|
||||
const auto res = handler.write_memory(address, data.data(), data.size());
|
||||
if (!res)
|
||||
{
|
||||
connection.send_reply("E01");
|
||||
return;
|
||||
}
|
||||
|
||||
connection.send_reply("OK");
|
||||
connection.send_reply(res ? "OK" : "E01");
|
||||
}
|
||||
|
||||
std::string decode_x_memory(const std::string_view payload)
|
||||
|
||||
Reference in New Issue
Block a user