foxygit / fake-08-xbox360 Log in
commit de5b219ad9f3d71b6c362eb390a9bf7fbcdb97b6
Author:     Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Tue Dec 30 08:44:57 2025 -0700
Commit:     Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Tue Dec 30 08:44:57 2025 -0700

    fix emoji as btn arguments (pass into sandbox)
---
 source/p8GlobalLuaFunctions.h |  28 +++++++++++
 test/carts/emojibuttons.p8    |  30 ++++++++++++
 test/vmtests.cpp              | 109 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 167 insertions(+)

diff --git a/source/p8GlobalLuaFunctions.h b/source/p8GlobalLuaFunctions.h
index 0335ba1..8a8e21e 100644
--- a/source/p8GlobalLuaFunctions.h
+++ b/source/p8GlobalLuaFunctions.h
@@ -440,6 +440,34 @@ function create_sandbox()
             t[k] = v
         end
     end
+    -- Button emoji variables (must be copied to sandbox for carts to use btn(❎) etc)
+    t["⬅️"] = 0
+    t["➡️"] = 1
+    t["⬆️"] = 2
+    t["⬇️"] = 3
+    t["🅾️"] = 4
+    t["❎"] = 5
+    -- Fill pattern emoji variables
+    t["█"] = 0
+    t["▒"] = 0x5a5a.8
+    t["🐱"] = 0x511f.8
+    t["░"] = 0x7d7d.8
+    t["✽"] = 0xb81d.8
+    t["●"] = 0xf99f.8
+    t["♥"] = 0x51bf.8
+    t["☉"] = 0xb5bf.8
+    t["웃"] = 0x999f.8
+    t["⌂"] = 0xb11f.8
+    t["😐"] = 0xa0e0.8
+    t["♪"] = 0x9b3f.8
+    t["◆"] = 0xb1bf.8
+    t["…"] = 0xf5ff.8
+    t["★"] = 0xb15f.8
+    t["⧗"] = 0x1b1f.8
+    t["ˇ"] = 0xf5bf.8
+    t["∧"] = 0x7adf.8
+    t["▤"] = 0x0f0f.8
+    t["▥"] = 0x5555.8
     return t;
 end

diff --git a/test/carts/emojibuttons.p8 b/test/carts/emojibuttons.p8
new file mode 100644
index 0000000..17a540a
--- /dev/null
+++ b/test/carts/emojibuttons.p8
@@ -0,0 +1,30 @@
+pico-8 cartridge // http://www.pico-8.com
+version 29
+__lua__
+-- Test that emoji button variables are available in sandbox
+-- These should resolve to numbers, not nil
+
+left_val = ⬅️
+right_val = ➡️
+up_val = ⬆️
+down_val = ⬇️
+o_val = 🅾️
+x_val = ❎
+
+-- Test btn() with emoji arguments
+btn_left = false
+btn_o = false
+btn_x = false
+
+function _update()
+    btn_left = btn(⬅️)
+    btn_o = btn(🅾️)
+    btn_x = btn(❎)
+end
+
+function _draw()
+    cls()
+end
+__gfx__
+00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+
diff --git a/test/vmtests.cpp b/test/vmtests.cpp
index 59b1245..2ad4491 100644
--- a/test/vmtests.cpp
+++ b/test/vmtests.cpp
@@ -495,6 +495,115 @@ TEST_CASE("Vm memory functions") {
         vm->CloseCart();
     }

+    SUBCASE("emoji button variables are available in sandbox"){
+        vm->LoadCart("emojibuttons.p8");
+        vm->vm_run();
+        vm->Step();
+
+        SUBCASE("emoji button variables resolve to correct numeric values"){
+            // Test that ⬅️ = 0, ➡️ = 1, ⬆️ = 2, ⬇️ = 3, 🅾️ = 4, ❎ = 5
+            bool left_correct = vm->ExecuteLua(
+                "function test_left_val()\n"
+                " return left_val == 0\n"
+                "end\n",
+                "test_left_val");
+            CHECK(left_correct);
+
+            bool right_correct = vm->ExecuteLua(
+                "function test_right_val()\n"
+                " return right_val == 1\n"
+                "end\n",
+                "test_right_val");
+            CHECK(right_correct);
+
+            bool up_correct = vm->ExecuteLua(
+                "function test_up_val()\n"
+                " return up_val == 2\n"
+                "end\n",
+                "test_up_val");
+            CHECK(up_correct);
+
+            bool down_correct = vm->ExecuteLua(
+                "function test_down_val()\n"
+                " return down_val == 3\n"
+                "end\n",
+                "test_down_val");
+            CHECK(down_correct);
+
+            bool o_correct = vm->ExecuteLua(
+                "function test_o_val()\n"
+                " return o_val == 4\n"
+                "end\n",
+                "test_o_val");
+            CHECK(o_correct);
+
+            bool x_correct = vm->ExecuteLua(
+                "function test_x_val()\n"
+                " return x_val == 5\n"
+                "end\n",
+                "test_x_val");
+            CHECK(x_correct);
+        }
+
+        SUBCASE("btn with emoji argument checks correct button"){
+            // Press O button (bit 4 = 16) and verify btn(🅾️) returns true but btn(❎) returns false
+            stubHost->stubInput(16, 16); // O button pressed
+            vm->Step();
+            vm->Step();
+
+            bool o_pressed = vm->ExecuteLua(
+                "function test_btn_o()\n"
+                " return btn_o == true\n"
+                "end\n",
+                "test_btn_o");
+            CHECK(o_pressed);
+
+            bool x_not_pressed = vm->ExecuteLua(
+                "function test_btn_x_not()\n"
+                " return btn_x == false\n"
+                "end\n",
+                "test_btn_x_not");
+            CHECK(x_not_pressed);
+
+            bool left_not_pressed = vm->ExecuteLua(
+                "function test_btn_left_not()\n"
+                " return btn_left == false\n"
+                "end\n",
+                "test_btn_left_not");
+            CHECK(left_not_pressed);
+        }
+
+        SUBCASE("left button does not trigger O or X button checks"){
+            // Press left button (bit 0 = 1) and verify btn(🅾️) and btn(❎) return false
+            stubHost->stubInput(1, 1); // Left button pressed
+            vm->Step();
+            vm->Step();
+
+            bool left_pressed = vm->ExecuteLua(
+                "function test_left_pressed()\n"
+                " return btn_left == true\n"
+                "end\n",
+                "test_left_pressed");
+            CHECK(left_pressed);
+
+            bool o_not_pressed = vm->ExecuteLua(
+                "function test_o_not_pressed()\n"
+                " return btn_o == false\n"
+                "end\n",
+                "test_o_not_pressed");
+            CHECK(o_not_pressed);
+
+            bool x_not_pressed = vm->ExecuteLua(
+                "function test_x_not_pressed()\n"
+                " return btn_x == false\n"
+                "end\n",
+                "test_x_not_pressed");
+            CHECK(x_not_pressed);
+        }
+
+        vm->CloseCart();
+    }
+
     SUBCASE("togglepausemenu resets and restores draw state") {
         graphics->pal(10, 12, 0);
         graphics->fillp(25);