diff options
author | Oxore <oxore@protonmail.com> | 2022-09-03 14:54:34 +0300 |
---|---|---|
committer | Oxore <oxore@protonmail.com> | 2022-09-03 15:12:58 +0300 |
commit | 9037b017d6519fed435eea20c3553d40d871d379 (patch) | |
tree | edd55ac4880c980f772f7a466f00edf5837fd38b /emulator.cpp | |
parent | f1573848a8ced69f45192b07bab9785e900d34a0 (diff) |
Impl writing memory via GDB
Diffstat (limited to 'emulator.cpp')
-rw-r--r-- | emulator.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/emulator.cpp b/emulator.cpp index 96588cd..1c8c6f9 100644 --- a/emulator.cpp +++ b/emulator.cpp @@ -4,6 +4,7 @@ #include "bus.hpp" #include "m68k_debugging.hpp" #include "gdbremote_parser.hpp" +#include "utils.hpp" #include "musashi-m68k/m68k.h" #include <cassert> @@ -92,14 +93,6 @@ static int setup_socket(uint16_t port) return socket_fd; } -static inline void ConvertByteToHex(uint8_t byte, char* out) -{ - const uint8_t c1 = (byte >> 4) & 0x0f; - const uint8_t c2 = byte& 0x0f; - out[0] = static_cast<char>(c1 < 0xa ? c1 + '0' : c1 + ('a' - 0xa)); - out[1] = static_cast<char>(c2 < 0xa ? c2 + '0' : c2 + ('a' - 0xa)); -} - static std::string CreateResponse( M68KDebuggingControl& m68k_debug, const GDBRemote::Packet& packet) @@ -131,9 +124,19 @@ static std::string CreateResponse( auto ret_data = std::string(length * 2, '\0'); for (uint32_t i = 0; i < length; i++) { const uint8_t byte = m68k_debug.Read8(i + offset); - ConvertByteToHex(byte, &ret_data[i*2]); + Utils::ConvertByteToHex(byte, &ret_data[i*2]); } return ret_data; + } else if (packet.type == PacketType::kWriteMemory) { + const auto * const packet_data = + reinterpret_cast<const PacketDataWriteMemory*>(packet.data.get()); + const uint32_t offset = packet_data->offset; + const uint32_t length = packet_data->length; + const auto write_data = packet_data->data; + for (uint32_t i = 0; i < length; i++) { + m68k_debug.Write8(i + offset, write_data[i]); + } + return "OK"; } else if (packet.type == PacketType::kReadGeneralRegisters) { const M68KCPUState state = m68k_debug.GetCPUState(); std::string result{}; |