+Karl G Posted August 20, 2020 Share Posted August 20, 2020 I was wondering if anyone had any clever ways to trap writes only to a specific bit of a variable? Quote Link to comment Share on other sites More sharing options...
+stephena Posted August 20, 2020 Share Posted August 20, 2020 IIRC, this functionality is already built in. It basically makes use of the '&' operator to look at specific bits. There are built-in functions that use it, so you could write your own expression to do it too. This is from the 'help' command in the debugger: Quote Built-in functions: _joy0left {!(*SWCHA & $40)} Left joystick moved left _joy0right {!(*SWCHA & $80)} Left joystick moved right _joy0up {!(*SWCHA & $10)} Left joystick moved up _joy0down {!(*SWCHA & $20)} Left joystick moved down _joy0button {!(*INPT4 & $80)} Left joystick button pressed _joy1left {!(*SWCHA & $04)} Right joystick moved left _joy1right {!(*SWCHA & $08)} Right joystick moved right _joy1up {!(*SWCHA & $01)} Right joystick moved up _joy1down {!(*SWCHA & $02)} Right joystick moved down _joy1button {!(*INPT5 & $80)} Right joystick button pressed _select {!(*SWCHB & $02)} Game Select pressed _reset {!(*SWCHB & $01)} Game Reset pressed _color {*SWCHB & $08 } Color/BW set to Color _bw {!(*SWCHB & $08)} Color/BW set to BW _diff0b {!(*SWCHB & $40)} Left diff. set to B (easy) _diff0a {*SWCHB & $40 } Left diff. set to A (hard) _diff1b {!(*SWCHB & $80)} Right diff. set to B (easy) _diff1a {*SWCHB & $80 } Right diff. set to A (hard) Note the "& $xx" parts above. This is only looking at those specific bits. Since this is using a conditional expression, you need to use the 'IF' versions of trap: trapif, trapreadif, trapwriteif. In your case, you would use the very last one. As always, the manual is your friend ? 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.