diff --git a/src/core/moviedata.cpp b/src/core/moviedata.cpp index 84a78204..4fdcdd52 100644 --- a/src/core/moviedata.cpp +++ b/src/core/moviedata.cpp @@ -14,6 +14,7 @@ #include "core/settings.hpp" #include +#include struct moviefile our_movie; struct loaded_rom* our_rom; @@ -99,6 +100,17 @@ namespace our_movie.authors[index] = g; }); + function_ptr_command dump_coresave("dump-coresave", "Dump bsnes core state", + "Syntax: dump-coresave \nDumps core save to \n", + [](const std::string& name) throw(std::bad_alloc, std::runtime_error) { + auto x = save_core_state(); + x.resize(x.size() - 32); + std::ofstream y(name.c_str(), std::ios::out | std::ios::binary); + y.write(&x[0], x.size()); + y.close(); + messages << "Saved core state to " << name << std::endl; + }); + void warn_hash_mismatch(const std::string& mhash, const loaded_slot& slot, const std::string& name) { diff --git a/src/lua/memory.cpp b/src/lua/memory.cpp index 8ecfeb7e..f4cd654a 100644 --- a/src/lua/memory.cpp +++ b/src/lua/memory.cpp @@ -1,5 +1,6 @@ #include "core/lua-int.hpp" #include "core/memorymanip.hpp" +#include "core/rom.hpp" namespace { @@ -80,6 +81,19 @@ namespace return handle_push_vma(LS, regions, i); }); + const char* hexes = "0123456789ABCDEF"; + + function_ptr_luafun hashstate("memory.hash_state", [](lua_State* LS, const std::string& fname) -> int { + char hash[64]; + auto x = save_core_state(); + size_t offset = x.size() - 32; + for(unsigned i = 0; i < 32; i++) { + hash[2 * i + 0] = hexes[static_cast(x[offset + i]) >> 4]; + hash[2 * i + 1] = hexes[static_cast(x[offset + i]) & 0xF]; + } + lua_pushlstring(LS, hash, 64); + return 1; + }); lua_read_memory rub("memory.readbyte"); lua_read_memory rsb("memory.readsbyte");