예제 #1
0
static RETSIGTYPE alarmhandler(int foo)
#endif
{
    frame_time_t bar;
    struct sigaction sa;
    sa.sa_flags = SA_RESTART;
#ifdef SA_ONSTACK
    sa.sa_flags |= SA_ONSTACK;
#endif
    sigemptyset (&sa.sa_mask);
    bar = read_processor_time ();
    if (! first_loop && bar - last_time < best_time)
	best_time = bar - last_time;
    first_loop = 0;
    if (--loops_to_go > 0) {
	sa.sa_handler = alarmhandler;
	sigaction (SIGALRM, &sa, NULL);
	last_time = read_processor_time ();
	set_the_alarm ();
    } else {
	alarm (0);
	sa.sa_handler = SIG_IGN;
	sigaction (SIGALRM, &sa, NULL);
    }
}
예제 #2
0
/*
 * Sleep for ms milliseconds either using an appropriate sleep routine on the
 * target system or, if the target's routine has too much latency to
 * accurately sleep for that period, then busy wait.
 *
 * Busy-waiting requires a high-resolution timer for accuracy. We use
 * the machine-dependent read_processor_time ()
 */
void sleep_millis (int ms)
{
    frame_time_t start = read_processor_time ();
    int sleep_time;

#ifndef SLEEP_DONT_BUSY_WAIT
    if (!currprefs.dont_busy_wait && ms < SLEEP_BUSY_THRESHOLD) {
	/* Typical sleep routines can't sleep for less than 10ms. If we want
	 * to sleep for a period shorter than the threshold, we'll have to busy wait . . .
	 */
	int end = start + ms * syncbase / 1000;
	int v;

        do {
	    v = (int)read_processor_time ();
	} while (v < end && v > -end);
    } else
#endif
	uae_msleep (ms);

    sleep_time = read_processor_time () - start;
    if (sleep_time < 0)
	sleep_time = -sleep_time;

    idletime += sleep_time;
}
예제 #3
0
static void do_call_function (struct uni *uni) {
    printf("uni: calling native function %p\n", uni->native_function);

    unsigned long start_time;
    const int flags = uni->flags;
    if ((flags & UNI_FLAG_ASYNCHRONOUS) == 0) {
        start_time = read_processor_time ();
    }

    if (uni->flags & UNI_FLAG_COMPAT) {
#if defined(X86_MSVC_ASSEMBLY)
        uni->result = (uae_s32) do_call_function_compat_asm(uni);
#else
        uni->result = ((uae_uni_native_compat_function) uni->native_function) (
                uni->d1, uni->d2, uni->d3, uni->d4, uni->d5, uni->d6,
                uni->d7, uni->a1, uni->a2, uni->a3, uni->a4, uni->a5,
                uni->uaevar_compat, uni->a7, &regs);
#endif
    }
    else {
        uni->result = ((uae_uni_native_function) uni->native_function) (uni);
    }

    if ((flags & UNI_FLAG_ASYNCHRONOUS) == 0) {
        unsigned long time_diff = read_processor_time () - start_time;
        double v = syncdivisor * time_diff;
        if (v > 0) {
            if (v > 1000000 * CYCLE_UNIT) {
                v = 1000000 * CYCLE_UNIT;
            }
            // compensate for the time spent in the native function
            do_extra_cycles ((unsigned long) (syncdivisor * time_diff));
        }
    }
}
예제 #4
0
void wait_for_vsync(void)
{
  unsigned long start = read_processor_time();
  int wait_till = host_frame;
  do {
    usleep(10);
  } while (wait_till >= host_frame && read_processor_time() - start < 500000); // wait max. 0.5 sec
}
예제 #5
0
void show_screen(int mode)
{
  unsigned long start = read_processor_time();

  last_synctime = start;
  while(last_synctime < next_amiga_frame_ends && last_synctime < start + time_per_frame) {
    usleep(10);
    last_synctime = read_processor_time();
  }
  amiga_frame = amiga_frame + 1 + currprefs.gfx_framerate;

  if(amiga_frame == currVSyncRate) {
    bool do_check = true;
    if(host_frame < host_hz) {
      // we are here before relevant vsync occured
      wait_for_vsync();
      if(sync_was_bogus)
        do_check = false;
    }
    if(do_check && host_frame == host_hz) {
      // Check time difference between Amiga and host sync.
      // If difference is too big, slightly ajust time per frame.
      long diff;
      static long last_diff = 0;
      if(next_amiga_frame_ends > host_frame_timestamp) {
        diff = next_amiga_frame_ends - host_frame_timestamp;
        if(diff > 50 && last_diff != 0 && diff > last_diff)
          time_per_frame--;
        last_diff = diff;
      } else {
        diff = host_frame_timestamp - next_amiga_frame_ends;
        if(diff > time_per_frame / 2) {
          next_amiga_frame_ends += time_per_frame;
          diff = -diff;
          last_diff = 0;
        } else {
          diff = -diff;
          if(diff < -50 && last_diff != 0 && diff < last_diff)
            time_per_frame++;
          last_diff = diff;
        }
      }
      write_log("Diff Amiga frame to host: %6d, time_per_frame = %6d\n", diff, time_per_frame);
    }
    host_frame = 0;
    amiga_frame = 0;
  }
  
  next_amiga_frame_ends += time_per_frame;
  if(currprefs.gfx_framerate)
    next_amiga_frame_ends += time_per_frame;
    
	wait_for_display_thread();
	write_comm_pipe_u32(display_pipe, DISPLAY_SIGNAL_SHOW, 1);

  idletime += last_synctime - start;
}
예제 #6
0
void do_cycles_slow (unsigned long cycles_to_add)
{
	if ((pissoff -= cycles_to_add) >= 0)
		return;

	cycles_to_add = -pissoff;
	pissoff = 0;

	while ((nextevent - currcycle) <= cycles_to_add) {
		int i;

		/* Keep only CPU emulation running while waiting for sync point. */
		if (is_syncline) {
			if (!vblank_found_chipset) {
				if (is_syncline > 0) {
					int rpt = read_processor_time ();
					int v = rpt - vsyncmintime;
					int v2 = rpt - is_syncline_end;
					if (v > vsynctimebase || v < -vsynctimebase) {
						v = 0;
					}
					if (v < 0 && v2 < 0) {
						pissoff = pissoff_value;
						return;
					}
				} else if (is_syncline < 0) {
					int rpt = read_processor_time ();
					int v = rpt - is_syncline_end;
					if (v < 0) {
						pissoff = pissoff_value;
						return;
					}
				}
			}
			is_syncline = 0;
		}

		cycles_to_add -= nextevent - currcycle;
		currcycle = nextevent;

		for (i = 0; i < ev_max; i++) {
			iwas1 = i;
			if (eventtab[i].active && eventtab[i].evtime == currcycle) {
				iwas2 = i;
				ihandled = -1;
				(*eventtab[i].handler)();
				ihandled = 1;
			}
		}
		events_schedule ();


	}
	currcycle += cycles_to_add;
}
예제 #7
0
파일: events.c 프로젝트: engur/PUAE
void do_cycles_slow (unsigned long cycles_to_add)
{
	if ((pissoff -= cycles_to_add) >= 0)
		return;

	cycles_to_add = -pissoff;
	pissoff = 0;

	while ((nextevent - currcycle) <= cycles_to_add) {
		int i;

		/* Keep only CPU emulation running while waiting for sync point. */
		if (is_syncline > 0) {
			int rpt = read_processor_time ();
			int v = rpt - vsyncmintime;
			int v2 = rpt - is_syncline_end;
			if (v > vsynctimebase || v < -vsynctimebase) {
				v = 0;
			}
			if (v < 0 && v2 < 0) {
				pissoff = pissoff_value;
				return;
			}
		} else if (is_syncline < 0) {
			int rpt = read_processor_time ();
			int v = rpt - is_syncline_end;
			if (v < 0) {
				pissoff = pissoff_value;
				return;
			}
			is_syncline = 0;
		}

		cycles_to_add -= nextevent - currcycle;
		currcycle = nextevent;

		for (i = 0; i < ev_max; i++) {
			if (eventtab[i].active && eventtab[i].evtime == currcycle) {
				if (eventtab[i].handler == NULL) {
					gui_message(_T("eventtab[%d].handler is null!\n"), i);
					eventtab[i].active = 0;
				} else {
					(*eventtab[i].handler)();
				}
			}
		}
		events_schedule ();


	}
	currcycle += cycles_to_add;
}
예제 #8
0
/*
 * Measure how long it takes to do a ms millisecond sleep. Timing is performed
 * with a machine-specific high-resolution timer.
 */
