I'm trying to implement emulator main loop. Emulator runs at full speed. About 60 Mhz. But I want to make it run at 4.77Mhz. How it's done ?
for (;;)
{
emu_step(ctx) ;
uint64_t current = get_gtod_clock_time () ;
uint64_t elapsed = current - last_time ;
if (elapsed >= 1000000)
{
printf("Cycles: %d\n", get_cycles(ctx)) ;
set_cycles_zero(ctx, 0) ;
last_time = get_gtod_clock_time () ;
}
}
emu_step() is function which executes one instruction. get_cycles(ctx) is sum of executed machine cycles. set_cycles_zero(ctx, 0) sets cycles counter to zero.