Shop OBEX P1 Docs P2 Docs Learn Events
STOREALL — Parallax Forums

STOREALL

Can someone please explain how STOREALL works. Please keep in mind that I'm a novice at programming, so keep it simple as possible. I have a Basic Stamp Programming Manual but I'm not sure if I am understanding this statement correctly. I'm using a BS2p.
Thanks, Arnold

Comments

  • Are you referring to the STOREALL.bsp program? There is no STOREALL command.
    ' STOREALL.BSP
    ' This program demonstrates the STORE command and how it can be used to
    ' "flatten" the EEPROM space for applications requiring a lot of storage.
    ' This program writes to EEPROM locations within program slots 1 through 7
    ' on the BS2p and BS2px, and 1 through 15 on the BS2pe, thus, has access
    ' to 14- or 30-kBytes of space.
    
    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
    
    #SELECT $STAMP
      #CASE BS2, BS2E, BS2SX
        #ERROR "This program requires BS2p, BS2pe, or BS2px"
      #CASE BS2P, BS2PX
        HiSlot      CON     7
      #CASE BS2PE
        HiSlot      CON     15
    #ENDSELECT
    
    LoSlot          CON     1                       ' first slot for "flat" EE
    MemSize         CON     HiSlot - LoSlot + 1 * 2048
    
    eeAddr          VAR     Word                    ' address pointer
    value           VAR     Word                    ' cell value
    slot            VAR     Byte                    ' current R/W slot
    
    
    Main:
      DEBUG "Flat Memory", CR,
            "---------------------", CR,
            "First Slot..... ", DEC LoSlot, CR,
            "Last Slot...... ", DEC HiSlot, CR,
            "Flat EE Size... ", DEC MemSize, CR, CR
    
      PAUSE 2000
      DEBUG "Writing to flat Memory...", CR
      PAUSE 1000
      FOR eeAddr = 0 TO (MemSize - 1) STEP 128      ' step through "flat" EE
        value = eeAddr * 2                          ' generate value
        GOSUB Write_Word                            ' write it
        GET 127, slot                               ' get R/W slot
        DEBUG "--> Location: ", DEC5 eeAddr, "   ",     ' show "flat" address
              "Value: ", DEC5 value, "   ",         ' show value
              "(", DEC slot.NIB1, ")", CR           ' show slot
      NEXT
      DEBUG CR
    
      DEBUG "Reading from flat Memory...", CR
      PAUSE 1000
      FOR eeAddr = 0 TO (MemSize - 1) STEP 128
        GOSUB Read_Word                             ' read value from EE
        GET 127, slot                               ' get W/R slot
        DEBUG "<-- Location: ", DEC5 eeAddr, "   ",
              "Value: ", DEC5 value, "   ",
              "(", DEC slot.NIB1, ")  "
         IF (value <> (2 * eeAddr)) THEN            ' verify location
          DEBUG "- Error"
        ENDIF
        DEBUG CR
      NEXT
      END
    
    Write_Word:
      STORE (eeAddr >> 11) + LoSlot                 ' set slot
      WRITE eeAddr, Word value                      ' write value
      RETURN
    
    Read_Word:
      STORE (eeAddr >> 11) + LoSlot                 ' set slot
      READ eeAddr, Word value                       ' read value
      RETURN
    
  • More information on the STORE command can be found in the PBASIC Language Help: http://www.parallax.com/go/PBASICHelp/
  • I see where using the STOREALL.bsp program lets you use unused memory in all the slots for data storage but does it let you write one long program, say 8K long, without having to use the RUN statement to go from slot to slot? If not then how do you call a subroutine in another slot and then return? I have tried writing the subroutine in every slot that uses it but that takes up a lot of memory and time. My program uses a lot of subroutines. The calling of subroutines is my biggest problem (at least for right now).
    Thanks for all the help from everyone.
    Arnold
  • davejamesdavejames Posts: 4,047
    edited 2015-09-13 15:15
    arnold113 wrote: »
    If not then how do you call a subroutine in another slot and then return?

    Arnold - you don't/can't, directly, that is.

    How many subroutines are you planning to have? If it's more than seven (eight slots are available for program code with slot 0 being "main"), it's possible to set up variables to decide which slot runs, which subroutine runs inside the selected slot, and then which slot runs after the subroutine is done. The PBASIC SELECT/CASE would become your very close friend.

    It'd be messy, but could be implemented.

    The article that Publison noted is kinda the beginning point in which to understand how to program across slots. It helped me develop and write an eight-slot program for a BS2pe, that also uses one of the extended slots for data storage.

    When creating a multi-slot program, it is very important to define any variables used across all slots, not just where they are used. Otherwise variable A in slot X may be overwritten by variable B in slot Y.

    Later,

    DJ

  • Just like to emphasize what davejames said:

    When creating a multi-slot program, it is very important to define any variables used across all slots, not just where they are used. Otherwise variable A in slot X may be overwritten by variable B in slot Y.

    The definitions of the variables that have to be maintained across slots pretty much have to be identical for all slots. Otherwise the compiler can assign the same register to multiple variables. I cannot tell you how many times I changed something in one slot and forgot to make the identical change in every slot. It can make for *very* nasty problems.
  • davejames, thanks for your comments. I have all of my variables defined in all the slots I'm using. I just do copy and paste for every slots variables.
    I have written a program that uses 3 word size variables in spram. When I leave a slot to go to the slot that contains my subroutines (13 so far) , I load the spram variables with the slot # I'm leaving, the target to return to in the slot I"m leaving, and the target I want to go to in the slot I'm going to. I numbered my subroutines (which I call my targets) so I can use IF THEN statements that looks at the spram variable that contains the target #. The IF VARIABLE X = 1 THEN GOTO SUBROUTINE Y is at the beginning of the slot so it knows which subroutine to go to. When I leave the subroutine slot, I reload the 3 spram variables for my return to the beginning slot, and beginning target. I haven't had time to try the program yet so I don't know if it'll work or not. Am I off in left field with this program?
    Thanks, Arnold
  • arnold113 wrote: »
    davejames, thanks for your comments.
    You are more than welcome, happy to help.
    arnold113 wrote: »
    Am I off in left field with this program?
    This solution seems quite elegant to me. I might steal it! :lol::blush:

    The program I mentioned uses just about all code space in the eight slots, all but a bit of variable space, and all but one or two of SPRAMs. In fact, IIRC, I had to implement variable "overlay" to utilize the variable space as efficiently as possible. Making sure not crashing variables between slots is imperative as tomcrawford reiterated.

    So, whatcha makin?
  • davejames, I told you wrong earlier. I used byte size variables in spram.
    The following is the program I worked out and it works (surprise surprise). Maybe someone else thats as new to slot programming as I am can use it.

    SLOT 0
    temp1 VAR Byte
    AUXIO
    ' SPRAM
    'PRESENT SLOT # B 31 SLOT # TO RETURN TO (PRESENT SLOT)
    'PRESENT SUB # B 32 SUBROUTINE # TO RETURN TO IN PRESENT SLOT
    'TARGET SUB # B 33 SUBROUTINE # TO GO TO IN TARGET SLOT
    '**************************************************************************
    GET 33, TEMP1
    PUT 31, 0 ' SLOT # TO RETURN TO
    IF TEMP1 = 0 THEN GOTO ZERO ' AN IF THEN STATEMENT REQUIRED
    IF TEMP1 = 1 THEN GOTO ONE FOR EACH SUBROUTINE
    ZERO: ' YOUR DESCRIPTIVE LABEL FOR SUBROUTINE
    SEROUT 2, 240, 10, [12, "THANKS EVERYONE"]
    PAUSE 1000
    PUT 32, 1 ' SUBROUTINE # TO RETURN TO IN PRESENT SLOT
    PUT 33, 0 ' SUBROUTINE # TO GO TO IN TARGET SLOT
    RUN 1
    ONE: ' YOUR DESCRIPTIVE LABEL FOR SUBROUTINE
    SEROUT 2, 240, 10, [12, "HELP YOU HAVE"]
    PAUSE 1000
    PUT 32, 0 ' SUBROUTINE # TO RETURN TO IN PRESENT SLOT
    PUT 33, 1 ' SUBROUTINE # TO GO TO IN TARGET SLOT
    RUN 1
    '**************************************************************************
    SLOT 1
    temp1 VAR Byte
    AUXIO
    ' SPRAM
    'PRESENT SLOT # B 31 SLOT # TO RETURN TO (PRESENT SLOT)
    'PRESENT SUB # B 32 SUBROUTINE # TO RETURN TO IN PRESENT SLOT
    'TARGET SUB # B 33 SUBROUTINE # TO GO TO IN TARGET SLOT
    '
    '**************************************************************************
    GET 33, TEMP1:
    PUT 31, 1 ' SLOT # TO RETURN TO
    IF TEMP1 = 0 THEN GOTO ZERO ' AN IF THEN STATEMENT REQUIRED
    IF TEMP1 = 1 THEN GOTO ONE FOR EACH SUBROUTINE
    ZERO: ' YOUR DESCRIPTIVE LABEL FOR SUBROUTINE
    SEROUT 2, 240, 10, [12, "FOR ALL THE"]
    PAUSE 1000
    PUT 32, 1 ' SUBROUTINE # TO RETURN TO IN PRESENT SLOT
    PUT 33, 1 ' SUBROUTINE # TO GO TO IN TARGET SLOT
    RUN 0
    ONE: ' YOUR DESCRIPTIVE LABEL FOR SUBROUTINE
    SEROUT 2, 240, 10, [12, "GIVEN ME."]
    PAUSE 1000
    PUT 32, 0 ' SUBROUTINE # TO RETURN TO IN PRESENT SLOT
    PUT 33, 0 ' SUBROUTINE # TO GO TO IN TARGET SLOT
    RUN 0
  • arnold113 wrote: »
    The following is the program I worked out and it works (surprise surprise). Maybe someone else thats as new to slot programming as I am can use it.

    So, to sum up, you're using SPRAM to store where the program ran from, and where the program will run to.

    Great idea. I will bookmark this thread for future reference.

    BTW - bounding the example code with "code tags" will preserve formatting making it easier to read.

    This can easily be done by highlighting the code, and then clicking on the 'C' button in the editor toolbar. Doing so will place "[kode] [/kode]" (but the 'k' will be a 'c') around the selected text.

  • Arnold, that seems like a very workable approach.

    I've made extensive use of cross-slot bouncing in my OWL2pe data loggers for years, programs that always use multiple slots. I'm attaching a pdf document that describes my mechanism for accomplishing it. There is more narrative on my web site, <http://emesystems.com/BS2SX.htm#Crossbank>. That dates from the time shortly after Parallax brought out the BS2SX, the first multislot Stamp.


Sign In or Register to comment.