commit 178c7909379cbeda63921955ec4d9d13aba568d8
Author: jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Fri Nov 13 19:26:31 2020 -0700
Commit: jtothebell <j.to.the.bell@gmail.com>
CommitDate: Fri Nov 13 19:26:31 2020 -0700
Tests trying to figure out pico driller input
---
test/carts/bitwiseandtest.p8 | 25 +++++++++++++++++++++++
test/carts/drillerinputtest.p8 | 36 +++++++++++++++++++++++++++++++++
test/vmtests.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 107 insertions(+)
diff --git a/test/carts/bitwiseandtest.p8 b/test/carts/bitwiseandtest.p8
new file mode 100644
index 0000000..d7f2352
--- /dev/null
+++ b/test/carts/bitwiseandtest.p8
@@ -0,0 +1,25 @@
+pico-8 cartridge // http://www.pico-8.com
+version 29
+__lua__
+
+function _update()
+
+end
+
+function _draw()
+ cls()
+ print(1 & 1)
+ print(1 & 2)
+ print(1 & 3)
+ print(2 & 0)
+ print(9 & 1)
+ print(11 & 2)
+end
+
+__gfx__
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
diff --git a/test/carts/drillerinputtest.p8 b/test/carts/drillerinputtest.p8
new file mode 100644
index 0000000..a93d6e7
--- /dev/null
+++ b/test/carts/drillerinputtest.p8
@@ -0,0 +1,36 @@
+pico-8 cartridge // http://www.pico-8.com
+version 29
+__lua__
+btnbits = 0
+function _update()
+ btnbits=0
+ for i=0,5 do
+ if btn(i) then
+ btnbits+=2^i
+ end
+ end
+end
+
+function _draw()
+ cls()
+ print(btnbits)
+ print(btn())
+ print(btnp())
+ leftband = band(btnbits,1);
+ rightband = band(btnbits,2);
+ print(leftband)
+ print(rightband)
+ if leftband>0 then
+ print("moving left")
+ end
+ if rightband>0 then
+ print("moving right")
+ end
+end
+__gfx__
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
diff --git a/test/vmtests.cpp b/test/vmtests.cpp
index af84b11..b942f48 100644
--- a/test/vmtests.cpp
+++ b/test/vmtests.cpp
@@ -386,6 +386,52 @@ TEST_CASE("Vm memory functions") {
CHECK_EQ(vm->vm_dget(34), 1923);
}
+ SUBCASE("pico driller style input"){
+ vm->LoadCart("carts/drillerinputtest.p8");
+
+ SUBCASE("no buttons gives 0"){
+ vm->UpdateAndDraw(0, 0);
+ bool btnbits = vm->ExecuteLua(
+ "function btnbitstest0()\n"
+ " return btnbits == 0\n"
+ "end\n",
+ "btnbitstest0");
+
+ CHECK(btnbits);
+ }
+ SUBCASE("left pushed returns 1"){
+ vm->UpdateAndDraw(1, 1);
+ bool btnbits = vm->ExecuteLua(
+ "function btnbitstest1()\n"
+ " printh(\"hello btnbits: \" .. btnbits .. \"\\\n\")"
+ " return btnbits == 1\n"
+ "end\n",
+ "btnbitstest1");
+
+ CHECK(btnbits);
+ }
+ SUBCASE("right pushed returns 2"){
+ vm->UpdateAndDraw(2, 2);
+ bool btnbits = vm->ExecuteLua(
+ "function btnbitstest2()\n"
+ " return btnbits == 2\n"
+ "end\n",
+ "btnbitstest2");
+
+ CHECK(btnbits);
+ }
+ SUBCASE("right pushed detected by band op"){
+ vm->UpdateAndDraw(2, 2);
+ bool btnbits = vm->ExecuteLua(
+ "function rightbandtest()\n"
+ " return rightband == 2\n"
+ "end\n",
+ "rightbandtest");
+
+ CHECK(btnbits);
+ }
+ vm->CloseCart();
+ }
delete graphics;