From 431377f92e6c1cbc2ece7d6d4557f40d3793ad1c Mon Sep 17 00:00:00 2001 From: Simon Gellis Date: Wed, 9 Oct 2024 23:25:43 -0400 Subject: [PATCH] Implement writing to memory --- server.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/server.c b/server.c index c4792af..03e104e 100644 --- a/server.c +++ b/server.c @@ -223,6 +223,22 @@ int handle_command(RdbResponse *res, CommandBuf *cmd, VB *sim, bool *running) { } return rdb_response_send_packet(res); } + if (cmd_match_str(cmd, "M")) { + /* write memory */ + uint32_t i, address, len; + if (!cmd_match_hex_number(cmd, &address)) return -1; + if (!cmd_match_str(cmd, ",")) return -1; + if (!cmd_match_hex_number(cmd, &len)) return -1; + if (!cmd_match_str(cmd, ":")) return -1; + + for (i = 0; i < len; ++i) { + uint8_t byte; + if (!cmd_match_hex_bytes(cmd, 1, &byte)) return -1; + vbWrite(sim, address + i, VB_U8, byte); + } + rdb_response_write_str(res, "OK"); + return rdb_response_send_packet(res); + } fprintf(stderr, "Unrecognized command.\n"); return rdb_response_send_packet(res); }