Jeremy Leach
Senior Member
This is just a rough idea and not tried it. It's an attempt to make the 'jump to slot' Run command act like a GOSUB and not a GOTO...
Scenario ...
Slot 3 holds a routine 'SubX' and there's nothing else in the Slot 3. Slot 0 want to run SubX. At this point the stack in Slot 0 has been created by a series of Gosubs ... Gosub SubA, Gosub SubB, Gosub SubC
Idea ...
The subroutines SubA, SubB, SubC in Slot 0 are just regular subroutines, except they start with the line If ReturnedFromSlot = 1 Then RSAJ_1
We execute the following code in Slot 0, in order to jump to SubX in Slot 3 ...
Slot 3 ends it's SubX routine by executing ..
At this point, the stack that existed in Slot 0 has been reset.
At the START of Slot0 we have the following RestackAndJump routine ...
This ReStackAndJump routine isn't executed when Slot0 initially boots up, because ReturnedFromSlot will be 0. But when we jump back in this example, from Slot 3, it executes and recreates the stack and then jumps to the point after the initial Run 3. So it's effectively performed a Gosub Sub X but in a long-winded way !
As I say, I haven't tried this, but might do once I get into X2s...
Scenario ...
Slot 3 holds a routine 'SubX' and there's nothing else in the Slot 3. Slot 0 want to run SubX. At this point the stack in Slot 0 has been created by a series of Gosubs ... Gosub SubA, Gosub SubB, Gosub SubC
Idea ...
The subroutines SubA, SubB, SubC in Slot 0 are just regular subroutines, except they start with the line If ReturnedFromSlot = 1 Then RSAJ_1
Code:
SubA:
If ReturnedFromSlot = 1 Then RSAJ_1
<code>
Return
SubB:
If ReturnedFromSlot = 1 Then RSAJ_1
<code>
Return
SubC:
If ReturnedFromSlot = 1 Then RSAJ_1
<code>
Return
Code:
ReturnPointRef = 1
Run 3
ReturnPoint01:
Code:
SubX:
.
.
ReturnedFromSlot = 1
Run 0
At the START of Slot0 we have the following RestackAndJump routine ...
Code:
ReStackAndJump:
If ReturnedFromSlot = 1 Then
Address = ReturnPointRef * 10
Read Address,StackDepth
For Count = 1 to StackDepth
Read SubRef
On SubRef Gosub SubA,SubB,SubC,SubD
RSAJ_1:
Next
ReturnedFromSlot = 0
On ReturnPointRef Goto ReturnPoint01,ReturnPoint02 ....
EndIf
As I say, I haven't tried this, but might do once I get into X2s...