+atari2600land Posted August 11, 2010 Share Posted August 11, 2010 Is there an easy way to check if a variable is a variable of 4 (i.e. if a=4, if a=8, if a=12, etc...) Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted August 12, 2010 Share Posted August 12, 2010 (edited) If (variable&%00000011) = 0 is true. If either bits 0 or 1 are set, it's not a multiple of 4. You'd need to check if the variable = 0 directly if you wanted to skip that condition. In inline assembly, this is accomplished by LDA variable BEQ Is_Zero ;to skip the =zero condition AND #%00000011 ;throw away the 6 upper bits BEQ Is_Multiple_Of_Four ;if true or BNE Is_Not_Multiple_Of_Four ;if false Edited August 12, 2010 by Nukey Shay Quote Link to comment Share on other sites More sharing options...
+atari2600land Posted August 12, 2010 Author Share Posted August 12, 2010 It doesn't seem to want to work. snake.bas Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted August 12, 2010 Share Posted August 12, 2010 How about if (variable&&%00000011)=0? (note the double ampersand) Either & or && should correspond to the AND opcode. Quote Link to comment Share on other sites More sharing options...
+atari2600land Posted August 12, 2010 Author Share Posted August 12, 2010 Nope, still won't work. Quote Link to comment Share on other sites More sharing options...
jbs30000 Posted August 12, 2010 Share Posted August 12, 2010 I haven't done this, but it should work. var2=var1//4 var1 is the variable you want to check. //4 means put the remainder of var1/4 in temp1. If temp1=0 then... If no remainder then 4 goes into var1 evenly. Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted August 12, 2010 Share Posted August 12, 2010 (edited) Instead of trying to use this: if (a && %00000011)=0 && u{0} && v=1 then x=2 if (e && %00000011)=0 && u{0} && v=1 then x=2 if (i && %00000011)=0 && u{0} && v=1 then x=2 if (m && %00000011)=0 && u{0} && v=1 then x=2 What about using this instead: temp5 = (a & %00000011) : if !temp5 && u{0} && v=1 then x=2 temp5 = (e & %00000011) : if !temp5 && u{0} && v=1 then x=2 temp5 = (i & %00000011) : if !temp5 && u{0} && v=1 then x=2 temp5 = (m & %00000011) : if !temp5 && u{0} && v=1 then x=2 Edited August 12, 2010 by Random Terrain Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted August 12, 2010 Share Posted August 12, 2010 Hmm...the use of multiple conditions on the same line might be the problem? Maybe try enclosing the entire expression between parenthesis? ex: if ((a&%00000011)=0) && u{0} && v=1 then x=2 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted August 12, 2010 Share Posted August 12, 2010 Hmm...the use of multiple conditions on the same line might be the problem? Maybe try enclosing the entire expression between parenthesis? ex: if ((a&%00000011)=0) && u{0} && v=1 then x=2 That doesn't want to compile either (using either type of AND). Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted August 12, 2010 Share Posted August 12, 2010 if (a&%00000011)<1 && u{0} && v=1 then x=2 This is getting nuts. Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted August 12, 2010 Share Posted August 12, 2010 (edited) if (a&%00000011)<1 && u{0} && v=1 then x=2 This is getting nuts. That doesn't seem to work either, but both of these compile: temp5 = (a & %00000011) : if temp5=0 && u{0} && v=1 then x=2 temp5 = (e & %00000011) : if temp5=0 && u{0} && v=1 then x=2 temp5 = (i & %00000011) : if temp5=0 && u{0} && v=1 then x=2 temp5 = (m & %00000011) : if temp5=0 && u{0} && v=1 then x=2 temp5 = (a & %00000011) : if !temp5 && u{0} && v=1 then x=2 temp5 = (e & %00000011) : if !temp5 && u{0} && v=1 then x=2 temp5 = (i & %00000011) : if !temp5 && u{0} && v=1 then x=2 temp5 = (m & %00000011) : if !temp5 && u{0} && v=1 then x=2 Edited August 12, 2010 by Random Terrain Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted August 12, 2010 Share Posted August 12, 2010 (edited) Hang on a second...you are constantly rechecking the same conditions. Remove them from the sequence... if !u{0} then skip_the_rest if v<>1 then skip_the_rest if (a&3)=0 then set_x if (e&3)=0 then set_x if (i&3)=0 then set_x if (m&3)<>0 then skip_the_rest set_x: x=2 skip_the_rest: Edited August 12, 2010 by Nukey Shay Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted August 12, 2010 Share Posted August 12, 2010 Hang on a second...you are constantly rechecking the same conditions. Remove them from the sequence... Yeah, I just posted his code as-is. Didn't try to clean it up. Quote Link to comment Share on other sites More sharing options...
GroovyBee Posted August 12, 2010 Share Posted August 12, 2010 I may be wrong but I think bB only does logical AND and not bitwise AND. I don't think the current version makes a distinction between & and &&. Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted August 12, 2010 Share Posted August 12, 2010 There should be both (unless something recently broke in it). Quote Link to comment Share on other sites More sharing options...
GroovyBee Posted August 12, 2010 Share Posted August 12, 2010 My mistake! I did find this from a few years ago :- http://www.atariage.com/forums/topic/100416-conditional-statements-with-score/page__view__findpost__p__1218564 By SeaGtGruff saying that bitwise operators don't work in "if" statements. However I don't know if that behaviour has been changed. Quote Link to comment Share on other sites More sharing options...
+batari Posted August 12, 2010 Share Posted August 12, 2010 My mistake! I did find this from a few years ago :- http://www.atariage.com/forums/topic/100416-conditional-statements-with-score/page__view__findpost__p__1218564 By SeaGtGruff saying that bitwise operators don't work in "if" statements. However I don't know if that behaviour has been changed. If you use the latest build, bitwise AND is supported in "if" statements with some restrictions. For example, you can do "if a & 3 then" but cannot check it against a value. To invert the condition, you need to use "else." This should work: if !u{0} then skip_the_rest if v<>1 then skip_the_rest if a&3 then skip_the_rest else set_x if e&3 then skip_the_rest else set_x if i&3 then skip_the_rest else set_x if m&3 then skip_the_rest set_x x=2 skip_the_rest Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted August 12, 2010 Share Posted August 12, 2010 Can you !a&3 That would avoid adding the extra "else" code. Quote Link to comment Share on other sites More sharing options...
+batari Posted August 12, 2010 Share Posted August 12, 2010 Can you !a&3 That would avoid adding the extra "else" code. Not currently. bB can evaluate a single bit or a condition between two simple operands and can't currently do anything with those operands (like invert them as you suggest.) Someday I may allow full expressions within conditions as this will vastly improve the language. Anyway, the code may be rewritten as follows, I think: if !u{0} then skip_the_rest if v<>1 then skip_the_rest if a&3 || e&3 || i&3 || m&3 then skip_the_rest x=2 skip_the_rest However, I am not sure if this will save any space over the above code. 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.