Some core debugging features:

- Lua function hashing core state
- Command to dump core state to file.
This commit is contained in:
Ilari Liusvaara 2011-11-12 00:40:02 +02:00
parent 18663a4caa
commit 22a41d1094
2 changed files with 26 additions and 0 deletions

View file

@ -14,6 +14,7 @@
#include "core/settings.hpp"
#include <iomanip>
#include <fstream>
struct moviefile our_movie;
struct loaded_rom* our_rom;
@ -99,6 +100,17 @@ namespace
our_movie.authors[index] = g;
});
function_ptr_command<const std::string&> dump_coresave("dump-coresave", "Dump bsnes core state",
"Syntax: dump-coresave <name>\nDumps core save to <name>\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)
{

View file

@ -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<unsigned char>(x[offset + i]) >> 4];
hash[2 * i + 1] = hexes[static_cast<unsigned char>(x[offset + i]) & 0xF];
}
lua_pushlstring(LS, hash, 64);
return 1;
});
lua_read_memory<uint8_t, uint8_t, memory_read_byte> rub("memory.readbyte");
lua_read_memory<int8_t, uint8_t, memory_read_byte> rsb("memory.readsbyte");