static int do_sleep_test (int ms)
{
    int t;
    int t2;

    t = read_processor_time ();
    uae_msleep (ms);
    t2 = read_processor_time () - t;

    if (t2 < 0)
	t2 = -t2;

    return t2;
}
예제 #9
0
파일: video.cpp 프로젝트: eehrich/fs-uae
frame_time_t vsync_busywait_end (int *flipdelay) {
#if 0
    printf("vsync_busywait_end\n");
    show_screen ();

    static int last_vblank = 0;
    while (fs_ml_get_vblank_count() == last_vblank) {

    }
    last_vblank++;// = fs_ml_get_vblank_count();

    if (!dooddevenskip) {
#if 0
        vsync_notvblank ();
        while (!vblank_found && vblankthread_mode == VBLANKTH_ACTIVE) {
            vsync_sleep (currprefs.m68k_speed < 0);
        }
#endif
    }
    //changevblankthreadmode_fast (VBLANKTH_ACTIVE_WAIT);
#if 0
    return thread_vblank_time;

    write_log("vsync_busywait_end\n");
#endif
#endif
    return read_processor_time();
}
예제 #10
0
파일: support.c 프로젝트: Yamakuzure/PUAE
static RETSIGTYPE alarmhandler(int32_t foo)
#endif
{
    frame_time_t bar;
    bar = read_processor_time ();
    if (! first_loop && bar - last_time < best_time)
	best_time = bar - last_time;
    first_loop = 0;
    if (--loops_to_go > 0) {
		signal (SIGALRM, alarmhandler);
		last_time = read_processor_time ();
		set_the_alarm ();
    } else {
		alarm (0);
		signal (SIGALRM, SIG_IGN);
    }
}
예제 #11
0
파일: support.c 프로젝트: ApolloniaUK/PUAE
/*
 * Calibrate PPC timebase frequency the hard way...
 * This is still dumb and horribly inefficient.
 */
