mirror of
https://github.com/st3fan/ewm.git
synced 2025-01-01 11:29:35 +00:00
Fixes #25 - Remove delay code
This commit is contained in:
parent
8eafb8b559
commit
79d951fb29
30
cpu.c
30
cpu.c
@ -30,8 +30,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <mach/mach.h>
|
|
||||||
#include <mach/mach_time.h>
|
|
||||||
|
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "ins.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) {
|
static int cpu_execute_instruction(struct cpu_t *cpu) {
|
||||||
/* Trace code - Refactor into its own function or module */
|
/* Trace code - Refactor into its own function or module */
|
||||||
char trace_instruction[256];
|
char trace_instruction[256];
|
||||||
@ -238,8 +226,6 @@ static int cpu_execute_instruction(struct cpu_t *cpu) {
|
|||||||
cpu_format_instruction(cpu, trace_instruction);
|
cpu_format_instruction(cpu, trace_instruction);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t start_time = mach_absolute_time();
|
|
||||||
|
|
||||||
/* Fetch instruction */
|
/* Fetch instruction */
|
||||||
cpu_instruction_t *i = &instructions[mem_get_byte(cpu, cpu->state.pc)];
|
cpu_instruction_t *i = &instructions[mem_get_byte(cpu, cpu->state.pc)];
|
||||||
if (i->handler == NULL) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user