Add EMU_SLOW_FACTOR environment variable to enable slowing down emulator #128
Add EMU_SLOW_FACTOR environment variable to enable slowing down emulator #128donno2048 wants to merge 7 commits intodmsc:masterfrom
EMU_SLOW_FACTOR environment variable to enable slowing down emulator #128Conversation
|
I might have some suggestions to make this more portable, I'll try to follow up soon. |
|
Hi! I'm in favor of adding some means of slowing down the emulator for use cases where speed is important. But, IMHO, this is not the correct approach - it uses a lot of CPU and is not precise. Instead of "nanoseconds per instruction", the user should set the variable to "instructions per millisecond", for example with "EMU_CPU_SPEED=1000" for 1000000 instructions per second. Then, in the emulator core, you set a (static) variable with the target time, this is the current monotonic time plus one millisecond. After EMU_CPU_SPEED instructions, you sleep if the current monotonic time is less than the target time, then advance the target time by 1 millisecond. In pseudocode: Then, you need to consider that REP will count as only only instruction, same as any IRQ or emulated DOS call. Have Fun! |
|
I don't have much spare time lately will try doing it next week, maybe even next month... 😅 |
This means every chunk of intructions will run in a very little time period. So for high values of Since we deal with only one millisecond it might not be important, but we can maybe instead calculate the avrerage delay between instructions and just apply it to make the delay more uniform... More importantly, there're situations where this approach can cause problems, for example, if there's a loop of 4 instructions and |
You have to make a tradeoff, I might be wrong but I don't think on linux there's a way to make the OS suspend your process for an exact number of nanoseconds/millisecond/seconds/etc, so you either busy wait (like in #134) or be willing to suffer losing a few microseconds here and there. |
|
Hi! You can think of the emulation as being "frame based", you can execute up to a video frame of instructions instantly, and then render the frame - the user will not notice any difference, as it is not possible to see more than one frame at a time. This is the method used by all "game" emulators - you just emulate a frame of instructions (and video/audio/etc.) and then pass it to the video rendering. In my example, instead of sleeping for one frame (16.6ms for 60HZ), IMHO, it is easier to simply sleep for 1ms, this will give the ability to absorb any jitter that the OS will introduce. I will try to make a patch over the weekend and test this. Have Fun! |
|
@dmsc the weekend had passed, would it be helpful if I implement it on my own? |
As proposed here #127