Beispiel #1
0
int osd_is_joy_pressed(int joycode)
{
	int joy_num,stick;


	/* special case for mouse buttons */
	switch (joycode)
	{
		case MOUSE_BUTTON(1):
			return ExKey1 & GP2X_B; break;
		case MOUSE_BUTTON(2):
			return ExKey1 & GP2X_X; break;
		case MOUSE_BUTTON(3):
			return ExKey1 & GP2X_A; break;
	}

	joy_num = GET_JOYCODE_JOY(joycode);

	/* do we have as many sticks? */
	if (joy_num == 0 || joy_num > num_joysticks)
		return 0;
	joy_num--;

	stick = GET_JOYCODE_STICK(joycode);

	if (stick == 0)
	{
		/* buttons */
		int button;

		button = GET_JOYCODE_BUTTON(joycode);
		if (button == 0 || button > 6)
			return 0;
		button--;

		switch (joy_num)
		{
			case 0: return is_joy_button_pressed(button, ExKey1); break;
			case 1: return is_joy_button_pressed(button, ExKey2); break;
			case 2: return is_joy_button_pressed(button, ExKey3); break;
			case 3: return is_joy_button_pressed(button, ExKey4); break;
			default: break;
		}
	}
	else
	{
		/* sticks */
		int axis,dir;

		if (stick > 1)
			return 0;
		stick--;

		axis = GET_JOYCODE_AXIS(joycode);
		dir = GET_JOYCODE_DIR(joycode);

		if (axis == 0 || axis > 2)
			return 0;
		axis--;

		switch (joy_num)
		{
			case 0: return is_joy_axis_pressed(axis, dir, ExKey1); break;
			case 1: return is_joy_axis_pressed(axis, dir, ExKey2); break;
			case 2: return is_joy_axis_pressed(axis, dir, ExKey3); break;
			case 3: return is_joy_axis_pressed(axis, dir, ExKey4); break;
			default: break;
		}
	}

	return 0;
}
Beispiel #2
0
static void select_game(char *emu, char *game)
{
	extern int kiosk_mode;

	unsigned long keytimer=0;
	int keydirection=0, last_keydirection=0;

	/* No Selected game */
	strcpy(game,"builtinn");

	/* Clean screen */
	FE_DisplayScreen();

	gp2x_joystick_clear();	

	/* Wait until user selects a game */
	while(1)
	{
		game_list_view(&last_game_selected);
		FE_DisplayScreen();
       	gp2x_timer_delay(70000);

		while(1)
		{
            usleep(10000);
			gp2x_joystick_read();	

			last_keydirection=keydirection;
			keydirection=0;

			//Any keyboard key pressed?
			if(osd_is_sdlkey_pressed(pi_key[LEFT_1]) || osd_is_sdlkey_pressed(pi_key[RIGHT_1]) ||
			   osd_is_sdlkey_pressed(pi_key[UP_1]) || osd_is_sdlkey_pressed(pi_key[DOWN_1]) )
			{
				keydirection=1;
				break;
			}

			if(osd_is_sdlkey_pressed(pi_key[START_1]) || osd_is_sdlkey_pressed(pi_key[A_1]) ||
			   osd_is_sdlkey_pressed(pi_key[QUIT]) || osd_is_sdlkey_pressed(pi_key[SELECT_1]) )
			{
				break;
			}

			//Any stick direction?
			if(is_joy_axis_pressed (joyaxis_LR, 1, 0) || is_joy_axis_pressed (joyaxis_LR, 2, 0) ||
			   is_joy_axis_pressed (joyaxis_UD, 1, 0) || is_joy_axis_pressed (joyaxis_UD, 2, 0) )
			{
				keydirection=1;
				break;
			}

			//Any joy buttons pressed?
			if (ExKey1)
			{
				break;
			}

			//Used to delay the initial key press, but 
			//once pressed and held the delay will clear
			keytimer = gp2x_timer_read() + (TICKS_PER_SEC/2);

		}

		//Key delay
		if(keydirection && last_keydirection && gp2x_timer_read() < keytimer) {
			continue;
		}

		int updown=0;
		if(is_joy_axis_pressed (joyaxis_UD, 1, 0)) {last_game_selected--; updown=1;};
		if(is_joy_axis_pressed (joyaxis_UD, 2, 0)) {last_game_selected++; updown=1;};

		// Stop diagonals on game selection
		if(!updown) {
			if(is_joy_axis_pressed (joyaxis_LR, 1, 0)) last_game_selected-=21;
			if(is_joy_axis_pressed (joyaxis_LR, 2, 0)) last_game_selected+=21;
		}

		if (osd_is_sdlkey_pressed(pi_key[UP_1])) last_game_selected--;
		if (osd_is_sdlkey_pressed(pi_key[DOWN_1])) last_game_selected++;
		if (osd_is_sdlkey_pressed(pi_key[LEFT_1])) last_game_selected-=21;
		if (osd_is_sdlkey_pressed(pi_key[RIGHT_1])) last_game_selected+=21;

		if (!kiosk_mode)
		{
			if( osd_is_sdlkey_pressed(pi_key[QUIT]) || 
			    	(is_joy_button_pressed(pi_joy[START_1], ExKey1) && is_joy_button_pressed(pi_joy[SELECT_1], ExKey1)) ) {
				gp2x_exit();
			}
		}

		if (is_joy_button_pressed(pi_joy[A_1], ExKey1) || 
			osd_is_sdlkey_pressed(pi_key[A_1]) || 
			osd_is_sdlkey_pressed(pi_key[START_1]) )
		{
			/* Select the game */
			game_list_select(last_game_selected, game, emu);

			break;
		}

		if (is_joy_button_pressed(pi_joy[SELECT_1], ExKey1) || osd_is_sdlkey_pressed(pi_key[SELECT_1]) )
		{
           //Check if the game is already a favorite
            game_list_select(last_game_selected, game, emu);

            int foundfav=0;
            int counter=0;
            while(true) {
                if (favarray[counter][0] == '\0') break;    //Null is the array terminator
                if (strcasecmp(favarray[counter], game) == 0) {
                    foundfav=1;
                    break;
                }
                counter++;
            }

            if(foundfav) {
                favorites_remove(game);
            } else {
                favorites_add(game);
            }

			//Redraw and pause slightly
	        game_list_view(&last_game_selected);
			FE_DisplayScreen();
			usleep(300000);
			gp2x_joystick_clear();

		}
	}
}