RevEng Posted June 21, 2009 Share Posted June 21, 2009 I was squeezing down some variables I was using like booleans into bitfields. To make my bit setting/reading a bit more meaningful, I was trying something along the lines of... dim gameflags=a const PLAYERDIED=0 ... gameflags{PLAYERDIED}=1 ...which unfortunately doesn't work. bB doesn't like variables in the bitfields, and rejects constants for the same reason. Understandable, as the constants get expanded in dasm, not the bB compiler. However I did discover that you could do something halfway there. bB will use the rightmost character as the bit position and ignore anything on the left, so you can make your source more readable with something like... dim gameflags=a ... gameflags{PLAYERDIED_0}=1 ... if gameflags{PLAYERDIED_0} then... ...this is totally undocumented and unintended behaviour from bB, so if you use it it could vanish in a future version of bB. Still, I like having my bits obvious, so I'm going to use it. I thought someone else here might care to use it too. Quote Link to comment Share on other sites More sharing options...
+batari Posted June 21, 2009 Share Posted June 21, 2009 I was squeezing down some variables I was using like booleans into bitfields. To make my bit setting/reading a bit more meaningful, I was trying something along the lines of... dim gameflags=a const PLAYERDIED=0 ... gameflags{PLAYERDIED}=1 ...which unfortunately doesn't work. bB doesn't like variables in the bitfields, and rejects constants for the same reason. Understandable, as the constants get expanded in dasm, not the bB compiler. However I did discover that you could do something halfway there. bB will use the rightmost character as the bit position and ignore anything on the left, so you can make your source more readable with something like... dim gameflags=a ... gameflags{PLAYERDIED_0}=1 ... if gameflags{PLAYERDIED_0} then... ...this is totally undocumented and unintended behaviour from bB, so if you use it it could vanish in a future version of bB. Still, I like having my bits obvious, so I'm going to use it. I thought someone else here might care to use it too. I think this method will probably be safe. However, you can use the def command to do the same thing without worrying about the trailing zero, or take it a step further and define the entire bit access: def PLAYERDIED=gameflags{0} ... if PLAYERDIED then ... Quote Link to comment Share on other sites More sharing options...
RevEng Posted June 21, 2009 Author Share Posted June 21, 2009 (edited) Aw sweet! I had no clue about the def command (it's not documented at Random Terrain's guide as far as I can see) but that's a *way* better way to do it! Now I can forget about the bit positions entirely. So basically def is a bB-level definition, and const is a dasm-level one... Excellent! Thanks for the clue, and for the excellent tools sir! (most excitedly awaiting Harmony!) Edited June 21, 2009 by RevEng Quote Link to comment Share on other sites More sharing options...
RevEng Posted June 21, 2009 Author Share Posted June 21, 2009 (edited) (31): Error: Unknown keyword: def I'm using 1.0 from the official site. It also doesn't appear to be in the manual included with bB. Just checked the source, and it's not in keywords.c. Is there a later version of bB I can grab somewhere with this implemented? Edited June 21, 2009 by RevEng Quote Link to comment Share on other sites More sharing options...
+batari Posted June 21, 2009 Share Posted June 21, 2009 (31): Error: Unknown keyword: def I'm using 1.0 from the official site. It also doesn't appear to be in the manual included with bB. Just checked the source, and it's not in keywords.c. Is there a later version of bB I can grab somewhere with this implemented? Yes, you need the latest build posted here: http://www.atariage.com/forums/index.php?a...t&id=130754 I am pointing you toward the minGW build as that is going to replace DJGPP, the old compiler. Quote Link to comment Share on other sites More sharing options...
RevEng Posted June 21, 2009 Author Share Posted June 21, 2009 Got it, and it's working great! Thanks again. 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.