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

GameCube Zelda HLE in Wii mode #12089

Merged

Conversation

stblr
Copy link
Contributor

@stblr stblr commented Aug 6, 2023

No description provided.

@Pokechu22
Copy link
Contributor

Can you provide some context as to where this is useful?

@stblr
Copy link
Contributor Author

stblr commented Aug 7, 2023

Running GameCube games in Wii mode can be useful for modding simply because of the additional hardware. To get audio to work on console and with LLE, the simplest approach is to patch ARAlloc to add 0x10000000 to addresses (since the ARAM addresses would be in MEM1 which is not what we want) and to patch ARQPostRequest to turn it into a memcpy. However, this breaks HLE, thus this PR.

@stblr stblr force-pushed the gamecube-zelda-hle-in-wii-mode branch from f48555c to 6923f28 Compare August 7, 2023 17:46
@stblr
Copy link
Contributor Author

stblr commented Aug 7, 2023

Here is a DOL (in the out folder) that applies these patches to Mario Kart: Double Dash!! and the corresponding source code (for reference only, that project is early and doesn't yet have build instructions). source.zip Update: the project is now available at https://github.com/doubledashdeluxe/ddd.

@dreamsyntax
Copy link
Member

Do you have an example of patching any GC dol? I would want to test this on a few different GC.

@stblr
Copy link
Contributor Author

stblr commented Aug 9, 2023

Do you have an example of patching any GC dol? I would want to test this on a few different GC.

I don't have other GameCube games on hand, but here is a minimal template. This will likely not work on a real console or with out of region games, but should work on Dolphin with the right fallback region.

@JMC47
Copy link
Contributor

JMC47 commented Aug 11, 2023

I'm guessing when we boot games from the Wii System Menu, Dolphin is cheating and just swapping to GameCube mode, hence this PR? I've definitely booted Wind Waker from the Wii System Menu before.

@Pokechu22
Copy link
Contributor

Yes, dolphin cheats by immediately loading MIOS when BC is loaded:

bool ESDevice::LaunchIOS(u64 ios_title_id, HangPPC hang_ppc)
{
// A real Wii goes through several steps before getting to MIOS.
//
// * The System Menu detects a GameCube disc and launches BC (1-100) instead of the game.
// * BC (similar to boot1) lowers the clock speed to the Flipper's and then launches boot2.
// * boot2 sees the lowered clock speed and launches MIOS (1-101) instead of the System Menu.
//
// Because we don't have boot1 and boot2, and BC is only ever used to launch MIOS
// (indirectly via boot2), we can just launch MIOS when BC is launched.
if (ios_title_id == Titles::BC)
{
NOTICE_LOG_FMT(IOS, "BC: Launching MIOS...");
return LaunchIOS(Titles::MIOS, hang_ppc);
}

and also has MIOS switch stuff into GameCube mode:

static void ReinitHardware()
{
SConfig::GetInstance().bWii = false;
// IOS clears mem2 and overwrites it with pseudo-random data (for security).
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
std::memset(memory.GetEXRAM(), 0, memory.GetExRamSizeReal());
// MIOS appears to only reset the DI and the PPC.
// HACK However, resetting DI will reset the DTK config, which is set by the system menu
// (and not by MIOS), causing games that use DTK to break. Perhaps MIOS doesn't actually
// reset DI fully, in such a way that the DTK config isn't cleared?
// system.GetDVDInterface().ResetDrive(true);
system.GetPowerPC().Reset();
Wiimote::ResetAllWiimotes();
// Note: this is specific to Dolphin and is required because we initialised it in Wii mode.
auto& dsp = system.GetDSP();
dsp.Reinit(Config::Get(Config::MAIN_DSP_HLE));
dsp.GetDSPEmulator()->Initialize(SConfig::GetInstance().bWii,
Config::Get(Config::MAIN_DSP_THREAD));
SystemTimers::ChangePPCClock(SystemTimers::Mode::GC);
}

That said, the way dolphin cheats is close to what happens on real hardware, just skipping lots of low level IOS emulation stuff; when running a GameCube game on a Wii, the Wii is in GameCube mode and most additional hardware is disabled. My understanding is that this PR is to make running GameCube games modified to run in Wii mode work on Dolphin with DSP HLE the same way it would work when loading such modified games on a real Wii (or on Dolphin with DSP LLE). It doesn't do anything that would apply when running unmodified GameCube games, even when booting them via the Wii Menu.

@stblr
Copy link
Contributor Author

stblr commented Aug 12, 2023

My understanding is that this PR is to make running GameCube games modified to run in Wii mode work on Dolphin with DSP HLE the same way it would work when loading such modified games on a real Wii (or on Dolphin with DSP LLE). It doesn't do anything that would apply when running unmodified GameCube games, even when booting them via the Wii Menu.

Indeed.

@JMC47
Copy link
Contributor

JMC47 commented Aug 30, 2023

Is anyone blocking this? I don't see a reason to block it if it won't affect anything outside of some mods that use it.

@@ -158,7 +158,7 @@ class ZeldaAudioRenderer
// the Wii, this points to some MRAM location since there is no ARAM to be
// used. If zero, use the top of ARAM.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment probably should be rewritten, since m_aram_base_addr = 0 no longer behaves differently (and SetARAMBaseAddr would never be called because command 0xE doesn't exist in GameCube uCode). I'm not 100% sure what it should say though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Came up with something, hopefully the wording is clear enough.

@stblr stblr force-pushed the gamecube-zelda-hle-in-wii-mode branch from 6923f28 to cc403c1 Compare September 29, 2023 18:48
Copy link
Contributor

@Pokechu22 Pokechu22 left a comment

Choose a reason for hiding this comment

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

Looks good to me.

I don't think AX needs a similar change, as it doesn't use GetARAMPtr, but I'm not super familiar with the details of it.

{
if (m_aram_base_addr)
return HLEMemory_Get_Pointer(m_aram_base_addr);
if (SConfig::GetInstance().bWii)
Copy link
Member

Choose a reason for hiding this comment

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

Not worth blocking over IMO, but I've heard mention of deferring SConfig to instead use the new config

Copy link
Contributor

Choose a reason for hiding this comment

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

bWii isn't something that would make sense to move to the new config system since it's not an actual setting, more of a global variable. It probably doesn't make sense to have it in SConfig, but moving it somewhere else would be part of a larger refactor (which is definitely out of scope for this PR).

Copy link
Member

Choose a reason for hiding this comment

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

Agreed. Adding new settings to SConfig would be rejected, but it's fine to keep using whatever is in there for the time being.

@AdmiralCurtiss AdmiralCurtiss merged commit 68c9362 into dolphin-emu:master Oct 4, 2023
11 checks passed
@stblr stblr deleted the gamecube-zelda-hle-in-wii-mode branch November 29, 2023 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
6 participants