Advertisement Jump to content
Sign in to follow this  

Need Help with Bit operations and storage.

This topic is 4916 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
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;

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!