static frame_time_t machdep_calibrate_timebase (void)
{
    const int num_loops = 5;
    frame_time_t last_time;
    frame_time_t best_time;
    int i;

    write_log ("Calibrating timebase...\n");
    flush_log ();

    sync ();
    last_time = read_processor_time ();
    for (i = 0; i < num_loops; i++)
	uae_msleep (1000);
    best_time = read_processor_time () - last_time;

    return best_time / num_loops;
}
예제 #12
0
int machdep_init (void)
{
  picasso_requested_on = 0;
  picasso_on = 0;
  screen_is_picasso = 0;

  // Initialize timebase
  g_uae_epoch = read_processor_time();
  syncbase = 1000000; // Microseconds

  return 1;
}
예제 #13
0
void machdep_init (void)
{
    static int done = 0;

    if (!done) {
	rpt_available = 1;

	write_log ("Calibrating timebase: ");
	flush_log ();

	loops_to_go = 5;
	sync ();
	last_time = read_processor_time ();
	uae_msleep (loops_to_go * 1000);
	best_time = read_processor_time () - last_time;

	syncbase = best_time / loops_to_go;
	write_log ("%.6f MHz\n", (double) syncbase / 1000000);

	sleep_test();

	done = 1;
    }
}
예제 #14
0
void vsync_callback(unsigned int a, void* b)
{
  atomic_inc(&host_frame);

  unsigned long currsync = read_processor_time();
  if(host_frame_timestamp == 0) {
    // first sync after start or after bogus frame
    host_frame_timestamp = currsync;
    sync_was_bogus = true;
    return;
  }
  unsigned long diff = currsync - host_frame_timestamp;
  if(diff < time_per_host_frame - sync_epsilon || diff > time_per_host_frame + sync_epsilon) {
    if(diff >= time_per_host_frame * 2 - sync_epsilon && diff < time_per_host_frame * 2 + sync_epsilon) {
      // two frames since last vsync
      atomic_inc(&host_frame);
      host_frame_timestamp = currsync;
      sync_was_bogus = false;
    } else {
      // Bogus frame -> ignore this and next
      host_frame_timestamp = 0;
      sync_was_bogus = true;
    }
    return; // no calibrate if two frames or bogus frame
  }

  sync_was_bogus = false;
  host_frame_timestamp = currsync;

  if(!calibrate_done) {
    if(calibrate_frames < 0) {
      calibrate_frames = calibrate_seconds * host_hz;
    }
    calibrate_frames--;
    calibrate_total += diff;
    if(calibrate_frames == 0) {
      // done
      time_for_host_hz_frames = calibrate_total / calibrate_seconds;
      time_per_host_frame = time_for_host_hz_frames / host_hz;
      time_per_frame = time_for_host_hz_frames / (currprefs.chipset_refreshrate);
      sound_adjust(1000000.0f / (float)time_for_host_hz_frames);
      write_log("calibrate: time_for_host_hz_frames = %ld\n", time_for_host_hz_frames);
      calibrate_frames = -1;
      calibrate_total = 0;
      calibrate_done = true;
    }
  }
}
예제 #15
0
void flush_screen ()
{
	if (show_inputmode)
		inputmode_redraw();	

	if (savestate_state == STATE_DOSAVE)
	{
    if(delay_savestate_frame > 0)
      --delay_savestate_frame;
    else
    {
	    CreateScreenshot();
		  save_thumb(screenshot_filename);
	    savestate_state = 0;
    }
  }

  unsigned long start = read_processor_time();
  if(start < next_synctime && next_synctime - start > time_per_frame - 1000)
    usleep((next_synctime - start) - 750);

  SDL_Flip(prSDLScreen);
  last_synctime = read_processor_time();

  if(!screen_is_picasso)
  	gfxvidinfo.bufmem = (uae_u8 *)prSDLScreen->pixels;
  
  if(last_synctime - next_synctime > time_per_frame - 1000)
    adjust_idletime(0);
  else
    adjust_idletime(next_synctime - start);
  
  if(last_synctime - next_synctime > time_per_frame - 5000)
    next_synctime = last_synctime + time_per_frame * (1 + currprefs.gfx_framerate);
  else
    next_synctime = next_synctime + time_per_frame * (1 + currprefs.gfx_framerate);

	init_row_map();

	if(stylusClickOverride)
	{
		justClicked = 0;
		mouseMoving = 0;
	}
	else
	{
		if(justClicked)
		{
			buttonstate[0] = 0;
			buttonstate[2] = 0;
			justClicked = 0;
		}

		if(mouseMoving)
		{
			if(fcounter >= currprefs.pandora_tapDelay)
			{
				if(doStylusRightClick)
			  {
					buttonstate[2] = 1;
        }
				else
			  {
					buttonstate[0] = 1;
  				mouseMoving = 0;
  				justClicked = 1;
  				fcounter = 0;
				}
			}
			fcounter++;
		}
	}
}
예제 #16
0
bool vsync_busywait_do (int *freetime, bool lace, bool oddeven)
{
	bool v;
	static bool framelost;
	int ti;
	frame_time_t t;
	frame_time_t prevtime = vblank_prev_time;
	struct apmode *ap = picasso_on ? &currprefs.gfx_apmode[1] : &currprefs.gfx_apmode[0];

	t = read_processor_time ();
	ti = t - prevtime;
	if (ti) {
		waitvblankstate (false, NULL, NULL);
		vblank_prev_time = t;

		return true;
	}

	if (freetime)
		*freetime = 0;
	v = 0;

	if (isthreadedvsync ()) {

		framelost = false;
		v = 1;

	} else {
		int vp;

		if (currprefs.turbo_emulation) {
			show_screen (0);
			vblank_prev_time = read_processor_time ();
			framelost = true;
			v = -1;

		} else {
			while (!framelost && read_processor_time () - prevtime < 0) {
				vsync_sleep (false);
			}
			vp = vblank_wait ();
			if (vp >= -1) {
				vblank_prev_time = read_processor_time ();
				if (ap->gfx_vflip == 0) {
					show_screen (0);
				}
				for (;;) {
					if (!getvblankpos (&vp))
						break;
					if (vp > 0)
						break;
					sleep_millis (1);
				}
				if (ap->gfx_vflip != 0) {
					show_screen (0);
				}
				v = framelost ? -1 : 1;
			}

			framelost = false;
		}
		getvblankpos (&vp);
	}

		return v;
	}
