コード例 #1
0
ファイル: joystick.c プロジェクト: Yamakuzure/PUAE
static void read_joy (uint32_t nr)
{
    if (LowLevelBase != NULL) {
	ULONG state = ReadJoyPort (nr);

	if ((state & JP_TYPE_MASK) != JP_TYPE_NOTAVAIL) {
	    int32_t x = 0, y = 0;

	    if (state & JPF_JOY_UP)
		y = -1;
	    else if (state & JPF_JOY_DOWN)
		y = 1;
	    if (state & JPF_JOY_LEFT)
		x = -1;
	    else if (state & JPF_JOY_RIGHT)
		x = 1;

	    setjoystickstate (nr, 0, x, 1);
	    setjoystickstate (nr, 1, y, 1);

	    setjoybuttonstate (nr, 0, state & JPF_BUTTON_RED);
	    setjoybuttonstate (nr, 1, state & JPF_BUTTON_BLUE);
	}
    }
}
コード例 #2
0
ファイル: joystick.c プロジェクト: engur/PUAE
/* static lastState = 0; */
static void read_joysticks (void)
{
    /* TODO(cstefansen): Support third joystick button (what games use
       this?) */

    /* Get current gamepad data. */
    struct PP_GamepadsSampleData gamepad_data;
    ppb_gamepad_interface->Sample(pp_instance, &gamepad_data);

    /* Update state for each connected gamepad. */
    size_t p = 0;
    for (; p < gamepad_data.length; ++p) {
      struct PP_GamepadSampleData pad = gamepad_data.items[p];

      if (!pad.connected)
        continue;

      /* Update axes. */
      size_t i = 0;
      int axisState[2] = {0, 0};
      for (; i < pad.axes_length; ++i) {
          axisState[i % 2] += pad.axes[i] < 0.1f && pad.axes[i] > -0.1f ?
              0 : (int) (pad.axes[i] * 32767);
      }
      /* Buttons 12-15 are up/down/left/right of a small digital
         joystick on the typical gamepad. */
      if (pad.buttons_length >= 15) {
          axisState[0] += (int) ((-pad.buttons[14] + pad.buttons[15]) * 32767);
          axisState[1] += (int) ((-pad.buttons[12] + pad.buttons[13]) * 32767);
      }
      setjoystickstate(p, 0, axisState[0] > 32767 ? 32767 :
                       axisState[0] < -32767 ? -32767 : axisState[0], 32767);
      setjoystickstate(p, 1, axisState[1] > 32767 ? 32767 :
                       axisState[1] < -32767 ? -32767 : axisState[1], 32767);

      /* Update buttons. */
      static const int buttons[16] =
          {0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1};
      size_t j = 0;
      int buttonState[2] = {0, 0};
      /* Buttons 12-15 are considered a joystick (i.e., for movement)
         and 16 and above are ignored. */
      for (; j < pad.buttons_length && j < 12; ++j) {
          buttonState[buttons[j]] |= pad.buttons[j] < 0.1f ? 0 : 1;
      }
      /* TODO(cstefansen): Figure out a proper autofire. */
      /*
      lastState = (lastState == 1 && buttonState[0] == 1) ? 0 : buttonState[0];
      setjoybuttonstate(p, 0, lastState);
      */
      setjoybuttonstate(p, 0, buttonState[0]);
      setjoybuttonstate(p, 1, buttonState[1]);
    }
}
コード例 #3
0
ファイル: joystick.c プロジェクト: Pa0l0ne/Amiga360
static void read_joy (unsigned int nr)
{
    unsigned int num, i, axes, axis;
    SDL_Joystick *joy;

    if (currprefs.input_selected_setting == 0) {
		if (jsem_isjoy (0, &currprefs) != (int)nr && jsem_isjoy (1, &currprefs) != (int)nr)
		    return;
    }
    joy = joys[nr].joy;
    axes = SDL_JoystickNumAxes (joy);
    for (i = 0; i < axes; i++) {
		axis = SDL_JoystickGetAxis (joy, i);
		setjoystickstate (nr, i, axis, 32767);
    }

    num = SDL_JoystickNumButtons (joy);
    for (i = 0; i < num; i++) {
		int bs = SDL_JoystickGetButton (joy, i) ? 1 : 0;
		setjoybuttonstate (nr, i, bs);	

		if (i == 10 && bs == 1)
		{
			inputdevice_add_inputcode (512, 1);
		}
    }
}
コード例 #4
0
ファイル: joystick.c プロジェクト: BackupTheBerlios/arp2-svn
static void read_joy(int nr)
{
    uae_joystick_t buffer;
    int len;
    int fd = nr == 0 ? js0 : js1;
    struct joy_range *r = nr == 0 ? &range0 : &range1;

    if (nr >= nr_joysticks)
	return;

    len = read(fd, &buffer, sizeof(buffer));
    if (len != sizeof(buffer))
	return;

    /* According to old 0.x JS API, we don't know the range
     * or the centre for either axis, so we try to work these
     * out as we go along.
     *
     * Must be a better way to do this . . .
     */
    if (buffer.x < r->minx) r->minx = buffer.x;
    if (buffer.y < r->miny) r->miny = buffer.y;
    if (buffer.x > r->maxx) r->maxx = buffer.x;
    if (buffer.y > r->maxy) r->maxy = buffer.y;

    r->centrex = (r->maxx-r->minx)/2 + r->minx;
    r->centrey = (r->maxy-r->miny)/2 + r->miny;

    /* Translate these values to be centred on 0 and
     * feed 'em to the inputdevice system */
    setjoystickstate (nr, 0, buffer.x - r->centrex, r->centrex );
    setjoystickstate (nr, 1, buffer.y - r->centrey, r->centrey );

#ifdef HAVE_MACHINE_JOYSTICK_H
    setjoybuttonstate (nr, 0, buffer.b1);
    setjoybuttonstate (nr, 1, buffer.b2);
#else
    setjoybuttonstate (nr, 0, buffer.buttons & 1);
    setjoybuttonstate (nr, 1, buffer.buttons & 2);
#endif
}
コード例 #5
0
ファイル: pandora_input.cpp プロジェクト: lubomyr/uae4arm
static void read_joystick (void)
{
  int i, j;
  Uint8 *keystate = NULL;

	for (i = 0; i < num_joystick; i++) {
		struct pidata *pid = &pi_joystick[i];
		if (!pid->acquired)
			continue;

		if(keystate == NULL)
  	  keystate = SDL_GetKeyState(NULL);

    // dPad is joystick only without right shoulder
    if(!keystate[SDLK_RCTRL]) {
      int axis = (keystate[SDLK_LEFT] ? -32767 : (keystate[SDLK_RIGHT] ? 32767 : 0));
      setjoystickstate (i, 0, axis, 32767);
      axis = (keystate[SDLK_UP] ? -32767 : (keystate[SDLK_DOWN] ? 32767 : 0));
      setjoystickstate (i, 1, axis, 32767);
    }
    for (j = 0; j < pid->buttons; ++j)
      setjoybuttonstate (i, j, keystate[pid->button_keycode[j]]);
	}
}
コード例 #6
0
ファイル: joystick.cpp プロジェクト: ApolloniaUK/PUAE
void UAEJoystick :: read ()
{
    DEBUG_LOG ("read: polling joy:%d\n", this->nr);

    if (this->Update () != B_ERROR) {

	/* Read axis values */
	{
	    unsigned int nr_axes = this->CountAxes ();
	    int16        values[nr_axes];
	    unsigned int axis;

	    this->GetAxisValues (values);

	    for (axis = 0; axis < nr_axes; axis++)
		setjoystickstate (this->nr, axis, values[axis], 32767);
	}
コード例 #7
0
ファイル: joystick.c プロジェクト: CrashSerious/PiUAE
static void read_joy (unsigned int num)
{
    struct joystick *joy = &joystickList[num];

    if (joy->handle) {
	void *buffer;

	/*
	 * Poll device for data
	 */
	if (AIN_ReadDevice (joy->context, joy->handle, &buffer)) {
	    unsigned int i;

	    /* Extract axis data from buffer and notify UAE of any changes
	     * in axis state
	     */
	    for (i = 0; i < joy->axisCount; i++) {
		int axisdata = BUFFER_OFFSET (buffer, joy->axisBufferOffset[i]);

		if (axisdata != joy->axisData[i]) {
		    setjoystickstate (num, i, axisdata, 32767);
		    joy->axisData[i] = axisdata;
		}
	    }

	    /* Extract button data from buffer and notify SDL of any changes
	     * in button state
	     *
	     * Note: We don't support analog buttons.
	     */
	    for (i = 0; i < joy->buttonCount; i++) {
		int buttondata = BUFFER_OFFSET (buffer, joy->buttonBufferOffset[i]);

		if (buttondata != joy->buttonData[i]) {
		    setjoybuttonstate (num, i, buttondata ? 1 : 0);
		    joy->buttonData[i] = buttondata;
		}
	    }

	}
    }
}
コード例 #8
0
ファイル: libretro-mapper.c プロジェクト: gbraad/libretro-uae
void update_input(void)
{
   int i;	
   //   RETRO      B    Y    SLT  STA  UP   DWN  LEFT RGT  A    X    L    R    L2   R2   L3   R3
   //   INDEX      0    1    2    3    4    5    6    7    8    9    10   11   12   13   14   15
   static int vbt[16]={0x1C,0x39,0x01,0x3B,0x01,0x02,0x04,0x08,0x80,0x6D,0x15,0x31,0x24,0x1F,0x6E,0x6F};
   static int oldi=-1;
   static int vkx=0,vky=0;

   MXjoy0=0;

   if(oldi!=-1)
   {
      retro_key_up(oldi);
      oldi=-1;
   }

   input_poll_cb();
   Process_key();

   if (key_state[RETROK_F11] || input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y))
   {
      pauseg=1;
      //enter_gui(); //old
   }

   i=3;//show vkey toggle
   if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) && mbt[i]==0 )
      mbt[i]=1;
   else if ( mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) )
   {
      mbt[i]=0;
      SHOWKEY=-SHOWKEY;
      Screen_SetFullUpdate();
   }

   i=2;//mouse/joy toggle
   if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) && mbt[i]==0 )
      mbt[i]=1;
   else if ( mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) )
   {
      mbt[i]=0;
      MOUSEMODE=-MOUSEMODE;
   }

   i=10;//num joy toggle
   if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) && mbt[i]==0 )
      mbt[i]=1;
   else if ( mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) )
   {
      mbt[i]=0;
      NUMJOY++;if(NUMJOY>1)NUMJOY=0;
      NUMjoy=-NUMjoy;
   }

   i=11;//mouse gui speed
   if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) && mbt[i]==0 )
      mbt[i]=1;
   else if ( mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) )
   {
      mbt[i]=0;
      PAS++;if(PAS>MAXPAS)PAS=1;
   }


   /*
   //FIXME
   i=9;//switch shift On/Off 
   if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) && mbt[i]==0 )
   mbt[i]=1;
   else if ( mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) )
   {
   mbt[i]=0;
   SHIFTON=-SHIFTON;
   Screen_SetFullUpdate();
   }
   */

   i=12;//show/hide statut
   if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) && mbt[i]==0 )
      mbt[i]=1;
   else if (mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i))
   {
      mbt[i]=0;
      STATUTON=-STATUTON;
      Screen_SetFullUpdate();
   }

   i=13;//sonud on/off
   if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) && mbt[i]==0 )
      mbt[i]=1;
   else if ( mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) )
   {
      mbt[i]=0;
      SND=-SND;
      //Screen_SetFullUpdate();
   }

   if(SHOWKEY==1)
   {
      static int vkflag[5]={0,0,0,0,0};		

      if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP) && vkflag[0]==0 )
         vkflag[0]=1;
      else if (vkflag[0]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP) )
      {
         vkflag[0]=0;
         vky -= 1; 
      }

      if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN) && vkflag[1]==0 )
         vkflag[1]=1;
      else if (vkflag[1]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN) )
      {
         vkflag[1]=0;
         vky += 1; 
      }

      if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT) && vkflag[2]==0 )
         vkflag[2]=1;
      else if (vkflag[2]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT) )
      {
         vkflag[2]=0;
         vkx -= 1;
      }

      if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT) && vkflag[3]==0 )
         vkflag[3]=1;
      else if (vkflag[3]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT) )
      {
         vkflag[3]=0;
         vkx += 1;
      }

      if(vkx < 0)
         vkx=9;
      if(vkx > 9)
         vkx=0;
      if(vky < 0)
         vky=4;
      if(vky > 4)
         vky=0;

      virtual_kdb(bmp,vkx,vky);

      i=8;
      if(input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i)  && vkflag[4]==0) 	
         vkflag[4]=1;
      else if( !input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i)  && vkflag[4]==1)
      {

         vkflag[4]=0;
         i=check_vkey2(vkx,vky);

         if(i==-2)
         {
            NPAGE=-NPAGE;oldi=-1;
            //Clear interface zone					
            Screen_SetFullUpdate();
         }
         else if(i==-1)
            oldi=-1;
         else if(i==-3)
         {//KDB bgcolor
            Screen_SetFullUpdate();
            KCOL=-KCOL;
            oldi=-1;
         }
         else if(i==-4)
         {//VKbd show/hide 			
            oldi=-1;
            Screen_SetFullUpdate();
            SHOWKEY=-SHOWKEY;
         }
         else if(i==-5)
         {//Change Joy number
            NUMjoy=-NUMjoy;
            oldi=-1;
         }
         else
         {
            if(i==0x60/*AK_LSH*/)
            {
               if(SHIFTON == 1)
                  retro_key_up(i);
               else retro_key_down(i);

               SHIFTON=-SHIFTON;

               Screen_SetFullUpdate();

               oldi=-1;
            }
            else
            {
               oldi=i;
               retro_key_down(i);
            }
         }				
      }

      if(STATUTON==1)
         Print_Statut();

      return;
   }

   static int mbL=0,mbR=0;
   int mouse_l;
   int mouse_r;
   int16_t mouse_x;
   int16_t mouse_y;

   if(MOUSEMODE==-1)
   { //Joy mode
      al[0] =(input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X));
      al[1] =(input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y));

      setjoybuttonstate (0,0,input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A));
      setjoybuttonstate (0,1,input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B));

      if(opt_analog)
      {
         setjoystickstate  (0, 0, al[0], 32767);
         setjoystickstate  (0, 1, al[1], 32767);   
      }
      else
      {
         for(i=4;i<8/*9*/;i++)
            if( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) )
               MXjoy0 |= vbt[i]; // Joy press	
         retro_joy0(MXjoy0);
      }

      mouse_x = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X);
      mouse_y = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y);
      mouse_l    = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT);
      mouse_r    = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_RIGHT);

      fmousex=mouse_x;
      fmousey=mouse_y;

   }
   else
   {  //Mouse mode
      fmousex=fmousey=0;

      //ANALOG RIGHT
      ar[0] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X));
      ar[1] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y));

      if(ar[0]<=-1024)
         fmousex-=(-ar[0])/1024;
      if(ar[0]>= 1024)
         fmousex+=( ar[0])/1024;
      if(ar[1]<=-1024)
         fmousey-=(-ar[1])/1024;
      if(ar[1]>= 1024)
         fmousey+=( ar[1])/1024;

      //PAD
      if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT))
         fmousex += PAS;
      if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT))
         fmousex -= PAS;
      if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN))
         fmousey += PAS;
      if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP))
         fmousey -= PAS;

      mouse_l=input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A);
      mouse_r=input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B);
   }

   if(mbL==0 && mouse_l)
   {
      mbL=1;		
      retro_mouse_but0(1);
   }
   else if(mbL==1 && !mouse_l)
   {
      retro_mouse_but0(0);
      mbL=0;
   }

   if(mbR==0 && mouse_r)
   {
      mbR=1;
      retro_mouse_but1(1);
   }
   else if(mbR==1 && !mouse_r)
   {
      retro_mouse_but1(0);
      mbR=0;
   }

   retro_mouse(fmousex, fmousey);

   if(STATUTON==1)
      Print_Statut();
}