VitorVilela7 / SA1-Root

Project for accelerating SNES games using the SA-1 chip.
503 stars 26 forks source link

Compatibility with the official Nintendo emulator Canoe #1

Open arkiokin opened 5 years ago

arkiokin commented 5 years ago

Hello,

First congrats for the hard work and the cool result you finally made with Gradius III. The patched game was very appreciated in the SNES classic community, where players could have play it with the Nintendo in-built emulator Canoe. However, if it seems to run perfectly well, a major issue appear as soon as this emulator's Save states and rewind features are triggered : some sprites become a sort of pixel square garbled (like the Vic viper, the powerup or the Sand dragons for example). As long as you don't use these features (so playing like an original SNES) : no problem, but if you want a save state and resume the game from it, the game is now glitched. The SA-1 chipset on this emulator is triggered by some special Nintendo features named preset ID (or pid) Most of games run without any special pid, but some others need a specific one (sometimes built for only one game) to work or to fix some issues or even to trigger an anti-epilepsy protection. Special preset ID are also required to emulate the chipset of the original cartridges. In the case of SA-1 games and this SA-1 gradius 3, a basic preset ID (the one used for Mario RPG) allows to run the game, but the glitched sprites issue is here. The same is obtained by trying other non SA-1 preset ID (which were known to solve some other issues) with the help of another nintendo feature, an extra-byte value that also can emulate different chipset (6 possible values for SA-1 emulation) in order to make running this "new SA-1 game". But no fix of this glitch. In fact, this issue was never been encountered for none SNES games with this emulator (and hundred of issues were reported on the full Romset, with hundreds which were corrected). So, as the game itself works perfectly fine as long as we don't use save states (and generally with SA-1 games), a small issue on this SA-1 root should be the cause of this problem. Maybe, Canoe is just not able to correctly emulate this game, but if you are interested in, any help on it would be greatly appreciated for our community yours sincerely

VitorVilela7 commented 5 years ago

Hi arkiokin! Thank you for the report and I'm glad you liked the game.

Unfortunately for those kind of bugs there is nothing that can be done on my side. From your report, it's more than likely that the emulator is not saving the entire game state, or maybe not at all. Because of that, when you reload the save state, not the entire game state is restored and because of that the game start having glitches and undefined behavior.

Most SA-1 games have either 8KB or 32KB of external memory. However, since the SA-1 remap method I used was very aggressive, I opted to move the entire SNES memory area to the SA-1 external memory, which totals 128 KB. Maybe the emulator does not save the entire data and when you restore the game state, only part of it is actually restored.

We can verify that. I don't have a SNES classic but by doing some small tests we can check out if that's it or not.

Take a save state while you are playing. Then die and get a game over. When you return to the title screen, restore the state. If not the entire state is restored, you will likely expect glitches there.

Another test: Take a save state, wait 5 seconds. Then restore it. Not all game state should have modified, so it should run fine again.

And this one: Go to one of the bosses. Take a save state. After beating it, as soon as the next stage level starts playing up, restore the state. If not all state is restored, part of the scene will likely be corrupt.

Note that while this can help understand the cause of it, there is nothing that can be done on my side without having to change the external memory, if that's the cause. However it can be used to understand better how Canoe works and what can be done for minimizing the issue.

arkiokin commented 5 years ago

Thanks for your kind answer, and your theory really makes sense !

However, I tried to follow your suggestions of small tests, but the main thing to know about this emulator is that you have to quit the game to create a save state (in fact a suspend point with rewind datas, typically the last 45s). So you have to come back to the main UI menu and place the save state in a slot. With that, possible tests become a bit distorded, since as soon as you quit the game and resume it quickly or after a few minutes, then you will have the game glitched in return. It's playable even you can't correctly estimate your spaceship hitbox with a square of pixels instead of the spaceship haha.

I tried to add some special arguments on the command line related to the save feature here https://github.com/ClusterM/hakchi2/wiki/Command-line-arguments-(SNES-Mini) and also continue to test new pid adjustements. But none configuration have improved this problem. Just to mention, if it might interest you, that the extra-byte value (06) that emulate SA-1 with (known) slowdown graphical issues lead indeed slowdown even with your patch, approximately at the same paths the original game had (when too much sprites on the screen)

If it also interest you further, last year, a ton of discoveries have been done on many points related to this emulator and how some hackers understood how exceeded the issues encountered in some games, with Rom hacking (specially the incredible Sluffy guy) here : https://www.romhacking.net/forum/index.php?topic=25789.0

Anyway, thanks to your support and keep your hard work (snes9x is always an option instead of canoe ;) )

VitorVilela7 commented 5 years ago

I see, thank you for the clarification.

Unfortunately, there is nothing that can be made for now. So it's more like a save state system for keeping your gameplay when you turn off your console and not something similar in emulators where people often use for playing hard games.

Anyways, the problem is caused purely because of the emulator, probably some limitation with not saving the entire SA-1 state, either because of the extra memory or some special states that Gradius III originally used and now it's shared with the SA-1 chip. In other words, there is nothing wrong with the patch itself but how Canoe handles the game, so technically this is not a problem on the patch, although normally I try adding workarounds for certain emulators (like ZSNES for Super Mario World).

Hope someone could eventually look the cause and, who knows, patch the emulator.

nl255 commented 5 years ago

It is both but that is just how it is implemented on the snesc. One thing I would suggest is to make simple homebrew test roms that use similar techniques that you use in your patch to narrow down the issue and will display more detailed messages about what exactly is happening if something goes wrong during a restore state.

VitorVilela7 commented 5 years ago

Any progress on this? Does it still have the same issues on 1.5 patch version and on both JPN/USA versions?

arkiokin commented 5 years ago

Unfortunately, no change at all with the 1.5 patch versions, neither JPN or USA : same graphical glitches after resuming game from suspend points. (to be honest, not tested this time all the possible "configurations" provided with this emulator, but at least no improvement with the more "generic" one)