+atari2600land Posted February 24, 2009 Share Posted February 24, 2009 (edited) Here's a little game I'm working on, and I need a little help. Say I want to have an even number out of a random one. So, I'd go a=rand/8 (I want the number to be less than 32.) Say the number it picks is 15. Then, I go a=a/2. The remainder would be 1/2. My question is, where does that 1/2 go? If it does go to temp1, then why doesn't this work? if temp1>0 then a=a+1 Any other suggestions, ideas, or comments welcome (and yes, that little sprite is supposed to be an alligator. If anyone wants to design a sprite, for this game it *must* be 8 pixels long.) zzyzzyx.bas zzyzzyx.bas.bin Edited February 24, 2009 by atari2600land Quote Link to comment Share on other sites More sharing options...
GroovyBee Posted February 24, 2009 Share Posted February 24, 2009 Bitwise AND the result with $FE (8 bits) or $FFFE (16 bits) as appropriate to make a number even. Quote Link to comment Share on other sites More sharing options...
+atari2600land Posted February 24, 2009 Author Share Posted February 24, 2009 Bitwise AND the result with $FE (8 bits) or $FFFE (16 bits) as appropriate to make a number even. What does that mean? Quote Link to comment Share on other sites More sharing options...
Omegamatrix Posted February 24, 2009 Share Posted February 24, 2009 (edited) The remainder would be 1/2. My question is, where does that 1/2 go? Hello Atari2600land, I believe BB would use a logical shift right (otherwise called LSR) to divide by 2. When you do a right shift the far right bit gets pushed into the carry. I believe in this case the carry would probably be disregarded after the shift, but I don't know what BB is doing. This is how I think it would sort of go: 1 / 2 = 0 2 / 2 = 1 3 / 2 = 1 4 / 2 = 2 5 / 2 = 2 6 / 2 = 3 Hope that helps. Edited February 24, 2009 by Omegamatrix Quote Link to comment Share on other sites More sharing options...
Omegamatrix Posted February 24, 2009 Share Posted February 24, 2009 Bitwise AND the result with $FE (8 bits) or $FFFE (16 bits) as appropriate to make a number even. What does that mean? That is a way to make numbers even using a simple assembly instruction. A byte is made of 8 bits, and each bit can be one or zero. That is simple enough, no? If the farthest right bit is a one, then the number is odd. To make it an even number we want to make that far right bit a zero. 11111111 < all the bits including the far right bit are 1's, this is an odd number as the far right bit is a "1" 11111110 < here the far right bit is a zero, so this number is even. So if the goal is to make an odd number even all we got to do is change the one far right bit. An "AND" instruction can do that. AND can keep a bit as it is, or clear it. Quote Link to comment Share on other sites More sharing options...
+atari2600land Posted February 24, 2009 Author Share Posted February 24, 2009 I changed the theme of the game from an alligator to a mouse. The title screen says "Cheesed Off!" but I might change the name to "Atomic Cheese." Anyway, I have no knowledge of assembly. What i need is a way to figure out how to find out if a number is odd and change it if it is, in bB language. I understand what Omegamatrix is trying to say about binary numbers, but I don't understand how to go about doing that in bB. zzyzzyx.bas.bin zzyzzyx.bas Quote Link to comment Share on other sites More sharing options...
Omegamatrix Posted February 24, 2009 Share Posted February 24, 2009 It's probably similar to a bitwise AND you would do in C. Try something like: X = X & 254 Where "X" is whatever variable you are using, "&" is your bitwise operator, 254 is equal to #$FE or %11111110. I'm not sure if you need a semicolon or other stuff. Quote Link to comment Share on other sites More sharing options...
+atari2600land Posted February 24, 2009 Author Share Posted February 24, 2009 I don't understand what it did, but it worked. Thank you. cheese.bas.bin cheese.bas Quote Link to comment Share on other sites More sharing options...
Omegamatrix Posted February 24, 2009 Share Posted February 24, 2009 I'm glad that it worked. I see that you are using a && instead of & in this case. These are quite different things in C, but I'm not sure about BB. In C the "&&" means if both expressions are true, return a one. The Bitwise operator is just a single "&" in C. Maybe just double check that "&&". It seems to me it should just be a single "&" in this case... Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted February 24, 2009 Share Posted February 24, 2009 I'm glad that it worked. I see that you are using a && instead of & in this case. These are quite different things in C, but I'm not sure about BB. In C the "&&" means if both expressions are true, return a one. The Bitwise operator is just a single "&" in C. Maybe just double check that "&&". It seems to me it should just be a single "&" in this case... In bB, && is used in if-then statements: http://www.randomterrain.com/atari-2600-me...ds.html#boolean http://www.randomterrain.com/atari-2600-me...mands.html#math Quote Link to comment Share on other sites More sharing options...
Omegamatrix Posted February 24, 2009 Share Posted February 24, 2009 Looking at RT's site it does seem you need to use a single "&" to do the Bitwise AND, just like C. Quote Link to comment Share on other sites More sharing options...
+batari Posted February 24, 2009 Share Posted February 24, 2009 At the moment, these are identical, because bB ignores the second &: x = x & 254 x = x && 254 However, you should use &, as bB may be expanded at some point to allow boolean expressions, and the two would be interpreted differently. Quote Link to comment Share on other sites More sharing options...
+atari2600land Posted February 24, 2009 Author Share Posted February 24, 2009 The way I learned bB is to use two ampersands. Did something change with the 1.0 release? What happened? Quote Link to comment Share on other sites More sharing options...
MausGames Posted February 24, 2009 Share Posted February 24, 2009 In bB, && is used in if-then statements: http://www.randomterrain.com/atari-2600-me...ds.html#boolean http://www.randomterrain.com/atari-2600-me...mands.html#math Quote Link to comment Share on other sites More sharing options...
+atari2600land Posted February 24, 2009 Author Share Posted February 24, 2009 Added some sound effects. Then I got to thinking, this is a lot like Space Treat Deluxe. What do you think? If so, what changes could I make to make it not like that? cheese.bas.bin cheese.bas 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.