Example #1
0
void
UpdatePads()
{
	#ifdef HW_RVL
	WPAD_ScanPads();
	#endif

	now = gettime();

	if(!padsConnected && diff_sec(prev, now) < 2)
		return;

	prev = now;

	padsConnected = PAD_ScanPads();

	if(!padsConnected)
		return;

	for(int i=3; i >= 0; i--)
	{
		userInput[i].pad.btns_d = PAD_ButtonsDown(i);
		userInput[i].pad.btns_u = PAD_ButtonsUp(i);
		userInput[i].pad.btns_h = PAD_ButtonsHeld(i);
		userInput[i].pad.stickX = PAD_StickX(i);
		userInput[i].pad.stickY = PAD_StickY(i);
		userInput[i].pad.substickX = PAD_SubStickX(i);
		userInput[i].pad.substickY = PAD_SubStickY(i);
		userInput[i].pad.triggerL = PAD_TriggerL(i);
		userInput[i].pad.triggerR = PAD_TriggerR(i);
	}
}
Example #2
0
/****************************************************************************
 * UpdatePadsCB
 *
 * called by postRetraceCallback in InitGCVideo - scans gcpad and wpad
 ***************************************************************************/
static void
UpdatePadsCB ()
{
	#ifdef HW_RVL
	WPAD_ScanPads();
	#endif
	PAD_ScanPads();

	for(int i=3; i >= 0; i--)
	{
		#ifdef HW_RVL
		memcpy(&userInput[i].wpad, WPAD_Data(i), sizeof(WPADData));
		#endif

		userInput[i].chan = i;
		userInput[i].pad.btns_d = PAD_ButtonsDown(i);
		userInput[i].pad.btns_u = PAD_ButtonsUp(i);
		userInput[i].pad.btns_h = PAD_ButtonsHeld(i);
		userInput[i].pad.stickX = PAD_StickX(i);
		userInput[i].pad.stickY = PAD_StickY(i);
		userInput[i].pad.substickX = PAD_SubStickX(i);
		userInput[i].pad.substickY = PAD_SubStickY(i);
		userInput[i].pad.triggerL = PAD_TriggerL(i);
		userInput[i].pad.triggerR = PAD_TriggerR(i);
	}
}
Example #3
0
void
UpdatePads()
{
	#ifdef HW_RVL
	WiiDRC_ScanPads();
	WPAD_ScanPads();
	#endif
	
	PAD_ScanPads();

	for(int i=3; i >= 0; i--)
	{
		userInput[i].pad.btns_d = PAD_ButtonsDown(i);
		userInput[i].pad.btns_u = PAD_ButtonsUp(i);
		userInput[i].pad.btns_h = PAD_ButtonsHeld(i);
		userInput[i].pad.stickX = PAD_StickX(i);
		userInput[i].pad.stickY = PAD_StickY(i);
		userInput[i].pad.substickX = PAD_SubStickX(i);
		userInput[i].pad.substickY = PAD_SubStickY(i);
		userInput[i].pad.triggerL = PAD_TriggerL(i);
		userInput[i].pad.triggerR = PAD_TriggerR(i);
	}
#ifdef HW_RVL
	if(WiiDRC_Inited() && WiiDRC_Connected())
	{
		userInput[0].wiidrcdata.btns_d = WiiDRC_ButtonsDown();
		userInput[0].wiidrcdata.btns_u = WiiDRC_ButtonsUp();
		userInput[0].wiidrcdata.btns_h = WiiDRC_ButtonsHeld();
		userInput[0].wiidrcdata.stickX = WiiDRC_lStickX();
		userInput[0].wiidrcdata.stickY = WiiDRC_lStickY();
		userInput[0].wiidrcdata.substickX = WiiDRC_rStickX();
		userInput[0].wiidrcdata.substickY = WiiDRC_rStickY();
	}
#endif
}
/****************************************************************************
 * UpdatePads
 *
 * Scans pad and wpad
 ***************************************************************************/
