gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > where i wrong??

#5684 - Link - Mon May 05, 2003 11:15 pm

i'm not success to see the sprite, this is the code:

Code:
#include "gba.h"
#include "screenmode.h"
#include "sprite.h"
#include "sprite1.h" //header file ottenuto da pcx2gfx

int main(void)
{

        SetMode(OBJ_MAP_2D | MODE_3 | OBJ_ENABLE);
        u8 sprite1Atributes = 0;
         
        s16 x = 10;
        s16 y = 10;
        u16 char_number = 0;

   //for(s16 loop = 0; loop < 256; loop++)
      //OBJPaletteMem[loop] = sprite1Palette[loop];

        sprites[sprite1Atributes].attribute0 = COLOR_256 | SQUARE | y;
        sprites[sprite1Atributes].attribute1 = SIZE_64 | x;
        sprites[sprite1Atributes].attribute2 = char_number;

        int x_loop = 0, y_loop = 0, index = 0;

        for(y_loop = 0; y_loop < 8; y_loop++)
           {
           for(x_loop = 0; x_loop < 256; x_loop++)
               {
                   CharMem[x_loop + y_loop * 512] = sprite1Data[index];
                index++;
               } //end for x_loop
           } //end for y_loop

void MoveSprite( OAMEntry* sp, int x, int y)
{

        sprites->attribute1 = sprites->attribute1 & 0xFE00; //azzera il vecchio valore di x
        sprites->attribute1 = sprites->attribute1 | x;

        sprites->attribute0 = sprites->attribute0 & 0xFF00; //azzera la vecchia y
        sprites->attribute0 = sprites->attribute0 | y;
}

int loop;

for(loop = 0; loop < 256; loop++)
OBJPaletteMem[loop] = sprite1Palette[loop];

void InitializeSprites(void)
{
         int loop;
         for(loop = 0; loop < 128; loop++)
        {
                sprites[loop].attribute0 = 160; //y to > 159
                sprites[loop].attribute1 = 240; //x to > 239
        }
}


}



here some declaration in gba.h:

....................
u16* OAMData =(u16*)0x6010000;

#define CharMem ((u16*)0x6010000)
#define OBJPaletteMem ((u16*)0x5000200)



#define REG_INTERUPT (*(volatile u32*)0x3007FFC)
#define REG_DISPCNT (*(volatile u32*)0x4000000)

..........................

[/code]

#5693 - Psyk - Tue May 06, 2003 8:01 am

Well it seems that you're not actually copying the data from the sprites structure into the actual OAM memory of the GBA. Also you seem to have functions in the middle of main.

#5697 - Link - Tue May 06, 2003 11:27 am

sorry, bad code not my own but just a distraction.
However this is new code can u let a look:
Code:
#include "gba.h"
#include "screenmode.h"
#include "sprite.h"
#include "sprite1.h" //header file ottenuto da pcx2gfx

void MoveSprite( OAMEntry* sp, int x, int y);
void InitializeSprites(void);
void WaitForVsync(void);
void CopyOAM(void);

int main(void)
{

        SetMode(OBJ_MAP_2D | MODE_3 | OBJ_ENABLE);
        u8 sprite1Atributes = 0;
         
        s16 x = 10;
        s16 y = 10;
        u16 char_number = 0;
        int loop, index;
       
   for(loop = 0; loop < 256; loop++)
      OBJPaletteMem[loop] = sprite1Palette[loop];
       
        InitializeSprites();

        sprites[sprite1Atributes].attribute0 = COLOR_256 | SQUARE | y;
        sprites[sprite1Atributes].attribute1 = SIZE_64 | x;
        sprites[sprite1Atributes].attribute2 = char_number;

   for(index = 0; index < 256*8; index++)
   {
      OAMData[index] = sprite1Data[index]; 
         
   }//end index loop


        /*int x_loop = 0, y_loop = 0, index = 0;

        for(y_loop = 0; y_loop < 8; y_loop++)
           {
           for(x_loop = 0; x_loop < 256; x_loop++)
               {
                   CharMem[x_loop + y_loop * 512] = sprite1Data[index];
                index++;
               } //end for x_loop
           } //end for y_loop*/

        while(1)
   {
      MoveSprite(&sprites[0],x,y);

      WaitForVsync();

      CopyOAM();

   }
}




void MoveSprite( OAMEntry* sp, int x, int y)
{

        sprites->attribute1 = sprites->attribute1 & 0xFE00; //azzera il

vecchio valore di x
        sprites->attribute1 = sprites->attribute1 | x;

        sprites->attribute0 = sprites->attribute0 & 0xFF00; //azzera la

vecchia y
        sprites->attribute0 = sprites->attribute0 | y;
}

void InitializeSprites(void)
{
      int loop;
         for(loop = 0; loop < 128; loop++)
        {
                sprites[loop].attribute0 = 160; //y to > 159
                sprites[loop].attribute1 = 240; //x to > 239
        }
}

void WaitForVsync(void)
{
    while(REG_VCOUNT == 160);
    while(REG_VCOUNT != 160);
}

void CopyOAM(void)
{
   u16 loop;
   u16* temp;
   temp = (u16*)sprites;
   for(loop = 0; loop < 128*4; loop++)
   {
      OAM[loop] = temp[loop];
   }
}

#5710 - Link - Tue May 06, 2003 3:59 pm

i've seen more and more times but i'm success to find the error!

i'm success to make the .bin file but i can't see the sprite on the screen!

#5714 - Psyk - Tue May 06, 2003 6:46 pm

i think you can only use the last half of the OAM when using bitmap screenmodes(modes 3, 4 and 5) so it might work if you change
Code:
u8 sprite1Atributes = 0;
to
Code:
u8 sprite1Atributes = 64;

#5715 - niltsair - Tue May 06, 2003 6:51 pm

Wrong.

You can can only use the last 512 Sprite's tiles, but you can use the full 128 OAM. So the problem is elsewhere.

#5716 - Link - Tue May 06, 2003 8:10 pm

niltsair wrote:
Wrong.

You can can only use the last 512 Sprite's tiles, but you can use the full 128 OAM. So the problem is elsewhere.


infact my question is Where i wrong?

however i change:
u8 sprite1Atributes = 0;
to
u8 sprite1Atributes = 64;
but nothing!
What need to change also?

#5717 - niltsair - Tue May 06, 2003 8:17 pm

I was replying to Psyk anwser.

I don't really have time to look at your code line per line, i'm at work.

I also think you should look at tutorial more, and figure out step by step what might be the problem, as we all did, instead of throwing all of your code at the slightess pebble in the road.

In your WaitFroVSync, you can remove the
'while(REG_VCOUNT == 160); '

and keep the rest. I don't think it'll fix your problem, but don't see the point of that line.

#5718 - Psyk - Tue May 06, 2003 9:01 pm

Quote:
Wrong.

You can can only use the last 512 Sprite's tiles, but you can use the full 128 OAM. So the problem is elsewhere.

I was close but now i think of it that makes more sense than what i said..

Well anyway i suggest you use 1D object mapping as it is much easier to work with. There is an explanation on www.thepernproject.com