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

SIO/MCD: hugely improved memcard swapping + reinsertion + Fix per game cards #9033

Merged
merged 2 commits into from Jun 26, 2023

Conversation

refractionpcsx2
Copy link
Member

@refractionpcsx2 refractionpcsx2 commented Jun 23, 2023

Description of Changes

Hugely improves swapping of memcards and reinserting (especially when loading a savestate).

Rationale behind Changes

Initially I just wanted to fix a bug I introduced with it not loading game specific memcards due to a chicken/egg problem with loading memory cards, I've kinda rewritten some of how that's done and centralised some of the code.

The second problem was one which has plagued PCSX2 since the beginning, reinserting memory cards on "swap". Previously we just ejected it and told the PS2 we were disconnected for 60 reads, and this kinda worked, but it was very unreliable, plus it was very annoying for people loading states as you had to keep retrying until it eventually worked.

The solution turned out to be simple. When the PS2 boots, the terminator for the memcard is set to 0x55, mcman picks this value up as "Uninitialized", then it does it's auth/setup dance and sets the card up. Previously we didn't change this back, so the PS2 didn't realise the card had been ejected, but now we reset it, and it seems to work very well. This means I have set the "reinsert" time to 1 second, so it won't stay ejected for long at all, and this seems to be reliable, and Ratchet & Clank no longer complains, it gracefully reinserts the memcard.

Suggested Testing Steps

⚠️ I recommend using a copy of your memcard for testing! I think it's fine but if it's not it could erase your memcard! ⚠️

Test fast booting games, full booting, going in to the bios then swapping in a disc, all three tests again with a game which has per game memcards which are different to the global ones, lastly try making a savestate in a game which reads the memcards constantly (Ratchet & Clank, or I believe GT4? I could be wrong), then change your memcard and reload that state, it should reinsert gracefully.

And no it will still toast your memcard if you shut down the emu/eject the card while it's saving!

Fixes #9032

pcsx2/MemoryCardFile.cpp Outdated Show resolved Hide resolved
pcsx2/MemoryCardFile.cpp Outdated Show resolved Hide resolved
pcsx2/Config.h Outdated Show resolved Hide resolved
@refractionpcsx2 refractionpcsx2 force-pushed the mcd_pergame branch 5 times, most recently from 651d5e7 to b9e3584 Compare June 23, 2023 10:41
Copy link
Sponsor Contributor

@RedPanda4552 RedPanda4552 left a comment

Choose a reason for hiding this comment

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

A little bit odd imo to tick down the insert timer in CDVD but probably still serviceable. I echo sten's review and that's about all I have the brain power to work out right now.

@refractionpcsx2
Copy link
Member Author

refractionpcsx2 commented Jun 23, 2023

A little bit odd imo to tick down the insert timer in CDVD but probably still serviceable. I echo sten's review and that's about all I have the brain power to work out right now.

That was intentional to keep the time based in console land, so it's 1 second of "console" time, so even if they have it in fast forward, it's not waiting forever (in console space) waiting for 1 real world second :) That said, depending on timing, it might be less than 1 second.

We might get away with not even having the whole fake eject dance, and just reset the terminator, but I wanted to be a bit safer.

@RedPanda4552
Copy link
Sponsor Contributor

That was intentional to keep the time based in console land, so it's 1 second of "console" time, so even if they have it in fast forward, it's not waiting forever (in console space) waiting for 1 real world second :) That said, depending on timing, it might be less than 1 second.

We might get away with not even having the whole fake eject dance, and just reset the terminator, but I wanted to be a bit safer.

Fair enough, but I do wonder if Counters.cpp would still be viable since vsyncs scale with speed. Or maybe it doesn't matter.

I would still keep the ejection action even though resetting the terminator might be enough on its own. Of course any time the card is inserted it is going to default it's terminator and we know the IOP module is checking for that. But additionally if we are trying to simulate yanking the card and putting it back in, well, during the ejection time, any commands sent over the rail are going to return dead air for data. So it's probably of no consequence, but imo still a good idea to report the card as missing during the eject so commands can still fail as if there was no device at all. Just resetting the terminator could imply the card was never ejected but just has some kind of reset or fault.

@refractionpcsx2
Copy link
Member Author

Yeah I agree, simulating the card being removed isn't the worst thing, and I don't want to rock the boat too much with it!

As for counters, I'm not sure, the CDVD is controlling the Real Time Clock, which is where I placed it, we could count 60 vsyncs or whatever, but then do we scale that for PAL? it could start getting out of control, I guess :P Another advantage of this way, adding a second on the CDVD is less hot code that the counters/vsync code, which gets called quite a bit, and this would mean adding the loop through all the memcards every frame.

@RedPanda4552
Copy link
Sponsor Contributor

Fair enough. Rest of the memcard bits seem fine to me.

@refractionpcsx2
Copy link
Member Author

Thanks for checking it :)

@refractionpcsx2 refractionpcsx2 changed the title SIO/MCD: hugely improved memcard swapping + reinsertion SIO/MCD: hugely improved memcard swapping + reinsertion + Fix per game cards Jun 23, 2023
@refractionpcsx2 refractionpcsx2 merged commit d51d51b into master Jun 26, 2023
23 checks passed
@refractionpcsx2 refractionpcsx2 deleted the mcd_pergame branch June 26, 2023 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]: Per-game memory card overrides don't work until reinserted
4 participants