Robert Gremillion Posted April 30, 2022 Share Posted April 30, 2022 I have all of these flag variables and I want to consolidate them into one byte called Flags. Flags is set to 0, but it doesn't branch here. lda #%00000010 ; setting up accumulator to check position 1 bit bit Flags ; comparing Flags - position 1 for Add Hole Flag set bne .SetPoleFlag What am I doing wrong? Thanks! Quote Link to comment Share on other sites More sharing options...
+splendidnut Posted April 30, 2022 Share Posted April 30, 2022 Ah... The logic is backwards.... switch the branch instruction to a BEQ if you want to branch when the 'position 1 bit' is not set. ---- I'll try to explain: It's best to think of the BIT op as an AND operation (that's mainly what it is)... not a CMP. If the 'Flags' variable is zero, the BIT op will set the zero flag because (Flags AND %00000010) will be zero. In this case, BNE won't branch because the zero flag is set. BNE is Branch Not Equal... but can also be thought of as BNZ - Branch if Not Zero (zero flag is not set). BEQ is Branch Equal... but can also be thought of as BZ - Branch if Zero (zero flag is set). BNE and BEQ are named as they are because they're typically used with the CMP op, in which their names make more sense. This is one of the fun little confusing bits of programming in Assembly language that sometimes trips me up also. Hopefully this all makes sense and I haven't made things more confusing. Quote Link to comment Share on other sites More sharing options...
Robert Gremillion Posted April 30, 2022 Author Share Posted April 30, 2022 18 minutes ago, splendidnut said: Ah... The logic is backwards.... Thank you for replying!!! The logic felt backwards to me and when I tried the opposite it seemed to work. Quote Link to comment Share on other sites More sharing options...
Robert Gremillion Posted April 30, 2022 Author Share Posted April 30, 2022 39 minutes ago, splendidnut said: Ah... The logic is backwards.... switch the branch instruction to a BEQ if you want to branch when the 'position 1 bit' is not set. Can I ask you one more question? What should I be using to set that bit on and off. I want to control it with the 2nd joystick - joystick right / turn off - joystick left / turn on. I have this code below, but cannot get it to work either. Thanks! CheckP1Left: lda #%00000100 ; player 1 joystick right - J bit SWCHA bne CheckP1Right lda Flags ; loading Flags variable into the accumulator ora #%00000010 ; Flags - Position 1 - setting Add Hole Flag to False sta Flags CheckP1Right: lda #%00001000 ; player 1 joystick left - G bit SWCHA bne CheckP1Up lda Flags ; loading Flags variable into the accumulator and #%00000010 ; Flags - Position 1 - setting Add Hole Flag to True sta Flags CheckP1Up: Quote Link to comment Share on other sites More sharing options...
+splendidnut Posted April 30, 2022 Share Posted April 30, 2022 To set a bit: lda Flags ; loading Flags variable into the accumulator ora #%00000010 ; Flags - Position 1 - setting Add Hole Flag to True sta Flags Basically OR with the bit you want to set ---- To clear a bit: lda Flags ; loading Flags variable into the accumulator and #%11111101 ; Flags - Position 1 - setting Add Hole Flag to False sta Flags In this case, you need to Mask off the bit by performing an AND op with the inverse. This basically keeps the state of all the other bits, while turning off the bit you want. Quote Link to comment Share on other sites More sharing options...
+splendidnut Posted April 30, 2022 Share Posted April 30, 2022 And if you want to flip / invert a bit: lda Flags ; loading Flags variable into the accumulator eor #%00000010 ; Flags - Position 1 - flip the state of the Add Hole Flag sta Flags If the Add Hole Flag is on, this will turn it off. If the Add Hole Flag is off, this will turn it on. Quote Link to comment Share on other sites More sharing options...
Robert Gremillion Posted April 30, 2022 Author Share Posted April 30, 2022 11 minutes ago, splendidnut said: And if you want to flip / invert a bit: lda Flags ; loading Flags variable into the accumulator eor #%00000010 ; Flags - Position 1 - flip the state of the Add Hole Flag sta Flags If the Add Hole Flag is on, this will turn it off. If the Add Hole Flag is off, this will turn it on. I was using eor for flipping the pause flag and that was the only part working fine. Thanks for all of your help!!!!! 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.