|
Forum Index : Microcontroller and PC projects : PicoMite - where am I ?
| Author | Message | ||||
| Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 5367 |
All, To prevent everyone spending time on this same topic I share my investigation. MMBasic filesystem has 2 (minimal 2 that I know of) variables that help you find your way in the filesystem. 1/ CWD$ (a reserved variable) CWD$ shows the location of the human (commandline). When you start MMBasic, this is defaulted to A:/ When you (commandline) change directory, CWD$ adapts according. CWD$ is the location you start a program from, but also the location you return to when the program closes. 2/ MM.INFO(path) Different to MS-DOS/Win, PATH does not indicate where the filesystem searches to find a file. In MMBasic the variable MM.INFO(path) is a string that identifies where the current running program is located in the filesystem. This is the variable you use to locate resources the program needs. MM.INFO(path) always shows a full path. So even when you start a program from a relative location (RUN "..\program.bas") the MM.INFO(path) variable shows the full path. When you run a program that is in memory (or in a flash slot) MM.INFO(path) returns "NONE". Note that when you run a program (i.e. a menu program) that starts another program (i.e. a game), the game can use MM.INFO(path) to know it's location, but it can not retrieve the location of the menu. To allow that functionality the menu program has to export it's location in some way (temporary file in the file system at fixed location) to get picked up by the game. Alternatively the menu program can be in a fixed location (such as in Game*Mite). Volhout Edited 2025-10-10 17:14 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
| thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 4325 |
Hi @Volhout, I've obviously been down this path myself, the "solution" I settled on for the MMB4L Game*Pack (but never backported to Game*Mite) was: 1. Decide on a fixed location for a file that would contain a single line which is the path of the shell/menu program to return to, I chose "A:/.mmbasic-shell" 2. When a shell/menu launches another program it a. writes its own path to the above file b. starts the child program with command-line argument '--shell' 3. When a child program exits it checks MM.CMDLINE$ for '--shell' and if it find it then it reads "A:/.mmbasic-shell" and RUNs the specified file. If such an "API" was agreed upon then the same client program could be RUN by multiple different shell programs without having to worry about the specific details. I wrote these helper-functions: Function sys.HOME$() Select Case Mm.Info$(Device X) Case "MMB4L" sys.HOME$ = Mm.Info$(EnvVar "HOME") Case "MMBasic for Windows" sys.HOME$ = Mm.Info$(EnvVar "HOMEDIR") + Mm.Info$(EnvVar "HOMEPATH") Case Else sys.HOME$ = "A:" End Select End Function ' Reads the '.mmbasic-shell' file. ' ' @param exist% If 1 then ERROR if file does not exist, otherwise return empty string. ' @param fnbr% File number to use for accessing the file, if unspecified/0 then uses #9. ' @return The contents of the first line of the file. Function sys.read_shell_file$(exist%, fnbr%) Const f$ = sys.HOME$() + "/.mmbasic-shell" If Not exist% And Not Mm.Info(Exists f$) Then Exit Function Const _fnbr% = Choice(fnbr%, fnbr%, 9) Open f$ For Input As _fnbr% Line Input #_fnbr%, sys.read_shell_file$ Close _fnbr% End Function ' Writes the '.mmbasic-shell' file for later reading by sys.run_shell(). ' ' @param s$ Contents to write to the file, if empty then writes path of current program. ' @param fnbr% File number to use for accessing the file, if unspecified/0 then uses #9. Sub sys.write_shell_file(s$, fnbr%) Const f$ = sys.HOME$() + "/.mmbasic-shell" Const _s$ = Choice(s$ = "", Mm.Info(Current), s$) Const _fnbr% = Choice(fnbr%, fnbr%, 9) If sys.read_shell_file$(0, _fnbr%) <> _s$ Then ' Only write if content has changed. Open f$ For Output As _fnbr% Print #_fnbr%, _s$ Close _fnbr% EndIf End Sub ' Runs the program specified by the '.mmbasic-shell' file. ' ' @param fnbr% File number to use for accessing the file, if unspecified/0 then uses #9. Sub sys.run_shell(fnbr%) Const prog$ = sys.read_shell_file$(1, fnbr%) If prog$ <> "" Then Run prog$ End Sub A shell program would launch a client with something like: Run client_path$, "--shell" And a client would return to the shell with something like: If InStr(Mm.CmdLine$, "--shell") Then sys.run_shell() YMMV, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |