Jump to content
  • Advertisement
Sign in to follow this  
justinrwalsh

Need Help with Bit operations and storage.

This topic is 4847 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So i'm working on this game for the GBA, and everything is done by minipulating bits. So i have this regesters defined for sprite graphics memory...
#define SpriteData ((unsigned short*)0x6010000)
#define SpriteMem ((unsigned short*)0x7000000)
Now i have this data that i copy to that address...
//This is for the SpriteData register
unsigned short imageData[1536];

//This is a single entry into SpriteMem
typedef struct tagSprite  {
     unsigned short attribute0;
     unsigned short attribute1;
     unsigned short attribute2;
     unsigned short attribute3;
}Sprite, *pSprite;
So here is where i am having the problem... I need to offset the registers SpriteMem, and SpriteData by the amount i just copied into it, so next time i copy i can start off at the next available block of memory... So would my code to do that look something like this..?
SpriteData += 1536 * sizeof(unsigned short);
SpriteMem += sizeof(Sprite);
I will always know the size of the unsigned short array for the data And the tagSprite struct never changes, so im pretty sure the code i have above will not work, i probably need to bit shift or something to get it right. Any mastermind that knows the answer feel free to school me, please. Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
If you just made SpriteData and SpriteMem pointers, wouldn't that work? Another thing is that pointer arithmetic already includes the size of the type.
    unsigned short* SpriteData = (unsigned short*)0x6010000;
Sprite* SpriteMem = (Sprite*)0x7000000;

memcpy( SpriteData, imageData, 1536*sizeof(unsigned short) );
*SpriteMem = sprite;

SpriteData += 1536;
++SpriteMem;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!