+Random Terrain Posted September 28, 2011 Share Posted September 28, 2011 (edited) I know we can't use this: if a{0} <> a{1} then blah blah blah If I knew how to compare two bits, I forgot and I don't see it on the bB page. The only thing I can think of is this: if a{0} then if !a{1} then goto __Pause_Game if !a{0} then if a{1} then goto __Pause_Game Is that the best way to do it? Thanks. Edited September 28, 2011 by Random Terrain Quote Link to comment Share on other sites More sharing options...
RevEng Posted September 28, 2011 Share Posted September 28, 2011 You can xor them together. If they differ, the result is 1. If they are the same, the result is 0. As far as efficiency, if the bits are neighbors you come out ahead 9 bytes of rom space, for your example... temp1=a^(a/2) if temp1{0} then goto __Pause_Game 1 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted September 28, 2011 Author Share Posted September 28, 2011 You can xor them together. If they differ, the result is 1. If they are the same, the result is 0. As far as efficiency, if the bits are neighbors you come out ahead 9 bytes of rom space, for your example... temp1=a^(a/2) if temp1{0} then goto __Pause_Game Thanks. Since it uses division, does that mean it's a little slower? Quote Link to comment Share on other sites More sharing options...
RevEng Posted September 28, 2011 Share Posted September 28, 2011 Yours is a bit faster because the comparisons avoid some work that mine does in constant time. (a division by 2 in this case only adds 2 cycles) I think your worst case scenario is 24 cycles, and mine is 33 cycles. 1 Quote Link to comment Share on other sites More sharing options...
Mr SQL Posted September 28, 2011 Share Posted September 28, 2011 You can xor them together. If they differ, the result is 1. If they are the same, the result is 0. As far as efficiency, if the bits are neighbors you come out ahead 9 bytes of rom space, for your example... temp1=a^(a/2) if temp1{0} then goto __Pause_Game Thanks. Since it uses division, does that mean it's a little slower? RT, Bitwise operations are fast but I think it would be easier to just evaluate the bitwise expression if it is handled: if (a{0} ^ !a{1}) then goto __Pause_Game Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted September 28, 2011 Author Share Posted September 28, 2011 Yours is a bit faster because the comparisons avoid some work that mine does in constant time. (a division by 2 in this case only adds 2 cycles) I think your worst case scenario is 24 cycles, and mine is 33 cycles. OK, thanks. I better put this on the bB page too. RT,Bitwise operations are fast but I think it would be easier to just evaluate the bitwise expression if it is handled: if (a{0} ^ !a{1}) then goto __Pause_Game Thanks, but I don't think we can do that with batari basic: http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#bit Quote Link to comment Share on other sites More sharing options...
Emehr Posted September 28, 2011 Share Posted September 28, 2011 You can xor them together. If they differ, the result is 1. If they are the same, the result is 0. As far as efficiency, if the bits are neighbors you come out ahead 9 bytes of rom space, for your example... temp1=a^(a/2) if temp1{0} then goto __Pause_Game Can you just bit-shift right once instead of dividing by 2? Or would that use the same number of cycles? (does bBasic support bit shifting?) Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted September 28, 2011 Author Share Posted September 28, 2011 Can you just bit-shift right once instead of dividing by 2? Or would that use the same number of cycles? (does bBasic support bit shifting?) We can use assembly language: http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#assembly But I usually try to keep things in bB mode for the bB page to avoid confusing new users. Unless it's something cool like this: http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#points_roll_up 1 Quote Link to comment Share on other sites More sharing options...
Mr SQL Posted September 28, 2011 Share Posted September 28, 2011 Yours is a bit faster because the comparisons avoid some work that mine does in constant time. (a division by 2 in this case only adds 2 cycles) I think your worst case scenario is 24 cycles, and mine is 33 cycles. OK, thanks. I better put this on the bB page too. RT,Bitwise operations are fast but I think it would be easier to just evaluate the bitwise expression if it is handled: if (a{0} ^ !a{1}) then goto __Pause_Game Thanks, but I don't think we can do that with batari basic: http://www.randomter...mmands.html#bit Sorry RT, I meant: if(a{0}^a{1}) then ... must have left the other operator in there; should work without the parenthesis if the compiler doesn't like them since only a single term is in the expression. Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted September 28, 2011 Author Share Posted September 28, 2011 (edited) Sorry RT,I meant: if(a{0}^a{1}) then ... must have left the other operator in there; should work without the parenthesis if the compiler doesn't like them since only a single term is in the expression. Check out the "Did You Know?" box here: http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#bit Unless we were never told about it or something has changed, I think we are very limited when it comes to bit operations and if-thens. Edited September 28, 2011 by Random Terrain Quote Link to comment Share on other sites More sharing options...
Mr SQL Posted September 28, 2011 Share Posted September 28, 2011 Sorry RT,I meant: if(a{0}^a{1}) then ... must have left the other operator in there; should work without the parenthesis if the compiler doesn't like them since only a single term is in the expression. Check out the "Did You Know?" box here: http://www.randomter...mmands.html#bit Unless we were never told about it or something has changed, I think we are very limited when it comes to bit operations and if-thens. You're right, you can't use ^ that way, it flips two arguments I thought it was a comparison operator I think your first solution has the least overhead. Quote Link to comment Share on other sites More sharing options...
RevEng Posted September 28, 2011 Share Posted September 28, 2011 Can you just bit-shift right once instead of dividing by 2? Or would that use the same number of cycles? (does bBasic support bit shifting?) bB automatically turns a divide with a power-of-2 into a number of LSR bit-shifts. 1 Quote Link to comment Share on other sites More sharing options...
ScumSoft Posted September 28, 2011 Share Posted September 28, 2011 (edited) [edit]Very nice bogax! My solution was way off Edited October 1, 2011 by ScumSoft 1 Quote Link to comment Share on other sites More sharing options...
bogax Posted September 30, 2011 Share Posted September 30, 2011 (edited) Not sure I remember the conventions rightly, but assuming bit 0 is the least significant bit ... If you add a 1 to a bit you can, in effect, propagate it to a more significant position via carry If you add two bits together the sum is the XORing of the two You can do both at once in this case by adding 1 to a Then use & to isolate bit 1 to test it (ie a bitwise AND with 2) if (a + 1)& 2 then goto __pause_game __pause_game produces .L00 ; if ( a + 1 ) & 2 then goto __pause_game ; complex statement detected LDA a CLC ADC #1 AND #2 BEQ .skipL00 .condpart0 jmp .__pause_game .skipL00 . ; .__pause_game ; __pause_game That ought to be something like what you want Edited September 30, 2011 by bogax 1 Quote Link to comment Share on other sites More sharing options...
bogax Posted October 1, 2011 Share Posted October 1, 2011 if a/2 ^ a & 1 then goto __pause_game __pause_game .L00 ; if a / 2 ^ a & 1 then goto __pause_game ; complex condition detected ; complex statement detected LDA a lsr EOR a AND #1 BEQ .skipL00 .condpart0 jmp .__pause_game .skipL00 . ; .__pause_game ; __pause_game 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.