Class AccurateFrequencyRunner
java.lang.Object
net.emustudio.emulib.plugin.cpu.AccurateFrequencyRunner
Accurate Frequency Runner.
This class can be used for emulating CPUs which need precise timing. Given a target frequency, it will try to run the instructions in this frequency, regardless of host CPU speed.
The algorithm is based on accurate counting of executed CPU cycles per fixed time slot.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExecutedCycles(long cycles) Adds executed cycles to the counter.run(Supplier<Double> getTargetFrequencyKHz, Supplier<CPU.RunState> runInstruction) Runs the CPU.runNoSleep(Supplier<Double> getTargetFrequencyKHz, Supplier<CPU.RunState> runInstruction) Runs the CPU without "sleeping".
-
Constructor Details
-
AccurateFrequencyRunner
public AccurateFrequencyRunner()Constructs a new AccurateFrequencyRunner.
-
-
Method Details
-
run
public CPU.RunState run(Supplier<Double> getTargetFrequencyKHz, Supplier<CPU.RunState> runInstruction) Runs the CPU.The "runInstruction" function must call
addExecutedCycles(long)to update executed cycles.- Parameters:
getTargetFrequencyKHz- get target frequency in kHzrunInstruction- runs one instruction- Returns:
- new run state
-
runNoSleep
public CPU.RunState runNoSleep(Supplier<Double> getTargetFrequencyKHz, Supplier<CPU.RunState> runInstruction) Runs the CPU without "sleeping".The "runInstruction" function must call
addExecutedCycles(long)to update executed cycles.- Parameters:
getTargetFrequencyKHz- get target frequency in kHzrunInstruction- runs one instruction- Returns:
- new run state
-
addExecutedCycles
public void addExecutedCycles(long cycles) Adds executed cycles to the counter.Should be called from "runInstruction" function when calling
run(Supplier, Supplier)method.- Parameters:
cycles- number of cycles
-