foxygit / fake-08-xbox360 Log in
commit f611d936fcb94a8af13c99b9ed5c702fb52dc0ef
Author:     jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Sun Nov 15 19:14:03 2020 -0700
Commit:     jtothebell <j.to.the.bell@gmail.com>
CommitDate: Sun Nov 15 19:14:03 2020 -0700

    fix transparency getting overwritten on pal() call
---
 source/graphics.cpp    |  3 ++-
 test/graphicstests.cpp | 11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/source/graphics.cpp b/source/graphics.cpp
index 62890e8..b902027 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -818,7 +818,8 @@ void Graphics::pal() {
 void Graphics::pal(uint8_t c0, uint8_t c1, uint8_t p){
 	if (c0 < 16 && c1 < 16) {
 		if (p == 0) {
-			_memory->drawState.drawPaletteMap[c0] = c1;
+			//for draw palette we have to preserve the transparency bit
+			_memory->drawState.drawPaletteMap[c0] = (_memory->drawState.drawPaletteMap[c0] & 0x10) | (c1 & 0xf);
 		} else if (p == 1) {
 			_memory->drawState.screenPaletteMap[c0] = c1;
 		}
diff --git a/test/graphicstests.cpp b/test/graphicstests.cpp
index b409151..a1ca840 100644
--- a/test/graphicstests.cpp
+++ b/test/graphicstests.cpp
@@ -1579,6 +1579,17 @@ TEST_CASE("graphics class behaves as expected") {

         checkPoints(graphics, expectedPoints);
     }
+    SUBCASE("pal({c0}, {c1}, {p}) doesn't change default transparency") {
+        graphics->pal(0, 0, 0);
+
+        CHECK(graphics->isColorTransparent(0) == true);
+    }
+    SUBCASE("pal({c0}, {c1}, {p}) doesn't change transparency") {
+        graphics->palt(4, true);
+        graphics->pal(4, 7, 0);
+
+        CHECK(graphics->isColorTransparent(4) == true);
+    }
     SUBCASE("cursor({x}, {y}) sets cursor loc in memory"){
         graphics->cursor(4, 13);