05-01-2012, 11:20 PM
slenkar Wrote:so one byte is 8 bits or 8 'switches'?ZX Basic supports BAND and bit shifting with SHR and SHL. In this case, you should use an array of 24 x 4 bytes => 24 Ulong and do the following (Note: This is *UNTESTED* :oops: )
so how would you say read or write a 'switch' in a byte? say I wanted to read switch 4 and read switch 5
if i have a byte array that is the size of the screen that is 32,24 which is 768 bytes
if I set up an array of bools it would only be 96 bytes
Code:
DIM ar(23, 3) as Ubyte ' 24 x 32 bits.
#define BitTest(x, i) Cast(Ubyte, 1 & (x >> i))
#define GetBool(a, i, j) BitTest(a(ii, j >> 3), j & 7)
#define SetBool(a, i, j) a(i, j >> 3) a(i, j >> 3) | 1 << (j & 7)
#define ResetBool(a, i, j) a(i, j >> 3) SetBool(a, i, j): a(i, j >> 3) = a(i, j >> 3) ~ 1 << (j & 7)
IF GetBool(ar, 3, 20) THEN
...
END IF