IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New is there a better way to double/quad up a bit pattern?
For my latest Atari 2600 game I'm having to use software collision detection. I'm about to add support for wide sprites (the Atari can 2x and 4x horizontally) for some new objects and need to revise the collision routines to handle that. Basically if a bit pattern is _X_XX_X_ I need to test the collision against __XX__XXXX__XX__.

I've written this up (but haven't tested it yet) and thought somebody here might have a better way to do it.

int DoubleBits(int bits)

{
int i;
int mask;
int result;

mask = 0x80;
result = 0;
for(i=0;i<8;i++)
{
result = (result << 2) + ((bits & mask) ? 3 : 0);
mask >>= 1;
}
return result;
}


To make that a QuadBits for the 4x sprites, I'd just change the 1 line to
        result = (result << 4) + ((bits & mask) ? 15 : 0);


Hmm, I know there's a way to post formatted code...
Expand Edited by SpiceWare Sept. 10, 2011, 10:50:46 PM EDT
New Try these
http://graphics.stan...leaveTableObvious

If you have space but not time, the table lookup method is probably best.
Regards,
-scott
Welcome to Rivendell, Mr. Anderson.
New Good stuff. Any (known) relation?
New Hah, I didn't notice that the first time
Regards,
-scott
Welcome to Rivendell, Mr. Anderson.
New thanks
looks like I'm doing a variation of the "obvious way", though mine is interleaving the value with itself.

table lookup would probably be best - think I'll do it with a 16 byte table and double up each nybble as a 512 byte table would take up too much room.
New I like the page title
I read it as, "A collection of code for by and for bit twiddling hacks."
--

Drew
New my table driven routine
const unsigned char double_nybble[] = { 0x00, 0x03, 0x0C, 0x0F,

0x30, 0x33, 0x3C, 0x3F,
0xC0, 0xC3, 0xCC, 0xCF,
0xF0, 0xF3, 0xFC, 0xFF};

int DoubleBits(int bits)
{
return (double_nybble[(bits & 0xf0) >> 4] << 8) + double_nybble[bits & 0x0f];
}
New Nice, looks like it should be quick
Regards,
-scott
Welcome to Rivendell, Mr. Anderson.
New Re: my table driven routine
Haven't seen the word "nybble" since my student days.
     is there a better way to double/quad up a bit pattern? - (SpiceWare) - (8)
         Try these - (malraux) - (4)
             Good stuff. Any (known) relation? -NT - (Another Scott) - (1)
                 Hah, I didn't notice that the first time -NT - (malraux)
             thanks - (SpiceWare)
             I like the page title - (drook)
         my table driven routine - (SpiceWare) - (2)
             Nice, looks like it should be quick -NT - (malraux)
             Re: my table driven routine - (pwhysall)

And then I went into computers...
86 ms