Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 17:48 12 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CMM2: RUNning a program named by a variable$ or string-expression

Author Message
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4302
Posted: 12:54pm 28 Jun 2020
Copy link to clipboard 
Print this post

The following post contains attributions to both matherp and TassyJim. I apologise in advance for any innaccuracies or misrepresentation.

I've come across this limitation in my development work and thought I would share in the event that others hit the same.

MMBasic on the CMM2 requires the target of a RUN statement to be a string literal , i.e. it doesn't allow you to do the following:

s$ = "foobar.bas"
Run s$


TassyJim suggested a workaround equivalent to the following:

s$ = "foobar.bas"
Open "/tmp.bas" For Output As s#1
Print #1, "Run " + Chr$(34) + s$ + Chr$(34)
Run "/tmp.bas"


But matherp said "This is a ... bad idea and causes the flash to be re-written twice." I think this argument was regarding wearing out the flash on the microcontroller, but it may also have been a comment on performance.

I thought some more about it and believe the following should work without the double-hit on the flash:

s$ = "foobar.inc"
Open "/tmp.bas" For Output As s#1
Print #1, "#Include " + Chr$(34) + s$ + Chr$(34)
Run "/tmp.bas"


Though it does require you to provide foobar as a .inc file instead of a .bas file. Of course if you also need to execute foobar standalone you can just have a parallel foobar.bas file consisting of a single #Include statement.

Best regards,

Tom
Edited 2020-06-28 22:59 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4302
Posted: 08:02pm 28 Jun 2020
Copy link to clipboard 
Print this post

Dang! it doesn't work in the general case because .inc files are not allowed to #Include other .inc files I guess I have to try an persuade Peter to make more changes

EDIT: and it would also be limited by the fact that #Include does not support absolute paths.

Tom
Edited 2020-06-29 07:24 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4302
Posted: 12:48pm 01 Jul 2020
Copy link to clipboard 
Print this post

I have been thinking some more about this and there are two related use-cases I'm seeking a solution for:

1. RUN a program where its name comes from a string expression.

2. RUN a program using the * command where that program is not situated in SEARCH PATH
 - some programs have additional .inc files and use other file resources you don't want to copy into SEARCH PATH and you don't want to use absolute paths to.
 - you don't want to hit the flash twice so the "solution" of having a stub file in SEARCH PATH that calls RUN on the real file is undesireable.

I believe there is a single solution to both, and looking at the MMBasic source (Pi version) it doesn't look too difficult to implement:

a. You define a .lnk file type that contains a single line containing the path of a .bas file to run.
- ideally it would also allow comments because I'm interested in autogenerating these files and autogenerated files should always indicate their origin.

b. When we use RUN or * and the file argument specifies a .lnk file then MMBasic reads that file and RUNs (i.e. "FileLoadProgram") the program specified therein.

This fixes problem (1) as follows:
s$ = "A:/subdir/foobar.bas"
Open "/tmp.lnk" For Output As s#1
Print #1, s$
Run "/tmp.lnk"


And for problem (2):

If you create a file "zmim.lnk" in the SEARCH PATH containing:
/zmim/src/main.bas


Then typing *zmim would RUN /zmim/src/main.bas with only a single hit on the flash.

Thanks for reading,

Tom
Edited 2020-07-01 23:14 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025