CDVD: set default region data for PStwo nvram, set iLink ID checksum for bios v1.70 and up

This commit is contained in:
AKuHAK 2022-11-28 11:09:13 +02:00 committed by refractionpcsx2
parent 9da8e9280f
commit 78ad2cfb88
2 changed files with 41 additions and 4 deletions

View File

@ -172,12 +172,27 @@ static void cdvdCreateNewNVM(std::FILE* fp)
// Write NVM ILink area with dummy data (Age of Empires 2)
// Also write language data defaulting to English (Guitar Hero 2)
// Also write PStwo region defaults
NVMLayout* nvmLayout = getNvmLayout();
u8 ILinkID_Data[8] = {0x00, 0xAC, 0xFF, 0xFF, 0xFF, 0xFF, 0xB9, 0x86};
if (((BiosVersion >> 8) == 2) && ((BiosVersion & 0xff) != 10)) // bios >= 200, except of 0x210 for PSX2 DESR
{
u8 RegParams[12];
memcpy(RegParams, &PStwoRegionDefaults[BiosRegion][0], 12);
std::fseek(fp, *(s32*)(((u8*)nvmLayout) + offsetof(NVMLayout, regparams)), SEEK_SET);
std::fwrite(RegParams, sizeof(RegParams), 1, fp);
}
u8 ILinkID_Data[8] = {0x00, 0xAC, 0xFF, 0xFF, 0xFF, 0xFF, 0xB9, 0x86};
std::fseek(fp, *(s32*)(((u8*)nvmLayout) + offsetof(NVMLayout, ilinkId)), SEEK_SET);
std::fwrite(ILinkID_Data, sizeof(ILinkID_Data), 1, fp);
if (nvmlayouts[1].biosVer <= BiosVersion)
{
u8 ILinkID_checksum[2] = {0x00, 0x18};
std::fseek(fp, *(s32*)(((u8*)nvmLayout) + offsetof(NVMLayout, ilinkId)) + 0x08, SEEK_SET);
std::fwrite(ILinkID_checksum, sizeof(ILinkID_checksum), 1, fp);
}
u8 biosLanguage[16];
memcpy(biosLanguage, &biosLangDefaults[BiosRegion][0], 16);
@ -208,14 +223,19 @@ static void cdvdNVM(u8* buffer, int offset, size_t bytes, bool read)
else
{
u8 LanguageParams[16];
u8 RegParams[12];
u8 zero[16] = {0};
NVMLayout* nvmLayout = getNvmLayout();
if (std::fseek(fp.get(), *(s32*)(((u8*)nvmLayout) + offsetof(NVMLayout, config1)) + 0x10, SEEK_SET) != 0 ||
std::fread(LanguageParams, 16, 1, fp.get()) != 1 ||
std::memcmp(LanguageParams, zero, sizeof(LanguageParams)) == 0)
std::memcmp(LanguageParams, zero, sizeof(LanguageParams)) == 0 ||
(((BiosVersion >> 8) == 2) && ((BiosVersion & 0xff) != 10) &&
(std::fseek(fp.get(), *(s32*)(((u8*)nvmLayout) + offsetof(NVMLayout, regparams)), SEEK_SET) != 0 ||
std::fread(RegParams, 12, 1, fp.get()) != 1 ||
std::memcmp(RegParams, zero, sizeof(RegParams)) == 0)))
{
Console.Warning("Language Parameters missing, filling in defaults");
Console.Warning("Language or Region Parameters missing, filling in defaults");
FileSystem::FSeek64(fp.get(), 0, SEEK_SET);
cdvdCreateNewNVM(fp.get());

View File

@ -277,6 +277,23 @@ static NVMLayout nvmlayouts[NVM_FORMAT_MAX] =
{0x146, 0x270, 0x2B0, 0x200, 0x1C8, 0x1E0, 0x1B0, 0x180, 0x198}, // eeproms from bios v1.70 and up
};
static u8 PStwoRegionDefaults[13][12] =
{
{0x4a, 0x4a, 0x6a, 0x70, 0x6e, 0x4a, 0x4a, 0x00, 0x00, 0x00, 0x00, 0x00}, // JJjpnJJ - Japan
{0x41, 0x41, 0x65, 0x6e, 0x67, 0x41, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00}, // AAengAU - USA
{0x45, 0x45, 0x65, 0x6e, 0x67, 0x45, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00}, // EEengEE - Europe
{0x45, 0x45, 0x65, 0x6e, 0x67, 0x45, 0x4f, 0x00, 0x00, 0x00, 0x00, 0x00}, // EEengEO - Oceania
{0x48, 0x48, 0x65, 0x6e, 0x67, 0x4a, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00}, // HHengJA - Asia
{0x45, 0x52, 0x65, 0x6e, 0x67, 0x45, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00}, // ERengER - Russia
{0x43, 0x43, 0x73, 0x63, 0x68, 0x4A, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00}, // CCschJC - China
{0x41, 0x41, 0x73, 0x70, 0x61, 0x41, 0x4D, 0x00, 0x00, 0x00, 0x00, 0x00}, // AAspaAM - Mexico
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // T10K (does not exist)
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Test (does not exist)
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Free (does not exist)
{0x48, 0x4b, 0x6b, 0x6f, 0x72, 0x4a, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00}, // HKkorJA - Korea
{0x48, 0x48, 0x74, 0x63, 0x68, 0x4a, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00}, // HHtchJA - Taiwan
};
static u8 biosLangDefaults[11][16] =
{
{0x20, 0x20, 0x80, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30}, // Japan (Japanese)
@ -289,5 +306,5 @@ static u8 biosLangDefaults[11][16] =
{0x30, 0x21, 0x80, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41}, // Mexico (English)
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // T10K (Japanese, generally gets overridden)
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Test (Japanese, as above)
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Free (Japanese, no examples to use)
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Free (Japanese, no examples to use)
};