diff options
author | 2017-06-25 09:37:31 -0400 | |
---|---|---|
committer | 2017-06-25 09:37:31 -0400 | |
commit | dd951ec62f03ab67c9d51b43627c4e033f54f7f8 (patch) | |
tree | 420290cc3349fb4c1a073e43a4a40dd835869c24 /src/emu/debug/debugcmd.cpp | |
parent | 319eb61d0fec64eca6ee72eb824e0531fac552ba (diff) |
Made the debugger 'load' length field be optional, C++-ification
Diffstat (limited to 'src/emu/debug/debugcmd.cpp')
-rw-r--r-- | src/emu/debug/debugcmd.cpp | 60 |
1 files changed, 34 insertions, 26 deletions
diff --git a/src/emu/debug/debugcmd.cpp b/src/emu/debug/debugcmd.cpp index 145aaa0ac3f..ecb0c7d1c8a 100644 --- a/src/emu/debug/debugcmd.cpp +++ b/src/emu/debug/debugcmd.cpp @@ -20,6 +20,7 @@ #include "natkeyboard.h" #include "render.h" #include <ctype.h> +#include <fstream> @@ -206,10 +207,10 @@ debugger_commands::debugger_commands(running_machine& machine, debugger_cpu& cpu 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_DECRYPTED_OPCODES, 3, 4, std::bind(&debugger_commands::execute_save, this, _1, _2)); - m_console.register_command("load", CMDFLAG_NONE, AS_PROGRAM, 3, 4, std::bind(&debugger_commands::execute_load, this, _1, _2)); - m_console.register_command("loadd", CMDFLAG_NONE, AS_DATA, 3, 4, std::bind(&debugger_commands::execute_load, this, _1, _2)); - m_console.register_command("loadi", CMDFLAG_NONE, AS_IO, 3, 4, std::bind(&debugger_commands::execute_load, this, _1, _2)); - m_console.register_command("loado", CMDFLAG_NONE, AS_DECRYPTED_OPCODES, 3, 4, std::bind(&debugger_commands::execute_load, 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_DECRYPTED_OPCODES, 2, 4, std::bind(&debugger_commands::execute_load, 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)); @@ -1684,44 +1685,51 @@ void debugger_commands::execute_save(int ref, const std::vector<std::string> &pa void debugger_commands::execute_load(int ref, const std::vector<std::string> ¶ms) { - u64 offset, endoffset, length; + u64 offset, endoffset, length = 0; address_space *space; - FILE *f; u64 i; - /* validate parameters */ + // validate parameters if (!validate_number_parameter(params[1], offset)) return; - if (!validate_number_parameter(params[2], length)) + if (params.size() > 2 && !validate_number_parameter(params[2], length)) return; if (!validate_cpu_space_parameter((params.size() > 3) ? params[3].c_str() : nullptr, 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(params[0].c_str(), "rb"); - if (!f) + // open the file + std::ifstream f; + f.open(params[0], std::ifstream::in | std::ifstream::binary); + if (f.fail()) { m_console.printf("Error opening file '%s'\n", params[0].c_str()); return; } - /* now read the data in, ignore endoffset and load entire file if length has been set to zero (offset-1) */ - u8 byte; - for (i = offset; i <= endoffset || endoffset == offset - 1 ; i++) + // determine the file size, if not specified + if (params.size() <= 2) { - fread(&byte, 1, 1, f); - /* check if end of file has been reached and stop loading if it has */ - if (feof(f)) - break; - m_cpu.write_byte(*space, i, byte, true); + f.seekg(0, std::ios::end); + length = f.tellg(); + f.seekg(0); } - /* close the file */ - fclose(f); - if ( i == offset) + + // determine the addresses to read + endoffset = space->address_to_byte(offset + length - 1) & space->bytemask(); + offset = space->address_to_byte(offset) & space->bytemask(); + + // now read the data in, ignore endoffset and load entire file if length has been set to zero (offset-1) + for (i = offset; f.good() && (i <= endoffset || endoffset == offset - 1); i++) + { + char byte; + f.read(&byte, 1); + if (f) + m_cpu.write_byte(*space, i, byte, true); + } + + if (!f.good()) + m_console.printf("I/O error, load failed\n"); + else if (i == offset) m_console.printf("Length specified too large, load failed\n"); else m_console.printf("Data loaded successfully to memory : 0x%X to 0x%X\n", offset, i-1); |