From f36b83fb51aa47bf6e91b64371270d6c62176860 Mon Sep 17 00:00:00 2001
From: icenine451 <benjamin.r.shelton@protonmail.com>
Date: Mon, 13 Mar 2023 12:22:36 -0400
Subject: [PATCH 1/5] Update submodule commits to HEAD

---
 rd-submodules/retroarch | 2 +-
 shared-modules          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/rd-submodules/retroarch b/rd-submodules/retroarch
index 176c8715..0b1cfb79 160000
--- a/rd-submodules/retroarch
+++ b/rd-submodules/retroarch
@@ -1 +1 @@
-Subproject commit 176c8715bdd09a1282a3861839dd2bd976380403
+Subproject commit 0b1cfb79e591e10488a3262d6b38db843c39a409
diff --git a/shared-modules b/shared-modules
index a9112b9c..3ac77f54 160000
--- a/shared-modules
+++ b/shared-modules
@@ -1 +1 @@
-Subproject commit a9112b9c62e2b84db4c2f6c55c9531fd7e8d03c1
+Subproject commit 3ac77f545ddf0ac581bc89d7b915c23eb18f841b

From 2d571d03b6e460a006b3a7f12a64c92d8ef79ffd Mon Sep 17 00:00:00 2001
From: icenine451 <benjamin.r.shelton@protonmail.com>
Date: Mon, 13 Mar 2023 12:25:43 -0400
Subject: [PATCH 2/5] Remove submodule files from my repo

---
 .gitmodules | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/.gitmodules b/.gitmodules
index 9d6f4fb6..fc753d6f 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,6 +1,8 @@
 [submodule "shared-modules"]
 	path = shared-modules
 	url = https://github.com/flathub/shared-modules.git
+	ignore = dirty
 [submodule "rd-submodules/retroarch"]
 	path = rd-submodules/retroarch
 	url = https://github.com/flathub/org.libretro.RetroArch.git
+	ignore = dirty

From a83580a0803eb2636d5070897ea7f742ea7d48da Mon Sep 17 00:00:00 2001
From: icenine451 <benjamin.r.shelton@protonmail.com>
Date: Mon, 13 Mar 2023 14:00:18 -0400
Subject: [PATCH 3/5] Revert submodule changes

---
 rd-submodules/retroarch | 2 +-
 shared-modules          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/rd-submodules/retroarch b/rd-submodules/retroarch
index 176c8715..0b1cfb79 160000
--- a/rd-submodules/retroarch
+++ b/rd-submodules/retroarch
@@ -1 +1 @@
-Subproject commit 176c8715bdd09a1282a3861839dd2bd976380403
+Subproject commit 0b1cfb79e591e10488a3262d6b38db843c39a409
diff --git a/shared-modules b/shared-modules
index a9112b9c..3ac77f54 160000
--- a/shared-modules
+++ b/shared-modules
@@ -1 +1 @@
-Subproject commit a9112b9c62e2b84db4c2f6c55c9531fd7e8d03c1
+Subproject commit 3ac77f545ddf0ac581bc89d7b915c23eb18f841b

From 98194481535c048f19470107abb92aa2de22e91a Mon Sep 17 00:00:00 2001
From: icenine451 <benjamin.r.shelton@protonmail.com>
Date: Tue, 14 Mar 2023 10:33:24 -0400
Subject: [PATCH 4/5] PICO-8 fixes.

---
 functions.sh   | 5 +++--
 post_update.sh | 6 ++++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/functions.sh b/functions.sh
