Esempio n. 1
0
void
ui_joystick_poll( void )
{
  int i;

  for( i = 0; i < joysticks_supported; i++ ) poll_joystick( i );
}
Esempio n. 2
0
void osd_poll_joysticks(void)
{
	updatekeyboard();

	if (joystick > JOY_TYPE_NONE)
		poll_joystick();
}
// updates all joystick states
void poll_joysticks( void )
{
	joydown = false;
	
	for (int j = 0; j < joysticks; j++)
		poll_joystick(j);
}
Esempio n. 4
0
void osd_poll_joysticks(void)
{
	//sched_yield();//???

	updatekeyboard();

	if (joystick > JOY_TYPE_NONE)
		poll_joystick();
}
Esempio n. 5
0
/* install_joystick:
 *  Initialises the joystick module.
 */
int install_joystick(int type)
{
   int c;

   if (_joystick_installed)
      return 0;

   clear_joystick_vars();

   allegro_error[0] = 0;

   /* search table for a specific driver */
   for (c=0; _joystick_driver_list[c].driver; c++) { 
      if (_joystick_driver_list[c].driver_id == type) {
	 joystick_driver = _joystick_driver_list[c].driver;
	 joy_type = type;
	 if (joystick_driver->init() != 0) {
	    if (!allegro_error[0])
	       sprintf(allegro_error, get_config_text("%s not found"), joystick_driver->name);
	    joystick_driver = NULL; 
	    joy_type = JOY_TYPE_NONE;
	    return -1;
	 }
	 break;
      }
   }

   /* autodetect driver */
   if (!joystick_driver) {
      if (!joy_loading) {
	 if (load_joystick_data(NULL) == 0)
	    return 0;
      }

      for (c=0; _joystick_driver_list[c].driver; c++) {
	 if (_joystick_driver_list[c].autodetect) {
	    joystick_driver = _joystick_driver_list[c].driver;
	    joy_type = _joystick_driver_list[c].driver_id;
	    if (_joystick_driver_list[c].driver->init() == 0)
	       break;
	 }
      }
   }

   for (c=0; c<num_joysticks; c++)
      update_calib(c);

   poll_joystick();

   _add_exit_func(remove_joystick);
   _joystick_installed = TRUE;

   return 0;
}
Esempio n. 6
0
void Game::update()
{
  poll_joystick();

  // Character movements (runs only every 2nd loop)
  if(frames_done % 2 == 0){
    character.update(tile_map);

    for(int i = 0; i < badGuy.size(); i++){
      badGuy.at(i) -> update(newTileMap, &character);
    }
  }

  // Tile map positions
  newTileMap -> x = tile_map -> x;
  newTileMap -> y = tile_map -> y;

  if(key[KEY_R]){
    enemy* newBadGuy = new enemy( character.getX(), character.getY(), enemy_mutant);
    newBadGuy -> load_images();
    newBadGuy -> load_sounds();
    badGuy.push_back(newBadGuy);
    rest(10);
  }
  if(key[KEY_T]){
    enemy* newBadGuy = new enemy( character.getX(), character.getY(), enemy_sentry);
    newBadGuy -> load_images();
    newBadGuy -> load_sounds();
    badGuy.push_back(newBadGuy);
    rest(100);
  }

  // Back to menu
  if( key[KEY_M] || joy[0].button[6].b){
    set_next_state( STATE_MENU);
  }

  // Die
  if(character.getDead() || character.getFinishLevel()){
    init();
    character.setFinishLevel( false);
  }

  // Respawn
  if(key[KEY_Y]){
    character.spawncommand(tile_map);
  }
}
void joystick_poll()
{
        int c;
        
        poll_joystick();

        for (c = 0; c < MIN(num_joysticks, 2); c++)
        {                
                joystick_state[c].x = joy[c].stick[0].axis[0].pos * 256;
                joystick_state[c].y = joy[c].stick[0].axis[1].pos * 256;
                joystick_state[c].b[0] = joy[c].button[0].b;
                joystick_state[c].b[1] = joy[c].button[1].b;
                joystick_state[c].b[2] = joy[c].button[2].b;
                joystick_state[c].b[3] = joy[c].button[3].b;
        }
}
Esempio n. 8
0
int any_joystick_input(void)
{
 if (options.joystick)
  poll_joystick();

  if (joy[0].stick[options.joy_stick].axis[0].pos < - MENU_SENSE
   || joy[0].stick[options.joy_stick].axis[0].pos > MENU_SENSE
   || joy[0].stick[options.joy_stick].axis[1].pos < -MENU_SENSE
   || joy[0].stick[options.joy_stick].axis[1].pos > MENU_SENSE)
    return 1;

   if (joy[0].button[options.joy_button [0]].b)
    return 1;

 return 0;
}
Esempio n. 9
0
/* handles fade effects and timing for the ready, steady, go messages */
static int fade_intro_item(int music_pos, int fade_speed)
{
   while (midi_pos < music_pos) {
      if (keypressed())
         return TRUE;

      poll_joystick();

      if ((joy[0].button[0].b) || (joy[0].button[1].b))
         return TRUE;
   }

   set_palette(data[GAME_PAL].dat);
   fade_out(fade_speed);

   return FALSE;
}
Esempio n. 10
0
void Controls()
{
		poll_joystick();

		BUTTON.UP = (key[Buttons_UP] || joy[0].stick[0].axis[1].d1)	 ? 1 : 0;
		BUTTON.DOWN = (key[Buttons_DOWN] || joy[0].stick[0].axis[1].d2)	 ? 1 : 0;
		BUTTON.LEFT = (key[Buttons_LEFT] || joy[0].stick[0].axis[0].d1)	 ? 1 : 0;
		BUTTON.RIGHT = (key[Buttons_RIGHT] || joy[0].stick[0].axis[0].d2)	 ? 1 : 0;
		
		BUTTON.A = (key[Buttons_A] || joy[0].button[Joypad_A].b) ? 1 : 0;
		BUTTON.B = (key[Buttons_B] || joy[0].button[Joypad_B].b) ? 1 : 0;
		BUTTON.C = (key[Buttons_C] || joy[0].button[Joypad_C].b) ? 1 : 0;
		BUTTON.D = (key[Buttons_D] || joy[0].button[Joypad_D].b) ? 1 : 0;
		BUTTON.START = (key[Buttons_START] || joy[0].button[Joypad_START].b)	 ? 1 : 0;
		BUTTON.SELECT = (key[Buttons_SELECT] || joy[0].button[Joypad_SELECT].b)	 ? 1 : 0;
		BUTTON.QUIT = key[Buttons_QUIT] ? 1 : 0;
}
Esempio n. 11
0
int menu_command(int cmd)
{

 if (options.joystick)
  poll_joystick();

 switch(cmd)
 {
  case MC_UP:
   if (key [KEY_UP] || key [KEY_8_PAD])
    return 1;
   if (options.joystick && joy[0].stick[options.joy_stick].axis[1].pos < -MENU_SENSE)
    return 1;
   return 0;
  case MC_DOWN:
   if (key [KEY_DOWN] || key [KEY_2_PAD])
    return 1;
   if (options.joystick && joy[0].stick[options.joy_stick].axis[1].pos > MENU_SENSE)
    return 1;
   return 0;
  case MC_LEFT:
   if (key [KEY_LEFT] || key [KEY_4_PAD])
    return 1;
   if (options.joystick && joy[0].stick[options.joy_stick].axis[0].pos < -MENU_SENSE)
    return 1;
   return 0;


  case MC_RIGHT:
   if (key [KEY_RIGHT] || key [KEY_6_PAD])
    return 1;
   if (options.joystick && joy[0].stick[options.joy_stick].axis[0].pos > MENU_SENSE)
    return 1;
   return 0;
  case MC_SELECT:
   if (key [KEY_SPACE] || key [KEY_ENTER] || key [KEY_ENTER_PAD] || key [KEY_Z])
    return 1;
   if (options.joystick && joy[0].button[options.joy_button [0]].b)
    return 1;
   return 0;

 }

 return 0;

}
Esempio n. 12
0
/*============================================================================*/
Byte in_bus()
{
	Byte si=0,d=0,mode=0,jn=0,sticknum=0;

	if ((p1 & 0x08) && (p1 & 0x10)) {
		/* Handle joystick read */
		if (!(p1 & 0x04)) {
			si = (p2 & 7);
		}
		d=0xFF;
		if (si == 1) {
			mode = app_data.stick[0];
			jn = 0;
			sticknum = app_data.sticknumber[0]-1;
		} else {
			mode = app_data.stick[1];
			jn = 1;
			sticknum = app_data.sticknumber[1]-1;
		}
		switch(mode) {
			case 1:
				d = keyjoy(jn);
				break;
			case 2:
				#ifndef __O2EM_SDL__
				/* TODO for SDL */
				poll_joystick();
				#endif
				if (joy[sticknum].stick[0].axis[1].d1) d &= 0xFE;			/* joy_up*/
				if (joy[sticknum].stick[0].axis[0].d2) d &= 0xFD;			/* joy_right*/
				if (joy[sticknum].stick[0].axis[1].d2) d &= 0xFB;			/* joy_down*/
				if (joy[sticknum].stick[0].axis[0].d1) d &= 0xF7;			/* joy_left*/
				if (joy[sticknum].button[0].b || joy[jn].button[1].b) d &= 0xEF;	/* both main-buttons*/
				break;
		}
		if (si == 1) {
			if (dbstick1) d = dbstick1;
		} else {
			if (dbstick2) d = dbstick2;
		}
   }
   return d;
}
Esempio n. 13
0
/* load_joystick_data:
 *  Restores a set of joystick calibration data previously saved by
 *  save_joystick_data().
 */
