summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Jacob <bombzj@gmail.com>2020-06-22 07:28:21 +0800
committer GitHub <noreply@github.com>2020-06-21 19:28:21 -0400
commit669b0fd4754d895f9c7ab32ce19ce957001cdf5e (patch)
tree8362f6339e19d8a78f7a437a51c74df8c4f50c00
parentec55387d2b251635a0ba8ca4460f13c60260bb1a (diff)
add saver to operate memory region (#6837)
* add debugger command saver for memory region * added debugger command loadr for memory region
-rw-r--r--src/emu/debug/debugcmd.cpp110
-rw-r--r--src/emu/debug/debugcmd.h5
2 files changed, 115 insertions, 0 deletions
diff --git a/src/emu/debug/debugcmd.cpp b/src/emu/debug/debugcmd.cpp
index efdd93da307..eaa273ee886 100644
--- a/src/emu/debug/debugcmd.cpp
+++ b/src/emu/debug/debugcmd.cpp
@@ -233,11 +233,13 @@ debugger_commands::debugger_commands(running_machine& machine, debugger_cpu& cpu
m_console.register_command("saved", CMDFLAG_NONE, AS_DATA, 3, 4, std::bind(&debugger_commands::execute_save, this, _1, _2));
m_console.register_command("savei", CMDFLAG_NONE, AS_IO, 3, 4, std::bind(&debugger_commands::execute_save, this, _1, _2));
m_console.register_command("saveo", CMDFLAG_NONE, AS_OPCODES, 3, 4, std::bind(&debugger_commands::execute_save, this, _1, _2));
+ m_console.register_command("saver", CMDFLAG_NONE, 0, 4, 4, std::bind(&debugger_commands::execute_saveregion, this, _1, _2));
m_console.register_command("load", CMDFLAG_NONE, AS_PROGRAM, 2, 4, std::bind(&debugger_commands::execute_load, this, _1, _2));
m_console.register_command("loadd", CMDFLAG_NONE, AS_DATA, 2, 4, std::bind(&debugger_commands::execute_load, this, _1, _2));
m_console.register_command("loadi", CMDFLAG_NONE, AS_IO, 2, 4, std::bind(&debugger_commands::execute_load, this, _1, _2));
m_console.register_command("loado", CMDFLAG_NONE, AS_OPCODES, 2, 4, std::bind(&debugger_commands::execute_load, this, _1, _2));
+ m_console.register_command("loadr", CMDFLAG_NONE, 0, 4, 4, std::bind(&debugger_commands::execute_loadregion, this, _1, _2));
m_console.register_command("dump", CMDFLAG_NONE, AS_PROGRAM, 3, 7, std::bind(&debugger_commands::execute_dump, this, _1, _2));
m_console.register_command("dumpd", CMDFLAG_NONE, AS_DATA, 3, 7, std::bind(&debugger_commands::execute_dump, this, _1, _2));
@@ -530,6 +532,25 @@ bool debugger_commands::validate_cpu_space_parameter(const char *param, int spac
/*-------------------------------------------------
+ validate_memory_region_parameter - validates
+ a parameter as a memory region name and
+ retrieves the given memory region
+-------------------------------------------------*/
+
+bool debugger_commands::validate_memory_region_parameter(const std::string &param, memory_region *&result)
+{
+ auto &regions = m_machine.memory().regions();
+ auto iter = regions.find(param);
+ if(iter == regions.end()) {
+ m_console.printf("No matching memory region found for '%s'\n", param);
+ return false;
+ }
+ result = iter->second.get();
+ return true;
+}
+
+
+/*-------------------------------------------------
debug_command_parameter_expression - validates
an expression parameter
-------------------------------------------------*/
@@ -1949,6 +1970,46 @@ void debugger_commands::execute_save(int ref, const std::vector<std::string> &pa
/*-------------------------------------------------
+ execute_saveregion - execute the save command on region memory
+-------------------------------------------------*/
+
+void debugger_commands::execute_saveregion(int ref, const std::vector<std::string> &params)
+{
+ u64 offset, length;
+ memory_region *region;
+ FILE *f;
+
+ /* validate parameters */
+ if (!validate_number_parameter(params[1], offset))
+ return;
+ if (!validate_number_parameter(params[2], length))
+ return;
+ if (!validate_memory_region_parameter(params[3], region))
+ return;
+
+ /* open the file */
+ f = fopen(params[0].c_str(), "wb");
+ if (!f) {
+ m_console.printf("Error opening file '%s'\n", params[0].c_str());
+ return;
+ }
+
+ if(offset >= region->bytes()) {
+ m_console.printf("Invalide offset\n");
+ return;
+ }
+ // get full length
+ if(length <= 0 || length + offset >= region->bytes()) {
+ length = region->bytes() - offset;
+ }
+ fwrite(region->base() + offset, 1, length, f);
+
+ fclose(f);
+ m_console.printf("Data saved successfully\n");
+}
+
+
+/*-------------------------------------------------
execute_load - execute the load command
-------------------------------------------------*/
@@ -2057,6 +2118,55 @@ void debugger_commands::execute_load(int ref, const std::vector<std::string> &pa
/*-------------------------------------------------
+ execute_saveregion - execute the save command on region memory
+-------------------------------------------------*/
+
+void debugger_commands::execute_loadregion(int ref, const std::vector<std::string> &params)
+{
+ u64 offset, length;
+ memory_region *region;
+ FILE *f;
+
+ /* validate parameters */
+ if (!validate_number_parameter(params[1], offset))
+ return;
+ if (!validate_number_parameter(params[2], length))
+ return;
+ if (!validate_memory_region_parameter(params[3], region))
+ return;
+
+ /* open the file */
+ f = fopen(params[0].c_str(), "rb");
+ if (!f) {
+ m_console.printf("Error opening file '%s'\n", params[0].c_str());
+ return;
+ }
+
+ fseek(f, 0L, SEEK_END);
+ u64 size = ftell(f);
+ rewind(f);
+
+ if(offset >= region->bytes()) {
+ m_console.printf("Invalide offset\n");
+ return;
+ }
+ // get full length
+ if(length <= 0 || length + offset >= region->bytes()) {
+ length = region->bytes() - offset;
+ }
+ // check file size
+ if(length >= size) {
+ length = size;
+ }
+
+ fread(region->base() + offset, 1, length, f);
+
+ fclose(f);
+ m_console.printf("Data loaded successfully to memory : 0x%X to 0x%X\n", offset, offset + length - 1);
+}
+
+
+/*-------------------------------------------------
execute_dump - execute the dump command
-------------------------------------------------*/
diff --git a/src/emu/debug/debugcmd.h b/src/emu/debug/debugcmd.h
index a47378765ff..04f54a4d75d 100644
--- a/src/emu/debug/debugcmd.h
+++ b/src/emu/debug/debugcmd.h
@@ -34,6 +34,9 @@ public:
/* validates a parameter as a cpu and retrieves the given address space */
bool validate_cpu_space_parameter(const char *param, int spacenum, address_space *&result);
+ /* validates a parameter as a memory region name and retrieves the given region */
+ bool validate_memory_region_parameter(const std::string &param, memory_region *&result);
+
private:
struct global_entry
{
@@ -139,7 +142,9 @@ private:
void execute_stateload(int ref, const std::vector<std::string> &params);
void execute_rewind(int ref, const std::vector<std::string> &params);
void execute_save(int ref, const std::vector<std::string> &params);
+ void execute_saveregion(int ref, const std::vector<std::string> &params);
void execute_load(int ref, const std::vector<std::string> &params);
+ void execute_loadregion(int ref, const std::vector<std::string> &params);
void execute_dump(int ref, const std::vector<std::string> &params);
void execute_cheatinit(int ref, const std::vector<std::string> &params);
void execute_cheatnext(int ref, const std::vector<std::string> &params);