Fix Homebrew region inconsistency exposed by #2596. #2622
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prior to #2596, Wii Homebrew would boot in either 50Hz or 60Hz depending on if the PAL60 option was ticked in Config -> Wii. This made some amount of sense if you weren't familiar with the internal boot logic, so no one noticed why or how that actually worked.
#2596 changed it so that NTSC games would always turn off the PAL60 setting because some NTSC games would read that setting and crash because they were never tested in that environment. This exposed an odd behavior: Wii Homebrew now always boots in 50Hz! How and why does that happen?
To find the answer to that, we have to look into the source code for libogc, which almost all homebrew uses, to figure out how they choose which video mode to use. The sample code suggests to select an appropriate video mode by calling
VIDEO_GetPreferredMode()
, which is defined invideo.c
. The relevant part is this:Most of this is pretty clear, but what exactly does
CONF_GetVideo()
(inconf.c
) do? Let's see...Aha!
__CONF_GetTxt()
reads from the Wii'ssetting.txt
file, soCONF_GetVideo()
uses the VIDEO string from that to figure out the console region. From here we can work backwards to understand what this code does in Dolphin.The
setting.txt
is generated in CBoot::SetupWiiMemory. Specifically, we decide which region to generate for with these lines:Homebrew doesn't have a game ID to read a country from, so it will always be
COUNTRY_UNKNOWN
, which in turn setsSETTING_EUROPE
. In other words, homebrew always boots in a European console environment.Well, that explains why the PAL60 setting affects the refresh rate of homebrew (compare with the
VIDEO_GetPreferredMode()
code), but it doesn't explain why that stopped working in #2596. So let's dig further.SConfig::AutoSetup runs before
CBoot::SetupWiiMemory
and sets up some boot parameters. For homebrew specifically, it sets:Now hold on, we just established that homebrew runs in a European environment! This is inconsistent! But it explains what happens and why #2596 broke it:
SConfig::AutoSetup
sets NTSC-U parameters, which in turn causes BootManager::BootCore() to turn off the PAL60 setting for compatibility reasons. Meanwhile,CBoot::SetupWiiMemory
generates a Europeansetting.txt
. Then, in libogc,VIDEO_GetPreferredMode()
sees the Europeansetting.txt
and the turned off PAL60 flag and selects a 50Hz video mode from that information.This PR changes this so that a turned off PAL60 setting will boot Wii homebrew in a PAL/Europe environment at 50Hz, and a turned on PAL60 setting will boot Wii homebrew in a PAL/Europe environment at 60Hz. GameCube homebrew always boots in NTSC at 60Hz. This corresponds to how homebrew booted before #2596 and removes the odd regional inconsistency.
In the future we should maybe provide options to boot homebrew in any environment, and I've set it up so you'd only have to change the bNTSC flag appropriately in
SConfig::AutoSetup()
for the rest to set properly, but this is probably good enough for most use cases for now.