Zardoz89 / dcpu_vm

Another DCPU-16 Virtual Machine
http://zardoz89.github.io/dcpu_vm/
MIT License
6 stars 2 forks source link

Emulator too fast ! #7

Closed lamogui closed 11 years ago

lamogui commented 11 years ago

The emulator speed is too fast whatever the emulation mode i use (by time or by frame) I can see it with the clock.bin program : the second are half of real second. I don't know if it's my config or other...

Zardoz89 commented 11 years ago

I just see it, It's running at double of the speed that should work the clock.

Zardoz89 commented 11 years ago

Plus I just see that does something much more problematic. The VM hangs sometimes running clock.bin!

lamogui commented 11 years ago

You think that come from the clock or from the dcpu ?

Zardoz89 commented 11 years ago

I need to check what happen here. (Now I going to dinner). Later, I will try to check if the hardware tick() is being called at the desired rate of 100KHz. An alternative is to use sfml timer/clock stuff to measure time, instead of the cpu clock ticks. In the specs not say anything of how the generic clock measures the time.

Zardoz89 commented 11 years ago

The VM hangs sometimes running clock.bin!

False alarm! In my desktop, I have yakuake, a Terminal that works like Quake console. It's launched with F12. So every time that I press F12 to hide/show it, the VM go/return of the debug mode. I will inspect what happen with the clock timing and later , i will try to create a window that represent the keyboard. If it have the Focus, then interprets the keyboard events, if not ignores it.

Zardoz89 commented 11 years ago

I just checked that gclock had had wrong calculation the max_tick. I fixed it, but I noticed that keeps running too fast. Also I just rechecked and the max_tick and B register values are correct for a interrupt every second, so the VM timming should be bad.

Zardoz89 commented 11 years ago

Ok, I think that I discover what happen. GClock measures time using the CPU clock, but the problem is that the CPU running speed isn't contant. Always run a bit faster that should be, thanks rounding errors. For example, with a Delta of 0.017516, the ticks that need to run are 1751, but If you do the math of measure how many time does 1751 ticks in VM time:

1751 * 100000^(-1) = 0.01751  < 0.017516

I will try to fix it, using asMicroseconds() and using a bool flag to add 1 tick every even loop, to keep the time around 100%

Zardoz89 commented 11 years ago

Actually I did this:

lamogui commented 11 years ago

On my computer the speed is really unstable oscillate between 95% and 177%. I have the sensation that's it slower than normal...

lamogui commented 11 years ago

Now the emulator run at 94%-95% pretty stable and the clock.bin program seems slower (but coherent with the indicated speed) with your recent changes (Sorry i have no time to see your changes monday/tuersday and wenesday, i have busy schedule 8->19)

Zardoz89 commented 11 years ago

Now the emulator run at 94%-95% pretty stable I'm my case it's around 97%-102%. Depend of what method of sync you uses. With time method looks more stable. Also, I change refresh rate to 50Hz, because it happens exactly every 2000 cycles of the CPU, instead of 60Hz that need 1666.66... cycles.

(Sorry i have no time to see your changes monday/tuersday and wenesday, i have busy schedule 8->19) Don't worry. Actually I have a lot of free time, so I not stop of coding :P Actually I'm making a floppy drive. It's half working. I only need to talk, in Trillek forums, about the file format to store the disk image. I not like to implement something to find that nobody will use it.

lamogui commented 11 years ago

Emulator is now full speed in timed mode ! 95% in refresh mode, It's the clock which have a problem : the accumation sometimes accumulate 0 instead of 1 or 2 (cause the time resolution on windows is not accurate and the refresh is too speed and the clock is restarted. I fixed that, it's not beautifull but that's should work.

Zardoz89 commented 11 years ago

The generic clock keeps being more slower that should be in Linux. I move this to a fresh issue