index 855c84b0..98d33403 100644
--- a/functions.sh
+++ b/functions.sh
@@ -1259,7 +1259,6 @@ finit() {
   mkdir -pv $saves_folder
   mkdir -pv $states_folder
   mkdir -pv $rdhome/screenshots
-  mkdir -pv $rdhome/bios/pico8
   mkdir -pv $rdhome/.logs
 
   # XMLSTARLET HERE
@@ -1270,7 +1269,9 @@ finit() {
   dir_prep "$themes_folder" "/var/config/emulationstation/.emulationstation/themes"
 
   # PICO-8
-  dir_prep "$roms_folder/pico8" "$rdhome/bios/pico8/bbs/carts" #this is the folder where pico-8 is saving the carts
+  dir_prep "$bios_folder/pico-8" "~/.lexaloffle/pico-8" # Store binary and config files together. The .lexaloffle directory is a hard-coded location for the PICO-8 config file, cannot be changed
+  dir_prep "$roms_folder/pico8" "$bios_folder/pico-8/carts" # Symlink default game location to RD roms for cleanliness (this location is overridden anyway by the --root_path launch argument anyway)
+  dir_prep "$bios_folder/pico-8/cdata" "$saves_folder/pico-8" # PICO-8 saves folder
 
   (
   ra_init
diff --git a/post_update.sh b/post_update.sh
index ce0ba1d3..cc469cec 100644
--- a/post_update.sh
+++ b/post_update.sh
@@ -186,12 +186,18 @@ post_update() {
     # In version 0.6.2b, the following changes were made that required config file updates/reset:
     # - Primehack preconfiguration completely redone. "Stop emulation" hotkey set to Start+Select, Xbox and Nintendo keymap profiles were created, Xbox set as default.
     # - Duckstation save and state locations were dir_prep'd to the rdhome/save and /state folders, which was not previously done. Much safer now!
+    # - Fix PICO-8 folder structure. ROM and save folders are now sane and binary files will go into ~/retrodeck/bios/pico-8/
     
     rm -rf /var/config/primehack # Purge old Primehack config files. Saves are safe as they are linked into /var/data/primehack.
     primehack_init
 
     dir_prep "$rdhome/saves/duckstation" "/var/data/duckstation/memcards"
     dir_prep "$rdhome/states/duckstation" "/var/data/duckstation/savestates"
+
+    mv "$bios_folder/pico8" "$bios_folder/pico8_olddata" # Move legacy (and incorrect / non-functional ) PICO-8 location for future cleanup / less confusion
+    dir_prep "$bios_folder/pico-8" "~/.lexaloffle/pico-8" # Store binary and config files together. The .lexaloffle directory is a hard-coded location for the PICO-8 config file, cannot be changed
+    dir_prep "$roms_folder/pico8" "$bios_folder/pico-8/carts" # Symlink default game location to RD roms for cleanliness (this location is overridden anyway by the --root_path launch argument anyway)
+    dir_prep "$bios_folder/pico-8/cdata" "$saves_folder/pico-8" # PICO-8 saves folder
   fi
 
   # The following commands are run every time.

From 074128c0700b13ee31bbef264186abc37f688b93 Mon Sep 17 00:00:00 2001
From: icenine451 <benjamin.r.shelton@protonmail.com>
Date: Tue, 14 Mar 2023 10:59:31 -0400
Subject: [PATCH 5/5] Update PICO-8 ES system entry

---
 es-configs/es_systems.xml | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/es-configs/es_systems.xml b/es-configs/es_systems.xml
index 3acbbfe4..63acdcc9 100644
--- a/es-configs/es_systems.xml
+++ b/es-configs/es_systems.xml
@@ -1037,16 +1037,14 @@
         <theme>pcfx</theme>
     </system>
     <system>
-    	<name>pico8</name>
-	<fullname>PICO-8 Fantasy Console</fullname>
-	<manufacturer>Lexaloffle</manufacturer>
-	<release>2015</release>
-	<hardware>console</hardware>
-	<path>%ROMPATH%/pico8</path>
-	<extension>.p8 .P8 .png .PNG</extension>
-	<command label="PICO-8 (Standalone)">%EMULATOR_PICO-8% -desktop ~/retrodeck/screenshots -windowed 0 -root_path %ROMPATH%/pico8 -run %ROM%</command>
-	<platform>pico8</platform>
-	<theme>pico8</theme>
+        <name>pico8</name>
+        <fullname>PICO-8 Fantasy Console</fullname>
+        <path>%ROMPATH%/pico8</path>
+        <extension>.p8 .P8 .png .PNG</extension>
+        <command label="PICO-8 (Standalone)">%EMULATOR_PICO-8% -desktop_path ~/retrodeck/screenshots -root_path %GAMEDIR% -run %ROM%</command>
+        <command label="PICO-8 Splore (Standalone)">%EMULATOR_PICO-8% -desktop_path ~/retrodeck/screenshots -root_path %GAMEDIR% -splore</command>
+        <platform>pico8</platform>
+        <theme>pico8</theme>
     </system>
     <system>
         <name>pokemini</name>