Shop OBEX P1 Docs P2 Docs Learn Events
How do you switch between programs inthe BS2p? — Parallax Forums

How do you switch between programs inthe BS2p?

JJaimeJJaime Posts: 8
edited 2012-02-21 21:40 in BASIC Stamp
do any of you could give me an script of how actually use the RUN command in the BS2p?
does this actually work for the BS2p?
What is the technique to enter a program in SLOT 0, 1, 2, 3 ..? do you have to use the PUT command for this purpose?
This issue has not been clear to me yet and I have not seen an straight example for the BS2p

Appreciate your input to this matter.

Comments

  • RDL2004RDL2004 Posts: 2,554
    edited 2012-01-15 12:58
    I've never actually used the extra program slots, but if you open the Stamp Editor's Help, select search (bottom of the left side panel), and search on both "RUN" and "multi-file", you should find the information you need. Each slot will actually use a separate program file.



    edit: my bad, multi-file not -slot, and don't forget the $Stamp directive
  • dredre Posts: 106
    edited 2012-01-15 13:13
    Hi,

    Read the 'run' command in the manual. The problem is that the 'run' command always causes the run-to program to restart at the beginning.
    Dr Tracy Allen [www.emesystems.com] has a write-up on this under his notes. I am trying to insert a routine to allow redirecting the receiver program to resume where it left off. Don't know at this time if I'm on the right track.

    cheers, David
  • ZootZoot Posts: 2,227
    edited 2012-01-15 13:51
    Before you possibly struggle with Tracy Allen's clever "bank switches", it's better to get TWO slots filled with what effectively is a single 4k program (twice as big as a "normal" Basic Stamp program).

    There are only three things you need to do for this to work right:

    1. create two program files, say slot0.bsp and slot1.bsp. Then define all your variables EXACTLY the same in both files. This is crucial.

    2. in the Stamp directive of the FIRST slot program (slot0.bsp) add the additional file name(s), separated by commas. In this case you would only have one extra file:
    {$STAMP BS2p, slot1.bsp}
    

    This tells the editor to load the "base" program into slot 0, and the file "slot1.bsp" into slot 1. "slot0.bsp" is the "base" or master program file.

    3. at the end of the code in "slot0.bsp" put the following line:
    RUN 1
    

    and at the end of the code in slot1.bsp put the following line:
    RUN 0
    

    Voila. When the 2k worth of code in slot 0 runs, it will "switch" to the code in slot 1 and carry on, then go back to the beginning.

    The reason for defining the variables EXACTLY the same in both programs is so you don't clobber or "lose" the variables when the slot switches. "Exactly" means the same names, the same ORDER of definition, the same sizes (word, byte, nib, etc).

    That said, if you all need to do is "skip" some initialization/setup code at the beginning of slot 0, use a bit flag to skip it after it's run once:
    'slot0.bsp
    
    {$STAMP BS2p, slot1.bsp}
    
    foo VAR Byte
    bar VAR Byte
    init VAR bit
    
    Reset:
      IF init = 0 THEN
         ' do some stuff ONE TIME on reset
        ' do more init stuff
        init = 1 ' never do it again
      ENDIF
    
    Main:
      ' do lots of stuff
    
    SlotDone:
       RUN 1
    

    'slot1.bsp
    
    {$STAMP BS2p}
    
    foo VAR Byte ' exactly the same variables
    bar VAR Byte
    init VAR bit
    
    Main:
      ' do lots of stuff
    
    SlotDone:
       RUN 0
    
  • ZootZoot Posts: 2,227
    edited 2012-01-15 13:57
    P.S. -- I usually don't waste a true variable bit on things like init states, that can be done using SPRAM registers, but hopefully you get the idea.
  • JJaimeJJaime Posts: 8
    edited 2012-01-15 20:16
    Zoot wrote: »
    Before you possibly struggle with Tracy Allen's clever "bank switches", it's better to get TWO slots filled with what effectively is a single 4k program (twice as big as a "normal" Basic Stamp program).

    There are only three things you need to do for this to work right:

    1. create two program files, say slot0.bsp and slot1.bsp. Then define all your variables EXACTLY the same in both files. This is crucial.

    2. in the Stamp directive of the FIRST slot program (slot0.bsp) add the additional file name(s), separated by commas. In this case you would only have one extra file:
    {$STAMP BS2p, slot1.bsp}
    



    Zoot: I have tried your technical advice. It worked beautifully. Thanks a lot for your valuable Hint

    This tells the editor to load the "base" program into slot 0, and the file "slot1.bsp" into slot 1. "slot0.bsp" is the "base" or master program file.

    3. at the end of the code in "slot0.bsp" put the following line:
    RUN 1
    

    and at the end of the code in slot1.bsp put the following line:
    RUN 0
    

    Voila. When the 2k worth of code in slot 0 runs, it will "switch" to the code in slot 1 and carry on, then go back to the beginning.

    The reason for defining the variables EXACTLY the same in both programs is so you don't clobber or "lose" the variables when the slot switches. "Exactly" means the same names, the same ORDER of definition, the same sizes (word, byte, nib, etc).

    That said, if you all need to do is "skip" some initialization/setup code at the beginning of slot 0, use a bit flag to skip it after it's run once:
    'slot0.bsp
    
    {$STAMP BS2p, slot1.bsp}
    
    foo VAR Byte
    bar VAR Byte
    init VAR bit
    
    Reset:
      IF init = 0 THEN
         ' do some stuff ONE TIME on reset
        ' do more init stuff
        init = 1 ' never do it again
      ENDIF
    
    Main:
      ' do lots of stuff
    
    SlotDone:
       RUN 1
    

    'slot1.bsp
    
    {$STAMP BS2p}
    
    foo VAR Byte ' exactly the same variables
    bar VAR Byte
    init VAR bit
    
    Main:
      ' do lots of stuff
    
    SlotDone:
       RUN 0
    
  • Scott4Scott4 Posts: 45
    edited 2012-02-20 07:47
    This is how most of my big programs end up looking:
    2-20-2012 10-39-10 AM.jpg

    I put the initialization and "do once" code in the first slot then just circulate through the other slots with the "RUN" command the last statement in each slot. -Scott
    685 x 386 - 44K
  • ZootZoot Posts: 2,227
    edited 2012-02-20 09:05
    Cool. Nifty. 10 characters at least!
  • Martin_HMartin_H Posts: 4,051
    edited 2012-02-20 14:52
    Here's a nuts and volts column on multi-bank programming::

    http://www.parallax.com/Portals/0/Do...3/col/nnnnv87.pdf

    It took me a bit of time to understand it, but works well once you get the knack. You break your program into tasks and use the scratch pad area to store the destination task and the return task, as well as save variables if you need to.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2012-02-21 21:40
    The link to Jon's column is corrupted. Currently it is,
    http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol3/col/nv87.pdf

    There is no one right way to approach multi-slot programming. I see that my own way of doing it came up in the thread in the context of it being a struggle. I've been working with it so long that it seems completely natural! :innocent:

    Anyway, I'm attaching a little pdf I had made to illustrate how it works. More graphic than what is on the web site.

    xSlotExample.png
    958 x 463 - 52K
Sign In or Register to comment.