|
|
|
@@ -74,8 +74,7 @@ int main(int argc, char* argv[]) { |
|
|
|
|
|
|
|
nes_render(rend, &sys.ppu); |
|
|
|
|
|
|
|
struct timespec t_target = {0}; |
|
|
|
time_get(&t_target); |
|
|
|
time_us t_target = time_now(); |
|
|
|
uint64_t cycle_last_frame = 0; |
|
|
|
|
|
|
|
uint64_t total_cycles = 0; |
|
|
|
@@ -92,14 +91,20 @@ int main(int argc, char* argv[]) { |
|
|
|
// Sleep to catch up to master clock |
|
|
|
uint64_t elapsed_cycles = total_cycles - |
|
|
|
cycle_last_frame; |
|
|
|
int elapsed_ns = ( elapsed_cycles * |
|
|
|
int elapsed_us = ( elapsed_cycles * |
|
|
|
nes_clock_master_den * |
|
|
|
NS_PER_S ) / |
|
|
|
US_PER_S ) / |
|
|
|
nes_clock_master_num; |
|
|
|
|
|
|
|
t_add_ns(&t_target, &t_target, elapsed_ns); |
|
|
|
t_target += elapsed_us; |
|
|
|
|
|
|
|
time_sleep_until(&t_target); |
|
|
|
time_us slept_us = time_sleep_until(t_target); |
|
|
|
(void)slept_us; |
|
|
|
|
|
|
|
if (slept_us <= -elapsed_us) { |
|
|
|
// We're way out of sync. |
|
|
|
t_target = time_now(); |
|
|
|
} |
|
|
|
|
|
|
|
cycle_last_frame = total_cycles; |
|
|
|
|
|
|
|
|