foxygit / fake-08-xbox360 Log in
commit 2e057c95dccdba51b0ec71853f2334c40aef79c5
Author:     jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Mon Sep 14 20:55:07 2020 -0600
Commit:     jtothebell <j.to.the.bell@gmail.com>
CommitDate: Tue Sep 15 17:09:09 2020 -0600

    add more screenshot tests and fix palette and clip bugs found by them
---
 source/graphics.cpp    | 16 ++++++++--------
 source/graphics.h      |  6 +++---
 test/endtoendtests.cpp | 28 ++--------------------------
 test/graphicstests.cpp | 14 +++++++-------
 4 files changed, 20 insertions(+), 44 deletions(-)

diff --git a/source/graphics.cpp b/source/graphics.cpp
index 2d5f655..a3c9815 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -318,40 +318,40 @@ uint8_t Graphics::getScreenPalMappedColor(uint8_t color) {
 bool Graphics::isWithinClip(int x, int y) {
 	return
 		x >= _memory->_gfxState_clip_xb &&
-		x <= _memory->_gfxState_clip_xe &&
+		x < _memory->_gfxState_clip_xe &&
 		y >= _memory->_gfxState_clip_yb &&
-		y <= _memory->_gfxState_clip_ye;
+		y < _memory->_gfxState_clip_ye;
 }

 bool Graphics::isXWithinClip(int x) {
 	return
 		x >= _memory->_gfxState_clip_xb &&
-		x <= _memory->_gfxState_clip_xe;
+		x < _memory->_gfxState_clip_xe;
 }

 bool Graphics::isYWithinClip(int y) {
 	return
 		y >= _memory->_gfxState_clip_yb &&
-		y <= _memory->_gfxState_clip_ye;
+		y < _memory->_gfxState_clip_ye;
 }


 int clampCoordToScreenDims(int val) {
-	return std::clamp(val, 0, 127);
+	return std::clamp(val, 0, 128);
 }

 int Graphics::clampXCoordToClip(int x) {
 	return std::clamp(
 		x,
 		_memory->_gfxState_clip_xb,
-		_memory->_gfxState_clip_xe);
+		_memory->_gfxState_clip_xe - 1);
 }

 int Graphics::clampYCoordToCLip(int y) {
 	return std::clamp(
 		y,
 		_memory->_gfxState_clip_yb,
-		_memory->_gfxState_clip_ye);
+		_memory->_gfxState_clip_ye - 1);
 }


