Array of constant on BS2?
I would like to make an array of constants on my BS2. The reason is I wish to save ram - don't need a variable, but I do want to be able to loop the values of the array. Is it possible to declare an array of constants in Pbasic? From what I can tell it is not.
If not, is there another way to do this smoothly?
BR/ MCA
If not, is there another way to do this smoothly?
BR/ MCA
Comments
DATA 10,20,30,40,50,60,70,80 X VAR BYTE Y VAR BYTE FOR X = 0 TO 7 READ X,Y DEBUG DEC X, TAB, DEC Y, CR NEXT
The DEBUG is just to show you how the READ works.
You probably wouldn't read them in a loop in your program; instead just READ the one you want when you need it.
READ 5,Y
BR / MCA
' {$STAMP BS2} ' {$PBASIC 2.5} const1 CON 1 const2 CON 2 const3 CON 3 const4 CON 4 ' ... etc tmpN1 VAR NIB ' work nib tmpB1 VAR BYTE ' work variable; you should always have at least one! tmpW1 VAR WORD ' ditto ' pass the index value of the constant you want (say, 0-3) and get the value back in tmpW1 Get_Const_By_Index: LOOKUP tmpN1, [ const1, const2, const2, const4 ], tmpW1 RETURN ' get the constant whose value is just greater than the passed "test" value ' presumes constants are arranged in ascending order Get_Const_By_LT_Val: LOOKDOWN tmpN1, <[ const1, const2, const2, const4 ], tmpN1 GOSUB Get_Const_By_Index RETURN ' etc