KevKelley Posted May 8, 2022 Share Posted May 8, 2022 I know in the regular standard kernel I can play around with playfield Variables to turn things on or off by using their variables like var30=%11010001 and then use some bitwise operations to turn them on or off. I was looking to do something similar with Superchip playfield but was a little confused on how I'd do it. Would I check them the same but use Superchip variables like w/r087, etc.? Quote Link to comment Share on other sites More sharing options...
+Karl G Posted May 8, 2022 Share Posted May 8, 2022 Yeah, that's how it would work. You can use the read variables to get playfield information, and the write variables to change the playfield on the fly. Quote Link to comment Share on other sites More sharing options...
KevKelley Posted May 8, 2022 Author Share Posted May 8, 2022 25 minutes ago, Karl G said: Yeah, that's how it would work. You can use the read variables to get playfield information, and the write variables to change the playfield on the fly. Thanks. I assumed but when I was looking at it this morning I couldn't figure it out. Hopefully I can get whatever I am looking to get done to work. Quote Link to comment Share on other sites More sharing options...
KevKelley Posted May 8, 2022 Author Share Posted May 8, 2022 1 hour ago, Karl G said: Yeah, that's how it would work. You can use the read variables to get playfield information, and the write variables to change the playfield on the fly. Would you happen to know if there is a relatively simple way to compare how many bits are different between a variable? For example, if a playfield variable is checked, if bits are off then they are flipped on, and then count how many bits are flipped? Quote Link to comment Share on other sites More sharing options...
+Karl G Posted May 8, 2022 Share Posted May 8, 2022 Here's a way to do it assuming that I'm understanding you correctly. Let's say the new value was $FF because you are turning all 8 pixels on, and let's say that the playfield block in question is 100. temp1 = r100^$FF. ; Exclusive or will set only the bits that differ to 1, and the rest are 0 w100 = $FF ; Actually change the variable after checking what bits differ ; Next we count the number of bits that are set to 1 in temp1, which will be the number of bits that were changed ; temp2 will be equal to the number of bits changed. temp2 = 0 BitCountLoop if temp1{0} then temp2 = temp2 + 1 ; check rightmost bit for a 1, and increment temp2 if so temp1 = temp1 / 2 ; shift all bytes to the right by 1 if temp1 then goto BitCountLoop ; Repeat again if any remaining bits are still 1 1 Quote Link to comment Share on other sites More sharing options...
KevKelley Posted May 8, 2022 Author Share Posted May 8, 2022 21 minutes ago, Karl G said: Here's a way to do it assuming that I'm understanding you correctly. Let's say the new value was $FF because you are turning all 8 pixels on, and let's say that the playfield block in question is 100. temp1 = r100^$FF. ; Exclusive or will set only the bits that differ to 1, and the rest are 0 w100 = $FF ; Actually change the variable after checking what bits differ ; Next we count the number of bits that are set to 1 in temp1, which will be the number of bits that were changed ; temp2 will be equal to the number of bits changed. temp2 = 0 BitCountLoop if temp1{0} then temp2 = temp2 + 1 ; check rightmost bit for a 1, and increment temp2 if so temp1 = temp1 / 2 ; shift all bytes to the right by 1 if temp1 then goto BitCountLoop ; Repeat again if any remaining bits are still 1 I think this was kind of what I was going for. I will have to post what I went with when I get home and test to see if it works. Thanks! Quote Link to comment Share on other sites More sharing options...
KevKelley Posted May 9, 2022 Author Share Posted May 9, 2022 (edited) So originally I was trying to kind of systematically go through each playfield variable, flip any bit that is off turning them on, and then turn off the same amount of bits but I was trying to make the bits that turn off either to the left or the right of the ones turned on. I think I was approaching my goal the wrong way (although I was interested in applicability of doing things like counting bits or comparing bits but this is the solution I came up with that pretty much achieved the desired effects and was much simpler: r=rand16&63 WINDLITTER if r>50 || player1y<40 then goto SKIP_WINDLITTER ; determines the frequency of when the playfield pixel is checked if var1>24 then var1=9 ; determines the row if var2>20 then var2=9 ; determines the column var3=var1+1: if var3>24 then var3=9 ; determines relocated pixel location if pfread(var1,var2) then goto SKIP_GRASSCHECK ; if the playfield is on then skip the repositioning pfpixel var1 var2 on: w004=r004-1:var4=1 ; turns on the playfield, w004 keeps track of pixels turned off or on if var4=1 && pfread(var3,var2) then pfpixel var3 var2 off:w004=r004+1:var4=0:var2=var2+1:var1=var1+1 ; turns off the pixel in new location goto SKIP_WINDLITTER SKIP_GRASSCHECK var1=var1+1:var2=var2+1 ; changes next playfield pixel location to check SKIP_WINDLITTER So far from testing it seems to work how I intended. Edited May 9, 2022 by KevKelley 1 Quote Link to comment Share on other sites More sharing options...
+Karl G Posted May 9, 2022 Share Posted May 9, 2022 Cool that you found a simpler solution for what you were trying to do, but I have a small nitpick for your code: 29 minutes ago, KevKelley said: r=rand16&63 That's not how rand16 is supposed to be used. You dim rand16 to one of your variables to improve the randomization routine by allowing it to use 16 bits. You still use rand for setting variables, however. 30 minutes ago, KevKelley said: r=rand&63 Quote Link to comment Share on other sites More sharing options...
KevKelley Posted May 9, 2022 Author Share Posted May 9, 2022 8 minutes ago, Karl G said: Cool that you found a simpler solution for what you were trying to do, but I have a small nitpick for your code: That's not how rand16 is supposed to be used. You dim rand16 to one of your variables to improve the randomization routine by allowing it to use 16 bits. You still use rand for setting variables, however. Oh! I didn't know that. I had thought it replaced rand. Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted May 16, 2022 Share Posted May 16, 2022 On 5/9/2022 at 12:05 PM, KevKelley said: Oh! I didn't know that. I had thought it replaced rand. I just updated the bB page to be more clear: https://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#rand_rand16 Quote Do not use “rand16” in your code; use rand as you normally would. The only place “rand16” is used is when you set it up with “dim rand16 = <var>”. 1 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.