+Random Terrain Posted March 13, 2012 Share Posted March 13, 2012 Ah, okay. So it's like the TIA values, in that SWCHA can't be read. I don't know if that's true, but it seems like addition, subtraction, multiplication, division, and that kind of ANDing don't work in an if-then. You have to do the work in a variable, then use the variable in the if-then. Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted March 14, 2012 Share Posted March 14, 2012 SWCHA uses a single & sign. Not sure if that makes a difference, but I just noticed that and thought it was interesting. As I understand it (maybe I have it backwards), && is a logical AND (A && B means A is true and B is also true), whereas & is a bit AND (A & B means do an AND between the bits in A and the bits in B). You'd have to do something like this: temp5 = SWCHA & 240 if temp5 <> 240 then P1_Acceleration=P1_Acceleration+4 else P1_Resistance=0 The code I posted works great for me when I compile it with batari Basic version 1.whatever (what is the latest version now, something like 1.1d?). But you're right that some of these types of operations required the use of an intermediate variable in order for it to work in an if. Note that when I compile the little test program I posted, the compiled assembly code says "complex condition detected," but it compiles to the correct assembly code: Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted March 14, 2012 Share Posted March 14, 2012 it seems like addition, subtraction, multiplication, division, and that kind of ANDing don't work in an if-then. You have to do the work in a variable, then use the variable in the if-then. At one time I think that was true, but the version I'm using (2600basic.exe dated 07/28/2011) seems to handle it just fine. Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted March 14, 2012 Share Posted March 14, 2012 Ah, okay. So it's like the TIA values, in that SWCHA can't be read. No, that's incorrect. SWCHA can definitely be read-- you *have* to read it to see whether the left joystick and/or right joystick are being pushed in a given direction. The left joystick (or joystick 0) uses the upper nibble, and the right joystick (joystick 1) uses the lower nibble. If all four bits in a nibble are 1, that means the joystick is *not* being pushed in any direction. If one or more of the bits are 0, it means the jostick is being pushed in that direction. SWCHA & 240 masks out the lower nibble and gives you just the upper nibble, so if the result equals 240 it means the joystick is *not* pushed in any direction, whereas any result other than 240 means it's being pushed in one or more directions. Since (in this particular section of code) you don't care what the direction is, only that it's pressed in some direction or other, that's the fastest way I could think of to check it. 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.