Jump to content



0

double or quad up a bit pattern?


3 replies to this topic

#1 SpiceWare OFFLINE  

SpiceWare

    Quadrunner

  • 5,990 posts
  • Medieval Mayhem
  • Location:Planet Houston

Posted Fri Sep 9, 2011 2:00 PM

I've been working on Frantic, an updated version of Berzerk/Frenzy, for the 2600. It's using the Harmony's ARM processor for the game logic and a slick display kernel that lets me multiplex the Atari's 2 players (sprites) quite effectively to draw all the objects on screen with minimal flicker.

I'm now in the process of planning out the Frenzy variation, which has special rooms* every so often. To show the special objects I'm planning to use a 2x or 4x player (I've already reviewed the kernel and while I don't have time to resize of Player 0, I do have time for Player 1).

Due to the flicker routines, I have to use software driven collision detection as 2 colliding objects might never be drawn on the same video frame. As such, I'll need to double up a 2x player's bit pattern so that the bits 76543210 become 7766554433221100. For example, if 1 line of the sprite looks like this:
_X__X_X_

I need to make it look like this:
__XX____XX__XX__

I can do this using a loop and shifting bits, but thought somebody might know a way to do it better.
int DoubleBits(unsigned char 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 function I'd just change 1 line:
        result = (result << 4) + ((bits & mask) ? 15 : 0);
* This video shows 3 of them, though it's stretched widescreen for some reason:
3:15 Big Otto
5:17 Power Plant
8:01 Central Computer



It's missing the Robot Factory. This video shows the ColecoVision version of Frenzy:
1:18 Big Otto
2:00 Power Plant
3:18 Central Computer
4:01 Robot Factory


#2 GroovyBee OFFLINE  

GroovyBee

    7800 Developer

  • 5,781 posts
  • Busy bee!
  • Location:North, England

Posted Fri Sep 9, 2011 6:40 PM

Can you show the compiled code? Are you targeting THUMB or ARM? In either case, unrolling the loop and using assembly language will be your best option.

#3 SpiceWare OFFLINE  

SpiceWare

    Quadrunner

  • 5,990 posts
  • Medieval Mayhem
  • Location:Planet Houston

Posted Fri Sep 9, 2011 11:23 PM

I've decided a better/faster way will be to use a 16 byte table and double up each nybble using a table lookup. Fastest would use a 512 byte table, but that'll take a lot more space than I'd like.

#4 SpiceWare OFFLINE  

SpiceWare

    Quadrunner

  • 5,990 posts
  • Medieval Mayhem
  • Location:Planet Houston

Posted Sat Sep 10, 2011 8:43 PM

new 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];
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users