Repository navigation
Description
The bug
We have identified an inconsistency in how the cart insert and debug symbols load console commands handle tilde (~) path expansion. While wrapping paths in [file normalize ...] works because Tcl expands the tilde before passing the result to the command, passing a tilde path directly will fail.
At this time, we have only verified this behavior for these two commands and cannot assert whether other file-handling commands in openMSX are affected.
Furthermore, the two affected commands fail in distinct ways: debug symbols load fails to locate the file passively, while cart insert attempts to resolve the path in an incorrect relative manner, prepending default directories and treating the ~ as a literal folder name.
Reproduce
Case 1: debug symbols load (Passive Failure)
Passing ~ directly fails to resolve the path outright:
debug symbols load "~/MSX/workspace/msxai-harness/out/bare-metal/bare-metal.sym"
Error output:
Couldn't load symbol file '~/MSX/workspace/msxai-harness/out/bare-metal/bare-metal.sym': File "~/MSX/workspace/msxai-harness/out/bare-metal/bare-metal.sym" not found
Case 2: cart insert (Active/Incorrect Concatenation)
Passing ~ directly to cart insert causes openMSX to treat the tilde as a literal folder name and concatenate it with the default emulator directory (on Windows, typically the user's Documents folder):
cart insert "~/MSX/workspace/msxai-harness/out/bare-metal/bare-metal.rom"
Error output:
Invalid ROM file: C:/Users/vdom-1/Documents/MSX/workspace/msxai-harness/out/bare-metal/bare-metal.rom
(Notice how the emulator has swapped the tilde forC:/Users/vdom-1/Documents)
The Workaround (Both Work)
Explicitly forcing Tcl to normalize the path beforehand resolves the issue perfectly:
debug symbols load [file normalize "~/MSX/workspace/msxai-harness/out/bare-metal/bare-metal.sym"]
cart insert [file normalize "~/MSX/workspace/msxai-harness/out/bare-metal/bare-metal.rom"]
Expected behavior
The cart insert and debug symbols load commands should consistently resolve and expand the tilde (~) shortcut to the user's home directory when passed directly, matching the behavior of Tcl's native resolution.
Ideally, standardizing this path/tilde expansion helper across all openMSX console commands that manipulate or load files would prevent similar issues from occurring elsewhere in the codebase.
Additional Context
This behavior was discussed with @MBilderbeek on msx.org who suggested creating an issue here.
Activity
m9710797 commentedon Jul 15, 2026
Hi,
Thanks for this bug report! Let me start with some background info. Afterwards we can discuss possible solutions:
diska,carta, ... but no embedded Tcl interpreter yet.file normalizefunctionality internally.file normalizedid tilde expansion. And when I do some research now, it seems that this is an incompatible change between Tcl8 and Tcl9: Tcl8 does tilde expansion in many places, Tcl9 doesn't do that anymore but instead offers a newfile tildeexpandcommand. See this article for more info. When reading that article, I agree that in a programming language automatic tilde expansion is not the best idea. OTOH it is very convenient for interactive use in the openMSX console.Now back to your bug report:
carta, but not fordebug symbols loadis because we explicitly handle it in the former, but not in the latter. That's an inconsistency that we should fix. (At no point isfile normalizeinvolved).carta) is something we implemented ourselves. I'm very familiar with Linux, so I made sure it works the same as tilde expansion in most Linux shells. I'm not familiar with Windows. (It's probably +25 years ago at this point) I think I made an attempt to also do something reasonable on Windows, but I have no idea if it's the same as current windows shells (and I also think 25 years ago most windows shells did not do tilde expansion .. I can be wrong).Anyway, that's the historical background. Now for the fix. I think there are two separate bugs:
tildeexpansionfunction yet (and we don't always want to combine it with a full normalization).vdom-1 commentedon Jul 15, 2026
Hi Wouter,
Thanks for the historical background! That makes perfect sense of why things behave the way they do.
Here are my thoughts on how we can tackle this:
1. Correcting a Small Misunderstanding on
carta insertvsdebug symbols loadJust to make sure we are on the exact same page neither commands is actually working right now... they just fail in different ways:
carta insert(tries to handle the tilde but gets it wrong): It actually swaps the tilde~forC:/Users/vdom-1/Documents/and notC:/Users/vdom-1/debug symbols load(doesn't try): It doesn't even attempt to resolve the tilde; it just fails immediately because it passes the literal~straight through.Your explanation of the background completely cleared up why they fail differently, and it makes total sense why
debug symbols loadisn't attempting any expansion!2. The Tcl 8 vs. Tcl 9 Dilemma &
file normalizeI don't have deep prior experience with Tcl, so the "Tilde Substitution" quirks mentioned in the wiki were new to me.
My take on this is pragmatism: we should focus on fixing this for the version we are actually working with right now (which is Tcl 8) and cross the Tcl 9 bridge when Tcl 9 is widely adopted and ready for openMSX.
My instincts (and some local tests) tell me that simply passing the input through
file normalizeon the Tcl side might do exactly what we need, at least within the context of the emulator's scripts.Do you think using
file normalizewould work as a clean wrapper for us on Tcl 8, or does your experience with Tcl’s quirks suggest that it might introduce some hidden edge cases?3. Streamlining implementation with a unified helper
I completely agree with doing an audit of all openMSX commands that use filenames to make them consistent.
The beauty of introducing a single, unified helper function is that we don't have to wait for Tcl 9 to solve the Tilde Substitution issue.
We can write a temporary path-normalization/tilde-expansion solution for Tcl 8 right now(perhaps using
file normalize). When Tcl 9 is eventually ready for production, we won't have to rewrite a thing across the rest of the codebase, we will only have to update that one single helper function to leverage Tcl 9's native features.This gives us a single source of truth to handle tildes, backslashes, or any platform-specific path issue, while keeping the codebase prepared for the future.
m9710797 commentedon Jul 15, 2026
A few clarifications, and questions:
Today openMSX can work with either Tcl8 or Tcl9. Some Linux distributions already have Tcl9, other still only offer Tcl8. ATM we make sure openMSX still works with 8, but if you have 9 installed on your system we use that. That's similar to the other libraries we use (zlib, libpng, FreeType, ...) we require some minimal version, but if you have a newer version we'd happily use that.
Usually that works fine, usually there are no backwards incompatibilities between library versions. This
file normalizething is one of the few exceptions (and before today I wasn't even aware of it).But that does mean we cannot use Tcl to do tilde expansion:
file normalize(file tildeexpanddoesn't exist yet) but that does much more than only tilde expansion (e.g. convert to absolute path, normalize..and.components, resolve symlinks, ...).file tildeexpand, but we cannot count on this.So I think we still have to implement tilde expansion ourselves. And to do that correctly in Windows I need your help:
~/be replaced with? (And is that maybe different on different windows versions? Or can it be overridden by environment variables or other settings? Then how to obtain this replacement string? ...)~<username>/?m9710797 commentedon Jul 15, 2026
I did some research:
SHGetSpecialFolderPathW(nullptr, bufW, CSIDL_PERSONAL, TRUE)SHGetKnownFolderPath(FOLDERID_Profile, 0, nullptr, &wPath)The former is a (now deprecated) old windows call. The later is "new" in Windows Vista, so actually also already quite old, but it didn't exist yet when we originally wrote this code in openMSX.
vdom-1 commentedon Jul 16, 2026
Given that
file normalizeperforms more than just tilde expansion, I think it's probably best to set that approach aside and focus purely on tilde expansion.Your research also clarified the Windows behavior for me. Looking back at my original report:
I initially misinterpreted what have happened, but it now makes sense that openMSX was performing tilde expansion. It was just expanding
~to the Documents folder because it currently uses the legacySHGetSpecialFolderPathWwithCSIDL_PERSONAL:CSIDL_PERSONALrepresents the user's Documents folder, that explains exactly where the extra Documents component came from.From what I've been reading,
SHGetKnownFolderPath(FOLDERID_Profile, ...)is the modern API (hasn't changed since Windows Vista) for obtaining the user's profile directory (e.g.C:\Users\<username>), which is what I would expect~to represent. From a user's perspective,~normally refers to the user's home directory.The only consideration I can think of is Windows XP compatibility, since
FOLDERID_Profilewas introduced in Windows Vista. If the openMSX 64 bit binary still intentionally supports Windows XP Professional x64 Edition, then the legacy implementation may need to remain as a fallback. Otherwise, if Vista or newer(up to Windows 11) is already the effective baseline for supported Windows versions, switching toSHGetKnownFolderPath(FOLDERID_Profile, ...)seems like the more appropriate implementation.So unless I'm overlooking something, it seems like we could simply update
getUserHomeDir()to use the appropriate Windows API for the current user's profile directory.m9710797 commentedon Jul 16, 2026
I think we dropped support for Windows XP a few(?) years ago?
In principle the fix is clear: change
SHGetSpecialFolderPathWtoSHGetKnownFolderPath. Though I'm a bit concerned about backwards compatibility? Are windows users using tilde expansion (clearly vdom-1 is)? Then after this change it will resolve to a different path. It's more correct (and probably more aligned with how other windows programs do tilde expansion), but nevertheless it's different, so it might break some users existing setup. Any ideas? Opinions?Maybe we should just change it and break backwards compatibility? Probably(?) not too many windows users actually use tilde expansion?
vdom-1 commentedon Jul 16, 2026
Hi Wouter,
I think we are completely safe to make this change.
If we are strictly talking about the openMSX Win 64-bit binary, the only users who could theoretically be impacted by the API change are those running Windows XP Professional x64 edition (the only 64-bit Windows release prior to Vista). That OS was never widely adopted—it essentially served as a public testbed for Microsoft's 64-bit ecosystem—so that user base is virtually non-existent today.
Furthermore, there is actually no risk of the path resolving differently for modern Windows users.
SHGetSpecialFolderPathW(..., CSIDL_PROFILE)andSHGetKnownFolderPath(..., FOLDERID_Profile)resolve to the exact same folder:C:\Users\<username>.As for tilde
~usage on Windows:m9710797 commentedon Jul 20, 2026
Sorry for the delay.
I agree that currently openMSX uses the wrong path. I agree there's no risk of openMSX no longer working on older windows versions.
I do not agree with your statement "... there is actually no risk of the path resolving differently for modern Windows users ...".
What I meant was:
But maybe this isn't a big deal, and we should just change it. And then possibly some users need to adapt.
Maybe the more difficult (as in tedious) part of fixing this, is finding all openMSX commands that deal with filenames, and make sure they apply tilde expansion. Do you think you could help with this?
vdom-1 commentedon Jul 21, 2026
You're right—some users may have adapted their setups to account for the legacy Windows API that uses the Documents folder instead of the user profile folder. So yes, there is a risk of this change breaking existing workflows or custom scripts.
Nevertheless, I believe aligning the Win 64-bit binary with the modern API is a positive step for the future of openMSX on the platform. Furthermore, the impact will be contained to the specific functions utilizing the legacy API, rather than all functions that need file access . As we know, there isn't a single, streamlined implementation for tilde (
~) expansion across the codebase, and some functions don't even support it at all.Ultimately, it is up to you whether you want to push forward with this change, and it might be worth gathering the community's input as well.
Count me in for this endeavor! I have already created a preliminary checklist of all the file-access functions I could find, which we can use to track our progress.
vdom-1 commentedon Jul 21, 2026
Legend
Installation
As per issue #2162 the Commit c7c3bc6 broke the installation because the documentation points users to the legacy
Documents\folder.Currently:
C:\Users\<user name>\Documents\openMSX\sharewhereby stands for your Windows login nameSuggested:
%APPDATA%\openMSX\shareorC:\Users\<user name>\AppData\Roaming\openMSX\share(whereby stands for your Windows login name)Commands
cart <filename>/carta/cartbcart insert <filename>/carta insert/cartb insertcasload <file>cassave <file>casrun <file> [<number>]cassetteplayer <filename>/cassetteplayer insert/cassetteplayer newdata_file$::env(OPENMSX_SYSTEM_DATA)debug symbols load <filename> [<type>]debug symbols remove <filename>debug symbols lookup [-filename <filename>] [-name <name>] [-value <value>]diska insert <diskfile>/diska <diskfile>diskmanipulator create <fn> <sz><fn>diskmanipulator savedsk <dn> <fn><dn>as dsk file named<fn>diskmanipulator import <disk> <dir/file><dir/file>diskmanipulator export <disk> <host dir><disk>to<host dir>get_breakpoints_dirC:/Users/vdom-1/Documents/openMSX/breakpoints)load_breakpoints <file>load_debuggable <file>load_machineload_settings <file>loadstate <name>multi_screenshot <num> [<base>]psg_log start <filename>record start <filename>reg_log record <debuggable> [<filename>]reg_log play <debuggable> <filename><filename>save_breakpoints <file>save_debuggable <debuggable> <file>save_msx_screensave_settingssave_to_file <filename> <args>savestate <name>sdcdb open <directories> [<cdbFile>]sdcdb list <file>:<line/functionName>screenshot <filename>sha1sum <file>store_machine <id> <file>store_setup <depth> [file]<depth>argument. I will create a an separate issue for this.type_from_file <args> <filename>type_password_from_file <filename> <index>vgm_recSettings
set {Debug Device output} <output file>set audio-inputfilenameset auto_save_replay_filenameset gui_font_default_filenameset gui_font_mono_filenameset midi-out-logfilenameset printerlogfilenameset rs232-inputfilenameset rs232-outputfilenameFix tilde expansion on windows
m9710797 commentedon Jul 21, 2026
Thanks for this checklist! Now let's fill it in and complete it (make all supported).
I propose to categorize these in 3 lists, maybe something like this:
carta,diska, ...debug symbols load, ...We could use lists like this, or update your checklist above. Does github allow infinite updates (i mean not limited in time) to comments, and by any user (that would be weird). My main point is: we need a category "to-be-investigated" in addition to just a binary check.
In the mean time I did push a fix for the actual tilde expansion on windows. Please help test (I can't test myself on windows).
vdom-1 commentedon Jul 21, 2026
I think GitHub allows for infinite edits to a post (we will find out).
As suggested, I've created a legend (key/status) so we can track our progress more precisely. Let's use the NOTES column to communicate specifics about a certain command or setting's implementation.
Bear in mind that since I am not testing against commit c7c3bc6 and don't yet know all the functions affected by the
getUserHomeDir()change, I might raise some false negatives. However, we can clarify those one by one as we go through the list.vdom-1 commentedon Jul 23, 2026
Hi Wouter,
When you see the Test Note—“Commit c7c3bc6 might've fixed it”—it's simply because those commands fail in the exact same way carta did prior to the new API change (appending the Documents folder to the user profile folder), rather than from a deep dive into the code implementation.
That said, I did take a look at some of the implementations to get a feel for what’s going on under the hood, just in case you need help there too. I guesstimate the API update will fix most of the issues marked as [❔] (TO-CHECK), though certainly not all of them.
Also, let me know if I should remove the description column (since we already know what the commands do) and perhaps use that space to track something else, like implementation notes?
Updates on Jul 21, 2026 19:52
6 remaining items
MBilderbeek commentedon Jul 30, 2026
vdom-1 commentedon Jul 30, 2026
A clear distinction must be made between installation and usage. While CSIDL_LOCAL_APPDATA is the correct target for the openMSX installation data, the path expansion (the tilde expansion) for used during runtime should target CSIDL_PERSONAL.
Furthermore, this migration will need to happen sooner or later and why not tackle it now while we have these many people already involved?
vdom-1 commentedon Jul 31, 2026
My suggestion:
3.4.1 ROM Locations
...
%LOCALAPPDATA%\openMSX\shareorC:\Users\<user name>\AppData\Local\openMSX\share(whereby stands for your Windows login name)MBilderbeek commentedon Jul 31, 2026
vdom-1 commentedon Jul 31, 2026
True, its just the "endgame" suggestion... Currently it just removes
Documentsfrom the path:C:\Users\<user name>\openMSX\share. Which is already better but far from ideal.MBilderbeek commentedon Jul 31, 2026
vdom-1 commentedon Jul 31, 2026
In a nutshell, ideally we need a strict separation of concerns between the System Domain (Emulator Config/Setup/Setting/Installation) and the User Domain (GUI/Console).
Currently, both domains share the same
expandTilde()/getUserHomeDir()logic, which is the root cause of the regression.This is how I thing we can get there:
Confine Tilde Expansion to the User Domain: Keep
expandTilde()/getUserHomeDir()strictly for the console and GUI.Isolate the System Domain: Create a dedicated function for configuration, setup, settings and installation (e.g.,
FileOperations::getLocalDataPath()).CSIDL_LOCAL_APPDATAon Windows—to locate user data and machine ROMs reliably.FileOperations::getUserOpenMSXDir()is the only function affected by this change, but again, someone more familiar with the code should have a look at this.MBilderbeek commentedon Jul 31, 2026
vdom-1 commentedon Jul 31, 2026
This is the one million dollar question. I have being digging the code to get a better grip of how openMSX resolve its working directories. What makes it a bit confusing, but not impossible to understand, is the "portability" factor(resolves OPENMSX_SYSTEM_DATA to the executable path) and as I said before how entangled the installation and the console logic is. I think that we should push forward with this commit c7c3bc6 and update the documentation by just removing
Documents\fromC:\Users\<user name>\Documents\openMSX\share whereby <user name> stands for your Windows login namefor now. This is already going to force people on the right direction by moving stuff out of the Documents folder.For the the endgame(
..\AppData\Local\openMSX\share), I am still investigating the best solution in any case let's continue this conversation in issue #1246 because it the situation quite well.Revert "Fix tilde expansion on windows"
m9710797 commentedon Aug 1, 2026
I've reverted this change. Because it broke windows installations that were working fine for +20 years (using the recommended installation paths). That's unacceptable without some transition period, or backwards compatibility mechanism. We should have reverted sooner, but I was on vacation.
I do agree that the new paths suggested by vdom-1 are better (as in: more as expected on "modern" windows applications), and we should migrate to those. But again NOT without some clear transition plan and/or backwards compatibility.
We introduced this problem by changing how tilde-expansion behaves (on windows). I wrongly thought that tilde-expansion would only have an effect on interactive usage (command line, or openMSX console commands). But that's wrong: it seems in 1 location (
getUserOpenMSXDir()) in the internal code we also use this. So as a first step I'll change that to be independent from tilde-expansion.Maybe after that we can re-apply the tilde-expansion change (which should then only have an effect on interactive use). I did already make the assumption that windows users rarely use tilde-expansion (in interactive commands). And that breaking backwards compatibility there would be acceptable? But maybe we should re-evaluate that now?
Updates on Aug 01, 2026 09:22
vdom-1 commentedon Aug 3, 2026
Since the advent of WSL(Windows subsystem for Linux) more and more Windows users are offloading parts of their workflows to Linux. Tilde expansion in Windows is now as important as it has always being in Linux especially on these hybrid workflows where path alignment is crucial between OS's.
As you notice the reason of the regression is not in "tilde expansion" itself but the fact that the interactive console shares the same user path resolution function(getUserOpenMSXDir) with the installer.
Separation of concerns here is crucial.
SHGetKnownFolderPath/FOLDERID_ProfileSHGetKnownFolderPath/FOLDERID_LocalAppDataand the legacySHGetSpecialFolderPathW/CSIDL_PERSONALas a fallback.MBilderbeek commentedon Aug 3, 2026
How is the installer at all related to all of this? I don't think it is, at all.
vdom-1 commentedon Aug 3, 2026
I am using the term installer loosely here just to represent the expected installation folders where the default installation expects to finds
systemromsandsoftware(savestates). The culprit really isstd::string getUserHomeDir(std::string_view username)being share by TCL and the rest of the application...