commit b42ac9b569c99ab578eaba5407e7dd208013e75e
Author: Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Tue Jun 14 21:42:50 2022 -0600
Commit: Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Tue Jun 14 21:42:50 2022 -0600
Fix lua integration with pal call
Pull argument from correct index on stack, and return nothing instead of
zero.
Also add some unit tests around the new pal(p) call and an e2e test for
various pal args
---
source/picoluaapi.cpp | 12 ++++-----
test/carts/pal_args_test.p8 | 37 +++++++++++++++++++++++++++
test/carts/screenshots/pal_args_test_f01.png | Bin 0 -> 610 bytes
test/endtoendtests.cpp | 14 ++++++++++
test/graphicstests.cpp | 20 +++++++++++++++
5 files changed, 76 insertions(+), 7 deletions(-)
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index 3a2b84a..ad7e9df 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -585,10 +585,7 @@ int pal(lua_State *L) {
if (numArgs == 0) {
_graphicsForLuaApi->pal();
- //I think this always returns 0, not nil
- lua_pushnumber(L, 0);
-
- return 1;
+ return 0;
}
uint8_t p = 0;
@@ -614,10 +611,11 @@ int pal(lua_State *L) {
return 0;
} else if (numArgs == 1) {
- p = lua_tonumber(L, 0);
+ p = lua_tonumber(L, 1);
+
_graphicsForLuaApi->pal(p);
- lua_pushnumber(L, 0);
- return 1;
+
+ return 0;
}
diff --git a/test/carts/pal_args_test.p8 b/test/carts/pal_args_test.p8
new file mode 100644
index 0000000..4a71c2f
--- /dev/null
+++ b/test/carts/pal_args_test.p8
@@ -0,0 +1,37 @@
+pico-8 cartridge // http://www.pico-8.com
+version 35
+__lua__
+function _draw()
+ cls()
+
+ print(pal(),7)
+
+ rectfill(0,0,10,10,3)
+
+ print(pal(3,4),7)
+
+ rectfill(10,10,20,20,3)
+
+ print(pal(1),7)
+
+ rectfill(20,20,30,30,3)
+
+ print(pal(0),7)
+
+ rectfill(30,30,40,40,3)
+
+ print(pal(3,4),7)
+
+ rectfill(40,40,50,50,3)
+
+ print(pal(nil),7)
+
+ rectfill(50,50,60,60,3)
+end
+__gfx__
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
diff --git a/test/carts/screenshots/pal_args_test_f01.png b/test/carts/screenshots/pal_args_test_f01.png
new file mode 100644
index 0000000..c9d53c2
Binary files /dev/null and b/test/carts/screenshots/pal_args_test_f01.png differ
diff --git a/test/endtoendtests.cpp b/test/endtoendtests.cpp
index ee370b1..c388e39 100644
--- a/test/endtoendtests.cpp
+++ b/test/endtoendtests.cpp
@@ -595,6 +595,20 @@ TEST_CASE("Loading and running carts") {
vm->CloseCart();
}
+ SUBCASE("various pal args test"){
+ vm->LoadCart("pal_args_test.p8");
+
+ SUBCASE("No error reported"){
+ CHECK(vm->GetBiosError() == "");
+ }
+ SUBCASE("sceen matches screenshot"){
+ vm->UpdateAndDraw();
+
+ CHECK(verifyScreenshot(vm, host, "carts/screenshots/pal_args_test_f01.png"));
+ }
+
+ vm->CloseCart();
+ }
delete vm;
delete host;
diff --git a/test/graphicstests.cpp b/test/graphicstests.cpp
index 2a96d61..d296939 100644
--- a/test/graphicstests.cpp
+++ b/test/graphicstests.cpp
@@ -1668,6 +1668,26 @@ TEST_CASE("graphics class behaves as expected") {
CHECK(isDefault);
}
+ SUBCASE("pal(0) resets draw palette only") {
+ graphics->pal(14, 5, 0);
+ graphics->pal(13, 4, 1);
+ graphics->palt(15, true);
+
+ graphics->pal(0);
+
+ CHECK_EQ(14, graphics->getDrawPalMappedColor(14));
+ CHECK_EQ(4, graphics->getScreenPalMappedColor(13));
+ }
+ SUBCASE("pal(1) resets screen palette only") {
+ graphics->pal(14, 5, 0);
+ graphics->pal(13, 4, 1);
+ graphics->palt(15, true);
+
+ graphics->pal(1);
+
+ CHECK_EQ(5, graphics->getDrawPalMappedColor(14));
+ CHECK_EQ(13, graphics->getScreenPalMappedColor(13));
+ }
SUBCASE("pal changes sprite colors"){
for(int i = 0; i < 128; i++) {
for (int j = 0; j < 32; j++)