View Full Version : Muiltiprograms

12-13-2002, 08:21 PM
Last year was my first year as programmer and I was a freshman who just happened to have a computer so I got the job. I know that sounds like a bad idea but that is what happened.
Anyway what my question is, How do I download multi-programs to the controller? I know how to call other programs but how do I install them with out overwriting the first?

Greg Ross
12-13-2002, 09:37 PM
Use the {$STAMP} directive to tell the BASIC Stamp Editor the names of the program files that belong in the other slots.

Let's say you have a Prog0.bsx which does the initialization, Prog1.bsx contains the main program loop, and Prog2.bsx contains the serout command. Prog0.bsx will need to contain the following line:

{$STAMP BS2SX, Prog1.bsx, Prog2.bsx}

12-13-2002, 09:46 PM
Ok that makes sence but is/are there any limitations to the other programs and what variables are carried over between programs?

Greg Ross
12-13-2002, 10:07 PM
You need to remember that the 26 bytes of variable storage are shared between all program slots. This means that you either need to insure that all variables are defined identically in all your programs, or you will have to assume that none of your variables will be preserved whenever you execute the run command.

I go with the former strategy, and to help me accomplish this, I wrote a BASIC Stamp Preprocessor which allows me to include a file which contains all data definitions into all my source files.

The preprocessor is available in the Programming section of the White Papers.

The older versions of my white paper have gone missing, and the one that is currently there only mentions the features added in that version of the program. Hopefully, this weekend I will be able to upload an update of the preprocessor and some more complete documentation.

In the mean time, you will need to know that the syntax for including a file is:
{$INCLUDE file}

12-14-2002, 08:20 AM
OK. I think I understand but is there a way to undeclare varibles. ie I would want to undeclare the varibles in a automation program so I would have more variables to work with.

Greg Ross
12-14-2002, 09:40 AM
I'm not sure I understand what you mean when you say undefine.

Of course you can delete variable definitions that you don't need. If you need a variable in one of your program slots that you don't need in another, then you'll need to be a little more creative.

We usually have a pool of temporary variables which may be used locally (within a subroutine or program slot) which may be used elsewhere with impunity.

These temp variables are named temp1, temp2, etc. We then either use those variables directly, or alias them to something like temp1_tableOffset, temp2_scaledY, etc.

12-14-2002, 03:41 PM
I mean to undeclared or define the varibles for the IO. If I could do this then I would have more varibles to work with. I want to do this to because it would alow more to be done, but if I am understanding your post it can't be done and I should keep trying to use less varibles.

12-15-2002, 12:08 AM
Are you talking about inputing, for example, p1_x sometimes and not inputing it at others? If so, my advice would be to still input it for simplicity, but immediately after the serin change its value to whatever you want it to be. Likewise, you can always alias a more convient name to use the same space as p1_x. For example:

newVarName VAR p1_x

just remember that anything you write to newVarName will also change the contents of p1_x, and vice-versa.

12-15-2002, 07:22 AM
That makes sense now. It is not really what I wanted but I guess it will have to do. I think what I want is not possible in the code. Thank you for your help.

12-15-2002, 11:17 AM
True, "undefining" variables is not possible as they are created at compile time by the PBASIC interpreter. However, as I said previously, you can always pretend they don't exist and use them for something else. If that's not what you are looking for, would you mind posting some more details? There's always a way to do pretty much anything you want, sometimes it's just a little more complicated.

12-15-2002, 11:36 AM
No I guess that will have to do. It is not so much not what I wanted as not what I wanted to hear. I wanted to undeclare the OI variables if they are not needed like if automation is required for half the match or something similar.