snes9xgit / snes9x

Snes9x - Portable Super Nintendo Entertainment System (TM) emulator
http://www.snes9x.com
Other
2.61k stars 451 forks source link

Can't load roms made from the Quad randomizer #936

Closed Skarsnik closed 1 month ago

Skarsnik commented 1 month ago

The quad randomizer is a randomizer that combines Zelda 3, Super Metroid, Metroid 1 and Zelda 1 in the same ROM. You can find more at https://quad.beta.samus.link/

It uses SA-1 and the roms refuse to load on anything above Sne9x 1.58.

After some bisecting, I found this commit to be the culprit. Sadly I don't know enough about SA-1 to try to fix the issue.

$ git bisect good
56af48c042a2e3e1fb4f80c565639c3d1bebc99a is the first bad commit
commit 56af48c042a2e3e1fb4f80c565639c3d1bebc99a
Author: Brandon Wright <bearoso@gmail.com>
Date:   Tue Jan 8 14:55:46 2019 -0600

    Reduced version of Vitor's fix for SA1 speed throttle.

Instead of a black screen you should have something like :

https://cdn.discordapp.com/attachments/638130116387536906/1264296278490091531/image.png?ex=669d5b2a&is=669c09aa&hm=f4db6cdaac0a7d583cfbe4c29845d5df41cdace4a914643bbf5ef169d12dc3ad&

qwertymodo commented 1 month ago

In order to root-cause this issue, has anybody gotten a quad rando ROM working on original hardware (i.e. an actual SA-1 cart, not the SD2SNES/FXPAK). IIRC Vitor ran into some weird issues with bootstrapping certain revisions of SA-1 chips on some of his conversion projects, and something similar could be going on here. I would be hesitant to start throwing fixes at this unless we actually know 100% for sure it isn't a ROM issue.

bearoso commented 1 month ago

It's 100% likely to be a memory mapping issue. This hack was made for older emulator versions whose heuristics provided more memory than was realistically available. Which means it won't run on an actual SA-1 cart.

I'm going to bet this uses one of those regions that was changed to mirrored memory in that commit.

If we implement manifest support it should allow hacks like this with imaginary memory maps to specify those instead of trying to fit to an existing official game's layout. As far as I can see, this hack doesn't provide any manifests for bsnes/higan/ares, so it probably doesn't run on those, either.

Skarsnik commented 1 month ago

It runs fine on Bsnes and Mesen and it is something that just came out this year x)

bearoso commented 1 month ago

I'll check how the heuristics differ. I plan to add manifest support eventually to allow any crazy layout to work.

tewtal commented 1 month ago

I'm the author of the Quad Randomizer/Hack in question here so figured I'd add some detail about exactly how the SA-1 is being used and in what capacity.

It's an 8MB SA-1 ROM (using 64kB of BW-RAM) and it's making quite heavy use of the Super MMC features to remap ROM regions depending on what game is currently running out of the four different games. It also remaps the BW-RAM window in the 6000-7FFF region. The SA-1 sits idle during game execution other than when a switch between games is performed, that's done by the SA-1 mostly.

The SA-1 does however run the main menu system that runs at boot which could be an issue since nothing shows up. Below is what happens at boot:

At boot the main thing that happens is that it sets the MMC mapping registers to map in the correct banks (from the SNES side) even before the SA-1 is initialized. It writes the SA-1 vectors to registers $2203, $2205 and $2207, write-enables I-RAM AND BW-RAM from the SNES side and clears I-RAM, WRAM and BW-RAM and then finally brings the SA-1 out of reset and then on the SNES side jumps into a loop waiting for commands from the SA-1 to do things like VRAM uploads and such.

On the SA-1 side when it boots it also write-enables I-RAM and BW-RAM from the SA-1 side, sets the SNES vectors to be read from ROM and enables IRQ messaging from the SNES to SA-1 (which is used later to ask the SA-1 to perform a game switch). And after that it waits for the SNES CPU to become ready for SA-1 commands and then executes the menu code.

Edit: As mentioned earlier I've tested this on various bsnes variants, mesen2 and also sd2snes/fxpak and it works fine there.

bearoso commented 1 month ago

I changed one of the RAM mappings that seemed out of place and the hack starts up now. I don't know if the game switching works, though.

Skarsnik commented 1 month ago

I managed to play a rom a bit and switching between game work fine : )