2 bit access
Nightrider7731
Posts: 46
Is there·any symbol that can be used to reference 2 bits of a byte?· I'm controlling 4 pairs of bits with the requirement that only one bit in each pair can be on (1).· I can label each bit and programmatically affect each pair one bit at a time, but I'd love to be able to reference and set them to %01 and %10 in a single call.· All I can find are symbols for 4 (Nib) and·8 (low/highbyte)·bit values.
Thanks!
Thanks!
Comments
·· There are 2 ways you could go about this.· The first would be to use a NIB variable and mask the bits you aren't using.· The other way would be to reference the individual bits.· For example:
OR
Something like that.· But basically there is BIT access, not just NIB and BYTE (And WORD).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Post Edited (Chris Savage (Parallax)) : 5/31/2005 3:25:46 AM GMT
TARGETCONTROL···· VAR Byte····· 'control pointer for all fire/popup code
Player1TargetUp···· VAR TARGETCONTROL.BIT0
Player1TargetDown·· VAR TARGETCONTROL.BIT1
Player2TargetUp···· VAR TARGETCONTROL.BIT2
Player2TargetDown·· VAR TARGETCONTROL.BIT3
Player3TargetUp···· VAR TARGETCONTROL.BIT4
Player3TargetDown·· VAR TARGETCONTROL.BIT5
Player4TargetUp···· VAR TARGETCONTROL.BIT6
Player4TargetDown·· VAR TARGETCONTROL.BIT7
... and I control each 2 bit value pair bit by bit.
Player1TargetUp = 1
Player1TargetDown = 0
···· and
Player1TargetUp = 0
Player1TargetDown = 1
There is a separate controller for each motion on each target, so simply turning a single bit value·on and off doesn't work in this case.· The byte is being passed to '595 to do the work.· Actually several 595s are chained together, but that doesn't matter.· I was looking for a cheap (code wise) way to alias 2 bit blocks like this...
TARGETCONTROL···· VAR Byte····· 'control pointer for all fire/popup code
Player1Target···· VAR TARGETCONTROL.2BIT0··········· ' 2BIT0 being a fictional symbol of course [noparse]:)[/noparse]
Player2Target···· VAR TARGETCONTROL.2BIT1
Player3Target···· VAR TARGETCONTROL.2BIT2
Player4Target···· VAR TARGETCONTROL.2BIT3
TargetUp···· = %10
TargetDown = %01
... and then manipulate TARGETCONTROL by ...
Player1Target = TargetUp
Player1Target = TargetDown
Player1Target = TargetDown
Player1Target = TargetUp
... and then shiftin TARGETCONTROL.· I guess I'll just stick to the Bit manipulation.
Or perhaps you could explain fundamentally what you want to do?
Post Edited (KenM) : 5/31/2005 6:13:22 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don Buczynski
http://www.buczynski.com
··
·· The immediate problem I see with what you're wanting to do, is you're trying to assign a 2-bit value (TargetUp) to a 1-bit variable (Player1Target).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
ps = %1001 ' 4 bits, one bit for each playertarget, set bits as desired for target up, down.
' then mathematically create the following
stateOfPlay = (1 << ps.bit0) + (4 << ps.bit1) + (16 << ps.bit2) + (64 << ps.bit3)
' that creates the byte, %10010110 to go with nib %1001
' to send to the controller
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
i've always been a fan of shifting, perhaps this method suits you
'unverified
playerdata VAR Word
Main:
GOSUB target_routine
FOR idx = 0 TO 6
playerdata >> 2
GOSUB target_routine
next
'... several lines later
target_routine:
SELECT playerdata // 2
CASE 0
'do that thing
CASE 1
'do that thing
CASE 2
'do that thing
CASE 3
'do that thing
ENDSELECT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Byte walks into a bar and orders a pint. Bartender asks him "What's wrong?"
Byte says "Parity error." Bartender nods and says "Yeah, I thought you looked a bit off."