[Rom] Support CRC calculation for 64DD IPLs

This commit is contained in:
LuigiBlood 2019-08-11 13:30:51 +02:00
parent 053ef11c5a
commit 3bd5595e77
4 changed files with 84 additions and 13 deletions

View File

@ -220,7 +220,7 @@ void DiskBMUpdate()
else
{
//Read Data
if (((g_Reg->ASIC_CUR_TK >> 16) & 0x1FFF) == 6 && g_Reg->ASIC_CUR_SECTOR == 0)
if (((g_Reg->ASIC_CUR_TK >> 16) & 0x1FFF) == 6 && g_Reg->ASIC_CUR_SECTOR == 0 && g_Reg->ASIC_ID_REG != 0x00040000)
{
g_Reg->ASIC_STATUS &= ~DD_STATUS_DATA_RQ;
g_Reg->ASIC_BM_STATUS |= DD_BM_STATUS_MICRO;

View File

@ -321,6 +321,7 @@ void CN64Rom::CalculateRomCrc()
uint32_t a0, a1, a2, a3;
uint32_t s0;
uint32_t v0, v1;
uint32_t length = 0x00100000;
// CIC_NUS_6101 at=0x5D588B65 , s6=0x3F
// CIC_NUS_6102 at=0x5D588B65 , s6=0x3F
@ -328,9 +329,11 @@ void CN64Rom::CalculateRomCrc()
// CIC_NUS_6105 at=0x5d588b65 , s6=0x91
// CIC_NUS_6106 at=0x6C078965 , s6=0x85
// 64DD IPL at=0x02E90EDD , s6=0xdd
// 64DD IPL (JPN) at=0x02E90EDD , s6=0xdd
// 64DD IPL (USA) at=0x02E90EDD , s6=0xde
// 64DD TOOL IPL at=0x0260BCD5 , s6=0xdd
//v0 = 0xFFFFFFFF & (0x3F * at) + 1;
//v0 = 0xFFFFFFFF & (s6 * at) + 1;
switch (m_CicChip)
{
case CIC_NUS_6101:
@ -338,6 +341,9 @@ void CN64Rom::CalculateRomCrc()
case CIC_NUS_6103: v0 = 0xA3886759; break;
case CIC_NUS_6105: v0 = 0xDF26F436; break;
case CIC_NUS_6106: v0 = 0x1FEA617A; break;
case CIC_NUS_DDUS: length = 0x000A0000; v0 = 0x861AE3A7; break;
case CIC_NUS_8303: length = 0x000A0000; v0 = 0x8331D4CA; break;
case CIC_NUS_DDTL: length = 0x000A0000; v0 = 0x0D8303E2; break;
default:
return;
}
@ -355,14 +361,23 @@ void CN64Rom::CalculateRomCrc()
a2 = v0;
t4 = v0;
for (t0 = 0; t0 < 0x00100000; t0 += 4)
for (t0 = 0; t0 < length; t0 += 4)
{
v0 = *(uint32_t *)(m_ROMImage + t0 + 0x1000);
v1 = a3 + v0;
a1 = v1;
if (v1 < a3) t2 += 0x1;
if (v1 < a3) {
if (m_CicChip == CIC_NUS_DDUS || m_CicChip == CIC_NUS_8303)
{
t2 = t2 ^ t3;
}
else
{
t2 += 0x1;
}
}
v1 = v0 & 0x001F;
a0 = (v0 << v1) | (v0 >> (t5 - v1));
@ -371,8 +386,17 @@ void CN64Rom::CalculateRomCrc()
t3 = t3 ^ v0;
s0 = s0 + a0;
if (a2 < v0) a2 = a3 ^ v0 ^ a2;
else a2 = a2 ^ a0;
if (a2 < v0)
{
a2 = a3 ^ v0 ^ a2;
}
else
{
if (m_CicChip == CIC_NUS_8303)
a2 = a2 + a0;
else
a2 = a2 ^ a0;
}
if (m_CicChip == CIC_NUS_6105)
{
@ -613,9 +637,23 @@ bool CN64Rom::LoadN64Image(const char * FileLoc, bool LoadBootCodeOnly)
}
m_Country = (Country)m_ROMImage[0x3D];
m_RomIdent.Format("%08X-%08X-C:%X", *(uint32_t *)(&m_ROMImage[0x10]), *(uint32_t *)(&m_ROMImage[0x14]), m_ROMImage[0x3D]);
WriteTrace(TraceN64System, TraceDebug, "Ident: %s", m_RomIdent.c_str());
CalculateCicChip();
uint32_t CRC1, CRC2;
if (m_CicChip == CIC_NUS_8303 || m_CicChip == CIC_NUS_DDUS || m_CicChip == CIC_NUS_DDTL)
{
//Handle CRC differently if 64DD IPL
CRC1 = (*(uint16_t *)(&m_ROMImage[0x608]) << 16) | *(uint16_t *)(&m_ROMImage[0x60C]);
CRC2 = (*(uint16_t *)(&m_ROMImage[0x638]) << 16) | *(uint16_t *)(&m_ROMImage[0x63C]);
}
else
{
CRC1 = *(uint32_t *)(&m_ROMImage[0x10]);
CRC2 = *(uint32_t *)(&m_ROMImage[0x14]);
}
m_RomIdent.Format("%08X-%08X-C:%X", CRC1, CRC2, m_ROMImage[0x3D]);
WriteTrace(TraceN64System, TraceDebug, "Ident: %s", m_RomIdent.c_str());
if (!LoadBootCodeOnly && g_Rom == this)
{
@ -757,9 +795,23 @@ bool CN64Rom::LoadN64ImageIPL(const char * FileLoc, bool LoadBootCodeOnly)
}
m_Country = (Country)m_ROMImage[0x3D];
m_RomIdent.Format("%08X-%08X-C:%X", *(uint32_t *)(&m_ROMImage[0x10]), *(uint32_t *)(&m_ROMImage[0x14]), m_ROMImage[0x3D]);
WriteTrace(TraceN64System, TraceDebug, "Ident: %s", m_RomIdent.c_str());
CalculateCicChip();
uint32_t CRC1, CRC2;
if (m_CicChip == CIC_NUS_8303 || m_CicChip == CIC_NUS_DDUS || m_CicChip == CIC_NUS_DDTL)
{
//Handle CRC differently if 64DD IPL
CRC1 = (*(uint16_t *)(&m_ROMImage[0x608]) << 16) | *(uint16_t *)(&m_ROMImage[0x60C]);
CRC2 = (*(uint16_t *)(&m_ROMImage[0x638]) << 16) | *(uint16_t *)(&m_ROMImage[0x63C]);
}
else
{
CRC1 = *(uint32_t *)(&m_ROMImage[0x10]);
CRC2 = *(uint32_t *)(&m_ROMImage[0x14]);
}
m_RomIdent.Format("%08X-%08X-C:%X", CRC1, CRC2, m_ROMImage[0x3D]);
WriteTrace(TraceN64System, TraceDebug, "Ident: %s", m_RomIdent.c_str());
if (!IsLoadedRomDDIPL())
{

View File

@ -475,6 +475,12 @@ bool CRomList::FillRomInfo(ROM_INFO * pRomInfo)
pRomInfo->CRC1 = *(uint32_t *)(RomData + 0x10);
pRomInfo->CRC2 = *(uint32_t *)(RomData + 0x14);
pRomInfo->CicChip = CN64Rom::GetCicChipID(RomData);
if (pRomInfo->CicChip == CIC_NUS_8303 || pRomInfo->CicChip == CIC_NUS_DDUS || pRomInfo->CicChip == CIC_NUS_DDTL)
{
pRomInfo->CRC1 = (*(uint16_t *)(RomData + 0x608) << 16) | *(uint16_t *)(RomData + 0x60C);
pRomInfo->CRC2 = (*(uint16_t *)(RomData + 0x638) << 16) | *(uint16_t *)(RomData + 0x63C);
}
FillRomExtensionInfo(pRomInfo);
}
else

View File

@ -137,8 +137,20 @@ DWORD CALLBACK RomInfoProc(HWND hDlg, DWORD uMsg, DWORD wParam, DWORD lParam)
default:
SetDlgItemTextW(hDlg, IDC_INFO_COUNTRY, stdstr_f(" Unknown %c (%02X)", RomHeader[0x3D], RomHeader[0x3D]).ToUTF16().c_str());
}
SetDlgItemTextW(hDlg, IDC_INFO_CRC1, stdstr_f("0x%08X", *(uint32_t *)(RomHeader + 0x10)).ToUTF16().c_str());
SetDlgItemTextW(hDlg, IDC_INFO_CRC2, stdstr_f("0x%08X", *(DWORD *)(RomHeader + 0x14)).ToUTF16().c_str());
switch (_this->m_pRomInfo->CicChipID())
{
case CIC_NUS_8303:
case CIC_NUS_DDUS:
case CIC_NUS_DDTL:
SetDlgItemTextW(hDlg, IDC_INFO_CRC1, stdstr_f("0x%08X", (*(uint16_t *)(RomHeader + 0x608) << 16) | *(uint16_t *)(RomHeader + 0x60C)).ToUTF16().c_str());
SetDlgItemTextW(hDlg, IDC_INFO_CRC2, stdstr_f("0x%08X", (*(uint16_t *)(RomHeader + 0x638) << 16) | *(uint16_t *)(RomHeader + 0x63C)).ToUTF16().c_str());
break;
default:
SetDlgItemTextW(hDlg, IDC_INFO_CRC1, stdstr_f("0x%08X", *(uint32_t *)(RomHeader + 0x10)).ToUTF16().c_str());
SetDlgItemTextW(hDlg, IDC_INFO_CRC2, stdstr_f("0x%08X", *(DWORD *)(RomHeader + 0x14)).ToUTF16().c_str());
break;
}
std::wstring CicChip;
switch (_this->m_pRomInfo->CicChipID())
@ -147,6 +159,7 @@ DWORD CALLBACK RomInfoProc(HWND hDlg, DWORD uMsg, DWORD wParam, DWORD lParam)
case CIC_NUS_8303: CicChip = L"CIC-NUS-8303"; break;
case CIC_NUS_5167: CicChip = L"CIC-NUS-5167"; break;
case CIC_NUS_DDUS: CicChip = L"CIC-NUS-????"; break;
case CIC_NUS_DDTL: CicChip = L"CIC-NUS-????"; break;
default: CicChip = stdstr_f("CIC-NUS-610%d", _this->m_pRomInfo->CicChipID()).ToUTF16(); break;
}
SetDlgItemTextW(hDlg, IDC_INFO_CIC, CicChip.c_str());