i broke my code

Post Reply
zelbo
Posts: 11
Joined: Tue Feb 10, 2009 6:23 am

i broke my code

Post by zelbo » Sat Apr 11, 2009 11:26 pm

i had the colors cycling, although a little choppy. When i tried to implement a smoother way of changing color, it broke. Any thoughts?

Code: Select all

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

void ClearScreen(void)
{
	int i;
	for(i = 0; i < 256 * 192; i++)
		VRAM_A[i] = RGB15(0, 0, 0);
  return;
}

int main(void)
{
// standard

// multi-purpose variables
int i;
int x;
int y;
int z;

// values
u16 valRed;
u16 valGreen;
u16 valBlue;

// increment?
bool incRed;
bool incGreen;
bool incBlue;

irqInit();
irqEnable(IRQ_VBLANK);
videoSetMode(MODE_FB0); // set video mode to frame buffer mode
vramSetBankA(VRAM_A_LCD); // assign first mem bank to lcd
consoleDemoInit(); // initilize console for printf to work

ClearScreen();


// hello world
printf("Hello World!\n");
printf("Hello East Wind!\n");
printf("In Your Neck!");
for(i = 0; i < 256 * 192; i++) // loop through each pixel on top screen
	VRAM_A[i] = RGB15(31,0,0); // and make it red
// end hello world

// keypad demo

i = 0;

valRed = 0;
valGreen = 0;
valBlue = 0;

incRed = 1;
incGreen = 1;
incBlue = 1;

while(1)
{

	for(x = 0; x < 32; x++)
	{
		for(y = 0; y < 32; y++)
		{
			for(z = 0; z < 32; z++)
			{
			  if (incRed)
			  {
				valRed--;
				if (valRed = 0) incRed = (1);
			  } 
			  else
			  {
				valRed++;
				if (valRed = 31) incRed = (0);
			  }
			  	swiWaitForVBlank();
				VRAM_A[i] = RGB15(valRed, valGreen, valBlue);
				i++;
				if (i = 256 * 192) {i = 0;}
				iprintf("i = %d, x = %d, y = %d, z = %d\n", i, x, y, z);
				iprintf("valRed = %d, valGreen = %d, valBlue = %d\n", valRed, valGreen, valBlue);
				iprintf("incRed = %d, incGreen = %d, incBlue = %d\n", incRed, incGreen, incBlue);
			}
			
			  if (incGreen)
			  {
				valGreen--;
				if (valGreen = 0) incGreen = (1);
			  } 
			  else
			  {
				valGreen++;
				if (valGreen = 31) incGreen = (0);
			  }
			swiWaitForVBlank();
			VRAM_A[i] = RGB15(valRed, valGreen, valBlue);
			i++;
			if (i = 256 * 192) {i = 0;}
			iprintf("i = %d, x = %d, y = %d, z = %d\n", i, x, y, z);
			iprintf("valRed = %d, valGreen = %d, valBlue = %d\n", valRed, valGreen, valBlue);
			iprintf("incRed = %d, incGreen = %d, incBlue = %d\n", incRed, incGreen, incBlue);
		}
			  if (incBlue)
			  {
				valBlue--;
				if (valBlue = 0) incBlue = (1);
			  } 
			  else
			  {
				valBlue++;
				if (valBlue = 31) incBlue = (0);
			  }
		swiWaitForVBlank();
		VRAM_A[i] = RGB15(valRed, valGreen, valBlue);
		i++;
		if (i = 256 * 192) {i = 0;}
		iprintf("i = %d, x = %d, y = %d, z = %d\n", i, x, y, z);
		iprintf("valRed = %d, valGreen = %d, valBlue = %d\n", valRed, valGreen, valBlue);
		iprintf("incRed = %d, incGreen = %d, incBlue = %d\n", incRed, incGreen, incBlue);

	}

iprintf("i = %d, x = %d, y = %d, z = %d\n", i, x, y, z);
iprintf("valRed = %d, valGreen = %d, valBlue = %d\n", valRed, valGreen, valBlue);
iprintf("incRed = %d, incGreen = %d, incBlue = %d\n", incRed, incGreen, incBlue);

}
// end keypad

return 0;
}



Last edited by zelbo on Mon Apr 13, 2009 10:51 pm, edited 1 time in total.

Al_Bro
Posts: 15
Joined: Wed Apr 08, 2009 10:33 pm

Re: i broke my code

Post by Al_Bro » Sat Apr 11, 2009 11:32 pm

zelbo wrote:

Code: Select all

			  if (incRed)
			  {
				valRed--;
				if (valRed = 0) incRed = (1);
			  } 
			  else
			  {
				valRed++;
				if (valRed = 31) incRed = (0);
			  }
You're making a classic C mistake - you should have if(valRed == 0) and if(valRed == 31) with double '=' signs. Same applies to the other similar "if" tests.

zelbo
Posts: 11
Joined: Tue Feb 10, 2009 6:23 am

Re: i broke my code

Post by zelbo » Sun Apr 12, 2009 2:43 am

awesome, thank you very much!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 13 guests