Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 22:17 06 May 2024 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 : Chain equivalent for SD card

     Page 1 of 2    
Author Message
Mark
Regular Member

Joined: 26/11/2022
Location: United States
Posts: 45
Posted: 05:07am 10 Feb 2023
Copy link to clipboard 
Print this post

Does MM BASIC have a “Chain” like feature for Files on a SD card? I’m looking for a way to include “library” code in one .BAS file in other programs.  In the same vein, is there a way to break a large file into smaller ones to make it easier to navigate? For example, the UI / GUI code in one file, the device interface stuff in another. Both files would need to be active at the same time.

I guess what I really want is a way to “load” the variables, functions and subroutines in one .BAS file so that they are available to another, without having to copy the code into the target file.
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 05:37am 10 Feb 2023
Copy link to clipboard 
Print this post

It depends on what platform you are talking about.
Maximite, original Colour Maximite, CMM2, Micromite, PicoMite, etc?

Geoff
Geoff Graham - http://geoffg.net
 
Mark
Regular Member

Joined: 26/11/2022
Location: United States
Posts: 45
Posted: 11:11am 10 Feb 2023
Copy link to clipboard 
Print this post

Sorry, I was too focused on my project This is with the PicoMite.

Another way that this might work would be something similar to C and C++ #include mechanism where the text of another file is inserted into the main file.

Mark
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 11:53am 10 Feb 2023
Copy link to clipboard 
Print this post

On the PicoMite you might be able to do what you want by using the EXECUTE command to run a program within the context of the current program (page 90 of the current PicoMite manual).

You can also chain programs saved in FLASH slots (page 16).

Geoff
Geoff Graham - http://geoffg.net
 
Mark
Regular Member

Joined: 26/11/2022
Location: United States
Posts: 45
Posted: 02:13pm 10 Feb 2023
Copy link to clipboard 
Print this post

Thanks for the reply.

I tried execute "run <filename>" where filename is the file name in quotes. I used CHR$(34). Is there another way to create a string with embedded quotes. That launched the second program but it didn't have any of the program memory (i.e. variables) from the original program.

If a program chain's to a program in flash, can the chained program return to the original program leaving the program memory intact?

Mark
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3852
Posted: 02:22pm 10 Feb 2023
Copy link to clipboard 
Print this post

I'll attempt some special TBS magic:

There is definitely no way of CHAINing (and keeping the variables) to a program on SD card.

The way this magic works is that all definitive statements made here are automatically demonstrated to be wrong by someone else on the forum, usually @matherp.

Best wishes,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8594
Posted: 02:25pm 10 Feb 2023
Copy link to clipboard 
Print this post

The way to do this is the FLASH CHAIN command. Anything which invokes "RUN" will clear all variables. Programs stored using FLASH SAVE are pre-tokenised. Anything that tokenises a file uses the variable memory as working space
Edited 2023-02-11 00:27 by matherp
 
Mark
Regular Member

Joined: 26/11/2022
Location: United States
Posts: 45
Posted: 02:33pm 10 Feb 2023
Copy link to clipboard 
Print this post

I wonder if a CSUB routine could load a file and tokenize it into the current program's working space?
 
Mark
Regular Member

Joined: 26/11/2022
Location: United States
Posts: 45
Posted: 06:35pm 10 Feb 2023
Copy link to clipboard 
Print this post

I've spent some time working with flash chain. I don't think I can use it for what I'm trying to do. While variables are preserved from the calling program to the chained program, it looks like functions and subroutines are not. IOW, if I declare a function or subroutine in the calling program, I get an error when I try to access that function or subroutine from the chained program.

Please don't take anything I'm saying as criticism or a request for any additions to the MMBASIC (unless they are trivial to add   ). I was just trying to figure out if something was doable.

Mark
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3019
Posted: 07:11pm 10 Feb 2023
Copy link to clipboard 
Print this post

  Mark said  I've spent some time working with flash chain. I don't think I can use it for what I'm trying to do.


Are your subroutines so large that they can't be included in multiple flash slots (along with the other needed code)? What in particular makes what you're trying to do unworkable?
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Mark
Regular Member

Joined: 26/11/2022
Location: United States
Posts: 45
Posted: 08:05pm 10 Feb 2023
Copy link to clipboard 
Print this post

I can (and currently do) include the subroutines in each program.

What I am trying to do is create a "library" of common routines that individual programs can use without having to include the source in each one. There are two main reasons: 1) when the library is updated, I would need to update each individual file and 2) extracting the library code from the file makes it smaller and easier to navigate.

