【问题标题】:Slow downing emulator speed降低模拟器速度
【发布时间】:2017-03-25 17:01:34
【问题描述】:

我正在尝试实现模拟器主循环。模拟器全速运行。大约 60 兆赫。但我想让它以 4.77Mhz 运行。它是怎么做的?

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() 是执行一条指令的函数。 get_cycles(ctx) 是已执行机器周期的总和。 set_cycles_zero(ctx, 0) 将周期计数器设置为零。

【问题讨论】:

    标签: c emulation simulation


    【解决方案1】:

    我认为这是因为 emu_step 在 for 循环的每次迭代中都会执行,如果您将其移动到 if 内,那么它只会在 elapsed >= 1000000 时执行。在这种特殊情况下,您可以独立于循环执行一次,这样您就不必等待一个受限制的cycle

    它可能看起来像

    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 () ;
            }
    }
    

    【讨论】:

      猜你喜欢
      • 2022-08-06
      • 1970-01-01
      • 1970-01-01
      • 2012-04-30
      • 2022-09-25
      • 2016-09-25
      • 1970-01-01
      • 2011-05-27
      • 1970-01-01
      相关资源
      最近更新 更多