Random Terrain, on Wed Mar 19, 2008 9:22 PM, said:
Does anyone have any thoughts about which is really better when it come to batari Basic?
If you aren't reusing code in an environment like the 2600 where space is at a premium, don't use gosub or goto blocks unless they are called in two places. If they are called in two places, then share the code.
More info:
See what Michael wrote
in this thread about the amount of cycles that is taken up by gosubs. From what I gathered from that using
gosub
then
return bank1
takes up the least amount of cycles (37). However, in terms of space, here is the breakdown (I don't know whether this is constant, but I've seen this in my testing).
goto and goto = 6 bytes
gosub and return = 4 bytes
gosub and return thisbank = 4 bytes
So if the goal is to take up the fewest amount of bytes but cycles don't matter much, gosub and return are best. But if the goal is to take up the fewest amount of bytes and cycles matter, use return thisbank (when calling in same bank) according to Michael's post, and see Michael's post in that thread for detail.
In bB, goto mostly seems to only make sense when you need to break out of a block that you've gosub'd too (known as a "subroutine"), and when you use it there you must call pop as many times before the goto as the subroutine is deep, for example:
mainloop
...
gosub mylabel1
...
gosub mylabel1
...
goto mainloop
mylabel1
...
if danger=1 then gosub mylabel2
...
return thisbank
mylabel
...
if died=1 then pop : pop : goto died
...
return thisbank
Edited by Fort Apocalypse, Wed Mar 19, 2008 8:13 PM.