C 减速仿真器速度
我正在尝试实现emulator主循环。模拟器以全速运行。大约60兆赫。但我想让它以4.77Mhz的频率运行。怎么做的C 减速仿真器速度,c,emulation,simulation,C,Emulation,Simulation,我正在尝试实现emulator主循环。模拟器以全速运行。大约60兆赫。但我想让它以4.77Mhz的频率运行。怎么做的 for (;;) { emu_step(ctx) ; uint64_t current = get_gtod_clock_time () ; uint64_t elapsed = current - last_time ; if (elapsed >= 1000000) {
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\u step()
是执行一条指令的函数<代码>获取周期(ctx)是已执行机器周期的总和set\u cycles\u zero(ctx,0)
将循环计数器设置为零。我认为这是因为在for循环的每次迭代中都会执行emu步骤
,如果您将其移动到if
中,那么它只会在经过时间>=1000000时执行。在这种特殊情况下,您可以独立于循环执行一次,这样您就不必等待一个限制的周期
它可能看起来像
emu_step(ctx) ;
for (;;)
{
uint64_t current = get_gtod_clock_time () ;
uint64_t elapsed = current - last_time ;
if (elapsed >= 1000000)
{
emu_step(ctx);
printf("Cycles: %d\n", get_cycles(ctx)) ;
set_cycles_zero(ctx, 0) ;
last_time = get_gtod_clock_time () ;
}
}