diff --git a/Emulator/Components/Memory/Memory.cpp b/Emulator/Components/Memory/Memory.cpp index 7bcd08c30..67b1bede2 100644 --- a/Emulator/Components/Memory/Memory.cpp +++ b/Emulator/Components/Memory/Memory.cpp @@ -655,67 +655,11 @@ Memory::extFingerprint() const return util::crc32(ext, config.extSize); } -/* -const char * -Memory::romTitle() -{ - return RomFile::title(romFingerprint()); -} - -const char * -Memory::romVersion() -{ - return RomFile::version(romFingerprint()); -} - -const char * -Memory::romReleased() -{ - return RomFile::released(romFingerprint()); -} - -const char * -Memory::romModel() -{ - return RomFile::model(romFingerprint()); -} - -const char * -Memory::extTitle() -{ - return RomFile::title(extFingerprint()); -} - -const char * -Memory::extVersion() -{ - return RomFile::version(extFingerprint()); -} - -const char * -Memory::extReleased() -{ - return RomFile::released(extFingerprint()); -} - -const char * -Memory::extModel() -{ - return RomFile::model(extFingerprint()); -} - -bool -Memory::hasArosRom() const -{ - return RomFile::isArosRom(romFingerprint()); -} -*/ - void Memory::loadRom(MediaFile &file) { - assert(amiga.isPoweredOff()); - + // if (amiga.isPoweredOn()) throw Error(ERROR_POWERED_ON); + try { auto &romFile = dynamic_cast(file); @@ -802,8 +746,8 @@ Memory::loadExt(const u8 *buf, isize len) void Memory::saveRom(const std::filesystem::path &path) { - if (rom == nullptr) return; - + if (rom == nullptr) throw Error(ERROR_ROM_MISSING); + RomFile file(rom, config.romSize); file.writeToFile(path); } @@ -811,8 +755,8 @@ Memory::saveRom(const std::filesystem::path &path) void Memory::saveWom(const std::filesystem::path &path) { - if (wom == nullptr) return; - + if (wom == nullptr) throw Error(ERROR_ROM_MISSING); + RomFile file(wom, config.womSize); file.writeToFile(path); } @@ -820,7 +764,7 @@ Memory::saveWom(const std::filesystem::path &path) void Memory::saveExt(const std::filesystem::path &path) { - if (ext == nullptr) return; + if (ext == nullptr) throw Error(ERROR_ROM_MISSING); RomFile file(ext, config.extSize); file.writeToFile(path); diff --git a/Emulator/Components/Memory/MemoryDebugger.cpp b/Emulator/Components/Memory/MemoryDebugger.cpp index e36d4bc4b..414c432bd 100644 --- a/Emulator/Components/Memory/MemoryDebugger.cpp +++ b/Emulator/Components/Memory/MemoryDebugger.cpp @@ -216,6 +216,46 @@ MemoryDebugger::write(u32 addr, u32 val, isize sz, isize repeats) } } +void +MemoryDebugger::load(std::istream& is, u32 addr) +{ + for (;; addr++) { + + auto val = is.get(); + if (val == EOF) return; + + mem.patch(addr, u8(val)); + } +} + +void +MemoryDebugger::load(fs::path& path, u32 addr) +{ + std::ifstream stream(path, std::ifstream::binary); + if (!stream.is_open()) throw Error(ERROR_FILE_NOT_FOUND, path); + + load(stream, addr); +} + +void +MemoryDebugger::save(std::ostream& os, u32 addr, isize count) +{ + for (isize i = 0; i < count; i++) { + + auto val = mem.peek8 (u32(addr + i)); + os.put(val); + } +} + +void +MemoryDebugger::save(fs::path& path, u32 addr, isize count) +{ + std::ofstream stream(path, std::ifstream::binary); + if (!stream.is_open()) throw Error(ERROR_FILE_CANT_CREATE, path); + + save(stream, addr, count); +} + bool MemoryDebugger::isReadable(ChipsetReg reg) const { diff --git a/Emulator/Components/Memory/MemoryDebugger.h b/Emulator/Components/Memory/MemoryDebugger.h index 7eb6c484f..05d1cca4a 100644 --- a/Emulator/Components/Memory/MemoryDebugger.h +++ b/Emulator/Components/Memory/MemoryDebugger.h @@ -103,6 +103,14 @@ class MemoryDebugger final : public SubComponent // Writes a value into memory (multiple times) void write(u32 addr, u32 val, isize sz, isize repeats = 1); + // Loads a chunk of memory from a stream or file + void load(std::istream& is, u32 addr); + void load(fs::path& path, u32 addr); + + // Saves a chunk of memory to a stream or file + void save(std::ostream& is, u32 addr, isize count); + void save(fs::path& path, u32 addr, isize count); + // // Handling registers diff --git a/Emulator/Misc/RetroShell/CommandConsole.cpp b/Emulator/Misc/RetroShell/CommandConsole.cpp index 908e55ccd..34e1374de 100644 --- a/Emulator/Misc/RetroShell/CommandConsole.cpp +++ b/Emulator/Misc/RetroShell/CommandConsole.cpp @@ -319,7 +319,7 @@ CommandConsole::initCommands(Command &root) initSetters(root, mem); root.add({cmd, "load"}, - "Installs a Rom image"); + "Load memory contents from a file"); root.add({cmd, "load", "rom"}, { Arg::path }, "Installs a Kickstart Rom", @@ -328,12 +328,45 @@ CommandConsole::initCommands(Command &root) amiga.mem.loadRom(argv.front()); }); - root.add({cmd, "load", "extrom"}, { Arg::path }, - "Installs a Rom extension", + root.add({cmd, "load", "ext"}, { Arg::path }, + "Installs an extension Rom", [this](Arguments& argv, long value) { amiga.mem.loadExt(argv.front()); }); + + root.add({cmd, "load", "bin"}, { Arg::path, Arg::address }, + "Loads a chunk of memory", + [this](Arguments& argv, long value) { + + fs::path path(argv[0]); + amiga.mem.debugger.load(path, parseAddr(argv[1])); + }); + + root.add({cmd, "save"}, + "Save memory contents to a file"); + + root.add({cmd, "save", "rom"}, { Arg::path }, + "Saves the Kickstart Rom", + [this](Arguments& argv, long value) { + + amiga.mem.saveRom(argv[0]); + }); + + root.add({cmd, "save", "ext"}, { Arg::path }, + "Saves the extension Rom", + [this](Arguments& argv, long value) { + + amiga.mem.saveExt(argv[0]); + }); + + root.add({cmd, "save", "bin"}, { Arg::path, Arg::address, Arg::count }, + "Loads a chunk of memory", + [this](Arguments& argv, long value) { + + fs::path path(argv[0]); + amiga.mem.debugger.save(path, parseAddr(argv[1]), parseNum(argv[2])); + }); } // diff --git a/Emulator/Utilities/BasicTypes.h b/Emulator/Utilities/BasicTypes.h index ab52b31d6..7f7c4551c 100644 --- a/Emulator/Utilities/BasicTypes.h +++ b/Emulator/Utilities/BasicTypes.h @@ -32,6 +32,16 @@ using std::string; #endif +// +// Filesystem +// + +#ifdef __cplusplus +#include +namespace vamiga { namespace fs = std::filesystem; } +#endif + + // // Integers // diff --git a/Emulator/Utilities/IOUtils.h b/Emulator/Utilities/IOUtils.h index cd3e7d8ad..b8bf7b313 100644 --- a/Emulator/Utilities/IOUtils.h +++ b/Emulator/Utilities/IOUtils.h @@ -21,9 +21,6 @@ #include #include -// Namespace aliases -namespace vamiga { namespace fs = std::filesystem; } - namespace vamiga::util { //