|
|
|
@@ -1,9 +1,9 @@ |
|
|
|
#include <inttypes.h> |
|
|
|
#include <limits.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <time.h> |
|
|
|
|
|
|
|
#include "nes.h" |
|
|
|
#include "timer.h" |
|
|
|
#include "render.h" |
|
|
|
#include "input.h" |
|
|
|
#include "audio.h" |
|
|
|
@@ -12,24 +12,6 @@ |
|
|
|
#define audio_freq (44100U) |
|
|
|
|
|
|
|
|
|
|
|
#define NS_PER_S (1000U * 1000U * 1000U) |
|
|
|
|
|
|
|
static inline int t_diff_ns(const struct timespec* b, |
|
|
|
const struct timespec* a) { |
|
|
|
int sec = (b->tv_sec - a->tv_sec); |
|
|
|
int nsec = (b->tv_nsec - a->tv_nsec); |
|
|
|
return ((sec * NS_PER_S) + nsec); |
|
|
|
} |
|
|
|
|
|
|
|
static inline void t_add_ns(struct timespec* s, |
|
|
|
const struct timespec* a, |
|
|
|
int b) { |
|
|
|
int nsec = a->tv_nsec + b; |
|
|
|
s->tv_sec = a->tv_sec + (nsec / NS_PER_S); |
|
|
|
s->tv_nsec = nsec % NS_PER_S; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
extern nes_Renderer sdl_renderer; |
|
|
|
|
|
|
|
extern nes_Input_Reader sdl_input; |
|
|
|
@@ -79,7 +61,7 @@ int main(int argc, char* argv[]) { |
|
|
|
nes_render(rend, &sys.ppu); |
|
|
|
|
|
|
|
struct timespec t_target = {0}; |
|
|
|
clock_gettime(CLOCK_MONOTONIC, &t_target); |
|
|
|
time_get(&t_target); |
|
|
|
uint64_t cycle_last_frame = 0; |
|
|
|
|
|
|
|
uint64_t total_cycles = 0; |
|
|
|
@@ -103,8 +85,7 @@ int main(int argc, char* argv[]) { |
|
|
|
|
|
|
|
t_add_ns(&t_target, &t_target, elapsed_ns); |
|
|
|
|
|
|
|
clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, |
|
|
|
&t_target, NULL); |
|
|
|
time_sleep_until(&t_target); |
|
|
|
|
|
|
|
cycle_last_frame = total_cycles; |
|
|
|
|
|
|
|
|