From 79d951fb2977354d6c633a9e06fcb7681f46f5af Mon Sep 17 00:00:00 2001 From: Stefan Arentz Date: Wed, 16 Nov 2016 22:26:40 -0500 Subject: [PATCH] Fixes #25 - Remove delay code --- cpu.c | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/cpu.c b/cpu.c index b869313..b86db17 100644 --- a/cpu.c +++ b/cpu.c @@ -30,8 +30,6 @@ #include #include #include -#include -#include #include "cpu.h" #include "ins.h" @@ -218,16 +216,6 @@ static void cpu_format_stack(struct cpu_t *cpu, char *buffer) { } } -static mach_timebase_info_data_t timebase_info; - -static uint64_t abs_to_nanos(uint64_t abs) { - return abs * timebase_info.numer / timebase_info.denom; -} - -static uint64_t nanos_to_abs(uint64_t nanos) { - return nanos * timebase_info.denom / timebase_info.numer; -} - static int cpu_execute_instruction(struct cpu_t *cpu) { /* Trace code - Refactor into its own function or module */ char trace_instruction[256]; @@ -238,8 +226,6 @@ static int cpu_execute_instruction(struct cpu_t *cpu) { cpu_format_instruction(cpu, trace_instruction); } - uint64_t start_time = mach_absolute_time(); - /* Fetch instruction */ cpu_instruction_t *i = &instructions[mem_get_byte(cpu, cpu->state.pc)]; if (i->handler == NULL) { @@ -300,22 +286,6 @@ static int cpu_execute_instruction(struct cpu_t *cpu) { } } - /* Delay */ - - if (timebase_info.denom == 0) { - (void) mach_timebase_info(&timebase_info); - } - - uint64_t now = mach_absolute_time(); - - uint64_t elapsed_nano = abs_to_nanos(now - start_time); - uint64_t expected_duration = (i->cycles * (1000000000 / 960000)); - uint64_t delay_nano = expected_duration - elapsed_nano; - - //fprintf(stderr, "Expected: %" PRId64 " Elapsed: %" PRId64 " Delay: %" PRId64 "\n", expected_duration, elapsed_nano, delay_nano); - - mach_wait_until(now + nanos_to_abs(delay_nano)); - return 0; }