joncampbell123 / dosbox-x

DOSBox-X fork of the DOSBox project
GNU General Public License v2.0
2.77k stars 381 forks source link

Emulator real time clock too fast when software is running #2081

Closed MX9000 closed 3 years ago

MX9000 commented 3 years ago

Describe the bug When I typed the DOS command TIME after playing a game, I noticed that the emulator's internal clock was far ahead compared to the host PC clock. With some games the issue is more pronounced (hours with Crystal Caves), less pronounced with others (minutes with Xargon). To synchronize the emulator's clock with host PC clock I had to reset the virtual machine. Thank you.

To Reproduce

  1. Play a game for some time.
  2. Exit from the game
  3. Type TIME command at DOS prompt
  4. Compare emulator time with host computer time

Expected behavior I think that the emulator clock and the host computer clock should always be synchronized.

Environment (please complete the following information):

Wengier commented 3 years ago

As mentioned in Issue #2082, you don't need to reset the virtual machine to synchronize the internal clock with host PC clock though - just type TIME /H should do the job. But I agree that there can be perhaps the default option to automatically synchronize the internal clock with the host PC clock.

Wengier commented 3 years ago

The latest code hopefully solves this by doing automatically synchronizing the host date/time. See Issue #2082 for more information.

MX9000 commented 3 years ago

@Wengier Thank you! I'll definitely try it in the next release.

joncampbell123 commented 3 years ago

@Wengier I had to adjust the BIOS_TIMER synchronize code due to some conflicts with demoscene stuff that relies on BIOS_TIMER while setting a higher tick rate, and I had to make "synchronize time" false by default.

The fix retains BIOS_TIMER synchronization with local time, but only if the timer is at the proper 18.2Hz rate. The fix temporarily skips synchronization if anything still uses the BIOS IRQ0 handler but at a faster tick rate (like the aformentioned demoscene stuff).

Wengier commented 3 years ago

@joncampbell123 I did see the changelog and could understand there are some concerns for the time synchronization. Apparently the time synchronization function is not yet perfect. For example, I was aware that it has no effect for the PC-98 mode. If there turns out to be more concerns I would support it to make it disabled by default, but users who desire it can always enable it if they want, either from the config file or from the “DOS” menu.

joncampbell123 commented 3 years ago

@Wengier Well, yes, the BIOS data area is completely different in PC-98 mode.

It's disabled by default because real hardware does not synchronize to an external clock source. It's a nice feature to have, it's also a step away from accurate emulation with respect to emulation time.

I think the way the feature is designed, you should be able to add an enable/disable from the menu without any issues.

Wengier commented 3 years ago

@joncampbell123 Good point. I previously considered the addition of the feature (and enable it by default) would make the date/time more accurate compared to the date/time on the system that the users are using, but the problem is that real DOS systems (at least standard ones) do not have such a synchronization method, although it can be done through external programs or devices. In such case I think it will be disabled by default indeed but can be enabled if desired. There is already a menu option to toggle it though.

MX9000 commented 3 years ago

@joncampbell123 , @Wengier Thank you very much for your efforts and Merry Christmas!

MX9000 commented 3 years ago

Issue solved. Thanks.