Merge pull request #10746 from Pokechu22/bs2-emu-registers

BS2Emu: Set HID0/1/2/4 and MSR with correct default values
This commit is contained in:
JMC47 2022-06-25 22:21:07 -04:00 committed by GitHub
commit e18053d307
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 5 deletions

View file

@ -538,14 +538,12 @@ bool CBoot::BootUp(std::unique_ptr<BootParameters> boot)
SetDefaultDisc();
SetupMSR();
SetupHID(config.bWii);
SetupBAT(config.bWii);
CopyDefaultExceptionHandlers();
if (config.bWii)
{
PowerPC::ppcState.spr[SPR_HID0] = 0x0011c464;
PowerPC::ppcState.spr[SPR_HID4] = 0x82000000;
// Set a value for the SP. It doesn't matter where this points to,
// as long as it is a valid location. This value is taken from a homebrew binary.
PowerPC::ppcState.gpr[1] = 0x8004d4bc;

View file

@ -160,6 +160,7 @@ private:
static bool BootNANDTitle(u64 title_id);
static void SetupMSR();
static void SetupHID(bool is_wii);
static void SetupBAT(bool is_wii);
static bool RunApploader(bool is_wii, const DiscIO::VolumeDisc& volume,
const std::vector<DiscIO::Riivolution::Patch>& riivolution_patches);

View file

@ -37,6 +37,10 @@
#include "DiscIO/RiivolutionPatcher.h"
#include "DiscIO/VolumeDisc.h"
#include "VideoCommon/VertexManagerBase.h"
#include "VideoCommon/VertexShaderManager.h"
#include "VideoCommon/XFMemory.h"
namespace
{
void PresetTimeBaseTicks()
@ -61,10 +65,44 @@ void CBoot::RunFunction(u32 address)
void CBoot::SetupMSR()
{
MSR.FP = 1;
// 0x0002032
MSR.RI = 1;
MSR.DR = 1;
MSR.IR = 1;
MSR.EE = 1;
MSR.FP = 1;
}
void CBoot::SetupHID(bool is_wii)
{
// HID0 is 0x0011c464 on GC, 0x0011c664 on Wii
HID0.BHT = 1;
HID0.BTIC = 1;
HID0.DCFA = 1;
if (is_wii)
HID0.SPD = 1;
HID0.DCFI = 1;
HID0.DCE = 1;
// Note that Datel titles will fail to boot if the instruction cache is not enabled; see
// https://bugs.dolphin-emu.org/issues/8223
HID0.ICE = 1;
HID0.NHR = 1;
HID0.DPM = 1;
// HID1 is initialized in PowerPC.cpp to 0x80000000
// HID2 is 0xe0000000
HID2.PSE = 1;
HID2.WPE = 1;
HID2.LSQE = 1;
// HID4 is 0 on GC and 0x83900000 on Wii
if (is_wii)
{
HID4.L2CFI = 1;
HID4.LPE = 1;
HID4.ST0 = 1;
HID4.SBE = 1;
HID4.reserved_3 = 1;
}
}
void CBoot::SetupBAT(bool is_wii)
@ -214,10 +252,22 @@ bool CBoot::EmulatedBS2_GC(const DiscIO::VolumeDisc& volume,
INFO_LOG_FMT(BOOT, "Faking GC BS2...");
SetupMSR();
SetupHID(/*is_wii*/ false);
SetupBAT(/*is_wii*/ false);
SetupGCMemory();
// Datel titles don't initialize the postMatrices, but they have dual-texture coordinate
// transformation enabled. We initialize all of xfmem to 0, which results in everything using
// a texture coordinate of (0, 0), breaking textures. Normally the IPL will initialize the last
// entry to the identity matrix, but the whole point of BS2 EMU is that it skips the IPL, so we
// need to do this initialization ourselves.
xfmem.postMatrices[0x3d * 4 + 0] = 1.0f;
xfmem.postMatrices[0x3e * 4 + 1] = 1.0f;
xfmem.postMatrices[0x3f * 4 + 2] = 1.0f;
g_vertex_manager->Flush();
VertexShaderManager::InvalidateXFRange(XFMEM_POSTMATRICES + 0x3d * 4, XFMEM_POSTMATRICES_END);
DVDReadDiscID(volume, 0x00000000);
bool streaming = Memory::Read_U8(0x80000008);
@ -500,6 +550,7 @@ bool CBoot::EmulatedBS2_Wii(const DiscIO::VolumeDisc& volume,
DVDRead(volume, 0, 0x3180, 4, partition);
SetupMSR();
SetupHID(/*is_wii*/ true);
SetupBAT(/*is_wii*/ true);
Memory::Write_U32(0x4c000064, 0x00000300); // Write default DSI Handler: rfi