bsnes-emu / bsnes

bsnes is a Super Nintendo (SNES) emulator focused on performance, features, and ease of use.
Other
1.64k stars 154 forks source link

Super Mario Kart - Inaccurate Emulation on Vanilla Lake 1 #242

Open alyosha-tas opened 2 years ago

alyosha-tas commented 2 years ago

Hello, I originally made this issue on Ares' page but figured I'd make it here too.

Recently I have been trying to replay Tool assisted Speedruns made in emulator on actual console. I use BizHawk 2.8 which has a port of BSNES v115 in it that I make the TASes with. I made a TAS of Super Mario Kart that plays through all cups to unlock 150cc, and when I tried to replay it on console, it syncs correctly through Mushroom Cup and Flower Cup, but then desynced on Vanilla Lake 1 in star cup.

Then I made another TAS of just Star Cup to see if the problem could be narrowed down to Vanilla Lake 1, and indeed on playback the TAS beat the first 2 course on Star Cup but then desynced on Vanilla Lake. I tried it multiple times with the same, seemingly deterministic result.

Then I made a TAS of time trial mode in Vanilla Lake 1 and it synced on console, so the problem seems to be restricted to cup mode.

I tried changing initial RAM setting in emulator, but that didn't change the results. I also made sure it was using the correct firmware for the DSP1b.

My guess would be that ice physics combined with AI player calculations etc. in cup mode is enough work that some timing error is being exposed in the DSP1b. I'm not well enough versed in the SNES to know where to look or how to check.

Mega Man X2/3 (using the Cx4) also desync on console, within a minute of play. It looks like some kind of Cx4 issue, but it's not as clear there where things go wrong. It looks like maybe expansion chip timings need some work in general.

orbea commented 2 years ago

@alyosha-tas Any chance you can provide some sort of video showing the issue so its easier to understand what you mean?

alyosha-tas commented 2 years ago

Sure thing:

Here is a video showing Vanilla Lake 1 time trial TAS replayed on my SNES:

https://youtu.be/t9E3snGh2y

And here is a video showing a TAS of Star cup, it plays back until Vanilla Lake 1 then desyncs. I played this TAS a couple times and it desyncs like this both times:

https://youtu.be/Vd8jvUvnymQ

If you want, I can also upload the much longer TAS that plays through both Mushroom Caup and Star cup, but then also desyncs on Vanilla Lake 1, so it really seems like a problem with that level.

orbea commented 2 years ago

Thanks for the videos, I understand clearly what you mean now. This might be an issue with the input polling rather the coprocessor , but may not be that easy to track down unfortunately.

alyosha-tas commented 2 years ago

Thanks for the videos, I understand clearly what you mean now. This might be an issue with the input polling rather the coprocessor , but may not be that easy to track down unfortunately.

If it's any motivation, I am offering a reward for work towards of this issue, see details here: https://forums.nesdev.org/viewtopic.php?t=23791

Max833 commented 2 years ago

Thanks for the videos, I understand clearly what you mean now. This might be an issue with the input polling rather the coprocessor , but may not be that easy to track down unfortunately.

If this is the case... I'm pretty sure BSNES v115 has still the input polling bug that has been fixed by now. Is this problem still there with the newest bsnes dev build?

Edit: Yep. This commit (and more before) was after the v115 release: https://github.com/bsnes-emu/bsnes/commit/4ea984b6886ecb61afc26c177eeced77e8582a44

Morilli commented 2 years ago

I'm pretty sure BSNES v115 has still the input polling bug that has been fixed by now.

The version of BSNESv115 that was ported to bizhawk always had that fix in it, see https://github.com/TASEmulators/BizHawk/blob/0d7de83d4b30a57eb079e9cae7d524b4bd94d632/waterbox/bsnescore/bsnes/sfc/cpu/io.cpp#L139-L145. So whatever it is, it cannot have been fixed by that or any earlier commit.

ghost commented 2 years ago

Does this happen on legacy bsnes? Before the “new bsnes”

does this happen on the last build of mesen-s? These thoughts might help if those other cores by some chance emulate it.

when isay legacy bsnes i mean such as accuracy core found now in bsnes-plus or classic. I have a feeling that some of nears new snes core optimizations or run ahead or something may contribute to this.

Im going to see if i can u derstand and replicate the desync and then try bsnes classic and mesen-s just to see what happens there

alyosha-tas commented 2 years ago

A little more info here. Morilli made a build where I could vary the DSP1b clock speed to see how it effects the run. The Star Cup run syncs on emulator in a range of clock speed from 7 to 8.2 MHz (default is 7.6.) At 6.95 and 8.3 MHz it desyncs in the first stage due to bad item RNG. So, it seem like imprecise clock is not likely to be the issue.