From 00a3403054702713c0e6433f0134e72351bb0229 Mon Sep 17 00:00:00 2001 From: Scott Stone Date: Thu, 3 Feb 2011 17:09:41 +0000 Subject: [PATCH] Add basic LOAD function to the debugger to complement the existing SAVE function. It allows you to load a binary file straight into writeable memory. The format is the same as the SAVE function with the exception that the can be handled differently. [Pugsy] --- src/emu/debug/debugcmd.c | 55 ++++++++++++++++++++++++++++++++++++++++ src/emu/debug/debughlp.c | 25 ++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/src/emu/debug/debugcmd.c b/src/emu/debug/debugcmd.c index dbea2d50af8..8c5c98ef234 100644 --- a/src/emu/debug/debugcmd.c +++ b/src/emu/debug/debugcmd.c @@ -130,6 +130,7 @@ static void execute_wpdisenable(running_machine *machine, int ref, int params, c static void execute_wplist(running_machine *machine, int ref, int params, const char **param); static void execute_hotspot(running_machine *machine, int ref, int params, const char **param); static void execute_save(running_machine *machine, int ref, int params, const char **param); +static void execute_load(running_machine *machine, int ref, int params, const char **param); static void execute_dump(running_machine *machine, int ref, int params, const char **param); static void execute_cheatinit(running_machine *machine, int ref, int params, const char **param); static void execute_cheatnext(running_machine *machine, int ref, int params, const char **param); @@ -314,6 +315,10 @@ void debug_command_init(running_machine *machine) debug_console_register_command(machine, "saved", CMDFLAG_NONE, ADDRESS_SPACE_DATA, 3, 4, execute_save); debug_console_register_command(machine, "savei", CMDFLAG_NONE, ADDRESS_SPACE_IO, 3, 4, execute_save); + debug_console_register_command(machine, "load", CMDFLAG_NONE, ADDRESS_SPACE_PROGRAM, 3, 4, execute_load); + debug_console_register_command(machine, "loadd", CMDFLAG_NONE, ADDRESS_SPACE_DATA, 3, 4, execute_load); + debug_console_register_command(machine, "loadi", CMDFLAG_NONE, ADDRESS_SPACE_IO, 3, 4, execute_load); + debug_console_register_command(machine, "dump", CMDFLAG_NONE, ADDRESS_SPACE_PROGRAM, 3, 6, execute_dump); debug_console_register_command(machine, "dumpd", CMDFLAG_NONE, ADDRESS_SPACE_DATA, 3, 6, execute_dump); debug_console_register_command(machine, "dumpi", CMDFLAG_NONE, ADDRESS_SPACE_IO, 3, 6, execute_dump); @@ -1547,6 +1552,56 @@ static void execute_save(running_machine *machine, int ref, int params, const ch } +/*------------------------------------------------- + execute_load - execute the load command +-------------------------------------------------*/ + +static void execute_load(running_machine *machine, int ref, int params, const char *param[]) +{ + UINT64 offset, endoffset, length; + address_space *space; + FILE *f; + UINT64 i; + + /* validate parameters */ + if (!debug_command_parameter_number(machine, param[1], &offset)) + return; + if (!debug_command_parameter_number(machine, param[2], &length)) + return; + if (!debug_command_parameter_cpu_space(machine, (params > 3) ? param[3] : NULL, ref, &space)) + return; + + /* determine the addresses to read */ + endoffset = space->address_to_byte(offset + length - 1) & space->bytemask(); + offset = space->address_to_byte(offset) & space->bytemask(); + + /* open the file */ + f = fopen(param[0], "rb"); + if (!f) + { + debug_console_printf(machine, "Error opening file '%s'\n", param[0]); + return; + } + + /* now read the data in, ignore endoffset and load entire file if length has been set to zero (offset-1) */ + UINT8 byte; + for (i = offset; i <= endoffset || endoffset == offset - 1 ; i++) + { + fread(&byte, 1, 1, f); + /* check if end of file has been reached and stop loading if it has */ + if (feof(f)) + break; + debug_write_byte(space, i, byte, TRUE); + } + /* close the file */ + fclose(f); + if ( i == offset) + debug_console_printf(machine, "Length specified too large, load failed\n"); + else + debug_console_printf(machine, "Data loaded successfully to memory : 0x%s to 0x%s\n", core_i64_hex_format(offset,0), core_i64_hex_format(i-1,0)); +} + + /*------------------------------------------------- execute_dump - execute the dump command -------------------------------------------------*/ diff --git a/src/emu/debug/debughlp.c b/src/emu/debug/debughlp.c index 8ef20db442f..36f06e15a15 100644 --- a/src/emu/debug/debughlp.c +++ b/src/emu/debug/debughlp.c @@ -106,6 +106,9 @@ static const help_item static_help_list[] = " save ,
,[,] -- save binary program memory to the given file\n" " saved ,
,[,] -- save binary data memory to the given file\n" " savei ,
,[,] -- save binary I/O memory to the given file\n" + " load ,
,[,] -- load binary program memory from the given file\n" + " loadd ,
,[,] -- load binary data memory from the given file\n" + " loadi ,
,[,] -- load binary I/O memory from the given file\n" " map
-- map logical program address to physical address and bank\n" " mapd
-- map logical data address to physical address and bank\n" " mapi
-- map logical I/O address to physical address and bank\n" @@ -488,6 +491,28 @@ static const help_item static_help_list[] = "saved harddriv.bin,3000,1000,3\n" " Saves data memory addresses 3000-3fff from CPU #3 to the binary file 'harddriv.bin'.\n" }, + { + "load", + "\n" + " load[{d|i}] ,
,[,]\n" + "\n" + "The load/loadd/loadi commands load raw memory from the binary file specified in the " + "parameter. 'load' will load program space memory, while 'loadd' will load data space memory " + "and 'loadi' will load I/O space memory.
indicates the address of the start of saving, " + "and indicates how much memory to load. The range
through
+-1 " + "inclusive will be read in from the file. If you specify = 0 or a length greater than the " + "total length of the file it will load the entire contents of the file and no more. You can also load " + "memory from another CPU by specifying the parameter.\n" + "NOTE: This will only actually write memory that is possible to overwrite in the Memory Window\n" + "\n" + "Examples:\n" + "\n" + "load venture.bin,0,10000\n" + " Loads addresses 0-ffff in the current CPU from the binary file 'venture.bin'.\n" + "\n" + "loadd harddriv.bin,3000,1000,3\n" + " Loads data memory addresses 3000-3fff from CPU #3 from the binary file 'harddriv.bin'.\n" + }, { "step", "\n"