foxygit / fake-08-xbox360 Log in
commit 87c369da007c27575f580a399579f0c774e1cb8a
Author:     Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Wed Apr 28 17:47:47 2021 -0600
Commit:     Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Wed Apr 28 17:47:47 2021 -0600

    Only write out cart data on cart change
---
 source/vm.cpp | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/source/vm.cpp b/source/vm.cpp
index ae43232..b8a4b87 100644
--- a/source/vm.cpp
+++ b/source/vm.cpp
@@ -113,6 +113,11 @@ bool abortLua;

 bool Vm::loadCart(Cart* cart) {
     _picoFrameCount = 0;
+
+    if (_cartdataKey.length() > 0) {
+        _host->saveCartData(_cartdataKey, getSerializedCartData());
+    }
+
     _cartdataKey = "";

     //reset memory (may have to be more selective about zeroing out to be accurate?)
@@ -714,11 +719,6 @@ fix32 Vm::vm_dget(uint8_t n) {
 void Vm::vm_dset(uint8_t n, fix32 value){
     if (n < 64) {
         vm_poke4(0x5e00 + 4 * n, value);
-
-        //pico 8 seems to write immediately
-        if (_cartdataKey.length() > 0) {
-            _host->saveCartData(_cartdataKey, getSerializedCartData());
-        }
     }
 }