As an example of the 'library' code, I have written a large number of constants and a few subroutines that print ANSI control codes to the terminal to position and color the text.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5742
Posted: 08:39pm 10 Feb 2023
Copy link to clipboard 
Print this post

I don't think that's *currently* possible on the PicoMite, although AUTOSAVE APPEND appears to have just appeared for the PicoMite-W. That looks like it might let you add text files to your program, so a set of those files could be your library. This is too new so I'm not fully certain.

Incidentally, if you'd like a VT100 library... :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5914
Posted: 08:44pm 10 Feb 2023
Copy link to clipboard 
Print this post

I don't think AUTOSAVE APPEND is much use if you are coding on the picomite.

If writing the code on a PC, there are many options.

If writing code on the pico, it wouldn't be too difficult to write your own INCLUDE program to scan code on the pico and add the include.

Jim
VK7JH
MMedit   MMBasic Help
 
Mark
Regular Member

Joined: 26/11/2022
Location: United States
Posts: 45
Posted: 11:44pm 10 Feb 2023
Copy link to clipboard 
Print this post

Jim,

I like the idea of kind of a pre-processor running in the PicoMite.  I think I'll play with that.

Mark
 
RonnS
Senior Member

Joined: 16/07/2015
Location: Germany
Posts: 120
Posted: 11:48pm 10 Feb 2023
Copy link to clipboard 
Print this post

very nice new functions.. i was already asking for it at arm mite.. unfortunately you only find out about it if you own a picomite, now i have one
I think a big problem is the manual, I miss working examples there, because the syntax is difficult to understand ( hope not only for me ) but all Basic vendors have more examples

Ron
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3852
Posted: 12:02am 11 Feb 2023
Copy link to clipboard 
Print this post

  Mark said  I like the idea of kind of a pre-processor running in the PicoMite ...


sptrans

But you will need to first transpile it using itself on CMM2, MMB4W or MMB4L. I believe it should work, but I've never got around to doing it myself.

My own workflow is to write code on Linux and then use gonzo (which can call sptrans) to transpile and squirt code over to the PicoMite.

MMEdit is an IDE that can do much the same, and probably has fewer bugs.

Best wishes,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Mark
Regular Member

Joined: 26/11/2022
Location: United States
Posts: 45
Posted: 01:15am 11 Feb 2023
Copy link to clipboard 
Print this post

Tom,

Looking at both sptrans and gonzo I see lines starting with #Include. Where is that handled? If I could get that working with PicoMite Basic, I think that would do all I need.

Mark
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5914
Posted: 01:57am 11 Feb 2023
Copy link to clipboard 
Print this post

The Colour Maximite 2 has an include directive.
You may wish to follow it's format.

The CMM2 has suffered from a shortage of the main chip but no doubt will be re-energised when the shortages finally get resolved.

  Quote  Syntax:
#INCLUDE file$

Description:
This will insert the file 'file$' into the program at that point.  

This file must be resident on the SD card and must have the extension ".INC".
Inserting the text is performed by the pre-processor when the program is loaded into program memory by the RUN command or on exiting EDIT or AUTOSAVE using F2.
Because this operation is performed before the program is run it is recommended that include files are specified relative to the directory holding the program or with full pathnames.
A command in the program like CHDIR will be executed at runtime so will not affect the location of include files.
This command acts exactly as if the included file was manually inserted into the code using an editor but it is more convenient for loading libraries and other static code fragments. It essentially replaces the LIBRARY command on the original Maximite.


Jim
VK7JH
MMedit   MMBasic Help
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1593
Posted: 03:23am 11 Feb 2023
Copy link to clipboard 
Print this post

Tom (thwill) has written 'sptrans' for the CMM2 that does that and more as part of his sptools. That may give you a head start.

If you have a CMM2 you could use sptrans on itself to produce a 'flat' version of itself to start on (or speak nicely to Tom?).

Bill
Edited 2023-02-11 13:29 by Turbo46
Keep safe. Live long and prosper.
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1083
Posted: 06:24am 11 Feb 2023
Copy link to clipboard 
Print this post

I was just experimenting - font definitions cannot be chained on the PicoMite either. Too bad. For example, I put all my DefineFonts in a program in slot 5. The only other statement in the program (either at the beginning or the end) is "flash chain 1". As can be expected, when the program in slot 1 runs, it errors out on the first text statement that tries to use one of the fonts defined in the other slot.

Not a big deal, it's just a pain sending all the font definitions with each Teraterm "autosave" as I have some 24k of font data. At least the serial port is faster than ye olde 1980's one at 2400 baud.
Visit Vegipete's *Mite Library for cool programs.
 
     Page 1 of 2    
Print this page
© JAQ Software 2024