commit d65e7376af53dd1ffe987f406a03b74e74d94280
Author: Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Sat Mar 2 17:46:16 2024 -0700
Commit: Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Sat Mar 2 17:46:16 2024 -0700
fix memory reset
carts still running too fast
---
source/graphics.cpp | 8 +++-----
source/main.cpp | 1 +
source/p8GlobalLuaFunctions.h | 4 +---
source/vm.cpp | 3 +++
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/source/graphics.cpp b/source/graphics.cpp
index e71e01d..f03f563 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -36,11 +36,9 @@ Graphics::Graphics(std::string fontdata, PicoRam* memory) {
uint8_t* Graphics::GetP8FrameBuffer(){
- // return _memory->hwState.screenDataMemMapping == 0
- // ? _memory->spriteSheetData
- // : _memory->screenBuffer;
- //not sure why this memory is wrong? maybe need to fix memory reset on cart load
- return _memory->screenBuffer;
+ return _memory->hwState.screenDataMemMapping == 0
+ ? _memory->spriteSheetData
+ : _memory->screenBuffer;
}
uint8_t* Graphics::GetP8SpriteSheetBuffer(){
diff --git a/source/main.cpp b/source/main.cpp
index 277434d..e9b5a30 100644
--- a/source/main.cpp
+++ b/source/main.cpp
@@ -38,6 +38,7 @@ int main(int argc, char* argv[])
Host *host = new Host(windowWidth, windowHeight);
PicoRam *memory = new PicoRam();
+ memory->Reset();
Audio *audio = new Audio(memory);
Logger_Initialize(host->logFilePrefix());
diff --git a/source/p8GlobalLuaFunctions.h b/source/p8GlobalLuaFunctions.h
index b0bd8ce..0d830fd 100644
--- a/source/p8GlobalLuaFunctions.h
+++ b/source/p8GlobalLuaFunctions.h
@@ -458,7 +458,6 @@ function __z8_reset_cartdata()
end
function __z8_run_cart(cart_code)
- printh("run cart func")
local glue_code = [[--
if (_init) _init()
if _update or _update60 or _draw then
@@ -474,7 +473,6 @@ function __z8_run_cart(cart_code)
_update_buttons()
end
if (_draw and do_frame) _draw()
- printh("game loop about to yield")
yield()
end
end
@@ -482,8 +480,8 @@ function __z8_run_cart(cart_code)
__z8_loop = cocreate(function()
+ -- Memory should be reset to default by the VM before this call
-- First reload cart into memory
- memset(0, 0, 0x8000)
reload()
__z8_reset_state()
diff --git a/source/vm.cpp b/source/vm.cpp
index ce2eb07..50e57ec 100644
--- a/source/vm.cpp
+++ b/source/vm.cpp
@@ -1068,6 +1068,9 @@ void Vm::vm_run() {
// loadCart(_loadedCart);
// }
+ //this might need to move?
+ _memory->Reset();
+
lua_getglobal(_luaState, "__z8_run_cart");
lua_pushstring(_luaState, _loadedCart->LuaString.c_str());
lua_pcall(_luaState, 1, 0, 0);