STOREALL
arnold113
Posts: 43
in BASIC Stamp
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
Thanks, Arnold
Comments
Thanks for all the help from everyone.
Arnold
https://www.parallax.com/sites/default/files/downloads/BS-Nuts-And-Volts87-Multi-Bank-Article_0.pdf
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
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.
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
This solution seems quite elegant to me. I might steal it!
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?
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
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.
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.