Skip to content

Commit 280ccf5

Browse files
Doom app: add support for SD card
1 parent 6f4b3f3 commit 280ccf5

File tree

1 file changed

+23
-7
lines changed
  • internal_filesystem/apps/com.micropythonos.doom/assets

1 file changed

+23
-7
lines changed

internal_filesystem/apps/com.micropythonos.doom/assets/doom.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from mpos.apps import Activity
2+
from mpos import TaskManager, sdcard
23

34
class Doom(Activity):
45

@@ -8,6 +9,7 @@ class Doom(Activity):
89
configdir = retrogodir + "/config"
910
bootfile = configdir + "/boot.json"
1011
partition_label = "prboom-go"
12+
mountpoint_sdcard = "/sdcard"
1113
esp32_partition_type_ota_0 = 16
1214
#partition_label = "retro-core"
1315
# Widgets:
@@ -24,7 +26,6 @@ def onCreate(self):
2426

2527
def onResume(self, screen):
2628
# Do it in a separate task so the UI doesn't hang (shows progress, status_label) and the serial console keeps showing prints
27-
from mpos import TaskManager
2829
TaskManager.create_task(self.start_wad(self.doomdir + '/Doom v1.9 Free Shareware.zip'))
2930

3031
def mkdir(self, dirname):
@@ -33,18 +34,33 @@ def mkdir(self, dirname):
3334
import os
3435
os.mkdir(dirname)
3536
except Exception as e:
36-
self.status_label.set_text(f"Info: could not create directory {dirname} because: {e}")
37+
# Not really useful to show this in the UI, as it's usually just an "already exists" error:
38+
print(f"Info: could not create directory {dirname} because: {e}")
3739

3840
async def start_wad(self, wadfile):
39-
self.mkdir(self.romdir)
40-
self.mkdir(self.doomdir)
41-
self.mkdir(self.retrogodir)
42-
self.mkdir(self.configdir)
41+
# Try to mount the SD card and if successful, use it, as retro-go can only use one or the other:
42+
bootfile_prefix = ""
43+
mounted_sdcard = sdcard.mount_with_optional_format(self.mountpoint_sdcard)
44+
if mounted_sdcard:
45+
print("sdcard is mounted, configuring it...")
46+
bootfile_prefix = self.mountpoint_sdcard
47+
bootfile_to_write = bootfile_prefix + self.bootfile
48+
print(f"writing to {bootfile_to_write}")
49+
self.status_label.set_text(f"Launching Doom with file: {bootfile_prefix}{wadfile}")
50+
await TaskManager.sleep(1) # Give the user a minimal amount of time to read the filename
51+
52+
# Create these folders, in case the user wants to add doom later:
53+
self.mkdir(bootfile_prefix + self.romdir)
54+
self.mkdir(bootfile_prefix + self.doomdir)
55+
56+
# Create structure to place bootfile:
57+
self.mkdir(bootfile_prefix + self.retrogodir)
58+
self.mkdir(bootfile_prefix + self.configdir)
4359
try:
4460
import os
4561
import json
4662
# Would be better to only write this if it differs from what's already there:
47-
fd = open(self.bootfile, 'w')
63+
fd = open(bootfile_to_write, 'w')
4864
bootconfig = {
4965
"BootName": "doom",
5066
"BootArgs": f"/sd{wadfile}",

0 commit comments

Comments
 (0)