Export the rerecord count via MMIO and Lua

This commit is contained in:
Ilari Liusvaara 2012-09-09 10:37:46 +03:00
parent 8e762c67e0
commit b9266f2bd4
4 changed files with 27 additions and 0 deletions

View file

@ -113,6 +113,12 @@ public:
* throws std::bad_alloc: Not enough memory.
*/
static uint64_t count(std::vector<char>& strm) throw(std::bad_alloc);
/**
* Count number of rerecords.
*
* returns: Rerecord count.
*/
static uint64_t count() throw();
/**
* Internal pointer used by add_internal.
*/

View file

@ -5,6 +5,7 @@
#include "core/moviedata.hpp"
#include "core/misc.hpp"
#include "core/rom.hpp"
#include "core/rrdata.hpp"
#include "library/string.hpp"
#include <iostream>
@ -56,6 +57,10 @@ namespace
//Lag counter.
uint64_t x = get_movie().get_lag_frames();
return x >> (8 * (offset & 7));
} else if(offset >= 24 && offset < 32 && !write) {
//Rerecord counter.
uint64_t x = rrdata::count();
return x >> (8 * (offset & 7));
} else
return 0;
}

View file

@ -287,6 +287,16 @@ uint64_t rrdata::count(std::vector<char>& strm) throw(std::bad_alloc)
return read(strm, true);
}
uint64_t rrdata::count() throw()
{
uint64_t c = rrset.size();
if(c)
return c - 1;
else
return 0;
}
std::ostream& operator<<(std::ostream& os, const struct rrdata::instance& j)
{
for(unsigned i = 0; i < 32; i++) {

View file

@ -1,6 +1,7 @@
#include "lua/internal.hpp"
#include "lua/unsaferewind.hpp"
#include "core/movie.hpp"
#include "core/rrdata.hpp"
#include "core/moviedata.hpp"
#include "core/mainloop.hpp"
@ -18,6 +19,11 @@ namespace
return 1;
});
function_ptr_luafun mrrs("movie.rerecords", [](lua_State* LS, const std::string& fname) -> int {
lua_pushnumber(LS, rrdata::count());
return 1;
});
function_ptr_luafun mro("movie.readonly", [](lua_State* LS, const std::string& fname) -> int {
auto& m = get_movie();
lua_pushboolean(LS, m.readonly_mode() ? 1 : 0);