foxygit / fake-08-xbox360 Log in
commit 859100f7e53c3ac0c84856a105d7fab94393dfe7
Author:     Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Mon Dec 29 13:20:32 2025 -0700
Commit:     Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Mon Dec 29 13:20:32 2025 -0700

    Add some logging and fix some issues with the default cart
---
 platform/SDL2Desktop/source/SDL2Host.cpp |  4 ++++
 source/DefaultCart.h                     | 26 +++++++++++++-------------
 source/p8GlobalLuaFunctions.h            |  4 +++-
 3 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/platform/SDL2Desktop/source/SDL2Host.cpp b/platform/SDL2Desktop/source/SDL2Host.cpp
index 3d5870d..5221ebf 100644
--- a/platform/SDL2Desktop/source/SDL2Host.cpp
+++ b/platform/SDL2Desktop/source/SDL2Host.cpp
@@ -208,6 +208,8 @@ InputState_t Host::scanInput(){
 vector<string> Host::listcarts(){
     vector<string> carts;

+    Logger_Write("Host::listcarts scanning directory: %s\n", _cartDirectory.c_str());
+
     DIR *dir;
     struct dirent *ent;
     if ((dir = opendir (_cartDirectory.c_str())) != NULL) {
@@ -218,8 +220,10 @@ vector<string> Host::listcarts(){
             }
         }
         closedir (dir);
+        Logger_Write("Host::listcarts found %zu carts\n", carts.size());
     } else {
         /* could not open directory */
+        Logger_Write("Host::listcarts failed to open directory: %s\n", _cartDirectory.c_str());
         perror ("");
     }

diff --git a/source/DefaultCart.h b/source/DefaultCart.h
index 9a6613f..712ea9c 100644
--- a/source/DefaultCart.h
+++ b/source/DefaultCart.h
@@ -27,6 +27,17 @@ sizebtn = "select to cycle screen sizes"

 darkenpal = {0,0,1,1,5,5,13,5,5,13,13,13,1,13,13}
 darkenpal[0] = 0
+
+-- pico8-compatible helper to find last occurrence of a character
+function findlastchar(s, c)
+	local lastidx = nil
+	for i = 1, #s do
+		if sub(s, i, i) == c then
+			lastidx = i
+		end
+	end
+	return lastidx
+end
 -->8
 --classic

@@ -35,15 +46,12 @@ function classic_init()
 	carts={}
 	numcarts = 0

-	usestring = true
-
 	if __getsetting then
 			pal(1, __getsetting('p8_bgcolor'))
 			pal(7, __getsetting('p8_textcolor'))
 	else
 		carts = {'cart1.p8','cart2.p8.png','thirdcart.p8'}
 		numcarts = 3
-		usestring = false
 	end


@@ -91,10 +99,7 @@ function classic_update()

 	if cidx > 0 and cidx <= numcarts then
 		carttoload = carts[cidx]
-		local lastslashidx = nil
-		if usestring then
-			lastslashidx = string.find(carttoload, "/[^/]*$")
-		end
+		local lastslashidx = findlastchar(carttoload, "/")
 		local dispstr = carttoload
 		if lastslashidx ~= nil and lastslashidx > 0 then
 			dispstr = sub(dispstr, lastslashidx + 1)
@@ -105,6 +110,7 @@ function classic_update()
 	end

 	if runcmd then
+		runcmd = false
 		--make call to global
 		--load cart here

@@ -157,8 +163,6 @@ function fancy_init()
 	carts={}
 	numcarts = 0

-	usestring = true
-
 	showerror = false
 	bioserror = ''
 	errortable = {'error! press ❎ to close.'}
@@ -206,7 +210,6 @@ function fancy_init()
 		--cartnames = {'cart1.p8','cart2.p8.png','thirdcart.p8','cart4.p8','5cart.p8','c6.p8','theseventhcart.p8.png'}
 		cartnames = {}
 		numcarts = #cartnames
-		usestring = false
 	end

 	loading = true
@@ -425,8 +428,6 @@ function list_init()
 	carts={}
 	numcarts = 0

-	usestring = true
-
 	showerror = false
 	bioserror = ''
 	errortable = {'error! press ❎ to close.'}
@@ -478,7 +479,6 @@ function list_init()
 		--cartnames = {'cart1.p8','cart2.p8.png','thirdcart.p8','cart4.p8','5cart.p8','c6.p8','theseventhcart.p8.png'}
 		cartnames = {}
 		numcarts = #cartnames
-		usestring = false
 	end

 	loading = true
diff --git a/source/p8GlobalLuaFunctions.h b/source/p8GlobalLuaFunctions.h
index 8fc7eba..5f55cb8 100644
--- a/source/p8GlobalLuaFunctions.h
+++ b/source/p8GlobalLuaFunctions.h
@@ -425,7 +425,9 @@ local picofuncnames = {
     count = 1, add = 1, sub = 1, foreach = 1, all = 1, del = 1, deli = 1, t = 1, dget = 1,
     dset = 1, cartdata = 1, load = 1, save = 1, info = 1, abort = 1, folder = 1,
     resume = 1, reboot = 1, dir = 1, ls = 1, flip = 1, mapdraw = 1, menuitem = 1,
-    __ispaused = 1
+
+    __ispaused = 1, __resetcart = 1, __loaddefaultcart = 1, __loadsettingscart = 1,
+    __listcarts = 1, __getbioserror = 1, __getsetting = 1, __setsetting = 1, __loadlabel = 1
  }
  return picofuncnames[funcname] == 1
 end