How to emulate the correct speed?

I want to write an emulator for a particularly slow processor that runs at 600 or so kilohertz. If I were to write an emulator for the CPU in a naive way (i.e. emulate one team at the same time without any others), emulation would be much faster than 600 kilohertz.

How can I program the emulator to emulate the processor at the correct speed, regardless of host speed? What technique do real-world emulators commonly use for this? How to avoid jitter that slows down emulation?

+4
source share
1 answer

" " , , , 0,6 . "" (, 100 ), " ", "" , . , "".

:

int cycle_budget = 0;
time last_sprint = something;

// on timer fire
cycle_budget += (current_time - last_sprint) * clock_rate;
last_sprint = current_time;
while (cycle_budget >= slowest_instruction)
    tick(); // emulates one instruction, subtracts from cycle_budget

, , , , . , , . , , , ( - z80, , ).

+3

All Articles