src/emulation/emulation.cc
/*
 * Ensures that the program waits at least 1/60 seconds between calls
 * to this function. Used to time emulation.
 */
Ensures that the program waits at least 1/60 seconds between calls
to this function. Used to time emulation.
Ensures that the program waits at least 1 / 60 seconds between calls to this function . Used to time emulation .
void Emulation::SyncFrameRate(void) {
  EmuTime wait_spec = { 0, NSECS_PER_SEC / NES_FRAME_RATE };
  wait_spec.tv_sec = last_sync_time_.tv_sec;
  wait_spec.tv_nsec += last_sync_time_.tv_nsec;
  if (wait_spec.tv_nsec >= NSECS_PER_SEC) {
    wait_spec.tv_nsec -= NSECS_PER_SEC;
    wait_spec.tv_sec++;
  }
  EmuTime current_time, diff;
  TimeGet(&current_time);
  if (TimeGt(&wait_spec, &current_time)) {
    TimeDiff(&wait_spec, &current_time, &diff);
    nanosleep(&diff, NULL);
    last_sync_time_.tv_sec = wait_spec.tv_sec;
    last_sync_time_.tv_nsec = wait_spec.tv_nsec;
  } else {
    last_sync_time_.tv_sec = current_time.tv_sec;
    last_sync_time_.tv_nsec = current_time.tv_nsec;
  }
  return;
}
void Emulation :: SyncFrameRate ( void ) { EmuTime wait_spec = { 0 , NSECS_PER_SEC / NES_FRAME_RATE } ; wait_spec . tv_sec = last_sync_time_ . tv_sec ; wait_spec . tv_nsec += last_sync_time_ . tv_nsec ; if ( wait_spec . tv_nsec >= NSECS_PER_SEC ) { wait_spec . tv_nsec -= NSECS_PER_SEC ; wait_spec . tv_sec ++ ; } EmuTime current_time , diff ; TimeGet ( & current_time ) ; if ( TimeGt ( & wait_spec , & current_time ) ) { TimeDiff ( & wait_spec , & current_time , & diff ) ; nanosleep ( & diff , NULL ) ; last_sync_time_ . tv_sec = wait_spec . tv_sec ; last_sync_time_ . tv_nsec = wait_spec . tv_nsec ; } else { last_sync_time_ . tv_sec = current_time . tv_sec ; last_sync_time_ . tv_nsec = current_time . tv_nsec ; } return ; }
Ensures that the program waits at least 1/60 seconds between calls
 to this function.
Ensures that the program waits at least 1 / 60 seconds between calls to this function .
// Determine the minimum time at which this function can return. // Pause the program until the minimum time has been reached. // Update the last call time with the target of the wait spec. // If we didn't meet timing, we just update the time and return.