Shop OBEX P1 Docs P2 Docs Learn Events
bs2/bs2e read/write — Parallax Forums

bs2/bs2e read/write

TobiasTobias Posts: 95
edited 2007-08-05 17:33 in BASIC Stamp
···· I finally figured out how to create·a multi slot program, I had a program in bs2 with four settings and when it went to setting two I had it write 1, 2 and at setting three write 1, 3 and so on, then when·I started the program I made it to read 1, set and had it go to the set number setting. Because when I would turn off the power to the bs2 at setting 3 then restart it later it would automatically goto setting 3. Now I'm still working with four settings but with the bs2e and a slot for each setting, is it possible for me to somehow create the same process? I tried the read and write but it seems like it reads and writes in its own slot not on the entire four slots.
Thank-You
Toby

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-08-04 06:27
    Hi Tobias, the STORE command used before a read/write will tell your program where to store the data

    If you want your data stored in slot·0 then :

    STORE 0

    WRITE 0,x,y

    to read from any other slot

    STORE 0

    READ 0,x,y

    Jeff T.

    EDIT just realized STORE is not valid for the BS2e but there is an example in the STORE help file of·pointing the read/writes to the same memory location.

    Post Edited (Unsoundcode) : 8/4/2007 6:55:37 AM GMT
  • TobiasTobias Posts: 95
    edited 2007-08-05 04:09
    Thankx for the advise, but I can't make it work with the bs2e. Would there be any other alternative?
    Toby
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-08-05 06:08
    Hi Toby, if you have a slot to spare what you could do is use·slot 0·as a pointer to the last program slot that was running on power down. Each time the program enters a slot it passes·the slot number via the scratchpad ram which is then written to slot 0 eeprom.

    ·<---SLOT 0
    >
    ·GET 62,x
    ·IF x<>0 THEN
    ·WRITE 0,x
    ·RUN x
    ·ELSE
    ·READ 0,x
    ·IF x=0 THEN
    ·RUN 1
    ·ELSE
    ·RUN x
    ·ENDIF
    ·ENDIF

    Each slot would have the following code as the first few lines

    GET 62,x
    ·IF x<> current_slot_number THEN
    ·PUT 62,current_slot_number
    ·RUN 0
    ·ENDIF

    Jeff T.

    ·Edit: forgot to include the read statement first go round

    Post Edited (Unsoundcode) : 8/5/2007 6:29:55 AM GMT
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-08-05 17:33
    A little less complicated might be a scheme that marks a WRITE 1,1 in the eeprom when the program starts up in a slot, and WRITE 1,0 when it leaves that slot. On power-up the program jumps from slot to slot until it find the "1"=active mark or runs out of slots.

    ' top of slot 0
    top:
      READ 1,result
      IF result=0 THEN RUN 1  ' not this one, try next, same code in slot 1 does a RUN 2, etc.
      ' result is 1, this is the one
      '  program executes here
      ' ...
    exitSlot:   ' going to a new slot
      WRITE 1,0   ' mark this one as non-active
      RUN newSlot   ' it will be marked as 1 when it starts
    



    The last slot in the chain would be the default, and would run by default if none are marked with a 1.

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