@@ -766,7 +766,7 @@ void Graphics::camera(int x, int y) {
 }

 void Graphics::clip() {
-	this->clip(0, 0, 127, 127);
+	this->clip(0, 0, 128, 128);
 }

 void Graphics::clip(int x, int y, int w, int h) {
diff --git a/source/graphics.h b/source/graphics.h
index 15209f8..48e3cb8 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -4,7 +4,7 @@
 #include "hostVmShared.h"
 #include "PicoRam.h"

-#define COLOR_00 {  0,   0,   0, 255}
+#define COLOR_00 {  2,   4,   8, 255}
 #define COLOR_01 { 29,  43,  83, 255}
 #define COLOR_02 {126,  37,  83, 255}
 #define COLOR_03 {  0, 135,  81, 255}
@@ -14,8 +14,8 @@
 #define COLOR_07 {255, 241, 232, 255}
 #define COLOR_08 {255,   0,  77, 255}
 #define COLOR_09 {255, 163,   0, 255}
-#define COLOR_10 {255, 240,  36, 255}
-#define COLOR_11 {  0, 231,  86, 255}
+#define COLOR_10 {255, 236,  39, 255}
+#define COLOR_11 {  0, 228,  54, 255}
 #define COLOR_12 { 41, 173, 255, 255}
 #define COLOR_13 {131, 118, 156, 255}
 #define COLOR_14 {255, 119, 168, 255}
diff --git a/test/endtoendtests.cpp b/test/endtoendtests.cpp
index 1552dad..e95a926 100644
--- a/test/endtoendtests.cpp
+++ b/test/endtoendtests.cpp
@@ -41,21 +41,7 @@ bool verifyScreenshot(Vm* vm, std::string screenshotFilename) {
         //ignore alpha
         //uint8_t a = image[i + 3];

-        //pico 8 screenshots don't have pure black for some reason?
-        bool black = r == 2 && g == 4 && b == 8;
-
-        if (black) {
-            continue;
-        }
-
-        /*
-        if (!black && i < 128 * 4) {
-            int x = (i / 4) % 128;
-            int y = (i / 4) / 128;
-            printf("Non-black pixel at idx %d (%d,%d): rgb: %d,%d,%d\n", i, x, y, r, g, b);
-        }
-        */
-        uint8_t pixIdx = i / 4;
+        int pixIdx = i / 4;
         int x = pixIdx % 128;
         int y = pixIdx / 128;
         uint8_t c = picoFb[(x * 128) + y];
@@ -63,7 +49,7 @@ bool verifyScreenshot(Vm* vm, std::string screenshotFilename) {

         bool pixelMatches = r == col.Red && g == col.Green && b == col.Blue;

-        if (!pixelMatches && pixIdx < 512) {
+        if (!pixelMatches) {

             printf("Non-matching pixel at idx %d (%d,%d): rgb: %d,%d,%d\n", pixIdx, x, y, r, g, b);

@@ -105,9 +91,7 @@ TEST_CASE("Loading and running carts") {
         }
         SUBCASE("sceen matches screenshot")
         {
-            printf("e2e test calling update and draw\n");
             vm->UpdateAndDraw(0, 0);
-            printf("done calling update and draw\n");

             CHECK(verifyScreenshot(vm, "carts/screenshots/pset00-test_f01.png"));
         }
@@ -122,16 +106,13 @@ TEST_CASE("Loading and running carts") {
         }
         SUBCASE("sceen matches screenshot")
         {
-            printf("e2e test calling update and draw\n");
             vm->UpdateAndDraw(0, 0);
-            printf("done calling update and draw\n");

             CHECK(verifyScreenshot(vm, "carts/screenshots/pset3pix_f01.png"));
         }

         vm->CloseCart();
     }
-    /*
     SUBCASE("pset all pixels test cart renders correctly"){
         vm->LoadCart("carts/psetall.p8");

@@ -140,9 +121,7 @@ TEST_CASE("Loading and running carts") {
         }
         SUBCASE("sceen matches screenshot")
         {
-            printf("e2e test calling update and draw\n");
             vm->UpdateAndDraw(0, 0);
-            printf("done calling update and draw\n");

             CHECK(verifyScreenshot(vm, "carts/screenshots/psetall_f01.png"));
         }
@@ -157,16 +136,13 @@ TEST_CASE("Loading and running carts") {
         }
         SUBCASE("sceen matches screenshot")
         {
-            printf("e2e test calling update and draw\n");
             vm->UpdateAndDraw(0, 0);
-            printf("done calling update and draw\n");

             CHECK(verifyScreenshot(vm, "carts/screenshots/cliptest_f01.png"));
         }

         vm->CloseCart();
     }
-    */

     delete vm;
 }
\ No newline at end of file
diff --git a/test/graphicstests.cpp b/test/graphicstests.cpp
index 070876c..0d002f7 100644
--- a/test/graphicstests.cpp
+++ b/test/graphicstests.cpp
@@ -51,7 +51,7 @@ TEST_CASE("graphics class behaves as expected") {
     SUBCASE("Palette set up in constructor") {
         Color* palette = graphics->GetPaletteColors();
         Color testColor;
-        testColor = {  0,   0,   0, 255};
+        testColor = {  2,   4,   8, 255};
         CHECK(colorsEqual(& palette[0], & testColor) == true);
         testColor = { 29,  43,  83, 255};
         CHECK(colorsEqual(& palette[1], & testColor) == true);
@@ -71,9 +71,9 @@ TEST_CASE("graphics class behaves as expected") {
         CHECK(colorsEqual(& palette[8], & testColor) == true);
         testColor = {255, 163,   0, 255};
         CHECK(colorsEqual(& palette[9], & testColor) == true);
-        testColor = {255, 240,  36, 255};
+        testColor = {255, 236,  39, 255};
         CHECK(colorsEqual(& palette[10], & testColor) == true);
-        testColor = {  0, 231,  86, 255};
+        testColor = {  0, 228,  54, 255};
         CHECK(colorsEqual(& palette[11], & testColor) == true);
         testColor = { 41, 173, 255, 255};
         CHECK(colorsEqual(& palette[12], & testColor) == true);
@@ -87,8 +87,8 @@ TEST_CASE("graphics class behaves as expected") {
     SUBCASE("Constructor sets default clip") {
         CHECK(picoRam._gfxState_clip_xb == 0);
         CHECK(picoRam._gfxState_clip_yb == 0);
-        CHECK(picoRam._gfxState_clip_xe == 127);
-        CHECK(picoRam._gfxState_clip_ye == 127);
+        CHECK(picoRam._gfxState_clip_xe == 128);
+        CHECK(picoRam._gfxState_clip_ye == 128);
     }
     SUBCASE("Constructor sets default color") {
         CHECK(picoRam._gfxState_color == 7);
@@ -1178,9 +1178,9 @@ TEST_CASE("graphics class behaves as expected") {
         graphics->clip();

         CHECK_EQ(picoRam._gfxState_clip_xb, 0);
-        CHECK_EQ(picoRam._gfxState_clip_xe, 127);
+        CHECK_EQ(picoRam._gfxState_clip_xe, 128);
         CHECK_EQ(picoRam._gfxState_clip_yb, 0);
-        CHECK_EQ(picoRam._gfxState_clip_ye, 127);
+        CHECK_EQ(picoRam._gfxState_clip_ye, 128);
     }
     SUBCASE("clip({x}, {y}, {w}, {h}) sets clip in memory")
     {