void UpdatePads() {
    XenonInputUpdate();

    for (int i = 3; i >= 0; i--) {
        userInput[i].pad.btns_d = PAD_ButtonsDown(i);
        userInput[i].pad.btns_u = PAD_ButtonsUp(i);
        userInput[i].pad.btns_h = PAD_ButtonsHeld(i);
        //        userInput[i].pad.stickX = PAD_StickX(i);
        //        userInput[i].pad.stickY = PAD_StickY(i);
        userInput[i].pad.substickX = PAD_SubStickX(i);
        userInput[i].pad.substickY = PAD_SubStickY(i);
        userInput[i].pad.triggerL = PAD_TriggerL(i);
        userInput[i].pad.triggerR = PAD_TriggerR(i);
    }
}
void GamecubePadSource::poll()
{
	if (PAD_ButtonsDown(padNumber) & PAD_BUTTON_UP)
	{
		upButton.notifyDownHandlers();
	}
	if (PAD_ButtonsDown(padNumber) & PAD_BUTTON_DOWN)
	{
		downButton.notifyDownHandlers();
	}
	if (PAD_ButtonsDown(padNumber) & PAD_BUTTON_LEFT)
	{
		leftButton.notifyDownHandlers();
	}
	if (PAD_ButtonsDown(padNumber) & PAD_BUTTON_RIGHT)
	{
		rightButton.notifyDownHandlers();
	}
	if (PAD_ButtonsDown(padNumber) & PAD_BUTTON_A)
	{
		fireButton.notifyDownHandlers();
	}
	if (PAD_ButtonsDown(padNumber) & PAD_BUTTON_START)
	{
		pauseButton.notifyDownHandlers();
	}

	if (PAD_ButtonsUp(padNumber) & PAD_BUTTON_UP)
	{
		upButton.notifyUpHandlers();
	}
	if (PAD_ButtonsUp(padNumber) & PAD_BUTTON_DOWN)
	{
		downButton.notifyUpHandlers();
	}
	if (PAD_ButtonsUp(padNumber) & PAD_BUTTON_LEFT)
	{
		leftButton.notifyUpHandlers();
	}
	if (PAD_ButtonsUp(padNumber) & PAD_BUTTON_RIGHT)
	{
		rightButton.notifyUpHandlers();
	}
	if (PAD_ButtonsUp(padNumber) & PAD_BUTTON_A)
	{
		fireButton.notifyUpHandlers();
	}
	if (PAD_ButtonsUp(padNumber) & PAD_BUTTON_START)
	{
		pauseButton.notifyUpHandlers();
	}


}
Example #6
0
u32 TMNTInput(unsigned short pad) {
	u32 J = StandardMovement(pad) | StandardDPad(pad);
	static u32 LastDir = VBA_RIGHT;
	static bool wait = false;
	static int holdcount = 0;
	bool Jump=0, Attack=0, SpinKick=0, Roll=0, Pause=0, Select=0;

#ifdef HW_RVL
	WPADData * wp = WPAD_Data(pad);
	if (wp->exp.type == WPAD_EXP_NUNCHUK) {
		Jump = (wp->btns_h & WPAD_BUTTON_A);
		Attack = (fabs(wp->gforce.x)> 1.5);
		SpinKick = (fabs(wp->exp.nunchuk.gforce.x)> 0.5);
		Roll = (wp->btns_h & WPAD_NUNCHUK_BUTTON_Z || wp->btns_h & WPAD_NUNCHUK_BUTTON_C);
		Pause = (wp->btns_h & WPAD_BUTTON_PLUS);
		Select = (wp->btns_h & WPAD_BUTTON_MINUS);
		// Swap Turtles or super turtle summon
		if (wp->btns_h & WPAD_BUTTON_B) {
			if (wp->exp.nunchuk.orient.pitch < -35 && wp->orient.pitch < -35)
				J |= VBA_BUTTON_L | VBA_BUTTON_R;
			else J |= VBA_BUTTON_R;
		}
	} else if (wp->exp.type == WPAD_EXP_CLASSIC) {
		Jump = (wp->btns_h & WPAD_CLASSIC_BUTTON_B);
		Attack = (wp->btns_h & WPAD_CLASSIC_BUTTON_A);
		SpinKick = (wp->btns_h & WPAD_CLASSIC_BUTTON_X);
		Pause = (wp->btns_h & WPAD_CLASSIC_BUTTON_PLUS);
		Select = (wp->btns_h & WPAD_CLASSIC_BUTTON_MINUS);
		Roll = (wp->btns_h & (WPAD_CLASSIC_BUTTON_FULL_L | WPAD_CLASSIC_BUTTON_FULL_R | WPAD_CLASSIC_BUTTON_ZL | WPAD_CLASSIC_BUTTON_ZR));
		// Swap Turtles or super turtle summon
		if (wp->btns_h & WPAD_CLASSIC_BUTTON_Y) {
			holdcount++;
			if (holdcount > 20)
				J |= VBA_BUTTON_L | VBA_BUTTON_R;
		}
		if (wp->btns_u & WPAD_CLASSIC_BUTTON_Y) {
			if (holdcount <= 20)
				J |= VBA_BUTTON_R;
			holdcount = 0;
		}
	} else {
		Jump = (wp->btns_h & WPAD_BUTTON_A);
		Attack = (fabs(wp->gforce.x)> 1.5);
		Pause = (wp->btns_h & WPAD_BUTTON_PLUS);
		Select = (wp->btns_h & WPAD_BUTTON_MINUS);
		// Swap Turtles or super turtle summon
		if (wp->btns_h & WPAD_BUTTON_B) {
			if (wp->orient.pitch < -40)
				J |= VBA_BUTTON_L | VBA_BUTTON_R;
			else J |= VBA_BUTTON_R;
		}
		SpinKick = (wp->btns_h & WPAD_BUTTON_1);
		Roll = (wp->btns_h & WPAD_BUTTON_2);
	}

#endif
	u32 gc = PAD_ButtonsHeld(pad);
	u32 released = PAD_ButtonsUp(pad);
	// DPad moves
	if (gc & PAD_BUTTON_UP)
		J |= VBA_UP;
	if (gc & PAD_BUTTON_DOWN)
		J |= VBA_DOWN;
	if (gc & PAD_BUTTON_LEFT)
		J |= VBA_LEFT;
	if (gc & PAD_BUTTON_RIGHT)
		J |= VBA_RIGHT;
	// Jump
	if (gc & PAD_BUTTON_A) J |= VBA_BUTTON_A;
	// Swap turtles, hold for super family move
	if (gc & PAD_BUTTON_B) {
		holdcount++;
		if (holdcount > 20)
			J |= VBA_BUTTON_L | VBA_BUTTON_R;
	}
	if (released & PAD_BUTTON_B) {
		if (holdcount <= 20)
			J |= VBA_BUTTON_R;
		holdcount = 0;
	}
	// Attack
	if (gc & PAD_BUTTON_X) Attack = true;
	// Spin kick
	if (gc & PAD_BUTTON_Y) SpinKick = true;
	// Pause
	if (gc & PAD_BUTTON_START) Pause = true;
	// Select
	if (gc & PAD_TRIGGER_Z) Select = true;
	// Roll
	if (gc & PAD_TRIGGER_L || gc & PAD_TRIGGER_R) Roll = true;

	if (Jump) J |= VBA_BUTTON_A;
	if (Attack) J |= VBA_BUTTON_B;
	if (SpinKick) J |= VBA_BUTTON_B | VBA_BUTTON_A;
	if (Pause) J |= VBA_BUTTON_START;
	if (Select) J |= VBA_BUTTON_SELECT;
	if (Roll) {
		if (!wait) {
			J |= LastDir; // Double tap D-Pad to roll
			wait = true;
		} else wait = false;
	}
	
		
	if (J & VBA_RIGHT) LastDir = VBA_RIGHT;
	else if (J & VBA_LEFT) LastDir = VBA_LEFT;
	return J;
}
Example #7
0
void getGamecubePadInput() 
{
   u32 pressed;
   int dpadPressed = 0;
   int virtualJoyIndex=0;
   int physicalJoyIndex=0;
   SDL_Event keyDownEvent[MAX_EVENTS_PER_CYCLE];
   
   //************************************************
   // Buttons PRESSED
   //************************************************
   for (virtualJoyIndex=0; virtualJoyIndex<2; virtualJoyIndex++)
   {
      if (joyGcUsed[virtualJoyIndex]==0) continue;
      physicalJoyIndex = virtualJoyIndex;
      if (joyGcUsed[0]==0)
      {
         physicalJoyIndex=0;
      }
      pressed = PAD_ButtonsDown(physicalJoyIndex);
      int keyDownIndex=0;
      
      if (pressed & PAD_BUTTON_A)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_09;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      if (pressed & PAD_BUTTON_Y)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_10;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      if (pressed & PAD_BUTTON_X)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_11;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);
      }
      
      if (pressed & PAD_BUTTON_B)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_12;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);
      }
      
      if (pressed & PAD_BUTTON_START)
      {
         keyDownEvent[keyDownIndex].key.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].key.type=SDL_KEYDOWN;
         keyDownEvent[keyDownIndex].key.keysym.sym=SDLK_F1;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      if (pressed & PAD_TRIGGER_R)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_02;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      if (pressed & PAD_TRIGGER_Z)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_00;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);  
      }
      
      if (pressed & PAD_TRIGGER_L)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_01;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      //************************************************
      // Buttons PRESSED --> D-Pads
      //************************************************
      
       if (
          (pressed & PAD_BUTTON_RIGHT)
         )
      {
         //x
         keyDownEvent[keyDownIndex].type = SDL_JOYAXISMOTION;
         keyDownEvent[keyDownIndex].jaxis.axis = 0;
         keyDownEvent[keyDownIndex].jaxis.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jaxis.value=10000;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);
         dpadPressed=1;
      }
      
      if (
          (pressed & PAD_BUTTON_DOWN)
         )
      {
         //y
         keyDownEvent[keyDownIndex].type = SDL_JOYAXISMOTION;
         keyDownEvent[keyDownIndex].jaxis.axis = 1;
         keyDownEvent[keyDownIndex].jaxis.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jaxis.value=10000;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);
         dpadPressed=1;      
      }
       
      if (
          (pressed & PAD_BUTTON_LEFT)
         )
      {
         //x
         keyDownEvent[keyDownIndex].type = SDL_JOYAXISMOTION;
         keyDownEvent[keyDownIndex].jaxis.axis = 0;
         keyDownEvent[keyDownIndex].jaxis.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jaxis.value=-10000;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);
         dpadPressed=1;      
      }
       
      if (
          (pressed & PAD_BUTTON_UP)
         )
      {
         //x
         keyDownEvent[keyDownIndex].type = SDL_JOYAXISMOTION;
         keyDownEvent[keyDownIndex].jaxis.axis = 1;
         keyDownEvent[keyDownIndex].jaxis.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jaxis.value=-10000;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);
         dpadPressed=1;      
      }
      
      //************************************************
      // Buttons Held --> D-Pads
      //************************************************
      

      pressed = PAD_ButtonsHeld(physicalJoyIndex);
      int keyHeldIndex=0;
      SDL_Event keyHeldEvent[MAX_EVENTS_PER_CYCLE];
      
      if (
          (pressed & PAD_BUTTON_RIGHT)
         )
      {
         //x
         keyHeldEvent[keyHeldIndex].type = SDL_JOYAXISMOTION;
         keyHeldEvent[keyHeldIndex].jaxis.axis = 0;
         keyHeldEvent[keyHeldIndex].jaxis.which=virtualJoyIndex;
         keyHeldEvent[keyHeldIndex].jaxis.value=10000;
         SDL_PushEvent(&keyHeldEvent[keyHeldIndex++]);  
         dpadPressed=1;
      }
    
      if (
          (pressed & PAD_BUTTON_DOWN)
         )
      {
         //y
         keyHeldEvent[keyHeldIndex].type = SDL_JOYAXISMOTION;
         keyHeldEvent[keyHeldIndex].jaxis.axis = 1;
         keyHeldEvent[keyHeldIndex].jaxis.which=virtualJoyIndex;
         keyHeldEvent[keyHeldIndex].jaxis.value=10000;
         SDL_PushEvent(&keyHeldEvent[keyHeldIndex++]);
         dpadPressed=1;
      }
      
      if (
          (pressed & PAD_BUTTON_LEFT)
         )
      {
         //x
         keyHeldEvent[keyHeldIndex].type = SDL_JOYAXISMOTION;
         keyHeldEvent[keyHeldIndex].jaxis.axis = 0;
         keyHeldEvent[keyHeldIndex].jaxis.which=virtualJoyIndex;
         keyHeldEvent[keyHeldIndex].jaxis.value=-10000;
         SDL_PushEvent(&keyHeldEvent[keyHeldIndex++]);
         dpadPressed=1;         
      }
    
      if (
          (pressed & PAD_BUTTON_UP)
         )
      {
         //x
         keyHeldEvent[keyHeldIndex].type = SDL_JOYAXISMOTION;
         keyHeldEvent[keyHeldIndex].jaxis.axis = 1;
         keyHeldEvent[keyHeldIndex].jaxis.which=virtualJoyIndex;
         keyHeldEvent[keyHeldIndex].jaxis.value=-10000;
         SDL_PushEvent(&keyHeldEvent[keyHeldIndex++]);
         dpadPressed=1;         
      }
      
      //************************************************
      // Buttons RELEASED
      //************************************************
      
      pressed = PAD_ButtonsUp(physicalJoyIndex);
      int keyUpIndex=0;
      SDL_Event keyUpEvent[MAX_EVENTS_PER_CYCLE];
      
      if (pressed & PAD_BUTTON_A)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_09;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & PAD_BUTTON_Y)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_10;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & PAD_BUTTON_X)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_11;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);
      }
      
      if (pressed & PAD_BUTTON_B)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_12;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & PAD_TRIGGER_R)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_02;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & PAD_TRIGGER_Z)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_00;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & PAD_TRIGGER_L)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_01;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);
      }
      
      //************************************************
      // Buttons RELEASED --> D-Pads
      //************************************************
      
      if (
          (pressed & PAD_BUTTON_RIGHT)
         )
      {
         //x
         keyUpEvent[keyUpIndex].type = SDL_JOYAXISMOTION;
         keyUpEvent[keyUpIndex].jaxis.axis = 0;
         keyUpEvent[keyUpIndex].jaxis.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jaxis.value=0;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);
         dpadPressed=1;
      }
    
      if (
          (pressed & PAD_BUTTON_DOWN)
         )
      {
         //y
         keyUpEvent[keyUpIndex].type = SDL_JOYAXISMOTION;
         keyUpEvent[keyUpIndex].jaxis.axis = 1;
         keyUpEvent[keyUpIndex].jaxis.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jaxis.value=0;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);
         dpadPressed=1;
      }
    
      if (
          (pressed & PAD_BUTTON_LEFT)
         )
      {
         //x
         keyUpEvent[keyUpIndex].type = SDL_JOYAXISMOTION;
         keyUpEvent[keyUpIndex].jaxis.axis = 0;
         keyUpEvent[keyUpIndex].jaxis.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jaxis.value=0;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);
         dpadPressed=1;
      }
    
      if (
          (pressed & PAD_BUTTON_UP)
         )
      {
         //x
         keyUpEvent[keyUpIndex].type = SDL_JOYAXISMOTION;
         keyUpEvent[keyUpIndex].jaxis.axis = 1;
         keyUpEvent[keyUpIndex].jaxis.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jaxis.value=0;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);
         dpadPressed=1;
      }
      
      //************************************************
      // Left stick --> JoyAXIS
      //************************************************
      int x = 0;
      int y = 0;
      int angleIndex = 0;
      s8 X1=0, Y1=0, X2=0, Y2=0;
      X1 = PAD_StickX(physicalJoyIndex);
      Y1 = PAD_StickY(physicalJoyIndex);	
      X2 = PAD_SubStickX(physicalJoyIndex);
      Y2 = PAD_SubStickY(physicalJoyIndex);
      
      if (!dpadPressed)
      {
         x = X1-DEFAULT_GC_LEFT_X_CENTER;
         y = Y1-DEFAULT_GC_LEFT_Y_CENTER;
         angleIndex = getAngleIndex(x,y);
           
         SDL_Event xevent;
         xevent.type = SDL_JOYAXISMOTION;
         xevent.jaxis.which=virtualJoyIndex;
         xevent.jaxis.axis = 0;
         
         SDL_Event yevent;
         yevent.type = SDL_JOYAXISMOTION;
         yevent.jaxis.which=virtualJoyIndex;
         yevent.jaxis.axis = 1;
         
         getSDLJoyAxisEvent(&xevent, &yevent, angleIndex);
         
         if ( 
             (x < GC_LEFT_X_TOLERANCE) &&
             (x > -GC_LEFT_X_TOLERANCE)
             )
         {
            xevent.jaxis.value = 0;
         }
          
         if (
             (y < GC_LEFT_Y_TOLERANCE) &&
             (y > -GC_LEFT_Y_TOLERANCE)
            )
         {
            yevent.jaxis.value = 0;
         }
         
         SDL_PushEvent(&xevent); 
         SDL_PushEvent(&yevent); 
      }
      
      //************************************************
      // Right stick --> HAT
      //************************************************
      
      x = X2-DEFAULT_GC_RIGHT_X_CENTER;
      y = Y2-DEFAULT_GC_RIGHT_Y_CENTER;
      angleIndex = getAngleIndex(x,y);
      
      SDL_Event hatEvent;
      hatEvent.type = SDL_JOYHATMOTION;
      hatEvent.jhat.which=virtualJoyIndex;
      hatEvent.jhat.hat = 0;
      hatEvent.jhat.value = SDL_HAT_CENTERED;
      
      if ( 
          (x > GC_RIGHT_X_TOLERANCE) ||
          (x < -GC_RIGHT_X_TOLERANCE)||
          (y > GC_RIGHT_Y_TOLERANCE) ||
          (y < -GC_RIGHT_Y_TOLERANCE)
         )
      {
         getHatEvent(&hatEvent, angleIndex);
      }
      if (lastHatSent[hatEvent.jhat.which] != hatEvent.jhat.value)
      {
        SDL_PushEvent(&hatEvent);
        lastHatSent[hatEvent.jhat.which] = hatEvent.jhat.value;
      }
   }
}
int main (int argc, char **argv)
{
    // init SDL (Video only)
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        fprintf(stderr, "Couldn't initialise SDL: %s", SDL_GetError());
        return 1;
    }
    atexit(SDL_Quit);

    screen = SDL_SetVideoMode(320, 240, 8, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
    if (!screen)
    {
        fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError());
        return 1;
    }

    SDL_ShowCursor(SDL_DISABLE);

    Game.InitSoundDriver();
    Game.InitGame();
    Game.LoadScores();
    Game.StartGame();

    int run = 1;
    int game_paused = 0;
    int game_speed = 55;
    int last_time = SDL_GetTicks();

    // load Menu images
    SDL_Surface *menu_logo = load_menu_bitmap(menu_logo_bmp, menu_logo_bmp_size);
    SDL_Surface *menu_pointer = load_menu_bitmap(menu_pointer_bmp, menu_pointer_bmp_size);
    SDL_Surface *menu_1player = load_menu_bitmap(menu_1player_bmp, menu_1player_bmp_size);
    SDL_Surface *menu_2players = load_menu_bitmap(menu_2players_bmp, menu_2players_bmp_size);
    SDL_Surface *menu_start = load_menu_bitmap(menu_start_bmp, menu_start_bmp_size);
    SDL_Surface *menu_widescreen = load_menu_bitmap(menu_widescreen_bmp, menu_widescreen_bmp_size);
    SDL_Surface *menu_music = load_menu_bitmap(menu_music_bmp, menu_music_bmp_size);
    SDL_Surface *menu_sound = load_menu_bitmap(menu_sound_bmp, menu_sound_bmp_size);
    SDL_Surface *menu_i = load_menu_bitmap(menu_i_bmp, menu_i_bmp_size);
    SDL_Surface *menu_exit = load_menu_bitmap(menu_exit_bmp, menu_exit_bmp_size);
    SDL_Surface *menu_yes = load_menu_bitmap(menu_yes_bmp, menu_yes_bmp_size);
    SDL_Surface *menu_no = load_menu_bitmap(menu_no_bmp, menu_no_bmp_size);

    // Some globals
    int active_menu_item = 0; // Start
    int widescreen_enabled = 0; //nope
    int music_volume = 10; // max
    int sound_volume = 10; // max
    int i;
    int players = 1;

    // load config here :)

    while(run)
    {
        // Get Controller state
        JOYSTICK *jptr1 = &Game.m_GameTarget.m_Joy1;
        JOYSTICK *jptr2 = &Game.m_GameTarget.m_Joy2;

        PAD_ScanPads();
        int bu_down, bu_up = 0;

        // Player 1
        bu_down = PAD_ButtonsDown(0);
        bu_up = PAD_ButtonsUp(0);

        // left
        if (PAD_StickX(0) <= -58)
            jptr1->left = 1;
        else
            jptr1->left = 0;

        // right
        if (PAD_StickX(0) >= 58)
            jptr1->right = 1;
        else
            jptr1->right = 0;

        // down
        if (PAD_StickY(0) <= -58)
            jptr1->down = 1;
        else
            jptr1->down = 0;

        // up
        if (PAD_StickY(0) >= 58)
            jptr1->up = 1;
        else
            jptr1->up = 0;

        // fire
        if (bu_down & PAD_BUTTON_A)
            jptr1->fire = 1;

        if (bu_up & PAD_BUTTON_A)
            jptr1->fire = 0;

        // Switch Player sprites
        if (bu_down & PAD_TRIGGER_Z)
            Game.m_GameTarget.m_Game.TogglePuffBlow();

        // Only Player 1 can Pause the Game
        if (bu_down & PAD_BUTTON_START)
            game_paused ^= 1;

        /* DEBUG: alter game speed + warp levels
        if (bu_down & PAD_TRIGGER_L) {
            game_speed += 5;
            if (game_speed > 100)
                game_speed = 100;
        }
        if (bu_down & PAD_TRIGGER_R) {
            game_speed -= 5;
            if (game_speed < 10)
                game_speed = 10;
        }
        if ((PAD_SubStickX(0) > 60) && (PAD_SubStickY(0) <= -60))
            jptr1->next_level = 1;
        else
            jptr1->next_level = 0;
        // DEBUG: end */

        // Player 2
        bu_down = PAD_ButtonsDown(1);
        bu_up = PAD_ButtonsUp(1);

        // left
        if (PAD_StickX(1) <= -58)
            jptr2->left = 1;
        else
            jptr2->left = 0;

        // right
        if (PAD_StickX(1) >= 58)
            jptr2->right = 1;
        else
            jptr2->right = 0;

        // down
        if (PAD_StickY(1) <= -58)
            jptr2->down = 1;
        else
            jptr2->down = 0;

        // up
        if (PAD_StickY(1) >= 58)
            jptr2->up = 1;
        else
            jptr2->up = 0;

        // fire
        if (bu_down & PAD_BUTTON_A)
            jptr2->fire = 1;

        if (bu_up & PAD_BUTTON_A)
            jptr2->fire = 0;

        // Fake a key press (to pass getPlayerName screen)
        jptr1->key = 13;

        // Add a delay
        int time_diff = 0;
        do
        {
            int time_now = SDL_GetTicks();
            time_diff = time_now - last_time;
            time_diff = game_speed - time_diff;
            if (time_diff > 50) SDL_Delay(20);
        } while(time_diff > 0);
        last_time = last_time + game_speed; 

        // Execute game logic
        Game.MainLoop(NULL, game_paused);

        // Display menu
        if (game_paused == 1)
        {
            // Draw logo + items
            SDL_Rect menu_pos;

            menu_pos.x = 16;
            menu_pos.y = 3;
            menu_pos.w = 0;
            menu_pos.h = 0;
            SDL_BlitSurface(menu_logo, NULL, screen, &menu_pos);

            menu_pos.x = 70;
            menu_pos.y = 120;
            menu_pos.w = 0;
            menu_pos.h = 0;
            SDL_BlitSurface(menu_start, NULL, screen, &menu_pos);

            menu_pos.x = 70;
            menu_pos.y = 140;
            menu_pos.w = 0;
            menu_pos.h = 0;

            if(players == 1)
                SDL_BlitSurface(menu_1player, NULL, screen, &menu_pos);
            else
                SDL_BlitSurface(menu_2players, NULL, screen, &menu_pos);

            menu_pos.x = 70;
            menu_pos.y = 160;
            menu_pos.w = 0;
            menu_pos.h = 0;
            SDL_BlitSurface(menu_widescreen, NULL, screen, &menu_pos);

            // Widescreen Indicator
            menu_pos.x = 255;
            menu_pos.y = 160;
            menu_pos.w = 0;
            menu_pos.h = 0;

            if(widescreen_enabled)
                SDL_BlitSurface(menu_yes, NULL, screen, &menu_pos);
            else
                SDL_BlitSurface(menu_no, NULL, screen, &menu_pos);

            menu_pos.x = 70;
            menu_pos.y = 180;
            menu_pos.w = 0;
            menu_pos.h = 0;
            SDL_BlitSurface(menu_sound, NULL, screen, &menu_pos);

            // Sound volume bar
            for (i = 1; i <= sound_volume; i++)
            {
                menu_pos.x = 160 + (i * 9);
                menu_pos.y = 180;
                menu_pos.w = 0;
                menu_pos.h = 0;
                SDL_BlitSurface(menu_i, NULL, screen, &menu_pos);
            }

            menu_pos.x = 70;
            menu_pos.y = 200;
            menu_pos.w = 0;
            menu_pos.h = 0;
            SDL_BlitSurface(menu_music, NULL, screen, &menu_pos);

            // Music volume bar
            for (i = 1; i <= music_volume; i++)
            {
                menu_pos.x = 160 + (i * 9);
                menu_pos.y = 200;
                menu_pos.w = 0;
                menu_pos.h = 0;
                SDL_BlitSurface(menu_i, NULL, screen, &menu_pos);
            }

            menu_pos.x = 70;
            menu_pos.y = 220;
            menu_pos.w = 0;
            menu_pos.h = 0;
            SDL_BlitSurface(menu_exit, NULL, screen, &menu_pos);

            // Pointer
            if((jptr1->down == 1) && (active_menu_item < 5))
                active_menu_item++;

            if((jptr1->up == 1) && (active_menu_item > 0))
                active_menu_item--;

            menu_pos.x = 30;
            menu_pos.y = 105 + (active_menu_item * 20);
            menu_pos.w = 0;
            menu_pos.h = 0;
            SDL_BlitSurface(menu_pointer, NULL, screen, &menu_pos);

            // React on items
            if((active_menu_item == 0) && (jptr1->fire)) // Start
            {
                game_paused = 0;
                Game.m_GameTarget.m_Game.InitGetPlayerNameScreen(players == 2);
            }

            if(active_menu_item == 1) // Players
            {
                if (jptr1->left)
                    players = 1;
                if (jptr1->right)
                    players = 2;
            }

            if(active_menu_item == 2) // Widescreen
            {
                if (jptr1->left)
                {
                    widescreen_enabled = 0;
                    CUBE_ChangeSquare(320, 240, 0, 0); // no padding
                }
                if (jptr1->right)
                {
                    widescreen_enabled = 1;
                    CUBE_ChangeSquare(280, 240, 0, 0); // add some padding
                }
            }

            if(active_menu_item == 3) // Sound
            {
                if((jptr1->right) && (sound_volume < 10))
                    sound_volume++;

                if((jptr1->left) && (sound_volume > 0))
                    sound_volume--;

                Game.ChangeVolume(sound_volume, music_volume);
            }

            if(active_menu_item == 4) // Music
            {
                if((jptr1->right) && (music_volume < 10))
                    music_volume++;

                if((jptr1->left) && (music_volume > 0))
                    music_volume--;

                Game.ChangeVolume(sound_volume, music_volume);
            }

            if((active_menu_item == 5) && (jptr1->fire)) //EXIT
                run = 0;

            // Show all
            SDL_Flip (screen);

            // Wait for buttonpresses
            SDL_Delay(60);

            // Fix delay timer
            last_time = SDL_GetTicks();
        }
    }

    Game.SaveScores();

    // save config here :)

    Game.RemoveSoundDriver();
    SDL_FreeSurface(screen);

    SDL_QuitSubSystem(SDL_INIT_VIDEO);

    //return 0;
    exit(0);
}