Welcome! Log In Create A New Profile

Advanced

Input Problem

Posted by Arikado 
Input Problem
August 22, 2008 01:59AM
I can't get the following piece of code to work properly:


int mode = 1;

void Menu(){
		  
		  // Initialise the video system
	VIDEO_Init();
	
	// This function initialises the attached controllers
	WPAD_Init();
	
	// Obtain the preferred video mode from the system
	// This will correspond to the settings in the Wii menu
	rmode = VIDEO_GetPreferredMode(NULL);

	// Allocate memory for the display in the uncached region
	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	
	// Initialise the console, required for printf
	console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
	
	// Set up the video registers with the chosen mode
	VIDEO_Configure(rmode);
	
	// Tell the video hardware where our display memory is
	VIDEO_SetNextFramebuffer(xfb);
	
	// Make the display visible
	VIDEO_SetBlack(FALSE);

	// Flush the video register changes to the hardware
	VIDEO_Flush();

	// Wait for Video setup to complete
	VIDEO_WaitVSync();
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();


	// The console understands VT terminal escape codes
	// This positions the cursor on row 2, column 0
	// we can use variables for this with format codes too
	// e.g. printf ("\x1b[%d;%dH", row, column );
	printf("\x1b[2;0H");
	

	printf("Wii Game");
		  
		    while(true){
			
			WPAD_ScanPads();
			
			printf("\x1b[5;5H");
			
			switch(mode){
			
			  case 1:
			  printf("Mode1");
			  break;
			  
			  case 2:
			  printf("Mode2");
			  break;
			  
			  case 3:
			  printf("Mode3");
			  break;
			  
			  case 4:
			  printf("Mode4");
			  break;
			  
			}
			
 if((WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_RIGHT)||(WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_NUNCHUK_BUTTON_Z))
			 mode++;
			 
if((WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_RIGHT)||(WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_NUNCHUK_BUTTON_C))
			 mode--;
			 
			 if(mode < 1)
			 mode = 4;
			 
			 if(mode > 4)
			 mode = 1;
			 
	if((WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_B)||(WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_A))
			 break;
			 
			 if(WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_HOME){
			 quit = 1;
			 break;
			 }
			 
			 // Wait for the next frame
		     VIDEO_WaitVSync();
			 
		  }
		 }

Code works fine, but the input lines to deincrement and increment mode don't work. If I ignore the input lines and and have mode increment itself in a loop, that works fine.



Edited 1 time(s). Last edit at 08/22/2008 01:59AM by Arikado.
Re: Input Problem
August 22, 2008 03:36AM
It looks like you made a typo in the input checking part. You check for WPAD_BUTTON_RIGHT twice.

-Santa
Re: Input Problem
August 22, 2008 08:47AM
That's true,if you press right, it does a ++--... that does nothing.

Try with Nunchuk.
Re: Input Problem
August 22, 2008 03:17PM
Thanks it works now. 99% actually, when it displays a short piece of text after a long pice of text, some of the characters from the long text are left over. Is there a way that I can clear the screen every loop?

system("cls");
//Will this work?
Re: Input Problem
August 22, 2008 03:23PM
with
VIDEO_ClearFrameBuffer (GXRModeObj *rmode, void *fb, u32 color)
you can clear the screen
system("cls"); is only for dos applications
Re: Input Problem
August 22, 2008 03:28PM
@nlxx
So it would prolly look like this, correct?

VIDEO_ClearFrameBuffer (rmode, xfb, COLOR_BLACK)

Re: Input Problem
August 22, 2008 03:31PM
Yes :)
Re: Input Problem
August 22, 2008 03:45PM
Thanks, it works perfectly now, I'll have someone lock this topic.

I love this forum...
Re: Input Problem
August 22, 2008 05:29PM
I do not think that the VIDEO API is console aware, the next output on the console should just undo the clearing.
Re: Input Problem
August 22, 2008 06:21PM
@henke37
Well, it works perfectly for me!
Sorry, only registered users may post in this forum.

Click here to login