예제 #17
0
int machdep_inithrtimer (void)
{
    static int done = 0;

    if (!done) {
	struct sigaction sa;
	sa.sa_flags = SA_RESTART;
#ifdef SA_ONSTACK
	sa.sa_flags |= SA_ONSTACK;
#endif
	sigemptyset (&sa.sa_mask);
	rpt_available = 1;

	write_log ("Testing the RDTSC instruction ... ");
	sa.sa_handler = illhandler;
	sigaction (SIGILL, &sa, NULL);
	if (setjmp (catch_test) == 0)
	    read_processor_time ();
	sa.sa_handler = SIG_DFL;
	sigaction (SIGILL, &sa, NULL);
	write_log ("done.\n");

	if (! rpt_available) {
	    write_log ("Your processor does not support the RDTSC instruction.\n");
	    return 0;
	}

	timebase = 0;

#ifdef __linux__
	timebase = linux_get_tsc_freq ();
#else
# ifdef __BEOS__
	timebase = beos_get_tsc_freq ();
# endif
#endif

	if (timebase <= 0) {
#ifdef USE_ALARM
	    struct sigaction sa;
	    sa.sa_flags = SA_RESTART;
#ifdef SA_ONSTACK
	    sa.sa_flags |= SA_ONSTACK;
#endif
	    sigemptyset (&sa.sa_mask);
#endif

	    write_log ("Calibrating TSC frequency...");
	    flush_log ();

	    best_time = MAX_FRAME_TIME;
	    loops_to_go = 5;

#ifdef USE_ALARM
	    sa.sa_handler = alarmhandler;
	    sigaction (SIGALRM, &sa, NULL);
#endif

	    /* We want exact values... */
	    sync (); sync (); sync ();

#ifdef USE_ALARM
	    last_time = read_processor_time ();
	    set_the_alarm ();

	    while (loops_to_go != 0)
		uae_msleep (10);
#else
	    int i = loops_to_go;
	    frame_time_t bar;

	    while (i-- > 0) {
		last_time = read_processor_time ();
		uae_msleep (TIME_DELAY);
		bar = read_processor_time ();
		if (i != loops_to_go && bar - last_time < best_time)
		    best_time = bar - last_time;
	    }
#endif

	    timebase = best_time * (1000000.0 / TIME_UNIT);
	}

	write_log ("TSC frequency: %f MHz\n", timebase / 1000000.0);

	done = 1;
     }
     return done;
}
예제 #18
0
void flush_screen ()
{
	if (savestate_state == STATE_DOSAVE)
	{
    if(delay_savestate_frame > 0)
      --delay_savestate_frame;
    else
    {
	    CreateScreenshot();
		  save_thumb(screenshot_filename);
	    savestate_state = 0;
    }
  }

#ifdef WITH_LOGGING
  RefreshLiveInfo();
#endif

  unsigned long start = read_processor_time();
  if(current_vsync_frame == 0) 
  {
    // Old style for vsync and idle time calc
    if(start < next_synctime && next_synctime - start > time_per_frame - 1000)
      usleep((next_synctime - start) - 750);
    ioctl(fbdev, OMAPFB_WAITFORVSYNC, &current_vsync_frame);
  } 
  else 
    {
    // New style for vsync and idle time calc
    int wait_till = current_vsync_frame;
    do 
    {
      ioctl(fbdev, OMAPFB_WAITFORVSYNC_FRAME, &current_vsync_frame);
    } while (wait_till >= current_vsync_frame);
    
    if(wait_till + 1 != current_vsync_frame) 
    {
      // We missed a vsync...
      next_synctime = 0;
    }
    current_vsync_frame += currprefs.gfx_framerate;
  }
    
  last_synctime = read_processor_time();
  SDL_Flip(prSDLScreen);

  if(!screen_is_picasso)
  	gfxvidinfo.bufmem = (uae_u8 *)prSDLScreen->pixels;

  if(last_synctime - next_synctime > time_per_frame * (1 + currprefs.gfx_framerate) - 1000 || next_synctime < start)
    adjust_idletime(-1);
  else
    adjust_idletime(next_synctime - start);
  
  if (last_synctime - next_synctime > time_per_frame - (long)5000)
    next_synctime = last_synctime + time_per_frame * (1 + currprefs.gfx_framerate);
  else
    next_synctime = next_synctime + time_per_frame * (1 + currprefs.gfx_framerate);

	init_row_map();
}
예제 #19
0
void flush_screen ()
{
    //SDL_UnlockSurface (prSDLScreen);

    if (show_inputmode)
    {
        inputmode_redraw();	
    }


    if (savestate_state == STATE_DOSAVE)
    {
    if(delay_savestate_frame > 0)
      --delay_savestate_frame;
    else
    {
        CreateScreenshot();
        save_thumb(screenshot_filename);
        savestate_state = 0;
    }
  }

  unsigned long start = read_processor_time();
  //if(start < next_synctime && next_synctime - start > time_per_frame - 1000)
  //  usleep((next_synctime - start) - 1000);
  //SDL_Flip(prSDLScreen);


	if (current_resource_amigafb == 1)
	{
		current_resource_amigafb = 0;
		vc_dispmanx_resource_write_data(  dispmanxresource_amigafb_1,
	                                    VC_IMAGE_RGB565,
	                                    gfxvidinfo.width * 2,
	                                    gfxvidinfo.bufmem,
	                                    &blit_rect );
		dispmanxupdate = vc_dispmanx_update_start( 10 );
		vc_dispmanx_element_change_source(dispmanxupdate,dispmanxelement,dispmanxresource_amigafb_1);

		vc_dispmanx_update_submit(dispmanxupdate,vsync_callback,NULL);
		//vc_dispmanx_update_submit_sync(dispmanxupdate);

	}
	else
	{
		current_resource_amigafb = 1;
		vc_dispmanx_resource_write_data(  dispmanxresource_amigafb_2,
	                                    VC_IMAGE_RGB565,
	                                    gfxvidinfo.width * 2,
	                                    gfxvidinfo.bufmem,
	                                    &blit_rect );
		dispmanxupdate = vc_dispmanx_update_start( 10 );
		vc_dispmanx_element_change_source(dispmanxupdate,dispmanxelement,dispmanxresource_amigafb_2);

		vc_dispmanx_update_submit(dispmanxupdate,vsync_callback,NULL);
	}

  last_synctime = read_processor_time();
  
  if(last_synctime - next_synctime > time_per_frame - 1000)
    adjust_idletime(0);
  else
    adjust_idletime(next_synctime - start);
  
  if(last_synctime - next_synctime > time_per_frame - 5000)
    next_synctime = last_synctime + time_per_frame * (1 + currprefs.gfx_framerate);
  else
    next_synctime = next_synctime + time_per_frame * (1 + currprefs.gfx_framerate);

	init_row_map();

}
예제 #20
0
static bool event_check_vsync(void)
{
	/* Keep only CPU emulation running while waiting for sync point. */
	if (is_syncline == -1) {

		if (!isvsync_chipset()) {
			events_reset_syncline();
			return false;
		}
		// wait for vblank
		audio_finish_pull();
		int done = vsync_isdone(NULL);
		if (done == -2) {
			// if no vsync thread
			int vp = target_get_display_scanline(-1);
			if (vp < is_syncline_end)
				done = 1;
			else if (vp > is_syncline_end)
				is_syncline_end = vp;
		}
		if (!done) {
#ifdef WITH_PPC
			if (ppc_state) {
				uae_ppc_execute_quick();
			}
#endif
			if (currprefs.cachesize)
				pissoff = pissoff_value;
			else
				pissoff = pissoff_nojit_value;
			return true;
		}
		vsync_clear();
		vsync_event_done();

	} else if (is_syncline == -2) {

		if (!isvsync_chipset()) {
			events_reset_syncline();
			return false;
		}
		// wait for vblank or early vblank
		audio_finish_pull();
		int done = vsync_isdone(NULL);
		if (done == -2)
			done = 0;
		int vp = target_get_display_scanline(-1);
		if (vp < 0 || vp >= is_syncline_end)
			done = 1;
		if (!done) {
#ifdef WITH_PPC
			if (ppc_state) {
				uae_ppc_execute_quick();
			}
#endif
			if (currprefs.cachesize)
				pissoff = pissoff_value;
			else
				pissoff = pissoff_nojit_value;
			return true;
		}
		vsync_clear();
		vsync_event_done();

	} else if (is_syncline == -3) {
		if (!isvsync_chipset()) {
			events_reset_syncline();
			return false;
		}
		// not vblank
		audio_finish_pull();
		int vp = target_get_display_scanline(-1);
		if (vp <= 0) {
#ifdef WITH_PPC
			if (ppc_state) {
				uae_ppc_execute_quick();
			}
#endif
			if (currprefs.cachesize)
				pissoff = pissoff_value;
			else
				pissoff = pissoff_nojit_value;
			return true;
		}
		vsync_clear();
		vsync_event_done();

	} else if (is_syncline > 0) {

		if (!isvsync_chipset()) {
			events_reset_syncline();
			return false;
		}
		audio_finish_pull();
		// wait for specific scanline
		int vp = target_get_display_scanline(-1);
		if (vp < 0 || is_syncline > vp) {
#ifdef WITH_PPC
			if (ppc_state) {
				uae_ppc_execute_check();
			}
#endif
			if (currprefs.cachesize)
				pissoff = pissoff_value;
			else
				pissoff = pissoff_nojit_value;
			return true;
		}
		vsync_event_done();

	}
	else if (is_syncline <= -100) {

		if (!isvsync_chipset()) {
			events_reset_syncline();
			return false;
		}
		audio_finish_pull();
		// wait for specific scanline
		int vp = target_get_display_scanline(-1);
		if (vp < 0 || vp >= (-(is_syncline + 100))) {
#ifdef WITH_PPC
			if (ppc_state) {
				uae_ppc_execute_check();
			}
#endif
			if (currprefs.cachesize)
				pissoff = pissoff_value;
			else
				pissoff = pissoff_nojit_value;
			return true;
		}
		vsync_event_done();

	} else if (is_syncline == -10) {

		// wait is_syncline_end
		if (event_wait) {
			int rpt = read_processor_time();
			int v = rpt - is_syncline_end;
			if (v < 0) {
#ifdef WITH_PPC
				if (ppc_state) {
					uae_ppc_execute_check();
				}
#endif
				if (currprefs.cachesize)
					pissoff = pissoff_value;
				else
					pissoff = pissoff_nojit_value;
				return true;
			}
		}
		events_reset_syncline();

	} else if (is_syncline < -10) {

		// wait is_syncline_end/vsyncmintime
		if (event_wait) {
			int rpt = read_processor_time();
			int v = rpt - vsyncmintime;
			int v2 = rpt - is_syncline_end;
			if (v > vsynctimebase || v < -vsynctimebase) {
				v = 0;
			}
			if (v < 0 && v2 < 0) {
#ifdef WITH_PPC
				if (ppc_state) {
					if (is_syncline == -11) {
						uae_ppc_execute_check();
					} else {
						uae_ppc_execute_quick();
					}
				}
#endif
				if (currprefs.cachesize)
					pissoff = pissoff_value;
				else
					pissoff = pissoff_nojit_value;
				return true;
			}
		}
		events_reset_syncline();
	}
	return false;
}
예제 #21
0
void real_main (int argc, char **argv)
{
	int numb;
	char pattern[100];
	char txt[100];
#ifdef USE_SDL
    SDL_Init (SDL_INIT_VIDEO | SDL_INIT_JOYSTICK 
#if !defined(NO_SOUND) && !defined(GP2X)
 			| SDL_INIT_AUDIO
#endif
	);
#endif
  // Initialize timebase
  g_uae_epoch = read_processor_time();
  syncbase = 1000000; // Microseconds

	//------------------------------------------
	//just safe the game conf file for later use
	//------------------------------------------
	if (argc > 1)
	{
		if (strlen(argv[1]) < 255)
		{
			strcpy(uae4all_game_conf_file0, argv[1]);

			strcpy(uae4all_game_conf_file1, argv[1]);
			strcpy(uae4all_game_conf_file2, argv[1]);
			strcpy(uae4all_game_conf_file3, argv[1]);
			strcpy(uae4all_game_conf_file4, argv[1]);
			strcpy(uae4all_game_conf_file5, argv[1]);
			strcpy(uae4all_game_conf_file6, argv[1]);
			strcpy(uae4all_game_conf_file7, argv[1]);
			getNumber(uae4all_game_conf_file0, "disk 1 of %", &numb);

			strcpy(pattern, "disk %");
			sprintf(txt, " of %d", numb);
			strcat(pattern, txt);
		    replaceNumber(uae4all_game_conf_file1, pattern, '2');

			strcpy(pattern, "disk %");
			sprintf(txt, " of %d", numb);
			strcat(pattern, txt);
		    replaceNumber(uae4all_game_conf_file2, pattern, '3');

			strcpy(pattern, "disk %");
			sprintf(txt, " of %d", numb);
			strcat(pattern, txt);
		    replaceNumber(uae4all_game_conf_file3, pattern, '4');

			strcpy(pattern, "disk %");
			sprintf(txt, " of %d", numb);
			strcat(pattern, txt);
		    replaceNumber(uae4all_game_conf_file4, pattern, '5');

			strcpy(pattern, "disk %");
			sprintf(txt, " of %d", numb);
			strcat(pattern, txt);
		    replaceNumber(uae4all_game_conf_file5, pattern, '6');

			strcpy(pattern, "disk %");
			sprintf(txt, " of %d", numb);
			strcat(pattern, txt);
		    replaceNumber(uae4all_game_conf_file6, pattern, '7');

			strcpy(pattern, "disk %");
			sprintf(txt, " of %d", numb);
			strcat(pattern, txt);
		    replaceNumber(uae4all_game_conf_file7, pattern, '8');

		}
	}

	getcwd(launchDir,250);
    /* PocketUAE prefs */
    default_prefs_uae (&currprefs);
    default_prefs();
#ifdef GP2X
    gp2x_init(argc, argv);
#endif
		// Set everthing to default and clear HD settings
		SetDefaultMenuSettings(1);
    loadconfig (1);

    if (! graphics_setup ()) {
		exit (1);
    }

    rtarea_init ();

	hardfile_install();

    if (! setup_sound ()) {
		write_log ("Sound driver unavailable: Sound output disabled\n");
		produce_sound = 0;
    }
    init_joystick ();

	int err = gui_init ();
	if (err == -1) {
	    write_log ("Failed to initialize the GUI\n");
	} else if (err == -2) {
	    exit (0);
	}
    if (sound_available && produce_sound > 1 && ! init_audio ()) {
		write_log ("Sound driver unavailable: Sound output disabled\n");
		produce_sound = 0;
    }

    /* Install resident module to get 8MB chipmem, if requested */
    rtarea_setup ();

    keybuf_init (); /* Must come after init_joystick */

#ifdef USE_AUTOCONFIG
    expansion_init ();
#endif

    memory_init ();

    filesys_install (); 
    native2amiga_install ();

    custom_init (); /* Must come after memory_init */
    DISK_init ();

    m68k_init(0);
    gui_update ();

#ifdef GP2X
    switch_to_hw_sdl(1);
#endif
	{
		start_program ();
	}
    leave_program ();
}
예제 #22
0
파일: video.cpp 프로젝트: eehrich/fs-uae
int vsync_busywait_do (int *freetime, bool lace, bool oddeven) {
    UAE_LOG_STUB("");
    return false;
#if 0
    bool v;
    static bool framelost;
    int ti;
    frame_time_t t;
    frame_time_t prevtime = vblank_prev_time;

    dooddevenskip = false;

    if (lace)
        vblankbaselace_chipset = oddeven;
    else
        vblankbaselace_chipset = -1;

    t = read_processor_time ();
    ti = t - prevtime;
    //if (ti > 2 * vblankbasefull || ti < -2 * vblankbasefull) {
    if (ti > 1 * vblankbasefull || ti < -1 * vblankbasefull) {
#if 0
        waitvblankstate (false, NULL);
#endif
        t = read_processor_time ();
        vblank_prev_time = t;
        thread_vblank_time = t;
        frame_missed++;
        return true;
    }

    //if (log_vsync) {
    //    console_out_f(_T("F:%8d M:%8d E:%8d %3d%% (%3d%%) %10d\r"), frame_counted, frame_missed, frame_errors, frame_usage, frame_usage_avg, (t - vblank_prev_time) - vblankbasefull);
    //}

    if (freetime)
        *freetime = 0;
    if (currprefs.turbo_emulation) {
        frame_missed++;
        return true;
    }
#if 0
    frame_usage = (t - prevtime) * 100 / vblankbasefull;
    if (frame_usage > 99)
        frame_usage = 99;
    else if (frame_usage < 0)
        frame_usage = 0;
    frame_usage_total += frame_usage;
    if (freetime)
        *freetime = frame_usage;
    if (frame_counted)
        frame_usage_avg = frame_usage_total / frame_counted;
#endif
    v = false;

    if (isthreadedvsync ()) {

        framelost = false;
        v = true;

    } else {
#if 0
        bool doskip = false;

        if (!framelost && t - prevtime > vblankbasefull) {
            framelost = true;
            frame_missed++;
            return true;
        }

        if (vblanklaceskip ()) {
            doskip = true;
            dooddevenskip = true;
        }

        if (!doskip) {
            while (!framelost && read_processor_time () - prevtime < vblankbasewait1) {
                vsync_sleep (false);
            }
            v = vblank_wait ();
        } else {
            v = true;
        }
        framelost = false;
#endif
    }

    if (v) {
        vblank_prev_time = read_processor_time ();
        frame_counted++;
        return true;
    }
    frame_errors++;
    return false;
#endif
}
예제 #23
0
파일: support.c 프로젝트: Yamakuzure/PUAE
int32_t machdep_inithrtimer (void)
{
    static int32_t done = 0;

    if (!done) {
//		rpt_available = 1;

		write_log ("Testing the RDTSC instruction ... ");
		signal (SIGILL, illhandler);
		if (setjmp (catch_test) == 0)
		    read_processor_time ();
		signal (SIGILL, SIG_DFL);
		write_log ("done.\n");

/*		if (! rpt_available) {
		    write_log ("Your processor does not support the RDTSC instruction.\n");
			return 0;
		}*/

		timebase = 0;
#ifdef __linux__
		timebase = linux_get_tsc_freq ();
#else
#ifdef __BEOS__
		timebase = beos_get_tsc_freq ();
#endif
#ifdef __APPLE__
//		timebase = apple_get_tsc_freq ();
#endif
#endif

		if (timebase <= 0) {
		    write_log ("Calibrating TSC frequency...");
		    flush_log ();

		    best_time = MAX_FRAME_TIME;
		    loops_to_go = 5;

#ifdef USE_ALARM
		    signal (SIGALRM, alarmhandler);
#endif

	    /* We want exact values... */
	    sync (); sync (); sync ();

#ifdef USE_ALARM
	    last_time = read_processor_time ();
	    set_the_alarm ();

	    while (loops_to_go != 0)
		uae_msleep (10);
#else
	    int32_t i = loops_to_go;
	    frame_time_t bar;

	    while (i-- > 0) {
		last_time = read_processor_time ();
		uae_msleep (TIME_DELAY);
		bar = read_processor_time ();
		if (i != loops_to_go && bar - last_time < best_time)
		    best_time = bar - last_time;
	    }
#endif

	    timebase = best_time * (1000000.0 / TIME_UNIT);
	}

	write_log ("TSC frequency: %f MHz\n", timebase / 1000000.0);
	done = 1;
     }
     return done;
}