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 > Sprite setup causing screen glitch?

#173746 - Pete_Lockwood - Wed Apr 28, 2010 12:07 am

I inherited the code below and it seems to be causing a small blob to display in the top left corner of the lower screen. It appears that this blob is actually an enlarged and distorted copy of the data in the top left 8x4 pixel corner of one of the 16x16 pixel sprites.

Presumably something trampling over memory? Or something not being initialized that should be? Anyone able to spot what?

Code:

powerOn(POWER_ALL_2D);

videoSetMode(MODE_5_2D | DISPLAY_SPR_ACTIVE |  //turn on sprites
             DISPLAY_BG3_ACTIVE |          //turn on background 0
             DISPLAY_SPR_1D_LAYOUT
             );

// Use the Sub Screen for text
videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE);

vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000,
                 VRAM_B_MAIN_SPRITE_0x06400000,
                 VRAM_C_SUB_BG_0x06200000,
                 VRAM_D_LCD         //not using D
                 );
lcdSwap();

for(int i = 0; i < 64; i++) {
   sprites[i].attribute[0] = ATTR0_DISABLED | ATTR0_COLOR_256;
   sprites[i].attribute[1] = ATTR1_SIZE_16;
   sprites[i].attribute[2] = 0;
   sprites[i].filler = 0;
}

for (int x=0; x<6;x++) {
   for(uint16 i=0; i<64; i++){
        SPRITE_GFX[128*x*2 + i]          = piecesTiles[8*96 + i+x*64];  // <-- remove this line and the blob goes away
        SPRITE_GFX[128*x*2 + 64 + i]     = piecesTiles[12*96+i+x*64];
        SPRITE_GFX[128*(x*2+1) + i]      = piecesTiles[i+x*64];
        SPRITE_GFX[128*(x*2+1) + 64 + i] = piecesTiles[4*96+i+x*64];
    }
}

for(uint16 i=0; i<256; i++) SPRITE_PALETTE[i] = piecesPal[i];

_________________
It's not an illusion, it just looks like one.

#173747 - Pete_Lockwood - Wed Apr 28, 2010 3:37 am

Aha. Looks like this solves it:

Code:
oamInit(&oamMain, SpriteMapping_1D_32 , false);

_________________
It's not an illusion, it just looks like one.

#173748 - ritz - Wed Apr 28, 2010 4:07 am

Glad I could help!
;)