cannot set video memory properly

Post Reply
marco6
Posts: 2
Joined: Sun Jan 15, 2012 11:38 am

cannot set video memory properly

Post by marco6 » Sun Jan 15, 2012 12:32 pm

Hi all! I'm Marco and I'm quite new to nds programming, so please be patient :P

In fact I run in a problem I can't solve! :roll:
I was trying out the paletted pixel format, but I can't get it working:

Code: Select all

#include <nds.h>

int main(){
		videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);
		vramSetBankA(VRAM_A_MAIN_BG_0x06000000); 
		bgInit(3, BgType_Bmp8, BgSize_B8_256x256, 0, 0);

		u16 *oRam = (u16*)BG_BMP_RAM(0);
		BG_PALETTE[0] = RGB15(0,31,0);
		BG_PALETTE[1] = RGB15(31,0,0);
		BG_PALETTE[2] = RGB15(0,0,31);
		BG_PALETTE[3] = 0;

		for(int i = 0; i < 128*192; i++){
			oRam[i] = (i & 3);
		}

		while(1)
			swiWaitForVBlank();
}
As you can see the green stripes alternate with every other color (green, red, blue and black)!
And that's not what I wanted! I think it depends on the type I used for "oRam". In fact it's made of 16 bit instead of 8, so the first 8 are set to 0 and cause the green to appear too many times.
So I changed that type to u8:

Code: Select all


#include <nds.h>
int main(){
		videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);
		vramSetBankA(VRAM_A_MAIN_BG_0x06000000); 
		bgInit(3, BgType_Bmp8, BgSize_B8_256x256, 0, 0);

		u8 *oRam = (u8*)BG_BMP_RAM(0);
		BG_PALETTE[0] = RGB15(0,31,0);
		BG_PALETTE[1] = RGB15(31,0,0);
		BG_PALETTE[2] = RGB15(0,0,31);
		BG_PALETTE[3] = 0;

		for(int i = 0; i < 256*192; i++){
			oRam[i] = (u8)(i & 3);
		}

		while(1)
			swiWaitForVBlank();
}
But all I get from this code is a green screen without any other color.

Can anyone tell me where I'm mistaking?

mtheall
Posts: 211
Joined: Thu Feb 03, 2011 10:47 pm

Re: cannot set video memory properly

Post by mtheall » Mon Jan 16, 2012 6:08 am

You cannot perform 8-bit writes to VRAM, so you must multiplex your writes into 16- or 32-bit writes. Or you can do a 16-bit read, change one of the bytes, and write the modified 16-bit data.

marco6
Posts: 2
Joined: Sun Jan 15, 2012 11:38 am

Re: cannot set video memory properly

Post by marco6 » Mon Jan 16, 2012 10:47 am

Thank you very much! Now it works :)

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 2 guests