Noob question, loading sprites

Post Reply
Derrik
Posts: 63
Joined: Wed Aug 14, 2013 8:28 pm

Noob question, loading sprites

Post by Derrik » Mon Apr 21, 2014 5:18 pm

I am trying to load a sprite, but just I can't get it to work.

My code is based on http://www.dev-scene.com/NDS/Tutorials_Day_5.

Here is the simplified version, nothing shows up.

Code: Select all

	consoleDemoInit();
	
	videoSetMode(MODE_0_2D);
	vramSetPrimaryBanks(VRAM_A_MAIN_SPRITE, VRAM_B_LCD, VRAM_C_LCD, VRAM_D_LCD);
		
	oamInit(&oamMain, SpriteMapping_Bmp_1D_128, false);
	u16 *gfx = oamAllocateGfx(&oamMain, SpriteSize_32x32, SpriteColorFormat_256Color);
	
	dmaCopy(tile_data, gfx, sizeof(tile_data));
	dmaCopy(palette, SPRITE_PALETTE, sizeof(palette));
	
	while(1) {
		scanKeys();
		
		oamSet(&oamMain, 0, 64, 32, 0, 0, SpriteSize_32x32, SpriteColorFormat_256Color, gfx, 0, false, false, false, false, false);
		oamUpdate(&oamMain);
		
		swiWaitForVBlank();
	}

Derrik
Posts: 63
Joined: Wed Aug 14, 2013 8:28 pm

Re: Noob question, loading sprites

Post by Derrik » Mon Apr 21, 2014 6:20 pm

Removing the consoleDemoInit doesn't help either.

Derrik
Posts: 63
Joined: Wed Aug 14, 2013 8:28 pm

Re: Noob question, loading sprites

Post by Derrik » Mon Apr 21, 2014 7:17 pm

Replacing the order to be this:

oamSet
swiWaitForVBlank
oamUpdate

Makes something appear on the screen. I think the rest is dependent on my specific project so I'll post more relevant code soon.

Derrik
Posts: 63
Joined: Wed Aug 14, 2013 8:28 pm

Re: Noob question, loading sprites

Post by Derrik » Tue Apr 22, 2014 7:55 pm

OK; I found that the problem is with the palette.

If I fill the palette with random data, then the image shows up (but obviously in the wrong colours):

Code: Select all

SPRITE_PALETTE[16 + 1] = RGB15(0, 0, 31);
SPRITE_PALETTE[16 + 2] = RGB15(31, 0, 0);
SPRITE_PALETTE[16 + 3] = RGB15(0, 31, 31);
SPRITE_PALETTE[16 + 4] = RGB15(0, 31, 0);
I have checked that the palette is in fact the correct data by dumping it with this:

Code: Select all

FILE *o = fopen("palette.bin", "wb");
fwrite(palette, sizeof(palette), 1, o);
fclose(o);
But when I try and copy the data:

Code: Select all

dmaCopy(palette, SPRITE_PALETTE, sizeof(palette));
It does not work (the image is completely black). And when I dump this data:

Code: Select all

FILE *o = fopen("palette.bin", "wb");
fwrite(SPRITE_PALETTE, sizeof(palette), 1, o);
fclose(o);
I get all 0s.

Can you only DMA copy to palette on ARM 7 or something? What's going on?

Derrik
Posts: 63
Joined: Wed Aug 14, 2013 8:28 pm

Re: Noob question, loading sprites

Post by Derrik » Tue Apr 22, 2014 8:00 pm

Nevermind, got it!

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests