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 > grit corrupting my image?

#166859 - vuurrobin - Sat Feb 21, 2009 12:51 am

hello

I was trying out WinterMute's Elevator Guide to Grit on the devkitpro's forum, but some part of my image somehow gets corrupted.

I posted the question there, but I'm reposting it here because there are more active people here.

here's the original message:

vuurrobin wrote:
hello

I'm trying to get this to work, but I'm having some troubles.

first I updated the code so it worked with the current libnds, and this was the result:

Code:

#include <nds.h>

#include "beerguy.h"

int main()
{
    powerOn(POWER_ALL_2D);

    // enable the main screen with background 0 active
    videoSetMode(MODE_0_2D | DISPLAY_BG0_ACTIVE);

    // map bank A for use with the background
    vramSetBankA(VRAM_A_MAIN_BG_0x06000000);

    // enable background 0 in 256 color mode with a 256x256 map
    // BG_TILE_BASE changes the offset where tile data is stored
    // BG_MAP_BASE gives the offset to the map data
    //BGCTRL[0]
    REG_BG0CNT = BG_TILE_BASE(0) | BG_MAP_BASE(4) | BG_COLOR_256 | BG_32x32; //| TEXTBG_SIZE_256x256;



    // use dma to copy the tile, map and palette data to VRAM
    // CHAR_BASE_BLOCK gives us the actual address of the tile data
    // SCREEN_BASE_BLOCK does the same thing for maps
    // these should match the BG_TILE_BASE and BG_MAP base numbers above
    dmaCopy(beerguyPal, BG_PALETTE, beerguyPalLen);
    dmaCopy(beerguyTiles, (void *)CHAR_BASE_BLOCK(0), beerguyTilesLen);
    dmaCopy(beerguyMap, (void *)SCREEN_BASE_BLOCK(4), beerguyMapLen);

    return 0;
}


next I took a picture which I had from another project, added the grit rule file (without any modifications), and modified the makefile I had so it would work with bmp files (only the png part was in the makefile). I compiled the project without any problems. but when I tried running the program on no$gba and on hardware, a small part of the image got corrupted.

here is the original image:
[Images not permitted - Click here to view it]

and here is the result (created with no$gba screenshot option):
[Images not permitted - Click here to view it]

seeing as more than half of the image shows up normal, I doubt the problem is in the code. I think it has something to do with grit, but I have no idea what. I already try'd disabling tile reduction, but the problem is still there (the color changed from yelow to blue tho).

can someone help me?

also, the link to the project doesn't work anymore.

#166865 - Cearn - Sat Feb 21, 2009 10:47 am

vuurrobin wrote:
Code:

    REG_BG0CNT = BG_TILE_BASE(0) | BG_MAP_BASE(4) | BG_COLOR_256 | BG_32x32;
    ...
    dmaCopy(beerguyTiles, (void *)CHAR_BASE_BLOCK(0), beerguyTilesLen);
    dmaCopy(beerguyMap, (void *)SCREEN_BASE_BLOCK(4), beerguyMapLen);

    return 0;
}

Charblock 0 and Screenblock 4 overlap. You're probably overwriting the tiles with the map. Try using screenblock 31.