Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let derived CDROM devices asynchronously lag their calls #2622

Merged
merged 4 commits into from Jun 20, 2023

Conversation

kcgen
Copy link
Member

@kcgen kcgen commented Jun 20, 2023

This PR simulates the delay a physical CD-ROM drive took to respond to queries.

This fixes picky games that (expect/assume) that real hardware always had some delay, and therefore back-to-back queries should report monotonically increasing Minute-Second-Frame (MSF) time values.

Fixes Chasm : the Rift's music, which previous failed to loop (resulting in the game eventually going silent), as ripsaw8080 nicely explains: https://www.vogons.org/viewtopic.php?p=225579#p225579

Previously these calls would return within the same tick, producing
 result that were not typically possible on real hardware. With real
hardware, delays were made up of the query and response trasvering:

 1. MSCDEX to
 2. CDROM Driver to
 3. IDE controller to
 4. CDROM controller board to
 5. (possibly) actuators to move the head positioning
 6. (possibly) Picking up the track and reading the data
 7. Sending the query response back up the chain.

The first generation of 1x and 2x CDROM drives had worst-cast repsonse
times of up to half a second, but typically were in the 300 ms range
(most of it spent in the track seek). Faster drives and hardware
caching brought these times down to fractions of these.

Some software expects (and worse, even assumes) that back-to-back
responses cannot occur essentially isntantaneously, as ripsaw8080
explains for Chasm: The Rift:

   ~~~

   Chasm: The Rift does indeed decide not to loop audio tracks, and
   ultimately it is an issue of timing. When using an image, the game
   concludes that playing has failed because the current frame appears
   not to advance over three successive checks. DOSBox processes the
   checks so quickly that the frame doesn't have time to advance. I
   haven't tested this, but playing audio from a physical CD might loop
   because of delay in reading the device.

   On real DOS systems there would be code overhead in MSCDEX and the
   CDROM device driver, but in DOSBox there is practically none. The
   attached TSR program adds overhead to the MSCDEX function that reads
   the current frame, ensuring that the frame counter will have advanced
   between checks. This workaround could be useful for anyone who is
   using an image and would like the CD audio to loop; simply run the
   program before running the game. Assembler source is included in the
   archive.

   Ref:  https://www.vogons.org/viewtopic.php?p=225579#p225579

   ~~~

Thanks, ripsaw8080!
@kcgen kcgen added bug Something isn't working audio Audio related issues or enhancements labels Jun 20, 2023
@kcgen kcgen requested a review from johnnovak June 20, 2023 03:36
@kcgen kcgen self-assigned this Jun 20, 2023
Copy link
Member

@johnnovak johnnovak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great enhancement! 🎉

@kcgen kcgen merged commit b7573e9 into main Jun 20, 2023
61 checks passed
@kcgen kcgen deleted the kc/lag-mscdex-queries-1 branch June 20, 2023 15:18
@johnnovak johnnovak added the enhancement New feature or enhancement of existing features label Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audio Audio related issues or enhancements bug Something isn't working enhancement New feature or enhancement of existing features
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants