示例#1
0
文件: event.c 项目: yoyofr/iNEOGEO
void reset_event(void) {
	SDL_Event event;
	int i;
	for (i = 0; i < GN_MAX_KEY; i++)
		joy_state[0][i] = 0;
	while (SDL_PollEvent(&event));
	last=-1;
	counter=40;
    
    for (i=0;i<VSTICK_NB_BUTTON;i++) virtual_stick[i].finger_id=0;
    virtual_stick_padfinger=0;
    virtual_stick_pad=0;
    wm_prev_joy_pl1=wm_prev_joy_pl2=0;
    if (num_of_joys>=2) {
        if (wm_prev_joy_pl2=iOS_wiimote_check(&(joys[1]))) virtual_stick_on=0;
    }   
    if (num_of_joys>=1) {
        if (wm_prev_joy_pl1=iOS_wiimote_check(&(joys[0]))) virtual_stick_on=0;
    }
    slide_detected=0;
}
示例#2
0
unsigned long gp2x_joystick_read(int n)
{
  unsigned long res=0;
	res = gp2x_pad_status;
		
	/* GP2X F200 Push Button */
	if ((res & GP2X_VOL_UP) && (res & GP2X_VOL_DOWN))
	  		res |= GP2X_PUSH;

	if (num_of_joys>n)
	{
	  	/* Check USB Joypad */
		//printf("%d %d\n",num_of_joys,n);
		res |= iOS_wiimote_check(&joys[n]);
	}
  	
	return res;
}
示例#3
0
文件: event.c 项目: yoyofr/iNEOGEO
int wait_event(void) {
	SDL_Event event;
    SDL_Touch *state;
	int i,a,rx,ry;
	//static int counter;
	//static int last=-1;
	//int last=-1;
	//for(i=0;i<GN_MAX_KEY;i++)
	//	if (joy_state[0][i]) last=i;
	//SDL_WaitEvent(&event);
    
    //printf("wait event\n");
    int wm_joy_pl1,wm_joy_pl2;
    wm_joy_pl1=wm_joy_pl2=0;
    
    if (device_isIpad) {
        if (cur_width>cur_height) virtual_stick=virtual_stick_ipad_landscape;
        else virtual_stick=virtual_stick_ipad_portrait;
    } else {
        if (cur_width>cur_height) virtual_stick=virtual_stick_iphone_landscape;
        else virtual_stick=virtual_stick_iphone_portrait;
    }
    
    if (num_of_joys>=2) {
        if (wm_joy_pl2=iOS_wiimote_check(&(joys[1]))) virtual_stick_on=0;
        if (wm_joy_pl2!=wm_prev_joy_pl2) {
            refresh_counter=1;
            wm_prev_joy_pl2=wm_joy_pl2;
        joy_state[1][GN_UP]=(wm_joy_pl2&WII_JOY_UP?1:0);
        joy_state[1][GN_DOWN]=(wm_joy_pl2&WII_JOY_DOWN?1:0);
        joy_state[1][GN_LEFT]=(wm_joy_pl2&WII_JOY_LEFT?1:0);
        joy_state[1][GN_RIGHT]=(wm_joy_pl2&WII_JOY_RIGHT?1:0);
        joy_state[1][GN_A]=(wm_joy_pl2&WII_JOY_A?1:0);
        joy_state[1][GN_B]=(wm_joy_pl2&WII_JOY_B?1:0);
        joy_state[1][GN_C]=(wm_joy_pl2&WII_JOY_C?1:0);
        joy_state[1][GN_D]=(wm_joy_pl2&WII_JOY_D?1:0);
        joy_state[1][GN_SELECT_COIN]=(wm_joy_pl2&WII_JOY_SELECT?1:0);
        joy_state[1][GN_START]=(wm_joy_pl2&WII_JOY_START?1:0);
        joy_state[1][GN_MENU_KEY]=(wm_joy_pl2&WII_JOY_HOME?1:0);
        joy_state[1][GN_TURBO]=(wm_joy_pl2&WII_JOY_E?1:0);
        }
    }
    if (num_of_joys>=1) {        
        if (wm_joy_pl1=iOS_wiimote_check(&(joys[0]))) virtual_stick_on=0;
        
        if (wm_joy_pl1!=wm_prev_joy_pl1) {
            refresh_counter=1;
            wm_prev_joy_pl1=wm_joy_pl1;
        joy_state[0][GN_UP]=(wm_joy_pl1&WII_JOY_UP?1:0);
        joy_state[0][GN_DOWN]=(wm_joy_pl1&WII_JOY_DOWN?1:0);
        joy_state[0][GN_LEFT]=(wm_joy_pl1&WII_JOY_LEFT?1:0);
        joy_state[0][GN_RIGHT]=(wm_joy_pl1&WII_JOY_RIGHT?1:0);
        joy_state[0][GN_A]=(wm_joy_pl1&WII_JOY_A?1:0);
        joy_state[0][GN_B]=(wm_joy_pl1&WII_JOY_B?1:0);
        joy_state[0][GN_C]=(wm_joy_pl1&WII_JOY_C?1:0);
        joy_state[0][GN_D]=(wm_joy_pl1&WII_JOY_D?1:0);
        joy_state[0][GN_SELECT_COIN]=(wm_joy_pl1&WII_JOY_SELECT?1:0);
        joy_state[0][GN_START]=(wm_joy_pl1&WII_JOY_START?1:0);
        joy_state[0][GN_MENU_KEY]=(wm_joy_pl1&WII_JOY_HOME?1:0);
        joy_state[0][GN_TURBO]=(wm_joy_pl1&WII_JOY_E?1:0);
            
        }
    }
    
	while (SDL_PollEvent(&event)) {        
        switch (event.type) {
            case SDL_MOUSEMOTION:
                break;
            case SDL_MOUSEBUTTONDOWN:
                break;
            case SDL_MOUSEBUTTONUP:
                break;
            case SDL_FINGERMOTION:
                refresh_counter=1;
                state = SDL_GetTouch(event.tfinger.touchId);
                rx = event.tfinger.x*cur_width / state->xres;
                ry = event.tfinger.y*cur_height / state->yres;
                
                //printf("delta: %d x %d\n",event.tfinger.dx*cur_width/ state->xres,event.tfinger.dy*cur_height/ state->yres);
                if ((event.tfinger.dy*100/ state->yres > SLIDEY_CHANGE_RENDERMODE_MIN)&&
                    (abs(event.tfinger.dx*100/ state->xres) < SLIDEX_CHANGE_RENDERMODE_MAX)) {
                    slide_detected=1;
                }
                
                if (event.tfinger.fingerId==virtual_stick_padfinger) { //is it the finger on pad
                    if (vstick_update_status(rx,ry)==0) virtual_stick_padfinger=0;
                    joy_state[0][GN_UP]=(virtual_stick_pad==GN_UP?1:0);
                    joy_state[0][GN_DOWN]=(virtual_stick_pad==GN_DOWN?1:0);
                    joy_state[0][GN_LEFT]=(virtual_stick_pad==GN_LEFT?1:0);
                    joy_state[0][GN_RIGHT]=(virtual_stick_pad==GN_RIGHT?1:0);
                    joy_state[0][GN_UPRIGHT]=(virtual_stick_pad==GN_UPRIGHT?1:0);
                    joy_state[0][GN_DOWNRIGHT]=(virtual_stick_pad==GN_DOWNRIGHT?1:0);
                    joy_state[0][GN_UPLEFT]=(virtual_stick_pad==GN_UPLEFT?1:0);
                    joy_state[0][GN_DOWNLEFT]=(virtual_stick_pad==GN_DOWNLEFT?1:0);
                } else if (virtual_stick_padfinger==0) {
                    if (vstick_update_status(rx,ry)) virtual_stick_padfinger=event.tfinger.fingerId;
                    joy_state[0][GN_UP]=(virtual_stick_pad==GN_UP?1:0);
                    joy_state[0][GN_DOWN]=(virtual_stick_pad==GN_DOWN?1:0);
                    joy_state[0][GN_LEFT]=(virtual_stick_pad==GN_LEFT?1:0);
                    joy_state[0][GN_RIGHT]=(virtual_stick_pad==GN_RIGHT?1:0);
                    joy_state[0][GN_UPRIGHT]=(virtual_stick_pad==GN_UPRIGHT?1:0);
                    joy_state[0][GN_DOWNRIGHT]=(virtual_stick_pad==GN_DOWNRIGHT?1:0);
                    joy_state[0][GN_UPLEFT]=(virtual_stick_pad==GN_UPLEFT?1:0);
                    joy_state[0][GN_DOWNLEFT]=(virtual_stick_pad==GN_DOWNLEFT?1:0);
                }
                
                for (int i=0;i<VSTICK_NB_BUTTON;i++) {                    
                    //is there a button already pressed with this finger ?
                    if (virtual_stick[i].finger_id==event.tfinger.fingerId) {
                        //a button was pressed and finger moved
                        //check if finger is still in button area
                        if ((rx>virtual_stick[i].x)&&(rx<virtual_stick[i].x+virtual_stick[i].w)&&
                            (ry>virtual_stick[i].y)&&(ry<virtual_stick[i].y+virtual_stick[i].h)){
                            break;
                        } else {
                            //button not pressed anymore
                            //do not break to check if finger moved to a new button
                            virtual_stick[i].finger_id=0;
                            joy_state[0][virtual_stick[i].button_id]=0;                            
                        }
                    } else {
                        //did the finger move to a new button area ?
                        if ((rx>virtual_stick[i].x)&&(rx<virtual_stick[i].x+virtual_stick[i].w)&&
                            (ry>virtual_stick[i].y)&&(ry<virtual_stick[i].y+virtual_stick[i].h)){
                            joy_state[0][virtual_stick[i].button_id]=1;
                            virtual_stick[i].finger_id=event.tfinger.fingerId;                        
                        }
                    }
                }
                
                break;
            case SDL_FINGERDOWN:
                refresh_counter=1;
                virtual_stick_on=1;
                state = SDL_GetTouch(event.tfinger.touchId);
                rx = event.tfinger.x*cur_width / state->xres;
                ry = event.tfinger.y*cur_height / state->yres;
                
                if (vstick_update_status(rx,ry)) { //finger is on pad
                    joy_state[0][GN_UP]=(virtual_stick_pad==GN_UP?1:0);
                    joy_state[0][GN_DOWN]=(virtual_stick_pad==GN_DOWN?1:0);
                    joy_state[0][GN_LEFT]=(virtual_stick_pad==GN_LEFT?1:0);
                    joy_state[0][GN_RIGHT]=(virtual_stick_pad==GN_RIGHT?1:0);
                    joy_state[0][GN_UPRIGHT]=(virtual_stick_pad==GN_UPRIGHT?1:0);
                    joy_state[0][GN_DOWNRIGHT]=(virtual_stick_pad==GN_DOWNRIGHT?1:0);
                    joy_state[0][GN_UPLEFT]=(virtual_stick_pad==GN_UPLEFT?1:0);
                    joy_state[0][GN_DOWNLEFT]=(virtual_stick_pad==GN_DOWNLEFT?1:0);
                    virtual_stick_padfinger=event.tfinger.fingerId;
                } else { //check if finger is on a button
                    for (int i=0;i<VSTICK_NB_BUTTON;i++) {
                        if ((rx>virtual_stick[i].x)&&(rx<virtual_stick[i].x+virtual_stick[i].w)&&
                            (ry>virtual_stick[i].y)&&(ry<virtual_stick[i].y+virtual_stick[i].h)){
                            joy_state[0][virtual_stick[i].button_id]=1;
                            virtual_stick[i].finger_id=event.tfinger.fingerId;
                            break;
                        }
                    }       
                }
                break;
            case SDL_FINGERUP:
                refresh_counter=1;
                if (virtual_stick_padfinger==event.tfinger.fingerId) {
                    virtual_stick_pad=0;                    
                    joy_state[0][GN_UP]=0;
                    joy_state[0][GN_DOWN]=0;
                    joy_state[0][GN_LEFT]=0;
                    joy_state[0][GN_RIGHT]=0;
                    joy_state[0][GN_UPRIGHT]=0;
                    joy_state[0][GN_DOWNRIGHT]=0;
                    joy_state[0][GN_UPLEFT]=0;
                    joy_state[0][GN_DOWNLEFT]=0;
                }
                    
                    for (int i=0;i<VSTICK_NB_BUTTON;i++) 
                        if (virtual_stick[i].finger_id==event.tfinger.fingerId) {
                            virtual_stick[i].finger_id=0;
                            joy_state[0][virtual_stick[i].button_id]=0;
                            break;
                        }
                
                if (slide_detected) {
                    slide_detected=0;
                    conf.rendermode++;
                    if (conf.rendermode>3) conf.rendermode=0;
                    
                }
                last=-1;
                counter=40;
                break;
            case SDL_KEYDOWN:
                refresh_counter=1;
                virtual_stick_on=0;
                /* Some default keyboard standard key */
                switch (event.key.keysym.sym) {
                    case SDLK_TAB:
                        joy_state[0][GN_MENU_KEY]=1;
                        //last=GN_MENU_KEY;
                        //return GN_MENU_KEY;
                        break;	
                    case SDLK_UP:
                        joy_state[0][GN_UP]=1;
                        //last=GN_UP;
                        //return GN_UP;
                        break;	
                    case SDLK_DOWN:
                        joy_state[0][GN_DOWN]=1;
                        //last=GN_DOWN;
                        //return GN_DOWN;
                        break;	
                    case SDLK_LEFT:
                        joy_state[0][GN_LEFT]=1;
                        //last=GN_LEFT;
                        //return GN_LEFT;
                        break;	
                    case SDLK_RIGHT:
                        joy_state[0][GN_RIGHT]=1;
                        //last=GN_RIGHT;
                        //return GN_RIGHT;
                        break;	
                    case SDLK_ESCAPE:
                        joy_state[0][GN_B]=1;
                        //last=GN_A;
                        //return GN_A;
                        break;
                    case SDLK_RETURN:
                    case SDLK_KP_ENTER:
                        joy_state[0][GN_A]=1;
                        //last=GN_B;
                        //return GN_B;
                        break;
                    default:
                        SDL_PushEvent(&event);
                        handle_event();
                        break;
                }
                break;
            case SDL_KEYUP:
                refresh_counter=1;
                //printf("KEYUPPPPP!!!\n");
                
                for(i=0;i<GN_MAX_KEY;i++)
                    joy_state[0][i]=0;
                last=-1;
                counter=40;
                break;
            default:
                SDL_PushEvent(&event);
				handle_event();
				/* Simulate keyup */
				a=0;
				for (i = 0; i < GN_MAX_KEY; i++)
					if (joy_state[0][i]) a++;
				if (a!=1) {
					for (i = 0; i < GN_MAX_KEY; i++)
                        joy_state[0][i] = 0;
                    last = -1;
                    counter = 40;
				}
                break;
        }
	}
    /*
     }
     SDL_PushEvent(&event);
     handle_event();
	 */
    
	if (last!=-1) {
		if (counter>0)
			counter--;
		if (counter==0) {
			counter=5;
			return last;
		}
	} else {
		for(i=0;i<GN_MAX_KEY;i++)
			if (joy_state[0][i]) {
				last=i;
				return i;
			}
	}
    /*
     for(i=0;i<GN_MAX_KEY;i++)
     if (joy_state[0][i] ) {
     if (i != last) {
     counter=30;
     last=i;
     return i;
     } else {
     counter--;
     if (counter==0) {
     counter=5;
     return i;
     }
     
     }
     
     
     }
     */
	return 0;
}
示例#4
0
文件: event.c 项目: yoyofr/iNEOGEO
int handle_event(void) {
	SDL_Event event;
    SDL_Touch *state;
    //	int i;
    int rx,ry;
	int ret;
	int jaxis_threshold=10000;
    
    int wm_joy_pl1,wm_joy_pl2;
    wm_joy_pl1=wm_joy_pl2=0;
    
    if (device_isIpad) {
        if (cur_width>cur_height) virtual_stick=virtual_stick_ipad_landscape;
        else virtual_stick=virtual_stick_ipad_portrait;
    } else {
        if (cur_width>cur_height) virtual_stick=virtual_stick_iphone_landscape;
        else virtual_stick=virtual_stick_iphone_portrait;
    }
    
    if (num_of_joys>=2) {
        if (wm_joy_pl2=iOS_wiimote_check(&(joys[1]))) virtual_stick_on=0;
        if (wm_joy_pl2!=wm_prev_joy_pl2) {
            wm_prev_joy_pl2=wm_joy_pl2;

        joy_state[1][GN_UP]=(wm_joy_pl2&WII_JOY_UP?1:0);
        joy_state[1][GN_DOWN]=(wm_joy_pl2&WII_JOY_DOWN?1:0);
        joy_state[1][GN_LEFT]=(wm_joy_pl2&WII_JOY_LEFT?1:0);
        joy_state[1][GN_RIGHT]=(wm_joy_pl2&WII_JOY_RIGHT?1:0);
        joy_state[1][GN_A]=(wm_joy_pl2&WII_JOY_A?1:0);
        joy_state[1][GN_B]=(wm_joy_pl2&WII_JOY_B?1:0);
        joy_state[1][GN_C]=(wm_joy_pl2&WII_JOY_C?1:0);
        joy_state[1][GN_D]=(wm_joy_pl2&WII_JOY_D?1:0);
        joy_state[1][GN_SELECT_COIN]=(wm_joy_pl2&WII_JOY_SELECT?1:0);
        joy_state[1][GN_START]=(wm_joy_pl2&WII_JOY_START?1:0);
        joy_state[1][GN_MENU_KEY]=(wm_joy_pl2&WII_JOY_HOME?1:0);
        joy_state[1][GN_TURBO]=(wm_joy_pl2&WII_JOY_E?1:0);
        }
    }
    if (num_of_joys>=1) {        
        if (wm_joy_pl1=iOS_wiimote_check(&(joys[0]))) virtual_stick_on=0;
        
        if (wm_joy_pl1!=wm_prev_joy_pl1) {
            wm_prev_joy_pl1=wm_joy_pl1;

        joy_state[0][GN_UP]=(wm_joy_pl1&WII_JOY_UP?1:0);
        joy_state[0][GN_DOWN]=(wm_joy_pl1&WII_JOY_DOWN?1:0);
        joy_state[0][GN_LEFT]=(wm_joy_pl1&WII_JOY_LEFT?1:0);
        joy_state[0][GN_RIGHT]=(wm_joy_pl1&WII_JOY_RIGHT?1:0);
        joy_state[0][GN_A]=(wm_joy_pl1&WII_JOY_A?1:0);
        joy_state[0][GN_B]=(wm_joy_pl1&WII_JOY_B?1:0);
        joy_state[0][GN_C]=(wm_joy_pl1&WII_JOY_C?1:0);
        joy_state[0][GN_D]=(wm_joy_pl1&WII_JOY_D?1:0);
        joy_state[0][GN_SELECT_COIN]=(wm_joy_pl1&WII_JOY_SELECT?1:0);
        joy_state[0][GN_START]=(wm_joy_pl1&WII_JOY_START?1:0);
        joy_state[0][GN_MENU_KEY]=(wm_joy_pl1&WII_JOY_HOME?1:0);
        joy_state[0][GN_TURBO]=(wm_joy_pl1&WII_JOY_E?1:0);
        }
    }
    
	while (SDL_PollEvent(&event)) {
	    if ((ret=handle_pdep_event(&event))!=0) {
	    	return ret;
	    }
    	switch (event.type) {
            case SDL_MOUSEMOTION:
                break;
            case SDL_MOUSEBUTTONDOWN:
                break;
            case SDL_MOUSEBUTTONUP:
                break;
            case SDL_FINGERMOTION:
                state = SDL_GetTouch(event.tfinger.touchId);
                rx = event.tfinger.x*cur_width / state->xres;
                ry = event.tfinger.y*cur_height / state->yres;
                
                //printf("delta: %d x %d\n",event.tfinger.dx*cur_width/ state->xres,event.tfinger.dy*cur_height/ state->yres);
                if ((event.tfinger.dy*100/ state->yres < -SLIDEY_CHANGE_RENDERMODE_MIN)&&
                    (abs(event.tfinger.dx*100/ state->xres) < SLIDEX_CHANGE_RENDERMODE_MAX)) {
                    slide_detected=1;
                }
                
                if (event.tfinger.fingerId==virtual_stick_padfinger) { //is it the finger on pad
                    if (vstick_update_status(rx,ry)==0) virtual_stick_padfinger=0;
                    joy_state[0][GN_UP]=(virtual_stick_pad==GN_UP?1:0);
                    joy_state[0][GN_DOWN]=(virtual_stick_pad==GN_DOWN?1:0);
                    joy_state[0][GN_LEFT]=(virtual_stick_pad==GN_LEFT?1:0);
                    joy_state[0][GN_RIGHT]=(virtual_stick_pad==GN_RIGHT?1:0);
                    joy_state[0][GN_UPRIGHT]=(virtual_stick_pad==GN_UPRIGHT?1:0);
                    joy_state[0][GN_DOWNRIGHT]=(virtual_stick_pad==GN_DOWNRIGHT?1:0);
                    joy_state[0][GN_UPLEFT]=(virtual_stick_pad==GN_UPLEFT?1:0);
                    joy_state[0][GN_DOWNLEFT]=(virtual_stick_pad==GN_DOWNLEFT?1:0);
                } else if (virtual_stick_padfinger==0) {
                    if (vstick_update_status(rx,ry)) virtual_stick_padfinger=event.tfinger.fingerId;
                    joy_state[0][GN_UP]=(virtual_stick_pad==GN_UP?1:0);
                    joy_state[0][GN_DOWN]=(virtual_stick_pad==GN_DOWN?1:0);
                    joy_state[0][GN_LEFT]=(virtual_stick_pad==GN_LEFT?1:0);
                    joy_state[0][GN_RIGHT]=(virtual_stick_pad==GN_RIGHT?1:0);
                    joy_state[0][GN_UPRIGHT]=(virtual_stick_pad==GN_UPRIGHT?1:0);
                    joy_state[0][GN_DOWNRIGHT]=(virtual_stick_pad==GN_DOWNRIGHT?1:0);
                    joy_state[0][GN_UPLEFT]=(virtual_stick_pad==GN_UPLEFT?1:0);
                    joy_state[0][GN_DOWNLEFT]=(virtual_stick_pad==GN_DOWNLEFT?1:0);
                }
                
                for (int i=0;i<VSTICK_NB_BUTTON;i++) {                    
                    //is there a button already pressed with this finger ?
                    if (virtual_stick[i].finger_id==event.tfinger.fingerId) {
                        //a button was pressed and finger moved
                        //check if finger is still in button area
                        if ((rx>virtual_stick[i].x)&&(rx<virtual_stick[i].x+virtual_stick[i].w)&&
                            (ry>virtual_stick[i].y)&&(ry<virtual_stick[i].y+virtual_stick[i].h)){
                            break;
                        } else {
                            //button not pressed anymore
                            //do not break to check if finger moved to a new button
                            virtual_stick[i].finger_id=0;
                            joy_state[0][virtual_stick[i].button_id]=0;                            
                        }
                    } else {
                        //did the finger move to a new button area ?
                        if ((rx>virtual_stick[i].x)&&(rx<virtual_stick[i].x+virtual_stick[i].w)&&
                            (ry>virtual_stick[i].y)&&(ry<virtual_stick[i].y+virtual_stick[i].h)){
                            joy_state[0][virtual_stick[i].button_id]=1;
                            virtual_stick[i].finger_id=event.tfinger.fingerId;                        
                        }
                    }
                }
                
                break;
            case SDL_FINGERDOWN:
                virtual_stick_on=1;
                state = SDL_GetTouch(event.tfinger.touchId);
                rx = event.tfinger.x*cur_width / state->xres;
                ry = event.tfinger.y*cur_height / state->yres;
                
                
                if (vstick_update_status(rx,ry)) { //finger is on pad
                    joy_state[0][GN_UP]=(virtual_stick_pad==GN_UP?1:0);
                    joy_state[0][GN_DOWN]=(virtual_stick_pad==GN_DOWN?1:0);
                    joy_state[0][GN_LEFT]=(virtual_stick_pad==GN_LEFT?1:0);
                    joy_state[0][GN_RIGHT]=(virtual_stick_pad==GN_RIGHT?1:0);
                    joy_state[0][GN_UPRIGHT]=(virtual_stick_pad==GN_UPRIGHT?1:0);
                    joy_state[0][GN_DOWNRIGHT]=(virtual_stick_pad==GN_DOWNRIGHT?1:0);
                    joy_state[0][GN_UPLEFT]=(virtual_stick_pad==GN_UPLEFT?1:0);
                    joy_state[0][GN_DOWNLEFT]=(virtual_stick_pad==GN_DOWNLEFT?1:0);
                    virtual_stick_padfinger=event.tfinger.fingerId;
                } else { //check if finger is on a button
                    for (int i=0;i<VSTICK_NB_BUTTON;i++) {
                        if ((rx>virtual_stick[i].x)&&(rx<virtual_stick[i].x+virtual_stick[i].w)&&
                            (ry>virtual_stick[i].y)&&(ry<virtual_stick[i].y+virtual_stick[i].h)){
                            joy_state[0][virtual_stick[i].button_id]=1;
                            virtual_stick[i].finger_id=event.tfinger.fingerId;
                            break;
                        }
                    }       
                }
                break;
            case SDL_FINGERUP:
                if (virtual_stick_padfinger==event.tfinger.fingerId) {
                    virtual_stick_pad=0;                    
                    joy_state[0][GN_UP]=0;
                    joy_state[0][GN_DOWN]=0;
                    joy_state[0][GN_LEFT]=0;
                    joy_state[0][GN_RIGHT]=0;
                    joy_state[0][GN_UPRIGHT]=0;
                    joy_state[0][GN_DOWNRIGHT]=0;
                    joy_state[0][GN_UPLEFT]=0;
                    joy_state[0][GN_DOWNLEFT]=0;
                } 
            
                    
                    for (int i=0;i<VSTICK_NB_BUTTON;i++) 
                        if (virtual_stick[i].finger_id==event.tfinger.fingerId) {
                            virtual_stick[i].finger_id=0;
                            joy_state[0][virtual_stick[i].button_id]=0;
                            break;
                        }
                if (slide_detected) {
                    slide_detected=0;
                    conf.rendermode++;
                    if (conf.rendermode>3) conf.rendermode=0;

                }
                break;
                
            case SDL_KEYUP:
                //printf("%d\n",jmap->key[event.key.keysym.sym].player);
                switch (jmap->key[event.key.keysym.sym].player) {
                    case 1:
                        joy_state[0][jmap->key[event.key.keysym.sym].map]=0;
                        break;
                    case 2:
                        joy_state[1][jmap->key[event.key.keysym.sym].map]=0;
                        break;
                    case 3:
                        joy_state[1][jmap->key[event.key.keysym.sym].map]=0;
                        joy_state[0][jmap->key[event.key.keysym.sym].map]=0;
                        break;
                    default:
                        break;
                }
                break;
            case SDL_KEYDOWN:
                virtual_stick_on=0;
                icade_detected=1;
                //				printf("%d %c\n", event.key.keysym.sym,event.key.keysym.sym);
                switch (jmap->key[event.key.keysym.sym].player) {
                    case 1:
                        joy_state[0][jmap->key[event.key.keysym.sym].map]=1;
                        break;
                    case 2:
                        joy_state[1][jmap->key[event.key.keysym.sym].map]=1;
                        break;
                    case 3:
                        joy_state[1][jmap->key[event.key.keysym.sym].map]=1;
                        joy_state[0][jmap->key[event.key.keysym.sym].map]=1;
                        break;
                    default:
                        break;
                }
                break;
            case SDL_JOYHATMOTION: /* Hat only support Joystick map */
            {
                int player=jmap->jhat[event.jhat.which][event.jhat.hat].player;
                int map=jmap->jhat[event.jhat.which][event.jhat.hat].map;
                int i;
                if (player && map==GN_UP) {
                    player-=1;
                    for(i=GN_UP;i<=GN_RIGHT;i++)
                        joy_state[player][i]=0;
                    if (event.jhat.value&SDL_HAT_UP) joy_state[player][GN_UP]=1;
                    if (event.jhat.value&SDL_HAT_DOWN) joy_state[player][GN_DOWN]=1;
                    if (event.jhat.value&SDL_HAT_LEFT) joy_state[player][GN_LEFT]=1;
                    if (event.jhat.value&SDL_HAT_RIGHT) joy_state[player][GN_RIGHT]=1;
                    
                }
                
                //printf("SDL_JOYHATMOTION  %d %d %d\n",event.jhat.which,
                //event.jhat.hat,event.jhat.value);
            }
                break;
            case SDL_JOYAXISMOTION:
            {
                int player=jmap->jaxe[event.jaxis.which][event.jaxis.axis].player;
                int map=jmap->jaxe[event.jaxis.which][event.jaxis.axis].map;
                int oldvalue=jmap->jaxe[event.jaxis.which][event.jaxis.axis].value;
                int value=0;
                //if (event.jaxis.axis!=6 &&event.jaxis.axis!=7 )
                //	printf("Axiw motions %d %d %d\n",event.jaxis.which,event.jaxis.axis,event.jaxis.value);
                if (player) {
                    player-=1;
                    
                    value=event.jaxis.value*jmap->jaxe[event.jaxis.which][event.jaxis.axis].dir;
                    
                    //printf("%d %d %d\n",player,map,value);
                    if (map==GN_UP || map==GN_DOWN) {
                        if (value>jaxis_threshold) {
                            joy_state[player][GN_UP]=1;
                            joy_state[player][GN_DOWN]=0;
                        }
                        if (value<-jaxis_threshold) {
                            joy_state[player][GN_DOWN]=1;
                            joy_state[player][GN_UP]=0;
                        }
                        if (oldvalue>jaxis_threshold && value<=jaxis_threshold && value>=-jaxis_threshold)
                            joy_state[player][GN_UP]=0;
                        if (oldvalue<-jaxis_threshold && value>=-jaxis_threshold && value<=jaxis_threshold)
                            joy_state[player][GN_DOWN]=0;
                        
                    }
                    if (map==GN_LEFT || map==GN_RIGHT) {
                        if (value>jaxis_threshold) {
                            joy_state[player][GN_RIGHT]=1;
                            joy_state[player][GN_LEFT]=0;
                        }
                        if (value<-jaxis_threshold) {
                            joy_state[player][GN_LEFT]=1;
                            joy_state[player][GN_RIGHT]=0;
                        }
                        if (oldvalue>jaxis_threshold && value<=jaxis_threshold && value>=-jaxis_threshold)
                            joy_state[player][GN_RIGHT]=0;
                        if (oldvalue<-jaxis_threshold && value>=-jaxis_threshold && value<=jaxis_threshold)
                            joy_state[player][GN_LEFT]=0;
                        
                    }
                    
                    jmap->jaxe[event.jaxis.which][event.jaxis.axis].value=value;
                    
                    
                }
                
                /*	if (abs(event.jaxis.value)>jaxis_threshold)
                 printf("SDL_JOYAXISMOTION %d %d %d %d\n",event.jaxis.which,
                 event.jaxis.axis,value,jmap->jaxe[event.jaxis.which][event.jaxis.axis].dir);
                 * */
            }
                break;
            case SDL_JOYBUTTONDOWN: 
            {
                int player=jmap->jbutton[event.jbutton.which][event.jbutton.button].player;
                int map=jmap->jbutton[event.jbutton.which][event.jbutton.button].map;
                //printf("player %d map %d\n",player,map);
                if (player) {
                    player-=1;
                    joy_state[player][map]=1;
                }
                
                //printf("SDL_JOYBUTTONDOWN %d %d\n",event.jbutton.which,event.jbutton.button);
            }
                break;
            case SDL_JOYBUTTONUP:
            {
                int player=jmap->jbutton[event.jbutton.which][event.jbutton.button].player;
                int map=jmap->jbutton[event.jbutton.which][event.jbutton.button].map;
                if (player) {
                    player-=1;
                    joy_state[player][map]=0;
                }
            }
                break;
            case SDL_VIDEORESIZE:
                conf.res_x=event.resize.w;
                conf.res_y=event.resize.h;
                screen_resize(event.resize.w, event.resize.h);
                break;
            case SDL_QUIT:
                return 1;
                break;
            default:
                break;
		}
	}
    /*
     for(i=0;i<GN_MAX_KEY;i++)
     printf("%d",joy_state[0][i]);
     printf("|");
     for(i=0;i<GN_MAX_KEY;i++)
     printf("%d",joy_state[1][i]);
     printf("\r");
     */
	/* Update coin data */
	memory.intern_coin = 0x7;
	if (joy_state[0][GN_SELECT_COIN])
		memory.intern_coin &= 0x6;
	if (joy_state[1][GN_SELECT_COIN])
		memory.intern_coin &= 0x5;
	/* Update start data TODO: Select */
	memory.intern_start = 0x8F;
	if (joy_state[0][GN_START])
		memory.intern_start &= 0xFE;
	if (joy_state[1][GN_START])
		memory.intern_start &= 0xFB;
    
    /* TURBO mode */
    if (joy_state[0][GN_TURBO]) {
        gTurboMode=1;
    } else gTurboMode=0;
    
	/* Update P1 */
	memory.intern_p1 = 0xFF;
	if ((joy_state[0][GN_UP]||joy_state[0][GN_UPLEFT]||joy_state[0][GN_UPRIGHT]) && ((!joy_state[0][GN_DOWN])||(!joy_state[0][GN_DOWNLEFT])||(!joy_state[0][GN_DOWNRIGHT])))
	    memory.intern_p1 &= 0xFE;
	if ((joy_state[0][GN_DOWN]||joy_state[0][GN_DOWNLEFT]||joy_state[0][GN_DOWNRIGHT]) && ((!joy_state[0][GN_UP])||(!joy_state[0][GN_UPLEFT])||(!joy_state[0][GN_UPRIGHT])))
	    memory.intern_p1 &= 0xFD;
	if ((joy_state[0][GN_LEFT]||joy_state[0][GN_UPLEFT]||joy_state[0][GN_DOWNLEFT]) && ((!joy_state[0][GN_RIGHT])||(!joy_state[0][GN_UPRIGHT])||(!joy_state[0][GN_DOWNRIGHT])))
	    memory.intern_p1 &= 0xFB;
	if ((joy_state[0][GN_RIGHT]||joy_state[0][GN_UPRIGHT]||joy_state[0][GN_DOWNRIGHT]) && ((!joy_state[0][GN_LEFT])||(!joy_state[0][GN_UPLEFT])||(!joy_state[0][GN_DOWNLEFT])))
	    memory.intern_p1 &= 0xF7;
	if (joy_state[0][GN_A])
	    memory.intern_p1 &= 0xEF;	// A
	if (joy_state[0][GN_B])
	    memory.intern_p1 &= 0xDF;	// B
	if (joy_state[0][GN_C])
	    memory.intern_p1 &= 0xBF;	// C
	if (joy_state[0][GN_D])
	    memory.intern_p1 &= 0x7F;	// D
    
	/* Update P1 */
	memory.intern_p2 = 0xFF;
	if (joy_state[1][GN_UP] && (!joy_state[1][GN_DOWN]))
	    memory.intern_p2 &= 0xFE;
	if (joy_state[1][GN_DOWN] && (!joy_state[1][GN_UP]))
	    memory.intern_p2 &= 0xFD;
	if (joy_state[1][GN_LEFT] && (!joy_state[1][GN_RIGHT]))
	    memory.intern_p2 &= 0xFB;
	if (joy_state[1][GN_RIGHT] && (!joy_state[1][GN_LEFT]))
	    memory.intern_p2 &= 0xF7;
	if (joy_state[1][GN_A])
	    memory.intern_p2 &= 0xEF;	// A
	if (joy_state[1][GN_B])
	    memory.intern_p2 &= 0xDF;	// B
	if (joy_state[1][GN_C])
	    memory.intern_p2 &= 0xBF;	// C
	if (joy_state[1][GN_D])
	    memory.intern_p2 &= 0x7F;	// D
    
#if defined(GP2X) || defined(WIZ)
	if (joy_state[0][GN_HOTKEY1] && joy_state[0][GN_HOTKEY2]
        && (joy_state[0][GN_START] || joy_state[0][GN_SELECT_COIN]))
		return 1;
#endif
    
	if(joy_state[0][GN_MENU_KEY]==1)
		return 1;
	else 
		return 0;
    
}