Can you clarify? because I am confused by your question.
'video_buffer_A1' is the array name.
'video_adress' is the pointer to an element in the array 'video_buffer_A1'.
So, to assign an element you would use
var1 = video_buffer_A1(element)
You can then obtain the bits of var1 by
var1bit = var1.1 : ' where .1 is the pointer to the bits.
So, what are your trying to achieve?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
"Can I specify the bit of a variable to alter using another variable?
No. Set variable.othervariable On may not generate an error, but it will not act as expected."
Does anybody know why is that ? It would make it easier for everyone no ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This limitation comes from the way that GCBASIC addresses individual bits. On a PIC, it uses btfss, btfsc, bsf and bcf instructions, all of which require the individual bit to be hard coded. One workaround is some code like this:
'Prepare a bit mask with only the correct bit set
TempMask = 0
Set C On
Repeat Pixel
Rotate TempMask Left
End Repeat
'OR with array element to set bit there
video_buffer_A1(video_adress) = video_buffer_A1(video_adress) Or TempMask
To clear a bit, you'd need similar code (but start with TempMask = 255, C = Off, and an And rather than an Or in the array set.)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
nice. I use the mask trick quite often now. Made an array of 8 bytes with one bit ON at the time and use the array(variable) to mask my bytes. It's good to learn.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
simple naive question : could this be potentially taken care of by the compiler ? i mean could we use the simple adressing syntax with a variable in our code and let the compiler do all the masking tricks ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As we have a method to addressn array bit within the current compiler constraint the investment (in time to develop and test) may not be worth benefit.
However, I have added to the list of the potential future changes.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi there,
What would be the syntax to address a single bit in an array ?
I've tried :
video_buffer_A1(video_adress).pixel = 1
video buffer is an array of 64 bytes, and pixel is a number between 0 and 7
doesn't seem to work...
Last edit: polyconnect 2013-09-26
Can you clarify? because I am confused by your question.
'video_buffer_A1' is the array name.
'video_adress' is the pointer to an element in the array 'video_buffer_A1'.
So, to assign an element you would use
var1 = video_buffer_A1(element)
You can then obtain the bits of var1 by
var1bit = var1.1 : ' where .1 is the pointer to the bits.
So, what are your trying to achieve?
Thanks for your answer. It helped ;)
According to the FAQ in the help file :
"Can I specify the bit of a variable to alter using another variable?
No. Set variable.othervariable On may not generate an error, but it will not act as expected."
Does anybody know why is that ? It would make it easier for everyone no ?
Sorry, I do not know the answer.
I have not seen any references to variable referential addressing. I am aware of referential addressing for ports.
This limitation comes from the way that GCBASIC addresses individual bits. On a PIC, it uses btfss, btfsc, bsf and bcf instructions, all of which require the individual bit to be hard coded. One workaround is some code like this:
To clear a bit, you'd need similar code (but start with TempMask = 255, C = Off, and an And rather than an Or in the array set.)
nice. I use the mask trick quite often now. Made an array of 8 bytes with one bit ON at the time and use the array(variable) to mask my bytes. It's good to learn.
simple naive question : could this be potentially taken care of by the compiler ? i mean could we use the simple adressing syntax with a variable in our code and let the compiler do all the masking tricks ?
As we have a method to addressn array bit within the current compiler constraint the investment (in time to develop and test) may not be worth benefit.
However, I have added to the list of the potential future changes.