supercat, on Sat Mar 1, 2008 3:44 PM, said:
Is it practical to use bB for part of the code in an assembly-language game while minimizing bB's own memory usage (preferably overlaying bB's temp variables with some kernel-temp variables from the assembly-language part)? Although I am definitely a fan of writing custom kernels suited to game requirements, there are some types of game code that could be done more conveniently in a higher-level language.
For example, it would be more convenient to say something like
if (joystick right and xvel < 2)
xvel = xvel + 0.25
else if (joystick left and xvel > -2) or (xvel > 0.25)
xvel = xvel - 0.25
else if (xvel < -0.25)
xvel = xvel + 0.25
else
xvel = 0
than to try to code all that in machine code. To be sure, the machine code version would be faster and more compact, but the bB version could still be much easier to work with.
Normally, bB reserves a lot of memory for variables, kernel temp stuff, the playfield, etc. I would want to get rid of all that. The goal would be to create subroutines in bB which don't use any memory except variables I've explicitly assigned, other than some temp variables which I've overlaid on my own kernel temps. Does that seem practical?
Yes, that's possible and bB was written so such a thing would be fairly simple to do.
You could do it one of two ways. One, you could make a custom includes file containing all of your asm files and none of the ones included with bB except bB.asm and the libraries it needs (e.g. fixed_point_math.asm, but even that isn't needed most of the time.) Your asm files should reference 2600basic_variable_redefs.h and the asm or header files contain any equates that bB expects to use. I think the fixed-point math routines use a few of the temp variables (temp1, temp2, etc.)
Another way is to simply have bB compile the code, creating bB.asm, which you can then "include" it from another asm file as long as you have defined the equates that it uses somewhere and also include any other asm libraries it needs, if any.
Lastly, if you are using fixed point variables, you need to "dim" them that way so the compiler knows how to deal with them. In the example below, I've picked a couple of names for the integer and fractional portions.
Here is your code rewritten for bB, partly due to syntax, and partly to work within the limitations. The number of booleans in a conditional statement is limited, and bB doesn't seem to like the unary minus (I thought I'd fixed that, but apparently I didn't) and in conditions, fixed point variables only compare their integer portions. (I may have made a mistake, so don't trust my code

)
dim xvel=xint.xfrac
if joy0right && xvel < 2 then add25
if joy0left && xvel >= 254 then xvel=xvel-0.25:goto donemoving
if xvel=255 && xfrac>192 then add25
xvel = 0:goto donemoving
add25
xvel = xvel + 0.25
donemoving