foxygit / fake-08-xbox360 Log in
commit bc0ddaff2ca75410460afeda2dddb1ef34cf7454
Author:     jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Mon Nov 23 06:43:18 2020 -0700
Commit:     jtothebell <j.to.the.bell@gmail.com>
CommitDate: Mon Nov 23 06:43:18 2020 -0700

    quick and dirty pass at implementing flip
---
 source/picoluaapi.cpp |  4 +++-
 source/vm.cpp         | 56 +++++++++++++++++++++++++++++++++++++++------------
 source/vm.h           |  2 ++
 3 files changed, 48 insertions(+), 14 deletions(-)

diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index d1fdd84..112c3a6 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -513,7 +513,9 @@ int fillp(lua_State *L) {
 }

 int flip(lua_State *L) {
-    return noop("flip");
+    _vmForLuaApi->vm_flip();
+
+    return 0;
 }

 //Input
diff --git a/source/vm.cpp b/source/vm.cpp
index 91a557d..c7ff2b6 100644
--- a/source/vm.cpp
+++ b/source/vm.cpp
@@ -131,6 +131,7 @@ bool Vm::loadCart(Cart* cart) {
     vm_reload(0, 0, sizeof(cart->CartRom), cart);

     _loadedCart = cart;
+    _cartChangeQueued = false;

     // initialize Lua interpreter
     _luaState = luaL_newstate();
@@ -313,6 +314,17 @@ void Vm::LoadCart(std::string filename){
 void Vm::UpdateAndDraw() {
     update_buttons();

+    _picoFrameCount++;
+
+    //todo: pause menu here, but for now just load bios
+    if (_input->btnp(6)) {
+        QueueCartChange("__FAKE08-BIOS.p8");
+    }
+
+    if (_cartChangeQueued) {
+        LoadCart(_nextCartKey);
+    }
+
     if (_hasUpdate){
         // Push the _update function on the top of the lua stack
         if (_targetFps == 60) {
@@ -337,18 +349,6 @@ void Vm::UpdateAndDraw() {
         lua_pop(_luaState, 0);
     }

-    _picoFrameCount++;
-
-    //todo: pause menu here, but for now just load bios
-    if (_input->btnp(6)) {
-        QueueCartChange("__FAKE08-BIOS.p8");
-    }
-
-    if (_cartChangeQueued) {
-        LoadCart(_nextCartKey);
-
-        _cartChangeQueued = false;
-    }
 }

 uint8_t* Vm::GetPicoInteralFb(){
@@ -650,4 +650,34 @@ void Vm::update_buttons() {
     //get button states from hardware
     auto inputState = _host->scanInput();
     _input->SetState(inputState.KDown, inputState.KHeld);
-}
\ No newline at end of file
+}
+
+void Vm::vm_flip() {
+    if (_host->shouldRunMainLoop() && !_host->shouldQuit()) {
+        update_buttons();
+
+        _picoFrameCount++;
+
+        //todo: pause menu here, but for now just load bios
+        if (_input->btnp(6)) {
+            QueueCartChange("__FAKE08-BIOS.p8");
+        }
+
+        if (_cartChangeQueued) {
+            LoadCart(_nextCartKey);
+        }
+
+        _host->changeStretch();
+
+        _host->setTargetFps(_targetFps);
+
+		uint8_t* picoFb = GetPicoInteralFb();
+		uint8_t* screenPaletteMap = GetScreenPaletteMap();
+
+		_host->drawFrame(picoFb, screenPaletteMap);
+
+        //is this better at the end of the loop?
+		_host->waitForTargetFps();
+    }
+
+}
diff --git a/source/vm.h b/source/vm.h
index 1b1cbc8..1b7b132 100644
--- a/source/vm.h
+++ b/source/vm.h
@@ -112,5 +112,7 @@ class Vm {
     void api_srand(fix32 seed);

     void update_buttons();
+
+    void vm_flip();
 };