/* * 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; }
static int unit_ready (SCSI *scgp) { register struct scg_cmd *scmd = scgp->scmd; if (test_unit_ready(scgp) >= 0) /* alles OK */ return 1; else if (scmd->error >= SCG_FATAL) /* nicht selektierbar */ return 0; if (scg_sense_key(scgp) == SC_UNIT_ATTENTION) { if (test_unit_ready(scgp) >= 0) /* alles OK */ return 1; } if ((scg_cmd_status(scgp) & ST_BUSY) != 0) { /* Busy/reservation_conflict */ uae_msleep (500); if (test_unit_ready(scgp) >= 0) /* alles OK */ return 1; } if (scg_sense_key(scgp) == -1) { /* non extended Sense */ if (scg_sense_code(scgp) == 4) /* NOT_READY */ return 0; return 1; } /* FALSE wenn NOT_READY */ return (scg_sense_key (scgp) != SC_NOT_READY); }
/* * 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; }
static void abort_async (struct devstruct *dev, uaecptr request, int errcode, int type) { int i; i = 0; while (i < MAX_ASYNC_REQUESTS) { if (dev->d_request[i] == request && dev->d_request_type[i] == ASYNC_REQUEST_TEMP) { /* ASYNC_REQUEST_TEMP = request is processing */ uae_msleep (10); i = 0; continue; } i++; } i = release_async_request (dev, request); if (i >= 0 && log_scsi) write_log ("asyncronous request=%08.8X aborted, error=%d\n", request, errcode); }
/* * 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; }
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; } }
void sleep_millis_main (int ms) { uae_msleep (ms); }
/* * Here's where all the action takes place! */ void real_main (int argc, char **argv) { show_version (); #if defined (NATMEM_OFFSET) if (NATMEM_OFFSET == 0 && sizeof (void*) < 8) { write_log ("NATMEM_OFFSET is 0; I hope you used 'uae-preloader' to load me, or else ...\n"); } #endif #ifdef FILESYS currprefs.mountinfo = changed_prefs.mountinfo = &options_mountinfo; #endif restart_program = 1; #ifdef _WIN32 sprintf (restart_config, "%sConfigurations\\", start_path); #endif strcat (restart_config, OPTIONSFILENAME); /* Initial state is stopped */ uae_target_state = UAE_STATE_STOPPED; while (uae_target_state != UAE_STATE_QUITTING) { int want_gui; set_state (uae_target_state); do_preinit_machine (argc, argv); /* Should we open the GUI? TODO: This mess needs to go away */ want_gui = currprefs.start_gui; if (restart_program == 2) want_gui = 0; else if (restart_program == 3) want_gui = 1; changed_prefs = currprefs; if (want_gui) { /* Handle GUI at start-up */ int err = gui_open (); if (err >= 0) { do { gui_handle_events (); uae_msleep (10); } while (!uae_state_change_pending ()); } else if (err == - 1) { if (restart_program == 3) { restart_program = 0; uae_quit (); } } else uae_quit (); currprefs = changed_prefs; fix_options (); inputdevice_init (); } restart_program = 0; if (uae_target_state == UAE_STATE_QUITTING) break; uae_target_state = UAE_STATE_COLD_START; /* Start emulator proper. */ if (!do_init_machine ()) break; while (uae_target_state != UAE_STATE_QUITTING && uae_target_state != UAE_STATE_STOPPED) { /* Reset */ set_state (uae_target_state); do_reset_machine (uae_state == UAE_STATE_COLD_START); /* Running */ uae_target_state = UAE_STATE_RUNNING; /* * Main Loop */ do { set_state (uae_target_state); /* Run emulator. */ do_run_machine (); if (uae_target_state == UAE_STATE_PAUSED) { /* Paused */ set_state (uae_target_state); audio_pause (); /* While UAE is paused we have to handle * input events, etc. ourselves. */ do { gui_handle_events (); handle_events (); /* Manually pump input device */ inputdevicefunc_keyboard.read (); inputdevicefunc_mouse.read (); inputdevicefunc_joystick.read (); inputdevice_handle_inputcode (); /* Don't busy wait. */ uae_msleep (10); } while (!uae_state_change_pending ()); audio_resume (); } } while (uae_target_state == UAE_STATE_RUNNING); /* * End of Main Loop * * We're no longer running or paused. */ set_inhibit_frame (IHF_QUIT_PROGRAM); #ifdef FILESYS /* Ensure any cached changes to virtual filesystem are flushed before * resetting or exitting. */ filesys_prepare_reset (); #endif } /* while (!QUITTING && !STOPPED) */ do_exit_machine (); /* TODO: This stuff is a hack. What we need to do is * check whether a config GUI is available. If not, * then quit. */ restart_program = 3; } zfile_exit (); }
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; }
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; }