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.

DS development > Artifacts on Upper Left Corners of Sprites (SOLVED)

#149828 - rook02 - Fri Jan 25, 2008 8:00 pm

Hello. I haven't posted in a while, becaues I've been busy fooling around with the OAM, trying things out for myself, seeing what I can do with it, etc. However, it seems that I've run into more problems.

I'm trying to make a function that takes a png file and puts it straight into the OAM as a sprite. I've been doing okay, until artifacts started appearing on the upper left corners of some of the sprites, and I can't seem to figure out what's causing them. I'm not sure... I might have screwed something up...

I don't think it's the PNG reading process because I can draw the PNG files correctly using framebuffer. So it might have something to do with the way I copied the the sprites into the memory...


This is my VRAM Bank setup:
Code:
      vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000,
                   VRAM_B_MAIN_BG_0x06020000,
                   VRAM_C_SUB_BG_0x06200000,
                   VRAM_D_LCD);

      vramSetBankE(VRAM_E_MAIN_SPRITE);

      videoSetMode(MODE_5_2D |
                DISPLAY_BG2_ACTIVE |
                DISPLAY_BG3_ACTIVE |
                DISPLAY_SPR_ACTIVE |
                DISPLAY_SPR_1D      |
                DISPLAY_SPR_1D_SIZE_64
                );


This is the bottom of my method... it chucks pixels and stuff into the OAM...

Code:
 
static int CONTENT_SPRITE_ADDRESS = 0;
   ...
   ...
// throw things into OAM
   dmaCopy ( CONTENT_GLOBAL_PALETTE, SPRITE_PALETTE, 256 * sizeof ( unsigned short ) );
   dmaCopy ( container.pixels, &SPRITE_GFX[ CONTENT_SPRITE_ADDRESS * 32 ], container.pixel_count * sizeof ( unsigned char ) );
   container.oam_address = CONTENT_SPRITE_ADDRESS;
   // increment for next use
   CONTENT_SPRITE_ADDRESS += container.pixel_count >> 6;


This has kept tracking tile addresses easy (1 index for each 8x8 tile), as far as I've tested... but like I said... I think I screwed up something recently, and I'm not sure what it is. It returns a Container struct that has info on the image as well as its tile address in the OAM (container->oam_address)

Here's the other half...

Code:

static int GRAPHICS_SPRITE_INDEX = 0;
void DrawSprite(Container* sprite, SpriteEntry * sprites )
{   
   // Attribute 0
    sprites[GRAPHICS_SPRITE_INDEX].posY = 0;
    sprites[GRAPHICS_SPRITE_INDEX].isRotoscale = false;
    sprites[GRAPHICS_SPRITE_INDEX].rsDouble = false;
    sprites[GRAPHICS_SPRITE_INDEX].objMode = OBJMODE_NORMAL;
    sprites[GRAPHICS_SPRITE_INDEX].isMosaic = false;
    sprites[GRAPHICS_SPRITE_INDEX].colMode = OBJCOLOR_256;
   // determine if tall, wide or square
   if ( sprite->width > sprite->height )
   {
   ...
   ...
   else
   {
      sprites[GRAPHICS_SPRITE_INDEX].objShape = OBJSHAPE_SQUARE;
   }


   //Attribute 1
    sprites[GRAPHICS_SPRITE_INDEX].posX = 0;
    sprites[GRAPHICS_SPRITE_INDEX].rsMatrixIdx = ATTR1_ROTDATA(0);
   // instead of a super complicated if-else chain, I'lll just use the number of pixels to figure out the size
   if ( sprite->pixel_count <= 128 )
   {
   ...
   ...
   }
   else
   {
      sprites[GRAPHICS_SPRITE_INDEX].objSize = OBJSIZE_64;
   }
   
   // Attribute 2
    sprites[GRAPHICS_SPRITE_INDEX].tileIdx = (u16) sprite->oam_address;
    sprites[GRAPHICS_SPRITE_INDEX].objPriority = OBJPRIORITY_0;
    //sprites[GRAPHICS_SPRITE_INDEX].objPal = 0;
   
   GRAPHICS_SPRITE_INDEX ++;
}


Hmm... Can anyone help me figure this out? Thanks...

EDIT

Fixed by using swiCopy instead of dmaCopy...

>.<

I get the errors with the really random kind of solutions...