示例#1
0
void
window_copy_resize(struct window_pane *wp, u_int sx, u_int sy)
{
	struct window_copy_mode_data	*data = wp->modedata;
	struct screen			*s = &data->screen;
	struct screen_write_ctx	 	 ctx;

	screen_resize(s, sx, sy);
	if (data->backing != &wp->base)
		screen_resize(data->backing, sx, sy);

	if (data->cy > sy - 1)
		data->cy = sy - 1;
	if (data->cx > sx)
		data->cx = sx;
	if (data->oy > screen_hsize(data->backing))
		data->oy = screen_hsize(data->backing);

	window_copy_clear_selection(wp);

	screen_write_start(&ctx, NULL, s);
	window_copy_write_lines(wp, &ctx, 0, screen_size_y(s) - 1);
	screen_write_stop(&ctx);

	window_copy_redraw_screen(wp);
}
示例#2
0
bool graph3d_gtk::screen_create(void)
{ 
  /* Attribute list for gtkglarea widget. Specifies a
     list of Boolean attributes and enum/integer
     attribute/value pairs. The last attribute must be
     GDK_GL_NONE. See glXChooseVisual manpage for further
     explanation.
  */
  int attrlist[] = {
    GDK_GL_RGBA,
    GDK_GL_RED_SIZE,1,
    GDK_GL_GREEN_SIZE,1,
    GDK_GL_BLUE_SIZE,1,
    GDK_GL_DOUBLEBUFFER,
    GDK_GL_NONE
  };

  /* Check if OpenGL is supported. */
  if(gdk_gl_query() == FALSE) {
    PERROR(FALSE, "OpenGL is not supported!");
    return(FALSE);
  }
  
  assert(p_area == NULL);
  
  /* Create new OpenGL widget. */
  p_area = GTK_WIDGET(gtk_gl_area_new(attrlist));
  if(!p_area) {
    PERROR(true, "gtk_gl_area_new failed!");
  }  
  gtk_widget_set_size_request(GTK_WIDGET(p_area), graphics_width, graphics_height);
    
  screen_resize(graphics_width, graphics_height);
  return(TRUE);
}
示例#3
0
static vmResult	win32ddraw_resize(u32 newxsize,u32 newysize)
{
	u8	*a;
	int		y,b;

	if (newxsize != win_logxsize)
	{
		b = 256 - (newxsize/2);
		if (b > 0)
		{
			a = win_bitmap;
			for (y=0; y < newysize; y ++)
			{
				memset(a, BG, b);
				memset(a + 256 - b, BG, b);
				a += 256;
			}
		}
		
		win_logxsize = newxsize;
		win_logysize = newysize;
		
		screen_resize(newxsize, newysize);
	}
	return vmOk;
}
示例#4
0
文件: ui.c 项目: KillTheMule/neovim
void ui_grid_resize(handle_T grid_handle, int width, int height, Error *error)
{
  if (grid_handle == DEFAULT_GRID_HANDLE) {
    screen_resize(width, height);
    return;
  }

  win_T *wp = get_win_by_grid_handle(grid_handle);
  if (wp == NULL) {
    api_set_error(error, kErrorTypeValidation,
                  "No window with the given handle");
    return;
  }

  if (wp->w_floating) {
    if (width != wp->w_width && height != wp->w_height) {
      wp->w_float_config.width = width;
      wp->w_float_config.height = height;
      win_config_float(wp, wp->w_float_config);
    }
  } else {
    // non-positive indicates no request
    wp->w_height_request = (int)MAX(height, 0);
    wp->w_width_request = (int)MAX(width, 0);
    win_set_inner_size(wp);
  }
}
示例#5
0
文件: cardgame.c 项目: stinvi/runner
void resize(int width, int height)
{
   screen_size = (vec2f_t) { width, height };
   buffer_size = (vec2f_t) { round_up_to_pot(width), round_up_to_pot(height) };

   camera.aspect = (float)width/(float)height;
   camera.scale = (float)width;
   camera_update(&camera);

   gfx_resize(gfx, width, height);
   gfx_depth_range(gfx, camera.znear, camera.zfar);

   vec2f_t rect = { width, height };
   char* textures[] = { "test_texture" };
   texture_options_t options =
   {
      TF_LINEAR,
      TF_LINEAR,
      TW_REPEAT,
      TW_REPEAT,
   };
   uint32_t ntextures = sizeof(textures)/sizeof(textures[0]);
   uint32_t i = 0;
   for (i = 0; i < ntextures; ++i)
   {
      gfx_setup_texture(gfx, textures[i], &rect, &options);
   }

   gfx_setup_target(gfx, "test_target", &rect, (const char**)textures, ntextures);

   screen_resize(width, height);
}
示例#6
0
void
window_more_resize(struct window_pane *wp, u_int sx, u_int sy)
{
	struct window_more_mode_data	*data = wp->modedata;
	struct screen			*s = &data->screen;

	screen_resize(s, sx, sy);
	window_more_redraw_screen(wp);
}
示例#7
0
文件: ui.c 项目: KillTheMule/neovim
void ui_refresh(void)
{
  if (!ui_active()) {
    return;
  }

  if (updating_screen) {
    ui_schedule_refresh();
    return;
  }

  int width = INT_MAX, height = INT_MAX;
  bool ext_widgets[kUIExtCount];
  for (UIExtension i = 0; (int)i < kUIExtCount; i++) {
    ext_widgets[i] = true;
  }

  for (size_t i = 0; i < ui_count; i++) {
    UI *ui = uis[i];
    width = MIN(ui->width, width);
    height = MIN(ui->height, height);
    for (UIExtension j = 0; (int)j < kUIExtCount; j++) {
      ext_widgets[j] &= ui->ui_ext[j];
    }
  }

  cursor_row = cursor_col = 0;
  pending_cursor_update = true;

  for (UIExtension i = 0; (int)i < kUIExtCount; i++) {
    ui_ext[i] = ext_widgets[i];
    if (i < kUIGlobalCount) {
      ui_call_option_set(cstr_as_string((char *)ui_ext_names[i]),
                         BOOLEAN_OBJ(ext_widgets[i]));
    }
  }

  ui_default_colors_set();

  int save_p_lz = p_lz;
  p_lz = false;  // convince redrawing() to return true ...
  screen_resize(width, height);
  p_lz = save_p_lz;

  if (ext_widgets[kUIMessages]) {
    p_ch = 0;
    command_height();
  }
  ui_mode_info_set();
  pending_mode_update = true;
  ui_cursor_shape();
}
示例#8
0
bool graph3d_sdl::screen_create(void)
{ 
  assert(graphics == FALSE);
  
  // Fetch the video info...
  const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
  if(!videoInfo) {
    pprintf("Video query failed: %s\n",SDL_GetError());
    return(FALSE);
  }
    
  /* the flags to pass to SDL_SetVideoMode */
  sdl_video_flags = SDL_OPENGL;       /* Enable OpenGL in SDL */
  sdl_video_flags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */
  sdl_video_flags |= SDL_DOUBLEBUF;       /* Enable double buffering */
  sdl_video_flags |= SDL_HWPALETTE;       /* Store the palette in hardware */
  sdl_video_flags |= SDL_RESIZABLE;       /* Enable window resizing */

  /* This checks to see if surfaces can be stored in memory */
  if(videoInfo->hw_available)
    sdl_video_flags |= SDL_HWSURFACE;
  else
    sdl_video_flags |= SDL_SWSURFACE;

  /* This checks if hardware blits can be done */
  if(videoInfo->blit_hw)
    sdl_video_flags |= SDL_HWACCEL;

  if(graphics_fullscreen)
    sdl_video_flags |= SDL_FULLSCREEN;
  
  /* Sets up OpenGL double buffering */
  SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
  
  /* Get resolution from screen */
  if(!graphics_width || !graphics_height) {  
    graphics_width = videoInfo->current_w;
    graphics_height = videoInfo->current_h; 
  }
  if(!graphics_bpp) {
    graphics_bpp = videoInfo->vfmt->BitsPerPixel;
  }  

  screen_resize(graphics_width, graphics_height);

#ifdef ENABLE_GL
  create_GL();
#endif

  return(TRUE);
}
示例#9
0
文件: main.c 项目: djrtl/ncmpc-dj
static gboolean
sigwinch_event(G_GNUC_UNUSED GIOChannel *source,
               G_GNUC_UNUSED GIOCondition condition, G_GNUC_UNUSED gpointer data)
{
	char ignoreme[64];
	if (1 > read(sigwinch_pipes[0], ignoreme, 64))
		exit(EXIT_FAILURE);

	endwin();
	refresh();
	screen_resize(mpd);

	return TRUE;
}
示例#10
0
文件: game.c 项目: raydog/tunneltanks
/* Step the game simulation by handling events, and drawing: */
int game_step(void *input) {
	GameData *gd = input;
	ASSERT_ACTIVE();
	
	EventType temp;
	
	/* Handle all queued events: */
	while( (temp=gamelib_event_get_type()) != GAME_EVENT_NONE ) {
		
		/* Trying to resize the window? */
		if(temp == GAME_EVENT_RESIZE) {
			Rect r = gamelib_event_resize_get_size();
			screen_resize(gd->data.active.s, r.w, r.h);
		
		/* Trying to toggle fullscreen? */
		} else if(temp == GAME_EVENT_TOGGLE_FULLSCREEN) {
			screen_set_fullscreen(gd->data.active.s, -1);
		
		/* Trying to exit? */
		} else if(temp == GAME_EVENT_EXIT) {
			return 1;
		}
		
		/* Done with this event: */
		gamelib_event_done();
	}
	
	/* Clear everything: */
	tanklist_map(gd->data.active.tl, tank_clear(t, gd->data.active.b));
	plist_clear (gd->data.active.pl, gd->data.active.b);

	/* Charge a small bit of energy for life: */
	tanklist_map(gd->data.active.tl, tank_alter_energy(t, TANK_IDLE_COST));

	/* See if we need to be healed: */
	tanklist_map(gd->data.active.tl, tank_try_base_heal(t));
	
	/* Move everything: */
	plist_step  (gd->data.active.pl, gd->data.active.lvl, gd->data.active.tl);
	tanklist_map(gd->data.active.tl, tank_move(t, gd->data.active.tl));
	
	/* Draw everything: */
	plist_draw  (gd->data.active.pl, gd->data.active.b);
	tanklist_map(gd->data.active.tl, tank_draw(t, gd->data.active.b));
	screen_draw (gd->data.active.s);
	
	return 0;
}
示例#11
0
文件: ui.c 项目: Alok/neovim-1
void ui_refresh(void)
{
  if (!ui_active()) {
    return;
  }

  int width = INT_MAX, height = INT_MAX;

  for (size_t i = 0; i < ui_count; i++) {
    UI *ui = uis[i];
    width = ui->width < width ? ui->width : width;
    height = ui->height < height ? ui->height : height;
  }

  row = col = 0;
  screen_resize(width, height);
}
示例#12
0
文件: ui.c 项目: SLieng/nvm
void ui_refresh(void)
{
  if (!ui_active()) {
    return;
  }

  if (updating_screen) {
    ui_schedule_refresh();
    return;
  }

  int width = INT_MAX, height = INT_MAX;
  bool ext_widgets[kUIExtCount];
  for (UIExtension i = 0; (int)i < kUIExtCount; i++) {
    ext_widgets[i] = true;
  }

  for (size_t i = 0; i < ui_count; i++) {
    UI *ui = uis[i];
    width = MIN(ui->width, width);
    height = MIN(ui->height, height);
    for (UIExtension i = 0; (int)i < kUIExtCount; i++) {
      ext_widgets[i] &= ui->ui_ext[i];
    }
  }

  row = col = 0;

  int save_p_lz = p_lz;
  p_lz = false;  // convince redrawing() to return true ...
  screen_resize(width, height);
  p_lz = save_p_lz;

  for (UIExtension i = 0; (int)i < kUIExtCount; i++) {
    ui_ext[i] = ext_widgets[i];
    ui_call_option_set(cstr_as_string((char *)ui_ext_names[i]),
                       BOOLEAN_OBJ(ext_widgets[i]));
  }
  ui_mode_info_set();
  old_mode_idx = -1;
  ui_cursor_shape();
  current_attr_code = -1;
}
示例#13
0
文件: plugin.c 项目: troglobit/gul
int screen_changed(void)
{
	int col, row;

	/* Check if the physical screen has been altered/resized. Some
	 * plugins need this to reallocate their own buffers and
	 * reinitialize them. Therefore we send pointers to the old
	 * size and hope the plugin does its own bit.
	 */
	screen_plugin_get_dim(&row, &col);

	if (col != screen.max_col || row != screen.max_row) {
		screen_resize(col, row);

		return 1;
	}

	return 0;
}
示例#14
0
文件: ui.c 项目: kranki/neovim
void ui_refresh(void)
{
  if (!ui_active()) {
    return;
  }

  int width = INT_MAX, height = INT_MAX;
  bool pum_external = true;

  for (size_t i = 0; i < ui_count; i++) {
    UI *ui = uis[i];
    width = ui->width < width ? ui->width : width;
    height = ui->height < height ? ui->height : height;
    pum_external &= ui->pum_external;
  }

  row = col = 0;
  screen_resize(width, height);
  pum_set_external(pum_external);
}
示例#15
0
文件: emu.c 项目: tredpath/GnGeo-pb
void main_loop(void)
{
    int neo_emu_done = 0;
    int overclk=CF_VAL(cf_get_item_by_name("overclock"));

    Uint32 cpu_68k_timeslice = (overclk==0?200000:200000+(overclk*200000/100.0));
    Uint32 cpu_68k_timeslice_scanline = cpu_68k_timeslice/262.0;
//    Uint32 cpu_z80_timeslice = 100000;
    Uint32 cpu_z80_timeslice = 73333;
    Uint32 tm_cycle=0;

    /*    Uint32 cpu_z80_timeslice=66666; // is it 4Mhz or 6Mhz ???? 4 seems to work fine....
       UPDATE: it's clear now that it's 6Mhz -> kof96 presentation */

    Uint32 cpu_z80_timeslice_interlace = cpu_z80_timeslice / (float) nb_interlace;
    char ksym_code[5];
    SDL_Event event;
    Uint16 scancode, i, a;
    char input_buf[20];
    Uint8 show_keysym=0;
    CONF_ITEM* item = cf_get_item_by_name("invertjoy");
    int invert_joy = 0;
    if (item)
    	invert_joy=CF_BOOL(item);

    reset_frame_skip();
    my_timer();
    //printf("Cpuspeed: %d\n",cpu_68k_timeslice);
/*
    printf("%s\n",&memory.cpu[0x100]);
    printf("NGH = %04x\n",READ_WORD(&memory.cpu[0x108]));
    printf("SSN = %04x\n",READ_WORD(&memory.cpu[0x114]));
*/

    while (!neo_emu_done) {
	if (conf.test_switch == 1)
	    conf.test_switch = 0;


	while (SDL_PollEvent(&event)) {
	    switch (event.type) {
	    case SDL_JOYAXISMOTION:
		joy_axe[event.jaxis.which][event.jaxis.axis] = event.jaxis.value;
		if (show_keysym) {
		    sprintf(ksym_code, "%d", event.jaxis.axis);
		    draw_message(ksym_code);
		}
		break;

	    case SDL_JOYHATMOTION:
		    switch (event.jhat.value) {
		    case SDL_HAT_CENTERED:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 0;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 0;
			    break;
			    
		    case SDL_HAT_UP:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = -32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 0;
			    break;
			    
		    case SDL_HAT_DOWN:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 0;
			    break;
			    
		    case SDL_HAT_LEFT:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = -32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 0;
			    break;
			    
		    case SDL_HAT_RIGHT:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 0;
			    break;
			    
		    case SDL_HAT_RIGHTUP:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = -32767;
			    break;
			    
		    case SDL_HAT_RIGHTDOWN:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = 32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 32767;
			    break;
			    
		    case SDL_HAT_LEFTUP:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = -32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = -32767;
			    break;
			    
		    case SDL_HAT_LEFTDOWN:
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which]] = -32767;
			    joy_axe[event.jhat.which][(event.jhat.hat * 2) + joy_numaxes[event.jhat.which] + 1] = 32767;
			    break;
			    
		    }
		    
		    if (show_keysym) {
			    sprintf(ksym_code, "%d", event.jhat.hat);
			    draw_message(ksym_code);
		    }
		    break;


	    case SDL_JOYBUTTONDOWN:
		joy_button[event.jbutton.which][event.jbutton.button] = 1;
		
		if (show_keysym) {
		    sprintf(ksym_code, "%d", event.jbutton.button);
		    draw_message(ksym_code);
		}
		break;
	    case SDL_JOYBUTTONUP:
		joy_button[event.jbutton.which][event.jbutton.button] = 0;
		break;

	    case SDL_KEYUP:
		if (player)
		{
			switch(event.key.keysym.sym)
			{
			case 273:
				key[264] = 0;
				break;
			case 275:
				key[274] = 0;
				break;
			case 274:
				key[261] = 0;
				break;
			case 276:
				key[260] = 0;
				break;
			case 122:
				key[108] = 0;
				break;
			case 120:
				key[59] = 0;
				break;
			case 97:
				key[111] = 0;
				break;
			case 115:
				key[112] = 0;
				break;
			case 49:
				key[50] = 0;
				break;
			case 51:
				key[52] = 0;
				break;
			default:
				key[event.key.keysym.sym] = 0;
				break;
			}
		}
		else
			key[event.key.keysym.sym] = 0;
		break;
	    case SDL_KEYDOWN:
		scancode = event.key.keysym.sym;
		if (show_keysym) {
		    sprintf(ksym_code, "%d", scancode);
		    draw_message(ksym_code);
		}
		if (player)
		{
			switch(scancode)
			{
			case 273:
				key[264] = 1;
				break;
			case 275:
				key[274] = 1;
				break;
			case 274:
				key[261] = 1;
				break;
			case 276:
				key[260] = 1;
				break;
			case 122:
				key[108] = 1;
				break;
			case 120:
				key[59] = 1;
				break;
			case 97:
				key[111] = 1;
				break;
			case 115:
				key[112] = 1;
				break;
			case 49:
				key[50] = 1;
				break;
			case 51:
				key[52] = 1;
				break;
			default:
				key[scancode] = 1;
				break;
			}
		}
		else
			key[scancode] = 1;

		switch (scancode) {
		case SDLK_ESCAPE:
		    neo_emu_done = 1;
#ifdef __QNXNTO__
		    shutdown = 1;
#endif
		    break;	// ESC
/*
		case SDLK_TAB:
		    main_gngeo_gui();
		    break;
*/
		case SDLK_F1:
		    draw_message("Reset");
		    //neogeo_init();
		    cpu_68k_reset();
		    break;
		case SDLK_F2:
		    take_screenshot();
		    draw_message("Screenshot saved");
		    break;
		case SDLK_F3:
		    draw_message("Test Switch ON");
		    conf.test_switch = 1;
		    break;
		case SDLK_F5:
		    show_fps ^= SDL_TRUE;
		    break;
		case SDLK_F4:
		    show_keysym = 1 - show_keysym;
		    if (show_keysym)
			draw_message("Show keysym code : ON");
		    else
			draw_message("Show keysym code : OFF");
		    break;
		case SDLK_F6:
		    slow_motion = 1 - slow_motion;
		    if (slow_motion)
			draw_message("SlowMotion : ON");
		    else {
			draw_message("SlowMotion : OFF");
			reset_frame_skip();
		    }
		    break;
		case SDLK_F7:
		    //screen_set_effect("scanline");
		    if (conf.debug) {
			dbg_step = 1;
		    }
		    break;
		case SDLK_F8: 
		{
		    int val;
		    char *endptr;
		    text_input("Save to slot [0-999]? ",16,227,input_buf,3);
		    val=strtol(input_buf,&endptr,10);
		    if (input_buf != endptr) {
			pending_save_state=val+1;
		    }
		}
		break;
		case SDLK_F9:
		{
		    int val;
		    char *endptr;
		    text_input("Load from slot [0-999]? ",16,227,input_buf,3);
		    val=strtol(input_buf,&endptr,10);
		    if (input_buf != endptr) {
			pending_load_state=val+1;
		    }
		}
		break; 
		case SDLK_F10:
		    autoframeskip ^= SDL_TRUE;
		    if (autoframeskip) {
			reset_frame_skip();
			draw_message("AutoFrameSkip : ON");
		    } else
			draw_message("AutoFrameSkip : OFF");
		    break;
		case SDLK_F11:
		    sleep_idle ^= SDL_TRUE;
		    if (sleep_idle)
			draw_message("Sleep idle : ON");
		    else
			draw_message("Sleep idle : OFF");
		    break;
		case SDLK_F12:
		    screen_fullscreen();
		    break;
#ifdef __QNXNTO__
		case SDLK_F13:
			neo_emu_done = 1;
			break;
		case SDLK_F14:
			if (player)
			{
				key[52] = 0;
				key[50] = 0;
				key[112] = 0;
				key[111] = 0;
				key[59] = 0;
				key[108] = 0;
				key[260] = 0;
				key[261] = 0;
				key[274] = 0;
				key[264] = 0;
			}
			player = !player;
			break;
#endif
		}
		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_ACTIVEEVENT:
			if (event.active.state & SDL_APPINPUTFOCUS)
			{
				if (!event.active.gain)
				{
					int J;
					SDL_PauseAudio(1);
					while (1)
					{
						usleep(10000);
						if (SDL_PollEvent(&event))
						{
							if (event.type == SDL_ACTIVEEVENT)
							{
								if (event.active.state & SDL_APPINPUTFOCUS)
								{
									if (event.active.gain)
										break;
								}
							}
							else if (event.type == SDL_QUIT)
							{
								neo_emu_done = 1;
								break;
							}
						}
					}
					SDL_PauseAudio(0);
				    reset_frame_skip();
				}
			}
			break;
		case SDL_USEREVENT:
			reset_frame_skip();
			break;
	    case SDL_QUIT:
		neo_emu_done = 1;
#ifdef __QNXNTO__
		shutdown = 1;
#endif
		break;
	    default:
		break;
	    }
	}

	/* update the internal representation of keyslot */
	update_p1_key();
	update_p2_key();
	update_start();
	update_coin();

	if (slow_motion)
	    SDL_Delay(100);

	if (conf.sound) {
	    PROFILER_START(PROF_Z80);
	    for (i = 0; i < nb_interlace; i++) {
		cpu_z80_run(cpu_z80_timeslice_interlace);
		my_timer();
	    }
	    PROFILER_STOP(PROF_Z80);
	} /*
	    else
	    my_timer();*/

	if (!conf.debug) {
	    if (conf.raster) {
		for (i = 0; i < 261; i++) {
		    tm_cycle=cpu_68k_run(cpu_68k_timeslice_scanline-tm_cycle);
		    if (update_scanline())
			cpu_68k_interrupt(2);
		}
		tm_cycle=cpu_68k_run(cpu_68k_timeslice_scanline-tm_cycle);
		state_handling(pending_save_state,pending_load_state);
		
		update_screen();
		cpu_68k_interrupt(1);
	    } else {
		PROFILER_START(PROF_68K);
		tm_cycle=cpu_68k_run(cpu_68k_timeslice-tm_cycle);
		PROFILER_STOP(PROF_68K);
		a = neo_interrupt();
		
		/* state handling (we save/load before interrupt) */
		state_handling(pending_save_state,pending_load_state);
		
		if (a) {
		    cpu_68k_interrupt(a);
		}
	    }
	} else {
	    /* we arre in debug mode -> we are just here for event handling */
	    neo_emu_done=1;
	}
#ifdef ENABLE_PROFILER
	profiler_show_stat();
#endif
	PROFILER_START(PROF_ALL);
    }
}
示例#16
0
int handle_event(void) {
	SDL_Event event;
//	int i;
	int ret;
	int jaxis_threshold=10000;
	//int jaxis_threshold=2;

	while (SDL_PollEvent(&event)) {
	    if ((ret=handle_pdep_event(&event))!=0) {
	    	return ret;
	    }
		switch (event.type) {
		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:
				//printf("%d\n", event.key.keysym.sym);
				if (show_keysym) output_keysym(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;

	/* Update P1 */
	memory.intern_p1 = 0xFF;
	if (joy_state[0][GN_UP] && (!joy_state[0][GN_DOWN]))
	    memory.intern_p1 &= 0xFE;
	if (joy_state[0][GN_DOWN] && (!joy_state[0][GN_UP]))
	    memory.intern_p1 &= 0xFD;
	if (joy_state[0][GN_LEFT] && (!joy_state[0][GN_RIGHT]))
	    memory.intern_p1 &= 0xFB;
	if (joy_state[0][GN_RIGHT] && (!joy_state[0][GN_LEFT]))
	    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;

}
示例#17
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;
    
}