BS2P Crossbank Calls
I have been using Tracy Allen's method of doing crossbank calls and am wondering if anyone has experience expanding the calls to further branches. Specifically, in the attached program I am trying to use the calling methods Tracy describes, but I need the program to do something a little different. I want to start by going to V00 then V01 to V10 to V02 to V11 and finally back to V00. On all subsequent loops I want to be able to run from V00 to V02 to V11 and back to V00. If anyone has a method of doing this or any insight as to how I can do this, it would be greatly appreciated!
Mike
Branch_1.bsp
2Banks_5Branches_0.bsp
Mike
Branch_1.bsp
2Banks_5Branches_0.bsp


Comments
MotionScriptMain.bse
MotorsAndSensors.BSE
[SIZE=1][FONT=courier new]wsx VAR word ' this is the slot xchange variable, first word spot VAR wsx.byte0 spotRun VAR spot.nib1 ' this is the target slot number, 0-7 spotGo VAR spot.nib0 ' this is the branch-to index in the target slot flags VAR word config VAR flags.byte0 ' configuration flags read from eeprom at starup status VAR flags.byte1 ' status flags change during program execution first VAR status.bit4 ' initialization flag ' .. first = 1 [/FONT][/SIZE]Accordingly, the code that decides whether or not to execute the initialization...
Bank 0:
' {$STAMP BS2p, Branch_1} ' {$PBASIC 2.5} ' ----------[ Variables ]--------------------------------------------------------- Jump VAR Word ' Word variable for switching vectors Ret VAR Jump.BYTE1 ' High BYTE of "Jump" for "return to" target bank and branch Go VAR Jump.BYTE0 ' Low BYTE of "Jump" for bank switching to a target bank and branch GoRun VAR Go.NIB1 ' High NIB of "Go" for specifying tagret bank Go2 VAR Go.NIB0 ' Low NIB of "Go" for specifying target branch Flags VAR Word ' Word variable for storing flags Status VAR Flags.BYTE1 ' Status flags change during program execution Config VAR Flags.BYTE0 ' Low BYTE of "Flags" for configuration flags read from EEPROM on startup First VAR Status.BIT4 ' Initialization flag n VAR Nib ' ----------[ Constants ]--------------------------------------------------------- ' Bank 0 Targets: V_00 CON $00 V_01 CON $01 V_02 CON $02 ' Bank 1 Targets: V_10 CON $10 V_11 CON $11 ' ----------[ Program ]---------------------------------------------------------- IF First = 0 THEN BRANCH Go2, [V00, V01, V02] ELSEIF First = 1 THEN BRANCH Go2, [V00, V02] ENDIF V00: DEBUG "Main Routine", CR PAUSE 1000 Ret = V_00 Go2 = V_01 V01: DEBUG "Going to Memory Initialization", CR PAUSE 1000 Go = V_10 RUN GoRun V02: DEBUG "Going to DataLogging", CR PAUSE 1000 Go = V_01Bank 1:
' {$STAMP BS2p}' {$PBASIC 2.5} ' ----------[ Variables ]--------------------------------------------------------- Jump VAR Word ' Word variable for switching vectors Ret VAR Jump.BYTE1 ' High BYTE of "Jump" for "return to" target bank and branch x VAR Ret.NIB1 Go VAR Jump.BYTE0 ' Low BYTE of "Jump" for bank switching to a target bank and branch GoRun VAR Go.NIB1 ' High NIB of "Go" for specifying tagret bank Go2 VAR Go.NIB0 ' Low NIB of "Go" for specifying target branch n VAR Nib ' ----------[ Constants ]--------------------------------------------------------- ' Bank 0 Targets: V_00 CON $00 V_01 CON $01 V_02 CON $02 ' Bank 1 Targets: V_10 CON $10 V_11 CON $11 ' ----------[ Program ]----------------------------------------------------------- BRANCH Go2, [V10, V11] V10: DEBUG "Initializing", CR PAUSE 1000 n = 1 Go2 = V_11 V11: DEBUG "Data Logging", CR PAUSE 1000 Go = V_00 RUN GoRunMy question is, is this the correct way to skip the initialization with the branch command?
Stupid question, but why does the bit need to be put in the SPRAM? Maybe I'm misunderstanding things, but I thought as long as the variables were defined in exactly the same order in each bank the values would carry over.
Mike
[SIZE=1][FONT=courier new]' {$STAMP BS2pe, "slotDemo (slot 1).bpe"} ' {$PBASIC 2.5} ' this is the slot 0 routine v_startup CON $00 v_mainRoutine CON $01 v_ret_mainRoutine CON $02 v_memoryInit CON $10 v_dataLogging CON $11 jump VAR WORD ret VAR jump.BYTE1 go VAR jump.BYTE0 goRun VAR go.NIB1 go2 VAR go.NIB0 BRANCH go2,[startup,mainRoutine,ret_mainRoutine] startup: ' some stuff Ret = v_mainRoutine Go =v_memoryInit RUN goRun ' runs the memoryInit routine and returns to mainRoutine mainRoutine: DO 'main stuff Ret=v_ret_mainRoutine Go=v_dataLogging RUN goRun ' runs the dataLogging routine and returns to the next instruction below ret_mainRoutine: ' more main stuff LOOP[/FONT][/SIZE][SIZE=1][FONT=courier new]' {$STAMP BS2pe} ' {$PBASIC 2.5} ' Slot 1, same variables and constants as slot0 v_startup CON $00 v_mainRoutine CON $01 v_ret_mainRoutine CON $02 v_memoryInit CON $10 v_dataLogging CON $11 jump VAR WORD ret VAR jump.BYTE1 go VAR jump.BYTE0 goRun VAR go.NIB1 go2 VAR go.NIB0 BRANCH go2,[memoryInit, dataLogging] memoryInit: ' do stuff go = ret ' note that this returns via the vector set up in slot 0 RUN goRUN dataLogging: ' do it go = ret ' ditto, it is just a one-level stack, but KISS RUN goRun[/FONT][/SIZE]This does not use the "first" flag, but it it did, it would be necessary to lower the flag at the end of the first cycle.