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 StatesPosts: 45 |
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: AustraliaPosts: 3165 |
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 StatesPosts: 45 |
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: AustraliaPosts: 3165 |
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 StatesPosts: 45 |
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 KingdomPosts: 3852 |
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 KingdomPosts: 8594 |
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 StatesPosts: 45 |
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 StatesPosts: 45 |
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 StatesPosts: 3019 |
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 StatesPosts: 45 |
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 KingdomPosts: 5742 |
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: AustraliaPosts: 5914 |
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 StatesPosts: 45 |
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: GermanyPosts: 120 |
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 KingdomPosts: 3852 |
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 StatesPosts: 45 |
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: AustraliaPosts: 5914 |
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. Jim VK7JH MMedit MMBasic Help |
||||
Turbo46 Guru Joined: 24/12/2017 Location: AustraliaPosts: 1593 |
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: CanadaPosts: 1083 |
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 |