View unanswered posts | View active topics It is currently Thu Jun 30, 2016 8:20 pm



Reply to topic  [ 5 posts ] 
 loading 512x512 background 
Author Message

Joined: Tue Aug 07, 2012 8:57 pm
Posts: 22
Reply with quote
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:
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.


Thu Jul 02, 2015 4:58 pm
Profile

Joined: Tue Aug 07, 2012 8:57 pm
Posts: 22
Reply with quote
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.


Sat Jul 04, 2015 12:04 am
Profile

Joined: Tue Aug 07, 2012 8:57 pm
Posts: 22
Reply with quote
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:
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?


Sat Jul 04, 2015 2:16 pm
Profile

Joined: Tue Aug 07, 2012 8:57 pm
Posts: 22
Reply with quote
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:
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.


Sat Jul 04, 2015 5:16 pm
Profile

Joined: Thu Dec 10, 2009 9:26 am
Posts: 40
Reply with quote
Sounds more like bg_rockfieldMap is a u8 array when the code expects it to be a u16 array, resulting in incorrect pointer math.


Wed Jul 08, 2015 7:43 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
  Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.
Get devkitPro at SourceForge.net. Fast, secure and Free Open Source software downloads