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 > 2D Mapping

#172457 - mog123 - Mon Feb 08, 2010 12:27 am

Hey, I've tried 1d mapping - worked great but was a pain in the ass to edit. So now I'm trying to do 2d mapping. I've got a BMP file I converted in grit. 8bpp, 32x32 sprites, 256x448. When I try to display it with this code:

Code:
// (1) Places the tiles
    //   into LOW obj memory (cbb == 4)
    memcpy(&tile_mem[4][0], Player256Tiles, 32*32);
    memcpy(pal_obj_mem, Player256Pal, Player256PalLen);


    // (2) Initialize all sprites
    oam_init(obj_buffer, 128);
    REG_DISPCNT= DCNT_MODE0 | DCNT_BG0 | DCNT_OBJ | DCNT_OBJ_2D;


    int x= 104, y= 64;
    u32 tid= 0, pb= 0;      // (3) tile id, pal-bank
    OBJ_ATTR *nin11= &obj_buffer[0];

    obj_set_attr(nin11,
        ATTR0_SQUARE | ATTR0_8BPP ,               // square sprite 8bpp
        ATTR1_SIZE_32,                       // 32x32p
        ATTR2_PALBANK(pb) | tid);            // palbank 0, tile 0

    // (4) position sprite (redundant here; the _real_ position
    // is set further down
    obj_set_pos(nin11, x, y);
oam_copy(oam_mem, obj_buffer, 1);


I only display a 8x32 (HxW) sprite. What am I doing wrong, or better yet - why is the thing I'm doing wrong, wrong.

#172461 - Cearn - Mon Feb 08, 2010 10:55 am

You're probably not copying enough tiles. With the line `memcpy(&tile_mem[4][0], Player256Tiles, 32*32);', you're copying in the first 16 tiles. In 1D-mode this would make up a 32x32@8 object, but in 2D-mode, the whole VRAM forms a single bitmap and the tiles you've copied in only make up the first tile-row of that bitmap. See Fig 8b and 8c from tonc:reg-obj. Basically, you need to copy in the rest of the tiles as well.

Also, on that VRAM bitmap the tile index of the second row is 32. This means that the bitmap is effectively 256x256 (32x32 tiles) in size for 4bpp objects, but 128x256 (16x32 tiles) for 8bpp. You probably need to change the size of the bitmap too.

#172496 - mog123 - Tue Feb 09, 2010 8:14 pm

I just found out the possibilities that usenti offers. I can easily make an image that will be ready for 1d mapping.
Great stuff Cearn!