Commit 26b11781 authored by Jack's avatar Jack
Browse files

added backup of cartridge do be used with reload

parent 3848b4b0
......@@ -81,9 +81,10 @@ void GameView::render()
retro8::io::Loader loader;
if (_path.empty())
_path = "cartridges/lands-of-yocta.png";
_path = "cartridges/pico-racer.png";
loader.load(_path, machine);
machine.memory().backupCartridge();
int32_t fps = machine.code().require60fps() ? 60 : 30;
manager->setFrameRate(fps);
......
......@@ -784,6 +784,18 @@ namespace platform
return 0;
}
int reload(lua_State* L)
{
assert(lua_gettop(L) <= 3);
address_t dest = lua_to_or_default(L, number, 1, 0);
address_t src = lua_to_or_default(L, number, 1, 0);
int32_t length = lua_to_or_default(L, number, 1, address::CART_DATA_LENGTH);
std::memcpy(machine.memory().base() + dest, machine.memory().backup() + src, length);
return 0;
}
int btn(lua_State* L)
{
......@@ -971,6 +983,7 @@ void lua::registerFunctions(lua_State* L)
lua_register(L, "peek", platform::peek);
lua_register(L, "memset", platform::memset);
lua_register(L, "memcpy", platform::memcpy);
lua_register(L, "reload", platform::reload);
lua_register(L, "flip", platform::flip);
}
......
......@@ -31,11 +31,14 @@ namespace retro8
static constexpr address_t TILE_MAP_LOW = 0x1000;
static constexpr address_t TILE_MAP_HIGH = 0x2000;
static constexpr int32_t CART_DATA_LENGTH = 0x4300;
};
class Memory
{
private:
uint8_t _backup[address::CART_DATA_LENGTH];
uint8_t memory[1024 * 32];
static constexpr size_t BYTES_PER_PALETTE = sizeof(retro8::gfx::palette_t);
......@@ -54,6 +57,12 @@ namespace retro8
cursor()->reset();
}
void backupCartridge()
{
std::memcpy(_backup, memory, address::CART_DATA_LENGTH);
}
const uint8_t* backup() const { return _backup; }
uint8_t* base() { return memory; }
gfx::color_byte_t* penColor() { return as<gfx::color_byte_t>(address::PEN_COLOR); }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment