mirror of
https://github.com/holub/mame
synced 2025-04-19 15:11:37 +03:00
add saver to operate memory region (#6837)
* add debugger command saver for memory region * added debugger command loadr for memory region
This commit is contained in:
parent
ec55387d2b
commit
669b0fd475
@ -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));
|
||||
@ -529,6 +531,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 ¶m, memory_region *&result)
|
||||
{
|
||||
auto ®ions = 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
|
||||
@ -1948,6 +1969,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> ¶ms)
|
||||
{
|
||||
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
|
||||
-------------------------------------------------*/
|
||||
@ -2056,6 +2117,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> ¶ms)
|
||||
{
|
||||
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
|
||||
-------------------------------------------------*/
|
||||
|
@ -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 ¶m, memory_region *&result);
|
||||
|
||||
private:
|
||||
struct global_entry
|
||||
{
|
||||
@ -139,7 +142,9 @@ private:
|
||||
void execute_stateload(int ref, const std::vector<std::string> ¶ms);
|
||||
void execute_rewind(int ref, const std::vector<std::string> ¶ms);
|
||||
void execute_save(int ref, const std::vector<std::string> ¶ms);
|
||||
void execute_saveregion(int ref, const std::vector<std::string> ¶ms);
|
||||
void execute_load(int ref, const std::vector<std::string> ¶ms);
|
||||
void execute_loadregion(int ref, const std::vector<std::string> ¶ms);
|
||||
void execute_dump(int ref, const std::vector<std::string> ¶ms);
|
||||
void execute_cheatinit(int ref, const std::vector<std::string> ¶ms);
|
||||
void execute_cheatnext(int ref, const std::vector<std::string> ¶ms);
|
||||
|
Loading…
Reference in New Issue
Block a user