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 > .nds vs libfat

#148309 - iainprice - Fri Jan 04, 2008 3:35 pm

I have a little program I am making.... it has md2 and bmp and pcx files.

I currrently use libfat and everything is happy. I wanted to link these files in so that it is easier to distribute but when I convert them to .bin and link into my .nds I run out of memory :(

Is there a crafty way to link files into an .nds but without running out of memory?

Cheers.

#148311 - Bloodypriest - Fri Jan 04, 2008 3:50 pm

Use EFS. It allows you to put data files in the NitroFS portion of your .nds . Very easy to use.

Here's a wrapper function around EFS for file loading:
Code:
int LoadFile(char *fn,void **pbuf)
{
   EFS_FILE* file;

   file = EFS_fopen(fn);
   if (file != 0) {
      int psize = EFS_GetFileSize(file);
      *pbuf = (void*)malloc(psize);

      EFS_fread(*pbuf, psize, 1, file);
      EFS_fclose(file);

      return psize;
   }

   *pbuf = 0;
   return -1;

Finally, you can also pre-convert your bmp and pcx files so you don't have to decode them every time you load them on the DS. Saves time.

#148353 - iainprice - Fri Jan 04, 2008 10:07 pm

I have converted my program to use efs... looking good, but yes my bmp screens just take ages.... how can I convert them to open and display faster on efs?

Thanks.

#148354 - Bloodypriest - Fri Jan 04, 2008 10:44 pm

You could use gfx2gba or grit to convert them to tiles. The latter has less features but is more user-friendly.

It would still be raw uncompressed bitmap data but it would save you the bmp decoding step. Also you would benefit from the tile rendering capabilities of the hardware which is way faster than rendering pixel by pixel.

BTW, what color-depth are your graphics? If I'm right, your bmps are probably saved in true-color format (RGB24). Converting them to paletted format (either 16 or 256 color) would make them a lot smaller and faster to load (GIMP, Paintshop PRO and Photoshop might help here).

#148356 - iainprice - Fri Jan 04, 2008 11:07 pm

They are 256 but if I convert them surely I then compile them in rather than loading using efs?

#148360 - wintermute - Fri Jan 04, 2008 11:33 pm

No, you don't have to. You can use grit to convert to a tiled format and outpit binary then put that in your file system.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#148362 - iainprice - Fri Jan 04, 2008 11:36 pm

Would it be best to use a command line in a batch file to convert using grit? I am looking at the example file for grit but cannot get it to work in my make file :(

Are there any nice examples of pcx/bmp convert and load?

#148363 - Bloodypriest - Fri Jan 04, 2008 11:47 pm

Never tried to use grit in a makefile. I did all my conversions on the command-line by referring to the examples in the TONC tutorial.

#148397 - iainprice - Sat Jan 05, 2008 11:04 am

I have converted files using grit.exe and no parameters.

I have put them in the build directory for now, I'll worry about efs later.

I have the following code:

[code]
#include "flames.h"

videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE);

SUB_BLEND_CR = BLEND_FADE_BLACK | BLEND_SRC_BG3 | BLEND_DST_BACKDROP;
SUB_BG3_CR = BG_BMP8_256x256;
SUB_BG3_XDX = 1 << 8;
SUB_BG3_XDY = 0;
SUB_BG3_YDX = 0;
SUB_BG3_YDY = 1 << 8;
SUB_BG3_CX = 0;
SUB_BG3_CY = 0 << 8;

dmaCopy(flamesTiles, BG_GFX_SUB, 256*192);
dmaCopy(flamesPal, BG_PALETTE_SUB, 256*2);
[/code]

but get rubbish on the screen?

#148434 - Bloodypriest - Sat Jan 05, 2008 6:11 pm

SUB_BG3_CR = BG_BMP8_256x256; would be your problem. This puts your exrot background in bitmap mode.

You need to either use a standard rotation background or setup your exrot bg in tiled mode, the latter option allowing you to use 16-bit map entries.