Shop OBEX P1 Docs P2 Docs Learn Events
Defining variables in different slots of the BS2sx.. — Parallax Forums

Defining variables in different slots of the BS2sx..

denodeno Posts: 242
edited 2007-06-08 16:39 in BASIC Stamp
Hello...The question is...do I have to define the exact same "name", size, and location in all program slots that I use?· Can each slot be independent? Each of the slots in use has a different program in that slot, thus requiring different variable names, sizes and locations.·

I do know that any values calculated can be put into scratch ram and called by different slots.

Deno

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2007-06-08 12:54
    If you want to 'reuse' values from one slot in another slot, without using scratch ram, then yes, they need to have the same names and types.

    If you don't care about that, then no you don't have to name them in the same order. Note that there ARE only 26 bytes of 'register space' RAM, and that each slot re-uses the same 26 bytes. So when a slot is activated with 'run', it's quite likely that its variables already have some 'junk' values in them.
  • denodeno Posts: 242
    edited 2007-06-08 14:06
    Thank you AllenLane5...I would assume that the exact same "order" as listed in slot 0 along with same name and same type aswell for the other slots?

    Deno
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-06-08 16:10
    It often happens that there are a few variables that need to be shared between slots, while others are specific to the slot and do not need to be shared or retained when switching slots. The ones that need to be shared have to be defined as words in the same order at the top in every slot. They do not necessarily have to have the same names, because it is the order that they are defined that matters, not the name. But usually they will have the same names. If there are variables that are not words that need to be shared, then give them alias names as part of a word that is in fact defined at the top of all banks, e.g.
    flags VAR Word
       sign VAR flags.bit0
       status VAR flags.bit1
        ' etc
    counters VAR word
       bcount VAR counters.byte0
       ix VAR counters.nib2
       jx VAR counters.nib3
    



    After those words that are to be shared, you can define other words, bytes, nibs and bits that are local to each slot.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • NewzedNewzed Posts: 2,503
    edited 2007-06-08 16:17
    Tracy, if I have a variable in the 9th position, say color··VAR· byte, in Bank 0, and I have a variable in the same position in Bank1, say turns VAR byte, if I read color in Bank0, isn't that going to contain whatever value Bank1 might have written to turns?

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Yesterday is history, tomorrow is a mystery, and today is a gift.

    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
    ·
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-06-08 16:39
    Hi Sid,

    Depends on what you mean by "9th position"

    The Stamp allocates space for all Words before it starts on the Bytes, then Nibs, then Bits. So if your program defines (for example), 4 words and then 5 bytes in slot 0, with your color variable as the fifth byte, and then you have the same arrangement in slot 1, yes, the two variables will be the same. In terms of counting bytes from the start of the Stamp RAM, the byte is in position 13, but it is 9th in terms of defined variables. If you add one more Word variable, even if you define it in the very last line of your program, your byte variable will be kicked up two positions (counting by byte) in the physical RAM.

    You always have to think about where it ends up in terms of counting in physical RAM, and understand that STAMPW.EXE allocates space by variable size, and within that, by the order the variables are declared in the program. That is why I like to define all my variables to be shared as words, and smaller variables to be shared as alias parts of those words.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.