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.

Beginners > Loading 256x512 map data.

#34464 - Celeryface - Wed Jan 19, 2005 11:08 pm

Hi there,

Awhile back I made a post about getting help on loading 512x256 backgrounds. Does anyone have the formula to load 256x512 backgrounds, and also 512x512 backgrounds?

Thanks in advance. :)

#34472 - tepples - Thu Jan 20, 2005 1:54 am

256x512 pixel text backgrounds are easy; they're just two stacked backgrounds.

512x512 pixel text backgrounds are like 512x256 pixel text backgrounds, except stacked two on top of one another.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#34505 - Celeryface - Thu Jan 20, 2005 5:32 pm

Cool. Thanks for the info. :)

#34518 - Celeryface - Thu Jan 20, 2005 9:00 pm

Hi again,

I seem to be having a few problems with some of my map data loading. Is this the correct way to load the 256x512 background?

Code:

    unsigned short loopY = 0;
    unsigned short loopX = 0;

    // top 32 tiles to first screen block.
    for( loopY = 0; loopY < 32; loopY++ )
    {

        for( loopX = 0; loopX < 32; loopX++ )
        {

            dest[loopY*32 + loopX] = source[loopY*32 + loopX];

        } // end for loopX

    } // end for loopY


    // bottom 32 tiles to the second screen block.
    for( loopY = 32; loopY < 64; loopY++ )
    {

        for( loopX = 0; loopX < 32; loopX++ )
        {

            dest[loopY*32 + loopX] = source[loopY*32 + loopX];

        } // end for loopX

    } // end for loopY

#34521 - Mucca - Thu Jan 20, 2005 10:00 pm

Your code should work loading a 256x512 source map to a 256x512 destination map, although there's no need to split it into two 'for' loops, just have one looping to 64. The code will not work for a source map wider than 256.

If I was loading a complete 256x512 map I'd probably just do this:
Code:

DmaCopy(3, mapSrc, mapDst, 0x1000, 32);


or if the source map is wider than 256:
Code:

u16 * mapSrc = whatever;
u16 * mapDst = whatever;
int x = whatever the x offset is in blocks, (pixels/8)
int y = whatever the y offset is in blocks, (pixels/8)
//Copy Each line individually
for(int i=0; i<64; i++)
{
    DmaCopy(3, mapSrc + (y*tile_width_of_source) + x, mapDst + (i*32), 64, 32);
    y++;
}


Last edited by Mucca on Fri Jan 21, 2005 3:54 pm; edited 1 time in total

#34524 - Celeryface - Thu Jan 20, 2005 10:45 pm

Mucca wrote:
Your code should work loading a 256x512 source map to a 256x512 destination map, although there's no need to split it into two 'for' loops, just have one looping to 64. The code will not work for a source map wider than 256.

If I was loading a complete 256x512 map I'd probably just do this:
Code:

DmaCopy(3, mapSrc, mapDst, 0x1000, 32);


or if the source map is wider than 256:
Code:

u16 * mapSrc = whatever;
u16 * mapDst = whatever;
int x = whatever the x offset is in blocks, (pixels/8)
int y = whatever the y offset is in blocks, (pixels/8)
//Copy Each line individually
for(int i=0; i<64; i++)
{
    DmaCopy(3, mapSrc + (y*tile_width_of_source) + x, mapDst + (y*32), 64, 32);
    y++;
}


Okay. Thanks :)