foxygit / fake-08-xbox360 Log in
commit eba146613a23f0f7a1e56e227aa1411e93360639
Author:     jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Thu Apr 8 07:55:58 2021 -0600
Commit:     jtothebell <j.to.the.bell@gmail.com>
CommitDate: Thu Apr 8 07:55:58 2021 -0600

    Don't reset general use ram on reload
---
 source/PicoRam.h       |  4 +++-
 test/endtoendtests.cpp | 25 +++++++++++++++++++++++++
 test/vmtests.cpp       |  6 ++++--
 3 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/source/PicoRam.h b/source/PicoRam.h
index fd2beca..bf33ccd 100644
--- a/source/PicoRam.h
+++ b/source/PicoRam.h
@@ -177,7 +177,9 @@ struct hwState_t {
 struct PicoRam
 {
     void Reset() {
-        memset(data, 0, 0x8000);
+        memset(data, 0, 0x4300);
+        //leave general use memory
+        memset(data + 0x5600, 0, 0x8000 - 0x5600);
     }

     union
diff --git a/test/endtoendtests.cpp b/test/endtoendtests.cpp
index 657a71a..7eda84e 100644
--- a/test/endtoendtests.cpp
+++ b/test/endtoendtests.cpp
@@ -495,6 +495,31 @@ TEST_CASE("Loading and running carts") {
             CHECK(verifyScreenshot(vm, "carts/screenshots/splittest_f01.png"));
         }

+        vm->CloseCart();
+    }
+    SUBCASE("General use memory persists across cart loads"){
+        vm->LoadCart("carts/cartparsetest.p8");
+        auto origFirstByte = vm->vm_peek(0);
+        vm->vm_poke(0x0000, 12);
+        vm->vm_poke(0x42ff, 92);
+
+        vm->vm_poke(0x4300, 33);
+        vm->vm_poke(0x55ff, 129);
+
+        vm->vm_poke(0x5600, 71);
+        vm->vm_poke(0x7fff, 223);
+        vm->LoadCart("carts/cartparsetest.p8");
+
+        CHECK_EQ(vm->vm_peek(0x0000), origFirstByte);
+        CHECK_EQ(vm->vm_peek(0x42ff), 0);
+
+        CHECK_EQ(vm->vm_peek(0x4300), 33);
+        CHECK_EQ(vm->vm_peek(0x55ff), 129);
+
+        CHECK_EQ(vm->vm_peek(0x5600), 0);
+        CHECK_EQ(vm->vm_peek(0x7fff), 0);
+
+
         vm->CloseCart();
     }

diff --git a/test/vmtests.cpp b/test/vmtests.cpp
index 0fb90d3..e5a4205 100644
--- a/test/vmtests.cpp
+++ b/test/vmtests.cpp
@@ -23,7 +23,7 @@ TEST_CASE("Vm memory functions") {
     SUBCASE("memory data stats with 0"){
         CHECK(memory->data[0] == 0);
     }
-    SUBCASE("resetting memory zeroes out everything"){
+    SUBCASE("resetting memory zeroes out everything except general use"){
         for(int i = 0; i < 0x8000; ++i) {
             memory->data[i] = i & 255;
         }
@@ -32,7 +32,9 @@ TEST_CASE("Vm memory functions") {

         bool allZeroes = true;
         for(int i = 0; i < 0x8000; ++i) {
-            allZeroes &= memory->data[i] == 0;
+            if (i < 0x4300 || i > 0x55ff) {
+                allZeroes &= memory->data[i] == 0;
+            }
         }

         CHECK(allZeroes);