int load_joystick_data(char *filename)
{
   int ret, c;

   joy_loading = TRUE;

   if (_joystick_installed)
      remove_joystick();

   if (filename) {
      push_config_state();
      set_config_file(filename);
   }

   joy_type = get_config_id("joystick", "joytype", -1);

   if (joy_type < 0) {
      joy_type = JOY_TYPE_NONE;
      ret = -1;
   }
   else {
      ret = install_joystick(joy_type);

      if (ret == 0) {
	 if (joystick_driver->load_data)
	    ret = joystick_driver->load_data();
      }
   }

   if (filename)
      pop_config_state();

   if (ret == 0) {
      for (c=0; c<num_joysticks; c++)
	 update_calib(c);

      poll_joystick();
   }

   joy_loading = FALSE;

   return ret;
}
Esempio n. 14
0
//******************************************************************************
// Función tcj_comprobar()
//    Comprueba el estado del teclado y/o joystick/joypad para actualizar los
//    valores de la tabla tcj_estado.
//******************************************************************************
void tcj_comprobar()
 {
  char f;
 
  // inicializamos y hacemos los polls necesarios
  for(f=0;f<8+TCJ_NUM_BOTONES;tcj_estado[f++]=0);
  if(ini_t) poll_keyboard();
  if(ini_j) poll_joystick();

  // Comprobamos las cuatro direcciones básicas.
  for(f=0;f<TCJ_MAX_ENTRADAS*4;f++)
    if(entrada[f]) if(*entrada[f]) tcj_estado[(f/TCJ_MAX_ENTRADAS)*2]=1;

  // En función de las cuatro básicas, informamos las cuatro de suma.
  if(tcj_estado[TCJ_ARR] && tcj_estado[TCJ_ABJ])
    tcj_estado[TCJ_ARR]=tcj_estado[TCJ_ABJ]=0;
  if(tcj_estado[TCJ_IZQ] && tcj_estado[TCJ_DER])
    tcj_estado[TCJ_IZQ]=tcj_estado[TCJ_DER]=0;
  if(tcj_estado[TCJ_ARR] && tcj_estado[TCJ_DER])
   {
    tcj_estado[TCJ_ARR]=tcj_estado[TCJ_DER]=0;
    tcj_estado[TCJ_A_D]=1;
   }
  if(tcj_estado[TCJ_ARR] && tcj_estado[TCJ_IZQ])
   {
    tcj_estado[TCJ_ARR]=tcj_estado[TCJ_IZQ]=0;
    tcj_estado[TCJ_A_I]=1;
   }
  if(tcj_estado[TCJ_ABJ] && tcj_estado[TCJ_DER])
   {
    tcj_estado[TCJ_ABJ]=tcj_estado[TCJ_DER]=0;
    tcj_estado[TCJ_B_D]=1;
   }
  if(tcj_estado[TCJ_ABJ] && tcj_estado[TCJ_IZQ])
   {
    tcj_estado[TCJ_ABJ]=tcj_estado[TCJ_IZQ]=0;
    tcj_estado[TCJ_B_I]=1;
   }
  
  // Comprobamos las acciones.
  for(;f<TCJ_MAX_ENTRADAS*(4+TCJ_NUM_BOTONES);f++)
    if(entrada[f]) if(*entrada[f]) tcj_estado[(f/TCJ_MAX_ENTRADAS)+4]=1;
}
Esempio n. 15
0
/*
    ti99_handset_task()
    Manage handsets, posting an event if the state of any handset has changed.
*/
void ti99_handset_device::do_task()
{
	int i;

	if (m_buflen == 0)
	{
		/* poll every handset */
		for (i=0; i < MAX_HANDSETS; i++)
			if (poll_joystick(i)==true) return;
		for (i=0; i < MAX_HANDSETS; i++)
			if (poll_keyboard(i)==true) return;
	}
	else if (m_buflen == 3)
	{   /* update messages after they have been posted */
		if (m_buf & 1)
		{   /* keyboard */
			poll_keyboard((~(m_buf >> 1)) & 0x3);
		}
		else
		{   /* joystick */
Esempio n. 16
0
Byte in_bus(void){
	Byte si=0,d=0,mode=0,jn=0,sticknum=0;

	if ((p1 & 0x08) && (p1 & 0x10)) {
		/* Handle joystick read */
		if (!(p1 & 0x04)) {
			si = (p2 & 7);
		}
		d=0xFF;
		if (si == 1) {
			mode = app_data.stick[0];
			jn = 0;
			sticknum = app_data.sticknumber[0]-1;
		} else {
			mode = app_data.stick[1];
			jn = 1;
			sticknum = app_data.sticknumber[1]-1;
		}
		switch(mode) {
			case 1:
				d = keyjoy(jn);
				break;
			case 2: 
				poll_joystick();
				if (joy[sticknum].stick[0].axis[1].d1) d &= 0xFE;			// joy_up
				if (joy[sticknum].stick[0].axis[0].d2) d &= 0xFD;			// joy_right
				if (joy[sticknum].stick[0].axis[1].d2) d &= 0xFB;			// joy_down
				if (joy[sticknum].stick[0].axis[0].d1) d &= 0xF7;			// joy_left
				if (joy[sticknum].button[0].b || joy[jn].button[1].b) d &= 0xEF;	// both main-buttons
				break;
		}
		if (si == 1) {
			if (dbstick1) d = dbstick1;
		} else {
			if (dbstick2) d = dbstick2;
		}
   }
   return d;
}
Esempio n. 17
0
void Menu::getInput(){
     poll_joystick();
     if(inputTimer <= 0){
          if(key[KEY_UP]||joy[0].stick[0].axis[1].d1){
               selectNum--;
               if(selectNum < 0)
                    selectNum = selections.size()-1;
               play_sample(scrollSnd,100,128,1000,false);
               inputTimer = 40;
          }else if(key[KEY_DOWN]||joy[0].stick[0].axis[1].d2){
               selectNum++;
               if(selectNum >= selections.size())
                    selectNum = 0;
               play_sample(scrollSnd,100,128,1000,false);
               inputTimer = 40;
          }else if(key[KEY_ENTER]||joy[0].button[0].b){
               play_sample(selectSnd,100,128,1000,false);
               choice = selections[selectNum];
               inputTimer = 40;
          }
     }
     inputTimer--;
}
Esempio n. 18
0
void Menu::update(){
  // Disable/Enable mouse control on input
  if(key[KEY_UP] || key[KEY_DOWN] || key[KEY_LEFT] || key[KEY_RIGHT] || key[KEY_W] || key[KEY_A] || key[KEY_S] || key[KEY_D] || joy[0].stick[0].axis[1].d2 || joy[0].stick[0].axis[1].d1 || joy[0].button[4].b || joy[0].button[5].b)
    mouse_control=false;
  else if (mouse_x!=old_mouse_x || mouse_y!=old_mouse_y)
    mouse_control=true;

  old_mouse_x = mouse_x;
  old_mouse_y = mouse_y;

  menuOpen = false;
  poll_joystick();

  // Move around live background
  if( scrollDirection == "right"){
    if( tile_map -> x + 1 < (tile_map -> width * 64 - SCREEN_W)){
      tile_map -> x += 1;
    }
    else{
      scrollDirection = "left";
    }
  }
  else if( scrollDirection == "left"){
    if( tile_map -> x - 1 > 0){
      tile_map -> x -= 1;
    }
    else{
      scrollDirection = "right";
    }
  }


  // Move selector
  if( selectorY != newSelectorY){
    int selectorVelocity;
    if( newSelectorY != selectorY){
      selectorVelocity = (newSelectorY - selectorY )/ 6;
      if( newSelectorY - selectorY < 0){
        selectorVelocity -= 1;
      }
      else if( newSelectorY - selectorY > 0){
        selectorVelocity += 1;
      }
    }
    selectorY += selectorVelocity;
  }
  if((key[KEY_W] || key[KEY_UP] || joy[0].stick[0].axis[1].d1) && step>10){
    if(selectorHovering!=0)
      selectorHovering--;
    else
      selectorHovering=3;
    step=0;
  }
  if((key[KEY_S] || key[KEY_DOWN] || joy[0].stick[0].axis[1].d2) && step>10){
    if(selectorHovering!=3)
      selectorHovering++;
    else
      selectorHovering=0;
    step=0;
  }

  // Hover play
  if((mouse_control && (collisionAny(mouse_x,mouse_x,60,270,mouse_y,mouse_y, SCREEN_H-323, SCREEN_H-278)) || !mouse_control && ( selectorHovering==0))){
    if(newSelectorY != SCREEN_H-323){
      newSelectorY = SCREEN_H-323;
      selectorX = 60;
      play_sample(click,255,125,1000,0);
    }

  }
  // Hover edit
  else if((mouse_control && (collisionAny(mouse_x,mouse_x,60,270,mouse_y,mouse_y, SCREEN_H-260, SCREEN_H-215)) || !mouse_control && ( selectorHovering==1))){
    if(newSelectorY != SCREEN_H-260){
      newSelectorY = SCREEN_H-260;
      selectorX = 60;
      play_sample(click,255,125,1000,0);
    }

  }
  // Hover help
  else if((mouse_control && (collisionAny(mouse_x,mouse_x,60,270,mouse_y,mouse_y, SCREEN_H-197, SCREEN_H-152)) || !mouse_control && ( selectorHovering==2))){
    if(newSelectorY != SCREEN_H-197){
      newSelectorY = SCREEN_H-197;
      selectorX = 60;
      play_sample(click,255,125,1000,0);
    }
    menuOpen = true;
  }
  //Hover exit
  else if((mouse_control && (collisionAny(mouse_x,mouse_x,60,270,mouse_y,mouse_y, SCREEN_H-132, SCREEN_H-87)) || !mouse_control && ( selectorHovering==3))){
    if(newSelectorY != SCREEN_H-132){
      newSelectorY = SCREEN_H-132;
      selectorX = 60;
      play_sample(click,255,125,1000,0);
    }
  }

  // Select button
  // level select left
  if(((collisionAny(mouse_x,mouse_x,SCREEN_W-180,SCREEN_W-140,mouse_y,mouse_y, 80, 120) && mouse_b & 1) || (key[KEY_A] || key[KEY_LEFT] || joy[0].button[4].b)) && step>10) {
    play_sample(click,255,125,1000,0);
    if( levelOn > 0){
      levelOn--;
    }
    else{
      levelOn = 3;
    }
    if( levelOn == 0){
      tile_map -> load( "data/levels/level_01");
    }
    else if( levelOn == 1){
      tile_map -> load( "data/levels/level_test");
    }
    else if( levelOn == 2){
      tile_map -> load( "data/saves/danny");
    }
    else if( levelOn == 3){
      tile_map -> load( "data/saves/dannyII");
    }
    tile_map -> y = random( 0, (tile_map -> height * 64) - SCREEN_H);
    tile_map -> x = 0;
    step=0;
  }
  if(((collisionAny(mouse_x,mouse_x,SCREEN_W-80,SCREEN_W-40,mouse_y,mouse_y, 80, 120) && mouse_b & 1) || (key[KEY_D] || key[KEY_RIGHT] || joy[0].button[5].b)) && step>10){
  // level select right
    play_sample(click,255,125,1000,0);
    if( levelOn < 3){
      levelOn++;
    }
    else{
      levelOn = 0;
    }
    if( levelOn == 0){
      tile_map -> load( "data/levels/level_01");
    }
    else if( levelOn == 1){
      tile_map -> load( "data/levels/level_test");
    }
    else if( levelOn == 2){
      tile_map -> load( "data/saves/danny");
    }
    else if( levelOn == 3){
      tile_map -> load( "data/saves/dannyII");
    }
    tile_map -> y = random( 0, (tile_map -> height * 64) - SCREEN_H);
    tile_map -> x = 0;
    step=0;
  }
  // Start
  if(((collisionAny(mouse_x,mouse_x,60,270,mouse_y,mouse_y,  SCREEN_H-323, SCREEN_H-278)&& mouse_b & 1)|| ((key[KEY_ENTER] || joy[0].button[0].b) && selectorHovering==0)) && step>10){
    set_next_state( STATE_GAME);
  }
  // Edit
  if(((collisionAny(mouse_x,mouse_x,60,270,mouse_y,mouse_y, SCREEN_H-260, SCREEN_H-215)&& mouse_b & 1)|| ((key[KEY_ENTER] || joy[0].button[0].b) && selectorHovering==1)) && step>10){
    set_next_state( STATE_EDIT);
  }
  // Quit
  if(((collisionAny(mouse_x,mouse_x,60,270,mouse_y,mouse_y,  SCREEN_H-132, SCREEN_H-87)&& mouse_b & 1)|| ((key[KEY_ENTER] || joy[0].button[0].b) && selectorHovering==3)) && step>10){
    set_next_state( STATE_EXIT);
  }
  step++;
}
Esempio n. 19
0
int
main (int argc, char *argv[]) 
{
  int DesiredJoystick = 0, i, j, Joystick, Stick, Axis, Offset, Changed = 0;
  float Factor;
  char *s;

#ifdef WIN32
  Out = stdout; // fopen ("yaACA.txt", "w");
#else
  Out = stdout;
#endif

  fprintf (Out, "Apollo Attitude Controller Assembly (ACA) emulation, version " NVER 
  	  ", built " __DATE__ "\n");
  fprintf (Out, "(c)2005,2009 Ronald S. Burkey\n");
  fprintf (Out, "Refer to http://www.ibiblio.org/apollo/index.html for more information.\n");
  fflush (Out);
  
  // Initialize Allegro.
Retry:
  allegro_init ();
  if (install_joystick (JOY_TYPE_AUTODETECT) || num_joysticks <= 0)
    {
      fprintf (Out, "Couldn\'t find any joysticks. Retrying ...\n");
      fflush (Out);
      //return (1);
#ifdef WIN32
      Sleep (5000);	    
#else // WIN32
      {
	struct timespec req, rem;
	req.tv_sec = 5;
	req.tv_nsec = 0;
	nanosleep (&req, &rem);
      }
#endif // WIN32
      allegro_exit ();
      goto Retry;
    }
    
    {
      GetParameters (Controller);
           
      //fprintf (Out, "%d joysticks found:\n", num_joysticks);
      for (i = 0; i < num_joysticks; i++)
        {
	  int k;
	  fprintf (Out, "Joystick device #%d:\n", i);
	  if (joy[i].flags & JOYFLAG_DIGITAL)
	    fprintf (Out, "\tThis control provides a digital input.\n");
	  else if (joy[i].flags & JOYFLAG_ANALOGUE)
	    fprintf (Out, "\tThis control provides an analog input.\n");
	  else if (joy[i].flags & JOYFLAG_CALIB_DIGITAL)
	    fprintf (Out, "\tThis control will provide a digital input after calibration.\n");
	  else if (joy[i].flags & JOYFLAG_CALIB_ANALOGUE)
	    fprintf (Out, "\tThis control will provide an analog input after calibration.\n"); 
	  else if (joy[i].flags & JOYFLAG_CALIBRATE)
	    fprintf (Out, "\tThis control needs calibration.\n");
	  else if (joy[i].flags & JOYFLAG_SIGNED)
	    fprintf (Out, "\tThis control provides signed data (i.e., -127 to 127).\n");
	  else if (joy[i].flags & JOYFLAG_UNSIGNED)
	    fprintf (Out, "\tThis control provides unsigned data (i.e., 0 to 255).\n");
	  for (j = 0; j < joy[i].num_sticks; j++)
	    {
	      fprintf (Out, "\tStick #%d of joystick device #%d:\n", j, i);
	      if (joy[i].stick[j].flags & JOYFLAG_DIGITAL)
		fprintf (Out, "\t\tThis control provides a digital input.\n");
	      else if (joy[i].stick[j].flags & JOYFLAG_ANALOGUE)
		fprintf (Out, "\t\tThis control provides an analog input.\n");
	      else if (joy[i].stick[j].flags & JOYFLAG_CALIB_DIGITAL)
		fprintf (Out, "\t\tThis control will provide a digital input after calibration.\n");
	      else if (joy[i].stick[j].flags & JOYFLAG_CALIB_ANALOGUE)
		fprintf (Out, "\t\tThis control will provide an analog input after calibration.\n"); 
	      else if (joy[i].stick[j].flags & JOYFLAG_CALIBRATE)
		fprintf (Out, "\t\tThis control needs calibration.\n");
	      else if (joy[i].stick[j].flags & JOYFLAG_SIGNED)
		fprintf (Out, "\t\tThis control provides signed data (i.e., -127 to 127).\n");
	      else if (joy[i].stick[j].flags & JOYFLAG_UNSIGNED)
		fprintf (Out, "\t\tThis control provides unsigned data (i.e., 0 to 255).\n");
	      fprintf (Out, "\t\tDescription = %s\n", joy[i].stick[j].name);
	      for (k = 0; k < joy[i].stick[j].num_axis; k++)
	        fprintf (Out, "\t\tAxis #%d description = %s\n", k, joy[i].stick[j].axis[k].name);
	    }
	  for (j = 0; j < joy[i].num_buttons; j++)
	    {
	      fprintf (Out, "\tButton %d = %s\n", j, joy[i].button[j].name);
	    }
	}
      fprintf (Out, "\n");
      fprintf (Out, "Note that only 3 degrees of freedom and no buttons are used by yaACA.\n");
      fprintf (Out, "Right roll, upward pitch, and clockwise yaw are positive values.\n");
      fprintf (Out, "Left roll, downward pitch, and counter-clockwise yaw are negative values.\n");
    }
    
  // Parse the command-line arguments.
  for (i = 1; i < argc; i++)
    {
      if (!strcmp (argv[i], "--help"))
        {
	  fprintf (Out, 
	    "\n"
	    "USAGE:\n"
	    "\tyaACA [OPTIONS]\n"
	    "The recognized options are:\n"
	    "--help\n"
	    "\tDisplays this message.\n"
	    "--roll=J,S,A,F,O  or  --pitch=J,S,A,F,O  or  --yaw=J,S,A,F,O\n"
	    "\tThese options allow you to configure how the roll/pitch/yaw degrees\n"
	    "\tof freedom map to the characteristics of the joystick as recognized\n"
	    "\tby the computer's operating system.  J is the joystick number (in \n"
	    "\tcase multiple joysticks are installed), S is the stick number within\n"
	    "\tthe joystick, and A is the axis within the stick.  F is a factor which\n"
	    "\tthe joystick reading is multiplied by, and O is an offset added to the\n"
	    "\tjoystick reading (after multiplication is completed).  The factor is \n"
	    "\tuseful (for example) in swapping right-to-left, back-to-front, or \n"
	    "\tclockwise-to-counter-clockwise.  The offset would be useful when the\n"
	    "\tthe joystick provides unsigned readings (0-255) rather than the desired\n"
	    "\tsigned readings (-127 to 127).  The defaults are:\n"
	    "\t\t\tRoll\t\t0,0,0,+1.0,0\n"
	    "\t\t\tPitch\t\t0,0,1,+1.0,0\n"
#ifdef __APPLE__
	    "\t\t\tYaw\t\t0,2,0,+1.0,%d\n"
#else	    
	    "\t\t\tYaw\t\t0,1,0,+1.0,%d\n"
#endif
	    "\t(By the way, the defaults work with a Logitech Extreme 3D Pro.)\n"
	    "\tAlthough it would appear that you can select a different joystick\n"
	    "\tcontroller (the first field) for each of the pitch/roll/yaw axes,\n"
	    "\tyou really cannot, so please do not do so.  For versions 20090406\n"
	    "\tand later, your selections are automatically stored in a configuration\n"
	    "\tfile called yaACA-N.cfg, where N is the joystick controller number,\n"
	    "\tand become the new defaults the next time the program is run.  In\n"
	    "\tother words, once you've determined the appropriate command-line\n"
	    "\tsettings for --roll, --pitch, and --yaw, you don't need to use the\n"
	    "\tcommand-line parameters again.  An exception is if the joystick\n"
	    "\tcontroller-number is non-zero.  If so, you will need to use at least\n"
	    "\tone of these command-line switches every time, or else the saved\n"
	    "\tsettings for controller 0 will be used.\n"
	    "--ip=Hostname\n"
	    "\tThe yaACA program and the yaAGC Apollo Guidance Computer simulation\n"
	    "\texist in a \"client/server\" relationship, in which the yaACA program\n"
	    "\tneeds to be aware of the IP address or symbolic name of the host\n"
	    "\tcomputer running the yaAGC program.  By default, this is \"localhost\",\n"
	    "\tmeaning that both yaACA and yaAGC are running on the same computer.\n"
            "--port=Portnumber\n"
	    "\tBy default, yaACA attempts to connect to the yaAGC program using port\n"
	    "\tnumber %d.  However, if more than one instance of yaACA is being\n"
	    "\trun, or if yaAGC has been configured to listen on different ports, then\n"
	    "\tdifferent port settings for yaACA are needed.  Note that by default,\n"
	    "\tyaAGC listens for new connections on ports 19697-19706, but that the\n"
	    "\trecommended port range when using yaAGC in the LM is 19797-19806.\n",
	    YawOffset, sPortnum
	  );
	  fprintf (Out, "--delay=N\n");
	  fprintf (Out, "\t\"Start-up delay\", in ms.  Defaults to %d.  What the start-up\n", StartupDelay);
	  fprintf (Out, "\tdelay does is to prevent yaACA from attempting to communicate with\n");
	  fprintf (Out, "\tyaAGC for a brief time after power-up.  This option is really only\n");
	  fprintf (Out, "\tuseful in Win32, to work around a problem with race-conditions in\n");
	  fprintf (Out, "\tat start-up time.\n");
	  return (0);
	}
      else if (5 == sscanf (argv[i], "--roll=%d,%d,%d,%f,%d", &Joystick, &Stick, &Axis, &Factor, &Offset) ||
               5 == sscanf (argv[i], "--pitch=%d,%d,%d,%f,%d", &Joystick, &Stick, &Axis, &Factor, &Offset) ||
	       5 == sscanf (argv[i], "--yaw=%d,%d,%d,%f,%d", &Joystick, &Stick, &Axis, &Factor, &Offset) )
        {
	  if (Joystick >= 0 && Joystick < num_joysticks)
	    {
	      DesiredJoystick = Joystick;
	      if (Stick < 0 || Stick >= joy[Joystick].num_sticks)
	        {
		  fprintf (Out, "\nJoystick #%d stick numbers must be >=0 and < %d.  Sorry!\n",
		          Joystick, joy[Joystick].num_sticks);
		  return (1);
		}
	      if (Axis < 0 || Axis >= joy[Joystick].stick[Stick].num_axis)
	        {
		  fprintf (Out, "\nJoystick #%d, stick #%d axis numbers must be >=0 and < %d.  Sorry!\n",
		          Joystick, Stick, joy[Joystick].stick[Stick].num_axis);
		  return (1);
		}
	      if (0 == (JOYFLAG_ANALOGUE & joy[Joystick].stick[Stick].flags))
	        {
		  fprintf (Out, "\nJoystick #%d, stick #%d is not analog.  Sorry!\n",
		          Joystick, Stick);
		  return (1);
		}
	      if ('r' == argv[i][2])
	        {
	          Roll = &joy[Joystick].stick[Stick].axis[Axis].pos;
		  RollFactor = Factor;
		  RollOffset = Offset;
		  Controller = Joystick;
		  RollStick = Stick;
		  RollAxis = Axis;
		  Changed = 1;
		}
	      else if ('p' == argv[i][2])
	        {
	          Pitch = &joy[Joystick].stick[Stick].axis[Axis].pos;
		  PitchFactor = Factor;
		  PitchOffset = Offset;
		  Controller = Joystick;
		  PitchStick = Stick;
		  PitchAxis = Axis;
		  Changed = 1;
		}
	      else
	        {
	          Yaw = &joy[Joystick].stick[Stick].axis[Axis].pos;
		  YawFactor = Factor;
		  YawOffset = Offset;
		  Controller = Joystick;
		  YawStick = Stick;
		  YawAxis = Axis;
		  Changed = 1;
		}
	    }
	  else
	    {
	      fprintf (Out, "\nJoystick numbers must be >= 0 and < %d.  Sorry!\n", num_joysticks);
	      return (1);
	    }  
	}
      else if (1 == sscanf (argv[i], "--delay=%d", &j))
        StartupDelay = j;
      else 
        {
	  fprintf (Out, "Unknown command-line switch \"%s\".\n", argv[i]);
	  fprintf (Out, "Try \"yaACA --help\".\n");
	  return (1);
	}	
    }
  if (Changed || !CfgExisted)
    WriteParameters (Controller);
    
  // Set up variables for quick access to just the desired joystick, and check for minimum
  // requirements.  Note that the ACA requires no pushbuttons (there are associated toggle
  // switches, but they're not physically on the hand-control, and they are toggle switches
  // anyhow).  
  s = (char *) calibrate_joystick_name (DesiredJoystick);
  if (s != NULL)
    {
      fprintf (Out, "%s\n", calibrate_joystick_name (DesiredJoystick));
      if (calibrate_joystick (DesiredJoystick))
	{
	  fprintf (Out, "Joystick calibration problem.\n");
	  return (1);
	}
    }
  PrintJoy ();
    
  // Now we start polling the joystick from time to time.  The way Allegro works is to 
  // maintain an array containing info on each joystick.  This array is updated only when
  // poll_joystick is called (which you have to do explicitly).  To see what has changed,
  // we maintain a copy of the joy[] array.
  while (1)
    {
      // Sleep for a while so that this job won't monopolize CPU cycles.
#ifdef WIN32
      Sleep (UPDATE_INTERVAL);	    
#else // WIN32
      struct timespec req, rem;
      req.tv_sec = 0;
      req.tv_nsec = 1000000 * UPDATE_INTERVAL;
      nanosleep (&req, &rem);
#endif // WIN32
      poll_joystick ();				// Get joystick values.
      PrintJoy ();				// Display them locally.
      PulseACA ();				// Manage server connection.
#if 0      
      {
        static int Count = 0;
        fprintf (Out, "*");
	Count++;
	if (Count >= 32)
	  {
	    Count = 0;
	    fflush (Out);
	  }
      }
#endif      
    }

  return (0);
}
Esempio n. 20
0
File: main.c Progetto: hoglet67/b-em
void main_run()
{
    int c, d;

    if (key[KEY_PGUP]) {
        bemfreerun = 1;
        old_key_pgup = 1;
    }
    else if (old_key_pgup) {
        old_key_pgup = 0;
        if (!key[KEY_LSHIFT] && !key[KEY_RSHIFT])
            bemfreerun = 0;
    }

    if (bemfreerun == 2) {
        // A key was pressed while freerunning; disable freerun temporarily
        // until no key is pressed any more.
        if (!key_any_down())
            bemfreerun = 1;
    }

        if ((fcount > 0 || (bemfreerun == 1) || (motor && fasttape)))
        {
                if (autoboot) autoboot--;
                fcount--;
                framesrun++;
                if (bemfreerun || (motor && fasttape)) fcount=0;
                if (x65c02) m65c02_exec();
                else        m6502_exec();
                ddnoiseframes++;
                if (ddnoiseframes >= 5)
                {
                        ddnoiseframes = 0;
                        ddnoise_mix();
                }
                key_check();
                poll_joystick();
                for (c = 0; c < 2; c++)
                {
                        joybutton[c] = 0;
                        for (d = 0; d < joy[c].num_buttons; d++)
                        {
                                if (joy[c].button[d].b) joybutton[c] = 1;
                        }
                }
                if (savestate_wantload) savestate_doload();
                if (savestate_wantsave) savestate_dosave();
                if (key[KEY_F10] && (debug_core || debug_tube)) debug_step = 1;
                if (key[KEY_F12] && !resetting)
                {
                        m6502_reset();
                        video_reset();
                        i8271_reset();
                        wd1770_reset();
                        sid_reset();
                        music5000_reset();

                        if (curtube != -1) tubes[curtube].reset();
                        tube_reset();
                }
                resetting = key[KEY_F12];
        }
        else
        {
                framesrun = 0;
                rest(1);
        }
        if (key[KEY_PGDN] && !old_key_pgdn)
            bempause ^= 1;
        old_key_pgdn = key[KEY_PGDN];
        if (key[KEY_RIGHT] && !old_key_right && bempause)
            bemstep = 1;
        old_key_right = key[KEY_RIGHT];
        if (framesrun > 10) fcount = 0;
}
Esempio n. 21
0
void osd_update_inputs(void)
{
    /* Reset input states */
    input.system    = 0;
    input.pad[0]    = 0;
    input.pad[1]    = 0;
    input.analog[0] = 0x7F;
    input.analog[1] = 0x7F;

    /* Alt+W : Dump work RAM */
    if((key[KEY_ALT] || key[KEY_ALTGR]) && check_key(KEY_W))
        dump_wram();

    /* Alt+V : Dump video RAM */
    if((key[KEY_ALT] || key[KEY_ALTGR]) && check_key(KEY_V))
        dump_vram();

    /* DEL : User-requested hard reset */
    if(check_key(KEY_DEL))
        system_reset();

    /* ENTER | SPACE : SMS PAUSE or GG START button */
    if(key[KEY_ENTER] || key[KEY_SPACE])
        input.system |= (IS_GG) ? INPUT_START : INPUT_PAUSE;

    /* Player #1 inputs */
    if(key[KEY_UP])         input.pad[0] |= INPUT_UP;
    else
    if(key[KEY_DOWN])       input.pad[0] |= INPUT_DOWN;
    if(key[KEY_LEFT])       input.pad[0] |= INPUT_LEFT;
    else
    if(key[KEY_RIGHT])      input.pad[0] |= INPUT_RIGHT;
    if(key[KEY_A])          input.pad[0] |= INPUT_BUTTON2;
    if(key[KEY_S])          input.pad[0] |= INPUT_BUTTON1;

    /* Player #2 inputs */
    if(key[KEY_8_PAD])      input.pad[1] |= INPUT_UP;
    else
    if(key[KEY_2_PAD])      input.pad[1] |= INPUT_DOWN;
    if(key[KEY_4_PAD])      input.pad[1] |= INPUT_LEFT;
    else
    if(key[KEY_6_PAD])      input.pad[1] |= INPUT_RIGHT;
    if(key[KEY_1_PAD])      input.pad[1] |= INPUT_BUTTON2;
    if(key[KEY_3_PAD])      input.pad[1] |= INPUT_BUTTON1;

    /* TAB : SMS RESET button */
    if(key[KEY_TAB])
        input.system |= INPUT_RESET;

    /* Check for any joysticks present */
    if(option.joy_driver != JOY_TYPE_NONE)
    {              
        poll_joystick();

        /* Parse player 1 joystick state */
        if(joy[0].stick[0].axis[1].d1) input.pad[0] |= INPUT_UP;
        else
        if(joy[0].stick[0].axis[1].d2) input.pad[0] |= INPUT_DOWN;
        if(joy[0].stick[0].axis[0].d1) input.pad[0] |= INPUT_LEFT;
        else
        if(joy[0].stick[0].axis[0].d2) input.pad[0] |= INPUT_RIGHT;
        if(joy[0].button[0].b)  input.pad[0] |= INPUT_BUTTON2;
        if(joy[0].button[1].b)  input.pad[0] |= INPUT_BUTTON1;
        if(joy[0].button[2].b)  input.system |= (IS_GG) ? INPUT_START : INPUT_PAUSE;

        /* Check if a 2nd joystick is present */
        if(num_joysticks > 2)
        {
            /* Parse player 2 joystick state  */
            if(joy[1].stick[0].axis[1].d1) input.pad[1] |= INPUT_UP;
            else
            if(joy[1].stick[0].axis[1].d2) input.pad[1] |= INPUT_DOWN;
            if(joy[1].stick[0].axis[0].d1) input.pad[1] |= INPUT_LEFT;
            else
            if(joy[1].stick[0].axis[0].d1) input.pad[1] |= INPUT_RIGHT;
            if(joy[1].button[0].b)  input.pad[1] |= INPUT_BUTTON2;
            if(joy[1].button[1].b)  input.pad[1] |= INPUT_BUTTON1;
        }
    }

    /* Check if a mouse is present. */
    if(use_mouse)
    {
        int temp;

        /* Poll mouse if necessary */
        if(mouse_needs_poll() == TRUE)
            poll_mouse();

        /* Calculate X axis value */
        temp = mouse_x;
        if(temp > 0xFF) temp = 0xFF;
        if(temp < 0x00) temp = 0x00;
        input.analog[0] = temp;

        /* Calculate Y axis value */
        temp = mouse_y;
        if(temp > 0xFF) temp = 0xFF;
        if(temp < 0x00) temp = 0x00;
        input.analog[1] = temp;

        /* Map mouse buttons to player #1 inputs */
        if(mouse_b & 4) input.pad[0] |= (IS_GG) ? INPUT_START : INPUT_PAUSE;
        if(mouse_b & 2) input.pad[0] |= INPUT_BUTTON2;
        if(mouse_b & 1) input.pad[0] |= INPUT_BUTTON1;
    }
}
Esempio n. 22
0
int cControls::ProcessActions()
{
   uInt32 i;
   sControl ctrl;

   // allegro get keyboard, joystick, and mouse info
   poll_keyboard();
   poll_joystick();
   //

   // error check
   if(m_player == NULL) return 1;
   if(m_game == NULL)   return 1;

   if(info == NULL)
      return 2;

   info->Reset();
   //

   //////////////////////////////////////////////////////////////
   // check player
   for(i = 0; i < m_gsize; ++i)
   {
      ctrl =  m_game[i];

      // Keyboard
      if(ctrl.key != -1)
      {
         if( key[ ctrl.key ] ) // key is allegro variable
         {
            info->g[ ctrl.action ] = true;
         }
      }
      //

      // JoyStick
      if(ctrl.joy_num != -1)
      {
         if(ctrl.joy_type == 1) // stick
         {
            if( ctrl.joy_pos > 0) // if greater then zero, check if pressed is greater then
            {
               if( joy[ ctrl.joy_num ].
                   stick[ ctrl.joy_stick ].
                   axis[ ctrl.joy_axis ].pos > ctrl.joy_pos )
               {
                  info->g[ ctrl.action ] = true;
               }
            } else {  // if less then zero, check if pressed is less then
               if( joy[ ctrl.joy_num ].
                   stick[ ctrl.joy_stick ].
                   axis[ ctrl.joy_axis ].pos < ctrl.joy_pos )
               {
                  info->g[ ctrl.action ] = true;
               }
            }
         } 
         else if(ctrl.joy_type == 2) // button
         {
            if( joy[ ctrl.joy_num ].button[ ctrl.joy_button ].b == 1 )
            {
               info->g[ ctrl.action ] = true;  
            }
         }
      }
      //
   }
   //
   //////////////////////////////////////////////////////////////


   //////////////////////////////////////////////////////////////
   // check player
   for(i = 0; i < m_psize; ++i)
   {
      ctrl =  m_player[i];

      // Keyboard
      if(ctrl.key != -1)
      {
         if( key[ ctrl.key ] ) // key is allegro variable
         {
            info->p[ ctrl.player ][ ctrl.action ] = true;
         }
      }
      //

      // JoyStick
      if(ctrl.joy_num != -1)
      {
         if(ctrl.joy_type == 1) // stick
         {
            if( ctrl.joy_pos > 0) // if greater then zero, check if pressed is greater then
            {
               if( joy[ ctrl.joy_num ].
                   stick[ ctrl.joy_stick ].
                   axis[ ctrl.joy_axis ].pos > ctrl.joy_pos )
               {
                  info->p[ ctrl.player ][ ctrl.action ] = true;
               }
            } else {  // if less then zero, check if pressed is less then
               if( joy[ ctrl.joy_num ].
                   stick[ ctrl.joy_stick ].
                   axis[ ctrl.joy_axis ].pos < ctrl.joy_pos )
               {
                  info->p[ ctrl.player ][ ctrl.action ] = true;
               }
            }
         } 
         else if(ctrl.joy_type == 2) // button
         {
            if( joy[ ctrl.joy_num ].button[ ctrl.joy_button ].b == 1 )
            {
               info->p[ ctrl.player ][ ctrl.action ] = true;  
            }
         }
      }
      //
   }
   //
   //////////////////////////////////////////////////////////////

   // pointer, todo
   // mouse
   /*
      mouse_x
   */

   return 0;
}
Esempio n. 23
0
void eof_read_controller(EOF_CONTROLLER * cp)
{
//	eof_log("eof_read_controller() entered");

	int i;

	if(!cp)
	{
		return;
	}
	(void) poll_joystick();
	for(i = 0; i < EOF_CONTROLLER_MAX_BUTTONS; i++)
	{
		switch(cp->button[i].type)
		{
			case EOF_CONTROLLER_BUTTON_TYPE_KEY:
			{
				if(key[cp->button[i].key])
				{
					cp->button[i].held++;
					if(cp->button[i].held == 1)
					{
						cp->button[i].pressed = 1;
					}
					else
					{
						cp->button[i].pressed = 0;
					}
				}
				else
				{
					if(cp->button[i].held)
					{
						cp->button[i].pressed = 0;
						cp->button[i].released = 1;
						cp->button[i].held = 0;
					}
					else
					{
						cp->button[i].pressed = 0;
						cp->button[i].released = 0;
					}
				}
				break;
			}
			case EOF_CONTROLLER_BUTTON_TYPE_JOYBUTTON:
			{
				if(joy[cp->button[i].joy].button[cp->button[i].key].b)
				{
					cp->button[i].held++;
					if(cp->button[i].held == 1)
					{
						cp->button[i].pressed = 1;
					}
					else
					{
						cp->button[i].pressed = 0;
					}
				}
				else
				{
					if(cp->button[i].held)
					{
						cp->button[i].pressed = 0;
						cp->button[i].released = 1;
						cp->button[i].held = 0;
					}
					else
					{
						cp->button[i].pressed = 0;
						cp->button[i].released = 0;
					}
				}
				break;
			}
			case EOF_CONTROLLER_BUTTON_TYPE_JOYAXIS:
			{
				if(cp->button[i].d == 0)
				{
					if(joy[cp->button[i].joy].stick[cp->button[i].index].axis[cp->button[i].key].d1)
					{
						cp->button[i].held++;
						if(cp->button[i].held == 1)
						{
							cp->button[i].pressed = 1;
						}
						else
						{
							cp->button[i].pressed = 0;
						}
					}
					else
					{
						if(cp->button[i].held)
						{
							cp->button[i].pressed = 0;
							cp->button[i].released = 1;
							cp->button[i].held = 0;
						}
						else
						{
							cp->button[i].pressed = 0;
							cp->button[i].released = 0;
						}
					}
				}
				else
				{
					if(joy[cp->button[i].joy].stick[cp->button[i].index].axis[cp->button[i].key].d2)
					{
						cp->button[i].held++;
						if(cp->button[i].held == 1)
						{
							cp->button[i].pressed = 1;
						}
						else
						{
							cp->button[i].pressed = 0;
						}
					}
					else
					{
						if(cp->button[i].held)
						{
							cp->button[i].pressed = 0;
							cp->button[i].released = 1;
							cp->button[i].held = 0;
						}
						else
						{
							cp->button[i].pressed = 0;
							cp->button[i].released = 0;
						}
					}
				}
				break;
			}
		}
	}
}
	void InputDeviceSingleton::UpdateJoystick()
	{
		poll_joystick();
	}
Esempio n. 25
0
void ReadJoysticks ()
{
    if (num_sidewinders == 0 && !grip_initialised)
    {
	poll_joystick ();
	if (!joystick_has_four_buttons && !joystick_has_six_buttons &&
	    !joystick_has_eight_buttons)
	{
	    if (joy_b1 ^ old_joy_b1)
	    {
		if (joy_b1)
		    joypads [0] |= SNES_A_MASK;
		else
		    joypads [0] &= ~SNES_A_MASK;
	    }
	    if (joy_b2 ^ old_joy_b2)
	    {
		if (joy_b2)
		    joypads [0] |= SNES_B_MASK;
		else
		    joypads [0] &= ~SNES_B_MASK;
	    }
	}
	else
	{
	    if (joy_b1 ^ old_joy_b1)
	    {
		if (joy_b1)
		    joypads [0] |= SNES_Y_MASK;
		else
		    joypads [0] &= ~SNES_Y_MASK;
	    }
	    if (joy_b2 ^ old_joy_b2)
	    {
		if (joy_b2)
		    joypads [0] |= SNES_X_MASK;
		else
		    joypads [0] &= ~SNES_X_MASK;
	    }
	}
	if (joy_b3 ^ old_joy_b3)
	{
	    if (joy_b3)
		joypads [0] |= SNES_B_MASK;
	    else
		joypads [0] &= ~SNES_B_MASK;
	}
	if (joy_b4 ^ old_joy_b4)
	{
	    if (joy_b4)
		joypads [0] |= SNES_A_MASK;
	    else
		joypads [0] &= ~SNES_A_MASK;
	}
	if (joy_b5 ^ old_joy_b5)
	{
	    if (joy_b5)
		joypads [0] |= SNES_TL_MASK;
	    else
		joypads [0] &= ~SNES_TL_MASK;
	}
	if (joy_b6 ^ old_joy_b6)
	{
	    if (joy_b6)
		joypads [0] |= SNES_TR_MASK;
	    else
		joypads [0] &= ~SNES_TR_MASK;
	}
	if (joy_b7 ^ old_joy_b7)
	{
	    if (joy_b7)
		joypads [0] |= SNES_SELECT_MASK;
	    else
		joypads [0] &= ~SNES_SELECT_MASK;
	}
	if (joy_b8 ^ old_joy_b8)
	{
	    if (joy_b8)
		joypads [0] |= SNES_START_MASK;
	    else
		joypads [0] &= ~SNES_START_MASK;
	}
	if (joy_left ^ old_joy_left)
	{
	    if (joy_left)
		joypads [0] |= SNES_LEFT_MASK;
	    else
		joypads [0] &= ~SNES_LEFT_MASK;
	}
	if (joy_right ^ old_joy_right)
	{
	    if (joy_right)
		joypads [0] |= SNES_RIGHT_MASK;
	    else
		joypads [0] &= ~SNES_RIGHT_MASK;
	}
	if (joy_up ^ old_joy_up)
	{
	    if (joy_up)
		joypads [0] |= SNES_UP_MASK;
	    else
		joypads [0] &= ~SNES_UP_MASK;
	}
	if (joy_down ^ old_joy_down)
	{
	    if (joy_down)
		joypads [0] |= SNES_DOWN_MASK;
	    else
		joypads [0] &= ~SNES_DOWN_MASK;
	}

	if (!joystick_has_four_buttons && !joystick_has_six_buttons &&
	    !joystick_has_eight_buttons)
	{
	    if (joy2_b1 ^ old_joy2_b1)
	    {
		if (joy2_b1)
		    joypads [1] |= SNES_A_MASK;
		else
		    joypads [1] &= ~SNES_A_MASK;
	    }
	    if (joy2_b2 ^ old_joy2_b2)
	    {
		if (joy2_b2)
		    joypads [1] |= SNES_B_MASK;
		else
		    joypads [1] &= ~SNES_B_MASK;
	    }
	    if (joy2_left ^ old_joy2_left)
	    {
		if (joy2_left)
		    joypads [1] |= SNES_LEFT_MASK;
		else
		    joypads [1] &= ~SNES_LEFT_MASK;
	    }
	    if (joy2_right ^ old_joy2_right)
	    {
		if (joy2_right)
		    joypads [1] |= SNES_RIGHT_MASK;
		else
		    joypads [1] &= ~SNES_RIGHT_MASK;
	    }
	    if (joy2_up ^ old_joy2_up)
	    {
		if (joy2_up)
		    joypads [1] |= SNES_UP_MASK;
		else
		    joypads [1] &= ~SNES_UP_MASK;
	    }
	    if (joy2_down ^ old_joy2_down)
	    {
		if (joy2_down)
		    joypads [1] |= SNES_DOWN_MASK;
		else
		    joypads [1] &= ~SNES_DOWN_MASK;
	    }
	}
	old_joy_left = joy_left;
	old_joy_right = joy_right;
	old_joy_up = joy_up;
	old_joy_down = joy_down;
	old_joy_b1 = joy_b1;
	old_joy_b2 = joy_b2;
	old_joy_b3 = joy_b3;
	old_joy_b4 = joy_b4;
	old_joy_b5 = joy_b5;
	old_joy_b6 = joy_b6;
	old_joy_b7 = joy_b7;
	old_joy_b8 = joy_b8;
	old_joy2_left = joy2_left;
	old_joy2_right = joy2_right;
	old_joy2_up = joy2_up;
	old_joy2_down = joy2_down;
	old_joy2_b1 = joy2_b1;
	old_joy2_b2 = joy2_b2;
    }
}
Esempio n. 26
0
void joystickb_lgallegro_poll(void)
{
	unsigned j, s, a;

	log_debug(("joystickb:lgallegro: joystickb_lgallegro_poll()\n"));

	target_clock_t now = target_clock();

	if (lgallegro_option.filter == FILTER_AUTO
		|| lgallegro_option.filter == FILTER_TIME
	) {
		/* don't poll too frequently */
		if (now - lgallegro_state.last > TARGET_CLOCKS_PER_SEC / 30) {
			log_debug(("joystickb:lgallegro: effective poll\n"));
			lgallegro_state.last = now;
			poll_joystick();
		} else {
			log_debug(("joystickb:lgallegro: skipped poll\n"));
		}
	} else {
		lgallegro_state.last = now;
		poll_joystick();
	}

	for(j=0;j<joystickb_lgallegro_count_get();++j) {
		for(s=0;s<joystickb_lgallegro_stick_count_get(j);++s) {
			for(a=0;a<joystickb_lgallegro_stick_axe_count_get(j,s);++a) {
				struct joystick_axe_context* c = &lgallegro_state.map[j].axe_map[s][a];

				int r = joy[j].stick[s].axis[a].pos;

				if (lgallegro_option.filter == FILTER_VALUE) {
					int limit = 127;
					if (r <= -limit || r >= limit) {
						/* skip */
						continue;
					}
				}

				/* store the new values */
				c->v = r;
				c->d1 = joy[j].stick[s].axis[a].d1;
				c->d2 = joy[j].stick[s].axis[a].d2;

				/* update autocalibration */
				if (c->l == 0 && c->h == 0) {
					c->l = c->v;
					c->h = c->v;
				} else {
					if (c->v < c->l)
						c->l = c->v;
					if (c->v > c->h)
						c->h = c->v;
				}

				if (lgallegro_option.calibration == CALIBRATION_AUTO) {
					c->a = joystickb_adjust_analog(c->v, c->l, c->h);
				} else if (lgallegro_option.calibration == CALIBRATION_NONE) {
					c->a = joystickb_adjust_analog(c->v, -128, 128);
				} else {
					c->a = 0;
				}

				log_debug(("joystickb:lgallegro: id:%d,%d,%d,v:%d[%d:%d>%d]\n", j, s, a, c->v, c->l, c->h, c->a));
			}
		}
	}
}
Esempio n. 27
0
int main()
{
  initializeCrap();
  install_int_ex(increment_speed_counter,BPS_TO_TIMER(120));
  int screenMode = 0; //0 for windowed, 1 for fullscreen
  srand((unsigned)time(NULL));

  BITMAP *buffer = create_bitmap(800,600);
  BITMAP *titleimg = load_bitmap("quiximgTitle.bmp",NULL);
  BITMAP *imgPlayers = load_bitmap("quiximgPlayerSet.bmp",NULL);
  MIDI *song = load_midi("quixsong.mid");
  PlayerObject poPlayer[4];
  LaserObject loLaser[4];
  LevelObject Level;
  MenuObject Menu;
  float scrollerX = -150.0, scrollerY = 5.0;
  int winner;

  poPlayer[0].setControlScheme(0);
  poPlayer[1].setControlScheme(1);
  poPlayer[2].setControlScheme(2);
  poPlayer[3].setControlScheme(3);
  poPlayer[0].samSound = load_sample("quixp1Death.wav");
  poPlayer[1].samSound = load_sample("quixp2Death.wav");
  poPlayer[2].samSound = load_sample("quixp3Death.wav");
  poPlayer[3].samSound = load_sample("quixp4Death.wav");
  poPlayer[0].setX(32);
  poPlayer[0].setY(32);
  poPlayer[0].setDir('l');
  poPlayer[1].setX(32);
  poPlayer[1].setY(544);
  poPlayer[1].setDir('l');
  poPlayer[2].setX(736);
  poPlayer[2].setY(544);
  poPlayer[2].setDir('r');
  poPlayer[3].setX(736);
  poPlayer[3].setY(32);
  poPlayer[3].setDir('r');

  int mouseDown[21];    //Kind of a crappy array --- Each button is a #
                        //and it's set to true if that button was clicked.
  for (int i = 0; i < 20; i++) { mouseDown[i] = false; }

  while ( !Menu.isDone() )
  {
    while (speed_counter > 0)
    {
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
      /* ~~~~~~~~~~~~~~~~~~~~~ MENU SCREEN ~~~~~~~~~~~~~~~~~~~~~ */
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
      if ( Menu.getEnabled() == true ) {
        if (key[KEY_Z]) {
          if (Menu.getFullscreen() == true) { Menu.changeScreenSize(0); Menu.setFullscreen(false); }
          else { Menu.changeScreenSize(1); Menu.setFullscreen(true); }
        }

        if (mouse_b & 1)
        {
          mouseDownClick(&Menu, mouseDown);
        }
        else {
          mouseUp(&Menu, mouseDown, poPlayer, &Level, song);
        }
      }
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
      /* ~~~~~~~~~~~~~~~~~~~~~~~ IN-GAME ~~~~~~~~~~~~~~~~~~~~~~~ */
      /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
      else {

        //Player Input1
        if (key[KEY_ESC]) {
            play_midi(NULL, false);
          if (Menu.fragLimitHit == true) {
            Menu.fragLimitHit == false;

            for (int i=0; i<4; i++) {
              poPlayer[i].resetScore();
              poPlayer[i].resetDeaths();
            }

            poPlayer[0].setX(32);
            poPlayer[0].setY(32);
            poPlayer[0].setDir('l');
            poPlayer[1].setX(32);
            poPlayer[1].setY(544);
            poPlayer[1].setDir('l');
            poPlayer[2].setX(736);
            poPlayer[2].setY(544);
            poPlayer[2].setDir('r');
            poPlayer[3].setX(736);
            poPlayer[3].setY(32);
            poPlayer[3].setDir('r');

            Menu.fragLimitHit = false;

            Menu.resetPressed = false;
            mouseDown[19] = false;

          }
          Level.setEnabled(false); Menu.setEnabled(true);
        }
        for (int i=0; i<4; i++) {
          if (poPlayer[i].getControlScheme() == 0) {
            if (key[KEY_W]) { moveCharacter(Level, &poPlayer[i], i, 'u'); }
            if (key[KEY_A]) { moveCharacter(Level, &poPlayer[i], i, 'l'); }
            if (key[KEY_S]) { moveCharacter(Level, &poPlayer[i], i, 'd'); }
            if (key[KEY_D]) { moveCharacter(Level, &poPlayer[i], i, 'r'); }
            if (key[KEY_F]) {
              if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); }
            }
          }
          else if (poPlayer[i].getControlScheme() == 1) {
            if (key[KEY_I]) { moveCharacter(Level, &poPlayer[i], i, 'u'); }
            if (key[KEY_J]) { moveCharacter(Level, &poPlayer[i], i, 'l'); }
            if (key[KEY_K]) { moveCharacter(Level, &poPlayer[i], i, 'd'); }
            if (key[KEY_L]) { moveCharacter(Level, &poPlayer[i], i, 'r'); }
            if (key[KEY_H]) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } }
          }
          else if (poPlayer[i].getControlScheme() == 2) {
            if (key[KEY_UP]) { moveCharacter(Level, &poPlayer[i], i, 'u'); }
            if (key[KEY_LEFT]) { moveCharacter(Level, &poPlayer[i], i, 'l'); }
            if (key[KEY_DOWN]) { moveCharacter(Level, &poPlayer[i], i, 'd'); }
            if (key[KEY_RIGHT]) { moveCharacter(Level, &poPlayer[i], i, 'r'); }
            if (key[KEY_RCONTROL]) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } }
          }
          else if (poPlayer[i].getControlScheme() == 3) {
            if (key[KEY_8_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'u'); }
            if (key[KEY_4_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'l'); }
            if (key[KEY_2_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'd'); }
            if (key[KEY_6_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'r'); }
            if (key[KEY_PLUS_PAD]) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } }
          }
          else if(poPlayer[i].getControlScheme() == 4) {
            //Joystick #1
            poll_joystick();
            if (joy[0].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up
            if (joy[0].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left
            if (joy[0].stick[0].axis[1].d2) { moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down
            if (joy[0].stick[0].axis[0].d2) { moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right
            if (joy[0].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } }
          }
          else if(poPlayer[i].getControlScheme() == 5) {
            //Joystick #2
            poll_joystick();
            if (joy[1].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up
            if (joy[1].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left
            if (joy[1].stick[0].axis[1].d2) { moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down
            if (joy[1].stick[0].axis[0].d2) {moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right
            if (joy[1].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } }
          }
          else if(poPlayer[i].getControlScheme() == 6) {
            //Joystick #3
            poll_joystick();
            if (joy[2].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up
            if (joy[2].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left
            if (joy[2].stick[0].axis[1].d2) {moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down
            if (joy[2].stick[0].axis[0].d2) { moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right
            if (joy[2].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } }
          }
          else if(poPlayer[i].getControlScheme() == 7) {
            //Joystick #4
            poll_joystick();
            if (joy[3].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up
            if (joy[3].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left
            if (joy[3].stick[0].axis[1].d2) { moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down
            if (joy[3].stick[0].axis[0].d2) { moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right
            if (joy[3].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } }
          }
        }
        if (Level.timeForAPowerupTimer >= 60) { Level.timeForAPowerupTimer = 0; }
        else { Level.timeForAPowerupTimer++; }
      }
      if ( Level.getFrame() < 32 ) { Level.setFrame( Level.getFrame() + 1 ); }
      else { Level.setFrame(0); }

    //Score Bar
      if (Level.getFragLimit() != 0 && Level.getEnabled() == true) {
        scrollerX += 0.5;
        if (scrollerX >= 1200.0) { scrollerX = -150.0; }
      }
      for (int i=0; i<4; i++) {
        //Res circle
        if (poPlayer[i].getRespawnCounter() >= 0) {
          poPlayer[i].setRespawnCounter( poPlayer[i].getRespawnCounter() + 1);
        }
        //"Laser" movement
        if (loLaser[i].getEnabled() == true) {
          if (loLaser[i].getDir() == 'u') { loLaser[i].moveUp('l'); }
          else if (loLaser[i].getDir() == 'd') { loLaser[i].moveDown('l'); }
          else if (loLaser[i].getDir() == 'l') { loLaser[i].moveLeft('l'); }
          else if (loLaser[i].getDir() == 'r') { loLaser[i].moveRight('l'); }
          checkCollision(&loLaser[i], poPlayer, i, Level);
        }
        if ((poPlayer[i].returnScore() == Level.getFragLimit()) && (Level.getFragLimit() > 0)) {
          //Frag Limit hit
          Menu.fragLimitHit = true;
          winner = i;
        }
      }

      speed_counter--;
    }//while (speed_counter > 0)

    if ( Menu.getEnabled() == true ) {
      drawMenuStuff(buffer, Menu, titleimg, imgPlayers, Level);
    }
    else if (Menu.fragLimitHit == true) {
      //Show win window!
      floodfill  (buffer, 0, 0, makecol(0,0,0));
      textprintf(buffer,font,348,203,makecol(100,0,0), "Player %i Wins!", winner+1 );
      textprintf(buffer,font,347,202,makecol(150,0,0), "Player %i Wins!", winner+1 );
      textprintf(buffer,font,346,201,makecol(200,0,0), "Player %i Wins!", winner+1 );
      textprintf(buffer,font,345,200,makecol(255,0,0), "Player %i Wins!", winner+1 );

      textprintf(buffer,font,330,250,makecol(255,0,0), "Player 1 score: %i", poPlayer[0].returnScore() );
      textprintf(buffer,font,330,260,makecol(255,0,0), "Player 2 score: %i", poPlayer[1].returnScore() );
      textprintf(buffer,font,330,270,makecol(255,0,0), "Player 3 score: %i", poPlayer[2].returnScore() );
      textprintf(buffer,font,330,280,makecol(255,0,0), "Player 4 score: %i", poPlayer[3].returnScore() );

      textprintf(buffer,font,330,249,makecol(255,255,255), "Player 1 score: %i", poPlayer[0].returnScore() );
      textprintf(buffer,font,330,259,makecol(255,255,255), "Player 2 score: %i", poPlayer[1].returnScore() );
      textprintf(buffer,font,330,269,makecol(255,255,255), "Player 3 score: %i", poPlayer[2].returnScore() );
      textprintf(buffer,font,330,279,makecol(255,255,255), "Player 4 score: %i", poPlayer[3].returnScore() );

      textout_centre(buffer, font, "Hit esc to continue", 400, 300, makecol(255,255,255));
    }
    else {
      generateBackground(buffer, Level);
      drawCharacters(poPlayer, Level, buffer);
      drawScoreBar(buffer, poPlayer, scrollerX, scrollerY, Level);
      if (loLaser[0].getEnabled() == true) { drawLaser(loLaser[0], buffer, Level, 0); }
      if (loLaser[1].getEnabled() == true) { drawLaser(loLaser[1], buffer, Level, 1); }
      if (loLaser[2].getEnabled() == true) { drawLaser(loLaser[2], buffer, Level, 2); }
      if (loLaser[3].getEnabled() == true) { drawLaser(loLaser[3], buffer, Level, 3); }
    }


    acquire_screen();
    blit(buffer, screen, 0, 0, 0, 0, 800, 600);
    clear_bitmap(buffer);
    release_screen();
  }//while ( !Menu.isDone() )

    return 0;

  return 0;
}
Esempio n. 28
0
void    Inputs_CFG_Map_Change_Update (void)
{
    t_app_inputs_config *app = &Inputs_CFG; // Global instance

    int           i, j;
    bool          found;
    t_input_src * input_src;

    if (Inputs_CFG.Current_Map == -1)
        return;

    found = FALSE;
    input_src = Inputs.Sources[Inputs_CFG.Current_Source];

    // Pressing ESC cancel map change
    if (key[KEY_ESC])
    {
        found = TRUE;
        input_src->Map [Inputs_CFG.Current_Map].Idx = -1;
        key[KEY_ESC] = 0; // Disable the key to avoid it to have an effect now
        Msg (MSGT_USER_INFOLINE, Msg_Get (MSG_Inputs_Src_Map_Cancelled));
        Inputs_CFG_Map_Change_End ();
        return;
    }

    // Check if a key/button/axis can be used as the mapping
    switch (input_src->type)
    {
        // Keyboard ----------------------------------------------------------------
    case INPUT_SRC_TYPE_KEYBOARD:
        {
            for (i = 0; i < KEY_MAX; i++)
                if (key [i])
                {
                    const t_key_info *key_info = KeyInfo_FindByScancode(i);
                    if (key_info)
                    {
                        input_src->Map [Inputs_CFG.Current_Map].Idx = i;
                        input_src->Map [Inputs_CFG.Current_Map].Type = INPUT_MAP_TYPE_KEY;
                        key[i] = 0; // Disable the key to avoid it to have an effect now
                        found = TRUE;
                        Msg (MSGT_USER_INFOLINE, Msg_Get (MSG_Inputs_Src_Map_Keyboard_Ok), key_info->name);
                    }
                    else
                    {
                        Msg (MSGT_DEBUG, "KeyInfo_FindByScancode(%x) failed", i);
                    }
                    break;
                }
                break;
        }
#ifdef MEKA_JOY
        // Digital Joypad/Joystick -------------------------------------------------
    case INPUT_SRC_TYPE_JOYPAD:
        {
            JOYSTICK_INFO *joystick;
            poll_joystick(); // It is necessary ?
            joystick = &joy[input_src->Connection_Port];

            // Check buttons
            for (i = 0; i < joystick->num_buttons; i++)
                if (joystick->button [i].b)
                {
                    input_src->Map [Inputs_CFG.Current_Map].Idx = i;
                    input_src->Map [Inputs_CFG.Current_Map].Type = INPUT_MAP_TYPE_JOY_BUTTON;
                    joystick->button [i].b = 0; // Disable the button to avoid..
                    found = TRUE;
                    Msg (MSGT_USER_INFOLINE, Msg_Get (MSG_Inputs_Src_Map_Joypad_Ok_B), i);
                    break;
                }
                if (found)
                    break;

                // Check axis
                for (i = 0; i < joystick->num_sticks; i++)
                {
                    JOYSTICK_STICK_INFO *stick = &joystick->stick[i];
                    // Msg (MSGT_DEBUG, "stick %d, flags=%04X", i, stick->flags);
                    for (j = 0; j < stick->num_axis; j++)
                    {
                        JOYSTICK_AXIS_INFO *axis = &stick->axis[j];
                        // Msg (MSGT_DEBUG, "- axis %d - pos %d - d1 %d - d2 %d\n", j, axis->pos, axis->d1, axis->d2);
                        if (axis->d1 || axis->d2)
                        {
                            input_src->Map [Inputs_CFG.Current_Map].Idx = MAKE_STICK_AXIS_DIR (i, j, (axis->d1 ? 0 : 1));
                            input_src->Map [Inputs_CFG.Current_Map].Type = INPUT_MAP_TYPE_JOY_AXIS;
                            found = TRUE;
                            // Msg (MSGT_USER_INFOLINE, Msg_Get (MSG_Inputs_Src_Map_Joypad_Ok_A), i, j, (axis->d1 ? '-' : '+'));
                            axis->d1 = axis->d2 = 0; // Need to be done on last line
                            break;
                        }
                    }
                    if (found)
                        break;
                }
                break;
        }
#endif // #ifdef MEKA_JOY
        // Mouse -------------------------------------------------------------------
    case INPUT_SRC_TYPE_MOUSE:
        {
            // Buttons
            if (Inputs_CFG.Current_Map >= INPUT_MAP_BUTTON1)
            {
                int n = -1;
                if ((gui.mouse.buttons & 1) && !(gui.mouse.buttons_prev & 1))
                    n = 0;
                else if ((gui.mouse.buttons & 2) && !(gui.mouse.buttons_prev & 2))
                    n = 1;
                else if ((gui.mouse.buttons & 4) && !(gui.mouse.buttons_prev & 4))
                    n = 2;
                if (n != -1)
                {
                    input_src->Map [Inputs_CFG.Current_Map].Idx = n;
                    input_src->Map [Inputs_CFG.Current_Map].Type = INPUT_MAP_TYPE_MOUSE_BUTTON;
                    gui.mouse.buttons_prev = gui.mouse.buttons; // Note: eating mouse press FIXME
                    found = TRUE;
                    Msg (MSGT_USER_INFOLINE, Msg_Get (MSG_Inputs_Src_Map_Mouse_Ok_B), n+1);
                    break;
                }
            }
            // Axis
            /*
            if (Inputs_CFG.Current_Map <= INPUT_MAP_ANALOG_AXIS_Y)
            {
            static int save_mouse[3] = { -1, -1, -1 };
            if (mouse_x != save_mouse[0] && save_mouse[0] != -1)
            {
            input_src->Map [Inputs_CFG.Current_Map].Idx = input_src->Map [Inputs_CFG.Current_Map + 2].Idx = MAKE_AXIS (0);
            input_src->Map [Inputs_CFG.Current_Map].Type = input_src->Map [Inputs_CFG.Current_Map + 2].Type = INPUT_MAP_TYPE_MOUSE_AXIS;
            save_mouse[0] = -1;
            found = TRUE;
            break;
            }
            if (mouse_y != save_mouse[1] && save_mouse[1] != -1)
            {
            input_src->Map [Inputs_CFG.Current_Map].Idx = input_src->Map [Inputs_CFG.Current_Map + 2].Idx = MAKE_AXIS (1);
            input_src->Map [Inputs_CFG.Current_Map].Type = input_src->Map [Inputs_CFG.Current_Map + 2].Type = INPUT_MAP_TYPE_MOUSE_AXIS;
            save_mouse[1] = -1;
            found = TRUE;
            break;
            }
            if (mouse_z != save_mouse[2] && save_mouse[2] != -1)
            {
            input_src->Map [Inputs_CFG.Current_Map].Idx = input_src->Map [Inputs_CFG.Current_Map + 2].Idx = MAKE_AXIS (2);
            input_src->Map [Inputs_CFG.Current_Map].Type = input_src->Map [Inputs_CFG.Current_Map + 2].Type = INPUT_MAP_TYPE_MOUSE_AXIS;
            save_mouse[2] = -1;
            found = TRUE;
            break;
            }
            save_mouse[0] = mouse_x;
            save_mouse[1] = mouse_y;
            save_mouse[2] = mouse_z;
            }
            */
            break;
        }
    }

    if (!found)
        return;

    Inputs_CFG_Map_Change_End ();
    app->dirty = TRUE;
}
Esempio n. 29
0
int eof_controller_set_button(EOF_CONTROLLER_BUTTON * bp)
{
	int i, j, k;
	int count = 0;
	char ignore[4][8][2];
	char ignoreb[4][32];

	memset(ignore, 0, sizeof(ignore));
	memset(ignoreb, 0, sizeof(ignoreb));
	eof_log("eof_controller_set_button() entered", 1);

	if(!bp)
	{
		return 0;
	}
	while(!key[KEY_ESC])
	{
		/* scan keyboard keys first */
		for(i = 0; i < KEY_MAX; i++)
		{
			if((i != KEY_SPACE) && key[i])
			{
				bp->type = EOF_CONTROLLER_BUTTON_TYPE_KEY;
				bp->key = i;
				(void) ustrcpy(bp->name, scancode_to_name(i));
				return 1;
			}
		}

		/* scan joysticks */
		(void) poll_joystick();
		for(i = 0; i < num_joysticks; i++)
		{

			/* scan buttons */
			for(j = 0; j < joy[i].num_buttons; j++)
			{
				if(joy[i].button[j].b)
				{
					if(count == 0)
					{
						ignoreb[i][j] = 1;
					}
					else if(!ignoreb[i][j])
					{
						bp->type = EOF_CONTROLLER_BUTTON_TYPE_JOYBUTTON;
						bp->joy = i;
						bp->key = j;
						(void) snprintf(bp->name, sizeof(bp->name) - 1, "Joy %d %s", i, joy[i].button[j].name);
						return 1;
					}
				}
				else
				{
					ignoreb[i][j] = 0;
				}
			}

			/* scan sticks */
			for(j = 0; j < joy[i].num_sticks; j++)
			{
				for(k = 0; k < joy[i].stick[j].num_axis; k++)
				{
					if(joy[i].stick[j].axis[k].d1)
					{
						if(count == 0)
						{
							ignore[i][j][k] = 1;
						}
						else if(!ignore[i][j][k])
						{
							bp->type = EOF_CONTROLLER_BUTTON_TYPE_JOYAXIS;
							bp->joy = i;
							bp->index = j;
							bp->key = k;
							bp->d = 0;
							(void) snprintf(bp->name, sizeof(bp->name) - 1, "Joy %d %s Axis (-)", i, joy[i].stick[j].axis[k].name);
							return 1;
						}
					}
					else if(joy[i].stick[j].axis[k].d2)
					{
						if(count == 0)
						{
							ignore[i][j][k] = 1;
						}
						else if(!ignore[i][j][k])
						{
							bp->type = EOF_CONTROLLER_BUTTON_TYPE_JOYAXIS;
							bp->joy = i;
							bp->index = j;
							bp->key = k;
							bp->d = 1;
							(void) snprintf(bp->name, sizeof(bp->name) - 1, "Joy %d %s Axis (+)", i, joy[i].stick[j].axis[k].name);
							return 1;
						}
					}
				}
			}
		}
		count++;
		rest(10);
	}
	if(key[KEY_ESC])
	{	//If user pressed Escape, undefine this controller button
		(void) ustrcpy(bp->name, "(none)");
		bp->type=bp->joy=bp->index=bp->d=bp->key=bp->held=bp->pressed=bp->released = 0;
	}
	return 0;
}