judofyr/rcpu — pull request #11 by Deradon (2012-04-09 21:28:34+00:00)
Title: "Add instruction counter to the emulator"

Given from one of your Issues, here is a sample implementation to count cycles.
I also refactored the debugger#s to stop, if it exeecds the current @emulator.cycle.

What do you think about it?

Another Idea, what I implemented in my code base, limit the CPU speed.
Here a code sample from my code base:

# Run in endless loop
def run
@started_at = Time.now
max_cycles = 1

while true do
if @cycle < max_cycles
step
else
diff = Time.now - @started_at
max_cycles = (diff * @clock_cycle)
end
end
end

# Current clock_cycle
def hz
diff = Time.now - (@started_at || Time.now)
diff = 1 if diff == 0
@cycle / diff
end