From e753ab9c6606b6b78c21400e25ed659cfddc5a3d Mon Sep 17 00:00:00 2001 From: The412Banner Date: Fri, 25 Sep 2026 07:37:07 -0400 Subject: [PATCH] melonDS: Hybrid screens, full screen from the front end, guide toggles full screen, BIOS found in the ROMs folder - bannerlator-pad-defaults: new installs start on the Hybrid layout with sharp pixels; an existing install is moved once, only where still on melonDS's defaults (marker keeps later choices). Guide = HK_FullscreenToggle. The user's DS/DSi BIOS, firmware and NAND are found in ROMs/nds/{bios,firmware} and filled in only where melonDS has no path. - Front end starts melonDS with -f, at the panel's own resolution unless the user chose one. --- .../com/droiddeck/launcher/SessionActivity.kt | 8 +- .../droiddeck/launcher/frontend/Library.kt | 16 +- .../launcher/session/SessionPrefs.kt | 4 + .../usr/local/bin/bannerlator-pad-defaults | 174 ++++++++++++++++-- 4 files changed, 181 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 3df0052dbc..13dd3e5eb9 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -30,6 +30,7 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.ComposeView import com.droiddeck.launcher.core.FileUtils +import com.droiddeck.launcher.frontend.Library import com.droiddeck.launcher.gpu.FrameGen import com.droiddeck.launcher.gpu.LsfgNative import com.droiddeck.launcher.gpu.TurnipDriver @@ -646,7 +647,12 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { val mode = SessionPrefs.prefMode(intent.getStringExtra(SessionService.EXTRA_MODE) ?: SessionService.MODE_STEAM) // A custom resolution is taken as given; the compositor fits it to the panel. SessionPrefs.customResolution(this, mode)?.let { return it } - val cap = SessionPrefs.resolutionCap(this, mode) + // An emulator whose frames cost next to nothing (Library.drawsAtPanel) gets the panel, + // unless the user chose a resolution for the mode. + val program = intent.getStringExtra(SessionService.EXTRA_PROGRAM) + val cap = if (intent.getStringExtra(SessionService.EXTRA_MODE) == SessionService.MODE_RUN && + Library.drawsAtPanel(program) && !SessionPrefs.resolutionChosen(this, mode)) 0 + else SessionPrefs.resolutionCap(this, mode) val height = (if (cap <= 0) panelH else minOf(panelH, cap.toFloat())).toInt() val width = (height * aspect).toInt() // Odd sizes upset the scaler; both dimensions even is what every mode here would be. diff --git a/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt b/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt index 63d8db5d85..a735b2925b 100644 --- a/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt +++ b/app/src/main/java/com/droiddeck/launcher/frontend/Library.kt @@ -94,7 +94,8 @@ object Library { .firstOrNull { it.isFile && it.length() > 0L } } - private class Spec(val id: String, val name: String, val system: String, val program: String, val folders: List, val exts: Set) + /** [atPanel]: frames cheap enough to draw at the panel's own size (see [drawsAtPanel]). */ + private class Spec(val id: String, val name: String, val system: String, val program: String, val folders: List, val exts: Set, val atPanel: Boolean = false) private val specs = listOf( Spec("rpcs3", "RPCS3", "PS3", "/opt/appimages/rpcs3.AppImage", listOf("ps3"), setOf("iso")), // PS2: ARMSX2, the PCSX2 fork with ARM64 recompilers. Upstream PCSX2 interprets the PS2's @@ -102,7 +103,7 @@ object Library { Spec("armsx2", "ARMSX2", "PS2", "/opt/appimages/armsx2.AppImage", listOf("ps2"), setOf("iso", "chd", "cso", "gz")), Spec("dolphin", "Dolphin", "GameCube / Wii", "/opt/appimages/dolphin.AppImage", listOf("gc", "gamecube", "wii"), setOf("iso", "rvz", "gcz", "wbfs", "ciso")), Spec("duckstation", "DuckStation", "PS1", "/opt/appimages/duckstation.AppImage", listOf("ps1", "psx"), setOf("cue", "chd", "pbp", "iso", "bin", "img", "ecm", "m3u")), - Spec("melonds", "melonDS", "DS", "/opt/appimages/melonds.AppImage", listOf("ds", "nds"), setOf("nds", "dsi")), + Spec("melonds", "melonDS", "DS", "/opt/appimages/melonds.AppImage", listOf("ds", "nds"), setOf("nds", "dsi"), atPanel = true), Spec("cemu", "Cemu", "Wii U", "/opt/appimages/cemu.AppImage", listOf("wiiu", "wii u"), setOf("wua", "wud", "wux", "rpx")), Spec("ppsspp", "PPSSPP", "PSP", "/usr/bin/PPSSPPSDL", listOf("psp"), setOf("iso", "cso", "pbp", "chd")), Spec("retroarch", "RetroArch", "many systems", "/usr/bin/retroarch", emptyList(), emptySet()), @@ -125,6 +126,14 @@ object Library { /** The emulator's name for a program path from the rail ("ARMSX2"), or null. */ fun nameForProgram(program: String?): String? = specs.firstOrNull { it.program == program }?.name + /** + * Whether a program from the rail runs at the panel's own resolution rather than the session's + * 720p default. melonDS draws two 256x192 screens on the CPU: the panel's size costs it + * nothing, and 720p scaled up to the panel blurs the sharp pixels its Hybrid layout is set + * up for (bannerlator-pad-defaults). + */ + fun drawsAtPanel(program: String?): Boolean = specs.any { it.program == program && it.atPanel } + /** Desktop catalog package that supplies this emulator. */ fun packageId(emulatorId: String): String? = installedIds[emulatorId] @@ -270,6 +279,9 @@ object Library { "-e", guestPath, ) "cemu" -> listOf("-g", guestPath) + // Full screen (CLI.cpp --fullscreen); the guide button leaves it for melonDS's menus and + // comes back (HK_FullscreenToggle, bannerlator-pad-defaults). + "melonds" -> listOf("-f", guestPath) else -> listOf(guestPath) } } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt index c44ead89a8..7498b4ad93 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt @@ -282,6 +282,10 @@ object SessionPrefs { */ fun resolutionCap(context: Context, mode: String): Int = prefs(context).getInt("resolutionCap.$mode", defaultResolutionCap(mode)) + /** Whether the user chose the mode's resolution (a cap or a custom size) rather than the default. */ + fun resolutionChosen(context: Context, mode: String): Boolean = + prefs(context).contains("resolutionCap.$mode") || customResolution(context, mode) != null + /** The FEXCore preset for the games the client launches (core/FexPreset ids); "" = FEX's defaults. */ fun fexPreset(context: Context): String = prefs(context).getString("fexPreset", "") ?: "" diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-pad-defaults b/tools/linuxfs/overlay/usr/local/bin/bannerlator-pad-defaults index 954916d296..ae0513142f 100755 --- a/tools/linuxfs/overlay/usr/local/bin/bannerlator-pad-defaults +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-pad-defaults @@ -723,8 +723,11 @@ def cemu(): # melonDS 1.x: raw SDL joystick indices. The session's pad has the kernel's Xbox 360 layout # (buttons A B X Y LB RB Back Start Guide LS RS = 0..10, hat 0 for the d-pad); the d-pad values -# also take the left stick (EmuInstanceInput.cpp; encoding InputConfig/MapButton.h). -MELONDS_JOY = """[Instance0.Joystick] +# also take the left stick (EmuInstanceInput.cpp; encoding InputConfig/MapButton.h). The guide +# button toggles full screen (HK_FullscreenToggle), as it does in Dolphin: the front end starts +# melonDS full screen (-f), and leaving it shows the window's menus for settings. +MELONDS_GUIDE = 8 +MELONDS_JOY = f"""[Instance0.Joystick] A = 1 B = 0 X = 3 @@ -737,14 +740,130 @@ Up = 17891585 Down = 16843012 Left = 1114376 Right = 65794 +HK_FullscreenToggle = {MELONDS_GUIDE} """ +# The screen a handheld's wide panel suits best: Hybrid (the top screen large, both screens small +# beside it - ScreenLayout.h screenLayout_Hybrid = 3), sharp pixels (no filtering, no integer +# steps that leave the panel half used). Keys as melonDS writes them (Window.cpp windowCfg). +MELONDS_WINDOW = """[Instance0.Window0] +ScreenLayout = 3 +ScreenSizing = 0 +IntegerScaling = false +ScreenFilter = false +""" +# melonDS's own defaults for those, which an existing install is moved off once. +MELONDS_WINDOW_DEFAULTS = {"ScreenLayout": "0", "ScreenFilter": "true"} + + +def toml_get(lines, table, key): + """The raw value of key in [table], or None.""" + inside = False + for l in lines: + t = l.strip() + if t.startswith("["): + inside = t == f"[{table}]" + elif inside and "=" in t and t.split("=", 1)[0].strip() == key: + return t.split("=", 1)[1].strip() + return None + + +def toml_set(lines, table, key, value): + """key = value in [table]; the table is added at the end when missing.""" + start = None + for i, l in enumerate(lines): + t = l.strip() + if t.startswith("["): + if start is not None: + break + if t == f"[{table}]": + start = i + elif start is not None and "=" in t and t.split("=", 1)[0].strip() == key: + lines[i] = f"{key} = {value}" + return + if start is None: + lines += ["", f"[{table}]", f"{key} = {value}"] + return + end = start + 1 + while end < len(lines) and not lines[end].strip().startswith("["): + end += 1 + while end > start + 1 and not lines[end - 1].strip(): + end -= 1 + lines.insert(end, f"{key} = {value}") + + +def toml_str(path): + return '"' + path.replace("\\", "\\\\").replace('"', '\\"') + '"' + + +# The user's own BIOS, firmware and DSi NAND, found in the ROMs folder's nds/bios (or firmware) +# folder by what each file is: the DS BIOSes by size and checksum (the GBA BIOS is also 16 KB), +# firmware and NAND by size, the DSi boot ROMs (both 64 KB) by the 7 or 9 in their names. A path +# is only filled where melonDS has none, and external files are only switched on when a whole set +# was found - without them melonDS runs DS games on its built-in free BIOS. +DS_BIOS7_MD5 = "df692a80a5b1bc90728bc3dfc76cd948" +DS_BIOS9_MD5 = "a392174eb3e572fed6447e956bde4b25" + + +def nds_firmware_files(): + import hashlib + base = system_folder(("nds", "ds"), "nds") + roots = [os.path.join(base, n) for n in ("bios", "BIOS", "firmware") if os.path.isdir(os.path.join(base, n))] + found = {} + for root in roots: + for d, _, files in os.walk(root): + if d[len(root):].count(os.sep) > 2: + continue + for name in sorted(files): + f = os.path.join(d, name) + try: + size = os.path.getsize(f) + except OSError: + continue + low = name.lower() + if size == 16384 or size == 4096: + with open(f, "rb") as h: + md5 = hashlib.md5(h.read()).hexdigest() + if md5 == DS_BIOS7_MD5: + found.setdefault("DS.BIOS7Path", f) + elif md5 == DS_BIOS9_MD5: + found.setdefault("DS.BIOS9Path", f) + elif size in (262144, 524288) and "dsi" not in low: + found.setdefault("DS.FirmwarePath", f) + elif size == 65536: + if "arm7" in low or "bios7" in low: + found.setdefault("DSi.BIOS7Path", f) + elif "arm9" in low or "bios9" in low: + found.setdefault("DSi.BIOS9Path", f) + elif size == 131072: + found.setdefault("DSi.FirmwarePath", f) + elif size >= 200 * 1024 * 1024 and "nand" in low: + found.setdefault("DSi.NANDPath", f) + return found + + +def melonds_bios(lines): + found = nds_firmware_files() + changed = [] + for key, f in found.items(): + table, k = key.split(".", 1) + if (toml_get(lines, table, k) or '""') == '""': + toml_set(lines, table, k, toml_str(f)) + changed.append(key) + for table, flag, keys in (("Emu", "ExternalBIOSEnable", ("DS.BIOS7Path", "DS.BIOS9Path", "DS.FirmwarePath")), + ("DSi", "ExternalBIOSEnable", ("DSi.BIOS7Path", "DSi.BIOS9Path", "DSi.FirmwarePath", "DSi.NANDPath"))): + if all(k in found for k in keys) and any(k in changed for k in keys): + toml_set(lines, table, flag, "true") + return changed + def melonds(): path = os.path.join(CONFIG, "melonDS/melonDS.toml") + marker = os.path.join(os.path.dirname(path), ".droiddeck-display") if not os.path.isfile(path): - seed(path, "[Instance0]\nJoystickID = 0\n\n" + MELONDS_JOY, "melonDS") - return + seed(path, "[Instance0]\nJoystickID = 0\n\n" + MELONDS_JOY + "\n" + MELONDS_WINDOW, "melonDS", + "Player 1 on the controller, Hybrid screens") + open(marker, "w").close() with open(path, encoding="utf-8", errors="replace") as f: text = f.read() try: @@ -752,20 +871,39 @@ def melonds(): joy = tomllib.loads(text).get("Instance0", {}).get("Joystick", {}) except Exception: return - if any(isinstance(v, int) and v != -1 for v in joy.values()): - return # something is bound already - # Replace melonDS's own all-unbound table with ours (a TOML table can be defined only once). - out, skipping = [], False - for line in text.splitlines(): - t = line.strip() - if t.startswith("["): - skipping = t == "[Instance0.Joystick]" - if not skipping: - out.append(line) - with open(path + ".tmp", "w", encoding="utf-8") as f: - f.write("\n".join(out).rstrip("\n") + "\n\n" + MELONDS_JOY) - os.replace(path + ".tmp", path) - print(f"bannerlator-pad-defaults: melonDS: Player 1 on the controller ({path})") + lines = text.splitlines() + done = [] + if not any(isinstance(v, int) and v != -1 and k != "HK_FullscreenToggle" for k, v in joy.items()): + # Replace melonDS's own all-unbound table with ours (a TOML table can be defined only once). + out, skipping = [], False + for line in lines: + t = line.strip() + if t.startswith("["): + skipping = t == "[Instance0.Joystick]" + if not skipping: + out.append(line) + lines = "\n".join(out).rstrip("\n").splitlines() + [""] + MELONDS_JOY.rstrip("\n").splitlines() + done.append("Player 1 on the controller") + elif joy.get("HK_FullscreenToggle", -1) == -1 and MELONDS_GUIDE not in joy.values(): + toml_set(lines, "Instance0.Joystick", "HK_FullscreenToggle", str(MELONDS_GUIDE)) + done.append("guide button toggles full screen") + # Once, for a melonDS set up before this: the Hybrid screens, where it is still on its own + # defaults. The marker keeps whatever the user picks in melonDS's View menu afterwards. + if not os.path.exists(marker): + for l in MELONDS_WINDOW.splitlines()[1:]: + k, v = (x.strip() for x in l.split("=", 1)) + if toml_get(lines, "Instance0.Window0", k) in (None, MELONDS_WINDOW_DEFAULTS.get(k)): + toml_set(lines, "Instance0.Window0", k, v) + done.append("Hybrid screens") + open(marker, "w").close() + bios = melonds_bios(lines) + if bios: + done.append("BIOS " + ", ".join(bios)) + if done: + with open(path + ".tmp", "w", encoding="utf-8") as f: + f.write("\n".join(lines).rstrip("\n") + "\n") + os.replace(path + ".tmp", path) + print(f"bannerlator-pad-defaults: melonDS: {'; '.join(done)} ({path})") # PPSSPP (SDL): its pad defaults leave the shoulders, the right stick and the triggers unbound on