NESe (pronounced "Nessie") is a NES emulator based on the e6502 emulator, also written in C with a focus on speed and portability for use on embedded platforms, especially ARM.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
499B

  1. #include <time.h>
  2. #include "time.h"
  3. #include <SDL2/SDL.h>
  4. void time_get(struct timespec* ts) {
  5. uint64_t time = SDL_GetTicks64();
  6. ts->tv_sec = time / 1000U;
  7. ts->tv_nsec = (time % 1000U) * 1000U * 1000U;
  8. }
  9. void time_sleep_until(const struct timespec* ts) {
  10. uint64_t t_target = ( (ts->tv_sec * 1000ULL) +
  11. (ts->tv_nsec / (1000U * 1000U)));
  12. uint64_t t_now = SDL_GetTicks64();
  13. if (t_target > t_now) {
  14. SDL_Delay(t_target - t_now);
  15. }
  16. }