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 > grit files

#149445 - Cave Johnson - Sun Jan 20, 2008 3:12 am

How do i convert a .png image into a grit rule file? And before you ask, yes i have googled it, but i just get manicuring tips. Thanks.

#149457 - Cearn - Sun Jan 20, 2008 1:38 pm

png files aren't converted into grit files; they're converted into GBA/NDS graphics data using the options given in the grit files</pedant>. The contents of the grit files are just extra options for the conversion process and you'll have to make those yourself.

There are examples of how to use grit in the nds examples. In particular, look at examples/nds/Graphics/2D/16bit_color_bmp. In its makefile are several lines using the PNGFILES variable and the rule for grit is at the bottom. Note that when creating the OFILES variable, the $(PNGFILES:.png=.o) line must go before the CPP/C/S files lines, because the conversion must happen before compilation/assembling.

I've also been using a separate makefile for the graphics conversions lately. This way the conversion process won't interfere with the main makefile and it'll be easier to create your own specialized conversions. Details here.

#149468 - Cave Johnson - Sun Jan 20, 2008 3:31 pm

I tried to follow the exampls as best i could, but i got the error message:

linking grit.elf
c:/devkitpro/devkitarm/bin/../lib/gcc/arm-eabi/4.1.2/../../../../arm-eabi/lib/th
umb/ds_arm9_crt0.o: In function `CIDLoop':
ds_arm9_crt0.s:(.init+0x2ac): undefined reference to `initSystem'
ds_arm9_crt0.s:(.init+0x2b8): undefined reference to `main'
collect2: ld returned 1 exit status
make[1]: *** [/c/Taylor/grit/grit.elf] Error 1
make: *** [build] Error 2

Were did i go wrong? In my file i had the .png image, the main.cpp file, and the make file, am i missing some other necessary files? Thanks.

#149470 - gmiller - Sun Jan 20, 2008 4:18 pm

The error says that the main function and the initSystem functions can not be found. The project you are building appears to be one for the DS not a GBA, is that what you wanted?

Normally you would not link and elf (that being an executable, but not in the correct format for the DS or GBA). You probably wanted to create an object file with your image in it and then link it into your project.

With a little more information (from you) as to what you are trying to build (DS/GBA) and maybe a small section of your makefile might help us help you better.

#149471 - Cave Johnson - Sun Jan 20, 2008 4:26 pm

Sorry for being so vague. Im trying to make a very basic ds game with a background and a sprite that can be moved with the dpad. The makfile im using is the same one from the drunkencoders logo example that came with devkit pro. The images im trying to create grit files of are the background .png image and the sprite which is also a .png image. Hope this clears everthing up. Thanks.

#149472 - Cearn - Sun Jan 20, 2008 6:13 pm

A missing initSystem() means that your libnds is out of date. As of devkitARM r21, the NDS boot code calls a part of the latest libnds. This means that you can't build a NDS game without it and that older versions will not work because they don't have a function called initSystem(). If you're working with PALib, this couldbe why you're seeing the message: PALib still uses an older libnds version.

A missing main() means that you don't have a main() function anywhere in the project. Since this is the entry point of any C program, it's rather important that you have one. If you think you do have one, it's possible that the directory it's in isn't part of the directory list in the makefile. Check if the directory with the source files is in the SOURCES variable in the makefile.

Sometimes it also helps to clean the project; dependencies between files can go wonky if you move stuff around and cleaning it will get rid of these dependencies.

#149477 - Cave Johnson - Sun Jan 20, 2008 8:35 pm

Hmmmm, im pretty sure that i have the latest version of libnds, because i checked, and there are no updates for devkitpro.

The main() problem is also confusing me because i took the drunken coders logo main.cpp, and changed it slightly to fit my picture. Did i do something wrong during my time changing the code?

#include <nds.h>
#include <stdio.h>

#include "colors_slot1.h"

int getSize(uint8 *source, uint16 *dest, uint32 arg) {
return *(uint32*)source;
}

uint8 readByte(uint8 *source) {
return *source;
}
TDecompressionStream colors_slot1_decomp = {
getSize,
NULL,
readByte
};

int main(void) {
irqInit();
irqEnable(IRQ_VBLANK);

videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);

videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);

vramSetMainBanks( VRAM_A_MAIN_BG_0x06000000, VRAM_B_LCD,
VRAM_C_SUB_BG , VRAM_D_LCD);

SUB_BG0_CR = BG_MAP_BASE(31);

BG_PALETTE_SUB[255] = RGB15(31,31,31);

consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);

iprintf("\n\n\tWelcome To\n");
iprintf("\tProject Satan\n");
iprintf("\t(Yes Its a Futurama Reference)");

BG3_CR = BG_BMP16_256x256;

BG3_XDX = 1 << 8;
BG3_XDY = 0;
BG3_YDX = 0;
BG3_YDY = 1 << 8;

BG3_CX = 0;
BG3_CY = 0;

swiDecompressLZSSVram((void*)colors_slot1Bitmap, BG_GFX, 0, &colors_slot1_decomp);
while(1) swiWaitForVBlank();

return 0;
}

My simple project is turning out to be quite a doozey. Thanks.

EDIT: Upon trying out some other programs, i think my first and major problem is my environment. I know for a fact that i have the latest libnds, but i also have palib, could the problem be that it is trying to run everything through palib and not libnds, if so how do i fix this? Now for the main() problem. Here is a snippet of some code that i wrote to create the troublesome background:

#include <nds.h>
#include "colors_slot1.h"

init main() {
iriqInit();
iriqSet (IRQ_VBLANK, 0);

lcdMainOnBottom();
initVideo();
initBackgrounds();

displaycolors_slot1();

return 0;
}

Isn't this what is meant by main() function? Why is it not finding this?Thanks. (and yes i know i wrote the code before getting the grip file of the image, it is just an example of a similar code that is giving me the same error message)

#149487 - Cave Johnson - Sun Jan 20, 2008 11:47 pm

Im getting closer, i fixed the initsystem problem, but the main() error still remains. So is the problem in the makefile, or embedded in the giant mass of code from my last post?