CPU Emulation and locking to a specific clock speed

前端 未结 7 1385
臣服心动
臣服心动 2020-12-04 14:58

If you had read my other question, you\'ll know I\'ve spent this weekend putting together a 6502 CPU emulator as a programming exercise.

The CPU emulator is mostly c

7条回答
  •  难免孤独
    2020-12-04 15:21

    As jfk says, the most common way to do this is tie the cpu speed to the vertical refresh of the (emulated) video output.

    Pick a number of cycles to run per video frame. This will often be machine-specific but you can calculate it by something like :

    cycles = clock speed in Hz / required frames-per-second
    

    Then you also get to do a sleep until the video update is hit, at which point you start the next n cycles of CPU emulation.

    If you're emulating something in particular then you just need to look up the fps rate and processor speed to get this approximately right.

    EDIT: If you don't have any external timing requirements then it is normal for an emulator to just run as fast as it possibly can. Sometimes this is a desired effect and sometimes not :)

提交回复
热议问题