cpu/sharc.cpp: stall if looping until a flag input changes #14505
+13
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When emulating Sega Model 2, 2A and 2C, if the TGP or TGPx4 DSP tries to read data from the input FIFO buffer but it is empty, the Model 2 driver will halt the DSP, improving emulation performance since the DSP is no longer running cycles while waiting for data.
This is not quite as simple for the SHARC DSP on Model 2B since it uses input flags to report the status of the FIFO buffers; it does not try to read the input FIFO buffer until it has confirmed that it is not empty by setting up an infinite loop that runs until flag #0 is clear.
Most Model 2B games set up a loop that repeatedly executes a NOP with the condition that flag #0 must be clear before exiting the loop, for example:
Virtua Striker instead has an instruction that jumps to itself if flag #0 is set:
For both cases I have made it so that the emulated SHARC eats the remaining cycles in its timeslice if a flag is causing a loop, since the flag state cannot change until the i960 is run which can only happen after the SHARC has finished its timeslice. For the former case, it only eats the remaining cycles if the looping instruction is a NOP to ensure that there can be no difference in results compared to letting the remaining cycles run.