Page 1 of 1

loading 512x512 background

Posted: Thu Jul 02, 2015 4:58 pm
by DayTripperID
I have successfully loaded 256x512 backgrounds but when I try to load a 512x512 it doesn't appear on screen properly. Here is my code in a nutshell:

Code: Select all

videoSetMode(MODE_0_2D);

vramSetBankA(VRAM_A_MAIN_BG);

int bg = bgInit(a_priority, BgType_Text4bpp, BgSize_T_512x512, 0, 1);
	
dmaCopy(bg_rockfieldTiles, bgGetGfxPtr(bg),  bg_rockfieldTilesLen);
   
dmaCopy(bg_rockfieldPal,   BG_PALETTE, 	    bg_rockfieldPalLen);

dmaCopy(bg_rockfieldMap,   bgGetMapPtr(bg),    bg_rockfieldMapLen);

Grit rule file reads as follows:

# Set the warning/log level to 3
-W3

# Tell grit to include a palette (the first index in it will be transparent)
-p

# Tile the image
-gt

# Set the bit depth to 4 (16 colors)
-gB4

# Include map data
-m

The tiles are about 13k in size and the map is about 8k.

The BG should look like this:http://postimg.org/image/khi1h2s4j/

But in game it looks like this:http://postimg.org/image/xkdo0cicj/

Can somebody please help me see what I am overlooking? Thank You.

Re: loading 512x512 background

Posted: Sat Jul 04, 2015 12:04 am
by DayTripperID
Ok now I see from the examples that you have to copy the map in 1 line at a time when the bg gfx are wider than 256 pixels.

Re: loading 512x512 background

Posted: Sat Jul 04, 2015 2:16 pm
by DayTripperID
OK I still can't get the bg to load properly. It looks like it's loading the image into a 256X512 space row by row, so it looks shredded into strips. My updated code looks like this:

Code: Select all

videoSetMode(MODE_0_2D);

vramSetBankA(VRAM_A_MAIN_BG);

int bg = bgInit(a_priority, BgType_Text8bpp, BgSize_T_512x512, 0, 1);
   
dmaCopy(bg_rockfieldTiles, bgGetGfxPtr(bg),  bg_rockfieldTilesLen);
   
dmaCopy(bg_rockfieldPal,   BG_PALETTE,        bg_rockfieldPalLen);

u16* map = (u16*)bgGetMapPtr(bg);

for(int y = 0; y < 32; y++){
		
     dmaCopy(bg_rockfieldMap + y * 64, map + y * 32, 32 * 2);
		
     dmaCopy(bg_rockfieldMap + y * 64 + 32, map + (32 * 32) + y * 32, 32 * 2);
}
 
map += 32 * 32 * 2;
 
for(int y = 0; y < 32; y++){
		
    dmaCopy(bg_rockfieldMap + (y + 32) * 64, map + y * 32, 32 * 2);
		
    dmaCopy(bg_rockfieldMap + (y + 32) * 64 + 32, map + (32 * 32) + y * 32, 32 * 2);
}

That is pretty much lifted straight from the examples, I just changed the names of some variables. When I run the example program it works fine on both hardware and emulator. But when I run mine it looks like the screen shot in the original post. Can anyone help me out?

Re: loading 512x512 background

Posted: Sat Jul 04, 2015 5:16 pm
by DayTripperID
OK I got it to load properly. The memory offsets were a little off when reading from the gfx pointer in dmaCopy(). I think maybe the grit in the DevKitPro toolchain packs the tiles differently than the one used by the guy who generated the example tiles using Pern Tools. So my code looks like this now:

Code: Select all

for(int y = 0; y < 32; y++){
      
     dmaCopy(bg_rockfieldMap + y * 128, map + y * 32, 32 * 2);
      
     dmaCopy(bg_rockfieldMap + y * 128 + 64, map + (32 * 32) + y * 32, 32 * 2);
}
 
map += 32 * 32 * 2;
 
for(int y = 0; y < 32; y++){
      
    dmaCopy(bg_rockfieldMap + (y + 32) * 128, map + y * 32, 32 * 2);
      
    dmaCopy(bg_rockfieldMap + (y + 32) * 128 + 64, map + (32 * 32) + y * 32, 32 * 2);
}
The y offsets needed to be doubled for the bg_rockfieldMap pointer for it to read from the correct offsets. I didn't touch the u16 * map offsets, which tells me that I'm either using different grit options from the example or a different version of grit that packs the map data in a different order.

Re: loading 512x512 background

Posted: Wed Jul 08, 2015 7:43 am
by tueidj
Sounds more like bg_rockfieldMap is a u8 array when the code expects it to be a u16 array, resulting in incorrect pointer math.