Jump to content
IGNORED

Named bit positions


RevEng

Recommended Posts

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.

Link to comment
Share on other sites

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 ...

Link to comment
Share on other sites

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 by RevEng
Link to comment
Share on other sites

(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 by RevEng
Link to comment
Share on other sites

(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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...